Skip to content

Commit

Permalink
fix(HLS): Disable audio/video correctly when loading a TS media playl…
Browse files Browse the repository at this point in the history
…ist (#7815)
  • Loading branch information
avelad authored Dec 31, 2024
1 parent 19c6e46 commit 626591e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 46 deletions.
4 changes: 2 additions & 2 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1164,8 +1164,8 @@ shaka.hls.HlsParser = class {

if (shaka.util.TsParser.probe(
shaka.util.BufferUtils.toUint8(data))) {
const basicInfo =
shaka.media.SegmentUtils.getBasicInfoFromTs(data);
const basicInfo = shaka.media.SegmentUtils.getBasicInfoFromTs(
data, this.config_.disableAudio, this.config_.disableVideo);
if (basicInfo) {
return basicInfo;
}
Expand Down
94 changes: 50 additions & 44 deletions lib/media/segment_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,60 +48,66 @@ shaka.media.SegmentUtils = class {

/**
* @param {!BufferSource} data
* @param {boolean=} disableAudio
* @param {boolean=} disableVideo
* @return {?shaka.media.SegmentUtils.BasicInfo}
*/
static getBasicInfoFromTs(data) {
static getBasicInfoFromTs(data, disableAudio = false, disableVideo = false) {
const uint8ArrayData = shaka.util.BufferUtils.toUint8(data);
const tsParser = new shaka.util.TsParser().parse(uint8ArrayData);
const tsCodecs = tsParser.getCodecs();
const videoInfo = tsParser.getVideoInfo();
const codecs = [];
let hasAudio = false;
let hasVideo = false;
switch (tsCodecs.audio) {
case 'aac':
case 'aac-loas':
codecs.push('mp4a.40.2');
hasAudio = true;
break;
case 'mp3':
codecs.push('mp4a.40.34');
hasAudio = true;
break;
case 'ac3':
codecs.push('ac-3');
hasAudio = true;
break;
case 'ec3':
codecs.push('ec-3');
hasAudio = true;
break;
case 'opus':
codecs.push('opus');
hasAudio = true;
break;
if (!disableAudio) {
switch (tsCodecs.audio) {
case 'aac':
case 'aac-loas':
codecs.push('mp4a.40.2');
hasAudio = true;
break;
case 'mp3':
codecs.push('mp4a.40.34');
hasAudio = true;
break;
case 'ac3':
codecs.push('ac-3');
hasAudio = true;
break;
case 'ec3':
codecs.push('ec-3');
hasAudio = true;
break;
case 'opus':
codecs.push('opus');
hasAudio = true;
break;
}
}
switch (tsCodecs.video) {
case 'avc':
if (videoInfo.codec) {
codecs.push(videoInfo.codec);
} else {
codecs.push('avc1.42E01E');
}
hasVideo = true;
break;
case 'hvc':
if (videoInfo.codec) {
codecs.push(videoInfo.codec);
} else {
codecs.push('hvc1.1.6.L93.90');
}
hasVideo = true;
break;
case 'av1':
codecs.push('av01.0.01M.08');
hasVideo = true;
break;
if (!disableVideo) {
switch (tsCodecs.video) {
case 'avc':
if (videoInfo.codec) {
codecs.push(videoInfo.codec);
} else {
codecs.push('avc1.42E01E');
}
hasVideo = true;
break;
case 'hvc':
if (videoInfo.codec) {
codecs.push(videoInfo.codec);
} else {
codecs.push('hvc1.1.6.L93.90');
}
hasVideo = true;
break;
case 'av1':
codecs.push('av01.0.01M.08');
hasVideo = true;
break;
}
}
if (!codecs.length) {
return null;
Expand Down

0 comments on commit 626591e

Please sign in to comment.