Search in sources :

Example 11 with AdtsExtractor

use of androidx.media3.extractor.ts.AdtsExtractor in project media by androidx.

the class AdtsExtractorSeekTest method adtsExtractorReads_returnSeekableSeekMap.

@Test
public void adtsExtractorReads_returnSeekableSeekMap() throws IOException {
    String fileName = TEST_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAdtsExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AdtsExtractor extractor = createAdtsExtractor();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, new FakeExtractorOutput(), dataSource, fileUri);
    assertThat(seekMap).isNotNull();
    assertThat(seekMap.getDurationUs()).isEqualTo(FILE_DURATION_US);
    assertThat(seekMap.isSeekable()).isTrue();
}
Also used : SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(androidx.media3.test.utils.FakeExtractorOutput) Test(org.junit.Test)

Example 12 with AdtsExtractor

use of androidx.media3.extractor.ts.AdtsExtractor in project media by androidx.

the class AdtsExtractorSeekTest method seeking_handlesSeekToEoF_extractsLastSample.

@Test
public void seeking_handlesSeekToEoF_extractsLastSample() throws IOException {
    String fileName = TEST_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAdtsExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AdtsExtractor extractor = createAdtsExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long targetSeekTimeUs = seekMap.getDurationUs();
    int extractedSampleIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedSampleIndex).isNotEqualTo(-1);
    assertFirstSampleAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedSampleIndex);
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(androidx.media3.test.utils.FakeExtractorOutput) Test(org.junit.Test)

Example 13 with AdtsExtractor

use of androidx.media3.extractor.ts.AdtsExtractor in project media by androidx.

the class AdtsExtractorSeekTest method seeking_handlesSeekingToPositionInFile_extractsCorrectSample.

@Test
public void seeking_handlesSeekingToPositionInFile_extractsCorrectSample() throws IOException {
    String fileName = TEST_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAdtsExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AdtsExtractor extractor = createAdtsExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long targetSeekTimeUs = 980_000;
    int extractedSampleIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedSampleIndex).isNotEqualTo(-1);
    assertFirstSampleAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedSampleIndex);
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(androidx.media3.test.utils.FakeExtractorOutput) Test(org.junit.Test)

Example 14 with AdtsExtractor

use of androidx.media3.extractor.ts.AdtsExtractor in project media by androidx.

the class BundledHlsMediaChunkExtractor method recreate.

@Override
public HlsMediaChunkExtractor recreate() {
    Assertions.checkState(!isReusable());
    Extractor newExtractorInstance;
    if (extractor instanceof WebvttExtractor) {
        newExtractorInstance = new WebvttExtractor(multivariantPlaylistFormat.language, timestampAdjuster);
    } else if (extractor instanceof AdtsExtractor) {
        newExtractorInstance = new AdtsExtractor();
    } else if (extractor instanceof Ac3Extractor) {
        newExtractorInstance = new Ac3Extractor();
    } else if (extractor instanceof Ac4Extractor) {
        newExtractorInstance = new Ac4Extractor();
    } else if (extractor instanceof Mp3Extractor) {
        newExtractorInstance = new Mp3Extractor();
    } else {
        throw new IllegalStateException("Unexpected extractor type for recreation: " + extractor.getClass().getSimpleName());
    }
    return new BundledHlsMediaChunkExtractor(newExtractorInstance, multivariantPlaylistFormat, timestampAdjuster);
}
Also used : AdtsExtractor(androidx.media3.extractor.ts.AdtsExtractor) Ac4Extractor(androidx.media3.extractor.ts.Ac4Extractor) Mp3Extractor(androidx.media3.extractor.mp3.Mp3Extractor) Ac4Extractor(androidx.media3.extractor.ts.Ac4Extractor) AdtsExtractor(androidx.media3.extractor.ts.AdtsExtractor) Mp3Extractor(androidx.media3.extractor.mp3.Mp3Extractor) Extractor(androidx.media3.extractor.Extractor) Ac3Extractor(androidx.media3.extractor.ts.Ac3Extractor) TsExtractor(androidx.media3.extractor.ts.TsExtractor) FragmentedMp4Extractor(androidx.media3.extractor.mp4.FragmentedMp4Extractor) Ac3Extractor(androidx.media3.extractor.ts.Ac3Extractor)

Example 15 with AdtsExtractor

use of androidx.media3.extractor.ts.AdtsExtractor in project hms-wiseplay-demo-exoplayer by HMS-Core.

the class DefaultHlsExtractorFactory method createExtractor.

