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

Use unique logger configurations across instances #6131

Merged
merged 1 commit into from
Jan 25, 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
64 changes: 44 additions & 20 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface AbrComponentAPI extends ComponentAPI {
// Warning: (ae-missing-release-tag) "AbrController" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export class AbrController implements AbrComponentAPI {
export class AbrController extends Logger implements AbrComponentAPI {
constructor(hls: Hls);
// (undocumented)
bwEstimator: EwmaBandWidthEstimator;
Expand Down Expand Up @@ -162,6 +162,8 @@ export class AudioStreamController extends BaseStreamController implements Netwo
// (undocumented)
onBufferReset(): void;
// (undocumented)
protected onError(event: Events.ERROR, data: ErrorData): void;
// (undocumented)
onFragBuffered(event: Events.FRAG_BUFFERED, data: FragBufferedData): void;
// (undocumented)
protected onHandlerDestroying(): void;
Expand All @@ -176,9 +178,13 @@ export class AudioStreamController extends BaseStreamController implements Netwo
// (undocumented)
protected onTickEnd(): void;
// (undocumented)
protected registerListeners(): void;
// (undocumented)
protected resetLoadingState(): void;
// (undocumented)
startLoad(startPosition: number): void;
// (undocumented)
protected unregisterListeners(): void;
}

// Warning: (ae-missing-release-tag) "AudioTrackController" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down Expand Up @@ -250,7 +256,7 @@ export interface BackBufferData {
// Warning: (ae-missing-release-tag) "BasePlaylistController" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export class BasePlaylistController implements NetworkComponentAPI {
export class BasePlaylistController extends Logger implements NetworkComponentAPI {
constructor(hls: Hls, logPrefix: string);
// (undocumented)
protected canLoad: boolean;
Expand All @@ -265,8 +271,6 @@ export class BasePlaylistController implements NetworkComponentAPI {
// (undocumented)
protected loadPlaylist(hlsUrlParameters?: HlsUrlParameters): void;
// (undocumented)
protected log: (msg: any) => void;
// (undocumented)
protected playlistLoaded(index: number, data: LevelLoadedData | AudioTrackLoadedData | TrackLoadedData, previousDetails?: LevelDetails): void;
// (undocumented)
protected requestScheduled: number;
Expand All @@ -282,8 +286,6 @@ export class BasePlaylistController implements NetworkComponentAPI {
protected switchParams(playlistUri: string, previous: LevelDetails | undefined): HlsUrlParameters | undefined;
// (undocumented)
protected timer: number;
// (undocumented)
protected warn: (msg: any) => void;
}

// Warning: (ae-missing-release-tag) "BaseSegment" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down Expand Up @@ -419,8 +421,6 @@ export class BaseStreamController extends TaskLoop implements NetworkComponentAP
// (undocumented)
protected _loadInitSegment(frag: Fragment, level: Level): void;
// (undocumented)
protected log: (msg: any) => void;
// (undocumented)
mapToInitFragWhenRequired(frag: Fragment | null): typeof frag;
// (undocumented)
protected media: HTMLMediaElement | null;
Expand All @@ -431,6 +431,8 @@ export class BaseStreamController extends TaskLoop implements NetworkComponentAP
// (undocumented)
protected nextLoadPosition: number;
// (undocumented)
protected onError(event: Events.ERROR, data: ErrorData): void;
// (undocumented)
protected onFragmentOrKeyLoadError(filterType: PlaylistLevelType, data: ErrorData): void;
// (undocumented)
protected onHandlerDestroyed(): void;
Expand All @@ -439,6 +441,8 @@ export class BaseStreamController extends TaskLoop implements NetworkComponentAP
// (undocumented)
protected onManifestLoaded(event: Events.MANIFEST_LOADED, data: ManifestLoadedData): void;
// (undocumented)
protected onManifestLoading(): void;
// (undocumented)
protected onMediaAttached(event: Events.MEDIA_ATTACHED, data: MediaAttachedData): void;
// (undocumented)
protected onMediaDetaching(): void;
Expand All @@ -457,6 +461,8 @@ export class BaseStreamController extends TaskLoop implements NetworkComponentAP
// (undocumented)
protected reduceMaxBufferLength(threshold: number): boolean;
// (undocumented)
protected registerListeners(): void;
// (undocumented)
protected removeUnbufferedFrags(start?: number): void;
// (undocumented)
protected resetFragmentErrors(filterType: PlaylistLevelType): void;
Expand Down Expand Up @@ -500,9 +506,9 @@ export class BaseStreamController extends TaskLoop implements NetworkComponentAP
// (undocumented)
protected transmuxer: TransmuxerInterface | null;
// (undocumented)
protected waitForCdnTuneIn(details: LevelDetails): boolean | 0;
protected unregisterListeners(): void;
// (undocumented)
protected warn: (msg: any) => void;
protected waitForCdnTuneIn(details: LevelDetails): boolean | 0;
}

// Warning: (ae-missing-release-tag) "BufferAppendedData" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down Expand Up @@ -554,7 +560,7 @@ export interface BufferCodecsData {
// Warning: (ae-missing-release-tag) "BufferController" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export class BufferController implements ComponentAPI {
export class BufferController extends Logger implements ComponentAPI {
constructor(hls: Hls);
// (undocumented)
protected appendChangeType(type: any, mimeType: any): void;
Expand All @@ -573,16 +579,12 @@ export class BufferController implements ComponentAPI {
// (undocumented)
destroy(): void;
// (undocumented)
protected error: (msg: any, obj?: any) => void;
// (undocumented)
flushBackBuffer(currentTime: number, targetDuration: number, targetBackBufferPosition: number): void;
// (undocumented)
flushFrontBuffer(currentTime: number, targetDuration: number, targetFrontBufferPosition: number): void;
// (undocumented)
hasSourceTypes(): boolean;
// (undocumented)
protected log: (msg: any) => void;
// (undocumented)
media: HTMLMediaElement | null;
// (undocumented)
mediaSource: MediaSource | null;
Expand Down Expand Up @@ -622,8 +624,6 @@ export class BufferController implements ComponentAPI {
protected unregisterListeners(): void;
// (undocumented)
updateSeekableRange(levelDetails: any): void;
// (undocumented)
protected warn: (msg: any, obj?: any) => void;
}

// Warning: (ae-missing-release-tag) "BufferControllerConfig" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down Expand Up @@ -795,7 +795,7 @@ export interface ComponentAPI {
// Warning: (ae-missing-release-tag) "ContentSteeringController" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export class ContentSteeringController implements NetworkComponentAPI {
export class ContentSteeringController extends Logger implements NetworkComponentAPI {
constructor(hls: Hls);
// (undocumented)
clearTimeout(): void;
Expand Down Expand Up @@ -922,7 +922,7 @@ export const enum ElementaryStreamTypes {
// Warning: (ae-missing-release-tag) "EMEController" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export class EMEController implements ComponentAPI {
export class EMEController extends Logger implements ComponentAPI {
constructor(hls: Hls);
// (undocumented)
static CDMCleanupPromise: Promise<void> | void;
Expand Down Expand Up @@ -964,7 +964,7 @@ export const enum ErrorActionFlags {
// Warning: (ae-missing-release-tag) "ErrorController" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export class ErrorController implements NetworkComponentAPI {
export class ErrorController extends Logger implements NetworkComponentAPI {
constructor(hls: Hls);
// (undocumented)
destroy(): void;
Expand Down Expand Up @@ -1604,6 +1604,7 @@ class Hls implements HlsEventEmitter {
// Warning: (ae-setter-with-docs) The doc comment for the property "loadLevel" must appear on the getter, not the setter.
set loadLevel(newLevel: number);
loadSource(url: string): void;
readonly logger: ILogger;
get lowLatencyMode(): boolean;
// Warning: (ae-setter-with-docs) The doc comment for the property "lowLatencyMode" must appear on the getter, not the setter.
set lowLatencyMode(mode: boolean);
Expand Down Expand Up @@ -2649,6 +2650,25 @@ export class LoadStats implements LoaderStats {
total: number;
}

// Warning: (ae-missing-release-tag) "Logger" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export class Logger implements ILogger {
constructor(label: string, logger: ILogger);
// (undocumented)
debug: ILogFunction;
// (undocumented)
error: ILogFunction;
// (undocumented)
info: ILogFunction;
// (undocumented)
log: ILogFunction;
// (undocumented)
trace: ILogFunction;
// (undocumented)
warn: ILogFunction;
}

// Warning: (ae-missing-release-tag) "MainPlaylistType" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down Expand Up @@ -3207,7 +3227,11 @@ export class SubtitleStreamController extends BaseStreamController implements Ne
// (undocumented)
onSubtitleTrackSwitch(event: Events.SUBTITLE_TRACK_SWITCH, data: TrackSwitchedData): void;
// (undocumented)
protected registerListeners(): void;
// (undocumented)
startLoad(startPosition: number): void;
// (undocumented)
protected unregisterListeners(): void;
}

// Warning: (ae-missing-release-tag) "SubtitleTrackController" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down
5 changes: 3 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import XhrLoader from './utils/xhr-loader';
import FetchLoader, { fetchSupported } from './utils/fetch-loader';
import Cues from './utils/cues';
import { requestMediaKeySystemAccess } from './utils/mediakeys-helper';
import { ILogger, logger } from './utils/logger';

import type Hls from './hls';
import type { CuesInterface } from './utils/cues';
import type { ILogger } from './utils/logger';
import type { MediaKeyFunc, KeySystems } from './utils/mediakeys-helper';
import type {
FragmentLoaderContext,
Expand Down Expand Up @@ -558,6 +558,7 @@ function timelineConfig(): TimelineControllerConfig {
export function mergeConfig(
defaultConfig: HlsConfig,
userConfig: Partial<HlsConfig>,
logger: ILogger,
): HlsConfig {
if (
(userConfig.liveSyncDurationCount ||
Expand Down Expand Up @@ -664,7 +665,7 @@ function deepCpy(obj: any): any {
/**
* @ignore
*/
export function enableStreamingMode(config) {
export function enableStreamingMode(config: HlsConfig, logger: ILogger) {
const currentLoader = config.loader;
if (currentLoader !== FetchLoader && currentLoader !== XhrLoader) {
// If a developer has configured their own loader, respect that choice
Expand Down
41 changes: 21 additions & 20 deletions src/controller/abr-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import EwmaBandWidthEstimator from '../utils/ewma-bandwidth-estimator';
import { Events } from '../events';
import { ErrorDetails } from '../errors';
import { PlaylistLevelType } from '../types/loader';
import { logger } from '../utils/logger';
import { Logger } from '../utils/logger';
import {
SUPPORTED_INFO_DEFAULT,
getMediaDecodingInfoPromise,
Expand Down Expand Up @@ -31,7 +31,7 @@ import type {
} from '../types/events';
import type { AbrComponentAPI } from '../types/component-api';

class AbrController implements AbrComponentAPI {
class AbrController extends Logger implements AbrComponentAPI {
protected hls: Hls;
private lastLevelLoadSec: number = 0;
private lastLoadedFragLevel: number = -1;
Expand All @@ -48,14 +48,15 @@ class AbrController implements AbrComponentAPI {
public bwEstimator: EwmaBandWidthEstimator;

constructor(hls: Hls) {
super('abr', hls.logger);
this.hls = hls;
this.bwEstimator = this.initEstimator();
this.registerListeners();
}

public resetEstimator(abrEwmaDefaultEstimate?: number) {
if (abrEwmaDefaultEstimate) {
logger.log(`setting initial bwe to ${abrEwmaDefaultEstimate}`);
this.log(`setting initial bwe to ${abrEwmaDefaultEstimate}`);
this.hls.config.abrEwmaDefaultEstimate = abrEwmaDefaultEstimate;
}
this.firstSelection = -1;
Expand Down Expand Up @@ -355,7 +356,7 @@ class AbrController implements AbrComponentAPI {
}

this.clearTimer();
logger.warn(`[abr] Fragment ${frag.sn}${
this.warn(`Fragment ${frag.sn}${
part ? ' part ' + part.index : ''
} of level ${frag.level} is loading too slowly;
Time to underbuffer: ${bufferStarvationDelay.toFixed(3)} s
Expand Down Expand Up @@ -479,8 +480,8 @@ class AbrController implements AbrComponentAPI {
}
const firstLevel = this.hls.firstLevel;
const clamped = Math.min(Math.max(firstLevel, minAutoLevel), maxAutoLevel);
logger.warn(
`[abr] Could not find best starting auto level. Defaulting to first in playlist ${firstLevel} clamped to ${clamped}`,
this.warn(
`Could not find best starting auto level. Defaulting to first in playlist ${firstLevel} clamped to ${clamped}`,
);
return clamped;
}
Expand Down Expand Up @@ -591,8 +592,8 @@ class AbrController implements AbrComponentAPI {
? Math.min(currentFragDuration, config.maxLoadingDelay)
: config.maxLoadingDelay;
maxStarvationDelay = maxLoadingDelay - bitrateTestDelay;
logger.info(
`[abr] bitrate test took ${Math.round(
this.info(
`bitrate test took ${Math.round(
1000 * bitrateTestDelay,
)}ms, set first fragment max fetchDuration to ${Math.round(
1000 * maxStarvationDelay,
Expand All @@ -611,8 +612,8 @@ class AbrController implements AbrComponentAPI {
bwFactor,
bwUpFactor,
);
logger.info(
`[abr] ${
this.info(
`${
bufferStarvationDelay ? 'rebuffering expected' : 'buffer is empty'
}, optimal quality level ${bestLevel}`,
);
Expand Down Expand Up @@ -691,7 +692,7 @@ class AbrController implements AbrComponentAPI {
: videoRanges[0];
currentFrameRate = minFramerate;
currentBw = Math.max(currentBw, minBitrate);
logger.log(`[abr] picked start tier ${JSON.stringify(startTier)}`);
this.log(`picked start tier ${JSON.stringify(startTier)}`);
} else {
currentCodecSet = level?.codecSet;
currentVideoRange = level?.videoRange;
Expand Down Expand Up @@ -741,19 +742,19 @@ class AbrController implements AbrComponentAPI {
const levels = this.hls.levels;
const index = levels.indexOf(levelInfo);
if (decodingInfo.error) {
logger.warn(
`[abr] MediaCapabilities decodingInfo error: "${
this.warn(
`MediaCapabilities decodingInfo error: "${
decodingInfo.error
}" for level ${index} ${JSON.stringify(decodingInfo)}`,
);
} else if (!decodingInfo.supported) {
logger.warn(
`[abr] Unsupported MediaCapabilities decodingInfo result for level ${index} ${JSON.stringify(
this.warn(
`Unsupported MediaCapabilities decodingInfo result for level ${index} ${JSON.stringify(
decodingInfo,
)}`,
);
if (index > -1 && levels.length > 1) {
logger.log(`[abr] Removing unsupported level ${index}`);
this.log(`Removing unsupported level ${index}`);
this.hls.removeLevel(index);
}
}
Expand Down Expand Up @@ -831,8 +832,8 @@ class AbrController implements AbrComponentAPI {
(forcedAutoLevel === -1 || forcedAutoLevel !== loadLevel)
) {
if (levelsSkipped.length) {
logger.trace(
`[abr] Skipped level(s) ${levelsSkipped.join(
this.trace(
`Skipped level(s) ${levelsSkipped.join(
',',
)} of ${maxAutoLevel} max with CODECS and VIDEO-RANGE:"${
levels[levelsSkipped[0]].codecs
Expand All @@ -841,8 +842,8 @@ class AbrController implements AbrComponentAPI {
}" ${currentVideoRange}`,
);
}
logger.info(
`[abr] switch candidate:${selectionBaseLevel}->${i} adjustedbw(${Math.round(
this.info(
`switch candidate:${selectionBaseLevel}->${i} adjustedbw(${Math.round(
adjustedbw,
)})-bitrate=${Math.round(
adjustedbw - bitrate,
Expand Down
Loading
Loading