@remotion/media-parser 4.0.241 → 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 (106) hide show
  1. package/dist/add-avc-profile-to-track.js +2 -2
  2. package/dist/boxes/avc/codec-private.js +2 -2
  3. package/dist/boxes/avc/create-sps-pps-data.d.ts +2 -0
  4. package/dist/boxes/avc/create-sps-pps-data.js +28 -0
  5. package/dist/boxes/iso-base-media/get-keyframes.d.ts +3 -0
  6. package/dist/boxes/iso-base-media/get-keyframes.js +30 -0
  7. package/dist/boxes/iso-base-media/mdat/mdat.d.ts +3 -3
  8. package/dist/boxes/iso-base-media/mdat/mdat.js +9 -5
  9. package/dist/boxes/iso-base-media/moov/moov.d.ts +3 -3
  10. package/dist/boxes/iso-base-media/moov/moov.js +5 -4
  11. package/dist/boxes/iso-base-media/process-box.d.ts +9 -9
  12. package/dist/boxes/iso-base-media/process-box.js +48 -56
  13. package/dist/boxes/iso-base-media/stsd/mebx.d.ts +3 -3
  14. package/dist/boxes/iso-base-media/stsd/mebx.js +5 -4
  15. package/dist/boxes/iso-base-media/stsd/samples.d.ts +5 -5
  16. package/dist/boxes/iso-base-media/stsd/samples.js +19 -16
  17. package/dist/boxes/iso-base-media/stsd/stsd.d.ts +3 -3
  18. package/dist/boxes/iso-base-media/stsd/stsd.js +2 -2
  19. package/dist/boxes/iso-base-media/trak/trak.d.ts +3 -3
  20. package/dist/boxes/iso-base-media/trak/trak.js +7 -6
  21. package/dist/boxes/riff/expect-riff-box.d.ts +3 -3
  22. package/dist/boxes/riff/expect-riff-box.js +5 -5
  23. package/dist/boxes/riff/get-tracks-from-avi.js +1 -1
  24. package/dist/boxes/riff/parse-box.d.ts +7 -7
  25. package/dist/boxes/riff/parse-box.js +29 -24
  26. package/dist/boxes/riff/parse-list-box.d.ts +3 -3
  27. package/dist/boxes/riff/parse-list-box.js +2 -2
  28. package/dist/boxes/riff/parse-movi.d.ts +5 -5
  29. package/dist/boxes/riff/parse-movi.js +35 -20
  30. package/dist/boxes/riff/parse-riff-box.d.ts +3 -3
  31. package/dist/boxes/riff/parse-riff-box.js +2 -2
  32. package/dist/boxes/transport-stream/get-tracks.js +1 -1
  33. package/dist/boxes/transport-stream/handle-aac-packet.d.ts +4 -3
  34. package/dist/boxes/transport-stream/handle-aac-packet.js +6 -4
  35. package/dist/boxes/transport-stream/handle-avc-packet.d.ts +4 -3
  36. package/dist/boxes/transport-stream/handle-avc-packet.js +8 -6
  37. package/dist/boxes/transport-stream/parse-packet.d.ts +3 -3
  38. package/dist/boxes/transport-stream/parse-packet.js +2 -2
  39. package/dist/boxes/transport-stream/parse-stream-packet.d.ts +3 -3
  40. package/dist/boxes/transport-stream/parse-stream-packet.js +14 -7
  41. package/dist/boxes/transport-stream/parse-transport-stream.d.ts +5 -6
  42. package/dist/boxes/transport-stream/parse-transport-stream.js +10 -9
  43. package/dist/boxes/transport-stream/process-stream-buffers.d.ts +6 -5
  44. package/dist/boxes/transport-stream/process-stream-buffers.js +18 -8
  45. package/dist/boxes/webm/ebml.d.ts +1 -1
  46. package/dist/boxes/webm/get-sample-from-block.d.ts +2 -2
  47. package/dist/boxes/webm/get-sample-from-block.js +8 -4
  48. package/dist/boxes/webm/parse-ebml.d.ts +4 -4
  49. package/dist/boxes/webm/parse-ebml.js +18 -18
  50. package/dist/boxes/webm/parse-webm-header.d.ts +5 -5
  51. package/dist/boxes/webm/parse-webm-header.js +6 -5
  52. package/dist/boxes/webm/segments/parse-children.d.ts +5 -5
  53. package/dist/boxes/webm/segments/parse-children.js +12 -13
  54. package/dist/boxes/webm/segments.d.ts +3 -3
  55. package/dist/boxes/webm/segments.js +13 -13
  56. package/dist/convert-audio-or-video-sample.js +2 -0
  57. package/dist/emit-available-info.d.ts +4 -5
  58. package/dist/emit-available-info.js +171 -57
  59. package/dist/esm/index.mjs +881 -490
  60. package/dist/get-duration.d.ts +1 -0
  61. package/dist/get-duration.js +14 -1
  62. package/dist/get-fields-from-callbacks.js +5 -0
  63. package/dist/get-fps.d.ts +1 -0
  64. package/dist/get-fps.js +17 -12
  65. package/dist/get-keyframes.d.ts +5 -0
  66. package/dist/get-keyframes.js +20 -0
  67. package/dist/get-tracks.d.ts +7 -1
  68. package/dist/get-tracks.js +15 -10
  69. package/dist/has-all-info.d.ts +2 -5
  70. package/dist/has-all-info.js +23 -4
  71. package/dist/index.d.ts +2 -1
  72. package/dist/may-skip-video-data/may-skip-video-data.d.ts +4 -0
  73. package/dist/may-skip-video-data/may-skip-video-data.js +14 -0
  74. package/dist/may-skip-video-data/need-samples-for-fields.d.ts +5 -0
  75. package/dist/may-skip-video-data/need-samples-for-fields.js +33 -0
  76. package/dist/options.d.ts +32 -0
  77. package/dist/parse-media.js +12 -40
  78. package/dist/parse-result.d.ts +2 -4
  79. package/dist/parse-video.d.ts +5 -5
  80. package/dist/parse-video.js +24 -10
  81. package/dist/register-track.d.ts +5 -5
  82. package/dist/register-track.js +12 -12
  83. package/dist/state/can-skip-tracks.js +5 -0
  84. package/dist/state/emitted-fields.d.ts +2 -0
  85. package/dist/state/emitted-fields.js +31 -0
  86. package/dist/state/has-tracks-section.d.ts +1 -0
  87. package/dist/state/keyframes.d.ts +6 -0
  88. package/dist/state/keyframes.js +15 -0
  89. package/dist/state/parser-state.d.ts +60 -29
  90. package/dist/state/parser-state.js +32 -150
  91. package/dist/state/riff.d.ts +10 -0
  92. package/dist/state/riff.js +32 -0
  93. package/dist/state/sample-callbacks.d.ts +31 -0
  94. package/dist/state/sample-callbacks.js +96 -0
  95. package/dist/state/slow-duration-fps.d.ts +8 -0
  96. package/dist/state/slow-duration-fps.js +36 -0
  97. package/dist/state/structure.d.ts +7 -0
  98. package/dist/state/structure.js +21 -0
  99. package/dist/state/tracks-and-samples.d.ts +0 -0
  100. package/dist/state/tracks-and-samples.js +1 -0
  101. package/dist/state/webm.d.ts +11 -0
  102. package/dist/state/webm.js +67 -0
  103. package/dist/version.d.ts +1 -1
  104. package/dist/version.js +1 -1
  105. package/dist/webcodec-sample-types.d.ts +2 -0
  106. package/package.json +3 -3
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addAvcProfileToTrack = void 0;
4
- const codec_private_1 = require("./boxes/avc/codec-private");
5
4
  const codec_string_1 = require("./boxes/avc/codec-string");
