Skip to content

Commit

Permalink
Bugfix dashevents (#3242)
Browse files Browse the repository at this point in the history
* [Wip] Improve DASH event handling

* Move EventController.js to StreamController.js and migrate to Singleton
  • Loading branch information
dsilhavy authored and jeffcunat committed May 5, 2020
1 parent 46e1718 commit b226bec
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 184 deletions.
4 changes: 2 additions & 2 deletions src/dash/DashAdapter.js
Expand Up @@ -311,7 +311,7 @@ function DashAdapter() {
const duration = eventBox.event_duration;
const id = eventBox.id;
const messageData = eventBox.message_data;
const presentationTime = startTime * timescale + presentationTimeDelta;
const calculatedPresentationTime = startTime * timescale + presentationTimeDelta;

if (!eventStreams[schemeIdUri + '/' + value]) return null;

Expand All @@ -320,7 +320,7 @@ function DashAdapter() {
event.eventStream.timescale = timescale;
event.duration = duration;
event.id = id;
event.presentationTime = presentationTime;
event.calculatedPresentationTime = calculatedPresentationTime;
event.messageData = messageData;
event.presentationTimeDelta = presentationTimeDelta;

Expand Down
2 changes: 2 additions & 0 deletions src/dash/models/DashManifestModel.js
Expand Up @@ -808,6 +808,8 @@ function DashManifestModel() {

if (eventStreams[i].Event_asArray[j].hasOwnProperty(DashConstants.PRESENTATION_TIME)) {
event.presentationTime = eventStreams[i].Event_asArray[j].presentationTime;
const presentationTimeOffset = eventStream.presentationTimeOffset ? eventStream.presentationTimeOffset * eventStream.timescale : 0;
event.calculatedPresentationTime = event.presentationTime + (period.start * eventStream.timescale) + presentationTimeOffset;
}
if (eventStreams[i].Event_asArray[j].hasOwnProperty(DashConstants.DURATION)) {
event.duration = eventStreams[i].Event_asArray[j].duration;
Expand Down
52 changes: 12 additions & 40 deletions src/streaming/Stream.js
Expand Up @@ -31,7 +31,6 @@
import Constants from './constants/Constants';
import DashConstants from '../dash/constants/DashConstants';
import StreamProcessor from './StreamProcessor';
import EventController from './controllers/EventController';
import FragmentController from './controllers/FragmentController';
import ThumbnailController from './thumbnail/ThumbnailController';
import EventBus from '../core/EventBus';
Expand Down Expand Up @@ -60,6 +59,7 @@ function Stream(config) {
const dashMetrics = config.dashMetrics;
const abrController = config.abrController;
const playbackController = config.playbackController;
const eventController = config.eventController;
const mediaController = config.mediaController;
const textController = config.textController;
const videoModel = config.videoModel;
Expand All @@ -76,7 +76,6 @@ function Stream(config) {
protectionController,
fragmentController,
thumbnailController,
eventController,
preloaded,
boxParser,
debug,
Expand Down Expand Up @@ -204,7 +203,7 @@ function Stream(config) {
i++;
} else {
streamProcessors[i].reset();
streamProcessors.splice(i,1);
streamProcessors.splice(i, 1);
}
}

Expand All @@ -216,7 +215,7 @@ function Stream(config) {

if (streamProcessors.length === 0) {
const msg = 'No streams to play.';
errHandler.error(new DashJSError(Errors.MANIFEST_ERROR_ID_NOSTREAMS_CODE, msg + 'nostreams', manifestModel.getValue()));
errHandler.error(new DashJSError(Errors.MANIFEST_ERROR_ID_NOSTREAMS_CODE, msg + 'nostreams', manifestModel.getValue()));
logger.fatal(msg);
}
}
Expand All @@ -230,8 +229,6 @@ function Stream(config) {

function reset() {

stopEventController();

if (playbackController) {
playbackController.pause();
}
Expand Down Expand Up @@ -297,18 +294,6 @@ function Stream(config) {
return abrController.getBitrateList(mediaInfo);
}

function startEventController() {
if (eventController) {
eventController.start();
}
}

function stopEventController() {
if (eventController) {
eventController.stop();
}
}

function onProtectionError(event) {
if (event.error) {
errHandler.error(event.error);
Expand Down Expand Up @@ -488,25 +473,14 @@ function Stream(config) {
createStreamProcessor(initialMediaInfo, allMediaForType, mediaSource);
}

function initializeEventController () {
//if initializeMedia is called from a switch period, eventController could have been already created.
if (!eventController) {
eventController = EventController(context).create();

eventController.setConfig({
manifestUpdater: manifestUpdater,
playbackController: playbackController
});
addInlineEvents();
function addInlineEvents() {
if (eventController) {
const events = adapter.getEventsFor(streamInfo);
eventController.addInlineEvents(events);
}
}

function addInlineEvents () {
const events = adapter.getEventsFor(streamInfo);
eventController.addInlineEvents(events);
}

function addInbandEvents (events) {
function addInbandEvents(events) {
if (eventController) {
eventController.addInbandEvents(events);
}
Expand All @@ -516,7 +490,7 @@ function Stream(config) {
checkConfig();
let element = videoModel.getElement();

initializeEventController();
addInlineEvents();

isUpdating = true;

Expand Down Expand Up @@ -783,7 +757,7 @@ function Stream(config) {
}

function compareCodecs(newStream, type) {
if (!newStream || !newStream.hasOwnProperty('getStreamInfo') ) {
if (!newStream || !newStream.hasOwnProperty('getStreamInfo')) {
return false;
}
const newStreamInfo = newStream.getStreamInfo();
Expand All @@ -801,7 +775,7 @@ function Stream(config) {
return !newAdaptation && !currentAdaptation;
}

const sameMimeType = newAdaptation && currentAdaptation && newAdaptation.mimeType === currentAdaptation.mimeType;
const sameMimeType = newAdaptation && currentAdaptation && newAdaptation.mimeType === currentAdaptation.mimeType;
const oldCodecs = currentAdaptation.Representation_asArray.map((representation) => {
return representation.codecs;
});
Expand Down Expand Up @@ -844,7 +818,7 @@ function Stream(config) {
}

function preload(mediaSource, previousBuffers) {
initializeEventController();
addInlineEvents();

initializeMediaForType(Constants.VIDEO, mediaSource);
initializeMediaForType(Constants.AUDIO, mediaSource);
Expand Down Expand Up @@ -878,8 +852,6 @@ function Stream(config) {
getFragmentController: getFragmentController,
getThumbnailController: getThumbnailController,
getBitrateListFor: getBitrateListFor,
startEventController: startEventController,
stopEventController: stopEventController,
updateData: updateData,
reset: reset,
getProcessors: getProcessors,
Expand Down

0 comments on commit b226bec

Please sign in to comment.