@remotion/media-parser 4.0.248 → 4.0.250

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 (162) hide show
  1. package/dist/boxes/avc/key.d.ts +1 -1
  2. package/dist/boxes/iso-base-media/continue-mdat-routine.d.ts +14 -0
  3. package/dist/boxes/iso-base-media/continue-mdat-routine.js +74 -0
  4. package/dist/boxes/iso-base-media/get-children.d.ts +8 -0
  5. package/dist/boxes/iso-base-media/get-children.js +23 -0
  6. package/dist/boxes/iso-base-media/mdat/mdat.d.ts +3 -22
  7. package/dist/boxes/iso-base-media/mdat/mdat.js +80 -121
  8. package/dist/boxes/iso-base-media/moov/moov.d.ts +1 -6
  9. package/dist/boxes/iso-base-media/moov/moov.js +5 -15
  10. package/dist/boxes/iso-base-media/parse-all-children.d.ts +8 -0
  11. package/dist/boxes/iso-base-media/parse-all-children.js +20 -0
  12. package/dist/boxes/iso-base-media/parse-boxes.d.ts +7 -0
  13. package/dist/boxes/iso-base-media/parse-boxes.js +46 -0
  14. package/dist/boxes/iso-base-media/parse-mdat-partially.d.ts +9 -0
  15. package/dist/boxes/iso-base-media/parse-mdat-partially.js +24 -0
  16. package/dist/boxes/iso-base-media/process-box.d.ts +2 -29
  17. package/dist/boxes/iso-base-media/process-box.js +56 -367
  18. package/dist/boxes/iso-base-media/stsd/mebx.d.ts +1 -4
  19. package/dist/boxes/iso-base-media/stsd/mebx.js +5 -15
  20. package/dist/boxes/iso-base-media/stsd/samples.d.ts +4 -12
  21. package/dist/boxes/iso-base-media/stsd/samples.js +24 -70
  22. package/dist/boxes/iso-base-media/stsd/stsd.d.ts +1 -4
  23. package/dist/boxes/iso-base-media/stsd/stsd.js +2 -5
  24. package/dist/boxes/iso-base-media/trak/trak.d.ts +1 -6
  25. package/dist/boxes/iso-base-media/trak/trak.js +5 -15
  26. package/dist/boxes/iso-base-media/traversal.d.ts +0 -2
  27. package/dist/boxes/iso-base-media/traversal.js +1 -12
  28. package/dist/boxes/mp3/get-duration.d.ts +2 -0
  29. package/dist/boxes/mp3/get-duration.js +30 -0
  30. package/dist/boxes/mp3/get-frame-length.d.ts +13 -0
  31. package/dist/boxes/mp3/get-frame-length.js +33 -0
  32. package/dist/boxes/mp3/get-metadata-from-mp3.d.ts +3 -0
  33. package/dist/boxes/mp3/get-metadata-from-mp3.js +8 -0
  34. package/dist/boxes/mp3/get-tracks-from-mp3.d.ts +4 -0
  35. package/dist/boxes/mp3/get-tracks-from-mp3.js +25 -0
  36. package/dist/boxes/mp3/id3-v1.d.ts +2 -0
  37. package/dist/boxes/mp3/id3-v1.js +12 -0
  38. package/dist/boxes/mp3/id3-v2.d.ts +0 -0
  39. package/dist/boxes/mp3/id3-v2.js +1 -0
  40. package/dist/boxes/mp3/id3.d.ts +6 -0
  41. package/dist/boxes/mp3/id3.js +80 -0
  42. package/dist/boxes/mp3/parse-mp3.d.ts +7 -0
  43. package/dist/boxes/mp3/parse-mp3.js +41 -0
  44. package/dist/boxes/mp3/parse-mpeg-header.d.ts +6 -0
  45. package/dist/boxes/mp3/parse-mpeg-header.js +274 -0
  46. package/dist/boxes/mp3/samples-per-mpeg-file.d.ts +4 -0
  47. package/dist/boxes/mp3/samples-per-mpeg-file.js +26 -0
  48. package/dist/boxes/riff/continue-after-riff-result.d.ts +13 -0
  49. package/dist/boxes/riff/continue-after-riff-result.js +34 -0
  50. package/dist/boxes/riff/expect-riff-box.d.ts +1 -7
  51. package/dist/boxes/riff/expect-riff-box.js +47 -24
  52. package/dist/boxes/riff/get-tracks-from-avi.d.ts +1 -1
  53. package/dist/boxes/riff/get-tracks-from-avi.js +6 -10
  54. package/dist/boxes/riff/parse-box.d.ts +1 -7
  55. package/dist/boxes/riff/parse-box.js +4 -120
  56. package/dist/boxes/riff/parse-fmt-box.d.ts +3 -2
  57. package/dist/boxes/riff/parse-fmt-box.js +7 -5
  58. package/dist/boxes/riff/parse-list-box.js +15 -14
  59. package/dist/boxes/riff/parse-movi.d.ts +2 -5
  60. package/dist/boxes/riff/parse-movi.js +34 -56
  61. package/dist/boxes/riff/parse-riff-body.d.ts +7 -0
  62. package/dist/boxes/riff/parse-riff-body.js +25 -0
  63. package/dist/boxes/riff/parse-riff-box.d.ts +1 -2
  64. package/dist/boxes/riff/parse-riff-box.js +2 -6
  65. package/dist/boxes/riff/parse-riff-header.d.ts +7 -0
  66. package/dist/boxes/riff/parse-riff-header.js +23 -0
  67. package/dist/boxes/riff/parse-riff.d.ts +7 -0
  68. package/dist/boxes/riff/parse-riff.js +15 -0
  69. package/dist/boxes/riff/parse-strf.d.ts +4 -4
  70. package/dist/boxes/riff/parse-strf.js +4 -8
  71. package/dist/boxes/riff/parse-strh.js +11 -0
  72. package/dist/boxes/riff/parse-video-section.d.ts +6 -0
  73. package/dist/boxes/riff/parse-video-section.js +20 -0
  74. package/dist/boxes/riff/riff-box.d.ts +4 -5
  75. package/dist/boxes/riff/traversal.d.ts +1 -2
  76. package/dist/boxes/riff/traversal.js +1 -6
  77. package/dist/boxes/transport-stream/get-tracks.d.ts +2 -3
  78. package/dist/boxes/transport-stream/get-tracks.js +4 -3
  79. package/dist/boxes/transport-stream/parse-packet.d.ts +1 -7
  80. package/dist/boxes/transport-stream/parse-packet.js +3 -4
  81. package/dist/boxes/transport-stream/parse-stream-packet.d.ts +1 -5
  82. package/dist/boxes/transport-stream/parse-stream-packet.js +10 -12
  83. package/dist/boxes/transport-stream/parse-transport-stream.d.ts +1 -7
  84. package/dist/boxes/transport-stream/parse-transport-stream.js +19 -49
  85. package/dist/boxes/transport-stream/process-stream-buffers.d.ts +1 -2
  86. package/dist/boxes/transport-stream/process-stream-buffers.js +3 -3
  87. package/dist/boxes/webm/parse-ebml.js +3 -0
  88. package/dist/boxes/webm/parse-webm-header.d.ts +2 -4
  89. package/dist/boxes/webm/parse-webm-header.js +41 -25
  90. package/dist/boxes/webm/segments/parse-children.d.ts +2 -16
  91. package/dist/boxes/webm/segments/parse-children.js +7 -130
  92. package/dist/boxes/webm/segments.d.ts +4 -8
  93. package/dist/boxes/webm/segments.js +41 -123
  94. package/dist/buffer-iterator.d.ts +6 -3
  95. package/dist/buffer-iterator.js +27 -16
  96. package/dist/bun-reader.d.ts +1 -0
  97. package/dist/bun-reader.js +17 -0
  98. package/dist/continue-mdat-routine.d.ts +17 -0
  99. package/dist/continue-mdat-routine.js +92 -0
  100. package/dist/emit-available-info.js +42 -28
  101. package/dist/esm/from-node.mjs +8 -9
  102. package/dist/esm/index.mjs +5133 -5085
  103. package/dist/file-types/detect-file-type.js +6 -2
  104. package/dist/get-audio-codec.d.ts +1 -1
  105. package/dist/get-audio-codec.js +3 -3
  106. package/dist/get-container.js +5 -1
  107. package/dist/get-dimensions.d.ts +1 -1
  108. package/dist/get-dimensions.js +4 -1
  109. package/dist/get-duration.js +6 -2
  110. package/dist/get-fields-from-callbacks.js +1 -0
  111. package/dist/get-fps.js +3 -0
  112. package/dist/get-is-hdr.d.ts +1 -1
  113. package/dist/get-is-hdr.js +3 -3
  114. package/dist/get-keyframes.js +1 -1
  115. package/dist/get-tracks.d.ts +2 -2
  116. package/dist/get-tracks.js +23 -15
  117. package/dist/get-video-codec.d.ts +1 -1
  118. package/dist/get-video-codec.js +3 -3
  119. package/dist/has-all-info.js +4 -3
  120. package/dist/index.d.ts +65 -21
  121. package/dist/index.js +1 -1
  122. package/dist/may-skip-video-data/may-skip-video-data.js +6 -2
  123. package/dist/may-skip-video-data/need-samples-for-fields.js +1 -0
  124. package/dist/metadata/get-metadata.d.ts +1 -0
  125. package/dist/metadata/get-metadata.js +16 -1
  126. package/dist/options.d.ts +12 -5
  127. package/dist/parse-media.js +88 -68
  128. package/dist/parse-result.d.ts +17 -19
  129. package/dist/parse-video.d.ts +3 -17
  130. package/dist/parse-video.js +52 -40
  131. package/dist/readers/from-node.js +7 -8
  132. package/dist/state/can-skip-tracks.d.ts +8 -1
  133. package/dist/state/can-skip-tracks.js +38 -26
  134. package/dist/state/emitted-fields.js +1 -0
  135. package/dist/state/images.d.ts +9 -0
  136. package/dist/state/images.js +14 -0
  137. package/dist/state/iso-base-media/cached-sample-positions.d.ts +15 -0
  138. package/dist/state/iso-base-media/cached-sample-positions.js +42 -0
  139. package/dist/state/iso-base-media/iso-state.d.ts +8 -0
  140. package/dist/state/iso-base-media/iso-state.js +15 -0
  141. package/dist/state/iso-state.d.ts +4 -0
  142. package/dist/state/iso-state.js +13 -0
  143. package/dist/state/mp3.d.ts +11 -0
  144. package/dist/state/mp3.js +13 -0
  145. package/dist/state/parser-state.d.ts +57 -11
  146. package/dist/state/parser-state.js +17 -2
  147. package/dist/state/sample-callbacks.d.ts +5 -1
  148. package/dist/state/sample-callbacks.js +8 -2
  149. package/dist/state/slow-duration-fps.d.ts +2 -1
  150. package/dist/state/slow-duration-fps.js +52 -18
  151. package/dist/state/transport-stream.d.ts +8 -0
  152. package/dist/state/transport-stream.js +11 -0
  153. package/dist/state/video-section.d.ts +16 -0
  154. package/dist/state/video-section.js +37 -0
  155. package/dist/state/webm.d.ts +15 -0
  156. package/dist/state/webm.js +32 -0
  157. package/dist/throttled-progress.d.ts +14 -0
  158. package/dist/throttled-progress.js +44 -0
  159. package/dist/version.d.ts +1 -1
  160. package/dist/version.js +1 -1
  161. package/package.json +3 -3
  162. package/test.json +663 -0
