use of com.google.android.exoplayer2.metadata.mp4.SlowMotionData.Segment in project ExoPlayer by google.
the class HlsMediaPlaylistParserTest method encryptedMapTag.
@Test
public void encryptedMapTag() throws IOException {
Uri playlistUri = Uri.parse("https://example.com/test3.m3u8");
String playlistString = "#EXTM3U\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-TARGETDURATION:5\n" + "#EXT-X-MEDIA-SEQUENCE:10\n" + "#EXT-X-KEY:METHOD=AES-128," + "URI=\"https://priv.example.com/key.php?r=2680\",IV=0x1566B\n" + "#EXT-X-MAP:URI=\"init1.ts\"" + "#EXTINF:5.005,\n" + "02/00/32.ts\n" + "#EXT-X-KEY:METHOD=NONE\n" + "#EXT-X-MAP:URI=\"init2.ts\"" + "#EXTINF:5.005,\n" + "02/00/47.ts\n";
InputStream inputStream = new ByteArrayInputStream(Util.getUtf8Bytes(playlistString));
HlsMediaPlaylist playlist = (HlsMediaPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream);
List<Segment> segments = playlist.segments;
Segment initSegment1 = segments.get(0).initializationSegment;
assertThat(initSegment1.fullSegmentEncryptionKeyUri).isEqualTo("https://priv.example.com/key.php?r=2680");
assertThat(initSegment1.encryptionIV).isEqualTo("0x1566B");
Segment initSegment2 = segments.get(1).initializationSegment;
assertThat(initSegment2.fullSegmentEncryptionKeyUri).isNull();
assertThat(initSegment2.encryptionIV).isNull();
}
use of com.google.android.exoplayer2.metadata.mp4.SlowMotionData.Segment in project ExoPlayer by google.
the class HlsMediaPlaylistParserTest method noExplicitInitSegmentInIFrameOnly_infersInitSegment.
@Test
public void noExplicitInitSegmentInIFrameOnly_infersInitSegment() throws IOException {
Uri playlistUri = Uri.parse("https://example.com/test3.m3u8");
String playlistString = "#EXTM3U\n" + "#EXT-X-TARGETDURATION:5\n" + "#EXT-X-I-FRAMES-ONLY\n" + "#EXTINF:5.005,\n" + "#EXT-X-BYTERANGE:100@300\n" + "segment1.ts\n" + "#EXTINF:5.005,\n" + "#EXT-X-BYTERANGE:100@400\n" + "segment2.ts\n" + "#EXTINF:5.005,\n" + "#EXT-X-BYTERANGE:100@400\n" + "segment1.ts\n";
InputStream inputStream = new ByteArrayInputStream(Util.getUtf8Bytes(playlistString));
HlsMediaPlaylist playlist = (HlsMediaPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream);
List<Segment> segments = playlist.segments;
@Nullable Segment initializationSegment = segments.get(0).initializationSegment;
assertThat(initializationSegment.url).isEqualTo("segment1.ts");
assertThat(initializationSegment.byteRangeOffset).isEqualTo(0);
assertThat(initializationSegment.byteRangeLength).isEqualTo(300);
initializationSegment = segments.get(1).initializationSegment;
assertThat(initializationSegment.url).isEqualTo("segment2.ts");
assertThat(initializationSegment.byteRangeOffset).isEqualTo(0);
assertThat(initializationSegment.byteRangeLength).isEqualTo(400);
initializationSegment = segments.get(2).initializationSegment;
assertThat(initializationSegment.url).isEqualTo("segment1.ts");
assertThat(initializationSegment.byteRangeOffset).isEqualTo(0);
assertThat(initializationSegment.byteRangeLength).isEqualTo(300);
}
use of com.google.android.exoplayer2.metadata.mp4.SlowMotionData.Segment in project ExoPlayer by google.
the class HlsDownloader method getSegments.
@Override
protected List<Segment> getSegments(DataSource dataSource, HlsPlaylist playlist, boolean removing) throws IOException, InterruptedException {
ArrayList<DataSpec> mediaPlaylistDataSpecs = new ArrayList<>();
if (playlist instanceof HlsMultivariantPlaylist) {
HlsMultivariantPlaylist multivariantPlaylist = (HlsMultivariantPlaylist) playlist;
addMediaPlaylistDataSpecs(multivariantPlaylist.mediaPlaylistUrls, mediaPlaylistDataSpecs);
} else {
mediaPlaylistDataSpecs.add(SegmentDownloader.getCompressibleDataSpec(Uri.parse(playlist.baseUri)));
}
ArrayList<Segment> segments = new ArrayList<>();
HashSet<Uri> seenEncryptionKeyUris = new HashSet<>();
for (DataSpec mediaPlaylistDataSpec : mediaPlaylistDataSpecs) {
segments.add(new Segment(/* startTimeUs= */
0, mediaPlaylistDataSpec));
HlsMediaPlaylist mediaPlaylist;
try {
mediaPlaylist = (HlsMediaPlaylist) getManifest(dataSource, mediaPlaylistDataSpec, removing);
} catch (IOException e) {
if (!removing) {
throw e;
}
// Generating an incomplete segment list is allowed. Advance to the next media playlist.
continue;
}
@Nullable HlsMediaPlaylist.Segment lastInitSegment = null;
List<HlsMediaPlaylist.Segment> hlsSegments = mediaPlaylist.segments;
for (int i = 0; i < hlsSegments.size(); i++) {
HlsMediaPlaylist.Segment segment = hlsSegments.get(i);
HlsMediaPlaylist.Segment initSegment = segment.initializationSegment;
if (initSegment != null && initSegment != lastInitSegment) {
lastInitSegment = initSegment;
addSegment(mediaPlaylist, initSegment, seenEncryptionKeyUris, segments);
}
addSegment(mediaPlaylist, segment, seenEncryptionKeyUris, segments);
}
}
return segments;
}
use of com.google.android.exoplayer2.metadata.mp4.SlowMotionData.Segment in project ExoPlayer by google.
the class HlsDownloader method addSegment.
private void addSegment(HlsMediaPlaylist mediaPlaylist, HlsMediaPlaylist.Segment segment, HashSet<Uri> seenEncryptionKeyUris, ArrayList<Segment> out) {
String baseUri = mediaPlaylist.baseUri;
long startTimeUs = mediaPlaylist.startTimeUs + segment.relativeStartTimeUs;
if (segment.fullSegmentEncryptionKeyUri != null) {
Uri keyUri = UriUtil.resolveToUri(baseUri, segment.fullSegmentEncryptionKeyUri);
if (seenEncryptionKeyUris.add(keyUri)) {
out.add(new Segment(startTimeUs, SegmentDownloader.getCompressibleDataSpec(keyUri)));
}
}
Uri segmentUri = UriUtil.resolveToUri(baseUri, segment.url);
DataSpec dataSpec = new DataSpec(segmentUri, segment.byteRangeOffset, segment.byteRangeLength);
out.add(new Segment(startTimeUs, dataSpec));
}
use of com.google.android.exoplayer2.metadata.mp4.SlowMotionData.Segment in project ExoPlayer by google.
the class DefaultHlsPlaylistTracker method getLoadedPlaylistDiscontinuitySequence.
private int getLoadedPlaylistDiscontinuitySequence(@Nullable HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
if (loadedPlaylist.hasDiscontinuitySequence) {
return loadedPlaylist.discontinuitySequence;
}
// TODO: Improve cross-playlist discontinuity adjustment.
int primaryUrlDiscontinuitySequence = primaryMediaPlaylistSnapshot != null ? primaryMediaPlaylistSnapshot.discontinuitySequence : 0;
if (oldPlaylist == null) {
return primaryUrlDiscontinuitySequence;
}
Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
if (firstOldOverlappingSegment != null) {
return oldPlaylist.discontinuitySequence + firstOldOverlappingSegment.relativeDiscontinuitySequence - loadedPlaylist.segments.get(0).relativeDiscontinuitySequence;
}
return primaryUrlDiscontinuitySequence;
}
Aggregations