Skip to content

Commit 7d0d1d0

Browse files
authored
propagate Properties common to all Representations to MediaInfo (#4682)
* (re-enable:) populate mediaInfo with Properties common to all Representations * improve names * fixing tests - apply renaming * apply naming patch from #4680 * cleaning * rename functions, fix typo * improvement as suggested * use internal/private function for common code * one final renaming to better describe the purpose of the function * harden unit test, reestablish old code as it works as expected (to optimize later) * rename var, delete comments, move functions
1 parent 87e1a26 commit 7d0d1d0

File tree

4 files changed

+176
-38
lines changed

4 files changed

+176
-38
lines changed

src/dash/DashAdapter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,8 @@ function DashAdapter() {
10391039
}
10401040

10411041
mediaInfo.isText = dashManifestModel.getIsText(realAdaptation);
1042-
mediaInfo.essentialProperties = dashManifestModel.getEssentialPropertiesForAdaptationSet(realAdaptation);
1043-
mediaInfo.supplementalProperties = dashManifestModel.getSupplementalPropertiesForAdaptation(realAdaptation);
1042+
mediaInfo.essentialProperties = dashManifestModel.getCombinedEssentialPropertiesForAdaptationSet(realAdaptation);
1043+
mediaInfo.supplementalProperties = dashManifestModel.getCombinedSupplementalPropertiesForAdaptationSet(realAdaptation);
10441044
mediaInfo.isFragmented = dashManifestModel.getIsFragmented(realAdaptation);
10451045
mediaInfo.isEmbedded = false;
10461046
mediaInfo.adaptationSetSwitchingCompatibleIds = _getAdaptationSetSwitchingCompatibleIds(mediaInfo);

src/dash/models/DashManifestModel.js

+68-30
Original file line numberDiff line numberDiff line change
@@ -578,29 +578,87 @@ function DashManifestModel() {
578578
}
579579
}
580580

