Fix janky post-track-selection behavior for HLS
We were forgetting to reset renderers during track selections where muxed media is used. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=128391816
This commit is contained in:
parent
0b4284d060
commit
75e2aee92e
@ -81,6 +81,7 @@ public final class HlsMediaSource implements MediaPeriod, MediaSource,
|
|||||||
|
|
||||||
private boolean seenFirstTrackSelection;
|
private boolean seenFirstTrackSelection;
|
||||||
private long durationUs;
|
private long durationUs;
|
||||||
|
private long pendingDiscontinuityPositionUs;
|
||||||
private boolean isLive;
|
private boolean isLive;
|
||||||
private TrackGroupArray trackGroups;
|
private TrackGroupArray trackGroups;
|
||||||
private int[] selectedTrackCounts;
|
private int[] selectedTrackCounts;
|
||||||
@ -104,6 +105,7 @@ public final class HlsMediaSource implements MediaPeriod, MediaSource,
|
|||||||
this.minLoadableRetryCount = minLoadableRetryCount;
|
this.minLoadableRetryCount = minLoadableRetryCount;
|
||||||
eventDispatcher = new EventDispatcher(eventHandler, eventListener);
|
eventDispatcher = new EventDispatcher(eventHandler, eventListener);
|
||||||
|
|
||||||
|
pendingDiscontinuityPositionUs = C.UNSET_TIME_US;
|
||||||
sampleStreamSources = new IdentityHashMap<>();
|
sampleStreamSources = new IdentityHashMap<>();
|
||||||
timestampAdjusterProvider = new PtsTimestampAdjusterProvider();
|
timestampAdjusterProvider = new PtsTimestampAdjusterProvider();
|
||||||
manifestParser = new HlsPlaylistParser();
|
manifestParser = new HlsPlaylistParser();
|
||||||
@ -177,7 +179,7 @@ public final class HlsMediaSource implements MediaPeriod, MediaSource,
|
|||||||
int enabledSampleStreamWrapperCount = 0;
|
int enabledSampleStreamWrapperCount = 0;
|
||||||
for (int i = 0; i < sampleStreamWrappers.length; i++) {
|
for (int i = 0; i < sampleStreamWrappers.length; i++) {
|
||||||
selectedTrackCounts[i] += selectTracks(sampleStreamWrappers[i], oldStreams, newSelections,
|
selectedTrackCounts[i] += selectTracks(sampleStreamWrappers[i], oldStreams, newSelections,
|
||||||
newStreams);
|
newStreams, positionUs);
|
||||||
if (selectedTrackCounts[i] > 0) {
|
if (selectedTrackCounts[i] > 0) {
|
||||||
enabledSampleStreamWrapperCount++;
|
enabledSampleStreamWrapperCount++;
|
||||||
}
|
}
|
||||||
@ -191,8 +193,9 @@ public final class HlsMediaSource implements MediaPeriod, MediaSource,
|
|||||||
enabledSampleStreamWrappers[enabledSampleStreamWrapperCount++] = sampleStreamWrappers[i];
|
enabledSampleStreamWrappers[enabledSampleStreamWrapperCount++] = sampleStreamWrappers[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (enabledSampleStreamWrapperCount > 0 && seenFirstTrackSelection
|
if (enabledSampleStreamWrapperCount == 0) {
|
||||||
&& !newSelections.isEmpty()) {
|
pendingDiscontinuityPositionUs = C.UNSET_TIME_US;
|
||||||
|
} else if (seenFirstTrackSelection && !newSelections.isEmpty()) {
|
||||||
seekToUs(positionUs);
|
seekToUs(positionUs);
|
||||||
}
|
}
|
||||||
seenFirstTrackSelection = true;
|
seenFirstTrackSelection = true;
|
||||||
@ -211,7 +214,9 @@ public final class HlsMediaSource implements MediaPeriod, MediaSource,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long readDiscontinuity() {
|
public long readDiscontinuity() {
|
||||||
return C.UNSET_TIME_US;
|
long result = pendingDiscontinuityPositionUs;
|
||||||
|
pendingDiscontinuityPositionUs = C.UNSET_TIME_US;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -419,7 +424,7 @@ public final class HlsMediaSource implements MediaPeriod, MediaSource,
|
|||||||
|
|
||||||
private int selectTracks(HlsSampleStreamWrapper sampleStreamWrapper,
|
private int selectTracks(HlsSampleStreamWrapper sampleStreamWrapper,
|
||||||
List<SampleStream> allOldStreams, List<TrackSelection> allNewSelections,
|
List<SampleStream> allOldStreams, List<TrackSelection> allNewSelections,
|
||||||
SampleStream[] allNewStreams) {
|
SampleStream[] allNewStreams, long positionUs) {
|
||||||
// Get the subset of the old streams for the source.
|
// Get the subset of the old streams for the source.
|
||||||
ArrayList<SampleStream> oldStreams = new ArrayList<>();
|
ArrayList<SampleStream> oldStreams = new ArrayList<>();
|
||||||
for (int i = 0; i < allOldStreams.size(); i++) {
|
for (int i = 0; i < allOldStreams.size(); i++) {
|
||||||
@ -444,6 +449,11 @@ public final class HlsMediaSource implements MediaPeriod, MediaSource,
|
|||||||
if (seenFirstTrackSelection && oldStreams.isEmpty() && newSelections.isEmpty()) {
|
if (seenFirstTrackSelection && oldStreams.isEmpty() && newSelections.isEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
// If there are other active SampleStreams provided by the wrapper then we need to report a
|
||||||
|
// discontinuity so that the consuming renderers are reset.
|
||||||
|
if (sampleStreamWrapper.getEnabledTrackCount() > oldStreams.size()) {
|
||||||
|
pendingDiscontinuityPositionUs = positionUs;
|
||||||
|
}
|
||||||
// Perform the selection.
|
// Perform the selection.
|
||||||
SampleStream[] newStreams = sampleStreamWrapper.selectTracks(oldStreams, newSelections,
|
SampleStream[] newStreams = sampleStreamWrapper.selectTracks(oldStreams, newSelections,
|
||||||
!seenFirstTrackSelection);
|
!seenFirstTrackSelection);
|
||||||
|
@ -143,6 +143,10 @@ import java.util.List;
|
|||||||
return chunkSource.getDurationUs();
|
return chunkSource.getDurationUs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getEnabledTrackCount() {
|
||||||
|
return enabledTrackCount;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isLive() {
|
public boolean isLive() {
|
||||||
return chunkSource.isLive();
|
return chunkSource.isLive();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user