Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for non-standard DASH label attribute #811

Merged
merged 5 commits into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions demo/info_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down Expand Up @@ -154,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};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name languages is now a misnomer. You're not passing an array of language strings, but an array of objects with track info.

In fact, these objects are a subset of what is already in tracks. So you don't need this at all.

At a higher level, what you're doing here in the UI is labeling the languages. Instead, you should be labeling the tracks, since labels are attached to tracks.

The language list should stay as it is.

});

shakaDemo.updateLanguageOptions_(list, languages, tracks);
};
Expand All @@ -168,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);
};
Expand Down Expand Up @@ -198,9 +201,9 @@ shakaDemo.updateLanguageOptions_ =
// Populate list with new options.
languages.forEach(function(lang) {
var option = document.createElement('option');
option.textContent = 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);
});
};
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
8 changes: 6 additions & 2 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,11 +957,13 @@ shaka.dash.DashParser.prototype.parseAdaptationSet_ = function(context, elem) {
var language =
shaka.util.LanguageUtils.normalize(elem.getAttribute('lang') || 'und');

var label = elem.getAttribute('label');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unable to find any mention of this attribute in the DASH spec (2014) or the latest DASH-IF-IOP (v4.0). I don't object to you adding it, though.

Please add a comment that this is a non-standard attribute supported by Kaltura.


// 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 @@ -1018,6 +1020,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 @@ -1026,7 +1029,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 @@ -1105,6 +1108,7 @@ shaka.dash.DashParser.prototype.parseRepresentation_ = function(
encrypted: contentProtection.drmInfos.length > 0,
keyId: keyId,
language: language,
label: label,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this new field to the definition of the shakaExtern.Stream structure in externs/shaka/manifest.js.

type: context.adaptationSet.contentType,
primary: isPrimary,
trickModeVideo: null,
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,
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 @@ -1408,14 +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
* @return {!Promise.<shakaExtern.Track>}
* @export
*/
shaka.Player.prototype.addTextTrack = function(
uri, language, kind, mime, opt_codec) {
uri, language, label, kind, mime, opt_codec) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not add additional parameters to the middle of an exported method. This would break backward compatibility. Instead, make it an optional parameter after opt_codec.

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: label,
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: label,
kind: kind,
width: null,
height: null
Expand Down
5 changes: 5 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize this to null, since the type allows for null instead of undefined. A minor difference, I know.

var tracks = variants.map(function(variant) {
var isActive;
if (variant.video && variant.audio) {
Expand All @@ -233,6 +234,9 @@ shaka.util.StreamUtils.getVariantTracks =
if (variant.audio) {
if (codecs != '') codecs += ', ';
codecs += variant.audio.codecs;
if (variant.audio.label) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "if" is unnecessary. Just set label = variant.audio.label.

label = variant.audio.label;
}
}

var audioCodec = variant.audio ? variant.audio.codecs : null;
Expand All @@ -251,6 +255,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">',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for updating the tests!

' <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
3 changes: 3 additions & 0 deletions test/offline/offline_utils_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ describe('OfflineUtils', function() {
frameRate: 22,
kind: undefined,
language: '',
label: '',
width: 250,
height: 100,
initSegmentUri: null,
Expand Down Expand Up @@ -183,6 +184,7 @@ describe('OfflineUtils', function() {
frameRate: undefined,
kind: undefined,
language: 'en',
label: 'English',
width: null,
height: null,
initSegmentUri: 'offline:1/' + id + '/0',
Expand Down Expand Up @@ -213,6 +215,7 @@ describe('OfflineUtils', function() {
frameRate: undefined,
kind: undefined,
language: 'en',
label: 'English',
width: null,
height: null,
initSegmentUri: 'offline:1/' + id + '/0',
Expand Down
23 changes: 19 additions & 4 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 @@ -320,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;
Expand Down Expand Up @@ -353,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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it will throw an exception, since variant.audio doesn't exist yet.


variant.audio = stream;
this.lastStreamAdded_ = stream;
Expand All @@ -372,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;
Expand Down Expand Up @@ -416,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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have the label() method to set the label of the current stream, I think we don't need to add this parameter.

goog.asserts.assert(!this.isIdUsed_(id),
'Streams should have unique ids!');

Expand Down Expand Up @@ -456,6 +470,7 @@ shaka.test.ManifestGenerator.prototype.createStream_ =
encrypted: false,
keyId: null,
language: language,
label: label,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default to null.

type: type,
primary: false,
trickModeVideo: null,
Expand Down