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

[Code refactoring] remove circular dependencies #3256

4 changes: 3 additions & 1 deletion src/core/events/CoreEvents.js
Expand Up @@ -52,7 +52,7 @@ class CoreEvents extends EventsBase {
this.INBAND_EVENTS = 'inbandEvents';
this.INITIALIZATION_LOADED = 'initializationLoaded';
this.INIT_FRAGMENT_LOADED = 'initFragmentLoaded';
this.INIT_REQUESTED = 'initRequested';
this.INIT_FRAGMENT_NEEDED = 'initFragmentNeeded';
this.INTERNAL_MANIFEST_LOADED = 'internalManifestLoaded';
this.ORIGINAL_MANIFEST_LOADED = 'originalManifestLoaded';
this.LIVE_EDGE_SEARCH_COMPLETED = 'liveEdgeSearchCompleted';
Expand All @@ -62,6 +62,7 @@ class CoreEvents extends EventsBase {
this.LOADING_ABANDONED = 'loadingAborted';
this.MANIFEST_UPDATED = 'manifestUpdated';
this.MEDIA_FRAGMENT_LOADED = 'mediaFragmentLoaded';
this.MEDIA_FRAGMENT_NEEDED = 'mediaFragmentNeeded';
this.QUOTA_EXCEEDED = 'quotaExceeded';
this.REPRESENTATION_UPDATE_STARTED = 'representationUpdateStarted';
this.REPRESENTATION_UPDATE_COMPLETED = 'representationUpdateCompleted';
Expand All @@ -82,6 +83,7 @@ class CoreEvents extends EventsBase {
this.XLINK_READY = 'xlinkReady';
this.SEGMENTBASE_INIT_REQUEST_NEEDED = 'segmentBaseInitRequestNeeded';
this.SEGMENTBASE_SEGMENTSLIST_REQUEST_NEEDED = 'segmentBaseSegmentsListRequestNeeded';
this.SEEK_TARGET = 'seekTarget';
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/dash/DashMetrics.js
Expand Up @@ -466,7 +466,7 @@ function DashMetrics(config) {
playListTraceMetrics.representationid = representationId;
playListTraceMetrics.start = new Date();
playListTraceMetrics.mstart = mediaStartTime;
playListTraceMetrics.playbackspeed = speed;
playListTraceMetrics.playbackspeed = speed !== null ? speed.toString() : null;
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/dash/controllers/RepresentationController.js
Expand Up @@ -62,8 +62,7 @@ function RepresentationController(config) {
}

function checkConfig() {
if (!abrController || !dashMetrics || !playbackController ||
!timelineConverter) {
if (!abrController || !dashMetrics || !playbackController || !timelineConverter) {
throw new Error(Constants.MISSING_CONFIG_ERROR);
}
}
Expand Down Expand Up @@ -237,8 +236,7 @@ function RepresentationController(config) {
err,
repSwitch;

if (r.adaptation.period.mpd.manifest.type === dashConstants.DYNAMIC && !r.adaptation.period.mpd.manifest.ignorePostponeTimePeriod)
{
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.computeLiveDelay(currentVoRepresentation.segmentDuration, streamInfo.manifestInfo.DVRWindowSize);
Expand Down
11 changes: 7 additions & 4 deletions src/mss/MssHandler.js
Expand Up @@ -36,6 +36,7 @@ import MssFragmentProcessor from './MssFragmentProcessor';
import MssParser from './parser/MssParser';
import MssErrors from './errors/MssErrors';
import DashJSError from '../streaming/vo/DashJSError';
import InitCache from '../streaming/utils/InitCache';

function MssHandler(config) {

Expand All @@ -62,10 +63,12 @@ function MssHandler(config) {
});
let mssParser,
fragmentInfoControllers,
initCache,
instance;

function setup() {
fragmentInfoControllers = [];
initCache = InitCache(context).getInstance();
}

function getStreamProcessor(type) {
Expand Down Expand Up @@ -128,8 +131,8 @@ function MssHandler(config) {
fragmentInfoControllers = [];
}

function onInitializationRequested(e) {
let streamProcessor = getStreamProcessor(e.mediaType);
function onInitFragmentNeeded(e) {
let streamProcessor = getStreamProcessor(e.sender.getType());
if (!streamProcessor) return;

// Create init segment request
Expand Down Expand Up @@ -208,15 +211,15 @@ function MssHandler(config) {
}

function registerEvents() {
eventBus.on(events.INIT_REQUESTED, onInitializationRequested, instance, dashjs.FactoryMaker.getSingletonFactoryByName(eventBus.getClassName()).EVENT_PRIORITY_HIGH); /* jshint ignore:line */
eventBus.on(events.INIT_FRAGMENT_NEEDED, onInitFragmentNeeded, instance, dashjs.FactoryMaker.getSingletonFactoryByName(eventBus.getClassName()).EVENT_PRIORITY_HIGH); /* jshint ignore:line */
eventBus.on(events.PLAYBACK_PAUSED, onPlaybackPaused, instance, dashjs.FactoryMaker.getSingletonFactoryByName(eventBus.getClassName()).EVENT_PRIORITY_HIGH); /* jshint ignore:line */
eventBus.on(events.PLAYBACK_SEEK_ASKED, onPlaybackSeekAsked, instance, dashjs.FactoryMaker.getSingletonFactoryByName(eventBus.getClassName()).EVENT_PRIORITY_HIGH); /* jshint ignore:line */
eventBus.on(events.FRAGMENT_LOADING_COMPLETED, onSegmentMediaLoaded, instance, dashjs.FactoryMaker.getSingletonFactoryByName(eventBus.getClassName()).EVENT_PRIORITY_HIGH); /* jshint ignore:line */
eventBus.on(events.TTML_TO_PARSE, onTTMLPreProcess, instance);
}

function reset() {
eventBus.off(events.INIT_REQUESTED, onInitializationRequested, this);
eventBus.off(events.INIT_FRAGMENT_NEEDED, onInitFragmentNeeded, this);
eventBus.off(events.PLAYBACK_PAUSED, onPlaybackPaused, this);
eventBus.off(events.PLAYBACK_SEEK_ASKED, onPlaybackSeekAsked, this);
eventBus.off(events.FRAGMENT_LOADING_COMPLETED, onSegmentMediaLoaded, this);
Expand Down
35 changes: 26 additions & 9 deletions src/streaming/Stream.js
Expand Up @@ -71,6 +71,8 @@ function Stream(config) {
isStreamActivated,
isMediaInitialized,
streamInfo,
hasVideoTrack,
hasAudioTrack,
updateError,
isUpdating,
protectionController,
Expand Down Expand Up @@ -225,6 +227,8 @@ function Stream(config) {
function resetInitialSettings() {
deactivate();
streamInfo = null;
hasVideoTrack = false;
hasAudioTrack = false;
updateError = {};
isUpdating = false;
}
Expand Down Expand Up @@ -265,6 +269,14 @@ function Stream(config) {
return streamInfo;
}

function getHasAudioTrack () {
return hasAudioTrack;
}

function getHasVideoTrack () {
return hasVideoTrack;
}

function getThumbnailController() {
return thumbnailController;
}
Expand Down Expand Up @@ -343,7 +355,7 @@ function Stream(config) {
logger.info('Stream - Process track changed at current time ' + currentTime);

logger.debug('Stream - Update stream controller');
if (manifest.refreshManifestOnSwitchTrack) {
if (manifest.refreshManifestOnSwitchTrack) { // Applies only for MSS streams
logger.debug('Stream - Refreshing manifest for switch track');
trackChangedEvent = e;
manifestUpdater.refreshManifest();
Expand Down Expand Up @@ -379,14 +391,13 @@ function Stream(config) {
abrController: abrController,
playbackController: playbackController,
mediaController: mediaController,
streamController: config.streamController,
textController: textController,
errHandler: errHandler,
settings: settings,
boxParser: boxParser
});

streamProcessor.initialize(mediaSource);
streamProcessor.initialize(mediaSource, hasVideoTrack);
abrController.updateTopQualityIndex(mediaInfo);

if (optionalSettings) {
Expand Down Expand Up @@ -426,6 +437,14 @@ function Stream(config) {
return;
}

if (type === Constants.VIDEO) {
hasVideoTrack = true;
}

if (type === Constants.AUDIO) {
hasAudioTrack = true;
}

for (let i = 0, ln = allMediaForType.length; i < ln; i++) {
mediaInfo = allMediaForType[i];

Expand Down Expand Up @@ -592,9 +611,7 @@ function Stream(config) {
if (error) {
errHandler.error(error);
} else {
eventBus.trigger(Events.STREAM_INITIALIZED, {
streamInfo: streamInfo
});
eventBus.trigger(Events.STREAM_INITIALIZED, { streamInfo: streamInfo });
}
}

Expand Down Expand Up @@ -624,9 +641,7 @@ function Stream(config) {
}

function onBufferingCompleted(e) {
if (e.streamInfo !== streamInfo) {
return;
}
if (e.streamId !== streamInfo.id) return;

let processors = getProcessors();
const ln = processors.length;
Expand Down Expand Up @@ -856,6 +871,8 @@ function Stream(config) {
getStartTime: getStartTime,
getId: getId,
getStreamInfo: getStreamInfo,
getHasAudioTrack: getHasAudioTrack,
getHasVideoTrack: getHasVideoTrack,
preload: preload,
getThumbnailController: getThumbnailController,
getBitrateListFor: getBitrateListFor,
Expand Down