Java Code Examples for com.google.android.exoplayer2.extractor.Extractor#RESULT_END_OF_INPUT

The following examples show how to use com.google.android.exoplayer2.extractor.Extractor#RESULT_END_OF_INPUT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebvttExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  int currentFileSize = (int) input.getLength();

  // Increase the size of sampleData if necessary.
  if (sampleSize == sampleData.length) {
    sampleData = Arrays.copyOf(sampleData,
        (currentFileSize != C.LENGTH_UNSET ? currentFileSize : sampleData.length) * 3 / 2);
  }

  // Consume to the input.
  int bytesRead = input.read(sampleData, sampleSize, sampleData.length - sampleSize);
  if (bytesRead != C.RESULT_END_OF_INPUT) {
    sampleSize += bytesRead;
    if (currentFileSize == C.LENGTH_UNSET || sampleSize != currentFileSize) {
      return Extractor.RESULT_CONTINUE;
    }
  }

  // We've reached the end of the input, which corresponds to the end of the current file.
  processSample();
  return Extractor.RESULT_END_OF_INPUT;
}
 
Example 2
Source File: MatroskaExtractor.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  sampleRead = false;
  boolean continueReading = true;
  while (continueReading && !sampleRead) {
    continueReading = reader.read(input);
    if (continueReading && maybeSeekForCues(seekPosition, input.getPosition())) {
      return Extractor.RESULT_SEEK;
    }
  }
  if (!continueReading) {
    for (int i = 0; i < tracks.size(); i++) {
      tracks.valueAt(i).outputPendingSampleMetadata();
    }
    return Extractor.RESULT_END_OF_INPUT;
  }
  return Extractor.RESULT_CONTINUE;
}
 
Example 3
Source File: WebvttExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  int currentFileSize = (int) input.getLength();

  // Increase the size of sampleData if necessary.
  if (sampleSize == sampleData.length) {
    sampleData = Arrays.copyOf(sampleData,
        (currentFileSize != C.LENGTH_UNSET ? currentFileSize : sampleData.length) * 3 / 2);
  }

  // Consume to the input.
  int bytesRead = input.read(sampleData, sampleSize, sampleData.length - sampleSize);
  if (bytesRead != C.RESULT_END_OF_INPUT) {
    sampleSize += bytesRead;
    if (currentFileSize == C.LENGTH_UNSET || sampleSize != currentFileSize) {
      return Extractor.RESULT_CONTINUE;
    }
  }

  // We've reached the end of the input, which corresponds to the end of the current file.
  processSample();
  return Extractor.RESULT_END_OF_INPUT;
}
 
Example 4
Source File: WebvttExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  int currentFileSize = (int) input.getLength();

  // Increase the size of sampleData if necessary.
  if (sampleSize == sampleData.length) {
    sampleData = Arrays.copyOf(sampleData,
        (currentFileSize != C.LENGTH_UNSET ? currentFileSize : sampleData.length) * 3 / 2);
  }

  // Consume to the input.
  int bytesRead = input.read(sampleData, sampleSize, sampleData.length - sampleSize);
  if (bytesRead != C.RESULT_END_OF_INPUT) {
    sampleSize += bytesRead;
    if (currentFileSize == C.LENGTH_UNSET || sampleSize != currentFileSize) {
      return Extractor.RESULT_CONTINUE;
    }
  }

  // We've reached the end of the input, which corresponds to the end of the current file.
  processSample();
  return Extractor.RESULT_END_OF_INPUT;
}
 
Example 5
Source File: MatroskaExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException,
    InterruptedException {
  sampleRead = false;
  boolean continueReading = true;
  while (continueReading && !sampleRead) {
    continueReading = reader.read(input);
    if (continueReading && maybeSeekForCues(seekPosition, input.getPosition())) {
      return Extractor.RESULT_SEEK;
    }
  }
  if (!continueReading) {
    for (int i = 0; i < tracks.size(); i++) {
      tracks.valueAt(i).outputPendingSampleMetadata();
    }
    return Extractor.RESULT_END_OF_INPUT;
  }
  return Extractor.RESULT_CONTINUE;
}
 
