Search in sources :

Example 1 with TsExtractor

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

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(Format.createTextSampleFormat(/* id= */
        null, MimeTypes.APPLICATION_CEA608, /* selectionFlags= */
        0, /* language= */
        null));
    } else {
        muxedCaptionFormats = Collections.emptyList();
    }
    String codecs = format.codecs;
    if (!TextUtils.isEmpty(codecs)) {
        // explicitly ignore them even if they're declared.
        if (!MimeTypes.AUDIO_AAC.equals(MimeTypes.getAudioMediaMimeType(codecs))) {
            payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_AAC_STREAM;
        }
        if (!MimeTypes.VIDEO_H264.equals(MimeTypes.getVideoMediaMimeType(codecs))) {
            payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_H264_STREAM;
        }
    }
    return new TsExtractor(TsExtractor.MODE_HLS, timestampAdjuster, new DefaultTsPayloadReaderFactory(payloadReaderFactoryFlags, muxedCaptionFormats));
}
Also used : TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) DefaultTsPayloadReaderFactory(com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory)

Example 2 with TsExtractor

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

the class DefaultExtractorsFactory method addExtractorsForFileType.

private void addExtractorsForFileType(@FileTypes.Type int fileType, List<Extractor> extractors) {
    switch(fileType) {
        case FileTypes.AC3:
            extractors.add(new Ac3Extractor());
            break;
        case FileTypes.AC4:
            extractors.add(new Ac4Extractor());
            break;
        case FileTypes.ADTS:
            extractors.add(new AdtsExtractor(adtsFlags | (constantBitrateSeekingEnabled ? AdtsExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING : 0) | (constantBitrateSeekingAlwaysEnabled ? AdtsExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING_ALWAYS : 0)));
            break;
        case FileTypes.AMR:
            extractors.add(new AmrExtractor(amrFlags | (constantBitrateSeekingEnabled ? AmrExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING : 0) | (constantBitrateSeekingAlwaysEnabled ? AmrExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING_ALWAYS : 0)));
            break;
        case FileTypes.FLAC:
            @Nullable Extractor flacExtractor = FLAC_EXTENSION_LOADER.getExtractor(flacFlags);
            if (flacExtractor != null) {
                extractors.add(flacExtractor);
            } else {
                extractors.add(new FlacExtractor(flacFlags));
            }
            break;
        case FileTypes.FLV:
            extractors.add(new FlvExtractor());
            break;
        case FileTypes.MATROSKA:
            extractors.add(new MatroskaExtractor(matroskaFlags));
            break;
        case FileTypes.MP3:
            extractors.add(new Mp3Extractor(mp3Flags | (constantBitrateSeekingEnabled ? Mp3Extractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING : 0) | (constantBitrateSeekingAlwaysEnabled ? Mp3Extractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING_ALWAYS : 0)));
            break;
        case FileTypes.MP4:
            extractors.add(new FragmentedMp4Extractor(fragmentedMp4Flags));
            extractors.add(new Mp4Extractor(mp4Flags));
            break;
        case FileTypes.OGG:
            extractors.add(new OggExtractor());
            break;
        case FileTypes.PS:
            extractors.add(new PsExtractor());
            break;
        case FileTypes.TS:
            extractors.add(new TsExtractor(tsMode, tsFlags, tsTimestampSearchBytes));
            break;
        case FileTypes.WAV:
            extractors.add(new WavExtractor());
            break;
        case FileTypes.JPEG:
            extractors.add(new JpegExtractor());
            break;
        case FileTypes.WEBVTT:
        case FileTypes.UNKNOWN:
        default:
            break;
    }
}
Also used : FragmentedMp4Extractor(androidx.media3.extractor.mp4.FragmentedMp4Extractor) JpegExtractor(androidx.media3.extractor.jpeg.JpegExtractor) Ac4Extractor(androidx.media3.extractor.ts.Ac4Extractor) AdtsExtractor(androidx.media3.extractor.ts.AdtsExtractor) Mp3Extractor(androidx.media3.extractor.mp3.Mp3Extractor) MatroskaExtractor(androidx.media3.extractor.mkv.MatroskaExtractor) TsExtractor(androidx.media3.extractor.ts.TsExtractor) FlacExtractor(androidx.media3.extractor.flac.FlacExtractor) AmrExtractor(androidx.media3.extractor.amr.AmrExtractor) Mp4Extractor(androidx.media3.extractor.mp4.Mp4Extractor) FragmentedMp4Extractor(androidx.media3.extractor.mp4.FragmentedMp4Extractor) PsExtractor(androidx.media3.extractor.ts.PsExtractor) OggExtractor(androidx.media3.extractor.ogg.OggExtractor) WavExtractor(androidx.media3.extractor.wav.WavExtractor) WavExtractor(androidx.media3.extractor.wav.WavExtractor) Ac4Extractor(androidx.media3.extractor.ts.Ac4Extractor) TsExtractor(androidx.media3.extractor.ts.TsExtractor) AmrExtractor(androidx.media3.extractor.amr.AmrExtractor) FlacExtractor(androidx.media3.extractor.flac.FlacExtractor) AdtsExtractor(androidx.media3.extractor.ts.AdtsExtractor) PsExtractor(androidx.media3.extractor.ts.PsExtractor) Mp3Extractor(androidx.media3.extractor.mp3.Mp3Extractor) OggExtractor(androidx.media3.extractor.ogg.OggExtractor) JpegExtractor(androidx.media3.extractor.jpeg.JpegExtractor) Ac3Extractor(androidx.media3.extractor.ts.Ac3Extractor) FlvExtractor(androidx.media3.extractor.flv.FlvExtractor) Mp4Extractor(androidx.media3.extractor.mp4.Mp4Extractor) MatroskaExtractor(androidx.media3.extractor.mkv.MatroskaExtractor) FragmentedMp4Extractor(androidx.media3.extractor.mp4.FragmentedMp4Extractor) FlvExtractor(androidx.media3.extractor.flv.FlvExtractor) Ac3Extractor(androidx.media3.extractor.ts.Ac3Extractor) Nullable(androidx.annotation.Nullable)

