Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master doris with patches #92

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading