com.google.android.exoplayer2.extractor.PositionHolder Java Examples

The following examples show how to use com.google.android.exoplayer2.extractor.PositionHolder. 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: Mp4Extractor.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 RESULT_END_OF_INPUT;
        }
        break;
      case STATE_READING_ATOM_PAYLOAD:
        if (readAtomPayload(input, seekPosition)) {
          return RESULT_SEEK;
        }
        break;
      case STATE_READING_SAMPLE:
        return readSample(input, seekPosition);
      default:
        throw new IllegalStateException();
    }
  }
}
 
Example #2
Source File: StreamReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @see Extractor#read(ExtractorInput, PositionHolder)
 */
final int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  switch (state) {
    case STATE_READ_HEADERS:
      return readHeaders(input);
    case STATE_SKIP_HEADERS:
      input.skipFully((int) payloadStartPosition);
      state = STATE_READ_PAYLOAD;
      return Extractor.RESULT_CONTINUE;
    case STATE_READ_PAYLOAD:
      return readPayload(input, seekPosition);
    default:
      // Never happens.
      throw new IllegalStateException();
  }
}
 
Example #3
Source File: OggExtractor.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 {
  if (streamReader == null) {
    if (!sniffInternal(input)) {
      throw new ParserException("Failed to determine bitstream type");
    }
    input.resetPeekPosition();
  }
  if (!streamReaderInitialized) {
    TrackOutput trackOutput = output.track(0, C.TRACK_TYPE_AUDIO);
    output.endTracks();
    streamReader.init(output, trackOutput);
    streamReaderInitialized = true;
  }
  return streamReader.read(input, seekPosition);
}
 
Example #4
Source File: Ac3Extractor.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 {
  int bytesRead = input.read(sampleData.data, 0, MAX_SYNC_FRAME_SIZE);
  if (bytesRead == C.RESULT_END_OF_INPUT) {
    return RESULT_END_OF_INPUT;
  }

  // Feed whatever data we have to the reader, regardless of whether the read finished or not.
  sampleData.setPosition(0);
  sampleData.setLimit(bytesRead);

  if (!startedPacket) {
    // Pass data to the reader as though it's contained within a single infinitely long packet.
    reader.packetStarted(/* pesTimeUs= */ 0, FLAG_DATA_ALIGNMENT_INDICATOR);
    startedPacket = true;
  }
  // TODO: Make it possible for the reader to consume the dataSource directly, so that it becomes
  // unnecessary to copy the data through packetBuffer.
  reader.consume(sampleData);
  return RESULT_CONTINUE;
}
 
Example #5
Source File: Mp3Extractor.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  if (synchronizedHeaderData == 0) {
    try {
      synchronize(input, false);
    } catch (EOFException e) {
      return RESULT_END_OF_INPUT;
    }
  }
  if (seeker == null) {
    seeker = setupSeeker(input);
    extractorOutput.seekMap(seeker);
    trackOutput.format(Format.createAudioSampleFormat(null, synchronizedHeader.mimeType, null,
        Format.NO_VALUE, MpegAudioHeader.MAX_FRAME_SIZE_BYTES, synchronizedHeader.channels,
        synchronizedHeader.sampleRate, Format.NO_VALUE, gaplessInfoHolder.encoderDelay,
        gaplessInfoHolder.encoderPadding, null, null, 0, null,
        (flags & FLAG_DISABLE_ID3_METADATA) != 0 ? null : metadata));
  }
  return readSample(input);
}
 
