Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiperiod representation update #3337

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 27 additions & 6 deletions src/dash/controllers/RepresentationController.js
Expand Up @@ -177,7 +177,10 @@ function RepresentationController(config) {
for (let i = 0, ln = voAvailableRepresentations.length; i < ln; i++) {
updateRepresentation(voAvailableRepresentations[i], isDynamic);
if (notifyUpdate) {
eventBus.trigger(events.REPRESENTATION_UPDATE_STARTED, { sender: instance, representation: voAvailableRepresentations[i]});
eventBus.trigger(events.REPRESENTATION_UPDATE_STARTED, {
sender: instance,
representation: voAvailableRepresentations[i]
});
}
}
}
Expand All @@ -190,7 +193,7 @@ function RepresentationController(config) {

function startDataUpdate() {
updating = true;
eventBus.trigger(events.DATA_UPDATE_STARTED, { sender: instance });
eventBus.trigger(events.DATA_UPDATE_STARTED, {sender: instance});
}

function endDataUpdate(error) {
Expand All @@ -215,7 +218,7 @@ function RepresentationController(config) {

updateAvailabilityWindow(playbackController.getIsDynamic(), true);
};
eventBus.trigger(events.AST_IN_FUTURE, { delay: delay });
eventBus.trigger(events.AST_IN_FUTURE, {delay: delay});
setTimeout(update, delay);
}

Expand All @@ -237,10 +240,8 @@ function RepresentationController(config) {
repSwitch;

if (r.adaptation.period.mpd.manifest.type === dashConstants.DYNAMIC && !r.adaptation.period.mpd.manifest.ignorePostponeTimePeriod) {
let segmentAvailabilityTimePeriod = r.segmentAvailabilityRange.end - r.segmentAvailabilityRange.start;
// We must put things to sleep unless till e.g. the startTime calculation in ScheduleController.onLiveEdgeSearchCompleted fall after the segmentAvailabilityRange.start
let liveDelay = playbackController.getLiveDelay();
postponeTimePeriod = (liveDelay - segmentAvailabilityTimePeriod) * 1000;
postponeTimePeriod = getRepresentationUpdatePostponeTimePeriod(r, streamInfo);
}

if (postponeTimePeriod > 0) {
Expand Down Expand Up @@ -277,6 +278,26 @@ function RepresentationController(config) {
}
}

function getRepresentationUpdatePostponeTimePeriod(representation, streamInfo) {
try {
const streamController = playbackController.getStreamController();
const activeStreamInfo = streamController.getActiveStreamInfo();
let startTimeAnchor = representation.segmentAvailabilityRange.start;

if (activeStreamInfo && activeStreamInfo.id && activeStreamInfo.id !== streamInfo.id) {
// We need to consider the currently playing period if a period switch is performed.
startTimeAnchor = Math.min(playbackController.getTime(), startTimeAnchor);
}

let segmentAvailabilityTimePeriod = representation.segmentAvailabilityRange.end - startTimeAnchor;
let liveDelay = playbackController.getLiveDelay();

return (liveDelay - segmentAvailabilityTimePeriod) * 1000;
} catch (e) {
return 0;
}
}

function onWallclockTimeUpdated(e) {
if (e.isDynamic) {
updateAvailabilityWindow(e.isDynamic);
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/controllers/PlaybackController.js
Expand Up @@ -623,7 +623,7 @@ function PlaybackController() {
const liveCatchupLatencyThreshold = mediaPlayerModel.getLiveCatchupLatencyThreshold();

return settings.get().streaming.lowLatencyEnabled && settings.get().streaming.liveCatchUpPlaybackRate > 0 && getTime() > 0 &&
latencyDrift > settings.get().streaming.liveCatchUpMinDrift && (isNaN(liveCatchupLatencyThreshold) || currentLiveLatency <= liveCatchupLatencyThreshold ) ;
latencyDrift > settings.get().streaming.liveCatchUpMinDrift && (isNaN(liveCatchupLatencyThreshold) || currentLiveLatency <= liveCatchupLatencyThreshold);
}

function startPlaybackCatchUp() {
Expand Down