Search in sources :

Example 11 with TsExtractor

use of androidx.media3.extractor.ts.TsExtractor in project ExoPlayer by google.

the class DefaultHlsExtractorFactory method createTsExtractor.

private static TsExtractor createTsExtractor(@DefaultTsPayloadReaderFactory.Flags int userProvidedPayloadReaderFactoryFlags, boolean exposeCea608WhenMissingDeclarations, Format format, @Nullable List<Format> muxedCaptionFormats, TimestampAdjuster timestampAdjuster) {
    @DefaultTsPayloadReaderFactory.Flags int payloadReaderFactoryFlags = DefaultTsPayloadReaderFactory.FLAG_IGNORE_SPLICE_INFO_STREAM | userProvidedPayloadReaderFactoryFlags;
    if (muxedCaptionFormats != null) {
        // The playlist declares closed caption renditions, we should ignore descriptors.
        payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_OVERRIDE_CAPTION_DESCRIPTORS;
    } else if (exposeCea608WhenMissingDeclarations) {
        // The playlist does not provide any closed caption information. We preemptively declare a
        // closed caption track on channel 0.
        muxedCaptionFormats = Collections.singletonList(new Format.Builder().setSampleMimeType(MimeTypes.APPLICATION_CEA608).build());
    } else {
        muxedCaptionFormats = Collections.emptyList();
    }
    @Nullable String codecs = format.codecs;
    if (!TextUtils.isEmpty(codecs)) {
        // explicitly ignore them even if they're declared.
        if (!MimeTypes.containsCodecsCorrespondingToMimeType(codecs, MimeTypes.AUDIO_AAC)) {
            payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_AAC_STREAM;
        }
        if (!MimeTypes.containsCodecsCorrespondingToMimeType(codecs, MimeTypes.VIDEO_H264)) {
            payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_H264_STREAM;
        }
    }
    return new TsExtractor(TsExtractor.MODE_HLS, timestampAdjuster, new DefaultTsPayloadReaderFactory(payloadReaderFactoryFlags, muxedCaptionFormats));
}
Also used : Format(com.google.android.exoplayer2.Format) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) SuppressLint(android.annotation.SuppressLint) Nullable(androidx.annotation.Nullable) DefaultTsPayloadReaderFactory(com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory)

Example 12 with TsExtractor

use of androidx.media3.extractor.ts.TsExtractor in project ExoPlayer by google.

the class HlsMediaChunk method createExtractor.

private Extractor createExtractor() {
    // Select the extractor that will read the chunk.
    Extractor extractor;
    boolean usingNewExtractor = true;
    if (MimeTypes.TEXT_VTT.equals(hlsUrl.format.sampleMimeType) || lastPathSegment.endsWith(WEBVTT_FILE_EXTENSION) || lastPathSegment.endsWith(VTT_FILE_EXTENSION)) {
        extractor = new WebvttExtractor(trackFormat.language, timestampAdjuster);
    } else if (!needNewExtractor) {
        // Only reuse TS and fMP4 extractors.
        usingNewExtractor = false;
        extractor = previousExtractor;
    } else if (lastPathSegment.endsWith(MP4_FILE_EXTENSION) || lastPathSegment.startsWith(M4_FILE_EXTENSION_PREFIX, lastPathSegment.length() - 4)) {
        extractor = new FragmentedMp4Extractor(0, timestampAdjuster);
    } else {
        // MPEG-2 TS segments, but we need a new extractor.
        // This flag ensures the change of pid between streams does not affect the sample queues.
        @DefaultTsPayloadReaderFactory.Flags int esReaderFactoryFlags = DefaultTsPayloadReaderFactory.FLAG_IGNORE_SPLICE_INFO_STREAM;
        if (!muxedCaptionFormats.isEmpty()) {
            // The playlist declares closed caption renditions, we should ignore descriptors.
            esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_OVERRIDE_CAPTION_DESCRIPTORS;
        }
        String codecs = trackFormat.codecs;
        if (!TextUtils.isEmpty(codecs)) {
            // explicitly ignore them even if they're declared.
            if (!MimeTypes.AUDIO_AAC.equals(MimeTypes.getAudioMediaMimeType(codecs))) {
                esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_AAC_STREAM;
            }
            if (!MimeTypes.VIDEO_H264.equals(MimeTypes.getVideoMediaMimeType(codecs))) {
                esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_H264_STREAM;
            }
        }
        extractor = new TsExtractor(TsExtractor.MODE_HLS, timestampAdjuster, new DefaultTsPayloadReaderFactory(esReaderFactoryFlags, muxedCaptionFormats));
    }
    if (usingNewExtractor) {
        extractor.init(extractorOutput);
    }
    return extractor;
}
Also used : FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) Extractor(com.google.android.exoplayer2.extractor.Extractor) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) DefaultTsPayloadReaderFactory(com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory)

Example 13 with TsExtractor

use of androidx.media3.extractor.ts.TsExtractor in project Telegram-FOSS by Telegram-FOSS-Team.

the class DefaultExtractorsFactory method createExtractors.

