Parse NAL units
Look into the contents of mdats and parse out the contained NAL unit types.
Showing
2 changed files
with
45 additions
and
5 deletions
... | @@ -168,13 +168,17 @@ test('can parse a pdin', function() { | ... | @@ -168,13 +168,17 @@ test('can parse a pdin', function() { |
168 | 168 | ||
169 | test('can parse an mdat', function() { | 169 | test('can parse an mdat', function() { |
170 | var mdat = new Uint8Array(box('mdat', | 170 | var mdat = new Uint8Array(box('mdat', |
171 | 0, 0, 0, 4, // length | ||
171 | 0x01, 0x02, 0x03, 0x04 // data | 172 | 0x01, 0x02, 0x03, 0x04 // data |
172 | )); | 173 | )); |
173 | deepEqual(videojs.inspectMp4(mdat), [{ | 174 | deepEqual(videojs.inspectMp4(mdat), [{ |
174 | size: 12, | 175 | size: 16, |
175 | type: 'mdat', | 176 | type: 'mdat', |
176 | byteLength: 4 | 177 | nals: [ |
177 | }], 'parsed an mdat'); | 178 | 'slice_layer_without_partitioning_rbsp' |
179 | ], | ||
180 | byteLength: 8 | ||
181 | }], 'parsed an mdat'); | ||
178 | }); | 182 | }); |
179 | 183 | ||
180 | test('can parse a free or skip', function() { | 184 | test('can parse a free or skip', function() { | ... | ... |
... | @@ -30,6 +30,41 @@ var | ... | @@ -30,6 +30,41 @@ var |
30 | degradationPriority: (flags[2] << 8) | flags[3] | 30 | degradationPriority: (flags[2] << 8) | flags[3] |
31 | }; | 31 | }; |
32 | }, | 32 | }, |
33 | nalParse = function(avcStream) { | ||
34 | var | ||
35 | avcView = new DataView(avcStream.buffer, avcStream.byteOffset, avcStream.byteLength), | ||
36 | result = [], | ||
37 | i, | ||
38 | length; | ||
39 | for (i = 0; i < avcStream.length; i += length) { | ||
40 | length = avcView.getUint32(i); | ||
41 | i += 4; | ||
42 | switch(avcStream[i] & 0x1F) { | ||
43 | case 0x01: | ||
44 | result.push('slice_layer_without_partitioning_rbsp'); | ||
45 | break; | ||
46 | case 0x05: | ||
47 | result.push('slice_layer_without_partitioning_rbsp_idr'); | ||
48 | break; | ||
49 | case 0x06: | ||
50 | result.push('sei_rbsp'); | ||
51 | break; | ||
52 | case 0x07: | ||
53 | result.push('seq_parameter_set_rbsp'); | ||
54 | break; | ||
55 | case 0x08: | ||
56 | result.push('pic_parameter_set_rbsp'); | ||
57 | break; | ||
58 | case 0x09: | ||
59 | result.push('access_unit_delimiter_rbsp'); | ||
60 | break; | ||
61 | default: | ||
62 | result.push(avcStream[i] & 0x1F); | ||
63 | break; | ||
64 | } | ||
65 | } | ||
66 | return result; | ||
67 | }, | ||
33 | 68 | ||
34 | // registry of handlers for individual mp4 box types | 69 | // registry of handlers for individual mp4 box types |
35 | parse = { | 70 | parse = { |
... | @@ -150,7 +185,8 @@ var | ... | @@ -150,7 +185,8 @@ var |
150 | }, | 185 | }, |
151 | mdat: function(data) { | 186 | mdat: function(data) { |
152 | return { | 187 | return { |
153 | byteLength: data.byteLength | 188 | byteLength: data.byteLength, |
189 | nals: nalParse(data) | ||
154 | }; | 190 | }; |
155 | }, | 191 | }, |
156 | mdhd: function(data) { | 192 | mdhd: function(data) { | ... | ... |
-
Please register or sign in to post a comment