Skip to content

Commit 453c1da

Browse files
authored
fix Settings sanitizer for initialTrackSelection based on id (Dash-Industry-Forum#4739)
* two unit tests for initial track selection based on @id * fix to MediaPlayer related to initialTrackSelectrion based on id in settings * small fix * handling of empty strings
1 parent 4a524c3 commit 453c1da

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

src/streaming/MediaPlayer.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,7 @@ function MediaPlayer() {
27092709

27102710
function __sanitizeDescriptorType(name, val, defaultSchemeIdUri) {
27112711
let out = {};
2712+
// For an empty string, let's unset the descriptor, i.e. return null
27122713
if (val) {
27132714
if (val instanceof Array) {
27142715
throw ARRAY_NOT_SUPPORTED_ERROR;
@@ -2725,22 +2726,25 @@ function MediaPlayer() {
27252726
return null;
27262727
}
27272728

2728-
if (value.lang) {
2729+
if (value.id !== undefined) {
2730+
output.id = value.id;
2731+
}
2732+
if (value.lang !== undefined) {
27292733
output.lang = value.lang;
27302734
}
27312735
if (!isNaN(value.index)) {
27322736
output.index = value.index;
27332737
}
2734-
if (value.viewpoint) {
2738+
if (value.viewpoint !== undefined) {
27352739
output.viewpoint = __sanitizeDescriptorType('viewpoint', value.viewpoint, defaults.viewpoint);
27362740
}
2737-
if (value.audioChannelConfiguration) {
2741+
if (value.audioChannelConfiguration !== undefined) {
27382742
output.audioChannelConfiguration = __sanitizeDescriptorType('audioChannelConfiguration', value.audioChannelConfiguration, defaults.audioChannelConfiguration);
27392743
}
2740-
if (value.role) {
2744+
if (value.role !== undefined) {
27412745
output.role = __sanitizeDescriptorType('role', value.role, defaults.role);
27422746
}
2743-
if (value.accessibility) {
2747+
if (value.accessibility !== undefined) {
27442748
output.accessibility = __sanitizeDescriptorType('accessibility', value.accessibility, defaults.accessibility);
27452749
}
27462750

test/unit/test/streaming/streaming.controllers.MediaController.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ describe('MediaController', function () {
384384
id: 'id'
385385
};
386386
const frTrack = {
387+
id: 0,
387388
type: trackType,
388389
streamInfo: streamInfo,
389390
lang: 'fr',
@@ -393,6 +394,7 @@ describe('MediaController', function () {
393394
audioChannelConfiguration: [{ schemeIdUri: 'urn:mpeg:mpegB:cicp:ChannelConfiguration', value: '2' }]
394395
};
395396
const qtzTrack = {
397+
id: 'qtz',
396398
type: trackType,
397399
streamInfo: streamInfo,
398400
lang: 'qtz',
@@ -402,6 +404,7 @@ describe('MediaController', function () {
402404
audioChannelConfiguration: [{ schemeIdUri: 'urn:mpeg:mpegB:cicp:ChannelConfiguration', value: '2' }]
403405
};
404406
const enTrack = {
407+
id: 2,
405408
type: trackType,
406409
streamInfo: streamInfo,
407410
lang: 'en',
@@ -412,6 +415,7 @@ describe('MediaController', function () {
412415
selectionPriority: 5
413416
};
414417
const enADTrack = {
418+
id: 3,
415419
type: trackType,
416420
streamInfo: streamInfo,
417421
lang: 'en',
@@ -422,6 +426,7 @@ describe('MediaController', function () {
422426
selectionPriority: 3
423427
};
424428
const esTrack = {
429+
id: 'esTrack',
425430
type: trackType,
426431
streamInfo: streamInfo,
427432
lang: 'es',
@@ -456,6 +461,46 @@ describe('MediaController', function () {
456461

457462
});
458463

464+
it('should check initial media settings to choose initial track via integer-id', function () {
465+
mediaController.addTrack(qtzTrack);
466+
mediaController.addTrack(esTrack);
467+
mediaController.addTrack(frTrack);
468+
mediaController.addTrack(enTrack);
469+
mediaController.addTrack(enADTrack);
470+
471+
let trackList = mediaController.getTracksFor(trackType, streamInfo.id);
472+
expect(trackList).to.have.lengthOf(5);
473+
474+
mediaController.setInitialSettings(trackType, {
475+
id: 2,
476+
lang: 'es'
477+
});
478+
mediaController.setInitialMediaSettingsForType(trackType, streamInfo);
479+
480+
let currentTrack = mediaController.getCurrentTrackFor(trackType, streamInfo.id);
481+
expect(objectUtils.areEqual(currentTrack, enTrack)).to.be.true;
482+
});
483+
484+
it('should check initial media settings to choose initial track via string-id', function () {
485+
mediaController.addTrack(qtzTrack);
486+
mediaController.addTrack(esTrack);
487+
mediaController.addTrack(frTrack);
488+
mediaController.addTrack(enTrack);
489+
mediaController.addTrack(enADTrack);
490+
491+
let trackList = mediaController.getTracksFor(trackType, streamInfo.id);
492+
expect(trackList).to.have.lengthOf(5);
493+
494+
mediaController.setInitialSettings(trackType, {
495+
id: 'esTrack',
496+
lang: 'en'
497+
});
498+
mediaController.setInitialMediaSettingsForType(trackType, streamInfo);
499+
500+
let currentTrack = mediaController.getCurrentTrackFor(trackType, streamInfo.id);
501+
expect(objectUtils.areEqual(currentTrack, esTrack)).to.be.true;
502+
});
503+
459504
it('should check initial media settings to choose initial track with 639-2 3-letter code', function () {
460505
mediaController.addTrack(qtzTrack);
461506
mediaController.addTrack(frTrack);

0 commit comments

Comments
 (0)