@kenzuya/mediabunny 1.26.0 → 1.28.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/bundles/{mediabunny.mjs → mediabunny.js} +21963 -21388
- package/dist/bundles/mediabunny.min.js +490 -0
- package/dist/modules/shared/mp3-misc.d.ts.map +1 -1
- package/dist/modules/src/adts/adts-demuxer.d.ts +6 -6
- package/dist/modules/src/adts/adts-demuxer.d.ts.map +1 -1
- package/dist/modules/src/adts/adts-muxer.d.ts +4 -4
- package/dist/modules/src/adts/adts-muxer.d.ts.map +1 -1
- package/dist/modules/src/adts/adts-reader.d.ts +1 -1
- package/dist/modules/src/adts/adts-reader.d.ts.map +1 -1
- package/dist/modules/src/avi/avi-demuxer.d.ts +44 -0
- package/dist/modules/src/avi/avi-demuxer.d.ts.map +1 -0
- package/dist/modules/src/avi/avi-misc.d.ts +88 -0
- package/dist/modules/src/avi/avi-misc.d.ts.map +1 -0
- package/dist/modules/src/avi/avi-muxer.d.ts +45 -0
- package/dist/modules/src/avi/avi-muxer.d.ts.map +1 -0
- package/dist/modules/src/avi/riff-writer.d.ts +26 -0
- package/dist/modules/src/avi/riff-writer.d.ts.map +1 -0
- package/dist/modules/src/codec-data.d.ts +8 -3
- package/dist/modules/src/codec-data.d.ts.map +1 -1
- package/dist/modules/src/codec.d.ts +10 -10
- package/dist/modules/src/codec.d.ts.map +1 -1
- package/dist/modules/src/conversion.d.ts +33 -16
- package/dist/modules/src/conversion.d.ts.map +1 -1
- package/dist/modules/src/custom-coder.d.ts +8 -8
- package/dist/modules/src/custom-coder.d.ts.map +1 -1
- package/dist/modules/src/demuxer.d.ts +3 -3
- package/dist/modules/src/demuxer.d.ts.map +1 -1
- package/dist/modules/src/encode.d.ts +8 -8
- package/dist/modules/src/encode.d.ts.map +1 -1
- package/dist/modules/src/flac/flac-demuxer.d.ts +7 -7
- package/dist/modules/src/flac/flac-demuxer.d.ts.map +1 -1
- package/dist/modules/src/flac/flac-misc.d.ts +3 -3
- package/dist/modules/src/flac/flac-misc.d.ts.map +1 -1
- package/dist/modules/src/flac/flac-muxer.d.ts +5 -5
- package/dist/modules/src/flac/flac-muxer.d.ts.map +1 -1
- package/dist/modules/src/id3.d.ts +3 -3
- package/dist/modules/src/id3.d.ts.map +1 -1
- package/dist/modules/src/index.d.ts +20 -20
- package/dist/modules/src/index.d.ts.map +1 -1
- package/dist/modules/src/input-format.d.ts +22 -0
- package/dist/modules/src/input-format.d.ts.map +1 -1
- package/dist/modules/src/input-track.d.ts +8 -8
- package/dist/modules/src/input-track.d.ts.map +1 -1
- package/dist/modules/src/input.d.ts +12 -12
- package/dist/modules/src/isobmff/isobmff-boxes.d.ts +2 -2
- package/dist/modules/src/isobmff/isobmff-boxes.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-demuxer.d.ts +12 -12
- package/dist/modules/src/isobmff/isobmff-demuxer.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-misc.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-muxer.d.ts +11 -11
- package/dist/modules/src/isobmff/isobmff-muxer.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-reader.d.ts +2 -2
- package/dist/modules/src/isobmff/isobmff-reader.d.ts.map +1 -1
- package/dist/modules/src/matroska/ebml.d.ts +3 -3
- package/dist/modules/src/matroska/ebml.d.ts.map +1 -1
- package/dist/modules/src/matroska/matroska-demuxer.d.ts +13 -13
- package/dist/modules/src/matroska/matroska-demuxer.d.ts.map +1 -1
- package/dist/modules/src/matroska/matroska-input.d.ts +33 -0
- package/dist/modules/src/matroska/matroska-input.d.ts.map +1 -0
- package/dist/modules/src/matroska/matroska-misc.d.ts.map +1 -1
- package/dist/modules/src/matroska/matroska-muxer.d.ts +5 -5
- package/dist/modules/src/matroska/matroska-muxer.d.ts.map +1 -1
- package/dist/modules/src/media-sink.d.ts +5 -5
- package/dist/modules/src/media-sink.d.ts.map +1 -1
- package/dist/modules/src/media-source.d.ts +22 -4
- package/dist/modules/src/media-source.d.ts.map +1 -1
- package/dist/modules/src/metadata.d.ts +2 -2
- package/dist/modules/src/metadata.d.ts.map +1 -1
- package/dist/modules/src/misc.d.ts +5 -4
- package/dist/modules/src/misc.d.ts.map +1 -1
- package/dist/modules/src/mp3/mp3-demuxer.d.ts +7 -7
- package/dist/modules/src/mp3/mp3-demuxer.d.ts.map +1 -1
- package/dist/modules/src/mp3/mp3-muxer.d.ts +4 -4
- package/dist/modules/src/mp3/mp3-muxer.d.ts.map +1 -1
- package/dist/modules/src/mp3/mp3-reader.d.ts +2 -2
- package/dist/modules/src/mp3/mp3-reader.d.ts.map +1 -1
- package/dist/modules/src/mp3/mp3-writer.d.ts +1 -1
- package/dist/modules/src/mp3/mp3-writer.d.ts.map +1 -1
- package/dist/modules/src/muxer.d.ts +4 -4
- package/dist/modules/src/muxer.d.ts.map +1 -1
- package/dist/modules/src/node.d.ts +1 -1
- package/dist/modules/src/ogg/ogg-demuxer.d.ts +7 -7
- package/dist/modules/src/ogg/ogg-demuxer.d.ts.map +1 -1
- package/dist/modules/src/ogg/ogg-misc.d.ts +1 -1
- package/dist/modules/src/ogg/ogg-misc.d.ts.map +1 -1
- package/dist/modules/src/ogg/ogg-muxer.d.ts +5 -5
- package/dist/modules/src/ogg/ogg-muxer.d.ts.map +1 -1
- package/dist/modules/src/ogg/ogg-reader.d.ts +1 -1
- package/dist/modules/src/ogg/ogg-reader.d.ts.map +1 -1
- package/dist/modules/src/output-format.d.ts +51 -6
- package/dist/modules/src/output-format.d.ts.map +1 -1
- package/dist/modules/src/output.d.ts +13 -13
- package/dist/modules/src/output.d.ts.map +1 -1
- package/dist/modules/src/packet.d.ts +1 -1
- package/dist/modules/src/packet.d.ts.map +1 -1
- package/dist/modules/src/pcm.d.ts.map +1 -1
- package/dist/modules/src/reader.d.ts +2 -2
- package/dist/modules/src/reader.d.ts.map +1 -1
- package/dist/modules/src/sample.d.ts +57 -15
- package/dist/modules/src/sample.d.ts.map +1 -1
- package/dist/modules/src/source.d.ts +3 -3
- package/dist/modules/src/source.d.ts.map +1 -1
- package/dist/modules/src/subtitles.d.ts +1 -1
- package/dist/modules/src/subtitles.d.ts.map +1 -1
- package/dist/modules/src/target.d.ts +2 -2
- package/dist/modules/src/target.d.ts.map +1 -1
- package/dist/modules/src/tsconfig.tsbuildinfo +1 -1
- package/dist/modules/src/wave/riff-writer.d.ts +1 -1
- package/dist/modules/src/wave/riff-writer.d.ts.map +1 -1
- package/dist/modules/src/wave/wave-demuxer.d.ts +6 -6
- package/dist/modules/src/wave/wave-demuxer.d.ts.map +1 -1
- package/dist/modules/src/wave/wave-muxer.d.ts +4 -4
- package/dist/modules/src/wave/wave-muxer.d.ts.map +1 -1
- package/dist/modules/src/writer.d.ts +1 -1
- package/dist/modules/src/writer.d.ts.map +1 -1
- package/dist/packages/eac3/eac3.wasm +0 -0
- package/dist/packages/eac3/mediabunny-eac3.js +1058 -0
- package/dist/packages/eac3/mediabunny-eac3.min.js +44 -0
- package/dist/packages/mp3-encoder/mediabunny-mp3-encoder.js +694 -0
- package/dist/packages/mp3-encoder/mediabunny-mp3-encoder.min.js +58 -0
- package/dist/packages/mpeg4/mediabunny-mpeg4.js +1198 -0
- package/dist/packages/mpeg4/mediabunny-mpeg4.min.js +44 -0
- package/dist/packages/mpeg4/xvid.wasm +0 -0
- package/package.json +18 -57
- package/dist/bundles/mediabunny.cjs +0 -26140
- package/dist/bundles/mediabunny.min.cjs +0 -147
- package/dist/bundles/mediabunny.min.mjs +0 -146
- package/dist/mediabunny.d.ts +0 -3319
- package/dist/modules/shared/mp3-misc.js +0 -147
- package/dist/modules/src/adts/adts-demuxer.js +0 -239
- package/dist/modules/src/adts/adts-muxer.js +0 -80
- package/dist/modules/src/adts/adts-reader.js +0 -63
- package/dist/modules/src/codec-data.js +0 -1730
- package/dist/modules/src/codec.js +0 -869
- package/dist/modules/src/conversion.js +0 -1459
- package/dist/modules/src/custom-coder.js +0 -117
- package/dist/modules/src/demuxer.js +0 -12
- package/dist/modules/src/encode.js +0 -442
- package/dist/modules/src/flac/flac-demuxer.js +0 -504
- package/dist/modules/src/flac/flac-misc.js +0 -135
- package/dist/modules/src/flac/flac-muxer.js +0 -222
- package/dist/modules/src/id3.js +0 -848
- package/dist/modules/src/index.js +0 -28
- package/dist/modules/src/input-format.js +0 -480
- package/dist/modules/src/input-track.js +0 -372
- package/dist/modules/src/input.js +0 -188
- package/dist/modules/src/isobmff/isobmff-boxes.js +0 -1480
- package/dist/modules/src/isobmff/isobmff-demuxer.js +0 -2618
- package/dist/modules/src/isobmff/isobmff-misc.js +0 -20
- package/dist/modules/src/isobmff/isobmff-muxer.js +0 -966
- package/dist/modules/src/isobmff/isobmff-reader.js +0 -72
- package/dist/modules/src/matroska/ebml.js +0 -653
- package/dist/modules/src/matroska/matroska-demuxer.js +0 -2133
- package/dist/modules/src/matroska/matroska-misc.js +0 -20
- package/dist/modules/src/matroska/matroska-muxer.js +0 -1017
- package/dist/modules/src/media-sink.js +0 -1736
- package/dist/modules/src/media-source.js +0 -1825
- package/dist/modules/src/metadata.js +0 -193
- package/dist/modules/src/misc.js +0 -623
- package/dist/modules/src/mp3/mp3-demuxer.js +0 -285
- package/dist/modules/src/mp3/mp3-muxer.js +0 -123
- package/dist/modules/src/mp3/mp3-reader.js +0 -26
- package/dist/modules/src/mp3/mp3-writer.js +0 -78
- package/dist/modules/src/muxer.js +0 -50
- package/dist/modules/src/node.js +0 -9
- package/dist/modules/src/ogg/ogg-demuxer.js +0 -763
- package/dist/modules/src/ogg/ogg-misc.js +0 -78
- package/dist/modules/src/ogg/ogg-muxer.js +0 -353
- package/dist/modules/src/ogg/ogg-reader.js +0 -65
- package/dist/modules/src/output-format.js +0 -527
- package/dist/modules/src/output.js +0 -300
- package/dist/modules/src/packet.js +0 -182
- package/dist/modules/src/pcm.js +0 -85
- package/dist/modules/src/reader.js +0 -236
- package/dist/modules/src/sample.js +0 -1056
- package/dist/modules/src/source.js +0 -1182
- package/dist/modules/src/subtitles.js +0 -575
- package/dist/modules/src/target.js +0 -140
- package/dist/modules/src/wave/riff-writer.js +0 -30
- package/dist/modules/src/wave/wave-demuxer.js +0 -447
- package/dist/modules/src/wave/wave-muxer.js +0 -318
- package/dist/modules/src/writer.js +0 -370
- package/src/adts/adts-demuxer.ts +0 -331
- package/src/adts/adts-muxer.ts +0 -111
- package/src/adts/adts-reader.ts +0 -85
- package/src/codec-data.ts +0 -2078
- package/src/codec.ts +0 -1092
- package/src/conversion.ts +0 -2112
- package/src/custom-coder.ts +0 -197
- package/src/demuxer.ts +0 -24
- package/src/encode.ts +0 -739
- package/src/flac/flac-demuxer.ts +0 -730
- package/src/flac/flac-misc.ts +0 -164
- package/src/flac/flac-muxer.ts +0 -320
- package/src/id3.ts +0 -925
- package/src/index.ts +0 -221
- package/src/input-format.ts +0 -541
- package/src/input-track.ts +0 -529
- package/src/input.ts +0 -235
- package/src/isobmff/isobmff-boxes.ts +0 -1719
- package/src/isobmff/isobmff-demuxer.ts +0 -3190
- package/src/isobmff/isobmff-misc.ts +0 -29
- package/src/isobmff/isobmff-muxer.ts +0 -1348
- package/src/isobmff/isobmff-reader.ts +0 -91
- package/src/matroska/ebml.ts +0 -730
- package/src/matroska/matroska-demuxer.ts +0 -2481
- package/src/matroska/matroska-misc.ts +0 -29
- package/src/matroska/matroska-muxer.ts +0 -1276
- package/src/media-sink.ts +0 -2179
- package/src/media-source.ts +0 -2243
- package/src/metadata.ts +0 -320
- package/src/misc.ts +0 -798
- package/src/mp3/mp3-demuxer.ts +0 -383
- package/src/mp3/mp3-muxer.ts +0 -166
- package/src/mp3/mp3-reader.ts +0 -34
- package/src/mp3/mp3-writer.ts +0 -120
- package/src/muxer.ts +0 -88
- package/src/node.ts +0 -11
- package/src/ogg/ogg-demuxer.ts +0 -1053
- package/src/ogg/ogg-misc.ts +0 -116
- package/src/ogg/ogg-muxer.ts +0 -497
- package/src/ogg/ogg-reader.ts +0 -93
- package/src/output-format.ts +0 -945
- package/src/output.ts +0 -488
- package/src/packet.ts +0 -263
- package/src/pcm.ts +0 -112
- package/src/reader.ts +0 -323
- package/src/sample.ts +0 -1461
- package/src/source.ts +0 -1688
- package/src/subtitles.ts +0 -711
- package/src/target.ts +0 -204
- package/src/tsconfig.json +0 -16
- package/src/wave/riff-writer.ts +0 -36
- package/src/wave/wave-demuxer.ts +0 -529
- package/src/wave/wave-muxer.ts +0 -371
- package/src/writer.ts +0 -490
|
@@ -1,653 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2025-present, Vanilagy and contributors
|
|
3
|
-
*
|
|
4
|
-
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
-
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
-
*/
|
|
8
|
-
import { assertNever, textDecoder, textEncoder } from '../misc.js';
|
|
9
|
-
import { readBytes, readF32Be, readF64Be, readU8 } from '../reader.js';
|
|
10
|
-
/** Wrapper around a number to be able to differentiate it in the writer. */
|
|
11
|
-
export class EBMLFloat32 {
|
|
12
|
-
constructor(value) {
|
|
13
|
-
this.value = value;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
/** Wrapper around a number to be able to differentiate it in the writer. */
|
|
17
|
-
export class EBMLFloat64 {
|
|
18
|
-
constructor(value) {
|
|
19
|
-
this.value = value;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/** Wrapper around a number to be able to differentiate it in the writer. */
|
|
23
|
-
export class EBMLSignedInt {
|
|
24
|
-
constructor(value) {
|
|
25
|
-
this.value = value;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export class EBMLUnicodeString {
|
|
29
|
-
constructor(value) {
|
|
30
|
-
this.value = value;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/** Defines some of the EBML IDs used by Matroska files. */
|
|
34
|
-
export var EBMLId;
|
|
35
|
-
(function (EBMLId) {
|
|
36
|
-
EBMLId[EBMLId["EBML"] = 440786851] = "EBML";
|
|
37
|
-
EBMLId[EBMLId["EBMLVersion"] = 17030] = "EBMLVersion";
|
|
38
|
-
EBMLId[EBMLId["EBMLReadVersion"] = 17143] = "EBMLReadVersion";
|
|
39
|
-
EBMLId[EBMLId["EBMLMaxIDLength"] = 17138] = "EBMLMaxIDLength";
|
|
40
|
-
EBMLId[EBMLId["EBMLMaxSizeLength"] = 17139] = "EBMLMaxSizeLength";
|
|
41
|
-
EBMLId[EBMLId["DocType"] = 17026] = "DocType";
|
|
42
|
-
EBMLId[EBMLId["DocTypeVersion"] = 17031] = "DocTypeVersion";
|
|
43
|
-
EBMLId[EBMLId["DocTypeReadVersion"] = 17029] = "DocTypeReadVersion";
|
|
44
|
-
EBMLId[EBMLId["Void"] = 236] = "Void";
|
|
45
|
-
EBMLId[EBMLId["Segment"] = 408125543] = "Segment";
|
|
46
|
-
EBMLId[EBMLId["SeekHead"] = 290298740] = "SeekHead";
|
|
47
|
-
EBMLId[EBMLId["Seek"] = 19899] = "Seek";
|
|
48
|
-
EBMLId[EBMLId["SeekID"] = 21419] = "SeekID";
|
|
49
|
-
EBMLId[EBMLId["SeekPosition"] = 21420] = "SeekPosition";
|
|
50
|
-
EBMLId[EBMLId["Duration"] = 17545] = "Duration";
|
|
51
|
-
EBMLId[EBMLId["Info"] = 357149030] = "Info";
|
|
52
|
-
EBMLId[EBMLId["TimestampScale"] = 2807729] = "TimestampScale";
|
|
53
|
-
EBMLId[EBMLId["MuxingApp"] = 19840] = "MuxingApp";
|
|
54
|
-
EBMLId[EBMLId["WritingApp"] = 22337] = "WritingApp";
|
|
55
|
-
EBMLId[EBMLId["Tracks"] = 374648427] = "Tracks";
|
|
56
|
-
EBMLId[EBMLId["TrackEntry"] = 174] = "TrackEntry";
|
|
57
|
-
EBMLId[EBMLId["TrackNumber"] = 215] = "TrackNumber";
|
|
58
|
-
EBMLId[EBMLId["TrackUID"] = 29637] = "TrackUID";
|
|
59
|
-
EBMLId[EBMLId["TrackType"] = 131] = "TrackType";
|
|
60
|
-
EBMLId[EBMLId["FlagEnabled"] = 185] = "FlagEnabled";
|
|
61
|
-
EBMLId[EBMLId["FlagDefault"] = 136] = "FlagDefault";
|
|
62
|
-
EBMLId[EBMLId["FlagForced"] = 21930] = "FlagForced";
|
|
63
|
-
EBMLId[EBMLId["FlagOriginal"] = 21934] = "FlagOriginal";
|
|
64
|
-
EBMLId[EBMLId["FlagHearingImpaired"] = 21931] = "FlagHearingImpaired";
|
|
65
|
-
EBMLId[EBMLId["FlagVisualImpaired"] = 21932] = "FlagVisualImpaired";
|
|
66
|
-
EBMLId[EBMLId["FlagCommentary"] = 21935] = "FlagCommentary";
|
|
67
|
-
EBMLId[EBMLId["FlagLacing"] = 156] = "FlagLacing";
|
|
68
|
-
EBMLId[EBMLId["Name"] = 21358] = "Name";
|
|
69
|
-
EBMLId[EBMLId["Language"] = 2274716] = "Language";
|
|
70
|
-
EBMLId[EBMLId["LanguageBCP47"] = 2274717] = "LanguageBCP47";
|
|
71
|
-
EBMLId[EBMLId["CodecID"] = 134] = "CodecID";
|
|
72
|
-
EBMLId[EBMLId["CodecPrivate"] = 25506] = "CodecPrivate";
|
|
73
|
-
EBMLId[EBMLId["CodecDelay"] = 22186] = "CodecDelay";
|
|
74
|
-
EBMLId[EBMLId["SeekPreRoll"] = 22203] = "SeekPreRoll";
|
|
75
|
-
EBMLId[EBMLId["DefaultDuration"] = 2352003] = "DefaultDuration";
|
|
76
|
-
EBMLId[EBMLId["Video"] = 224] = "Video";
|
|
77
|
-
EBMLId[EBMLId["PixelWidth"] = 176] = "PixelWidth";
|
|
78
|
-
EBMLId[EBMLId["PixelHeight"] = 186] = "PixelHeight";
|
|
79
|
-
EBMLId[EBMLId["AlphaMode"] = 21440] = "AlphaMode";
|
|
80
|
-
EBMLId[EBMLId["Audio"] = 225] = "Audio";
|
|
81
|
-
EBMLId[EBMLId["SamplingFrequency"] = 181] = "SamplingFrequency";
|
|
82
|
-
EBMLId[EBMLId["Channels"] = 159] = "Channels";
|
|
83
|
-
EBMLId[EBMLId["BitDepth"] = 25188] = "BitDepth";
|
|
84
|
-
EBMLId[EBMLId["SimpleBlock"] = 163] = "SimpleBlock";
|
|
85
|
-
EBMLId[EBMLId["BlockGroup"] = 160] = "BlockGroup";
|
|
86
|
-
EBMLId[EBMLId["Block"] = 161] = "Block";
|
|
87
|
-
EBMLId[EBMLId["BlockAdditions"] = 30113] = "BlockAdditions";
|
|
88
|
-
EBMLId[EBMLId["BlockMore"] = 166] = "BlockMore";
|
|
89
|
-
EBMLId[EBMLId["BlockAdditional"] = 165] = "BlockAdditional";
|
|
90
|
-
EBMLId[EBMLId["BlockAddID"] = 238] = "BlockAddID";
|
|
91
|
-
EBMLId[EBMLId["BlockDuration"] = 155] = "BlockDuration";
|
|
92
|
-
EBMLId[EBMLId["ReferenceBlock"] = 251] = "ReferenceBlock";
|
|
93
|
-
EBMLId[EBMLId["Cluster"] = 524531317] = "Cluster";
|
|
94
|
-
EBMLId[EBMLId["Timestamp"] = 231] = "Timestamp";
|
|
95
|
-
EBMLId[EBMLId["Cues"] = 475249515] = "Cues";
|
|
96
|
-
EBMLId[EBMLId["CuePoint"] = 187] = "CuePoint";
|
|
97
|
-
EBMLId[EBMLId["CueTime"] = 179] = "CueTime";
|
|
98
|
-
EBMLId[EBMLId["CueTrackPositions"] = 183] = "CueTrackPositions";
|
|
99
|
-
EBMLId[EBMLId["CueTrack"] = 247] = "CueTrack";
|
|
100
|
-
EBMLId[EBMLId["CueClusterPosition"] = 241] = "CueClusterPosition";
|
|
101
|
-
EBMLId[EBMLId["Colour"] = 21936] = "Colour";
|
|
102
|
-
EBMLId[EBMLId["MatrixCoefficients"] = 21937] = "MatrixCoefficients";
|
|
103
|
-
EBMLId[EBMLId["TransferCharacteristics"] = 21946] = "TransferCharacteristics";
|
|
104
|
-
EBMLId[EBMLId["Primaries"] = 21947] = "Primaries";
|
|
105
|
-
EBMLId[EBMLId["Range"] = 21945] = "Range";
|
|
106
|
-
EBMLId[EBMLId["Projection"] = 30320] = "Projection";
|
|
107
|
-
EBMLId[EBMLId["ProjectionType"] = 30321] = "ProjectionType";
|
|
108
|
-
EBMLId[EBMLId["ProjectionPoseRoll"] = 30325] = "ProjectionPoseRoll";
|
|
109
|
-
EBMLId[EBMLId["Attachments"] = 423732329] = "Attachments";
|
|
110
|
-
EBMLId[EBMLId["AttachedFile"] = 24999] = "AttachedFile";
|
|
111
|
-
EBMLId[EBMLId["FileDescription"] = 18046] = "FileDescription";
|
|
112
|
-
EBMLId[EBMLId["FileName"] = 18030] = "FileName";
|
|
113
|
-
EBMLId[EBMLId["FileMediaType"] = 18016] = "FileMediaType";
|
|
114
|
-
EBMLId[EBMLId["FileData"] = 18012] = "FileData";
|
|
115
|
-
EBMLId[EBMLId["FileUID"] = 18094] = "FileUID";
|
|
116
|
-
EBMLId[EBMLId["Chapters"] = 272869232] = "Chapters";
|
|
117
|
-
EBMLId[EBMLId["Tags"] = 307544935] = "Tags";
|
|
118
|
-
EBMLId[EBMLId["Tag"] = 29555] = "Tag";
|
|
119
|
-
EBMLId[EBMLId["Targets"] = 25536] = "Targets";
|
|
120
|
-
EBMLId[EBMLId["TargetTypeValue"] = 26826] = "TargetTypeValue";
|
|
121
|
-
EBMLId[EBMLId["TargetType"] = 25546] = "TargetType";
|
|
122
|
-
EBMLId[EBMLId["TagTrackUID"] = 25541] = "TagTrackUID";
|
|
123
|
-
EBMLId[EBMLId["TagEditionUID"] = 25545] = "TagEditionUID";
|
|
124
|
-
EBMLId[EBMLId["TagChapterUID"] = 25540] = "TagChapterUID";
|
|
125
|
-
EBMLId[EBMLId["TagAttachmentUID"] = 25542] = "TagAttachmentUID";
|
|
126
|
-
EBMLId[EBMLId["SimpleTag"] = 26568] = "SimpleTag";
|
|
127
|
-
EBMLId[EBMLId["TagName"] = 17827] = "TagName";
|
|
128
|
-
EBMLId[EBMLId["TagLanguage"] = 17530] = "TagLanguage";
|
|
129
|
-
EBMLId[EBMLId["TagString"] = 17543] = "TagString";
|
|
130
|
-
EBMLId[EBMLId["TagBinary"] = 17541] = "TagBinary";
|
|
131
|
-
EBMLId[EBMLId["ContentEncodings"] = 28032] = "ContentEncodings";
|
|
132
|
-
EBMLId[EBMLId["ContentEncoding"] = 25152] = "ContentEncoding";
|
|
133
|
-
EBMLId[EBMLId["ContentEncodingOrder"] = 20529] = "ContentEncodingOrder";
|
|
134
|
-
EBMLId[EBMLId["ContentEncodingScope"] = 20530] = "ContentEncodingScope";
|
|
135
|
-
EBMLId[EBMLId["ContentCompression"] = 20532] = "ContentCompression";
|
|
136
|
-
EBMLId[EBMLId["ContentCompAlgo"] = 16980] = "ContentCompAlgo";
|
|
137
|
-
EBMLId[EBMLId["ContentCompSettings"] = 16981] = "ContentCompSettings";
|
|
138
|
-
EBMLId[EBMLId["ContentEncryption"] = 20533] = "ContentEncryption";
|
|
139
|
-
})(EBMLId || (EBMLId = {}));
|
|
140
|
-
export const LEVEL_0_EBML_IDS = [
|
|
141
|
-
EBMLId.EBML,
|
|
142
|
-
EBMLId.Segment,
|
|
143
|
-
];
|
|
144
|
-
// All the stuff that can appear in a segment, basically
|
|
145
|
-
export const LEVEL_1_EBML_IDS = [
|
|
146
|
-
EBMLId.SeekHead,
|
|
147
|
-
EBMLId.Info,
|
|
148
|
-
EBMLId.Cluster,
|
|
149
|
-
EBMLId.Tracks,
|
|
150
|
-
EBMLId.Cues,
|
|
151
|
-
EBMLId.Attachments,
|
|
152
|
-
EBMLId.Chapters,
|
|
153
|
-
EBMLId.Tags,
|
|
154
|
-
];
|
|
155
|
-
export const LEVEL_0_AND_1_EBML_IDS = [
|
|
156
|
-
...LEVEL_0_EBML_IDS,
|
|
157
|
-
...LEVEL_1_EBML_IDS,
|
|
158
|
-
];
|
|
159
|
-
export const measureUnsignedInt = (value) => {
|
|
160
|
-
if (value < (1 << 8)) {
|
|
161
|
-
return 1;
|
|
162
|
-
}
|
|
163
|
-
else if (value < (1 << 16)) {
|
|
164
|
-
return 2;
|
|
165
|
-
}
|
|
166
|
-
else if (value < (1 << 24)) {
|
|
167
|
-
return 3;
|
|
168
|
-
}
|
|
169
|
-
else if (value < 2 ** 32) {
|
|
170
|
-
return 4;
|
|
171
|
-
}
|
|
172
|
-
else if (value < 2 ** 40) {
|
|
173
|
-
return 5;
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
return 6;
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
export const measureUnsignedBigInt = (value) => {
|
|
180
|
-
if (value < (1n << 8n)) {
|
|
181
|
-
return 1;
|
|
182
|
-
}
|
|
183
|
-
else if (value < (1n << 16n)) {
|
|
184
|
-
return 2;
|
|
185
|
-
}
|
|
186
|
-
else if (value < (1n << 24n)) {
|
|
187
|
-
return 3;
|
|
188
|
-
}
|
|
189
|
-
else if (value < (1n << 32n)) {
|
|
190
|
-
return 4;
|
|
191
|
-
}
|
|
192
|
-
else if (value < (1n << 40n)) {
|
|
193
|
-
return 5;
|
|
194
|
-
}
|
|
195
|
-
else if (value < (1n << 48n)) {
|
|
196
|
-
return 6;
|
|
197
|
-
}
|
|
198
|
-
else if (value < (1n << 56n)) {
|
|
199
|
-
return 7;
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
return 8;
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
export const measureSignedInt = (value) => {
|
|
206
|
-
if (value >= -(1 << 6) && value < (1 << 6)) {
|
|
207
|
-
return 1;
|
|
208
|
-
}
|
|
209
|
-
else if (value >= -(1 << 13) && value < (1 << 13)) {
|
|
210
|
-
return 2;
|
|
211
|
-
}
|
|
212
|
-
else if (value >= -(1 << 20) && value < (1 << 20)) {
|
|
213
|
-
return 3;
|
|
214
|
-
}
|
|
215
|
-
else if (value >= -(1 << 27) && value < (1 << 27)) {
|
|
216
|
-
return 4;
|
|
217
|
-
}
|
|
218
|
-
else if (value >= -(2 ** 34) && value < 2 ** 34) {
|
|
219
|
-
return 5;
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
return 6;
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
export const measureVarInt = (value) => {
|
|
226
|
-
if (value < (1 << 7) - 1) {
|
|
227
|
-
/** Top bit is set, leaving 7 bits to hold the integer, but we can't store
|
|
228
|
-
* 127 because "all bits set to one" is a reserved value. Same thing for the
|
|
229
|
-
* other cases below:
|
|
230
|
-
*/
|
|
231
|
-
return 1;
|
|
232
|
-
}
|
|
233
|
-
else if (value < (1 << 14) - 1) {
|
|
234
|
-
return 2;
|
|
235
|
-
}
|
|
236
|
-
else if (value < (1 << 21) - 1) {
|
|
237
|
-
return 3;
|
|
238
|
-
}
|
|
239
|
-
else if (value < (1 << 28) - 1) {
|
|
240
|
-
return 4;
|
|
241
|
-
}
|
|
242
|
-
else if (value < 2 ** 35 - 1) {
|
|
243
|
-
return 5;
|
|
244
|
-
}
|
|
245
|
-
else if (value < 2 ** 42 - 1) {
|
|
246
|
-
return 6;
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
throw new Error('EBML varint size not supported ' + value);
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
export class EBMLWriter {
|
|
253
|
-
constructor(writer) {
|
|
254
|
-
this.writer = writer;
|
|
255
|
-
this.helper = new Uint8Array(8);
|
|
256
|
-
this.helperView = new DataView(this.helper.buffer);
|
|
257
|
-
/**
|
|
258
|
-
* Stores the position from the start of the file to where EBML elements have been written. This is used to
|
|
259
|
-
* rewrite/edit elements that were already added before, and to measure sizes of things.
|
|
260
|
-
*/
|
|
261
|
-
this.offsets = new WeakMap();
|
|
262
|
-
/** Same as offsets, but stores position where the element's data starts (after ID and size fields). */
|
|
263
|
-
this.dataOffsets = new WeakMap();
|
|
264
|
-
}
|
|
265
|
-
writeByte(value) {
|
|
266
|
-
this.helperView.setUint8(0, value);
|
|
267
|
-
this.writer.write(this.helper.subarray(0, 1));
|
|
268
|
-
}
|
|
269
|
-
writeFloat32(value) {
|
|
270
|
-
this.helperView.setFloat32(0, value, false);
|
|
271
|
-
this.writer.write(this.helper.subarray(0, 4));
|
|
272
|
-
}
|
|
273
|
-
writeFloat64(value) {
|
|
274
|
-
this.helperView.setFloat64(0, value, false);
|
|
275
|
-
this.writer.write(this.helper);
|
|
276
|
-
}
|
|
277
|
-
writeUnsignedInt(value, width = measureUnsignedInt(value)) {
|
|
278
|
-
let pos = 0;
|
|
279
|
-
// Each case falls through:
|
|
280
|
-
switch (width) {
|
|
281
|
-
case 6:
|
|
282
|
-
// Need to use division to access >32 bits of floating point var
|
|
283
|
-
this.helperView.setUint8(pos++, (value / 2 ** 40) | 0);
|
|
284
|
-
// eslint-disable-next-line no-fallthrough
|
|
285
|
-
case 5:
|
|
286
|
-
this.helperView.setUint8(pos++, (value / 2 ** 32) | 0);
|
|
287
|
-
// eslint-disable-next-line no-fallthrough
|
|
288
|
-
case 4:
|
|
289
|
-
this.helperView.setUint8(pos++, value >> 24);
|
|
290
|
-
// eslint-disable-next-line no-fallthrough
|
|
291
|
-
case 3:
|
|
292
|
-
this.helperView.setUint8(pos++, value >> 16);
|
|
293
|
-
// eslint-disable-next-line no-fallthrough
|
|
294
|
-
case 2:
|
|
295
|
-
this.helperView.setUint8(pos++, value >> 8);
|
|
296
|
-
// eslint-disable-next-line no-fallthrough
|
|
297
|
-
case 1:
|
|
298
|
-
this.helperView.setUint8(pos++, value);
|
|
299
|
-
break;
|
|
300
|
-
default:
|
|
301
|
-
throw new Error('Bad unsigned int size ' + width);
|
|
302
|
-
}
|
|
303
|
-
this.writer.write(this.helper.subarray(0, pos));
|
|
304
|
-
}
|
|
305
|
-
writeUnsignedBigInt(value, width = measureUnsignedBigInt(value)) {
|
|
306
|
-
let pos = 0;
|
|
307
|
-
for (let i = width - 1; i >= 0; i--) {
|
|
308
|
-
this.helperView.setUint8(pos++, Number((value >> BigInt(i * 8)) & 0xffn));
|
|
309
|
-
}
|
|
310
|
-
this.writer.write(this.helper.subarray(0, pos));
|
|
311
|
-
}
|
|
312
|
-
writeSignedInt(value, width = measureSignedInt(value)) {
|
|
313
|
-
if (value < 0) {
|
|
314
|
-
// Two's complement stuff
|
|
315
|
-
value += 2 ** (width * 8);
|
|
316
|
-
}
|
|
317
|
-
this.writeUnsignedInt(value, width);
|
|
318
|
-
}
|
|
319
|
-
writeVarInt(value, width = measureVarInt(value)) {
|
|
320
|
-
let pos = 0;
|
|
321
|
-
switch (width) {
|
|
322
|
-
case 1:
|
|
323
|
-
this.helperView.setUint8(pos++, (1 << 7) | value);
|
|
324
|
-
break;
|
|
325
|
-
case 2:
|
|
326
|
-
this.helperView.setUint8(pos++, (1 << 6) | (value >> 8));
|
|
327
|
-
this.helperView.setUint8(pos++, value);
|
|
328
|
-
break;
|
|
329
|
-
case 3:
|
|
330
|
-
this.helperView.setUint8(pos++, (1 << 5) | (value >> 16));
|
|
331
|
-
this.helperView.setUint8(pos++, value >> 8);
|
|
332
|
-
this.helperView.setUint8(pos++, value);
|
|
333
|
-
break;
|
|
334
|
-
case 4:
|
|
335
|
-
this.helperView.setUint8(pos++, (1 << 4) | (value >> 24));
|
|
336
|
-
this.helperView.setUint8(pos++, value >> 16);
|
|
337
|
-
this.helperView.setUint8(pos++, value >> 8);
|
|
338
|
-
this.helperView.setUint8(pos++, value);
|
|
339
|
-
break;
|
|
340
|
-
case 5:
|
|
341
|
-
/**
|
|
342
|
-
* JavaScript converts its doubles to 32-bit integers for bitwise
|
|
343
|
-
* operations, so we need to do a division by 2^32 instead of a
|
|
344
|
-
* right-shift of 32 to retain those top 3 bits
|
|
345
|
-
*/
|
|
346
|
-
this.helperView.setUint8(pos++, (1 << 3) | ((value / 2 ** 32) & 0x7));
|
|
347
|
-
this.helperView.setUint8(pos++, value >> 24);
|
|
348
|
-
this.helperView.setUint8(pos++, value >> 16);
|
|
349
|
-
this.helperView.setUint8(pos++, value >> 8);
|
|
350
|
-
this.helperView.setUint8(pos++, value);
|
|
351
|
-
break;
|
|
352
|
-
case 6:
|
|
353
|
-
this.helperView.setUint8(pos++, (1 << 2) | ((value / 2 ** 40) & 0x3));
|
|
354
|
-
this.helperView.setUint8(pos++, (value / 2 ** 32) | 0);
|
|
355
|
-
this.helperView.setUint8(pos++, value >> 24);
|
|
356
|
-
this.helperView.setUint8(pos++, value >> 16);
|
|
357
|
-
this.helperView.setUint8(pos++, value >> 8);
|
|
358
|
-
this.helperView.setUint8(pos++, value);
|
|
359
|
-
break;
|
|
360
|
-
default:
|
|
361
|
-
throw new Error('Bad EBML varint size ' + width);
|
|
362
|
-
}
|
|
363
|
-
this.writer.write(this.helper.subarray(0, pos));
|
|
364
|
-
}
|
|
365
|
-
writeAsciiString(str) {
|
|
366
|
-
this.writer.write(new Uint8Array(str.split('').map(x => x.charCodeAt(0))));
|
|
367
|
-
}
|
|
368
|
-
writeEBML(data) {
|
|
369
|
-
if (data === null)
|
|
370
|
-
return;
|
|
371
|
-
if (data instanceof Uint8Array) {
|
|
372
|
-
this.writer.write(data);
|
|
373
|
-
}
|
|
374
|
-
else if (Array.isArray(data)) {
|
|
375
|
-
for (const elem of data) {
|
|
376
|
-
this.writeEBML(elem);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
this.offsets.set(data, this.writer.getPos());
|
|
381
|
-
this.writeUnsignedInt(data.id); // ID field
|
|
382
|
-
if (Array.isArray(data.data)) {
|
|
383
|
-
const sizePos = this.writer.getPos();
|
|
384
|
-
const sizeSize = data.size === -1 ? 1 : (data.size ?? 4);
|
|
385
|
-
if (data.size === -1) {
|
|
386
|
-
// Write the reserved all-one-bits marker for unknown/unbounded size.
|
|
387
|
-
this.writeByte(0xff);
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
this.writer.seek(this.writer.getPos() + sizeSize);
|
|
391
|
-
}
|
|
392
|
-
const startPos = this.writer.getPos();
|
|
393
|
-
this.dataOffsets.set(data, startPos);
|
|
394
|
-
this.writeEBML(data.data);
|
|
395
|
-
if (data.size !== -1) {
|
|
396
|
-
const size = this.writer.getPos() - startPos;
|
|
397
|
-
const endPos = this.writer.getPos();
|
|
398
|
-
this.writer.seek(sizePos);
|
|
399
|
-
this.writeVarInt(size, sizeSize);
|
|
400
|
-
this.writer.seek(endPos);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
else if (typeof data.data === 'number') {
|
|
404
|
-
const size = data.size ?? measureUnsignedInt(data.data);
|
|
405
|
-
this.writeVarInt(size);
|
|
406
|
-
this.writeUnsignedInt(data.data, size);
|
|
407
|
-
}
|
|
408
|
-
else if (typeof data.data === 'bigint') {
|
|
409
|
-
const size = data.size ?? measureUnsignedBigInt(data.data);
|
|
410
|
-
this.writeVarInt(size);
|
|
411
|
-
this.writeUnsignedBigInt(data.data, size);
|
|
412
|
-
}
|
|
413
|
-
else if (typeof data.data === 'string') {
|
|
414
|
-
this.writeVarInt(data.data.length);
|
|
415
|
-
this.writeAsciiString(data.data);
|
|
416
|
-
}
|
|
417
|
-
else if (data.data instanceof Uint8Array) {
|
|
418
|
-
this.writeVarInt(data.data.byteLength, data.size);
|
|
419
|
-
this.writer.write(data.data);
|
|
420
|
-
}
|
|
421
|
-
else if (data.data instanceof EBMLFloat32) {
|
|
422
|
-
this.writeVarInt(4);
|
|
423
|
-
this.writeFloat32(data.data.value);
|
|
424
|
-
}
|
|
425
|
-
else if (data.data instanceof EBMLFloat64) {
|
|
426
|
-
this.writeVarInt(8);
|
|
427
|
-
this.writeFloat64(data.data.value);
|
|
428
|
-
}
|
|
429
|
-
else if (data.data instanceof EBMLSignedInt) {
|
|
430
|
-
const size = data.size ?? measureSignedInt(data.data.value);
|
|
431
|
-
this.writeVarInt(size);
|
|
432
|
-
this.writeSignedInt(data.data.value, size);
|
|
433
|
-
}
|
|
434
|
-
else if (data.data instanceof EBMLUnicodeString) {
|
|
435
|
-
const bytes = textEncoder.encode(data.data.value);
|
|
436
|
-
this.writeVarInt(bytes.length);
|
|
437
|
-
this.writer.write(bytes);
|
|
438
|
-
}
|
|
439
|
-
else {
|
|
440
|
-
assertNever(data.data);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
export const MAX_VAR_INT_SIZE = 8;
|
|
446
|
-
export const MIN_HEADER_SIZE = 2; // 1-byte ID and 1-byte size
|
|
447
|
-
export const MAX_HEADER_SIZE = /* #__PURE__ */ 2 * MAX_VAR_INT_SIZE; // 8-byte ID and 8-byte size
|
|
448
|
-
export const readVarIntSize = (slice) => {
|
|
449
|
-
const firstByte = readU8(slice);
|
|
450
|
-
slice.skip(-1);
|
|
451
|
-
if (firstByte === 0) {
|
|
452
|
-
return null; // Invalid VINT
|
|
453
|
-
}
|
|
454
|
-
let width = 1;
|
|
455
|
-
let mask = 0x80;
|
|
456
|
-
while ((firstByte & mask) === 0) {
|
|
457
|
-
width++;
|
|
458
|
-
mask >>= 1;
|
|
459
|
-
}
|
|
460
|
-
return width;
|
|
461
|
-
};
|
|
462
|
-
export const readVarInt = (slice) => {
|
|
463
|
-
// Read the first byte to determine the width of the variable-length integer
|
|
464
|
-
const firstByte = readU8(slice);
|
|
465
|
-
if (firstByte === 0) {
|
|
466
|
-
return null; // Invalid VINT
|
|
467
|
-
}
|
|
468
|
-
// Find the position of VINT_MARKER, which determines the width
|
|
469
|
-
let width = 1;
|
|
470
|
-
let mask = 1 << 7;
|
|
471
|
-
while ((firstByte & mask) === 0) {
|
|
472
|
-
width++;
|
|
473
|
-
mask >>= 1;
|
|
474
|
-
}
|
|
475
|
-
// First byte's value needs the marker bit cleared
|
|
476
|
-
let value = firstByte & (mask - 1);
|
|
477
|
-
// Read remaining bytes
|
|
478
|
-
for (let i = 1; i < width; i++) {
|
|
479
|
-
value *= 1 << 8;
|
|
480
|
-
value += readU8(slice);
|
|
481
|
-
}
|
|
482
|
-
return value;
|
|
483
|
-
};
|
|
484
|
-
export const readUnsignedInt = (slice, width) => {
|
|
485
|
-
if (width < 1 || width > 8) {
|
|
486
|
-
throw new Error('Bad unsigned int size ' + width);
|
|
487
|
-
}
|
|
488
|
-
let value = 0;
|
|
489
|
-
// Read bytes from most significant to least significant
|
|
490
|
-
for (let i = 0; i < width; i++) {
|
|
491
|
-
value *= 1 << 8;
|
|
492
|
-
value += readU8(slice);
|
|
493
|
-
}
|
|
494
|
-
return value;
|
|
495
|
-
};
|
|
496
|
-
export const readUnsignedBigInt = (slice, width) => {
|
|
497
|
-
if (width < 1) {
|
|
498
|
-
throw new Error('Bad unsigned int size ' + width);
|
|
499
|
-
}
|
|
500
|
-
let value = 0n;
|
|
501
|
-
for (let i = 0; i < width; i++) {
|
|
502
|
-
value <<= 8n;
|
|
503
|
-
value += BigInt(readU8(slice));
|
|
504
|
-
}
|
|
505
|
-
return value;
|
|
506
|
-
};
|
|
507
|
-
export const readSignedInt = (slice, width) => {
|
|
508
|
-
let value = readUnsignedInt(slice, width);
|
|
509
|
-
// If the highest bit is set, convert from two's complement
|
|
510
|
-
if (value & (1 << (width * 8 - 1))) {
|
|
511
|
-
value -= 2 ** (width * 8);
|
|
512
|
-
}
|
|
513
|
-
return value;
|
|
514
|
-
};
|
|
515
|
-
export const readElementId = (slice) => {
|
|
516
|
-
const size = readVarIntSize(slice);
|
|
517
|
-
if (size === null) {
|
|
518
|
-
return null;
|
|
519
|
-
}
|
|
520
|
-
const id = readUnsignedInt(slice, size);
|
|
521
|
-
return id;
|
|
522
|
-
};
|
|
523
|
-
export const readElementSize = (slice) => {
|
|
524
|
-
let size = readU8(slice);
|
|
525
|
-
if (size === 0xff) {
|
|
526
|
-
size = null;
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
slice.skip(-1);
|
|
530
|
-
size = readVarInt(slice);
|
|
531
|
-
// In some (livestreamed) files, this is the value of the size field. While this technically is just a very
|
|
532
|
-
// large number, it is intended to behave like the reserved size 0xFF, meaning the size is undefined. We
|
|
533
|
-
// catch the number here. Note that it cannot be perfectly represented as a double, but the comparison works
|
|
534
|
-
// nonetheless.
|
|
535
|
-
// eslint-disable-next-line no-loss-of-precision
|
|
536
|
-
if (size === 0x00ffffffffffffff) {
|
|
537
|
-
size = null;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
return size;
|
|
541
|
-
};
|
|
542
|
-
export const readElementHeader = (slice) => {
|
|
543
|
-
const id = readElementId(slice);
|
|
544
|
-
if (id === null) {
|
|
545
|
-
return null;
|
|
546
|
-
}
|
|
547
|
-
const size = readElementSize(slice);
|
|
548
|
-
return { id, size };
|
|
549
|
-
};
|
|
550
|
-
export const readAsciiString = (slice, length) => {
|
|
551
|
-
const bytes = readBytes(slice, length);
|
|
552
|
-
// Actual string length might be shorter due to null terminators
|
|
553
|
-
let strLength = 0;
|
|
554
|
-
while (strLength < length && bytes[strLength] !== 0) {
|
|
555
|
-
strLength += 1;
|
|
556
|
-
}
|
|
557
|
-
return String.fromCharCode(...bytes.subarray(0, strLength));
|
|
558
|
-
};
|
|
559
|
-
export const readUnicodeString = (slice, length) => {
|
|
560
|
-
const bytes = readBytes(slice, length);
|
|
561
|
-
// Actual string length might be shorter due to null terminators
|
|
562
|
-
let strLength = 0;
|
|
563
|
-
while (strLength < length && bytes[strLength] !== 0) {
|
|
564
|
-
strLength += 1;
|
|
565
|
-
}
|
|
566
|
-
return textDecoder.decode(bytes.subarray(0, strLength));
|
|
567
|
-
};
|
|
568
|
-
export const readFloat = (slice, width) => {
|
|
569
|
-
if (width === 0) {
|
|
570
|
-
return 0;
|
|
571
|
-
}
|
|
572
|
-
if (width !== 4 && width !== 8) {
|
|
573
|
-
throw new Error('Bad float size ' + width);
|
|
574
|
-
}
|
|
575
|
-
return width === 4 ? readF32Be(slice) : readF64Be(slice);
|
|
576
|
-
};
|
|
577
|
-
/** Returns the byte offset in the file of the next element with a matching ID. */
|
|
578
|
-
export const searchForNextElementId = async (reader, startPos, ids, until) => {
|
|
579
|
-
const idsSet = new Set(ids);
|
|
580
|
-
let currentPos = startPos;
|
|
581
|
-
while (until === null || currentPos < until) {
|
|
582
|
-
let slice = reader.requestSliceRange(currentPos, MIN_HEADER_SIZE, MAX_HEADER_SIZE);
|
|
583
|
-
if (slice instanceof Promise)
|
|
584
|
-
slice = await slice;
|
|
585
|
-
if (!slice)
|
|
586
|
-
break;
|
|
587
|
-
const elementHeader = readElementHeader(slice);
|
|
588
|
-
if (!elementHeader) {
|
|
589
|
-
break;
|
|
590
|
-
}
|
|
591
|
-
if (idsSet.has(elementHeader.id)) {
|
|
592
|
-
return { pos: currentPos, found: true };
|
|
593
|
-
}
|
|
594
|
-
assertDefinedSize(elementHeader.size);
|
|
595
|
-
currentPos = slice.filePos + elementHeader.size;
|
|
596
|
-
}
|
|
597
|
-
return { pos: (until !== null && until > currentPos) ? until : currentPos, found: false };
|
|
598
|
-
};
|
|
599
|
-
/** Searches for the next occurrence of an element ID using a naive byte-wise search. */
|
|
600
|
-
export const resync = async (reader, startPos, ids, until) => {
|
|
601
|
-
const CHUNK_SIZE = 2 ** 16; // So we don't need to grab thousands of slices
|
|
602
|
-
const idsSet = new Set(ids);
|
|
603
|
-
let currentPos = startPos;
|
|
604
|
-
while (currentPos < until) {
|
|
605
|
-
let slice = reader.requestSliceRange(currentPos, 0, Math.min(CHUNK_SIZE, until - currentPos));
|
|
606
|
-
if (slice instanceof Promise)
|
|
607
|
-
slice = await slice;
|
|
608
|
-
if (!slice)
|
|
609
|
-
break;
|
|
610
|
-
if (slice.length < MAX_VAR_INT_SIZE)
|
|
611
|
-
break;
|
|
612
|
-
for (let i = 0; i < slice.length - MAX_VAR_INT_SIZE; i++) {
|
|
613
|
-
slice.filePos = currentPos;
|
|
614
|
-
const elementId = readElementId(slice);
|
|
615
|
-
if (elementId !== null && idsSet.has(elementId)) {
|
|
616
|
-
return currentPos;
|
|
617
|
-
}
|
|
618
|
-
currentPos++;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
return null;
|
|
622
|
-
};
|
|
623
|
-
export const CODEC_STRING_MAP = {
|
|
624
|
-
'avc': 'V_MPEG4/ISO/AVC',
|
|
625
|
-
'hevc': 'V_MPEGH/ISO/HEVC',
|
|
626
|
-
'vp8': 'V_VP8',
|
|
627
|
-
'vp9': 'V_VP9',
|
|
628
|
-
'av1': 'V_AV1',
|
|
629
|
-
'aac': 'A_AAC',
|
|
630
|
-
'mp3': 'A_MPEG/L3',
|
|
631
|
-
'opus': 'A_OPUS',
|
|
632
|
-
'vorbis': 'A_VORBIS',
|
|
633
|
-
'flac': 'A_FLAC',
|
|
634
|
-
'pcm-u8': 'A_PCM/INT/LIT',
|
|
635
|
-
'pcm-s16': 'A_PCM/INT/LIT',
|
|
636
|
-
'pcm-s16be': 'A_PCM/INT/BIG',
|
|
637
|
-
'pcm-s24': 'A_PCM/INT/LIT',
|
|
638
|
-
'pcm-s24be': 'A_PCM/INT/BIG',
|
|
639
|
-
'pcm-s32': 'A_PCM/INT/LIT',
|
|
640
|
-
'pcm-s32be': 'A_PCM/INT/BIG',
|
|
641
|
-
'pcm-f32': 'A_PCM/FLOAT/IEEE',
|
|
642
|
-
'pcm-f64': 'A_PCM/FLOAT/IEEE',
|
|
643
|
-
'webvtt': 'S_TEXT/WEBVTT',
|
|
644
|
-
'srt': 'S_TEXT/UTF8',
|
|
645
|
-
'ass': 'S_TEXT/ASS',
|
|
646
|
-
'ssa': 'S_TEXT/SSA',
|
|
647
|
-
};
|
|
648
|
-
export function assertDefinedSize(size) {
|
|
649
|
-
if (size === null) {
|
|
650
|
-
throw new Error('Undefined element size is used in a place where it is not supported.');
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
;
|