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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 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 @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

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

There are two things wrong with this part:

  1. currentTrack is a misleading name. It is not the currently-selected track you've identified, it's just any track that matches the language.
  2. You shouldn't annotate the languages with track labels. Instead, annotate the track list.

For example, if you have two tracks of the same language, as @erankor suggested is common for this feature, you would have these tracks:

[
  { id: 1, lang: 'en', label: 'with music' },
  { id: 2, lang: 'en', label: 'without music' },
]

But the only language in the language list will be "en". With what you've written, your language options in HTML would wind up as:

<select>
<option value="en">with music</option>
</select>

While the variant tracks would still both show "language: en" with no differentiation.

I think the method you really want to modify here is shakaDemo.updateTrackOptions_, specifically the formatters callbacks.

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);
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 @@ -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');
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it makes sense to pass the label through language tools or default to the language code 'und'. Label, as I understand it from @erankor's explanation, is a free-form string and may reasonably be missing (null).


// 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 +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
Expand All @@ -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;

Expand Down Expand Up @@ -1105,6 +1109,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
4 changes: 4 additions & 0 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,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.

variant.label = 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.

It doesn't make sense to push it from variant.audio (Stream structure) to variant (Variant structure) in this utility. If you need this on variant, you should add it when the variant is generated in the DASH parser.

Instead, though, I recommend just storing the label in a local var. I don't see any good reason to push it up to the variant.

}
}

var audioCodec = variant.audio ? variant.audio.codecs : null;
Expand All @@ -251,6 +254,7 @@ shaka.util.StreamUtils.getVariantTracks =
type: 'variant',
bandwidth: variant.bandwidth,
language: variant.language,
label: variant.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.Track structure in externs/shaka/player.js.

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
12 changes: 12 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.currentStreamOrVariant_().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 use currentStream_() instead, since this attribute should only live at the stream level.

return this;
};


/**
* Sets that the most recent variant or text stream is primary.
*
Expand Down