Search in sources :

Example 1 with FakeDataSource

use of androidx.media3.test.utils.FakeDataSource in project media by androidx.

the class DefaultDashChunkSourceTest method getNextChunk_forVodManifest_doesNotSetMayNotLoadAtFullNetworkSpeedFlag.

@Test
public void getNextChunk_forVodManifest_doesNotSetMayNotLoadAtFullNetworkSpeedFlag() throws Exception {
    long nowMs = 2_000_000_000_000L;
    SystemClock.setCurrentTimeMillis(nowMs);
    DashManifest manifest = new DashManifestParser().parse(Uri.parse("https://example.com/test.mpd"), TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD_VOD));
    DefaultDashChunkSource chunkSource = new DefaultDashChunkSource(BundledChunkExtractor.FACTORY, new LoaderErrorThrower.Dummy(), manifest, new BaseUrlExclusionList(), /* periodIndex= */
    0, /* adaptationSetIndices= */
    new int[] { 0 }, new FixedTrackSelection(new TrackGroup(new Format.Builder().build()), /* track= */
    0), C.TRACK_TYPE_VIDEO, new FakeDataSource(), /* elapsedRealtimeOffsetMs= */
    0, /* maxSegmentsPerLoad= */
    1, /* enableEventMessageTrack= */
    false, /* closedCaptionFormats */
    ImmutableList.of(), /* playerTrackEmsgHandler= */
    null, PlayerId.UNSET);
    ChunkHolder output = new ChunkHolder();
    chunkSource.getNextChunk(/* playbackPositionUs= */
    0, /* loadPositionUs= */
    0, /* queue= */
    ImmutableList.of(), output);
    assertThat(output.chunk.dataSpec.flags & DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED).isEqualTo(0);
}
Also used : DashManifestParser(androidx.media3.exoplayer.dash.manifest.DashManifestParser) FakeDataSource(androidx.media3.test.utils.FakeDataSource) LoaderErrorThrower(androidx.media3.exoplayer.upstream.LoaderErrorThrower) TrackGroup(androidx.media3.common.TrackGroup) ChunkHolder(androidx.media3.exoplayer.source.chunk.ChunkHolder) DashManifest(androidx.media3.exoplayer.dash.manifest.DashManifest) FixedTrackSelection(androidx.media3.exoplayer.trackselection.FixedTrackSelection) Test(org.junit.Test)

Example 2 with FakeDataSource

use of androidx.media3.test.utils.FakeDataSource in project media by androidx.

the class DefaultDashChunkSourceTest method createDashChunkSource.

private DashChunkSource createDashChunkSource(int numberOfTracks) throws IOException {
    Assertions.checkArgument(numberOfTracks < 6);
    DashManifest manifest = new DashManifestParser().parse(Uri.parse("https://example.com/test.mpd"), TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD_VOD_LOCATION_FALLBACK));
    int[] adaptationSetIndices = new int[] { 0 };
    int[] selectedTracks = new int[numberOfTracks];
    Format[] formats = new Format[numberOfTracks];
    for (int i = 0; i < numberOfTracks; i++) {
        selectedTracks[i] = i;
        formats[i] = manifest.getPeriod(0).adaptationSets.get(adaptationSetIndices[0]).representations.get(i).format;
    }
    AdaptiveTrackSelection adaptiveTrackSelection = new AdaptiveTrackSelection(new TrackGroup(formats), selectedTracks, new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).build());
    return new DefaultDashChunkSource(BundledChunkExtractor.FACTORY, new LoaderErrorThrower.Dummy(), manifest, new BaseUrlExclusionList(new Random(/* seed= */
    1234)), /* periodIndex= */
    0, /* adaptationSetIndices= */
    adaptationSetIndices, adaptiveTrackSelection, C.TRACK_TYPE_VIDEO, new FakeDataSource(), /* elapsedRealtimeOffsetMs= */
    0, /* maxSegmentsPerLoad= */
    1, /* enableEventMessageTrack= */
    false, /* closedCaptionFormats */
    ImmutableList.of(), /* playerTrackEmsgHandler= */
    null, PlayerId.UNSET);
}
Also used : DashManifest(androidx.media3.exoplayer.dash.manifest.DashManifest) DashManifestParser(androidx.media3.exoplayer.dash.manifest.DashManifestParser) Format(androidx.media3.common.Format) Random(java.util.Random) FakeDataSource(androidx.media3.test.utils.FakeDataSource) AdaptiveTrackSelection(androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection) TrackGroup(androidx.media3.common.TrackGroup) LoaderErrorThrower(androidx.media3.exoplayer.upstream.LoaderErrorThrower)

Example 3 with FakeDataSource

use of androidx.media3.test.utils.FakeDataSource in project media by androidx.

the class DashDownloaderTest method progressiveDownloadSeparatePeriods.

