Skip to content

Commit 1b19d0a

Browse files
committed
Add the remaining adaptationsets to the filtering event
1 parent 0602cff commit 1b19d0a

2 files changed

Lines changed: 105 additions & 5 deletions

File tree

src/streaming/utils/CapabilitiesFilter.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,26 @@ function CapabilitiesFilter() {
110110
return;
111111
}
112112

113-
period.AdaptationSet = period.AdaptationSet.filter((as) => {
113+
const removedAdaptationSets = new Set();
114+
const adaptationSets = period.AdaptationSet;
115+
116+
period.AdaptationSet = adaptationSets.filter((as) => {
114117
if (adapter.getIsTypeOf(as, type)) {
115118
_filterUnsupportedRepresentationsOfAdaptation(as, type);
116119
}
117120
const supported = as.Representation && as.Representation.length > 0;
118121
if (!supported) {
122+
removedAdaptationSets.add(as);
123+
124+
const remainingAdaptationSets = adaptationSets.filter((entry) => {
125+
return entry !== as &&
126+
adapter.getIsTypeOf(entry, type) &&
127+
!removedAdaptationSets.has(entry);
128+
});
129+
119130
eventBus.trigger(Events.ADAPTATION_SET_REMOVED_NO_CAPABILITIES, {
120-
adaptationSet: as
131+
adaptationSet: as,
132+
remainingAdaptationSets
121133
});
122134
logger.warn(`[CapabilitiesFilter] AdaptationSet with ID ${as.id ? as.id : 'undefined'} and codec ${as.codecs ? as.codecs : 'undefined'} has been removed because of no supported Representation`);
123135
}

test/unit/test/streaming/streaming.utils.CapabilitiesFilter.js

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,34 @@ import AdapterMock from '../../mocks/AdapterMock.js';
33
import CapabilitiesMock from '../../mocks/CapabilitiesMock.js';
44
import Settings from '../../../../src/core/Settings.js';
55
import CustomParametersModel from '../../../../src/streaming/models/CustomParametersModel.js';
6+
import EventBus from '../../../../src/core/EventBus.js';
7+
import Events from '../../../../src/core/events/Events.js';
68

79
import {expect} from 'chai';
810

911
let adapterMock;
1012
let capabilitiesFilter;
1113
let settings;
1214
let capabilitiesMock;
13-
let customParametersModel = CustomParametersModel({}).getInstance();
15+
let customParametersModel;
16+
let context;
17+
let eventBus;
1418

1519
describe('CapabilitiesFilter', function () {
1620
beforeEach(function () {
21+
context = {};
1722
adapterMock = new AdapterMock();
1823
adapterMock.getIsTypeOf = function (as, type) {
1924
return (type === 'audio' && as.mimeType === 'audio/mp4') || (type === 'video' && as.mimeType === 'video/mp4');
2025
};
2126

22-
settings = Settings({}).getInstance();
27+
settings = Settings(context).getInstance();
2328
capabilitiesMock = new CapabilitiesMock();
29+
customParametersModel = CustomParametersModel(context).getInstance();
30+
eventBus = EventBus(context).getInstance();
2431
customParametersModel.reset();
2532

26-
capabilitiesFilter = CapabilitiesFilter({}).getInstance();
33+
capabilitiesFilter = CapabilitiesFilter(context).getInstance();
2734

2835
capabilitiesFilter.setConfig({
2936
adapter: adapterMock,
@@ -33,6 +40,18 @@ describe('CapabilitiesFilter', function () {
3340
});
3441
});
3542

43+
afterEach(function () {
44+
if (eventBus) {
45+
eventBus.reset();
46+
}
47+
if (settings) {
48+
settings.reset();
49+
}
50+
if (customParametersModel) {
51+
customParametersModel.reset();
52+
}
53+
});
54+
3655
describe('filterUnsupportedFeatures', function () {
3756

3857
describe('filter codecs', function () {
@@ -111,6 +130,75 @@ describe('CapabilitiesFilter', function () {
111130
});
112131
});
113132

133+
it('should include remaining same-type AdaptationSets in removal event payload', function (done) {
134+
const adaptationSet1 = {
135+
id: '1',
136+
mimeType: 'audio/mp4',
137+
Representation: [
138+
{
139+
mimeType: 'audio/mp4',
140+
codecs: 'mp4a.40.1',
141+
audioSamplingRate: '48000'
142+
}
143+
]
144+
};
145+
const adaptationSet2 = {
146+
id: '2',
147+
mimeType: 'audio/mp4',
148+
Representation: [
149+
{
150+
mimeType: 'audio/mp4',
151+
codecs: 'mp4a.40.2',
152+
audioSamplingRate: '48000'
153+
}
154+
]
155+
};
156+
const adaptationSet3 = {
157+
id: '3',
158+
mimeType: 'audio/mp4',
159+
Representation: [
160+
{
161+
mimeType: 'audio/mp4',
162+
codecs: 'mp4a.40.5',
163+
audioSamplingRate: '48000'
164+
}
165+
]
166+
};
167+
168+
const manifest = {
169+
Period: [{
170+
AdaptationSet: [adaptationSet1, adaptationSet2, adaptationSet3]
171+
}]
172+
};
173+
174+
const removedEvents = [];
175+
const onAdaptationSetRemoved = function (e) {
176+
removedEvents.push(e);
177+
};
178+
179+
capabilitiesMock.isCodecSupportedBasedOnTestedConfigurations = function (config) {
180+
return config.codec === 'audio/mp4;codecs="mp4a.40.5"';
181+
};
182+
183+
eventBus.on(Events.ADAPTATION_SET_REMOVED_NO_CAPABILITIES, onAdaptationSetRemoved);
184+
185+
capabilitiesFilter.filterUnsupportedFeatures(manifest)
186+
.then(() => {
187+
expect(removedEvents).to.have.lengthOf(2);
188+
expect(removedEvents[0].adaptationSet.id).to.equal('1');
189+
expect(removedEvents[0].remainingAdaptationSets).to.deep.equal([adaptationSet2, adaptationSet3]);
190+
expect(removedEvents[1].adaptationSet.id).to.equal('2');
191+
expect(removedEvents[1].remainingAdaptationSets).to.deep.equal([adaptationSet3]);
192+
193+
eventBus.off(Events.ADAPTATION_SET_REMOVED_NO_CAPABILITIES, onAdaptationSetRemoved);
194+
done();
195+
})
196+
.catch((e) => {
197+
eventBus.off(Events.ADAPTATION_SET_REMOVED_NO_CAPABILITIES, onAdaptationSetRemoved);
198+
done(e);
199+
});
200+
});
201+
114202
it('should filter Representations', function (done) {
115203
const manifest = {
116204
Period: [{

0 commit comments

Comments
 (0)