5
+ const create_sps_pps_data_1 = require("./boxes/avc/create-sps-pps-data");
6
6
  const addAvcProfileToTrack = (track, avc1Profile) => {
7
7
  if (avc1Profile === null) {
8
8
  return track;
@@ -10,7 +10,7 @@ const addAvcProfileToTrack = (track, avc1Profile) => {
10
10
  return {
11
11
  ...track,
12
12
  codec: (0, codec_string_1.getCodecStringFromSpsAndPps)(avc1Profile.sps),
13
- codecPrivate: (0, codec_private_1.getAvccBoxContent)(avc1Profile),
13
+ codecPrivate: (0, create_sps_pps_data_1.createSpsPpsData)(avc1Profile),
14
14
  };
15
15
  };
16
16
  exports.addAvcProfileToTrack = addAvcProfileToTrack;
@@ -7,9 +7,9 @@ const getAvccBoxContent = (avc1Profile) => {
7
7
  new Uint8Array([
8
8
  // https://gist.github.com/uupaa/8493378ec15f644a3d2b
9
9
  1, // version
10
- avc1Profile.sps.spsData.level,
11
- avc1Profile.sps.spsData.compatibility,
12
10
  avc1Profile.sps.spsData.profile,
11
+ avc1Profile.sps.spsData.compatibility,
12
+ avc1Profile.sps.spsData.level,
13
13
  0xff,
14
14
  0xe1,
15
15
  ]),
@@ -0,0 +1,2 @@
1
+ import type { SpsAndPps } from '../../state/parser-state';
2
+ export declare const createSpsPpsData: (avc1Profile: SpsAndPps) => Uint8Array;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSpsPpsData = void 0;
4
+ const make_header_1 = require("../webm/make-header");
5
+ const createSpsPpsData = (avc1Profile) => {
6
+ return (0, make_header_1.combineUint8Arrays)([
7
+ new Uint8Array([
8
+ // https://gist.github.com/uupaa/8493378ec15f644a3d2b
9
+ 1, // version
10
+ avc1Profile.sps.spsData.profile,
11
+ avc1Profile.sps.spsData.compatibility,
12
+ avc1Profile.sps.spsData.level,
13
+ 0xff,
14
+ 0xe1,
15
+ ]),
16
+ // sequence parameter set length
17
+ (0, make_header_1.serializeUint16)(avc1Profile.sps.sps.length),
18
+ // sequence parameter set
19
+ avc1Profile.sps.sps,
20
+ // num of PPS
21
+ new Uint8Array([0x01]),
22
+ // picture parameter set length
23
+ (0, make_header_1.serializeUint16)(avc1Profile.pps.pps.length),
24
+ // PPS
25
+ avc1Profile.pps.pps,
26
+ ]);
27
+ };
28
+ exports.createSpsPpsData = createSpsPpsData;
@@ -0,0 +1,3 @@
1
+ import type { MediaParserKeyframe } from '../../options';
2
+ import type { IsoBaseMediaStructure } from '../../parse-result';
3
+ export declare const getKeyframesFromIsoBaseMedia: (structure: IsoBaseMediaStructure) => MediaParserKeyframe[];
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getKeyframesFromIsoBaseMedia = void 0;
4
+ const get_tracks_1 = require("../../get-tracks");
5
+ const get_sample_positions_from_track_1 = require("./get-sample-positions-from-track");
6
+ const traversal_1 = require("./traversal");
7
+ const getKeyframesFromIsoBaseMedia = (structure) => {
8
+ const { videoTracks } = (0, get_tracks_1.getTracksFromIsoBaseMedia)(structure.boxes);
9
+ const moofBox = (0, traversal_1.getMoofBox)(structure.boxes);
10
+ const allSamples = videoTracks.map((t) => {
11
+ const { timescale: ts } = t;
12
+ const samplePositions = (0, get_sample_positions_from_track_1.getSamplePositionsFromTrack)(t.trakBox, moofBox);
13
+ const keyframes = samplePositions
14
+ .filter((k) => {
15
+ return k.isKeyframe;
16
+ })
17
+ .map((k) => {
18
+ return {
19
+ trackId: t.trackId,
20
+ presentationTimeInSeconds: k.cts / ts,
21
+ decodingTimeInSeconds: k.dts / ts,
22
+ positionInBytes: k.offset,
23
+ sizeInBytes: k.size,
24
+ };
25
+ });
26
+ return keyframes;
27
+ });
28
+ return allSamples.flat();
29
+ };
30
+ exports.getKeyframesFromIsoBaseMedia = getKeyframesFromIsoBaseMedia;
@@ -1,6 +1,6 @@
1
1
  import type { BufferIterator } from '../../../buffer-iterator';
2
2
  import type { IsoBaseMediaBox } from '../../../parse-result';
3
- import type { ParserContext } from '../../../parser-context';
3
+ import type { ParserState } from '../../../state/parser-state';
4
4
  type MdatStatus = {
5
5
  status: 'samples-buffered';
6
6
  } | {
@@ -13,12 +13,12 @@ export type MdatBox = {
13
13
  boxSize: number;
14
14
  fileOffset: number;
15
15
  } & MdatStatus;
16
- export declare const parseMdat: ({ data, size, fileOffset, existingBoxes, options, signal, maySkipSampleProcessing, }: {
16
+ export declare const parseMdat: ({ data, size, fileOffset, existingBoxes, state, signal, maySkipSampleProcessing, }: {
17
17
  data: BufferIterator;
18
18
  size: number;
19
19
  fileOffset: number;
20
20
  existingBoxes: IsoBaseMediaBox[];
21
- options: ParserContext;
21
+ state: ParserState;
22
22
  signal: AbortSignal | null;
23
23
  maySkipSampleProcessing: boolean;
24
24
  }) => Promise<MdatBox>;
@@ -5,11 +5,11 @@ const convert_audio_or_video_sample_1 = require("../../../convert-audio-or-video
5
5
  const get_tracks_1 = require("../../../get-tracks");
6
6
  const get_sample_positions_from_track_1 = require("../get-sample-positions-from-track");
7
7
  const traversal_1 = require("../traversal");
8
- const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, signal, maySkipSampleProcessing, }) => {
8
+ const parseMdat = async ({ data, size, fileOffset, existingBoxes, state, signal, maySkipSampleProcessing, }) => {
9
9
  const alreadyHas = (0, get_tracks_1.hasTracks)({
10
10
  type: 'iso-base-media',
11
11
  boxes: existingBoxes,
12
- }, options.parserState);
12
+ }, state);
13
13
  if (!alreadyHas) {
14
14
  if (maySkipSampleProcessing) {
15
15
  data.discard(size - (data.counter.getOffset() - fileOffset));
@@ -29,7 +29,7 @@ const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, signa
29
29
  fileOffset,
30
30
  });
31
31
  }
32
- const tracks = (0, get_tracks_1.getTracks)({ type: 'iso-base-media', boxes: existingBoxes }, options.parserState);
32
+ const tracks = (0, get_tracks_1.getTracks)({ type: 'iso-base-media', boxes: existingBoxes }, state);
33
33
  const allTracks = [
34
34
  ...tracks.videoTracks,
35
35
  ...tracks.audioTracks,
@@ -79,7 +79,7 @@ const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, signa
79
79
  const bytes = data.getSlice(samplesWithIndex.samplePosition.size);
80
80
  const { cts, dts, duration } = samplesWithIndex.samplePosition;
81
81
  if (samplesWithIndex.track.type === 'audio') {
82
- await options.parserState.onAudioSample(samplesWithIndex.track.trackId, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
82
+ await state.callbacks.onAudioSample(samplesWithIndex.track.trackId, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
83
83
  data: bytes,
84
84
  timestamp: cts,
85
85
  duration,
@@ -87,10 +87,12 @@ const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, signa
87
87
  dts,
88
88
  trackId: samplesWithIndex.track.trackId,
89
89
  type: samplesWithIndex.samplePosition.isKeyframe ? 'key' : 'delta',
90
+ offset: samplesWithIndex.samplePosition.offset,
91
+ timescale: samplesWithIndex.track.timescale,
90
92
  }, samplesWithIndex.track.timescale));
91
93
  }
92
94
  if (samplesWithIndex.track.type === 'video') {
93
- await options.parserState.onVideoSample(samplesWithIndex.track.trackId, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
95
+ await state.callbacks.onVideoSample(samplesWithIndex.track.trackId, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
94
96
  data: bytes,
95
97
  timestamp: cts,
96
98
  duration,
@@ -98,6 +100,8 @@ const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, signa
98
100
  dts,
99
101
  trackId: samplesWithIndex.track.trackId,
100
102
  type: samplesWithIndex.samplePosition.isKeyframe ? 'key' : 'delta',
103
+ offset: samplesWithIndex.samplePosition.offset,
104
+ timescale: samplesWithIndex.track.timescale,
101
105
  }, samplesWithIndex.track.timescale));
102
106
  }
103
107
  const remaining = size - (data.counter.getOffset() - fileOffset);
@@ -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 MoovBox extends BaseBox {
8
8
  type: 'moov-box';
9
9
  children: AnySegment[];
10
10
  }
11
- export declare const parseMoov: ({ iterator, offset, size, options, signal, logLevel, fields, }: {
11
+ export declare const parseMoov: ({ iterator, offset, size, state, signal, logLevel, 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
  logLevel: LogLevel;
18
18
  fields: Options<ParseMediaFields>;
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMoov = void 0;
4
4
  const process_box_1 = require("../process-box");
5
- const parseMoov = async ({ iterator, offset, size, options, signal, logLevel, fields, }) => {
5
+ const parseMoov = async ({ iterator, offset, size, state, signal, logLevel, fields, }) => {
6
+ const boxes = [];
6
7
  const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
7
8
  iterator,
8
9
  maxBytes: size - (iterator.counter.getOffset() - offset),
9
10
  allowIncompleteBoxes: false,
10
- initialBoxes: [],
11
- options,
11
+ initialBoxes: boxes,
12
+ state,
12
13
  continueMdat: false,
13
14
  signal,
14
15
  logLevel,
@@ -21,7 +22,7 @@ const parseMoov = async ({ iterator, offset, size, options, signal, logLevel, fi
21
22
  offset,
22
23
  boxSize: size,
23
24
  type: 'moov-box',
24
- children: children.segments.boxes,
25
+ children: boxes,
25
26
  };
26
27
  };
27
28
  exports.parseMoov = parseMoov;
@@ -1,34 +1,34 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
2
  import type { LogLevel } from '../../log';
3
3
  import type { Options, ParseMediaFields } from '../../options';
4
- import type { IsoBaseMediaBox, IsoBaseMediaStructure, ParseResult } from '../../parse-result';
4
+ import type { IsoBaseMediaBox, ParseResult } from '../../parse-result';
5
5
  import type { BoxAndNext, PartialMdatBox } from '../../parse-video';
6
- import type { ParserContext } from '../../parser-context';
7
- export declare const parseMdatPartially: ({ iterator, boxSize, fileOffset, parsedBoxes, options, signal, }: {
6
+ import type { ParserState } from '../../state/parser-state';
7
+ export declare const parseMdatPartially: ({ iterator, boxSize, fileOffset, parsedBoxes, state, signal, }: {
8
8
  iterator: BufferIterator;
9
9
  boxSize: number;
10
10
  fileOffset: number;
11
11
  parsedBoxes: IsoBaseMediaBox[];
12
- options: ParserContext;
12
+ state: ParserState;
13
13
  signal: AbortSignal | null;
14
14
  }) => Promise<BoxAndNext>;
15
- export declare const processBox: ({ iterator, allowIncompleteBoxes, parsedBoxes, options, signal, logLevel, fields, }: {
15
+ export declare const processBox: ({ iterator, allowIncompleteBoxes, parsedBoxes, state, signal, logLevel, fields, }: {
16
16
  iterator: BufferIterator;
17
17
  allowIncompleteBoxes: boolean;
18
18
  parsedBoxes: IsoBaseMediaBox[];
19
- options: ParserContext;
19
+ state: ParserState;
20
20
  signal: AbortSignal | null;
21
21
  logLevel: LogLevel;
22
22
  fields: Options<ParseMediaFields>;
23
23
  }) => Promise<BoxAndNext>;
24
- export declare const parseIsoBaseMediaBoxes: ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, options, continueMdat, signal, logLevel, fields, }: {
24
+ export declare const parseIsoBaseMediaBoxes: ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, state, continueMdat, signal, logLevel, fields, }: {
25
25
  iterator: BufferIterator;
26
26
  maxBytes: number;
27
27
  allowIncompleteBoxes: boolean;
28
28
  initialBoxes: IsoBaseMediaBox[];
29
- options: ParserContext;
29
+ state: ParserState;
30
30
  continueMdat: false | PartialMdatBox;
31
31
  signal: AbortSignal | null;
32
32
  logLevel: LogLevel;
33
33
  fields: Options<ParseMediaFields>;
34
- }) => Promise<ParseResult<IsoBaseMediaStructure>>;
34
+ }) => Promise<ParseResult>;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseIsoBaseMediaBoxes = exports.processBox = exports.parseMdatPartially = void 0;
4
4
  const get_tracks_1 = require("../../get-tracks");
5
5
  const has_all_info_1 = require("../../has-all-info");
6
+ const may_skip_video_data_1 = require("../../may-skip-video-data/may-skip-video-data");
6
7
  const register_track_1 = require("../../register-track");
7
8
  const esds_1 = require("./esds/esds");
8
9
  const ftyp_1 = require("./ftyp");
@@ -33,7 +34,7 @@ const tkhd_1 = require("./tkhd");
33
34
  const trak_1 = require("./trak/trak");
34
35
  const traversal_1 = require("./traversal");
35
36
  const trun_1 = require("./trun");
36
- const getChildren = async ({ boxType, iterator, bytesRemainingInBox, options, signal, logLevel, fields, }) => {
37
+ const getChildren = async ({ boxType, iterator, bytesRemainingInBox, state, signal, logLevel, fields, }) => {
37
38
  const parseChildren = boxType === 'mdia' ||
38
39
  boxType === 'minf' ||
39
40
  boxType === 'stbl' ||
@@ -45,13 +46,14 @@ const getChildren = async ({ boxType, iterator, bytesRemainingInBox, options, si
45
46
  boxType === 'traf' ||
46
47
  boxType === 'stsb';
47
48
  if (parseChildren) {
49
+ const boxes = [];
48
50
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
49
51
  const parsed = await (0, exports.parseIsoBaseMediaBoxes)({
50
52
  iterator,
51
53
  maxBytes: bytesRemainingInBox,
52
54
  allowIncompleteBoxes: false,
53
- initialBoxes: [],
54
- options,
55
+ initialBoxes: boxes,
56
+ state,
55
57
  continueMdat: false,
56
58
  signal,
57
59
  logLevel,
@@ -60,7 +62,7 @@ const getChildren = async ({ boxType, iterator, bytesRemainingInBox, options, si
60
62
  if (parsed.status === 'incomplete') {
61
63
  throw new Error('Incomplete boxes are not allowed');
62
64
  }
63
- return parsed.segments.boxes;
65
+ return boxes;
64
66
  }
65
67
  if (bytesRemainingInBox < 0) {
66
68
  throw new Error('Box size is too big ' + JSON.stringify({ boxType }));
@@ -68,15 +70,15 @@ const getChildren = async ({ boxType, iterator, bytesRemainingInBox, options, si
68
70
  iterator.discard(bytesRemainingInBox);
69
71
  return [];
70
72
  };
71
- const parseMdatPartially = async ({ iterator, boxSize, fileOffset, parsedBoxes, options, signal, }) => {
73
+ const parseMdatPartially = async ({ iterator, boxSize, fileOffset, parsedBoxes, state, signal, }) => {
72
74
  const box = await (0, mdat_1.parseMdat)({
73
75
  data: iterator,
74
76
  size: boxSize,
75
77
  fileOffset,
76
78
  existingBoxes: parsedBoxes,
77
- options,
79
+ state,
78
80
  signal,
79
- maySkipSampleProcessing: options.supportsContentRange,
81
+ maySkipSampleProcessing: state.supportsContentRange,
80
82
  });
81
83
  if ((box.status === 'samples-processed' || box.status === 'samples-buffered') &&
82
84
  box.fileOffset + boxSize === iterator.counter.getOffset()) {
@@ -94,7 +96,7 @@ const parseMdatPartially = async ({ iterator, boxSize, fileOffset, parsedBoxes,
94
96
  };
95
97
  };
96
98
  exports.parseMdatPartially = parseMdatPartially;
97
- const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options, signal, logLevel, fields, }) => {
99
+ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, state, signal, logLevel, fields, }) => {
98
100
  const fileOffset = iterator.counter.getOffset();
99
101
  const bytesRemaining = iterator.bytesRemaining();
100
102
  const boxSizeRaw = iterator.getFourByteNumber();
@@ -125,9 +127,9 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
125
127
  if (bytesRemaining < boxSize) {
126
128
  if (boxType === 'mdat') {
127
129
  // Check if the moov atom is at the end
128
- const shouldSkip = options.parserState.maySkipVideoData() ||
129
- (!(0, get_tracks_1.hasTracks)({ type: 'iso-base-media', boxes: parsedBoxes }, options.parserState) &&
130
- options.supportsContentRange);
130
+ const shouldSkip = (0, may_skip_video_data_1.maySkipVideoData)({ state }) ||
131
+ (!(0, get_tracks_1.hasTracks)({ type: 'iso-base-media', boxes: parsedBoxes }, state) &&
132
+ state.supportsContentRange);
131
133
  if (shouldSkip) {
132
134
  const skipTo = fileOffset + boxSize;
133
135
  const bytesToSkip = skipTo - iterator.counter.getOffset();
@@ -152,7 +154,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
152
154
  boxSize,
153
155
  fileOffset,
154
156
  parsedBoxes,
155
- options,
157
+ state,
156
158
  signal,
157
159
  });
158
160
  }
@@ -227,7 +229,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
227
229
  iterator,
228
230
  offset: fileOffset,
229
231
  size: boxSize,
230
- options,
232
+ state,
231
233
  signal,
232
234
  fields,
233
235
  });
@@ -322,7 +324,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
322
324
  iterator,
323
325
  offset: fileOffset,
324
326
  size: boxSize,
325
- options,
327
+ state,
326
328
  signal,
327
329
  fields,
328
330
  });
@@ -369,12 +371,12 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
369
371
  iterator,
370
372
  offset: fileOffset,
371
373
  size: boxSize,
372
- options,
374
+ state,
373
375
  signal,
374
376
  logLevel,
375
377
  fields,
376
378
  });
377
- options.parserState.tracks.setIsDone();
379
+ state.callbacks.tracks.setIsDone();
378
380
  return {
379
381
  type: 'complete',
380
382
  box,
@@ -387,7 +389,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
387
389
  data: iterator,
388
390
  size: boxSize,
389
391
  offsetAtStart: fileOffset,
390
- options,
392
+ state,
391
393
  signal,
392
394
  logLevel,
393
395
  fields,
@@ -395,7 +397,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
395
397
  const transformedTrack = (0, make_track_1.makeBaseMediaTrack)(box);
396
398
  if (transformedTrack) {
397
399
  await (0, register_track_1.registerTrack)({
398
- options,
400
+ state,
399
401
  track: transformedTrack,
400
402
  container: 'mp4',
401
403
  });
@@ -502,9 +504,9 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
502
504
  size: boxSize,
503
505
  fileOffset,
504
506
  existingBoxes: parsedBoxes,
505
- options,
507
+ state,
506
508
  signal,
507
- maySkipSampleProcessing: options.supportsContentRange,
509
+ maySkipSampleProcessing: state.supportsContentRange,
508
510
  });
509
511
  if (box === null) {
510
512
  throw new Error('Unexpected null');
@@ -521,7 +523,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
521
523
  boxType,
522
524
  iterator,
523
525
  bytesRemainingInBox,
524
- options,
526
+ state,
525
527
  signal,
526
528
  logLevel,
527
529
  fields,
@@ -540,13 +542,11 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
540
542
  };
541
543
  };
542
544
  exports.processBox = processBox;
543
- const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, options, continueMdat, signal, logLevel, fields, }) => {
544
- const structure = {
545
- type: 'iso-base-media',
546
- boxes: initialBoxes,
547
- };
545
+ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, state, continueMdat, signal, logLevel, fields, }) => {
546
+ var _a;
548
547
  const initialOffset = iterator.counter.getOffset();
549
- const alreadyHasMdat = structure.boxes.find((b) => b.type === 'mdat-box');
548
+ const alreadyHasMdat = (_a = state.structure
549
+ .getStructureOrNull()) === null || _a === void 0 ? void 0 : _a.boxes.find((b) => b.type === 'mdat-box');
550
550
  while (iterator.bytesRemaining() > 0 &&
551
551
  iterator.counter.getOffset() - initialOffset < maxBytes) {
552
552
  const result = continueMdat
@@ -555,14 +555,14 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
555
555
  boxSize: continueMdat.boxSize,
556
556
  fileOffset: continueMdat.fileOffset,
557
557
  parsedBoxes: initialBoxes,
558
- options,
558
+ state,
559
559
  signal,
560
560
  })
561
561
  : await (0, exports.processBox)({
562
562
  iterator,
563
563
  allowIncompleteBoxes,
564
564
  parsedBoxes: initialBoxes,
565
- options,
565
+ state,
566
566
  signal,
567
567
  logLevel,
568
568
  fields,
@@ -573,14 +573,13 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
573
573
  }
574
574
  return {
575
575
  status: 'incomplete',
576
- segments: structure,
577
576
  continueParsing: () => {
578
577
  return (0, exports.parseIsoBaseMediaBoxes)({
579
578
  iterator,
580
579
  maxBytes,
581
580
  allowIncompleteBoxes,
582
- initialBoxes: structure.boxes,
583
- options,
581
+ initialBoxes,
582
+ state,
584
583
  continueMdat: false,
585
584
  signal,
586
585
  logLevel,
@@ -593,14 +592,13 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
593
592
  if (result.type === 'partial-mdat-box') {
594
593
  return {
595
594
  status: 'incomplete',
596
- segments: structure,
597
595
  continueParsing: () => {
598
596
  return Promise.resolve((0, exports.parseIsoBaseMediaBoxes)({
599
597
  iterator,
600
598
  maxBytes,
601
599
  allowIncompleteBoxes,
602
- initialBoxes: structure.boxes,
603
- options,
600
+ initialBoxes,
601
+ state,
604
602
  continueMdat: result,
605
603
  signal,
606
604
  logLevel,
@@ -611,8 +609,8 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
611
609
  };
612
610
  }
613
611
  if (result.box.type === 'mdat-box' && alreadyHasMdat) {
614
- structure.boxes = structure.boxes.filter((b) => b.type !== 'mdat-box');
615
- structure.boxes.push(result.box);
612
+ initialBoxes = initialBoxes.filter((b) => b.type !== 'mdat-box');
613
+ initialBoxes.push(result.box);
616
614
  iterator.allowDiscard();
617
615
  if (result.box.status !== 'samples-processed') {
618
616
  throw new Error('unexpected');
@@ -620,28 +618,26 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
620
618
  break;
621
619
  }
622
620
  else {
623
- structure.boxes.push(result.box);
624
- if ((0, has_all_info_1.hasAllInfo)({ fields, state: options.parserState, structure })) {
621
+ initialBoxes.push(result.box);
622
+ if ((0, has_all_info_1.hasAllInfo)({ fields, state })) {
625
623
  return {
626
624
  status: 'done',
627
- segments: structure,
628
625
  };
629
626
  }
630
627
  }
631
628
  if (result.skipTo !== null) {
632
- if (!options.supportsContentRange) {
629
+ if (!state.supportsContentRange) {
633
630
  throw new Error('Content-Range header is not supported by the reader, but was asked to seek');
634
631
  }
635
632
  return {
636
633
  status: 'incomplete',
637
- segments: structure,
638
634
  continueParsing: () => {
639
635
  return (0, exports.parseIsoBaseMediaBoxes)({
640
636
  iterator,
641
637
  maxBytes,
642
638
  allowIncompleteBoxes,
643
- initialBoxes: structure.boxes,
644
- options,
639
+ initialBoxes,
640
+ state,
645
641
  continueMdat: false,
646
642
  signal,
647
643
  logLevel,
@@ -654,14 +650,13 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
654
650
  if (iterator.bytesRemaining() < 0) {
655
651
  return {
656
652
  status: 'incomplete',
657
- segments: structure,
658
653
  continueParsing: () => {
659
654
  return (0, exports.parseIsoBaseMediaBoxes)({
660
655
  iterator,
661
656
  maxBytes,
662
657
  allowIncompleteBoxes,
663
- initialBoxes: structure.boxes,
664
- options,
658
+ initialBoxes,
659
+ state,
665
660
  continueMdat: false,
666
661
  signal,
667
662
  logLevel,
@@ -673,16 +668,14 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
673
668
  }
674
669
  iterator.removeBytesRead();
675
670
  }
676
- const mdatState = (0, traversal_1.getMdatBox)(structure.boxes);
671
+ const mdatState = (0, traversal_1.getMdatBox)(initialBoxes);
677
672
  const skipped = (mdatState === null || mdatState === void 0 ? void 0 : mdatState.status) === 'samples-skipped' &&
678
- !options.parserState.maySkipVideoData() &&
679
- options.supportsContentRange;
680
- const buffered = (mdatState === null || mdatState === void 0 ? void 0 : mdatState.status) === 'samples-buffered' &&
681
- !options.parserState.maySkipVideoData();
673
+ !(0, may_skip_video_data_1.maySkipVideoData)({ state }) &&
674
+ state.supportsContentRange;
675
+ const buffered = (mdatState === null || mdatState === void 0 ? void 0 : mdatState.status) === 'samples-buffered' && !(0, may_skip_video_data_1.maySkipVideoData)({ state });
682
676
  if (skipped || buffered) {
683
677
  return {
684
678
  status: 'incomplete',
685
- segments: structure,
686
679
  continueParsing: () => {
687
680
  if (buffered) {
688
681
  iterator.skipTo(mdatState.fileOffset, false);
@@ -691,8 +684,8 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
691
684
  iterator,
692
685
  maxBytes,
693
686
  allowIncompleteBoxes: false,
694
- initialBoxes: structure.boxes,
695
- options,
687
+ initialBoxes,
688
+ state,
696
689
  continueMdat: false,
697
690
  signal,
698
691
  logLevel,
@@ -704,7 +697,6 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
704
697
  }
705
698
  return {
706
699
  status: 'done',
707
- segments: structure,
708
700
  };
709
701
  };
710
702
  exports.parseIsoBaseMediaBoxes = parseIsoBaseMediaBoxes;
@@ -1,7 +1,7 @@
1
1
  import type { BufferIterator } from '../../../buffer-iterator';
2
2
  import type { Options, ParseMediaFields } from '../../../options';
3
3
  import type { AnySegment } from '../../../parse-result';
4
- import type { ParserContext } from '../../../parser-context';
4
+ import type { ParserState } from '../../../state/parser-state';
5
5
  import type { BaseBox } from '../base-type';
6
6
  export interface MebxBox extends BaseBox {
7
7
  type: 'mebx-box';
@@ -9,11 +9,11 @@ export interface MebxBox extends BaseBox {
9
9
  format: string;
10
10
  children: AnySegment[];
11
11
  }
12
- export declare const parseMebx: ({ iterator, offset, size, options, signal, fields, }: {
12
+ export declare const parseMebx: ({ iterator, offset, size, state, signal, fields, }: {
13
13
  iterator: BufferIterator;
14
14
  offset: number;
15
15
  size: number;
16
- options: ParserContext;
16
+ state: ParserState;
17
17
  signal: AbortSignal | null;
18
18
  fields: Options<ParseMediaFields>;
19
19
  }) => Promise<MebxBox>;
@@ -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;