mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +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());
|
||||
}
|
||||
}
|
||||
int newSegmentsCount = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;
|
||||
if (newSegmentsCount == 0 && oldPlaylist.hasEndTag == newPlaylist.hasEndTag) {
|
||||
return oldPlaylist;
|
||||
}
|
||||
List<HlsMediaPlaylist.Segment> oldSegments = oldPlaylist.segments;
|
||||
int oldPlaylistSize = oldSegments.size();
|
||||
if (newSegmentsCount <= oldPlaylistSize) {
|
||||
ArrayList<HlsMediaPlaylist.Segment> newSegments = new ArrayList<>();
|
||||
int newPlaylistSize = newPlaylist.segments.size();
|
||||
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.
|
||||
int newPlaylistSize = newPlaylist.segments.size();
|
||||
for (int i = newSegmentsCount; i < oldPlaylistSize; i++) {
|
||||
ArrayList<HlsMediaPlaylist.Segment> newSegments = new ArrayList<>(newPlaylistSize);
|
||||
for (int i = mediaSequenceOffset; i < oldPlaylistSize; i++) {
|
||||
newSegments.add(oldSegments.get(i));
|
||||
}
|
||||
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.startTimeUs + lastSegment.durationUs);
|
||||
newSegments.add(lastSegment);
|
||||
|
Loading…
x
Reference in New Issue
Block a user