Skip to content

Commit 27976f1

Browse files
authored
feat: Add streaming.preferNativeDash config (#7737)
This is useful for WebOS, because in MSE there is no support for VVC but there is support for src=
1 parent 79a481e commit 27976f1

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed

demo/config.js

+2
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ shakaDemo.Config = class {
488488
.addBoolInput_('Force HTTPS', 'streaming.forceHTTPS')
489489
.addNumberInput_('Min bytes for progress events',
490490
'streaming.minBytesForProgressEvents')
491+
.addBoolInput_('Prefer native DASH playback when available',
492+
'streaming.preferNativeDash')
491493
.addBoolInput_('Prefer native HLS playback when available',
492494
'streaming.preferNativeHls')
493495
.addNumberInput_('Update interval seconds',

externs/shaka/player.js

+5
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,7 @@ shaka.extern.LiveSyncConfiguration;
15641564
* forceHTTP: boolean,
15651565
* forceHTTPS: boolean,
15661566
* minBytesForProgressEvents: number,
1567+
* preferNativeDash: boolean,
15671568
* preferNativeHls: boolean,
15681569
* updateIntervalSeconds: number,
15691570
* observeQualityChanges: boolean,
@@ -1740,6 +1741,10 @@ shaka.extern.LiveSyncConfiguration;
17401741
* if possible. To avoid issues around feeding ABR with request history, this
17411742
* value should be greater than or equal to `abr.advanced.minBytes`.
17421743
* By default equals 16e3 (the same value as `abr.advanced.minBytes`).
1744+
* @property {boolean} preferNativeDash
1745+
* If true, prefer native DASH playback when possible, regardless of platform.
1746+
* <br>
1747+
* Defaults to <code>false</code>.
17431748
* @property {boolean} preferNativeHls
17441749
* If true, prefer native HLS playback when possible, regardless of platform.
17451750
* <br>

lib/player.js

+5
Original file line numberDiff line numberDiff line change
@@ -2371,6 +2371,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
23712371
return this.config_.streaming.preferNativeHls;
23722372
}
23732373

2374+
if (MimeUtils.isDashType(mimeType)) {
2375+
// Native DASH can be preferred on any platform via this flag:
2376+
return this.config_.streaming.preferNativeDash;
2377+
}
2378+
23742379
// In all other cases, we prefer MediaSource.
23752380
return false;
23762381
}

lib/util/mime_utils.js

+11
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,17 @@ shaka.util.MimeUtils = class {
251251
mimeType === 'application/vnd.apple.mpegurl';
252252
}
253253

254+
/**
255+
* Checks if the given MIME type is DASH MIME type.
256+
*
257+
* @param {string} mimeType
258+
* @return {boolean}
259+
*/
260+
static isDashType(mimeType) {
261+
return mimeType === 'application/dash+xml' ||
262+
mimeType === 'video/vnd.mpeg.dash.mpd';
263+
}
264+
254265
/**
255266
* Get the base and profile of a codec string. Where [0] will be the codec
256267
* base and [1] will be the profile.

lib/util/player_configuration.js

+1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ shaka.util.PlayerConfiguration = class {
233233
forceHTTP: false,
234234
forceHTTPS: false,
235235
minBytesForProgressEvents: minBytes,
236+
preferNativeDash: false,
236237
preferNativeHls: false,
237238
updateIntervalSeconds: 1,
238239
observeQualityChanges: false,

test/player_unit.js

+56
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,62 @@ describe('Player', () => {
731731
});
732732
});
733733

734+
describe('when config.streaming.preferNativeDash is set to true', () => {
735+
beforeAll(() => {
736+
shaka.media.ManifestParser.registerParserByMime(
737+
'application/dash+xml',
738+
() => new shaka.test.FakeManifestParser(manifest));
739+
});
740+
741+
afterAll(() => {
742+
// IMPORTANT: restore the ORIGINAL parser. DO NOT just unregister the
743+
// fake!
744+
shaka.media.ManifestParser.registerParserByMime(
745+
'application/dash+xml',
746+
() => new shaka.dash.DashParser());
747+
});
748+
749+
afterEach(() => {
750+
video.canPlayType.calls.reset();
751+
});
752+
753+
it('only applies to DASH streams', async () => {
754+
video.canPlayType.and.returnValue('maybe');
755+
spyOn(shaka.util.Platform, 'anyMediaElement').and.returnValue(video);
756+
spyOn(shaka.util.Platform, 'supportsMediaSource').and.returnValue(true);
757+
// Make sure player.load() resolves for src=
758+
spyOn(shaka.util.MediaReadyState, 'waitForReadyState').and.callFake(
759+
(mediaElement, readyState, eventManager, callback) => {
760+
callback();
761+
});
762+
763+
player.configure({
764+
streaming: {
765+
preferNativeDash: true,
766+
},
767+
});
768+
769+
await player.load(fakeManifestUri, undefined, 'application/dash+xml');
770+
771+
expect(player.getLoadMode()).toBe(shaka.Player.LoadMode.SRC_EQUALS);
772+
});
773+
774+
it('does not apply to non-DASH streams', async () => {
775+
video.canPlayType.and.returnValue('maybe');
776+
spyOn(shaka.util.Platform, 'supportsMediaSource').and.returnValue(true);
777+
778+
player.configure({
779+
streaming: {
780+
preferNativeDash: true,
781+
},
782+
});
783+
784+
await player.load(fakeManifestUri, 0, fakeMimeType);
785+
786+
expect(player.getLoadMode()).toBe(shaka.Player.LoadMode.MEDIA_SOURCE);
787+
});
788+
});
789+
734790
describe('when config.streaming.preferNativeHls is set to true', () => {
735791
beforeAll(() => {
736792
shaka.media.ManifestParser.registerParserByMime(

0 commit comments

Comments
 (0)