From 8fee97bbdfe8a6533d3c7bdc74f97939bc7ef0e4 Mon Sep 17 00:00:00 2001 From: yajin2021 Date: Tue, 9 Aug 2022 17:28:08 +0800 Subject: [PATCH 1/5] fix: a/v out of sync --- src/remux/mp4-remuxer.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/remux/mp4-remuxer.ts b/src/remux/mp4-remuxer.ts index 78fea472e84..ddc5e079771 100644 --- a/src/remux/mp4-remuxer.ts +++ b/src/remux/mp4-remuxer.ts @@ -55,6 +55,7 @@ export default class MP4Remuxer implements Remuxer { height?: number; pixelRatio?: [number, number]; }; + private isDiscontinuity: boolean = false; constructor( observer: HlsEventEmitter, @@ -86,6 +87,7 @@ export default class MP4Remuxer implements Remuxer { resetTimeStamp(defaultTimeStamp: RationalTimestamp | null) { logger.log('[mp4-remuxer]: initPTS & initDTS reset'); this._initPTS = this._initDTS = defaultTimeStamp; + this.isDiscontinuity = true; } resetNextTimestamp() { @@ -182,7 +184,11 @@ export default class MP4Remuxer implements Remuxer { if (enoughVideoSamples) { firstKeyFrameIndex = findKeyframeIndex(videoTrack.samples); - if (!isVideoContiguous && this.config.forceKeyFrameOnDiscontinuity) { + if ( + this.config.forceKeyFrameOnDiscontinuity && + (!isVideoContiguous || + (this.isDiscontinuity && firstKeyFrameIndex > 0)) + ) { independent = true; if (firstKeyFrameIndex > 0) { logger.warn( @@ -190,6 +196,9 @@ export default class MP4Remuxer implements Remuxer { ); const startPTS = this.getVideoStartPts(videoTrack.samples); videoTrack.samples = videoTrack.samples.slice(firstKeyFrameIndex); + if (this.isDiscontinuity) { + firstKeyFrameIndex = 0; + } videoTrack.dropped += firstKeyFrameIndex; videoTimeOffset += (videoTrack.samples[0].pts - startPTS) / From 069478e6642e6548cac738e862cf4980efcaba52 Mon Sep 17 00:00:00 2001 From: grabofus Date: Wed, 24 Apr 2024 16:20:45 +0100 Subject: [PATCH 2/5] fix: avoid filtering out VTTCues with matching ids --- src/utils/texttrack-utils.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/utils/texttrack-utils.ts b/src/utils/texttrack-utils.ts index b1a164ed29a..ad64dbfb7b3 100644 --- a/src/utils/texttrack-utils.ts +++ b/src/utils/texttrack-utils.ts @@ -13,6 +13,25 @@ export function sendAddTrackEvent(track: TextTrack, videoEl: HTMLMediaElement) { videoEl.dispatchEvent(event); } +function containsCue(track: TextTrack, cue: VTTCue) { + if (!track.cues) { + return false; + } + + for (let i = 0; i < track.cues.length; i++) { + const cueInTextTrack = track.cues[i] as VTTCue; + if ( + cueInTextTrack.startTime === cue.startTime && + cueInTextTrack.endTime === cue.endTime && + cueInTextTrack.text === cue.text + ) { + return true; + } + } + + return false; +} + export function addCueToTrack(track: TextTrack, cue: VTTCue) { // Sometimes there are cue overlaps on segmented vtts so the same // cue can appear more than once in different vtt files. @@ -21,7 +40,8 @@ export function addCueToTrack(track: TextTrack, cue: VTTCue) { if (mode === 'disabled') { track.mode = 'hidden'; } - if (track.cues && !track.cues.getCueById(cue.id)) { + + if (track.cues && !containsCue(track, cue)) { try { track.addCue(cue); if (!track.cues.getCueById(cue.id)) { From 476c31a6847f7fe2d206432a4afe939731a86b90 Mon Sep 17 00:00:00 2001 From: grabofus Date: Fri, 21 Jun 2024 17:12:03 +0100 Subject: [PATCH 3/5] fix: Transition from Clear to DRM content (originally https://github.com/DiceTechnology/hls.js/commit/82f6aea7885ca6701418d6805adceae37629f7dd) --- src/controller/eme-controller.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controller/eme-controller.ts b/src/controller/eme-controller.ts index ae2c40f249e..0d8d97f4a49 100644 --- a/src/controller/eme-controller.ts +++ b/src/controller/eme-controller.ts @@ -291,6 +291,7 @@ class EMEController implements ComponentAPI { certificate, ); } + this.attemptSetMediaKeys(keySystem, mediaKeys); return mediaKeys; }); }); From a8a1885854f7c4c825ed2698de243e9d02dc2e94 Mon Sep 17 00:00:00 2001 From: yajin2021 Date: Wed, 3 Aug 2022 15:27:23 +0800 Subject: [PATCH 4/5] fix: whitelist codecs --- api-extractor/report/hls.js.api.md | 1 + src/config.ts | 2 ++ src/controller/level-controller.ts | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/api-extractor/report/hls.js.api.md b/api-extractor/report/hls.js.api.md index 4a1d1129b69..a6a7d4a6c2f 100644 --- a/api-extractor/report/hls.js.api.md +++ b/api-extractor/report/hls.js.api.md @@ -2149,6 +2149,7 @@ export interface LevelAttributes extends AttrList { // @public (undocumented) export type LevelControllerConfig = { startLevel?: number; + replaceCodecs: [string, string][]; }; // Warning: (ae-missing-release-tag) "LevelDetails" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) diff --git a/src/config.ts b/src/config.ts index 05b3e52938a..747c8a142de 100644 --- a/src/config.ts +++ b/src/config.ts @@ -146,6 +146,7 @@ export type FPSControllerConfig = { export type LevelControllerConfig = { startLevel?: number; + replaceCodecs: [string, string][]; }; export type MP4RemuxerConfig = { @@ -366,6 +367,7 @@ export const hlsDefaultConfig: HlsConfig = { workerPath: null, // used by transmuxer enableSoftwareAES: true, // used by decrypter startLevel: undefined, // used by level-controller + replaceCodecs: [], // used by level-controller startFragPrefetch: false, // used by stream-controller fpsDroppedMonitoringPeriod: 5000, // used by fps-controller fpsDroppedMonitoringThreshold: 0.2, // used by fps-controller diff --git a/src/controller/level-controller.ts b/src/controller/level-controller.ts index 972a85f11c8..4fe596cf6e0 100644 --- a/src/controller/level-controller.ts +++ b/src/controller/level-controller.ts @@ -120,6 +120,17 @@ export default class LevelController extends BasePlaylistController { data.levels.forEach((levelParsed: LevelParsed) => { const attributes = levelParsed.attrs; + // replace codecs with the ones defined as supported by this browser + const { replaceCodecs } = this.hls.config; + for (const [from, to] of replaceCodecs) { + if (levelParsed.videoCodec?.toLowerCase() === from.toLowerCase()) { + levelParsed.videoCodec = to; + } + if (levelParsed.audioCodec?.toLowerCase() === from.toLowerCase()) { + levelParsed.audioCodec = to; + } + } + // erase audio codec info if browser does not support mp4a.40.34. // demuxer will autodetect codec and fallback to mpeg/audio let { audioCodec, videoCodec } = levelParsed; From a612452f3939eeee04ba9d49c5cda423215773ec Mon Sep 17 00:00:00 2001 From: grabofus Date: Fri, 21 Jun 2024 17:20:55 +0100 Subject: [PATCH 5/5] set version in package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 7ee1fb58ec1..bbb05fa1097 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "hls.js", + "version": "1.5.12", "license": "Apache-2.0", "description": "JavaScript HLS client using MediaSourceExtension", "homepage": "https://github.com/video-dev/hls.js",