Skip to content

Commit

Permalink
Merge pull request #92 from DiceTechnology/master-doris-with-patches
Browse files Browse the repository at this point in the history
Master doris with patches
  • Loading branch information
grabofus authored Jun 24, 2024
2 parents 9255170 + a612452 commit f92c68e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export type FPSControllerConfig = {

export type LevelControllerConfig = {
startLevel?: number;
replaceCodecs: [string, string][];
};

export type MP4RemuxerConfig = {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/controller/eme-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class EMEController implements ComponentAPI {
certificate,
);
}
this.attemptSetMediaKeys(keySystem, mediaKeys);
return mediaKeys;
});
});
Expand Down
11 changes: 11 additions & 0 deletions src/controller/level-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/remux/mp4-remuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default class MP4Remuxer implements Remuxer {
height?: number;
pixelRatio?: [number, number];
};
private isDiscontinuity: boolean = false;

constructor(
observer: HlsEventEmitter,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -182,14 +184,21 @@ 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(
`[mp4-remuxer]: Dropped ${firstKeyFrameIndex} out of ${length} video samples due to a missing keyframe`,
);
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) /
Expand Down
22 changes: 21 additions & 1 deletion src/utils/texttrack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)) {
Expand Down

0 comments on commit f92c68e

Please sign in to comment.