Search in sources :

Example 76 with ExtractorOutput

use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.

the class AmrExtractorSeekTest method seeking_handlesSeekingForward_extractsCorrectFrames_forNarrowBandAmr.

@Test
public void seeking_handlesSeekingForward_extractsCorrectFrames_forNarrowBandAmr() throws IOException {
    String fileName = NARROW_BAND_AMR_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAmrExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AmrExtractor extractor = createAmrExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long firstSeekTimeUs = 980_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 1_200_000;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(-1);
    assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 77 with ExtractorOutput

use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.

the class FlvExtractor method readTagData.

/**
 * Reads the body of a tag from the provided {@link ExtractorInput}.
 *
 * @param input The {@link ExtractorInput} from which to read.
 * @return True if the data was consumed by a reader. False if it was skipped.
 * @throws IOException If an error occurred reading or parsing data from the source.
 */
@RequiresNonNull("extractorOutput")
private boolean readTagData(ExtractorInput input) throws IOException {
    boolean wasConsumed = true;
    boolean wasSampleOutput = false;
    long timestampUs = getCurrentTimestampUs();
    if (tagType == TAG_TYPE_AUDIO && audioReader != null) {
        ensureReadyForMediaOutput();
        wasSampleOutput = audioReader.consume(prepareTagData(input), timestampUs);
    } else if (tagType == TAG_TYPE_VIDEO && videoReader != null) {
        ensureReadyForMediaOutput();
        wasSampleOutput = videoReader.consume(prepareTagData(input), timestampUs);
    } else if (tagType == TAG_TYPE_SCRIPT_DATA && !outputSeekMap) {
        wasSampleOutput = metadataReader.consume(prepareTagData(input), timestampUs);
        long durationUs = metadataReader.getDurationUs();
        if (durationUs != C.TIME_UNSET) {
            extractorOutput.seekMap(new IndexSeekMap(metadataReader.getKeyFrameTagPositions(), metadataReader.getKeyFrameTimesUs(), durationUs));
            outputSeekMap = true;
        }
    } else {
        input.skipFully(tagDataSize);
        wasConsumed = false;
    }
    if (!outputFirstSample && wasSampleOutput) {
        outputFirstSample = true;
        mediaTagTimestampOffsetUs = metadataReader.getDurationUs() == C.TIME_UNSET ? -tagTimestampUs : 0;
    }
    // There's a 4 byte previous tag size before the next header.
    bytesToNextTagHeader = 4;
    state = STATE_SKIPPING_TO_TAG_HEADER;
    return wasConsumed;
}
Also used : IndexSeekMap(com.google.android.exoplayer2.extractor.IndexSeekMap) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 78 with ExtractorOutput

use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.

the class JpegExtractor method sniffMotionPhotoVideo.

private void sniffMotionPhotoVideo(ExtractorInput input) throws IOException {
    // Check if the file is truncated.
    boolean peekedData = input.peekFully(scratch.getData(), /* offset= */
    0, /* length= */
    1, /* allowEndOfInput= */
    true);
    if (!peekedData) {
        endReadingWithImageTrack();
    } else {
        input.resetPeekPosition();
        if (mp4Extractor == null) {
            mp4Extractor = new Mp4Extractor();
        }
        mp4ExtractorStartOffsetExtractorInput = new StartOffsetExtractorInput(input, mp4StartPosition);
        if (mp4Extractor.sniff(mp4ExtractorStartOffsetExtractorInput)) {
            mp4Extractor.init(new StartOffsetExtractorOutput(mp4StartPosition, checkNotNull(extractorOutput)));
            startReadingMotionPhoto();
        } else {
            endReadingWithImageTrack();
        }
    }
}
Also used : Mp4Extractor(com.google.android.exoplayer2.extractor.mp4.Mp4Extractor)

Example 79 with ExtractorOutput

use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.

the class JpegExtractor method outputImageTrack.

private void outputImageTrack(Metadata.Entry... metadataEntries) {
    TrackOutput imageTrackOutput = checkNotNull(extractorOutput).track(IMAGE_TRACK_ID, C.TRACK_TYPE_IMAGE);
    imageTrackOutput.format(new Format.Builder().setContainerMimeType(MimeTypes.IMAGE_JPEG).setMetadata(new Metadata(metadataEntries)).build());
}
Also used : MotionPhotoMetadata(com.google.android.exoplayer2.metadata.mp4.MotionPhotoMetadata) Metadata(com.google.android.exoplayer2.metadata.Metadata) TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput)

Example 80 with ExtractorOutput

use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.

the class TsExtractorSeekTest method handlePendingSeek_handlesSeekingForward_extractsCorrectFrame.

@Test
public void handlePendingSeek_handlesSeekingForward_extractsCorrectFrame() throws IOException {
    TsExtractor extractor = new TsExtractor();
    Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(AUDIO_TRACK_ID);
    long firstSeekTimeUs = 987_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 1_234_000;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(-1);
    assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Aggregations

SeekMap (com.google.android.exoplayer2.extractor.SeekMap)79 Test (org.junit.Test)66 Uri (android.net.Uri)59 FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)57 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)31 Nullable (androidx.annotation.Nullable)12 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)9 Format (com.google.android.exoplayer2.Format)6 TrackIdGenerator (com.google.android.exoplayer2.extractor.ts.TsPayloadReader.TrackIdGenerator)6 Metadata (com.google.android.exoplayer2.metadata.Metadata)6 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)5 Extractor (com.google.android.exoplayer2.extractor.Extractor)4 OutputFrameHolder (com.google.android.exoplayer2.ext.flac.FlacBinarySearchSeeker.OutputFrameHolder)3 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)3 ExtractorOutput (com.google.android.exoplayer2.extractor.ExtractorOutput)3 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)3 Before (org.junit.Before)3 CallSuper (androidx.annotation.CallSuper)2 Format (androidx.media3.common.Format)2 Metadata (androidx.media3.common.Metadata)2