hls.js 1.4.6 → 1.4.8
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/dist/hls.js +58 -50
- package/dist/hls.js.map +1 -1
- package/dist/hls.light.js +15 -9
- 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 +15 -9
- 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 +62 -56
- package/dist/hls.mjs.map +1 -1
- package/dist/hls.worker.js +1 -1
- package/package.json +1 -1
- package/src/controller/base-stream-controller.ts +10 -5
- package/src/controller/stream-controller.ts +6 -2
- package/src/controller/subtitle-stream-controller.ts +21 -20
- package/src/controller/timeline-controller.ts +23 -24
- package/src/utils/webvtt-parser.ts +8 -6
- package/src/utils/xhr-loader.ts +1 -0
|
@@ -304,7 +304,7 @@ export class TimelineController implements ComponentAPI {
|
|
|
304
304
|
this.captionsTracks = {};
|
|
305
305
|
this.nonNativeCaptionsTracks = {};
|
|
306
306
|
this.textTracks = [];
|
|
307
|
-
this.unparsedVttFrags =
|
|
307
|
+
this.unparsedVttFrags = [];
|
|
308
308
|
this.initPTS = [];
|
|
309
309
|
if (this.cea608Parser1 && this.cea608Parser2) {
|
|
310
310
|
this.cea608Parser1.reset();
|
|
@@ -477,24 +477,9 @@ export class TimelineController implements ComponentAPI {
|
|
|
477
477
|
data: FragDecryptedData | FragLoadedData
|
|
478
478
|
) {
|
|
479
479
|
const { frag, payload } = data;
|
|
480
|
-
const { initPTS, unparsedVttFrags } = this;
|
|
481
480
|
if (frag.type === PlaylistLevelType.SUBTITLE) {
|
|
482
481
|
// If fragment is subtitle type, parse as WebVTT.
|
|
483
482
|
if (payload.byteLength) {
|
|
484
|
-
// We need an initial synchronisation PTS. Store fragments as long as none has arrived.
|
|
485
|
-
if (!initPTS[frag.cc]) {
|
|
486
|
-
unparsedVttFrags.push(data);
|
|
487
|
-
if (initPTS.length) {
|
|
488
|
-
// finish unsuccessfully, otherwise the subtitle-stream-controller could be blocked from loading new frags.
|
|
489
|
-
this.hls.trigger(Events.SUBTITLE_FRAG_PROCESSED, {
|
|
490
|
-
success: false,
|
|
491
|
-
frag,
|
|
492
|
-
error: new Error('Missing initial subtitle PTS'),
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
return;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
483
|
const decryptData = frag.decryptdata;
|
|
499
484
|
// fragment after decryption has a stats object
|
|
500
485
|
const decrypted = 'stats' in data;
|
|
@@ -516,7 +501,7 @@ export class TimelineController implements ComponentAPI {
|
|
|
516
501
|
) {
|
|
517
502
|
this._parseIMSC1(frag, payload);
|
|
518
503
|
} else {
|
|
519
|
-
this._parseVTTs(
|
|
504
|
+
this._parseVTTs(data);
|
|
520
505
|
}
|
|
521
506
|
}
|
|
522
507
|
} else {
|
|
@@ -553,7 +538,16 @@ export class TimelineController implements ComponentAPI {
|
|
|
553
538
|
);
|
|
554
539
|
}
|
|
555
540
|
|
|
556
|
-
private _parseVTTs(
|
|
541
|
+
private _parseVTTs(data: FragDecryptedData | FragLoadedData) {
|
|
542
|
+
const { frag, payload } = data;
|
|
543
|
+
// We need an initial synchronisation PTS. Store fragments as long as none has arrived
|
|
544
|
+
const { initPTS, unparsedVttFrags } = this;
|
|
545
|
+
const maxAvCC = initPTS.length - 1;
|
|
546
|
+
if (!initPTS[frag.cc] && maxAvCC === -1) {
|
|
547
|
+
unparsedVttFrags.push(data);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
|
|
557
551
|
const hls = this.hls;
|
|
558
552
|
// Parse the WebVTT file contents.
|
|
559
553
|
const payloadWebVTT = frag.initSegment?.data
|
|
@@ -562,7 +556,7 @@ export class TimelineController implements ComponentAPI {
|
|
|
562
556
|
parseWebVTT(
|
|
563
557
|
payloadWebVTT,
|
|
564
558
|
this.initPTS[frag.cc],
|
|
565
|
-
vttCCs,
|
|
559
|
+
this.vttCCs,
|
|
566
560
|
frag.cc,
|
|
567
561
|
frag.start,
|
|
568
562
|
(cues) => {
|
|
@@ -573,9 +567,18 @@ export class TimelineController implements ComponentAPI {
|
|
|
573
567
|
});
|
|
574
568
|
},
|
|
575
569
|
(error) => {
|
|
576
|
-
|
|
570
|
+
const missingInitPTS =
|
|
571
|
+
error.message === 'Missing initPTS for VTT MPEGTS';
|
|
572
|
+
if (missingInitPTS) {
|
|
573
|
+
unparsedVttFrags.push(data);
|
|
574
|
+
} else {
|
|
575
|
+
this._fallbackToIMSC1(frag, payload);
|
|
576
|
+
}
|
|
577
577
|
// Something went wrong while parsing. Trigger event with success false.
|
|
578
578
|
logger.log(`Failed to parse VTT cue: ${error}`);
|
|
579
|
+
if (missingInitPTS && maxAvCC > frag.cc) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
579
582
|
hls.trigger(Events.SUBTITLE_FRAG_PROCESSED, {
|
|
580
583
|
success: false,
|
|
581
584
|
frag: frag,
|
|
@@ -631,10 +634,6 @@ export class TimelineController implements ComponentAPI {
|
|
|
631
634
|
) {
|
|
632
635
|
const { frag } = data;
|
|
633
636
|
if (frag.type === PlaylistLevelType.SUBTITLE) {
|
|
634
|
-
if (!this.initPTS[frag.cc]) {
|
|
635
|
-
this.unparsedVttFrags.push(data as unknown as FragLoadedData);
|
|
636
|
-
return;
|
|
637
|
-
}
|
|
638
637
|
this.onFragLoaded(Events.FRAG_LOADED, data as unknown as FragLoadedData);
|
|
639
638
|
}
|
|
640
639
|
}
|
|
@@ -92,7 +92,7 @@ const calculateOffset = function (vttCCs: VTTCCs, cc, presentationTime) {
|
|
|
92
92
|
|
|
93
93
|
export function parseWebVTT(
|
|
94
94
|
vttByteArray: ArrayBuffer,
|
|
95
|
-
initPTS: RationalTimestamp,
|
|
95
|
+
initPTS: RationalTimestamp | undefined,
|
|
96
96
|
vttCCs: VTTCCs,
|
|
97
97
|
cc: number,
|
|
98
98
|
timeOffset: number,
|
|
@@ -107,10 +107,9 @@ export function parseWebVTT(
|
|
|
107
107
|
.replace(LINEBREAKS, '\n')
|
|
108
108
|
.split('\n');
|
|
109
109
|
const cues: VTTCue[] = [];
|
|
110
|
-
const init90kHz =
|
|
111
|
-
initPTS.baseTime,
|
|
112
|
-
|
|
113
|
-
);
|
|
110
|
+
const init90kHz = initPTS
|
|
111
|
+
? toMpegTsClockFromTimescale(initPTS.baseTime, initPTS.timescale)
|
|
112
|
+
: 0;
|
|
114
113
|
let cueTime = '00:00.000';
|
|
115
114
|
let timestampMapMPEGTS = 0;
|
|
116
115
|
let timestampMapLOCAL = 0;
|
|
@@ -134,8 +133,11 @@ export function parseWebVTT(
|
|
|
134
133
|
calculateOffset(vttCCs, cc, webVttMpegTsMapOffset);
|
|
135
134
|
}
|
|
136
135
|
}
|
|
137
|
-
|
|
138
136
|
if (webVttMpegTsMapOffset) {
|
|
137
|
+
if (!initPTS) {
|
|
138
|
+
parsingError = new Error('Missing initPTS for VTT MPEGTS');
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
139
141
|
// If we have MPEGTS, offset = presentation time + discontinuity offset
|
|
140
142
|
cueOffset = webVttMpegTsMapOffset - vttCCs.presentationOffset;
|
|
141
143
|
}
|