Skip to content

Commit

Permalink
Merge pull request #1051 from AkamaiDASH/development
Browse files Browse the repository at this point in the history
Fix for #947
  • Loading branch information
Dan Sparacio authored and Dan Sparacio committed Jan 22, 2016
2 parents f8884e0 + ad46815 commit 3d95d06
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 70 deletions.
6 changes: 4 additions & 2 deletions samples/dash-if-reference-player/app/eme-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ app.controller('DashController', function($scope, Sources, Notes, Contributors,
if ($scope.selectedItem.hasOwnProperty("protData")) {
protectionData = $scope.selectedItem.protData;
}
player.attachSource($scope.selectedItem.url, null, protectionData);
player.setProtectionData(protectionData);
player.attachSource($scope.selectedItem.url);
player.setAutoSwitchQuality($scope.abrEnabled);
controlbar.reset();
controlbar.enable();
Expand Down Expand Up @@ -350,7 +351,8 @@ app.controller('DashController', function($scope, Sources, Notes, Contributors,
};

$scope.play = function(data) {
player.attachSource(data.manifest, data.protCtrl);
player.attachProtectionController(data.protCtrl)
player.attachSource(data.manifest);
for (var i = 0; i < $scope.drmData.length; i++) {
var drmData = $scope.drmData[i];
drmData.isPlaying = !!(drmData === data);
Expand Down
6 changes: 3 additions & 3 deletions samples/dash-if-reference-player/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,12 +653,12 @@ app.controller('DashController', function($scope, Sources, Notes, Contributors,
}

$scope.doLoad = function () {
var protData = null,
initialSettings;
var protData = null;
if ($scope.selectedItem.hasOwnProperty("protData")) {
protData = $scope.selectedItem.protData;
}
player.attachSource($scope.selectedItem.url, null, protData);
player.setProtectionData(protData);
player.attachSource($scope.selectedItem.url);
player.setAutoSwitchQuality($scope.abrEnabled);
controlbar.reset();
controlbar.enable();
Expand Down
10 changes: 5 additions & 5 deletions src/core/FactoryMaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let FactoryMaker = (function () {
}
return {
create: function () {
return merge(classConstructor.__dashjs_factory_name, classConstructor.apply({ context: context }, arguments), context);
return merge(classConstructor.__dashjs_factory_name, classConstructor.apply({ context: context }, arguments), context, arguments);
}
};
};
Expand All @@ -92,7 +92,7 @@ let FactoryMaker = (function () {
}
// If there's no instance on the context then create one
if (!instance) {
instance = merge(classConstructor.__dashjs_factory_name, classConstructor.apply({ context: context }, arguments), context);
instance = merge(classConstructor.__dashjs_factory_name, classConstructor.apply({ context: context }, arguments), context, arguments);
singletonContexts.push({ name: classConstructor.__dashjs_factory_name, context: context, instance: instance });
}
return instance;
Expand All @@ -101,20 +101,20 @@ let FactoryMaker = (function () {
};
}

function merge(name, classConstructor, context) {
function merge(name, classConstructor, context, args) {
let extensionContext = getExtensionContext(context);
let extensionObject = extensionContext[name];
if (extensionObject) {
let extension = extensionObject.instance;
if (extensionObject.override) { //Override public methods in parent but keep parent.
extension = extension.apply({ context: context, factory: instance, parent: classConstructor});
extension = extension.apply({ context: context, factory: instance, parent: classConstructor}, args);
for (const prop in extension) {
if (classConstructor.hasOwnProperty(prop)) {
classConstructor[prop] = extension[prop];
}
}
} else { //replace parent object completely with new object. Same as dijon.
return extension.apply({ context: context, factory: instance});
return extension.apply({ context: context, factory: instance}, args);
}
}
return classConstructor;
Expand Down
90 changes: 49 additions & 41 deletions src/streaming/MediaPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ function MediaPlayer() {
source,
protectionData,
initialized,
resetting,
playbackInitiated,
autoPlay,
abrController,
Expand All @@ -111,7 +110,6 @@ function MediaPlayer() {

function setup() {
initialized = false;
resetting = false;
playbackInitiated = false;
autoPlay = true;
protectionController = null;
Expand Down Expand Up @@ -167,7 +165,7 @@ function MediaPlayer() {
* @instance
*/
function isReady() {
return (!!element && !!source && !resetting);
return (!!element && !!source);
}

/**
Expand Down Expand Up @@ -1295,6 +1293,26 @@ function MediaPlayer() {
return detectProtection();
}

/**
* @param {ProtectionController} [value] valid protection controller instance.
* @memberof module:MediaPlayer
* @instance
*/
function attachProtectionController(value) {
protectionController = value;
}

/**
* @param {ProtectionData} [value] object containing
* property names corresponding to key system name strings and associated
* values being instances of
* @memberof module:MediaPlayer
* @instance
*/
function setProtectionData(value) {
protectionData = value;
}

/**
* This method serves to control captions z-index value. If 'true' is passed, the captions will have the highest z-index and be
* displayed on top of other html elements. Default value is 'false' (z-index is not set).
Expand Down Expand Up @@ -1342,9 +1360,9 @@ function MediaPlayer() {
videoModel.setElement(element);
// Workaround to force Firefox to fire the canplay event.
element.preload = 'auto';
//Todo figure out a better place for this!
detectProtection();
}
resetAndCheckAutoPlay();
}

/**
Expand All @@ -1368,17 +1386,14 @@ function MediaPlayer() {
*
* @param {string | object} urlOrManifest A URL to a valid MPD manifest file, or a
* parsed manifest object.
* @param {MediaPlayer.dependencies.ProtectionController} [protectionCtrl] optional
* protection controller
* @param {MediaPlayer.vo.protection.ProtectionData} [data] object containing
* property names corresponding to key system name strings and associated
* values being instances of
*
*
* @throw "MediaPlayer not initialized!"
*
* @memberof module:MediaPlayer
* @instance
*/
function attachSource(urlOrManifest, protectionCtrl, data) {//TODO way too overloaded with protection. Break out all protection and only accept source.
function attachSource(urlOrManifest) {
if (!initialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
Expand All @@ -1391,50 +1406,41 @@ function MediaPlayer() {
source = urlOrManifest;
}

//TODO figure out a better place for this. see attachView.
if (protectionCtrl) {
protectionController = protectionCtrl;
}
protectionData = data;
resetAndPlay();
resetAndCheckAutoPlay();
}

/**
* @memberof module:MediaPlayer
* @instance
*/
//function destroy() {}

/**
* Sets the MPD source and the video element to null.
* @memberof module:MediaPlayer
* @instance
*/
function reset() {
//todo add all vars in reset that need to be in here
attachSource(null);
attachView(null);
protectionController = null;
protectionData = null;
}

function resetAndPlay() {
adapter.reset();
if (playbackInitiated && streamController) {
if (!resetting) {
resetting = true;
eventBus.on(Events.STREAM_TEARDOWN_COMPLETE, onStreamTeardownComplete, this);
streamController.reset();
function resetAndCheckAutoPlay() {
if (playbackInitiated) {
playbackInitiated = false;
adapter.reset();
streamController.reset();
playbackController.reset();
abrController.reset();
rulesController.reset();
mediaController.reset();
streamController = null;
protectionController = null;
protectionData = null;
if (autoPlay && isReady()) {
play();
}
} else if (autoPlay) {
play();
}
}

function onStreamTeardownComplete() { //TODO see if we really need to be async here in streamController.reset() and resetAndPlay above.
abrController.reset();
rulesController.reset();
playbackController.reset();
mediaController.reset();
streamController = null;
playbackInitiated = false;
eventBus.off(Events.STREAM_TEARDOWN_COMPLETE, onStreamTeardownComplete, this);
resetting = false;
if (autoPlay) {
} else if (autoPlay && isReady()) {
play();
}
}
Expand Down Expand Up @@ -1628,6 +1634,8 @@ function MediaPlayer() {
setLongFormContentDurationThreshold: setLongFormContentDurationThreshold,
setRichBufferThreshold: setRichBufferThreshold,
getProtectionController: getProtectionController,
attachProtectionController: attachProtectionController,
setProtectionData: setProtectionData,
enableManifestDateHeaderTimeSource: enableManifestDateHeaderTimeSource,
displayCaptionsOnTop: displayCaptionsOnTop,
attachVideoContainer: attachVideoContainer,
Expand Down
16 changes: 8 additions & 8 deletions src/streaming/controllers/PlaybackController.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,21 @@ function PlaybackController() {
}

function reset() {
eventBus.off(Events.DATA_UPDATE_COMPLETED, onDataUpdateCompleted, this);
eventBus.off(Events.BUFFER_LEVEL_STATE_CHANGED, onBufferLevelStateChanged, this);
eventBus.off(Events.LIVE_EDGE_SEARCH_COMPLETED, onLiveEdgeSearchCompleted, this);
eventBus.off(Events.BYTES_APPENDED, onBytesAppended, this);

stopUpdatingWallclockTime();
removeAllListeners();
if (videoModel && element) {
eventBus.off(Events.DATA_UPDATE_COMPLETED, onDataUpdateCompleted, this);
eventBus.off(Events.BUFFER_LEVEL_STATE_CHANGED, onBufferLevelStateChanged, this);
eventBus.off(Events.LIVE_EDGE_SEARCH_COMPLETED, onLiveEdgeSearchCompleted, this);
eventBus.off(Events.BYTES_APPENDED, onBytesAppended, this);
stopUpdatingWallclockTime();
removeAllListeners();
}
videoModel = null;
streamInfo = null;
element = null;
isDynamic = null;
setup();
}


function setConfig(config) {
if (!config) return;

Expand Down
13 changes: 2 additions & 11 deletions src/streaming/controllers/StreamController.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,16 +580,12 @@ function StreamController() {
}

function reset() {

var stream;
timeSyncController.reset();

for (var i = 0, ln = streams.length; i < ln; i++) {
stream = streams[i];
for (let i = 0, ln = streams.length; i < ln; i++) {
let stream = streams[i];
eventBus.off(Events.STREAM_INITIALIZED, onStreamInitialized, this);
stream.reset(hasMediaError);
}

streams = [];

eventBus.off(Events.PLAYBACK_TIME_UPDATED, onPlaybackTimeUpdated, this);
Expand All @@ -613,14 +609,11 @@ function StreamController() {
activeStream = null;
canPlay = false;
hasMediaError = false;

if (mediaSource) {
mediaSourceExt.detachMediaSource(videoModel);
mediaSource = null;
}

videoModel = null;

if (protectionController) {
protectionController.setMediaElement(null);
protectionController = null;
Expand All @@ -629,8 +622,6 @@ function StreamController() {
eventBus.trigger(Events.PROTECTION_DESTROYED, {data: manifestModel.getValue().url});
}
}

eventBus.trigger(Events.STREAM_TEARDOWN_COMPLETE);
}

instance = {
Expand Down

0 comments on commit 3d95d06

Please sign in to comment.