mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Tweak live-streaming track selection logic.
Follow-up on the update to ABR logic in AdaptiveTrackSelection for live streaming case: - Do not reset liveEdgeTimeUs when user seek to a different position. - For HlsChunkSource, for non-independent segments, currently the bufferedDuration calculate will subtract previousChunk's duration. So to make it work with live-streaming ABR logic, we subtract timeToLiveEdgeUs a similar amount to compensate for that operation. - Minor update to DefaultSSChunkSource, only perform TrackSelection when needed (after checking necessary conditions). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=169531275
This commit is contained in:
parent
d71400d280
commit
324339b88f
3 changed files with 25 additions and 21 deletions
|
|
@ -181,7 +181,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
long bufferedDurationUs = previous != null ? (previous.endTimeUs - playbackPositionUs) : 0;
|
long bufferedDurationUs = previous != null ? (previous.endTimeUs - playbackPositionUs) : 0;
|
||||||
long timeToLiveEdgeUs = resolveTimeToLiveEdgeUs(playbackPositionUs, previous == null);
|
long timeToLiveEdgeUs = resolveTimeToLiveEdgeUs(playbackPositionUs);
|
||||||
trackSelection.updateSelectedTrack(bufferedDurationUs, timeToLiveEdgeUs);
|
trackSelection.updateSelectedTrack(bufferedDurationUs, timeToLiveEdgeUs);
|
||||||
|
|
||||||
RepresentationHolder representationHolder =
|
RepresentationHolder representationHolder =
|
||||||
|
|
@ -385,9 +385,8 @@ public class DefaultDashChunkSource implements DashChunkSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long resolveTimeToLiveEdgeUs(long playbackPositionUs, boolean isAfterPositionReset) {
|
private long resolveTimeToLiveEdgeUs(long playbackPositionUs) {
|
||||||
boolean resolveTimeToLiveEdgePossible = manifest.dynamic
|
boolean resolveTimeToLiveEdgePossible = manifest.dynamic && liveEdgeTimeUs != C.TIME_UNSET;
|
||||||
&& !isAfterPositionReset && liveEdgeTimeUs != C.TIME_UNSET;
|
|
||||||
return resolveTimeToLiveEdgePossible ? liveEdgeTimeUs - playbackPositionUs : C.TIME_UNSET;
|
return resolveTimeToLiveEdgePossible ? liveEdgeTimeUs - playbackPositionUs : C.TIME_UNSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -209,14 +209,24 @@ import java.util.List;
|
||||||
int oldVariantIndex = previous == null ? C.INDEX_UNSET
|
int oldVariantIndex = previous == null ? C.INDEX_UNSET
|
||||||
: trackGroup.indexOf(previous.trackFormat);
|
: trackGroup.indexOf(previous.trackFormat);
|
||||||
expectedPlaylistUrl = null;
|
expectedPlaylistUrl = null;
|
||||||
// Unless segments are known to be independent, switching variant will require downloading
|
long bufferedDurationUs = previous == null ? 0 : previous.endTimeUs - playbackPositionUs;
|
||||||
// overlapping segments. Hence we use the start time of the previous chunk rather than its end
|
|
||||||
// time for this case.
|
long timeToLiveEdgeUs = resolveTimeToLiveEdgeUs(playbackPositionUs);
|
||||||
long bufferedDurationUs = previous == null ? 0 : Math.max(0,
|
if (previous != null && !independentSegments) {
|
||||||
(independentSegments ? previous.endTimeUs : previous.startTimeUs) - playbackPositionUs);
|
// Unless segments are known to be independent, switching variant will require downloading
|
||||||
|
// overlapping segments. Hence we will subtract previous chunk's duration from buffered
|
||||||
|
// duration.
|
||||||
|
// This may affect the live-streaming adaptive track selection logic, when we are comparing
|
||||||
|
// buffered duration to time to live edge to decide whether to switch. Therefore,
|
||||||
|
// we will subtract this same amount from timeToLiveEdgeUs as well.
|
||||||
|
long subtractedDurationUs = previous.getDurationUs();
|
||||||
|
bufferedDurationUs = Math.max(0, bufferedDurationUs - subtractedDurationUs);
|
||||||
|
if (timeToLiveEdgeUs != C.TIME_UNSET) {
|
||||||
|
timeToLiveEdgeUs = Math.max(0, timeToLiveEdgeUs - subtractedDurationUs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Select the variant.
|
// Select the variant.
|
||||||
long timeToLiveEdgeUs = resolveTimeToLiveEdgeUs(playbackPositionUs, previous == null);
|
|
||||||
trackSelection.updateSelectedTrack(bufferedDurationUs, timeToLiveEdgeUs);
|
trackSelection.updateSelectedTrack(bufferedDurationUs, timeToLiveEdgeUs);
|
||||||
int selectedVariantIndex = trackSelection.getSelectedIndexInTrackGroup();
|
int selectedVariantIndex = trackSelection.getSelectedIndexInTrackGroup();
|
||||||
|
|
||||||
|
|
@ -365,9 +375,8 @@ import java.util.List;
|
||||||
|
|
||||||
// Private methods.
|
// Private methods.
|
||||||
|
|
||||||
private long resolveTimeToLiveEdgeUs(long playbackPositionUs, boolean isAfterPositionReset) {
|
private long resolveTimeToLiveEdgeUs(long playbackPositionUs) {
|
||||||
final boolean resolveTimeToLiveEdgePossible = !isAfterPositionReset
|
final boolean resolveTimeToLiveEdgePossible = liveEdgeTimeUs != C.TIME_UNSET;
|
||||||
&& liveEdgeTimeUs != C.TIME_UNSET;
|
|
||||||
return resolveTimeToLiveEdgePossible ? liveEdgeTimeUs - playbackPositionUs : C.TIME_UNSET;
|
return resolveTimeToLiveEdgePossible ? liveEdgeTimeUs - playbackPositionUs : C.TIME_UNSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,10 +154,6 @@ public class DefaultSsChunkSource implements SsChunkSource {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long bufferedDurationUs = previous != null ? (previous.endTimeUs - playbackPositionUs) : 0;
|
|
||||||
long timeToLiveEdgeUs = resolveTimeToLiveEdgeUs(playbackPositionUs);
|
|
||||||
trackSelection.updateSelectedTrack(bufferedDurationUs, timeToLiveEdgeUs);
|
|
||||||
|
|
||||||
StreamElement streamElement = manifest.streamElements[elementIndex];
|
StreamElement streamElement = manifest.streamElements[elementIndex];
|
||||||
if (streamElement.chunkCount == 0) {
|
if (streamElement.chunkCount == 0) {
|
||||||
// There aren't any chunks for us to load.
|
// There aren't any chunks for us to load.
|
||||||
|
|
@ -183,6 +179,10 @@ public class DefaultSsChunkSource implements SsChunkSource {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long bufferedDurationUs = previous != null ? (previous.endTimeUs - playbackPositionUs) : 0;
|
||||||
|
long timeToLiveEdgeUs = resolveTimeToLiveEdgeUs(playbackPositionUs);
|
||||||
|
trackSelection.updateSelectedTrack(bufferedDurationUs, timeToLiveEdgeUs);
|
||||||
|
|
||||||
long chunkStartTimeUs = streamElement.getStartTimeUs(chunkIndex);
|
long chunkStartTimeUs = streamElement.getStartTimeUs(chunkIndex);
|
||||||
long chunkEndTimeUs = chunkStartTimeUs + streamElement.getChunkDurationUs(chunkIndex);
|
long chunkEndTimeUs = chunkStartTimeUs + streamElement.getChunkDurationUs(chunkIndex);
|
||||||
int currentAbsoluteChunkIndex = chunkIndex + currentManifestChunkOffset;
|
int currentAbsoluteChunkIndex = chunkIndex + currentManifestChunkOffset;
|
||||||
|
|
@ -229,10 +229,6 @@ public class DefaultSsChunkSource implements SsChunkSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamElement currentElement = manifest.streamElements[elementIndex];
|
StreamElement currentElement = manifest.streamElements[elementIndex];
|
||||||
if (currentElement.chunkCount == 0) {
|
|
||||||
return C.TIME_UNSET;
|
|
||||||
}
|
|
||||||
|
|
||||||
int lastChunkIndex = currentElement.chunkCount - 1;
|
int lastChunkIndex = currentElement.chunkCount - 1;
|
||||||
long lastChunkEndTimeUs = currentElement.getStartTimeUs(lastChunkIndex)
|
long lastChunkEndTimeUs = currentElement.getStartTimeUs(lastChunkIndex)
|
||||||
+ currentElement.getChunkDurationUs(lastChunkIndex);
|
+ currentElement.getChunkDurationUs(lastChunkIndex);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue