Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: config.streaming.preferNativeHls only applies to HLS streams #5167

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
*/
shouldUseSrcEquals_(payload) {
const Platform = shaka.util.Platform;
const MimeUtils = shaka.util.MimeUtils;

// If we are using a platform that does not support media source, we will
// fall back to src= to handle all playback.
Expand Down Expand Up @@ -1402,7 +1403,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
// version there.

// Native HLS can be preferred on any platform via this flag:
if (this.config_.streaming.preferNativeHls) {
if (MimeUtils.isHlsType(mimeType) &&
this.config_.streaming.preferNativeHls) {
return true;
}

Expand Down
11 changes: 11 additions & 0 deletions lib/util/mime_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ shaka.util.MimeUtils = class {
return value;
}

/**
* Checks if the given MIME type is HLS MIME type.
*
* @param {string} mimeType
* @return {boolean}
*/
static isHlsType(mimeType) {
return mimeType === 'application/x-mpegurl' ||
mimeType === 'application/vnd.apple.mpegurl';
}

/**
* Get the base and profile of a codec string. Where [0] will be the codec
* base and [1] will be the profile.
Expand Down
54 changes: 54 additions & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,60 @@ describe('Player', () => {
expect(streamingEngine.unloadTextStream).not.toHaveBeenCalled();
});
});

describe('when config.streaming.preferNativeHls is set to true', () => {
beforeEach(() => {
shaka.media.ManifestParser.registerParserByMime(
'application/x-mpegurl',
() => new shaka.test.FakeManifestParser(manifest));
});

afterEach(() => {
shaka.media.ManifestParser.unregisterParserByMime(
'application/x-mpegurl');
video.canPlayType.calls.reset();
});

it('only applies to HLS streams', async () => {
video.canPlayType.and.returnValue('maybe');
spyOn(shaka.util.Platform, 'anyMediaElement').and.returnValue(video);
spyOn(shaka.util.Platform, 'supportsMediaSource').and.returnValue(true);
spyOn(shaka.util.Platform, 'isApple').and.returnValue(false);
// Make sure player.load() resolves for src=
spyOn(shaka.util.MediaReadyState, 'waitForReadyState').and.callFake(
(mediaElement, readyState, eventManager, callback) => {
callback();
});

player.configure({
streaming: {
preferNativeHls: true,
useNativeHlsOnSafari: false,
},
});

await player.load(fakeManifestUri, undefined, 'application/x-mpegurl');

expect(player.getLoadMode()).toBe(shaka.Player.LoadMode.SRC_EQUALS);
});

it('does not apply to non-HLS streams', async () => {
video.canPlayType.and.returnValue('maybe');
spyOn(shaka.util.Platform, 'supportsMediaSource').and.returnValue(true);
spyOn(shaka.util.Platform, 'isApple').and.returnValue(false);

player.configure({
streaming: {
preferNativeHls: true,
useNativeHlsOnSafari: false,
},
});

await player.load(fakeManifestUri, 0, fakeMimeType);

expect(player.getLoadMode()).toBe(shaka.Player.LoadMode.MEDIA_SOURCE);
});
});
}); // describe('load/unload')

describe('getConfiguration', () => {
Expand Down
3 changes: 3 additions & 0 deletions test/test/util/fake_drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ shaka.test.FakeDrmEngine = class {
/** @type {!jasmine.Spy} */
this.supportsVariant = jasmine.createSpy('supportsVariant');
this.supportsVariant.and.returnValue(true);

/** @type {!jasmine.Spy} */
this.setSrcEquals = jasmine.createSpy('setSrcEquals');
}

/**
Expand Down
3 changes: 3 additions & 0 deletions test/test/util/simple_fakes.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ shaka.test.FakeVideo = class {

/** @type {!jasmine.Spy} */
this.dispatchEvent = jasmine.createSpy('dispatchEvent');

/** @type {!jasmine.Spy} */
this.canPlayType = jasmine.createSpy('canPlayType');
}
};

Expand Down
10 changes: 10 additions & 0 deletions test/util/mime_utils_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,14 @@ describe('MimeUtils', () => {
expect(getNormalizedCodec('dvh1.05')).toBe('dovi');
expect(getNormalizedCodec('dvhe.05')).toBe('dovi');
});

it('isHlsType', () => {
const isHlsType = (mimeType) => shaka.util.MimeUtils.isHlsType(mimeType);

expect(isHlsType('application/x-mpegurl')).toBe(true);
expect(isHlsType('application/vnd.apple.mpegurl')).toBe(true);
expect(isHlsType('application/dash+xml')).toBe(false);
expect(isHlsType('application/vnd.ms-sstr+xml')).toBe(false);
expect(isHlsType('foo')).toBe(false);
});
});