Skip to content

Commit

Permalink
fix(HLS): Fix switching between muxed MP4 and muxed TS
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Feb 11, 2025
1 parent 9a618d4 commit 3e34717
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ module.exports = (config) => {
{pattern: 'test/test/assets/dv-p10-av1/*', included: false},
{pattern: 'test/test/assets/hls-aes-256/*', included: false},
{pattern: 'test/test/assets/hls-interstitial/*', included: false},
{pattern: 'test/test/assets/hls-muxed-mp4-ts/*', included: false},
{pattern: 'test/test/assets/hls-raw-aac/*', included: false},
{pattern: 'test/test/assets/hls-raw-ac3/*', included: false},
{pattern: 'test/test/assets/hls-raw-ec3/*', included: false},
Expand Down
3 changes: 2 additions & 1 deletion lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2422,7 +2422,8 @@ shaka.media.MediaSourceEngine = class {
const newMimeType = realInfo.mimeType;

let muxedContentCheck = true;
if (transmuxerMuxed) {
if (transmuxerMuxed &&
this.sourceBufferTypes_.has(ContentType.AUDIO)) {
const muxedRealInfo =
this.getRealInfo_(ContentType.AUDIO, mimeType, codecs);
const muxedCurrentCodec = MimeUtils.getNormalizedCodec(
Expand Down
30 changes: 30 additions & 0 deletions test/hls/hls_parser_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,34 @@ describe('HlsParser', () => {

await player.unload();
});

it('allow switch between mp4 muxed and ts muxed', async () => {
if (!await Util.isTypeSupported(
'video/mp4; codecs="av01.0.31M.08"',
/* width= */ 1920, /* height= */ 1080)) {
pending('Codec AV1 is not supported by the platform.');
}
player.configure('abr.enabled', false);
await player.load('/base/test/test/assets/hls-muxed-mp4-ts/master.m3u8');
await video.play();

expect(player.getVariantTracks().length).toBe(2);

// We want to test TS --> MP4 and MP4 --> TS, that's why
// selectVariantTrack is called twice

await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 1, 30);

let nonActiveVariant = player.getVariantTracks().find((v) => !v.active);
player.selectVariantTrack(nonActiveVariant, /* clearBuffer= */ true);

await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 3, 30);

nonActiveVariant = player.getVariantTracks().find((v) => !v.active);
player.selectVariantTrack(nonActiveVariant, /* clearBuffer= */ true);

await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 5, 30);

await player.unload();
});
});
Binary file added test/test/assets/hls-muxed-mp4-ts/000000000.m4s
Binary file not shown.
Binary file added test/test/assets/hls-muxed-mp4-ts/000000000.ts
Binary file not shown.
Binary file added test/test/assets/hls-muxed-mp4-ts/init.mp4
Binary file not shown.
6 changes: 6 additions & 0 deletions test/test/assets/hls-muxed-mp4-ts/master.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=3500000,RESOLUTION=1920x1080,FRAMERATE=60,CODECS="av01.0.31M.08,mp4a.40.2",NAME="1080p60 AV1"
mp4.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2600000,RESOLUTION=1280x720,FRAMERATE=30,CODECS="avc1.4D401F,mp4a.40.2",NAME="720p"
ts.m3u8
9 changes: 9 additions & 0 deletions test/test/assets/hls-muxed-mp4-ts/mp4.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#EXTM3U
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:8
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="init.mp4"
#EXTINF:8.000000,
000000000.m4s
#EXT-X-ENDLIST
8 changes: 8 additions & 0 deletions test/test/assets/hls-muxed-mp4-ts/ts.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:8
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:8.000000,
000000000.ts
#EXT-X-ENDLIST

0 comments on commit 3e34717

Please sign in to comment.