@Override
public synchronized Extractor[] createExtractors() {
    Extractor[] extractors = new Extractor[14];
    extractors[0] = new MatroskaExtractor(matroskaFlags);
    extractors[1] = new FragmentedMp4Extractor(fragmentedMp4Flags);
    extractors[2] = new Mp4Extractor(mp4Flags);
    extractors[3] = new OggExtractor();
    extractors[4] = new Mp3Extractor(mp3Flags | (constantBitrateSeekingEnabled ? Mp3Extractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING : 0));
    extractors[5] = new AdtsExtractor(adtsFlags | (constantBitrateSeekingEnabled ? AdtsExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING : 0));
    extractors[6] = new Ac3Extractor();
    extractors[7] = new TsExtractor(tsMode, tsFlags);
    extractors[8] = new FlvExtractor();
    extractors[9] = new PsExtractor();
    extractors[10] = new WavExtractor();
    extractors[11] = new AmrExtractor(amrFlags | (constantBitrateSeekingEnabled ? AmrExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING : 0));
    extractors[12] = new Ac4Extractor();
    if (FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR != null) {
        try {
            extractors[13] = FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR.newInstance();
        } catch (Exception e) {
            // Should never happen.
            throw new IllegalStateException("Unexpected error creating FLAC extractor", e);
        }
    } else {
        extractors[13] = new FlacExtractor();
    }
    return extractors;
}
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) MatroskaExtractor(com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) FlacExtractor(com.google.android.exoplayer2.extractor.flac.FlacExtractor) AmrExtractor(com.google.android.exoplayer2.extractor.amr.AmrExtractor) FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) Mp4Extractor(com.google.android.exoplayer2.extractor.mp4.Mp4Extractor) PsExtractor(com.google.android.exoplayer2.extractor.ts.PsExtractor) OggExtractor(com.google.android.exoplayer2.extractor.ogg.OggExtractor) WavExtractor(com.google.android.exoplayer2.extractor.wav.WavExtractor) FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) PsExtractor(com.google.android.exoplayer2.extractor.ts.PsExtractor) FlvExtractor(com.google.android.exoplayer2.extractor.flv.FlvExtractor) OggExtractor(com.google.android.exoplayer2.extractor.ogg.OggExtractor) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) Mp4Extractor(com.google.android.exoplayer2.extractor.mp4.Mp4Extractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor) Ac4Extractor(com.google.android.exoplayer2.extractor.ts.Ac4Extractor) WavExtractor(com.google.android.exoplayer2.extractor.wav.WavExtractor) AmrExtractor(com.google.android.exoplayer2.extractor.amr.AmrExtractor) MatroskaExtractor(com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) FlacExtractor(com.google.android.exoplayer2.extractor.flac.FlacExtractor) FlvExtractor(com.google.android.exoplayer2.extractor.flv.FlvExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor)

Example 14 with TsExtractor

use of androidx.media3.extractor.ts.TsExtractor in project Telegram-FOSS by Telegram-FOSS-Team.

the class DefaultHlsExtractorFactory method createExtractor.

@Override
public Result createExtractor(@Nullable Extractor previousExtractor, Uri uri, Format format, @Nullable List<Format> muxedCaptionFormats, 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, 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);
        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)

Example 15 with TsExtractor

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

the class TsExtractorSeekTest method readInputFileOnce.

// Internal methods
private void readInputFileOnce(TsExtractor extractor, FakeExtractorOutput extractorOutput, Uri fileUri) throws IOException {
    extractor.init(extractorOutput);
    int readResult = Extractor.RESULT_CONTINUE;
    ExtractorInput input = TestUtil.getExtractorInputFromPosition(dataSource, 0, fileUri);
    while (readResult != Extractor.RESULT_END_OF_INPUT) {
        try {
            while (readResult == Extractor.RESULT_CONTINUE) {
                readResult = extractor.read(input, positionHolder);
            }
        } finally {
            DataSourceUtil.closeQuietly(dataSource);
        }
        if (readResult == Extractor.RESULT_SEEK) {
            input = TestUtil.getExtractorInputFromPosition(dataSource, positionHolder.position, fileUri);
            readResult = Extractor.RESULT_CONTINUE;
        }
    }
}
Also used : ExtractorInput(androidx.media3.extractor.ExtractorInput)

Aggregations

FakeExtractorOutput (androidx.media3.test.utils.FakeExtractorOutput)9 TsExtractor (com.google.android.exoplayer2.extractor.ts.TsExtractor)9 Test (org.junit.Test)9 Uri (android.net.Uri)7 SeekMap (androidx.media3.extractor.SeekMap)7 FakeTrackOutput (androidx.media3.test.utils.FakeTrackOutput)7 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)6 FragmentedMp4Extractor (com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor)6 Ac3Extractor (com.google.android.exoplayer2.extractor.ts.Ac3Extractor)6 AdtsExtractor (com.google.android.exoplayer2.extractor.ts.AdtsExtractor)6 Ac4Extractor (com.google.android.exoplayer2.extractor.ts.Ac4Extractor)5 Nullable (androidx.annotation.Nullable)4 DefaultTsPayloadReaderFactory (com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory)4 PositionHolder (androidx.media3.extractor.PositionHolder)3 Extractor (com.google.android.exoplayer2.extractor.Extractor)3 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