Skip to content

Commit 64b4c34

Browse files
committed
parse list box
1 parent 5bd86d6 commit 64b4c34

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

packages/media-parser/src/boxes/riff/parse-fmt-box.ts

-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const parseFmtBox = ({
1010
boxes: RiffBox[];
1111
size: number;
1212
}): RiffBox => {
13-
const offset = iterator.counter.getOffset();
1413
const header = boxes.find((b) => b.type === 'riff-header');
1514
if (!header) {
1615
throw new Error('Expected RIFF header');
@@ -31,8 +30,6 @@ export const parseFmtBox = ({
3130
const blockAlign = iterator.getUint16Le();
3231
const bitsPerSample = iterator.getUint16Le();
3332

34-
iterator.discard(size - (iterator.counter.getOffset() - offset));
35-
3633
return {
3734
type: 'wave-format-box',
3835
formatTag: wFormatTag,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type {BufferIterator} from '../../buffer-iterator';
2+
import type {RiffBox} from './riff-box';
3+
4+
export const parseListBox = ({
5+
iterator,
6+
boxes,
7+
size,
8+
}: {
9+
iterator: BufferIterator;
10+
boxes: RiffBox[];
11+
size: number;
12+
}): RiffBox => {
13+
const counter = iterator.counter.getOffset();
14+
const listType = iterator.getByteString(4);
15+
iterator.discard(size - (iterator.counter.getOffset() - counter));
16+
17+
return {
18+
type: 'list-box',
19+
listType,
20+
};
21+
};

packages/media-parser/src/boxes/riff/parse-riff-box.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {BufferIterator} from '../../buffer-iterator';
22
import {parseFmtBox} from './parse-fmt-box';
3+
import {parseListBox} from './parse-list-box';
34
import type {RiffBox, RiffRegularBox} from './riff-box';
45

56
export const parseRiffBox = ({
@@ -17,6 +18,10 @@ export const parseRiffBox = ({
1718
return parseFmtBox({iterator, boxes, size});
1819
}
1920

21+
if (id === 'LIST') {
22+
return parseListBox({iterator, boxes, size});
23+
}
24+
2025
iterator.discard(size);
2126

2227
const box: RiffRegularBox = {

packages/media-parser/src/boxes/riff/riff-box.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export type WaveFormatBox = {
88
bitsPerSample: number;
99
};
1010

11+
export type ListBox = {
12+
type: 'list-box';
13+
listType: string;
14+
};
15+
1116
export type RiffRegularBox = {
1217
type: 'riff-box';
1318
size: number;
@@ -20,4 +25,4 @@ export type RiffHeader = {
2025
fileType: string;
2126
};
2227

23-
export type RiffBox = RiffRegularBox | WaveFormatBox | RiffHeader;
28+
export type RiffBox = RiffRegularBox | WaveFormatBox | RiffHeader | ListBox;

packages/media-parser/src/test/parse-avi-file.test.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,21 @@ test('AVI file', async () => {
1818
type: 'riff-header',
1919
},
2020
{
21-
id: 'LIST',
22-
size: 8894,
23-
type: 'riff-box',
21+
listType: 'hdrl',
22+
type: 'list-box',
2423
},
2524
{
26-
id: 'LIST',
27-
size: 26,
28-
type: 'riff-box',
25+
listType: 'INFO',
26+
type: 'list-box',
2927
},
3028
{
3129
id: 'JUNK',
3230
size: 1016,
3331
type: 'riff-box',
3432
},
3533
{
36-
id: 'LIST',
37-
size: 695114,
38-
type: 'riff-box',
34+
listType: 'movi',
35+
type: 'list-box',
3936
},
4037
{
4138
id: 'idx1',

packages/media-parser/src/test/parse-wav-file.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ test('WAV file', async () => {
3232
type: 'riff-box',
3333
},
3434
{
35-
id: 'LIST',
36-
size: 46,
37-
type: 'riff-box',
35+
listType: 'INFO',
36+
type: 'list-box',
3837
},
3938
{
4039
id: 'id3',

0 commit comments

Comments
 (0)