@remotion/media-parser 4.0.240 → 4.0.242

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.
Files changed (186) hide show
  1. package/dist/add-avc-profile-to-track.js +2 -2
  2. package/dist/boxes/avc/codec-private.d.ts +1 -1
  3. package/dist/boxes/avc/codec-private.js +2 -2
  4. package/dist/boxes/avc/create-sps-pps-data.d.ts +2 -0
  5. package/dist/boxes/avc/create-sps-pps-data.js +28 -0
  6. package/dist/boxes/iso-base-media/get-keyframes.d.ts +3 -0
  7. package/dist/boxes/iso-base-media/get-keyframes.js +30 -0
  8. package/dist/boxes/iso-base-media/mdat/mdat.d.ts +3 -3
  9. package/dist/boxes/iso-base-media/mdat/mdat.js +9 -5
  10. package/dist/boxes/iso-base-media/moov/moov.d.ts +3 -3
  11. package/dist/boxes/iso-base-media/moov/moov.js +5 -4
  12. package/dist/boxes/iso-base-media/process-box.d.ts +9 -9
  13. package/dist/boxes/iso-base-media/process-box.js +48 -56
  14. package/dist/boxes/iso-base-media/stsd/mebx.d.ts +3 -3
  15. package/dist/boxes/iso-base-media/stsd/mebx.js +5 -4
  16. package/dist/boxes/iso-base-media/stsd/samples.d.ts +5 -5
  17. package/dist/boxes/iso-base-media/stsd/samples.js +19 -16
  18. package/dist/boxes/iso-base-media/stsd/stsd.d.ts +3 -3
  19. package/dist/boxes/iso-base-media/stsd/stsd.js +2 -2
  20. package/dist/boxes/iso-base-media/trak/trak.d.ts +3 -3
  21. package/dist/boxes/iso-base-media/trak/trak.js +7 -6
  22. package/dist/boxes/riff/expect-riff-box.d.ts +3 -3
  23. package/dist/boxes/riff/expect-riff-box.js +5 -5
  24. package/dist/boxes/riff/get-tracks-from-avi.js +1 -1
  25. package/dist/boxes/riff/parse-box.d.ts +7 -7
  26. package/dist/boxes/riff/parse-box.js +29 -24
  27. package/dist/boxes/riff/parse-list-box.d.ts +3 -3
  28. package/dist/boxes/riff/parse-list-box.js +2 -2
  29. package/dist/boxes/riff/parse-movi.d.ts +5 -5
  30. package/dist/boxes/riff/parse-movi.js +35 -20
  31. package/dist/boxes/riff/parse-riff-box.d.ts +3 -3
  32. package/dist/boxes/riff/parse-riff-box.js +2 -2
  33. package/dist/boxes/transport-stream/adts-header.d.ts +1 -1
  34. package/dist/boxes/transport-stream/discard-rest-of-packet.d.ts +1 -1
  35. package/dist/boxes/transport-stream/get-tracks.js +1 -1
  36. package/dist/boxes/transport-stream/handle-aac-packet.d.ts +4 -3
  37. package/dist/boxes/transport-stream/handle-aac-packet.js +6 -4
  38. package/dist/boxes/transport-stream/handle-avc-packet.d.ts +4 -3
  39. package/dist/boxes/transport-stream/handle-avc-packet.js +8 -6
  40. package/dist/boxes/transport-stream/parse-packet.d.ts +3 -3
  41. package/dist/boxes/transport-stream/parse-packet.js +2 -2
  42. package/dist/boxes/transport-stream/parse-stream-packet.d.ts +3 -3
  43. package/dist/boxes/transport-stream/parse-stream-packet.js +14 -7
  44. package/dist/boxes/transport-stream/parse-transport-stream.d.ts +5 -6
  45. package/dist/boxes/transport-stream/parse-transport-stream.js +10 -9
  46. package/dist/boxes/transport-stream/process-stream-buffers.d.ts +6 -5
  47. package/dist/boxes/transport-stream/process-stream-buffers.js +18 -8
  48. package/dist/boxes/webm/ebml.d.ts +1 -1
  49. package/dist/boxes/webm/get-sample-from-block.d.ts +2 -2
  50. package/dist/boxes/webm/get-sample-from-block.js +8 -4
  51. package/dist/boxes/webm/make-header.d.ts +3 -3
  52. package/dist/boxes/webm/parse-ebml.d.ts +4 -4
  53. package/dist/boxes/webm/parse-ebml.js +18 -18
  54. package/dist/boxes/webm/parse-webm-header.d.ts +5 -5
  55. package/dist/boxes/webm/parse-webm-header.js +6 -5
  56. package/dist/boxes/webm/segments/parse-children.d.ts +5 -5
  57. package/dist/boxes/webm/segments/parse-children.js +12 -13
  58. package/dist/boxes/webm/segments.d.ts +3 -3
  59. package/dist/boxes/webm/segments.js +13 -13
  60. package/dist/buffer-iterator.d.ts +2 -6
  61. package/dist/buffer-iterator.js +4 -29
  62. package/dist/convert-audio-or-video-sample.js +2 -0
  63. package/dist/create/iso-base-media/codec-specific/avc1.d.ts +1 -1
  64. package/dist/create/iso-base-media/codec-specific/create-codec-specific-data.d.ts +1 -1
  65. package/dist/create/iso-base-media/codec-specific/mp4a.d.ts +1 -1
  66. package/dist/create/iso-base-media/create-colr.d.ts +1 -1
  67. package/dist/create/iso-base-media/create-ftyp.d.ts +2 -2
  68. package/dist/create/iso-base-media/create-ilst.d.ts +1 -1
  69. package/dist/create/iso-base-media/create-mdia.d.ts +1 -1
  70. package/dist/create/iso-base-media/create-moov.d.ts +1 -1
  71. package/dist/create/iso-base-media/create-mvhd.d.ts +1 -1
  72. package/dist/create/iso-base-media/create-trak.d.ts +1 -1
  73. package/dist/create/iso-base-media/create-udta.d.ts +1 -1
  74. package/dist/create/iso-base-media/create-url.d.ts +1 -1
  75. package/dist/create/iso-base-media/ilst/create-cmt.d.ts +1 -1
  76. package/dist/create/iso-base-media/ilst/create-too.d.ts +1 -1
  77. package/dist/create/iso-base-media/mdia/create-mdhd.d.ts +1 -1
  78. package/dist/create/iso-base-media/mp4-header.d.ts +1 -1
  79. package/dist/create/iso-base-media/primitives.d.ts +13 -13
  80. package/dist/create/iso-base-media/serialize-track.d.ts +1 -1
  81. package/dist/create/iso-base-media/trak/create-tkhd.d.ts +2 -2
  82. package/dist/create/iso-base-media/trak/mdia/create-minf.d.ts +1 -1
  83. package/dist/create/iso-base-media/trak/mdia/minf/create-dinf.d.ts +1 -1
  84. package/dist/create/iso-base-media/trak/mdia/minf/create-smhd.d.ts +1 -1
  85. package/dist/create/iso-base-media/trak/mdia/minf/create-stbl.d.ts +1 -1
  86. package/dist/create/iso-base-media/trak/mdia/minf/create-vmhd.d.ts +1 -1
  87. package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-ctts.d.ts +1 -1
  88. package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stco.d.ts +1 -1
  89. package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stsc.d.ts +1 -1
  90. package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stss.d.ts +1 -1
  91. package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stsz.d.ts +1 -1
  92. package/dist/create/iso-base-media/trak/mdia/minf/stbl/create-stts.d.ts +1 -1
  93. package/dist/create/iso-base-media/trak/mdia/minf/stbl/stsd/create-avc1.d.ts +1 -1
  94. package/dist/create/iso-base-media/trak/mdia/minf/stbl/stsd/create-avcc.d.ts +1 -1
  95. package/dist/create/iso-base-media/trak/mdia/minf/stbl/stsd/create-pasp.d.ts +1 -1
  96. package/dist/create/iso-base-media/udta/create-meta.d.ts +1 -1
  97. package/dist/create/iso-base-media/udta/meta/create-hdlr.d.ts +1 -1
  98. package/dist/create/matroska/cluster-segment.d.ts +1 -1
  99. package/dist/emit-available-info.d.ts +6 -4
  100. package/dist/emit-available-info.js +231 -79
  101. package/dist/errors/detect-file-type.d.ts +1 -0
  102. package/dist/errors/detect-file-type.js +88 -0
  103. package/dist/errors/file-types.d.ts +1 -0
  104. package/dist/errors/file-types.js +88 -0
  105. package/dist/errors.d.ts +68 -0
  106. package/dist/errors.js +71 -0
  107. package/dist/esm/from-fetch.mjs +1 -0
  108. package/dist/esm/from-node.mjs +1 -0
  109. package/dist/esm/from-web-file.mjs +2 -1
  110. package/dist/esm/index.mjs +1457 -542
  111. package/dist/file-types/bmp.d.ts +6 -0
  112. package/dist/file-types/bmp.js +23 -0
  113. package/dist/file-types/detect-file-type.d.ts +42 -0
  114. package/dist/file-types/detect-file-type.js +59 -0
  115. package/dist/file-types/get-jpeg-dimensions.d.ts +4 -0
  116. package/dist/file-types/get-jpeg-dimensions.js +32 -0
  117. package/dist/file-types/index.d.ts +2 -0
  118. package/dist/file-types/index.js +57 -0
  119. package/dist/file-types/jpeg.d.ts +12 -0
  120. package/dist/file-types/jpeg.js +44 -0
  121. package/dist/file-types/pdf.d.ts +4 -0
  122. package/dist/file-types/pdf.js +12 -0
  123. package/dist/file-types/png.d.ts +10 -0
  124. package/dist/file-types/png.js +32 -0
  125. package/dist/file-types/webp.d.ts +6 -0
  126. package/dist/file-types/webp.js +69 -0
  127. package/dist/file-types.d.ts +1 -0
  128. package/dist/file-types.js +88 -0
  129. package/dist/get-audio-codec.d.ts +1 -1
  130. package/dist/get-duration.d.ts +1 -0
  131. package/dist/get-duration.js +14 -1
  132. package/dist/get-fields-from-callbacks.d.ts +5 -0
  133. package/dist/get-fields-from-callbacks.js +32 -0
  134. package/dist/get-fps.d.ts +1 -0
  135. package/dist/get-fps.js +17 -12
  136. package/dist/get-keyframes.d.ts +5 -0
  137. package/dist/get-keyframes.js +20 -0
  138. package/dist/get-tracks.d.ts +7 -1
  139. package/dist/get-tracks.js +15 -10
  140. package/dist/has-all-info.d.ts +5 -4
  141. package/dist/has-all-info.js +31 -5
  142. package/dist/index.d.ts +2 -0
  143. package/dist/index.js +7 -1
  144. package/dist/may-skip-video-data/may-skip-video-data.d.ts +4 -0
  145. package/dist/may-skip-video-data/may-skip-video-data.js +14 -0
  146. package/dist/may-skip-video-data/need-samples-for-fields.d.ts +5 -0
  147. package/dist/may-skip-video-data/need-samples-for-fields.js +33 -0
  148. package/dist/options.d.ts +68 -53
  149. package/dist/parse-media.js +42 -31
  150. package/dist/parse-result.d.ts +2 -4
  151. package/dist/parse-video.d.ts +8 -5
  152. package/dist/parse-video.js +94 -17
  153. package/dist/probing/detect-file-type.d.ts +1 -0
  154. package/dist/probing/detect-file-type.js +88 -0
  155. package/dist/probing/get-jpeg-dimensions.d.ts +4 -0
  156. package/dist/probing/get-jpeg-dimensions.js +32 -0
  157. package/dist/readers/from-fetch.js +1 -0
  158. package/dist/readers/from-node.js +1 -0
  159. package/dist/readers/from-web-file.js +1 -0
  160. package/dist/readers/reader.d.ts +1 -0
  161. package/dist/register-track.d.ts +5 -5
  162. package/dist/register-track.js +12 -12
  163. package/dist/state/can-skip-tracks.js +6 -0
  164. package/dist/state/emitted-fields.d.ts +2 -0
  165. package/dist/state/emitted-fields.js +31 -0
  166. package/dist/state/has-tracks-section.d.ts +1 -0
  167. package/dist/state/keyframes.d.ts +6 -0
  168. package/dist/state/keyframes.js +15 -0
  169. package/dist/state/parser-state.d.ts +60 -29
  170. package/dist/state/parser-state.js +32 -150
  171. package/dist/state/riff.d.ts +10 -0
  172. package/dist/state/riff.js +32 -0
  173. package/dist/state/sample-callbacks.d.ts +31 -0
  174. package/dist/state/sample-callbacks.js +96 -0
  175. package/dist/state/slow-duration-fps.d.ts +8 -0
  176. package/dist/state/slow-duration-fps.js +36 -0
  177. package/dist/state/structure.d.ts +7 -0
  178. package/dist/state/structure.js +21 -0
  179. package/dist/state/tracks-and-samples.d.ts +0 -0
  180. package/dist/state/tracks-and-samples.js +1 -0
  181. package/dist/state/webm.d.ts +11 -0
  182. package/dist/state/webm.js +67 -0
  183. package/dist/version.d.ts +1 -1
  184. package/dist/version.js +1 -1
  185. package/dist/webcodec-sample-types.d.ts +2 -0
  186. package/package.json +3 -3