Example 6
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  while (true) {
    switch (parserState) {
      case STATE_READING_ATOM_HEADER:
        if (!readAtomHeader(input)) {
          return Extractor.RESULT_END_OF_INPUT;
        }
        break;
      case STATE_READING_ATOM_PAYLOAD:
        readAtomPayload(input);
        break;
      case STATE_READING_ENCRYPTION_DATA:
        readEncryptionData(input);
        break;
      default:
        if (readSample(input)) {
          return RESULT_CONTINUE;
        }
    }
  }
}
 
Example 7
Source File: WebvttExtractor.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  int currentFileSize = (int) input.getLength();

  // Increase the size of sampleData if necessary.
  if (sampleSize == sampleData.length) {
    sampleData = Arrays.copyOf(sampleData,
        (currentFileSize != C.LENGTH_UNSET ? currentFileSize : sampleData.length) * 3 / 2);
  }

  // Consume to the input.
  int bytesRead = input.read(sampleData, sampleSize, sampleData.length - sampleSize);
  if (bytesRead != C.RESULT_END_OF_INPUT) {
    sampleSize += bytesRead;
    if (currentFileSize == C.LENGTH_UNSET || sampleSize != currentFileSize) {
      return Extractor.RESULT_CONTINUE;
    }
  }

  // We've reached the end of the input, which corresponds to the end of the current file.
  processSample();
  return Extractor.RESULT_END_OF_INPUT;
}
 
Example 8
Source File: MatroskaExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException,
    InterruptedException {
  sampleRead = false;
  boolean continueReading = true;
  while (continueReading && !sampleRead) {
    continueReading = reader.read(input);
    if (continueReading && maybeSeekForCues(seekPosition, input.getPosition())) {
      return Extractor.RESULT_SEEK;
    }
  }
  if (!continueReading) {
    for (int i = 0; i < tracks.size(); i++) {
      tracks.valueAt(i).outputPendingSampleMetadata();
    }
    return Extractor.RESULT_END_OF_INPUT;
  }
  return Extractor.RESULT_CONTINUE;
}
 
Example 9
Source File: WebvttExtractor.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  int currentFileSize = (int) input.getLength();

  // Increase the size of sampleData if necessary.
  if (sampleSize == sampleData.length) {
    sampleData = Arrays.copyOf(sampleData,
        (currentFileSize != C.LENGTH_UNSET ? currentFileSize : sampleData.length) * 3 / 2);
  }

  // Consume to the input.
  int bytesRead = input.read(sampleData, sampleSize, sampleData.length - sampleSize);
  if (bytesRead != C.RESULT_END_OF_INPUT) {
    sampleSize += bytesRead;
    if (currentFileSize == C.LENGTH_UNSET || sampleSize != currentFileSize) {
      return Extractor.RESULT_CONTINUE;
    }
  }

  // We've reached the end of the input, which corresponds to the end of the current file.
  processSample();
  return Extractor.RESULT_END_OF_INPUT;
}
 
Example 10
Source File: MatroskaExtractor.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public final int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  haveOutputSample = false;
  boolean continueReading = true;
  while (continueReading && !haveOutputSample) {
    continueReading = reader.read(input);
    if (continueReading && maybeSeekForCues(seekPosition, input.getPosition())) {
      return Extractor.RESULT_SEEK;
    }
  }
  if (!continueReading) {
    for (int i = 0; i < tracks.size(); i++) {
      tracks.valueAt(i).outputPendingSampleMetadata();
    }
    return Extractor.RESULT_END_OF_INPUT;
  }
  return Extractor.RESULT_CONTINUE;
}
 
Example 11
Source File: FragmentedMp4Extractor.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  while (true) {
    switch (parserState) {
      case STATE_READING_ATOM_HEADER:
        if (!readAtomHeader(input)) {
          return Extractor.RESULT_END_OF_INPUT;
        }
        break;
      case STATE_READING_ATOM_PAYLOAD:
        readAtomPayload(input);
        break;
      case STATE_READING_ENCRYPTION_DATA:
        readEncryptionData(input);
        break;
      default:
        if (readSample(input)) {
          return RESULT_CONTINUE;
        }
    }
  }
}
 
