Skip to content

Commit

Permalink
Add settings attribute to enable/disable MediaCapabilities API
Browse files Browse the repository at this point in the history
  • Loading branch information
dsilhavy committed May 28, 2021
1 parent e18e0a4 commit 215fc3d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 27 deletions.
5 changes: 4 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,12 @@ declare namespace dashjs {
wallclockTimeUpdateInterval?: number,
lowLatencyEnabled?: boolean,
manifestUpdateRetryInterval?: number,
filterUnsupportedEssentialProperties?: boolean,
cacheInitSegments?: boolean,
eventControllerRefreshDelay?: number,
capabilities?: {
filterUnsupportedEssentialProperties?: boolean,
useMediaCapabilitiesApi?: boolean
},
timeShiftBuffer?: {
calcFromSegmentTimeline?: boolean
fallbackToSegmentTimeline?: boolean
Expand Down
21 changes: 17 additions & 4 deletions src/core/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ import {HTTPRequest} from '../streaming/vo/metrics/HTTPRequest';
* wallclockTimeUpdateInterval: 100,
* lowLatencyEnabled: false,
* manifestUpdateRetryInterval: 100,
* filterUnsupportedEssentialProperties: true,
* cacheInitSegments: true,
* eventControllerRefreshDelay: 100,
* capabilities: {
* filterUnsupportedEssentialProperties: true,
* useMediaCapabilitiesApi: false
* },
* timeShiftBuffer: {
* calcFromSegmentTimeline: false,
* fallbackToSegmentTimeline: true
Expand Down Expand Up @@ -477,6 +480,14 @@ import {HTTPRequest} from '../streaming/vo/metrics/HTTPRequest';
* If true, the ProtectionController and then created MediaKeys and MediaKeySessions will be preserved during the MediaPlayer lifetime.
*/

/**
* @typedef {Object} Capabilities
* @property {boolean} [filterUnsupportedEssentialProperties=true]
* Enable to filter all the AdaptationSets and Representations which contain an unsupported \<EssentialProperty\> element.
* @property {boolean} [useMediaCapabilitiesApi=false]
* Enable to use the MediaCapabilities API to check whether codecs are supported. If disabled MSE.isTypeSupported will be used instead.
*/

/**
* @typedef {Object} AbrSettings
* @property {string} [movingAverageMethod="slidingWindow"]
Expand Down Expand Up @@ -594,15 +605,14 @@ import {HTTPRequest} from '../streaming/vo/metrics/HTTPRequest';
* The use of the date header will happen only after the other timing source that take precedence fail or are omitted as described.
* @property {number} [manifestUpdateRetryInterval=100]
* For live streams, set the interval-frequency in milliseconds at which dash.js will check if the current manifest is still processed before downloading the next manifest once the minimumUpdatePeriod time has.
* @property {boolean} [filterUnsupportedEssentialProperties=true]
* Enable to filter all the AdaptationSets and Representations which contain an unsupported \<EssentialProperty\> element.
* @property {boolean} [cacheInitSegments=true]
* Enables the caching of init segments to avoid requesting the init segments before each representation switch.
* @property {number} [eventControllerRefreshDelay=100]
* Defines the delay in milliseconds between two consecutive checks for events to be fired.
* @property {module:Settings~LiveDelay} delay Live Delay settings
* @property {module:Settings~TimeShiftBuffer} timeShiftBuffer TimeShiftBuffer settings
* @property {module:Settings~Protection} protection DRM related settings
* @property {module:Settings~Capabilities} capabilities Capability related settings
* @property {module:Settings~Buffer} buffer Buffer related settings
* @property {module:Settings~Gaps} gaps Gap related settings
* @property {module:Settings~UtcSynchronizationSettings} utcSynchronization Settings related to UTC clock synchronization
Expand Down Expand Up @@ -686,9 +696,12 @@ function Settings() {
wallclockTimeUpdateInterval: 100,
lowLatencyEnabled: false,
manifestUpdateRetryInterval: 100,
filterUnsupportedEssentialProperties: true,
cacheInitSegments: true,
eventControllerRefreshDelay: 150,
capabilities: {
filterUnsupportedEssentialProperties: true,
useMediaCapabilitiesApi: false
},
timeShiftBuffer: {
calcFromSegmentTimeline: false,
fallbackToSegmentTimeline: true
Expand Down
3 changes: 3 additions & 0 deletions src/streaming/MediaPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ function MediaPlayer() {
function initialize(view, source, AutoPlay) {
if (!capabilities) {
capabilities = Capabilities(context).getInstance();
capabilities.setConfig({
settings
})
}

errHandler = ErrorHandler(context).getInstance();
Expand Down
14 changes: 13 additions & 1 deletion src/streaming/utils/Capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,23 @@ export function supportsMediaSource() {
function Capabilities() {

let instance,
settings,
encryptedMediaSupported;

function setup() {
encryptedMediaSupported = false;
}

function setConfig(config) {
if (!config) {
return;
}

if (config.settings) {
settings = config.settings;
}
}

/**
* Returns whether Encrypted Media Extensions are supported on this
* user agent
Expand Down Expand Up @@ -105,7 +116,7 @@ function Capabilities() {
*/
function _canUseMediaCapabilitiesApi(config, type) {

return navigator.mediaCapabilities && navigator.mediaCapabilities.decodingInfo && ((config.codec && type === Constants.AUDIO) || (type === Constants.VIDEO && config.codec && config.width && config.height && config.bitrate && config.framerate));
return settings.get().streaming.capabilities.useMediaCapabilitiesApi && navigator.mediaCapabilities && navigator.mediaCapabilities.decodingInfo && ((config.codec && type === Constants.AUDIO) || (type === Constants.VIDEO && config.codec && config.width && config.height && config.bitrate && config.framerate));
}

/**
Expand Down Expand Up @@ -211,6 +222,7 @@ function Capabilities() {
}

instance = {
setConfig,
supportsMediaSource,
supportsEncryptedMedia,
supportsCodec,
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 @@ -44,7 +44,7 @@ function CapabilitiesFilter() {

Promise.all(promises)
.then(() => {
if (settings.get().streaming.filterUnsupportedEssentialProperties) {
if (settings.get().streaming.capabilities.filterUnsupportedEssentialProperties) {
_filterUnsupportedEssentialProperties(manifest);
}
_applyCustomFilters(manifest);
Expand Down
41 changes: 21 additions & 20 deletions test/unit/streaming.utils.CapabilitiesFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('CapabilitiesFilter', function () {
describe('filter codecs', function () {

beforeEach(function () {
settings.update({ streaming: { filterUnsupportedEssentialProperties: false } });
settings.update({ streaming: { capabilities: { filterUnsupportedEssentialProperties: false } } });
});

it('should not filter AdaptationSets and Representations', function (done) {
Expand Down Expand Up @@ -147,11 +147,11 @@ describe('CapabilitiesFilter', function () {
describe('filter EssentialProperty values', function () {

beforeEach(function () {
settings.update({ streaming: { filterUnsupportedEssentialProperties: true } });
settings.update({ streaming: { capabilities: { filterUnsupportedEssentialProperties: true }} });
});

it('should not filter AdaptationSets and Representations if filterUnsupportedEssentialProperties is disabled', function (done) {
settings.update({ streaming: { filterUnsupportedEssentialProperties: false } });
settings.update({ streaming: { capabilities: {filterUnsupportedEssentialProperties: false }} });
const manifest = {
Period_asArray: [{
AdaptationSet_asArray: [{
Expand Down Expand Up @@ -337,24 +337,25 @@ describe('CapabilitiesFilter', function () {
it('should use provided custom filters', function (done) {
const manifest = {
Period_asArray: [{
AdaptationSet_asArray: [{
mimeType: 'video/mp4',
Representation_asArray: [
{
mimeType: 'video/mp4',
height: 1080
},
{
mimeType: 'video/mp4',
height: 720
},
{
mimeType: 'video/mp4',
height: 480
}
]
AdaptationSet_asArray: [{
mimeType: 'video/mp4',
Representation_asArray: [
{
mimeType: 'video/mp4',
height: 1080
},
{
mimeType: 'video/mp4',
height: 720
},
{
mimeType: 'video/mp4',
height: 480
}
]
}]
}]
}]};
};

capabilitiesFilter.setCustomCapabilitiesFilters([function (representation) {
return representation.height <= 720;
Expand Down

0 comments on commit 215fc3d

Please sign in to comment.