@Test
public void progressiveDownloadSeparatePeriods() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("period_2_segment_1", 1).setRandomData("period_2_segment_2", 2).setRandomData("period_2_segment_3", 3);
    FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
    FakeDataSource.Factory factory = mock(FakeDataSource.Factory.class);
    when(factory.createDataSource()).thenReturn(fakeDataSource);
    DashDownloader dashDownloader = getDashDownloader(factory, new StreamKey(0, 0, 0), new StreamKey(1, 0, 0));
    dashDownloader.download(progressListener);
    DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
    assertThat(openedDataSpecs.length).isEqualTo(8);
    assertThat(openedDataSpecs[0].uri).isEqualTo(TEST_MPD_URI);
    assertThat(openedDataSpecs[1].uri.getPath()).isEqualTo("audio_init_data");
    assertThat(openedDataSpecs[2].uri.getPath()).isEqualTo("audio_segment_1");
    assertThat(openedDataSpecs[3].uri.getPath()).isEqualTo("audio_segment_2");
    assertThat(openedDataSpecs[4].uri.getPath()).isEqualTo("audio_segment_3");
    assertThat(openedDataSpecs[5].uri.getPath()).isEqualTo("period_2_segment_1");
    assertThat(openedDataSpecs[6].uri.getPath()).isEqualTo("period_2_segment_2");
    assertThat(openedDataSpecs[7].uri.getPath()).isEqualTo("period_2_segment_3");
}
Also used : FakeDataSource(androidx.media3.test.utils.FakeDataSource) FakeDataSet(androidx.media3.test.utils.FakeDataSet) DataSpec(androidx.media3.datasource.DataSpec) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 4 with FakeDataSource

use of androidx.media3.test.utils.FakeDataSource in project media by androidx.

the class DashDownloaderTest method progressiveDownload.

@Test
public void progressiveDownload() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("text_segment_1", 1).setRandomData("text_segment_2", 2).setRandomData("text_segment_3", 3);
    FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
    FakeDataSource.Factory factory = mock(FakeDataSource.Factory.class);
    when(factory.createDataSource()).thenReturn(fakeDataSource);
    DashDownloader dashDownloader = getDashDownloader(factory, new StreamKey(0, 0, 0), new StreamKey(0, 1, 0));
    dashDownloader.download(progressListener);
    DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
    assertThat(openedDataSpecs.length).isEqualTo(8);
    assertThat(openedDataSpecs[0].uri).isEqualTo(TEST_MPD_URI);
    assertThat(openedDataSpecs[1].uri.getPath()).isEqualTo("audio_init_data");
    assertThat(openedDataSpecs[2].uri.getPath()).isEqualTo("audio_segment_1");
    assertThat(openedDataSpecs[3].uri.getPath()).isEqualTo("text_segment_1");
    assertThat(openedDataSpecs[4].uri.getPath()).isEqualTo("audio_segment_2");
    assertThat(openedDataSpecs[5].uri.getPath()).isEqualTo("text_segment_2");
    assertThat(openedDataSpecs[6].uri.getPath()).isEqualTo("audio_segment_3");
    assertThat(openedDataSpecs[7].uri.getPath()).isEqualTo("text_segment_3");
}
Also used : FakeDataSource(androidx.media3.test.utils.FakeDataSource) FakeDataSet(androidx.media3.test.utils.FakeDataSet) DataSpec(androidx.media3.datasource.DataSpec) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 5 with FakeDataSource

use of androidx.media3.test.utils.FakeDataSource in project media by androidx.

the class ExtractorUtilTest method skipFullyQuietly_endNotReached_isTrueAndSkipsData.

@Test
public void skipFullyQuietly_endNotReached_isTrueAndSkipsData() throws Exception {
    FakeDataSource testDataSource = new FakeDataSource();
    testDataSource.getDataSet().newDefaultData().appendReadData(Arrays.copyOf(TEST_DATA, 3)).appendReadData(Arrays.copyOfRange(TEST_DATA, 3, 6)).appendReadData(Arrays.copyOfRange(TEST_DATA, 6, 9));
    testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
    ExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
    int length = 4;
    boolean hasRead = ExtractorUtil.skipFullyQuietly(input, length);
    assertThat(hasRead).isTrue();
    assertThat(input.getPosition()).isEqualTo(length);
}
Also used : FakeDataSource(androidx.media3.test.utils.FakeDataSource) DataSpec(androidx.media3.datasource.DataSpec) Test(org.junit.Test)

Aggregations

FakeDataSource (androidx.media3.test.utils.FakeDataSource)41 Test (org.junit.Test)38 DataSpec (androidx.media3.datasource.DataSpec)32 FakeDataSet (androidx.media3.test.utils.FakeDataSet)9 IOException (java.io.IOException)5 Uri (android.net.Uri)3 TrackGroup (androidx.media3.common.TrackGroup)3 FileDataSource (androidx.media3.datasource.FileDataSource)3 DashManifest (androidx.media3.exoplayer.dash.manifest.DashManifest)3 DashManifestParser (androidx.media3.exoplayer.dash.manifest.DashManifestParser)3 LoaderErrorThrower (androidx.media3.exoplayer.upstream.LoaderErrorThrower)3 StreamKey (androidx.media3.common.StreamKey)2 ChunkHolder (androidx.media3.exoplayer.source.chunk.ChunkHolder)2 FixedTrackSelection (androidx.media3.exoplayer.trackselection.FixedTrackSelection)2 FakeData (androidx.media3.test.utils.FakeDataSet.FakeData)2 Random (java.util.Random)2 Format (androidx.media3.common.Format)1 DataSource (androidx.media3.datasource.DataSource)1 AdaptiveTrackSelection (androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection)1 FailOnCloseDataSink (androidx.media3.test.utils.FailOnCloseDataSink)1