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

Refactoring code #3166

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7bc1f96
remove unused reference
nicosang Oct 9, 2019
43ba44e
when an init data is needed, scheduleController has to send an event …
nicosang Oct 10, 2019
f089bf5
reduce streamProcessors reference in ScheduleController
nicosang Oct 11, 2019
fb1603e
setLiveEdgeSeekTarget has been moved in StreamProcessor class
nicosang Oct 11, 2019
fc22f8a
INIT_FRAGMENT_LOADED and MEDIA_FRAGMENT_LOADED events don't need to u…
nicosang Oct 11, 2019
855b030
reduce references to streamProcessor
nicosang Oct 14, 2019
8d33454
when an init data is needed, scheduleController has to send an event …
nicosang Oct 10, 2019
76feb32
reduce streamProcessors reference in ScheduleController
nicosang Oct 11, 2019
dc809d7
setLiveEdgeSeekTarget has been moved in StreamProcessor class
nicosang Oct 11, 2019
543e43f
reduce references to streamProcessor
nicosang Oct 14, 2019
48d619a
update STREAM_COMPLETED event
nicosang Oct 14, 2019
2966f9d
request element was missing in INIT_FRAGMENT_LOADED
nicosang Oct 15, 2019
d567d28
reduce streamProcessor reference
nicosang Oct 15, 2019
a755c5a
add removeExecutedRequestsBeforeTime function in StreamProcessor class
Oct 25, 2019
da92a22
remove getFragmentController function
nicosang Nov 4, 2019
bfefdfe
add removeExecutedRequestsAfterTime and abortRequests functions to St…
nicosang Nov 4, 2019
d831da2
add getRequests function to StreamProcessor
nicosang Nov 4, 2019
49b6088
add NEW_FRAGMENT_NEEDED event, remove NextFragmentRequestRule
nicosang Nov 4, 2019
40704c4
reduce streamProcessor references in BufferController, add ADD_INBAND…
nicosang Nov 5, 2019
be9526a
update tests in OnMediaFragmentLoaded callback
nicosang Nov 5, 2019
7ae827c
add isMediaSegmentRequest function
Nov 19, 2019
7ebde64
fix after rebase
bbert Mar 17, 2020
e176e35
update PR to force CircleCi build
bbert Mar 25, 2020
1eed10d
update PR to force CircleCi build
bbert Mar 25, 2020
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
4 changes: 3 additions & 1 deletion src/core/events/CoreEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class CoreEvents extends EventsBase {
this.DATA_UPDATE_STARTED = 'dataUpdateStarted';
this.INITIALIZATION_LOADED = 'initializationLoaded';
this.INIT_FRAGMENT_LOADED = 'initFragmentLoaded';
this.INIT_REQUESTED = 'initRequested';
this.INIT_DATA_NEEDED = 'initDataNeeded';
this.NEW_FRAGMENT_NEEDED = 'newFragmentNeeded';
this.INTERNAL_MANIFEST_LOADED = 'internalManifestLoaded';
this.LIVE_EDGE_SEARCH_COMPLETED = 'liveEdgeSearchCompleted';
this.LOADING_COMPLETED = 'loadingCompleted';
Expand Down Expand Up @@ -80,6 +81,7 @@ class CoreEvents extends EventsBase {
this.XLINK_READY = 'xlinkReady';
this.SEGMENTBASE_INIT_REQUEST_NEEDED = 'segmentBaseInitRequestNeeded';
this.SEGMENTBASE_SEGMENTSLIST_REQUEST_NEEDED = 'segmentBaseSegmentsListRequestNeeded';
this.ADD_INBAND_EVENTS_REQUESTED = 'addInbandEventsRequested';
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/dash/controllers/RepresentationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ function RepresentationController() {
timelineConverter,
dashMetrics,
type,
streamId,
manifestModel;
streamId;

function setup() {
resetInitialSettings();
Expand All @@ -76,9 +75,6 @@ function RepresentationController() {
if (config.timelineConverter) {
timelineConverter = config.timelineConverter;
}
if (config.manifestModel) {
manifestModel = config.manifestModel;
}
if (config.type) {
type = config.type;
}
Expand All @@ -89,7 +85,7 @@ function RepresentationController() {

function checkConfig() {
if (!abrController || !dashMetrics || !playbackController ||
!timelineConverter || !manifestModel) {
!timelineConverter) {
throw new Error(Constants.MISSING_CONFIG_ERROR);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mss/MssFragmentInfoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function MssFragmentInfoController(config) {
function requestFragment(request) {

logger.debug('Load fragment for time: ' + request.startTime);
if (streamProcessor.getFragmentModel().isFragmentLoadedOrPending(request)) {
if (fragmentModel.isFragmentLoadedOrPending(request)) {
// We may have reached end of timeline in case of start-over streams
logger.debug('No more fragments');
return;
Expand Down
2 changes: 1 addition & 1 deletion src/mss/MssFragmentProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function MssFragmentProcessor(config) {

let request = e.request;

if (request.type === 'MediaSegment') {
if (request.isMediaSegmentRequest()) {
// it's a MediaSegment, let's convert fragment
mssFragmentMoofProcessor.convertFragment(e, sp);

Expand Down
90 changes: 55 additions & 35 deletions src/mss/MssHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function MssHandler(config) {
let eventBus = config.eventBus;
const events = config.events;
const constants = config.constants;
const initCache = config.initCache;
const initSegmentType = config.initSegmentType;
let dashMetrics = config.dashMetrics;
let playbackController = config.playbackController;
Expand All @@ -64,34 +65,46 @@ function MssHandler(config) {
function setup() {}

function onInitializationRequested(e) {
let streamProcessor = e.sender.getStreamProcessor();
let request = new FragmentRequest();
let representationController = streamProcessor.getRepresentationController();
let representation = representationController.getCurrentRepresentation();

request.mediaType = representation.adaptation.type;
request.type = initSegmentType;
request.range = representation.range;
request.quality = representation.index;
request.mediaInfo = streamProcessor.getMediaInfo();
request.representationId = representation.id;

const chunk = createDataChunk(request, streamProcessor.getStreamInfo().id, e.type !== events.FRAGMENT_LOADING_PROGRESS);

try {
// Generate initialization segment (moov)
chunk.bytes = mssFragmentProcessor.generateMoov(representation);
} catch (e) {
config.errHandler.error(new DashJSError(e.code, e.message, e.data));
}
let streamController = playbackController.getStreamController();

eventBus.trigger(events.INIT_FRAGMENT_LOADED, {
chunk: chunk,
fragmentModel: streamProcessor.getFragmentModel()
});
if (streamController) {
let streamProcessor = streamController.getActiveStreamProcessors().find((sp) => {
return sp.getType() === e.sender.getType();
});
const streamInfo = streamProcessor.getStreamInfo();
const streamId = streamInfo ? streamInfo.id : null;
let representationController = streamProcessor.getRepresentationController();
let representation = representationController.getCurrentRepresentation();

const chunk = initCache.extract(streamId, representation.id);
//if chunk has already created, bufferController will push it from the cache directly, not need to build init segment again
if (!chunk) {
let request = new FragmentRequest();

request.mediaType = representation.adaptation.type;
request.type = initSegmentType;
request.range = representation.range;
request.quality = representation.index;
request.mediaInfo = streamProcessor.getMediaInfo();
request.representationId = representation.id;

const chunk = createDataChunk(request, streamId, e.type !== events.FRAGMENT_LOADING_PROGRESS);

try {
// Generate initialization segment (moov)
chunk.bytes = mssFragmentProcessor.generateMoov(representation);
} catch (e) {
config.errHandler.error(new DashJSError(e.code, e.message, e.data));
}

eventBus.trigger(events.INIT_FRAGMENT_LOADED, {
chunk: chunk
});

// Change the sender value to stop event to be propagated
e.sender = null;
// Change the representationId value to stop event to be propagated
e.representationId = null;
}
}
}

function createDataChunk(request, streamId, endFragment) {
Expand Down Expand Up @@ -157,14 +170,21 @@ function MssHandler(config) {
if (e.error) {
return;
}
// Process moof to transcode it from MSS to DASH
let streamProcessor = e.sender.getStreamProcessor();
mssFragmentProcessor.processFragment(e, streamProcessor);

// Start MssFragmentInfoControllers in case of start-over streams
let streamInfo = streamProcessor.getStreamInfo();
if (!streamInfo.manifestInfo.isDynamic && streamInfo.manifestInfo.DVRWindowSize !== Infinity) {
startFragmentInfoControllers();
let streamController = playbackController.getStreamController();

if (streamController) {
let streamProcessor = streamController.getActiveStreamProcessors().find((sp) => {
return sp.getType() === e.request.mediaType;
});
// Process moof to transcode it from MSS to DASH
mssFragmentProcessor.processFragment(e, streamProcessor);

// Start MssFragmentInfoControllers in case of start-over streams
let streamInfo = streamProcessor.getStreamInfo();
if (!streamInfo.manifestInfo.isDynamic && streamInfo.manifestInfo.DVRWindowSize !== Infinity) {
startFragmentInfoControllers();
}
}
}

Expand All @@ -189,15 +209,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_DATA_NEEDED, onInitializationRequested, 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_DATA_NEEDED, onInitializationRequested, 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
4 changes: 3 additions & 1 deletion src/streaming/MediaPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import AbrController from './controllers/AbrController';
import VideoModel from './models/VideoModel';
import CmcdModel from './models/CmcdModel';
import DOMStorage from './utils/DOMStorage';
import InitCache from './utils/InitCache';
import Debug from './../core/Debug';
import Errors from './../core/errors/Errors';
import EventBus from './../core/EventBus';
Expand Down Expand Up @@ -2009,7 +2010,8 @@ function MediaPlayer() {
initSegmentType: HTTPRequest.INIT_SEGMENT_TYPE,
BASE64: BASE64,
ISOBoxer: ISOBoxer,
settings: settings
settings: settings,
initCache: InitCache(context).getInstance()
});
}
}
Expand Down
24 changes: 11 additions & 13 deletions src/streaming/Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ function Stream(config) {
function registerEvents() {
eventBus.on(Events.BUFFERING_COMPLETED, onBufferingCompleted, instance);
eventBus.on(Events.DATA_UPDATE_COMPLETED, onDataUpdateCompleted, instance);
eventBus.on(Events.ADD_INBAND_EVENTS_REQUESTED, onAddInbandEventsRequested, instance);
}

function unRegisterEvents() {
eventBus.off(Events.DATA_UPDATE_COMPLETED, onDataUpdateCompleted, instance);
eventBus.off(Events.BUFFERING_COMPLETED, onBufferingCompleted, instance);
eventBus.off(Events.ADD_INBAND_EVENTS_REQUESTED, onAddInbandEventsRequested, instance);
}

function registerProtectionEvents() {
Expand Down Expand Up @@ -170,8 +172,7 @@ function Stream(config) {
let ln = streamProcessors ? streamProcessors.length : 0;
const errored = false;
for (let i = 0; i < ln; i++) {
let fragmentModel = streamProcessors[i].getFragmentModel();
fragmentModel.removeExecutedRequestsBeforeTime(getStartTime() + getDuration());
streamProcessors[i].removeExecutedRequestsBeforeTime(getStartTime() + getDuration());
streamProcessors[i].reset(errored, keepBuffers);
}
streamProcessors = [];
Expand Down Expand Up @@ -254,10 +255,6 @@ function Stream(config) {
return streamInfo;
}

function getFragmentController() {
return fragmentController;
}

function getThumbnailController() {
return thumbnailController;
}
Expand Down Expand Up @@ -357,7 +354,7 @@ function Stream(config) {
if (mediaInfo.type !== Constants.FRAGMENTED_TEXT) {
abrController.updateTopQualityIndex(mediaInfo);
processor.switchTrackAsked();
processor.getFragmentModel().abortRequests();
processor.abortRequests();
} else {
processor.getScheduleController().setSeekTarget(currentTime);
processor.setIndexHandlerTime(currentTime);
Expand Down Expand Up @@ -386,7 +383,8 @@ function Stream(config) {
settings: settings
});

streamProcessor.initialize(mediaSource);
streamProcessor.initialize(mediaSource, fragmentController.getModel(getId(), mediaInfo ? mediaInfo.type : null));

abrController.updateTopQualityIndex(mediaInfo);

if (optionalSettings) {
Expand Down Expand Up @@ -489,9 +487,11 @@ function Stream(config) {
eventController.addInlineEvents(events);
}

function addInbandEvents (events) {
function onAddInbandEventsRequested (eventObj) {
if (eventObj.sender.getStreamInfo() !== getStreamInfo()) return;

if (eventController) {
eventController.addInbandEvents(events);
eventController.addInbandEvents(eventObj.events);
}
}

Expand Down Expand Up @@ -858,7 +858,6 @@ function Stream(config) {
getId: getId,
getStreamInfo: getStreamInfo,
preload: preload,
getFragmentController: getFragmentController,
getThumbnailController: getThumbnailController,
getBitrateListFor: getBitrateListFor,
startEventController: startEventController,
Expand All @@ -869,8 +868,7 @@ function Stream(config) {
setMediaSource: setMediaSource,
isMediaCodecCompatible: isMediaCodecCompatible,
isProtectionCompatible: isProtectionCompatible,
getPreloaded: getPreloaded,
addInbandEvents: addInbandEvents
getPreloaded: getPreloaded
};

setup();
Expand Down
Loading