Skip to content

Commit

Permalink
Use configured logger in remuxer and demuxer instances and static cal…
Browse files Browse the repository at this point in the history
…ls to probe

Related to #2461
  • Loading branch information
robwalch committed Jul 12, 2024
1 parent fee5b29 commit db2fbcf
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 68 deletions.
6 changes: 3 additions & 3 deletions src/demux/audio/aacdemuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import BaseAudioDemuxer from './base-audio-demuxer';
import * as ADTS from './adts';
import * as MpegAudio from './mpegaudio';
import { logger } from '../../utils/logger';
import { getId3Data } from '@svta/common-media-library/id3/getId3Data';
import type { HlsEventEmitter } from '../../events';
import type { HlsConfig } from '../../config';
import type { ILogger } from '../../utils/logger';

class AACDemuxer extends BaseAudioDemuxer {
private readonly observer: HlsEventEmitter;
private readonly config: HlsConfig;

constructor(observer, config) {
constructor(observer: HlsEventEmitter, config) {
super();
this.observer = observer;
this.config = config;
Expand Down Expand Up @@ -42,7 +42,7 @@ class AACDemuxer extends BaseAudioDemuxer {
}

// Source for probe info - https://wiki.multimedia.cx/index.php?title=ADTS
static probe(data: Uint8Array | undefined): boolean {
static probe(data: Uint8Array | undefined, logger: ILogger): boolean {
if (!data) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/demux/audio/ac3-demuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { AudioFrame, DemuxedAudioTrack } from '../../types/demuxer';
export class AC3Demuxer extends BaseAudioDemuxer {
private readonly observer: HlsEventEmitter;

constructor(observer) {
constructor(observer: HlsEventEmitter) {
super();
this.observer = observer;
}
Expand Down
2 changes: 2 additions & 0 deletions src/demux/transmuxer-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export default class TransmuxerInterface {
config,
'',
id,
hls.logger,
);
}
return;
Expand All @@ -123,6 +124,7 @@ export default class TransmuxerInterface {
config,
'',
id,
hls.logger,
);
}

Expand Down
1 change: 1 addition & 0 deletions src/demux/transmuxer-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function startWorker() {
config,
'',
data.id,
logger,
);
forwardMessage('init', null, instanceNo);
return;
Expand Down
22 changes: 12 additions & 10 deletions src/demux/transmuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import MP3Demuxer from './audio/mp3demuxer';
import { AC3Demuxer } from './audio/ac3-demuxer';
import MP4Remuxer from '../remux/mp4-remuxer';
import PassThroughRemuxer from '../remux/passthrough-remuxer';
import { logger } from '../utils/logger';
import { PlaylistLevelType } from '../types/loader';
import {
isFullSegmentEncryption,
getAesModeFromFullSegmentMethod,
Expand All @@ -19,16 +19,15 @@ import type { Remuxer } from '../types/remuxer';
import type { TransmuxerResult, ChunkMetadata } from '../types/transmuxer';
import type { HlsConfig } from '../config';
import type { DecryptData } from '../loader/level-key';
import type { PlaylistLevelType } from '../types/loader';
import type { TypeSupported } from '../utils/codecs';
import type { ILogger } from '../utils/logger';
import type { RationalTimestamp } from '../utils/timescale-conversion';

let now: () => number;
// performance.now() not available on WebWorker, at least on Safari Desktop
try {
now = self.performance.now.bind(self.performance);
} catch (err) {
logger.debug('Unable to use Performance API on this environment');
now = Date.now;
}

Expand All @@ -52,6 +51,7 @@ if (__USE_M2TS_ADVANCED_CODECS__) {

export default class Transmuxer {
private asyncResult: boolean = false;
private logger: ILogger;
private observer: HlsEventEmitter;
private typeSupported: TypeSupported;
private config: HlsConfig;
Expand All @@ -71,12 +71,14 @@ export default class Transmuxer {
config: HlsConfig,
vendor: string,
id: PlaylistLevelType,
logger: ILogger,
) {
this.observer = observer;
this.typeSupported = typeSupported;
this.config = config;
this.vendor = vendor;
this.id = id;
this.logger = logger;
}

configure(transmuxConfig: TransmuxConfig) {
Expand Down Expand Up @@ -170,7 +172,7 @@ export default class Transmuxer {
if (resetMuxers) {
const error = this.configureTransmuxer(uintData);
if (error) {
logger.warn(`[transmuxer] ${error.message}`);
this.logger.warn(`[transmuxer] ${error.message}`);
this.observer.emit(Events.ERROR, Events.ERROR, {
type: ErrorTypes.MEDIA_ERROR,
details: ErrorDetails.FRAG_PARSING_ERROR,
Expand Down Expand Up @@ -288,10 +290,10 @@ export default class Transmuxer {
) {
const { audioTrack, videoTrack, id3Track, textTrack } = demuxResult;
const { accurateTimeOffset, timeOffset } = this.currentTransmuxState;
logger.log(
`[transmuxer.ts]: Flushed fragment ${chunkMeta.sn}${
this.logger.log(
`[transmuxer.ts]: Flushed ${this.id} sn: ${chunkMeta.sn}${
chunkMeta.part > -1 ? ' p: ' + chunkMeta.part : ''
} of level ${chunkMeta.level}`,
} of ${this.id === PlaylistLevelType.MAIN ? 'level' : 'track'} ${chunkMeta.level}`,
);
const remuxResult = this.remuxer!.remux(
audioTrack,
Expand Down Expand Up @@ -449,7 +451,7 @@ export default class Transmuxer {
// probe for content type
let mux;
for (let i = 0, len = muxConfig.length; i < len; i++) {
if (muxConfig[i].demux?.probe(data)) {
if (muxConfig[i].demux?.probe(data, this.logger)) {
mux = muxConfig[i];
break;
}
Expand All @@ -463,10 +465,10 @@ export default class Transmuxer {
const Remuxer: MuxConfig['remux'] = mux.remux;
const Demuxer: MuxConfig['demux'] = mux.demux;
if (!remuxer || !(remuxer instanceof Remuxer)) {
this.remuxer = new Remuxer(observer, config, typeSupported, vendor);
this.remuxer = new Remuxer(observer, config, typeSupported, this.logger);
}
if (!demuxer || !(demuxer instanceof Demuxer)) {
this.demuxer = new Demuxer(observer, config, typeSupported);
this.demuxer = new Demuxer(observer, config, typeSupported, this.logger);
this.probe = Demuxer.probe;
}
}
Expand Down
Loading

0 comments on commit db2fbcf

Please sign in to comment.