Skip to content

Commit

Permalink
Fix a bug that lead to the BOLA rule requesting a wrong Representatio…
Browse files Browse the repository at this point in the history
…n after a track switch
  • Loading branch information
dsilhavy committed Feb 14, 2025
1 parent 92bb1ee commit de7e55e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/streaming/StreamProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ function StreamProcessor(config) {
});
}
currentMediaInfo = value;
abrController.handleNewMediaInfo(currentMediaInfo);
eventBus.trigger(Events.MEDIAINFO_UPDATED, {
mediaType: type,
streamId: streamInfo.id,
Expand Down
5 changes: 5 additions & 0 deletions src/streaming/controllers/AbrController.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,10 @@ function AbrController() {
abrRulesCollection.clearDataForStream(streamId);
}

function handleNewMediaInfo(newMediaInfo) {
abrRulesCollection.handleNewMediaInfo(newMediaInfo);
}


instance = {
checkPlaybackQuality,
Expand All @@ -861,6 +865,7 @@ function AbrController() {
getPossibleVoRepresentations,
getPossibleVoRepresentationsFilteredBySettings,
getRepresentationByAbsoluteIndex,
handleNewMediaInfo,
initialize,
isPlayingAtLowestQuality,
isPlayingAtTopQuality,
Expand Down
6 changes: 6 additions & 0 deletions src/streaming/rules/abr/ABRRulesCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,19 @@ function ABRRulesCollection(config) {
_updateRules()
}

function handleNewMediaInfo(newMediaInfo) {
qualitySwitchRules.forEach(rule => rule.handleNewMediaInfo && rule.handleNewMediaInfo(newMediaInfo));
abandonFragmentRules.forEach(rule => rule.handleNewMediaInfo && rule.handleNewMediaInfo(newMediaInfo));
}

instance = {
clearDataForStream,
getAbandonFragmentRules,
getBestPossibleSwitchRequest,
getBolaState,
getMinSwitchRequest,
getQualitySwitchRules,
handleNewMediaInfo,
initialize,
reset,
setBolaState,
Expand Down
14 changes: 6 additions & 8 deletions src/streaming/rules/abr/BolaRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function BolaRule(config) {
eventBus.on(MediaPlayerEvents.METRIC_ADDED, _onMetricAdded, instance);
eventBus.on(MediaPlayerEvents.QUALITY_CHANGE_REQUESTED, _onQualityChangeRequested, instance);
eventBus.on(MediaPlayerEvents.FRAGMENT_LOADING_ABANDONED, _onFragmentLoadingAbandoned, instance);
eventBus.on(MediaPlayerEvents.NEW_TRACK_SELECTED, _onNewTrackSelected, instance);
eventBus.on(Events.MEDIA_FRAGMENT_LOADED, _onMediaFragmentLoaded, instance);
eventBus.on(Events.SETTING_UPDATED_MAX_BITRATE, _onMinMaxBitrateUpdated, instance);
eventBus.on(Events.SETTING_UPDATED_MIN_BITRATE, _onMinMaxBitrateUpdated, instance);
Expand Down Expand Up @@ -446,13 +445,12 @@ function BolaRule(config) {
}
}

function _onNewTrackSelected(e) {
if (!e || !e.currentMediaInfo) {
return;
function handleNewMediaInfo(newMediaInfo) {
if (!newMediaInfo || !newMediaInfo.streamInfo || !newMediaInfo.type) {
return
}
const currentMediaInfo = e.currentMediaInfo;
if (bolaStateDict[currentMediaInfo.streamInfo.id] && bolaStateDict[currentMediaInfo.streamInfo.id][currentMediaInfo.type]) {
delete bolaStateDict[currentMediaInfo.streamInfo.id][currentMediaInfo.type];
if (bolaStateDict[newMediaInfo.streamInfo.id] && bolaStateDict[newMediaInfo.streamInfo.id][newMediaInfo.type]) {
delete bolaStateDict[newMediaInfo.streamInfo.id][newMediaInfo.type];
}
}

Expand Down Expand Up @@ -626,14 +624,14 @@ function BolaRule(config) {
eventBus.off(MediaPlayerEvents.METRIC_ADDED, _onMetricAdded, instance);
eventBus.off(MediaPlayerEvents.QUALITY_CHANGE_REQUESTED, _onQualityChangeRequested, instance);
eventBus.off(MediaPlayerEvents.FRAGMENT_LOADING_ABANDONED, _onFragmentLoadingAbandoned, instance);
eventBus.off(MediaPlayerEvents.NEW_TRACK_SELECTED, _onNewTrackSelected, instance);
eventBus.off(Events.MEDIA_FRAGMENT_LOADED, _onMediaFragmentLoaded, instance);
eventBus.off(Events.SETTING_UPDATED_MAX_BITRATE, _onMinMaxBitrateUpdated, instance);
eventBus.off(Events.SETTING_UPDATED_MIN_BITRATE, _onMinMaxBitrateUpdated, instance);
}

instance = {
getSwitchRequest,
handleNewMediaInfo,
reset
};

Expand Down

0 comments on commit de7e55e

Please sign in to comment.