Search in sources :

Example 26 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class DashDownloaderTest method downloadRepresentationInSmallParts.

@Test
public void downloadRepresentationInSmallParts() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).newData("audio_segment_1").appendReadData(TestUtil.buildTestData(10)).appendReadData(TestUtil.buildTestData(10)).appendReadData(TestUtil.buildTestData(10)).endData().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(com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 27 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class DashDownloaderTest method downloadRepresentations.

@Test
public void downloadRepresentations() 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);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet, new StreamKey(0, 0, 0), new StreamKey(0, 1, 0));
    dashDownloader.download(progressListener);
    assertCachedData(cache, new RequestSet(fakeDataSet).useBoundedDataSpecFor("audio_init_data"));
}
Also used : RequestSet(com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet) FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 28 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class SsManifest method copy.

@Override
public final SsManifest copy(List<StreamKey> streamKeys) {
    ArrayList<StreamKey> sortedKeys = new ArrayList<>(streamKeys);
    Collections.sort(sortedKeys);
    StreamElement currentStreamElement = null;
    List<StreamElement> copiedStreamElements = new ArrayList<>();
    List<Format> copiedFormats = new ArrayList<>();
    for (int i = 0; i < sortedKeys.size(); i++) {
        StreamKey key = sortedKeys.get(i);
        StreamElement streamElement = streamElements[key.groupIndex];
        if (streamElement != currentStreamElement && currentStreamElement != null) {
            // We're advancing to a new stream element. Add the current one.
            copiedStreamElements.add(currentStreamElement.copy(copiedFormats.toArray(new Format[0])));
            copiedFormats.clear();
        }
        currentStreamElement = streamElement;
        copiedFormats.add(streamElement.formats[key.streamIndex]);
    }
    if (currentStreamElement != null) {
        // Add the last stream element.
        copiedStreamElements.add(currentStreamElement.copy(copiedFormats.toArray(new Format[0])));
    }
    StreamElement[] copiedStreamElementsArray = copiedStreamElements.toArray(new StreamElement[0]);
    return new SsManifest(majorVersion, minorVersion, durationUs, dvrWindowLengthUs, lookAheadCount, isLive, protectionElement, copiedStreamElementsArray);
}
Also used : Format(com.google.android.exoplayer2.Format) ArrayList(java.util.ArrayList) StreamKey(com.google.android.exoplayer2.offline.StreamKey)

Example 29 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class SsManifestTest method copyRemoveStreamElement.

@Test
public void copyRemoveStreamElement() throws Exception {
    Format[][] formats = newFormats(2, 3);
    SsManifest sourceManifest = createSsManifest(createStreamElement("1", formats[0]), createStreamElement("2", formats[1]));
    List<StreamKey> keys = Collections.singletonList(new StreamKey(1, 0));
    SsManifest copyManifest = sourceManifest.copy(keys);
    SsManifest expectedManifest = createSsManifest(createStreamElement("2", formats[1][0]));
    assertManifestEquals(expectedManifest, copyManifest);
}
Also used : SsTestUtils.createSsManifest(com.google.android.exoplayer2.source.smoothstreaming.SsTestUtils.createSsManifest) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 30 with StreamKey

use of com.google.android.exoplayer2.offline.StreamKey in project ExoPlayer by google.

the class SsDownloaderTest method createWithDefaultDownloaderFactory.

@Test
public void createWithDefaultDownloaderFactory() throws Exception {
    CacheDataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(Mockito.mock(Cache.class)).setUpstreamDataSourceFactory(DummyDataSource.FACTORY);
    DownloaderFactory factory = new DefaultDownloaderFactory(cacheDataSourceFactory, /* executor= */
    Runnable::run);
    Downloader downloader = factory.createDownloader(new DownloadRequest.Builder(/* id= */
    "id", Uri.parse("https://www.test.com/download")).setMimeType(MimeTypes.APPLICATION_SS).setStreamKeys(Collections.singletonList(new StreamKey(/* groupIndex= */
    0, /* trackIndex= */
    0))).build());
    assertThat(downloader).isInstanceOf(SsDownloader.class);
}
Also used : CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) DefaultDownloaderFactory(com.google.android.exoplayer2.offline.DefaultDownloaderFactory) DefaultDownloaderFactory(com.google.android.exoplayer2.offline.DefaultDownloaderFactory) DownloaderFactory(com.google.android.exoplayer2.offline.DownloaderFactory) Downloader(com.google.android.exoplayer2.offline.Downloader) DefaultDownloaderFactory(com.google.android.exoplayer2.offline.DefaultDownloaderFactory) DownloaderFactory(com.google.android.exoplayer2.offline.DownloaderFactory) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Aggregations

StreamKey (com.google.android.exoplayer2.offline.StreamKey)27 Test (org.junit.Test)18 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)11 ArrayList (java.util.ArrayList)10 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)5 DefaultDownloaderFactory (com.google.android.exoplayer2.offline.DefaultDownloaderFactory)4 RequestSet (com.google.android.exoplayer2.testutil.CacheAsserts.RequestSet)4 ExoTrackSelection (com.google.android.exoplayer2.trackselection.ExoTrackSelection)4 Downloader (com.google.android.exoplayer2.offline.Downloader)3 DownloaderFactory (com.google.android.exoplayer2.offline.DownloaderFactory)3 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)3 Context (android.content.Context)2 Format (com.google.android.exoplayer2.Format)2 DefaultDownloadIndex (com.google.android.exoplayer2.offline.DefaultDownloadIndex)2 DownloadRequest (com.google.android.exoplayer2.offline.DownloadRequest)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)2 AdaptationSet (com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)2 SsTestUtils.createSsManifest (com.google.android.exoplayer2.source.smoothstreaming.SsTestUtils.createSsManifest)2 DummyMainThread (com.google.android.exoplayer2.testutil.DummyMainThread)2