Search in sources :

Example 6 with Extractor

use of androidx.media3.extractor.Extractor in project media by androidx.

the class FlacExtractorSeekTest method seeking_seekTable_handlesSeekToEoF.

@Test
public void seeking_seekTable_handlesSeekToEoF() throws IOException {
    String fileName = TEST_FILE_SEEK_TABLE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long targetSeekTimeUs = seekMap.getDurationUs();
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
    assertFirstFrameAfterSeekPrecedesTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 7 with Extractor

use of androidx.media3.extractor.Extractor in project media by androidx.

the class FlacExtractorSeekTest method flacExtractorReads_seekTable_returnSeekableSeekMap.

@Test
public void flacExtractorReads_seekTable_returnSeekableSeekMap() throws IOException {
    Uri fileUri = TestUtil.buildAssetUri(TEST_FILE_SEEK_TABLE);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    assertThat(seekMap).isNotNull();
    assertThat(seekMap.getDurationUs()).isEqualTo(DURATION_US);
    assertThat(seekMap.isSeekable()).isTrue();
}
Also used : SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 8 with Extractor

use of androidx.media3.extractor.Extractor in project media by androidx.

the class FlacExtractorSeekTest method seeking_seekTable_handlesSeekingBackward.

@Test
public void seeking_seekTable_handlesSeekingBackward() throws IOException {
    String fileName = TEST_FILE_SEEK_TABLE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long firstSeekTimeUs = 1_234_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 987_000;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
    assertFirstFrameAfterSeekPrecedesTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 9 with Extractor

use of androidx.media3.extractor.Extractor in project media by androidx.

the class FlacExtractorSeekTest method flacExtractorReads_binarySearch_returnSeekableSeekMap.

@Test
public void flacExtractorReads_binarySearch_returnSeekableSeekMap() throws IOException {
    Uri fileUri = TestUtil.buildAssetUri(TEST_FILE_BINARY_SEARCH);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    assertThat(seekMap).isNotNull();
    assertThat(seekMap.getDurationUs()).isEqualTo(DURATION_US);
    assertThat(seekMap.isSeekable()).isTrue();
}
Also used : SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 10 with Extractor

use of androidx.media3.extractor.Extractor in project media by androidx.

the class DefaultMediaSourceFactory method createMediaSource.

@UnstableApi
@Override
public MediaSource createMediaSource(MediaItem mediaItem) {
    Assertions.checkNotNull(mediaItem.localConfiguration);
    @Nullable String scheme = mediaItem.localConfiguration.uri.getScheme();
    if (scheme != null && scheme.equals(C.SSAI_SCHEME)) {
        return checkNotNull(serverSideAdInsertionMediaSourceFactory).createMediaSource(mediaItem);
    }
    @C.ContentType int type = Util.inferContentTypeForUriAndMimeType(mediaItem.localConfiguration.uri, mediaItem.localConfiguration.mimeType);
    @Nullable MediaSource.Factory mediaSourceFactory = delegateFactoryLoader.getMediaSourceFactory(type);
    checkStateNotNull(mediaSourceFactory, "No suitable media source factory found for content type: " + type);
    MediaItem.LiveConfiguration.Builder liveConfigurationBuilder = mediaItem.liveConfiguration.buildUpon();
    if (mediaItem.liveConfiguration.targetOffsetMs == C.TIME_UNSET) {
        liveConfigurationBuilder.setTargetOffsetMs(liveTargetOffsetMs);
    }
    if (mediaItem.liveConfiguration.minPlaybackSpeed == C.RATE_UNSET) {
        liveConfigurationBuilder.setMinPlaybackSpeed(liveMinSpeed);
    }
    if (mediaItem.liveConfiguration.maxPlaybackSpeed == C.RATE_UNSET) {
        liveConfigurationBuilder.setMaxPlaybackSpeed(liveMaxSpeed);
    }
    if (mediaItem.liveConfiguration.minOffsetMs == C.TIME_UNSET) {
        liveConfigurationBuilder.setMinOffsetMs(liveMinOffsetMs);
    }
    if (mediaItem.liveConfiguration.maxOffsetMs == C.TIME_UNSET) {
        liveConfigurationBuilder.setMaxOffsetMs(liveMaxOffsetMs);
    }
    MediaItem.LiveConfiguration liveConfiguration = liveConfigurationBuilder.build();
    // Make sure to retain the very same media item instance, if no value needs to be overridden.
    if (!liveConfiguration.equals(mediaItem.liveConfiguration)) {
        mediaItem = mediaItem.buildUpon().setLiveConfiguration(liveConfiguration).build();
    }
    MediaSource mediaSource = mediaSourceFactory.createMediaSource(mediaItem);
    List<MediaItem.SubtitleConfiguration> subtitleConfigurations = castNonNull(mediaItem.localConfiguration).subtitleConfigurations;
    if (!subtitleConfigurations.isEmpty()) {
        MediaSource[] mediaSources = new MediaSource[subtitleConfigurations.size() + 1];
        mediaSources[0] = mediaSource;
        for (int i = 0; i < subtitleConfigurations.size(); i++) {
            if (useProgressiveMediaSourceForSubtitles) {
                Format format = new Format.Builder().setSampleMimeType(subtitleConfigurations.get(i).mimeType).setLanguage(subtitleConfigurations.get(i).language).setSelectionFlags(subtitleConfigurations.get(i).selectionFlags).setRoleFlags(subtitleConfigurations.get(i).roleFlags).setLabel(subtitleConfigurations.get(i).label).setId(subtitleConfigurations.get(i).id).build();
                ExtractorsFactory extractorsFactory = () -> new Extractor[] { SubtitleDecoderFactory.DEFAULT.supportsFormat(format) ? new SubtitleExtractor(SubtitleDecoderFactory.DEFAULT.createDecoder(format), format) : new UnknownSubtitlesExtractor(format) };
                mediaSources[i + 1] = new ProgressiveMediaSource.Factory(dataSourceFactory, extractorsFactory).setLoadErrorHandlingPolicy(loadErrorHandlingPolicy).createMediaSource(MediaItem.fromUri(subtitleConfigurations.get(i).uri.toString()));
            } else {
                mediaSources[i + 1] = new SingleSampleMediaSource.Factory(dataSourceFactory).setLoadErrorHandlingPolicy(loadErrorHandlingPolicy).createMediaSource(subtitleConfigurations.get(i), /* durationUs= */
                C.TIME_UNSET);
            }
        }
        mediaSource = new MergingMediaSource(mediaSources);
    }
    return maybeWrapWithAdsMediaSource(mediaItem, maybeClipMediaSource(mediaItem, mediaSource));
}
Also used : SubtitleExtractor(androidx.media3.extractor.text.SubtitleExtractor) Format(androidx.media3.common.Format) AdsMediaSource(androidx.media3.exoplayer.source.ads.AdsMediaSource) DefaultExtractorsFactory(androidx.media3.extractor.DefaultExtractorsFactory) ExtractorsFactory(androidx.media3.extractor.ExtractorsFactory) MediaItem(androidx.media3.common.MediaItem) Extractor(androidx.media3.extractor.Extractor) SubtitleExtractor(androidx.media3.extractor.text.SubtitleExtractor) Nullable(androidx.annotation.Nullable) UnstableApi(androidx.media3.common.util.UnstableApi)

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)18 Nullable (androidx.annotation.Nullable)12 ExtractorInput (androidx.media3.extractor.ExtractorInput)12 FakeExtractorInput (androidx.media3.test.utils.FakeExtractorInput)12 FragmentedMp4Extractor (com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor)10 DefaultExtractorInput (androidx.media3.extractor.DefaultExtractorInput)9 WebvttDecoder (androidx.media3.extractor.text.webvtt.WebvttDecoder)8 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)8 Extractor (androidx.media3.extractor.Extractor)7 Ac3Extractor (com.google.android.exoplayer2.extractor.ts.Ac3Extractor)7 AdtsExtractor (com.google.android.exoplayer2.extractor.ts.AdtsExtractor)7 TsExtractor (com.google.android.exoplayer2.extractor.ts.TsExtractor)7 Format (androidx.media3.common.Format)6 Mp3Extractor (androidx.media3.extractor.mp3.Mp3Extractor)6 FragmentedMp4Extractor (androidx.media3.extractor.mp4.FragmentedMp4Extractor)6