hls.js 1.5.2-0.canary.9934 → 1.5.3

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 (60) hide show
  1. package/dist/hls-demo.js +0 -5
  2. package/dist/hls-demo.js.map +1 -1
  3. package/dist/hls.js +757 -883
  4. package/dist/hls.js.d.ts +47 -56
  5. package/dist/hls.js.map +1 -1
  6. package/dist/hls.light.js +477 -600
  7. package/dist/hls.light.js.map +1 -1
  8. package/dist/hls.light.min.js +1 -1
  9. package/dist/hls.light.min.js.map +1 -1
  10. package/dist/hls.light.mjs +335 -446
  11. package/dist/hls.light.mjs.map +1 -1
  12. package/dist/hls.min.js +1 -1
  13. package/dist/hls.min.js.map +1 -1
  14. package/dist/hls.mjs +572 -681
  15. package/dist/hls.mjs.map +1 -1
  16. package/dist/hls.worker.js +1 -1
  17. package/dist/hls.worker.js.map +1 -1
  18. package/package.json +11 -11
  19. package/src/config.ts +2 -3
  20. package/src/controller/abr-controller.ts +22 -22
  21. package/src/controller/audio-stream-controller.ts +14 -11
  22. package/src/controller/audio-track-controller.ts +1 -1
  23. package/src/controller/base-playlist-controller.ts +7 -7
  24. package/src/controller/base-stream-controller.ts +29 -47
  25. package/src/controller/buffer-controller.ts +11 -10
  26. package/src/controller/cap-level-controller.ts +2 -1
  27. package/src/controller/cmcd-controller.ts +3 -25
  28. package/src/controller/content-steering-controller.ts +6 -8
  29. package/src/controller/eme-controller.ts +22 -9
  30. package/src/controller/error-controller.ts +8 -6
  31. package/src/controller/fps-controller.ts +3 -2
  32. package/src/controller/gap-controller.ts +16 -43
  33. package/src/controller/latency-controller.ts +11 -9
  34. package/src/controller/level-controller.ts +17 -5
  35. package/src/controller/stream-controller.ts +31 -24
  36. package/src/controller/subtitle-stream-controller.ts +14 -13
  37. package/src/controller/subtitle-track-controller.ts +3 -5
  38. package/src/controller/timeline-controller.ts +30 -23
  39. package/src/crypt/aes-crypto.ts +2 -21
  40. package/src/crypt/decrypter.ts +18 -32
  41. package/src/crypt/fast-aes-key.ts +5 -24
  42. package/src/demux/audio/adts.ts +4 -9
  43. package/src/demux/sample-aes.ts +0 -2
  44. package/src/demux/transmuxer-interface.ts +12 -4
  45. package/src/demux/transmuxer-worker.ts +4 -4
  46. package/src/demux/transmuxer.ts +3 -16
  47. package/src/demux/tsdemuxer.ts +17 -12
  48. package/src/events.ts +0 -7
  49. package/src/hls.ts +20 -33
  50. package/src/loader/fragment-loader.ts +2 -9
  51. package/src/loader/key-loader.ts +0 -2
  52. package/src/loader/level-key.ts +9 -10
  53. package/src/remux/mp4-remuxer.ts +4 -20
  54. package/src/task-loop.ts +2 -5
  55. package/src/types/demuxer.ts +0 -1
  56. package/src/types/events.ts +0 -4
  57. package/src/utils/codecs.ts +4 -33
  58. package/src/utils/logger.ts +24 -53
  59. package/src/crypt/decrypter-aes-mode.ts +0 -4
  60. package/src/utils/encryption-methods-util.ts +0 -21
