hls.js 1.5.10-0.canary.10328 → 1.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +3 -4
  2. package/dist/hls-demo.js +38 -41
  3. package/dist/hls-demo.js.map +1 -1
  4. package/dist/hls.js +2194 -3476
  5. package/dist/hls.js.d.ts +85 -108
  6. package/dist/hls.js.map +1 -1
  7. package/dist/hls.light.js +3137 -3784
  8. package/dist/hls.light.js.map +1 -1
  9. package/dist/hls.light.min.js +1 -1
  10. package/dist/hls.light.min.js.map +1 -1
  11. package/dist/hls.light.mjs +1256 -1928
  12. package/dist/hls.light.mjs.map +1 -1
  13. package/dist/hls.min.js +1 -1
  14. package/dist/hls.min.js.map +1 -1
  15. package/dist/hls.mjs +4182 -5487
  16. package/dist/hls.mjs.map +1 -1
  17. package/dist/hls.worker.js +1 -1
  18. package/dist/hls.worker.js.map +1 -1
  19. package/package.json +36 -36
  20. package/src/config.ts +2 -3
  21. package/src/controller/abr-controller.ts +20 -24
  22. package/src/controller/audio-stream-controller.ts +74 -68
  23. package/src/controller/audio-track-controller.ts +1 -1
  24. package/src/controller/base-playlist-controller.ts +10 -27
  25. package/src/controller/base-stream-controller.ts +38 -160
  26. package/src/controller/buffer-controller.ts +92 -230
  27. package/src/controller/buffer-operation-queue.ts +19 -16
  28. package/src/controller/cap-level-controller.ts +2 -3
  29. package/src/controller/cmcd-controller.ts +14 -51
  30. package/src/controller/content-steering-controller.ts +15 -29
  31. package/src/controller/eme-controller.ts +23 -10
  32. package/src/controller/error-controller.ts +8 -6
  33. package/src/controller/fps-controller.ts +3 -8
  34. package/src/controller/fragment-tracker.ts +11 -15
  35. package/src/controller/gap-controller.ts +16 -43
  36. package/src/controller/id3-track-controller.ts +7 -7
  37. package/src/controller/latency-controller.ts +11 -9
  38. package/src/controller/level-controller.ts +19 -37
  39. package/src/controller/stream-controller.ts +32 -37
  40. package/src/controller/subtitle-stream-controller.ts +40 -28
  41. package/src/controller/subtitle-track-controller.ts +3 -5
  42. package/src/controller/timeline-controller.ts +21 -19
  43. package/src/crypt/aes-crypto.ts +2 -21
  44. package/src/crypt/decrypter.ts +16 -32
  45. package/src/crypt/fast-aes-key.ts +5 -28
  46. package/src/demux/audio/aacdemuxer.ts +2 -2
  47. package/src/demux/audio/ac3-demuxer.ts +3 -4
  48. package/src/demux/audio/adts.ts +4 -9
  49. package/src/demux/audio/base-audio-demuxer.ts +14 -16
  50. package/src/demux/audio/mp3demuxer.ts +3 -4
  51. package/src/demux/audio/mpegaudio.ts +1 -1
  52. package/src/demux/id3.ts +411 -0
  53. package/src/demux/mp4demuxer.ts +7 -7
  54. package/src/demux/sample-aes.ts +0 -2
  55. package/src/demux/transmuxer-interface.ts +12 -4
  56. package/src/demux/transmuxer-worker.ts +4 -4
  57. package/src/demux/transmuxer.ts +3 -16
  58. package/src/demux/tsdemuxer.ts +38 -75
  59. package/src/demux/video/avc-video-parser.ts +119 -208
  60. package/src/demux/video/base-video-parser.ts +18 -147
  61. package/src/demux/video/exp-golomb.ts +208 -0
  62. package/src/events.ts +1 -8
  63. package/src/exports-named.ts +1 -1
  64. package/src/hls.ts +38 -61
  65. package/src/loader/fragment-loader.ts +3 -10
  66. package/src/loader/key-loader.ts +1 -3
  67. package/src/loader/level-key.ts +9 -10
  68. package/src/loader/playlist-loader.ts +5 -4
  69. package/src/remux/mp4-generator.ts +1 -196
  70. package/src/remux/mp4-remuxer.ts +8 -24
  71. package/src/task-loop.ts +2 -5
  72. package/src/types/component-api.ts +1 -3
  73. package/src/types/demuxer.ts +0 -4
  74. package/src/types/events.ts +0 -4
  75. package/src/types/remuxer.ts +1 -1
  76. package/src/utils/buffer-helper.ts +31 -12
  77. package/src/utils/cea-608-parser.ts +3 -1
  78. package/src/utils/codecs.ts +5 -34
  79. package/src/utils/fetch-loader.ts +1 -1
  80. package/src/utils/imsc1-ttml-parser.ts +1 -1
  81. package/src/utils/keysystem-util.ts +6 -1
  82. package/src/utils/logger.ts +23 -58
  83. package/src/utils/mp4-tools.ts +3 -5
  84. package/src/utils/webvtt-parser.ts +1 -1
  85. package/src/crypt/decrypter-aes-mode.ts +0 -4
  86. package/src/demux/video/hevc-video-parser.ts +0 -749
  87. package/src/utils/encryption-methods-util.ts +0 -21
  88. package/src/utils/utf8-utils.ts +0 -18
