Skip to content

Commit

Permalink
Ignore duplicate CODECS in HLS.
Browse files Browse the repository at this point in the history
In HLS, the CODECS attribute may contain duplicate of the same codec
with different profiles.

Closes #1817

Change-Id: I0d59c1ade6c8387a2e6b3ca00c0287e15c943ea3
  • Loading branch information
TheModMaker committed Apr 29, 2019
1 parent bd291ef commit fbb558a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
30 changes: 29 additions & 1 deletion lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,8 @@ shaka.hls.HlsParser.prototype.createVariantsForTag_ =
const codecsString = tag.getAttributeValue('CODECS', defaultCodecs);
// Strip out internal whitespace while splitting on commas:
/** @type {!Array.<string>} */
let codecs = codecsString.split(/\s*,\s*/);
let codecs =
shaka.hls.HlsParser.filterDuplicateCodecs_(codecsString.split(/\s*,\s*/));
let resolutionAttr = tag.getAttribute('RESOLUTION');
let width = null;
let height = null;
Expand Down Expand Up @@ -1891,6 +1892,33 @@ shaka.hls.HlsParser.prototype.getStartTimeFromTextSegment_ =
};


/**
* Filters out duplicate codecs from the codec list.
* @param {!Array.<string>} codecs
* @return {!Array.<string>}
* @private
*/
shaka.hls.HlsParser.filterDuplicateCodecs_ = function(codecs) {
const seen = new Set();
const ret = [];
for (const codec of codecs) {
// HLS says the CODECS field needs to include all codecs that appear in the
// content. This means that if the content changes profiles, it should
// include both. Since all known browsers support changing profiles without
// any other work, just ignore them See also:
// https://github.com/google/shaka-player/issues/1817
const shortCodec = shaka.util.MimeUtils.getCodecBase(codec);
if (!seen.has(shortCodec)) {
ret.push(codec);
seen.add(shortCodec);
} else {
shaka.log.debug('Ignoring duplicate codec');
}
}
return ret;
};


/**
* Attempts to guess which codecs from the codecs list belong to a given content
* type. Does not assume a single codec is anything special, and does not throw
Expand Down
28 changes: 28 additions & 0 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,34 @@ describe('HlsParser', function() {
.catch(fail).then(done);
});

it('ignores duplicate CODECS', async function() {
let master = [
'#EXTM3U\n',
'#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1.4d001e,avc1.42000d",',
'RESOLUTION=960x540,FRAME-RATE=60\n',
'video',
].join('');

let media = [
'#EXTM3U\n',
'#EXT-X-PLAYLIST-TYPE:VOD\n',
'#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
'#EXTINF:5,\n',
'#EXT-X-BYTERANGE:121090@616\n',
'main.mp4',
].join('');

let manifest = new shaka.test.ManifestGenerator()
.anyTimeline()
.addPeriod(0)
.addPartialVariant()
.addPartialStream(ContentType.VIDEO)
.mime('video/mp4', 'avc1.4d001e')
.build();

await testHlsParser(master, media, manifest);
});

it('parses video-only variant', async function() {
let master = [
'#EXTM3U\n',
Expand Down

0 comments on commit fbb558a

Please sign in to comment.