hls.js 1.5.14-0.canary.10559 → 1.5.15
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 +2911 -4558
- package/dist/hls.js.d.ts +112 -186
- package/dist/hls.js.map +1 -1
- package/dist/hls.light.js +2291 -3311
- 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 +1813 -2835
- 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 +4707 -6356
- 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 +42 -42
- package/src/config.ts +2 -5
- package/src/controller/abr-controller.ts +25 -39
- package/src/controller/audio-stream-controller.ts +136 -156
- 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 +107 -263
- 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 +5 -5
- package/src/demux/audio/ac3-demuxer.ts +4 -5
- package/src/demux/audio/adts.ts +4 -9
- package/src/demux/audio/base-audio-demuxer.ts +15 -21
- 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/inject-worker.ts +4 -38
- package/src/demux/mp4demuxer.ts +8 -17
- package/src/demux/sample-aes.ts +0 -2
- package/src/demux/transmuxer-interface.ts +83 -106
- package/src/demux/transmuxer-worker.ts +77 -111
- package/src/demux/transmuxer.ts +22 -46
- package/src/demux/tsdemuxer.ts +65 -131
- package/src/demux/video/avc-video-parser.ts +156 -219
- package/src/demux/video/base-video-parser.ts +9 -133
- package/src/demux/video/exp-golomb.ts +208 -0
- package/src/errors.ts +0 -2
- package/src/events.ts +1 -8
- package/src/exports-named.ts +1 -1
- package/src/hls.ts +48 -97
- 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 +84 -55
- package/src/remux/passthrough-remuxer.ts +8 -23
- package/src/task-loop.ts +2 -5
- package/src/types/component-api.ts +1 -3
- package/src/types/demuxer.ts +1 -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/discontinuities.ts +47 -21
- 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/dist/hls.d.mts +0 -3179
- package/dist/hls.d.ts +0 -3179
- package/src/crypt/decrypter-aes-mode.ts +0 -4
- package/src/demux/video/hevc-video-parser.ts +0 -718
- 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/version.ts +0 -1
@@ -1,718 +0,0 @@
|
|
1
|
-
import BaseVideoParser from './base-video-parser';
|
2
|
-
import type {
|
3
|
-
DemuxedVideoTrack,
|
4
|
-
DemuxedUserdataTrack,
|
5
|
-
} from '../../types/demuxer';
|
6
|
-
import { parseSEIMessageFromNALu } from '../../utils/mp4-tools';
|
7
|
-
|
8
|
-
import type { PES } from '../tsdemuxer';
|
9
|
-
|
10
|
-
import ExpGolomb from './exp-golomb';
|
11
|
-
|
12
|
-
class HevcVideoParser extends BaseVideoParser {
|
13
|
-
protected initVPS: Uint8Array | null = null;
|
14
|
-
|
15
|
-
public parsePES(
|
16
|
-
track: DemuxedVideoTrack,
|
17
|
-
textTrack: DemuxedUserdataTrack,
|
18
|
-
pes: PES,
|
19
|
-
endOfSegment: boolean,
|
20
|
-
) {
|
21
|
-
const units = this.parseNALu(track, pes.data, endOfSegment);
|
22
|
-
let VideoSample = this.VideoSample;
|
23
|
-
let push: boolean;
|
24
|
-
let spsfound = false;
|
25
|
-
// free pes.data to save up some memory
|
26
|
-
(pes as any).data = null;
|
27
|
-
|
28
|
-
// if new NAL units found and last sample still there, let's push ...
|
29
|
-
// this helps parsing streams with missing AUD (only do this if AUD never found)
|
30
|
-
if (VideoSample && units.length && !track.audFound) {
|
31
|
-
this.pushAccessUnit(VideoSample, track);
|
32
|
-
VideoSample = this.VideoSample = this.createVideoSample(
|
33
|
-
false,
|
34
|
-
pes.pts,
|
35
|
-
pes.dts,
|
36
|
-
);
|
37
|
-
}
|
38
|
-
|
39
|
-
units.forEach((unit) => {
|
40
|
-
switch (unit.type) {
|
41
|
-
// NON-IDR, NON RANDOM ACCESS SLICE
|
42
|
-
case 0:
|
43
|
-
case 1:
|
44
|
-
case 2:
|
45
|
-
case 3:
|
46
|
-
case 4:
|
47
|
-
case 5:
|
48
|
-
case 6:
|
49
|
-
case 7:
|
50
|
-
case 8:
|
51
|
-
case 9:
|
52
|
-
if (!VideoSample) {
|
53
|
-
VideoSample = this.VideoSample = this.createVideoSample(
|
54
|
-
false,
|
55
|
-
pes.pts,
|
56
|
-
pes.dts,
|
57
|
-
);
|
58
|
-
}
|
59
|
-
VideoSample.frame = true;
|
60
|
-
push = true;
|
61
|
-
break;
|
62
|
-
|
63
|
-
// CRA, BLA (random access picture)
|
64
|
-
case 16:
|
65
|
-
case 17:
|
66
|
-
case 18:
|
67
|
-
case 21:
|
68
|
-
push = true;
|
69
|
-
if (spsfound) {
|
70
|
-
// handle PES not starting with AUD
|
71
|
-
// if we have frame data already, that cannot belong to the same frame, so force a push
|
72
|
-
if (VideoSample?.frame && !VideoSample.key) {
|
73
|
-
this.pushAccessUnit(VideoSample, track);
|
74
|
-
VideoSample = this.VideoSample = null;
|
75
|
-
}
|
76
|
-
}
|
77
|
-
if (!VideoSample) {
|
78
|
-
VideoSample = this.VideoSample = this.createVideoSample(
|
79
|
-
true,
|
80
|
-
pes.pts,
|
81
|
-
pes.dts,
|
82
|
-
);
|
83
|
-
}
|
84
|
-
|
85
|
-
VideoSample.key = true;
|
86
|
-
VideoSample.frame = true;
|
87
|
-
break;
|
88
|
-
|
89
|
-
// IDR
|
90
|
-
case 19:
|
91
|
-
case 20:
|
92
|
-
push = true;
|
93
|
-
// handle PES not starting with AUD
|
94
|
-
// if we have frame data already, that cannot belong to the same frame, so force a push
|
95
|
-
if (VideoSample?.frame && !VideoSample.key) {
|
96
|
-
this.pushAccessUnit(VideoSample, track);
|
97
|
-
VideoSample = this.VideoSample = null;
|
98
|
-
}
|
99
|
-
if (!VideoSample) {
|
100
|
-
VideoSample = this.VideoSample = this.createVideoSample(
|
101
|
-
true,
|
102
|
-
pes.pts,
|
103
|
-
pes.dts,
|
104
|
-
);
|
105
|
-
}
|
106
|
-
|
107
|
-
VideoSample.key = true;
|
108
|
-
VideoSample.frame = true;
|
109
|
-
break;
|
110
|
-
|
111
|
-
// SEI
|
112
|
-
case 39:
|
113
|
-
push = true;
|
114
|
-
parseSEIMessageFromNALu(
|
115
|
-
unit.data,
|
116
|
-
2, // NALu header size
|
117
|
-
pes.pts as number,
|
118
|
-
textTrack.samples,
|
119
|
-
);
|
120
|
-
break;
|
121
|
-
|
122
|
-
// VPS
|
123
|
-
case 32:
|
124
|
-
push = true;
|
125
|
-
if (!track.vps) {
|
126
|
-
const config = this.readVPS(unit.data);
|
127
|
-
track.params = { ...config };
|
128
|
-
this.initVPS = unit.data;
|
129
|
-
}
|
130
|
-
track.vps = [unit.data];
|
131
|
-
break;
|
132
|
-
|
133
|
-
// SPS
|
134
|
-
case 33:
|
135
|
-
push = true;
|
136
|
-
spsfound = true;
|
137
|
-
if (typeof track.params === 'object') {
|
138
|
-
if (
|
139
|
-
track.vps !== undefined &&
|
140
|
-
track.vps[0] !== this.initVPS &&
|
141
|
-
track.sps !== undefined &&
|
142
|
-
!this.matchSPS(track.sps[0], unit.data)
|
143
|
-
) {
|
144
|
-
this.initVPS = track.vps[0];
|
145
|
-
track.sps = track.pps = undefined;
|
146
|
-
}
|
147
|
-
if (!track.sps) {
|
148
|
-
const config = this.readSPS(unit.data);
|
149
|
-
track.width = config.width;
|
150
|
-
track.height = config.height;
|
151
|
-
track.pixelRatio = config.pixelRatio;
|
152
|
-
track.codec = config.codecString;
|
153
|
-
track.sps = [];
|
154
|
-
for (const prop in config.params) {
|
155
|
-
track.params[prop] = config.params[prop];
|
156
|
-
}
|
157
|
-
}
|
158
|
-
if (track.vps !== undefined && track.vps[0] === this.initVPS) {
|
159
|
-
track.sps.push(unit.data);
|
160
|
-
}
|
161
|
-
}
|
162
|
-
if (!VideoSample) {
|
163
|
-
VideoSample = this.VideoSample = this.createVideoSample(
|
164
|
-
true,
|
165
|
-
pes.pts,
|
166
|
-
pes.dts,
|
167
|
-
);
|
168
|
-
}
|
169
|
-
VideoSample.key = true;
|
170
|
-
break;
|
171
|
-
|
172
|
-
// PPS
|
173
|
-
case 34:
|
174
|
-
push = true;
|
175
|
-
if (typeof track.params === 'object') {
|
176
|
-
if (!track.pps) {
|
177
|
-
track.pps = [];
|
178
|
-
const config = this.readPPS(unit.data);
|
179
|
-
for (const prop in config) {
|
180
|
-
track.params[prop] = config[prop];
|
181
|
-
}
|
182
|
-
}
|
183
|
-
if (this.initVPS !== null || track.pps.length === 0) {
|
184
|
-
track.pps.push(unit.data);
|
185
|
-
}
|
186
|
-
}
|
187
|
-
break;
|
188
|
-
|
189
|
-
// ACCESS UNIT DELIMITER
|
190
|
-
case 35:
|
191
|
-
push = true;
|
192
|
-
track.audFound = true;
|
193
|
-
if (VideoSample?.frame) {
|
194
|
-
this.pushAccessUnit(VideoSample, track);
|
195
|
-
VideoSample = null;
|
196
|
-
}
|
197
|
-
if (!VideoSample) {
|
198
|
-
VideoSample = this.VideoSample = this.createVideoSample(
|
199
|
-
false,
|
200
|
-
pes.pts,
|
201
|
-
pes.dts,
|
202
|
-
);
|
203
|
-
}
|
204
|
-
break;
|
205
|
-
|
206
|
-
default:
|
207
|
-
push = false;
|
208
|
-
break;
|
209
|
-
}
|
210
|
-
if (VideoSample && push) {
|
211
|
-
const units = VideoSample.units;
|
212
|
-
units.push(unit);
|
213
|
-
}
|
214
|
-
});
|
215
|
-
// if last PES packet, push samples
|
216
|
-
if (endOfSegment && VideoSample) {
|
217
|
-
this.pushAccessUnit(VideoSample, track);
|
218
|
-
this.VideoSample = null;
|
219
|
-
}
|
220
|
-
}
|
221
|
-
|
222
|
-
protected getNALuType(data: Uint8Array, offset: number): number {
|
223
|
-
return (data[offset] & 0x7e) >>> 1;
|
224
|
-
}
|
225
|
-
|
226
|
-
protected ebsp2rbsp(arr: Uint8Array): Uint8Array {
|
227
|
-
const dst = new Uint8Array(arr.byteLength);
|
228
|
-
let dstIdx = 0;
|
229
|
-
for (let i = 0; i < arr.byteLength; i++) {
|
230
|
-
if (i >= 2) {
|
231
|
-
// Unescape: Skip 0x03 after 00 00
|
232
|
-
if (arr[i] === 0x03 && arr[i - 1] === 0x00 && arr[i - 2] === 0x00) {
|
233
|
-
continue;
|
234
|
-
}
|
235
|
-
}
|
236
|
-
dst[dstIdx] = arr[i];
|
237
|
-
dstIdx++;
|
238
|
-
}
|
239
|
-
return new Uint8Array(dst.buffer, 0, dstIdx);
|
240
|
-
}
|
241
|
-
|
242
|
-
readVPS(vps: Uint8Array): {
|
243
|
-
numTemporalLayers: number;
|
244
|
-
temporalIdNested: boolean;
|
245
|
-
} {
|
246
|
-
const eg = new ExpGolomb(vps);
|
247
|
-
// remove header
|
248
|
-
eg.readUByte();
|
249
|
-
eg.readUByte();
|
250
|
-
|
251
|
-
eg.readBits(4); // video_parameter_set_id
|
252
|
-
eg.skipBits(2);
|
253
|
-
eg.readBits(6); // max_layers_minus1
|
254
|
-
const max_sub_layers_minus1 = eg.readBits(3);
|
255
|
-
const temporal_id_nesting_flag = eg.readBoolean();
|
256
|
-
// ...vui fps can be here, but empty fps value is not critical for metadata
|
257
|
-
|
258
|
-
return {
|
259
|
-
numTemporalLayers: max_sub_layers_minus1 + 1,
|
260
|
-
temporalIdNested: temporal_id_nesting_flag,
|
261
|
-
};
|
262
|
-
}
|
263
|
-
|
264
|
-
readSPS(sps: Uint8Array): {
|
265
|
-
codecString: string;
|
266
|
-
params: object;
|
267
|
-
width: number;
|
268
|
-
height: number;
|
269
|
-
pixelRatio: [number, number];
|
270
|
-
} {
|
271
|
-
const eg = new ExpGolomb(this.ebsp2rbsp(sps));
|
272
|
-
eg.readUByte();
|
273
|
-
eg.readUByte();
|
274
|
-
|
275
|
-
eg.readBits(4); //video_parameter_set_id
|
276
|
-
const max_sub_layers_minus1 = eg.readBits(3);
|
277
|
-
eg.readBoolean(); // temporal_id_nesting_flag
|
278
|
-
|
279
|
-
// profile_tier_level
|
280
|
-
const general_profile_space = eg.readBits(2);
|
281
|
-
const general_tier_flag = eg.readBoolean();
|
282
|
-
const general_profile_idc = eg.readBits(5);
|
283
|
-
const general_profile_compatibility_flags_1 = eg.readUByte();
|
284
|
-
const general_profile_compatibility_flags_2 = eg.readUByte();
|
285
|
-
const general_profile_compatibility_flags_3 = eg.readUByte();
|
286
|
-
const general_profile_compatibility_flags_4 = eg.readUByte();
|
287
|
-
const general_constraint_indicator_flags_1 = eg.readUByte();
|
288
|
-
const general_constraint_indicator_flags_2 = eg.readUByte();
|
289
|
-
const general_constraint_indicator_flags_3 = eg.readUByte();
|
290
|
-
const general_constraint_indicator_flags_4 = eg.readUByte();
|
291
|
-
const general_constraint_indicator_flags_5 = eg.readUByte();
|
292
|
-
const general_constraint_indicator_flags_6 = eg.readUByte();
|
293
|
-
const general_level_idc = eg.readUByte();
|
294
|
-
const sub_layer_profile_present_flags: boolean[] = [];
|
295
|
-
const sub_layer_level_present_flags: boolean[] = [];
|
296
|
-
for (let i = 0; i < max_sub_layers_minus1; i++) {
|
297
|
-
sub_layer_profile_present_flags.push(eg.readBoolean());
|
298
|
-
sub_layer_level_present_flags.push(eg.readBoolean());
|
299
|
-
}
|
300
|
-
if (max_sub_layers_minus1 > 0) {
|
301
|
-
for (let i = max_sub_layers_minus1; i < 8; i++) {
|
302
|
-
eg.readBits(2);
|
303
|
-
}
|
304
|
-
}
|
305
|
-
for (let i = 0; i < max_sub_layers_minus1; i++) {
|
306
|
-
if (sub_layer_profile_present_flags[i]) {
|
307
|
-
eg.readUByte(); // sub_layer_profile_space, sub_layer_tier_flag, sub_layer_profile_idc
|
308
|
-
eg.readUByte();
|
309
|
-
eg.readUByte();
|
310
|
-
eg.readUByte();
|
311
|
-
eg.readUByte(); // sub_layer_profile_compatibility_flag
|
312
|
-
eg.readUByte();
|
313
|
-
eg.readUByte();
|
314
|
-
eg.readUByte();
|
315
|
-
eg.readUByte();
|
316
|
-
eg.readUByte();
|
317
|
-
eg.readUByte();
|
318
|
-
}
|
319
|
-
if (sub_layer_level_present_flags[i]) {
|
320
|
-
eg.readUByte();
|
321
|
-
}
|
322
|
-
}
|
323
|
-
|
324
|
-
eg.readUEG(); // seq_parameter_set_id
|
325
|
-
const chroma_format_idc = eg.readUEG();
|
326
|
-
if (chroma_format_idc == 3) {
|
327
|
-
eg.skipBits(1); //separate_colour_plane_flag
|
328
|
-
}
|
329
|
-
const pic_width_in_luma_samples = eg.readUEG();
|
330
|
-
const pic_height_in_luma_samples = eg.readUEG();
|
331
|
-
const conformance_window_flag = eg.readBoolean();
|
332
|
-
let pic_left_offset = 0,
|
333
|
-
pic_right_offset = 0,
|
334
|
-
pic_top_offset = 0,
|
335
|
-
pic_bottom_offset = 0;
|
336
|
-
if (conformance_window_flag) {
|
337
|
-
pic_left_offset += eg.readUEG();
|
338
|
-
pic_right_offset += eg.readUEG();
|
339
|
-
pic_top_offset += eg.readUEG();
|
340
|
-
pic_bottom_offset += eg.readUEG();
|
341
|
-
}
|
342
|
-
const bit_depth_luma_minus8 = eg.readUEG();
|
343
|
-
const bit_depth_chroma_minus8 = eg.readUEG();
|
344
|
-
const log2_max_pic_order_cnt_lsb_minus4 = eg.readUEG();
|
345
|
-
const sub_layer_ordering_info_present_flag = eg.readBoolean();
|
346
|
-
for (
|
347
|
-
let i = sub_layer_ordering_info_present_flag ? 0 : max_sub_layers_minus1;
|
348
|
-
i <= max_sub_layers_minus1;
|
349
|
-
i++
|
350
|
-
) {
|
351
|
-
eg.skipUEG(); // max_dec_pic_buffering_minus1[i]
|
352
|
-
eg.skipUEG(); // max_num_reorder_pics[i]
|
353
|
-
eg.skipUEG(); // max_latency_increase_plus1[i]
|
354
|
-
}
|
355
|
-
eg.skipUEG(); // log2_min_luma_coding_block_size_minus3
|
356
|
-
eg.skipUEG(); // log2_diff_max_min_luma_coding_block_size
|
357
|
-
eg.skipUEG(); // log2_min_transform_block_size_minus2
|
358
|
-
eg.skipUEG(); // log2_diff_max_min_transform_block_size
|
359
|
-
eg.skipUEG(); // max_transform_hierarchy_depth_inter
|
360
|
-
eg.skipUEG(); // max_transform_hierarchy_depth_intra
|
361
|
-
const scaling_list_enabled_flag = eg.readBoolean();
|
362
|
-
if (scaling_list_enabled_flag) {
|
363
|
-
const sps_scaling_list_data_present_flag = eg.readBoolean();
|
364
|
-
if (sps_scaling_list_data_present_flag) {
|
365
|
-
for (let sizeId = 0; sizeId < 4; sizeId++) {
|
366
|
-
for (
|
367
|
-
let matrixId = 0;
|
368
|
-
matrixId < (sizeId === 3 ? 2 : 6);
|
369
|
-
matrixId++
|
370
|
-
) {
|
371
|
-
const scaling_list_pred_mode_flag = eg.readBoolean();
|
372
|
-
if (!scaling_list_pred_mode_flag) {
|
373
|
-
eg.readUEG(); // scaling_list_pred_matrix_id_delta
|
374
|
-
} else {
|
375
|
-
const coefNum = Math.min(64, 1 << (4 + (sizeId << 1)));
|
376
|
-
if (sizeId > 1) {
|
377
|
-
eg.readEG();
|
378
|
-
}
|
379
|
-
for (let i = 0; i < coefNum; i++) {
|
380
|
-
eg.readEG();
|
381
|
-
}
|
382
|
-
}
|
383
|
-
}
|
384
|
-
}
|
385
|
-
}
|
386
|
-
}
|
387
|
-
|
388
|
-
eg.readBoolean(); // amp_enabled_flag
|
389
|
-
eg.readBoolean(); // sample_adaptive_offset_enabled_flag
|
390
|
-
const pcm_enabled_flag = eg.readBoolean();
|
391
|
-
if (pcm_enabled_flag) {
|
392
|
-
eg.readUByte();
|
393
|
-
eg.skipUEG();
|
394
|
-
eg.skipUEG();
|
395
|
-
eg.readBoolean();
|
396
|
-
}
|
397
|
-
const num_short_term_ref_pic_sets = eg.readUEG();
|
398
|
-
let num_delta_pocs = 0;
|
399
|
-
for (let i = 0; i < num_short_term_ref_pic_sets; i++) {
|
400
|
-
let inter_ref_pic_set_prediction_flag = false;
|
401
|
-
if (i !== 0) {
|
402
|
-
inter_ref_pic_set_prediction_flag = eg.readBoolean();
|
403
|
-
}
|
404
|
-
if (inter_ref_pic_set_prediction_flag) {
|
405
|
-
if (i === num_short_term_ref_pic_sets) {
|
406
|
-
eg.readUEG();
|
407
|
-
}
|
408
|
-
eg.readBoolean();
|
409
|
-
eg.readUEG();
|
410
|
-
let next_num_delta_pocs = 0;
|
411
|
-
for (let j = 0; j <= num_delta_pocs; j++) {
|
412
|
-
const used_by_curr_pic_flag = eg.readBoolean();
|
413
|
-
let use_delta_flag = false;
|
414
|
-
if (!used_by_curr_pic_flag) {
|
415
|
-
use_delta_flag = eg.readBoolean();
|
416
|
-
}
|
417
|
-
if (used_by_curr_pic_flag || use_delta_flag) {
|
418
|
-
next_num_delta_pocs++;
|
419
|
-
}
|
420
|
-
}
|
421
|
-
num_delta_pocs = next_num_delta_pocs;
|
422
|
-
} else {
|
423
|
-
const num_negative_pics = eg.readUEG();
|
424
|
-
const num_positive_pics = eg.readUEG();
|
425
|
-
num_delta_pocs = num_negative_pics + num_positive_pics;
|
426
|
-
for (let j = 0; j < num_negative_pics; j++) {
|
427
|
-
eg.readUEG();
|
428
|
-
eg.readBoolean();
|
429
|
-
}
|
430
|
-
for (let j = 0; j < num_positive_pics; j++) {
|
431
|
-
eg.readUEG();
|
432
|
-
eg.readBoolean();
|
433
|
-
}
|
434
|
-
}
|
435
|
-
}
|
436
|
-
|
437
|
-
const long_term_ref_pics_present_flag = eg.readBoolean();
|
438
|
-
if (long_term_ref_pics_present_flag) {
|
439
|
-
const num_long_term_ref_pics_sps = eg.readUEG();
|
440
|
-
for (let i = 0; i < num_long_term_ref_pics_sps; i++) {
|
441
|
-
for (let j = 0; j < log2_max_pic_order_cnt_lsb_minus4 + 4; j++) {
|
442
|
-
eg.readBits(1);
|
443
|
-
}
|
444
|
-
eg.readBits(1);
|
445
|
-
}
|
446
|
-
}
|
447
|
-
|
448
|
-
let min_spatial_segmentation_idc = 0;
|
449
|
-
let sar_width = 1,
|
450
|
-
sar_height = 1;
|
451
|
-
let fps_fixed = true,
|
452
|
-
fps_den = 1,
|
453
|
-
fps_num = 0;
|
454
|
-
eg.readBoolean(); // sps_temporal_mvp_enabled_flag
|
455
|
-
eg.readBoolean(); // strong_intra_smoothing_enabled_flag
|
456
|
-
let default_display_window_flag = false;
|
457
|
-
const vui_parameters_present_flag = eg.readBoolean();
|
458
|
-
if (vui_parameters_present_flag) {
|
459
|
-
const aspect_ratio_info_present_flag = eg.readBoolean();
|
460
|
-
if (aspect_ratio_info_present_flag) {
|
461
|
-
const aspect_ratio_idc = eg.readUByte();
|
462
|
-
const sar_width_table = [
|
463
|
-
1, 12, 10, 16, 40, 24, 20, 32, 80, 18, 15, 64, 160, 4, 3, 2,
|
464
|
-
];
|
465
|
-
const sar_height_table = [
|
466
|
-
1, 11, 11, 11, 33, 11, 11, 11, 33, 11, 11, 33, 99, 3, 2, 1,
|
467
|
-
];
|
468
|
-
if (aspect_ratio_idc > 0 && aspect_ratio_idc < 16) {
|
469
|
-
sar_width = sar_width_table[aspect_ratio_idc - 1];
|
470
|
-
sar_height = sar_height_table[aspect_ratio_idc - 1];
|
471
|
-
} else if (aspect_ratio_idc === 255) {
|
472
|
-
sar_width = eg.readBits(16);
|
473
|
-
sar_height = eg.readBits(16);
|
474
|
-
}
|
475
|
-
}
|
476
|
-
const overscan_info_present_flag = eg.readBoolean();
|
477
|
-
if (overscan_info_present_flag) {
|
478
|
-
eg.readBoolean();
|
479
|
-
}
|
480
|
-
const video_signal_type_present_flag = eg.readBoolean();
|
481
|
-
if (video_signal_type_present_flag) {
|
482
|
-
eg.readBits(3);
|
483
|
-
eg.readBoolean();
|
484
|
-
const colour_description_present_flag = eg.readBoolean();
|
485
|
-
if (colour_description_present_flag) {
|
486
|
-
eg.readUByte();
|
487
|
-
eg.readUByte();
|
488
|
-
eg.readUByte();
|
489
|
-
}
|
490
|
-
}
|
491
|
-
const chroma_loc_info_present_flag = eg.readBoolean();
|
492
|
-
if (chroma_loc_info_present_flag) {
|
493
|
-
eg.readUEG();
|
494
|
-
eg.readUEG();
|
495
|
-
}
|
496
|
-
eg.readBoolean(); // neutral_chroma_indication_flag
|
497
|
-
eg.readBoolean(); // field_seq_flag
|
498
|
-
eg.readBoolean(); // frame_field_info_present_flag
|
499
|
-
default_display_window_flag = eg.readBoolean();
|
500
|
-
if (default_display_window_flag) {
|
501
|
-
pic_left_offset += eg.readUEG();
|
502
|
-
pic_right_offset += eg.readUEG();
|
503
|
-
pic_top_offset += eg.readUEG();
|
504
|
-
pic_bottom_offset += eg.readUEG();
|
505
|
-
}
|
506
|
-
const vui_timing_info_present_flag = eg.readBoolean();
|
507
|
-
if (vui_timing_info_present_flag) {
|
508
|
-
fps_den = eg.readBits(32);
|
509
|
-
fps_num = eg.readBits(32);
|
510
|
-
const vui_poc_proportional_to_timing_flag = eg.readBoolean();
|
511
|
-
if (vui_poc_proportional_to_timing_flag) {
|
512
|
-
eg.readUEG();
|
513
|
-
}
|
514
|
-
const vui_hrd_parameters_present_flag = eg.readBoolean();
|
515
|
-
if (vui_hrd_parameters_present_flag) {
|
516
|
-
//const commonInfPresentFlag = true;
|
517
|
-
//if (commonInfPresentFlag) {
|
518
|
-
const nal_hrd_parameters_present_flag = eg.readBoolean();
|
519
|
-
const vcl_hrd_parameters_present_flag = eg.readBoolean();
|
520
|
-
let sub_pic_hrd_params_present_flag = false;
|
521
|
-
if (
|
522
|
-
nal_hrd_parameters_present_flag ||
|
523
|
-
vcl_hrd_parameters_present_flag
|
524
|
-
) {
|
525
|
-
sub_pic_hrd_params_present_flag = eg.readBoolean();
|
526
|
-
if (sub_pic_hrd_params_present_flag) {
|
527
|
-
eg.readUByte();
|
528
|
-
eg.readBits(5);
|
529
|
-
eg.readBoolean();
|
530
|
-
eg.readBits(5);
|
531
|
-
}
|
532
|
-
eg.readBits(4); // bit_rate_scale
|
533
|
-
eg.readBits(4); // cpb_size_scale
|
534
|
-
if (sub_pic_hrd_params_present_flag) {
|
535
|
-
eg.readBits(4);
|
536
|
-
}
|
537
|
-
eg.readBits(5);
|
538
|
-
eg.readBits(5);
|
539
|
-
eg.readBits(5);
|
540
|
-
}
|
541
|
-
//}
|
542
|
-
for (let i = 0; i <= max_sub_layers_minus1; i++) {
|
543
|
-
fps_fixed = eg.readBoolean(); // fixed_pic_rate_general_flag
|
544
|
-
const fixed_pic_rate_within_cvs_flag =
|
545
|
-
fps_fixed || eg.readBoolean();
|
546
|
-
let low_delay_hrd_flag = false;
|
547
|
-
if (fixed_pic_rate_within_cvs_flag) {
|
548
|
-
eg.readEG();
|
549
|
-
} else {
|
550
|
-
low_delay_hrd_flag = eg.readBoolean();
|
551
|
-
}
|
552
|
-
const cpb_cnt = low_delay_hrd_flag ? 1 : eg.readUEG() + 1;
|
553
|
-
if (nal_hrd_parameters_present_flag) {
|
554
|
-
for (let j = 0; j < cpb_cnt; j++) {
|
555
|
-
eg.readUEG();
|
556
|
-
eg.readUEG();
|
557
|
-
if (sub_pic_hrd_params_present_flag) {
|
558
|
-
eg.readUEG();
|
559
|
-
eg.readUEG();
|
560
|
-
}
|
561
|
-
eg.skipBits(1);
|
562
|
-
}
|
563
|
-
}
|
564
|
-
if (vcl_hrd_parameters_present_flag) {
|
565
|
-
for (let j = 0; j < cpb_cnt; j++) {
|
566
|
-
eg.readUEG();
|
567
|
-
eg.readUEG();
|
568
|
-
if (sub_pic_hrd_params_present_flag) {
|
569
|
-
eg.readUEG();
|
570
|
-
eg.readUEG();
|
571
|
-
}
|
572
|
-
eg.skipBits(1);
|
573
|
-
}
|
574
|
-
}
|
575
|
-
}
|
576
|
-
}
|
577
|
-
}
|
578
|
-
const bitstream_restriction_flag = eg.readBoolean();
|
579
|
-
if (bitstream_restriction_flag) {
|
580
|
-
eg.readBoolean(); // tiles_fixed_structure_flag
|
581
|
-
eg.readBoolean(); // motion_vectors_over_pic_boundaries_flag
|
582
|
-
eg.readBoolean(); // restricted_ref_pic_lists_flag
|
583
|
-
min_spatial_segmentation_idc = eg.readUEG();
|
584
|
-
}
|
585
|
-
}
|
586
|
-
|
587
|
-
let width = pic_width_in_luma_samples,
|
588
|
-
height = pic_height_in_luma_samples;
|
589
|
-
if (conformance_window_flag || default_display_window_flag) {
|
590
|
-
let chroma_scale_w = 1,
|
591
|
-
chroma_scale_h = 1;
|
592
|
-
if (chroma_format_idc === 1) {
|
593
|
-
// YUV 420
|
594
|
-
chroma_scale_w = chroma_scale_h = 2;
|
595
|
-
} else if (chroma_format_idc == 2) {
|
596
|
-
// YUV 422
|
597
|
-
chroma_scale_w = 2;
|
598
|
-
}
|
599
|
-
width =
|
600
|
-
pic_width_in_luma_samples -
|
601
|
-
chroma_scale_w * pic_right_offset -
|
602
|
-
chroma_scale_w * pic_left_offset;
|
603
|
-
height =
|
604
|
-
pic_height_in_luma_samples -
|
605
|
-
chroma_scale_h * pic_bottom_offset -
|
606
|
-
chroma_scale_h * pic_top_offset;
|
607
|
-
}
|
608
|
-
|
609
|
-
const profile_space_string = general_profile_space
|
610
|
-
? ['A', 'B', 'C'][general_profile_space]
|
611
|
-
: '';
|
612
|
-
const profile_compatibility_buf =
|
613
|
-
(general_profile_compatibility_flags_1 << 24) |
|
614
|
-
(general_profile_compatibility_flags_2 << 16) |
|
615
|
-
(general_profile_compatibility_flags_3 << 8) |
|
616
|
-
general_profile_compatibility_flags_4;
|
617
|
-
let profile_compatibility_rev = 0;
|
618
|
-
for (let i = 0; i < 32; i++) {
|
619
|
-
profile_compatibility_rev =
|
620
|
-
(profile_compatibility_rev |
|
621
|
-
(((profile_compatibility_buf >> i) & 1) << (31 - i))) >>>
|
622
|
-
0; // reverse bit position (and cast as UInt32)
|
623
|
-
}
|
624
|
-
let profile_compatibility_flags_string =
|
625
|
-
profile_compatibility_rev.toString(16);
|
626
|
-
if (
|
627
|
-
general_profile_idc === 1 &&
|
628
|
-
profile_compatibility_flags_string === '2'
|
629
|
-
) {
|
630
|
-
profile_compatibility_flags_string = '6';
|
631
|
-
}
|
632
|
-
const tier_flag_string = general_tier_flag ? 'H' : 'L';
|
633
|
-
|
634
|
-
return {
|
635
|
-
codecString: `hvc1.${profile_space_string}${general_profile_idc}.${profile_compatibility_flags_string}.${tier_flag_string}${general_level_idc}.B0`,
|
636
|
-
params: {
|
637
|
-
general_tier_flag,
|
638
|
-
general_profile_idc,
|
639
|
-
general_profile_space,
|
640
|
-
general_profile_compatibility_flags: [
|
641
|
-
general_profile_compatibility_flags_1,
|
642
|
-
general_profile_compatibility_flags_2,
|
643
|
-
general_profile_compatibility_flags_3,
|
644
|
-
general_profile_compatibility_flags_4,
|
645
|
-
],
|
646
|
-
general_constraint_indicator_flags: [
|
647
|
-
general_constraint_indicator_flags_1,
|
648
|
-
general_constraint_indicator_flags_2,
|
649
|
-
general_constraint_indicator_flags_3,
|
650
|
-
general_constraint_indicator_flags_4,
|
651
|
-
general_constraint_indicator_flags_5,
|
652
|
-
general_constraint_indicator_flags_6,
|
653
|
-
],
|
654
|
-
general_level_idc,
|
655
|
-
bit_depth: bit_depth_luma_minus8 + 8,
|
656
|
-
bit_depth_luma_minus8,
|
657
|
-
bit_depth_chroma_minus8,
|
658
|
-
min_spatial_segmentation_idc,
|
659
|
-
chroma_format_idc: chroma_format_idc,
|
660
|
-
frame_rate: {
|
661
|
-
fixed: fps_fixed,
|
662
|
-
fps: fps_num / fps_den,
|
663
|
-
},
|
664
|
-
},
|
665
|
-
width,
|
666
|
-
height,
|
667
|
-
pixelRatio: [sar_width, sar_height],
|
668
|
-
};
|
669
|
-
}
|
670
|
-
|
671
|
-
readPPS(pps: Uint8Array): {
|
672
|
-
parallelismType: number;
|
673
|
-
} {
|
674
|
-
const eg = new ExpGolomb(this.ebsp2rbsp(pps));
|
675
|
-
eg.readUByte();
|
676
|
-
eg.readUByte();
|
677
|
-
eg.skipUEG(); // pic_parameter_set_id
|
678
|
-
eg.skipUEG(); // seq_parameter_set_id
|
679
|
-
eg.skipBits(2); // dependent_slice_segments_enabled_flag, output_flag_present_flag
|
680
|
-
eg.skipBits(3); // num_extra_slice_header_bits
|
681
|
-
eg.skipBits(2); // sign_data_hiding_enabled_flag, cabac_init_present_flag
|
682
|
-
eg.skipUEG();
|
683
|
-
eg.skipUEG();
|
684
|
-
eg.skipEG(); // init_qp_minus26
|
685
|
-
eg.skipBits(2); // constrained_intra_pred_flag, transform_skip_enabled_flag
|
686
|
-
const cu_qp_delta_enabled_flag = eg.readBoolean();
|
687
|
-
if (cu_qp_delta_enabled_flag) {
|
688
|
-
eg.skipUEG();
|
689
|
-
}
|
690
|
-
eg.skipEG(); // cb_qp_offset
|
691
|
-
eg.skipEG(); // cr_qp_offset
|
692
|
-
eg.skipBits(4); // pps_slice_chroma_qp_offsets_present_flag, weighted_pred_flag, weighted_bipred_flag, transquant_bypass_enabled_flag
|
693
|
-
const tiles_enabled_flag = eg.readBoolean();
|
694
|
-
const entropy_coding_sync_enabled_flag = eg.readBoolean();
|
695
|
-
let parallelismType = 1; // slice-based parallel decoding
|
696
|
-
if (entropy_coding_sync_enabled_flag && tiles_enabled_flag) {
|
697
|
-
parallelismType = 0; // mixed-type parallel decoding
|
698
|
-
} else if (entropy_coding_sync_enabled_flag) {
|
699
|
-
parallelismType = 3; // wavefront-based parallel decoding
|
700
|
-
} else if (tiles_enabled_flag) {
|
701
|
-
parallelismType = 2; // tile-based parallel decoding
|
702
|
-
}
|
703
|
-
|
704
|
-
return {
|
705
|
-
parallelismType,
|
706
|
-
};
|
707
|
-
}
|
708
|
-
|
709
|
-
matchSPS(sps1: Uint8Array, sps2: Uint8Array): boolean {
|
710
|
-
// compare without headers and VPS related params
|
711
|
-
return (
|
712
|
-
String.fromCharCode.apply(null, sps1).substr(3) ===
|
713
|
-
String.fromCharCode.apply(null, sps2).substr(3)
|
714
|
-
);
|
715
|
-
}
|
716
|
-
}
|
717
|
-
|
718
|
-
export default HevcVideoParser;
|