From 34607c9536ad7851612bb29362084ef266c33fba Mon Sep 17 00:00:00 2001 From: Itay Kinnrot Date: Wed, 17 May 2017 16:10:43 +0300 Subject: [PATCH 1/4] add support to label attribute for audio and text --- demo/info_section.js | 7 +++++-- lib/dash/dash_parser.js | 9 +++++++-- lib/util/stream_utils.js | 4 ++++ test/dash/dash_parser_manifest_unit.js | 3 ++- test/test/util/manifest_generator.js | 12 ++++++++++++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/demo/info_section.js b/demo/info_section.js index 249da17406..e6ebd23cbf 100644 --- a/demo/info_section.js +++ b/demo/info_section.js @@ -84,7 +84,6 @@ shakaDemo.updateVariantTracks_ = function() { */ shakaDemo.updateTextTracks_ = function() { var trackList = document.getElementById('textTracks'); - var langList = document.getElementById('textLanguages'); var language = langList.selectedIndex >= 0 ? langList.options[langList.selectedIndex].value : @@ -198,7 +197,11 @@ shakaDemo.updateLanguageOptions_ = // Populate list with new options. languages.forEach(function(lang) { var option = document.createElement('option'); - option.textContent = lang; + var currentTrack = tracks.filter(function(track) { + return track.language === lang; + }); + option.textContent = currentTrack[0].label != 'und' ? + currentTrack[0].label : lang; option.value = lang; option.selected = lang == selectedTrack.language; list.appendChild(option); diff --git a/lib/dash/dash_parser.js b/lib/dash/dash_parser.js index ec494c552d..05a68a7545 100644 --- a/lib/dash/dash_parser.js +++ b/lib/dash/dash_parser.js @@ -957,11 +957,14 @@ shaka.dash.DashParser.prototype.parseAdaptationSet_ = function(context, elem) { var language = shaka.util.LanguageUtils.normalize(elem.getAttribute('lang') || 'und'); + var label = + shaka.util.LanguageUtils.normalize(elem.getAttribute('label') || 'und'); + // 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) { @@ -1018,6 +1021,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 @@ -1026,7 +1030,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; @@ -1105,6 +1109,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, diff --git a/lib/util/stream_utils.js b/lib/util/stream_utils.js index 3fc7f47332..67e3e201be 100644 --- a/lib/util/stream_utils.js +++ b/lib/util/stream_utils.js @@ -233,6 +233,9 @@ shaka.util.StreamUtils.getVariantTracks = if (variant.audio) { if (codecs != '') codecs += ', '; codecs += variant.audio.codecs; + if (variant.audio.label) { + variant.label = variant.audio.label; + } } var audioCodec = variant.audio ? variant.audio.codecs : null; @@ -251,6 +254,7 @@ shaka.util.StreamUtils.getVariantTracks = type: 'variant', bandwidth: variant.bandwidth, language: variant.language, + label: variant.label, kind: kind || null, width: variant.video ? variant.video.width : null, height: variant.video ? variant.video.height : null, diff --git a/test/dash/dash_parser_manifest_unit.js b/test/dash/dash_parser_manifest_unit.js index 70c85ce2be..5b9b833ac0 100644 --- a/test/dash/dash_parser_manifest_unit.js +++ b/test/dash/dash_parser_manifest_unit.js @@ -119,7 +119,7 @@ describe('DashParser Manifest', function() { ' ', ' ', ' ', + ' lang="es" label="spanish">', ' ', ' ', ' ', @@ -176,6 +176,7 @@ describe('DashParser Manifest', function() { .primary() .addTextStream(jasmine.any(Number)) .language('es') + .label('spanish') .primary() .anySegmentFunctions() .anyInitSegment() diff --git a/test/test/util/manifest_generator.js b/test/test/util/manifest_generator.js index 97a15372fa..099642783a 100644 --- a/test/test/util/manifest_generator.js +++ b/test/test/util/manifest_generator.js @@ -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.currentStreamOrVariant_().label = label; + return this; +}; + + /** * Sets that the most recent variant or text stream is primary. * From 272334e5577ac0f37a60b638599f5d0fa3f1ee4a Mon Sep 17 00:00:00 2001 From: Itay Kinnrot Date: Mon, 22 May 2017 14:53:49 +0300 Subject: [PATCH 2/4] fix code review, add label to shakaExtern.Track and shakaExtern.Stream and update project according to it --- demo/info_section.js | 18 +++++++++--------- externs/shaka/manifest.js | 3 +++ externs/shaka/offline.js | 3 +++ externs/shaka/player.js | 3 +++ lib/dash/dash_parser.js | 3 +-- lib/offline/offline_utils.js | 1 + lib/offline/storage.js | 1 + lib/player.js | 5 ++++- lib/util/stream_utils.js | 5 +++-- test/offline/offline_utils_unit.js | 3 +++ test/test/util/manifest_generator.js | 13 ++++++++----- 11 files changed, 39 insertions(+), 19 deletions(-) diff --git a/demo/info_section.js b/demo/info_section.js index e6ebd23cbf..066f3b35e9 100644 --- a/demo/info_section.js +++ b/demo/info_section.js @@ -153,8 +153,10 @@ shakaDemo.updateLanguages_ = function() { shakaDemo.updateTextLanguages_ = function() { var player = shakaDemo.player_; var list = document.getElementById('textLanguages'); - var languages = player.getTextLanguages(); var tracks = player.getTextTracks(); + var languages = tracks.map(function(track) { + return { id: track.id, lang: track.language, label: track.label}; + }); shakaDemo.updateLanguageOptions_(list, languages, tracks); }; @@ -167,8 +169,10 @@ shakaDemo.updateTextLanguages_ = function() { shakaDemo.updateAudioLanguages_ = function() { var player = shakaDemo.player_; var list = document.getElementById('audioLanguages'); - var languages = player.getAudioLanguages(); var tracks = player.getVariantTracks(); + var languages = tracks.map(function(track) { + return { id: track.id, lang: track.language, label: track.label}; + }); shakaDemo.updateLanguageOptions_(list, languages, tracks); }; @@ -197,13 +201,9 @@ shakaDemo.updateLanguageOptions_ = // Populate list with new options. languages.forEach(function(lang) { var option = document.createElement('option'); - var currentTrack = tracks.filter(function(track) { - return track.language === lang; - }); - option.textContent = currentTrack[0].label != 'und' ? - currentTrack[0].label : lang; - option.value = lang; - option.selected = lang == selectedTrack.language; + option.textContent = lang.label ? lang.label : lang.lang; + option.value = lang.lang; + option.selected = lang.lang == selectedTrack.language; list.appendChild(option); }); }; diff --git a/externs/shaka/manifest.js b/externs/shaka/manifest.js index e165893ea7..f9f58c74a1 100644 --- a/externs/shaka/manifest.js +++ b/externs/shaka/manifest.js @@ -297,6 +297,7 @@ shakaExtern.GetSegmentReferenceFunction; * encrypted: boolean, * keyId: ?string, * language: string, + * label: ?string, * type: string, * primary: boolean, * trickModeVideo: ?shakaExtern.Stream, @@ -371,6 +372,8 @@ shakaExtern.GetSegmentReferenceFunction; * The Stream's language, specified as a language code.
* 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 * Required.
* Content type (e.g. 'video', 'audio' or 'text') diff --git a/externs/shaka/offline.js b/externs/shaka/offline.js index 0b600a9776..16151ffd7a 100644 --- a/externs/shaka/offline.js +++ b/externs/shaka/offline.js @@ -148,6 +148,7 @@ shakaExtern.PeriodDB; * frameRate: (number|undefined), * kind: (string|undefined), * language: string, + * label: ?string, * width: ?number, * height: ?number, * initSegmentUri: ?string, @@ -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 diff --git a/externs/shaka/player.js b/externs/shaka/player.js index df0a3597f7..73bc9abcc1 100644 --- a/externs/shaka/player.js +++ b/externs/shaka/player.js @@ -130,6 +130,7 @@ shakaExtern.Stats; * bandwidth: number, * * language: string, + * label: ?string, * kind: ?string, * width: ?number, * height: ?number, @@ -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'. diff --git a/lib/dash/dash_parser.js b/lib/dash/dash_parser.js index 05a68a7545..5440883ee8 100644 --- a/lib/dash/dash_parser.js +++ b/lib/dash/dash_parser.js @@ -957,8 +957,7 @@ shaka.dash.DashParser.prototype.parseAdaptationSet_ = function(context, elem) { var language = shaka.util.LanguageUtils.normalize(elem.getAttribute('lang') || 'und'); - var label = - shaka.util.LanguageUtils.normalize(elem.getAttribute('label') || 'und'); + var label = elem.getAttribute('label'); // Parse Representations into Streams. var representations = XmlUtils.findChildren(elem, 'Representation'); diff --git a/lib/offline/offline_utils.js b/lib/offline/offline_utils.js index 45e4a5b7d3..5d4b354e01 100644 --- a/lib/offline/offline_utils.js +++ b/lib/offline/offline_utils.js @@ -251,6 +251,7 @@ shaka.offline.OfflineUtils.createStream_ = function(streamDb) { encrypted: streamDb.encrypted, keyId: streamDb.keyId, language: streamDb.language, + label: streamDb.label, type: streamDb.contentType, primary: streamDb.primary, trickModeVideo: null, diff --git a/lib/offline/storage.js b/lib/offline/storage.js index 0e268de0da..33a86f6a2d 100644 --- a/lib/offline/storage.js +++ b/lib/offline/storage.js @@ -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, diff --git a/lib/player.js b/lib/player.js index a84d29aaec..3baa7437ee 100644 --- a/lib/player.js +++ b/lib/player.js @@ -1408,6 +1408,7 @@ shaka.Player.prototype.getStats = function() { * * @param {string} uri * @param {string} language + * @param {?string} label * @param {string} kind * @param {string} mime * @param {string=} opt_codec @@ -1415,7 +1416,7 @@ shaka.Player.prototype.getStats = function() { * @export */ shaka.Player.prototype.addTextTrack = function( - uri, language, kind, mime, opt_codec) { + uri, language, label, kind, mime, opt_codec) { if (!this.streamingEngine_) { shaka.log.error( 'Must call load() and wait for it to resolve before adding text ' + @@ -1466,6 +1467,7 @@ shaka.Player.prototype.addTextTrack = function( encrypted: false, keyId: null, language: language, + label: label, type: ContentType.TEXT, primary: false, trickModeVideo: null, @@ -1494,6 +1496,7 @@ shaka.Player.prototype.addTextTrack = function( type: ContentType.TEXT, bandwidth: 0, language: language, + label: label, kind: kind, width: null, height: null diff --git a/lib/util/stream_utils.js b/lib/util/stream_utils.js index 67e3e201be..660fbdca8a 100644 --- a/lib/util/stream_utils.js +++ b/lib/util/stream_utils.js @@ -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; var tracks = variants.map(function(variant) { var isActive; if (variant.video && variant.audio) { @@ -234,7 +235,7 @@ shaka.util.StreamUtils.getVariantTracks = if (codecs != '') codecs += ', '; codecs += variant.audio.codecs; if (variant.audio.label) { - variant.label = variant.audio.label; + label = variant.audio.label; } } @@ -254,7 +255,7 @@ shaka.util.StreamUtils.getVariantTracks = type: 'variant', bandwidth: variant.bandwidth, language: variant.language, - label: variant.label, + label: label, kind: kind || null, width: variant.video ? variant.video.width : null, height: variant.video ? variant.video.height : null, diff --git a/test/offline/offline_utils_unit.js b/test/offline/offline_utils_unit.js index 85e3048a0b..c8ead1860c 100644 --- a/test/offline/offline_utils_unit.js +++ b/test/offline/offline_utils_unit.js @@ -152,6 +152,7 @@ describe('OfflineUtils', function() { frameRate: 22, kind: undefined, language: '', + label: '', width: 250, height: 100, initSegmentUri: null, @@ -183,6 +184,7 @@ describe('OfflineUtils', function() { frameRate: undefined, kind: undefined, language: 'en', + label: 'English', width: null, height: null, initSegmentUri: 'offline:1/' + id + '/0', @@ -213,6 +215,7 @@ describe('OfflineUtils', function() { frameRate: undefined, kind: undefined, language: 'en', + label: 'English', width: null, height: null, initSegmentUri: 'offline:1/' + id + '/0', diff --git a/test/test/util/manifest_generator.js b/test/test/util/manifest_generator.js index 099642783a..51a5c76e70 100644 --- a/test/test/util/manifest_generator.js +++ b/test/test/util/manifest_generator.js @@ -169,7 +169,7 @@ shaka.test.ManifestGenerator.prototype.language = function(language) { * @return {!shaka.test.ManifestGenerator} */ shaka.test.ManifestGenerator.prototype.label = function(label) { - this.currentStreamOrVariant_().label = label; + this.currentStream_().label = label; return this; }; @@ -332,7 +332,7 @@ shaka.test.ManifestGenerator.prototype.addVideo = function(id) { } if (!stream) - stream = this.createStream_(id, ContentType.VIDEO, 'und'); + stream = this.createStream_(id, ContentType.VIDEO, 'und', null); variant.video = stream; this.lastStreamAdded_ = stream; @@ -365,7 +365,8 @@ shaka.test.ManifestGenerator.prototype.addAudio = function(id) { } if (!stream) - stream = this.createStream_(id, ContentType.AUDIO, variant.language); + stream = this.createStream_(id, ContentType.AUDIO, variant.language, + variant.audio.label); variant.audio = stream; this.lastStreamAdded_ = stream; @@ -384,7 +385,7 @@ shaka.test.ManifestGenerator.prototype.addAudio = function(id) { shaka.test.ManifestGenerator.prototype.addTextStream = function(id) { var ContentType = shaka.util.ManifestParserUtils.ContentType; var period = this.currentPeriod_(); - var stream = this.createStream_(id, ContentType.TEXT, 'und'); + var stream = this.createStream_(id, ContentType.TEXT, 'und', ''); period.textStreams.push(stream); this.lastObjectAdded_ = stream; this.lastStreamAdded_ = stream; @@ -428,11 +429,12 @@ shaka.test.ManifestGenerator.prototype.isIdUsed_ = function(id) { * @param {number} id * @param {string} type * @param {string} language + * @param {?string} label * @return {!shakaExtern.Stream} * @private */ shaka.test.ManifestGenerator.prototype.createStream_ = - function(id, type, language) { + function(id, type, language, label) { goog.asserts.assert(!this.isIdUsed_(id), 'Streams should have unique ids!'); @@ -468,6 +470,7 @@ shaka.test.ManifestGenerator.prototype.createStream_ = encrypted: false, keyId: null, language: language, + label: label, type: type, primary: false, trickModeVideo: null, From 474add7c6e6148b5b147a0e3a892ff7b912edc1c Mon Sep 17 00:00:00 2001 From: Itay Kinnrot Date: Tue, 23 May 2017 15:01:36 +0300 Subject: [PATCH 3/4] more fixes --- demo/info_section.js | 16 ++++++---------- lib/player.js | 8 ++++---- lib/util/stream_utils.js | 6 ++---- test/test/util/manifest_generator.js | 12 +++++------- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/demo/info_section.js b/demo/info_section.js index 066f3b35e9..59cd54d4e5 100644 --- a/demo/info_section.js +++ b/demo/info_section.js @@ -153,10 +153,8 @@ shakaDemo.updateLanguages_ = function() { shakaDemo.updateTextLanguages_ = function() { var player = shakaDemo.player_; var list = document.getElementById('textLanguages'); + var languages = player.getTextLanguages(); var tracks = player.getTextTracks(); - var languages = tracks.map(function(track) { - return { id: track.id, lang: track.language, label: track.label}; - }); shakaDemo.updateLanguageOptions_(list, languages, tracks); }; @@ -169,10 +167,8 @@ shakaDemo.updateTextLanguages_ = function() { shakaDemo.updateAudioLanguages_ = function() { var player = shakaDemo.player_; var list = document.getElementById('audioLanguages'); + var languages = player.getAudioLanguages(); var tracks = player.getVariantTracks(); - var languages = tracks.map(function(track) { - return { id: track.id, lang: track.language, label: track.label}; - }); shakaDemo.updateLanguageOptions_(list, languages, tracks); }; @@ -199,11 +195,11 @@ shakaDemo.updateLanguageOptions_ = var selectedTrack = activeTracks[0]; // Populate list with new options. - languages.forEach(function(lang) { + tracks.forEach(function(track) { var option = document.createElement('option'); - option.textContent = lang.label ? lang.label : lang.lang; - option.value = lang.lang; - option.selected = lang.lang == selectedTrack.language; + option.textContent = track.label ? track.label : track.language; + option.value = track.language; + option.selected = track.language == selectedTrack.language; list.appendChild(option); }); }; diff --git a/lib/player.js b/lib/player.js index 3baa7437ee..076a7d3914 100644 --- a/lib/player.js +++ b/lib/player.js @@ -1408,15 +1408,15 @@ shaka.Player.prototype.getStats = function() { * * @param {string} uri * @param {string} language - * @param {?string} label * @param {string} kind * @param {string} mime * @param {string=} opt_codec + * @param {string=} opt_label * @return {!Promise.} * @export */ shaka.Player.prototype.addTextTrack = function( - uri, language, label, 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 ' + @@ -1467,7 +1467,7 @@ shaka.Player.prototype.addTextTrack = function( encrypted: false, keyId: null, language: language, - label: label, + label: opt_label || null, type: ContentType.TEXT, primary: false, trickModeVideo: null, @@ -1496,7 +1496,7 @@ shaka.Player.prototype.addTextTrack = function( type: ContentType.TEXT, bandwidth: 0, language: language, - label: label, + label: opt_label || null, kind: kind, width: null, height: null diff --git a/lib/util/stream_utils.js b/lib/util/stream_utils.js index 660fbdca8a..cb470d60a7 100644 --- a/lib/util/stream_utils.js +++ b/lib/util/stream_utils.js @@ -219,7 +219,7 @@ shaka.util.StreamUtils.getVariantTracks = function(period, activeAudioId, activeVideoId) { var StreamUtils = shaka.util.StreamUtils; var variants = StreamUtils.getPlayableVariants(period.variants); - var label; + var label = null; var tracks = variants.map(function(variant) { var isActive; if (variant.video && variant.audio) { @@ -234,9 +234,7 @@ shaka.util.StreamUtils.getVariantTracks = if (variant.audio) { if (codecs != '') codecs += ', '; codecs += variant.audio.codecs; - if (variant.audio.label) { - label = variant.audio.label; - } + label = variant.audio.label; } var audioCodec = variant.audio ? variant.audio.codecs : null; diff --git a/test/test/util/manifest_generator.js b/test/test/util/manifest_generator.js index 51a5c76e70..9dd7ab2d5b 100644 --- a/test/test/util/manifest_generator.js +++ b/test/test/util/manifest_generator.js @@ -332,7 +332,7 @@ shaka.test.ManifestGenerator.prototype.addVideo = function(id) { } if (!stream) - stream = this.createStream_(id, ContentType.VIDEO, 'und', null); + stream = this.createStream_(id, ContentType.VIDEO, 'und'); variant.video = stream; this.lastStreamAdded_ = stream; @@ -365,8 +365,7 @@ shaka.test.ManifestGenerator.prototype.addAudio = function(id) { } if (!stream) - stream = this.createStream_(id, ContentType.AUDIO, variant.language, - variant.audio.label); + stream = this.createStream_(id, ContentType.AUDIO, variant.language); variant.audio = stream; this.lastStreamAdded_ = stream; @@ -385,7 +384,7 @@ shaka.test.ManifestGenerator.prototype.addAudio = function(id) { shaka.test.ManifestGenerator.prototype.addTextStream = function(id) { var ContentType = shaka.util.ManifestParserUtils.ContentType; var period = this.currentPeriod_(); - var stream = this.createStream_(id, ContentType.TEXT, 'und', ''); + var stream = this.createStream_(id, ContentType.TEXT, 'und'); period.textStreams.push(stream); this.lastObjectAdded_ = stream; this.lastStreamAdded_ = stream; @@ -429,12 +428,11 @@ shaka.test.ManifestGenerator.prototype.isIdUsed_ = function(id) { * @param {number} id * @param {string} type * @param {string} language - * @param {?string} label * @return {!shakaExtern.Stream} * @private */ shaka.test.ManifestGenerator.prototype.createStream_ = - function(id, type, language, label) { + function(id, type, language) { goog.asserts.assert(!this.isIdUsed_(id), 'Streams should have unique ids!'); @@ -470,7 +468,7 @@ shaka.test.ManifestGenerator.prototype.createStream_ = encrypted: false, keyId: null, language: language, - label: label, + label: null, type: type, primary: false, trickModeVideo: null, From 71e2adef34e240eca979b09b9d8bd304c10de1b7 Mon Sep 17 00:00:00 2001 From: Itay Kinnrot Date: Wed, 24 May 2017 15:21:08 +0300 Subject: [PATCH 4/4] fix unit test + add HLS NAME attribute as label --- demo/info_section.js | 19 +++++++++++-------- lib/dash/dash_parser.js | 1 + lib/hls/hls_parser.js | 8 ++++++-- test/offline/offline_utils_unit.js | 8 +++++--- test/offline/storage_unit.js | 1 + test/player_unit.js | 5 +++++ 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/demo/info_section.js b/demo/info_section.js index 59cd54d4e5..f65ff5102a 100644 --- a/demo/info_section.js +++ b/demo/info_section.js @@ -84,6 +84,7 @@ shakaDemo.updateVariantTracks_ = function() { */ shakaDemo.updateTextTracks_ = function() { var trackList = document.getElementById('textTracks'); + var langList = document.getElementById('textLanguages'); var language = langList.selectedIndex >= 0 ? langList.options[langList.selectedIndex].value : @@ -106,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); @@ -195,11 +198,11 @@ shakaDemo.updateLanguageOptions_ = var selectedTrack = activeTracks[0]; // Populate list with new options. - tracks.forEach(function(track) { + languages.forEach(function(lang) { var option = document.createElement('option'); - option.textContent = track.label ? track.label : track.language; - option.value = track.language; - option.selected = track.language == selectedTrack.language; + option.textContent = lang; + option.value = lang; + option.selected = lang == selectedTrack.language; list.appendChild(option); }); }; diff --git a/lib/dash/dash_parser.js b/lib/dash/dash_parser.js index 5440883ee8..c881808e6f 100644 --- a/lib/dash/dash_parser.js +++ b/lib/dash/dash_parser.js @@ -957,6 +957,7 @@ 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. diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index 8bb114b51a..5673102284 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -480,6 +480,8 @@ shaka.hls.HlsParser.prototype.createStreamInfoFromMediaTag_ = var LanguageUtils = shaka.util.LanguageUtils; var langAttr = tag.getAttribute('LANGUAGE'); var language = langAttr ? LanguageUtils.normalize(langAttr.value) : 'und'; + var labelAttr = tag.getAttribute('NAME'); + var label = labelAttr ? labelAttr.value : null; var defaultAttr = tag.getAttribute('DEFAULT'); var autoselectAttr = tag.getAttribute('AUTOSELECT'); @@ -491,7 +493,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)); @@ -526,12 +528,13 @@ shaka.hls.HlsParser.prototype.createStreamInfoFromVariantTag_ = * @param {?number} timeOffset * @param {!string} language * @param {boolean} primary + * @param {?string=} opt_label * @return {!Promise.} * @throws shaka.util.Error * @private */ shaka.hls.HlsParser.prototype.createStreamInfo_ = - function(uri, allCodecs, type, timeOffset, language, primary) { + function(uri, allCodecs, type, timeOffset, language, primary, opt_label) { var Utils = shaka.hls.Utils; var ContentType = shaka.util.ManifestParserUtils.ContentType; var HlsParser = shaka.hls.HlsParser; @@ -643,6 +646,7 @@ shaka.hls.HlsParser.prototype.createStreamInfo_ = encrypted: encrypted, keyId: keyId, language: language, + label: opt_label || null, type: type, primary: primary, // TODO: trick mode diff --git a/test/offline/offline_utils_unit.js b/test/offline/offline_utils_unit.js index c8ead1860c..43c065479e 100644 --- a/test/offline/offline_utils_unit.js +++ b/test/offline/offline_utils_unit.js @@ -56,6 +56,7 @@ describe('OfflineUtils', function() { var variant = period.variants[0]; expect(variant.id).toEqual(jasmine.any(Number)); expect(variant.language).toBe(periodDb.streams[1].language); + expect(variant.label).toBe(periodDb.streams[1].label); expect(variant.primary).toBe(false); expect(variant.bandwidth).toEqual(jasmine.any(Number)); expect(variant.drmInfos).toBe(drmInfos); @@ -152,7 +153,7 @@ describe('OfflineUtils', function() { frameRate: 22, kind: undefined, language: '', - label: '', + label: undefined, width: 250, height: 100, initSegmentUri: null, @@ -184,7 +185,7 @@ describe('OfflineUtils', function() { frameRate: undefined, kind: undefined, language: 'en', - label: 'English', + label: undefined, width: null, height: null, initSegmentUri: 'offline:1/' + id + '/0', @@ -215,7 +216,7 @@ describe('OfflineUtils', function() { frameRate: undefined, kind: undefined, language: 'en', - label: 'English', + label: undefined, width: null, height: null, initSegmentUri: 'offline:1/' + id + '/0', @@ -258,6 +259,7 @@ describe('OfflineUtils', function() { encrypted: streamDb.encrypted, keyId: streamDb.keyId, language: streamDb.language, + label: streamDb.label, type: streamDb.contentType, primary: streamDb.primary, trickModeVideo: null, diff --git a/test/offline/storage_unit.js b/test/offline/storage_unit.js index 404afd3b83..6221f7bff9 100644 --- a/test/offline/storage_unit.js +++ b/test/offline/storage_unit.js @@ -133,6 +133,7 @@ describe('Storage', function() { type: 'variant', bandwidth: 0, language: 'en', + label: undefined, kind: null, width: 1920, height: 1080, diff --git a/test/player_unit.js b/test/player_unit.js index 3351931c40..4119fa1d33 100644 --- a/test/player_unit.js +++ b/test/player_unit.js @@ -784,6 +784,7 @@ describe('Player', function() { type: 'variant', bandwidth: 200, language: 'en', + label: null, kind: null, width: 100, height: 200, @@ -800,6 +801,7 @@ describe('Player', function() { type: 'variant', bandwidth: 300, language: 'en', + label: null, kind: null, width: 200, height: 400, @@ -816,6 +818,7 @@ describe('Player', function() { type: 'variant', bandwidth: 200, language: 'en', + label: null, kind: null, width: 100, height: 200, @@ -832,6 +835,7 @@ describe('Player', function() { type: 'variant', bandwidth: 300, language: 'en', + label: null, kind: null, width: 200, height: 400, @@ -848,6 +852,7 @@ describe('Player', function() { type: 'variant', bandwidth: 300, language: 'es', + label: null, kind: null, width: 200, height: 400,