Skip to content

Commit

Permalink
feat(HLS): Improve the stream info when EXT-X-MEDIA has not uri (#5886)
Browse files Browse the repository at this point in the history
Closes #5447
  • Loading branch information
avelad authored Nov 16, 2023
1 parent d8aa24f commit b5b6a0f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
46 changes: 38 additions & 8 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1501,8 +1501,32 @@ shaka.hls.HlsParser = class {
}

if (!ignoreStream) {
const streamInfo =
this.createStreamInfoFromVariantTags_(tags, allCodecs, type);
let language = null;
let name = null;
let channelsCount = null;
let spatialAudio = false;
let characteristics = null;
let sampleRate = null;
if (!streamInfos.length) {
const mediaTag = mediaTags.find((tag) => {
const uri = tag.getAttributeValue('URI') || '';
const type = tag.getAttributeValue('TYPE');
const groupId = tag.getRequiredAttrValue('GROUP-ID');
return type != 'SUBTITLES' && uri == '' &&
globalGroupIds.includes(groupId);
});
if (mediaTag) {
language = mediaTag.getAttributeValue('LANGUAGE');
name = mediaTag.getAttributeValue('NAME');
channelsCount = this.getChannelsCount_(mediaTag);
spatialAudio = this.isSpatialAudio_(mediaTag);
characteristics = mediaTag.getAttributeValue('CHARACTERISTICS');
sampleRate = this.getSampleRate_(mediaTag);
}
}
const streamInfo = this.createStreamInfoFromVariantTags_(
tags, allCodecs, type, language, name, channelsCount,
characteristics, sampleRate, spatialAudio);
if (globalGroupId) {
streamInfo.stream.groupId = globalGroupId;
}
Expand Down Expand Up @@ -2035,10 +2059,17 @@ shaka.hls.HlsParser = class {
* @param {!Array.<!shaka.hls.Tag>} tags
* @param {!Array.<string>} allCodecs
* @param {string} type
* @param {?string} language
* @param {?string} name
* @param {?number} channelsCount
* @param {?string} characteristics
* @param {?number} sampleRate
* @param {boolean} spatialAudio
* @return {!shaka.hls.HlsParser.StreamInfo}
* @private
*/
createStreamInfoFromVariantTags_(tags, allCodecs, type) {
createStreamInfoFromVariantTags_(tags, allCodecs, type, language, name,
channelsCount, characteristics, sampleRate, spatialAudio) {
const streamId = this.globalId_++;
const verbatimMediaPlaylistUris = [];
for (const tag of tags) {
Expand All @@ -2060,11 +2091,10 @@ shaka.hls.HlsParser = class {
const closedCaptions = this.getClosedCaptions_(tags[0], type);
const codecs = shaka.util.ManifestParserUtils.guessCodecs(type, allCodecs);
const streamInfo = this.createStreamInfo_(
streamId, verbatimMediaPlaylistUris,
codecs, type, /* language= */ null, /* primary= */ false,
/* name= */ null, /* channelcount= */ null, closedCaptions,
/* characteristics= */ null, /* forced= */ false,
/* sampleRate= */ null, /* spatialAudio= */ false);
streamId, verbatimMediaPlaylistUris, codecs, type, language,
/* primary= */ false, name, channelsCount, closedCaptions,
characteristics, /* forced= */ false, sampleRate,
/* spatialAudio= */ false);

this.uriToStreamInfosMap_.set(key, streamInfo);
return streamInfo;
Expand Down
5 changes: 4 additions & 1 deletion test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ describe('HlsParser', () => {
'#EXT-X-STREAM-INF:BANDWIDTH=200,',
'RESOLUTION=960x540,FRAME-RATE=60,AUDIO="aud1"\n',
'video\n',
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",NAME="audio"\n',
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="eng",NAME="audio"\n',
].join('');

const media = [
Expand All @@ -941,6 +941,9 @@ describe('HlsParser', () => {
manifest.addPartialVariant((variant) => {
variant.addPartialStream(ContentType.VIDEO, (stream) => {
stream.mime('video/mp4', /** @type {?} */ (jasmine.any(String)));
stream.language = 'en';
stream.originalLanguage = 'eng';
stream.label = 'audio';
});
});
manifest.sequenceMode = sequenceMode;
Expand Down

0 comments on commit b5b6a0f

Please sign in to comment.