@@ -2,16 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMebx = void 0;
4
4
  const process_box_1 = require("../process-box");
5
- const parseMebx = async ({ iterator, offset, size, options, signal, fields, }) => {
5
+ const parseMebx = async ({ iterator, offset, size, state, signal, fields, }) => {
6
6
  // reserved, 6 bit
7
7
  iterator.discard(6);
8
8
  const dataReferenceIndex = iterator.getUint16();
9
+ const boxes = [];
9
10
  const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
10
11
  iterator,
11
12
  maxBytes: iterator.counter.getOffset() - offset,
12
13
  allowIncompleteBoxes: false,
13
- initialBoxes: [],
14
- options,
14
+ initialBoxes: boxes,
15
+ state,
15
16
  continueMdat: false,
16
17
  signal,
17
18
  logLevel: 'info',
@@ -26,7 +27,7 @@ const parseMebx = async ({ iterator, offset, size, options, signal, fields, }) =
26
27
  offset,
27
28
  dataReferenceIndex,
28
29
  format: 'mebx',
29
- children: children.segments.boxes,
30
+ children: boxes,
30
31
  };
31
32
  };
32
33
  exports.parseMebx = parseMebx;
@@ -2,7 +2,7 @@ import type { BufferIterator } from '../../../buffer-iterator';
2
2
  import type { LogLevel } from '../../../log';
