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

Update setup and reset functions #2030

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/dash/DashHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ function DashHandler(config) {

function setup() {
log = Debug(context).getInstance().log.bind(instance);
index = -1;
currentTime = 0;
earliestTime = NaN;

resetInitialSettings();

segmentBaseLoader = isWebM(config.mimeType) ? WebmSegmentBaseLoader(context).getInstance() : SegmentBaseLoader(context).getInstance();
segmentBaseLoader.setConfig({
Expand Down Expand Up @@ -121,13 +120,18 @@ function DashHandler(config) {
return earliestTime;
}

function reset() {
segmentsGetter = null;
function resetInitialSettings() {
index = -1;
currentTime = 0;
earliestTime = NaN;
requestedTime = NaN;
index = -1;
streamProcessor = null;
segmentsGetter = null;
}

function reset() {
resetInitialSettings();

eventBus.off(Events.INITIALIZATION_LOADED, onInitializationLoaded, instance);
eventBus.off(Events.SEGMENTS_LOADED, onSegmentsLoaded, instance);
}
Expand Down
24 changes: 12 additions & 12 deletions src/dash/controllers/RepresentationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ function RepresentationController() {
manifestModel;

function setup() {
realAdaptation = null;
realAdaptationIndex = -1;
updating = true;
voAvailableRepresentations = [];
resetInitialSettings();

eventBus.on(Events.QUALITY_CHANGE_REQUESTED, onQualityChanged, instance);
eventBus.on(Events.REPRESENTATION_UPDATED, onRepresentationUpdated, instance);
Expand Down Expand Up @@ -128,14 +125,7 @@ function RepresentationController() {
return currentVoRepresentation;
}

function reset() {

eventBus.off(Events.QUALITY_CHANGE_REQUESTED, onQualityChanged, instance);
eventBus.off(Events.REPRESENTATION_UPDATED, onRepresentationUpdated, instance);
eventBus.off(Events.WALLCLOCK_TIME_UPDATED, onWallclockTimeUpdated, instance);
eventBus.off(Events.BUFFER_LEVEL_UPDATED, onBufferLevelUpdated, instance);


function resetInitialSettings() {
realAdaptation = null;
realAdaptationIndex = -1;
updating = true;
Expand All @@ -149,6 +139,16 @@ function RepresentationController() {
dashMetrics = null;
}

function reset() {

eventBus.off(Events.QUALITY_CHANGE_REQUESTED, onQualityChanged, instance);
eventBus.off(Events.REPRESENTATION_UPDATED, onRepresentationUpdated, instance);
eventBus.off(Events.WALLCLOCK_TIME_UPDATED, onWallclockTimeUpdated, instance);
eventBus.off(Events.BUFFER_LEVEL_UPDATED, onBufferLevelUpdated, instance);

resetInitialSettings();
}

function updateData(newRealAdaptation, voAdaptation, type) {
let quality,
averageThroughput;
Expand Down
20 changes: 10 additions & 10 deletions src/streaming/Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ function Stream(config) {
trackChangedEvent;

function setup() {
streamProcessors = [];
isStreamActivated = false;
isMediaInitialized = false;
streamInfo = null;
updateError = {};
isUpdating = false;
resetInitialSettings();

fragmentController = FragmentController(context).create({
mediaPlayerModel: mediaPlayerModel,
Expand Down Expand Up @@ -123,7 +118,7 @@ function Stream(config) {
* @memberof Stream#
*/
function deactivate() {
let ln = streamProcessors.length;
let ln = streamProcessors ? streamProcessors.length : 0;
for (let i = 0; i < ln; i++) {
streamProcessors[i].reset();
}
Expand All @@ -134,6 +129,13 @@ function Stream(config) {
eventBus.off(Events.CURRENT_TRACK_CHANGED, onCurrentTrackChanged, instance);
}

function resetInitialSettings() {
deactivate();
streamInfo = null;
updateError = {};
isUpdating = false;
}

function reset() {

if (playbackController) {
Expand All @@ -146,7 +148,7 @@ function Stream(config) {
fragmentController = null;
}

deactivate();
resetInitialSettings();
mediaController = null;
abrController = null;
manifestUpdater = null;
Expand All @@ -155,8 +157,6 @@ function Stream(config) {
capabilities = null;
log = null;
errHandler = null;
isUpdating = false;
updateError = {};

eventBus.off(Events.DATA_UPDATE_COMPLETED, onDataUpdateCompleted, instance);
eventBus.off(Events.BUFFERING_COMPLETED, onBufferingCompleted, instance);
Expand Down
17 changes: 9 additions & 8 deletions src/streaming/StreamProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ function StreamProcessor(config) {
spExternalControllers;

function setup() {
mediaInfoArr = [];
spExternalControllers = [];

liveEdgeFinder = LiveEdgeFinder(context).create({
timelineConverter: timelineConverter,
streamProcessor: instance
});
resetInitialSettings();
}

function initialize(mediaSource) {
Expand Down Expand Up @@ -153,6 +151,12 @@ function StreamProcessor(config) {
spExternalControllers = [];
}

function resetInitialSettings() {
mediaInfoArr = [];
mediaInfo = null;
unregisterAllExternalController();
}

function reset(errored) {

indexHandler.reset();
Expand All @@ -175,13 +179,10 @@ function StreamProcessor(config) {
spExternalControllers.forEach(function (controller) {
controller.reset();
});
unregisterAllExternalController();

stream = null;
mediaInfo = null;
mediaInfoArr = [];
resetInitialSettings();
type = null;

stream = null;
liveEdgeFinder.reset();
}

Expand Down
15 changes: 1 addition & 14 deletions src/streaming/controllers/AbrController.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,7 @@ function AbrController() {

function setup() {
log = debug.log.bind(instance);
autoSwitchBitrate = {video: true, audio: true};
topQualities = {};
qualityDict = {};
bitrateDict = {};
ratioDict = {};
abandonmentStateDict = {};
streamProcessorDict = {};
switchHistoryDict = {};
limitBitrateByPortal = false;
usePixelRatioInLimitBitrateByPortal = false;
if (windowResizeEventCalled === undefined) {
windowResizeEventCalled = false;
}

reset();
}

Expand Down Expand Up @@ -135,7 +123,6 @@ function AbrController() {
}

function reset() {
log = debug.log.bind(instance);
autoSwitchBitrate = {video: true, audio: true};
topQualities = {};
qualityDict = {};
Expand Down
16 changes: 4 additions & 12 deletions src/streaming/controllers/BufferController.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,8 @@ function BufferController(config) {

function setup() {
log = Debug(context).getInstance().log.bind(instance);
requiredQuality = AbrController.QUALITY_DEFAULT;
isBufferingCompleted = false;
bufferLevel = 0;
criticalBufferLevel = Number.POSITIVE_INFINITY;
maxAppendedIndex = 0;
lastIndex = Number.POSITIVE_INFINITY;
buffer = null;
bufferState = BUFFER_EMPTY;
wallclockTicked = 0;
appendingMediaChunk = false;
isAppendingInProgress = false;
isPruningInProgress = false;

reset();
}

function getBufferControllerType() {
Expand Down Expand Up @@ -498,6 +488,8 @@ function BufferController(config) {
isBufferingCompleted = false;
isAppendingInProgress = false;
isPruningInProgress = false;
bufferLevel = 0;
wallclockTicked = 0;

if (!errored) {
sourceBufferController.abort(mediaSource, buffer);
Expand Down
10 changes: 7 additions & 3 deletions src/streaming/controllers/FragmentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function FragmentController( config ) {
fragmentModels;

function setup() {
fragmentModels = {};
resetInitialSettings();
eventBus.on(Events.FRAGMENT_LOADING_COMPLETED, onFragmentLoadingCompleted, instance);
}

Expand All @@ -80,14 +80,18 @@ function FragmentController( config ) {
return (request && request.type && request.type === HTTPRequest.INIT_SEGMENT_TYPE);
}

function reset() {
eventBus.off(Events.FRAGMENT_LOADING_COMPLETED, onFragmentLoadingCompleted, this);
function resetInitialSettings() {
for (let model in fragmentModels) {
fragmentModels[model].reset();
}
fragmentModels = {};
}

function reset() {
eventBus.off(Events.FRAGMENT_LOADING_COMPLETED, onFragmentLoadingCompleted, this);
resetInitialSettings();
}

function createDataChunk(bytes, request, streamId) {
const chunk = new DataChunk();

Expand Down
24 changes: 11 additions & 13 deletions src/streaming/controllers/ScheduleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,8 @@ function ScheduleController(config) {

function setup() {
log = Debug(context).getInstance().log.bind(instance);
initialRequest = true;
lastInitQuality = NaN;
lastQualityIndex = NaN;
topQualityIndex = {};
replaceRequestArray = [];
isStopped = true;
playListMetrics = null;
playListTraceMetrics = null;
playListTraceMetricsClosed = true;
isFragmentProcessingInProgress = false;
timeToLoadDelay = 0;
seekTarget = NaN;

reset();
}


Expand Down Expand Up @@ -318,7 +308,7 @@ function ScheduleController(config) {
}

function completeQualityChange(trigger) {
if (playbackController) {
if (playbackController && fragmentModel) {
const item = fragmentModel.getRequests({
state: FragmentModel.FRAGMENT_MODEL_EXECUTED,
time: playbackController.getTime(),
Expand Down Expand Up @@ -614,6 +604,14 @@ function ScheduleController(config) {
timeToLoadDelay = 0;
seekTarget = NaN;
playListMetrics = null;
playListTraceMetrics = null;
playListTraceMetricsClosed = true;
initialRequest = true;
lastInitQuality = NaN;
lastQualityIndex = NaN;
topQualityIndex = {};
replaceRequestArray = [];
isStopped = true;
}

instance = {
Expand Down
38 changes: 19 additions & 19 deletions src/streaming/controllers/StreamController.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,11 @@ function StreamController() {
audioTrackDetected;

function setup() {
protectionController = null;
streams = [];
timeSyncController = TimeSyncController(context).getInstance();
baseURLController = BaseURLController(context).getInstance();
mediaSourceController = MediaSourceController(context).getInstance();
autoPlay = true;
isStreamSwitchingInProgress = false;
isPaused = false;
initialPlayback = true;
playListMetrics = null;
hasMediaError = false;
hasInitialisationError = false;

resetInitialSettings();
}

function initialize(autoPl, protData) {
Expand Down Expand Up @@ -706,8 +699,23 @@ function StreamController() {
}
}

function resetInitialSettings() {
streams = [];
protectionController = null;
isStreamSwitchingInProgress = false;
activeStream = null;
hasMediaError = false;
hasInitialisationError = false;
videoTrackDetected = undefined;
initialPlayback = true;
isPaused = false;
autoPlay = true;
playListMetrics = null;
}

function reset() {
checkSetConfigCall();

timeSyncController.reset();

flushPlaylistMetrics(
Expand All @@ -716,13 +724,11 @@ function StreamController() {
PlayListTrace.USER_REQUEST_STOP_REASON
);

for (let i = 0, ln = streams.length; i < ln; i++) {
for (let i = 0, ln = streams ? streams.length : 0; i < ln; i++) {
let stream = streams[i];
stream.reset(hasMediaError);
}

streams = [];

eventBus.off(Events.PLAYBACK_TIME_UPDATED, onPlaybackTimeUpdated, this);
eventBus.off(Events.PLAYBACK_SEEKING, onPlaybackSeeking, this);
eventBus.off(Events.PLAYBACK_ERROR, onPlaybackError, this);
Expand All @@ -740,13 +746,6 @@ function StreamController() {
manifestLoader.reset();
timelineConverter.reset();
initCache.reset();
isStreamSwitchingInProgress = false;
activeStream = null;
hasMediaError = false;
hasInitialisationError = false;
videoTrackDetected = undefined;
initialPlayback = true;
isPaused = false;

if (mediaSource) {
mediaSourceController.detachMediaSource(videoModel);
Expand All @@ -765,6 +764,7 @@ function StreamController() {
}

eventBus.trigger(Events.STREAM_TEARDOWN_COMPLETE);
resetInitialSettings();
}

function onMetricAdded(e) {
Expand Down
Loading