Skip to content

Commit

Permalink
Fix multiperiod representation update (#3337)
Browse files Browse the repository at this point in the history
* Move the logic whether to postpone the update of representations to the playback controller. This allows us to consider the current playback position for multiperiod streams.

* Keep logic for representation updates in RepresentationController but use playback controller and schedule controller to determine current period
  • Loading branch information
dsilhavy committed Jul 16, 2020
1 parent 857b49c commit b82c275
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
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

0 comments on commit b82c275

Please sign in to comment.