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());
}
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);
}
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());
}
}
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;
}
}
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));
}
Aggregations