Example 12
Source File: MatroskaExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  sampleRead = false;
  boolean continueReading = true;
  while (continueReading && !sampleRead) {
    continueReading = reader.read(input);
    if (continueReading && maybeSeekForCues(seekPosition, input.getPosition())) {
      return Extractor.RESULT_SEEK;
    }
  }
  if (!continueReading) {
    for (int i = 0; i < tracks.size(); i++) {
      tracks.valueAt(i).outputPendingSampleMetadata();
    }
    return Extractor.RESULT_END_OF_INPUT;
  }
  return Extractor.RESULT_CONTINUE;
}
 
Example 13
Source File: StreamReader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private int readPayload(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  long position = oggSeeker.read(input);
  if (position >= 0) {
    seekPosition.position = position;
    return Extractor.RESULT_SEEK;
  } else if (position < -1) {
    onSeekEnd(-(position + 2));
  }
  if (!seekMapSet) {
    SeekMap seekMap = oggSeeker.createSeekMap();
    extractorOutput.seekMap(seekMap);
    seekMapSet = true;
  }

  if (lengthOfReadPacket > 0 || oggPacket.populate(input)) {
    lengthOfReadPacket = 0;
    ParsableByteArray payload = oggPacket.getPayload();
    long granulesInPacket = preparePayload(payload);
    if (granulesInPacket >= 0 && currentGranule + granulesInPacket >= targetGranule) {
      // calculate time and send payload data to codec
      long timeUs = convertGranuleToTime(currentGranule);
      trackOutput.sampleData(payload, payload.limit());
      trackOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, payload.limit(), 0, null);
      targetGranule = -1;
    }
    currentGranule += granulesInPacket;
  } else {
    state = STATE_END_OF_INPUT;
    return Extractor.RESULT_END_OF_INPUT;
  }
  return Extractor.RESULT_CONTINUE;
}
 
Example 14
Source File: StreamReader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private int readHeaders(ExtractorInput input) throws IOException, InterruptedException {
  boolean readingHeaders = true;
  while (readingHeaders) {
    if (!oggPacket.populate(input)) {
      state = STATE_END_OF_INPUT;
      return Extractor.RESULT_END_OF_INPUT;
    }
    lengthOfReadPacket = input.getPosition() - payloadStartPosition;

    readingHeaders = readHeaders(oggPacket.getPayload(), payloadStartPosition, setupData);
    if (readingHeaders) {
      payloadStartPosition = input.getPosition();
    }
  }

  sampleRate = setupData.format.sampleRate;
  if (!formatSet) {
    trackOutput.format(setupData.format);
    formatSet = true;
  }

  if (setupData.oggSeeker != null) {
    oggSeeker = setupData.oggSeeker;
  } else if (input.getLength() == C.LENGTH_UNSET) {
    oggSeeker = new UnseekableOggSeeker();
  } else {
    OggPageHeader firstPayloadPageHeader = oggPacket.getPageHeader();
    oggSeeker = new DefaultOggSeeker(payloadStartPosition, input.getLength(), this,
        firstPayloadPageHeader.headerSize + firstPayloadPageHeader.bodySize,
        firstPayloadPageHeader.granulePosition);
  }

  setupData = null;
  state = STATE_READ_PAYLOAD;
  // First payload packet. Trim the payload array of the ogg packet after headers have been read.
  oggPacket.trimPayload();
  return Extractor.RESULT_CONTINUE;
}
 
Example 15
Source File: StreamReader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private int readHeaders(ExtractorInput input) throws IOException, InterruptedException {
  boolean readingHeaders = true;
  while (readingHeaders) {
    if (!oggPacket.populate(input)) {
      state = STATE_END_OF_INPUT;
      return Extractor.RESULT_END_OF_INPUT;
    }
    lengthOfReadPacket = input.getPosition() - payloadStartPosition;

    readingHeaders = readHeaders(oggPacket.getPayload(), payloadStartPosition, setupData);
    if (readingHeaders) {
      payloadStartPosition = input.getPosition();
    }
  }

  sampleRate = setupData.format.sampleRate;
  if (!formatSet) {
    trackOutput.format(setupData.format);
    formatSet = true;
  }

  if (setupData.oggSeeker != null) {
    oggSeeker = setupData.oggSeeker;
  } else if (input.getLength() == C.LENGTH_UNSET) {
    oggSeeker = new UnseekableOggSeeker();
  } else {
    OggPageHeader firstPayloadPageHeader = oggPacket.getPageHeader();
    oggSeeker = new DefaultOggSeeker(payloadStartPosition, input.getLength(), this,
        firstPayloadPageHeader.headerSize + firstPayloadPageHeader.bodySize,
        firstPayloadPageHeader.granulePosition);
  }

  setupData = null;
  state = STATE_READ_PAYLOAD;
  // First payload packet. Trim the payload array of the ogg packet after headers have been read.
  oggPacket.trimPayload();
  return Extractor.RESULT_CONTINUE;
}
 