3
3
  import type { Options, ParseMediaFields } from '../../../options';
4
4
  import type { AnySegment, IsoBaseMediaBox } from '../../../parse-result';
5
- import type { ParserContext } from '../../../parser-context';
5
+ import type { ParserState } from '../../../state/parser-state';
6
6
  type SampleBase = {
7
7
  format: string;
8
8
  offset: number;
@@ -50,17 +50,17 @@ export type Sample = AudioSample | VideoSample | UnknownSample;
50
50
  type SampleAndNext = {
51
51
  sample: Sample | null;
52
52
  };
53
- export declare const processSample: ({ iterator, options, signal, logLevel, fields, }: {
53
+ export declare const processSample: ({ iterator, state: options, signal, logLevel, fields, }: {
54
54
  iterator: BufferIterator;
55
- options: ParserContext;
55
+ state: ParserState;
56
56
  signal: AbortSignal | null;
57
57
  logLevel: LogLevel;
58
58
  fields: Options<ParseMediaFields>;
59
59
  }) => Promise<SampleAndNext>;
60
- export declare const parseSamples: ({ iterator, maxBytes, options, signal, logLevel, fields, }: {
60
+ export declare const parseSamples: ({ iterator, maxBytes, state, signal, logLevel, fields, }: {
61
61
  iterator: BufferIterator;
62
62
  maxBytes: number;
63
- options: ParserContext;
63
+ state: ParserState;
64
64
  signal: AbortSignal | null;
65
65
  logLevel: LogLevel;
66
66
  fields: Options<ParseMediaFields>;
@@ -62,7 +62,7 @@ const audioTags = [
62
62
  'mp4a',
63
63
  'ac-3',
64
64
  ];
65
- const processSample = async ({ iterator, options, signal, logLevel, fields, }) => {
65
+ const processSample = async ({ iterator, state: options, signal, logLevel, fields, }) => {
66
66
  const fileOffset = iterator.counter.getOffset();
67
67
  const bytesRemaining = iterator.bytesRemaining();
68
68
  const boxSize = iterator.getUint32();
@@ -99,12 +99,13 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
99
99
  const packetSize = iterator.getUint16();
100
100
  const sampleRate = iterator.getFixedPointUnsigned1616Number();
101
101
  const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
102
+ const initialBoxes = [];
102
103
  const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
103
104
  iterator,
104
105
  allowIncompleteBoxes: false,
105
106
  maxBytes: bytesRemainingInBox,
106
- initialBoxes: [],
107
- options,
107
+ initialBoxes,
108
+ state: options,
108
109
  continueMdat: false,
109
110
  signal,
110
111
  logLevel,
@@ -132,7 +133,7 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
132
133
  bytesPerPacket: null,
133
134
  bytesPerFrame: null,
134
135
  bitsPerSample: null,
135
- children: children.segments.boxes,
136
+ children: initialBoxes,
136
137
  },
137
138
  };
138
139
  }
@@ -147,12 +148,13 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
147
148
  const bytesPerFrame = iterator.getUint32();
148
149
  const bytesPerSample = iterator.getUint32();
149
150
  const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
151
+ const initialBoxes = [];
150
152
  const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
151
153
  iterator,
152
154
  allowIncompleteBoxes: false,
153
155
  maxBytes: bytesRemainingInBox,
154
- initialBoxes: [],
155
- options,
156
+ initialBoxes,
157
+ state: options,
156
158
  continueMdat: false,
157
159
  signal,
158
160
  logLevel,
@@ -180,7 +182,7 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
180
182
  bytesPerPacket,
181
183
  bytesPerFrame,
182
184
  bitsPerSample: bytesPerSample,
183
- children: children.segments.boxes,
185
+ children: initialBoxes,
184
186
  },
185
187
  };
186
188
  }
@@ -204,7 +206,7 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
204
206
  allowIncompleteBoxes: false,
205
207
  maxBytes: bytesRemainingInBox,
206
208
  initialBoxes: [],
207
- options,
209
+ state: options,
208
210
  continueMdat: false,
209
211
  signal,
210
212
  logLevel,
@@ -213,6 +215,7 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
213
215
  if (children.status === 'incomplete') {
214
216
  throw new Error('Incomplete boxes are not allowed');
215
217
  }
218
+ const initialBoxes = [];
216
219
  return {
217
220
  sample: {
218
221
  format: boxFormat,
@@ -232,7 +235,7 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
232
235
  bytesPerPacket: null,
233
236
  bytesPerFrame,
234
237
  bitsPerSample: bitsPerChannel,
235
- children: children.segments.boxes,
238
+ children: initialBoxes,
236
239
  },
237
240
  };
238
241
  }
@@ -254,20 +257,20 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
254
257
  const depth = iterator.getUint16();
255
258
  const colorTableId = iterator.getInt16();
256
259
  const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
260
+ const initialBoxes = [];
257
261
  const children = bytesRemainingInBox > 8
258
262
  ? await (0, process_box_1.parseIsoBaseMediaBoxes)({
259
263
  iterator,
260
264
  allowIncompleteBoxes: false,
261
265
  maxBytes: bytesRemainingInBox,
262
- initialBoxes: [],
263
- options,
266
+ initialBoxes,
267
+ state: options,
264
268
  continueMdat: false,
265
269
  signal,
266
270
  logLevel,
267
271
  fields,
268
272
  })
269
- : (iterator.discard(bytesRemainingInBox),
270
- { status: 'done', segments: { boxes: [], type: 'iso-base-media' } });
273
+ : (iterator.discard(bytesRemainingInBox), { status: 'done' });
271
274
  if (children.status === 'incomplete') {
272
275
  throw new Error('Incomplete boxes are not allowed');
273
276
  }
@@ -292,21 +295,21 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
292
295
  compressorName,
293
296
  depth,
294
297
  colorTableId,
295
- descriptors: children.segments.boxes,
298
+ descriptors: initialBoxes,
296
299
  },
297
300
  };
