MSWSP: add two more Property Sets
[wireshark-wip.git] / epan / dissectors / packet-mp4ves.c
blob7649fee80b443687eedc2346f7dc65772d866de9
1 /*
2 * packet-mp4ves.c
3 * Routines for MPEG4 dissection
4 * Copyright 2007-2008, Anders Broman <anders.broman[at]ericsson.com>
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * References:
27 * http://www.ietf.org/rfc/rfc3016.txt?number=3016
30 #include "config.h"
32 #include <string.h>
34 #include <glib.h>
36 #include <epan/packet.h>
37 #include <epan/asn1.h>
39 #include <epan/prefs.h>
41 /* Initialize the protocol and registered fields */
42 static int proto_mp4ves = -1;
44 static int hf_mp4ves_config = -1;
45 static int hf_mp4ves_start_code_prefix = -1;
46 static int hf_mp4ves_start_code = -1;
47 static int hf_mp4ves_vop_coding_type = -1;
48 static int hf_mp4ves_profile_and_level_indication = -1;
49 static int hf_mp4ves_is_visual_object_identifier = -1;
50 static int hf_mp4ves_visual_object_type = -1;
51 static int hf_mp4ves_video_signal_type = -1;
52 static int hf_mp4ves_stuffing = -1;
53 static int hf_mp4ves_video_object_type_indication = -1;
54 static int hf_mp4ves_random_accessible_vol = -1;
55 static int hf_mp4ves_is_object_layer_identifier = -1;
56 static int hf_mp4ves_aspect_ratio_info = -1;
57 static int hf_mp4ves_vol_control_parameters = -1;
58 static int hf_mp4ves_video_object_layer_shape = -1;
60 /* Initialize the subtree pointers */
61 static int ett_mp4ves = -1;
62 static int ett_mp4ves_config = -1;
64 /* The dynamic payload type which will be dissected as MP4V-ES */
66 static guint global_dynamic_payload_type = 0;
70 14496-2, Annex G, Table G-1.
71 Table G-1 FLC table for profile_and_level_indication Profile/Level Code
73 const value_string mp4ves_level_indication_vals[] =
75 { 0, "Reserved" },
76 { 1, "Simple Profile/Level 1" },
77 { 2, "Simple Profile/Level 2" },
78 { 3, "Reserved" },
79 { 4, "Reserved" },
80 { 5, "Reserved" },
81 { 6, "Reserved" },
82 { 7, "Reserved" },
83 { 8, "Simple Profile/Level 0" },
84 { 9, "Simple Profile/Level 0b" },
85 /* Reserved 00001001 - 00010000 */
86 { 0x11, "Simple Scalable Profile/Level 1" },
87 { 0x12, "Simple Scalable Profile/Level 2" },
88 /* Reserved 00010011 - 00100000 */
89 { 0x21, "Core Profile/Level 1" },
90 { 0x22, "Core Profile/Level 2" },
91 /* Reserved 00100011 - 00110001 */
92 { 0x32, "Main Profile/Level 2" },
93 { 0x33, "Main Profile/Level 3" },
94 { 0x34, "Main Profile/Level 4" },
95 /* Reserved 00110101 - 01000001 */
96 { 0x42, "N-bit Profile/Level 2" },
97 /* Reserved 01000011 - 01010000 */
98 { 0x51, "Scalable Texture Profile/Level 1" },
99 /* Reserved 01010010 - 01100000 */
100 { 0x61, "Simple Face Animation Profile/Level 1" },
101 { 0x62, "Simple Face Animation Profile/Level 2" },
102 { 0x63, "Simple FBA Profile/Level 1" },
103 { 0x64, "Simple FBA Profile/Level 2" },
104 /* Reserved 01100101 - 01110000 */
105 { 0x71, "Basic Animated Texture Profile/Level 1" },
106 { 0x72, "Basic Animated Texture Profile/Level 2" },
107 /* Reserved 01110011 - 10000000 */
108 { 0x81, "Hybrid Profile/Level 1" },
109 { 0x82, "Hybrid Profile/Level 2" },
110 /* Reserved 10000011 - 10010000 */
111 { 0x91, "Advanced Real Time Simple Profile/Level 1" },
112 { 0x92, "Advanced Real Time Simple Profile/Level 2" },
113 { 0x93, "Advanced Real Time Simple Profile/Level 3" },
114 { 0x94, "Advanced Real Time Simple Profile/Level 4" },
115 /* Reserved 10010101 - 10100000 */
116 { 0xa1, "Core Scalable Profile/Level 1" },
117 { 0xa2, "Core Scalable Profile/Level 2" },
118 { 0xa3, "Core Scalable Profile/Level 3" },
119 /* Reserved 10100100 - 10110000 */
120 { 0xb1, "Advanced Coding Efficiency Profile/Level 1" },
121 { 0xb2, "Advanced Coding Efficiency Profile/Level 2" },
122 { 0xb3, "Advanced Coding Efficiency Profile/Level 3" },
123 { 0xb4, "Advanced Coding Efficiency Profile/Level 4" },
124 /* Reserved 10110101 - 11000000 */
125 { 0xc1, "Advanced Core Profile/Level 1" },
126 { 0xc2, "Advanced Core Profile/Level 2" },
127 /* Reserved 11000011 - 11010000 */
128 { 0xd1, "Advanced Scalable Texture/Level 1" },
129 { 0xd2, "Advanced Scalable Texture/Level 2" },
130 { 0xd3, "Advanced Scalable Texture/Level 3" },
131 /* Reserved 11010100 - 11100000 */
132 { 0xe1, "Simple Studio Profile/Level 1" },
133 { 0xe2, "Simple Studio Profile/Level 2" },
134 { 0xe3, "Simple Studio Profile/Level 3" },
135 { 0xe4, "Simple Studio Profile/Level 4" },
136 { 0xe5, "Core Studio Profile/Level 1" },
137 { 0xe6, "Core Studio Profile/Level 2" },
138 { 0xe7, "Core Studio Profile/Level 3" },
139 { 0xe8, "Core Studio Profile/Level 4" },
140 /* Reserved 11101001 - 11101111 */
141 { 0xf0, "Advanced Simple Profile/Level 0" },
142 { 0xf1, "Advanced Simple Profile/Level 1" },
143 { 0xf2, "Advanced Simple Profile/Level 2" },
144 { 0xf3, "Advanced Simple Profile/Level 3" },
145 { 0xf4, "Advanced Simple Profile/Level 4" },
146 { 0xf5, "Advanced Simple Profile/Level 5" },
147 /* Reserved 11110110 - 11110111 */
148 { 0xf8, "Fine Granularity Scalable Profile/Level 0" },
149 { 0xf9, "Fine Granularity Scalable Profile/Level 1" },
150 { 0xfa, "Fine Granularity Scalable Profile/Level 2" },
151 { 0xfb, "Fine Granularity Scalable Profile/Level 3" },
152 { 0xfc, "Fine Granularity Scalable Profile/Level 4" },
153 { 0xfd, "Fine Granularity Scalable Profile/Level 5" },
154 { 0xfe, "Reserved" },
155 { 0xff, "Reserved for Escape" },
156 { 0, NULL },
158 static const range_string mp4ves_startcode_vals[] = {
159 { 0x00, 0x1f, "video_object_start_code" },
160 { 0x20, 0x2f, "video_object_layer_start_code" },
161 { 0x30, 0xaf, "reserved" },
162 { 0xb0, 0xb0, "visual_object_sequence_start_code" },
163 { 0xb1, 0xb1, "visual_object_sequence_end_code" },
164 { 0xb2, 0xb2, "user_data_start_code" },
165 { 0xb3, 0xb3, "group_of_vop_start_code" },
166 { 0xb4, 0xb4, "video_session_error_code" },
167 { 0xb5, 0xb5, "visual_object_start_code" },
168 { 0xb6, 0xb6, "vop_start_code" },
169 { 0xb7, 0xb9, "reserved" },
170 { 0xba, 0xba, "fba_object_start_code" },
171 { 0xbb, 0xbb, "fba_object_plane_start_code" },
172 { 0xbc, 0xbc, "mesh_object_start_code" },
173 { 0xbd, 0xbd, "mesh_object_plane_start_code" },
174 { 0xbe, 0xbe, "still_texture_object_start_code" },
175 { 0xbf, 0xbf, "texture_spatial_layer_start_code" },
176 { 0xc0, 0xc0, "texture_snr_layer_start_code" },
177 { 0xc1, 0xc1, "texture_tile_start_code" },
178 { 0xc2, 0xc2, "texture_shape_layer_start_code" },
179 { 0xc3, 0xc3, "stuffing_start_code" },
180 { 0xc4, 0xc5, "reserved" },
181 { 0xc6, 0xcf, "System start codes" }, /* NOTE System start codes are defined in ISO/IEC 14496-1:1999 */
182 { 0, 0, NULL }
185 static const value_string mp4ves_vop_coding_type_vals[] = {
186 { 0, "intra-coded (I)" },
187 { 1, "predictive-coded (P)" },
188 { 2, "bidirectionally-predictive-coded (B)" },
189 { 3, "sprite (S)" },
190 { 0, NULL }
194 * FLC table for video_object_type indication
196 static const value_string mp4ves_video_object_type_vals[] = {
197 { 0x0, "Reserved" },
198 { 0x1, "Simple Object Type" },
199 { 0x2, "Simple Scalable Object Type" },
200 { 0x3, "Core Object Type" },
201 { 0x4, "Main Object Type" },
202 { 0x5, "N-bit Object Type" },
203 { 0x6, "Basic Anim. 2D Texture" },
204 { 0x7, "Anim. 2D Mesh" },
205 { 0x8, "Simple Face" },
206 { 0x9, "Still Scalable Texture" },
207 { 0xa, "Advanced Real Time Simple" },
208 { 0xb, "Core Scalable" },
209 { 0xc, "Advanced Coding Efficiency" },
210 { 0xd, "Advanced Scalable Texture" },
211 { 0xe, "Simple FBA" },
212 { 0, NULL }
214 /* Visual object type */
215 static const value_string mp4ves_visual_object_type_vals[] = {
216 { 0x0, "reserved" },
217 { 0x1, "video ID" },
218 { 0x2, "still texture ID" },
219 { 0x3, "mesh ID" },
220 { 0x4, "FBA ID" },
221 { 0x5, "3D mesh ID" },
222 { 0x6, "reserved" },
223 { 0x7, "reserved" },
224 { 0x8, "reserved" },
225 { 0x9, "reserved" },
226 { 0xa, "reserved" },
227 { 0xb, "reserved" },
228 { 0xc, "reserved" },
229 { 0xd, "reserved" },
230 { 0xe, "reserved" },
231 { 0xf, "reserved" },
232 { 0, NULL }
235 static const value_string mp4ves_video_object_type_indication_vals[] = {
236 { 0x0, "Reserved" },
237 { 0x1, "Simple Object Type" },
238 { 0x2, "Simple Scalable Object Type" },
239 { 0x3, "Core Object Type" },
240 { 0x4, "Main Object Type" },
241 { 0x5, "N-bit Object Type" },
242 { 0x6, "Basic Anim. 2D Texture" },
243 { 0x7, "Anim. 2D Mesh" },
244 { 0x8, "Simple Face" },
245 { 0x9, "Still Scalable Texture" },
246 { 0xa, "Advanced Real Time Simple" },
247 { 0xb, "Core Scalable" },
248 { 0xc, "Advanced Coding Efficiency" },
249 { 0xd, "Advanced Scalable Texture" },
250 { 0xe, "Simple FBA" },
251 { 0xf, "Reserved" },
252 /* Reserved 00001111 - 11111111 */
253 { 0, NULL }
255 /* 6.2.2.1 User data */
256 static int
257 dissect_mp4ves_user_data(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int bit_offset)
259 int start_bit_offset;
261 /* user_data_start_code */
262 proto_tree_add_bits_item(tree, hf_mp4ves_start_code_prefix, tvb, bit_offset, 24, ENC_BIG_ENDIAN);
263 bit_offset+=24;
264 proto_tree_add_bits_item(tree, hf_mp4ves_start_code, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
265 bit_offset+=8;
266 start_bit_offset = bit_offset;
267 /* while( next_bits() != '000 0000 0000 0000 0000 0001') { */
268 while ( tvb_get_bits32(tvb,bit_offset, 24, ENC_BIG_ENDIAN) != 1){
269 bit_offset+=8;
270 /* user_data 8 bits */
272 proto_tree_add_text(tree, tvb, start_bit_offset>>3, (bit_offset - start_bit_offset)>>2, "User data");
274 return bit_offset;
277 next_start_code() {
278 zero_bit
279 while (!bytealigned())
280 one_bit
283 static int
284 dissect_mp4ves_next_start_code(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int bit_offset)
286 guint8 zero_bit;
287 int start_bit_offset;
289 start_bit_offset = bit_offset;
291 zero_bit = tvb_get_bits8(tvb,bit_offset,1);
292 if (zero_bit != 0){
293 /* Error */
295 bit_offset++;
297 /* zero stuffing bits */
298 if(bit_offset %8 == 0)
299 return bit_offset;
301 while(bit_offset %8 != 0){
302 bit_offset++;
305 proto_tree_add_bits_item(tree, hf_mp4ves_stuffing, tvb, start_bit_offset, bit_offset-start_bit_offset, ENC_BIG_ENDIAN);
307 return bit_offset;
310 #if 0
311 video_signal_type() {
312 video_signal_type
313 if (video_signal_type) {
314 video_format 3 uimsbf
315 video_range 1 bslbf
316 colour_description 1 bslbf
317 if (colour_description) {
318 colour_primaries 8 uimsbf
319 transfer_characteristics 8 uimsbf
320 matrix_coefficients 8 uimsbf
324 #endif
326 static int
327 dissect_mp4ves_visual_object_type(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int bit_offset)
329 guint8 video_signal_type, colour_description;
331 video_signal_type = tvb_get_bits8(tvb,bit_offset,1);
332 proto_tree_add_bits_item(tree, hf_mp4ves_video_signal_type, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
333 bit_offset++;
334 if (video_signal_type) {
335 /* video_format 3 bits */
336 bit_offset+=3;
337 /* video_range 1 bit */
338 bit_offset++;
339 /* colour_description 1 bit */
340 colour_description = tvb_get_bits8(tvb,bit_offset,1);
341 if (colour_description) {
342 /* colour_primaries 8 bits */
343 bit_offset+=8;
344 /* transfer_characteristics 8 bits */
345 bit_offset+=8;
346 /* matrix_coefficients 8 bits*/
347 bit_offset+=8;
351 return bit_offset;
354 * 6.2.3 Video Object Layer
358 * Table 6-12 -- Meaning of pixel aspect ratio
361 static const value_string mp4ves_aspect_ratio_info_vals[] = {
362 { 0x0, "Forbidden" },
363 { 0x1, "1:1 (Square)" },
364 { 0x2, "12:11 (625-type for 4:3 picture)" },
365 { 0x3, "10:11 (525-type for 4:3 picture)" },
366 { 0x4, "16:11 (625-type stretched for 16:9 picture)" },
367 { 0x5, "40:33 (525-type stretched for 16:9 picture)" },
368 { 0x6, "Reserved" },
369 { 0x7, "Reserved" },
370 { 0x8, "Reserved" },
371 { 0x9, "Reserved" },
372 { 0xa, "Reserved" },
373 { 0xb, "Reserved" },
374 { 0xc, "Reserved" },
375 { 0xd, "Reserved" },
376 { 0xe, "Reserved" },
377 { 0xf, "Extended PAR" },
378 { 0, NULL }
381 /* Table 6-14 Video Object Layer shape type */
382 static const value_string mp4ves_video_object_layer_shape_vals[] = {
383 { 0x0, "rectangular" },
384 { 0x1, "binary" },
385 { 0x2, "binary only" },
386 { 0x3, "grayscale" },
387 { 0, NULL }
390 static int
391 dissect_mp4ves_VideoObjectLayer(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int bit_offset)
393 guint32 dword;
394 int current_bit_offset;
395 guint8 octet, is_object_layer_identifier, aspect_ratio_info, vol_control_parameters, vbv_parameters;
396 guint8 video_object_layer_shape, video_object_layer_verid = 0;
398 /* if(next_bits() == video_object_layer_start_code) { */
399 dword = tvb_get_bits32(tvb,bit_offset, 24, ENC_BIG_ENDIAN);
400 if (dword != 1){
401 return bit_offset;
403 octet = tvb_get_bits8(tvb,bit_offset+24, 8);
404 if((octet>=0x20)&&(octet<=0x2f)){
405 /* Continue */
406 }else{
407 return bit_offset;
409 /* video_object_layer_start_code */
410 proto_tree_add_bits_item(tree, hf_mp4ves_start_code_prefix, tvb, bit_offset, 24, ENC_BIG_ENDIAN);
411 bit_offset+=24;
412 proto_tree_add_bits_item(tree, hf_mp4ves_start_code, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
413 bit_offset+= 8;
415 /* short_video_header = 0 */
416 /* random_accessible_vol 1 */
417 proto_tree_add_bits_item(tree, hf_mp4ves_random_accessible_vol, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
418 bit_offset++;
419 /* video_object_type_indication 8 */
420 proto_tree_add_bits_item(tree, hf_mp4ves_video_object_type_indication, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
421 bit_offset+= 8;
422 /* is_object_layer_identifier 1 */
423 is_object_layer_identifier = tvb_get_bits8(tvb,bit_offset, 1);
424 proto_tree_add_bits_item(tree, hf_mp4ves_is_object_layer_identifier, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
425 bit_offset++;
426 if(is_object_layer_identifier) {
427 /* video_object_layer_verid 4 uimsbf */
428 bit_offset+=4;
429 /* video_object_layer_priority 3 uimsbf */
430 bit_offset+=3;
432 /* aspect_ratio_info 4 uimsbf */
433 aspect_ratio_info = tvb_get_bits8(tvb,bit_offset, 1);
434 proto_tree_add_bits_item(tree, hf_mp4ves_aspect_ratio_info, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
435 if (aspect_ratio_info == 0xf /*"extended_PAR"*/ ) {
436 /* par_width 8 uimsbf */
437 bit_offset+=8;
438 /* par_height 8 uimsbf */
439 bit_offset+=8;
441 /* vol_control_parameters 1 bslbf */
442 /* vol_control_parameters 1 bslbf */
443 vol_control_parameters = tvb_get_bits8(tvb,bit_offset, 1);
444 proto_tree_add_bits_item(tree, hf_mp4ves_vol_control_parameters, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
445 bit_offset++;
446 current_bit_offset = bit_offset;
447 if (vol_control_parameters) {
448 /* chroma_format 2 uimsbf */
449 bit_offset+=2;
450 /* low_delay 1 uimsbf */
451 bit_offset++;
452 /* vbv_parameters 1 blsbf */
453 vbv_parameters = tvb_get_bits8(tvb,bit_offset, 1);
454 bit_offset++;
455 if (vbv_parameters) {
456 /* first_half_bit_rate 15 uimsbf */
457 bit_offset+=15;
458 /* marker_bit 1 bslbf */
459 bit_offset++;
460 /* latter_half_bit_rate 15 uimsbf */
461 bit_offset+=15;
462 /* marker_bit 1 bslbf */
463 bit_offset++;
464 /* first_half_vbv_buffer_size 15 uimsbf */
465 bit_offset+=15;
466 /* marker_bit 1 bslbf */
467 bit_offset++;
468 /* latter_half_vbv_buffer_size 3 uimsbf */
469 bit_offset+=3;
470 /* first_half_vbv_occupancy 11 uimsbf */
471 bit_offset+=11;
472 /* marker_bit 1 blsbf */
473 bit_offset++;
474 /* latter_half_vbv_occupancy 15 uimsbf */
475 bit_offset+=15;
476 /* marker_bit 1 blsbf */
477 bit_offset++;
480 if(bit_offset-current_bit_offset > 0)
481 proto_tree_add_text(tree, tvb, current_bit_offset>>3, (bit_offset+7)>>3, "Not dissected bits");
482 /* video_object_layer_shape 2 uimsbf */
483 video_object_layer_shape = tvb_get_bits8(tvb,bit_offset, 2);
484 proto_tree_add_bits_item(tree, hf_mp4ves_video_object_layer_shape, tvb, bit_offset, 2, ENC_BIG_ENDIAN);
485 bit_offset+=2;
486 if (video_object_layer_shape == 3/*"grayscale"*/&& video_object_layer_verid != 1){
487 /* video_object_layer_shape_extension 4 uimsbf */
488 bit_offset+=4;
490 /* marker_bit 1 bslbf */
491 bit_offset++;
492 /* vop_time_increment_resolution 16 uimsbf */
493 bit_offset+=16;
494 /* marker_bit 1 bslbf */
495 bit_offset++;
496 /* fixed_vop_rate 1 bslbf */
497 bit_offset++;
500 return bit_offset;
502 /* Visual object */
504 VisualObject() {
505 visual_object_start_code
506 is_visual_object_identifier
507 if (is_visual_object_identifier) {
508 visual_object_verid
509 visual_object_priority
511 visual_object_type
512 if (visual_object_type == "Video ID" || visual_object_type == "still textureID") {
513 video_signal_type()
515 next_start_code()
516 while ( next_bits()== user_data_start_code){
517 user_data()
519 if (visual_object_type == "Video ID") {
520 video_object_start_code
521 VideoObjectLayer()
523 else if (visual_object_type == "still texture ID") {
524 StillTextureObject()
526 else if (visual_object_type == "mesh ID") {
527 MeshObject()
529 else if (visual_object_type == "FBA ID") {
530 FBAObject()
532 else if (visual_object_type == "3D mesh ID") {
533 3D_Mesh_Object()
535 if (next_bits() != "0000 0000 0000 0000 0000 0001")
536 next_start_code()
539 static int
540 dissect_mp4ves_VisualObject(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int bit_offset)
542 proto_item *item;
543 guint8 is_visual_object_identifier, visual_object_type;
544 guint32 dword;
545 guint8 octet;
547 is_visual_object_identifier = tvb_get_bits8(tvb,bit_offset,1);
548 proto_tree_add_bits_item(tree, hf_mp4ves_is_visual_object_identifier, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
549 bit_offset++;
550 if(is_visual_object_identifier){
551 /* visual_object_verid 4 bits*/
552 bit_offset+=4;
553 /* visual_object_priority 3 bits*/
554 bit_offset+=3;
556 /* visual_object_type 4 bits*/
557 visual_object_type = tvb_get_bits8(tvb,bit_offset,4);
558 proto_tree_add_bits_item(tree, hf_mp4ves_visual_object_type, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
559 bit_offset+=4;
560 if ((visual_object_type == 1/*"Video ID"*/) || (visual_object_type == 2/*"still textureID"*/)) {
561 /* video_signal_type() */
562 bit_offset = dissect_mp4ves_visual_object_type(tvb, pinfo, tree, bit_offset);
564 /* next_start_code() */
565 bit_offset = dissect_mp4ves_next_start_code(tvb, pinfo, tree, bit_offset);
566 dword = tvb_get_bits32(tvb,bit_offset, 32, ENC_BIG_ENDIAN);
568 while ( next_bits()== user_data_start_code){
569 user_data()
572 while(dword==0x1b2){
573 bit_offset = dissect_mp4ves_user_data(tvb, pinfo, tree, bit_offset);
574 dword = tvb_get_bits32(tvb,bit_offset, 32, ENC_BIG_ENDIAN);
576 if (visual_object_type == 1/*"Video ID"*/) {
578 * video_object_start_code
580 dword = tvb_get_bits32(tvb,bit_offset, 24, ENC_BIG_ENDIAN);
581 if (dword != 1){
582 /* no start code */
583 return -1;
585 octet = tvb_get_bits8(tvb,bit_offset+24, 8);
586 if(octet>0x20){
587 /* Error */
588 return -1;
590 proto_tree_add_bits_item(tree, hf_mp4ves_start_code_prefix, tvb, bit_offset, 24, ENC_BIG_ENDIAN);
591 bit_offset+=24;
592 proto_tree_add_bits_item(tree, hf_mp4ves_start_code, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
593 bit_offset+= 8;
594 if(tvb_length_remaining(tvb,(bit_offset>>3))<=0){
595 item = proto_tree_add_text(tree, tvb, 0, -1, "Config string too short");
596 PROTO_ITEM_SET_GENERATED(item);
597 return -1;
600 VideoObjectLayer()
602 bit_offset = dissect_mp4ves_VideoObjectLayer(tvb, pinfo, tree, bit_offset);
605 return bit_offset;
608 static int
609 dissect_mp4ves_VisualObjectSequence(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int bit_offset)
611 guint32 dword;
613 /*VisualObjectSequence() {
614 do {
615 visual_object_sequence_start_code
618 /* Get start code prefix */
619 dword = tvb_get_bits32(tvb,bit_offset, 32, ENC_BIG_ENDIAN);
620 if ((dword & 0x00000100) != 0x00000100){
621 /* No start code prefix */
622 return -1;
624 proto_tree_add_bits_item(tree, hf_mp4ves_start_code_prefix, tvb, bit_offset, 24, ENC_BIG_ENDIAN);
625 bit_offset+= 24;
627 proto_tree_add_bits_item(tree, hf_mp4ves_start_code, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
628 bit_offset+= 8;
630 /* Expect visual_object_sequence_start_code */
631 if(dword != 0x1b0)
632 return -1;
633 /* profile_and_level_indication */
634 proto_tree_add_bits_item(tree, hf_mp4ves_profile_and_level_indication, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
635 bit_offset+= 8;
637 /* while ( next_bits()== user_data_start_code){
638 user_data()
641 dword = tvb_get_bits32(tvb,bit_offset, 32, ENC_BIG_ENDIAN);
642 bit_offset+= 32;
643 if ((dword & 0x00000100) != 0x00000100){
644 /* No start code prefix */
645 return -1;
647 if(dword==0x1b2){
649 * user_data_start_code
650 * XXX call user data dissection here
652 return -1;
654 if(dword==0x1b5){
656 * VisualObject()
658 bit_offset = dissect_mp4ves_VisualObject(tvb, pinfo, tree, bit_offset);
661 } while ( next_bits() != visual_object_sequence_end_code)
662 visual_object_sequence_end_code
664 return bit_offset;
667 void
668 dissect_mp4ves_config(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
670 proto_item *item;
671 proto_tree *mp4ves_tree;
673 item = proto_tree_add_item(tree, hf_mp4ves_config, tvb, 0, -1, ENC_NA);
674 mp4ves_tree = proto_item_add_subtree(item, ett_mp4ves_config);
676 dissect_mp4ves_VisualObjectSequence(tvb, pinfo, mp4ves_tree, 0);
679 void
680 dissect_mp4ves(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
682 int bit_offset = 0;
683 proto_item *item;
684 proto_tree *mp4ves_tree;
685 guint32 dword;
687 /* Make entries in Protocol column and Info column on summary display */
688 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MP4V-ES");
689 if (tree) {
690 item = proto_tree_add_item(tree, proto_mp4ves, tvb, 0, -1, ENC_NA);
691 mp4ves_tree = proto_item_add_subtree(item, ett_mp4ves);
693 +------+------+------+------+
694 (a) | RTP | VS | VO | VOL |
695 |header|header|header|header|
696 +------+------+------+------+
698 +------+------+------+------+------------+
699 (b) | RTP | VS | VO | VOL |Video Packet|
700 |header|header|header|header| |
701 +------+------+------+------+------------+
703 +------+-----+------------------+
704 (c) | RTP | GOV |Video Object Plane|
705 |header| | |
706 +------+-----+------------------+
708 +------+------+------------+ +------+------+------------+
709 (d) | RTP | VOP |Video Packet| | RTP | VP |Video Packet|
710 |header|header| (1) | |header|header| (2) |
711 +------+------+------------+ +------+------+------------+
713 +------+------+------------+------+------------+------+------------+
714 (e) | RTP | VP |Video Packet| VP |Video Packet| VP |Video Packet|
715 |header|header| (1) |header| (2) |header| (3) |
716 +------+------+------------+------+------------+------+------------+
718 +------+------+------------+ +------+------------+
719 (f) | RTP | VOP |VOP fragment| | RTP |VOP fragment|
720 |header|header| (1) | |header| (2) | ___
721 +------+------+------------+ +------+------------+
723 Figure 2 - Examples of RTP packetized MPEG-4 Visual bitstream
725 So a valid packet should start with
726 VS - Visual Object Sequence Header
727 GOV - Group_of_VideoObjectPlane
728 VOP - Video Object Plane
729 VP - Video Plane
730 Otherwies it's a VOP fragment.
732 visual_object_sequence_start_code: The visual_object_sequence_start_code is
733 the bit string '000001B0' in hexadecimal. It initiates a visual session.
735 group_of_vop_start_code: The group_of_vop_start_code is the bit string '000001B3' in hexadecimal. It identifies
736 the beginning of a GOV header.
738 vop_start_code: This is the bit string '000001B6' in hexadecimal.
742 if (tvb_length(tvb)< 4){
743 /* To short to be a start code */
744 proto_tree_add_text(mp4ves_tree, tvb, bit_offset>>3, -1, "Data");
745 return;
747 dword = tvb_get_bits32(tvb,bit_offset, 24, ENC_BIG_ENDIAN);
748 if (dword != 1){
749 /* if it's not 23 zeros followed by 1 it isn't a start code */
750 proto_tree_add_text(mp4ves_tree, tvb, bit_offset>>3, -1, "Data");
751 return;
753 dword = tvb_get_bits8(tvb,24, 8);
754 bit_offset = bit_offset+8;
755 switch(dword){
756 /* vop_start_code */
757 case 0xb6:
758 proto_tree_add_bits_item(mp4ves_tree, hf_mp4ves_start_code_prefix, tvb, bit_offset, 24, ENC_BIG_ENDIAN);
759 bit_offset = bit_offset+24;
760 /* vop_coding_type 2 bits */
761 proto_tree_add_bits_item(mp4ves_tree, hf_mp4ves_vop_coding_type, tvb, bit_offset, 2, ENC_BIG_ENDIAN);
762 break;
763 case 0xb0:
764 /* VS start code */
765 /*bit_offset = */dissect_mp4ves_VisualObjectSequence(tvb, pinfo, mp4ves_tree, 0);
766 break;
767 default:
768 proto_tree_add_bits_item(mp4ves_tree, hf_mp4ves_start_code_prefix, tvb, bit_offset, 24, ENC_BIG_ENDIAN);
769 /*bit_offset = bit_offset+24;*/
770 break;
776 * Parameter name profileAndLevel
777 * Parameter description This is a nonCollapsing GenericParameter
778 * Parameter identifier value 0
779 * Parameter status Mandatory
780 * Parameter type unsignedMax. Shall be in the range 0..255.
781 * H245:
782 * unsignedMax INTEGER(0..65535), -- Look for max
784 static int
785 dissect_mp4ves_par_profile(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree _U_, void *data)
787 int offset = 0;
788 guint16 lvl;
789 const gchar *p = NULL;
790 asn1_ctx_t *actx = get_asn1_ctx(data);
792 DISSECTOR_ASSERT(actx);
794 lvl = tvb_get_ntohs(tvb, offset);
795 p = try_val_to_str(lvl, VALS(mp4ves_level_indication_vals));
796 if (p) {
797 proto_item_append_text(actx->created_item, " - profileAndLevel %s", p);
799 offset += 2;
800 return offset;
802 static int
803 dissect_mp4ves_par_video_object_type(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree _U_, void *data)
805 int offset = 0;
806 guint16 lvl;
807 const gchar *p = NULL;
808 asn1_ctx_t *actx = get_asn1_ctx(data);
810 DISSECTOR_ASSERT(actx);
812 lvl = tvb_get_ntohs(tvb, offset);
813 p = try_val_to_str(lvl, VALS(mp4ves_video_object_type_vals));
814 if (p) {
815 proto_item_append_text(actx->created_item, " - video_object_type %s", p);
817 offset += 2;
818 return offset;
821 static int
822 dissect_mp4ves_par_decoderConfigurationInformation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
824 asn1_ctx_t *actx = get_asn1_ctx(data);
826 DISSECTOR_ASSERT(actx);
828 dissect_mp4ves_config(tvb, pinfo, tree);
830 return tvb_length(tvb);
833 typedef struct _mp4ves_capability_t {
834 const gchar *id;
835 const gchar *name;
836 new_dissector_t content_pdu;
837 } mp4ves_capability_t;
839 static mp4ves_capability_t mp4ves_capability_tab[] = {
840 /* ITU-T H.245 capabilities ISO/IEC 14496-2(m*/
841 { "GenericCapability/0.0.8.245.1.0.0/nonCollapsing/0", "profileAndLevel", dissect_mp4ves_par_profile },
842 { "GenericCapability/0.0.8.245.1.0.0/nonCollapsing/1", "object", dissect_mp4ves_par_video_object_type },
843 { "GenericCapability/0.0.8.245.1.0.0/nonCollapsing/2", "decoderConfigurationInformation", dissect_mp4ves_par_decoderConfigurationInformation },
844 { "GenericCapability/0.0.8.245.1.0.0/nonCollapsing/3", "drawingOrder", NULL },
845 { "GenericCapability/0.0.8.245.1.0.0/collapsing/4", "visualBackChannelHandle", NULL },
846 { NULL, NULL, NULL },
849 static mp4ves_capability_t *find_cap(const gchar *id) {
850 mp4ves_capability_t *ftr = NULL;
851 mp4ves_capability_t *f;
853 for (f=mp4ves_capability_tab; f->id; f++) {
854 if (!strcmp(id, f->id)) { ftr = f; break; }
856 return ftr;
859 static int
860 dissect_mp4ves_name(tvbuff_t *tvb _U_, packet_info *pinfo, proto_tree *tree, void* data)
862 asn1_ctx_t *actx = get_asn1_ctx(data);
863 mp4ves_capability_t *ftr;
865 DISSECTOR_ASSERT(actx);
866 if (tree) {
867 ftr = find_cap(pinfo->match_string);
868 if (ftr) {
869 proto_item_append_text(actx->created_item, " - %s", ftr->name);
870 proto_item_append_text(proto_item_get_parent(proto_tree_get_parent(tree)), ": %s", ftr->name);
871 } else {
872 proto_item_append_text(actx->created_item, " - unknown(%s)", pinfo->match_string);
876 return tvb_length(tvb);
879 void
880 proto_reg_handoff_mp4ves(void);
882 void
883 proto_register_mp4ves(void)
887 /* Setup list of header fields See Section 1.6.1 for details*/
888 static hf_register_info hf[] = {
889 { &hf_mp4ves_config,
890 { "Configuration", "mp4ves.configuration",
891 FT_BYTES, BASE_NONE, NULL, 0x0,
892 NULL, HFILL }
894 { &hf_mp4ves_start_code_prefix,
895 { "start code prefix", "mp4ves.start_code_prefix",
896 FT_UINT32, BASE_HEX, NULL, 0x0,
897 NULL, HFILL }
899 { &hf_mp4ves_start_code,
900 { "Start code", "mp4ves.start_code",
901 FT_UINT8, BASE_RANGE_STRING|BASE_HEX, RVALS(mp4ves_startcode_vals), 0x0,
902 NULL, HFILL }
904 { &hf_mp4ves_vop_coding_type,
905 { "vop_coding_type", "mp4ves.vop_coding_type",
906 FT_UINT8, BASE_DEC, VALS(mp4ves_vop_coding_type_vals), 0x0,
907 "Start code", HFILL }
909 {&hf_mp4ves_profile_and_level_indication,
910 { "profile_and_level_indication", "mp4ves.profile_and_level_indication",
911 FT_UINT8, BASE_DEC,VALS(mp4ves_level_indication_vals), 0x0,
912 NULL, HFILL }
914 { &hf_mp4ves_is_visual_object_identifier,
915 { "visual_object_identifier", "mp4ves.visual_object_identifier",
916 FT_UINT8, BASE_DEC, NULL, 0x0,
917 NULL, HFILL }
919 { &hf_mp4ves_visual_object_type,
920 { "visual_object_type", "mp4ves.visual_object_type",
921 FT_UINT32, BASE_DEC, VALS(mp4ves_visual_object_type_vals), 0x0,
922 NULL, HFILL }
924 { &hf_mp4ves_video_signal_type,
925 { "video_signal_type", "mp4ves.video_signal_type",
926 FT_UINT8, BASE_DEC, NULL, 0x0,
927 NULL, HFILL }
929 { &hf_mp4ves_stuffing,
930 { "Stuffing", "mp4ves.stuffing",
931 FT_UINT8, BASE_DEC, NULL, 0x0,
932 NULL, HFILL }
934 { &hf_mp4ves_video_object_type_indication,
935 { "video_object_type_indication", "mp4ves.video_object_type_indication",
936 FT_UINT8, BASE_DEC, VALS(mp4ves_video_object_type_indication_vals), 0x0,
937 NULL, HFILL }
939 { &hf_mp4ves_random_accessible_vol,
940 { "random_accessible_vol", "mp4ves.random_accessible_vol",
941 FT_UINT8, BASE_DEC, NULL, 0x0,
942 "video_object_type_indication", HFILL }
944 { &hf_mp4ves_is_object_layer_identifier,
945 { "is_object_layer_identifier", "mp4ves.is_object_layer_identifier",
946 FT_UINT8, BASE_DEC, NULL, 0x0,
947 NULL, HFILL }
949 { &hf_mp4ves_aspect_ratio_info,
950 { "aspect_ratio_info", "mp4ves.aspect_ratio_info",
951 FT_UINT8, BASE_DEC, VALS(mp4ves_aspect_ratio_info_vals), 0x0,
952 NULL, HFILL }
954 { &hf_mp4ves_vol_control_parameters,
955 { "vol_control_parameters", "mp4ves.vol_control_parameters",
956 FT_UINT8, BASE_DEC, NULL, 0x0,
957 NULL, HFILL }
959 { &hf_mp4ves_video_object_layer_shape,
960 { "video_object_layer_shape", "mp4ves.video_object_layer_shape",
961 FT_UINT8, BASE_DEC, VALS(mp4ves_video_object_layer_shape_vals), 0x0,
962 NULL, HFILL }
966 /* Setup protocol subtree array */
967 static gint *ett[] = {
968 &ett_mp4ves,
969 &ett_mp4ves_config,
972 module_t *mp4ves_module;
974 /* Register the protocol name and description */
975 proto_mp4ves = proto_register_protocol("MP4V-ES","MP4V-ES", "mp4v-es");
977 /* Required function calls to register the header fields and subtrees used */
978 proto_register_field_array(proto_mp4ves, hf, array_length(hf));
979 proto_register_subtree_array(ett, array_length(ett));
980 /* Register a configuration option for port */
982 register_dissector("mp4ves", dissect_mp4ves, proto_mp4ves);
984 /* Register a configuration option for port */
985 mp4ves_module = prefs_register_protocol(proto_mp4ves, proto_reg_handoff_mp4ves);
987 prefs_register_uint_preference(mp4ves_module,
988 "dynamic.payload.type",
989 "MP4V-ES dynamic payload type",
990 "The dynamic payload type which will be interpreted as MP4V-ES",
992 &global_dynamic_payload_type);
996 void
997 proto_reg_handoff_mp4ves(void)
999 static dissector_handle_t mp4ves_handle;
1000 static guint dynamic_payload_type;
1001 static gboolean mp4ves_prefs_initialized = FALSE;
1003 if (!mp4ves_prefs_initialized) {
1004 dissector_handle_t mp4ves_name_handle;
1005 mp4ves_capability_t *ftr;
1007 mp4ves_handle = find_dissector("mp4ves");
1008 dissector_add_string("rtp_dyn_payload_type","MP4V-ES", mp4ves_handle);
1009 mp4ves_prefs_initialized = TRUE;
1011 mp4ves_name_handle = new_create_dissector_handle(dissect_mp4ves_name, proto_mp4ves);
1012 for (ftr=mp4ves_capability_tab; ftr->id; ftr++) {
1013 if (ftr->name)
1014 dissector_add_string("h245.gef.name", ftr->id, mp4ves_name_handle);
1015 if (ftr->content_pdu)
1016 dissector_add_string("h245.gef.content", ftr->id, new_create_dissector_handle(ftr->content_pdu, proto_mp4ves));
1018 }else{
1019 if ( dynamic_payload_type > 95 )
1020 dissector_delete_uint("rtp.pt", dynamic_payload_type, mp4ves_handle);
1022 dynamic_payload_type = global_dynamic_payload_type;
1024 if ( dynamic_payload_type > 95 ){
1025 dissector_add_uint("rtp.pt", dynamic_payload_type, mp4ves_handle);