Example #6
Source File: PsDurationReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reads a PS duration from the input.
 *
 * <p>This reader reads the duration by reading SCR values from the header of a pack at the start
 * and at the end of the stream, calculating the difference, and converting that into stream
 * duration.
 *
 * @param input The {@link ExtractorInput} from which data should be read.
 * @param seekPositionHolder If {@link Extractor#RESULT_SEEK} is returned, this holder is updated
 *     to hold the position of the required seek.
 * @return One of the {@code RESULT_} values defined in {@link Extractor}.
 * @throws IOException If an error occurred reading from the input.
 * @throws InterruptedException If the thread was interrupted.
 */
public @Extractor.ReadResult int readDuration(
    ExtractorInput input, PositionHolder seekPositionHolder)
    throws IOException, InterruptedException {
  if (!isLastScrValueRead) {
    return readLastScrValue(input, seekPositionHolder);
  }
  if (lastScrValue == C.TIME_UNSET) {
    return finishReadDuration(input);
  }
  if (!isFirstScrValueRead) {
    return readFirstScrValue(input, seekPositionHolder);
  }
  if (firstScrValue == C.TIME_UNSET) {
    return finishReadDuration(input);
  }

  long minScrPositionUs = scrTimestampAdjuster.adjustTsTimestamp(firstScrValue);
  long maxScrPositionUs = scrTimestampAdjuster.adjustTsTimestamp(lastScrValue);
  durationUs = maxScrPositionUs - minScrPositionUs;
  return finishReadDuration(input);
}
 
Example #7
Source File: TsDurationReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private int readLastPcrValue(ExtractorInput input, PositionHolder seekPositionHolder, int pcrPid)
    throws IOException, InterruptedException {
  int bytesToRead = (int) Math.min(DURATION_READ_BYTES, input.getLength());
  long bufferStartStreamPosition = input.getLength() - bytesToRead;
  if (input.getPosition() != bufferStartStreamPosition) {
    seekPositionHolder.position = bufferStartStreamPosition;
    return Extractor.RESULT_SEEK;
  }

  input.resetPeekPosition();
  input.peekFully(packetBuffer.data, /* offset= */ 0, bytesToRead);
  packetBuffer.setPosition(0);
  packetBuffer.setLimit(bytesToRead);

  lastPcrValue = readLastPcrValueFromBuffer(packetBuffer, pcrPid);
  isLastPcrValueRead = true;
  return Extractor.RESULT_CONTINUE;
}
 
Example #8
Source File: PsDurationReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private int readLastScrValue(ExtractorInput input, PositionHolder seekPositionHolder)
    throws IOException, InterruptedException {
  int bytesToRead = (int) Math.min(DURATION_READ_BYTES, input.getLength());
  long bufferStartStreamPosition = input.getLength() - bytesToRead;
  if (input.getPosition() != bufferStartStreamPosition) {
    seekPositionHolder.position = bufferStartStreamPosition;
    return Extractor.RESULT_SEEK;
  }

  input.resetPeekPosition();
  input.peekFully(packetBuffer.data, /* offset= */ 0, bytesToRead);
  packetBuffer.setPosition(0);
  packetBuffer.setLimit(bytesToRead);

  lastScrValue = readLastScrValueFromBuffer(packetBuffer);
  isLastScrValueRead = true;
  return Extractor.RESULT_CONTINUE;
}
 
Example #9
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 #10
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 #11
Source File: MatroskaExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Updates the position of the holder to Cues element's position if the extractor configuration
 * permits use of master seek entry. After building Cues sets the holder's position back to where
 * it was before.
 *
 * @param seekPosition The holder whose position will be updated.
 * @param currentPosition Current position of the input.
 * @return Whether the seek position was updated.
 */
private boolean maybeSeekForCues(PositionHolder seekPosition, long currentPosition) {
  if (seekForCues) {
    seekPositionAfterBuildingCues = currentPosition;
    seekPosition.position = cuesContentPosition;
    seekForCues = false;
    return true;
  }
  // After parsing Cues, seek back to original position if available. We will not do this unless
  // we seeked to get to the Cues in the first place.
  if (sentSeekMap && seekPositionAfterBuildingCues != C.POSITION_UNSET) {
    seekPosition.position = seekPositionAfterBuildingCues;
    seekPositionAfterBuildingCues = C.POSITION_UNSET;
    return true;
  }
  return false;
}
 
Example #12
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 #13
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 #14
Source File: FlvExtractor.java    From LiveVideoBroadcaster 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_FLV_HEADER:
        if (!readFlvHeader(input)) {
          return RESULT_END_OF_INPUT;
        }
        break;
      case STATE_SKIPPING_TO_TAG_HEADER:
        skipToTagHeader(input);
        break;
      case STATE_READING_TAG_HEADER:
        if (!readTagHeader(input)) {
          return RESULT_END_OF_INPUT;
        }
        break;
      case STATE_READING_TAG_DATA:
        if (readTagData(input)) {
          return RESULT_CONTINUE;
        }
        break;
    }
  }
}
 
