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);
}
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);
}
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"));
}
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);
}
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"));
}
Aggregations