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: CMAF HLS. Source buffer change type is called with wrong codecs sometimes when append segment without init data because of a race condition. #1375

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1715,9 +1715,11 @@ export class PlaylistController extends videojs.EventTarget {
audio: this.audioSegmentLoader_.getCurrentMediaInfo_() || {}
};

const playlist = this.mainSegmentLoader_.getPendingSegmentPlaylist() || this.media();

// set "main" media equal to video
media.video = media.main;
const playlistCodecs = codecsForPlaylist(this.main(), this.media());
const playlistCodecs = codecsForPlaylist(this.main(), playlist);
const codecs = {};
const usingAudioLoader = !!this.mediaTypes_.AUDIO.activePlaylistLoader;

Expand All @@ -1738,7 +1740,7 @@ export class PlaylistController extends videojs.EventTarget {
// no codecs, no playback.
if (!codecs.audio && !codecs.video) {
this.excludePlaylist({
playlistToExclude: this.media(),
playlistToExclude: playlist,
error: { message: 'Could not determine codecs for playlist.' },
playlistExclusionDuration: Infinity
});
Expand All @@ -1763,13 +1765,13 @@ export class PlaylistController extends videojs.EventTarget {
}
});

if (usingAudioLoader && unsupportedAudio && this.media().attributes.AUDIO) {
const audioGroup = this.media().attributes.AUDIO;
if (usingAudioLoader && unsupportedAudio && playlist.attributes.AUDIO) {
const audioGroup = playlist.attributes.AUDIO;

this.main().playlists.forEach(variant => {
const variantAudioGroup = variant.attributes && variant.attributes.AUDIO;

if (variantAudioGroup === audioGroup && variant !== this.media()) {
if (variantAudioGroup === audioGroup && variant !== playlist) {
variant.excludeUntil = Infinity;
}
});
Expand All @@ -1790,7 +1792,7 @@ export class PlaylistController extends videojs.EventTarget {
}, '') + '.';

this.excludePlaylist({
playlistToExclude: this.media(),
playlistToExclude: playlist,
error: {
internal: true,
message
Expand All @@ -1817,7 +1819,7 @@ export class PlaylistController extends videojs.EventTarget {

if (switchMessages.length) {
this.excludePlaylist({
playlistToExclude: this.media(),
playlistToExclude: playlist,
error: {
message: `Codec switching not supported: ${switchMessages.join(', ')}.`,
internal: true
Expand Down
5 changes: 5 additions & 0 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,7 @@ export default class SegmentLoader extends videojs.EventTarget {
*/
resetEverything(done) {
this.ended_ = false;
this.activeInitSegmentId_ = null;
this.appendInitSegment_ = {
audio: true,
video: true
Expand Down Expand Up @@ -1983,6 +1984,10 @@ export default class SegmentLoader extends videojs.EventTarget {
return this.getCurrentMediaInfo_(segmentInfo) || this.startingMediaInfo_;
}

getPendingSegmentPlaylist() {
return this.pendingSegment_ ? this.pendingSegment_.playlist : null;
}

hasEnoughInfoToAppend_() {
if (!this.sourceUpdater_.ready()) {
return false;
Expand Down
40 changes: 40 additions & 0 deletions test/playlist-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4971,6 +4971,25 @@ QUnit.test('playlist codecs take priority over others', function(assert) {
assert.deepEqual(codecs, {video: 'avc1.4b400d', audio: 'mp4a.40.20'}, 'codecs returned');
});

QUnit.test('Current pending segment\'s playlist codecs take priority over others', function(assert) {
this.contentSetup({
mainStartingMedia: {videoCodec: 'avc1.4c400d', hasVideo: true, hasAudio: false},
audioStartingMedia: {audioCodec: 'mp4a.40.5', hasVideo: false, hasAudio: true},
mainPlaylist: {attributes: {CODECS: 'avc1.4b400d', AUDIO: 'low-quality'}},
audioPlaylist: {attributes: {CODECS: 'mp4a.40.20'}}
});

const originalGetPendingSegmentPlaylist = this.pc.mainSegmentLoader_.getPendingSegmentPlaylist.bind(this.pc.mainSegmentLoader_);

this.pc.mainSegmentLoader_.getPendingSegmentPlaylist = () => ({attributes: {CODECS: 'avc1.64001f', AUDIO: 'low-quality'}});

const codecs = this.pc.getCodecsOrExclude_();

assert.deepEqual(this.exclusionList, [], 'did not blacklist anything');
assert.deepEqual(codecs, {video: 'avc1.64001f', audio: 'mp4a.40.20'}, 'codecs returned');
this.pc.mainSegmentLoader_.getPendingSegmentPlaylist = originalGetPendingSegmentPlaylist;
});

QUnit.test('uses default codecs if no codecs are found', function(assert) {
this.contentSetup({
mainStartingMedia: {hasVideo: true, hasAudio: false},
Expand Down Expand Up @@ -5002,6 +5021,27 @@ QUnit.test('excludes playlist without detected audio/video', function(assert) {
assert.deepEqual(codecs, void 0, 'no codecs returned');
});

QUnit.test('excludes current pending segment\'s playlist without detected audio/video', function(assert) {
this.contentSetup({
mainStartingMedia: {},
audioStartingMedia: {},
mainPlaylist: {attributes: {}}
});

const originalGetPendingSegmentPlaylist = this.pc.mainSegmentLoader_.getPendingSegmentPlaylist.bind(this.pc.mainSegmentLoader_);

this.pc.mainSegmentLoader_.getPendingSegmentPlaylist = () => ({attributes: {CODECS: ''}});
const codecs = this.pc.getCodecsOrExclude_();

assert.deepEqual(this.exclusionList, [{
playlistExclusionDuration: Infinity,
playlistToExclude: {attributes: {CODECS: ''}},
error: { message: 'Could not determine codecs for playlist.' }
}], 'excluded playlist');
assert.deepEqual(codecs, void 0, 'no codecs returned');
this.pc.mainSegmentLoader_.getPendingSegmentPlaylist = originalGetPendingSegmentPlaylist;
});

QUnit.test('excludes unsupported muxer codecs for ts', function(assert) {
this.contentSetup({
mainStartingMedia: {
Expand Down