Search in sources :

Example 1 with Extractor

use of androidx.media3.extractor.Extractor in project ExoPlayer by google.

the class HlsMediaChunk method buildPackedAudioExtractor.

private Extractor buildPackedAudioExtractor(long startTimeUs) {
    Extractor extractor;
    if (lastPathSegment.endsWith(AAC_FILE_EXTENSION)) {
        extractor = new AdtsExtractor(startTimeUs);
    } else if (lastPathSegment.endsWith(AC3_FILE_EXTENSION) || lastPathSegment.endsWith(EC3_FILE_EXTENSION)) {
        extractor = new Ac3Extractor(startTimeUs);
    } else if (lastPathSegment.endsWith(MP3_FILE_EXTENSION)) {
        extractor = new Mp3Extractor(0, startTimeUs);
    } else {
        throw new IllegalArgumentException("Unkown extension for audio file: " + lastPathSegment);
    }
    extractor.init(extractorOutput);
    return extractor;
}
Also used : AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) 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) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor)

Example 2 with Extractor

use of androidx.media3.extractor.Extractor in project ExoPlayer by google.

the class DashUtil method newWrappedExtractor.

private static ChunkExtractorWrapper newWrappedExtractor(Format format) {
    String mimeType = format.containerMimeType;
    boolean isWebm = mimeType.startsWith(MimeTypes.VIDEO_WEBM) || mimeType.startsWith(MimeTypes.AUDIO_WEBM);
    Extractor extractor = isWebm ? new MatroskaExtractor() : new FragmentedMp4Extractor();
    return new ChunkExtractorWrapper(extractor, format);
}
Also used : FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) ChunkExtractorWrapper(com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper) FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) Extractor(com.google.android.exoplayer2.extractor.Extractor) MatroskaExtractor(com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor) MatroskaExtractor(com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor)

Example 3 with Extractor

use of androidx.media3.extractor.Extractor in project ExoPlayer by google.

the class BundledExtractorsAdapter method init.

@Override
public void init(DataReader dataReader, Uri uri, Map<String, List<String>> responseHeaders, long position, long length, ExtractorOutput output) throws IOException {
    ExtractorInput extractorInput = new DefaultExtractorInput(dataReader, position, length);
    this.extractorInput = extractorInput;
    if (extractor != null) {
        return;
    }
    Extractor[] extractors = extractorsFactory.createExtractors(uri, responseHeaders);
    if (extractors.length == 1) {
        this.extractor = extractors[0];
    } else {
        for (Extractor extractor : extractors) {
            try {
                if (extractor.sniff(extractorInput)) {
                    this.extractor = extractor;
                    break;
                }
            } catch (EOFException e) {
            // Do nothing.
            } finally {
                Assertions.checkState(this.extractor != null || extractorInput.getPosition() == position);
                extractorInput.resetPeekPosition();
            }
        }
        if (extractor == null) {
            throw new UnrecognizedInputFormatException("None of the available extractors (" + Util.getCommaDelimitedSimpleClassNames(extractors) + ") could read the stream.", Assertions.checkNotNull(uri));
        }
    }
    extractor.init(output);
}
Also used : ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) EOFException(java.io.EOFException) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) Extractor(com.google.android.exoplayer2.extractor.Extractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)

Example 4 with Extractor

use of androidx.media3.extractor.Extractor in project ExoPlayer by google.

the class DashUtil method newChunkExtractor.

private static ChunkExtractor newChunkExtractor(int trackType, Format format) {
    String mimeType = format.containerMimeType;
    boolean isWebm = mimeType != null && (mimeType.startsWith(MimeTypes.VIDEO_WEBM) || mimeType.startsWith(MimeTypes.AUDIO_WEBM));
    Extractor extractor = isWebm ? new MatroskaExtractor() : new FragmentedMp4Extractor();
    return new BundledChunkExtractor(extractor, trackType, format);
}
Also used : FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) BundledChunkExtractor(com.google.android.exoplayer2.source.chunk.BundledChunkExtractor) ChunkExtractor(com.google.android.exoplayer2.source.chunk.ChunkExtractor) Extractor(com.google.android.exoplayer2.extractor.Extractor) MatroskaExtractor(com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor) BundledChunkExtractor(com.google.android.exoplayer2.source.chunk.BundledChunkExtractor) MatroskaExtractor(com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor)

Example 5 with Extractor

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

the class ContainerMediaChunk method load.

@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public final void load() throws IOException, InterruptedException {
    if (nextLoadPosition == 0) {
        // Configure the output and set it as the target for the extractor wrapper.
        BaseMediaChunkOutput output = getOutput();
        output.setSampleOffsetUs(sampleOffsetUs);
        extractorWrapper.init(getTrackOutputProvider(output), clippedStartTimeUs == C.TIME_UNSET ? C.TIME_UNSET : (clippedStartTimeUs - sampleOffsetUs), clippedEndTimeUs == C.TIME_UNSET ? C.TIME_UNSET : (clippedEndTimeUs - sampleOffsetUs));
    }
    try {
        // Create and open the input.
        DataSpec loadDataSpec = dataSpec.subrange(nextLoadPosition);
        ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
        // Load and decode the sample data.
        try {
            Extractor extractor = extractorWrapper.extractor;
            int result = Extractor.RESULT_CONTINUE;
            while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
                result = extractor.read(input, DUMMY_POSITION_HOLDER);
            }
            Assertions.checkState(result != Extractor.RESULT_SEEK);
        } finally {
            nextLoadPosition = input.getPosition() - dataSpec.absoluteStreamPosition;
        }
    } finally {
        Util.closeQuietly(dataSource);
    }
    loadCompleted = true;
}
Also used : ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) Extractor(com.google.android.exoplayer2.extractor.Extractor)

Aggregations

Test (org.junit.Test)87 SeekMap (androidx.media3.extractor.SeekMap)73 Uri (android.net.Uri)67 FakeTrackOutput (androidx.media3.test.utils.FakeTrackOutput)59 FakeExtractorOutput (androidx.media3.test.utils.FakeExtractorOutput)44 Extractor (com.google.android.exoplayer2.extractor.Extractor)16 ExtractorInput (androidx.media3.extractor.ExtractorInput)12 FakeExtractorInput (androidx.media3.test.utils.FakeExtractorInput)12 Nullable (androidx.annotation.Nullable)11 DefaultExtractorInput (androidx.media3.extractor.DefaultExtractorInput)9 WebvttDecoder (androidx.media3.extractor.text.webvtt.WebvttDecoder)8 FragmentedMp4Extractor (com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor)8 Extractor (androidx.media3.extractor.Extractor)7 Format (androidx.media3.common.Format)6 Mp3Extractor (androidx.media3.extractor.mp3.Mp3Extractor)6 FragmentedMp4Extractor (androidx.media3.extractor.mp4.FragmentedMp4Extractor)6 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)6 PositionHolder (androidx.media3.extractor.PositionHolder)5 Ac3Extractor (androidx.media3.extractor.ts.Ac3Extractor)5 Ac4Extractor (androidx.media3.extractor.ts.Ac4Extractor)5