package/src/events.ts CHANGED
@@ -3,7 +3,6 @@ import {
3
3
  ManifestLoadingData,
4
4
  MediaAttachedData,
5
5
  MediaAttachingData,
6
- MediaEndedData,
7
6
  LevelLoadingData,
8
7
  LevelLoadedData,
9
8
  ManifestParsedData,
@@ -61,8 +60,6 @@ export enum Events {
61
60
  MEDIA_DETACHING = 'hlsMediaDetaching',
62
61
  // Fired when MediaSource has been detached from media element
63
62
  MEDIA_DETACHED = 'hlsMediaDetached',
64
- // Fired when HTMLMediaElement dispatches "ended" event, or stalls at end of VOD program
65
- MEDIA_ENDED = 'hlsMediaEnded',
66
63
  // Fired when the buffer is going to be reset
67
64
  BUFFER_RESET = 'hlsBufferReset',
68
65
  // Fired when we know about the codecs that we need buffers for to push into - data: {tracks : { container, codec, levelCodec, initSegment, metadata }}
@@ -187,10 +184,6 @@ export interface HlsListeners {
187
184
  ) => void;
188
185
  [Events.MEDIA_DETACHING]: (event: Events.MEDIA_DETACHING) => void;
189
186
  [Events.MEDIA_DETACHED]: (event: Events.MEDIA_DETACHED) => void;
190
- [Events.MEDIA_ENDED]: (
191
- event: Events.MEDIA_ENDED,
192
- data: MediaEndedData,
193
- ) => void;
194
187
  [Events.BUFFER_RESET]: (event: Events.BUFFER_RESET) => void;
195
188
  [Events.BUFFER_CODECS]: (
196
189
  event: Events.BUFFER_CODECS,
package/src/hls.ts CHANGED
@@ -8,7 +8,7 @@ import KeyLoader from './loader/key-loader';
8
8
  import StreamController from './controller/stream-controller';
9
9
  import { isMSESupported, isSupported } from './is-supported';
10
10
  import { getMediaSource } from './utils/mediasource-helper';
11
- import { enableLogs, type ILogger } from './utils/logger';
11
+ import { logger, enableLogs } from './utils/logger';
12
12
  import { enableStreamingMode, hlsDefaultConfig, mergeConfig } from './config';
13
13
  import { EventEmitter } from 'eventemitter3';
14
14
  import { Events } from './events';
@@ -59,11 +59,6 @@ export default class Hls implements HlsEventEmitter {
59
59
  */
60
60
  public readonly userConfig: Partial<HlsConfig>;
61
61
 
62
- /**
63
- * The logger functions used by this player instance, configured on player instantiation.
64
- */
65
- public readonly logger: ILogger;
66
-
67
62
  private coreComponents: ComponentAPI[];
68
63
  private networkControllers: NetworkComponentAPI[];
69
64
  private started: boolean = false;
@@ -147,19 +142,12 @@ export default class Hls implements HlsEventEmitter {
147
142
  * @param userConfig - Configuration options applied over `Hls.DefaultConfig`
148
143
  */
149
144
  constructor(userConfig: Partial<HlsConfig> = {}) {
150
- const logger = (this.logger = enableLogs(
151
- userConfig.debug || false,
152
- 'Hls instance',
153
- ));
154
- const config = (this.config = mergeConfig(
155
- Hls.DefaultConfig,
156
- userConfig,
157
- logger,
158
- ));
145
+ enableLogs(userConfig.debug || false, 'Hls instance');
146
+ const config = (this.config = mergeConfig(Hls.DefaultConfig, userConfig));
159
147
  this.userConfig = userConfig;
160
148
 
161
149
  if (config.progressive) {
162
- enableStreamingMode(config, logger);
150
+ enableStreamingMode(config);
163
151
  }
164
152
 
165
153
  // core controllers and network loaders
@@ -332,7 +320,7 @@ export default class Hls implements HlsEventEmitter {
332
320
  try {
333
321
  return this.emit(event, event, eventObject);
334
322
  } catch (error) {
335
- this.logger.error(
323
+ logger.error(
336
324
  'An internal error happened while handling event ' +
337
325
  event +
338
326
  '. Error message: "' +
@@ -366,7 +354,7 @@ export default class Hls implements HlsEventEmitter {
366
354
  * Dispose of the instance
367
355
  */
368
356
  destroy() {
369
- this.logger.log('destroy');
357
+ logger.log('destroy');
370
358
  this.trigger(Events.DESTROYING, undefined);
371
359
  this.detachMedia();
372
360
  this.removeAllListeners();
@@ -389,7 +377,7 @@ export default class Hls implements HlsEventEmitter {
389
377
  * Attaches Hls.js to a media element
390
378
  */
391
379
  attachMedia(media: HTMLMediaElement) {
392
- this.logger.log('attachMedia');
380
+ logger.log('attachMedia');
393
381
  this._media = media;
394
382
  this.trigger(Events.MEDIA_ATTACHING, { media: media });
395
383
  }
@@ -398,7 +386,7 @@ export default class Hls implements HlsEventEmitter {
398
386
  * Detach Hls.js from the media
399
387
  */
400
388
  detachMedia() {
401
- this.logger.log('detachMedia');
389
+ logger.log('detachMedia');
402
390
  this.trigger(Events.MEDIA_DETACHING, undefined);
403
391
  this._media = null;
404
392
  }
@@ -419,7 +407,7 @@ export default class Hls implements HlsEventEmitter {
419
407
  ));
420
408
  this._autoLevelCapping = -1;
421
409
  this._maxHdcpLevel = null;
422
- this.logger.log(`loadSource:${loadingSource}`);
410
+ logger.log(`loadSource:${loadingSource}`);
423
411
  if (
424
412
  media &&
425
413
  loadedSource &&
@@ -440,7 +428,7 @@ export default class Hls implements HlsEventEmitter {
440
428
  * Defaults to -1 (None: starts from earliest point)
441
429
  */
442
430
  startLoad(startPosition: number = -1) {
443
- this.logger.log(`startLoad(${startPosition})`);
431
+ logger.log(`startLoad(${startPosition})`);
444
432
  this.started = true;
445
433
  this.networkControllers.forEach((controller) => {
446
434
  controller.startLoad(startPosition);
@@ -451,7 +439,7 @@ export default class Hls implements HlsEventEmitter {
451
439
  * Stop loading of any stream data.
452
440
  */
453
441
  stopLoad() {
454
- this.logger.log('stopLoad');
442
+ logger.log('stopLoad');
455
443
  this.started = false;
456
444
  this.networkControllers.forEach((controller) => {
457
445
  controller.stopLoad();
@@ -487,7 +475,7 @@ export default class Hls implements HlsEventEmitter {
487
475
  * Swap through possible audio codecs in the stream (for example to switch from stereo to 5.1)
488
476
  */
489
477
  swapAudioCodec() {
490
- this.logger.log('swapAudioCodec');
478
+ logger.log('swapAudioCodec');
491
479
  this.streamController.swapAudioCodec();
492
480
  }
493
481
 
@@ -498,7 +486,7 @@ export default class Hls implements HlsEventEmitter {
498
486
  * Automatic recovery of media-errors by this process is configurable.
499
487
  */
500
488
  recoverMediaError() {
501
- this.logger.log('recoverMediaError');
489
+ logger.log('recoverMediaError');
502
490
  const media = this._media;
503
491
  this.detachMedia();
504
492
  if (media) {
@@ -529,7 +517,7 @@ export default class Hls implements HlsEventEmitter {
529
517
  * Set quality level index immediately. This will flush the current buffer to replace the quality asap. That means playback will interrupt at least shortly to re-buffer and re-sync eventually. Set to -1 for automatic level selection.
530
518
  */
531
519
  set currentLevel(newLevel: number) {
532
- this.logger.log(`set currentLevel:${newLevel}`);
520
+ logger.log(`set currentLevel:${newLevel}`);
533
521
  this.levelController.manualLevel = newLevel;
534
522
  this.streamController.immediateLevelSwitch();
535
523
  }
@@ -548,7 +536,7 @@ export default class Hls implements HlsEventEmitter {
548
536
  * @param newLevel - Pass -1 for automatic level selection
549
537
  */
550
538
  set nextLevel(newLevel: number) {
551
- this.logger.log(`set nextLevel:${newLevel}`);
539
+ logger.log(`set nextLevel:${newLevel}`);
552
540
  this.levelController.manualLevel = newLevel;
553
541
  this.streamController.nextLevelSwitch();
554
542
  }
@@ -567,7 +555,7 @@ export default class Hls implements HlsEventEmitter {
567
555
  * @param newLevel - Pass -1 for automatic level selection
568
556
  */
569
557
  set loadLevel(newLevel: number) {
570
- this.logger.log(`set loadLevel:${newLevel}`);
558
+ logger.log(`set loadLevel:${newLevel}`);
571
559
  this.levelController.manualLevel = newLevel;
572
560
  }
573
561
 
@@ -598,7 +586,7 @@ export default class Hls implements HlsEventEmitter {
598
586
  * Sets "first-level", see getter.
599
587
  */
600
588
  set firstLevel(newLevel: number) {
601
- this.logger.log(`set firstLevel:${newLevel}`);
589
+ logger.log(`set firstLevel:${newLevel}`);
602
590
  this.levelController.firstLevel = newLevel;
603
591
  }
604
592
 
@@ -623,7 +611,7 @@ export default class Hls implements HlsEventEmitter {
623
611
  * (determined from download of first segment)
624
612
  */
625
613
  set startLevel(newLevel: number) {
626
- this.logger.log(`set startLevel:${newLevel}`);
614
+ logger.log(`set startLevel:${newLevel}`);
627
615
  // if not in automatic start level detection, ensure startLevel is greater than minAutoLevel
628
616
  if (newLevel !== -1) {
629
617
  newLevel = Math.max(newLevel, this.minAutoLevel);
@@ -698,7 +686,7 @@ export default class Hls implements HlsEventEmitter {
698
686
  */
699
687
  set autoLevelCapping(newLevel: number) {
700
688
  if (this._autoLevelCapping !== newLevel) {
701
- this.logger.log(`set autoLevelCapping:${newLevel}`);
689
+ logger.log(`set autoLevelCapping:${newLevel}`);
702
690
  this._autoLevelCapping = newLevel;
703
691
  this.levelController.checkMaxAutoUpdated();
704
692
  }
@@ -1044,7 +1032,7 @@ export type {
1044
1032
  TSDemuxerConfig,
1045
1033
  } from './config';
1046
1034
  export type { MediaKeySessionContext } from './controller/eme-controller';
1047
- export type { ILogger, Logger } from './utils/logger';
1035
+ export type { ILogger } from './utils/logger';
1048
1036
  export type {
1049
1037
  PathwayClone,
1050
1038
  SteeringManifest,
@@ -1159,7 +1147,6 @@ export type {
1159
1147
  ManifestParsedData,
1160
1148
  MediaAttachedData,
1161
1149
  MediaAttachingData,
1162
- MediaEndedData,
1163
1150
  NonNativeTextTrack,
1164
1151
  NonNativeTextTracksData,
1165
1152
  SteeringManifestLoadedData,
@@ -336,11 +336,8 @@ function createLoaderContext(
336
336
  if (Number.isFinite(start) && Number.isFinite(end)) {
337
337
  let byteRangeStart = start;
338
338
  let byteRangeEnd = end;
339
- if (
340
- frag.sn === 'initSegment' &&
341
- isMethodFullSegmentAesCbc(frag.decryptdata?.method)
342
- ) {
343
- // MAP segment encrypted with method 'AES-128' or 'AES-256' (cbc), when served with HTTP Range,
339
+ if (frag.sn === 'initSegment' && frag.decryptdata?.method === 'AES-128') {
340
+ // MAP segment encrypted with method 'AES-128', when served with HTTP Range,
344
341
  // has the unencrypted size specified in the range.
345
342
  // Ref: https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-08#section-6.3.6
346
343
  const fragmentLen = end - start;
@@ -375,10 +372,6 @@ function createGapLoadError(frag: Fragment, part?: Part): LoadError {
375
372
  return new LoadError(errorData);
376
373
  }
377
374
 
378
- function isMethodFullSegmentAesCbc(method) {
379
- return method === 'AES-128' || method === 'AES-256';
380
- }
381
-
382
375
  export class LoadError extends Error {
383
376
  public readonly data: FragLoadFailResult;
384
377
  constructor(data: FragLoadFailResult) {
@@ -194,8 +194,6 @@ export default class KeyLoader implements ComponentAPI {
194
194
  }
195
195
  return this.loadKeyEME(keyInfo, frag);
196
196
  case 'AES-128':
197
- case 'AES-256':
198
- case 'AES-256-CTR':
199
197
  return this.loadKeyHTTP(keyInfo, frag);
200
198
  default:
201
199
  return Promise.reject(
@@ -2,7 +2,6 @@ import {
2
2
  changeEndianness,
3
3
  convertDataUriToArrayBytes,
4
4
  } from '../utils/keysystem-util';
5
- import { isFullSegmentEncryption } from '../utils/encryption-methods-util';
6
5
  import { KeySystemFormats } from '../utils/mediakeys-helper';
7
6
  import { mp4pssh } from '../utils/mp4-tools';
8
7
  import { logger } from '../utils/logger';
@@ -52,14 +51,13 @@ export class LevelKey implements DecryptData {
52
51
  this.keyFormatVersions = formatversions;
53
52
  this.iv = iv;
54
53
  this.encrypted = method ? method !== 'NONE' : false;
55
- this.isCommonEncryption =
56
- this.encrypted && !isFullSegmentEncryption(method);
54
+ this.isCommonEncryption = this.encrypted && method !== 'AES-128';
57
55
  }
58
56
 
59
57
  public isSupported(): boolean {
60
58
  // If it's Segment encryption or No encryption, just select that key system
61
59
  if (this.method) {
62
- if (isFullSegmentEncryption(this.method) || this.method === 'NONE') {
60
+ if (this.method === 'AES-128' || this.method === 'NONE') {
63
61
  return true;
64
62
  }
65
63
  if (this.keyFormat === 'identity') {
@@ -90,15 +88,16 @@ export class LevelKey implements DecryptData {
90
88
  return null;
91
89
  }
92
90
 
93
- if (isFullSegmentEncryption(this.method) && this.uri && !this.iv) {
91
+ if (this.method === 'AES-128' && this.uri && !this.iv) {
94
92
  if (typeof sn !== 'number') {
95
93
  // We are fetching decryption data for a initialization segment
96
- // If the segment was encrypted with AES-128/256
94
+ // If the segment was encrypted with AES-128
97
95
  // It must have an IV defined. We cannot substitute the Segment Number in.
98
- logger.warn(
99
- `missing IV for initialization segment with method="${this.method}" - compliance issue`,
100
- );
101
-
96
+ if (this.method === 'AES-128' && !this.iv) {
97
+ logger.warn(
98
+ `missing IV for initialization segment with method="${this.method}" - compliance issue`,
99
+ );
100
+ }
102
101
  // Explicitly set sn to resulting value from implicit conversions 'initSegment' values for IV generation.
103
102
  sn = 0;
104
103
  }
@@ -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;
@@ -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(
@@ -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
 
@@ -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
 
@@ -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;
@@ -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,
@@ -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
- }
@@ -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 | undefined,
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
- let 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,23 +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
  }
80
+ } else {
81
+ exportedLogger = fakeLogger;
109
82
  }
110
- exportedLogger = newLogger;
111
- return newLogger;
112
83
  }
113
84
 
114
85
  export const logger: ILogger = exportedLogger;
@@ -1,4 +0,0 @@
1
- export const enum DecrypterAesMode {
2
- cbc = 0,
3
- ctr = 1,
4
- }
@@ -1,21 +0,0 @@
1
- import { DecrypterAesMode } from '../crypt/decrypter-aes-mode';
2
-
3
- export function isFullSegmentEncryption(method: string): boolean {
4
- return (
5
- method === 'AES-128' || method === 'AES-256' || method === 'AES-256-CTR'
6
- );
7
- }
8
-
9
- export function getAesModeFromFullSegmentMethod(
10
- method: string,
11
- ): DecrypterAesMode {
12
- switch (method) {
13
- case 'AES-128':
14
- case 'AES-256':
15
- return DecrypterAesMode.cbc;
16
- case 'AES-256-CTR':
17
- return DecrypterAesMode.ctr;
18
- default:
19
- throw new Error(`invalid full segment method ${method}`);
20
- }
21
- }