use of com.google.android.exoplayer2.testutil.FakeDataSet.FakeData.Segment in project ExoPlayer by google.
the class HlsMediaSourceTest method loadLivePlaylist_withNonPreciseStartTime_targetLiveOffsetFromStartTime.
@Test
public void loadLivePlaylist_withNonPreciseStartTime_targetLiveOffsetFromStartTime() throws TimeoutException, ParserException {
String playlistUri = "fake://foo.bar/media0/playlist.m3u8";
// The playlist has a duration of 16 seconds, and part hold back, hold back and start time
// defined.
String playlist = "#EXTM3U\n" + "#EXT-X-PROGRAM-DATE-TIME:2020-01-01T00:00:00.0+00:00\n" + "#EXT-X-TARGETDURATION:4\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-START:TIME-OFFSET=-10\n" + "#EXT-X-MEDIA-SEQUENCE:0\n" + "#EXTINF:4.00000,\n" + "fileSequence0.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence1.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence2.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence3.ts\n" + "#EXT-X-SERVER-CONTROL:HOLD-BACK=12,PART-HOLD-BACK=3\n";
// The playlist finishes 1 second before the current time.
SystemClock.setCurrentTimeMillis(Util.parseXsDateTime("2020-01-01T00:00:17.0+00:00"));
HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri, playlist);
MediaItem mediaItem = MediaItem.fromUri(playlistUri);
HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
Timeline timeline = prepareAndWaitForTimeline(mediaSource);
Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
// The target live offset is picked from start time (16 - 10 = 6) and then expressed in relation
// to the live edge (17 - 6 = 11 seconds).
assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(11000);
// The default position points to the segment containing the start time.
assertThat(window.defaultPositionUs).isEqualTo(4000000);
}
use of com.google.android.exoplayer2.testutil.FakeDataSet.FakeData.Segment in project ExoPlayer by google.
the class HlsMediaPlaylistParserTest method variableSubstitution.
@Test
public void variableSubstitution() throws IOException {
Uri playlistUri = Uri.parse("https://example.com/substitution.m3u8");
String playlistString = "#EXTM3U\n" + "#EXT-X-VERSION:8\n" + "#EXT-X-DEFINE:NAME=\"underscore_1\",VALUE=\"{\"\n" + "#EXT-X-DEFINE:NAME=\"dash-1\",VALUE=\"replaced_value.ts\"\n" + "#EXT-X-TARGETDURATION:5\n" + "#EXT-X-MEDIA-SEQUENCE:10\n" + "#EXTINF:5.005,\n" + "segment1.ts\n" + "#EXT-X-MAP:URI=\"{$dash-1}\"" + "#EXTINF:5.005,\n" + "segment{$underscore_1}$name_1}\n";
InputStream inputStream = new ByteArrayInputStream(Util.getUtf8Bytes(playlistString));
HlsMediaPlaylist playlist = (HlsMediaPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream);
Segment segment = playlist.segments.get(1);
assertThat(segment.initializationSegment.url).isEqualTo("replaced_value.ts");
assertThat(segment.url).isEqualTo("segment{$name_1}");
}
use of com.google.android.exoplayer2.testutil.FakeDataSet.FakeData.Segment in project ExoPlayer by google.
the class HlsMediaSourceTest method loadLivePlaylist_withNonPreciseStartTimeAndUserDefinedLiveOffset_startsFromPrecedingSegment.
@Test
public void loadLivePlaylist_withNonPreciseStartTimeAndUserDefinedLiveOffset_startsFromPrecedingSegment() throws TimeoutException, ParserException {
String playlistUri = "fake://foo.bar/media0/playlist.m3u8";
// The playlist has a duration of 16 seconds, and part hold back, hold back and start time
// defined.
String playlist = "#EXTM3U\n" + "#EXT-X-PROGRAM-DATE-TIME:2020-01-01T00:00:00.0+00:00\n" + "#EXT-X-TARGETDURATION:4\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-START:TIME-OFFSET=-10\n" + "#EXT-X-MEDIA-SEQUENCE:0\n" + "#EXTINF:4.00000,\n" + "fileSequence0.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence1.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence2.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence3.ts\n" + "#EXT-X-SERVER-CONTROL:HOLD-BACK=12,PART-HOLD-BACK=3\n";
// The playlist finishes 1 second before the current time.
SystemClock.setCurrentTimeMillis(Util.parseXsDateTime("2020-01-01T00:00:17.0+00:00"));
HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri, playlist);
MediaItem mediaItem = new MediaItem.Builder().setUri(playlistUri).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(3000).build()).build();
HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
Timeline timeline = prepareAndWaitForTimeline(mediaSource);
Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(3000);
// The default position points to the segment containing the start time.
assertThat(window.defaultPositionUs).isEqualTo(4000000);
}
use of com.google.android.exoplayer2.testutil.FakeDataSet.FakeData.Segment in project ExoPlayer by google.
the class HlsMediaPlaylistSegmentIteratorTest method next_startIteratorAtPartWithinSegment_correctElements.
@Test
public void next_startIteratorAtPartWithinSegment_correctElements() {
HlsMediaPlaylist mediaPlaylist = getHlsMediaPlaylist(LOW_LATENCY_SEGMENTS_AND_PARTS);
HlsChunkSource.HlsMediaPlaylistSegmentIterator hlsMediaPlaylistSegmentIterator = new HlsChunkSource.HlsMediaPlaylistSegmentIterator(mediaPlaylist.baseUri, /* startOfPlaylistInPeriodUs= */
0, HlsChunkSource.getSegmentBaseList(mediaPlaylist, /* mediaSequence= */
14, /* partIndex= */
1));
List<DataSpec> datasSpecs = new ArrayList<>();
while (hlsMediaPlaylistSegmentIterator.next()) {
datasSpecs.add(hlsMediaPlaylistSegmentIterator.getDataSpec());
}
assertThat(datasSpecs).hasSize(7);
// The iterator starts with 11 parts.
assertThat(datasSpecs.get(0).uri.toString()).isEqualTo("fileSequence14.1.ts");
assertThat(datasSpecs.get(1).uri.toString()).isEqualTo("fileSequence14.2.ts");
assertThat(datasSpecs.get(2).uri.toString()).isEqualTo("fileSequence14.3.ts");
// Use a segment in between if possible.
assertThat(datasSpecs.get(3).uri.toString()).isEqualTo("fileSequence15.ts");
// Then parts again.
assertThat(datasSpecs.get(4).uri.toString()).isEqualTo("fileSequence16.0.ts");
assertThat(datasSpecs.get(5).uri.toString()).isEqualTo("fileSequence16.1.ts");
assertThat(datasSpecs.get(6).uri.toString()).isEqualTo("fileSequence16.2.ts");
}
Aggregations