Skip to content

Commit

Permalink
Add support for the Role tag.
Browse files Browse the repository at this point in the history
AdaptationSets are sorted by language (audio-only), then by those with
the "main" role.  Main sets are preferred when there are multiple to
choose from.

Closes #20, b/19214703.

Change-Id: I4fdd601c0bd7c7d29801084199123311ab9dbec3
  • Loading branch information
joeyparrish committed Jan 30, 2015
1 parent 52ddfd2 commit a92d673
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
39 changes: 37 additions & 2 deletions lib/dash/mpd_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ shaka.dash.mpd.AdaptationSet = function() {



/** @constructor */
shaka.dash.mpd.Role = function() {
/** @type {?string} */
this.value = null;
};


/** @constructor */
shaka.dash.mpd.ContentComponent = function() {
/** @type {?string} */
Expand Down Expand Up @@ -279,6 +286,9 @@ shaka.dash.mpd.Representation = function() {

/** @type {!Array.<!shaka.dash.mpd.ContentProtection>} */
this.contentProtections = [];

/** @type {boolean} */
this.main = false;
};


Expand All @@ -291,10 +301,16 @@ shaka.dash.mpd.ContentProtection = function() {
*/
this.schemeIdUri = null;

/** @type {?string} */
/**
* @type {?string}
* @expose
*/
this.value = null;

/** @type {!Array.<!Node>} */
/**
* @type {!Array.<!Node>}
* @expose
*/
this.children = [];

/**
Expand Down Expand Up @@ -525,6 +541,10 @@ shaka.dash.mpd.Period.TAG_NAME = 'Period';
shaka.dash.mpd.AdaptationSet.TAG_NAME = 'AdaptationSet';


/** @const {string} */
shaka.dash.mpd.Role.TAG_NAME = 'Role';


/** @const {string} */
shaka.dash.mpd.ContentComponent.TAG_NAME = 'ContentComponent';

Expand Down Expand Up @@ -647,6 +667,7 @@ shaka.dash.mpd.AdaptationSet.prototype.parse = function(parent, elem) {
// Parse children which provide properties of the AdaptationSet.
var contentComponent = mpd.parseChild_(this, elem, mpd.ContentComponent) ||
{};
var role = mpd.parseChild_(this, elem, mpd.Role);

// Parse attributes.
this.id = mpd.parseAttr_(elem, 'id', mpd.parseString_);
Expand All @@ -658,6 +679,7 @@ shaka.dash.mpd.AdaptationSet.prototype.parse = function(parent, elem) {
this.height = mpd.parseAttr_(elem, 'height', mpd.parsePositiveInt_);
this.mimeType = mpd.parseAttr_(elem, 'mimeType', mpd.parseString_);
this.codecs = mpd.parseAttr_(elem, 'codecs', mpd.parseString_);
this.main = role && role.value == 'main';

// Normalize the language tag.
if (this.lang) this.lang = shaka.util.LanguageUtils.normalize(this.lang);
Expand Down Expand Up @@ -700,6 +722,19 @@ shaka.dash.mpd.AdaptationSet.prototype.parse = function(parent, elem) {
};


/**
* Parses a "Role" tag.
* @param {!shaka.dash.mpd.AdaptationSet} parent The parent AdaptationSet.
* @param {!Node} elem The Role XML element.
*/
shaka.dash.mpd.Role.prototype.parse = function(parent, elem) {
var mpd = shaka.dash.mpd;

// Parse attributes.
this.value = mpd.parseAttr_(elem, 'value', mpd.parseString_);
};


/**
* Parses a "ContentComponent" tag.
* @param {!shaka.dash.mpd.AdaptationSet} parent The parent AdaptationSet.
Expand Down
1 change: 1 addition & 0 deletions lib/dash/mpd_processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ shaka.dash.MpdProcessor.prototype.createManifestInfo_ = function(mpd) {
var adaptationSet = period.adaptationSets[j];

var streamSetInfo = new shaka.media.StreamSetInfo();
streamSetInfo.main = adaptationSet.main;
streamSetInfo.contentType = adaptationSet.contentType || '';

for (var k = 0; k < adaptationSet.representations.length; ++k) {
Expand Down
3 changes: 3 additions & 0 deletions lib/media/stream_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ shaka.media.StreamSetInfo = function() {

/** @type {!Array.<!shaka.player.DrmSchemeInfo>} */
this.drmSchemes = [];

/** @type {boolean} */
this.main = false;
};


Expand Down
24 changes: 23 additions & 1 deletion lib/media/stream_info_processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ shaka.media.StreamInfoProcessor.prototype.filterStreamSetInfo_ =


/**
* Sorts each StreamSetInfo by bandwidth.
* Sorts each Period's StreamSetInfos by "main-ness" and each StreamSetInfo's
* StreamInfos by bandwidth.
*
* @param {!Array.<!shaka.media.PeriodInfo>} periodInfos
* @private
Expand All @@ -383,6 +384,8 @@ shaka.media.StreamInfoProcessor.prototype.sortStreamSetInfos_ = function(
periodInfos) {
for (var i = 0; i < periodInfos.length; ++i) {
var periodInfo = periodInfos[i];
periodInfo.streamSetInfos.sort(
shaka.media.StreamInfoProcessor.compareByMain_);
for (var j = 0; j < periodInfo.streamSetInfos.length; ++j) {
var streamSetInfo = periodInfo.streamSetInfos[j];
streamSetInfo.streamInfos.sort(
Expand All @@ -392,6 +395,25 @@ shaka.media.StreamInfoProcessor.prototype.sortStreamSetInfos_ = function(
};


/**
* Compares two StreamSetInfos by "main-ness".
*
* @param {!shaka.media.StreamSetInfo} streamSetInfo1
* @param {!shaka.media.StreamSetInfo} streamSetInfo2
* @return {number}
* @private
*/
shaka.media.StreamInfoProcessor.compareByMain_ = function(streamSetInfo1,
streamSetInfo2) {
if (streamSetInfo1.main == streamSetInfo2.main) {
return 0;
} else if (streamSetInfo1.main) {
return -1;
}
return 1;
};


/**
* Compares two StreamInfos by bandwidth.
*
Expand Down

0 comments on commit a92d673

Please sign in to comment.