Example #15
Source File: MatroskaExtractor.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Updates the position of the holder to Cues element's position if the extractor configuration
 * permits use of master seek entry. After building Cues sets the holder's position back to where
 * it was before.
 *
 * @param seekPosition The holder whose position will be updated.
 * @param currentPosition Current position of the input.
 * @return Whether the seek position was updated.
 */
private boolean maybeSeekForCues(PositionHolder seekPosition, long currentPosition) {
  if (seekForCues) {
    seekPositionAfterBuildingCues = currentPosition;
    seekPosition.position = cuesContentPosition;
    seekForCues = false;
    return true;
  }
  // After parsing Cues, seek back to original position if available. We will not do this unless
  // we seeked to get to the Cues in the first place.
  if (sentSeekMap && seekPositionAfterBuildingCues != C.POSITION_UNSET) {
    seekPosition.position = seekPositionAfterBuildingCues;
    seekPositionAfterBuildingCues = C.POSITION_UNSET;
    return true;
  }
  return false;
}
 
Example #16
Source File: TsDurationReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private int readFirstPcrValue(ExtractorInput input, PositionHolder seekPositionHolder, int pcrPid)
    throws IOException, InterruptedException {
  if (input.getPosition() != 0) {
    seekPositionHolder.position = 0;
    return Extractor.RESULT_SEEK;
  }

  int bytesToRead = (int) Math.min(DURATION_READ_BYTES, input.getLength());
  input.resetPeekPosition();
  input.peekFully(packetBuffer.data, /* offset= */ 0, bytesToRead);
  packetBuffer.setPosition(0);
  packetBuffer.setLimit(bytesToRead);

  firstPcrValue = readFirstPcrValueFromBuffer(packetBuffer, pcrPid);
  isFirstPcrValueRead = true;
  return Extractor.RESULT_CONTINUE;
}
 
Example #17
Source File: TsDurationReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reads a TS duration from the input, using the given PCR PID.
 *
 * <p>This reader reads the duration by reading PCR values of the PCR PID packets at the start and
 * at the end of the stream, calculating the difference, and converting that into stream duration.
 *
 * @param input The {@link ExtractorInput} from which data should be read.
 * @param seekPositionHolder If {@link Extractor#RESULT_SEEK} is returned, this holder is updated
 *     to hold the position of the required seek.
 * @param pcrPid The PID of the packet stream within this TS stream that contains PCR values.
 * @return One of the {@code RESULT_} values defined in {@link Extractor}.
 * @throws IOException If an error occurred reading from the input.
 * @throws InterruptedException If the thread was interrupted.
 */
public @Extractor.ReadResult int readDuration(
    ExtractorInput input, PositionHolder seekPositionHolder, int pcrPid)
    throws IOException, InterruptedException {
  if (pcrPid <= 0) {
    return finishReadDuration(input);
  }
  if (!isLastPcrValueRead) {
    return readLastPcrValue(input, seekPositionHolder, pcrPid);
  }
  if (lastPcrValue == C.TIME_UNSET) {
    return finishReadDuration(input);
  }
  if (!isFirstPcrValueRead) {
    return readFirstPcrValue(input, seekPositionHolder, pcrPid);
  }
  if (firstPcrValue == C.TIME_UNSET) {
    return finishReadDuration(input);
  }

  long minPcrPositionUs = pcrTimestampAdjuster.adjustTsTimestamp(firstPcrValue);
  long maxPcrPositionUs = pcrTimestampAdjuster.adjustTsTimestamp(lastPcrValue);
  durationUs = maxPcrPositionUs - minPcrPositionUs;
  return finishReadDuration(input);
}
 
Example #18
Source File: Ac3Extractor.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 bytesRead = input.read(sampleData.data, 0, MAX_SYNC_FRAME_SIZE);
  if (bytesRead == C.RESULT_END_OF_INPUT) {
    return RESULT_END_OF_INPUT;
  }

  // Feed whatever data we have to the reader, regardless of whether the read finished or not.
  sampleData.setPosition(0);
  sampleData.setLimit(bytesRead);

  if (!startedPacket) {
    // Pass data to the reader as though it's contained within a single infinitely long packet.
    reader.packetStarted(firstSampleTimestampUs, true);
    startedPacket = true;
  }
  // TODO: Make it possible for the reader to consume the dataSource directly, so that it becomes
  // unnecessary to copy the data through packetBuffer.
  reader.consume(sampleData);
  return RESULT_CONTINUE;
}
 
