com.google.android.exoplayer2.extractor.Extractor Java Examples
The following examples show how to use
com.google.android.exoplayer2.extractor.Extractor.
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: MatroskaExtractor.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@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 #2
Source File: FragmentedMp4Extractor.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@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 #3
Source File: MatroskaExtractor.java From MediaSDK with Apache License 2.0 | 6 votes |
@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 #4
Source File: FragmentedMp4Extractor.java From MediaSDK with Apache License 2.0 | 6 votes |
@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 #5
Source File: WebvttExtractor.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@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 #6
Source File: InitializationChunk.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("NonAtomicVolatileUpdate") @Override public void load() throws IOException, InterruptedException { DataSpec loadDataSpec = dataSpec.subrange(nextLoadPosition); try { // Create and open the input. ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec)); if (nextLoadPosition == 0) { extractorWrapper.init(/* trackOutputProvider= */ null, C.TIME_UNSET); } // Load and decode the initialization data. try { Extractor extractor = extractorWrapper.extractor; int result = Extractor.RESULT_CONTINUE; while (result == Extractor.RESULT_CONTINUE && !loadCanceled) { result = extractor.read(input, DUMMY_POSITION_HOLDER); } Assertions.checkState(result != Extractor.RESULT_SEEK); } finally { nextLoadPosition = input.getPosition() - dataSpec.absoluteStreamPosition; } } finally { Util.closeQuietly(dataSource); } }
Example #7
Source File: HlsMediaChunk.java From K-Sonic with MIT License | 6 votes |
private void maybeLoadInitData() throws IOException, InterruptedException { if (previousExtractor == extractor || initLoadCompleted || initDataSpec == null) { // According to spec, for packed audio, initDataSpec is expected to be null. return; } DataSpec initSegmentDataSpec = Util.getRemainderDataSpec(initDataSpec, initSegmentBytesLoaded); try { ExtractorInput input = new DefaultExtractorInput(initDataSource, initSegmentDataSpec.absoluteStreamPosition, initDataSource.open(initSegmentDataSpec)); try { int result = Extractor.RESULT_CONTINUE; while (result == Extractor.RESULT_CONTINUE && !loadCanceled) { result = extractor.read(input, null); } } finally { initSegmentBytesLoaded = (int) (input.getPosition() - initDataSpec.absoluteStreamPosition); } } finally { Util.closeQuietly(dataSource); } initLoadCompleted = true; }
Example #8
Source File: TsDurationReader.java From Telegram with GNU General Public License v2.0 | 6 votes |
private int readLastPcrValue(ExtractorInput input, PositionHolder seekPositionHolder, int pcrPid) throws IOException, InterruptedException { long inputLength = input.getLength(); int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, inputLength); long searchStartPosition = inputLength - bytesToSearch; if (input.getPosition() != searchStartPosition) { seekPositionHolder.position = searchStartPosition; return Extractor.RESULT_SEEK; } packetBuffer.reset(bytesToSearch); input.resetPeekPosition(); input.peekFully(packetBuffer.data, /* offset= */ 0, bytesToSearch); lastPcrValue = readLastPcrValueFromBuffer(packetBuffer, pcrPid); isLastPcrValueRead = true; return Extractor.RESULT_CONTINUE; }
Example #9
Source File: FragmentedMp4Extractor.java From K-Sonic with MIT License | 6 votes |
@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: TsDurationReader.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private int readLastPcrValue(ExtractorInput input, PositionHolder seekPositionHolder, int pcrPid) throws IOException, InterruptedException { long inputLength = input.getLength(); int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, inputLength); long searchStartPosition = inputLength - bytesToSearch; if (input.getPosition() != searchStartPosition) { seekPositionHolder.position = searchStartPosition; return Extractor.RESULT_SEEK; } packetBuffer.reset(bytesToSearch); input.resetPeekPosition(); input.peekFully(packetBuffer.data, /* offset= */ 0, bytesToSearch); lastPcrValue = readLastPcrValueFromBuffer(packetBuffer, pcrPid); isLastPcrValueRead = true; return Extractor.RESULT_CONTINUE; }
Example #11
Source File: TsDurationReader.java From MediaSDK with Apache License 2.0 | 6 votes |
private int readLastPcrValue(ExtractorInput input, PositionHolder seekPositionHolder, int pcrPid) throws IOException, InterruptedException { long inputLength = input.getLength(); int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, inputLength); long searchStartPosition = inputLength - bytesToSearch; if (input.getPosition() != searchStartPosition) { seekPositionHolder.position = searchStartPosition; return Extractor.RESULT_SEEK; } packetBuffer.reset(bytesToSearch); input.resetPeekPosition(); input.peekFully(packetBuffer.data, /* offset= */ 0, bytesToSearch); lastPcrValue = readLastPcrValueFromBuffer(packetBuffer, pcrPid); isLastPcrValueRead = true; return Extractor.RESULT_CONTINUE; }
Example #12
Source File: TsDurationReader.java From MediaSDK with Apache License 2.0 | 6 votes |
private int readFirstPcrValue(ExtractorInput input, PositionHolder seekPositionHolder, int pcrPid) throws IOException, InterruptedException { int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, input.getLength()); int searchStartPosition = 0; if (input.getPosition() != searchStartPosition) { seekPositionHolder.position = searchStartPosition; return Extractor.RESULT_SEEK; } packetBuffer.reset(bytesToSearch); input.resetPeekPosition(); input.peekFully(packetBuffer.data, /* offset= */ 0, bytesToSearch); firstPcrValue = readFirstPcrValueFromBuffer(packetBuffer, pcrPid); isFirstPcrValueRead = true; return Extractor.RESULT_CONTINUE; }
Example #13
Source File: PsDurationReader.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private int readFirstScrValue(ExtractorInput input, PositionHolder seekPositionHolder) throws IOException, InterruptedException { int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, input.getLength()); int searchStartPosition = 0; if (input.getPosition() != searchStartPosition) { seekPositionHolder.position = searchStartPosition; return Extractor.RESULT_SEEK; } packetBuffer.reset(bytesToSearch); input.resetPeekPosition(); input.peekFully(packetBuffer.data, /* offset= */ 0, bytesToSearch); firstScrValue = readFirstScrValueFromBuffer(packetBuffer); isFirstScrValueRead = true; return Extractor.RESULT_CONTINUE; }
Example #14
Source File: StreamReader.java From K-Sonic with MIT License | 6 votes |
/** * @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 #15
Source File: TsDurationReader.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private int readFirstPcrValue(ExtractorInput input, PositionHolder seekPositionHolder, int pcrPid) throws IOException, InterruptedException { int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, input.getLength()); int searchStartPosition = 0; if (input.getPosition() != searchStartPosition) { seekPositionHolder.position = searchStartPosition; return Extractor.RESULT_SEEK; } packetBuffer.reset(bytesToSearch); input.resetPeekPosition(); input.peekFully(packetBuffer.data, /* offset= */ 0, bytesToSearch); firstPcrValue = readFirstPcrValueFromBuffer(packetBuffer, pcrPid); isFirstPcrValueRead = true; return Extractor.RESULT_CONTINUE; }
Example #16
Source File: PsDurationReader.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
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 #17
Source File: PsDurationReader.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * 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 #18
Source File: TsDurationReader.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
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 #19
Source File: TsDurationReader.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
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 #20
Source File: TsDurationReader.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * 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 #21
Source File: InitializationChunk.java From K-Sonic with MIT License | 6 votes |
@SuppressWarnings("NonAtomicVolatileUpdate") @Override public void load() throws IOException, InterruptedException { DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded); try { // Create and open the input. ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec)); if (bytesLoaded == 0) { extractorWrapper.init(null); } // Load and decode the initialization data. try { Extractor extractor = extractorWrapper.extractor; int result = Extractor.RESULT_CONTINUE; while (result == Extractor.RESULT_CONTINUE && !loadCanceled) { result = extractor.read(input, null); } Assertions.checkState(result != Extractor.RESULT_SEEK); } finally { bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition); } } finally { Util.closeQuietly(dataSource); } }
Example #22
Source File: TsDurationReader.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * 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 #23
Source File: TsDurationReader.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * 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 #24
Source File: PsDurationReader.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private int readLastScrValue(ExtractorInput input, PositionHolder seekPositionHolder) throws IOException, InterruptedException { long inputLength = input.getLength(); int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, inputLength); long searchStartPosition = inputLength - bytesToSearch; if (input.getPosition() != searchStartPosition) { seekPositionHolder.position = searchStartPosition; return Extractor.RESULT_SEEK; } packetBuffer.reset(bytesToSearch); input.resetPeekPosition(); input.peekFully(packetBuffer.data, /* offset= */ 0, bytesToSearch); lastScrValue = readLastScrValueFromBuffer(packetBuffer); isLastScrValueRead = true; return Extractor.RESULT_CONTINUE; }
Example #25
Source File: HlsMediaChunk.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private void maybeLoadInitData() throws IOException, InterruptedException { if (initLoadCompleted || initDataSpec == null) { // Note: The HLS spec forbids initialization segments for packed audio. return; } DataSpec initSegmentDataSpec = initDataSpec.subrange(initSegmentBytesLoaded); try { DefaultExtractorInput input = prepareExtraction(initDataSource, initSegmentDataSpec); try { int result = Extractor.RESULT_CONTINUE; while (result == Extractor.RESULT_CONTINUE && !loadCanceled) { result = extractor.read(input, null); } } finally { initSegmentBytesLoaded = (int) (input.getPosition() - initDataSpec.absoluteStreamPosition); } } finally { Util.closeQuietly(initDataSource); } initLoadCompleted = true; }
Example #26
Source File: PsDurationReader.java From Telegram with GNU General Public License v2.0 | 6 votes |
private int readLastScrValue(ExtractorInput input, PositionHolder seekPositionHolder) throws IOException, InterruptedException { long inputLength = input.getLength(); int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, inputLength); long searchStartPosition = inputLength - bytesToSearch; if (input.getPosition() != searchStartPosition) { seekPositionHolder.position = searchStartPosition; return Extractor.RESULT_SEEK; } packetBuffer.reset(bytesToSearch); input.resetPeekPosition(); input.peekFully(packetBuffer.data, /* offset= */ 0, bytesToSearch); lastScrValue = readLastScrValueFromBuffer(packetBuffer); isLastScrValueRead = true; return Extractor.RESULT_CONTINUE; }
Example #27
Source File: PsDurationReader.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * 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 #28
Source File: FragmentedMp4Extractor.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@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 #29
Source File: PsDurationReader.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
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; }
Example #30
Source File: StreamReader.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * @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(); } }