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