Example #19
Source File: AdtsExtractor.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 bytesRead = input.read(packetBuffer.data, 0, MAX_PACKET_SIZE);
  if (bytesRead == C.RESULT_END_OF_INPUT) {
    return RESULT_END_OF_INPUT;
  }

  // Feed whatever data we have to the reader, regardless of whether the read finished or not.
  packetBuffer.setPosition(0);
  packetBuffer.setLimit(bytesRead);

  if (!startedPacket) {
    // Pass data to the reader as though it's contained within a single infinitely long packet.
    reader.packetStarted(firstSampleTimestampUs, true);
    startedPacket = true;
  }
  // TODO: Make it possible for reader to consume the dataSource directly, so that it becomes
  // unnecessary to copy the data through packetBuffer.
  reader.consume(packetBuffer);
  return RESULT_CONTINUE;
}
 
Example #20
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 #21
Source File: FragmentedMp4Extractor.java    From K-Sonic with MIT License 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 #22
Source File: MatroskaExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Updates the position of the holder to Cues element's position if the extractor configuration
 * permits use of master seek entry. After building Cues sets the holder's position back to where
 * it was before.
 *
 * @param seekPosition The holder whose position will be updated.
 * @param currentPosition Current position of the input.
 * @return Whether the seek position was updated.
 */
private boolean maybeSeekForCues(PositionHolder seekPosition, long currentPosition) {
  if (seekForCues) {
    seekPositionAfterBuildingCues = currentPosition;
    seekPosition.position = cuesContentPosition;
    seekForCues = false;
    return true;
  }
  // After parsing Cues, seek back to original position if available. We will not do this unless
  // we seeked to get to the Cues in the first place.
  if (sentSeekMap && seekPositionAfterBuildingCues != C.POSITION_UNSET) {
    seekPosition.position = seekPositionAfterBuildingCues;
    seekPositionAfterBuildingCues = C.POSITION_UNSET;
    return true;
  }
  return false;
}
 
