Skip to content

Commit

Permalink
Add support for DASH label and HLS NAME attributes (#811)
Browse files Browse the repository at this point in the history
* add support for non-standard DASH label attribute
* add support for HLS NAME attribute

Closes #825
  • Loading branch information
iKinnrot authored and joeyparrish committed Jun 5, 2017
1 parent a0fa0d2 commit 2841de2
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 12 deletions.
10 changes: 6 additions & 4 deletions demo/info_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,19 @@ shakaDemo.updateTrackOptions_ = function(list, tracks, language) {
variant: function(track) {
var trackInfo = '';
if (track.language) trackInfo += 'language: ' + track.language + ', ';
if (track.label) trackInfo += 'label: ' + track.label + ', ';
if (track.width && track.height)
trackInfo += track.width + 'x' + track.height + ', ';
trackInfo += track.bandwidth + ' bits/s';
return trackInfo;
},
} ,
text: function(track) {
return 'language: ' + track.language + ' ' +
'(' + track.kind + ')';
var trackInfo = 'language: ' + track.language + ', ';
if (track.label) trackInfo += 'label: ' + track.label + ', ';
trackInfo += 'kind: ' + track.kind;
return trackInfo;
}
};

// Remove old tracks
while (list.firstChild) {
list.removeChild(list.firstChild);
Expand Down
3 changes: 3 additions & 0 deletions externs/shaka/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ shakaExtern.GetSegmentReferenceFunction;
* encrypted: boolean,
* keyId: ?string,
* language: string,
* label: ?string,
* type: string,
* primary: boolean,
* trickModeVideo: ?shakaExtern.Stream,
Expand Down Expand Up @@ -371,6 +372,8 @@ shakaExtern.GetSegmentReferenceFunction;
* The Stream's language, specified as a language code. <br>
* Audio stream's language must be identical to the language of the containing
* Variant.
* @property {?string} label
* The Stream's label, unique text that should describe the audio/text track.
* @property {string} type
* <i>Required.</i> <br>
* Content type (e.g. 'video', 'audio' or 'text')
Expand Down
3 changes: 3 additions & 0 deletions externs/shaka/offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ shakaExtern.PeriodDB;
* frameRate: (number|undefined),
* kind: (string|undefined),
* language: string,
* label: ?string,
* width: ?number,
* height: ?number,
* initSegmentUri: ?string,
Expand Down Expand Up @@ -175,6 +176,8 @@ shakaExtern.PeriodDB;
* The kind of text stream; undefined for audio/video.
* @property {string} language
* The language of the stream; '' for video.
* @property {?string} label
* The label of the stream; '' for video.
* @property {?number} width
* The width of the stream; null for audio/text.
* @property {?number} height
Expand Down
3 changes: 3 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ shakaExtern.Stats;
* bandwidth: number,
*
* language: string,
* label: ?string,
* kind: ?string,
* width: ?number,
* height: ?number,
Expand Down Expand Up @@ -161,6 +162,8 @@ shakaExtern.Stats;
* @property {string} language
* The language of the track, or 'und' if not given. This is the exact
* value provided in the manifest; it may need to be normalized.
* @property {?string} label
* The track label, unique text that should describe the track.
* @property {?string} kind
* (only for text tracks) The kind of text track, either 'caption' or
* 'subtitle'.
Expand Down
9 changes: 7 additions & 2 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,11 +950,14 @@ shaka.dash.DashParser.prototype.parseAdaptationSet_ = function(context, elem) {
var language =
shaka.util.LanguageUtils.normalize(elem.getAttribute('lang') || 'und');

// non-standard attribute(yet) supported by Kaltura
var label = elem.getAttribute('label');

// Parse Representations into Streams.
var representations = XmlUtils.findChildren(elem, 'Representation');
var streams = representations
.map(this.parseRepresentation_.bind(
this, context, contentProtection, kind, language, main))
this, context, contentProtection, kind, language, label, main))
.filter(function(s) { return !!s; });

