Skip to content

Commit

Permalink
Feature/#4421 (#4551)
Browse files Browse the repository at this point in the history
* Allow to use Representations from different AdaptationSets when calling setRepresentationForTypeById

* Minor changes to functional tests
  • Loading branch information
dsilhavy authored Aug 16, 2024
1 parent 2a5be5f commit dcf985f
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/streaming/MediaPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ function MediaPlayer() {
}

/**
* Sets the current quality for media type instead of letting the ABR Heuristics automatically selecting it.
* Sets the current quality for media type instead of letting the ABR Heuristics automatically select it.
* This value will be overwritten by the ABR rules unless autoSwitchBitrate is set to false.
*
* @param {MediaType} type - 'video', 'audio' or 'image'
Expand Down Expand Up @@ -1567,7 +1567,7 @@ function MediaPlayer() {
}

/**
* Sets the current quality for media type instead of letting the ABR Heuristics automatically selecting it.
* Sets the current quality for media type instead of letting the ABR Heuristics automatically select it.
* This value will be overwritten by the ABR rules unless autoSwitchBitrate is set to false.
* Note that you need to specify a relative index based on the position of the target entry in the return value of getRepresentationsByType().
* Do NOT use representation.absoluteIndex here as this index was assigned prior to applying any filter function. If you want to select a specific representation then use setRepresentationForTypeById() instead.
Expand Down
43 changes: 31 additions & 12 deletions src/streaming/Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ function Stream(config) {
}
return thumbnailController.getPossibleVoRepresentations();
}
const mediaInfo = getMediaInfo(type);
const mediaInfo = _getMediaInfo(type);
return abrController.getPossibleVoRepresentationsFilteredBySettings(mediaInfo, true);
}

Expand All @@ -706,8 +706,11 @@ function Stream(config) {
}
possibleVoRepresentations = thumbnailController.getPossibleVoRepresentations();
} else {
const mediaInfo = getMediaInfo(type);
possibleVoRepresentations = abrController.getPossibleVoRepresentationsFilteredBySettings(mediaInfo, true);
const mediaInfos = _getAllMediaInfos(type);

possibleVoRepresentations = mediaInfos.flatMap((mediaInfo) => {
return abrController.getPossibleVoRepresentationsFilteredBySettings(mediaInfo, true);
})
}

if (!possibleVoRepresentations || possibleVoRepresentations.length === 0) {
Expand Down Expand Up @@ -735,7 +738,7 @@ function Stream(config) {
}
possibleVoRepresentations = thumbnailController.getPossibleVoRepresentations();
} else {
const mediaInfo = getMediaInfo(type);
const mediaInfo = _getMediaInfo(type);
possibleVoRepresentations = abrController.getPossibleVoRepresentationsFilteredBySettings(mediaInfo, true);
}

Expand Down Expand Up @@ -801,20 +804,36 @@ function Stream(config) {
}
}

function getMediaInfo(type) {
let streamProcessor = null;

for (let i = 0; i < streamProcessors.length; i++) {
streamProcessor = streamProcessors[i];
function _getMediaInfo(type) {
let streamProcessor = _getStreamProcessorForType(type);

if (streamProcessor.getType() === type) {
return streamProcessor.getMediaInfo();
}
if (streamProcessor) {
return streamProcessor.getMediaInfo();
}

return null;
}

function _getAllMediaInfos(type) {
let streamProcessor = _getStreamProcessorForType(type);

if (streamProcessor) {
return streamProcessor.getAllMediaInfos();
}

return [];
}

function _getStreamProcessorForType(type) {
if (!type) {
return null
}

return streamProcessors.find((streamProcessor) => {
return streamProcessor.getType() === type;
})
}

function onBufferingCompleted() {
let processors = getStreamProcessors();
const ln = processors.length;
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/utils/CapabilitiesFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function CapabilitiesFilter() {
eventBus.trigger(Events.ADAPTATION_SET_REMOVED_NO_CAPABILITIES, {
adaptationSet: as
});
logger.warn(`AdaptationSet has been removed because of no supported Representation`);
logger.warn(`AdaptationSet with ID ${as.id ? as.id : 'unknown'} and codec ${as.codecs ? as.codecs : 'unknown'} has been removed because of no supported Representation`);
}

return supported;
Expand Down
1 change: 1 addition & 0 deletions test/functional/adapter/DashJsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class DashJsAdapter {
destroy() {
this.logEvents = {};
if (this.player) {
this._unregisterInternalEvents();
this.player.resetSettings();
this.player.destroy();
}
Expand Down
5 changes: 4 additions & 1 deletion test/functional/adapter/GoogleAdManagerAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ class GoogleAdManagerAdapter {
this._onVastEvent, false);
}

unregisterVastEventListener() {
this.streamManager.removeEventListener(Object.keys(VAST_EVENTS_TO_VERIFY), this._onVastEvent, false);
}

_onVastEvent(event) {
console.log(`Received ${event.type} event at playback time ${this.playerAdapter.getCurrentTime()}`);
switch (event.type) {
case google.ima.dai.api.StreamEvent.Type.STARTED:
case google.ima.dai.api.StreamEvent.Type.FIRST_QUARTILE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"all"
],
"excluded": [
"vendor/google-ad-manager-emsg",
"buffer/buffer-to-keep-seek"
"buffer/buffer-to-keep-seek",
"vendor/google-ad-manager-emsg"
]
},
"testvectors": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"all"
],
"excluded": [
"vendor/google-ad-manager-emsg"
]
},
"testvectors": [
Expand Down
2 changes: 1 addition & 1 deletion test/functional/test/vendor/google-ad-manager-emsg.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ before(() => {

after(() => {
mpd = null;
playerAdapter.destroy();
googleAdManagerAdapter.reset();
playerAdapter.destroy();
})

it('Register DAI pod session', async () => {
Expand Down

0 comments on commit dcf985f

Please sign in to comment.