Example #23
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 #24
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 #25
Source File: Mp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Processes the atom payload. If {@link #atomData} is null and the size is at or above the
 * threshold {@link #RELOAD_MINIMUM_SEEK_DISTANCE}, {@code true} is returned and the caller should
 * restart loading at the position in {@code positionHolder}. Otherwise, the atom is read/skipped.
 */
private boolean readAtomPayload(ExtractorInput input, PositionHolder positionHolder)
    throws IOException, InterruptedException {
  long atomPayloadSize = atomSize - atomHeaderBytesRead;
  long atomEndPosition = input.getPosition() + atomPayloadSize;
  boolean seekRequired = false;
  if (atomData != null) {
    input.readFully(atomData.data, atomHeaderBytesRead, (int) atomPayloadSize);
    if (atomType == Atom.TYPE_ftyp) {
      isQuickTime = processFtypAtom(atomData);
    } else if (!containerAtoms.isEmpty()) {
      containerAtoms.peek().add(new Atom.LeafAtom(atomType, atomData));
    }
  } else {
    // We don't need the data. Skip or seek, depending on how large the atom is.
    if (atomPayloadSize < RELOAD_MINIMUM_SEEK_DISTANCE) {
      input.skipFully((int) atomPayloadSize);
    } else {
      positionHolder.position = input.getPosition() + atomPayloadSize;
      seekRequired = true;
    }
  }
  processAtomEnded(atomEndPosition);
  return seekRequired && parserState != STATE_READING_SAMPLE;
}
 
Example #26
Source File: Mp4Extractor.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 RESULT_END_OF_INPUT;
        }
        break;
      case STATE_READING_ATOM_PAYLOAD:
        if (readAtomPayload(input, seekPosition)) {
          return RESULT_SEEK;
        }
        break;
      case STATE_READING_SAMPLE:
        return readSample(input, seekPosition);
      default:
        throw new IllegalStateException();
    }
  }
}
 
Example #27
Source File: StreamReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @see Extractor#read(ExtractorInput, PositionHolder)
 */
final int read(ExtractorInput input, PositionHolder seekPosition)
    throws IOException, InterruptedException {
  switch (state) {
    case STATE_READ_HEADERS:
      return readHeaders(input);
    case STATE_SKIP_HEADERS:
      input.skipFully((int) payloadStartPosition);
      state = STATE_READ_PAYLOAD;
      return Extractor.RESULT_CONTINUE;
    case STATE_READ_PAYLOAD:
      return readPayload(input, seekPosition);
    default:
      // Never happens.
      throw new IllegalStateException();
  }
}
 
Example #28
Source File: OggExtractor.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 {
  if (streamReader == null) {
    if (!sniffInternal(input)) {
      throw new ParserException("Failed to determine bitstream type");
    }
    input.resetPeekPosition();
  }
  if (!streamReaderInitialized) {
    TrackOutput trackOutput = output.track(0, C.TRACK_TYPE_AUDIO);
    output.endTracks();
    streamReader.init(output, trackOutput);
    streamReaderInitialized = true;
  }
  return streamReader.read(input, seekPosition);
}
 
Example #29
Source File: PsDurationReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private int readLastScrValue(ExtractorInput input, PositionHolder seekPositionHolder)
    throws IOException, InterruptedException {
  int bytesToRead = (int) Math.min(DURATION_READ_BYTES, input.getLength());
  long bufferStartStreamPosition = input.getLength() - bytesToRead;
  if (input.getPosition() != bufferStartStreamPosition) {
    seekPositionHolder.position = bufferStartStreamPosition;
    return Extractor.RESULT_SEEK;
  }

  input.resetPeekPosition();
  input.peekFully(packetBuffer.data, /* offset= */ 0, bytesToRead);
  packetBuffer.setPosition(0);
  packetBuffer.setLimit(bytesToRead);

  lastScrValue = readLastScrValueFromBuffer(packetBuffer);
  isLastScrValueRead = true;
  return Extractor.RESULT_CONTINUE;
}
 
Example #30
Source File: PsDurationReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private int readFirstScrValue(ExtractorInput input, PositionHolder seekPositionHolder)
    throws IOException, InterruptedException {
  if (input.getPosition() != 0) {
    seekPositionHolder.position = 0;
    return Extractor.RESULT_SEEK;
  }

  int bytesToRead = (int) Math.min(DURATION_READ_BYTES, input.getLength());
  input.resetPeekPosition();
  input.peekFully(packetBuffer.data, /* offset= */ 0, bytesToRead);
  packetBuffer.setPosition(0);
  packetBuffer.setLimit(bytesToRead);

  firstScrValue = readFirstScrValueFromBuffer(packetBuffer);
  isFirstScrValueRead = true;
  return Extractor.RESULT_CONTINUE;
}