mirror of
https://github.com/androidx/media.git
synced 2025-05-04 06:00:37 +08:00
Allow playlists of different size in HlsPlaylistTracker playlist adjustment
Issue:#2059 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=139331670
This commit is contained in:
parent
0effffb89f
commit
d6eb9cb79f
@ -294,21 +294,23 @@ public final class HlsPlaylistTracker implements Loader.Callback<ParsingLoadable
|
|||||||
return newPlaylist.copyWithStartTimeUs(primaryPlaylistSnapshot.getStartTimeUs());
|
return newPlaylist.copyWithStartTimeUs(primaryPlaylistSnapshot.getStartTimeUs());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int newSegmentsCount = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;
|
|
||||||
if (newSegmentsCount == 0 && oldPlaylist.hasEndTag == newPlaylist.hasEndTag) {
|
|
||||||
return oldPlaylist;
|
|
||||||
}
|
|
||||||
List<HlsMediaPlaylist.Segment> oldSegments = oldPlaylist.segments;
|
List<HlsMediaPlaylist.Segment> oldSegments = oldPlaylist.segments;
|
||||||
int oldPlaylistSize = oldSegments.size();
|
int oldPlaylistSize = oldSegments.size();
|
||||||
if (newSegmentsCount <= oldPlaylistSize) {
|
int newPlaylistSize = newPlaylist.segments.size();
|
||||||
ArrayList<HlsMediaPlaylist.Segment> newSegments = new ArrayList<>();
|
int mediaSequenceOffset = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;
|
||||||
|
if (newPlaylistSize == oldPlaylistSize && mediaSequenceOffset == 0
|
||||||
|
&& oldPlaylist.hasEndTag == newPlaylist.hasEndTag) {
|
||||||
|
// Playlist has not changed.
|
||||||
|
return oldPlaylist;
|
||||||
|
}
|
||||||
|
if (mediaSequenceOffset <= oldPlaylistSize) {
|
||||||
// We can extrapolate the start time of new segments from the segments of the old snapshot.
|
// We can extrapolate the start time of new segments from the segments of the old snapshot.
|
||||||
int newPlaylistSize = newPlaylist.segments.size();
|
ArrayList<HlsMediaPlaylist.Segment> newSegments = new ArrayList<>(newPlaylistSize);
|
||||||
for (int i = newSegmentsCount; i < oldPlaylistSize; i++) {
|
for (int i = mediaSequenceOffset; i < oldPlaylistSize; i++) {
|
||||||
newSegments.add(oldSegments.get(i));
|
newSegments.add(oldSegments.get(i));
|
||||||
}
|
}
|
||||||
HlsMediaPlaylist.Segment lastSegment = oldSegments.get(oldPlaylistSize - 1);
|
HlsMediaPlaylist.Segment lastSegment = oldSegments.get(oldPlaylistSize - 1);
|
||||||
for (int i = newPlaylistSize - newSegmentsCount; i < newPlaylistSize; i++) {
|
for (int i = newSegments.size(); i < newPlaylistSize; i++) {
|
||||||
lastSegment = newPlaylist.segments.get(i).copyWithStartTimeUs(
|
lastSegment = newPlaylist.segments.get(i).copyWithStartTimeUs(
|
||||||
lastSegment.startTimeUs + lastSegment.durationUs);
|
lastSegment.startTimeUs + lastSegment.durationUs);
|
||||||
newSegments.add(lastSegment);
|
newSegments.add(lastSegment);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user