@@ -4,7 +4,7 @@ import type { HlsEventEmitter } from '../events';
4
4
  import { Events } from '../events';
5
5
  import { ErrorTypes, ErrorDetails } from '../errors';
6
6
  import { logger } from '../utils/logger';
7
- import type {
7
+ import {
8
8
  InitSegmentData,
9
9
  Remuxer,
10
10
  RemuxerResult,
@@ -29,7 +29,6 @@ import type { TrackSet } from '../types/track';
29
29
  import type { SourceBufferName } from '../types/buffer';
30
30
  import type { Fragment } from '../loader/fragment';
31
31
  import type { HlsConfig } from '../config';
32
- import type { TypeSupported } from '../utils/codecs';
33
32
 
34
33
  const MAX_SILENT_FRAME_DURATION = 10 * 1000; // 10 seconds
35
34
  const AAC_SAMPLES_PER_FRAME = 1024;
@@ -42,7 +41,7 @@ let safariWebkitVersion: number | null = null;
42
41
  export default class MP4Remuxer implements Remuxer {
43
42
  private observer: HlsEventEmitter;
44
43
  private config: HlsConfig;
45
- private typeSupported: TypeSupported;
44
+ private typeSupported: any;
46
45
  private ISGenerated: boolean = false;
47
46
  private _initPTS: RationalTimestamp | null = null;
48
47
  private _initDTS: RationalTimestamp | null = null;
@@ -516,7 +515,7 @@ export default class MP4Remuxer implements Remuxer {
516
515
  if (foundHole || foundOverlap) {
517
516
  if (foundHole) {
518
517
  logger.warn(
519
- `${(track.segmentCodec || '').toUpperCase()}: ${toMsFromMpegTsClock(
518
+ `AVC: ${toMsFromMpegTsClock(
520
519
  delta,
521
520
  true,
522
521
  )} ms (${delta}dts) hole between fragments detected at ${timeOffset.toFixed(
@@ -525,7 +524,7 @@ export default class MP4Remuxer implements Remuxer {
525
524
  );
526
525
  } else {
527
526
  logger.warn(
528
- `${(track.segmentCodec || '').toUpperCase()}: ${toMsFromMpegTsClock(
527
+ `AVC: ${toMsFromMpegTsClock(
529
528
  -delta,
530
529
  true,
531
530
  )} ms (${delta}dts) overlapping between fragments detected at ${timeOffset.toFixed(
@@ -544,27 +543,12 @@ export default class MP4Remuxer implements Remuxer {
544
543
  inputSamples[0].dts = firstDTS;
545
544
  inputSamples[0].pts = firstPTS;
546
545
  } else {
547
- let isPTSOrderRetained = true;
548
546
  for (let i = 0; i < inputSamples.length; i++) {
549
- if (inputSamples[i].dts > firstPTS && isPTSOrderRetained) {
547
+ if (inputSamples[i].dts > firstPTS) {
550
548
  break;
551
549
  }
552
-
553
- const prevPTS = inputSamples[i].pts;
554
550
  inputSamples[i].dts -= delta;
555
551
  inputSamples[i].pts -= delta;
556
-
557
- // check to see if this sample's PTS order has changed
558
- // relative to the next one
559
- if (i < inputSamples.length - 1) {
560
- const nextSamplePTS = inputSamples[i + 1].pts;
561
- const currentSamplePTS = inputSamples[i].pts;
562
-
563
- const currentOrder = nextSamplePTS <= currentSamplePTS;
564
- const prevOrder = nextSamplePTS <= prevPTS;
565
-
566
- isPTSOrderRetained = currentOrder == prevOrder;
567
- }
568
552
  }
569
553
  }
570
554
  logger.log(
@@ -759,7 +743,7 @@ export default class MP4Remuxer implements Remuxer {
759
743
  }
760
744
  }
761
745
  }
762
- // next AVC/HEVC sample DTS should be equal to last sample DTS + last sample duration (in PES timescale)
746
+ // next AVC sample DTS should be equal to last sample DTS + last sample duration (in PES timescale)
763
747
  mp4SampleDuration =
764
748
  stretchedLastFrame || !mp4SampleDuration
765
749
  ? averageSampleDuration
@@ -943,7 +927,7 @@ export default class MP4Remuxer implements Remuxer {
943
927
  for (let j = 0; j < missing; j++) {
944
928
  const newStamp = Math.max(nextPts as number, 0);
945
929
  let fillFrame = AAC.getSilentFrame(
946
- track.parsedCodec || track.manifestCodec || track.codec,
930
+ track.manifestCodec || track.codec,
947
931
  track.channelCount,
948
932
  );
949
933
  if (!fillFrame) {
@@ -1093,7 +1077,7 @@ export default class MP4Remuxer implements Remuxer {
1093
1077
  const nbSamples: number = Math.ceil((endDTS - startDTS) / frameDuration);
1094
1078
  // silent frame
1095
1079
  const silentFrame: Uint8Array | undefined = AAC.getSilentFrame(
1096
- track.parsedCodec || track.manifestCodec || track.codec,
1080
+ track.manifestCodec || track.codec,
1097
1081
  track.channelCount,
1098
1082
  );
1099
1083
 
package/src/task-loop.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { type ILogger, Logger } from './utils/logger';
2
-
3
1
  /**
4
2
  * @ignore
5
3
  * Sub-class specialization of EventHandler base class.
@@ -29,14 +27,13 @@ import { type ILogger, Logger } from './utils/logger';
29
27
  * we are limiting the task execution per call stack to exactly one, but scheduling/post-poning further
30
28
  * task processing on the next main loop iteration (also known as "next tick" in the Node/JS runtime lingo).
31
29
  */
32
- export default class TaskLoop extends Logger {
30
+ export default class TaskLoop {
33
31
  private readonly _boundTick: () => void;
34
32
  private _tickTimer: number | null = null;
35
33
  private _tickInterval: number | null = null;
36
34
  private _tickCallCount = 0;
37
35
 
38
- constructor(label: string, logger: ILogger) {
39
- super(label, logger);
36
+ constructor() {
40
37
  this._boundTick = this.tick.bind(this);
41
38
  }
42
39
 
@@ -1,4 +1,4 @@
1
- import type EwmaBandWidthEstimator from '../utils/ewma-bandwidth-estimator';
1
+ import EwmaBandWidthEstimator from '../utils/ewma-bandwidth-estimator';
2
2
 
3
3
  export interface ComponentAPI {
4
4
  destroy(): void;
@@ -15,6 +15,4 @@ export interface AbrComponentAPI extends ComponentAPI {
15
15
  export interface NetworkComponentAPI extends ComponentAPI {
16
16
  startLoad(startPosition: number): void;
17
17
  stopLoad(): void;
18
- pauseBuffering?(): void;
19
- resumeBuffering?(): void;
20
18
  }
@@ -64,7 +64,6 @@ export interface DemuxedAudioTrack extends DemuxedTrack {
64
64
  segmentCodec?: string;
65
65
  channelCount?: number;
66
66
  manifestCodec?: string;
67
- parsedCodec?: string;
68
67
  samples: AudioSample[];
69
68
  }
70
69
 
@@ -73,15 +72,12 @@ export interface DemuxedVideoTrackBase extends DemuxedTrack {
73
72
  height?: number;
74
73
  pixelRatio?: [number, number];
75
74
  audFound?: boolean;
76
- vps?: Uint8Array[];
77
75
  pps?: Uint8Array[];
78
76
  sps?: Uint8Array[];
79
77
  naluState?: number;
80
- lastNalu?: VideoSampleUnit | null;
81
78
  segmentCodec?: string;
82
79
  manifestCodec?: string;
83
80
  samples: VideoSample[] | Uint8Array;
84
- params?: object;
85
81
  }
86
82
 
87
83
  export interface DemuxedVideoTrack extends DemuxedVideoTrackBase {
@@ -42,10 +42,6 @@ export interface MediaAttachedData {
42
42
  mediaSource?: MediaSource;
43
43
  }
44
44
 
45
- export interface MediaEndedData {
46
- stalled: boolean;
47
- }
48
-
49
45
  export interface BufferCodecsData {
50
46
  video?: Track;
51
47
  audio?: Track;
@@ -1,5 +1,5 @@
1
1
  import type { TrackSet } from './track';
2
- import type {
2
+ import {
3
3
  DemuxedAudioTrack,
4
4
  DemuxedMetadataTrack,
5
5
  DemuxedUserdataTrack,
@@ -35,13 +35,19 @@ export class BufferHelper {
35
35
  * Return true if `media`'s buffered include `position`
36
36
  */
37
37
  static isBuffered(media: Bufferable, position: number): boolean {
38
- if (media) {
39
- const buffered = BufferHelper.getBuffered(media);
40
- for (let i = buffered.length; i--; ) {
41
- if (position >= buffered.start(i) && position <= buffered.end(i)) {
42
- return true;
38
+ try {
39
+ if (media) {
40
+ const buffered = BufferHelper.getBuffered(media);
41
+ for (let i = 0; i < buffered.length; i++) {
42
+ if (position >= buffered.start(i) && position <= buffered.end(i)) {
43
+ return true;
44
+ }
43
45
  }
44
46
  }
47
+ } catch (error) {
48
+ // this is to catch
49
+ // InvalidStateError: Failed to read the 'buffered' property from 'SourceBuffer':
50
+ // This SourceBuffer has been removed from the parent media source
45
51
  }
46
52
  return false;
47
53
  }
@@ -51,15 +57,21 @@ export class BufferHelper {
51
57
  pos: number,
52
58
  maxHoleDuration: number,
53
59
  ): BufferInfo {
54
- if (media) {
55
- const vbuffered = BufferHelper.getBuffered(media);
56
- if (vbuffered.length) {
60
+ try {
61
+ if (media) {
62
+ const vbuffered = BufferHelper.getBuffered(media);
57
63
  const buffered: BufferTimeRange[] = [];
58
- for (let i = 0; i < vbuffered.length; i++) {
64
+ let i: number;
65
+ for (i = 0; i < vbuffered.length; i++) {
59
66
  buffered.push({ start: vbuffered.start(i), end: vbuffered.end(i) });
60
67
  }
61
- return BufferHelper.bufferedInfo(buffered, pos, maxHoleDuration);
68
+
69
+ return this.bufferedInfo(buffered, pos, maxHoleDuration);
62
70
  }
71
+ } catch (error) {
72
+ // this is to catch
73
+ // InvalidStateError: Failed to read the 'buffered' property from 'SourceBuffer':
74
+ // This SourceBuffer has been removed from the parent media source
63
75
  }
64
76
  return { len: 0, start: pos, end: pos, nextStart: undefined };
65
77
  }
@@ -76,7 +88,14 @@ export class BufferHelper {
76
88
  } {
77
89
  pos = Math.max(0, pos);
78
90
  // sort on buffer.start/smaller end (IE does not always return sorted buffered range)
79
- buffered.sort((a, b) => a.start - b.start || b.end - a.end);
91
+ buffered.sort(function (a, b) {
92
+ const diff = a.start - b.start;
93
+ if (diff) {
94
+ return diff;
95
+ } else {
96
+ return b.end - a.end;
97
+ }
98
+ });
80
99
 
81
100
  let buffered2: BufferTimeRange[] = [];
82
101
  if (maxHoleDuration) {
@@ -145,7 +164,7 @@ export class BufferHelper {
145
164
  */
146
165
  static getBuffered(media: Bufferable): TimeRanges {
147
166
  try {
148
- return media.buffered || noopBuffered;
167
+ return media.buffered;
149
168
  } catch (e) {
150
169
  logger.log('failed to get media.buffered', e);
151
170
  return noopBuffered;
@@ -1331,7 +1331,9 @@ class Cea608Parser {
1331
1331
  if (charCodes) {
1332
1332
  this.logger.log(
1333
1333
  VerboseLevel.DEBUG,
1334
- () => 'Char codes = ' + numArrayToHexArray(charCodes).join(','),
1334
+ () =>
1335
+ 'Char codes = ' +
1336
+ numArrayToHexArray(charCodes as number[]).join(','),
1335
1337
  );
1336
1338
  }
1337
1339
  return charCodes;
@@ -147,15 +147,12 @@ function getCodecCompatibleNameLower(
147
147
  return CODEC_COMPATIBLE_NAMES[lowerCaseCodec]!;
148
148
  }
149
149
 
150
+ // Idealy fLaC and Opus would be first (spec-compliant) but
151
+ // some browsers will report that fLaC is supported then fail.
152
+ // see: https://bugs.chromium.org/p/chromium/issues/detail?id=1422728
150
153
  const codecsToCheck = {
151
- // Idealy fLaC and Opus would be first (spec-compliant) but
152
- // some browsers will report that fLaC is supported then fail.
153
- // see: https://bugs.chromium.org/p/chromium/issues/detail?id=1422728
154
154
  flac: ['flac', 'fLaC', 'FLAC'],
155
155
  opus: ['opus', 'Opus'],
156
- // Replace audio codec info if browser does not support mp4a.40.34,
157
- // and demuxer can fallback to 'audio/mpeg' or 'audio/mp4;codecs="mp3"'
158
- 'mp4a.40.34': ['mp3'],
159
156
  }[lowerCaseCodec];
160
157
 
161
158
  for (let i = 0; i < codecsToCheck.length; i++) {
@@ -168,18 +165,13 @@ function getCodecCompatibleNameLower(
168
165
  ) {
169
166
  CODEC_COMPATIBLE_NAMES[lowerCaseCodec] = codecsToCheck[i];
170
167
  return codecsToCheck[i];
171
- } else if (
172
- codecsToCheck[i] === 'mp3' &&
173
- getMediaSource(preferManagedMediaSource)?.isTypeSupported('audio/mpeg')
174
- ) {
175
- return '';
176
168
  }
177
169
  }
178
170
 
179
171
  return lowerCaseCodec;
180
172
  }
181
173
 
182
- const AUDIO_CODEC_REGEXP = /flac|opus|mp4a\.40\.34/i;
174
+ const AUDIO_CODEC_REGEXP = /flac|opus/i;
183
175
  export function getCodecCompatibleName(
184
176
  codec: string,
185
177
  preferManagedMediaSource = true,
@@ -193,7 +185,7 @@ export function getCodecCompatibleName(
193
185
  }
194
186
 
195
187
  export function pickMostCompleteCodecName(
196
- parsedCodec: string | undefined,
188
+ parsedCodec: string,
197
189
  levelCodec: string | undefined,
198
190
  ): string | undefined {
199
191
  // Parsing of mp4a codecs strings in mp4-tools from media is incomplete as of d8c6c7a
@@ -217,24 +209,3 @@ export function convertAVC1ToAVCOTI(codec: string) {
217
209
  }
218
210
  return codec;
219
211
  }
220
-
221
- export interface TypeSupported {
222
- mpeg: boolean;
223
- mp3: boolean;
224
- ac3: boolean;
225
- }
226
-
227
- export function getM2TSSupportedAudioTypes(
228
- preferManagedMediaSource: boolean,
229
- ): TypeSupported {
230
- const MediaSource = getMediaSource(preferManagedMediaSource) || {
231
- isTypeSupported: () => false,
232
- };
233
- return {
234
- mpeg: MediaSource.isTypeSupported('audio/mpeg'),
235
- mp3: MediaSource.isTypeSupported('audio/mp4; codecs="mp3"'),
236
- ac3: __USE_M2TS_ADVANCED_CODECS__
237
- ? MediaSource.isTypeSupported('audio/mp4; codecs="ac-3"')
238
- : false,
239
- };
240
- }
@@ -1,4 +1,4 @@
1
- import type {
1
+ import {
2
2
  LoaderCallbacks,
3
3
  LoaderContext,
4
4
  Loader,
@@ -1,7 +1,7 @@
1
1
  import { findBox } from './mp4-tools';
2
2
  import { parseTimeStamp } from './vttparser';
3
3
  import VTTCue from './vttcue';
4
- import { utf8ArrayToStr } from '@svta/common-media-library/utils/utf8ArrayToStr';
4
+ import { utf8ArrayToStr } from '../demux/id3';
5
5
  import {
6
6
  RationalTimestamp,
7
7
  toTimescaleFromScale,
@@ -1,5 +1,4 @@
1
1
  import { base64Decode } from './numeric-encoding-utils';
2
- import { strToUtf8array } from './utf8-utils';
3
2
 
4
3
  function getKeyIdBytes(str: string): Uint8Array {
5
4
  const keyIdbytes = strToUtf8array(str).subarray(0, 16);
@@ -41,3 +40,9 @@ export function convertDataUriToArrayBytes(uri: string): Uint8Array | null {
41
40
  }
42
41
  return keydata;
43
42
  }
43
+
44
+ export function strToUtf8array(str: string): Uint8Array {
45
+ return Uint8Array.from(unescape(encodeURIComponent(str)), (c) =>
46
+ c.charCodeAt(0),
47
+ );
48
+ }
@@ -11,25 +11,6 @@ export interface ILogger {
11
11
  error: ILogFunction;
12
12
  }
13
13
 
14
- export class Logger implements ILogger {
15
- trace: ILogFunction;
16
- debug: ILogFunction;
17
- log: ILogFunction;
18
- warn: ILogFunction;
19
- info: ILogFunction;
20
- error: ILogFunction;
21
-
22
- constructor(label: string, logger: ILogger) {
23
- const lb = `[${label}]:`;
24
- this.trace = noop;
25
- this.debug = logger.debug.bind(null, lb);
26
- this.log = logger.log.bind(null, lb);
27
- this.warn = logger.warn.bind(null, lb);
28
- this.info = logger.info.bind(null, lb);
29
- this.error = logger.error.bind(null, lb);
30
- }
31
- }
32
-
33
14
  const noop: ILogFunction = function () {};
34
15
 
35
16
  const fakeLogger: ILogger = {
@@ -41,9 +22,7 @@ const fakeLogger: ILogger = {
41
22
  error: noop,
42
23
  };
43
24
 
44
- function createLogger() {
45
- return Object.assign({}, fakeLogger);
46
- }
25
+ let exportedLogger: ILogger = fakeLogger;
47
26
 
48
27
  // let lastCallTime;
49
28
  // function formatMsgWithTimeInfo(type, msg) {
@@ -54,37 +33,33 @@ function createLogger() {
54
33
  // return msg;
55
34
  // }
56
35
 
57
- function consolePrintFn(type: string, id: string | undefined): ILogFunction {
36
+ function consolePrintFn(type: string): ILogFunction {
58
37
  const func: ILogFunction = self.console[type];
59
- return func
60
- ? func.bind(self.console, `${id ? '[' + id + '] ' : ''}[${type}] >`)
61
- : noop;
38
+ if (func) {
39
+ return func.bind(self.console, `[${type}] >`);
40
+ }
41
+ return noop;
62
42
  }
63
43
 
64
- function getLoggerFn(
65
- key: string,
66
- debugConfig: boolean | Partial<ILogger>,
67
- id?: string,
68
- ): ILogFunction {
69
- return debugConfig[key]
70
- ? debugConfig[key].bind(debugConfig)
71
- : consolePrintFn(key, id);
44
+ function exportLoggerFunctions(
45
+ debugConfig: boolean | ILogger,
46
+ ...functions: string[]
47
+ ): void {
48
+ functions.forEach(function (type) {
49
+ exportedLogger[type] = debugConfig[type]
50
+ ? debugConfig[type].bind(debugConfig)
51
+ : consolePrintFn(type);
52
+ });
72
53
  }
73
54
 
74
- const exportedLogger: ILogger = createLogger();
75
-
76
- export function enableLogs(
77
- debugConfig: boolean | ILogger,
78
- context: string,
79
- id?: string | undefined,
80
- ): ILogger {
55
+ export function enableLogs(debugConfig: boolean | ILogger, id: string): void {
81
56
  // check that console is available
82
- const newLogger = createLogger();
83
57
  if (
84
58
  (typeof console === 'object' && debugConfig === true) ||
85
59
  typeof debugConfig === 'object'
86
60
  ) {
87
- const keys: (keyof ILogger)[] = [
61
+ exportLoggerFunctions(
62
+ debugConfig,
88
63
  // Remove out from list here to hard-disable a log-level
89
64
  // 'trace',
90
65
  'debug',
@@ -92,29 +67,19 @@ export function enableLogs(
92
67
  'info',
93
68
  'warn',
94
69
  'error',
95
- ];
96
- keys.forEach((key) => {
97
- newLogger[key] = getLoggerFn(key, debugConfig, id);
98
- });
70
+ );
99
71
  // Some browsers don't allow to use bind on console object anyway
100
72
  // fallback to default if needed
101
73
  try {
102
- newLogger.log(
103
- `Debug logs enabled for "${context}" in hls.js version ${__VERSION__}`,
74
+ exportedLogger.log(
75
+ `Debug logs enabled for "${id}" in hls.js version ${__VERSION__}`,
104
76
  );
105
77
  } catch (e) {
106
- /* log fn threw an exception. All logger methods are no-ops. */
107
- return createLogger();
78
+ exportedLogger = fakeLogger;
108
79
  }
109
- // global exported logger uses the same functions as new logger without `id`
110
- keys.forEach((key) => {
111
- exportedLogger[key] = getLoggerFn(key, debugConfig);
112
- });
113
80
  } else {
114
- // Reset global exported logger
115
- Object.assign(exportedLogger, newLogger);
81
+ exportedLogger = fakeLogger;
116
82
  }
117
- return newLogger;
118
83
  }
119
84
 
120
85
  export const logger: ILogger = exportedLogger;
@@ -1,6 +1,6 @@
1
1
  import { ElementaryStreamTypes } from '../loader/fragment';
2
2
  import { sliceUint8 } from './typed-array';
3
- import { utf8ArrayToStr } from '@svta/common-media-library/utils/utf8ArrayToStr';
3
+ import { utf8ArrayToStr } from '../demux/id3';
4
4
  import { logger } from '../utils/logger';
5
5
  import Hex from './hex';
6
6
  import type { PassthroughTrack, UserdataSample } from '../types/demuxer';
@@ -327,7 +327,7 @@ function parseStsd(stsd: Uint8Array): { codec: string; encrypted: boolean } {
327
327
  case 'mp4a': {
328
328
  const codecBox = findBox(sampleEntries, [fourCC])[0];
329
329
  const esdsBox = findBox(codecBox.subarray(28), ['esds'])[0];
330
- if (esdsBox && esdsBox.length > 7) {
330
+ if (esdsBox && esdsBox.length > 12) {
331
331
  let i = 4;
332
332
  // ES Descriptor tag
333
333
  if (esdsBox[i++] !== 0x03) {
@@ -478,9 +478,7 @@ function parseStsd(stsd: Uint8Array): { codec: string; encrypted: boolean } {
478
478
 
479
479
  function skipBERInteger(bytes: Uint8Array, i: number): number {
480
480
  const limit = i + 5;
481
- while (bytes[i++] & 0x80 && i < limit) {
482
- /* do nothing */
483
- }
481
+ while (bytes[i++] & 0x80 && i < limit) {}
484
482
  return i;
485
483
  }
486
484
 
@@ -1,5 +1,5 @@
1
1
  import { VTTParser } from './vttparser';
2
- import { utf8ArrayToStr } from '@svta/common-media-library/utils/utf8ArrayToStr';
2
+ import { utf8ArrayToStr } from '../demux/id3';
3
3
  import {
4
4
  RationalTimestamp,
5
5
  toMpegTsClockFromTimescale,
@@ -1,4 +0,0 @@
1
- export const enum DecrypterAesMode {
2
- cbc = 0,
3
- ctr = 1,
4
- }