Example 3 with TsExtractor

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

the class TsExtractorSeekTest method handlePendingSeek_handlesRandomSeeksAfterReadingFileOnce_extractsCorrectFrame.

@Test
public void handlePendingSeek_handlesRandomSeeksAfterReadingFileOnce_extractsCorrectFrame() throws IOException {
    TsExtractor extractor = new TsExtractor();
    Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    readInputFileOnce(extractor, extractorOutput, fileUri);
    SeekMap seekMap = extractorOutput.seekMap;
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(AUDIO_TRACK_ID);
    long numSeek = 100;
    for (long i = 0; i < numSeek; i++) {
        long targetSeekTimeUs = random.nextInt(DURATION_US + 1);
        int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
        assertThat(extractedFrameIndex).isNotEqualTo(-1);
        assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
    }
}
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 4 with TsExtractor

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

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(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 5 with TsExtractor

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

the class TsExtractorSeekTest method setUp.

@Before
public void setUp() throws IOException {
    positionHolder = new PositionHolder();
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(new TsExtractor(), ApplicationProvider.getApplicationContext(), TEST_FILE).trackOutputs.get(AUDIO_TRACK_ID);
    dataSource = new DefaultDataSource.Factory(ApplicationProvider.getApplicationContext()).createDataSource();
}
Also used : PositionHolder(androidx.media3.extractor.PositionHolder) Before(org.junit.Before)

Aggregations

FakeExtractorOutput (androidx.media3.test.utils.FakeExtractorOutput)9 Test (org.junit.Test)9 Uri (android.net.Uri)7 SeekMap (androidx.media3.extractor.SeekMap)7 FakeTrackOutput (androidx.media3.test.utils.FakeTrackOutput)7 TsExtractor (com.google.android.exoplayer2.extractor.ts.TsExtractor)6 Nullable (androidx.annotation.Nullable)4 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)4 FragmentedMp4Extractor (com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor)4 Ac3Extractor (com.google.android.exoplayer2.extractor.ts.Ac3Extractor)4 AdtsExtractor (com.google.android.exoplayer2.extractor.ts.AdtsExtractor)4 PositionHolder (androidx.media3.extractor.PositionHolder)3 Ac4Extractor (com.google.android.exoplayer2.extractor.ts.Ac4Extractor)3 DefaultTsPayloadReaderFactory (com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory)3 SuppressLint (android.annotation.SuppressLint)2 Format (androidx.media3.common.Format)2 TimestampAdjuster (androidx.media3.common.util.TimestampAdjuster)2 TsExtractor (androidx.media3.extractor.ts.TsExtractor)2 FakeExtractorInput (androidx.media3.test.utils.FakeExtractorInput)2 Extractor (com.google.android.exoplayer2.extractor.Extractor)2