Example 16
Source File: StreamReader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private int readPayload(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  long position = oggSeeker.read(input);
  if (position >= 0) {
    seekPosition.position = position;
    return Extractor.RESULT_SEEK;
  } else if (position < -1) {
    onSeekEnd(-(position + 2));
  }
  if (!seekMapSet) {
    SeekMap seekMap = oggSeeker.createSeekMap();
    extractorOutput.seekMap(seekMap);
    seekMapSet = true;
  }

  if (lengthOfReadPacket > 0 || oggPacket.populate(input)) {
    lengthOfReadPacket = 0;
    ParsableByteArray payload = oggPacket.getPayload();
    long granulesInPacket = preparePayload(payload);
    if (granulesInPacket >= 0 && currentGranule + granulesInPacket >= targetGranule) {
      // calculate time and send payload data to codec
      long timeUs = convertGranuleToTime(currentGranule);
      trackOutput.sampleData(payload, payload.limit());
      trackOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, payload.limit(), 0, null);
      targetGranule = -1;
    }
    currentGranule += granulesInPacket;
  } else {
    state = STATE_END_OF_INPUT;
    return Extractor.RESULT_END_OF_INPUT;
  }
  return Extractor.RESULT_CONTINUE;
}
 
Example 17
Source File: StreamReader.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private int readPayload(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  long position = oggSeeker.read(input);
  if (position >= 0) {
    seekPosition.position = position;
    return Extractor.RESULT_SEEK;
  } else if (position < -1) {
    onSeekEnd(-(position + 2));
  }
  if (!seekMapSet) {
    SeekMap seekMap = oggSeeker.createSeekMap();
    extractorOutput.seekMap(seekMap);
    seekMapSet = true;
  }

  if (lengthOfReadPacket > 0 || oggPacket.populate(input)) {
    lengthOfReadPacket = 0;
    ParsableByteArray payload = oggPacket.getPayload();
    long granulesInPacket = preparePayload(payload);
    if (granulesInPacket >= 0 && currentGranule + granulesInPacket >= targetGranule) {
      // calculate time and send payload data to codec
      long timeUs = convertGranuleToTime(currentGranule);
      trackOutput.sampleData(payload, payload.limit());
      trackOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, payload.limit(), 0, null);
      targetGranule = -1;
    }
    currentGranule += granulesInPacket;
  } else {
    state = STATE_END_OF_INPUT;
    return Extractor.RESULT_END_OF_INPUT;
  }
  return Extractor.RESULT_CONTINUE;
}
 
Example 18
Source File: StreamReader.java    From K-Sonic with MIT License 5 votes vote down vote up
private int readHeaders(ExtractorInput input) throws IOException, InterruptedException {
  boolean readingHeaders = true;
  while (readingHeaders) {
    if (!oggPacket.populate(input)) {
      state = STATE_END_OF_INPUT;
      return Extractor.RESULT_END_OF_INPUT;
    }
    lengthOfReadPacket = input.getPosition() - payloadStartPosition;

    readingHeaders = readHeaders(oggPacket.getPayload(), payloadStartPosition, setupData);
    if (readingHeaders) {
      payloadStartPosition = input.getPosition();
    }
  }

  sampleRate = setupData.format.sampleRate;
  if (!formatSet) {
    trackOutput.format(setupData.format);
    formatSet = true;
  }

  if (setupData.oggSeeker != null) {
    oggSeeker = setupData.oggSeeker;
  } else if (input.getLength() == C.LENGTH_UNSET) {
    oggSeeker = new UnseekableOggSeeker();
  } else {
    OggPageHeader firstPayloadPageHeader = oggPacket.getPageHeader();
    oggSeeker = new DefaultOggSeeker(payloadStartPosition, input.getLength(), this,
        firstPayloadPageHeader.headerSize + firstPayloadPageHeader.bodySize,
        firstPayloadPageHeader.granulePosition);
  }

  setupData = null;
  state = STATE_READ_PAYLOAD;
  return Extractor.RESULT_CONTINUE;
}
 
