Search in sources :

Example 6 with TsExtractor

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

the class TsExtractorTest method customPesReader.

@Test
public void customPesReader() throws Exception {
    CustomTsPayloadReaderFactory factory = new CustomTsPayloadReaderFactory(true, false);
    TsExtractor tsExtractor = new TsExtractor(TsExtractor.MODE_MULTI_PMT, new TimestampAdjuster(0), factory);
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), "media/ts/sample_h262_mpeg_audio.ts")).setSimulateIOErrors(false).setSimulateUnknownLength(false).setSimulatePartialReads(false).build();
    FakeExtractorOutput output = new FakeExtractorOutput();
    tsExtractor.init(output);
    PositionHolder seekPositionHolder = new PositionHolder();
    int readResult = Extractor.RESULT_CONTINUE;
    while (readResult != Extractor.RESULT_END_OF_INPUT) {
        readResult = tsExtractor.read(input, seekPositionHolder);
        if (readResult == Extractor.RESULT_SEEK) {
            input.setPosition((int) seekPositionHolder.position);
        }
    }
    CustomEsReader reader = factory.esReader;
    assertThat(reader.packetsRead).isEqualTo(2);
    TrackOutput trackOutput = reader.getTrackOutput();
    assertThat(trackOutput == output.trackOutputs.get(257)).isTrue();
    assertThat(((FakeTrackOutput) trackOutput).lastFormat).isEqualTo(new Format.Builder().setId("1/257").setSampleMimeType("mime").setLanguage("und").build());
}
Also used : FakeExtractorInput(androidx.media3.test.utils.FakeExtractorInput) FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) TimestampAdjuster(androidx.media3.common.util.TimestampAdjuster) Format(androidx.media3.common.Format) PositionHolder(androidx.media3.extractor.PositionHolder) FakeExtractorOutput(androidx.media3.test.utils.FakeExtractorOutput) TrackOutput(androidx.media3.extractor.TrackOutput) FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) Test(org.junit.Test)

Example 7 with TsExtractor

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

the class TsExtractorTest method customInitialSectionReader.

@Test
public void customInitialSectionReader() throws Exception {
    CustomTsPayloadReaderFactory factory = new CustomTsPayloadReaderFactory(false, true);
    TsExtractor tsExtractor = new TsExtractor(TsExtractor.MODE_MULTI_PMT, new TimestampAdjuster(0), factory);
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), "media/ts/sample_with_sdt.ts")).setSimulateIOErrors(false).setSimulateUnknownLength(false).setSimulatePartialReads(false).build();
    tsExtractor.init(new FakeExtractorOutput());
    PositionHolder seekPositionHolder = new PositionHolder();
    int readResult = Extractor.RESULT_CONTINUE;
    while (readResult != Extractor.RESULT_END_OF_INPUT) {
        readResult = tsExtractor.read(input, seekPositionHolder);
        if (readResult == Extractor.RESULT_SEEK) {
            input.setPosition((int) seekPositionHolder.position);
        }
    }
    assertThat(factory.sdtReader.consumedSdts).isEqualTo(2);
}
Also used : FakeExtractorInput(androidx.media3.test.utils.FakeExtractorInput) PositionHolder(androidx.media3.extractor.PositionHolder) TimestampAdjuster(androidx.media3.common.util.TimestampAdjuster) FakeExtractorOutput(androidx.media3.test.utils.FakeExtractorOutput) Test(org.junit.Test)

Example 8 with TsExtractor

use of androidx.media3.extractor.ts.TsExtractor in project bolan by qiusunshine.

the class MyDefaultExtractorsFactory method addExtractorsForFileType.

private void addExtractorsForFileType(int fileType, List<Extractor> extractors) {
    switch(fileType) {
        case -1:
        case 13:
        default:
            break;
        case 0:
            extractors.add(new Ac3Extractor());
            break;
        case 1:
            extractors.add(new Ac4Extractor());
            break;
        case 2:
            extractors.add(new AdtsExtractor(this.adtsFlags | (this.constantBitrateSeekingEnabled ? 1 : 0)));
            break;
        case 3:
            extractors.add(new AmrExtractor(this.amrFlags | (this.constantBitrateSeekingEnabled ? 1 : 0)));
            break;
        case 4:
            if (FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR != null) {
                try {
                    extractors.add((Extractor) FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR.newInstance(this.flacFlags));
                } catch (Exception var4) {
                    throw new IllegalStateException("Unexpected error creating FLAC extractor", var4);
                }
            } else {
                extractors.add(new FlacExtractor(this.flacFlags));
            }
            break;
        case 5:
            extractors.add(new FlvExtractor());
            break;
        case 6:
            extractors.add(new MatroskaExtractor(this.matroskaFlags));
            break;
        case 7:
            extractors.add(new Mp3Extractor(this.mp3Flags | (this.constantBitrateSeekingEnabled ? 1 : 0)));
            break;
        case 8:
            extractors.add(new FragmentedMp4Extractor(this.fragmentedMp4Flags));
            extractors.add(new Mp4Extractor(this.mp4Flags));
            break;
        case 9:
            extractors.add(new OggExtractor());
            break;
        case 10:
            extractors.add(new PsExtractor());
            break;
        case 11:
            extractors.add(new TsExtractor(this.tsMode, this.tsFlags, this.tsTimestampSearchBytes));
            break;
        case 12:
            extractors.add(new WavExtractor());
            break;
        case 14:
            extractors.add(new JpegExtractor());
    }
}
Also used : FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) JpegExtractor(com.google.android.exoplayer2.extractor.jpeg.JpegExtractor) Ac4Extractor(com.google.android.exoplayer2.extractor.ts.Ac4Extractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) 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) FlvExtractor(com.google.android.exoplayer2.extractor.flv.FlvExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor)

Example 9 with TsExtractor

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

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(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) JpegExtractor(com.google.android.exoplayer2.extractor.jpeg.JpegExtractor) Ac4Extractor(com.google.android.exoplayer2.extractor.ts.Ac4Extractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) 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) JpegExtractor(com.google.android.exoplayer2.extractor.jpeg.JpegExtractor) Mp4Extractor(com.google.android.exoplayer2.extractor.mp4.Mp4Extractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor) Ac4Extractor(com.google.android.exoplayer2.extractor.ts.Ac4Extractor) WavExtractor(com.google.android.exoplayer2.extractor.wav.WavExtractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor) AmrExtractor(com.google.android.exoplayer2.extractor.amr.AmrExtractor) MatroskaExtractor(com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor) FlacExtractor(com.google.android.exoplayer2.extractor.flac.FlacExtractor) FlvExtractor(com.google.android.exoplayer2.extractor.flv.FlvExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor) Nullable(androidx.annotation.Nullable)

Example 10 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)

Aggregations

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