Skip to content

Commit

Permalink
Fix multiperiod switching (#3581)
Browse files Browse the repository at this point in the history
* Fix multiperiod switches regarding controllers lifecycle (event listeners)

* Fix seeking listener in ScheduleController when switching period
  • Loading branch information
bbert authored Mar 30, 2021
1 parent e94f0e9 commit 84c552e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/streaming/controllers/BufferController.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ function BufferController(config) {
// START Buffer Level, State & Sufficiency Handling.
//**********************************************************************
function onPlaybackSeeking(e) {
if (!buffer) return;
seekTarget = e.seekTime;
if (isBufferingCompleted) {
seekClearedBufferingCompleted = true;
Expand All @@ -398,6 +399,7 @@ function BufferController(config) {

// Prune full buffer but what is around current time position
function pruneAllSafely() {
if (!buffer) return;
buffer.waitForUpdateEnd(() => {
const ranges = getAllRangesWithSafetyFactor();
if (!ranges || ranges.length === 0) {
Expand All @@ -409,6 +411,7 @@ function BufferController(config) {

// Get all buffer ranges but a range around current time position
function getAllRangesWithSafetyFactor() {
if (!buffer) return;
const clearRanges = [];
const ranges = buffer.getAllBufferRanges();
if (!ranges || ranges.length === 0) {
Expand Down
4 changes: 3 additions & 1 deletion src/streaming/controllers/PlaybackController.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,9 @@ function PlaybackController() {
logger.info('Native video element event: ended');
pause();
stopUpdatingWallclockTime();
eventBus.trigger(Events.PLAYBACK_ENDED, { 'isLast': streamController.getActiveStreamInfo().isLast });
const streamInfo = streamController ? streamController.getActiveStreamInfo() : null;
if (!streamInfo) return;
eventBus.trigger(Events.PLAYBACK_ENDED, { 'isLast': streamInfo.isLast });
}

// Handle DASH PLAYBACK_ENDED event
Expand Down
9 changes: 7 additions & 2 deletions src/streaming/controllers/ScheduleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ function ScheduleController(config) {
const abrController = config.abrController;
const playbackController = config.playbackController;
const textController = config.textController;
const streamInfo = config.streamInfo;
const type = config.type;
const mimeType = config.mimeType;
const mediaController = config.mediaController;
const bufferController = config.bufferController;
const settings = config.settings;

let instance,
streamInfo,
logger,
currentRepresentationInfo,
initialRequest,
Expand All @@ -80,6 +80,7 @@ function ScheduleController(config) {
function setup() {
logger = Debug(context).getInstance().getLogger(instance);
resetInitialSettings();
streamInfo = config.streamInfo;
}

function initialize(_hasVideoTrack) {
Expand Down Expand Up @@ -126,6 +127,7 @@ function ScheduleController(config) {
}

function start() {
if (!streamInfo) return;
if (isStarted()) return;
if (!currentRepresentationInfo || bufferController.getIsBufferingCompleted()) return;

Expand Down Expand Up @@ -163,6 +165,7 @@ function ScheduleController(config) {
}

function schedule() {
if (!streamInfo) return;
if (isStopped || isFragmentProcessingInProgress ||
(playbackController.isPaused() && !settings.get().streaming.scheduleWhilePaused) ||
((type === Constants.FRAGMENTED_TEXT || type === Constants.TEXT) && !textController.isTextEnabled()) ||
Expand Down Expand Up @@ -443,14 +446,15 @@ function ScheduleController(config) {
}

function onPlaybackSeeking(e) {
if (!streamInfo) return;
setSeekTarget(e.seekTime);
setTimeToLoadDelay(0);

if (isStopped) {
start();
}

const latency = currentRepresentationInfo.DVRWindow && playbackController ? currentRepresentationInfo.DVRWindow.end - playbackController.getTime() : NaN;
const latency = currentRepresentationInfo && currentRepresentationInfo.DVRWindow && playbackController ? currentRepresentationInfo.DVRWindow.end - playbackController.getTime() : NaN;
dashMetrics.updateManifestUpdateInfo({
latency: latency
});
Expand Down Expand Up @@ -524,6 +528,7 @@ function ScheduleController(config) {
stop();
completeQualityChange(false);
resetInitialSettings();
streamInfo = null;
}

function getPlaybackController() {
Expand Down

0 comments on commit 84c552e

Please sign in to comment.