@@ -1,152 +1,70 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.expectSegment = void 0;
4
+ const log_1 = require("../../log");
4
5
  const parse_ebml_1 = require("./parse-ebml");
5
- const parse_children_1 = require("./segments/parse-children");
6
- const continueAfterMatroskaParseResult = async ({ result, iterator, state, segment, }) => {
7
- if (result.status === 'done') {
8
- throw new Error('Should not continue after done');
9
- }
10
- const proceeded = await result.continueParsing();
11
- if (proceeded.status === 'done') {
12
- return {
13
- status: 'done',
14
- segment,
15
- };
16
- }
17
- return {
18
- continueParsing() {
19
- return continueAfterMatroskaParseResult({
20
- result: proceeded,
21
- iterator,
22
- state,
23
- segment,
24
- });
25
- },
26
- segment: null,
27
- status: 'incomplete',
28
- };
29
- };
30
- const expectSegment = async ({ iterator, state, offset, children, fields, topLevelStructure, }) => {
31
- iterator.counter.decrement(iterator.counter.getOffset() - offset);
6
+ const all_segments_1 = require("./segments/all-segments");
7
+ const expectSegment = async ({ iterator, state, isInsideSegment, }) => {
8
+ var _a;
32
9
  if (iterator.bytesRemaining() === 0) {
33
- return {
34
- status: 'incomplete',
35
- continueParsing: () => {
36
- return (0, parse_children_1.expectAndProcessSegment)({
37
- iterator,
38
- state,
39
- offset,
40
- children,
41
- fields,
42
- topLevelStructure,
43
- });
44
- },
45
- segment: null,
46
- };
10
+ throw new Error('has no bytes');
47
11
  }
12
+ const offset = iterator.counter.getOffset();
13
+ const { returnToCheckpoint } = iterator.startCheckpoint();
48
14
  const segmentId = iterator.getMatroskaSegmentId();
49
15
  if (segmentId === null) {
50
- iterator.counter.decrement(iterator.counter.getOffset() - offset);
51
- return {
52
- status: 'incomplete',
53
- continueParsing: () => {
54
- return (0, parse_children_1.expectAndProcessSegment)({
55
- iterator,
56
- state,
57
- offset,
58
- children,
59
- fields,
60
- topLevelStructure,
61
- });
62
- },
63
- segment: null,
64
- };
16
+ returnToCheckpoint();
17
+ return null;
65
18
  }
66
19
  const offsetBeforeVInt = iterator.counter.getOffset();
67
- const length = iterator.getVint();
20
+ const size = iterator.getVint();
68
21
  const offsetAfterVInt = iterator.counter.getOffset();
69
- if (length === null) {
70
- iterator.counter.decrement(iterator.counter.getOffset() - offset);
71
- return {
72
- status: 'incomplete',
73
- continueParsing: () => {
74
- return (0, exports.expectSegment)({
75
- iterator,
76
- state,
77
- offset,
78
- children,
79
- fields,
80
- topLevelStructure,
81
- });
82
- },
83
- segment: null,
84
- };
22
+ if (size === null) {
23
+ returnToCheckpoint();
24
+ return null;
85
25
  }
86
- const bytesRemainingNow = iterator.byteLength() - iterator.counter.getOffset();
87
- if (segmentId === '0x18538067' || segmentId === '0x1f43b675') {
26
+ const bytesRemainingNow = iterator.bytesRemaining();
27
+ log_1.Log.trace(state.logLevel, 'Segment ID:', (_a = all_segments_1.ebmlMap[segmentId]) === null || _a === void 0 ? void 0 : _a.name, 'Size:' + size, bytesRemainingNow);
28
+ if (segmentId === all_segments_1.matroskaElements.Segment) {
29
+ state.webm.addSegment({
30
+ start: offset,
31
+ size,
32
+ });
88
33
  const newSegment = {
89
- type: segmentId === '0x18538067' ? 'Segment' : 'Cluster',
34
+ type: 'Segment',
90
35
  minVintWidth: offsetAfterVInt - offsetBeforeVInt,
91
36
  value: [],
92
37
  };
93
- const main = await (0, parse_children_1.expectChildren)({
94
- iterator,
95
- length,
96
- children: newSegment.value,
97
- state,
98
- startOffset: iterator.counter.getOffset(),
99
- fields,
100
- topLevelStructure,
101
- });
102
- if (main.status === 'incomplete') {
103
- return {
104
- status: 'incomplete',
105
- continueParsing: () => {
106
- return continueAfterMatroskaParseResult({
107
- iterator,
108
- state,
109
- result: main,
110
- segment: newSegment,
111
- });
112
- },
113
- segment: newSegment,
114
- };
38
+ return newSegment;
39
+ }
40
+ if (segmentId === all_segments_1.matroskaElements.Cluster) {
41
+ if (isInsideSegment === null) {
42
+ throw new Error('Expected to be inside segment');
115
43
  }
116
- return {
117
- status: 'done',
118
- segment: newSegment,
44
+ state.webm.addCluster({
45
+ start: offset,
46
+ size,
47
+ segment: isInsideSegment.index,
48
+ });
49
+ const newSegment = {
50
+ type: 'Cluster',
51
+ minVintWidth: offsetAfterVInt - offsetBeforeVInt,
52
+ value: [],
119
53
  };
54
+ return newSegment;
120
55
  }
121
- if (bytesRemainingNow < length) {
122
- const bytesRead = iterator.counter.getOffset() - offset;
123
- iterator.counter.decrement(bytesRead);
124
- return {
125
- status: 'incomplete',
126
- segment: null,
127
- continueParsing: () => {
128
- return (0, exports.expectSegment)({
129
- iterator,
130
- state,
131
- offset,
132
- children,
133
- fields,
134
- topLevelStructure,
135
- });
136
- },
137
- };
56
+ if (bytesRemainingNow < size) {
57
+ returnToCheckpoint();
58
+ return null;
138
59
  }
139
60
  const segment = await parseSegment({
140
61
  segmentId,
141
62
  iterator,
142
- length,
63
+ length: size,
143
64
  state,
144
65
  headerReadSoFar: iterator.counter.getOffset() - offset,
145
66
  });
146
- return {
147
- status: 'done',
148
- segment,
149
- };
67
+ return segment;
150
68
  };
151
69
  exports.expectSegment = expectSegment;
152
70
  const parseSegment = async ({ segmentId, iterator, length, state, headerReadSoFar, }) => {
@@ -18,7 +18,6 @@ export declare const getArrayBufferIterator: (initialData: Uint8Array, maxBytes:
18
18
  peekB: (length: number) => void;
19
19
  peekD: (length: number) => void;
20
20
  getBits: (bits: number) => number;
21
- byteLength: () => number;
22
21
  bytesRemaining: () => number;
23
22
  leb128: () => number;
24
23
  removeBytesRead: () => void;
@@ -48,6 +47,9 @@ export declare const getArrayBufferIterator: (initialData: Uint8Array, maxBytes:
48
47
  getPascalString: () => number[];
49
48
  getUint(length: number): number;
50
49
  getByteString(length: number, trimTrailingZeroes: boolean): string;
50
+ planBytes: (size: number) => {
51
+ discardRest: () => Uint8Array;
52
+ };
51
53
  getFloat64: () => number;
52
54
  readUntilNullTerminator: () => string;
53
55
  getFloat32: () => number;
@@ -55,12 +57,13 @@ export declare const getArrayBufferIterator: (initialData: Uint8Array, maxBytes:
55
57
  getInt32Le: () => number;
56
58
  getInt32: () => number;
57
59
  destroy: () => void;
58
- disallowDiscard: () => void;
59
- allowDiscard: () => void;
60
60
  startBox: (size: number) => {
61
61
  discardRest: () => void;
62
62
  expectNoMoreBytes: () => void;
63
63
  };
64
64
  readExpGolomb: () => number;
65
+ startCheckpoint: () => {
66
+ returnToCheckpoint: () => void;
67
+ };
65
68
  };
66
69
  export type BufferIterator = ReturnType<typeof getArrayBufferIterator>;
@@ -69,18 +69,19 @@ const getArrayBufferIterator = (initialData, maxBytes) => {
69
69
  data.set(initialData);
70
70
  let view = new DataView(data.buffer);
71
71
  const counter = makeOffsetCounter();
72
- let discardAllowed = true;
72
+ const startCheckpoint = () => {
73
+ const checkpoint = counter.getOffset();
74
+ return {
75
+ returnToCheckpoint: () => {
76
+ counter.decrement(counter.getOffset() - checkpoint);
77
+ },
78
+ };
79
+ };
73
80
  const getSlice = (amount) => {
74
81
  const value = data.slice(counter.getDiscardedOffset(), counter.getDiscardedOffset() + amount);
75
82
  counter.increment(amount);
76
83
  return value;
77
84
  };
78
- const disallowDiscard = () => {
79
- discardAllowed = false;
80
- };
81
- const allowDiscard = () => {
82
- discardAllowed = true;
83
- };
84
85
  const discard = (length) => {
85
86
  counter.increment(length);
86
87
  };
@@ -191,22 +192,22 @@ const getArrayBufferIterator = (initialData, maxBytes) => {
191
192
  const addData = (newData) => {
192
193
  const oldLength = buf.byteLength;
193
194
  const newLength = oldLength + newData.byteLength;
195
+ if (newLength < oldLength) {
196
+ throw new Error('Cannot decrement size');
197
+ }
198
+ if (newLength > (maxBytes !== null && maxBytes !== void 0 ? maxBytes : Infinity)) {
199
+ throw new Error(`Exceeded maximum byte length ${maxBytes} with ${newLength}`);
200
+ }
194
201
  buf.resize(newLength);
195
202
  const newArray = new Uint8Array(buf);
196
203
  newArray.set(newData, oldLength);
197
204
  data = newArray;
198
205
  view = new DataView(data.buffer);
199
206
  };
200
- const byteLength = () => {
201
- return data.byteLength;
202
- };
203
207
  const bytesRemaining = () => {
204
208
  return data.byteLength - counter.getDiscardedOffset();
205
209
  };
206
210
  const removeBytesRead = () => {
207
- if (!discardAllowed) {
208
- return;
209
- }
210
211
  const bytesToRemove = counter.getDiscardedOffset();
211
212
  // Only do this operation if it is really worth it 😇
212
213
  if (bytesToRemove < 100000) {
@@ -323,7 +324,6 @@ const getArrayBufferIterator = (initialData, maxBytes) => {
323
324
  peekB,
324
325
  peekD,
325
326
  getBits,
326
- byteLength,
327
327
  bytesRemaining,
328
328
  leb128,
329
329
  removeBytesRead,
@@ -501,6 +501,18 @@ const getArrayBufferIterator = (initialData, maxBytes) => {
501
501
  }
502
502
  return new TextDecoder().decode(bytes).trim();
503
503
  },
504
+ planBytes: (size) => {
505
+ const currentOffset = counter.getOffset();
506
+ return {
507
+ discardRest: () => {
508
+ const toDiscard = size - (counter.getOffset() - currentOffset);
509
+ if (toDiscard < 0) {
510
+ throw new Error('read too many bytes');
511
+ }
512
+ return getSlice(toDiscard);
513
+ },
514
+ };
515
+ },
504
516
  getFloat64: () => {
505
517
  const val = view.getFloat64(counter.getDiscardedOffset());
506
518
  counter.increment(8);
@@ -516,10 +528,9 @@ const getArrayBufferIterator = (initialData, maxBytes) => {
516
528
  getInt32Le,
517
529
  getInt32,
518
530
  destroy,
519
- disallowDiscard,
520
- allowDiscard,
521
531
  startBox,
522
532
  readExpGolomb,
533
+ startCheckpoint,
523
534
  };
524
535
  };
525
536
  exports.getArrayBufferIterator = getArrayBufferIterator;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const example_videos_1 = require("@remotion/example-videos");
4
+ const fs_1 = require("fs");
5
+ const stream_1 = require("stream");
6
+ const range = null;
7
+ const stream = (0, fs_1.createReadStream)(example_videos_1.exampleVideos.framer24fps, {
8
+ start: range === null ? 0 : typeof range === 'number' ? range : range[0],
9
+ end: range === null ? Infinity : typeof range === 'number' ? Infinity : range[1],
10
+ });
11
+ const reader = stream_1.Readable.toWeb(stream).getReader();
12
+ console.log(await reader.read());
13
+ console.log(await reader.read());
14
+ console.log(await reader.read());
15
+ console.log(await reader.read());
16
+ console.log(await reader.read());
17
+ console.log(await reader.read());
@@ -0,0 +1,17 @@
1
+ import type { BufferIterator } from './buffer-iterator';
2
+ import type { LogLevel } from './log';
3
+ import type { Options, ParseMediaFields } from './options';
4
+ import type { IsoBaseMediaBox, ParseResult } from './parse-result';
5
+ import type { PartialMdatBox } from './parse-video';
6
+ import type { ParserState } from './state/parser-state';
7
+ export declare const continueMdatRoutine: ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, state, continueMdat, signal, logLevel, fields, }: {
8
+ iterator: BufferIterator;
9
+ maxBytes: number;
10
+ allowIncompleteBoxes: boolean;
11
+ initialBoxes: IsoBaseMediaBox[];
12
+ state: ParserState;
13
+ continueMdat: PartialMdatBox;
14
+ signal: AbortSignal | null;
15
+ logLevel: LogLevel;
16
+ fields: Options<ParseMediaFields>;
17
+ }) => Promise<ParseResult>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.continueMdatRoutine = void 0;
4
+ const parse_boxes_1 = require("./boxes/iso-base-media/parse-boxes");
5
+ const parse_mdat_partially_1 = require("./boxes/iso-base-media/parse-mdat-partially");
6
+ const traversal_1 = require("./boxes/iso-base-media/traversal");
7
+ const has_all_info_1 = require("./has-all-info");
8
+ const may_skip_video_data_1 = require("./may-skip-video-data/may-skip-video-data");
9
+ const continueMdatRoutine = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, state, continueMdat, signal, logLevel, fields, }) => {
10
+ var _a;
11
+ const initialOffset = iterator.counter.getOffset();
12
+ while (iterator.bytesRemaining() > 0 &&
13
+ iterator.counter.getOffset() - initialOffset < maxBytes) {
14
+ const result = await (0, parse_mdat_partially_1.parseMdatPartially)({
15
+ iterator,
16
+ boxSize: continueMdat.boxSize,
17
+ fileOffset: continueMdat.fileOffset,
18
+ parsedBoxes: initialBoxes,
19
+ state,
20
+ signal,
21
+ });
22
+ if (result.type === 'incomplete') {
23
+ throw new Error('Incomplete boxes are not allowed in this routine');
24
+ }
25
+ if (result.type === 'partial-mdat-box') {
26
+ return {
27
+ status: 'incomplete',
28
+ continueParsing: () => {
29
+ return Promise.resolve((0, exports.continueMdatRoutine)({
30
+ iterator,
31
+ maxBytes,
32
+ allowIncompleteBoxes,
33
+ initialBoxes,
34
+ state,
35
+ continueMdat: result,
36
+ signal,
37
+ logLevel,
38
+ fields,
39
+ }));
40
+ },
41
+ skipTo: null,
42
+ };
43
+ }
44
+ const alreadyHasMdat = (_a = state.structure
45
+ .getStructureOrNull()) === null || _a === void 0 ? void 0 : _a.boxes.find((b) => b.type === 'mdat-box');
46
+ if (result.box.type === 'mdat-box' && alreadyHasMdat) {
47
+ initialBoxes = initialBoxes.filter((b) => b.type !== 'mdat-box');
48
+ initialBoxes.push(result.box);
49
+ iterator.allowDiscard();
50
+ break;
51
+ }
52
+ else {
53
+ initialBoxes.push(result.box);
54
+ if ((0, has_all_info_1.hasAllInfo)({ fields, state })) {
55
+ return {
56
+ status: 'done',
57
+ };
58
+ }
59
+ }
60
+ iterator.removeBytesRead();
61
+ }
62
+ const mdatState = (0, traversal_1.getMdatBox)(initialBoxes);
63
+ const skipped = (mdatState === null || mdatState === void 0 ? void 0 : mdatState.status) === 'samples-skipped' &&
64
+ !(0, may_skip_video_data_1.maySkipVideoData)({ state }) &&
65
+ state.supportsContentRange;
66
+ const buffered = (mdatState === null || mdatState === void 0 ? void 0 : mdatState.status) === 'samples-buffered' && !(0, may_skip_video_data_1.maySkipVideoData)({ state });
67
+ if (skipped || buffered) {
68
+ return {
69
+ status: 'incomplete',
70
+ continueParsing: () => {
71
+ if (buffered) {
72
+ iterator.skipTo(mdatState.fileOffset, false);
73
+ }
74
+ return (0, parse_boxes_1.parseIsoBaseMediaBoxes)({
75
+ iterator,
76
+ maxBytes,
77
+ allowIncompleteBoxes: false,
78
+ initialBoxes,
79
+ state,
80
+ signal,
81
+ logLevel,
82
+ fields,
83
+ });
84
+ },
85
+ skipTo: skipped ? mdatState.fileOffset : null,
86
+ };
87
+ }
88
+ return {
89
+ status: 'done',
90
+ };
91
+ };
92
+ exports.continueMdatRoutine = continueMdatRoutine;
@@ -13,7 +13,7 @@ const get_tracks_1 = require("./get-tracks");
13
13
  const get_video_codec_1 = require("./get-video-codec");
14
14
  const get_metadata_1 = require("./metadata/get-metadata");
15
15
  const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue, contentLength, name, mimeType, fieldsInReturnValue, }) => {
16
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
16
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
17
17
  const keys = Object.keys(hasInfo);
18
18
  const segments = state.structure.getStructureOrNull();
19
19
  const { emittedFields } = state;
@@ -102,10 +102,12 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
102
102
  parseResult &&
103
103
  segments) {
104
104
  const dimensionsQueried = (0, get_dimensions_1.getDimensions)(segments, state);
105
- const dimensions = {
106
- height: dimensionsQueried.height,
107
- width: dimensionsQueried.width,
108
- };
105
+ const dimensions = dimensionsQueried === null
106
+ ? null
107
+ : {
108
+ height: dimensionsQueried.height,
109
+ width: dimensionsQueried.width,
110
+ };
109
111
  (_h = callbacks.onDimensions) === null || _h === void 0 ? void 0 : _h.call(callbacks, dimensions);
110
112
  if (fieldsInReturnValue.dimensions) {
111
113
  returnValue.dimensions = dimensions;
@@ -120,10 +122,12 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
120
122
  parseResult &&
121
123
  segments) {
122
124
  const dimensionsQueried = (0, get_dimensions_1.getDimensions)(segments, state);
123
- const unrotatedDimensions = {
124
- height: dimensionsQueried.unrotatedHeight,
125
- width: dimensionsQueried.unrotatedWidth,
126
- };
125
+ const unrotatedDimensions = dimensionsQueried === null
126
+ ? null
127
+ : {
128
+ height: dimensionsQueried.unrotatedHeight,
129
+ width: dimensionsQueried.unrotatedWidth,
130
+ };
127
131
  (_j = callbacks.onUnrotatedDimensions) === null || _j === void 0 ? void 0 : _j.call(callbacks, unrotatedDimensions);
128
132
  if (fieldsInReturnValue.unrotatedDimensions) {
129
133
  returnValue.unrotatedDimensions = unrotatedDimensions;
@@ -138,8 +142,8 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
138
142
  parseResult &&
139
143
  segments) {
140
144
  const dimensionsQueried = (0, get_dimensions_1.getDimensions)(segments, state);
141
- const { rotation } = dimensionsQueried;
142
- (_k = callbacks.onRotation) === null || _k === void 0 ? void 0 : _k.call(callbacks, rotation);
145
+ const rotation = (_k = dimensionsQueried === null || dimensionsQueried === void 0 ? void 0 : dimensionsQueried.rotation) !== null && _k !== void 0 ? _k : 0;
146
+ (_l = callbacks.onRotation) === null || _l === void 0 ? void 0 : _l.call(callbacks, rotation);
143
147
  if (fieldsInReturnValue.rotation) {
144
148
  returnValue.rotation = rotation;
145
149
  }
@@ -152,8 +156,8 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
152
156
  hasInfo.videoCodec &&
153
157
  parseResult &&
154
158
  segments) {
155
- const videoCodec = (0, get_video_codec_1.getVideoCodec)(segments, state);
156
- (_l = callbacks.onVideoCodec) === null || _l === void 0 ? void 0 : _l.call(callbacks, videoCodec);
159
+ const videoCodec = (0, get_video_codec_1.getVideoCodec)(state);
160
+ (_m = callbacks.onVideoCodec) === null || _m === void 0 ? void 0 : _m.call(callbacks, videoCodec);
157
161
  if (fieldsInReturnValue.videoCodec) {
158
162
  returnValue.videoCodec = videoCodec;
159
163
  }
@@ -166,8 +170,8 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
166
170
  hasInfo.audioCodec &&
167
171
  parseResult &&
168
172
  segments) {
169
- const audioCodec = (0, get_audio_codec_1.getAudioCodec)(segments, state);
170
- (_m = callbacks.onAudioCodec) === null || _m === void 0 ? void 0 : _m.call(callbacks, audioCodec);
173
+ const audioCodec = (0, get_audio_codec_1.getAudioCodec)(state);
174
+ (_o = callbacks.onAudioCodec) === null || _o === void 0 ? void 0 : _o.call(callbacks, audioCodec);
171
175
  if (fieldsInReturnValue.audioCodec) {
172
176
  returnValue.audioCodec = audioCodec;
173
177
  }
@@ -177,8 +181,8 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
177
181
  }
178
182
  if (key === 'tracks') {
179
183
  if (!emittedFields.tracks && hasInfo.tracks && parseResult && segments) {
180
- const { videoTracks, audioTracks } = (0, get_tracks_1.getTracks)(segments, state);
181
- (_o = callbacks.onTracks) === null || _o === void 0 ? void 0 : _o.call(callbacks, { videoTracks, audioTracks });
184
+ const { videoTracks, audioTracks } = (0, get_tracks_1.getTracks)(state);
185
+ (_p = callbacks.onTracks) === null || _p === void 0 ? void 0 : _p.call(callbacks, { videoTracks, audioTracks });
182
186
  if (fieldsInReturnValue.tracks) {
183
187
  returnValue.tracks = { videoTracks, audioTracks };
184
188
  }
@@ -199,7 +203,7 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
199
203
  }
200
204
  if (key === 'size') {
201
205
  if (!emittedFields.size && hasInfo.size) {
202
- (_p = callbacks.onSize) === null || _p === void 0 ? void 0 : _p.call(callbacks, contentLength);
206
+ (_q = callbacks.onSize) === null || _q === void 0 ? void 0 : _q.call(callbacks, contentLength);
203
207
  if (fieldsInReturnValue.size) {
204
208
  returnValue.size = contentLength;
205
209
  }
@@ -209,7 +213,7 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
209
213
  }
210
214
  if (key === 'mimeType') {
211
215
  if (!emittedFields.mimeType && hasInfo.mimeType) {
212
- (_q = callbacks.onMimeType) === null || _q === void 0 ? void 0 : _q.call(callbacks, mimeType);
216
+ (_r = callbacks.onMimeType) === null || _r === void 0 ? void 0 : _r.call(callbacks, mimeType);
213
217
  if (fieldsInReturnValue.mimeType) {
214
218
  returnValue.mimeType = mimeType;
215
219
  }
@@ -219,7 +223,7 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
219
223
  }
220
224
  if (key === 'name') {
221
225
  if (!emittedFields.name && hasInfo.name) {
222
- (_r = callbacks.onName) === null || _r === void 0 ? void 0 : _r.call(callbacks, name);
226
+ (_s = callbacks.onName) === null || _s === void 0 ? void 0 : _s.call(callbacks, name);
223
227
  if (fieldsInReturnValue.name) {
224
228
  returnValue.name = name;
225
229
  }
@@ -229,8 +233,8 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
229
233
  }
230
234
  if (key === 'isHdr') {
231
235
  if (!returnValue.isHdr && hasInfo.isHdr && parseResult && segments) {
232
- const isHdr = (0, get_is_hdr_1.getIsHdr)(segments, state);
233
- (_s = callbacks.onIsHdr) === null || _s === void 0 ? void 0 : _s.call(callbacks, isHdr);
236
+ const isHdr = (0, get_is_hdr_1.getIsHdr)(state);
237
+ (_t = callbacks.onIsHdr) === null || _t === void 0 ? void 0 : _t.call(callbacks, isHdr);
234
238
  if (fieldsInReturnValue.isHdr) {
235
239
  returnValue.isHdr = isHdr;
236
240
  }
@@ -244,7 +248,7 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
244
248
  parseResult &&
245
249
  segments) {
246
250
  const container = (0, get_container_1.getContainer)(segments);
247
- (_t = callbacks.onContainer) === null || _t === void 0 ? void 0 : _t.call(callbacks, container);
251
+ (_u = callbacks.onContainer) === null || _u === void 0 ? void 0 : _u.call(callbacks, container);
248
252
  if (fieldsInReturnValue.container) {
249
253
  returnValue.container = container;
250
254
  }
@@ -258,7 +262,7 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
258
262
  parseResult &&
259
263
  segments) {
260
264
  const metadata = (0, get_metadata_1.getMetadata)(segments);
261
- (_u = callbacks.onMetadata) === null || _u === void 0 ? void 0 : _u.call(callbacks, metadata);
265
+ (_v = callbacks.onMetadata) === null || _v === void 0 ? void 0 : _v.call(callbacks, metadata);
262
266
  if (fieldsInReturnValue.metadata) {
263
267
  returnValue.metadata = metadata;
264
268
  }
@@ -272,7 +276,7 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
272
276
  parseResult &&
273
277
  segments) {
274
278
  const location = (0, get_location_1.getLocation)(segments);
275
- (_v = callbacks.onLocation) === null || _v === void 0 ? void 0 : _v.call(callbacks, location);
279
+ (_w = callbacks.onLocation) === null || _w === void 0 ? void 0 : _w.call(callbacks, location);
276
280
  if (fieldsInReturnValue.location) {
277
281
  returnValue.location = location;
278
282
  }
@@ -284,7 +288,7 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
284
288
  if (!emittedFields.slowKeyframes &&
285
289
  hasInfo.slowKeyframes &&
286
290
  parseResult) {
287
- (_w = callbacks.onSlowKeyframes) === null || _w === void 0 ? void 0 : _w.call(callbacks, state.keyframes.getKeyframes());
291
+ (_x = callbacks.onSlowKeyframes) === null || _x === void 0 ? void 0 : _x.call(callbacks, state.keyframes.getKeyframes());
288
292
  if (fieldsInReturnValue.slowKeyframes) {
289
293
  returnValue.slowKeyframes = state.keyframes.getKeyframes();
290
294
  }
@@ -296,7 +300,7 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
296
300
  if (!emittedFields.slowNumberOfFrames &&
297
301
  hasInfo.slowNumberOfFrames &&
298
302
  parseResult) {
299
- (_x = callbacks.onSlowNumberOfFrames) === null || _x === void 0 ? void 0 : _x.call(callbacks, state.slowDurationAndFps.getSlowNumberOfFrames());
303
+ (_y = callbacks.onSlowNumberOfFrames) === null || _y === void 0 ? void 0 : _y.call(callbacks, state.slowDurationAndFps.getSlowNumberOfFrames());
300
304
  if (fieldsInReturnValue.slowNumberOfFrames) {
301
305
  returnValue.slowNumberOfFrames =
302
306
  state.slowDurationAndFps.getSlowNumberOfFrames();
@@ -307,7 +311,7 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
307
311
  }
308
312
  if (key === 'keyframes') {
309
313
  if (!emittedFields.keyframes && hasInfo.keyframes && parseResult) {
310
- (_y = callbacks.onKeyframes) === null || _y === void 0 ? void 0 : _y.call(callbacks, (0, get_keyframes_1.getKeyframes)(state.structure.getStructure()));
314
+ (_z = callbacks.onKeyframes) === null || _z === void 0 ? void 0 : _z.call(callbacks, (0, get_keyframes_1.getKeyframes)(state.structure.getStructure()));
311
315
  if (fieldsInReturnValue.keyframes) {
312
316
  returnValue.keyframes = (0, get_keyframes_1.getKeyframes)(state.structure.getStructure());
313
317
  }
@@ -315,6 +319,16 @@ const emitAvailableInfo = ({ hasInfo, parseResult, callbacks, state, returnValue
315
319
  }
316
320
  continue;
317
321
  }
322
+ if (key === 'images') {
323
+ if (!emittedFields.images && hasInfo.images && parseResult) {
324
+ (_0 = callbacks.onImages) === null || _0 === void 0 ? void 0 : _0.call(callbacks, state.images.images);
325
+ if (fieldsInReturnValue.images) {
326
+ returnValue.images = state.images.images;
327
+ }
328
+ emittedFields.images = true;
329
+ }
330
+ continue;
331
+ }
318
332
  throw new Error(`Unhandled key: ${key}`);
319
333
  }
320
334
  };