581-
function getEssentialPropertiesForAdaptationSet(adaptation) {
582-
if (!adaptation || !adaptation.hasOwnProperty(DashConstants.ESSENTIAL_PROPERTY) || !adaptation[DashConstants.ESSENTIAL_PROPERTY].length) {
581+
// propertyType is one of { DashConstants.ESSENTIAL_PROPERTY, DashConstants.SUPPLEMENTAL_PROPERTY }
582+
function _getProperties(propertyType, element) {
583+
if (!element || !element.hasOwnProperty(propertyType) || !element[propertyType].length) {
583584
return [];
584585
}
585-
return adaptation[DashConstants.ESSENTIAL_PROPERTY].map(essentialProperty => {
586+
587+
return element[propertyType].map((property) => {
586588
const s = new DescriptorType();
587-
s.init(essentialProperty);
589+
s.init(property);
588590
return s
589591
});
590592
}
591593

592-
function getEssentialPropertiesForRepresentation(realRepresentation) {
593-
if (!realRepresentation || !realRepresentation.hasOwnProperty(DashConstants.ESSENTIAL_PROPERTY) || !realRepresentation[DashConstants.ESSENTIAL_PROPERTY].length) {
594+
function _getPropertiesCommonToAllRepresentations(propertyType, repr) {
595+
if (!repr || !repr.length) {
596+
return [];
597+
}
598+
599+
let propertiesOfFirstRepresentation = repr[0][propertyType] || [];
600+
601+
if (propertiesOfFirstRepresentation.length === 0) {
602+
return [];
603+
}
604+
605+
if (repr.length === 1) {
606+
return propertiesOfFirstRepresentation;
607+
}
608+
609+
// now, only return properties present on all Representations
610+
// repr.legth is always >= 2
611+
return propertiesOfFirstRepresentation.filter( prop => {
612+
return repr.slice(1).every( currRep => {
613+
return currRep[propertyType].some( e => {
614+
return e.schemeIdUri === prop.schemeIdUri && e.value === prop.value;
615+
});
616+
});
617+
})
618+
}
619+
620+
function _getCombinedPropertiesForAdaptationSet(propertyType, adaptation) {
621+
if (!adaptation) {
594622
return [];
595623
}
596624

597-
return realRepresentation[DashConstants.ESSENTIAL_PROPERTY].map((essentialProperty) => {
625+
let allProperties = _getPropertiesCommonToAllRepresentations(propertyType, adaptation[DashConstants.REPRESENTATION]);
626+
if (adaptation.hasOwnProperty(propertyType) && adaptation[propertyType].length) {
627+
allProperties.push(...adaptation[propertyType])
628+
}
629+
// we don't check whether there are duplicates on AdaptationSets and Representations
630+
631+
return allProperties.map(essentialProperty => {
598632
const s = new DescriptorType();
599633
s.init(essentialProperty);
600634
return s
601635
});
602636
}
603637

638+
function getEssentialPropertiesForAdaptationSet(adaptation) {
639+
return _getProperties(DashConstants.ESSENTIAL_PROPERTY, adaptation);
640+
}
641+
642+
function getCombinedEssentialPropertiesForAdaptationSet(adaptation) {
643+
return _getCombinedPropertiesForAdaptationSet(DashConstants.ESSENTIAL_PROPERTY, adaptation);
644+
}
645+
646+
function getEssentialPropertiesForRepresentation(realRepresentation) {
647+
return _getProperties(DashConstants.ESSENTIAL_PROPERTY, realRepresentation);
648+
}
649+
650+
function getSupplementalPropertiesForAdaptationSet(adaptation) {
651+
return _getProperties(DashConstants.SUPPLEMENTAL_PROPERTY, adaptation);
652+
}
653+
654+
function getCombinedSupplementalPropertiesForAdaptationSet(adaptation) {
655+
return _getCombinedPropertiesForAdaptationSet(DashConstants.SUPPLEMENTAL_PROPERTY, adaptation);
656+
}
657+
658+
function getSupplementalPropertiesForRepresentation(representation) {
659+
return _getProperties(DashConstants.SUPPLEMENTAL_PROPERTY, representation);
660+
}
661+
604662
function getRepresentationFor(index, adaptation) {
605663
return adaptation && adaptation.Representation && adaptation.Representation.length > 0 &&
606664
isInteger(index) ? adaptation.Representation[index] : null;
@@ -1430,28 +1488,6 @@ function DashManifestModel() {
14301488
return serviceDescriptions;
14311489
}
14321490

1433-
function getSupplementalPropertiesForAdaptation(adaptation) {
1434-
if (!adaptation || !adaptation.hasOwnProperty(DashConstants.SUPPLEMENTAL_PROPERTY) || !adaptation[DashConstants.SUPPLEMENTAL_PROPERTY].length) {
1435-
return [];
1436-
}
1437-
return adaptation[DashConstants.SUPPLEMENTAL_PROPERTY].map(supp => {
1438-
const s = new DescriptorType();
1439-
s.init(supp);
1440-
return s
1441-
});
1442-
}
1443-
1444-
function getSupplementalPropertiesForRepresentation(representation) {
1445-
if (!representation || !representation.hasOwnProperty(DashConstants.SUPPLEMENTAL_PROPERTY) || !representation[DashConstants.SUPPLEMENTAL_PROPERTY].length) {
1446-
return [];
1447-
}
1448-
return representation[DashConstants.SUPPLEMENTAL_PROPERTY].map(supp => {
1449-
const s = new DescriptorType();
1450-
s.init(supp);
1451-
return s
1452-
});
1453-
}
1454-
14551491
function setConfig(config) {
14561492
if (!config) {
14571493
return;
@@ -1479,6 +1515,8 @@ function DashManifestModel() {
14791515
getBaseURLsFromElement,
14801516
getBitrateListForAdaptation,
14811517
getCodec,
1518+
getCombinedEssentialPropertiesForAdaptationSet,
1519+
getCombinedSupplementalPropertiesForAdaptationSet,
14821520
getContentProtectionByAdaptation,
14831521
getContentProtectionByManifest,
14841522
getContentProtectionByPeriod,
@@ -1517,7 +1555,7 @@ function DashManifestModel() {
15171555
getServiceDescriptions,
15181556
getSubSegmentAlignment,
15191557
getSuggestedPresentationDelay,
1520-
getSupplementalPropertiesForAdaptation,
1558+
getSupplementalPropertiesForAdaptationSet,
15211559
getSupplementalPropertiesForRepresentation,
15221560
getUTCTimingSources,
15231561
getViewpointForAdaptation,

test/unit/test/dash/dash.DashAdapter.js

+100
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,68 @@ const manifest_with_supplemental_properties = {
9090
}]
9191
}]
9292
};
93+
const manifest_with_essential_properties_on_repr = {
94+
loadedTime: new Date(),
95+
mediaPresentationDuration: 10,
96+
Period: [{
97+
AdaptationSet: [{
98+
id: 0, mimeType: Constants.VIDEO,
99+
[DashConstants.REPRESENTATION]: [
100+
{
101+
id: 10, bandwidth: 128000,
102+
[DashConstants.ESSENTIAL_PROPERTY]: [
103+
{ schemeIdUri: 'test:scheme', value: 'value1' },
104+
{ schemeIdUri: 'test:scheme', value: 'value2' },
105+
{ schemeIdUri: 'test:scheme', value: 'value3' }
106+
]
107+
},
108+
{
109+
id: 11, bandwidth: 160000,
110+
[DashConstants.ESSENTIAL_PROPERTY]: [
111+
{ schemeIdUri: 'test:scheme', value: 'value4' },
112+
{ schemeIdUri: 'test:scheme', value: 'value3' },
113+
{ schemeIdUri: 'test:scheme', value: 'value2' },
114+
{ schemeIdUri: 'test:scheme', value: 'value0' }
115+
]
116+
},
117+
{
118+
id: 12, bandwidth: 192000,
119+
[DashConstants.ESSENTIAL_PROPERTY]: [
120+
{ schemeIdUri: 'test:scheme', value: 'value3' },
121+
{ schemeIdUri: 'test:scheme', value: 'value1' }
122+
]
123+
}
124+
]
125+
}]
126+
}]
127+
};
128+
const manifest_with_supplemental_properties_on_repr = {
129+
loadedTime: new Date(),
130+
mediaPresentationDuration: 10,
131+
Period: [{
132+
AdaptationSet: [{
133+
id: 0, mimeType: Constants.VIDEO,
134+
[DashConstants.REPRESENTATION]: [
135+
{
136+
id: 10, bandwidth: 128000,
137+
[DashConstants.SUPPLEMENTAL_PROPERTY]: [
138+
{ schemeIdUri: 'test:scheme', value: 'value1' },
139+
{ schemeIdUri: 'test:scheme', value: 'value2' },
140+
{ schemeIdUri: 'test:scheme', value: 'value3' }
141+
]
142+
},
143+
{
144+
id: 11, bandwidth: 160000,
145+
[DashConstants.SUPPLEMENTAL_PROPERTY]: [
146+
{ schemeIdUri: 'test:scheme', value: 'value1' },
147+
{ schemeIdUri: 'test:scheme', value: 'value2' },
148+
{ schemeIdUri: 'test:scheme', value: 'value4' }
149+
]
150+
}
151+
]
152+
}]
153+
}]
154+
};
93155
const manifest_with_essential_properties_on_only_one_repr = {
94156
loadedTime: new Date(),
95157
mediaPresentationDuration: 10,
@@ -597,6 +659,25 @@ describe('DashAdapter', function () {
597659
expect(mediaInfoArray[0].essentialProperties.length).equals(2);
598660
});
599661

662+
it('essential properties should be filled if set on all representations', function () {
663+
const mediaInfoArray = dashAdapter.getAllMediaInfoForType({
664+
id: 'defaultId_0',
665+
index: 0
666+
}, Constants.VIDEO, manifest_with_essential_properties_on_repr);
667+
668+
expect(mediaInfoArray).to.be.instanceOf(Array);
669+
expect(mediaInfoArray.length).equals(1);
670+
671+
expect(mediaInfoArray[0].representationCount).equals(3);
672+
expect(mediaInfoArray[0].codec).not.to.be.null;
673+
674+
expect(mediaInfoArray[0].essentialProperties).to.be.instanceOf(Array);
675+
expect(mediaInfoArray[0].essentialProperties.length).equals(1);
676+
677+
expect(mediaInfoArray[0].essentialProperties[0].schemeIdUri).equals('test:scheme');
678+
expect(mediaInfoArray[0].essentialProperties[0].value).equals('value3');
679+
});
680+
600681
it('essential properties should not be filled if not set on all representations', function () {
601682
const mediaInfoArray = dashAdapter.getAllMediaInfoForType({
602683
id: 'defaultId_0',
@@ -640,6 +721,25 @@ describe('DashAdapter', function () {
640721
expect(mediaInfoArray[0].supplementalProperties.length).equals(2);
641722
});
642723

724+
it('supplemental properties should be filled if set on all representations', function () {
725+
const mediaInfoArray = dashAdapter.getAllMediaInfoForType({
726+
id: 'defaultId_0',
727+
index: 0
728+
}, Constants.VIDEO, manifest_with_supplemental_properties_on_repr);
729+
730+
expect(mediaInfoArray).to.be.instanceOf(Array);
731+
expect(mediaInfoArray.length).equals(1);
732+
733+
expect(mediaInfoArray[0].representationCount).equals(2);
734+
expect(mediaInfoArray[0].codec).not.to.be.null;
735+
736+
expect(mediaInfoArray[0].supplementalProperties).to.be.instanceOf(Array);
737+
expect(mediaInfoArray[0].supplementalProperties.length).equals(2);
738+
739+
expect(mediaInfoArray[0].supplementalProperties[1].schemeIdUri).equals('test:scheme');
740+
expect(mediaInfoArray[0].supplementalProperties[1].value).equals('value2');
741+
});
742+
643743
it('supplemental properties should not be filled if not set on all representations', function () {
644744
const mediaInfoArray = dashAdapter.getAllMediaInfoForType({
645745
id: 'defaultId_0',

test/unit/test/dash/dash.models.DashManifestModel.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -186,22 +186,22 @@ describe('DashManifestModel', function () {
186186
expect(essPropArray[0].value).equals('testVal');
187187
});
188188

189-
it('should return an empty array when getSupplementalPropertiesForAdaptation', () => {
190-
const suppPropArray = dashManifestModel.getSupplementalPropertiesForAdaptation();
189+
it('should return an empty array when getSupplementalPropertiesForAdaptationSet', () => {
190+
const suppPropArray = dashManifestModel.getSupplementalPropertiesForAdaptationSet();
191191

192192
expect(suppPropArray).to.be.instanceOf(Object);
193193
expect(suppPropArray).to.be.empty;
194194
});
195195

196-
it('should return an empty array when getSupplementalPropertiesForAdaptation', () => {
197-
const suppPropArray = dashManifestModel.getSupplementalPropertiesForAdaptation();
196+
it('should return an empty array when getSupplementalPropertiesForAdaptationSet', () => {
197+
const suppPropArray = dashManifestModel.getSupplementalPropertiesForAdaptationSet();
198198

199199
expect(suppPropArray).to.be.instanceOf(Array);
200200
expect(suppPropArray).to.be.empty;
201201
});
202202

203-
it('should return correct array of DescriptorType when getSupplementalPropertiesForAdaptation is called', () => {
204-
const suppPropArray = dashManifestModel.getSupplementalPropertiesForAdaptation({
203+
it('should return correct array of DescriptorType when getSupplementalPropertiesForAdaptationSet is called', () => {
204+
const suppPropArray = dashManifestModel.getSupplementalPropertiesForAdaptationSet({
205205
SupplementalProperty: [{ schemeIdUri: 'test.scheme', value: 'testVal' }, {
206206
schemeIdUri: 'test.scheme',
207207
value: 'test2Val'

0 commit comments

Comments
 (0)