hls.js 1.5.12-0.canary.10398 → 1.5.12
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.
- package/README.md +3 -4
- package/dist/hls-demo.js +38 -41
- package/dist/hls-demo.js.map +1 -1
- package/dist/hls.js +2678 -4226
- package/dist/hls.js.d.ts +109 -174
- package/dist/hls.js.map +1 -1
- package/dist/hls.light.js +1964 -2900
- package/dist/hls.light.js.map +1 -1
- package/dist/hls.light.min.js +1 -1
- package/dist/hls.light.min.js.map +1 -1
- package/dist/hls.light.mjs +3409 -4360
- package/dist/hls.light.mjs.map +1 -1
- package/dist/hls.min.js +1 -1
- package/dist/hls.min.js.map +1 -1
- package/dist/hls.mjs +4451 -6014
- package/dist/hls.mjs.map +1 -1
- package/dist/hls.worker.js +1 -1
- package/dist/hls.worker.js.map +1 -1
- package/package.json +38 -38
- package/src/config.ts +2 -5
- package/src/controller/abr-controller.ts +25 -39
- package/src/controller/audio-stream-controller.ts +137 -141
- package/src/controller/audio-track-controller.ts +1 -1
- package/src/controller/base-playlist-controller.ts +10 -27
- package/src/controller/base-stream-controller.ts +97 -223
- package/src/controller/buffer-controller.ts +97 -250
- package/src/controller/buffer-operation-queue.ts +19 -16
- package/src/controller/cap-level-controller.ts +2 -3
- package/src/controller/cmcd-controller.ts +14 -51
- package/src/controller/content-steering-controller.ts +15 -29
- package/src/controller/eme-controller.ts +23 -10
- package/src/controller/error-controller.ts +22 -28
- package/src/controller/fps-controller.ts +3 -8
- package/src/controller/fragment-finders.ts +16 -44
- package/src/controller/fragment-tracker.ts +25 -58
- package/src/controller/gap-controller.ts +16 -43
- package/src/controller/id3-track-controller.ts +35 -45
- package/src/controller/latency-controller.ts +13 -18
- package/src/controller/level-controller.ts +19 -37
- package/src/controller/stream-controller.ts +83 -100
- package/src/controller/subtitle-stream-controller.ts +47 -35
- package/src/controller/subtitle-track-controller.ts +3 -5
- package/src/controller/timeline-controller.ts +22 -20
- package/src/crypt/aes-crypto.ts +2 -21
- package/src/crypt/decrypter.ts +16 -32
- package/src/crypt/fast-aes-key.ts +5 -28
- package/src/demux/audio/aacdemuxer.ts +2 -2
- package/src/demux/audio/ac3-demuxer.ts +3 -4
- package/src/demux/audio/adts.ts +4 -9
- package/src/demux/audio/base-audio-demuxer.ts +14 -16
- package/src/demux/audio/mp3demuxer.ts +3 -4
- package/src/demux/audio/mpegaudio.ts +1 -1
- package/src/demux/id3.ts +411 -0
- package/src/demux/mp4demuxer.ts +7 -7
- package/src/demux/sample-aes.ts +0 -2
- package/src/demux/transmuxer-interface.ts +16 -8
- package/src/demux/transmuxer-worker.ts +4 -4
- package/src/demux/transmuxer.ts +3 -16
- package/src/demux/tsdemuxer.ts +38 -75
- package/src/demux/video/avc-video-parser.ts +121 -210
- package/src/demux/video/base-video-parser.ts +2 -135
- package/src/demux/video/exp-golomb.ts +208 -0
- package/src/events.ts +1 -8
- package/src/exports-named.ts +1 -1
- package/src/hls.ts +43 -73
- package/src/loader/date-range.ts +5 -71
- package/src/loader/fragment-loader.ts +21 -23
- package/src/loader/fragment.ts +4 -8
- package/src/loader/key-loader.ts +1 -3
- package/src/loader/level-details.ts +6 -6
- package/src/loader/level-key.ts +9 -10
- package/src/loader/m3u8-parser.ts +144 -138
- package/src/loader/playlist-loader.ts +7 -5
- package/src/remux/mp4-generator.ts +1 -196
- package/src/remux/mp4-remuxer.ts +16 -36
- package/src/remux/passthrough-remuxer.ts +1 -1
- package/src/task-loop.ts +2 -5
- package/src/types/component-api.ts +1 -3
- package/src/types/demuxer.ts +0 -3
- package/src/types/events.ts +6 -19
- package/src/types/fragment-tracker.ts +2 -2
- package/src/types/general.ts +6 -0
- package/src/types/media-playlist.ts +1 -9
- package/src/types/remuxer.ts +1 -1
- package/src/utils/attr-list.ts +9 -96
- package/src/utils/buffer-helper.ts +31 -12
- package/src/utils/cea-608-parser.ts +3 -1
- package/src/utils/codecs.ts +5 -34
- package/src/utils/fetch-loader.ts +1 -1
- package/src/utils/hdr.ts +7 -4
- package/src/utils/imsc1-ttml-parser.ts +1 -1
- package/src/utils/keysystem-util.ts +6 -1
- package/src/utils/level-helper.ts +44 -71
- package/src/utils/logger.ts +23 -58
- package/src/utils/mp4-tools.ts +3 -5
- package/src/utils/rendition-helper.ts +74 -100
- package/src/utils/variable-substitution.ts +19 -0
- package/src/utils/webvtt-parser.ts +12 -2
- package/src/crypt/decrypter-aes-mode.ts +0 -4
- package/src/demux/video/hevc-video-parser.ts +0 -749
- package/src/utils/encryption-methods-util.ts +0 -21
- package/src/utils/hash.ts +0 -10
- package/src/utils/utf8-utils.ts +0 -18
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 {
|
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,13 +59,9 @@ 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[];
|
64
|
+
private started: boolean = false;
|
69
65
|
private _emitter: HlsEventEmitter = new EventEmitter();
|
70
66
|
private _autoLevelCapping: number = -1;
|
71
67
|
private _maxHdcpLevel: HdcpLevel = null;
|
@@ -146,19 +142,12 @@ export default class Hls implements HlsEventEmitter {
|
|
146
142
|
* @param userConfig - Configuration options applied over `Hls.DefaultConfig`
|
147
143
|
*/
|
148
144
|
constructor(userConfig: Partial<HlsConfig> = {}) {
|
149
|
-
|
150
|
-
|
151
|
-
'Hls instance',
|
152
|
-
));
|
153
|
-
const config = (this.config = mergeConfig(
|
154
|
-
Hls.DefaultConfig,
|
155
|
-
userConfig,
|
156
|
-
logger,
|
157
|
-
));
|
145
|
+
enableLogs(userConfig.debug || false, 'Hls instance');
|
146
|
+
const config = (this.config = mergeConfig(Hls.DefaultConfig, userConfig));
|
158
147
|
this.userConfig = userConfig;
|
159
148
|
|
160
149
|
if (config.progressive) {
|
161
|
-
enableStreamingMode(config
|
150
|
+
enableStreamingMode(config);
|
162
151
|
}
|
163
152
|
|
164
153
|
// core controllers and network loaders
|
@@ -171,10 +160,8 @@ export default class Hls implements HlsEventEmitter {
|
|
171
160
|
} = config;
|
172
161
|
const errorController = new ConfigErrorController(this);
|
173
162
|
const abrController = (this.abrController = new ConfigAbrController(this));
|
174
|
-
// FragmentTracker must be defined before StreamController because the order of event handling is important
|
175
|
-
const fragmentTracker = new FragmentTracker(this);
|
176
163
|
const bufferController = (this.bufferController =
|
177
|
-
new ConfigBufferController(this
|
164
|
+
new ConfigBufferController(this));
|
178
165
|
const capLevelController = (this.capLevelController =
|
179
166
|
new ConfigCapLevelController(this));
|
180
167
|
|
@@ -183,7 +170,7 @@ export default class Hls implements HlsEventEmitter {
|
|
183
170
|
const id3TrackController = new ID3TrackController(this);
|
184
171
|
|
185
172
|
const ConfigContentSteeringController = config.contentSteeringController;
|
186
|
-
//
|
173
|
+
// ConentSteeringController is defined before LevelController to receive Multivariant Playlist events first
|
187
174
|
const contentSteering = ConfigContentSteeringController
|
188
175
|
? new ConfigContentSteeringController(this)
|
189
176
|
: null;
|
@@ -191,6 +178,8 @@ export default class Hls implements HlsEventEmitter {
|
|
191
178
|
this,
|
192
179
|
contentSteering,
|
193
180
|
));
|
181
|
+
// FragmentTracker must be defined before StreamController because the order of event handling is important
|
182
|
+
const fragmentTracker = new FragmentTracker(this);
|
194
183
|
const keyLoader = new KeyLoader(this.config);
|
195
184
|
const streamController = (this.streamController = new StreamController(
|
196
185
|
this,
|
@@ -232,7 +221,7 @@ export default class Hls implements HlsEventEmitter {
|
|
232
221
|
new AudioStreamControllerClass(this, fragmentTracker, keyLoader),
|
233
222
|
);
|
234
223
|
}
|
235
|
-
//
|
224
|
+
// subtitleTrackController must be defined before subtitleStreamController because the order of event handling is important
|
236
225
|
this.subtitleTrackController = this.createController(
|
237
226
|
config.subtitleTrackController,
|
238
227
|
networkControllers,
|
@@ -331,7 +320,7 @@ export default class Hls implements HlsEventEmitter {
|
|
331
320
|
try {
|
332
321
|
return this.emit(event, event, eventObject);
|
333
322
|
} catch (error) {
|
334
|
-
|
323
|
+
logger.error(
|
335
324
|
'An internal error happened while handling event ' +
|
336
325
|
event +
|
337
326
|
'. Error message: "' +
|
@@ -365,7 +354,7 @@ export default class Hls implements HlsEventEmitter {
|
|
365
354
|
* Dispose of the instance
|
366
355
|
*/
|
367
356
|
destroy() {
|
368
|
-
|
357
|
+
logger.log('destroy');
|
369
358
|
this.trigger(Events.DESTROYING, undefined);
|
370
359
|
this.detachMedia();
|
371
360
|
this.removeAllListeners();
|
@@ -388,7 +377,7 @@ export default class Hls implements HlsEventEmitter {
|
|
388
377
|
* Attaches Hls.js to a media element
|
389
378
|
*/
|
390
379
|
attachMedia(media: HTMLMediaElement) {
|
391
|
-
|
380
|
+
logger.log('attachMedia');
|
392
381
|
this._media = media;
|
393
382
|
this.trigger(Events.MEDIA_ATTACHING, { media: media });
|
394
383
|
}
|
@@ -397,7 +386,7 @@ export default class Hls implements HlsEventEmitter {
|
|
397
386
|
* Detach Hls.js from the media
|
398
387
|
*/
|
399
388
|
detachMedia() {
|
400
|
-
|
389
|
+
logger.log('detachMedia');
|
401
390
|
this.trigger(Events.MEDIA_DETACHING, undefined);
|
402
391
|
this._media = null;
|
403
392
|
}
|
@@ -418,7 +407,7 @@ export default class Hls implements HlsEventEmitter {
|
|
418
407
|
));
|
419
408
|
this._autoLevelCapping = -1;
|
420
409
|
this._maxHdcpLevel = null;
|
421
|
-
|
410
|
+
logger.log(`loadSource:${loadingSource}`);
|
422
411
|
if (
|
423
412
|
media &&
|
424
413
|
loadedSource &&
|
@@ -439,7 +428,8 @@ export default class Hls implements HlsEventEmitter {
|
|
439
428
|
* Defaults to -1 (None: starts from earliest point)
|
440
429
|
*/
|
441
430
|
startLoad(startPosition: number = -1) {
|
442
|
-
|
431
|
+
logger.log(`startLoad(${startPosition})`);
|
432
|
+
this.started = true;
|
443
433
|
this.networkControllers.forEach((controller) => {
|
444
434
|
controller.startLoad(startPosition);
|
445
435
|
});
|
@@ -449,31 +439,34 @@ export default class Hls implements HlsEventEmitter {
|
|
449
439
|
* Stop loading of any stream data.
|
450
440
|
*/
|
451
441
|
stopLoad() {
|
452
|
-
|
442
|
+
logger.log('stopLoad');
|
443
|
+
this.started = false;
|
453
444
|
this.networkControllers.forEach((controller) => {
|
454
445
|
controller.stopLoad();
|
455
446
|
});
|
456
447
|
}
|
457
448
|
|
458
449
|
/**
|
459
|
-
* Resumes stream controller segment loading
|
450
|
+
* Resumes stream controller segment loading if previously started.
|
460
451
|
*/
|
461
452
|
resumeBuffering() {
|
462
|
-
this.
|
463
|
-
|
464
|
-
controller
|
465
|
-
|
466
|
-
|
453
|
+
if (this.started) {
|
454
|
+
this.networkControllers.forEach((controller) => {
|
455
|
+
if ('fragmentLoader' in controller) {
|
456
|
+
controller.startLoad(-1);
|
457
|
+
}
|
458
|
+
});
|
459
|
+
}
|
467
460
|
}
|
468
461
|
|
469
462
|
/**
|
470
|
-
*
|
463
|
+
* Stops stream controller segment loading without changing 'started' state like stopLoad().
|
471
464
|
* This allows for media buffering to be paused without interupting playlist loading.
|
472
465
|
*/
|
473
466
|
pauseBuffering() {
|
474
467
|
this.networkControllers.forEach((controller) => {
|
475
|
-
if (controller
|
476
|
-
controller.
|
468
|
+
if ('fragmentLoader' in controller) {
|
469
|
+
controller.stopLoad();
|
477
470
|
}
|
478
471
|
});
|
479
472
|
}
|
@@ -482,7 +475,7 @@ export default class Hls implements HlsEventEmitter {
|
|
482
475
|
* Swap through possible audio codecs in the stream (for example to switch from stereo to 5.1)
|
483
476
|
*/
|
484
477
|
swapAudioCodec() {
|
485
|
-
|
478
|
+
logger.log('swapAudioCodec');
|
486
479
|
this.streamController.swapAudioCodec();
|
487
480
|
}
|
488
481
|
|
@@ -493,7 +486,7 @@ export default class Hls implements HlsEventEmitter {
|
|
493
486
|
* Automatic recovery of media-errors by this process is configurable.
|
494
487
|
*/
|
495
488
|
recoverMediaError() {
|
496
|
-
|
489
|
+
logger.log('recoverMediaError');
|
497
490
|
const media = this._media;
|
498
491
|
this.detachMedia();
|
499
492
|
if (media) {
|
@@ -524,7 +517,7 @@ export default class Hls implements HlsEventEmitter {
|
|
524
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.
|
525
518
|
*/
|
526
519
|
set currentLevel(newLevel: number) {
|
527
|
-
|
520
|
+
logger.log(`set currentLevel:${newLevel}`);
|
528
521
|
this.levelController.manualLevel = newLevel;
|
529
522
|
this.streamController.immediateLevelSwitch();
|
530
523
|
}
|
@@ -543,7 +536,7 @@ export default class Hls implements HlsEventEmitter {
|
|
543
536
|
* @param newLevel - Pass -1 for automatic level selection
|
544
537
|
*/
|
545
538
|
set nextLevel(newLevel: number) {
|
546
|
-
|
539
|
+
logger.log(`set nextLevel:${newLevel}`);
|
547
540
|
this.levelController.manualLevel = newLevel;
|
548
541
|
this.streamController.nextLevelSwitch();
|
549
542
|
}
|
@@ -562,7 +555,7 @@ export default class Hls implements HlsEventEmitter {
|
|
562
555
|
* @param newLevel - Pass -1 for automatic level selection
|
563
556
|
*/
|
564
557
|
set loadLevel(newLevel: number) {
|
565
|
-
|
558
|
+
logger.log(`set loadLevel:${newLevel}`);
|
566
559
|
this.levelController.manualLevel = newLevel;
|
567
560
|
}
|
568
561
|
|
@@ -593,7 +586,7 @@ export default class Hls implements HlsEventEmitter {
|
|
593
586
|
* Sets "first-level", see getter.
|
594
587
|
*/
|
595
588
|
set firstLevel(newLevel: number) {
|
596
|
-
|
589
|
+
logger.log(`set firstLevel:${newLevel}`);
|
597
590
|
this.levelController.firstLevel = newLevel;
|
598
591
|
}
|
599
592
|
|
@@ -618,7 +611,7 @@ export default class Hls implements HlsEventEmitter {
|
|
618
611
|
* (determined from download of first segment)
|
619
612
|
*/
|
620
613
|
set startLevel(newLevel: number) {
|
621
|
-
|
614
|
+
logger.log(`set startLevel:${newLevel}`);
|
622
615
|
// if not in automatic start level detection, ensure startLevel is greater than minAutoLevel
|
623
616
|
if (newLevel !== -1) {
|
624
617
|
newLevel = Math.max(newLevel, this.minAutoLevel);
|
@@ -693,7 +686,7 @@ export default class Hls implements HlsEventEmitter {
|
|
693
686
|
*/
|
694
687
|
set autoLevelCapping(newLevel: number) {
|
695
688
|
if (this._autoLevelCapping !== newLevel) {
|
696
|
-
|
689
|
+
logger.log(`set autoLevelCapping:${newLevel}`);
|
697
690
|
this._autoLevelCapping = newLevel;
|
698
691
|
this.levelController.checkMaxAutoUpdated();
|
699
692
|
}
|
@@ -802,10 +795,6 @@ export default class Hls implements HlsEventEmitter {
|
|
802
795
|
return this.streamController.getMainFwdBufferInfo();
|
803
796
|
}
|
804
797
|
|
805
|
-
public get maxBufferLength(): number {
|
806
|
-
return this.streamController.maxBufferLength;
|
807
|
-
}
|
808
|
-
|
809
798
|
/**
|
810
799
|
* Find and select the best matching audio track, making a level switch when a Group change is necessary.
|
811
800
|
* Updates `hls.config.audioPreference`. Returns the selected track, or null when no matching track is found.
|
@@ -813,7 +802,7 @@ export default class Hls implements HlsEventEmitter {
|
|
813
802
|
public setAudioOption(
|
814
803
|
audioOption: MediaPlaylist | AudioSelectionOption | undefined,
|
815
804
|
): MediaPlaylist | null {
|
816
|
-
return this.audioTrackController?.setAudioOption(audioOption)
|
805
|
+
return this.audioTrackController?.setAudioOption(audioOption);
|
817
806
|
}
|
818
807
|
/**
|
819
808
|
* Find and select the best matching subtitle track, making a level switch when a Group change is necessary.
|
@@ -822,9 +811,8 @@ export default class Hls implements HlsEventEmitter {
|
|
822
811
|
public setSubtitleOption(
|
823
812
|
subtitleOption: MediaPlaylist | SubtitleSelectionOption | undefined,
|
824
813
|
): MediaPlaylist | null {
|
825
|
-
|
826
|
-
|
827
|
-
);
|
814
|
+
this.subtitleTrackController?.setSubtitleOption(subtitleOption);
|
815
|
+
return null;
|
828
816
|
}
|
829
817
|
|
830
818
|
/**
|
@@ -969,10 +957,6 @@ export default class Hls implements HlsEventEmitter {
|
|
969
957
|
return this.latencyController.targetLatency;
|
970
958
|
}
|
971
959
|
|
972
|
-
set targetLatency(latency: number) {
|
973
|
-
this.latencyController.targetLatency = latency;
|
974
|
-
}
|
975
|
-
|
976
960
|
/**
|
977
961
|
* the rate at which the edge of the current live playlist is advancing or 1 if there is none
|
978
962
|
*/
|
@@ -986,17 +970,6 @@ export default class Hls implements HlsEventEmitter {
|
|
986
970
|
get forceStartLoad(): boolean {
|
987
971
|
return this.streamController.forceStartLoad;
|
988
972
|
}
|
989
|
-
|
990
|
-
/**
|
991
|
-
* ContentSteering pathwayPriority getter/setter
|
992
|
-
*/
|
993
|
-
get pathwayPriority(): string[] | null {
|
994
|
-
return this.levelController.pathwayPriority;
|
995
|
-
}
|
996
|
-
|
997
|
-
set pathwayPriority(pathwayPriority: string[]) {
|
998
|
-
this.levelController.pathwayPriority = pathwayPriority;
|
999
|
-
}
|
1000
973
|
}
|
1001
974
|
|
1002
975
|
export type {
|
@@ -1059,7 +1032,7 @@ export type {
|
|
1059
1032
|
TSDemuxerConfig,
|
1060
1033
|
} from './config';
|
1061
1034
|
export type { MediaKeySessionContext } from './controller/eme-controller';
|
1062
|
-
export type { ILogger
|
1035
|
+
export type { ILogger } from './utils/logger';
|
1063
1036
|
export type {
|
1064
1037
|
PathwayClone,
|
1065
1038
|
SteeringManifest,
|
@@ -1073,7 +1046,7 @@ export type {
|
|
1073
1046
|
KeySystems,
|
1074
1047
|
KeySystemFormats,
|
1075
1048
|
} from './utils/mediakeys-helper';
|
1076
|
-
export type { DateRange
|
1049
|
+
export type { DateRange } from './loader/date-range';
|
1077
1050
|
export type { LoadStats } from './loader/load-stats';
|
1078
1051
|
export type { LevelKey } from './loader/level-key';
|
1079
1052
|
export type { LevelDetails } from './loader/level-details';
|
@@ -1123,7 +1096,6 @@ export type { ChunkMetadata } from './types/transmuxer';
|
|
1123
1096
|
export type {
|
1124
1097
|
BaseSegment,
|
1125
1098
|
Fragment,
|
1126
|
-
MediaFragment,
|
1127
1099
|
Part,
|
1128
1100
|
ElementaryStreams,
|
1129
1101
|
ElementaryStreamTypes,
|
@@ -1175,7 +1147,6 @@ export type {
|
|
1175
1147
|
ManifestParsedData,
|
1176
1148
|
MediaAttachedData,
|
1177
1149
|
MediaAttachingData,
|
1178
|
-
MediaEndedData,
|
1179
1150
|
NonNativeTextTrack,
|
1180
1151
|
NonNativeTextTracksData,
|
1181
1152
|
SteeringManifestLoadedData,
|
@@ -1190,4 +1161,3 @@ export type {
|
|
1190
1161
|
IErrorAction,
|
1191
1162
|
} from './controller/error-controller';
|
1192
1163
|
export type { AttrList } from './utils/attr-list';
|
1193
|
-
export type { ParsedMultivariantPlaylist } from './loader/m3u8-parser';
|
package/src/loader/date-range.ts
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
import { AttrList } from '../utils/attr-list';
|
2
2
|
import { logger } from '../utils/logger';
|
3
|
-
import type { Fragment } from './fragment';
|
4
3
|
|
5
4
|
// Avoid exporting const enum so that these values can be inlined
|
6
5
|
const enum DateRangeAttribute {
|
7
6
|
ID = 'ID',
|
8
7
|
CLASS = 'CLASS',
|
9
|
-
CUE = 'CUE',
|
10
8
|
START_DATE = 'START-DATE',
|
11
9
|
DURATION = 'DURATION',
|
12
10
|
END_DATE = 'END-DATE',
|
@@ -14,22 +12,12 @@ const enum DateRangeAttribute {
|
|
14
12
|
PLANNED_DURATION = 'PLANNED-DURATION',
|
15
13
|
SCTE35_OUT = 'SCTE35-OUT',
|
16
14
|
SCTE35_IN = 'SCTE35-IN',
|
17
|
-
SCTE35_CMD = 'SCTE35-CMD',
|
18
15
|
}
|
19
16
|
|
20
|
-
export type DateRangeCue = {
|
21
|
-
pre: boolean;
|
22
|
-
post: boolean;
|
23
|
-
once: boolean;
|
24
|
-
};
|
25
|
-
|
26
|
-
const CLASS_INTERSTITIAL = 'com.apple.hls.interstitial';
|
27
|
-
|
28
17
|
export function isDateRangeCueAttribute(attrName: string): boolean {
|
29
18
|
return (
|
30
19
|
attrName !== DateRangeAttribute.ID &&
|
31
20
|
attrName !== DateRangeAttribute.CLASS &&
|
32
|
-
attrName !== DateRangeAttribute.CUE &&
|
33
21
|
attrName !== DateRangeAttribute.START_DATE &&
|
34
22
|
attrName !== DateRangeAttribute.DURATION &&
|
35
23
|
attrName !== DateRangeAttribute.END_DATE &&
|
@@ -40,27 +28,17 @@ export function isDateRangeCueAttribute(attrName: string): boolean {
|
|
40
28
|
export function isSCTE35Attribute(attrName: string): boolean {
|
41
29
|
return (
|
42
30
|
attrName === DateRangeAttribute.SCTE35_OUT ||
|
43
|
-
attrName === DateRangeAttribute.SCTE35_IN
|
44
|
-
attrName === DateRangeAttribute.SCTE35_CMD
|
31
|
+
attrName === DateRangeAttribute.SCTE35_IN
|
45
32
|
);
|
46
33
|
}
|
47
34
|
|
48
35
|
export class DateRange {
|
49
36
|
public attr: AttrList;
|
50
|
-
public tagAnchor: Fragment | null;
|
51
|
-
public tagOrder: number;
|
52
37
|
private _startDate: Date;
|
53
38
|
private _endDate?: Date;
|
54
|
-
private _cue?: DateRangeCue;
|
55
39
|
private _badValueForSameId?: string;
|
56
40
|
|
57
|
-
constructor(
|
58
|
-
dateRangeAttr: AttrList,
|
59
|
-
dateRangeWithSameId?: DateRange | undefined,
|
60
|
-
tagCount: number = 0,
|
61
|
-
) {
|
62
|
-
this.tagAnchor = dateRangeWithSameId?.tagAnchor || null;
|
63
|
-
this.tagOrder = dateRangeWithSameId?.tagOrder ?? tagCount;
|
41
|
+
constructor(dateRangeAttr: AttrList, dateRangeWithSameId?: DateRange) {
|
64
42
|
if (dateRangeWithSameId) {
|
65
43
|
const previousAttr = dateRangeWithSameId.attr;
|
66
44
|
for (const key in previousAttr) {
|
@@ -83,13 +61,9 @@ export class DateRange {
|
|
83
61
|
);
|
84
62
|
}
|
85
63
|
this.attr = dateRangeAttr;
|
86
|
-
this._startDate =
|
87
|
-
? dateRangeWithSameId.startDate
|
88
|
-
: new Date(dateRangeAttr[DateRangeAttribute.START_DATE]);
|
64
|
+
this._startDate = new Date(dateRangeAttr[DateRangeAttribute.START_DATE]);
|
89
65
|
if (DateRangeAttribute.END_DATE in this.attr) {
|
90
|
-
const endDate =
|
91
|
-
dateRangeWithSameId?.endDate ||
|
92
|
-
new Date(this.attr[DateRangeAttribute.END_DATE]);
|
66
|
+
const endDate = new Date(this.attr[DateRangeAttribute.END_DATE]);
|
93
67
|
if (Number.isFinite(endDate.getTime())) {
|
94
68
|
this._endDate = endDate;
|
95
69
|
}
|
@@ -104,36 +78,6 @@ export class DateRange {
|
|
104
78
|
return this.attr.CLASS;
|
105
79
|
}
|
106
80
|
|
107
|
-
get cue(): DateRangeCue {
|
108
|
-
const _cue = this._cue;
|
109
|
-
if (_cue === undefined) {
|
110
|
-
return (this._cue = this.attr.enumeratedStringList(
|
111
|
-
this.attr.CUE ? 'CUE' : 'X-CUE',
|
112
|
-
{
|
113
|
-
pre: false,
|
114
|
-
post: false,
|
115
|
-
once: false,
|
116
|
-
},
|
117
|
-
));
|
118
|
-
}
|
119
|
-
return _cue;
|
120
|
-
}
|
121
|
-
|
122
|
-
get startTime(): number {
|
123
|
-
const { tagAnchor } = this;
|
124
|
-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
125
|
-
if (tagAnchor === null || tagAnchor.programDateTime === null) {
|
126
|
-
logger.warn(
|
127
|
-
`Expected tagAnchor Fragment with PDT set for DateRange "${this.id}": ${tagAnchor}`,
|
128
|
-
);
|
129
|
-
return NaN;
|
130
|
-
}
|
131
|
-
return (
|
132
|
-
tagAnchor.start +
|
133
|
-
(this.startDate.getTime() - tagAnchor.programDateTime) / 1000
|
134
|
-
);
|
135
|
-
}
|
136
|
-
|
137
81
|
get startDate(): Date {
|
138
82
|
return this._startDate;
|
139
83
|
}
|
@@ -176,23 +120,13 @@ export class DateRange {
|
|
176
120
|
return this.attr.bool(DateRangeAttribute.END_ON_NEXT);
|
177
121
|
}
|
178
122
|
|
179
|
-
get isInterstitial(): boolean {
|
180
|
-
return this.class === CLASS_INTERSTITIAL;
|
181
|
-
}
|
182
|
-
|
183
123
|
get isValid(): boolean {
|
184
124
|
return (
|
185
125
|
!!this.id &&
|
186
126
|
!this._badValueForSameId &&
|
187
127
|
Number.isFinite(this.startDate.getTime()) &&
|
188
128
|
(this.duration === null || this.duration >= 0) &&
|
189
|
-
(!this.endOnNext || !!this.class)
|
190
|
-
(!this.attr.CUE ||
|
191
|
-
(!this.cue.pre && !this.cue.post) ||
|
192
|
-
this.cue.pre !== this.cue.post) &&
|
193
|
-
(!this.isInterstitial ||
|
194
|
-
'X-ASSET-URI' in this.attr ||
|
195
|
-
'X-ASSET-LIST' in this.attr)
|
129
|
+
(!this.endOnNext || !!this.class)
|
196
130
|
);
|
197
131
|
}
|
198
132
|
}
|
@@ -1,17 +1,18 @@
|
|
1
1
|
import { ErrorTypes, ErrorDetails } from '../errors';
|
2
|
+
import { Fragment } from './fragment';
|
3
|
+
import {
|
4
|
+
Loader,
|
5
|
+
LoaderConfiguration,
|
6
|
+
FragmentLoaderContext,
|
7
|
+
} from '../types/loader';
|
2
8
|
import { getLoaderConfigWithoutReties } from '../utils/error-helper';
|
3
9
|
import type { HlsConfig } from '../config';
|
4
|
-
import type { BaseSegment,
|
10
|
+
import type { BaseSegment, Part } from './fragment';
|
5
11
|
import type {
|
6
12
|
ErrorData,
|
7
13
|
FragLoadedData,
|
8
14
|
PartsLoadedData,
|
9
15
|
} from '../types/events';
|
10
|
-
import type {
|
11
|
-
Loader,
|
12
|
-
LoaderConfiguration,
|
13
|
-
FragmentLoaderContext,
|
14
|
-
} from '../types/loader';
|
15
16
|
|
16
17
|
const MIN_CHUNK_SIZE = Math.pow(2, 17); // 128kb
|
17
18
|
|
@@ -76,11 +77,13 @@ export default class FragmentLoader {
|
|
76
77
|
frag.gap = false;
|
77
78
|
}
|
78
79
|
}
|
79
|
-
const loader =
|
80
|
-
|
81
|
-
|
80
|
+
const loader =
|
81
|
+
(this.loader =
|
82
|
+
frag.loader =
|
83
|
+
FragmentILoader
|
84
|
+
? new FragmentILoader(config)
|
85
|
+
: (new DefaultILoader(config) as Loader<FragmentLoaderContext>));
|
82
86
|
const loaderContext = createLoaderContext(frag);
|
83
|
-
frag.loader = loader;
|
84
87
|
const loadPolicy = getLoaderConfigWithoutReties(
|
85
88
|
config.fragLoadPolicy.default,
|
86
89
|
);
|
@@ -185,11 +188,13 @@ export default class FragmentLoader {
|
|
185
188
|
reject(createGapLoadError(frag, part));
|
186
189
|
return;
|
187
190
|
}
|
188
|
-
const loader =
|
189
|
-
|
190
|
-
|
191
|
+
const loader =
|
192
|
+
(this.loader =
|
193
|
+
frag.loader =
|
194
|
+
FragmentILoader
|
195
|
+
? new FragmentILoader(config)
|
196
|
+
: (new DefaultILoader(config) as Loader<FragmentLoaderContext>));
|
191
197
|
const loaderContext = createLoaderContext(frag, part);
|
192
|
-
frag.loader = loader;
|
193
198
|
// Should we define another load policy for parts?
|
194
199
|
const loadPolicy = getLoaderConfigWithoutReties(
|
195
200
|
config.fragLoadPolicy.default,
|
@@ -331,11 +336,8 @@ function createLoaderContext(
|
|
331
336
|
if (Number.isFinite(start) && Number.isFinite(end)) {
|
332
337
|
let byteRangeStart = start;
|
333
338
|
let byteRangeEnd = end;
|
334
|
-
if (
|
335
|
-
|
336
|
-
isMethodFullSegmentAesCbc(frag.decryptdata?.method)
|
337
|
-
) {
|
338
|
-
// 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,
|
339
341
|
// has the unencrypted size specified in the range.
|
340
342
|
// Ref: https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-08#section-6.3.6
|
341
343
|
const fragmentLen = end - start;
|
@@ -370,10 +372,6 @@ function createGapLoadError(frag: Fragment, part?: Part): LoadError {
|
|
370
372
|
return new LoadError(errorData);
|
371
373
|
}
|
372
374
|
|
373
|
-
function isMethodFullSegmentAesCbc(method) {
|
374
|
-
return method === 'AES-128' || method === 'AES-256';
|
375
|
-
}
|
376
|
-
|
377
375
|
export class LoadError extends Error {
|
378
376
|
public readonly data: FragLoadFailResult;
|
379
377
|
constructor(data: FragLoadFailResult) {
|
package/src/loader/fragment.ts
CHANGED
@@ -90,10 +90,6 @@ export class BaseSegment {
|
|
90
90
|
}
|
91
91
|
}
|
92
92
|
|
93
|
-
export interface MediaFragment extends Fragment {
|
94
|
-
sn: number;
|
95
|
-
}
|
96
|
-
|
97
93
|
/**
|
98
94
|
* Object representing parsed data from an HLS Segment. Found in {@link hls.js#LevelDetails.fragments}.
|
99
95
|
*/
|
@@ -127,9 +123,9 @@ export class Fragment extends BaseSegment {
|
|
127
123
|
// The ending Presentation Time Stamp (PTS) of the fragment. Set after transmux complete.
|
128
124
|
public endPTS?: number;
|
129
125
|
// The starting Decode Time Stamp (DTS) of the fragment. Set after transmux complete.
|
130
|
-
public startDTS
|
126
|
+
public startDTS!: number;
|
131
127
|
// The ending Decode Time Stamp (DTS) of the fragment. Set after transmux complete.
|
132
|
-
public endDTS
|
128
|
+
public endDTS!: number;
|
133
129
|
// The start time of the fragment, as listed in the manifest. Updated after transmux complete.
|
134
130
|
public start: number = 0;
|
135
131
|
// Set by `updateFragPTSDTS` in level-helper
|
@@ -278,13 +274,13 @@ export class Part extends BaseSegment {
|
|
278
274
|
public readonly gap: boolean = false;
|
279
275
|
public readonly independent: boolean = false;
|
280
276
|
public readonly relurl: string;
|
281
|
-
public readonly fragment:
|
277
|
+
public readonly fragment: Fragment;
|
282
278
|
public readonly index: number;
|
283
279
|
public stats: LoadStats = new LoadStats();
|
284
280
|
|
285
281
|
constructor(
|
286
282
|
partAttrs: AttrList,
|
287
|
-
frag:
|
283
|
+
frag: Fragment,
|
288
284
|
baseurl: string,
|
289
285
|
index: number,
|
290
286
|
previous?: Part,
|
package/src/loader/key-loader.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ErrorTypes, ErrorDetails } from '../errors';
|
2
|
-
import
|
2
|
+
import {
|
3
3
|
LoaderStats,
|
4
4
|
LoaderResponse,
|
5
5
|
LoaderConfiguration,
|
@@ -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(
|
@@ -1,6 +1,7 @@
|
|
1
|
-
import
|
2
|
-
import type {
|
1
|
+
import { Part } from './fragment';
|
2
|
+
import type { Fragment } from './fragment';
|
3
3
|
import type { AttrList } from '../utils/attr-list';
|
4
|
+
import type { DateRange } from './date-range';
|
4
5
|
import type { VariableMap } from '../types/level';
|
5
6
|
|
6
7
|
const DEFAULT_TARGET_DURATION = 10;
|
@@ -14,11 +15,10 @@ export class LevelDetails {
|
|
14
15
|
public averagetargetduration?: number;
|
15
16
|
public endCC: number = 0;
|
16
17
|
public endSN: number = 0;
|
17
|
-
public fragments:
|
18
|
-
public fragmentHint?:
|
18
|
+
public fragments: Fragment[];
|
19
|
+
public fragmentHint?: Fragment;
|
19
20
|
public partList: Part[] | null = null;
|
20
21
|
public dateRanges: Record<string, DateRange>;
|
21
|
-
public dateRangeTagCount: number = 0;
|
22
22
|
public live: boolean = true;
|
23
23
|
public ageHeader: number = 0;
|
24
24
|
public advancedDateTime?: number;
|
@@ -148,7 +148,7 @@ export class LevelDetails {
|
|
148
148
|
|
149
149
|
get lastPartSn(): number {
|
150
150
|
if (this.partList?.length) {
|
151
|
-
return this.partList[this.partList.length - 1].fragment.sn;
|
151
|
+
return this.partList[this.partList.length - 1].fragment.sn as number;
|
152
152
|
}
|
153
153
|
return this.endSN;
|
154
154
|
}
|