Search in sources :

Example 1 with StreamKey

use of androidx.media3.common.StreamKey in project media by androidx.

the class DefaultDownloadIndex method encodeStreamKeys.

@VisibleForTesting
static /* package */
String encodeStreamKeys(List<StreamKey> streamKeys) {
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < streamKeys.size(); i++) {
        StreamKey streamKey = streamKeys.get(i);
        stringBuilder.append(streamKey.periodIndex).append('.').append(streamKey.groupIndex).append('.').append(streamKey.streamIndex).append(',');
    }
    if (stringBuilder.length() > 0) {
        stringBuilder.setLength(stringBuilder.length() - 1);
    }
    return stringBuilder.toString();
}
Also used : StreamKey(androidx.media3.common.StreamKey) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 2 with StreamKey

use of androidx.media3.common.StreamKey in project media by androidx.

the class DashManifestTest method copy.

@Test
public void copy() {
    Representation[][][] representations = newRepresentations(3, 2, 3);
    ServiceDescriptionElement serviceDescriptionElement = new ServiceDescriptionElement(/* targetOffsetMs= */
    20, /* minOffsetMs= */
    10, /* maxOffsetMs= */
    40, /* minPlaybackSpeed= */
    0.9f, /* maxPlaybackSpeed= */
    1.1f);
    DashManifest sourceManifest = newDashManifest(10, serviceDescriptionElement, newPeriod("1", 1, newAdaptationSet(2, representations[0][0]), newAdaptationSet(3, representations[0][1])), newPeriod("4", 4, newAdaptationSet(5, representations[1][0]), newAdaptationSet(6, representations[1][1])), newPeriod("7", 7, newAdaptationSet(8, representations[2][0]), newAdaptationSet(9, representations[2][1])));
    List<StreamKey> keys = Arrays.asList(new StreamKey(0, 0, 0), new StreamKey(0, 0, 1), new StreamKey(0, 1, 2), new StreamKey(1, 0, 1), new StreamKey(1, 1, 0), new StreamKey(1, 1, 2), new StreamKey(2, 0, 1), new StreamKey(2, 0, 2), new StreamKey(2, 1, 0));
    // Keys don't need to be in any particular order
    Collections.shuffle(keys, new Random(0));
    DashManifest copyManifest = sourceManifest.copy(keys);
    DashManifest expectedManifest = newDashManifest(10, serviceDescriptionElement, newPeriod("1", 1, newAdaptationSet(2, representations[0][0][0], representations[0][0][1]), newAdaptationSet(3, representations[0][1][2])), newPeriod("4", 4, newAdaptationSet(5, representations[1][0][1]), newAdaptationSet(6, representations[1][1][0], representations[1][1][2])), newPeriod("7", 7, newAdaptationSet(8, representations[2][0][1], representations[2][0][2]), newAdaptationSet(9, representations[2][1][0])));
    assertManifestEquals(expectedManifest, copyManifest);
}
Also used : Random(java.util.Random) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Example 3 with StreamKey

use of androidx.media3.common.StreamKey in project media by androidx.

the class DashManifest method copyAdaptationSets.

private static ArrayList<AdaptationSet> copyAdaptationSets(List<AdaptationSet> adaptationSets, LinkedList<StreamKey> keys) {
    StreamKey key = keys.poll();
    int periodIndex = key.periodIndex;
    ArrayList<AdaptationSet> copyAdaptationSets = new ArrayList<>();
    do {
        int adaptationSetIndex = key.groupIndex;
        AdaptationSet adaptationSet = adaptationSets.get(adaptationSetIndex);
        List<Representation> representations = adaptationSet.representations;
        ArrayList<Representation> copyRepresentations = new ArrayList<>();
        do {
            Representation representation = representations.get(key.streamIndex);
            copyRepresentations.add(representation);
            key = keys.poll();
        } while (key.periodIndex == periodIndex && key.groupIndex == adaptationSetIndex);
        copyAdaptationSets.add(new AdaptationSet(adaptationSet.id, adaptationSet.type, copyRepresentations, adaptationSet.accessibilityDescriptors, adaptationSet.essentialProperties, adaptationSet.supplementalProperties));
    } while (key.periodIndex == periodIndex);
    // Add back the last key which doesn't belong to the period being processed
    keys.addFirst(key);
    return copyAdaptationSets;
}
Also used : ArrayList(java.util.ArrayList) StreamKey(androidx.media3.common.StreamKey)

Example 4 with StreamKey

use of androidx.media3.common.StreamKey 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 5 with StreamKey

use of androidx.media3.common.StreamKey in project media by androidx.

the class DashDownloaderTest method downloadRepresentation.

@Test
public void downloadRepresentation() 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);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet, new StreamKey(0, 0, 0));
    dashDownloader.download(progressListener);
    assertCachedData(cache, new RequestSet(fakeDataSet).useBoundedDataSpecFor("audio_init_data"));
}
Also used : RequestSet(androidx.media3.test.utils.CacheAsserts.RequestSet) FakeDataSet(androidx.media3.test.utils.FakeDataSet) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Aggregations

StreamKey (androidx.media3.common.StreamKey)38 Test (org.junit.Test)24 FakeDataSet (androidx.media3.test.utils.FakeDataSet)11 ArrayList (java.util.ArrayList)11 CacheDataSource (androidx.media3.datasource.cache.CacheDataSource)5 DefaultDownloaderFactory (androidx.media3.exoplayer.offline.DefaultDownloaderFactory)4 ExoTrackSelection (androidx.media3.exoplayer.trackselection.ExoTrackSelection)4 RequestSet (androidx.media3.test.utils.CacheAsserts.RequestSet)4 Downloader (androidx.media3.exoplayer.offline.Downloader)3 DownloaderFactory (androidx.media3.exoplayer.offline.DownloaderFactory)3 FakeDataSource (androidx.media3.test.utils.FakeDataSource)3 Context (android.content.Context)2 Format (androidx.media3.common.Format)2 TrackGroup (androidx.media3.common.TrackGroup)2 TrackGroupArray (androidx.media3.common.TrackGroupArray)2 DataSpec (androidx.media3.datasource.DataSpec)2 NoOpCacheEvictor (androidx.media3.datasource.cache.NoOpCacheEvictor)2 SimpleCache (androidx.media3.datasource.cache.SimpleCache)2 AdaptationSet (androidx.media3.exoplayer.dash.manifest.AdaptationSet)2 DefaultDownloadIndex (androidx.media3.exoplayer.offline.DefaultDownloadIndex)2