298
301
  }
299
302
  throw new Error(`Unknown sample format ${boxFormat}`);
300
303
  };
301
304
  exports.processSample = processSample;
302
- const parseSamples = async ({ iterator, maxBytes, options, signal, logLevel, fields, }) => {
305
+ const parseSamples = async ({ iterator, maxBytes, state, signal, logLevel, fields, }) => {
303
306
  const samples = [];
304
307
  const initialOffset = iterator.counter.getOffset();
305
308
  while (iterator.bytesRemaining() > 0 &&
306
309
  iterator.counter.getOffset() - initialOffset < maxBytes) {
307
310
  const { sample } = await (0, exports.processSample)({
308
311
  iterator,
309
- options,
312
+ state,
310
313
  signal,
311
314
  logLevel,
312
315
  fields,
@@ -1,6 +1,6 @@
1
1
  import type { BufferIterator } from '../../../buffer-iterator';
2
2
  import type { Options, ParseMediaFields } from '../../../options';
3
- import type { ParserContext } from '../../../parser-context';
3
+ import type { ParserState } from '../../../state/parser-state';
4
4
  import type { BaseBox } from '../base-type';
5
5
  import type { Sample } from './samples';
6
6
  export interface StsdBox extends BaseBox {
@@ -8,11 +8,11 @@ export interface StsdBox extends BaseBox {
8
8
  numberOfEntries: number;
9
9
  samples: Sample[];
10
10
  }
11
- export declare const parseStsd: ({ iterator, offset, size, options, signal, fields, }: {
11
+ export declare const parseStsd: ({ iterator, offset, size, state, signal, fields, }: {
12
12
  iterator: BufferIterator;
13
13
  offset: number;
14
14
  size: number;
15
- options: ParserContext;
15
+ state: ParserState;
16
16
  signal: AbortSignal | null;
17
17
  fields: Options<ParseMediaFields>;
18
18
  }) => Promise<StsdBox>;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseStsd = void 0;
4
4
  const samples_1 = require("./samples");
5
- const parseStsd = async ({ iterator, offset, size, options, signal, fields, }) => {
5
+ const parseStsd = async ({ iterator, offset, size, state, signal, fields, }) => {
6
6
  const version = iterator.getUint8();
7
7
  if (version !== 0) {
8
8
  throw new Error(`Unsupported STSD version ${version}`);
@@ -14,7 +14,7 @@ const parseStsd = async ({ iterator, offset, size, options, signal, fields, }) =
14
14
  const boxes = await (0, samples_1.parseSamples)({
15
15
  iterator,
16
16
  maxBytes: bytesRemainingInBox,
17
- options,
17
+ state,
18
18
  signal,
19
19
  logLevel: 'info',
20
20
  fields,
@@ -2,17 +2,17 @@ import type { BufferIterator } from '../../../buffer-iterator';
2
2
  import type { LogLevel } from '../../../log';
3
3
  import type { Options, ParseMediaFields } from '../../../options';
4
4
  import type { AnySegment } from '../../../parse-result';
5
- import type { ParserContext } from '../../../parser-context';
5
+ import type { ParserState } from '../../../state/parser-state';
6
6
  import type { BaseBox } from '../base-type';
7
7
  export interface TrakBox extends BaseBox {
8
8
  type: 'trak-box';
9
9
  children: AnySegment[];
10
10
  }
11
- export declare const parseTrak: ({ data, size, offsetAtStart, options, signal, logLevel, fields, }: {
11
+ export declare const parseTrak: ({ data, size, offsetAtStart, state: options, signal, logLevel, fields, }: {
12
12
  data: BufferIterator;
13
13
  size: number;
14
14
  offsetAtStart: number;
15
- options: ParserContext;
15
+ state: ParserState;
16
16
  signal: AbortSignal | null;
17
17
  logLevel: LogLevel;
18
18
  fields: Options<ParseMediaFields>;
@@ -2,26 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseTrak = void 0;
4
4
  const process_box_1 = require("../process-box");
5
- const parseTrak = async ({ data, size, offsetAtStart, options, signal, logLevel, fields, }) => {
6
- const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
5
+ const parseTrak = async ({ data, size, offsetAtStart, state: options, signal, logLevel, fields, }) => {
6
+ const initialBoxes = [];
7
+ const result = await (0, process_box_1.parseIsoBaseMediaBoxes)({
7
8
  iterator: data,
8
9
  maxBytes: size - (data.counter.getOffset() - offsetAtStart),
9
10
  allowIncompleteBoxes: false,
10
- initialBoxes: [],
11
- options,
11
+ initialBoxes,
12
+ state: options,
12
13
  continueMdat: false,
13
14
  signal,
14
15
  logLevel,
15
16
  fields,
16
17
  });
17
- if (children.status === 'incomplete') {
18
+ if (result.status === 'incomplete') {
18
19
  throw new Error('Incomplete boxes are not allowed');
19
20
  }
20
21
  return {
21
22
  offset: offsetAtStart,
22
23
  boxSize: size,
23
24
  type: 'trak-box',
24
- children: children.segments.boxes,
25
+ children: initialBoxes,
25
26
  };
26
27
  };
27
28
  exports.parseTrak = parseTrak;
@@ -1,6 +1,6 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
2
  import type { RiffStructure } from '../../parse-result';
3
- import type { ParserContext } from '../../parser-context';
3
+ import type { ParserState } from '../../state/parser-state';
4
4
  import type { RiffBox } from './riff-box';
5
5
  export type RiffResult = {
6
6
  type: 'incomplete';
@@ -10,8 +10,8 @@ export type RiffResult = {
10
10
  box: RiffBox | null;
11
11
  skipTo: number | null;
12
12
  };
13
- export declare const expectRiffBox: ({ iterator, options, structure, }: {
13
+ export declare const expectRiffBox: ({ iterator, state, structure, }: {
14
14
  iterator: BufferIterator;
15
- options: ParserContext;
15
+ state: ParserState;
16
16
  structure: RiffStructure;
17
17
  }) => Promise<RiffResult>;
@@ -4,13 +4,13 @@ exports.expectRiffBox = void 0;
4
4
  const is_movi_1 = require("./is-movi");
5
5
  const parse_movi_1 = require("./parse-movi");
6
6
  const parse_riff_box_1 = require("./parse-riff-box");
7
- const expectRiffBox = async ({ iterator, options, structure, }) => {
7
+ const expectRiffBox = async ({ iterator, state, structure, }) => {
8
8
  // Need at least 16 bytes to read LIST,size,movi,size
9
9
  if (iterator.bytesRemaining() < 16) {
10
10
  return {
11
11
  type: 'incomplete',
12
12
  continueParsing() {
13
- return (0, exports.expectRiffBox)({ structure, iterator, options });
13
+ return (0, exports.expectRiffBox)({ structure, iterator, state });
14
14
  },
15
15
  };
16
16
  }
@@ -21,7 +21,7 @@ const expectRiffBox = async ({ iterator, options, structure, }) => {
21
21
  return (0, parse_movi_1.parseMovi)({
22
22
  iterator,
23
23
  maxOffset: ckSize + iterator.counter.getOffset() - 4,
24
- options,
24
+ state,
25
25
  structure,
26
26
  });
27
27
  }
@@ -30,7 +30,7 @@ const expectRiffBox = async ({ iterator, options, structure, }) => {
30
30
  return {
31
31
  type: 'incomplete',
32
32
  continueParsing: () => {
33
- return (0, exports.expectRiffBox)({ structure, iterator, options });
33
+ return (0, exports.expectRiffBox)({ structure, iterator, state });
34
34
  },
35
35
  };
36
36
  }
@@ -41,7 +41,7 @@ const expectRiffBox = async ({ iterator, options, structure, }) => {
41
41
  iterator,
42
42
  size: ckSize,
43
43
  boxes: structure.boxes,
44
- options,
44
+ state,
45
45
  }),
46
46
  skipTo: null,
47
47
  };
@@ -82,7 +82,7 @@ const getTracksFromAvi = (structure, state) => {
82
82
  continue;
83
83
  }
84
84
  if (strf.type === 'strf-box-video') {
85
- videoTracks.push((0, add_avc_profile_to_track_1.addAvcProfileToTrack)((0, exports.makeAviVideoTrack)({ strh, strf, index: i }), state.getAvcProfile()));
85
+ videoTracks.push((0, add_avc_profile_to_track_1.addAvcProfileToTrack)((0, exports.makeAviVideoTrack)({ strh, strf, index: i }), state.riff.getAvcProfile()));
86
86
  }
87
87
  else if (strh.fccType === 'auds') {
88
88
  audioTracks.push((0, exports.makeAviAudioTrack)({ strf, index: i }));
@@ -1,15 +1,15 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
2
  import type { Options, ParseMediaFields } from '../../options';
3
3
  import type { ParseResult, RiffStructure } from '../../parse-result';
4
- import type { ParserContext } from '../../parser-context';
5
- export declare const parseRiffBody: ({ iterator, structure, maxOffset, options, }: {
4
+ import type { ParserState } from '../../state/parser-state';
5
+ export declare const parseRiffBody: ({ iterator, structure, maxOffset, state, }: {
6
6
  iterator: BufferIterator;
7
7
  structure: RiffStructure;
8
8
  maxOffset: number;
9
- options: ParserContext;
10
- }) => Promise<ParseResult<RiffStructure>>;
11
- export declare const parseRiff: ({ iterator, options, fields, }: {
9
+ state: ParserState;
10
+ }) => Promise<ParseResult>;
11
+ export declare const parseRiff: ({ iterator, state, fields, }: {
12
12
  iterator: BufferIterator;
13
- options: ParserContext;
13
+ state: ParserState;
14
14
  fields: Options<ParseMediaFields>;
15
- }) => Promise<ParseResult<RiffStructure>>;
15
+ }) => Promise<ParseResult>;
@@ -7,7 +7,7 @@ const register_track_1 = require("../../register-track");
7
7
  const expect_riff_box_1 = require("./expect-riff-box");
8
8
  const get_tracks_from_avi_1 = require("./get-tracks-from-avi");
9
9
  const traversal_1 = require("./traversal");
10
- const continueAfterRiffBoxResult = ({ result, structure, iterator, maxOffset, options, }) => {
10
+ const continueAfterRiffBoxResult = ({ result, structure, iterator, maxOffset, state: options, }) => {
11
11
  if (result.type === 'incomplete') {
12
12
  return Promise.resolve({
13
13
  status: 'incomplete',
@@ -17,7 +17,7 @@ const continueAfterRiffBoxResult = ({ result, structure, iterator, maxOffset, op
17
17
  structure,
18
18
  iterator,
19
19
  maxOffset,
20
- options,
20
+ state: options,
21
21
  }));
22
22
  },
23
23
  segments: structure,
@@ -27,26 +27,25 @@ const continueAfterRiffBoxResult = ({ result, structure, iterator, maxOffset, op
27
27
  if (result.type === 'complete' && result.box) {
28
28
  structure.boxes.push(result.box);
29
29
  }
30
- return (0, exports.parseRiffBody)({ iterator, maxOffset, options, structure });
30
+ return (0, exports.parseRiffBody)({ iterator, maxOffset, state: options, structure });
31
31
  };
32
- const parseRiffBody = async ({ iterator, structure, maxOffset, options, }) => {
32
+ const parseRiffBody = async ({ iterator, structure, maxOffset, state, }) => {
33
33
  while (iterator.bytesRemaining() > 0 &&
34
34
  iterator.counter.getOffset() < maxOffset) {
35
35
  const result = await (0, expect_riff_box_1.expectRiffBox)({
36
36
  iterator,
37
- options,
37
+ state,
38
38
  structure,
39
39
  });
40
40
  if (result.type === 'complete' && result.skipTo !== null) {
41
41
  return {
42
42
  status: 'incomplete',
43
43
  skipTo: result.skipTo,
44
- segments: structure,
45
44
  continueParsing() {
46
45
  return Promise.resolve(continueAfterRiffBoxResult({
47
46
  iterator,
48
47
  maxOffset,
49
- options,
48
+ state,
50
49
  result,
51
50
  structure,
52
51
  }));
@@ -60,12 +59,11 @@ const parseRiffBody = async ({ iterator, structure, maxOffset, options, }) => {
60
59
  return Promise.resolve(continueAfterRiffBoxResult({
61
60
  iterator,
62
61
  maxOffset,
63
- options,
62
+ state,
64
63
  result: await result.continueParsing(),
65
64
  structure,
66
65
  }));
67
66
  },
68
- segments: structure,
69
67
  skipTo: null,
70
68
  };
71
69
  }
@@ -75,14 +73,14 @@ const parseRiffBody = async ({ iterator, structure, maxOffset, options, }) => {
75
73
  structure.boxes.push(result.box);
76
74
  // When parsing an AVI
77
75
  if (result.box.type === 'list-box' && result.box.listType === 'hdrl') {
78
- const tracks = (0, get_tracks_1.getTracks)(structure, options.parserState);
76
+ const tracks = (0, get_tracks_1.getTracks)(structure, state);
79
77
  if (!tracks.videoTracks.some((t) => t.codec === get_tracks_from_avi_1.TO_BE_OVERRIDDEN_LATER)) {
80
- options.parserState.tracks.setIsDone();
78
+ state.callbacks.tracks.setIsDone();
81
79
  }
82
80
  }
83
81
  // When parsing a WAV
84
82
  if (result.box.type === 'wave-format-box') {
85
- options.parserState.tracks.setIsDone();
83
+ state.callbacks.tracks.setIsDone();
86
84
  }
87
85
  if (result.box.type === 'strf-box-video' ||
88
86
  result.box.type === 'strf-box-audio') {
@@ -91,56 +89,63 @@ const parseRiffBody = async ({ iterator, structure, maxOffset, options, }) => {
91
89
  if (!strh || !strf) {
92
90
  throw new Error('strh or strf box missing');
93
91
  }
94
- if (strf.type === 'strf-box-audio' && options.onAudioTrack) {
92
+ if (strf.type === 'strf-box-audio' && state.onAudioTrack) {
95
93
  const audioTrack = (0, get_tracks_from_avi_1.makeAviAudioTrack)({
96
- index: options.nextTrackIndex,
94
+ index: state.riff.getNextTrackIndex(),
97
95
  strf,
98
96
  });
99
97
  await (0, register_track_1.registerTrack)({
100
- options,
98
+ state,
101
99
  track: audioTrack,
102
100
  container: 'avi',
103
101
  });
104
102
  }
105
- if (options.onVideoTrack && strf.type === 'strf-box-video') {
103
+ if (state.onVideoTrack && strf.type === 'strf-box-video') {
106
104
  const videoTrack = (0, get_tracks_from_avi_1.makeAviVideoTrack)({
107
105
  strh,
108
- index: options.nextTrackIndex,
106
+ index: state.riff.getNextTrackIndex(),
109
107
  strf,
110
108
  });
111
109
  (0, register_track_1.registerVideoTrackWhenProfileIsAvailable)({
112
- options,
110
+ state,
113
111
  track: videoTrack,
114
112
  container: 'avi',
115
113
  });
116
114
  }
117
- options.nextTrackIndex++;
115
+ state.riff.incrementNextTrackIndex();
118
116
  }
119
117
  }
120
118
  return {
121
119
  status: 'done',
122
- segments: structure,
123
120
  };
124
121
  };
125
122
  exports.parseRiffBody = parseRiffBody;
126
- const parseRiff = ({ iterator, options, fields, }) => {
127
- const structure = { type: 'riff', boxes: [] };
123
+ const parseRiff = ({ iterator, state, fields, }) => {
128
124
  const riff = iterator.getByteString(4);
129
125
  if (riff !== 'RIFF') {
130
126
  throw new Error('Not a RIFF file');
131
127
  }
128
+ const structure = state.structure.getStructure();
129
+ if (structure.type !== 'riff') {
130
+ throw new Error('Structure is not a RIFF structure');
131
+ }
132
132
  const size = iterator.getUint32Le();
133
133
  const fileType = iterator.getByteString(4);
134
134
  if (fileType !== 'WAVE' && fileType !== 'AVI') {
135
135
  throw new Error(`File type ${fileType} not supported`);
136
136
  }
137
137
  structure.boxes.push({ type: 'riff-header', fileSize: size, fileType });
138
- if ((0, has_all_info_1.hasAllInfo)({ fields, structure, state: options.parserState })) {
138
+ if ((0, has_all_info_1.hasAllInfo)({ fields, state })) {
139
139
  return Promise.resolve({
140
140
  status: 'done',
141
141
  segments: structure,
142
142
  });
143
143
  }
144
- return (0, exports.parseRiffBody)({ iterator, structure, maxOffset: Infinity, options });
144
+ return (0, exports.parseRiffBody)({
145
+ iterator,
146
+ maxOffset: Infinity,
147
+ state,
148
+ structure,
149
+ });
145
150
  };
146
151
  exports.parseRiff = parseRiff;
@@ -1,8 +1,8 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
- import type { ParserContext } from '../../parser-context';
2
+ import type { ParserState } from '../../state/parser-state';
3
3
  import type { RiffBox } from './riff-box';
4
- export declare const parseListBox: ({ iterator, size, options, }: {
4
+ export declare const parseListBox: ({ iterator, size, state, }: {
5
5
  iterator: BufferIterator;
6
6
  size: number;
7
- options: ParserContext;
7
+ state: ParserState;
8
8
  }) => Promise<RiffBox>;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseListBox = void 0;
4
4
  const parse_box_1 = require("./parse-box");
5
- const parseListBox = async ({ iterator, size, options, }) => {
5
+ const parseListBox = async ({ iterator, size, state, }) => {
6
6
  const counter = iterator.counter.getOffset();
7
7
  const listType = iterator.getByteString(4);
8
8
  if (listType === 'movi') {
@@ -16,7 +16,7 @@ const parseListBox = async ({ iterator, size, options, }) => {
16
16
  structure,
17
17
  iterator,
18
18
  maxOffset: counter + size,
19
- options,
19
+ state,
20
20
  });
21
21
  if (result.status === 'incomplete') {
22
22
  throw new Error(`Should only parse complete boxes (${listType})`);
@@ -1,17 +1,17 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
2
  import type { RiffStructure } from '../../parse-result';
3
- import type { ParserContext } from '../../parser-context';
3
+ import type { ParserState } from '../../state/parser-state';
4
4
  import type { RiffResult } from './expect-riff-box';
5
- export declare const handleChunk: ({ iterator, options, structure, ckId, ckSize, }: {
5
+ export declare const handleChunk: ({ iterator, state, structure, ckId, ckSize, }: {
6
6
  iterator: BufferIterator;
7
- options: ParserContext;
7
+ state: ParserState;
8
8
  structure: RiffStructure;
9
9
  ckId: string;
10
10
  ckSize: number;
11
11
  }) => Promise<void>;
12
- export declare const parseMovi: ({ iterator, maxOffset, options, structure, }: {
12
+ export declare const parseMovi: ({ iterator, maxOffset, state, structure, }: {
13
13
  iterator: BufferIterator;
14
14
  maxOffset: number;
15
- options: ParserContext;
15
+ state: ParserState;
16
16
  structure: RiffStructure;
17
17
  }) => Promise<RiffResult>;