Skip to content

Commit

Permalink
Better implement diff in track_dispatcher for workers
Browse files Browse the repository at this point in the history
  • Loading branch information
peaBerberian committed Aug 31, 2023
1 parent 956466f commit 7b60f64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 12 additions & 8 deletions src/core/api/track_management/track_dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ import {
* @class TrackDispatcher
*/
export default class TrackDispatcher extends EventEmitter<ITrackDispatcherEvent> {
public onManifestUpdate: () => void;
public onDeciperabilityUpdate: () => void;
/**
* Force the `TrackDispatcher` to re-consider the current track.
* Should be called when any information on the track had a chance to change,
* especially:
* - after a Manifest update
* - after one or several of its Representation were found to be either
* unsupported or undecipherable.
*/
public refresh: () => void;

/**
* Reference through which the wanted track will be emitted.
Expand Down Expand Up @@ -83,8 +90,7 @@ export default class TrackDispatcher extends EventEmitter<ITrackDispatcherEvent>
this._canceller = new TaskCanceller();
this._adaptationRef = adaptationRef;
this._updateToken = false;
this.onManifestUpdate = noop;
this.onDeciperabilityUpdate = noop;
this.refresh = noop;
}

/**
Expand Down Expand Up @@ -162,8 +168,7 @@ export default class TrackDispatcher extends EventEmitter<ITrackDispatcherEvent>

/* eslint-disable-next-line @typescript-eslint/no-this-alias */
const self = this;
this.onManifestUpdate = updateReferenceIfNeeded;
this.onDeciperabilityUpdate = updateReferenceIfNeeded;
this.refresh = updateReferenceIfNeeded;
this._canceller.signal.register(removeListeners);
trackInfo.lockedRepresentations.onUpdate(updateReferenceIfNeeded, {
clearSignal: this._canceller.signal,
Expand Down Expand Up @@ -222,8 +227,7 @@ export default class TrackDispatcher extends EventEmitter<ITrackDispatcherEvent>
}

function removeListeners() {
self.onManifestUpdate = noop;
self.onDeciperabilityUpdate = noop;
self.refresh = noop;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/api/track_management/tracks_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ export default class TracksStore extends EventEmitter<ITracksStoreEvents> {
}

for (const storedPeriodInfo of this._storedPeriodInfo) {
storedPeriodInfo.audio.dispatcher?.onManifestUpdate();
storedPeriodInfo.video.dispatcher?.onManifestUpdate();
storedPeriodInfo.text.dispatcher?.onManifestUpdate();
storedPeriodInfo.audio.dispatcher?.refresh();
storedPeriodInfo.video.dispatcher?.refresh();
storedPeriodInfo.text.dispatcher?.refresh();
}
}

Expand Down

0 comments on commit 7b60f64

Please sign in to comment.