if (streams.length == 0) {
Expand Down Expand Up @@ -1011,6 +1014,7 @@ shaka.dash.DashParser.prototype.parseAdaptationSet_ = function(context, elem) {
* @param {shaka.dash.ContentProtection.Context} contentProtection
* @param {(string|undefined)} kind
* @param {string} language
* @param {string} label
* @param {boolean} isPrimary
* @param {!Element} node
* @return {?shakaExtern.Stream} The Stream, or null when there is a
Expand All @@ -1019,7 +1023,7 @@ shaka.dash.DashParser.prototype.parseAdaptationSet_ = function(context, elem) {
* @private
*/
shaka.dash.DashParser.prototype.parseRepresentation_ = function(
context, contentProtection, kind, language, isPrimary, node) {
context, contentProtection, kind, language, label, isPrimary, node) {
var XmlUtils = shaka.util.XmlUtils;
var ContentType = shaka.util.ManifestParserUtils.ContentType;

Expand Down Expand Up @@ -1098,6 +1102,7 @@ shaka.dash.DashParser.prototype.parseRepresentation_ = function(
encrypted: contentProtection.drmInfos.length > 0,
keyId: keyId,
language: language,
label: label,
type: context.adaptationSet.contentType,
primary: isPrimary,
trickModeVideo: null,
Expand Down
12 changes: 9 additions & 3 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ shaka.hls.HlsParser.prototype.createStreamInfoFromMediaTag_ =
var LanguageUtils = shaka.util.LanguageUtils;
var language = LanguageUtils.normalize(/** @type {string} */(
tag.getAttributeValue('LANGUAGE', 'und')));
var labelValue = tag.getAttributeValue('NAME');
var label = labelValue ? labelValue.toString() : null;


var defaultAttr = tag.getAttribute('DEFAULT');
var autoselectAttr = tag.getAttribute('AUTOSELECT');
Expand All @@ -511,7 +514,7 @@ shaka.hls.HlsParser.prototype.createStreamInfoFromMediaTag_ =
var uri = HlsParser.getRequiredAttributeValue_(tag, 'URI');
var primary = !!defaultAttr || !!autoselectAttr;
return this.createStreamInfo_(uri, allCodecs, type, timeOffset, language,
primary).then(function(streamInfo) {
primary, label).then(function(streamInfo) {
this.mediaTagsToStreamInfosMap_[tag.id] = streamInfo;
return streamInfo;
}.bind(this));
Expand All @@ -535,7 +538,8 @@ shaka.hls.HlsParser.prototype.createStreamInfoFromVariantTag_ =

var uri = shaka.hls.HlsParser.getRequiredAttributeValue_(tag, 'URI');
return this.createStreamInfo_(uri, allCodecs, type, timeOffset,
/* language */ 'und', /* primary */ false);
/* language */ 'und', /* primary */ false,
null);
};


Expand All @@ -546,12 +550,13 @@ shaka.hls.HlsParser.prototype.createStreamInfoFromVariantTag_ =
* @param {?number} timeOffset
* @param {!string} language
* @param {boolean} primary
* @param {?string} label
* @return {!Promise.<shaka.hls.HlsParser.StreamInfo>}
* @throws shaka.util.Error
* @private
*/
shaka.hls.HlsParser.prototype.createStreamInfo_ =
function(uri, allCodecs, type, timeOffset, language, primary) {
function(uri, allCodecs, type, timeOffset, language, primary, label) {
var Utils = shaka.hls.Utils;
var ContentType = shaka.util.ManifestParserUtils.ContentType;
var HlsParser = shaka.hls.HlsParser;
Expand Down Expand Up @@ -663,6 +668,7 @@ shaka.hls.HlsParser.prototype.createStreamInfo_ =
encrypted: encrypted,
keyId: keyId,
language: language,
label: label || null,
type: type,
primary: primary,
// TODO: trick mode
Expand Down
1 change: 1 addition & 0 deletions lib/offline/offline_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ shaka.offline.OfflineUtils.createStream_ = function(streamDb) {
encrypted: streamDb.encrypted,
keyId: streamDb.keyId,
language: streamDb.language,
label: streamDb.label || null,
type: streamDb.contentType,
primary: streamDb.primary,
trickModeVideo: null,
Expand Down
1 change: 1 addition & 0 deletions lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ shaka.offline.Storage.prototype.createStream_ = function(
frameRate: stream.frameRate,
kind: stream.kind,
language: stream.language,
label: stream.label,
width: stream.width || null,
height: stream.height || null,
initSegmentUri: initUri,
Expand Down
5 changes: 4 additions & 1 deletion lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1411,11 +1411,12 @@ shaka.Player.prototype.getStats = function() {
* @param {string} kind
* @param {string} mime
* @param {string=} opt_codec
* @param {string=} opt_label
* @return {!Promise.<shakaExtern.Track>}
* @export
*/
shaka.Player.prototype.addTextTrack = function(
uri, language, kind, mime, opt_codec) {
uri, language, kind, mime, opt_codec, opt_label) {
if (!this.streamingEngine_) {
shaka.log.error(
'Must call load() and wait for it to resolve before adding text ' +
Expand Down Expand Up @@ -1466,6 +1467,7 @@ shaka.Player.prototype.addTextTrack = function(
encrypted: false,
keyId: null,
language: language,
label: opt_label || null,
type: ContentType.TEXT,
primary: false,
trickModeVideo: null,
Expand Down Expand Up @@ -1494,6 +1496,7 @@ shaka.Player.prototype.addTextTrack = function(
type: ContentType.TEXT,
bandwidth: 0,
language: language,
label: opt_label || null,
kind: kind,
width: null,
height: null
Expand Down
3 changes: 3 additions & 0 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ shaka.util.StreamUtils.getVariantTracks =
function(period, activeAudioId, activeVideoId) {
var StreamUtils = shaka.util.StreamUtils;
var variants = StreamUtils.getPlayableVariants(period.variants);
var label = null;
var tracks = variants.map(function(variant) {
var isActive;
if (variant.video && variant.audio) {
Expand All @@ -233,6 +234,7 @@ shaka.util.StreamUtils.getVariantTracks =
if (variant.audio) {
if (codecs != '') codecs += ', ';
codecs += variant.audio.codecs;
label = variant.audio.label;
}

var audioCodec = variant.audio ? variant.audio.codecs : null;
Expand All @@ -251,6 +253,7 @@ shaka.util.StreamUtils.getVariantTracks =
type: 'variant',
bandwidth: variant.bandwidth,
language: variant.language,
label: label,
kind: kind || null,
width: variant.video ? variant.video.width : null,
height: variant.video ? variant.video.height : null,
Expand Down
3 changes: 2 additions & 1 deletion test/dash/dash_parser_manifest_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('DashParser Manifest', function() {
' <Representation bandwidth="50" width="576" height="432" />',
' </AdaptationSet>',
' <AdaptationSet mimeType="text/vtt"',
' lang="es">',
' lang="es" label="spanish">',
' <Role value="caption" />',
' <Role value="main" />',
' <Representation bandwidth="100" />',
Expand Down Expand Up @@ -176,6 +176,7 @@ describe('DashParser Manifest', function() {
.primary()
.addTextStream(jasmine.any(Number))
.language('es')
.label('spanish')
.primary()
.anySegmentFunctions()
.anyInitSegment()
Expand Down
5 changes: 4 additions & 1 deletion test/offline/offline_utils_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ describe('OfflineUtils', function() {
startTime: 60,
streams: [createVideoStreamDb(1), createAudioStreamDb(2)]
};

var period = OfflineUtils.reconstructPeriod(periodDb, drmInfos, timeline);
expect(period).toBeTruthy();
expect(period.startTime).toBe(periodDb.startTime);
Expand Down Expand Up @@ -152,6 +151,7 @@ describe('OfflineUtils', function() {
frameRate: 22,
kind: undefined,
language: '',
label: null,
width: 250,
height: 100,
initSegmentUri: null,
Expand Down Expand Up @@ -183,6 +183,7 @@ describe('OfflineUtils', function() {
frameRate: undefined,
kind: undefined,
language: 'en',
label: null,
width: null,
height: null,
initSegmentUri: 'offline:1/' + id + '/0',
Expand Down Expand Up @@ -213,6 +214,7 @@ describe('OfflineUtils', function() {
frameRate: undefined,
kind: undefined,
language: 'en',
label: null,
width: null,
height: null,
initSegmentUri: 'offline:1/' + id + '/0',
Expand Down Expand Up @@ -255,6 +257,7 @@ describe('OfflineUtils', function() {
encrypted: streamDb.encrypted,
keyId: streamDb.keyId,
language: streamDb.language,
label: streamDb.label,
type: streamDb.contentType,
primary: streamDb.primary,
trickModeVideo: null,
Expand Down
1 change: 1 addition & 0 deletions test/offline/storage_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ describe('Storage', function() {
type: 'variant',
bandwidth: 0,
language: 'en',
label: null,
kind: null,
width: 1920,
height: 1080,
Expand Down
5 changes: 5 additions & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ describe('Player', function() {
type: 'variant',
bandwidth: 200,
language: 'en',
label: null,
kind: null,
width: 100,
height: 200,
Expand All @@ -800,6 +801,7 @@ describe('Player', function() {
type: 'variant',
bandwidth: 300,
language: 'en',
label: null,
kind: null,
width: 200,
height: 400,
Expand All @@ -816,6 +818,7 @@ describe('Player', function() {
type: 'variant',
bandwidth: 200,
language: 'en',
label: null,
kind: null,
width: 100,
height: 200,
Expand All @@ -832,6 +835,7 @@ describe('Player', function() {
type: 'variant',
bandwidth: 300,
language: 'en',
label: null,
kind: null,
width: 200,
height: 400,
Expand All @@ -848,6 +852,7 @@ describe('Player', function() {
type: 'variant',
bandwidth: 300,
language: 'es',
label: null,
kind: null,
width: 200,
height: 400,
Expand Down
13 changes: 13 additions & 0 deletions test/test/util/manifest_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ shaka.test.ManifestGenerator.prototype.language = function(language) {
};


/**
* Sets the label of the language of the most recent variant or text stream.
*
* @param {string} label
* @return {!shaka.test.ManifestGenerator}
*/
shaka.test.ManifestGenerator.prototype.label = function(label) {
this.currentStream_().label = label;
return this;
};


/**
* Sets that the most recent variant or text stream is primary.
*
Expand Down Expand Up @@ -456,6 +468,7 @@ shaka.test.ManifestGenerator.prototype.createStream_ =
encrypted: false,
keyId: null,
language: language,
label: null,
type: type,
primary: false,
trickModeVideo: null,
Expand Down

0 comments on commit 2841de2

Please sign in to comment.