@Override
public Result createExtractor(@Nullable Extractor previousExtractor, Uri uri, Format format, @Nullable List<Format> muxedCaptionFormats, DrmInitData drmInitData, TimestampAdjuster timestampAdjuster, Map<String, List<String>> responseHeaders, ExtractorInput extractorInput) throws InterruptedException, IOException {
    if (previousExtractor != null) {
        // A extractor has already been successfully used. Return one of the same type.
        if (isReusable(previousExtractor)) {
            return buildResult(previousExtractor);
        } else {
            Result result = buildResultForSameExtractorType(previousExtractor, format, timestampAdjuster);
            if (result == null) {
                throw new IllegalArgumentException("Unexpected previousExtractor type: " + previousExtractor.getClass().getSimpleName());
            }
        }
    }
    // Try selecting the extractor by the file extension.
    Extractor extractorByFileExtension = createExtractorByFileExtension(uri, format, muxedCaptionFormats, drmInitData, timestampAdjuster);
    extractorInput.resetPeekPosition();
    if (sniffQuietly(extractorByFileExtension, extractorInput)) {
        return buildResult(extractorByFileExtension);
    }
    if (!(extractorByFileExtension instanceof WebvttExtractor)) {
        WebvttExtractor webvttExtractor = new WebvttExtractor(format.language, timestampAdjuster);
        if (sniffQuietly(webvttExtractor, extractorInput)) {
            return buildResult(webvttExtractor);
        }
    }
    if (!(extractorByFileExtension instanceof AdtsExtractor)) {
        AdtsExtractor adtsExtractor = new AdtsExtractor();
        if (sniffQuietly(adtsExtractor, extractorInput)) {
            return buildResult(adtsExtractor);
        }
    }
    if (!(extractorByFileExtension instanceof Ac3Extractor)) {
        Ac3Extractor ac3Extractor = new Ac3Extractor();
        if (sniffQuietly(ac3Extractor, extractorInput)) {
            return buildResult(ac3Extractor);
        }
    }
    if (!(extractorByFileExtension instanceof Ac4Extractor)) {
        Ac4Extractor ac4Extractor = new Ac4Extractor();
        if (sniffQuietly(ac4Extractor, extractorInput)) {
            return buildResult(ac4Extractor);
        }
    }
    if (!(extractorByFileExtension instanceof Mp3Extractor)) {
        Mp3Extractor mp3Extractor = new Mp3Extractor(/* flags= */
        0, /* forcedFirstSampleTimestampUs= */
        0);
        if (sniffQuietly(mp3Extractor, extractorInput)) {
            return buildResult(mp3Extractor);
        }
    }
    if (!(extractorByFileExtension instanceof FragmentedMp4Extractor)) {
        FragmentedMp4Extractor fragmentedMp4Extractor = createFragmentedMp4Extractor(timestampAdjuster, format, muxedCaptionFormats);
        if (sniffQuietly(fragmentedMp4Extractor, extractorInput)) {
            return buildResult(fragmentedMp4Extractor);
        }
    }
    if (!(extractorByFileExtension instanceof TsExtractor)) {
        TsExtractor tsExtractor = createTsExtractor(payloadReaderFactoryFlags, exposeCea608WhenMissingDeclarations, format, muxedCaptionFormats, timestampAdjuster, drmInitData);
        if (sniffQuietly(tsExtractor, extractorInput)) {
            return buildResult(tsExtractor);
        }
    }
    // Fall back on the extractor created by file extension.
    return buildResult(extractorByFileExtension);
}
Also used : FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) Ac4Extractor(com.google.android.exoplayer2.extractor.ts.Ac4Extractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor) FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) Extractor(com.google.android.exoplayer2.extractor.Extractor) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor) Ac4Extractor(com.google.android.exoplayer2.extractor.ts.Ac4Extractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor)

Aggregations

Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)7 FragmentedMp4Extractor (com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor)7 Ac3Extractor (com.google.android.exoplayer2.extractor.ts.Ac3Extractor)7 AdtsExtractor (com.google.android.exoplayer2.extractor.ts.AdtsExtractor)7 TsExtractor (com.google.android.exoplayer2.extractor.ts.TsExtractor)7 Uri (android.net.Uri)6 SeekMap (androidx.media3.extractor.SeekMap)6 FakeExtractorOutput (androidx.media3.test.utils.FakeExtractorOutput)6 Ac4Extractor (com.google.android.exoplayer2.extractor.ts.Ac4Extractor)6 Test (org.junit.Test)6 FakeTrackOutput (androidx.media3.test.utils.FakeTrackOutput)5 Extractor (com.google.android.exoplayer2.extractor.Extractor)4 AmrExtractor (com.google.android.exoplayer2.extractor.amr.AmrExtractor)3 FlacExtractor (com.google.android.exoplayer2.extractor.flac.FlacExtractor)3 FlvExtractor (com.google.android.exoplayer2.extractor.flv.FlvExtractor)3 MatroskaExtractor (com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor)3 Mp4Extractor (com.google.android.exoplayer2.extractor.mp4.Mp4Extractor)3 OggExtractor (com.google.android.exoplayer2.extractor.ogg.OggExtractor)3 PsExtractor (com.google.android.exoplayer2.extractor.ts.PsExtractor)3 WavExtractor (com.google.android.exoplayer2.extractor.wav.WavExtractor)3