Skip to content

Commit

Permalink
fix: only prevent audio group creation if no other playlists are usin…
Browse files Browse the repository at this point in the history
…g it (#981)
  • Loading branch information
brandonocasey authored Oct 30, 2020
1 parent 200c87b commit 645e979
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 10 deletions.
6 changes: 6 additions & 0 deletions scripts/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,5 +303,11 @@
"uri": "https://d2zihajmogu5jn.cloudfront.net/audio-only-dupe-groups/prog_index.m3u8",
"mimetype": "application/x-mpegurl",
"features": []
},
{
"name": "Big Buck Bunny Demuxed av, audio only rendition same as group",
"uri": "https://d2zihajmogu5jn.cloudfront.net/demuxed-ts-with-audio-only-rendition/master.m3u8",
"mimetype": "application/x-mpegurl",
"features": []
}
]
20 changes: 10 additions & 10 deletions src/media-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,18 +405,18 @@ export const initialize = {
for (const variantLabel in mediaGroups[type][groupId]) {
let properties = mediaGroups[type][groupId][variantLabel];

// List of playlists for the current group ID that have a matching uri with
// this alternate audio variant
const matchingPlaylists = groupPlaylists.filter(playlist => {
return playlist.resolvedUri === properties.resolvedUri;
// List of playlists for the current group ID that do not have a matching uri
// with this alternate audio variant
const unmatchingPlaylists = groupPlaylists.filter(playlist => {
return playlist.resolvedUri !== properties.resolvedUri;
});

if (matchingPlaylists.length) {
// If there is a playlist that has the same uri as this audio variant, assume
// that the playlist is audio only. We delete the resolvedUri property here
// to prevent a playlist loader from being created so that we don't have
// both the main and audio segment loaders loading the same audio segments
// from the same playlist.
// If there are no playlists using this audio group other than ones
// that match it's uri, then the playlist is audio only. We delete the resolvedUri
// property here to prevent a playlist loader from being created so that we don't have
// both the main and audio segment loaders loading the same audio segments
// from the same playlist.
if (!unmatchingPlaylists.length && groupPlaylists.length) {
delete properties.resolvedUri;
}

Expand Down
37 changes: 37 additions & 0 deletions test/media-groups.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,43 @@ QUnit.test('initialize audio correctly uses HLS source type', function(assert) {
);
});

QUnit.test('no audio loader for audio only with duplicated audio groups', function(assert) {
this.master.mediaGroups.AUDIO.aud1 = {
en: { default: true, language: 'en', resolvedUri: 'en.m3u8' }
};

this.settings.sourceType = 'hls';

this.settings.master.playlists = [
{resolvedUri: 'en.m3u8', attributes: {AUDIO: 'aud1'}}
];
MediaGroups.initialize.AUDIO('AUDIO', this.settings);

assert.notOk(
this.mediaTypes.AUDIO.groups.aud1[0].playlistLoader,
'no loader as audio group is the same as main renditions'
);
});

QUnit.test('audio loader created with audio group duplicated as audio only rendition', function(assert) {
this.master.mediaGroups.AUDIO.aud1 = {
en: { default: true, language: 'en', resolvedUri: 'en.m3u8' }
};

this.settings.sourceType = 'hls';

this.settings.master.playlists = [
{resolvedUri: 'video/en.m3u8', attributes: {AUDIO: 'aud1'}},
{resolvedUri: 'en.m3u8', attributes: {AUDIO: 'aud1'}}
];
MediaGroups.initialize.AUDIO('AUDIO', this.settings);

assert.ok(
this.mediaTypes.AUDIO.groups.aud1[0].playlistLoader,
'audio loader created'
);
});

QUnit.test('initialize audio correctly uses DASH source type', function(assert) {
// allow async methods to resolve before next test
const done = assert.async();
Expand Down
19 changes: 19 additions & 0 deletions test/playback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,25 @@ QUnit[testFn]('Big Buck Bunny audio only, groups & renditions same uri', functio
});
});

QUnit[testFn]('Big Buck Bunny Demuxed av, audio only rendition same as group', function(assert) {
const done = assert.async();

assert.expect(2);
const player = this.player;

playFor(player, 25, function() {
assert.ok(true, 'played for at least 25 seconds');
assert.equal(player.error(), null, 'has no player errors');

done();
});

player.src({
src: 'https://d2zihajmogu5jn.cloudfront.net/demuxed-ts-with-audio-only-rendition/master.m3u8',
type: 'application/x-mpegURL'
});
});

QUnit[testFn]('Live DASH', function(assert) {
const done = assert.async();

Expand Down

0 comments on commit 645e979

Please sign in to comment.