Example 19
Source File: WavExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  if (wavHeader == null) {
    wavHeader = WavHeaderReader.peek(input);
    if (wavHeader == null) {
      // Should only happen if the media wasn't sniffed.
      throw new ParserException("Unsupported or unrecognized wav header.");
    }
    Format format = Format.createAudioSampleFormat(null, MimeTypes.AUDIO_RAW, null,
        wavHeader.getBitrate(), MAX_INPUT_SIZE, wavHeader.getNumChannels(),
        wavHeader.getSampleRateHz(), wavHeader.getEncoding(), null, null, 0, null);
    trackOutput.format(format);
    bytesPerFrame = wavHeader.getBytesPerFrame();
  }

  if (!wavHeader.hasDataBounds()) {
    WavHeaderReader.skipToData(input, wavHeader);
    extractorOutput.seekMap(wavHeader);
  } else if (input.getPosition() == 0) {
    input.skipFully(wavHeader.getDataStartPosition());
  }

  long dataEndPosition = wavHeader.getDataEndPosition();
  Assertions.checkState(dataEndPosition != C.POSITION_UNSET);

  long bytesLeft = dataEndPosition - input.getPosition();
  if (bytesLeft <= 0) {
    return Extractor.RESULT_END_OF_INPUT;
  }

  int maxBytesToRead = (int) Math.min(MAX_INPUT_SIZE - pendingBytes, bytesLeft);
  int bytesAppended = trackOutput.sampleData(input, maxBytesToRead, true);
  if (bytesAppended != RESULT_END_OF_INPUT) {
    pendingBytes += bytesAppended;
  }

  // Samples must consist of a whole number of frames.
  int pendingFrames = pendingBytes / bytesPerFrame;
  if (pendingFrames > 0) {
    long timeUs = wavHeader.getTimeUs(input.getPosition() - pendingBytes);
    int size = pendingFrames * bytesPerFrame;
    pendingBytes -= size;
    trackOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, size, pendingBytes, null);
  }

  return bytesAppended == RESULT_END_OF_INPUT ? RESULT_END_OF_INPUT : RESULT_CONTINUE;
}
 
Example 20
Source File: StreamReader.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private int readHeaders(ExtractorInput input) throws IOException, InterruptedException {
  boolean readingHeaders = true;
  while (readingHeaders) {
    if (!oggPacket.populate(input)) {
      state = STATE_END_OF_INPUT;
      return Extractor.RESULT_END_OF_INPUT;
    }
    lengthOfReadPacket = input.getPosition() - payloadStartPosition;

    readingHeaders = readHeaders(oggPacket.getPayload(), payloadStartPosition, setupData);
    if (readingHeaders) {
      payloadStartPosition = input.getPosition();
    }
  }

  sampleRate = setupData.format.sampleRate;
  if (!formatSet) {
    trackOutput.format(setupData.format);
    formatSet = true;
  }

  if (setupData.oggSeeker != null) {
    oggSeeker = setupData.oggSeeker;
  } else if (input.getLength() == C.LENGTH_UNSET) {
    oggSeeker = new UnseekableOggSeeker();
  } else {
    OggPageHeader firstPayloadPageHeader = oggPacket.getPageHeader();
    boolean isLastPage = (firstPayloadPageHeader.type & 0x04) != 0; // Type 4 is end of stream.
    oggSeeker =
        new DefaultOggSeeker(
            this,
            payloadStartPosition,
            input.getLength(),
            firstPayloadPageHeader.headerSize + firstPayloadPageHeader.bodySize,
            firstPayloadPageHeader.granulePosition,
            isLastPage);
  }

  setupData = null;
  state = STATE_READ_PAYLOAD;
  // First payload packet. Trim the payload array of the ogg packet after headers have been read.
  oggPacket.trimPayload();
  return Extractor.RESULT_CONTINUE;
}