Skip to content

Commit

Permalink
Performance micro-optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
robwalch committed Jul 22, 2023
1 parent 29c9579 commit e160a3c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 2 additions & 0 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,8 @@ export interface ComponentAPI {
export class ContentSteeringController implements NetworkComponentAPI {
constructor(hls: Hls);
// (undocumented)
clearTimeout(): void;
// (undocumented)
destroy(): void;
// (undocumented)
filterParsedLevels(levels: Level[]): Level[];
Expand Down
17 changes: 12 additions & 5 deletions src/controller/content-steering-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ export default class ContentSteeringController implements NetworkComponentAPI {
hls.off(Events.ERROR, this.onError, this);
}

startLoad(): void {
startLoad() {
this.started = true;
self.clearTimeout(this.reloadTimer);
this.clearTimeout();
if (this.enabled && this.uri) {
if (this.updated) {
const ttl = Math.max(
Expand All @@ -104,13 +104,20 @@ export default class ContentSteeringController implements NetworkComponentAPI {
}
}

stopLoad(): void {
stopLoad() {
this.started = false;
if (this.loader) {
this.loader.destroy();
this.loader = null;
}
self.clearTimeout(this.reloadTimer);
this.clearTimeout();
}

clearTimeout() {
if (this.reloadTimer !== -1) {
self.clearTimeout(this.reloadTimer);
this.reloadTimer = -1;
}
}

destroy() {
Expand Down Expand Up @@ -455,7 +462,7 @@ export default class ContentSteeringController implements NetworkComponentAPI {
}

private scheduleRefresh(uri: string, ttlMs: number = this.timeToLoad * 1000) {
self.clearTimeout(this.reloadTimer);
this.clearTimeout();
this.reloadTimer = self.setTimeout(() => {
this.loadSteeringManifest(uri);
}, ttlMs);
Expand Down
12 changes: 4 additions & 8 deletions src/controller/timeline-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,10 @@ export class TimelineController implements ComponentAPI {
track: MediaPlaylist
): TextTrackKind {
if (track.attrs.CHARACTERISTICS) {
const transcribesSpokenDialog = /transcribes-spoken-dialog/gi.test(
track.attrs.CHARACTERISTICS
);
const describesMusicAndSound = /describes-music-and-sound/gi.test(
track.attrs.CHARACTERISTICS
);

if (transcribesSpokenDialog && describesMusicAndSound) {
if (
/transcribes-spoken-dialog/gi.test(track.attrs.CHARACTERISTICS) &&
/describes-music-and-sound/gi.test(track.attrs.CHARACTERISTICS)
) {
return 'captions';
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/utils/cea-608-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1022,18 +1022,16 @@ type CmdHistory = {
class Cea608Parser {
channels: Array<Cea608Channel | null>;
currentChannel: Channels = 0;
cmdHistory: CmdHistory;
cmdHistory: CmdHistory = createCmdHistory();
logger: CaptionsLogger;

constructor(field: SupportedField, out1: OutputFilter, out2: OutputFilter) {
const logger = new CaptionsLogger();
const logger = (this.logger = new CaptionsLogger());
this.channels = [
null,
new Cea608Channel(field, out1, logger),
new Cea608Channel(field + 1, out2, logger),
];
this.cmdHistory = createCmdHistory();
this.logger = logger;
}

getHandler(channel: number) {
Expand Down

0 comments on commit e160a3c

Please sign in to comment.