@yume-chan/media-codec 3.0.0-beta.0
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/LICENSE +21 -0
- package/README.md +3 -0
- package/esm/av1.d.ts +470 -0
- package/esm/av1.d.ts.map +1 -0
- package/esm/av1.js +666 -0
- package/esm/av1.js.map +1 -0
- package/esm/format.d.ts +4 -0
- package/esm/format.d.ts.map +1 -0
- package/esm/format.js +44 -0
- package/esm/format.js.map +1 -0
- package/esm/h264.d.ts +47 -0
- package/esm/h264.d.ts.map +1 -0
- package/esm/h264.js +240 -0
- package/esm/h264.js.map +1 -0
- package/esm/h265.d.ts +501 -0
- package/esm/h265.d.ts.map +1 -0
- package/esm/h265.js +1095 -0
- package/esm/h265.js.map +1 -0
- package/esm/index.d.ts +6 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +6 -0
- package/esm/index.js.map +1 -0
- package/esm/nalu.d.ts +28 -0
- package/esm/nalu.d.ts.map +1 -0
- package/esm/nalu.js +250 -0
- package/esm/nalu.js.map +1 -0
- package/package.json +43 -0
- package/src/av1.ts +782 -0
- package/src/format.ts +53 -0
- package/src/h264.ts +306 -0
- package/src/h265.ts +1393 -0
- package/src/index.ts +5 -0
- package/src/nalu.ts +304 -0
- package/tsconfig.build.json +3 -0
package/esm/av1.js
ADDED
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
// cspell: ignore uvlc
|
|
2
|
+
// cspell: ignore interintra
|
|
3
|
+
// cspell: ignore superres
|
|
4
|
+
// cspell: ignore cdef
|
|
5
|
+
// cspell: ignore bitdepth
|
|
6
|
+
// cspell: ignore Smpte
|
|
7
|
+
// cspell: ignore Chromat
|
|
8
|
+
import { decimalTwoDigits } from "./format.js";
|
|
9
|
+
export const AndroidAv1Profile = {
|
|
10
|
+
Main8: 1 << 0,
|
|
11
|
+
Main10: 1 << 1,
|
|
12
|
+
Main10Hdr10: 1 << 12,
|
|
13
|
+
Main10Hdr10Plus: 1 << 13,
|
|
14
|
+
};
|
|
15
|
+
export const AndroidAv1Level = {
|
|
16
|
+
Level2: 1 << 0,
|
|
17
|
+
Level21: 1 << 1,
|
|
18
|
+
Level22: 1 << 2,
|
|
19
|
+
Level23: 1 << 3,
|
|
20
|
+
Level3: 1 << 4,
|
|
21
|
+
Level31: 1 << 5,
|
|
22
|
+
Level32: 1 << 6,
|
|
23
|
+
Level33: 1 << 7,
|
|
24
|
+
Level4: 1 << 8,
|
|
25
|
+
Level41: 1 << 9,
|
|
26
|
+
Level42: 1 << 10,
|
|
27
|
+
Level43: 1 << 11,
|
|
28
|
+
Level5: 1 << 12,
|
|
29
|
+
Level51: 1 << 13,
|
|
30
|
+
Level52: 1 << 14,
|
|
31
|
+
Level53: 1 << 15,
|
|
32
|
+
Level6: 1 << 16,
|
|
33
|
+
Level61: 1 << 17,
|
|
34
|
+
Level62: 1 << 18,
|
|
35
|
+
Level63: 1 << 19,
|
|
36
|
+
Level7: 1 << 20,
|
|
37
|
+
Level71: 1 << 21,
|
|
38
|
+
Level72: 1 << 22,
|
|
39
|
+
Level73: 1 << 23,
|
|
40
|
+
};
|
|
41
|
+
class BitReader {
|
|
42
|
+
#data;
|
|
43
|
+
#byte;
|
|
44
|
+
#bytePosition = 0;
|
|
45
|
+
#bitPosition = 7;
|
|
46
|
+
get byteAligned() {
|
|
47
|
+
return this.#bitPosition === 7;
|
|
48
|
+
}
|
|
49
|
+
get ended() {
|
|
50
|
+
return this.#bytePosition >= this.#data.length;
|
|
51
|
+
}
|
|
52
|
+
constructor(data) {
|
|
53
|
+
this.#data = data;
|
|
54
|
+
this.#byte = data[0];
|
|
55
|
+
}
|
|
56
|
+
f1() {
|
|
57
|
+
const value = this.#byte >> this.#bitPosition;
|
|
58
|
+
this.#bitPosition -= 1;
|
|
59
|
+
if (this.#bitPosition < 0) {
|
|
60
|
+
this.#bytePosition += 1;
|
|
61
|
+
this.#bitPosition = 7;
|
|
62
|
+
this.#byte = this.#data[this.#bytePosition];
|
|
63
|
+
}
|
|
64
|
+
return value & 1;
|
|
65
|
+
}
|
|
66
|
+
f(n) {
|
|
67
|
+
let value = 0;
|
|
68
|
+
for (; n > 0; n -= 1) {
|
|
69
|
+
value <<= 1;
|
|
70
|
+
value |= this.f1();
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
skip(n) {
|
|
75
|
+
if (n <= this.#bitPosition + 1) {
|
|
76
|
+
this.#bytePosition += 1;
|
|
77
|
+
this.#bitPosition = 7;
|
|
78
|
+
this.#byte = this.#data[this.#bytePosition];
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
n -= this.#bitPosition + 1;
|
|
82
|
+
this.#bytePosition += 1;
|
|
83
|
+
const bytes = (n / 8) | 0;
|
|
84
|
+
if (bytes > 0) {
|
|
85
|
+
this.#bytePosition += bytes;
|
|
86
|
+
n -= bytes * 8;
|
|
87
|
+
}
|
|
88
|
+
this.#bitPosition = 7 - n;
|
|
89
|
+
this.#byte = this.#data[this.#bytePosition];
|
|
90
|
+
}
|
|
91
|
+
readBytes(n) {
|
|
92
|
+
if (!this.byteAligned) {
|
|
93
|
+
throw new Error("Bytes must be byte-aligned");
|
|
94
|
+
}
|
|
95
|
+
const value = this.#data.subarray(this.#bytePosition, this.#bytePosition + n);
|
|
96
|
+
this.#bytePosition += n;
|
|
97
|
+
this.#byte = this.#data[this.#bytePosition];
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
getPosition() {
|
|
101
|
+
return [this.#bytePosition, this.#bitPosition];
|
|
102
|
+
}
|
|
103
|
+
setPosition([bytePosition, bitPosition]) {
|
|
104
|
+
this.#bytePosition = bytePosition;
|
|
105
|
+
this.#bitPosition = bitPosition;
|
|
106
|
+
this.#byte = this.#data[bytePosition];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const ObuType = {
|
|
110
|
+
SequenceHeader: 1,
|
|
111
|
+
TemporalDelimiter: 2,
|
|
112
|
+
FrameHeader: 3,
|
|
113
|
+
TileGroup: 4,
|
|
114
|
+
Metadata: 5,
|
|
115
|
+
Frame: 6,
|
|
116
|
+
RedundantFrameHeader: 7,
|
|
117
|
+
TileList: 8,
|
|
118
|
+
Padding: 15,
|
|
119
|
+
};
|
|
120
|
+
const ColorPrimaries = {
|
|
121
|
+
Bt709: 1,
|
|
122
|
+
Unspecified: 2,
|
|
123
|
+
Bt470M: 4,
|
|
124
|
+
Bt470BG: 5,
|
|
125
|
+
Bt601: 6,
|
|
126
|
+
Smpte240: 7,
|
|
127
|
+
GenericFilm: 8,
|
|
128
|
+
Bt2020: 9,
|
|
129
|
+
Xyz: 10,
|
|
130
|
+
Smpte431: 11,
|
|
131
|
+
Smpte432: 12,
|
|
132
|
+
Ebu3213: 22,
|
|
133
|
+
};
|
|
134
|
+
const TransferCharacteristics = {
|
|
135
|
+
Bt709: 1,
|
|
136
|
+
Unspecified: 2,
|
|
137
|
+
Bt470M: 4,
|
|
138
|
+
Bt470BG: 5,
|
|
139
|
+
Bt601: 6,
|
|
140
|
+
Smpte240: 7,
|
|
141
|
+
Linear: 8,
|
|
142
|
+
Log100: 9,
|
|
143
|
+
Log100Sqrt10: 10,
|
|
144
|
+
Iec61966: 11,
|
|
145
|
+
Bt1361: 12,
|
|
146
|
+
Srgb: 13,
|
|
147
|
+
Bt2020Ten: 14,
|
|
148
|
+
Bt2020Twelve: 15,
|
|
149
|
+
Smpte2084: 16,
|
|
150
|
+
Smpte428: 17,
|
|
151
|
+
Hlg: 18,
|
|
152
|
+
};
|
|
153
|
+
const MatrixCoefficients = {
|
|
154
|
+
Identity: 0,
|
|
155
|
+
Bt709: 1,
|
|
156
|
+
Unspecified: 2,
|
|
157
|
+
Fcc: 4,
|
|
158
|
+
Bt470BG: 5,
|
|
159
|
+
Bt601: 6,
|
|
160
|
+
Smpte240: 7,
|
|
161
|
+
YCgCo: 8,
|
|
162
|
+
Bt2020Ncl: 9,
|
|
163
|
+
Bt2020Cl: 10,
|
|
164
|
+
Smpte2085: 11,
|
|
165
|
+
ChromatNcl: 12,
|
|
166
|
+
ChromatCl: 13,
|
|
167
|
+
ICtCp: 14,
|
|
168
|
+
};
|
|
169
|
+
export class Av1 extends BitReader {
|
|
170
|
+
static ObuType = ObuType;
|
|
171
|
+
static ColorPrimaries = ColorPrimaries;
|
|
172
|
+
static TransferCharacteristics = TransferCharacteristics;
|
|
173
|
+
static MatrixCoefficients = MatrixCoefficients;
|
|
174
|
+
/**
|
|
175
|
+
* Generate a codec string from an AV1 sequence header
|
|
176
|
+
* per Section 5 of AV1 Codec ISO Media File Format Binding
|
|
177
|
+
* https://aomediacodec.github.io/av1-isobmff/#codecsparam
|
|
178
|
+
* @param sequenceHeader The parsed AV1 sequence header
|
|
179
|
+
* @returns A codec string
|
|
180
|
+
*/
|
|
181
|
+
static toCodecString(sequenceHeader) {
|
|
182
|
+
const { seq_profile: seqProfile, seq_level_idx: [seqLevelIdx = 0], color_config: { BitDepth, mono_chrome: monoChrome, subsampling_x: subsamplingX, subsampling_y: subsamplingY, chroma_sample_position: chromaSamplePosition, color_description_present_flag, }, } = sequenceHeader;
|
|
183
|
+
let colorPrimaries;
|
|
184
|
+
let transferCharacteristics;
|
|
185
|
+
let matrixCoefficients;
|
|
186
|
+
let colorRange;
|
|
187
|
+
if (color_description_present_flag) {
|
|
188
|
+
({
|
|
189
|
+
color_primaries: colorPrimaries,
|
|
190
|
+
transfer_characteristics: transferCharacteristics,
|
|
191
|
+
matrix_coefficients: matrixCoefficients,
|
|
192
|
+
color_range: colorRange,
|
|
193
|
+
} = sequenceHeader.color_config);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
colorPrimaries = Av1.ColorPrimaries.Bt709;
|
|
197
|
+
transferCharacteristics = Av1.TransferCharacteristics.Bt709;
|
|
198
|
+
matrixCoefficients = Av1.MatrixCoefficients.Bt709;
|
|
199
|
+
colorRange = false;
|
|
200
|
+
}
|
|
201
|
+
return [
|
|
202
|
+
"av01",
|
|
203
|
+
seqProfile.toString(16),
|
|
204
|
+
decimalTwoDigits(seqLevelIdx) +
|
|
205
|
+
(sequenceHeader.seq_tier[0] ? "H" : "M"),
|
|
206
|
+
decimalTwoDigits(BitDepth),
|
|
207
|
+
monoChrome ? "1" : "0",
|
|
208
|
+
(subsamplingX ? "1" : "0") +
|
|
209
|
+
(subsamplingY ? "1" : "0") +
|
|
210
|
+
chromaSamplePosition.toString(),
|
|
211
|
+
decimalTwoDigits(colorPrimaries),
|
|
212
|
+
decimalTwoDigits(transferCharacteristics),
|
|
213
|
+
decimalTwoDigits(matrixCoefficients),
|
|
214
|
+
colorRange ? "1" : "0",
|
|
215
|
+
].join(".");
|
|
216
|
+
}
|
|
217
|
+
#Leb128Bytes = 0;
|
|
218
|
+
uvlc() {
|
|
219
|
+
let leadingZeros = 0;
|
|
220
|
+
while (!this.f1()) {
|
|
221
|
+
leadingZeros += 1;
|
|
222
|
+
}
|
|
223
|
+
if (leadingZeros >= 32) {
|
|
224
|
+
return 2 ** 32 - 1;
|
|
225
|
+
}
|
|
226
|
+
const value = this.f(leadingZeros);
|
|
227
|
+
return value + ((1 << leadingZeros) >>> 0) - 1;
|
|
228
|
+
}
|
|
229
|
+
leb128() {
|
|
230
|
+
if (!this.byteAligned) {
|
|
231
|
+
throw new Error("LEB128 must be byte-aligned");
|
|
232
|
+
}
|
|
233
|
+
let value = 0n;
|
|
234
|
+
this.#Leb128Bytes = 0;
|
|
235
|
+
for (let i = 0n; i < 8n; i += 1n) {
|
|
236
|
+
const leb128_byte = this.f(8);
|
|
237
|
+
value |= BigInt(leb128_byte & 0x7f) << (7n * i);
|
|
238
|
+
this.#Leb128Bytes += 1;
|
|
239
|
+
if ((leb128_byte & 0x80) == 0) {
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return value;
|
|
244
|
+
}
|
|
245
|
+
*annexBBitstream() {
|
|
246
|
+
while (!this.ended) {
|
|
247
|
+
const temporal_unit_size = this.leb128();
|
|
248
|
+
yield* this.temporalUnit(temporal_unit_size);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
*temporalUnit(sz) {
|
|
252
|
+
while (sz > 0) {
|
|
253
|
+
const frame_unit_size = this.leb128();
|
|
254
|
+
sz -= BigInt(this.#Leb128Bytes);
|
|
255
|
+
yield* this.frameUnit(frame_unit_size);
|
|
256
|
+
sz -= frame_unit_size;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
*frameUnit(sz) {
|
|
260
|
+
while (sz > 0) {
|
|
261
|
+
const obu_length = this.leb128();
|
|
262
|
+
sz -= BigInt(this.#Leb128Bytes);
|
|
263
|
+
const obu = this.openBitstreamUnit(obu_length);
|
|
264
|
+
if (obu) {
|
|
265
|
+
yield obu;
|
|
266
|
+
}
|
|
267
|
+
sz -= obu_length;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
#OperatingPointIdc = 0;
|
|
271
|
+
openBitstreamUnit(sz) {
|
|
272
|
+
const obu_header = this.obuHeader();
|
|
273
|
+
let obu_size;
|
|
274
|
+
if (obu_header.obu_has_size_field) {
|
|
275
|
+
obu_size = this.leb128();
|
|
276
|
+
}
|
|
277
|
+
else if (sz !== undefined) {
|
|
278
|
+
obu_size = sz - 1n - (obu_header.obu_extension_flag ? 1n : 0n);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
throw new Error("obu_has_size_field must be true");
|
|
282
|
+
}
|
|
283
|
+
const startPosition = this.getPosition();
|
|
284
|
+
if (obu_header.obu_type !== Av1.ObuType.SequenceHeader &&
|
|
285
|
+
obu_header.obu_type !== Av1.ObuType.TemporalDelimiter &&
|
|
286
|
+
this.#OperatingPointIdc !== 0 &&
|
|
287
|
+
obu_header.obu_extension_header) {
|
|
288
|
+
const inTemporalLayer = !!(this.#OperatingPointIdc &
|
|
289
|
+
(1 << obu_header.obu_extension_header.temporal_id));
|
|
290
|
+
const inSpatialLayer = !!(this.#OperatingPointIdc &
|
|
291
|
+
(1 << (obu_header.obu_extension_header.spatial_id + 8)));
|
|
292
|
+
if (!inTemporalLayer || !inSpatialLayer) {
|
|
293
|
+
this.skip(Number(obu_size));
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
let sequence_header_obu;
|
|
298
|
+
switch (obu_header.obu_type) {
|
|
299
|
+
case Av1.ObuType.SequenceHeader:
|
|
300
|
+
sequence_header_obu = this.sequenceHeaderObu();
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
const currentPosition = this.getPosition();
|
|
304
|
+
const payloadBits = (currentPosition[0] - startPosition[0]) * 8 +
|
|
305
|
+
(startPosition[1] - currentPosition[1]);
|
|
306
|
+
if (obu_size > 0 /* &&
|
|
307
|
+
obu_header.obu_type !== Av1.ObuType.TileGroup &&
|
|
308
|
+
obu_header.obu_type !== Av1.ObuType.TileList &&
|
|
309
|
+
obu_header.obu_type !== Av1.ObuType.Frame */) {
|
|
310
|
+
this.skip(Number(obu_size) * 8 - payloadBits);
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
obu_header,
|
|
314
|
+
obu_size,
|
|
315
|
+
sequence_header_obu,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
obuHeader() {
|
|
319
|
+
const obu_forbidden_bit = !!this.f1();
|
|
320
|
+
if (obu_forbidden_bit) {
|
|
321
|
+
throw new Error("Invalid data");
|
|
322
|
+
}
|
|
323
|
+
const obu_type = this.f(4);
|
|
324
|
+
const obu_extension_flag = !!this.f1();
|
|
325
|
+
const obu_has_size_field = !!this.f1();
|
|
326
|
+
this.f1();
|
|
327
|
+
let obu_extension_header;
|
|
328
|
+
if (obu_extension_flag) {
|
|
329
|
+
obu_extension_header = this.obuExtensionHeader();
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
obu_type,
|
|
333
|
+
obu_extension_flag,
|
|
334
|
+
obu_has_size_field,
|
|
335
|
+
obu_extension_header,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
obuExtensionHeader() {
|
|
339
|
+
const temporal_id = this.f(3);
|
|
340
|
+
const spatial_id = this.f(2);
|
|
341
|
+
this.skip(3);
|
|
342
|
+
return { temporal_id, spatial_id };
|
|
343
|
+
}
|
|
344
|
+
static SelectScreenContentTools = 2;
|
|
345
|
+
static SelectIntegerMv = 2;
|
|
346
|
+
sequenceHeaderObu() {
|
|
347
|
+
const seq_profile = this.f(3);
|
|
348
|
+
const still_picture = !!this.f1();
|
|
349
|
+
const reduced_still_picture_header = !!this.f1();
|
|
350
|
+
let timing_info_present_flag = false;
|
|
351
|
+
let timing_info;
|
|
352
|
+
let decoder_model_info_present_flag = false;
|
|
353
|
+
let decoder_model_info;
|
|
354
|
+
let initial_display_delay_present_flag = false;
|
|
355
|
+
let operating_points_cnt_minus_1 = 0;
|
|
356
|
+
const operating_point_idc = [];
|
|
357
|
+
const seq_level_idx = [];
|
|
358
|
+
const seq_tier = [];
|
|
359
|
+
const decoder_model_present_for_this_op = [];
|
|
360
|
+
const initial_display_delay_present_for_this_op = [];
|
|
361
|
+
let operating_parameters_info;
|
|
362
|
+
let initial_display_delay_minus_1;
|
|
363
|
+
if (reduced_still_picture_header) {
|
|
364
|
+
operating_point_idc[0] = 0;
|
|
365
|
+
seq_level_idx[0] = this.f(5);
|
|
366
|
+
seq_tier[0] = 0;
|
|
367
|
+
decoder_model_present_for_this_op[0] = false;
|
|
368
|
+
initial_display_delay_present_for_this_op[0] = false;
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
timing_info_present_flag = !!this.f1();
|
|
372
|
+
if (timing_info_present_flag) {
|
|
373
|
+
timing_info = this.timingInfo();
|
|
374
|
+
decoder_model_info_present_flag = !!this.f1();
|
|
375
|
+
if (decoder_model_info_present_flag) {
|
|
376
|
+
decoder_model_info = this.decoderModelInfo();
|
|
377
|
+
operating_parameters_info = [];
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
initial_display_delay_present_flag = !!this.f1();
|
|
381
|
+
if (initial_display_delay_present_flag) {
|
|
382
|
+
initial_display_delay_minus_1 = [];
|
|
383
|
+
}
|
|
384
|
+
operating_points_cnt_minus_1 = this.f(5);
|
|
385
|
+
for (let i = 0; i <= operating_points_cnt_minus_1; i += 1) {
|
|
386
|
+
operating_point_idc[i] = this.f(12);
|
|
387
|
+
seq_level_idx[i] = this.f(5);
|
|
388
|
+
if (seq_level_idx[i] > 7) {
|
|
389
|
+
seq_tier[i] = this.f1();
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
seq_tier[i] = 0;
|
|
393
|
+
}
|
|
394
|
+
if (decoder_model_info_present_flag) {
|
|
395
|
+
decoder_model_present_for_this_op[i] = !!this.f1();
|
|
396
|
+
if (decoder_model_present_for_this_op[i]) {
|
|
397
|
+
operating_parameters_info[i] =
|
|
398
|
+
this.operatingParametersInfo(decoder_model_info);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
decoder_model_present_for_this_op[i] = false;
|
|
403
|
+
}
|
|
404
|
+
if (initial_display_delay_present_flag) {
|
|
405
|
+
initial_display_delay_present_for_this_op[i] = !!this.f1();
|
|
406
|
+
if (initial_display_delay_present_for_this_op[i]) {
|
|
407
|
+
initial_display_delay_minus_1[i] = this.f(4);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
const operatingPoint = this.chooseOperatingPoint();
|
|
413
|
+
this.#OperatingPointIdc = operating_point_idc[operatingPoint];
|
|
414
|
+
const frame_width_bits_minus_1 = this.f(4);
|
|
415
|
+
const frame_height_bits_minus_1 = this.f(4);
|
|
416
|
+
const max_frame_width_minus_1 = this.f(frame_width_bits_minus_1 + 1);
|
|
417
|
+
const max_frame_height_minus_1 = this.f(frame_height_bits_minus_1 + 1);
|
|
418
|
+
let frame_id_numbers_present_flag = false;
|
|
419
|
+
let delta_frame_id_length_minus_2;
|
|
420
|
+
let additional_frame_id_length_minus_1;
|
|
421
|
+
if (!reduced_still_picture_header) {
|
|
422
|
+
frame_id_numbers_present_flag = !!this.f1();
|
|
423
|
+
if (frame_id_numbers_present_flag) {
|
|
424
|
+
delta_frame_id_length_minus_2 = this.f(4);
|
|
425
|
+
additional_frame_id_length_minus_1 = this.f(3);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
const use_128x128_superblock = !!this.f1();
|
|
429
|
+
const enable_filter_intra = !!this.f1();
|
|
430
|
+
const enable_intra_edge_filter = !!this.f1();
|
|
431
|
+
let enable_interintra_compound = false;
|
|
432
|
+
let enable_masked_compound = false;
|
|
433
|
+
let enable_warped_motion = false;
|
|
434
|
+
let enable_dual_filter = false;
|
|
435
|
+
let enable_order_hint = false;
|
|
436
|
+
let enable_jnt_comp = false;
|
|
437
|
+
let enable_ref_frame_mvs = false;
|
|
438
|
+
let seq_choose_screen_content_tools = false;
|
|
439
|
+
let seq_force_screen_content_tools = Av1.SelectScreenContentTools;
|
|
440
|
+
let seq_choose_integer_mv = false;
|
|
441
|
+
let seq_force_integer_mv = Av1.SelectIntegerMv;
|
|
442
|
+
let order_hint_bits_minus_1;
|
|
443
|
+
// let OrderHintBits = 0;
|
|
444
|
+
if (!reduced_still_picture_header) {
|
|
445
|
+
enable_interintra_compound = !!this.f1();
|
|
446
|
+
enable_masked_compound = !!this.f1();
|
|
447
|
+
enable_warped_motion = !!this.f1();
|
|
448
|
+
enable_dual_filter = !!this.f1();
|
|
449
|
+
enable_order_hint = !!this.f1();
|
|
450
|
+
if (enable_order_hint) {
|
|
451
|
+
enable_jnt_comp = !!this.f1();
|
|
452
|
+
enable_ref_frame_mvs = !!this.f1();
|
|
453
|
+
}
|
|
454
|
+
seq_choose_screen_content_tools = !!this.f1();
|
|
455
|
+
if (!seq_choose_screen_content_tools) {
|
|
456
|
+
seq_force_screen_content_tools = this.f1();
|
|
457
|
+
}
|
|
458
|
+
if (seq_force_screen_content_tools > 0) {
|
|
459
|
+
seq_choose_integer_mv = !!this.f1();
|
|
460
|
+
if (!seq_choose_integer_mv) {
|
|
461
|
+
seq_force_integer_mv = this.f1();
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (enable_order_hint) {
|
|
465
|
+
order_hint_bits_minus_1 = this.f(3);
|
|
466
|
+
// OrderHintBits = order_hint_bits_minus_1 + 1;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
const enable_superres = !!this.f1();
|
|
470
|
+
const enable_cdef = !!this.f1();
|
|
471
|
+
const enable_restoration = !!this.f1();
|
|
472
|
+
const color_config = this.colorConfig(seq_profile);
|
|
473
|
+
const film_grain_params_present = !!this.f1();
|
|
474
|
+
return {
|
|
475
|
+
seq_profile,
|
|
476
|
+
still_picture,
|
|
477
|
+
reduced_still_picture_header,
|
|
478
|
+
timing_info_present_flag,
|
|
479
|
+
timing_info,
|
|
480
|
+
decoder_model_info_present_flag,
|
|
481
|
+
decoder_model_info,
|
|
482
|
+
initial_display_delay_present_flag,
|
|
483
|
+
initial_display_delay_minus_1,
|
|
484
|
+
operating_points_cnt_minus_1,
|
|
485
|
+
operating_point_idc,
|
|
486
|
+
seq_level_idx,
|
|
487
|
+
seq_tier,
|
|
488
|
+
decoder_model_present_for_this_op,
|
|
489
|
+
operating_parameters_info,
|
|
490
|
+
initial_display_delay_present_for_this_op,
|
|
491
|
+
frame_width_bits_minus_1,
|
|
492
|
+
frame_height_bits_minus_1,
|
|
493
|
+
max_frame_width_minus_1,
|
|
494
|
+
max_frame_height_minus_1,
|
|
495
|
+
frame_id_numbers_present_flag,
|
|
496
|
+
delta_frame_id_length_minus_2,
|
|
497
|
+
additional_frame_id_length_minus_1,
|
|
498
|
+
use_128x128_superblock,
|
|
499
|
+
enable_filter_intra,
|
|
500
|
+
enable_intra_edge_filter,
|
|
501
|
+
enable_interintra_compound,
|
|
502
|
+
enable_masked_compound,
|
|
503
|
+
enable_warped_motion,
|
|
504
|
+
enable_dual_filter,
|
|
505
|
+
enable_order_hint,
|
|
506
|
+
enable_jnt_comp,
|
|
507
|
+
enable_ref_frame_mvs,
|
|
508
|
+
seq_choose_screen_content_tools,
|
|
509
|
+
seq_force_screen_content_tools,
|
|
510
|
+
seq_choose_integer_mv,
|
|
511
|
+
seq_force_integer_mv,
|
|
512
|
+
order_hint_bits_minus_1,
|
|
513
|
+
enable_superres,
|
|
514
|
+
enable_cdef,
|
|
515
|
+
enable_restoration,
|
|
516
|
+
color_config,
|
|
517
|
+
film_grain_params_present,
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
searchSequenceHeaderObu() {
|
|
521
|
+
while (!this.ended) {
|
|
522
|
+
const obu = this.openBitstreamUnit();
|
|
523
|
+
if (!obu) {
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
if (obu.sequence_header_obu) {
|
|
527
|
+
return obu.sequence_header_obu;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return undefined;
|
|
531
|
+
}
|
|
532
|
+
timingInfo() {
|
|
533
|
+
const num_units_in_display_tick = this.f(32);
|
|
534
|
+
const time_scale = this.f(32);
|
|
535
|
+
const equal_picture_interval = !!this.f1();
|
|
536
|
+
let num_ticks_per_picture_minus_1;
|
|
537
|
+
if (equal_picture_interval) {
|
|
538
|
+
num_ticks_per_picture_minus_1 = this.uvlc();
|
|
539
|
+
}
|
|
540
|
+
return {
|
|
541
|
+
num_units_in_display_tick,
|
|
542
|
+
time_scale,
|
|
543
|
+
equal_picture_interval,
|
|
544
|
+
num_ticks_per_picture_minus_1,
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
decoderModelInfo() {
|
|
548
|
+
const buffer_delay_length_minus_1 = this.f(5);
|
|
549
|
+
const num_units_in_decoding_tick = this.f(32);
|
|
550
|
+
const buffer_removal_time_length_minus_1 = this.f(5);
|
|
551
|
+
const frame_presentation_time_length_minus_1 = this.f(5);
|
|
552
|
+
return {
|
|
553
|
+
buffer_delay_length_minus_1,
|
|
554
|
+
num_units_in_decoding_tick,
|
|
555
|
+
buffer_removal_time_length_minus_1,
|
|
556
|
+
frame_presentation_time_length_minus_1,
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
operatingParametersInfo(decoderModelInfo) {
|
|
560
|
+
const n = decoderModelInfo.buffer_delay_length_minus_1 + 1;
|
|
561
|
+
const decoder_buffer_delay = this.f(n);
|
|
562
|
+
const encoder_buffer_delay = this.f(n);
|
|
563
|
+
const low_delay_mode_flag = !!this.f1();
|
|
564
|
+
return {
|
|
565
|
+
decoder_buffer_delay,
|
|
566
|
+
encoder_buffer_delay,
|
|
567
|
+
low_delay_mode_flag,
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
chooseOperatingPoint() {
|
|
571
|
+
return 0;
|
|
572
|
+
}
|
|
573
|
+
colorConfig(seq_profile) {
|
|
574
|
+
const high_bitdepth = !!this.f1();
|
|
575
|
+
let twelve_bit = false;
|
|
576
|
+
let BitDepth = 8;
|
|
577
|
+
if (seq_profile === 2 && high_bitdepth) {
|
|
578
|
+
twelve_bit = !!this.f1();
|
|
579
|
+
BitDepth = twelve_bit ? 12 : 10;
|
|
580
|
+
}
|
|
581
|
+
else if (seq_profile <= 2) {
|
|
582
|
+
BitDepth = high_bitdepth ? 10 : 8;
|
|
583
|
+
}
|
|
584
|
+
let mono_chrome = false;
|
|
585
|
+
if (seq_profile === 1) {
|
|
586
|
+
mono_chrome = !!this.f1();
|
|
587
|
+
}
|
|
588
|
+
// const NumPlanes = mono_chrome ? 1 : 3;
|
|
589
|
+
const color_description_present_flag = !!this.f1();
|
|
590
|
+
let color_primaries = Av1.ColorPrimaries.Unspecified;
|
|
591
|
+
let transfer_characteristics = Av1.TransferCharacteristics.Unspecified;
|
|
592
|
+
let matrix_coefficients = Av1.MatrixCoefficients.Unspecified;
|
|
593
|
+
if (color_description_present_flag) {
|
|
594
|
+
color_primaries = this.f(8);
|
|
595
|
+
transfer_characteristics = this.f(8);
|
|
596
|
+
matrix_coefficients = this.f(8);
|
|
597
|
+
}
|
|
598
|
+
let color_range;
|
|
599
|
+
let subsampling_x;
|
|
600
|
+
let subsampling_y;
|
|
601
|
+
let chroma_sample_position = 0;
|
|
602
|
+
let separate_uv_delta_q = false;
|
|
603
|
+
if (mono_chrome) {
|
|
604
|
+
color_range = !!this.f1();
|
|
605
|
+
subsampling_x = true;
|
|
606
|
+
subsampling_y = true;
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
if (color_primaries === Av1.ColorPrimaries.Bt709 &&
|
|
610
|
+
transfer_characteristics === Av1.TransferCharacteristics.Srgb &&
|
|
611
|
+
matrix_coefficients === Av1.MatrixCoefficients.Identity) {
|
|
612
|
+
color_range = true;
|
|
613
|
+
subsampling_x = false;
|
|
614
|
+
subsampling_y = false;
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
color_range = !!this.f1();
|
|
618
|
+
switch (seq_profile) {
|
|
619
|
+
case 0:
|
|
620
|
+
subsampling_x = true;
|
|
621
|
+
subsampling_y = true;
|
|
622
|
+
break;
|
|
623
|
+
case 1:
|
|
624
|
+
subsampling_x = false;
|
|
625
|
+
subsampling_y = false;
|
|
626
|
+
break;
|
|
627
|
+
default:
|
|
628
|
+
if (BitDepth == 12) {
|
|
629
|
+
subsampling_x = !!this.f1();
|
|
630
|
+
if (subsampling_x) {
|
|
631
|
+
subsampling_y = !!this.f1();
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
subsampling_y = false;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
subsampling_x = true;
|
|
639
|
+
subsampling_y = false;
|
|
640
|
+
}
|
|
641
|
+
break;
|
|
642
|
+
}
|
|
643
|
+
if (subsampling_x && subsampling_y) {
|
|
644
|
+
chroma_sample_position = this.f(2);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
separate_uv_delta_q = !!this.f1();
|
|
648
|
+
}
|
|
649
|
+
return {
|
|
650
|
+
high_bitdepth,
|
|
651
|
+
twelve_bit,
|
|
652
|
+
BitDepth,
|
|
653
|
+
mono_chrome,
|
|
654
|
+
color_description_present_flag,
|
|
655
|
+
color_primaries,
|
|
656
|
+
transfer_characteristics,
|
|
657
|
+
matrix_coefficients,
|
|
658
|
+
color_range,
|
|
659
|
+
subsampling_x,
|
|
660
|
+
subsampling_y,
|
|
661
|
+
chroma_sample_position,
|
|
662
|
+
separate_uv_delta_q,
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
//# sourceMappingURL=av1.js.map
|