@dolbylaboratories/alps 2.0.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.
@@ -0,0 +1,4929 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __typeError = (msg) => {
8
+ throw TypeError(msg);
9
+ };
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __commonJS = (cb, mod) => function __require() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
32
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
33
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
34
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
35
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
36
+
37
+ // node_modules/codem-isoboxer/dist/iso_boxer.js
38
+ var require_iso_boxer = __commonJS({
39
+ "node_modules/codem-isoboxer/dist/iso_boxer.js"(exports) {
40
+ var ISOBoxer2 = {};
41
+ ISOBoxer2.parseBuffer = function(arrayBuffer) {
42
+ return new ISOFile(arrayBuffer).parse();
43
+ };
44
+ ISOBoxer2.addBoxProcessor = function(type, parser) {
45
+ if (typeof type !== "string" || typeof parser !== "function") {
46
+ return;
47
+ }
48
+ ISOBox.prototype._boxProcessors[type] = parser;
49
+ };
50
+ ISOBoxer2.createFile = function() {
51
+ return new ISOFile();
52
+ };
53
+ ISOBoxer2.createBox = function(type, parent, pos) {
54
+ var newBox = ISOBox.create(type);
55
+ if (parent) {
56
+ parent.append(newBox, pos);
57
+ }
58
+ return newBox;
59
+ };
60
+ ISOBoxer2.createFullBox = function(type, parent, pos) {
61
+ var newBox = ISOBoxer2.createBox(type, parent, pos);
62
+ newBox.version = 0;
63
+ newBox.flags = 0;
64
+ return newBox;
65
+ };
66
+ ISOBoxer2.Utils = {};
67
+ ISOBoxer2.Utils.dataViewToString = function(dataView, encoding) {
68
+ var impliedEncoding = encoding || "utf-8";
69
+ if (typeof TextDecoder !== "undefined") {
70
+ return new TextDecoder(impliedEncoding).decode(dataView);
71
+ }
72
+ var a = [];
73
+ var i = 0;
74
+ if (impliedEncoding === "utf-8") {
75
+ while (i < dataView.byteLength) {
76
+ var c = dataView.getUint8(i++);
77
+ if (c < 128) {
78
+ } else if (c < 224) {
79
+ c = (c & 31) << 6;
80
+ c |= dataView.getUint8(i++) & 63;
81
+ } else if (c < 240) {
82
+ c = (c & 15) << 12;
83
+ c |= (dataView.getUint8(i++) & 63) << 6;
84
+ c |= dataView.getUint8(i++) & 63;
85
+ } else {
86
+ c = (c & 7) << 18;
87
+ c |= (dataView.getUint8(i++) & 63) << 12;
88
+ c |= (dataView.getUint8(i++) & 63) << 6;
89
+ c |= dataView.getUint8(i++) & 63;
90
+ }
91
+ a.push(String.fromCharCode(c));
92
+ }
93
+ } else {
94
+ while (i < dataView.byteLength) {
95
+ a.push(String.fromCharCode(dataView.getUint8(i++)));
96
+ }
97
+ }
98
+ return a.join("");
99
+ };
100
+ ISOBoxer2.Utils.utf8ToByteArray = function(string) {
101
+ var u, i;
102
+ if (typeof TextEncoder !== "undefined") {
103
+ u = new TextEncoder().encode(string);
104
+ } else {
105
+ u = [];
106
+ for (i = 0; i < string.length; ++i) {
107
+ var c = string.charCodeAt(i);
108
+ if (c < 128) {
109
+ u.push(c);
110
+ } else if (c < 2048) {
111
+ u.push(192 | c >> 6);
112
+ u.push(128 | 63 & c);
113
+ } else if (c < 65536) {
114
+ u.push(224 | c >> 12);
115
+ u.push(128 | 63 & c >> 6);
116
+ u.push(128 | 63 & c);
117
+ } else {
118
+ u.push(240 | c >> 18);
119
+ u.push(128 | 63 & c >> 12);
120
+ u.push(128 | 63 & c >> 6);
121
+ u.push(128 | 63 & c);
122
+ }
123
+ }
124
+ }
125
+ return u;
126
+ };
127
+ ISOBoxer2.Utils.appendBox = function(parent, box, pos) {
128
+ box._offset = parent._cursor.offset;
129
+ box._root = parent._root ? parent._root : parent;
130
+ box._raw = parent._raw;
131
+ box._parent = parent;
132
+ if (pos === -1) {
133
+ return;
134
+ }
135
+ if (pos === void 0 || pos === null) {
136
+ parent.boxes.push(box);
137
+ return;
138
+ }
139
+ var index = -1, type;
140
+ if (typeof pos === "number") {
141
+ index = pos;
142
+ } else {
143
+ if (typeof pos === "string") {
144
+ type = pos;
145
+ } else if (typeof pos === "object" && pos.type) {
146
+ type = pos.type;
147
+ } else {
148
+ parent.boxes.push(box);
149
+ return;
150
+ }
151
+ for (var i = 0; i < parent.boxes.length; i++) {
152
+ if (type === parent.boxes[i].type) {
153
+ index = i + 1;
154
+ break;
155
+ }
156
+ }
157
+ }
158
+ parent.boxes.splice(index, 0, box);
159
+ };
160
+ if (typeof exports !== "undefined") {
161
+ exports.parseBuffer = ISOBoxer2.parseBuffer;
162
+ exports.addBoxProcessor = ISOBoxer2.addBoxProcessor;
163
+ exports.createFile = ISOBoxer2.createFile;
164
+ exports.createBox = ISOBoxer2.createBox;
165
+ exports.createFullBox = ISOBoxer2.createFullBox;
166
+ exports.Utils = ISOBoxer2.Utils;
167
+ }
168
+ ISOBoxer2.Cursor = function(initialOffset) {
169
+ this.offset = typeof initialOffset == "undefined" ? 0 : initialOffset;
170
+ };
171
+ var ISOFile = function(arrayBuffer) {
172
+ this._cursor = new ISOBoxer2.Cursor();
173
+ this.boxes = [];
174
+ if (arrayBuffer) {
175
+ this._raw = new DataView(arrayBuffer);
176
+ }
177
+ };
178
+ ISOFile.prototype.fetch = function(type) {
179
+ var result = this.fetchAll(type, true);
180
+ return result.length ? result[0] : null;
181
+ };
182
+ ISOFile.prototype.fetchAll = function(type, returnEarly) {
183
+ var result = [];
184
+ ISOFile._sweep.call(this, type, result, returnEarly);
185
+ return result;
186
+ };
187
+ ISOFile.prototype.parse = function() {
188
+ this._cursor.offset = 0;
189
+ this.boxes = [];
190
+ while (this._cursor.offset < this._raw.byteLength) {
191
+ var box = ISOBox.parse(this);
192
+ if (typeof box.type === "undefined") break;
193
+ this.boxes.push(box);
194
+ }
195
+ return this;
196
+ };
197
+ ISOFile._sweep = function(type, result, returnEarly) {
198
+ if (this.type && this.type == type) result.push(this);
199
+ for (var box in this.boxes) {
200
+ if (result.length && returnEarly) return;
201
+ ISOFile._sweep.call(this.boxes[box], type, result, returnEarly);
202
+ }
203
+ };
204
+ ISOFile.prototype.write = function() {
205
+ var length = 0, i;
206
+ for (i = 0; i < this.boxes.length; i++) {
207
+ length += this.boxes[i].getLength(false);
208
+ }
209
+ var bytes = new Uint8Array(length);
210
+ this._rawo = new DataView(bytes.buffer);
211
+ this.bytes = bytes;
212
+ this._cursor.offset = 0;
213
+ for (i = 0; i < this.boxes.length; i++) {
214
+ this.boxes[i].write();
215
+ }
216
+ return bytes.buffer;
217
+ };
218
+ ISOFile.prototype.append = function(box, pos) {
219
+ ISOBoxer2.Utils.appendBox(this, box, pos);
220
+ };
221
+ var ISOBox = function() {
222
+ this._cursor = new ISOBoxer2.Cursor();
223
+ };
224
+ ISOBox.parse = function(parent) {
225
+ var newBox = new ISOBox();
226
+ newBox._offset = parent._cursor.offset;
227
+ newBox._root = parent._root ? parent._root : parent;
228
+ newBox._raw = parent._raw;
229
+ newBox._parent = parent;
230
+ newBox._parseBox();
231
+ parent._cursor.offset = newBox._raw.byteOffset + newBox._raw.byteLength;
232
+ return newBox;
233
+ };
234
+ ISOBox.create = function(type) {
235
+ var newBox = new ISOBox();
236
+ newBox.type = type;
237
+ newBox.boxes = [];
238
+ return newBox;
239
+ };
240
+ ISOBox.prototype._boxContainers = ["dinf", "edts", "mdia", "meco", "mfra", "minf", "moof", "moov", "mvex", "stbl", "strk", "traf", "trak", "tref", "udta", "vttc", "sinf", "schi", "encv", "enca", "meta", "grpl", "prsl"];
241
+ ISOBox.prototype._boxProcessors = {};
242
+ ISOBox.prototype._procField = function(name, type, size) {
243
+ if (this._parsing) {
244
+ this[name] = this._readField(type, size);
245
+ } else {
246
+ this._writeField(type, size, this[name]);
247
+ }
248
+ };
249
+ ISOBox.prototype._procFieldArray = function(name, length, type, size) {
250
+ var i;
251
+ if (this._parsing) {
252
+ this[name] = [];
253
+ for (i = 0; i < length; i++) {
254
+ this[name][i] = this._readField(type, size);
255
+ }
256
+ } else {
257
+ for (i = 0; i < this[name].length; i++) {
258
+ this._writeField(type, size, this[name][i]);
259
+ }
260
+ }
261
+ };
262
+ ISOBox.prototype._procFullBox = function() {
263
+ this._procField("version", "uint", 8);
264
+ this._procField("flags", "uint", 24);
265
+ };
266
+ ISOBox.prototype._procEntries = function(name, length, fn) {
267
+ var i;
268
+ if (this._parsing) {
269
+ this[name] = [];
270
+ for (i = 0; i < length; i++) {
271
+ this[name].push({});
272
+ fn.call(this, this[name][i]);
273
+ }
274
+ } else {
275
+ for (i = 0; i < length; i++) {
276
+ fn.call(this, this[name][i]);
277
+ }
278
+ }
279
+ };
280
+ ISOBox.prototype._procSubEntries = function(entry, name, length, fn) {
281
+ var i;
282
+ if (this._parsing) {
283
+ entry[name] = [];
284
+ for (i = 0; i < length; i++) {
285
+ entry[name].push({});
286
+ fn.call(this, entry[name][i]);
287
+ }
288
+ } else {
289
+ for (i = 0; i < length; i++) {
290
+ fn.call(this, entry[name][i]);
291
+ }
292
+ }
293
+ };
294
+ ISOBox.prototype._procEntryField = function(entry, name, type, size) {
295
+ if (this._parsing) {
296
+ entry[name] = this._readField(type, size);
297
+ } else {
298
+ this._writeField(type, size, entry[name]);
299
+ }
300
+ };
301
+ ISOBox.prototype._procSubBoxes = function(name, length) {
302
+ var i;
303
+ if (this._parsing) {
304
+ this[name] = [];
305
+ for (i = 0; i < length; i++) {
306
+ this[name].push(ISOBox.parse(this));
307
+ }
308
+ } else {
309
+ for (i = 0; i < length; i++) {
310
+ if (this._rawo) {
311
+ this[name][i].write();
312
+ } else {
313
+ this.size += this[name][i].getLength();
314
+ }
315
+ }
316
+ }
317
+ };
318
+ ISOBox.prototype._readField = function(type, size) {
319
+ switch (type) {
320
+ case "uint":
321
+ return this._readUint(size);
322
+ case "int":
323
+ return this._readInt(size);
324
+ case "template":
325
+ return this._readTemplate(size);
326
+ case "string":
327
+ return size === -1 ? this._readTerminatedString() : this._readString(size);
328
+ case "data":
329
+ return this._readData(size);
330
+ case "utf8":
331
+ return this._readUTF8String();
332
+ case "utf8string":
333
+ return this._readUTF8TerminatedString();
334
+ default:
335
+ return -1;
336
+ }
337
+ };
338
+ ISOBox.prototype._readInt = function(size) {
339
+ var result = null, offset = this._cursor.offset - this._raw.byteOffset;
340
+ switch (size) {
341
+ case 8:
342
+ result = this._raw.getInt8(offset);
343
+ break;
344
+ case 16:
345
+ result = this._raw.getInt16(offset);
346
+ break;
347
+ case 32:
348
+ result = this._raw.getInt32(offset);
349
+ break;
350
+ case 64:
351
+ var s1 = this._raw.getInt32(offset);
352
+ var s2 = this._raw.getInt32(offset + 4);
353
+ result = s1 * Math.pow(2, 32) + s2;
354
+ break;
355
+ }
356
+ this._cursor.offset += size >> 3;
357
+ return result;
358
+ };
359
+ ISOBox.prototype._readUint = function(size) {
360
+ var result = null, offset = this._cursor.offset - this._raw.byteOffset, s1, s2;
361
+ switch (size) {
362
+ case 8:
363
+ result = this._raw.getUint8(offset);
364
+ break;
365
+ case 16:
366
+ result = this._raw.getUint16(offset);
367
+ break;
368
+ case 24:
369
+ s1 = this._raw.getUint16(offset);
370
+ s2 = this._raw.getUint8(offset + 2);
371
+ result = (s1 << 8) + s2;
372
+ break;
373
+ case 32:
374
+ result = this._raw.getUint32(offset);
375
+ break;
376
+ case 64:
377
+ s1 = this._raw.getUint32(offset);
378
+ s2 = this._raw.getUint32(offset + 4);
379
+ result = s1 * Math.pow(2, 32) + s2;
380
+ break;
381
+ }
382
+ this._cursor.offset += size >> 3;
383
+ return result;
384
+ };
385
+ ISOBox.prototype._readString = function(length) {
386
+ var str = "";
387
+ for (var c = 0; c < length; c++) {
388
+ var char = this._readUint(8);
389
+ str += String.fromCharCode(char);
390
+ }
391
+ return str;
392
+ };
393
+ ISOBox.prototype._readTemplate = function(size) {
394
+ var pre = this._readUint(size / 2);
395
+ var post = this._readUint(size / 2);
396
+ return pre + post / Math.pow(2, size / 2);
397
+ };
398
+ ISOBox.prototype._readTerminatedString = function() {
399
+ var str = "";
400
+ while (this._cursor.offset - this._offset < this._raw.byteLength) {
401
+ var char = this._readUint(8);
402
+ if (char === 0) break;
403
+ str += String.fromCharCode(char);
404
+ }
405
+ return str;
406
+ };
407
+ ISOBox.prototype._readData = function(size) {
408
+ var length = size > 0 ? size : this._raw.byteLength - (this._cursor.offset - this._offset);
409
+ if (length > 0) {
410
+ var data = new Uint8Array(this._raw.buffer, this._cursor.offset, length);
411
+ this._cursor.offset += length;
412
+ return data;
413
+ } else {
414
+ return null;
415
+ }
416
+ };
417
+ ISOBox.prototype._readUTF8String = function() {
418
+ var length = this._raw.byteLength - (this._cursor.offset - this._offset);
419
+ var data = null;
420
+ if (length > 0) {
421
+ data = new DataView(this._raw.buffer, this._cursor.offset, length);
422
+ this._cursor.offset += length;
423
+ }
424
+ return data ? ISOBoxer2.Utils.dataViewToString(data) : data;
425
+ };
426
+ ISOBox.prototype._readUTF8TerminatedString = function() {
427
+ var length = this._raw.byteLength - (this._cursor.offset - this._offset);
428
+ var data = null;
429
+ if (length > 0) {
430
+ data = new DataView(this._raw.buffer, this._cursor.offset, length);
431
+ var l;
432
+ for (l = 0; l < length; l++)
433
+ if (data.getUint8(l) === 0)
434
+ break;
435
+ data = new DataView(this._raw.buffer, this._cursor.offset, l);
436
+ this._cursor.offset += Math.min(l + 1, length);
437
+ }
438
+ return data ? ISOBoxer2.Utils.dataViewToString(data) : data;
439
+ };
440
+ ISOBox.prototype._parseBox = function() {
441
+ this._parsing = true;
442
+ this._cursor.offset = this._offset;
443
+ if (this._offset + 8 > this._raw.buffer.byteLength) {
444
+ this._root._incomplete = true;
445
+ return;
446
+ }
447
+ this._procField("size", "uint", 32);
448
+ this._procField("type", "string", 4);
449
+ if (this.size === 1) {
450
+ this._procField("largesize", "uint", 64);
451
+ }
452
+ if (this.type === "uuid") {
453
+ this._procFieldArray("usertype", 16, "uint", 8);
454
+ }
455
+ switch (this.size) {
456
+ case 0:
457
+ this._raw = new DataView(this._raw.buffer, this._offset);
458
+ break;
459
+ case 1:
460
+ if (this._offset + this.size > this._raw.buffer.byteLength) {
461
+ this._incomplete = true;
462
+ this._root._incomplete = true;
463
+ } else {
464
+ this._raw = new DataView(this._raw.buffer, this._offset, this.largesize);
465
+ }
466
+ break;
467
+ default:
468
+ if (this._offset + this.size > this._raw.buffer.byteLength) {
469
+ this._incomplete = true;
470
+ this._root._incomplete = true;
471
+ } else {
472
+ this._raw = new DataView(this._raw.buffer, this._offset, this.size);
473
+ }
474
+ }
475
+ if (!this._incomplete) {
476
+ if (this._boxProcessors[this.type]) {
477
+ this._boxProcessors[this.type].call(this);
478
+ }
479
+ if (this._boxContainers.indexOf(this.type) !== -1) {
480
+ this._parseContainerBox();
481
+ } else {
482
+ this._data = this._readData();
483
+ }
484
+ }
485
+ };
486
+ ISOBox.prototype._parseFullBox = function() {
487
+ this.version = this._readUint(8);
488
+ this.flags = this._readUint(24);
489
+ };
490
+ ISOBox.prototype._parseContainerBox = function() {
491
+ this.boxes = [];
492
+ while (this._cursor.offset - this._raw.byteOffset < this._raw.byteLength) {
493
+ this.boxes.push(ISOBox.parse(this));
494
+ }
495
+ };
496
+ ISOBox.prototype.append = function(box, pos) {
497
+ ISOBoxer2.Utils.appendBox(this, box, pos);
498
+ };
499
+ ISOBox.prototype.getLength = function() {
500
+ this._parsing = false;
501
+ this._rawo = null;
502
+ this.size = 0;
503
+ this._procField("size", "uint", 32);
504
+ this._procField("type", "string", 4);
505
+ if (this.size === 1) {
506
+ this._procField("largesize", "uint", 64);
507
+ }
508
+ if (this.type === "uuid") {
509
+ this._procFieldArray("usertype", 16, "uint", 8);
510
+ }
511
+ if (this._boxProcessors[this.type]) {
512
+ this._boxProcessors[this.type].call(this);
513
+ }
514
+ if (this._boxContainers.indexOf(this.type) !== -1) {
515
+ for (var i = 0; i < this.boxes.length; i++) {
516
+ this.size += this.boxes[i].getLength();
517
+ }
518
+ }
519
+ if (this._data) {
520
+ this._writeData(this._data);
521
+ }
522
+ return this.size;
523
+ };
524
+ ISOBox.prototype.write = function() {
525
+ this._parsing = false;
526
+ this._cursor.offset = this._parent._cursor.offset;
527
+ switch (this.size) {
528
+ case 0:
529
+ this._rawo = new DataView(this._parent._rawo.buffer, this._cursor.offset, this.parent._rawo.byteLength - this._cursor.offset);
530
+ break;
531
+ case 1:
532
+ this._rawo = new DataView(this._parent._rawo.buffer, this._cursor.offset, this.largesize);
533
+ break;
534
+ default:
535
+ this._rawo = new DataView(this._parent._rawo.buffer, this._cursor.offset, this.size);
536
+ }
537
+ this._procField("size", "uint", 32);
538
+ this._procField("type", "string", 4);
539
+ if (this.size === 1) {
540
+ this._procField("largesize", "uint", 64);
541
+ }
542
+ if (this.type === "uuid") {
543
+ this._procFieldArray("usertype", 16, "uint", 8);
544
+ }
545
+ if (this._boxProcessors[this.type]) {
546
+ this._boxProcessors[this.type].call(this);
547
+ }
548
+ if (this._boxContainers.indexOf(this.type) !== -1) {
549
+ for (var i = 0; i < this.boxes.length; i++) {
550
+ this.boxes[i].write();
551
+ }
552
+ }
553
+ if (this._data) {
554
+ this._writeData(this._data);
555
+ }
556
+ this._parent._cursor.offset += this.size;
557
+ return this.size;
558
+ };
559
+ ISOBox.prototype._writeInt = function(size, value) {
560
+ if (this._rawo) {
561
+ var offset = this._cursor.offset - this._rawo.byteOffset;
562
+ switch (size) {
563
+ case 8:
564
+ this._rawo.setInt8(offset, value);
565
+ break;
566
+ case 16:
567
+ this._rawo.setInt16(offset, value);
568
+ break;
569
+ case 32:
570
+ this._rawo.setInt32(offset, value);
571
+ break;
572
+ case 64:
573
+ var s1 = Math.floor(value / Math.pow(2, 32));
574
+ var s2 = value - s1 * Math.pow(2, 32);
575
+ this._rawo.setUint32(offset, s1);
576
+ this._rawo.setUint32(offset + 4, s2);
577
+ break;
578
+ }
579
+ this._cursor.offset += size >> 3;
580
+ } else {
581
+ this.size += size >> 3;
582
+ }
583
+ };
584
+ ISOBox.prototype._writeUint = function(size, value) {
585
+ if (this._rawo) {
586
+ var offset = this._cursor.offset - this._rawo.byteOffset, s1, s2;
587
+ switch (size) {
588
+ case 8:
589
+ this._rawo.setUint8(offset, value);
590
+ break;
591
+ case 16:
592
+ this._rawo.setUint16(offset, value);
593
+ break;
594
+ case 24:
595
+ s1 = (value & 16776960) >> 8;
596
+ s2 = value & 255;
597
+ this._rawo.setUint16(offset, s1);
598
+ this._rawo.setUint8(offset + 2, s2);
599
+ break;
600
+ case 32:
601
+ this._rawo.setUint32(offset, value);
602
+ break;
603
+ case 64:
604
+ s1 = Math.floor(value / Math.pow(2, 32));
605
+ s2 = value - s1 * Math.pow(2, 32);
606
+ this._rawo.setUint32(offset, s1);
607
+ this._rawo.setUint32(offset + 4, s2);
608
+ break;
609
+ }
610
+ this._cursor.offset += size >> 3;
611
+ } else {
612
+ this.size += size >> 3;
613
+ }
614
+ };
615
+ ISOBox.prototype._writeString = function(size, str) {
616
+ for (var c = 0; c < size; c++) {
617
+ this._writeUint(8, str.charCodeAt(c));
618
+ }
619
+ };
620
+ ISOBox.prototype._writeTerminatedString = function(str) {
621
+ if (str.length === 0) {
622
+ return;
623
+ }
624
+ for (var c = 0; c < str.length; c++) {
625
+ this._writeUint(8, str.charCodeAt(c));
626
+ }
627
+ this._writeUint(8, 0);
628
+ };
629
+ ISOBox.prototype._writeTemplate = function(size, value) {
630
+ var pre = Math.floor(value);
631
+ var post = (value - pre) * Math.pow(2, size / 2);
632
+ this._writeUint(size / 2, pre);
633
+ this._writeUint(size / 2, post);
634
+ };
635
+ ISOBox.prototype._writeData = function(data) {
636
+ var i;
637
+ if (data) {
638
+ if (this._rawo) {
639
+ if (data instanceof Array) {
640
+ var offset = this._cursor.offset - this._rawo.byteOffset;
641
+ for (var i = 0; i < data.length; i++) {
642
+ this._rawo.setInt8(offset + i, data[i]);
643
+ }
644
+ this._cursor.offset += data.length;
645
+ }
646
+ if (data instanceof Uint8Array) {
647
+ this._root.bytes.set(data, this._cursor.offset);
648
+ this._cursor.offset += data.length;
649
+ }
650
+ } else {
651
+ this.size += data.length;
652
+ }
653
+ }
654
+ };
655
+ ISOBox.prototype._writeUTF8String = function(string) {
656
+ var u = ISOBoxer2.Utils.utf8ToByteArray(string);
657
+ if (this._rawo) {
658
+ var dataView = new DataView(this._rawo.buffer, this._cursor.offset, u.length);
659
+ for (var i = 0; i < u.length; i++) {
660
+ dataView.setUint8(i, u[i]);
661
+ }
662
+ } else {
663
+ this.size += u.length;
664
+ }
665
+ };
666
+ ISOBox.prototype._writeField = function(type, size, value) {
667
+ switch (type) {
668
+ case "uint":
669
+ this._writeUint(size, value);
670
+ break;
671
+ case "int":
672
+ this._writeInt(size, value);
673
+ break;
674
+ case "template":
675
+ this._writeTemplate(size, value);
676
+ break;
677
+ case "string":
678
+ if (size == -1) {
679
+ this._writeTerminatedString(value);
680
+ } else {
681
+ this._writeString(size, value);
682
+ }
683
+ break;
684
+ case "data":
685
+ this._writeData(value);
686
+ break;
687
+ case "utf8":
688
+ this._writeUTF8String(value);
689
+ break;
690
+ default:
691
+ break;
692
+ }
693
+ };
694
+ ISOBox.prototype._boxProcessors["ardi"] = function() {
695
+ this._procFullBox();
696
+ this._procField("audio_rendering_indication", "uint", 8);
697
+ };
698
+ ISOBox.prototype._boxProcessors["avc1"] = ISOBox.prototype._boxProcessors["avc2"] = ISOBox.prototype._boxProcessors["avc3"] = ISOBox.prototype._boxProcessors["avc4"] = ISOBox.prototype._boxProcessors["hvc1"] = ISOBox.prototype._boxProcessors["hev1"] = ISOBox.prototype._boxProcessors["encv"] = function() {
699
+ this._procFieldArray("reserved1", 6, "uint", 8);
700
+ this._procField("data_reference_index", "uint", 16);
701
+ this._procField("pre_defined1", "uint", 16);
702
+ this._procField("reserved2", "uint", 16);
703
+ this._procFieldArray("pre_defined2", 3, "uint", 32);
704
+ this._procField("width", "uint", 16);
705
+ this._procField("height", "uint", 16);
706
+ this._procField("horizresolution", "template", 32);
707
+ this._procField("vertresolution", "template", 32);
708
+ this._procField("reserved3", "uint", 32);
709
+ this._procField("frame_count", "uint", 16);
710
+ this._procFieldArray("compressorname", 32, "uint", 8);
711
+ this._procField("depth", "uint", 16);
712
+ this._procField("pre_defined3", "int", 16);
713
+ this._procField("config", "data", -1);
714
+ };
715
+ ISOBox.prototype._boxProcessors["ctts"] = function() {
716
+ this._procFullBox();
717
+ this._procField("entry_count", "uint", 32);
718
+ this._procEntries("entries", this.entry_count, function(entry) {
719
+ this._procEntryField(entry, "sample_count", "uint", 32);
720
+ this._procEntryField(entry, "sample_offset", this.version === 1 ? "int" : "uint", 32);
721
+ });
722
+ };
723
+ ISOBox.prototype._boxProcessors["dref"] = function() {
724
+ this._procFullBox();
725
+ this._procField("entry_count", "uint", 32);
726
+ this._procSubBoxes("entries", this.entry_count);
727
+ };
728
+ ISOBox.prototype._boxProcessors["elng"] = function() {
729
+ this._procFullBox();
730
+ this._procField("extended_language", "utf8string");
731
+ };
732
+ ISOBox.prototype._boxProcessors["elst"] = function() {
733
+ this._procFullBox();
734
+ this._procField("entry_count", "uint", 32);
735
+ this._procEntries("entries", this.entry_count, function(entry) {
736
+ this._procEntryField(entry, "segment_duration", "uint", this.version === 1 ? 64 : 32);
737
+ this._procEntryField(entry, "media_time", "int", this.version === 1 ? 64 : 32);
738
+ this._procEntryField(entry, "media_rate_integer", "int", 16);
739
+ this._procEntryField(entry, "media_rate_fraction", "int", 16);
740
+ });
741
+ };
742
+ ISOBox.prototype._boxProcessors["emsg"] = function() {
743
+ this._procFullBox();
744
+ if (this.version == 1) {
745
+ this._procField("timescale", "uint", 32);
746
+ this._procField("presentation_time", "uint", 64);
747
+ this._procField("event_duration", "uint", 32);
748
+ this._procField("id", "uint", 32);
749
+ this._procField("scheme_id_uri", "string", -1);
750
+ this._procField("value", "string", -1);
751
+ } else {
752
+ this._procField("scheme_id_uri", "string", -1);
753
+ this._procField("value", "string", -1);
754
+ this._procField("timescale", "uint", 32);
755
+ this._procField("presentation_time_delta", "uint", 32);
756
+ this._procField("event_duration", "uint", 32);
757
+ this._procField("id", "uint", 32);
758
+ }
759
+ this._procField("message_data", "data", -1);
760
+ };
761
+ ISOBox.prototype._boxProcessors["free"] = ISOBox.prototype._boxProcessors["skip"] = function() {
762
+ this._procField("data", "data", -1);
763
+ };
764
+ ISOBox.prototype._boxProcessors["frma"] = function() {
765
+ this._procField("data_format", "uint", 32);
766
+ };
767
+ ISOBox.prototype._boxProcessors["ftyp"] = ISOBox.prototype._boxProcessors["styp"] = function() {
768
+ this._procField("major_brand", "string", 4);
769
+ this._procField("minor_version", "uint", 32);
770
+ var nbCompatibleBrands = -1;
771
+ if (this._parsing) {
772
+ nbCompatibleBrands = (this._raw.byteLength - (this._cursor.offset - this._raw.byteOffset)) / 4;
773
+ }
774
+ this._procFieldArray("compatible_brands", nbCompatibleBrands, "string", 4);
775
+ };
776
+ ISOBox.prototype._boxProcessors["hdlr"] = function() {
777
+ this._procFullBox();
778
+ this._procField("pre_defined", "uint", 32);
779
+ this._procField("handler_type", "string", 4);
780
+ this._procFieldArray("reserved", 3, "uint", 32);
781
+ this._procField("name", "string", -1);
782
+ };
783
+ ISOBox.prototype._boxProcessors["imda"] = function() {
784
+ this._procField("imda_identifier", "uint", 32);
785
+ this._procField("data", "data", -1);
786
+ };
787
+ ISOBox.prototype._boxProcessors["kind"] = function() {
788
+ this._procFullBox();
789
+ this._procField("schemeURI", "utf8string");
790
+ this._procField("value", "utf8string");
791
+ };
792
+ ISOBox.prototype._boxProcessors["labl"] = function() {
793
+ this._procFullBox();
794
+ this.is_group_label = (this.flags & 1) != 0;
795
+ this._procField("label_id", "uint", 16);
796
+ this._procField("language", "utf8string");
797
+ this._procField("label", "utf8string");
798
+ };
799
+ ISOBox.prototype._boxProcessors["mdat"] = function() {
800
+ this._procField("data", "data", -1);
801
+ };
802
+ ISOBox.prototype._boxProcessors["mdhd"] = function() {
803
+ this._procFullBox();
804
+ this._procField("creation_time", "uint", this.version == 1 ? 64 : 32);
805
+ this._procField("modification_time", "uint", this.version == 1 ? 64 : 32);
806
+ this._procField("timescale", "uint", 32);
807
+ this._procField("duration", "uint", this.version == 1 ? 64 : 32);
808
+ if (!this._parsing && typeof this.language === "string") {
809
+ this.language = this.language.charCodeAt(0) - 96 << 10 | this.language.charCodeAt(1) - 96 << 5 | this.language.charCodeAt(2) - 96;
810
+ }
811
+ this._procField("language", "uint", 16);
812
+ if (this._parsing) {
813
+ this.language = String.fromCharCode(
814
+ (this.language >> 10 & 31) + 96,
815
+ (this.language >> 5 & 31) + 96,
816
+ (this.language & 31) + 96
817
+ );
818
+ }
819
+ this._procField("pre_defined", "uint", 16);
820
+ };
821
+ ISOBox.prototype._boxProcessors["mehd"] = function() {
822
+ this._procFullBox();
823
+ this._procField("fragment_duration", "uint", this.version == 1 ? 64 : 32);
824
+ };
825
+ ISOBox.prototype._boxProcessors["meta"] = function() {
826
+ this._procFullBox();
827
+ };
828
+ ISOBox.prototype._boxProcessors["mfhd"] = function() {
829
+ this._procFullBox();
830
+ this._procField("sequence_number", "uint", 32);
831
+ };
832
+ ISOBox.prototype._boxProcessors["mfro"] = function() {
833
+ this._procFullBox();
834
+ this._procField("mfra_size", "uint", 32);
835
+ };
836
+ ISOBox.prototype._boxProcessors["mp4a"] = ISOBox.prototype._boxProcessors["enca"] = function() {
837
+ this._procFieldArray("reserved1", 6, "uint", 8);
838
+ this._procField("data_reference_index", "uint", 16);
839
+ this._procFieldArray("reserved2", 2, "uint", 32);
840
+ this._procField("channelcount", "uint", 16);
841
+ this._procField("samplesize", "uint", 16);
842
+ this._procField("pre_defined", "uint", 16);
843
+ this._procField("reserved3", "uint", 16);
844
+ this._procField("samplerate", "template", 32);
845
+ this._procField("esds", "data", -1);
846
+ };
847
+ ISOBox.prototype._boxProcessors["mvhd"] = function() {
848
+ this._procFullBox();
849
+ this._procField("creation_time", "uint", this.version == 1 ? 64 : 32);
850
+ this._procField("modification_time", "uint", this.version == 1 ? 64 : 32);
851
+ this._procField("timescale", "uint", 32);
852
+ this._procField("duration", "uint", this.version == 1 ? 64 : 32);
853
+ this._procField("rate", "template", 32);
854
+ this._procField("volume", "template", 16);
855
+ this._procField("reserved1", "uint", 16);
856
+ this._procFieldArray("reserved2", 2, "uint", 32);
857
+ this._procFieldArray("matrix", 9, "template", 32);
858
+ this._procFieldArray("pre_defined", 6, "uint", 32);
859
+ this._procField("next_track_ID", "uint", 32);
860
+ };
861
+ ISOBox.prototype._boxProcessors["payl"] = function() {
862
+ this._procField("cue_text", "utf8");
863
+ };
864
+ ISOBox.prototype._boxProcessors["prft"] = function() {
865
+ this._procFullBox();
866
+ this._procField("reference_track_ID", "uint", 32);
867
+ this._procField("ntp_timestamp_sec", "uint", 32);
868
+ this._procField("ntp_timestamp_frac", "uint", 32);
869
+ this._procField("media_time", "uint", this.version == 1 ? 64 : 32);
870
+ };
871
+ ISOBox.prototype._boxProcessors["prsl"] = function() {
872
+ this._procFullBox();
873
+ this._procField("group_id", "uint", 32);
874
+ this._procField("num_entities_in_group", "uint", 32);
875
+ this._procEntries("entities", this.num_entities_in_group, function(entry) {
876
+ this._procEntryField(entry, "entity_id", "uint", 32);
877
+ });
878
+ if (this.flags & 4096) this._procField("preselection_tag", "utf8string");
879
+ if (this.flags & 8192) this._procField("selection_priority", "uint", 8);
880
+ if (this.flags & 16384) this._procField("interleaving_tag", "utf8string");
881
+ };
882
+ ISOBox.prototype._boxProcessors["pssh"] = function() {
883
+ this._procFullBox();
884
+ this._procFieldArray("SystemID", 16, "uint", 8);
885
+ this._procField("DataSize", "uint", 32);
886
+ this._procFieldArray("Data", this.DataSize, "uint", 8);
887
+ };
888
+ ISOBox.prototype._boxProcessors["schm"] = function() {
889
+ this._procFullBox();
890
+ this._procField("scheme_type", "uint", 32);
891
+ this._procField("scheme_version", "uint", 32);
892
+ if (this.flags & 1) {
893
+ this._procField("scheme_uri", "string", -1);
894
+ }
895
+ };
896
+ ISOBox.prototype._boxProcessors["sdtp"] = function() {
897
+ this._procFullBox();
898
+ var sample_count = -1;
899
+ if (this._parsing) {
900
+ sample_count = this._raw.byteLength - (this._cursor.offset - this._raw.byteOffset);
901
+ }
902
+ this._procFieldArray("sample_dependency_table", sample_count, "uint", 8);
903
+ };
904
+ ISOBox.prototype._boxProcessors["sidx"] = function() {
905
+ this._procFullBox();
906
+ this._procField("reference_ID", "uint", 32);
907
+ this._procField("timescale", "uint", 32);
908
+ this._procField("earliest_presentation_time", "uint", this.version == 1 ? 64 : 32);
909
+ this._procField("first_offset", "uint", this.version == 1 ? 64 : 32);
910
+ this._procField("reserved", "uint", 16);
911
+ this._procField("reference_count", "uint", 16);
912
+ this._procEntries("references", this.reference_count, function(entry) {
913
+ if (!this._parsing) {
914
+ entry.reference = (entry.reference_type & 1) << 31;
915
+ entry.reference |= entry.referenced_size & 2147483647;
916
+ entry.sap = (entry.starts_with_SAP & 1) << 31;
917
+ entry.sap |= (entry.SAP_type & 3) << 28;
918
+ entry.sap |= entry.SAP_delta_time & 268435455;
919
+ }
920
+ this._procEntryField(entry, "reference", "uint", 32);
921
+ this._procEntryField(entry, "subsegment_duration", "uint", 32);
922
+ this._procEntryField(entry, "sap", "uint", 32);
923
+ if (this._parsing) {
924
+ entry.reference_type = entry.reference >> 31 & 1;
925
+ entry.referenced_size = entry.reference & 2147483647;
926
+ entry.starts_with_SAP = entry.sap >> 31 & 1;
927
+ entry.SAP_type = entry.sap >> 28 & 7;
928
+ entry.SAP_delta_time = entry.sap & 268435455;
929
+ }
930
+ });
931
+ };
932
+ ISOBox.prototype._boxProcessors["smhd"] = function() {
933
+ this._procFullBox();
934
+ this._procField("balance", "uint", 16);
935
+ this._procField("reserved", "uint", 16);
936
+ };
937
+ ISOBox.prototype._boxProcessors["ssix"] = function() {
938
+ this._procFullBox();
939
+ this._procField("subsegment_count", "uint", 32);
940
+ this._procEntries("subsegments", this.subsegment_count, function(subsegment) {
941
+ this._procEntryField(subsegment, "ranges_count", "uint", 32);
942
+ this._procSubEntries(subsegment, "ranges", subsegment.ranges_count, function(range) {
943
+ this._procEntryField(range, "level", "uint", 8);
944
+ this._procEntryField(range, "range_size", "uint", 24);
945
+ });
946
+ });
947
+ };
948
+ ISOBox.prototype._boxProcessors["stsd"] = function() {
949
+ this._procFullBox();
950
+ this._procField("entry_count", "uint", 32);
951
+ this._procSubBoxes("entries", this.entry_count);
952
+ };
953
+ ISOBox.prototype._boxProcessors["sttg"] = function() {
954
+ this._procField("settings", "utf8");
955
+ };
956
+ ISOBox.prototype._boxProcessors["stts"] = function() {
957
+ this._procFullBox();
958
+ this._procField("entry_count", "uint", 32);
959
+ this._procEntries("entries", this.entry_count, function(entry) {
960
+ this._procEntryField(entry, "sample_count", "uint", 32);
961
+ this._procEntryField(entry, "sample_delta", "uint", 32);
962
+ });
963
+ };
964
+ ISOBox.prototype._boxProcessors["subs"] = function() {
965
+ this._procFullBox();
966
+ this._procField("entry_count", "uint", 32);
967
+ this._procEntries("entries", this.entry_count, function(entry) {
968
+ this._procEntryField(entry, "sample_delta", "uint", 32);
969
+ this._procEntryField(entry, "subsample_count", "uint", 16);
970
+ this._procSubEntries(entry, "subsamples", entry.subsample_count, function(subsample) {
971
+ this._procEntryField(subsample, "subsample_size", "uint", this.version === 1 ? 32 : 16);
972
+ this._procEntryField(subsample, "subsample_priority", "uint", 8);
973
+ this._procEntryField(subsample, "discardable", "uint", 8);
974
+ this._procEntryField(subsample, "codec_specific_parameters", "uint", 32);
975
+ });
976
+ });
977
+ };
978
+ ISOBox.prototype._boxProcessors["tenc"] = function() {
979
+ this._procFullBox();
980
+ this._procField("default_IsEncrypted", "uint", 24);
981
+ this._procField("default_IV_size", "uint", 8);
982
+ this._procFieldArray("default_KID", 16, "uint", 8);
983
+ };
984
+ ISOBox.prototype._boxProcessors["tfdt"] = function() {
985
+ this._procFullBox();
986
+ this._procField("baseMediaDecodeTime", "uint", this.version == 1 ? 64 : 32);
987
+ };
988
+ ISOBox.prototype._boxProcessors["tfhd"] = function() {
989
+ this._procFullBox();
990
+ this._procField("track_ID", "uint", 32);
991
+ if (this.flags & 1) this._procField("base_data_offset", "uint", 64);
992
+ if (this.flags & 2) this._procField("sample_description_offset", "uint", 32);
993
+ if (this.flags & 8) this._procField("default_sample_duration", "uint", 32);
994
+ if (this.flags & 16) this._procField("default_sample_size", "uint", 32);
995
+ if (this.flags & 32) this._procField("default_sample_flags", "uint", 32);
996
+ };
997
+ ISOBox.prototype._boxProcessors["tfra"] = function() {
998
+ this._procFullBox();
999
+ this._procField("track_ID", "uint", 32);
1000
+ if (!this._parsing) {
1001
+ this.reserved = 0;
1002
+ this.reserved |= (this.length_size_of_traf_num & 48) << 4;
1003
+ this.reserved |= (this.length_size_of_trun_num & 12) << 2;
1004
+ this.reserved |= this.length_size_of_sample_num & 3;
1005
+ }
1006
+ this._procField("reserved", "uint", 32);
1007
+ if (this._parsing) {
1008
+ this.length_size_of_traf_num = (this.reserved & 48) >> 4;
1009
+ this.length_size_of_trun_num = (this.reserved & 12) >> 2;
1010
+ this.length_size_of_sample_num = this.reserved & 3;
1011
+ }
1012
+ this._procField("number_of_entry", "uint", 32);
1013
+ this._procEntries("entries", this.number_of_entry, function(entry) {
1014
+ this._procEntryField(entry, "time", "uint", this.version === 1 ? 64 : 32);
1015
+ this._procEntryField(entry, "moof_offset", "uint", this.version === 1 ? 64 : 32);
1016
+ this._procEntryField(entry, "traf_number", "uint", (this.length_size_of_traf_num + 1) * 8);
1017
+ this._procEntryField(entry, "trun_number", "uint", (this.length_size_of_trun_num + 1) * 8);
1018
+ this._procEntryField(entry, "sample_number", "uint", (this.length_size_of_sample_num + 1) * 8);
1019
+ });
1020
+ };
1021
+ ISOBox.prototype._boxProcessors["tkhd"] = function() {
1022
+ this._procFullBox();
1023
+ this._procField("creation_time", "uint", this.version == 1 ? 64 : 32);
1024
+ this._procField("modification_time", "uint", this.version == 1 ? 64 : 32);
1025
+ this._procField("track_ID", "uint", 32);
1026
+ this._procField("reserved1", "uint", 32);
1027
+ this._procField("duration", "uint", this.version == 1 ? 64 : 32);
1028
+ this._procFieldArray("reserved2", 2, "uint", 32);
1029
+ this._procField("layer", "uint", 16);
1030
+ this._procField("alternate_group", "uint", 16);
1031
+ this._procField("volume", "template", 16);
1032
+ this._procField("reserved3", "uint", 16);
1033
+ this._procFieldArray("matrix", 9, "template", 32);
1034
+ this._procField("width", "template", 32);
1035
+ this._procField("height", "template", 32);
1036
+ };
1037
+ ISOBox.prototype._boxProcessors["trex"] = function() {
1038
+ this._procFullBox();
1039
+ this._procField("track_ID", "uint", 32);
1040
+ this._procField("default_sample_description_index", "uint", 32);
1041
+ this._procField("default_sample_duration", "uint", 32);
1042
+ this._procField("default_sample_size", "uint", 32);
1043
+ this._procField("default_sample_flags", "uint", 32);
1044
+ };
1045
+ ISOBox.prototype._boxProcessors["trun"] = function() {
1046
+ this._procFullBox();
1047
+ this._procField("sample_count", "uint", 32);
1048
+ if (this.flags & 1) this._procField("data_offset", "int", 32);
1049
+ if (this.flags & 4) this._procField("first_sample_flags", "uint", 32);
1050
+ this._procEntries("samples", this.sample_count, function(sample) {
1051
+ if (this.flags & 256) this._procEntryField(sample, "sample_duration", "uint", 32);
1052
+ if (this.flags & 512) this._procEntryField(sample, "sample_size", "uint", 32);
1053
+ if (this.flags & 1024) this._procEntryField(sample, "sample_flags", "uint", 32);
1054
+ if (this.flags & 2048) this._procEntryField(sample, "sample_composition_time_offset", this.version === 1 ? "int" : "uint", 32);
1055
+ });
1056
+ };
1057
+ ISOBox.prototype._boxProcessors["url "] = ISOBox.prototype._boxProcessors["urn "] = function() {
1058
+ this._procFullBox();
1059
+ if (this.type === "urn ") {
1060
+ this._procField("name", "string", -1);
1061
+ }
1062
+ this._procField("location", "string", -1);
1063
+ };
1064
+ ISOBox.prototype._boxProcessors["vlab"] = function() {
1065
+ this._procField("source_label", "utf8");
1066
+ };
1067
+ ISOBox.prototype._boxProcessors["vmhd"] = function() {
1068
+ this._procFullBox();
1069
+ this._procField("graphicsmode", "uint", 16);
1070
+ this._procFieldArray("opcolor", 3, "uint", 16);
1071
+ };
1072
+ ISOBox.prototype._boxProcessors["vttC"] = function() {
1073
+ this._procField("config", "utf8");
1074
+ };
1075
+ ISOBox.prototype._boxProcessors["vtte"] = function() {
1076
+ };
1077
+ }
1078
+ });
1079
+
1080
+ // src/constants/isobmff_box_names.js
1081
+ var MOVIE = "moov";
1082
+ var TRACK = "trak";
1083
+ var TRACK_HEADER = "tkhd";
1084
+ var META = "meta";
1085
+ var GROUPS_LIST = "grpl";
1086
+ var PRESELECTION_GROUP = "prsl";
1087
+ var USER_DATA = "udta";
1088
+ var DIALOG_PROCESSING = "diap";
1089
+ var EXTENDED_LANGUAGE_TAG = "elng";
1090
+ var AUDIO_RENDERING_INDICATION = "ardi";
1091
+ var LABEL = "labl";
1092
+ var KIND = "kind";
1093
+ var MOVIE_FRAGMENT = "moof";
1094
+ var TRACK_FRAGMENT = "traf";
1095
+ var TRACK_FRAGMENT_HEADER = "tfhd";
1096
+ var TRACK_FRAGMENT_RUN = "trun";
1097
+
1098
+ // src/constants/toc_elements.js
1099
+ var B_PRESENTATION_ID = "b_presentation_id";
1100
+ var PRESENTATION_ID = "presentation_id";
1101
+ var PRESENTATION_LEVEL = "presentation_level";
1102
+ var PAYLOAD_BASE_MINUS1 = "payload_base_minus1";
1103
+ var BYTE_ALIGNMENT = "byte_alignment";
1104
+ var AC4_TOC_END = "ac4_toc_end";
1105
+
1106
+ // src/bitwise_operations.js
1107
+ var shiftLeft = (data, offset, width, shift) => {
1108
+ const startByte = offset >> 3;
1109
+ const endByte = offset + width - 1 >> 3;
1110
+ const startBit = offset & 7;
1111
+ const endBit = offset + width - 1 & 7;
1112
+ const startMask = 255 >> startBit;
1113
+ const endMask = 255 << 7 - endBit & 255;
1114
+ let shiftAcc = 0;
1115
+ for (let i = endByte; i >= startByte; i--) {
1116
+ const currByte = data.getUint8(i);
1117
+ let mask = 255;
1118
+ if (i === startByte) {
1119
+ mask &= startMask;
1120
+ }
1121
+ if (i === endByte) {
1122
+ mask &= endMask;
1123
+ }
1124
+ const clearedByte = currByte & ~mask;
1125
+ const maskedCurrByte = currByte & mask;
1126
+ shiftAcc = (maskedCurrByte << shift) + shiftAcc;
1127
+ const shiftedCurrByte = clearedByte | shiftAcc & 255 & mask;
1128
+ shiftAcc >>= 8;
1129
+ data.setUint8(i, shiftedCurrByte);
1130
+ }
1131
+ return data;
1132
+ };
1133
+ var setBits = (data, offset, width, value) => {
1134
+ const byteOffset = offset >>> 3;
1135
+ const bitOffset = offset & 7;
1136
+ const mask = (1 << width) - 1 << 16 - width >> bitOffset;
1137
+ let word = data.getUint8(byteOffset) << 8 | data.getUint8(byteOffset + 1);
1138
+ word &= ~mask;
1139
+ word |= value << 16 - width - bitOffset;
1140
+ data.setUint8(byteOffset, word >>> 8);
1141
+ data.setUint8(byteOffset + 1, word & 255);
1142
+ };
1143
+
1144
+ // src/get_sample_offsets.js
1145
+ var getSampleOffsets = (parsedBuffer) => {
1146
+ const sampleOffsets = [];
1147
+ const DEFAULT_BASE_IS_MOOF_FLAG_OFFSET = 131072;
1148
+ const movieFragment = parsedBuffer.fetch(MOVIE_FRAGMENT);
1149
+ let isFirstTrackFragment = true;
1150
+ for (const trackFragment of parsedBuffer.fetchAll(TRACK_FRAGMENT)) {
1151
+ const trackFragmentHeader = trackFragment.boxes.find((box) => box.type === TRACK_FRAGMENT_HEADER);
1152
+ const baseDataOffset = trackFragmentHeader.base_data_offset || 0;
1153
+ const defaultBaseIsMoof = trackFragmentHeader.flags & DEFAULT_BASE_IS_MOOF_FLAG_OFFSET;
1154
+ if (baseDataOffset) {
1155
+ throw Error(
1156
+ "base_data_offset is relative to the file identified by the referenced data reference entry unsupported"
1157
+ );
1158
+ }
1159
+ if (!defaultBaseIsMoof) {
1160
+ if (isFirstTrackFragment) {
1161
+ throw Error(
1162
+ "base_data_offset is relative to the first byte of the MovieFragmentBox containing this box unsupported"
1163
+ );
1164
+ }
1165
+ throw Error(
1166
+ "base_data_offset is relative to the end of the data defined by the preceding track fragment is unsupported"
1167
+ );
1168
+ }
1169
+ const relative = movieFragment._offset;
1170
+ for (const trackFragmentRun of trackFragment.boxes.filter((box) => box.type === TRACK_FRAGMENT_RUN)) {
1171
+ let sampleOffset = relative + baseDataOffset + trackFragmentRun.data_offset;
1172
+ for (const sample of trackFragmentRun.samples) {
1173
+ sampleOffsets.push({ offset: sampleOffset, size: sample.sample_size });
1174
+ sampleOffset += sample.sample_size;
1175
+ }
1176
+ }
1177
+ isFirstTrackFragment = false;
1178
+ }
1179
+ return sampleOffsets;
1180
+ };
1181
+
1182
+ // src/ac4_toc_parser_wrapper/bitsource.js
1183
+ var BitSource = class {
1184
+ /**
1185
+ * Create the BitSource
1186
+ * @param {Iterator<number>} iterator - an iterator object
1187
+ */
1188
+ constructor(iterator) {
1189
+ this.iterator = iterator;
1190
+ this.cache = 0;
1191
+ this.bitsLeft = 0;
1192
+ }
1193
+ /**
1194
+ * This function reads n-bit value from the source, where "n" is the specified width.
1195
+ *
1196
+ * It works by keeping a 32 bit wide cache.
1197
+ * In the cache, the next bits are "left/top aligned".
1198
+ * That is to say, to read the next three bits, you take the three most significant bits.
1199
+ * This can be accomplished by right-shifting the cache by 32-3=29 bits, taking care that it is an unsigned shift and no sign extension takes place.
1200
+ * To "expel" the read bits from the cache, simple left-shift the cache by 3 bits.
1201
+ *
1202
+ * Before any bits are read from the cache, it needs to be filled.
1203
+ * We check if more bits are needed, and whether at least 8 can be filled in. If so, do it.
1204
+ * This means that the cache contains 25 bits at a minimum after it is filled.
1205
+ * Therefore, 25 bits are the most bits that the reader can deliver. We don't check for end of stream in the bit reader. That is better delegated elsewhere.
1206
+ *
1207
+ * @summary Get a value of specified width from the bit source
1208
+ *
1209
+ * @param {string} varname - Name of the variable being read (it serves only logging purposes)
1210
+ * @param {number} bitsWidth - Width of the value to be read (maximum 25 bits)
1211
+ * @returns {number} The value read from the bit source
1212
+ */
1213
+ get(varname, bitsWidth) {
1214
+ const MAX_SHIFT = 24;
1215
+ const MAX_SUPPORTED_WIDTH = 25;
1216
+ const BYTE_SIZE = 8;
1217
+ const INT_SIZE = 32;
1218
+ if (bitsWidth > MAX_SUPPORTED_WIDTH) {
1219
+ }
1220
+ let width = bitsWidth;
1221
+ while (this.bitsLeft < width) {
1222
+ const nextByte = this.iterator.next();
1223
+ const nextByteShift = MAX_SHIFT - this.bitsLeft;
1224
+ this.cache |= nextByte.value << nextByteShift;
1225
+ this.bitsLeft += BYTE_SIZE;
1226
+ if (width > MAX_SUPPORTED_WIDTH) {
1227
+ this.cache <<= BYTE_SIZE;
1228
+ this.bitsLeft -= BYTE_SIZE;
1229
+ width -= BYTE_SIZE;
1230
+ }
1231
+ }
1232
+ const readValue = this.cache >>> INT_SIZE - width;
1233
+ this.cache <<= width;
1234
+ this.bitsLeft -= width;
1235
+ return readValue;
1236
+ }
1237
+ /**
1238
+ * Get bits needed for byte alignment
1239
+ *
1240
+ * @param {number} numberOfBits - Number of bits to align
1241
+ * @returns {number} The value read for alignment
1242
+ */
1243
+ get_align(numberOfBits) {
1244
+ return this.get("align", numberOfBits);
1245
+ }
1246
+ };
1247
+
1248
+ // src/ac4_toc_parser_wrapper/filtersink.js
1249
+ var FilterSink = class {
1250
+ /**
1251
+ * Create the Filter Sink
1252
+ * @param {string[]} elements - The AC-4 TOC elements to be filtered
1253
+ * @param {sinkCallback} callback - The callback function to be called for filtered elements
1254
+ */
1255
+ constructor(elements, callback) {
1256
+ this.elements = elements;
1257
+ this.callback = callback;
1258
+ }
1259
+ /**
1260
+ * Called before calling embedded BSDL function
1261
+ * @param {string} _fname - name of the BSDL function
1262
+ * @param {unknown} _params - parameters passed to the BSDL function
1263
+ * @param {string} name - name of the AC-4 TOC element
1264
+ * @param {number} position - position read before calling embedded BSDL function
1265
+ */
1266
+ before_call(_fname, _params, name, position) {
1267
+ if (this.elements.includes(name)) {
1268
+ this.callback(name, null, null, position, "before_call");
1269
+ }
1270
+ }
1271
+ /**
1272
+ * Called after calling embedded BSDL function. The position is written after field is read
1273
+ * @param {string} _fname - name of the BSDL function
1274
+ * @param {number} value - value returned by the BSDL function
1275
+ * @param {string} name - name of the AC-4 TOC element
1276
+ * @param {number} position - position read after calling embedded BSDL function
1277
+ */
1278
+ after_call(_fname, value, name, position) {
1279
+ if (this.elements.includes(name)) {
1280
+ this.callback(name, value, null, position, "after_call");
1281
+ }
1282
+ }
1283
+ /**
1284
+ * Called when assigning a variable.
1285
+ * @param {string} name - name of the AC-4 TOC element
1286
+ * @param {number} width - width of the AC-4 TOC element
1287
+ * @param {number} value - value of the AC-4 TOC element
1288
+ * @param {number} position - position of the AC-4 TOC element
1289
+ */
1290
+ write_uint(name, width, value, position) {
1291
+ if (this.elements.includes(name)) {
1292
+ this.callback(name, value, width, position);
1293
+ }
1294
+ }
1295
+ /**
1296
+ * Called when assigning byte alignment to a variable.
1297
+ * @param {number} width - width of the byte alignment field
1298
+ * @param {number} value - value of byte alignment field
1299
+ */
1300
+ write_align(width, value) {
1301
+ if (this.elements.includes(BYTE_ALIGNMENT)) {
1302
+ this.callback(BYTE_ALIGNMENT, value, width, null, "write_align");
1303
+ }
1304
+ }
1305
+ /**
1306
+ * Called after BSDL position() call to obtain bit position
1307
+ * @param {string} name - name of the variable that the position will be assigned to
1308
+ * @param {number} position - obtained position
1309
+ */
1310
+ after_position(name, position) {
1311
+ if (this.elements.includes(name)) {
1312
+ this.callback(name, null, null, position, "after_position");
1313
+ }
1314
+ }
1315
+ };
1316
+
1317
+ // src/ac4_toc_parser.js
1318
+ var ParseError = class extends Error {
1319
+ };
1320
+ var Parser = class {
1321
+ constructor(BAM_source, BAM_sink) {
1322
+ // Class field declarations
1323
+ __publicField(this, "v", null);
1324
+ __publicField(this, "content_classifier", null);
1325
+ __publicField(this, "i", null);
1326
+ __publicField(this, "frame_rate_factor", null);
1327
+ __publicField(this, "bk_substream_index", null);
1328
+ __publicField(this, "a_substream_indices", null);
1329
+ __publicField(this, "last_referenced_substream", null);
1330
+ __publicField(this, "referenced_substreams", null);
1331
+ __publicField(this, "protection_bits_primary_bits", null);
1332
+ __publicField(this, "protection_bits_secondary_bits", null);
1333
+ __publicField(this, "toc_i", null);
1334
+ __publicField(this, "OAMD_OBJECT_TYPE_BED", null);
1335
+ __publicField(this, "OAMD_OBJECT_TYPE_ISF", null);
1336
+ __publicField(this, "OAMD_OBJECT_TYPE_DYNAMIC", null);
1337
+ __publicField(this, "OAMD_OBJECT_TYPE_RESERVED", null);
1338
+ __publicField(this, "toc_j", null);
1339
+ __publicField(this, "vb", null);
1340
+ __publicField(this, "presentation_to_groups", null);
1341
+ __publicField(this, "group_frame_rate_factor", null);
1342
+ __publicField(this, "b_hsf_ext", null);
1343
+ __publicField(this, "b_single_substream", null);
1344
+ __publicField(this, "n_bed_objects", null);
1345
+ __publicField(this, "a_num_bed_objects", null);
1346
+ __publicField(this, "b_bed_objects_prev", null);
1347
+ __publicField(this, "num_lfe", null);
1348
+ __publicField(this, "n", null);
1349
+ __publicField(this, "n_skip_bytes", null);
1350
+ __publicField(this, "b_more_skip_bytes", null);
1351
+ __publicField(this, "n_bits_read_0", null);
1352
+ __publicField(this, "n_bits_read_1", null);
1353
+ __publicField(this, "n_bits_read", null);
1354
+ __publicField(this, "n_skip_bits", null);
1355
+ __publicField(this, "reserved", null);
1356
+ __publicField(this, "padding", null);
1357
+ __publicField(this, "CHANNEL_MODE_MONO", null);
1358
+ __publicField(this, "CHANNEL_MODE_STEREO", null);
1359
+ __publicField(this, "CHANNEL_MODE_30", null);
1360
+ __publicField(this, "CHANNEL_MODE_50", null);
1361
+ __publicField(this, "CHANNEL_MODE_51", null);
1362
+ __publicField(this, "CHANNEL_MODE_70_34", null);
1363
+ __publicField(this, "CHANNEL_MODE_71_34", null);
1364
+ __publicField(this, "CHANNEL_MODE_70_52", null);
1365
+ __publicField(this, "CHANNEL_MODE_71_52", null);
1366
+ __publicField(this, "CHANNEL_MODE_70_322", null);
1367
+ __publicField(this, "CHANNEL_MODE_71_322", null);
1368
+ __publicField(this, "CHANNEL_MODE_704", null);
1369
+ __publicField(this, "CHANNEL_MODE_714", null);
1370
+ __publicField(this, "CHANNEL_MODE_904", null);
1371
+ __publicField(this, "CHANNEL_MODE_914", null);
1372
+ __publicField(this, "CHANNEL_MODE_222", null);
1373
+ __publicField(this, "presentation_config", null);
1374
+ __publicField(this, "presentation_version", null);
1375
+ __publicField(this, "b_add_emdf_substreams", null);
1376
+ __publicField(this, "presentation_level", null);
1377
+ __publicField(this, "b_presentation_id", null);
1378
+ __publicField(this, "presentation_id", null);
1379
+ __publicField(this, "b_pre_virtualized", null);
1380
+ __publicField(this, "n_add_emdf_substreams", null);
1381
+ __publicField(this, "pi_i", null);
1382
+ __publicField(this, "b_single_substream_group", null);
1383
+ __publicField(this, "b_presentation_filter", null);
1384
+ __publicField(this, "b_enable_presentation", null);
1385
+ __publicField(this, "n_substream_groups", null);
1386
+ __publicField(this, "b_multi_pid", null);
1387
+ __publicField(this, "n_substream_groups_minus2", null);
1388
+ __publicField(this, "sg", null);
1389
+ __publicField(this, "bitstream_version", null);
1390
+ __publicField(this, "fs_index", null);
1391
+ __publicField(this, "frame_rate_index", null);
1392
+ __publicField(this, "BAM_g_position", 0);
1393
+ __publicField(this, "BAM_g_table0", [0, 2, 4, 6]);
1394
+ __publicField(this, "BAM_g_table1", [252, 253, 508, 509]);
1395
+ __publicField(this, "BAM_g_table2", [122, 123, 124, 125]);
1396
+ __publicField(this, "BAM_g_table3", [252, 253, 508, 509]);
1397
+ __publicField(this, "BAM_g_table4", [4, 6, 8, 10, 12, 14]);
1398
+ __publicField(this, "BAM_g_table5", [122, 123, 124, 125]);
1399
+ __publicField(this, "BAM_g_table6", [0, 0]);
1400
+ __publicField(this, "BAM_g_table7", [0, 1, 2, 3, 5, 0, 0, 0]);
1401
+ __publicField(this, "BAM_g_table8", [2, 3, 6, 8, 10, 8, 10, 12]);
1402
+ __publicField(this, "BAM_g_table9", [2, 1, 1, 2, 2, 2, 2, 2, 2, 1]);
1403
+ __publicField(this, "BAM_g_table10", [4, 8, 10, 14, 15, 30, -1, -1]);
1404
+ __publicField(this, "BAM_g_table11", [2, 3, 4, 5, 6, 7]);
1405
+ __publicField(this, "BAM_g_table12", [2, 1, 1, 2, 2, 2, 2, 2, 2, 1]);
1406
+ __publicField(this, "BAM_g_table13", [1920, 1920, 2048, 1536, 1536, 960, 960, 1024, 768, 768, 512, 384, 384, 2048]);
1407
+ __publicField(this, "BAM_g_table14", [2, 3, 4]);
1408
+ __publicField(this, "BAM_g_table15", { 0: 2, 1: 4 });
1409
+ __publicField(this, "BAM_g_table16", [0, 1, 7, 8, 9]);
1410
+ __publicField(this, "BAM_g_table17", { 0: 1, 1: 2 });
1411
+ __publicField(this, "BAM_g_table18", [5, 6, 7, 8, 9]);
1412
+ __publicField(this, "BAM_g_table19", [10, 11, 12]);
1413
+ this.BAM_source = BAM_source;
1414
+ this.BAM_sink = BAM_sink;
1415
+ }
1416
+ F_channel_mode_contains_LFE(cm) {
1417
+ {
1418
+ if (cm == this.CHANNEL_MODE_51 || cm == this.CHANNEL_MODE_71_34 || cm == this.CHANNEL_MODE_71_52 || cm == this.CHANNEL_MODE_71_322) {
1419
+ return 1;
1420
+ } else {
1421
+ return 0;
1422
+ }
1423
+ }
1424
+ }
1425
+ F_bitrate_indicator() {
1426
+ var bi;
1427
+ var factor;
1428
+ {
1429
+ {
1430
+ bi = this.BAM_source.get("", 3);
1431
+ this.BAM_g_position += 3;
1432
+ }
1433
+ if (this.BAM_g_table0.slice(0).indexOf(bi) >= 0) {
1434
+ {
1435
+ bi = bi >> 1;
1436
+ }
1437
+ } else {
1438
+ {
1439
+ {
1440
+ this.v = this.BAM_source.get("", 2);
1441
+ this.BAM_g_position += 2;
1442
+ }
1443
+ {
1444
+ this.v = (bi << 2) + this.v;
1445
+ }
1446
+ {
1447
+ factor = Math.floor(this.v / 8);
1448
+ }
1449
+ {
1450
+ bi = this.v - factor * 4;
1451
+ }
1452
+ }
1453
+ }
1454
+ }
1455
+ }
1456
+ F_content_type() {
1457
+ var b_serialized_language_tag;
1458
+ var n_language_tag_bytes;
1459
+ var language_tag_chunk;
1460
+ var language_tag_bytes;
1461
+ var b_language_indicator;
1462
+ var b_start_tag;
1463
+ {
1464
+ {
1465
+ this.content_classifier = this.BAM_source.get("", 3);
1466
+ this.BAM_g_position += 3;
1467
+ }
1468
+ {
1469
+ b_language_indicator = this.BAM_source.get("", 1);
1470
+ this.BAM_g_position += 1;
1471
+ }
1472
+ if (b_language_indicator) {
1473
+ {
1474
+ {
1475
+ b_serialized_language_tag = this.BAM_source.get("", 1);
1476
+ this.BAM_g_position += 1;
1477
+ }
1478
+ if (b_serialized_language_tag) {
1479
+ {
1480
+ {
1481
+ b_start_tag = this.BAM_source.get("", 1);
1482
+ this.BAM_g_position += 1;
1483
+ }
1484
+ {
1485
+ language_tag_chunk = this.BAM_source.get("", 16);
1486
+ this.BAM_g_position += 16;
1487
+ }
1488
+ }
1489
+ } else {
1490
+ {
1491
+ {
1492
+ n_language_tag_bytes = this.BAM_source.get("", 6);
1493
+ this.BAM_g_position += 6;
1494
+ }
1495
+ for (this.i = 0; this.i < n_language_tag_bytes; this.i++) {
1496
+ {
1497
+ language_tag_bytes = this.BAM_source.get("", 8);
1498
+ this.BAM_g_position += 8;
1499
+ }
1500
+ }
1501
+ }
1502
+ }
1503
+ }
1504
+ }
1505
+ }
1506
+ }
1507
+ F_ac4_substream_info_chan(asio_group_index, asio_gs_index, asio_b_substreams_present_chan) {
1508
+ var substream_index;
1509
+ var b_sf_multiplier;
1510
+ var b_bitrate_info;
1511
+ var si_ch_mode;
1512
+ var si_channel_mode;
1513
+ var top_channels_present;
1514
+ var b_4_back_channels_present;
1515
+ var si_b_iframe;
1516
+ var b_center_present;
1517
+ var b_lfe = null;
1518
+ var b_lfe;
1519
+ var sf_multiplier;
1520
+ var add_ch_base;
1521
+ {
1522
+ {
1523
+ this.F_define_channel_modes();
1524
+ }
1525
+ {
1526
+ this.F_define_oamd();
1527
+ }
1528
+ {
1529
+ si_channel_mode = this.F_channel_mode();
1530
+ if (si_channel_mode == null) {
1531
+ throw ParseError("F_channel_mode", "expected to return a value, returned None");
1532
+ }
1533
+ }
1534
+ if (si_channel_mode == 511) {
1535
+ {
1536
+ {
1537
+ this.v = this.F_variable_bits(2);
1538
+ if (this.v == null) {
1539
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
1540
+ }
1541
+ }
1542
+ {
1543
+ si_channel_mode += this.v;
1544
+ }
1545
+ }
1546
+ }
1547
+ if (this.BAM_g_table1.slice(0).indexOf(si_channel_mode) >= 0) {
1548
+ {
1549
+ {
1550
+ b_4_back_channels_present = this.BAM_source.get("", 1);
1551
+ this.BAM_g_position += 1;
1552
+ }
1553
+ {
1554
+ b_center_present = this.BAM_source.get("", 1);
1555
+ this.BAM_g_position += 1;
1556
+ }
1557
+ {
1558
+ top_channels_present = this.BAM_source.get("", 2);
1559
+ this.BAM_g_position += 2;
1560
+ }
1561
+ }
1562
+ }
1563
+ if (this.fs_index == 1) {
1564
+ {
1565
+ {
1566
+ b_sf_multiplier = this.BAM_source.get("", 1);
1567
+ this.BAM_g_position += 1;
1568
+ }
1569
+ if (b_sf_multiplier) {
1570
+ {
1571
+ sf_multiplier = this.BAM_source.get("", 1);
1572
+ this.BAM_g_position += 1;
1573
+ }
1574
+ }
1575
+ }
1576
+ }
1577
+ {
1578
+ b_bitrate_info = this.BAM_source.get("", 1);
1579
+ this.BAM_g_position += 1;
1580
+ }
1581
+ if (b_bitrate_info) {
1582
+ {
1583
+ this.F_bitrate_indicator();
1584
+ }
1585
+ }
1586
+ if (this.BAM_g_table2.slice(0).indexOf(si_channel_mode) >= 0) {
1587
+ {
1588
+ add_ch_base = this.BAM_source.get("", 1);
1589
+ this.BAM_g_position += 1;
1590
+ }
1591
+ }
1592
+ {
1593
+ this.frame_rate_factor = this.group_frame_rate_factor[asio_group_index];
1594
+ }
1595
+ for (this.i = 0; this.i < this.frame_rate_factor; this.i++) {
1596
+ {
1597
+ si_b_iframe = this.BAM_source.get("", 1);
1598
+ this.BAM_g_position += 1;
1599
+ }
1600
+ }
1601
+ if (asio_b_substreams_present_chan == 1) {
1602
+ {
1603
+ {
1604
+ substream_index = this.BAM_source.get("", 2);
1605
+ this.BAM_g_position += 2;
1606
+ }
1607
+ if (substream_index == 3) {
1608
+ {
1609
+ {
1610
+ this.v = this.F_variable_bits(2);
1611
+ if (this.v == null) {
1612
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
1613
+ }
1614
+ }
1615
+ {
1616
+ substream_index += this.v;
1617
+ }
1618
+ }
1619
+ }
1620
+ }
1621
+ } else {
1622
+ {
1623
+ {
1624
+ substream_index = this.bk_substream_index;
1625
+ }
1626
+ {
1627
+ this.bk_substream_index = this.bk_substream_index + 1;
1628
+ }
1629
+ }
1630
+ }
1631
+ {
1632
+ this.a_substream_indices.push(substream_index);
1633
+ }
1634
+ for (this.i = 0; this.i < this.frame_rate_factor; this.i++) {
1635
+ {
1636
+ if (asio_b_substreams_present_chan == 1) {
1637
+ {
1638
+ {
1639
+ this.last_referenced_substream = Math.max(this.last_referenced_substream, substream_index + this.i);
1640
+ }
1641
+ {
1642
+ this.referenced_substreams.push(substream_index + this.i);
1643
+ }
1644
+ }
1645
+ }
1646
+ if (this.BAM_g_table3.slice(0).indexOf(si_channel_mode) >= 0) {
1647
+ }
1648
+ {
1649
+ si_ch_mode = this.F_get_ch_mode(si_channel_mode);
1650
+ if (si_ch_mode == null) {
1651
+ throw ParseError("F_get_ch_mode", "expected to return a value, returned None");
1652
+ }
1653
+ }
1654
+ if (this.BAM_g_table4.slice(0).indexOf(si_ch_mode) >= 0) {
1655
+ {
1656
+ if (b_lfe == null) {
1657
+ b_lfe = new Array(substream_index + this.i + 1).fill(0);
1658
+ } else if (b_lfe.length <= substream_index + this.i) {
1659
+ b_lfe.push.apply(b_lfe, new Array(substream_index + this.i - b_lfe.length + 1).fill(0));
1660
+ }
1661
+ b_lfe[substream_index + this.i] = 1;
1662
+ }
1663
+ } else {
1664
+ {
1665
+ if (b_lfe == null) {
1666
+ b_lfe = new Array(substream_index + this.i + 1).fill(0);
1667
+ } else if (b_lfe.length <= substream_index + this.i) {
1668
+ b_lfe.push.apply(b_lfe, new Array(substream_index + this.i - b_lfe.length + 1).fill(0));
1669
+ }
1670
+ b_lfe[substream_index + this.i] = 0;
1671
+ }
1672
+ }
1673
+ }
1674
+ }
1675
+ }
1676
+ }
1677
+ F_channel_mode() {
1678
+ var value;
1679
+ var stereo_channel_mode;
1680
+ {
1681
+ {
1682
+ value = this.BAM_source.get("", 1);
1683
+ this.BAM_g_position += 1;
1684
+ }
1685
+ if (value == 1) {
1686
+ {
1687
+ {
1688
+ this.v = this.BAM_source.get("", 1);
1689
+ this.BAM_g_position += 1;
1690
+ }
1691
+ {
1692
+ value = (value << 1) + this.v;
1693
+ }
1694
+ {
1695
+ stereo_channel_mode = 2;
1696
+ }
1697
+ if (value == 3) {
1698
+ {
1699
+ {
1700
+ this.v = this.BAM_source.get("", 2);
1701
+ this.BAM_g_position += 2;
1702
+ }
1703
+ {
1704
+ value = (value << 2) + this.v;
1705
+ }
1706
+ if (value == 15) {
1707
+ {
1708
+ {
1709
+ this.v = this.BAM_source.get("", 3);
1710
+ this.BAM_g_position += 3;
1711
+ }
1712
+ {
1713
+ value = (value << 3) + this.v;
1714
+ }
1715
+ if (value == 120 || value == 121) {
1716
+ {
1717
+ {
1718
+ stereo_channel_mode = value;
1719
+ }
1720
+ {
1721
+ value = 2;
1722
+ }
1723
+ }
1724
+ }
1725
+ if (value == 126) {
1726
+ {
1727
+ {
1728
+ this.v = this.BAM_source.get("", 1);
1729
+ this.BAM_g_position += 1;
1730
+ }
1731
+ {
1732
+ value = (value << 1) + this.v;
1733
+ }
1734
+ }
1735
+ }
1736
+ if (value == 127) {
1737
+ {
1738
+ {
1739
+ this.v = this.BAM_source.get("", 2);
1740
+ this.BAM_g_position += 2;
1741
+ }
1742
+ {
1743
+ value = (value << 2) + this.v;
1744
+ }
1745
+ }
1746
+ }
1747
+ }
1748
+ }
1749
+ }
1750
+ }
1751
+ }
1752
+ }
1753
+ return value;
1754
+ }
1755
+ }
1756
+ F_ac4_substream_info(si_b_associated, si_b_dialog, si_ps_index) {
1757
+ var substream_index;
1758
+ var si_b_iframe;
1759
+ var b_sf_multiplier;
1760
+ var b_bitrate_info;
1761
+ var b_dialog_content;
1762
+ var si_channel_mode;
1763
+ var b_lfe = null;
1764
+ var b_lfe;
1765
+ var sf_multiplier;
1766
+ var add_ch_base;
1767
+ var b_associated_content;
1768
+ var b_content_type;
1769
+ {
1770
+ {
1771
+ this.F_define_channel_modes();
1772
+ }
1773
+ {
1774
+ si_channel_mode = this.F_channel_mode();
1775
+ if (si_channel_mode == null) {
1776
+ throw ParseError("F_channel_mode", "expected to return a value, returned None");
1777
+ }
1778
+ }
1779
+ if (si_channel_mode == 511) {
1780
+ {
1781
+ {
1782
+ this.v = this.F_variable_bits(2);
1783
+ if (this.v == null) {
1784
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
1785
+ }
1786
+ }
1787
+ {
1788
+ si_channel_mode += this.v;
1789
+ }
1790
+ }
1791
+ }
1792
+ if (this.fs_index == 1) {
1793
+ {
1794
+ {
1795
+ b_sf_multiplier = this.BAM_source.get("", 1);
1796
+ this.BAM_g_position += 1;
1797
+ }
1798
+ if (b_sf_multiplier) {
1799
+ {
1800
+ sf_multiplier = this.BAM_source.get("", 1);
1801
+ this.BAM_g_position += 1;
1802
+ }
1803
+ }
1804
+ }
1805
+ }
1806
+ {
1807
+ b_bitrate_info = this.BAM_source.get("", 1);
1808
+ this.BAM_g_position += 1;
1809
+ }
1810
+ if (b_bitrate_info) {
1811
+ {
1812
+ this.F_bitrate_indicator();
1813
+ }
1814
+ }
1815
+ if (this.BAM_g_table5.slice(0).indexOf(si_channel_mode) >= 0) {
1816
+ {
1817
+ add_ch_base = this.BAM_source.get("", 1);
1818
+ this.BAM_g_position += 1;
1819
+ }
1820
+ }
1821
+ {
1822
+ b_content_type = this.BAM_source.get("", 1);
1823
+ this.BAM_g_position += 1;
1824
+ }
1825
+ if (b_content_type) {
1826
+ {
1827
+ {
1828
+ this.F_content_type();
1829
+ }
1830
+ if (this.content_classifier == 0) {
1831
+ {
1832
+ {
1833
+ b_associated_content = 0;
1834
+ }
1835
+ {
1836
+ b_dialog_content = 0;
1837
+ }
1838
+ }
1839
+ } else if (this.content_classifier == 1) {
1840
+ {
1841
+ {
1842
+ b_associated_content = 0;
1843
+ }
1844
+ {
1845
+ b_dialog_content = 0;
1846
+ }
1847
+ }
1848
+ } else if (this.content_classifier == 2) {
1849
+ {
1850
+ {
1851
+ b_associated_content = 1;
1852
+ }
1853
+ {
1854
+ b_dialog_content = 0;
1855
+ }
1856
+ }
1857
+ } else if (this.content_classifier == 3) {
1858
+ {
1859
+ {
1860
+ b_associated_content = 1;
1861
+ }
1862
+ {
1863
+ b_dialog_content = 0;
1864
+ }
1865
+ }
1866
+ } else if (this.content_classifier == 4) {
1867
+ {
1868
+ {
1869
+ b_associated_content = 0;
1870
+ }
1871
+ {
1872
+ b_dialog_content = 1;
1873
+ }
1874
+ }
1875
+ } else if (this.content_classifier == 5) {
1876
+ {
1877
+ {
1878
+ b_associated_content = 1;
1879
+ }
1880
+ {
1881
+ b_dialog_content = 0;
1882
+ }
1883
+ }
1884
+ } else if (this.content_classifier == 6) {
1885
+ {
1886
+ {
1887
+ b_associated_content = 0;
1888
+ }
1889
+ {
1890
+ b_dialog_content = 0;
1891
+ }
1892
+ }
1893
+ } else if (this.content_classifier == 7) {
1894
+ {
1895
+ {
1896
+ b_associated_content = 0;
1897
+ }
1898
+ {
1899
+ b_dialog_content = 0;
1900
+ }
1901
+ }
1902
+ }
1903
+ }
1904
+ } else {
1905
+ {
1906
+ {
1907
+ b_associated_content = 0;
1908
+ }
1909
+ {
1910
+ b_dialog_content = 0;
1911
+ }
1912
+ }
1913
+ }
1914
+ for (this.i = 0; this.i < this.frame_rate_factor; this.i++) {
1915
+ {
1916
+ si_b_iframe = this.BAM_source.get("", 1);
1917
+ this.BAM_g_position += 1;
1918
+ }
1919
+ }
1920
+ {
1921
+ substream_index = this.BAM_source.get("", 2);
1922
+ this.BAM_g_position += 2;
1923
+ }
1924
+ if (substream_index == 3) {
1925
+ {
1926
+ {
1927
+ this.v = this.F_variable_bits(2);
1928
+ if (this.v == null) {
1929
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
1930
+ }
1931
+ }
1932
+ {
1933
+ substream_index += this.v;
1934
+ }
1935
+ }
1936
+ }
1937
+ {
1938
+ this.a_substream_indices.push(substream_index);
1939
+ }
1940
+ for (this.i = 0; this.i < this.frame_rate_factor; this.i++) {
1941
+ {
1942
+ {
1943
+ this.last_referenced_substream = Math.max(this.last_referenced_substream, substream_index + this.i);
1944
+ }
1945
+ {
1946
+ this.referenced_substreams.push(substream_index + this.i);
1947
+ }
1948
+ {
1949
+ if (b_lfe == null) {
1950
+ b_lfe = new Array(substream_index + 1 + 1).fill(0);
1951
+ } else if (b_lfe.length <= substream_index + 1) {
1952
+ b_lfe.push.apply(b_lfe, new Array(substream_index + 1 - b_lfe.length + 1).fill(0));
1953
+ }
1954
+ b_lfe[substream_index + 1] = this.F_channel_mode_contains_LFE(si_channel_mode);
1955
+ if (b_lfe[substream_index + 1] == null) {
1956
+ throw ParseError("F_channel_mode_contains_LFE", "expected to return a value, returned None");
1957
+ }
1958
+ }
1959
+ }
1960
+ }
1961
+ }
1962
+ }
1963
+ F_emdf_protection() {
1964
+ var protection_bits_secondary;
1965
+ var protection_length_secondary;
1966
+ var protection_length_primary;
1967
+ var protection_bits_primary;
1968
+ {
1969
+ {
1970
+ protection_length_primary = this.BAM_source.get("", 2);
1971
+ this.BAM_g_position += 2;
1972
+ }
1973
+ {
1974
+ protection_length_secondary = this.BAM_source.get("", 2);
1975
+ this.BAM_g_position += 2;
1976
+ }
1977
+ if (protection_length_primary == 0) {
1978
+ if (1) {
1979
+ throw "protection_length_primary == 0 is reserved";
1980
+ }
1981
+ } else if (protection_length_primary == 1) {
1982
+ {
1983
+ this.protection_bits_primary_bits = 8;
1984
+ }
1985
+ } else if (protection_length_primary == 2) {
1986
+ {
1987
+ this.protection_bits_primary_bits = 32;
1988
+ }
1989
+ } else if (protection_length_primary == 3) {
1990
+ {
1991
+ this.protection_bits_primary_bits = 128;
1992
+ }
1993
+ }
1994
+ {
1995
+ protection_bits_primary = this.BAM_source.get("", this.protection_bits_primary_bits);
1996
+ this.BAM_g_position += this.protection_bits_primary_bits;
1997
+ }
1998
+ if (protection_length_secondary == 0) {
1999
+ {
2000
+ this.protection_bits_secondary_bits = 0;
2001
+ }
2002
+ } else if (protection_length_secondary == 1) {
2003
+ {
2004
+ this.protection_bits_secondary_bits = 8;
2005
+ }
2006
+ } else if (protection_length_secondary == 2) {
2007
+ {
2008
+ this.protection_bits_secondary_bits = 32;
2009
+ }
2010
+ } else if (protection_length_secondary == 3) {
2011
+ {
2012
+ this.protection_bits_secondary_bits = 128;
2013
+ }
2014
+ }
2015
+ {
2016
+ protection_bits_secondary = this.BAM_source.get("", this.protection_bits_secondary_bits);
2017
+ this.BAM_g_position += this.protection_bits_secondary_bits;
2018
+ }
2019
+ }
2020
+ }
2021
+ F_emdf_info() {
2022
+ var key_id;
2023
+ var b_emdf_payloads_substream_info;
2024
+ var emdf_version;
2025
+ {
2026
+ {
2027
+ emdf_version = this.BAM_source.get("", 2);
2028
+ this.BAM_g_position += 2;
2029
+ }
2030
+ if (emdf_version == 3) {
2031
+ {
2032
+ {
2033
+ this.v = this.F_variable_bits(2);
2034
+ if (this.v == null) {
2035
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
2036
+ }
2037
+ }
2038
+ {
2039
+ emdf_version += this.v;
2040
+ }
2041
+ }
2042
+ }
2043
+ {
2044
+ key_id = this.BAM_source.get("", 3);
2045
+ this.BAM_g_position += 3;
2046
+ }
2047
+ if (key_id == 7) {
2048
+ {
2049
+ {
2050
+ this.v = this.F_variable_bits(3);
2051
+ if (this.v == null) {
2052
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
2053
+ }
2054
+ }
2055
+ {
2056
+ key_id += this.v;
2057
+ }
2058
+ }
2059
+ }
2060
+ {
2061
+ b_emdf_payloads_substream_info = this.BAM_source.get("", 1);
2062
+ this.BAM_g_position += 1;
2063
+ }
2064
+ if (b_emdf_payloads_substream_info) {
2065
+ {
2066
+ this.F_emdf_payloads_substream_info(this.toc_i);
2067
+ }
2068
+ }
2069
+ {
2070
+ this.F_emdf_protection();
2071
+ }
2072
+ }
2073
+ }
2074
+ F_emdf_payloads_substream_info(toc_i) {
2075
+ var substream_index;
2076
+ {
2077
+ {
2078
+ substream_index = this.BAM_source.get("", 2);
2079
+ this.BAM_g_position += 2;
2080
+ }
2081
+ if (substream_index == 3) {
2082
+ {
2083
+ {
2084
+ this.v = this.F_variable_bits(2);
2085
+ if (this.v == null) {
2086
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
2087
+ }
2088
+ }
2089
+ {
2090
+ substream_index += this.v;
2091
+ }
2092
+ }
2093
+ }
2094
+ {
2095
+ this.last_referenced_substream = Math.max(this.last_referenced_substream, substream_index);
2096
+ }
2097
+ {
2098
+ this.referenced_substreams.push(substream_index);
2099
+ }
2100
+ {
2101
+ this.a_substream_indices.push(substream_index);
2102
+ }
2103
+ }
2104
+ }
2105
+ F_ac4_hsf_ext_substream_info(ahsf_b_substreams_present) {
2106
+ var substream_index;
2107
+ {
2108
+ if (ahsf_b_substreams_present == 1) {
2109
+ {
2110
+ {
2111
+ substream_index = this.BAM_source.get("", 2);
2112
+ this.BAM_g_position += 2;
2113
+ }
2114
+ if (substream_index == 3) {
2115
+ {
2116
+ {
2117
+ this.v = this.F_variable_bits(2);
2118
+ if (this.v == null) {
2119
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
2120
+ }
2121
+ }
2122
+ {
2123
+ substream_index += this.v;
2124
+ }
2125
+ }
2126
+ }
2127
+ }
2128
+ } else {
2129
+ {
2130
+ {
2131
+ substream_index = this.bk_substream_index;
2132
+ }
2133
+ {
2134
+ this.bk_substream_index = this.bk_substream_index + 1;
2135
+ }
2136
+ }
2137
+ }
2138
+ if (ahsf_b_substreams_present == 1) {
2139
+ {
2140
+ {
2141
+ this.last_referenced_substream = Math.max(this.last_referenced_substream, substream_index);
2142
+ }
2143
+ {
2144
+ this.referenced_substreams.push(substream_index);
2145
+ }
2146
+ }
2147
+ }
2148
+ }
2149
+ }
2150
+ F_oamd_common_data() {
2151
+ var add_data_bits;
2152
+ var ocd_p1;
2153
+ var add_data;
2154
+ var ocd_p0;
2155
+ var bits_used;
2156
+ var b_bed_object_chan_distribute;
2157
+ var master_screen_size_ratio;
2158
+ var add_data_bytes_minus1;
2159
+ var add_data_bytes;
2160
+ var b_additional_data;
2161
+ var b_default_screen_size_ratio;
2162
+ {
2163
+ {
2164
+ b_default_screen_size_ratio = this.BAM_source.get("", 1);
2165
+ this.BAM_g_position += 1;
2166
+ }
2167
+ if (b_default_screen_size_ratio == 0) {
2168
+ {
2169
+ master_screen_size_ratio = this.BAM_source.get("", 5);
2170
+ this.BAM_g_position += 5;
2171
+ }
2172
+ }
2173
+ {
2174
+ b_bed_object_chan_distribute = this.BAM_source.get("", 1);
2175
+ this.BAM_g_position += 1;
2176
+ }
2177
+ {
2178
+ b_additional_data = this.BAM_source.get("", 1);
2179
+ this.BAM_g_position += 1;
2180
+ }
2181
+ if (b_additional_data) {
2182
+ {
2183
+ {
2184
+ add_data_bytes_minus1 = this.BAM_source.get("", 1);
2185
+ this.BAM_g_position += 1;
2186
+ }
2187
+ {
2188
+ add_data_bytes = add_data_bytes_minus1 + 1;
2189
+ }
2190
+ if (add_data_bytes == 2) {
2191
+ {
2192
+ {
2193
+ this.v = this.F_variable_bits(2);
2194
+ if (this.v == null) {
2195
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
2196
+ }
2197
+ }
2198
+ {
2199
+ add_data_bytes += this.v;
2200
+ }
2201
+ }
2202
+ }
2203
+ {
2204
+ add_data_bits = add_data_bytes * 8;
2205
+ }
2206
+ {
2207
+ ocd_p0 = this.BAM_g_position;
2208
+ }
2209
+ {
2210
+ ocd_p1 = this.BAM_g_position;
2211
+ }
2212
+ {
2213
+ bits_used = ocd_p1 - ocd_p0;
2214
+ }
2215
+ {
2216
+ add_data_bits = add_data_bits - bits_used;
2217
+ }
2218
+ if (add_data_bits < 0) {
2219
+ throw "Wrong add_data_bytes_minus1 size indication";
2220
+ }
2221
+ {
2222
+ add_data = this.BAM_source.get("", add_data_bits);
2223
+ this.BAM_g_position += add_data_bits;
2224
+ }
2225
+ }
2226
+ }
2227
+ }
2228
+ }
2229
+ F_define_oamd() {
2230
+ var NUM_TRIM_CONFIGS;
2231
+ {
2232
+ {
2233
+ this.OAMD_OBJECT_TYPE_BED = 0;
2234
+ }
2235
+ {
2236
+ this.OAMD_OBJECT_TYPE_ISF = 1;
2237
+ }
2238
+ {
2239
+ this.OAMD_OBJECT_TYPE_DYNAMIC = 2;
2240
+ }
2241
+ {
2242
+ this.OAMD_OBJECT_TYPE_RESERVED = 3;
2243
+ }
2244
+ {
2245
+ NUM_TRIM_CONFIGS = 9;
2246
+ }
2247
+ }
2248
+ }
2249
+ F_ac4_substream_info_ajoc(asio_group_index, asio_gs_index_ajoc, asio_b_substreams_present) {
2250
+ var n_fullband_upmix_signals_minus1;
2251
+ var substream_index;
2252
+ var b_oamd_common_data_present;
2253
+ var b_sf_multiplier;
2254
+ var b_bitrate_info;
2255
+ var n_fullband_dmx_signals;
2256
+ var n_fullband_upmix_signals;
2257
+ var si_b_iframe;
2258
+ var num_objects_DYNAMIC = null;
2259
+ var num_objects_DYNAMIC;
2260
+ var ajoc_b_lfe;
2261
+ var n_fullband_dmx_signals_minus1;
2262
+ var b_lfe = null;
2263
+ var b_lfe;
2264
+ var si_channel_mode_j;
2265
+ var b_static_dmx;
2266
+ var sf_multiplier;
2267
+ {
2268
+ {
2269
+ num_objects_DYNAMIC = this.BAM_g_table6.slice(0);
2270
+ }
2271
+ {
2272
+ this.F_define_channel_modes();
2273
+ }
2274
+ {
2275
+ ajoc_b_lfe = this.BAM_source.get("", 1);
2276
+ this.BAM_g_position += 1;
2277
+ }
2278
+ {
2279
+ b_static_dmx = this.BAM_source.get("", 1);
2280
+ this.BAM_g_position += 1;
2281
+ }
2282
+ if (b_static_dmx) {
2283
+ {
2284
+ {
2285
+ n_fullband_dmx_signals = 5;
2286
+ }
2287
+ if (ajoc_b_lfe) {
2288
+ {
2289
+ si_channel_mode_j = this.CHANNEL_MODE_51;
2290
+ }
2291
+ } else {
2292
+ {
2293
+ si_channel_mode_j = this.CHANNEL_MODE_50;
2294
+ }
2295
+ }
2296
+ }
2297
+ } else {
2298
+ {
2299
+ {
2300
+ n_fullband_dmx_signals_minus1 = this.BAM_source.get("", 4);
2301
+ this.BAM_g_position += 4;
2302
+ }
2303
+ {
2304
+ n_fullband_dmx_signals = n_fullband_dmx_signals_minus1 + 1;
2305
+ }
2306
+ {
2307
+ this.F_bed_dyn_obj_assignment(n_fullband_dmx_signals, 0, ajoc_b_lfe);
2308
+ }
2309
+ }
2310
+ }
2311
+ {
2312
+ b_oamd_common_data_present = this.BAM_source.get("", 1);
2313
+ this.BAM_g_position += 1;
2314
+ }
2315
+ if (b_oamd_common_data_present) {
2316
+ {
2317
+ this.F_oamd_common_data();
2318
+ }
2319
+ }
2320
+ {
2321
+ n_fullband_upmix_signals_minus1 = this.BAM_source.get("", 4);
2322
+ this.BAM_g_position += 4;
2323
+ }
2324
+ {
2325
+ n_fullband_upmix_signals = n_fullband_upmix_signals_minus1 + 1;
2326
+ }
2327
+ if (n_fullband_upmix_signals == 16) {
2328
+ {
2329
+ {
2330
+ this.v = this.F_variable_bits(3);
2331
+ if (this.v == null) {
2332
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
2333
+ }
2334
+ }
2335
+ {
2336
+ n_fullband_upmix_signals = n_fullband_upmix_signals + this.v;
2337
+ }
2338
+ }
2339
+ }
2340
+ {
2341
+ this.F_bed_dyn_obj_assignment(n_fullband_upmix_signals, 1, ajoc_b_lfe);
2342
+ }
2343
+ if (this.fs_index == 1) {
2344
+ {
2345
+ {
2346
+ b_sf_multiplier = this.BAM_source.get("", 1);
2347
+ this.BAM_g_position += 1;
2348
+ }
2349
+ if (b_sf_multiplier) {
2350
+ {
2351
+ sf_multiplier = this.BAM_source.get("", 1);
2352
+ this.BAM_g_position += 1;
2353
+ }
2354
+ }
2355
+ }
2356
+ }
2357
+ {
2358
+ b_bitrate_info = this.BAM_source.get("", 1);
2359
+ this.BAM_g_position += 1;
2360
+ }
2361
+ if (b_bitrate_info) {
2362
+ {
2363
+ this.F_bitrate_indicator();
2364
+ }
2365
+ }
2366
+ {
2367
+ this.frame_rate_factor = this.group_frame_rate_factor[asio_group_index];
2368
+ }
2369
+ for (this.i = 0; this.i < this.frame_rate_factor; this.i++) {
2370
+ {
2371
+ si_b_iframe = this.BAM_source.get("", 1);
2372
+ this.BAM_g_position += 1;
2373
+ }
2374
+ }
2375
+ if (asio_b_substreams_present == 1) {
2376
+ {
2377
+ {
2378
+ substream_index = this.BAM_source.get("", 2);
2379
+ this.BAM_g_position += 2;
2380
+ }
2381
+ if (substream_index == 3) {
2382
+ {
2383
+ {
2384
+ this.v = this.F_variable_bits(2);
2385
+ if (this.v == null) {
2386
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
2387
+ }
2388
+ }
2389
+ {
2390
+ substream_index += this.v;
2391
+ }
2392
+ }
2393
+ }
2394
+ }
2395
+ } else {
2396
+ {
2397
+ {
2398
+ substream_index = this.bk_substream_index;
2399
+ }
2400
+ {
2401
+ this.bk_substream_index = this.bk_substream_index + 1;
2402
+ }
2403
+ }
2404
+ }
2405
+ {
2406
+ this.a_substream_indices.push(substream_index);
2407
+ }
2408
+ for (this.i = 0; this.i < this.frame_rate_factor; this.i++) {
2409
+ {
2410
+ if (asio_b_substreams_present == 1) {
2411
+ {
2412
+ {
2413
+ this.last_referenced_substream = Math.max(this.last_referenced_substream, substream_index + this.i);
2414
+ }
2415
+ {
2416
+ this.referenced_substreams.push(substream_index + this.i);
2417
+ }
2418
+ }
2419
+ }
2420
+ {
2421
+ if (b_lfe == null) {
2422
+ b_lfe = new Array(substream_index + this.i + 1).fill(0);
2423
+ } else if (b_lfe.length <= substream_index + this.i) {
2424
+ b_lfe.push.apply(b_lfe, new Array(substream_index + this.i - b_lfe.length + 1).fill(0));
2425
+ }
2426
+ b_lfe[substream_index + this.i] = ajoc_b_lfe;
2427
+ }
2428
+ }
2429
+ }
2430
+ }
2431
+ }
2432
+ F_ac4_sgi_specifier(asgi_b_associated, asgi_b_dialog, group_in_presentation_index) {
2433
+ var group_index;
2434
+ {
2435
+ if (this.bitstream_version == 1) {
2436
+ {
2437
+ {
2438
+ this.F_ac4_substream_group_info(this.toc_j);
2439
+ }
2440
+ {
2441
+ this.toc_j += 1;
2442
+ }
2443
+ }
2444
+ } else {
2445
+ {
2446
+ {
2447
+ group_index = this.BAM_source.get("", 3);
2448
+ this.BAM_g_position += 3;
2449
+ }
2450
+ if (group_index == 7) {
2451
+ {
2452
+ {
2453
+ this.vb = this.F_variable_bits(2);
2454
+ if (this.vb == null) {
2455
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
2456
+ }
2457
+ }
2458
+ {
2459
+ group_index += this.vb;
2460
+ }
2461
+ }
2462
+ }
2463
+ {
2464
+ if (this.presentation_to_groups == null) {
2465
+ this.presentation_to_groups = new Array(this.toc_i + 1).fill(null);
2466
+ } else if (this.presentation_to_groups.length <= this.toc_i) {
2467
+ this.presentation_to_groups.push.apply(this.presentation_to_groups, new Array(this.toc_i - this.presentation_to_groups.length + 1).fill(null));
2468
+ }
2469
+ this.presentation_to_groups[this.toc_i].push(group_index);
2470
+ }
2471
+ {
2472
+ if (this.group_frame_rate_factor == null) {
2473
+ this.group_frame_rate_factor = new Array(group_index + 1).fill(0);
2474
+ } else if (this.group_frame_rate_factor.length <= group_index) {
2475
+ this.group_frame_rate_factor.push.apply(this.group_frame_rate_factor, new Array(group_index - this.group_frame_rate_factor.length + 1).fill(0));
2476
+ }
2477
+ this.group_frame_rate_factor[group_index] = this.frame_rate_factor;
2478
+ }
2479
+ }
2480
+ }
2481
+ }
2482
+ }
2483
+ F_ac4_substream_group_info(si_group_index) {
2484
+ var obj_index;
2485
+ var b_dialog_content;
2486
+ var sus;
2487
+ var n_lf_substreams;
2488
+ var b_substreams_present;
2489
+ var b_channel_coded;
2490
+ var b_ajoc;
2491
+ var n_lf_substreams_minus2;
2492
+ var sus_ver;
2493
+ var b_oamd_substream;
2494
+ var b_content_type;
2495
+ var b_associated_content;
2496
+ {
2497
+ {
2498
+ b_substreams_present = this.BAM_source.get("", 1);
2499
+ this.BAM_g_position += 1;
2500
+ }
2501
+ {
2502
+ this.b_hsf_ext = this.BAM_source.get("", 1);
2503
+ this.BAM_g_position += 1;
2504
+ }
2505
+ {
2506
+ this.b_single_substream = this.BAM_source.get("", 1);
2507
+ this.BAM_g_position += 1;
2508
+ }
2509
+ if (this.b_single_substream) {
2510
+ {
2511
+ n_lf_substreams = 1;
2512
+ }
2513
+ } else {
2514
+ {
2515
+ {
2516
+ n_lf_substreams_minus2 = this.BAM_source.get("", 2);
2517
+ this.BAM_g_position += 2;
2518
+ }
2519
+ {
2520
+ n_lf_substreams = n_lf_substreams_minus2 + 2;
2521
+ }
2522
+ if (n_lf_substreams == 5) {
2523
+ {
2524
+ {
2525
+ this.v = this.F_variable_bits(2);
2526
+ if (this.v == null) {
2527
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
2528
+ }
2529
+ }
2530
+ {
2531
+ n_lf_substreams += this.v;
2532
+ }
2533
+ }
2534
+ }
2535
+ }
2536
+ }
2537
+ {
2538
+ b_channel_coded = this.BAM_source.get("", 1);
2539
+ this.BAM_g_position += 1;
2540
+ }
2541
+ {
2542
+ this.n_bed_objects = -1;
2543
+ }
2544
+ {
2545
+ this.a_num_bed_objects = [];
2546
+ }
2547
+ if (b_channel_coded) {
2548
+ {
2549
+ {
2550
+ b_ajoc = 0;
2551
+ }
2552
+ for (sus = 0; sus < n_lf_substreams; sus++) {
2553
+ {
2554
+ if (this.bitstream_version == 1) {
2555
+ {
2556
+ sus_ver = this.BAM_source.get("", 1);
2557
+ this.BAM_g_position += 1;
2558
+ }
2559
+ } else {
2560
+ {
2561
+ sus_ver = 1;
2562
+ }
2563
+ }
2564
+ {
2565
+ this.F_ac4_substream_info_chan(si_group_index, sus, b_substreams_present);
2566
+ }
2567
+ if (this.b_hsf_ext) {
2568
+ {
2569
+ this.F_ac4_hsf_ext_substream_info(b_substreams_present);
2570
+ }
2571
+ }
2572
+ }
2573
+ }
2574
+ }
2575
+ } else {
2576
+ {
2577
+ {
2578
+ b_oamd_substream = this.BAM_source.get("", 1);
2579
+ this.BAM_g_position += 1;
2580
+ }
2581
+ if (b_oamd_substream) {
2582
+ {
2583
+ this.F_oamd_substream_info(b_substreams_present);
2584
+ }
2585
+ }
2586
+ {
2587
+ obj_index = 0;
2588
+ }
2589
+ {
2590
+ this.b_bed_objects_prev = 0;
2591
+ }
2592
+ for (sus = 0; sus < n_lf_substreams; sus++) {
2593
+ {
2594
+ {
2595
+ b_ajoc = this.BAM_source.get("", 1);
2596
+ this.BAM_g_position += 1;
2597
+ }
2598
+ if (b_ajoc) {
2599
+ {
2600
+ {
2601
+ this.F_ac4_substream_info_ajoc(si_group_index, sus, b_substreams_present);
2602
+ }
2603
+ if (this.b_hsf_ext) {
2604
+ {
2605
+ this.F_ac4_hsf_ext_substream_info(b_substreams_present);
2606
+ }
2607
+ }
2608
+ }
2609
+ } else {
2610
+ {
2611
+ {
2612
+ this.F_ac4_substream_info_obj(si_group_index, sus, obj_index, b_substreams_present);
2613
+ }
2614
+ {
2615
+ obj_index += 1;
2616
+ }
2617
+ if (this.b_hsf_ext) {
2618
+ {
2619
+ this.F_ac4_hsf_ext_substream_info(b_substreams_present);
2620
+ }
2621
+ }
2622
+ }
2623
+ }
2624
+ }
2625
+ }
2626
+ }
2627
+ }
2628
+ {
2629
+ b_content_type = this.BAM_source.get("", 1);
2630
+ this.BAM_g_position += 1;
2631
+ }
2632
+ if (b_content_type) {
2633
+ {
2634
+ {
2635
+ this.F_content_type();
2636
+ }
2637
+ if (this.content_classifier == 0) {
2638
+ {
2639
+ {
2640
+ b_associated_content = 0;
2641
+ }
2642
+ {
2643
+ b_dialog_content = 0;
2644
+ }
2645
+ }
2646
+ } else if (this.content_classifier == 1) {
2647
+ {
2648
+ {
2649
+ b_associated_content = 0;
2650
+ }
2651
+ {
2652
+ b_dialog_content = 0;
2653
+ }
2654
+ }
2655
+ } else if (this.content_classifier == 2) {
2656
+ {
2657
+ {
2658
+ b_associated_content = 1;
2659
+ }
2660
+ {
2661
+ b_dialog_content = 0;
2662
+ }
2663
+ }
2664
+ } else if (this.content_classifier == 3) {
2665
+ {
2666
+ {
2667
+ b_associated_content = 1;
2668
+ }
2669
+ {
2670
+ b_dialog_content = 0;
2671
+ }
2672
+ }
2673
+ } else if (this.content_classifier == 4) {
2674
+ {
2675
+ {
2676
+ b_associated_content = 0;
2677
+ }
2678
+ {
2679
+ b_dialog_content = 1;
2680
+ }
2681
+ }
2682
+ } else if (this.content_classifier == 5) {
2683
+ {
2684
+ {
2685
+ b_associated_content = 1;
2686
+ }
2687
+ {
2688
+ b_dialog_content = 0;
2689
+ }
2690
+ }
2691
+ } else if (this.content_classifier == 6) {
2692
+ {
2693
+ {
2694
+ b_associated_content = 0;
2695
+ }
2696
+ {
2697
+ b_dialog_content = 0;
2698
+ }
2699
+ }
2700
+ } else if (this.content_classifier == 7) {
2701
+ {
2702
+ {
2703
+ b_associated_content = 0;
2704
+ }
2705
+ {
2706
+ b_dialog_content = 0;
2707
+ }
2708
+ }
2709
+ }
2710
+ }
2711
+ } else {
2712
+ {
2713
+ {
2714
+ b_associated_content = 0;
2715
+ }
2716
+ {
2717
+ b_dialog_content = 0;
2718
+ }
2719
+ }
2720
+ }
2721
+ }
2722
+ }
2723
+ F_oamd_substream_info(oamd_b_substreams_present) {
2724
+ var substream_index;
2725
+ var b_iframe_oamd;
2726
+ {
2727
+ {
2728
+ this.F_define_oamd();
2729
+ }
2730
+ {
2731
+ b_iframe_oamd = this.BAM_source.get("", 1);
2732
+ this.BAM_g_position += 1;
2733
+ }
2734
+ if (oamd_b_substreams_present == 1) {
2735
+ {
2736
+ {
2737
+ substream_index = this.BAM_source.get("", 2);
2738
+ this.BAM_g_position += 2;
2739
+ }
2740
+ if (substream_index == 3) {
2741
+ {
2742
+ {
2743
+ this.vb = this.F_variable_bits(2);
2744
+ if (this.vb == null) {
2745
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
2746
+ }
2747
+ }
2748
+ {
2749
+ substream_index += this.vb;
2750
+ }
2751
+ }
2752
+ }
2753
+ }
2754
+ } else {
2755
+ {
2756
+ {
2757
+ substream_index = this.bk_substream_index;
2758
+ }
2759
+ {
2760
+ this.bk_substream_index = this.bk_substream_index + 1;
2761
+ }
2762
+ }
2763
+ }
2764
+ if (oamd_b_substreams_present == 1) {
2765
+ {
2766
+ {
2767
+ this.last_referenced_substream = Math.max(this.last_referenced_substream, substream_index);
2768
+ }
2769
+ {
2770
+ this.referenced_substreams.push(substream_index);
2771
+ }
2772
+ }
2773
+ }
2774
+ }
2775
+ }
2776
+ F_ac4_substream_info_obj(asio_group_index, asio_gs_index, asio_gs_index_obj, asio_b_substreams_present) {
2777
+ var obj_type;
2778
+ var b_nonstd_bed_channel_assignment;
2779
+ var res_bytes;
2780
+ var b_bed_start;
2781
+ var bed_chan_assign_code;
2782
+ var j;
2783
+ var si_b_iframe;
2784
+ var n_objs;
2785
+ var si_num_channels;
2786
+ var reserved_data;
2787
+ var b_isf_start;
2788
+ var n_objects_code;
2789
+ var isf_config;
2790
+ var substream_index;
2791
+ var b_sf_multiplier;
2792
+ var b_bed_objects;
2793
+ var b_dynamic_objects;
2794
+ var b_bitrate_info;
2795
+ var b_isf;
2796
+ var nonstd_bed_channel_assignment_mask;
2797
+ var b_ch_assign_code;
2798
+ var b_lfe = null;
2799
+ var b_lfe;
2800
+ var std_bed_channel_assignment_mask;
2801
+ var sf_multiplier;
2802
+ var si_b_lfe;
2803
+ {
2804
+ {
2805
+ n_objs = 0;
2806
+ }
2807
+ {
2808
+ this.F_define_oamd();
2809
+ }
2810
+ {
2811
+ this.F_define_channel_modes();
2812
+ }
2813
+ {
2814
+ n_objects_code = this.BAM_source.get("", 3);
2815
+ this.BAM_g_position += 3;
2816
+ }
2817
+ {
2818
+ si_num_channels = this.BAM_g_table7.slice(0)[n_objects_code];
2819
+ }
2820
+ {
2821
+ b_dynamic_objects = this.BAM_source.get("", 1);
2822
+ this.BAM_g_position += 1;
2823
+ }
2824
+ if (b_dynamic_objects) {
2825
+ {
2826
+ {
2827
+ si_b_lfe = this.BAM_source.get("", 1);
2828
+ this.BAM_g_position += 1;
2829
+ }
2830
+ {
2831
+ obj_type = this.OAMD_OBJECT_TYPE_DYNAMIC;
2832
+ }
2833
+ {
2834
+ this.b_bed_objects_prev = 0;
2835
+ }
2836
+ }
2837
+ } else {
2838
+ {
2839
+ {
2840
+ b_bed_objects = this.BAM_source.get("", 1);
2841
+ this.BAM_g_position += 1;
2842
+ }
2843
+ if (b_bed_objects) {
2844
+ {
2845
+ if (this.b_bed_objects_prev && this.num_lfe == 2) {
2846
+ {
2847
+ si_b_lfe = 1;
2848
+ }
2849
+ } else {
2850
+ {
2851
+ si_b_lfe = 0;
2852
+ }
2853
+ }
2854
+ {
2855
+ this.b_bed_objects_prev = 1;
2856
+ }
2857
+ {
2858
+ this.num_lfe = 0;
2859
+ }
2860
+ {
2861
+ obj_type = this.OAMD_OBJECT_TYPE_BED;
2862
+ }
2863
+ {
2864
+ b_bed_start = this.BAM_source.get("", 1);
2865
+ this.BAM_g_position += 1;
2866
+ }
2867
+ if (b_bed_start) {
2868
+ {
2869
+ {
2870
+ b_ch_assign_code = this.BAM_source.get("", 1);
2871
+ this.BAM_g_position += 1;
2872
+ }
2873
+ if (b_ch_assign_code) {
2874
+ {
2875
+ {
2876
+ bed_chan_assign_code = this.BAM_source.get("", 3);
2877
+ this.BAM_g_position += 3;
2878
+ }
2879
+ for (this.i = 0; this.i < this.BAM_g_table8.slice(0)[bed_chan_assign_code]; this.i++) {
2880
+ {
2881
+ n_objs += 1;
2882
+ }
2883
+ }
2884
+ if (bed_chan_assign_code >= 2) {
2885
+ {
2886
+ si_b_lfe = 1;
2887
+ }
2888
+ }
2889
+ }
2890
+ } else {
2891
+ {
2892
+ {
2893
+ b_nonstd_bed_channel_assignment = this.BAM_source.get("", 1);
2894
+ this.BAM_g_position += 1;
2895
+ }
2896
+ if (b_nonstd_bed_channel_assignment) {
2897
+ {
2898
+ {
2899
+ nonstd_bed_channel_assignment_mask = this.BAM_source.get("", 17);
2900
+ this.BAM_g_position += 17;
2901
+ }
2902
+ for (this.i = 0; this.i < 17; this.i++) {
2903
+ if ((nonstd_bed_channel_assignment_mask & 1 << this.i) != 0) {
2904
+ {
2905
+ if (this.i == 3 || this.i == 16) {
2906
+ {
2907
+ this.num_lfe += 1;
2908
+ }
2909
+ }
2910
+ {
2911
+ n_objs += 1;
2912
+ }
2913
+ }
2914
+ }
2915
+ }
2916
+ }
2917
+ } else {
2918
+ {
2919
+ {
2920
+ std_bed_channel_assignment_mask = this.BAM_source.get("", 10);
2921
+ this.BAM_g_position += 10;
2922
+ }
2923
+ for (this.i = 0; this.i < 10; this.i++) {
2924
+ if ((std_bed_channel_assignment_mask & 1 << this.i) != 0) {
2925
+ for (j = 0; j < this.BAM_g_table9.slice(0)[this.i]; j++) {
2926
+ {
2927
+ if (this.i == 2 || this.i == 9) {
2928
+ {
2929
+ this.num_lfe += 1;
2930
+ }
2931
+ }
2932
+ {
2933
+ n_objs += 1;
2934
+ }
2935
+ }
2936
+ }
2937
+ }
2938
+ }
2939
+ }
2940
+ }
2941
+ if (this.num_lfe > 0) {
2942
+ {
2943
+ si_b_lfe = 1;
2944
+ }
2945
+ }
2946
+ }
2947
+ }
2948
+ {
2949
+ this.n_bed_objects = n_objs;
2950
+ }
2951
+ {
2952
+ this.a_num_bed_objects.push(this.n_bed_objects);
2953
+ }
2954
+ }
2955
+ }
2956
+ }
2957
+ } else {
2958
+ {
2959
+ {
2960
+ si_b_lfe = 0;
2961
+ }
2962
+ {
2963
+ this.b_bed_objects_prev = 0;
2964
+ }
2965
+ {
2966
+ b_isf = this.BAM_source.get("", 1);
2967
+ this.BAM_g_position += 1;
2968
+ }
2969
+ if (b_isf) {
2970
+ {
2971
+ {
2972
+ obj_type = this.OAMD_OBJECT_TYPE_ISF;
2973
+ }
2974
+ {
2975
+ b_isf_start = this.BAM_source.get("", 1);
2976
+ this.BAM_g_position += 1;
2977
+ }
2978
+ if (b_isf_start) {
2979
+ {
2980
+ isf_config = this.BAM_source.get("", 3);
2981
+ this.BAM_g_position += 3;
2982
+ }
2983
+ }
2984
+ }
2985
+ } else {
2986
+ {
2987
+ {
2988
+ res_bytes = this.BAM_source.get("", 4);
2989
+ this.BAM_g_position += 4;
2990
+ }
2991
+ {
2992
+ reserved_data = this.BAM_source.get("", 8 * res_bytes);
2993
+ this.BAM_g_position += 8 * res_bytes;
2994
+ }
2995
+ {
2996
+ obj_type = this.OAMD_OBJECT_TYPE_RESERVED;
2997
+ }
2998
+ if (si_num_channels == 0) {
2999
+ throw "No non-LFE objects (of OAMD_OBJECT_TYPE_RESERVED) in substream!";
3000
+ }
3001
+ }
3002
+ }
3003
+ }
3004
+ }
3005
+ }
3006
+ }
3007
+ if (this.fs_index == 1) {
3008
+ {
3009
+ {
3010
+ b_sf_multiplier = this.BAM_source.get("", 1);
3011
+ this.BAM_g_position += 1;
3012
+ }
3013
+ if (b_sf_multiplier) {
3014
+ {
3015
+ sf_multiplier = this.BAM_source.get("", 1);
3016
+ this.BAM_g_position += 1;
3017
+ }
3018
+ }
3019
+ }
3020
+ }
3021
+ {
3022
+ b_bitrate_info = this.BAM_source.get("", 1);
3023
+ this.BAM_g_position += 1;
3024
+ }
3025
+ if (b_bitrate_info) {
3026
+ {
3027
+ this.F_bitrate_indicator();
3028
+ }
3029
+ }
3030
+ {
3031
+ this.frame_rate_factor = this.group_frame_rate_factor[asio_group_index];
3032
+ }
3033
+ for (this.i = 0; this.i < this.frame_rate_factor; this.i++) {
3034
+ {
3035
+ si_b_iframe = this.BAM_source.get("", 1);
3036
+ this.BAM_g_position += 1;
3037
+ }
3038
+ }
3039
+ if (asio_b_substreams_present == 1) {
3040
+ {
3041
+ {
3042
+ substream_index = this.BAM_source.get("", 2);
3043
+ this.BAM_g_position += 2;
3044
+ }
3045
+ if (substream_index == 3) {
3046
+ {
3047
+ {
3048
+ this.v = this.F_variable_bits(2);
3049
+ if (this.v == null) {
3050
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
3051
+ }
3052
+ }
3053
+ {
3054
+ substream_index += this.v;
3055
+ }
3056
+ }
3057
+ }
3058
+ }
3059
+ } else {
3060
+ {
3061
+ {
3062
+ substream_index = this.bk_substream_index;
3063
+ }
3064
+ {
3065
+ this.bk_substream_index = this.bk_substream_index + 1;
3066
+ }
3067
+ }
3068
+ }
3069
+ {
3070
+ this.a_substream_indices.push(substream_index);
3071
+ }
3072
+ for (this.i = 0; this.i < this.frame_rate_factor; this.i++) {
3073
+ {
3074
+ if (asio_b_substreams_present == 1) {
3075
+ {
3076
+ {
3077
+ this.last_referenced_substream = Math.max(this.last_referenced_substream, substream_index + this.i);
3078
+ }
3079
+ {
3080
+ this.referenced_substreams.push(substream_index + this.i);
3081
+ }
3082
+ }
3083
+ }
3084
+ {
3085
+ if (b_lfe == null) {
3086
+ b_lfe = new Array(substream_index + this.i + 1).fill(0);
3087
+ } else if (b_lfe.length <= substream_index + this.i) {
3088
+ b_lfe.push.apply(b_lfe, new Array(substream_index + this.i - b_lfe.length + 1).fill(0));
3089
+ }
3090
+ b_lfe[substream_index + this.i] = si_b_lfe;
3091
+ }
3092
+ }
3093
+ }
3094
+ }
3095
+ }
3096
+ F_bed_dyn_obj_assignment(n_signals, b_upmix, bd_lfe) {
3097
+ var n_isf;
3098
+ var isf_config;
3099
+ var oc_num_channels;
3100
+ var obj_type;
3101
+ var n_bed_signals_minus1;
3102
+ var b_nonstd_bed_channel_assignment;
3103
+ var nonstd_bed_channel_assignment;
3104
+ var bed_chan_assign_code;
3105
+ var nonstd_bed_channel_assignment_mask;
3106
+ var lfe_signalled;
3107
+ var b_is_isf;
3108
+ var n_bed_signals;
3109
+ var bed_ch_bits;
3110
+ var b_ch_assign_code;
3111
+ var std_bed_channel_assignment_mask;
3112
+ var b_dyn_objects_only;
3113
+ var b_chan_assign_mask;
3114
+ var b;
3115
+ {
3116
+ {
3117
+ this.F_define_oamd();
3118
+ }
3119
+ {
3120
+ lfe_signalled = 0;
3121
+ }
3122
+ {
3123
+ b_dyn_objects_only = this.BAM_source.get("", 1);
3124
+ this.BAM_g_position += 1;
3125
+ }
3126
+ if (b_dyn_objects_only == 0) {
3127
+ {
3128
+ {
3129
+ b_is_isf = this.BAM_source.get("", 1);
3130
+ this.BAM_g_position += 1;
3131
+ }
3132
+ if (b_is_isf) {
3133
+ {
3134
+ {
3135
+ isf_config = this.BAM_source.get("", 3);
3136
+ this.BAM_g_position += 3;
3137
+ }
3138
+ {
3139
+ obj_type = this.OAMD_OBJECT_TYPE_ISF;
3140
+ }
3141
+ {
3142
+ n_isf = this.BAM_g_table10.slice(0)[isf_config];
3143
+ }
3144
+ }
3145
+ } else {
3146
+ {
3147
+ {
3148
+ obj_type = this.OAMD_OBJECT_TYPE_BED;
3149
+ }
3150
+ {
3151
+ b_ch_assign_code = this.BAM_source.get("", 1);
3152
+ this.BAM_g_position += 1;
3153
+ }
3154
+ if (b_ch_assign_code) {
3155
+ {
3156
+ {
3157
+ bed_chan_assign_code = this.BAM_source.get("", 3);
3158
+ this.BAM_g_position += 3;
3159
+ }
3160
+ if (this.BAM_g_table11.slice(0).indexOf(bed_chan_assign_code) >= 0) {
3161
+ {
3162
+ lfe_signalled = 1;
3163
+ }
3164
+ }
3165
+ }
3166
+ } else {
3167
+ {
3168
+ {
3169
+ b_chan_assign_mask = this.BAM_source.get("", 1);
3170
+ this.BAM_g_position += 1;
3171
+ }
3172
+ if (b_chan_assign_mask) {
3173
+ {
3174
+ {
3175
+ b_nonstd_bed_channel_assignment = this.BAM_source.get("", 1);
3176
+ this.BAM_g_position += 1;
3177
+ }
3178
+ if (b_nonstd_bed_channel_assignment) {
3179
+ {
3180
+ {
3181
+ nonstd_bed_channel_assignment_mask = this.BAM_source.get("", 17);
3182
+ this.BAM_g_position += 17;
3183
+ }
3184
+ for (this.i = 0; this.i < 17; this.i++) {
3185
+ if (nonstd_bed_channel_assignment_mask >> this.i & 1) {
3186
+ if (this.i == 3 || this.i == 16) {
3187
+ {
3188
+ lfe_signalled = 1;
3189
+ }
3190
+ }
3191
+ }
3192
+ }
3193
+ }
3194
+ } else {
3195
+ {
3196
+ {
3197
+ std_bed_channel_assignment_mask = this.BAM_source.get("", 10);
3198
+ this.BAM_g_position += 10;
3199
+ }
3200
+ for (this.i = 0; this.i < 10; this.i++) {
3201
+ if (std_bed_channel_assignment_mask >> this.i & 1) {
3202
+ {
3203
+ if (this.i == 2 || this.i == 9) {
3204
+ {
3205
+ lfe_signalled = 1;
3206
+ }
3207
+ }
3208
+ {
3209
+ oc_num_channels = this.BAM_g_table12.slice(0)[this.i];
3210
+ }
3211
+ }
3212
+ }
3213
+ }
3214
+ }
3215
+ }
3216
+ }
3217
+ } else {
3218
+ {
3219
+ if (n_signals > 1) {
3220
+ {
3221
+ {
3222
+ bed_ch_bits = Math.ceil(Math.log(n_signals) / Math.log(2));
3223
+ }
3224
+ {
3225
+ n_bed_signals_minus1 = this.BAM_source.get("", bed_ch_bits);
3226
+ this.BAM_g_position += bed_ch_bits;
3227
+ }
3228
+ {
3229
+ n_bed_signals = n_bed_signals_minus1 + 1;
3230
+ }
3231
+ }
3232
+ } else {
3233
+ {
3234
+ n_bed_signals = 1;
3235
+ }
3236
+ }
3237
+ for (b = 0; b < n_bed_signals; b++) {
3238
+ {
3239
+ {
3240
+ nonstd_bed_channel_assignment = this.BAM_source.get("", 4);
3241
+ this.BAM_g_position += 4;
3242
+ }
3243
+ if (n_bed_signals == 3 || n_bed_signals == 16) {
3244
+ {
3245
+ lfe_signalled = 1;
3246
+ }
3247
+ }
3248
+ }
3249
+ }
3250
+ }
3251
+ }
3252
+ }
3253
+ }
3254
+ }
3255
+ }
3256
+ }
3257
+ }
3258
+ }
3259
+ }
3260
+ F_ac4_presentation_substream_info(aps_presentation_version) {
3261
+ var substream_index;
3262
+ var b_lfe = null;
3263
+ var b_lfe;
3264
+ var b_alternative;
3265
+ var b_iframe_pres;
3266
+ {
3267
+ {
3268
+ b_alternative = this.BAM_source.get("", 1);
3269
+ this.BAM_g_position += 1;
3270
+ }
3271
+ {
3272
+ b_iframe_pres = this.BAM_source.get("", 1);
3273
+ this.BAM_g_position += 1;
3274
+ }
3275
+ {
3276
+ substream_index = this.BAM_source.get("", 2);
3277
+ this.BAM_g_position += 2;
3278
+ }
3279
+ if (substream_index == 3) {
3280
+ {
3281
+ {
3282
+ this.v = this.F_variable_bits(2);
3283
+ if (this.v == null) {
3284
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
3285
+ }
3286
+ }
3287
+ {
3288
+ substream_index += this.v;
3289
+ }
3290
+ }
3291
+ }
3292
+ {
3293
+ if (b_lfe == null) {
3294
+ b_lfe = new Array(substream_index + 1).fill(0);
3295
+ } else if (b_lfe.length <= substream_index) {
3296
+ b_lfe.push.apply(b_lfe, new Array(substream_index - b_lfe.length + 1).fill(0));
3297
+ }
3298
+ b_lfe[substream_index] = 0;
3299
+ }
3300
+ {
3301
+ this.last_referenced_substream = Math.max(this.last_referenced_substream, substream_index);
3302
+ }
3303
+ {
3304
+ this.referenced_substreams.push(substream_index);
3305
+ }
3306
+ }
3307
+ }
3308
+ F_presentation_version() {
3309
+ var val;
3310
+ var b_tmp;
3311
+ {
3312
+ {
3313
+ val = 0;
3314
+ }
3315
+ {
3316
+ b_tmp = this.BAM_source.get("", 1);
3317
+ this.BAM_g_position += 1;
3318
+ }
3319
+ while (b_tmp) {
3320
+ {
3321
+ {
3322
+ val = val + 1;
3323
+ }
3324
+ {
3325
+ b_tmp = this.BAM_source.get("", 1);
3326
+ this.BAM_g_position += 1;
3327
+ }
3328
+ }
3329
+ }
3330
+ return val;
3331
+ }
3332
+ }
3333
+ F_get_ch_mode(cm) {
3334
+ {
3335
+ if (cm == this.CHANNEL_MODE_MONO) {
3336
+ {
3337
+ this.n = 0;
3338
+ }
3339
+ } else if (cm == this.CHANNEL_MODE_STEREO) {
3340
+ {
3341
+ this.n = 1;
3342
+ }
3343
+ } else if (cm == this.CHANNEL_MODE_30) {
3344
+ {
3345
+ this.n = 2;
3346
+ }
3347
+ } else if (cm == this.CHANNEL_MODE_50) {
3348
+ {
3349
+ this.n = 3;
3350
+ }
3351
+ } else if (cm == this.CHANNEL_MODE_51) {
3352
+ {
3353
+ this.n = 4;
3354
+ }
3355
+ } else if (cm == this.CHANNEL_MODE_70_34) {
3356
+ {
3357
+ this.n = 5;
3358
+ }
3359
+ } else if (cm == this.CHANNEL_MODE_71_34) {
3360
+ {
3361
+ this.n = 6;
3362
+ }
3363
+ } else if (cm == this.CHANNEL_MODE_70_52) {
3364
+ {
3365
+ this.n = 7;
3366
+ }
3367
+ } else if (cm == this.CHANNEL_MODE_71_52) {
3368
+ {
3369
+ this.n = 8;
3370
+ }
3371
+ } else if (cm == this.CHANNEL_MODE_70_322) {
3372
+ {
3373
+ this.n = 9;
3374
+ }
3375
+ } else if (cm == this.CHANNEL_MODE_71_322) {
3376
+ {
3377
+ this.n = 10;
3378
+ }
3379
+ } else if (cm == this.CHANNEL_MODE_704) {
3380
+ {
3381
+ this.n = 11;
3382
+ }
3383
+ } else if (cm == this.CHANNEL_MODE_714) {
3384
+ {
3385
+ this.n = 12;
3386
+ }
3387
+ } else if (cm == this.CHANNEL_MODE_904) {
3388
+ {
3389
+ this.n = 13;
3390
+ }
3391
+ } else if (cm == this.CHANNEL_MODE_914) {
3392
+ {
3393
+ this.n = 14;
3394
+ }
3395
+ } else {
3396
+ if (1) {
3397
+ throw "Unknown channel mode!";
3398
+ }
3399
+ }
3400
+ return this.n;
3401
+ }
3402
+ }
3403
+ F_presentation_config_ext_info() {
3404
+ {
3405
+ {
3406
+ this.n_skip_bytes = this.BAM_source.get("", 5);
3407
+ this.BAM_g_position += 5;
3408
+ }
3409
+ {
3410
+ this.b_more_skip_bytes = this.BAM_source.get("", 1);
3411
+ this.BAM_g_position += 1;
3412
+ }
3413
+ if (this.b_more_skip_bytes) {
3414
+ {
3415
+ {
3416
+ this.v = this.F_variable_bits(2);
3417
+ if (this.v == null) {
3418
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
3419
+ }
3420
+ }
3421
+ {
3422
+ this.n_skip_bytes += this.v << 5;
3423
+ }
3424
+ }
3425
+ }
3426
+ if (0) {
3427
+ {
3428
+ {
3429
+ this.n_bits_read_0 = this.BAM_g_position;
3430
+ }
3431
+ {
3432
+ this.F_ac4_presentation_v2_info(this.toc_i);
3433
+ }
3434
+ {
3435
+ this.n_bits_read_1 = this.BAM_g_position;
3436
+ }
3437
+ {
3438
+ this.n_bits_read = this.n_bits_read_1 - this.n_bits_read_0;
3439
+ }
3440
+ if ((n_bits_read % 8 + 8) % 8) {
3441
+ {
3442
+ {
3443
+ this.n_skip_bits = 8 - (n_bits_read % 8 + 8) % 8;
3444
+ }
3445
+ {
3446
+ this.reserved = this.BAM_source.get("", this.n_skip_bits);
3447
+ this.BAM_g_position += this.n_skip_bits;
3448
+ }
3449
+ {
3450
+ this.n_bits_read += this.n_skip_bits;
3451
+ }
3452
+ }
3453
+ }
3454
+ {
3455
+ this.n_skip_bytes = this.n_skip_bytes - Math.floor(this.n_bits_read / 8);
3456
+ }
3457
+ }
3458
+ }
3459
+ if (this.bitstream_version >= 1 && this.presentation_config == 8) {
3460
+ {
3461
+ {
3462
+ this.n_bits_read_0 = this.BAM_g_position;
3463
+ }
3464
+ {
3465
+ this.n_bits_read_1 = this.BAM_g_position;
3466
+ }
3467
+ {
3468
+ this.padding = this.BAM_source.get("", this.n_skip_bytes * 8 - (this.n_bits_read_1 - this.n_bits_read_0));
3469
+ this.BAM_g_position += this.n_skip_bytes * 8 - (this.n_bits_read_1 - this.n_bits_read_0);
3470
+ }
3471
+ }
3472
+ } else {
3473
+ for (this.i = 0; this.i < this.n_skip_bytes; this.i++) {
3474
+ {
3475
+ this.reserved = this.BAM_source.get("", 8);
3476
+ this.BAM_g_position += 8;
3477
+ }
3478
+ }
3479
+ }
3480
+ }
3481
+ }
3482
+ F_define_channel_modes() {
3483
+ var CHANNEL_MODE_7X_34 = null;
3484
+ var CHANNEL_MODE_7X_34;
3485
+ var CHANNEL_MODE_7X_322 = null;
3486
+ var CHANNEL_MODE_7X_322;
3487
+ var CHANNEL_MODE_7X = null;
3488
+ var CHANNEL_MODE_7X;
3489
+ var CHANNEL_MODE_7X_52 = null;
3490
+ var CHANNEL_MODE_7X_52;
3491
+ var CHANNEL_MODE_5X = null;
3492
+ var CHANNEL_MODE_5X;
3493
+ {
3494
+ {
3495
+ this.CHANNEL_MODE_MONO = 0;
3496
+ }
3497
+ {
3498
+ this.CHANNEL_MODE_STEREO = 2;
3499
+ }
3500
+ {
3501
+ this.CHANNEL_MODE_30 = 12;
3502
+ }
3503
+ {
3504
+ this.CHANNEL_MODE_50 = 13;
3505
+ }
3506
+ {
3507
+ this.CHANNEL_MODE_51 = 14;
3508
+ }
3509
+ {
3510
+ this.CHANNEL_MODE_70_34 = 120;
3511
+ }
3512
+ {
3513
+ this.CHANNEL_MODE_71_34 = 121;
3514
+ }
3515
+ {
3516
+ this.CHANNEL_MODE_70_52 = 122;
3517
+ }
3518
+ {
3519
+ this.CHANNEL_MODE_71_52 = 123;
3520
+ }
3521
+ {
3522
+ this.CHANNEL_MODE_70_322 = 124;
3523
+ }
3524
+ {
3525
+ this.CHANNEL_MODE_71_322 = 125;
3526
+ }
3527
+ {
3528
+ this.CHANNEL_MODE_704 = 252;
3529
+ }
3530
+ {
3531
+ this.CHANNEL_MODE_714 = 253;
3532
+ }
3533
+ {
3534
+ this.CHANNEL_MODE_904 = 508;
3535
+ }
3536
+ {
3537
+ this.CHANNEL_MODE_914 = 509;
3538
+ }
3539
+ {
3540
+ this.CHANNEL_MODE_222 = 510;
3541
+ }
3542
+ {
3543
+ CHANNEL_MODE_5X = [this.CHANNEL_MODE_50, this.CHANNEL_MODE_51];
3544
+ }
3545
+ {
3546
+ CHANNEL_MODE_7X_34 = [this.CHANNEL_MODE_70_34, this.CHANNEL_MODE_71_34];
3547
+ }
3548
+ {
3549
+ CHANNEL_MODE_7X_52 = [this.CHANNEL_MODE_70_52, this.CHANNEL_MODE_71_52];
3550
+ }
3551
+ {
3552
+ CHANNEL_MODE_7X_322 = [this.CHANNEL_MODE_70_322, this.CHANNEL_MODE_71_322];
3553
+ }
3554
+ {
3555
+ CHANNEL_MODE_7X = CHANNEL_MODE_7X_34 + CHANNEL_MODE_7X_52 + CHANNEL_MODE_7X_322;
3556
+ }
3557
+ }
3558
+ }
3559
+ F_channel_mode_to_ch_mode(cm) {
3560
+ {
3561
+ if (cm == this.CHANNEL_MODE_MONO) {
3562
+ return 0;
3563
+ } else if (cm == this.CHANNEL_MODE_STEREO) {
3564
+ return 1;
3565
+ } else if (cm == this.CHANNEL_MODE_30) {
3566
+ return 2;
3567
+ } else if (cm == this.CHANNEL_MODE_50) {
3568
+ return 3;
3569
+ } else if (cm == this.CHANNEL_MODE_51) {
3570
+ return 4;
3571
+ } else if (cm == this.CHANNEL_MODE_70_34) {
3572
+ return 5;
3573
+ } else if (cm == this.CHANNEL_MODE_71_34) {
3574
+ return 6;
3575
+ } else if (cm == this.CHANNEL_MODE_70_52) {
3576
+ return 7;
3577
+ } else if (cm == this.CHANNEL_MODE_71_52) {
3578
+ return 8;
3579
+ } else if (cm == this.CHANNEL_MODE_70_322) {
3580
+ return 9;
3581
+ } else if (cm == this.CHANNEL_MODE_71_322) {
3582
+ return 10;
3583
+ } else if (cm == this.CHANNEL_MODE_704) {
3584
+ return 11;
3585
+ } else if (cm == this.CHANNEL_MODE_714) {
3586
+ return 12;
3587
+ } else if (cm == this.CHANNEL_MODE_904) {
3588
+ return 13;
3589
+ } else if (cm == this.CHANNEL_MODE_914) {
3590
+ return 14;
3591
+ } else if (cm == this.CHANNEL_MODE_222) {
3592
+ return 15;
3593
+ } else {
3594
+ if (1) {
3595
+ throw "Cannot convert extended channel mode to ch_mode!";
3596
+ }
3597
+ }
3598
+ }
3599
+ }
3600
+ F_variable_bits(n_bits) {
3601
+ var read;
3602
+ var value;
3603
+ var b_read_more;
3604
+ {
3605
+ {
3606
+ value = 0;
3607
+ }
3608
+ {
3609
+ b_read_more = 1;
3610
+ }
3611
+ while (b_read_more) {
3612
+ {
3613
+ {
3614
+ read = this.BAM_source.get("", n_bits);
3615
+ this.BAM_g_position += n_bits;
3616
+ }
3617
+ {
3618
+ value += read;
3619
+ }
3620
+ {
3621
+ b_read_more = this.BAM_source.get("", 1);
3622
+ this.BAM_g_position += 1;
3623
+ }
3624
+ if (b_read_more) {
3625
+ {
3626
+ {
3627
+ value <<= n_bits;
3628
+ }
3629
+ {
3630
+ value += 1 << n_bits;
3631
+ }
3632
+ }
3633
+ }
3634
+ }
3635
+ }
3636
+ return value;
3637
+ }
3638
+ }
3639
+ F_raw_ac4_frame_toc_only() {
3640
+ var ac4_toc_end;
3641
+ var ac4_toc_begin;
3642
+ var frame_len_base;
3643
+ {
3644
+ {
3645
+ ac4_toc_begin = this.BAM_g_position;
3646
+ }
3647
+ {
3648
+ this.F_ac4_toc();
3649
+ }
3650
+ {
3651
+ ac4_toc_end = this.BAM_g_position;
3652
+ this.BAM_sink.after_position("ac4_toc_end", ac4_toc_end);
3653
+ }
3654
+ {
3655
+ frame_len_base = this.BAM_g_table13.slice(0)[this.frame_rate_index];
3656
+ }
3657
+ }
3658
+ }
3659
+ F_ac4_presentation_info() {
3660
+ {
3661
+ {
3662
+ this.b_single_substream = this.BAM_source.get("", 1);
3663
+ this.BAM_g_position += 1;
3664
+ }
3665
+ if (this.b_single_substream != 1) {
3666
+ {
3667
+ {
3668
+ this.presentation_config = this.BAM_source.get("", 3);
3669
+ this.BAM_g_position += 3;
3670
+ }
3671
+ if (this.presentation_config == 7) {
3672
+ {
3673
+ {
3674
+ this.v = this.F_variable_bits(2);
3675
+ if (this.v == null) {
3676
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
3677
+ }
3678
+ }
3679
+ {
3680
+ this.presentation_config += this.v;
3681
+ }
3682
+ }
3683
+ }
3684
+ }
3685
+ }
3686
+ {
3687
+ this.presentation_version = this.F_presentation_version();
3688
+ if (this.presentation_version == null) {
3689
+ throw ParseError("F_presentation_version", "expected to return a value, returned None");
3690
+ }
3691
+ }
3692
+ if (this.b_single_substream != 1 && this.presentation_config == 6) {
3693
+ {
3694
+ this.b_add_emdf_substreams = 1;
3695
+ }
3696
+ } else {
3697
+ {
3698
+ {
3699
+ this.presentation_level = this.BAM_source.get("", 3);
3700
+ this.BAM_g_position += 3;
3701
+ this.BAM_sink.write_uint("presentation_level", 3, this.presentation_level, this.BAM_g_position);
3702
+ }
3703
+ {
3704
+ this.b_presentation_id = this.BAM_source.get("", 1);
3705
+ this.BAM_g_position += 1;
3706
+ this.BAM_sink.write_uint("b_presentation_id", 1, this.b_presentation_id, this.BAM_g_position);
3707
+ }
3708
+ if (this.b_presentation_id) {
3709
+ {
3710
+ this.BAM_sink.before_call("variable_bits", [2], "presentation_id", this.BAM_g_position);
3711
+ this.presentation_id = this.F_variable_bits(2);
3712
+ if (this.presentation_id == null) {
3713
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
3714
+ }
3715
+ this.BAM_sink.after_call("variable_bits", this.presentation_id, "presentation_id", this.BAM_g_position);
3716
+ }
3717
+ }
3718
+ {
3719
+ this.F_frame_rate_multiply_info();
3720
+ }
3721
+ {
3722
+ this.F_emdf_info();
3723
+ }
3724
+ if (this.b_single_substream == 1) {
3725
+ {
3726
+ this.F_ac4_substream_info(0, 0, 0);
3727
+ }
3728
+ } else {
3729
+ {
3730
+ {
3731
+ this.b_hsf_ext = this.BAM_source.get("", 1);
3732
+ this.BAM_g_position += 1;
3733
+ }
3734
+ if (this.presentation_config == 0) {
3735
+ {
3736
+ {
3737
+ this.F_ac4_substream_info(0, 0, 0);
3738
+ }
3739
+ if (this.b_hsf_ext) {
3740
+ {
3741
+ this.F_ac4_hsf_ext_substream_info(1);
3742
+ }
3743
+ }
3744
+ {
3745
+ this.F_ac4_substream_info(0, 1, 1);
3746
+ }
3747
+ }
3748
+ } else if (this.presentation_config == 1) {
3749
+ {
3750
+ {
3751
+ this.F_ac4_substream_info(0, 0, 0);
3752
+ }
3753
+ if (this.b_hsf_ext) {
3754
+ {
3755
+ this.F_ac4_hsf_ext_substream_info(1);
3756
+ }
3757
+ }
3758
+ {
3759
+ this.F_ac4_substream_info(0, 0, 1);
3760
+ }
3761
+ }
3762
+ } else if (this.presentation_config == 2) {
3763
+ {
3764
+ {
3765
+ this.F_ac4_substream_info(0, 0, 0);
3766
+ }
3767
+ if (this.b_hsf_ext) {
3768
+ {
3769
+ this.F_ac4_hsf_ext_substream_info(1);
3770
+ }
3771
+ }
3772
+ {
3773
+ this.F_ac4_substream_info(1, 0, 1);
3774
+ }
3775
+ }
3776
+ } else if (this.presentation_config == 3) {
3777
+ {
3778
+ {
3779
+ this.F_ac4_substream_info(0, 0, 0);
3780
+ }
3781
+ if (this.b_hsf_ext) {
3782
+ {
3783
+ this.F_ac4_hsf_ext_substream_info(1);
3784
+ }
3785
+ }
3786
+ {
3787
+ this.F_ac4_substream_info(0, 1, 1);
3788
+ }
3789
+ {
3790
+ this.F_ac4_substream_info(1, 0, 2);
3791
+ }
3792
+ }
3793
+ } else if (this.presentation_config == 4) {
3794
+ {
3795
+ {
3796
+ this.F_ac4_substream_info(0, 0, 0);
3797
+ }
3798
+ if (this.b_hsf_ext) {
3799
+ {
3800
+ this.F_ac4_hsf_ext_substream_info(1);
3801
+ }
3802
+ }
3803
+ {
3804
+ this.F_ac4_substream_info(0, 0, 1);
3805
+ }
3806
+ {
3807
+ this.F_ac4_substream_info(1, 0, 2);
3808
+ }
3809
+ }
3810
+ } else if (this.presentation_config == 5) {
3811
+ {
3812
+ {
3813
+ this.F_ac4_substream_info(0, 0, 0);
3814
+ }
3815
+ if (this.b_hsf_ext) {
3816
+ {
3817
+ this.F_ac4_hsf_ext_substream_info(1);
3818
+ }
3819
+ }
3820
+ }
3821
+ } else {
3822
+ {
3823
+ this.F_presentation_config_ext_info();
3824
+ }
3825
+ }
3826
+ }
3827
+ }
3828
+ {
3829
+ this.b_pre_virtualized = this.BAM_source.get("", 1);
3830
+ this.BAM_g_position += 1;
3831
+ }
3832
+ {
3833
+ this.b_add_emdf_substreams = this.BAM_source.get("", 1);
3834
+ this.BAM_g_position += 1;
3835
+ }
3836
+ }
3837
+ }
3838
+ if (this.b_add_emdf_substreams) {
3839
+ {
3840
+ {
3841
+ this.n_add_emdf_substreams = this.BAM_source.get("", 2);
3842
+ this.BAM_g_position += 2;
3843
+ }
3844
+ if (this.n_add_emdf_substreams == 0) {
3845
+ {
3846
+ {
3847
+ this.v = this.F_variable_bits(2);
3848
+ if (this.v == null) {
3849
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
3850
+ }
3851
+ }
3852
+ {
3853
+ this.n_add_emdf_substreams = this.v + 4;
3854
+ }
3855
+ }
3856
+ }
3857
+ for (this.pi_i = 0; this.pi_i < this.n_add_emdf_substreams; this.pi_i++) {
3858
+ {
3859
+ this.F_emdf_info();
3860
+ }
3861
+ }
3862
+ }
3863
+ }
3864
+ }
3865
+ }
3866
+ F_substream_index_table() {
3867
+ var b_size_present;
3868
+ var substream_type = null;
3869
+ var substream_type;
3870
+ var b_substream_type_known = null;
3871
+ var b_substream_type_known;
3872
+ var substream_size = null;
3873
+ var substream_size;
3874
+ var n_substreams;
3875
+ var s;
3876
+ var b_more_bits;
3877
+ {
3878
+ {
3879
+ n_substreams = this.BAM_source.get("", 2);
3880
+ this.BAM_g_position += 2;
3881
+ }
3882
+ if (n_substreams == 0) {
3883
+ {
3884
+ {
3885
+ this.v = this.F_variable_bits(2);
3886
+ if (this.v == null) {
3887
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
3888
+ }
3889
+ }
3890
+ {
3891
+ n_substreams = this.v + 4;
3892
+ }
3893
+ }
3894
+ }
3895
+ if (n_substreams - 1 < this.last_referenced_substream) {
3896
+ throw "Number of substreams (n_substreams) indicated by substream_index_table is less than last referenced substream in TOC (last_referenced_substream).";
3897
+ }
3898
+ if (n_substreams - 1 > this.last_referenced_substream) {
3899
+ {
3900
+ {
3901
+ if (b_substream_type_known == null) {
3902
+ b_substream_type_known = new Array(n_substreams - 1 + 1).fill(0);
3903
+ } else if (b_substream_type_known.length <= n_substreams - 1) {
3904
+ b_substream_type_known.push.apply(b_substream_type_known, new Array(n_substreams - 1 - b_substream_type_known.length + 1).fill(0));
3905
+ }
3906
+ b_substream_type_known[n_substreams - 1] = 0;
3907
+ }
3908
+ {
3909
+ if (substream_type == null) {
3910
+ substream_type = new Array(n_substreams - 1 + 1).fill(null);
3911
+ } else if (substream_type.length <= n_substreams - 1) {
3912
+ substream_type.push.apply(substream_type, new Array(n_substreams - 1 - substream_type.length + 1).fill(null));
3913
+ }
3914
+ substream_type[n_substreams - 1] = "unknown";
3915
+ }
3916
+ }
3917
+ }
3918
+ if (n_substreams == 1) {
3919
+ {
3920
+ b_size_present = this.BAM_source.get("", 1);
3921
+ this.BAM_g_position += 1;
3922
+ }
3923
+ } else {
3924
+ {
3925
+ b_size_present = 1;
3926
+ }
3927
+ }
3928
+ if (b_size_present) {
3929
+ for (s = 0; s < n_substreams; s++) {
3930
+ {
3931
+ {
3932
+ b_more_bits = this.BAM_source.get("", 1);
3933
+ this.BAM_g_position += 1;
3934
+ }
3935
+ {
3936
+ if (substream_size == null) {
3937
+ substream_size = new Array(s + 1).fill(0);
3938
+ } else if (substream_size.length <= s) {
3939
+ substream_size.push.apply(substream_size, new Array(s - substream_size.length + 1).fill(0));
3940
+ }
3941
+ substream_size[s] = this.BAM_source.get("", 10);
3942
+ this.BAM_g_position += 10;
3943
+ }
3944
+ if (b_more_bits) {
3945
+ {
3946
+ {
3947
+ this.v = this.F_variable_bits(2);
3948
+ if (this.v == null) {
3949
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
3950
+ }
3951
+ }
3952
+ {
3953
+ if (substream_size == null) {
3954
+ substream_size = new Array(s + 1).fill(0);
3955
+ } else if (substream_size.length <= s) {
3956
+ substream_size.push.apply(substream_size, new Array(s - substream_size.length + 1).fill(0));
3957
+ }
3958
+ substream_size[s] += this.v << 10;
3959
+ }
3960
+ }
3961
+ }
3962
+ }
3963
+ }
3964
+ }
3965
+ }
3966
+ }
3967
+ F_ac4_presentation_v2_info(apv_toc_i) {
3968
+ {
3969
+ {
3970
+ if (this.presentation_to_groups == null) {
3971
+ this.presentation_to_groups = new Array(this.toc_i + 1).fill(null);
3972
+ } else if (this.presentation_to_groups.length <= this.toc_i) {
3973
+ this.presentation_to_groups.push.apply(this.presentation_to_groups, new Array(this.toc_i - this.presentation_to_groups.length + 1).fill(null));
3974
+ }
3975
+ this.presentation_to_groups[this.toc_i] = [];
3976
+ }
3977
+ {
3978
+ this.b_single_substream_group = this.BAM_source.get("", 1);
3979
+ this.BAM_g_position += 1;
3980
+ }
3981
+ if (this.b_single_substream_group != 1) {
3982
+ {
3983
+ {
3984
+ this.presentation_config = this.BAM_source.get("", 3);
3985
+ this.BAM_g_position += 3;
3986
+ }
3987
+ if (this.presentation_config == 7) {
3988
+ {
3989
+ {
3990
+ this.v = this.F_variable_bits(2);
3991
+ if (this.v == null) {
3992
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
3993
+ }
3994
+ }
3995
+ {
3996
+ this.presentation_config += this.v;
3997
+ }
3998
+ }
3999
+ }
4000
+ }
4001
+ }
4002
+ if (this.bitstream_version != 1) {
4003
+ {
4004
+ this.presentation_version = this.F_presentation_version();
4005
+ if (this.presentation_version == null) {
4006
+ throw ParseError("F_presentation_version", "expected to return a value, returned None");
4007
+ }
4008
+ }
4009
+ }
4010
+ if (this.b_single_substream_group != 1 && this.presentation_config == 6) {
4011
+ {
4012
+ this.b_add_emdf_substreams = 1;
4013
+ }
4014
+ } else {
4015
+ {
4016
+ if (this.bitstream_version != 1) {
4017
+ {
4018
+ this.presentation_level = this.BAM_source.get("", 3);
4019
+ this.BAM_g_position += 3;
4020
+ this.BAM_sink.write_uint("presentation_level", 3, this.presentation_level, this.BAM_g_position);
4021
+ }
4022
+ }
4023
+ {
4024
+ this.b_presentation_id = this.BAM_source.get("", 1);
4025
+ this.BAM_g_position += 1;
4026
+ this.BAM_sink.write_uint("b_presentation_id", 1, this.b_presentation_id, this.BAM_g_position);
4027
+ }
4028
+ if (this.b_presentation_id) {
4029
+ {
4030
+ this.BAM_sink.before_call("variable_bits", [2], "presentation_id", this.BAM_g_position);
4031
+ this.presentation_id = this.F_variable_bits(2);
4032
+ if (this.presentation_id == null) {
4033
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
4034
+ }
4035
+ this.BAM_sink.after_call("variable_bits", this.presentation_id, "presentation_id", this.BAM_g_position);
4036
+ }
4037
+ }
4038
+ {
4039
+ this.F_frame_rate_multiply_info();
4040
+ }
4041
+ {
4042
+ this.F_frame_rate_fractions_info();
4043
+ }
4044
+ {
4045
+ this.F_emdf_info();
4046
+ }
4047
+ {
4048
+ this.b_presentation_filter = this.BAM_source.get("", 1);
4049
+ this.BAM_g_position += 1;
4050
+ }
4051
+ if (this.b_presentation_filter) {
4052
+ {
4053
+ this.b_enable_presentation = this.BAM_source.get("", 1);
4054
+ this.BAM_g_position += 1;
4055
+ }
4056
+ }
4057
+ if (this.b_single_substream_group == 1) {
4058
+ {
4059
+ {
4060
+ this.F_ac4_sgi_specifier(0, 0, 0);
4061
+ }
4062
+ {
4063
+ this.n_substream_groups = 1;
4064
+ }
4065
+ }
4066
+ } else {
4067
+ {
4068
+ {
4069
+ this.b_multi_pid = this.BAM_source.get("", 1);
4070
+ this.BAM_g_position += 1;
4071
+ }
4072
+ if (this.presentation_config == 0) {
4073
+ {
4074
+ {
4075
+ this.F_ac4_sgi_specifier(0, 0, 0);
4076
+ }
4077
+ {
4078
+ this.F_ac4_sgi_specifier(0, 1, 1);
4079
+ }
4080
+ {
4081
+ this.n_substream_groups = 2;
4082
+ }
4083
+ }
4084
+ } else if (this.presentation_config == 1) {
4085
+ {
4086
+ {
4087
+ this.F_ac4_sgi_specifier(0, 0, 0);
4088
+ }
4089
+ {
4090
+ this.F_ac4_sgi_specifier(0, 0, 1);
4091
+ }
4092
+ {
4093
+ this.n_substream_groups = 1;
4094
+ }
4095
+ }
4096
+ } else if (this.presentation_config == 2) {
4097
+ {
4098
+ {
4099
+ this.F_ac4_sgi_specifier(0, 0, 0);
4100
+ }
4101
+ {
4102
+ this.F_ac4_sgi_specifier(1, 0, 1);
4103
+ }
4104
+ {
4105
+ this.n_substream_groups = 2;
4106
+ }
4107
+ }
4108
+ } else if (this.presentation_config == 3) {
4109
+ {
4110
+ {
4111
+ this.F_ac4_sgi_specifier(0, 0, 0);
4112
+ }
4113
+ {
4114
+ this.F_ac4_sgi_specifier(0, 1, 1);
4115
+ }
4116
+ {
4117
+ this.F_ac4_sgi_specifier(1, 0, 2);
4118
+ }
4119
+ {
4120
+ this.n_substream_groups = 3;
4121
+ }
4122
+ }
4123
+ } else if (this.presentation_config == 4) {
4124
+ {
4125
+ {
4126
+ this.F_ac4_sgi_specifier(0, 0, 0);
4127
+ }
4128
+ {
4129
+ this.F_ac4_sgi_specifier(0, 0, 1);
4130
+ }
4131
+ {
4132
+ this.F_ac4_sgi_specifier(1, 0, 2);
4133
+ }
4134
+ {
4135
+ this.n_substream_groups = 2;
4136
+ }
4137
+ }
4138
+ } else if (this.presentation_config == 5) {
4139
+ {
4140
+ {
4141
+ this.n_substream_groups_minus2 = this.BAM_source.get("", 2);
4142
+ this.BAM_g_position += 2;
4143
+ }
4144
+ {
4145
+ this.n_substream_groups = this.n_substream_groups_minus2 + 2;
4146
+ }
4147
+ if (this.n_substream_groups == 5) {
4148
+ {
4149
+ {
4150
+ this.v = this.F_variable_bits(2);
4151
+ if (this.v == null) {
4152
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
4153
+ }
4154
+ }
4155
+ {
4156
+ this.n_substream_groups += this.v;
4157
+ }
4158
+ }
4159
+ }
4160
+ for (this.sg = 0; this.sg < this.n_substream_groups; this.sg++) {
4161
+ {
4162
+ this.F_ac4_sgi_specifier(0, 0, 0);
4163
+ }
4164
+ }
4165
+ }
4166
+ } else {
4167
+ {
4168
+ {
4169
+ this.n_substream_groups = 0;
4170
+ }
4171
+ {
4172
+ this.F_presentation_config_ext_info();
4173
+ }
4174
+ }
4175
+ }
4176
+ }
4177
+ }
4178
+ {
4179
+ this.b_pre_virtualized = this.BAM_source.get("", 1);
4180
+ this.BAM_g_position += 1;
4181
+ }
4182
+ {
4183
+ this.b_add_emdf_substreams = this.BAM_source.get("", 1);
4184
+ this.BAM_g_position += 1;
4185
+ }
4186
+ {
4187
+ this.F_ac4_presentation_substream_info(this.presentation_version);
4188
+ }
4189
+ }
4190
+ }
4191
+ if (this.b_add_emdf_substreams) {
4192
+ {
4193
+ {
4194
+ this.n_add_emdf_substreams = this.BAM_source.get("", 2);
4195
+ this.BAM_g_position += 2;
4196
+ }
4197
+ if (this.n_add_emdf_substreams == 0) {
4198
+ {
4199
+ {
4200
+ this.v = this.F_variable_bits(2);
4201
+ if (this.v == null) {
4202
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
4203
+ }
4204
+ }
4205
+ {
4206
+ this.n_add_emdf_substreams = this.v + 4;
4207
+ }
4208
+ }
4209
+ }
4210
+ for (this.pi_i = 0; this.pi_i < this.n_add_emdf_substreams; this.pi_i++) {
4211
+ {
4212
+ this.F_emdf_info();
4213
+ }
4214
+ }
4215
+ }
4216
+ }
4217
+ }
4218
+ }
4219
+ F_frame_size() {
4220
+ var frame_size;
4221
+ {
4222
+ {
4223
+ frame_size = this.BAM_source.get("", 16);
4224
+ this.BAM_g_position += 16;
4225
+ }
4226
+ if (frame_size == 65535) {
4227
+ {
4228
+ frame_size = this.BAM_source.get("", 24);
4229
+ this.BAM_g_position += 24;
4230
+ }
4231
+ }
4232
+ }
4233
+ }
4234
+ F_ac4_toc() {
4235
+ var b_wait_frames;
4236
+ var payload_base_minus1;
4237
+ var n_presentations;
4238
+ var wait_frames;
4239
+ var b_payload_base;
4240
+ var program_uuid;
4241
+ var total_n_substream_groups;
4242
+ var payload_base;
4243
+ var b_program_uuid_present;
4244
+ var b_single_presentation;
4245
+ var b_iframe_global;
4246
+ var sequence_counter;
4247
+ var b_program_id;
4248
+ var b_more_presentations;
4249
+ var short_program_id;
4250
+ {
4251
+ {
4252
+ this.bitstream_version = this.BAM_source.get("", 2);
4253
+ this.BAM_g_position += 2;
4254
+ }
4255
+ if (this.bitstream_version == 3) {
4256
+ {
4257
+ {
4258
+ this.v = this.F_variable_bits(2);
4259
+ if (this.v == null) {
4260
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
4261
+ }
4262
+ }
4263
+ {
4264
+ this.bitstream_version += this.v;
4265
+ }
4266
+ }
4267
+ }
4268
+ {
4269
+ sequence_counter = this.BAM_source.get("", 10);
4270
+ this.BAM_g_position += 10;
4271
+ }
4272
+ {
4273
+ b_wait_frames = this.BAM_source.get("", 1);
4274
+ this.BAM_g_position += 1;
4275
+ }
4276
+ if (b_wait_frames) {
4277
+ {
4278
+ {
4279
+ wait_frames = this.BAM_source.get("", 3);
4280
+ this.BAM_g_position += 3;
4281
+ }
4282
+ if (wait_frames > 0) {
4283
+ {
4284
+ this.reserved = this.BAM_source.get("", 2);
4285
+ this.BAM_g_position += 2;
4286
+ }
4287
+ }
4288
+ }
4289
+ }
4290
+ {
4291
+ this.fs_index = this.BAM_source.get("", 1);
4292
+ this.BAM_g_position += 1;
4293
+ }
4294
+ {
4295
+ this.frame_rate_index = this.BAM_source.get("", 4);
4296
+ this.BAM_g_position += 4;
4297
+ }
4298
+ if (this.frame_rate_index > 13) {
4299
+ throw "frame_rate_index must be in range 0..13";
4300
+ }
4301
+ if (this.fs_index == 0 && this.frame_rate_index != 13) {
4302
+ throw "44.1kHz sampling rate && frame rates other than 13 are illegal. See table 84 in the ETSI spec.";
4303
+ }
4304
+ {
4305
+ b_iframe_global = this.BAM_source.get("", 1);
4306
+ this.BAM_g_position += 1;
4307
+ }
4308
+ {
4309
+ b_single_presentation = this.BAM_source.get("", 1);
4310
+ this.BAM_g_position += 1;
4311
+ }
4312
+ if (b_single_presentation) {
4313
+ {
4314
+ n_presentations = 1;
4315
+ }
4316
+ } else {
4317
+ {
4318
+ {
4319
+ b_more_presentations = this.BAM_source.get("", 1);
4320
+ this.BAM_g_position += 1;
4321
+ }
4322
+ if (b_more_presentations) {
4323
+ {
4324
+ {
4325
+ this.v = this.F_variable_bits(2);
4326
+ if (this.v == null) {
4327
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
4328
+ }
4329
+ }
4330
+ {
4331
+ n_presentations = this.v + 2;
4332
+ }
4333
+ }
4334
+ } else {
4335
+ {
4336
+ n_presentations = 0;
4337
+ }
4338
+ }
4339
+ }
4340
+ }
4341
+ {
4342
+ payload_base = 0;
4343
+ }
4344
+ {
4345
+ b_payload_base = this.BAM_source.get("", 1);
4346
+ this.BAM_g_position += 1;
4347
+ }
4348
+ if (b_payload_base) {
4349
+ {
4350
+ {
4351
+ payload_base_minus1 = this.BAM_source.get("", 5);
4352
+ this.BAM_g_position += 5;
4353
+ this.BAM_sink.write_uint("payload_base_minus1", 5, payload_base_minus1, this.BAM_g_position);
4354
+ }
4355
+ {
4356
+ payload_base = payload_base_minus1 + 1;
4357
+ }
4358
+ if (payload_base == 32) {
4359
+ {
4360
+ {
4361
+ this.v = this.F_variable_bits(3);
4362
+ if (this.v == null) {
4363
+ throw ParseError("F_variable_bits", "expected to return a value, returned None");
4364
+ }
4365
+ }
4366
+ {
4367
+ payload_base += this.v;
4368
+ }
4369
+ }
4370
+ }
4371
+ }
4372
+ }
4373
+ {
4374
+ this.a_substream_indices = [];
4375
+ }
4376
+ {
4377
+ this.last_referenced_substream = -1;
4378
+ }
4379
+ {
4380
+ this.referenced_substreams = [];
4381
+ }
4382
+ {
4383
+ this.bk_substream_index = 100;
4384
+ }
4385
+ if (this.bitstream_version <= 1) {
4386
+ {
4387
+ {
4388
+ this.toc_j = 0;
4389
+ }
4390
+ for (this.toc_i = 0; this.toc_i < n_presentations; this.toc_i++) {
4391
+ {
4392
+ this.F_ac4_presentation_info();
4393
+ }
4394
+ }
4395
+ }
4396
+ } else {
4397
+ {
4398
+ {
4399
+ b_program_id = this.BAM_source.get("", 1);
4400
+ this.BAM_g_position += 1;
4401
+ }
4402
+ if (b_program_id) {
4403
+ {
4404
+ {
4405
+ short_program_id = this.BAM_source.get("", 16);
4406
+ this.BAM_g_position += 16;
4407
+ }
4408
+ {
4409
+ b_program_uuid_present = this.BAM_source.get("", 1);
4410
+ this.BAM_g_position += 1;
4411
+ }
4412
+ if (b_program_uuid_present) {
4413
+ {
4414
+ program_uuid = this.BAM_source.get("", 16 * 8);
4415
+ this.BAM_g_position += 16 * 8;
4416
+ }
4417
+ }
4418
+ }
4419
+ }
4420
+ {
4421
+ total_n_substream_groups = 0;
4422
+ }
4423
+ for (this.toc_i = 0; this.toc_i < n_presentations; this.toc_i++) {
4424
+ {
4425
+ {
4426
+ this.F_ac4_presentation_v2_info(this.toc_i);
4427
+ }
4428
+ for (this.i = 0; this.i < this.presentation_to_groups[this.toc_i].length; this.i++) {
4429
+ {
4430
+ total_n_substream_groups = Math.max(total_n_substream_groups, 1 + this.presentation_to_groups[this.toc_i][this.i]);
4431
+ }
4432
+ }
4433
+ }
4434
+ }
4435
+ for (this.toc_j = 0; this.toc_j < total_n_substream_groups; this.toc_j++) {
4436
+ {
4437
+ this.F_ac4_substream_group_info(this.toc_j);
4438
+ }
4439
+ }
4440
+ }
4441
+ }
4442
+ {
4443
+ this.F_substream_index_table();
4444
+ }
4445
+ {
4446
+ this.BAM_l_align = (8 - (this.BAM_g_position % 8 + 8) % 8 % 8 + 8) % 8;
4447
+ this.BAM_l_align_val = this.BAM_source.get_align(this.BAM_l_align);
4448
+ this.BAM_sink.write_align((8 - (this.BAM_g_position % 8 + 8) % 8 % 8 + 8) % 8, this.BAM_l_align_val);
4449
+ this.BAM_g_position += this.BAM_l_align;
4450
+ }
4451
+ }
4452
+ }
4453
+ F_get_num_channels(cm) {
4454
+ {
4455
+ if (cm == this.CHANNEL_MODE_MONO) {
4456
+ {
4457
+ this.n = 1;
4458
+ }
4459
+ } else if (cm == this.CHANNEL_MODE_STEREO) {
4460
+ {
4461
+ this.n = 2;
4462
+ }
4463
+ } else if (cm == this.CHANNEL_MODE_30) {
4464
+ {
4465
+ this.n = 3;
4466
+ }
4467
+ } else if (cm == this.CHANNEL_MODE_50) {
4468
+ {
4469
+ this.n = 5;
4470
+ }
4471
+ } else if (cm == this.CHANNEL_MODE_51) {
4472
+ {
4473
+ this.n = 6;
4474
+ }
4475
+ } else if (cm == this.CHANNEL_MODE_70_34) {
4476
+ {
4477
+ this.n = 7;
4478
+ }
4479
+ } else if (cm == this.CHANNEL_MODE_71_34) {
4480
+ {
4481
+ this.n = 8;
4482
+ }
4483
+ } else if (cm == this.CHANNEL_MODE_70_52) {
4484
+ {
4485
+ this.n = 7;
4486
+ }
4487
+ } else if (cm == this.CHANNEL_MODE_71_52) {
4488
+ {
4489
+ this.n = 8;
4490
+ }
4491
+ } else if (cm == this.CHANNEL_MODE_70_322) {
4492
+ {
4493
+ this.n = 7;
4494
+ }
4495
+ } else if (cm == this.CHANNEL_MODE_71_322) {
4496
+ {
4497
+ this.n = 8;
4498
+ }
4499
+ } else if (cm == this.CHANNEL_MODE_704) {
4500
+ {
4501
+ this.n = 11;
4502
+ }
4503
+ } else if (cm == this.CHANNEL_MODE_714) {
4504
+ {
4505
+ this.n = 12;
4506
+ }
4507
+ } else if (cm == this.CHANNEL_MODE_904) {
4508
+ {
4509
+ this.n = 13;
4510
+ }
4511
+ } else if (cm == this.CHANNEL_MODE_914) {
4512
+ {
4513
+ this.n = 14;
4514
+ }
4515
+ } else {
4516
+ if (1) {
4517
+ throw "Unknown channel mode!";
4518
+ }
4519
+ }
4520
+ return this.n;
4521
+ }
4522
+ }
4523
+ F_frame_rate_multiply_info() {
4524
+ var multiplier_bit;
4525
+ var b_multiplier;
4526
+ {
4527
+ if (this.BAM_g_table14.slice(0).indexOf(this.frame_rate_index) >= 0) {
4528
+ {
4529
+ {
4530
+ b_multiplier = this.BAM_source.get("", 1);
4531
+ this.BAM_g_position += 1;
4532
+ }
4533
+ if (b_multiplier) {
4534
+ {
4535
+ {
4536
+ multiplier_bit = this.BAM_source.get("", 1);
4537
+ this.BAM_g_position += 1;
4538
+ }
4539
+ {
4540
+ this.frame_rate_factor = this.BAM_g_table15[multiplier_bit];
4541
+ }
4542
+ }
4543
+ } else {
4544
+ {
4545
+ this.frame_rate_factor = 1;
4546
+ }
4547
+ }
4548
+ }
4549
+ } else {
4550
+ if (this.BAM_g_table16.slice(0).indexOf(this.frame_rate_index) >= 0) {
4551
+ {
4552
+ {
4553
+ b_multiplier = this.BAM_source.get("", 1);
4554
+ this.BAM_g_position += 1;
4555
+ }
4556
+ {
4557
+ this.frame_rate_factor = this.BAM_g_table17[b_multiplier];
4558
+ }
4559
+ }
4560
+ } else {
4561
+ {
4562
+ this.frame_rate_factor = 1;
4563
+ }
4564
+ }
4565
+ }
4566
+ }
4567
+ }
4568
+ F_frame_rate_fractions_info() {
4569
+ var b_frame_rate_fraction_is_4;
4570
+ var frame_rate_fraction;
4571
+ var b_frame_rate_fraction;
4572
+ {
4573
+ {
4574
+ frame_rate_fraction = 1;
4575
+ }
4576
+ if (this.BAM_g_table18.slice(0).indexOf(this.frame_rate_index) >= 0) {
4577
+ if (this.frame_rate_factor == 1) {
4578
+ {
4579
+ {
4580
+ b_frame_rate_fraction = this.BAM_source.get("", 1);
4581
+ this.BAM_g_position += 1;
4582
+ }
4583
+ if (b_frame_rate_fraction == 1) {
4584
+ {
4585
+ frame_rate_fraction = 2;
4586
+ }
4587
+ }
4588
+ }
4589
+ }
4590
+ }
4591
+ if (this.BAM_g_table19.slice(0).indexOf(this.frame_rate_index) >= 0) {
4592
+ {
4593
+ {
4594
+ b_frame_rate_fraction = this.BAM_source.get("", 1);
4595
+ this.BAM_g_position += 1;
4596
+ }
4597
+ if (b_frame_rate_fraction == 1) {
4598
+ {
4599
+ {
4600
+ b_frame_rate_fraction_is_4 = this.BAM_source.get("", 1);
4601
+ this.BAM_g_position += 1;
4602
+ }
4603
+ if (b_frame_rate_fraction_is_4 == 1) {
4604
+ {
4605
+ frame_rate_fraction = 4;
4606
+ }
4607
+ } else {
4608
+ {
4609
+ frame_rate_fraction = 2;
4610
+ }
4611
+ }
4612
+ }
4613
+ }
4614
+ }
4615
+ }
4616
+ }
4617
+ }
4618
+ };
4619
+
4620
+ // src/ac4_toc_parser_wrapper/index.js
4621
+ var parseTocElements = (data, elements) => {
4622
+ let parsedElements = [];
4623
+ let index = 0;
4624
+ const bitSourceIterator = {
4625
+ next() {
4626
+ if (index < data.byteLength) {
4627
+ return { value: data.getUint8(index), done: ++index >= data.byteLength };
4628
+ }
4629
+ return { value: void 0, done: true };
4630
+ }
4631
+ };
4632
+ const sinkCallback = (name, value, width, position, handler) => {
4633
+ const pos = position - width;
4634
+ parsedElements.push({ handler, name, pos, value, width });
4635
+ };
4636
+ const bitSource = new BitSource(bitSourceIterator);
4637
+ const sink = new FilterSink(elements, sinkCallback);
4638
+ const parser = new Parser(bitSource, sink);
4639
+ try {
4640
+ parser.F_raw_ac4_frame_toc_only();
4641
+ } catch (err) {
4642
+ parsedElements = null;
4643
+ }
4644
+ return parsedElements;
4645
+ };
4646
+
4647
+ // src/alps_core.js
4648
+ var PRESENTATION_LEVEL_WIDTH = 3;
4649
+ var UNDECODABLE_PRESENTATION_LEVEL = 7;
4650
+ var BITS_TO_SHIFT_TO_DIVIDE_BY_8 = 3;
4651
+ var MINIMUM_PRESENTATIONS_AMOUNT = 2;
4652
+ var DIALOG_GAIN_ADJUSTMENT_FACTOR = 256;
4653
+ var elementsToParse = [
4654
+ PRESENTATION_LEVEL,
4655
+ B_PRESENTATION_ID,
4656
+ PRESENTATION_ID,
4657
+ PAYLOAD_BASE_MINUS1,
4658
+ BYTE_ALIGNMENT,
4659
+ AC4_TOC_END
4660
+ ];
4661
+ var processIsoBmffInitSegment = (parsedSegmentBuffer) => {
4662
+ var _a, _b, _c, _d;
4663
+ const movie = parsedSegmentBuffer.fetch(MOVIE);
4664
+ const meta = parsedSegmentBuffer.fetch(META);
4665
+ const presentations = [];
4666
+ const groupsList = meta && meta.boxes.find((box) => box.type === GROUPS_LIST);
4667
+ const preselectionGroups = groupsList && groupsList.boxes.filter((box) => box.type === PRESELECTION_GROUP);
4668
+ const tracks = movie && movie.boxes.filter((box) => box.type === TRACK);
4669
+ const trackIds = (_a = tracks == null ? void 0 : tracks.map((track) => {
4670
+ const trackHeader = track.boxes.find((box) => box.type === TRACK_HEADER);
4671
+ return trackHeader.track_ID;
4672
+ })) != null ? _a : [];
4673
+ if (Array.isArray(preselectionGroups)) {
4674
+ for (const preselectionGroup of preselectionGroups) {
4675
+ if (preselectionGroup.entities.every((entity) => trackIds.includes(entity.entity_id))) {
4676
+ const parsedPreselectionTag = parseInt(preselectionGroup.preselection_tag, 10);
4677
+ const id = isNaN(parsedPreselectionTag) ? null : parsedPreselectionTag;
4678
+ const selectionPriority = (_b = preselectionGroup.selection_priority) != null ? _b : null;
4679
+ const udtaBox = preselectionGroup.boxes.find((box) => box.type === USER_DATA);
4680
+ const diapBox = udtaBox == null ? void 0 : udtaBox.boxes.find((box) => box.type === DIALOG_PROCESSING);
4681
+ const dialogGain = Number.isInteger(diapBox == null ? void 0 : diapBox.dialog_gain) ? diapBox.dialog_gain / DIALOG_GAIN_ADJUSTMENT_FACTOR : null;
4682
+ const languageBox = preselectionGroup.boxes.find((box) => box.type === EXTENDED_LANGUAGE_TAG);
4683
+ const extendedLanguage = (_c = languageBox == null ? void 0 : languageBox.extended_language) != null ? _c : null;
4684
+ const audioRenderingIndicationBox = preselectionGroup.boxes.find(
4685
+ (box) => box.type === AUDIO_RENDERING_INDICATION
4686
+ );
4687
+ const audioRenderingIndication = (_d = audioRenderingIndicationBox == null ? void 0 : audioRenderingIndicationBox.audio_rendering_indication) != null ? _d : null;
4688
+ const labelBoxes = preselectionGroup.boxes.filter((box) => box.type === LABEL);
4689
+ const labels = labelBoxes.map((labelBox) => ({
4690
+ isGroupLabel: labelBox.is_group_label,
4691
+ label: labelBox.label,
4692
+ labelId: labelBox.label_id,
4693
+ language: labelBox.language
4694
+ }));
4695
+ const kindBoxes = preselectionGroup.boxes.filter((box) => box.type === KIND);
4696
+ const kinds = kindBoxes.map((kindBox) => ({
4697
+ schemeURI: kindBox.schemeURI,
4698
+ value: kindBox.value
4699
+ }));
4700
+ presentations.push({
4701
+ audioRenderingIndication,
4702
+ dialogGain,
4703
+ extendedLanguage,
4704
+ id,
4705
+ kinds,
4706
+ labels,
4707
+ selectionPriority
4708
+ });
4709
+ }
4710
+ }
4711
+ } else {
4712
+ }
4713
+ return presentations;
4714
+ };
4715
+ var processIsoBmffMediaSegment = (parsedSegmentBuffer, activePresentationId) => {
4716
+ const sampleOffsets = getSampleOffsets(parsedSegmentBuffer);
4717
+ for (const sampleOffset of sampleOffsets) {
4718
+ const sampleData = new DataView(parsedSegmentBuffer._raw.buffer, sampleOffset.offset, sampleOffset.size);
4719
+ const parsedElements = parseTocElements(sampleData, elementsToParse);
4720
+ if (parsedElements === null) {
4721
+ return null;
4722
+ }
4723
+ const payloadBaseMinus1 = parsedElements.find((element) => element.name === PAYLOAD_BASE_MINUS1);
4724
+ if (!payloadBaseMinus1) {
4725
+ return null;
4726
+ }
4727
+ let accumulatedShift = 0;
4728
+ const byteAlignment = parsedElements.find((element) => element.name === BYTE_ALIGNMENT);
4729
+ if (byteAlignment) {
4730
+ accumulatedShift = byteAlignment.width;
4731
+ }
4732
+ const ac4TocEnd = parsedElements.find((element) => element.name === AC4_TOC_END);
4733
+ const presentationOffsets = [];
4734
+ const bPresentationIds = [];
4735
+ parsedElements.forEach((element) => {
4736
+ switch (element.name) {
4737
+ case PRESENTATION_LEVEL: {
4738
+ presentationOffsets.push({ pos: element.pos, value: element.value, width: element.width });
4739
+ break;
4740
+ }
4741
+ case PRESENTATION_ID: {
4742
+ const lastPresentationOffset = presentationOffsets[presentationOffsets.length - 1];
4743
+ if (presentationOffsets.length === 0) {
4744
+ }
4745
+ if (element.handler === "before_call") {
4746
+ lastPresentationOffset.presentationIdPos = element.pos;
4747
+ }
4748
+ if (element.handler === "after_call") {
4749
+ lastPresentationOffset.presentationId = element.value;
4750
+ const width = element.pos - lastPresentationOffset.presentationIdPos;
4751
+ lastPresentationOffset.presentationIdWidth = width;
4752
+ accumulatedShift += width;
4753
+ }
4754
+ break;
4755
+ }
4756
+ case B_PRESENTATION_ID: {
4757
+ bPresentationIds.push(element);
4758
+ break;
4759
+ }
4760
+ case PAYLOAD_BASE_MINUS1:
4761
+ case BYTE_ALIGNMENT:
4762
+ case AC4_TOC_END: {
4763
+ break;
4764
+ }
4765
+ default: {
4766
+ }
4767
+ }
4768
+ });
4769
+ if (presentationOffsets.length < MINIMUM_PRESENTATIONS_AMOUNT) {
4770
+ return null;
4771
+ }
4772
+ if (presentationOffsets.some((presentation) => presentation.presentationId === void 0)) {
4773
+ return null;
4774
+ }
4775
+ if (presentationOffsets.every((offset) => offset.presentationId !== activePresentationId)) {
4776
+ return null;
4777
+ }
4778
+ presentationOffsets.forEach((presentation) => {
4779
+ const presentationId = presentation.presentationId;
4780
+ if (presentation.width !== PRESENTATION_LEVEL_WIDTH) {
4781
+ }
4782
+ if (activePresentationId !== presentationId) {
4783
+ setBits(sampleData, presentation.pos, presentation.width, UNDECODABLE_PRESENTATION_LEVEL);
4784
+ }
4785
+ });
4786
+ const availableAdditionalBytes = accumulatedShift >>> BITS_TO_SHIFT_TO_DIVIDE_BY_8;
4787
+ setBits(
4788
+ sampleData,
4789
+ payloadBaseMinus1.pos,
4790
+ payloadBaseMinus1.width,
4791
+ payloadBaseMinus1.value + availableAdditionalBytes
4792
+ );
4793
+ bPresentationIds.forEach((bPresentationId) => {
4794
+ setBits(sampleData, bPresentationId.pos, bPresentationId.width, 0);
4795
+ });
4796
+ presentationOffsets.slice().reverse().forEach((presentation) => {
4797
+ const shiftWidth = ac4TocEnd.pos - presentation.presentationIdPos;
4798
+ shiftLeft(sampleData, presentation.presentationIdPos, shiftWidth, presentation.presentationIdWidth);
4799
+ });
4800
+ }
4801
+ return activePresentationId;
4802
+ };
4803
+
4804
+ // src/alps.js
4805
+ var import_codem_isoboxer = __toESM(require_iso_boxer(), 1);
4806
+ var SEGMENT_TYPES = {
4807
+ INIT: "init",
4808
+ MEDIA: "media"
4809
+ };
4810
+ import_codem_isoboxer.default.addBoxProcessor("diap", function() {
4811
+ this._procFullBox();
4812
+ this._procField("dialog_gain", "int", 16);
4813
+ });
4814
+ var _streams, _presentationsChangedEventHandler, _Alps_instances, initializeStream_fn;
4815
+ var Alps = class {
4816
+ /**
4817
+ * Create the ALPS object
4818
+ */
4819
+ constructor() {
4820
+ __privateAdd(this, _Alps_instances);
4821
+ /** @type {Record<string,Stream>} */
4822
+ __privateAdd(this, _streams, {});
4823
+ /** @type {presentationsChangedCallback|undefined} */
4824
+ __privateAdd(this, _presentationsChangedEventHandler);
4825
+ }
4826
+ /**
4827
+ * Get presentation and activePresentationId for all streams
4828
+ * @returns {Record<string,Stream>} Data for all streams present in current ALPS state
4829
+ */
4830
+ getStreams() {
4831
+ return __privateGet(this, _streams);
4832
+ }
4833
+ /**
4834
+ * Clear data for unused stream
4835
+ * @param {string|null} streamId Stream ID which should be deleted, null for non-multi-period use
4836
+ */
4837
+ clearStream(streamId = null) {
4838
+ delete __privateGet(this, _streams)[streamId];
4839
+ }
4840
+ /**
4841
+ * Set presentationsChangedEventHandler
4842
+ * @param {presentationsChangedCallback} presentationsChangedEventHandler Callback function that will be called if the list of presentations changes
4843
+ */
4844
+ setPresentationsChangedEventHandler(presentationsChangedEventHandler) {
4845
+ __privateSet(this, _presentationsChangedEventHandler, presentationsChangedEventHandler);
4846
+ }
4847
+ /**
4848
+ * Get the list of available presentations
4849
+ * @param {string|null} streamId The ID of the stream, null for non-multi-period use
4850
+ * @returns {import('./types.js').Presentation[]} An array of presentation objects
4851
+ */
4852
+ getPresentations(streamId = null) {
4853
+ __privateMethod(this, _Alps_instances, initializeStream_fn).call(this, streamId);
4854
+ return __privateGet(this, _streams)[streamId].presentations;
4855
+ }
4856
+ /**
4857
+ * Get the ID of the currently active presentation
4858
+ * @param {string|null} streamId The ID of the stream, null for non-multi-period use
4859
+ * @returns {number|undefined} The ID of the active presentation, -1 if no presentation is set, undefined if no stream data exists
4860
+ */
4861
+ getActivePresentationId(streamId = null) {
4862
+ var _b;
4863
+ return (_b = __privateGet(this, _streams)[streamId]) == null ? void 0 : _b.activePresentationId;
4864
+ }
4865
+ /**
4866
+ * Set the ID of the active presentation
4867
+ * @param {number|undefined} presentationId - The ID of the presentation to set as active, -1 to select the default presentation or undefined to clear any active presentation
4868
+ * @param {string|null} streamId The ID of the stream, null for non-multi-period use
4869
+ */
4870
+ setActivePresentationId(presentationId, streamId = null) {
4871
+ __privateMethod(this, _Alps_instances, initializeStream_fn).call(this, streamId);
4872
+ __privateGet(this, _streams)[streamId].activePresentationId = presentationId;
4873
+ }
4874
+ /**
4875
+ * Process an ISOBMFF segment buffer
4876
+ * @param {ArrayBuffer} segmentBuffer - The ISOBMFF segment buffer to process
4877
+ * @param {string|null} streamId - Stream ID for Segment buffer, null for non-multi-period use
4878
+ * @param {number|undefined} activePresentationId - Forced presentation ID that should be selected for processing, use -1 for TV default, and leave undefined to use value set by setActivePresentationId. This parameter takes precedence over this.activePresentationId
4879
+ * @returns {ProcessIsoBmffSegmentResult} Data retrieved from processed segment
4880
+ */
4881
+ processIsoBmffSegment(segmentBuffer, streamId = null, activePresentationId = void 0) {
4882
+ let forcedPresentationId = null;
4883
+ let presentations = null;
4884
+ let segmentType = null;
4885
+ const parsedSegmentBuffer = import_codem_isoboxer.default.parseBuffer(segmentBuffer);
4886
+ const movie = parsedSegmentBuffer.fetch(MOVIE);
4887
+ const meta = parsedSegmentBuffer.fetch(META);
4888
+ const movieFragment = parsedSegmentBuffer.fetch(MOVIE_FRAGMENT);
4889
+ __privateMethod(this, _Alps_instances, initializeStream_fn).call(this, streamId);
4890
+ const stream = __privateGet(this, _streams)[streamId];
4891
+ if (movie && meta) {
4892
+ presentations = processIsoBmffInitSegment(parsedSegmentBuffer);
4893
+ stream.presentations = presentations;
4894
+ if (__privateGet(this, _presentationsChangedEventHandler)) {
4895
+ __privateGet(this, _presentationsChangedEventHandler).call(this, { streamId });
4896
+ }
4897
+ segmentType = SEGMENT_TYPES.INIT;
4898
+ }
4899
+ if (movieFragment) {
4900
+ forcedPresentationId = processIsoBmffMediaSegment(
4901
+ parsedSegmentBuffer,
4902
+ activePresentationId != null ? activePresentationId : stream.activePresentationId
4903
+ );
4904
+ segmentType = SEGMENT_TYPES.MEDIA;
4905
+ }
4906
+ return {
4907
+ forcedPresentationId,
4908
+ presentations,
4909
+ segmentType
4910
+ };
4911
+ }
4912
+ };
4913
+ _streams = new WeakMap();
4914
+ _presentationsChangedEventHandler = new WeakMap();
4915
+ _Alps_instances = new WeakSet();
4916
+ initializeStream_fn = function(streamId) {
4917
+ if (__privateGet(this, _streams)[streamId] === void 0) {
4918
+ __privateGet(this, _streams)[streamId] = { activePresentationId: -1, presentations: [] };
4919
+ }
4920
+ };
4921
+ export {
4922
+ Alps
4923
+ };
4924
+ /*! Bundled license information:
4925
+
4926
+ codem-isoboxer/dist/iso_boxer.js:
4927
+ (*! codem-isoboxer v0.3.10 https://github.com/madebyhiro/codem-isoboxer/blob/master/LICENSE.txt *)
4928
+ */
4929
+ //# sourceMappingURL=alps.bundle.js.map