Search in sources :

Example 21 with StreamKey

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

the class DashManifest method copy.

@Override
public final DashManifest copy(List<StreamKey> streamKeys) {
    LinkedList<StreamKey> keys = new LinkedList<>(streamKeys);
    Collections.sort(keys);
    // Add a stopper key to the end
    keys.add(new StreamKey(-1, -1, -1));
    ArrayList<Period> copyPeriods = new ArrayList<>();
    long shiftMs = 0;
    for (int periodIndex = 0; periodIndex < getPeriodCount(); periodIndex++) {
        if (keys.peek().periodIndex != periodIndex) {
            // No representations selected in this period.
            long periodDurationMs = getPeriodDurationMs(periodIndex);
            if (periodDurationMs != C.TIME_UNSET) {
                shiftMs += periodDurationMs;
            }
        } else {
            Period period = getPeriod(periodIndex);
            ArrayList<AdaptationSet> copyAdaptationSets = copyAdaptationSets(period.adaptationSets, keys);
            Period copiedPeriod = new Period(period.id, period.startMs - shiftMs, copyAdaptationSets, period.eventStreams);
            copyPeriods.add(copiedPeriod);
        }
    }
    long newDuration = durationMs != C.TIME_UNSET ? durationMs - shiftMs : C.TIME_UNSET;
    return new DashManifest(availabilityStartTimeMs, newDuration, minBufferTimeMs, dynamic, minUpdatePeriodMs, timeShiftBufferDepthMs, suggestedPresentationDelayMs, publishTimeMs, programInformation, utcTiming, serviceDescription, location, copyPeriods);
}
Also used : ArrayList(java.util.ArrayList) StreamKey(com.google.android.exoplayer2.offline.StreamKey) LinkedList(java.util.LinkedList)

Example 22 with StreamKey

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

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(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 23 with StreamKey

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

the class DashDownloaderTest method downloadRepresentationFailure.

@Test
public void downloadRepresentationFailure() throws Exception {
    FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).setRandomData("audio_segment_1", 4).newData("audio_segment_2").appendReadData(TestUtil.buildTestData(2)).appendReadError(new IOException()).appendReadData(TestUtil.buildTestData(3)).endData().setRandomData("audio_segment_3", 6);
    DashDownloader dashDownloader = getDashDownloader(fakeDataSet, new StreamKey(0, 0, 0));
    try {
        dashDownloader.download(progressListener);
        fail();
    } catch (IOException e) {
    // Expected.
    }
    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) IOException(java.io.IOException) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 24 with StreamKey

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

the class DashDownloaderTest method remove.

@Test
public void remove() 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);
    dashDownloader.remove();
    assertCacheEmpty(cache);
}
Also used : FakeDataSet(com.google.android.exoplayer2.testutil.FakeDataSet) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 25 with StreamKey

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

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(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)

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