Don't guard col_set_str (COL_PROTOCOL) with col_check
[obnox/wireshark/wip.git] / epan / dissectors / packet-h264.c
1 /* packet-h264.c
2  * Routines for H.264 dissection
3  * Copyright 2007 - 2009, Anders Broman <anders.broman[at]ericsson.com>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  * 
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  *
25  * References:
26  * http://www.ietf.org/rfc/rfc3984.txt?number=3984
27  * http://www.itu.int/rec/T-REC-H.264/en
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #include <glib.h>
39
40 #include <epan/packet.h>
41 #include <epan/proto.h>
42 #include <epan/asn1.h>
43 #include <epan/strutil.h>
44
45 #include "prefs.h"
46
47
48 /* Initialize the protocol and registered fields */
49 static int proto_h264                                                           = -1;
50 static int hf_h264_type                                                         = -1;
51 static int hf_h264_nal_f_bit                                            = -1;
52 static int hf_h264_nal_nri                                                      = -1;
53 static int hf_h264_start_bit                                            = -1;
54 static int hf_h264_forbidden_bit                                        = -1;
55 static int hf_h264_end_bit                                                      = -1;
56 static int hf_h264_profile                                                      = -1;
57 static int hf_h264_profile_idc                                          = -1;
58 static int hf_h264_rbsp_stop_bit                                        = -1;
59 static int hf_h264_rbsp_trailing_bits                           = -1;
60 static int hf_h264_constraint_set0_flag                         = -1;
61 static int hf_h264_constraint_set1_flag                         = -1;
62 static int hf_h264_constraint_set2_flag                         = -1;
63 static int hf_h264_constraint_set3_flag                         = -1;
64 static int hf_h264_reserved_zero_4bits                          = -1;
65 static int hf_h264_level_idc                                            = -1;
66 static int hf_h264_nal_unit                                                     = -1;
67 static int hf_h264_forbidden_zero_bit                           = -1;
68 static int hf_h264_nal_ref_idc                                          = -1;
69 static int hf_h264_nal_unit_type                                        = -1;
70 static int hf_h264_seq_parameter_set_id                         = -1;
71 static int hf_h264_chroma_format_idc                            = -1;
72 static int hf_h264_residual_colour_transform_flag       = -1;
73 static int hf_h264_bit_depth_luma_minus8                        = -1;
74 static int hf_h264_bit_depth_chroma_minus8                      = -1;
75 static int hf_h264_qpprime_y_zero_transform_bypass_flag = -1;
76 static int hf_h264_seq_scaling_matrix_present_flag      = -1;
77 static int hf_h264_log2_max_frame_num_minus4            = -1;
78 static int hf_h264_pic_order_cnt_type                           = -1;
79 static int hf_h264_log2_max_pic_order_cnt_lsb_minus4 = -1;
80 static int hf_h264_delta_pic_order_always_zero_flag = -1;
81 static int hf_h264_offset_for_non_ref_pic                       = -1;
82 static int hf_h264_offset_for_top_to_bottom_field       = -1;
83 static int hf_h264_num_ref_frames_in_pic_order_cnt_cycle = -1;
84 static int hf_h264_offset_for_ref_frame                         = -1;
85 static int hf_h264_num_ref_frames                                       = -1;
86 static int hf_h264_gaps_in_frame_num_value_allowed_flag = -1;
87 static int hf_h264_pic_width_in_mbs_minus1                      = -1;
88 static int hf_h264_pic_height_in_map_units_minus1       = -1;
89 static int hf_h264_frame_mbs_only_flag                          = -1;
90 static int hf_h264_mb_adaptive_frame_field_flag         = -1;
91 static int hf_h264_direct_8x8_inference_flag            = -1;
92 static int hf_h264_frame_cropping_flag                          = -1;
93 static int hf_h264_frame_crop_left_offset                       = -1;
94 static int hf_h264_frame_crop_right_offset                      = -1;
95 static int hf_h264_frame_crop_top_offset                        = -1;
96 static int hf_h264_frame_crop_bottom_offset                     = -1;
97 static int hf_h264_vui_parameters_present_flag          = -1;
98 static int hf_h264_pic_parameter_set_id                         = -1;
99 static int hf_h264_entropy_coding_mode_flag                     = -1;
100 static int hf_h264_pic_order_present_flag                       = -1;
101 static int hf_h264_num_slice_groups_minus1                      = -1;
102 static int hf_h264_slice_group_map_type                         = -1;
103 static int hf_h264_num_ref_idx_l0_active_minus1         = -1;
104 static int hf_h264_num_ref_idx_l1_active_minus1         = -1;
105 static int hf_h264_weighted_pred_flag                           = -1;
106 static int hf_h264_weighted_bipred_idc                          = -1;
107 static int hf_h264_pic_init_qp_minus26                          = -1;
108 static int hf_h264_pic_init_qs_minus26                          = -1;
109 static int hf_h264_chroma_qp_index_offset                       = -1;
110 static int hf_h264_deblocking_filter_control_present_flag = -1;
111 static int hf_h264_constrained_intra_pred_flag          = -1;
112 static int hf_h264_redundant_pic_cnt_present_flag       = -1;
113 static int hf_h264_transform_8x8_mode_flag                      = -1;
114 static int hf_h264_pic_scaling_matrix_present_flag      = -1;
115 static int hf_h264_second_chroma_qp_index_offset        = -1;
116 static int hf_h264_par_profile                                          = -1;
117 static int hf_h264_par_profile_b                                        = -1;
118 static int hf_h264_par_profile_m                                        = -1;
119 static int hf_h264_par_profile_e                                        = -1;
120 static int hf_h264_par_profile_h                                        = -1;
121 static int hf_h264_par_profile_h10                                      = -1;
122 static int hf_h264_par_profile_h4_2_2                           = -1;
123 static int hf_h264_par_profile_h4_4_4                           = -1;
124 static int hf_h264_par_add_mode_sup                                     = -1;
125 static int hf_h264_par_AdditionalModesSupported         = -1;
126 static int hf_h264_par_add_mode_sup_rcdo                        = -1;
127 static int hf_h264_par_ProfileIOP                                       = -1;
128 static int hf_h264_par_constraint_set0_flag                     = -1;
129 static int hf_h264_par_constraint_set1_flag                     = -1;
130 static int hf_h264_par_constraint_set2_flag                     = -1;
131
132 /* VUI parameters */
133 static int hf_h264_aspect_ratio_info_present_flag       = -1;
134 static int hf_h264_aspect_ratio_idc                                     = -1;
135 static int hf_h264_sar_width                                            = -1;
136 static int hf_h264_sar_height                                           = -1;
137 static int hf_h264_overscan_info_present_flag           = -1;
138 static int hf_h264_overscan_appropriate_flag            = -1;
139 static int hf_h264_video_signal_type_present_flag       = -1;
140 static int hf_h264_video_format                                         = -1;
141 static int hf_h264_video_full_range_flag                        = -1;
142 static int hf_h264_colour_description_present_flag      = -1;
143 static int hf_h264_colour_primaries                                     = -1;
144 static int hf_h264_transfer_characteristics                     = -1;
145 static int hf_h264_matrix_coefficients                          = -1;
146 static int hf_h264_chroma_loc_info_present_flag         = -1;
147 static int hf_h264_chroma_sample_loc_type_top_field = -1;
148 static int hf_h264_chroma_sample_loc_type_bottom_field = -1;
149 static int hf_h264_timing_info_present_flag                     = -1;
150 static int hf_h264_num_units_in_tick                            = -1;
151 static int hf_h264_time_scale                                           = -1;
152 static int hf_h264_fixed_frame_rate_flag                        = -1;
153 static int hf_h264_nal_hrd_parameters_present_flag      = -1;
154 static int hf_h264_vcl_hrd_parameters_present_flag      = -1;
155 static int hf_h264_low_delay_hrd_flag                           = -1;
156 static int hf_h264_pic_struct_present_flag                      = -1;
157 static int hf_h264_bitstream_restriction_flag           = -1;
158 static int hf_h264_motion_vectors_over_pic_boundaries_flag = -1;
159 static int hf_h264_max_bytes_per_pic_denom                      = -1;
160 static int hf_h264_max_bits_per_mb_denom                        = -1;
161 static int hf_h264_log2_max_mv_length_horizontal        = -1;
162 static int hf_h264_log2_max_mv_length_vertical          = -1;
163 static int hf_h264_num_reorder_frames                           = -1;
164 static int hf_h264_max_dec_frame_buffering                      = -1;
165 static int hf_h264_cpb_cnt_minus1                                       = -1;
166 static int hf_h264_bit_rate_scale                                       = -1;
167 static int hf_h264_cpb_size_scale                                       = -1;
168 static int hf_h264_bit_rate_value_minus1                        = -1;
169 static int hf_h264_cpb_size_value_minus1                        = -1;
170 static int hf_h264_cbr_flag                                                     = -1;
171 static int hf_h264_initial_cpb_removal_delay_length_minus1 = -1;
172 static int hf_h264_cpb_removal_delay_length_minus1      = -1;
173 static int hf_h264_dpb_output_delay_length_minus11      = -1;
174 static int hf_h264_time_offset_length                           = -1;
175
176 static int hf_h264_first_mb_in_slice                            = -1;
177 static int hf_h264_slice_type                                           = -1;
178 static int hf_h264_slice_id                                                     = -1;
179 static int hf_h264_payloadsize                                          = -1;
180 static int hf_h264_payloadtype                                                  = -1;
181 static int hf_h264_frame_num                                            = -1;
182
183 /* Initialize the subtree pointers */
184 static int ett_h264 = -1;
185 static int ett_h264_profile = -1;
186 static int ett_h264_nal = -1;
187 static int ett_h264_fua = -1;
188 static int ett_h264_stream = -1;
189 static int ett_h264_nal_unit = -1;
190 static int ett_h264_par_profile = -1;
191 static int ett_h264_par_AdditionalModesSupported = -1;
192 static int ett_h264_par_ProfileIOP                               = -1;
193
194 /* The dynamic payload type which will be dissected as H.264 */
195
196 static guint temp_dynamic_payload_type = 0;
197
198 /* syntax tables in subclause 7.3 is equal to
199  * ue(v), me(v), se(v), or te(v).
200  */
201 typedef enum {
202     H264_UE_V = 0,
203     H264_ME_V = 1,
204     H264_SE_V = 2,
205     H264_TE_V = 3
206 } h264_golomb_descriptors;
207
208
209 static const true_false_string h264_f_bit_vals = {
210   "Bit errors or other syntax violations",
211   "No bit errors or other syntax violations"
212 };
213 static const true_false_string h264_start_bit_vals = {
214   "the first packet of FU-A picture",
215   "Not the first packet of FU-A picture"
216 };
217 static const true_false_string h264_end_bit_vals = {
218   "the last packet of FU-A picture",
219   "Not the last packet of FU-A picture"
220 };
221 static const true_false_string h264_forbidden_bit_vals = {
222   "Forbidden Bit of FU-A",
223   "Not Forbidden Bit of FU-A"
224 };
225
226 #define H264_SEQ_PAR_SET                7
227 #define H264_PIC_PAR_SET                8
228
229 static const value_string h264_type_values[] = {
230         { 0,    "Undefined" }, 
231         { 1,    "NAL unit - Coded slice of a non-IDR picture" },        /* Single NAL unit packet per H.264 */
232         { 2,    "NAL unit - Coded slice data partition A" },
233         { 3,    "NAL unit - Coded slice data partition B" },
234         { 4,    "NAL unit - Coded slice data partition C" },
235         { 5,    "NAL unit - Coded slice of an IDR picture" },
236         { 6,    "NAL unit - Supplemental enhancement information (SEI)" },
237         { H264_SEQ_PAR_SET,     "NAL unit - Sequence parameter set" },                          /* 7 */
238         { H264_PIC_PAR_SET,     "NAL unit - Picture parameter set" },                           /* 8 */
239         { 9,    "NAL unit - Access unit delimiter" },
240         { 10,   "NAL unit - End of sequence" },
241         { 11,   "NAL unit - End of stream" },   
242         { 12,   "NAL unit - Filler data" },
243         { 13,   "NAL unit - Sequence parameter set extension" },
244         { 14,   "NAL unit - Reserved" },
245         { 15,   "NAL unit - Reserved" },
246         { 16,   "NAL unit - Reserved" },
247         { 17,   "NAL unit - Reserved" },
248         { 18,   "NAL unit - Reserved" },
249         { 19,   "NAL unit - Coded slice of an auxiliary coded picture without partitioning" },
250         { 20,   "NAL unit - Reserved" },
251         { 21,   "NAL unit - Reserved" },        
252         { 22,   "NAL unit - Reserved" },
253         { 23,   "NAL unit - Reserved" },
254         { 24,   "STAP-A" },             /* Single-time aggregation packet */
255         { 25,   "STAP-B" },             /* Single-time aggregation packet */
256         { 26,   "MTAP16" },             /* Multi-time aggregation packet */
257         { 27,   "MTAP24" },             /* Multi-time aggregation packet */ 
258         { 28,   "FU-A" },               /* Fragmentation unit */
259         { 29,   "FU-B" },               /* Fragmentation unit */
260         { 30,   "undefined" }, 
261         { 31,   "undefined" }, 
262         { 0,    NULL }
263 };
264
265
266 static const value_string h264_profile_idc_values[] = {
267         { 66,   "Baseline profile" },
268         { 77,   "Main profile" },
269         { 88,   "Extended profile" },
270         { 100,  "High profile" },
271         { 110,  "High 10 profile" },
272         { 122,  "High 4:2:2 profile" },
273         { 144,  "High 4:4:4 profile" },
274         { 0,    NULL }
275 };
276
277 static const value_string h264_level_bitrate_values[] = {
278         { 10,   "64kb/s" },
279         { 11,   "192kb/s" },
280         { 12,   "384kb/s" },
281         { 13,   "2 Mb/s" }, 
282         { 20,   "2 Mb/s" },
283         { 21,   "4 Mb/s" },
284         { 22,   "4 Mb/s" },
285         { 30,   "10 Mb/s" },
286         { 31,   "14 Mb/s" },
287         { 32,   "20 Mb/s" },
288         { 40,   "20 Mb/s" },
289         { 41,   "50 Mb/s" },
290         { 42,   "50 Mb/s" },
291         { 50,   "135 Mb/s" },
292         { 51,   "240 Mb/s" },   
293         { 0,    NULL }
294 };
295
296 static const value_string h264_nal_unit_type_vals[] = {
297         { 0,    "Unspecified" },
298         { 1,    "Coded slice of a non-IDR picture" },
299         { 2,    "Coded slice data partition A" },
300         { 3,    "Coded slice data partition B" },
301         { 4,    "Coded slice data partition C" },
302         { 5,    "Coded slice of an IDR picture" },
303         { 6,    "Supplemental enhancement information (SEI)" },
304         { 7,    "Sequence parameter set" },
305         { 8,    "Picture parameter set" },
306         { 9,    "Access unit delimiter" },
307         { 10,   "End of sequence" },
308         { 11,   "End of stream" },
309         { 12,   "Filler data" },
310         { 13,   "Sequence parameter set extension" },
311         { 14,   "Reserved" },
312         { 15,   "Reserved" },
313         { 16,   "Reserved" },
314         { 17,   "Reserved" },
315         { 18,   "Reserved" },
316         { 19,   "Coded slice of an auxiliary coded picture without partitioning" },
317         { 20,   "Reserved" },
318         { 21,   "Reserved" },
319         { 22,   "Reserved" },
320         { 23,   "Reserved" },
321         { 24,   "Unspecified" },
322         { 25,   "Unspecified" },
323         { 26,   "Unspecified" },
324         { 27,   "Unspecified" },
325         { 28,   "FU-A" },
326         { 29,   "Unspecified" },
327         { 30,   "Unspecified" },
328         { 31,   "Unspecified" },
329         { 0,    NULL }
330 };
331
332 static const value_string h264_slice_group_map_type_vals[] = {
333         { 0,    "Interleaved slice groups" },
334         { 1,    "Dispersed slice group mapping" },
335         { 2,    "One or more foreground slice groups and a leftover slice group" },
336         { 3,    "Changing slice groups" },
337         { 4,    "Changing slice groups" },
338         { 5,    "Changing slice groups" },
339         { 6,    "Explicit assignment of a slice group to each slice group map unit" },
340         { 0,    NULL }
341 };
342
343 /* Table 7-6 Name association to slice_type */
344 static const value_string h264_slice_type_vals[] = {
345         { 0,    "P (P slice)" },
346         { 1,    "B (B slice)" },
347         { 2,    "I (I slice)" },
348         { 3,    "SP (SP slice)" },
349         { 4,    "SI (SI slice)" },
350         { 5,    "P (P slice)" },
351         { 6,    "B (B slice)" },
352         { 7,    "I (I slice)" },
353         { 8,    "SP (SP slice)" },
354         { 9,    "SI (SI slice)" },
355         { 0,    NULL }
356 };
357 /* byte_aligned( ) is specified as follows.
358  * - If the current position in the bitstream is on a byte boundary, i.e.,
359  *       the next bit in the bitstream is the first bit in a byte,
360  *       the return value of byte_aligned( ) is equal to TRUE.
361  * - Otherwise, the return value of byte_aligned( ) is equal to FALSE.
362  */
363 static gboolean
364 h264_byte_aligned(int bit_offset)
365 {
366         if(bit_offset&0x3)
367                 return FALSE;
368
369         return TRUE;
370 }
371 /* Expect a tvb and a bit offset into the tvb
372  * returns the valu and bit_offset
373  */
374 #define cVALS(x) (const value_string*)(x)
375
376 guint32
377 dissect_h264_exp_golomb_code(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint *start_bit_offset, h264_golomb_descriptors descriptor)
378 /*(tvbuff_t *tvb, gint *start_bit_offset) */
379 {
380         gint            leading_zero_bits, bit_offset;
381         guint32         codenum, mask, value, tmp;
382         gint32          se_value=0;             
383         gint            b;
384         char *str;
385         int bit;
386         int i;
387         header_field_info *hf_field = NULL;
388
389         if(hf_index > -1)
390                 hf_field = proto_registrar_get_nth(hf_index);
391
392         bit_offset = *start_bit_offset;
393
394         /* prepare the string */
395         str=ep_alloc(256);
396         str[0]='\0';
397         for(bit=0;bit<((int)(bit_offset&0x07));bit++){
398                 if(bit&&(!(bit%4))){
399                         g_strlcat(str, " ", 256);
400                 }
401                 g_strlcat(str,".", 256);
402         }
403
404
405         leading_zero_bits = -1;
406         for( b = 0; !b; leading_zero_bits++ ){
407                 if(bit&&(!(bit%4))){
408                         g_strlcat(str, " ", 256);
409                 }
410                 if(bit&&(!(bit%8))){
411                         g_strlcat(str, " ", 256);
412                 }
413                 b = tvb_get_bits8(tvb, bit_offset, 1);
414                 if(b != 0){
415                         g_strlcat(str, "1", 256);
416                 } else {
417                         g_strlcat(str, "0", 256);
418                 }
419                 bit++;
420                 bit_offset++;
421         }
422
423         if(leading_zero_bits==0){
424                 codenum = 0;
425                 *start_bit_offset = bit_offset;
426                 for(;bit%8;bit++){
427                         if(bit&&(!(bit%4))){
428                                 g_strlcat(str, " ", 256);
429                         }
430                 g_strlcat(str,".", 256);
431                 }
432                 if(hf_field){
433                         g_strlcat(str," = ", 256);
434                         g_strlcat(str,hf_field->name, 256);
435                         switch (descriptor){
436                         case H264_SE_V:
437                                 /* if the syntax element is coded as se(v), 
438                                  * the value of the syntax element is derived by invoking the
439                                  * mapping process for signed Exp-Golomb codes as specified in 
440                                  * subclause 9.1.1 with codeNum as the input.
441                                  */
442                                 if(hf_field->type==FT_INT32){
443                                         if (hf_field->strings) {
444                                                 proto_tree_add_int_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
445                                                           "%s: %s (%d)",
446                                                           str,
447                                                           val_to_str(codenum, cVALS(hf_field->strings), "Unknown "),
448                                                           codenum);
449                                         }else{
450                                                 switch(hf_field->display){
451                                                         case BASE_DEC:
452                                                                 proto_tree_add_int_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
453                                                                  "%s: %d",
454                                                                           str,
455                                                                           codenum);
456                                                                 break;
457                                                         default:
458                                                                 DISSECTOR_ASSERT_NOT_REACHED();
459                                                                 break;
460                                                 }
461                                         }
462                                 }
463                                 return codenum;
464                         default:
465                                 break;
466                         }
467                         if(hf_field->type==FT_UINT32){
468                                 if (hf_field->strings) {
469                                         proto_tree_add_uint_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
470                                                   "%s: %s (%u)",
471                                                   str,
472                                                   val_to_str(codenum, cVALS(hf_field->strings), "Unknown "),
473                                                   codenum);
474                                 }else{
475                                         switch(hf_field->display){
476                                                 case BASE_DEC:
477                                                         proto_tree_add_uint_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
478                                                          "%s: %u",
479                                                                   str,
480                                                                   codenum);
481                                                         break;
482                                                 case BASE_HEX:
483                                                         proto_tree_add_uint_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
484                                                      "%s: 0x%x",
485                                                                   str,
486                                                                   codenum);
487                                                         break;
488                                                 default:
489                                                         DISSECTOR_ASSERT_NOT_REACHED();
490                                                         break;
491                                         }
492                                 }
493                         }else{
494                                 /* Only allow guint32 */
495                                 DISSECTOR_ASSERT_NOT_REACHED();
496                         }
497                 }
498                 return codenum;
499         }
500
501         /*
502         Syntax elements coded as ue(v), me(v), or se(v) are Exp-Golomb-coded. Syntax elements coded as te(v) are truncated
503         Exp-Golomb-coded. The parsing process for these syntax elements begins with reading the bits starting at the current
504         location in the bitstream up to and including the first non-zero bit, and counting the number of leading bits that are
505         equal to 0. This process is specified as follows:
506         leadingZeroBits = -1;
507         for( b = 0; !b; leadingZeroBits++ )
508         b = read_bits( 1 )
509         The variable codeNum is then assigned as follows:
510         codeNum = 2leadingZeroBits - 1 + read_bits( leadingZeroBits )
511         where the value returned from read_bits( leadingZeroBits ) is interpreted as a binary representation of an unsigned
512         integer with most significant bit written first.
513         */
514         codenum = 1;
515         codenum = codenum << leading_zero_bits;
516         mask = codenum>>1;
517         if (leading_zero_bits > 8)
518                 value = tvb_get_bits16(tvb, bit_offset,leading_zero_bits, FALSE);
519         else
520                 value = tvb_get_bits8(tvb, bit_offset,leading_zero_bits );
521         codenum = (codenum-1) + value; 
522         bit_offset = bit_offset + leading_zero_bits;
523
524         /* read the bits for the int */
525         for(i=0;i<leading_zero_bits;i++){
526                 if(bit&&(!(bit%4))){
527                         g_strlcat(str, " ", 256);
528                 }
529                 if(bit&&(!(bit%8))){
530                         g_strlcat(str, " ", 256);
531                 }
532                 bit++;
533                 tmp = value & mask;
534                 if(tmp != 0){
535                         g_strlcat(str, "1", 256);
536                 } else {
537                         g_strlcat(str, "0", 256);
538                 }
539                 mask = mask>>1;
540         }
541         for(;bit%8;bit++){
542                 if(bit&&(!(bit%4))){
543                         g_strlcat(str, " ", 256);
544                 }
545                 g_strlcat(str,".", 256);
546         }
547
548         switch (descriptor){
549         case H264_SE_V:
550                 /* if the syntax element is coded as se(v), 
551                  * the value of the syntax element is derived by invoking the
552                  * mapping process for signed Exp-Golomb codes as specified in 
553                  * subclause 9.1.1 with codeNum as the input.
554                  *              k+1 
555                  * (-1)    Ceil( k/2 )
556                  */
557                 se_value = (codenum + 1) >> 1;
558                 if (!(se_value & 1)){
559                         se_value =  - se_value;
560                 }
561                 break;
562         default:
563                 break;
564         }
565
566         if(hf_field){
567                 g_strlcat(str," = ", 256);
568                 g_strlcat(str,hf_field->name, 256);
569                 switch (descriptor){
570                 case H264_SE_V:
571                         g_strlcat(str,"(se(v))", 256);
572                         /* if the syntax element is coded as se(v), 
573                          * the value of the syntax element is derived by invoking the
574                          * mapping process for signed Exp-Golomb codes as specified in 
575                          * subclause 9.1.1 with codeNum as the input.
576                          */
577                         break;
578                 default:
579                 break;
580                 }
581                 if((hf_field->type==FT_UINT32)&&(descriptor==H264_UE_V)){
582                         if (hf_field->strings) {
583                                 proto_tree_add_uint_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
584                                                   "%s: %s (%u)",
585                                                   str,
586                                                   val_to_str(codenum, cVALS(hf_field->strings), "Unknown "),
587                                                   codenum);
588                         }else{
589                                 switch(hf_field->display){
590                                         case BASE_DEC:
591                                                 proto_tree_add_uint_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
592                                                  "%s: %u",
593                                                           str,
594                                                           codenum);
595                                                 break;
596                                         case BASE_HEX:
597                                                 proto_tree_add_uint_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
598                                              "%s: 0x%x",
599                                                           str,
600                                                           codenum);
601                                                 break;
602                                         default:
603                                                 DISSECTOR_ASSERT_NOT_REACHED();
604                                                 break;
605                                 }
606                         }
607                 }else if((hf_field->type==FT_INT32)&&(descriptor==H264_SE_V)){
608                         if (hf_field->strings) {
609                                 proto_tree_add_int_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
610                                                   "%s: %s (%d)",
611                                                   str,
612                                                   val_to_str(codenum, cVALS(hf_field->strings), "Unknown "),
613                                                   se_value);
614                         }else{
615                                 switch(hf_field->display){
616                                         case BASE_DEC:
617                                                 proto_tree_add_int_format(tree, hf_index, tvb, bit_offset>>3, 1, codenum,
618                                                  "%s: %d",
619                                                           str,
620                                                           se_value);
621                                                 break;
622                                         default:
623                                                 DISSECTOR_ASSERT_NOT_REACHED();
624                                                 break;
625                                 }
626                         }
627                         *start_bit_offset = bit_offset;
628                         return se_value;
629
630                 }else{
631                         /* Only allow guint32 */
632                         DISSECTOR_ASSERT_NOT_REACHED();
633                 }
634         }
635
636         *start_bit_offset = bit_offset;
637         return codenum;
638
639 }
640
641 /* This funktion is adapted to parsing NAL units from SDP data where the
642  * base64 coding may add extra padding
643  */
644
645 static gboolean
646 more_rbsp_data(proto_tree *tree _U_, tvbuff_t *tvb, packet_info *pinfo _U_, gint bit_offset)
647 {
648
649         int offset;
650         int remaining_length;
651         int last_one_bit;
652         guint8 b = 0;
653
654         /* XXX might not be the best way of doing things but:
655          * Serch from the end of the tvb for the first '1' bit
656          * assuming that its's the RTBSP stop bit
657          */
658
659         /* Set offset to the byte we are treating */
660         offset = bit_offset>>3;
661         remaining_length = tvb_length_remaining(tvb,offset);
662         /* If there is more then 2 bytes left there *should* be more data */
663         if(remaining_length>2){
664                 return TRUE;
665         }
666         /* Start from last bit */
667         last_one_bit = (tvb_length(tvb) << 3);
668
669         for( b = 0; !b; ){
670                 last_one_bit--;
671                 b = tvb_get_bits8(tvb, last_one_bit, 1);
672         }
673
674         if( last_one_bit == bit_offset){
675                 return FALSE;
676         }
677
678         return TRUE;
679 }
680
681 static int
682 dissect_h264_rbsp_trailing_bits(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint bit_offset)
683 {
684         gint remaining_bits=0;
685
686         proto_tree_add_bits_item(tree, hf_h264_rbsp_stop_bit, tvb, bit_offset, 1, FALSE);
687         bit_offset++;
688
689         if((bit_offset&0x7)!=0){
690                 remaining_bits = 8 - (bit_offset&0x7);
691                 proto_tree_add_bits_item(tree, hf_h264_rbsp_trailing_bits, tvb, bit_offset, remaining_bits, FALSE);
692         }
693
694         return bit_offset+remaining_bits;
695 }
696
697 /*
698  * 7.3.3 Slice header syntax
699  * slice_header( )
700  * XXX Just parse a few bytes
701  */
702 static int
703 dissect_h264_slice_header(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint bit_offset)
704 {
705         /* first_mb_in_slice 2 ue(v) */
706         dissect_h264_exp_golomb_code(tree, hf_h264_first_mb_in_slice, tvb, &bit_offset, H264_UE_V);
707
708         /* slice_type 2 ue(v) */
709         dissect_h264_exp_golomb_code(tree, hf_h264_slice_type, tvb, &bit_offset, H264_UE_V);
710         
711         /* pic_parameter_set_id 2 ue(v) */
712         dissect_h264_exp_golomb_code(tree, hf_h264_pic_parameter_set_id, tvb, &bit_offset, H264_UE_V);
713         
714         /* frame_num 2 u(v) */
715         /*  
716          * represented by log2_max_frame_num_minus4 + 4 bits in
717          * the bitstream
718          * proto_tree_add_bits_item(tree, hf_h264_frame_num, tvb, bit_offset, 4, FALSE);
719          */
720         
721
722         return bit_offset;
723 }
724
725
726 /* 7.3.2.1.1 Scaling list syntax 
727  * 
728  * scaling_list( scalingList, sizeOfScalingList, useDefaultScalingMatrixFlag )
729  */
730 /*
731 static int
732 dissect_h264_scaling_list(proto_tree *tree, tvbuff_t *tvb, gint bit_offset, int hf_index_scalinglist,
733                                                   guint8 sizeOfScalingList, int hf_index_usedefaultscalingmatrixflag)
734 {
735
736         guint8 lastScale = 8;
737         guint8 nextScale = 8:
738         guint8 delta_scale;
739
740         for( j = 0; j < sizeOfScalingList; j++ ) {
741           if( nextScale != 0 ) {
742                   / delta_scale 0 | 1 se(v) /
743                   delta_scale = dissect_h264_exp_golomb_code(tree, hf_h264_delta_scale, tvb, &bit_offset);
744                   nextScale = ( lastScale + delta_scale + 256 ) % 256;
745                   useDefaultScalingMatrixFlag = ( j == 0 && nextScale == 0 );
746         }
747         scalingList[ j ] = ( nextScale == 0 ) ? lastScale : nextScale
748         lastScale = scalingList[ j ]
749         }
750 }
751 */
752 /* E.1.2 HRD parameters syntax */
753 static int
754 dissect_h264_hrd_parameters(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint bit_offset)
755 {
756         guint8 cpb_cnt_minus1;
757         int SchedSelIdx;
758
759
760         /* cpb_cnt_minus1 0 ue(v) */
761         cpb_cnt_minus1 = dissect_h264_exp_golomb_code(tree, hf_h264_cpb_cnt_minus1, tvb, &bit_offset, H264_UE_V);
762
763         /* bit_rate_scale 0 u(4) */
764         proto_tree_add_bits_item(tree, hf_h264_bit_rate_scale, tvb, bit_offset, 4, FALSE);
765         bit_offset = bit_offset + 4;
766
767         /* cpb_size_scale 0 u(4) */
768         proto_tree_add_bits_item(tree, hf_h264_cpb_size_scale, tvb, bit_offset, 4, FALSE);
769         bit_offset = bit_offset + 4;
770         /* for( SchedSelIdx = 0; SchedSelIdx <= cpb_cnt_minus1; SchedSelIdx++ ) { */
771         for( SchedSelIdx = 0; SchedSelIdx <= cpb_cnt_minus1; SchedSelIdx++ ) {
772
773                 /* bit_rate_value_minus1[ SchedSelIdx ] 0 ue(v) */
774                 dissect_h264_exp_golomb_code(tree, hf_h264_bit_rate_value_minus1, tvb, &bit_offset, H264_UE_V);
775
776                 /* cpb_size_value_minus1[ SchedSelIdx ] 0 ue(v)*/
777                 dissect_h264_exp_golomb_code(tree, hf_h264_cpb_size_value_minus1, tvb, &bit_offset, H264_UE_V);
778
779                 /* cbr_flag[ SchedSelIdx ] 0 u(1) */
780                 proto_tree_add_bits_item(tree, hf_h264_cbr_flag, tvb, bit_offset, 1, FALSE);
781                 bit_offset++;
782         }
783         /* initial_cpb_removal_delay_length_minus1 0 u(5) */
784         proto_tree_add_bits_item(tree, hf_h264_initial_cpb_removal_delay_length_minus1, tvb, bit_offset, 5, FALSE);
785         bit_offset = bit_offset + 5;
786
787         /* cpb_removal_delay_length_minus1 0 u(5) */
788         proto_tree_add_bits_item(tree, hf_h264_cpb_removal_delay_length_minus1, tvb, bit_offset, 5, FALSE);
789         bit_offset = bit_offset + 5;
790
791         /* dpb_output_delay_length_minus1 0 u(5) */
792         proto_tree_add_bits_item(tree, hf_h264_dpb_output_delay_length_minus11, tvb, bit_offset, 5, FALSE);
793         bit_offset = bit_offset + 5;
794
795         /* time_offset_length 0 u(5) */
796         proto_tree_add_bits_item(tree, hf_h264_time_offset_length, tvb, bit_offset, 5, FALSE);
797         bit_offset = bit_offset + 5;
798
799         return bit_offset;
800 }
801
802 #define EXTENDED_SAR 255
803
804 /* E.1.1 VUI parameters syntax */
805 static int
806 dissect_h264_vui_parameters(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint bit_offset)
807 {
808
809         guint8 aspect_ratio_info_present_flag, aspect_ratio_idc, overscan_info_present_flag;
810         guint8 video_signal_type_present_flag, colour_description_present_flag, chroma_loc_info_present_flag;
811         guint8 timing_info_present_flag, nal_hrd_parameters_present_flag, vcl_hrd_parameters_present_flag;
812         guint8 bitstream_restriction_flag;
813
814         /* vui_parameters( ) {
815          * aspect_ratio_info_present_flag 0 u(1)
816          */
817         aspect_ratio_info_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
818         proto_tree_add_bits_item(tree, hf_h264_aspect_ratio_info_present_flag, tvb, bit_offset, 1, FALSE);
819         bit_offset++;
820
821         if( aspect_ratio_info_present_flag ) {
822                 /* aspect_ratio_idc 0 u(8) */
823                 aspect_ratio_idc = tvb_get_bits8(tvb, bit_offset, 8);
824                 proto_tree_add_bits_item(tree, hf_h264_aspect_ratio_idc, tvb, bit_offset, 8, FALSE);
825                 bit_offset = bit_offset + 8;
826
827                 if( aspect_ratio_idc == EXTENDED_SAR ) {
828                         /* sar_width 0 u(16) */
829                         proto_tree_add_bits_item(tree, hf_h264_sar_width, tvb, bit_offset, 16, FALSE);
830                         bit_offset = bit_offset + 16;
831                 
832                         /* sar_height 0 u(16) */
833                         proto_tree_add_bits_item(tree, hf_h264_sar_height, tvb, bit_offset, 16, FALSE);
834                         bit_offset = bit_offset + 16;
835                 }
836         }
837         /* overscan_info_present_flag 0 u(1) */
838         overscan_info_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
839         proto_tree_add_bits_item(tree, hf_h264_overscan_info_present_flag, tvb, bit_offset, 1, FALSE);
840         bit_offset++;
841         
842         if( overscan_info_present_flag ){
843                 /* overscan_appropriate_flag 0 u(1) */
844                 proto_tree_add_bits_item(tree, hf_h264_overscan_appropriate_flag, tvb, bit_offset, 1, FALSE);
845                 bit_offset++;
846         }
847         
848         /* video_signal_type_present_flag 0 u(1) */
849         video_signal_type_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
850         proto_tree_add_bits_item(tree, hf_h264_video_signal_type_present_flag, tvb, bit_offset, 1, FALSE);
851         bit_offset++;
852         
853         if( video_signal_type_present_flag ) {
854                 /* video_format 0 u(3) > */
855                 proto_tree_add_bits_item(tree, hf_h264_video_format, tvb, bit_offset, 3, FALSE);
856                 bit_offset = bit_offset + 3;
857         
858                 /* video_full_range_flag 0 u(1)*/
859                 proto_tree_add_bits_item(tree, hf_h264_video_full_range_flag, tvb, bit_offset, 1, FALSE);
860                 bit_offset++;
861                 
862                 /* colour_description_present_flag 0 u(1) */
863                 colour_description_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
864                 proto_tree_add_bits_item(tree, hf_h264_colour_description_present_flag, tvb, bit_offset, 1, FALSE);
865                 bit_offset++;
866                 
867                 if( colour_description_present_flag ) {
868                         /* colour_primaries 0 u(8) */
869                         proto_tree_add_bits_item(tree, hf_h264_colour_primaries, tvb, bit_offset, 8, FALSE);
870                         bit_offset = bit_offset + 8;
871
872                         /* transfer_characteristics 0 u(8) */
873                         proto_tree_add_bits_item(tree, hf_h264_transfer_characteristics, tvb, bit_offset, 8, FALSE);
874                         bit_offset = bit_offset + 8;
875
876                         /* matrix_coefficients 0 u(8)*/
877                         proto_tree_add_bits_item(tree, hf_h264_matrix_coefficients, tvb, bit_offset, 8, FALSE);
878                         bit_offset = bit_offset + 8;
879                 }
880         }
881
882         /* chroma_loc_info_present_flag 0 u(1) */
883         chroma_loc_info_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
884         proto_tree_add_bits_item(tree, hf_h264_chroma_loc_info_present_flag, tvb, bit_offset, 1, FALSE);
885         bit_offset++;
886
887         if( chroma_loc_info_present_flag ) {
888                 /* chroma_sample_loc_type_top_field 0 ue(v) */
889                 dissect_h264_exp_golomb_code(tree, hf_h264_chroma_sample_loc_type_top_field, tvb, &bit_offset, H264_UE_V);
890
891                 /* chroma_sample_loc_type_bottom_field 0 ue(v) */
892                 dissect_h264_exp_golomb_code(tree, hf_h264_chroma_sample_loc_type_bottom_field, tvb, &bit_offset, H264_UE_V);
893         }
894
895         /* timing_info_present_flag 0 u(1) */
896         timing_info_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
897         proto_tree_add_bits_item(tree, hf_h264_timing_info_present_flag, tvb, bit_offset, 1, FALSE);
898         bit_offset++;
899
900         if( timing_info_present_flag ) {
901                 /* num_units_in_tick 0 u(32) */
902                 proto_tree_add_bits_item(tree, hf_h264_num_units_in_tick, tvb, bit_offset, 32, FALSE);
903                 bit_offset = bit_offset + 32;
904
905                 /* time_scale 0 u(32) */
906                 proto_tree_add_bits_item(tree, hf_h264_time_scale, tvb, bit_offset, 32, FALSE);
907                 bit_offset = bit_offset + 32;
908                 
909                 /* fixed_frame_rate_flag 0 u(1) */
910                 proto_tree_add_bits_item(tree, hf_h264_fixed_frame_rate_flag, tvb, bit_offset, 1, FALSE);
911                 bit_offset++;
912         }
913         /* nal_hrd_parameters_present_flag 0 u(1) */
914         nal_hrd_parameters_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
915         proto_tree_add_bits_item(tree, hf_h264_nal_hrd_parameters_present_flag, tvb, bit_offset, 1, FALSE);
916         bit_offset++;
917
918         if( nal_hrd_parameters_present_flag ){
919                 /* hrd_parameters( ) */
920                 bit_offset = dissect_h264_hrd_parameters(tree, tvb, pinfo, bit_offset);
921         }
922
923         /* vcl_hrd_parameters_present_flag 0 u(1) */
924         vcl_hrd_parameters_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
925         proto_tree_add_bits_item(tree, hf_h264_vcl_hrd_parameters_present_flag, tvb, bit_offset, 1, FALSE);
926         bit_offset++;
927
928         if( vcl_hrd_parameters_present_flag ){
929                 /* hrd_parameters( ) */
930                 bit_offset = dissect_h264_hrd_parameters(tree, tvb, pinfo, bit_offset);
931         }
932         if( nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag ){
933                 /* low_delay_hrd_flag 0 u(1) */
934                 proto_tree_add_bits_item(tree, hf_h264_low_delay_hrd_flag, tvb, bit_offset, 1, FALSE);
935                 bit_offset++;
936         }
937         /* pic_struct_present_flag 0 u(1) */
938         proto_tree_add_bits_item(tree, hf_h264_pic_struct_present_flag, tvb, bit_offset, 1, FALSE);
939         bit_offset++;
940
941         /* bitstream_restriction_flag 0 u(1) */
942         bitstream_restriction_flag = tvb_get_bits8(tvb, bit_offset, 1);
943         proto_tree_add_bits_item(tree, hf_h264_bitstream_restriction_flag, tvb, bit_offset, 1, FALSE);
944         bit_offset++;
945
946         if( bitstream_restriction_flag ) {
947                 /* motion_vectors_over_pic_boundaries_flag 0 u(1) */
948                 proto_tree_add_bits_item(tree, hf_h264_motion_vectors_over_pic_boundaries_flag, tvb, bit_offset, 1, FALSE);
949                 bit_offset++;
950
951                 /* max_bytes_per_pic_denom 0 ue(v) */
952                 dissect_h264_exp_golomb_code(tree, hf_h264_max_bytes_per_pic_denom, tvb, &bit_offset, H264_UE_V);
953                 
954                 /* max_bits_per_mb_denom 0 ue(v) */
955                 dissect_h264_exp_golomb_code(tree, hf_h264_max_bits_per_mb_denom, tvb, &bit_offset, H264_UE_V);
956                 
957                 /* log2_max_mv_length_horizontal 0 ue(v) */
958                 dissect_h264_exp_golomb_code(tree, hf_h264_log2_max_mv_length_horizontal, tvb, &bit_offset, H264_UE_V);
959                 
960                 /* log2_max_mv_length_vertical 0 ue(v) */
961                 dissect_h264_exp_golomb_code(tree, hf_h264_log2_max_mv_length_vertical, tvb, &bit_offset, H264_UE_V);
962                 
963                 /* num_reorder_frames 0 ue(v) */
964                 dissect_h264_exp_golomb_code(tree, hf_h264_num_reorder_frames, tvb, &bit_offset, H264_UE_V);
965                 
966                 /* max_dec_frame_buffering 0 ue(v) */
967                 dissect_h264_exp_golomb_code(tree, hf_h264_max_dec_frame_buffering, tvb, &bit_offset, H264_UE_V);
968         }
969
970         return bit_offset;
971 }
972
973
974 /* Used To dissect SDP parameter (H.264)profile */
975 void
976 dissect_h264_profile(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
977 {
978         proto_item *item, *level_item;
979         proto_tree *h264_profile_tree;
980         gint    offset = 0;
981         guint8  constraint_set3_flag;
982         guint32 level_idc;
983
984         item = proto_tree_add_item(tree, hf_h264_profile, tvb, offset, -1, FALSE);
985         h264_profile_tree = proto_item_add_subtree(item, ett_h264_profile);
986
987         proto_tree_add_item(h264_profile_tree, hf_h264_profile_idc, tvb, offset, 1, FALSE);
988         offset++;
989         
990         constraint_set3_flag = (tvb_get_guint8(tvb,offset)&0x10)>>4;
991         proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set0_flag, tvb, offset, 1, FALSE);
992         proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set1_flag, tvb, offset, 1, FALSE);
993         proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set2_flag, tvb, offset, 1, FALSE);
994         proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set3_flag, tvb, offset, 1, FALSE);
995         proto_tree_add_item(h264_profile_tree, hf_h264_reserved_zero_4bits, tvb, offset, 1, FALSE);
996         offset++;
997
998         /* A level to which the bitstream conforms shall be indicated by the syntax element level_idc as follows.
999          *      - If level_idc is equal to 11 and constraint_set3_flag is equal to 1, the indicated level is level 1b.
1000          *      - Otherwise (level_idc is not equal to 11 or constraint_set3_flag is not equal to 1), level_idc shall
1001          *    be set equal to a value of ten times the level number specified in Table A-1 and constraint_set3_flag
1002          *    shall be set equal to 0.
1003          */
1004
1005         level_idc = tvb_get_guint8(tvb,offset);
1006         level_item = proto_tree_add_item(h264_profile_tree, hf_h264_level_idc, tvb, offset, 1, FALSE);
1007         if((level_idc==11)&&(constraint_set3_flag==1)){
1008                 proto_item_append_text(level_item," [Level 1b (128kb/s)]");
1009         }else{
1010                 proto_item_append_text(level_item," [Level %.1f %s]",((double)level_idc/10),val_to_str(level_idc, h264_level_bitrate_values, "Unknown "));
1011         }
1012
1013 }
1014
1015 /*
1016  * 7.3.2.8 Slice layer without partitioning RBSP syntax
1017  * slice_layer_without_partitioning_rbsp( )
1018  */
1019
1020 static void
1021 dissect_h264_slice_layer_without_partitioning_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint offset)
1022 {
1023         gint bit_offset;
1024
1025         bit_offset = offset <<3;
1026
1027         /* slice_header( ) 2 */
1028         bit_offset = dissect_h264_slice_header(tree, tvb, pinfo, bit_offset);
1029         proto_tree_add_text(tree, tvb, bit_offset>>3, -1, "[Not decoded yet]");
1030         return; 
1031         /* slice_data( ) * all categories of slice_data( ) syntax * 2 | 3 | 4 */
1032         /* rbsp_slice_trailing_bits( ) */
1033
1034 }
1035
1036 /*
1037  * 7.3.2.9.1 Slice data partition A RBSP syntax
1038  * slice_data_partition_a_layer_rbsp( )
1039  */
1040 static void
1041 dissect_h264_slice_data_partition_a_layer_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1042 {
1043         gint bit_offset;
1044
1045         bit_offset = offset <<3;
1046
1047         /* slice_header( ) 2 */
1048         bit_offset = dissect_h264_slice_header(tree, tvb, pinfo, bit_offset);
1049
1050         /* slice_id All ue(v) */
1051         dissect_h264_exp_golomb_code(tree, hf_h264_slice_id, tvb, &bit_offset, H264_UE_V);
1052         proto_tree_add_text(tree, tvb, bit_offset>>3, -1, "[Not decoded yet]");
1053         return; 
1054         /* slice_data( ) * only category 2 parts of slice_data( ) syntax * 2*/
1055         /* rbsp_slice_trailing_bits( )*/
1056
1057 }
1058
1059 /* 
1060  * 7.3.2.9.2 Slice data partition B RBSP syntax
1061  * slice_data_partition_b_layer_rbsp(
1062  */
1063 static void
1064 dissect_h264_slice_data_partition_b_layer_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1065 {
1066         gint bit_offset;
1067
1068         bit_offset = offset <<3;
1069
1070         /* slice_id All ue(v) */
1071         dissect_h264_exp_golomb_code(tree, hf_h264_slice_id, tvb, &bit_offset, H264_UE_V);
1072         /* if( redundant_pic_cnt_present_flag ) */
1073         /* redundant_pic_cnt All ue(v) */
1074         /* slice_data( ) * only category 3 parts of slice_data( ) syntax * 3 */
1075         /* rbsp_slice_trailing_bits( ) 3 */
1076         proto_tree_add_text(tree, tvb, bit_offset>>3, -1, "[Not decoded yet]");
1077
1078 }
1079
1080 /*
1081  * 7.3.2.9.3 Slice data partition C RBSP syntax
1082  * slice_data_partition_c_layer_rbsp( )
1083  */
1084 static void
1085 dissect_h264_slice_data_partition_c_layer_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1086 {
1087         gint bit_offset;
1088
1089         bit_offset = offset <<3;
1090
1091         /* slice_id All ue(v) */
1092         dissect_h264_exp_golomb_code(tree, hf_h264_slice_id, tvb, &bit_offset, H264_UE_V);
1093         /* if( redundant_pic_cnt_present_flag ) */
1094         /* redundant_pic_cnt All ue(v) */
1095         /* slice_data( ) * only category 4 parts of slice_data( ) syntax * 4 */
1096         /* rbsp_slice_trailing_bits( ) 4 */
1097         proto_tree_add_text(tree, tvb, bit_offset>>3, -1, "[Not decoded yet]");
1098
1099 }
1100 /* D.1.6 User data unregistered SEI message syntax */
1101
1102 static int
1103 h264_user_data_unregistered(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint bit_offset, guint32 payloadSize)
1104 {
1105         /* user_data_unregistered( payloadSize ) { C Descriptor */
1106         /* uuid_iso_iec_11578 5 u(128)
1107          * uuid_iso_iec_11578 shall have a value specified as a UUID 
1108          * according to the procedures of ISO/IEC 11578:1996 Annex A.
1109          */
1110         proto_tree_add_text(tree, tvb, bit_offset>>3, 16, "uuid_iso_iec_1157");
1111         bit_offset+=128;
1112         /*      for( i = 16; i < payloadSize; i++ )
1113          *      user_data_payload_byte 5 b(8)
1114          */
1115         proto_tree_add_text(tree, tvb, bit_offset>>3, payloadSize-16, "user_data_payload");
1116         bit_offset+=(payloadSize-16)<<3;
1117
1118                 return bit_offset;
1119 }
1120 /* D.1 SEI payload syntax */
1121 static const value_string h264_sei_payload_vals[] = {
1122         { 0,    "buffering_period" },
1123         { 1,    "pic_timing" },
1124         { 2,    "pan_scan_rect" },
1125         { 3,    "filler_payload" },
1126         { 4,    "user_data_registered_itu_t_t35" },
1127         { 5,    "user_data_unregistered" },
1128         { 6,    "recovery_point" },
1129         { 7,    "dec_ref_pic_marking_repetition" },
1130         { 8,    "spare_pic" },
1131         { 9,    "scene_inf)" },
1132         { 10,   "sub_seq_info)" },
1133         { 11,   "sub_seq_layer_characteristics" },
1134         { 12,   "sub_seq_characteristics" },
1135         { 13,   "full_frame_freeze_release" },
1136         { 14,   "full_frame_freeze_release" },
1137         { 15,   "full_frame_snapshot" },
1138         { 16,   "progressive_refinement_segment_start" },
1139         { 17,   "progressive_refinement_segment_end" },
1140         { 18,   "motion_constrained_slice_group_set" },
1141         { 19,   "film_grain_characteristics)" },
1142         { 20,   "deblocking_filter_display_preference)" },
1143         { 21,   "stereo_video_info)" },
1144         { 22,   "reserved_sei_message)" },
1145         { 0,    NULL }
1146 };
1147
1148 static int
1149 h264_sei_payload(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint bit_offset, guint32 payloadType, guint32 payloadSize)
1150 {
1151         /* sei_payload( payloadType, payloadSize ) { C Descriptor */
1152         if( payloadType == 0 ){
1153                 /* buffering_period( payloadSize ) 5 */
1154                 bit_offset = bit_offset +(payloadSize<<3);
1155 #if 0
1156         }else if( payloadType == 1 ){
1157                 /* pic_timing( payloadSize ) 5 */
1158         }else if( payloadType == 2 ){
1159                 /* pan_scan_rect( payloadSize ) 5 */
1160         }else if( payloadType == 3 ){
1161                 /* filler_payload( payloadSize ) 5 */
1162         }else if( payloadType == 4 ){
1163                 /* user_data_registered_itu_t_t35( payloadSize ) 5 */
1164 #endif
1165         }else if( payloadType == 5 ){
1166                 /* user_data_unregistered( payloadSize ) 5 */
1167                 bit_offset = h264_user_data_unregistered( tree, tvb, pinfo, bit_offset, payloadSize);
1168         }else if( payloadType == 6 ){
1169                 /* recovery_point( payloadSize ) 5 */
1170                 bit_offset = bit_offset +(payloadSize<<3);
1171         }else if( payloadType == 7 ){
1172                 /* dec_ref_pic_marking_repetition( payloadSize ) 5 */
1173                 bit_offset = bit_offset +(payloadSize<<3);
1174         }
1175 #if 0
1176 else if( payloadType == 8 )
1177 spare_pic( payloadSize ) 5
1178 else if( payloadType == 9 )
1179 scene_info( payloadSize ) 5
1180 else if( payloadType == 10 )
1181 sub_seq_info( payloadSize ) 5
1182 else if( payloadType == 11 )
1183 sub_seq_layer_characteristics( payloadSize ) 5
1184 else if( payloadType == 12 )
1185 sub_seq_characteristics( payloadSize ) 5
1186 else if( payloadType == 13 )
1187 full_frame_freeze( payloadSize ) 5
1188 else if( payloadType == 14 )
1189 full_frame_freeze_release( payloadSize ) 5
1190 else if( payloadType == 15 )
1191 full_frame_snapshot( payloadSize ) 5
1192 else if( payloadType == 16 )
1193 progressive_refinement_segment_start( payloadSize ) 5
1194 else if( payloadType == 17 )
1195 progressive_refinement_segment_end( payloadSize ) 5
1196 else if( payloadType == 18 )
1197 motion_constrained_slice_group_set( payloadSize ) 5
1198 else if( payloadType == 19 )
1199 film_grain_characteristics( payloadSize ) 5
1200 else if( payloadType == 20 )
1201 deblocking_filter_display_preference( payloadSize ) 5
1202 else if( payloadType == 21 )
1203 stereo_video_info( payloadSize ) 5
1204 else
1205 reserved_sei_message( payloadSize ) 5
1206         return bit_offset;
1207 #endif
1208         if( !h264_byte_aligned(bit_offset)){
1209                 /* bit_equal_to_one / * equal to 1 * / 5 f(1) */
1210                 /* TODO:Display the filler and, error if not 1 ?? */
1211                 bit_offset++;
1212                 while( !h264_byte_aligned(bit_offset)){
1213                         /* bit_equal_to_zero / * equal to 0 * / 5 f(1) */
1214                         /* TODO:Display the filler and, error if not 0 ?? */
1215                         bit_offset++;
1216                 }
1217         }
1218         return bit_offset;
1219 }
1220
1221 /*
1222  * 7.3.2.3.1 Supplemental enhancement information message syntax
1223  */
1224 static gint
1225 dissect_h264_sei_message(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint bit_offset)
1226 {
1227         /* sei_message( ) { C Descriptor */
1228         guint32 payloadType = 0, payloadSize;
1229         gint start_bit_offset, length;
1230
1231         start_bit_offset = bit_offset;
1232
1233         /* while( next_bits( 8 ) == 0xFF ) { */
1234         while( tvb_get_bits8(tvb, bit_offset, 8) == 0xFF ) {
1235                 /* ff_byte / * equal to 0xFF * / 5 f(8) */
1236                 payloadType += 255;
1237                 bit_offset+=8;
1238         }
1239         /* last_payload_type_byte 5 u(8) */
1240         payloadType += tvb_get_bits8(tvb, bit_offset, 8);
1241         bit_offset+=8;
1242         length = (bit_offset - start_bit_offset)>>3;
1243
1244         proto_tree_add_uint(tree, hf_h264_payloadtype, tvb, start_bit_offset>>3, length, payloadType);
1245
1246         payloadSize = 0;
1247         start_bit_offset = bit_offset;
1248         /* while( next_bits( 8 ) == 0xFF ) { */
1249         while( tvb_get_bits8(tvb, bit_offset, 8) == 0xFF ) {
1250                 /* ff_byte / * equal to 0xFF * / 5 f(8) */
1251                 payloadSize += 255;
1252                 bit_offset+=8;
1253         }
1254         /* last_payload_size_byte 5 u(8) */
1255         /* payloadSize += last_payload_size_byte */
1256         payloadSize += tvb_get_bits8(tvb, bit_offset, 8);
1257         bit_offset+=8;
1258         length = (bit_offset - start_bit_offset)>>3;
1259         proto_tree_add_uint(tree, hf_h264_payloadsize, tvb, start_bit_offset>>3, length, payloadSize);
1260
1261         /*sei_payload( payloadType, payloadSize ) 5 */
1262         bit_offset = h264_sei_payload( tree, tvb, pinfo, bit_offset, payloadType, payloadSize);
1263         return bit_offset;
1264 }
1265 /*
1266  * 7.3.2.3 Supplemental enhancement information RBSP syntax
1267  * sei_rbsp( )
1268  */
1269 static void
1270 dissect_h264_sei_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1271 {
1272         gint bit_offset;
1273
1274         bit_offset = offset <<3;
1275         /* do */
1276         /* sei_message( ) 5*/
1277         bit_offset = dissect_h264_sei_message( tree, tvb, pinfo, bit_offset);
1278
1279         /* while( more_rbsp_data( ) )
1280          * If there is more data in an RBSP before rbsp_trailing_bits( ), 
1281          * the return value of more_rbsp_data( ) is equal to TRUE.
1282          */
1283         /* rbsp_trailing_bits( ) 5 */
1284         bit_offset = dissect_h264_rbsp_trailing_bits(tree, tvb, pinfo, bit_offset);
1285
1286 }
1287
1288 /* Ref 7.3.2.1 Sequence parameter set RBSP syntax */
1289 static int
1290 dissect_h264_seq_parameter_set_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint offset)
1291 {
1292         proto_item *level_item;
1293         gint bit_offset;
1294         guint8  constraint_set3_flag;
1295         guint32 level_idc;
1296
1297         gint i; 
1298         guint8 profile_idc, chroma_format_idc, frame_mbs_only_flag, frame_cropping_flag;
1299         guint8 pic_order_cnt_type, vui_parameters_present_flag, num_ref_frames_in_pic_order_cnt_cycle;
1300         guint8 seq_scaling_matrix_present_flag; /* seq_scaling_list_present_flag */
1301
1302         /* profile_idc 0 u(8) */
1303         profile_idc = tvb_get_guint8(tvb,offset);
1304         proto_tree_add_item(tree, hf_h264_profile_idc, tvb, offset, 1, FALSE);
1305         offset++;
1306         
1307         constraint_set3_flag = (tvb_get_guint8(tvb,offset)&0x10)>>4;
1308         /* constraint_set0_flag 0 u(1) */
1309         proto_tree_add_item(tree, hf_h264_constraint_set0_flag, tvb, offset, 1, FALSE);
1310         
1311         /* constraint_set1_flag 0 u(1) */
1312         proto_tree_add_item(tree, hf_h264_constraint_set1_flag, tvb, offset, 1, FALSE);
1313         
1314         /* constraint_set2_flag 0 u(1) */
1315         proto_tree_add_item(tree, hf_h264_constraint_set2_flag, tvb, offset, 1, FALSE);
1316         
1317         /* constraint_set3_flag 0 u(1) */
1318         proto_tree_add_item(tree, hf_h264_constraint_set3_flag, tvb, offset, 1, FALSE);
1319         
1320         /* reserved_zero_4bits  equal to 0  0 u(4)*/
1321         proto_tree_add_item(tree, hf_h264_reserved_zero_4bits, tvb, offset, 1, FALSE);
1322         offset++;
1323         
1324         /* level_idc 0 u(8) */
1325         level_idc = tvb_get_guint8(tvb,offset);
1326         level_item = proto_tree_add_item(tree, hf_h264_level_idc, tvb, offset, 1, FALSE);
1327         if((level_idc==11)&&(constraint_set3_flag==1)){
1328                 proto_item_append_text(level_item,"[Level 1b]");
1329         }else{
1330                 proto_item_append_text(level_item," [Level %.1f %s]",((double)level_idc/10),val_to_str(level_idc, h264_level_bitrate_values, "Unknown "));
1331         }
1332         offset++;
1333         /* seq_parameter_set_id 0 ue(v) 
1334          * ue(v): unsigned integer Exp-Golomb-coded syntax element with the left bit first.
1335          * The parsing process for this descriptor is specified in subclause 9.1.
1336          */
1337         bit_offset = offset<<3;
1338         dissect_h264_exp_golomb_code(tree, hf_h264_seq_parameter_set_id, tvb, &bit_offset, H264_UE_V);
1339
1340
1341         if( profile_idc == 100 || profile_idc == 110 ||
1342                 profile_idc == 122 || profile_idc == 144 ) {
1343
1344                 /* chroma_format_idc 0 ue(v) */
1345                 chroma_format_idc = dissect_h264_exp_golomb_code(tree, hf_h264_chroma_format_idc, tvb, &bit_offset, H264_UE_V);
1346                 if( chroma_format_idc == 3 ){
1347                         /* residual_colour_transform_flag 0 u(1) */
1348                         proto_tree_add_bits_item(tree, hf_h264_residual_colour_transform_flag, tvb, bit_offset, 1, FALSE);
1349                         bit_offset++;
1350                 }
1351
1352                 /* bit_depth_luma_minus8 0 ue(v) */
1353                 dissect_h264_exp_golomb_code(tree, hf_h264_bit_depth_luma_minus8, tvb, &bit_offset, H264_UE_V);
1354
1355                 /* bit_depth_chroma_minus8 0 ue(v) */
1356                 dissect_h264_exp_golomb_code(tree, hf_h264_bit_depth_chroma_minus8, tvb, &bit_offset, H264_UE_V);
1357
1358                 /* qpprime_y_zero_transform_bypass_flag 0 u(1) */
1359                 proto_tree_add_bits_item(tree, hf_h264_qpprime_y_zero_transform_bypass_flag, tvb, bit_offset, 1, FALSE);
1360                 bit_offset++;
1361
1362                 /* seq_scaling_matrix_present_flag 0 u(1) */
1363                 seq_scaling_matrix_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1364                 proto_tree_add_bits_item(tree, hf_h264_seq_scaling_matrix_present_flag, tvb, bit_offset, 1, FALSE);
1365                 bit_offset++;
1366                 
1367                 if( seq_scaling_matrix_present_flag ){
1368                         /*
1369                         for( i = 0; i < 8; i++ ) {
1370                                 / seq_scaling_list_present_flag[ i ] 0 u(1) /
1371                                 seq_scaling_list_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1372                                 bit_offset++;
1373                                 if( seq_scaling_list_present_flag){
1374                                         if( i < 6 )
1375                                                 scaling_list( ScalingList4x4[ i ], 16,UseDefaultScalingMatrix4x4Flag[ i ])0
1376                                                 dissect_h264_scaling_list()
1377                                         else
1378                                                 scaling_list( ScalingList8x8[ i - 6 ], 64,UseDefaultScalingMatrix8x8Flag[ i - 6 ] )0
1379                                 }
1380                         }
1381                         */
1382                         proto_tree_add_text(tree, tvb, offset, -1, "[Not decoded yet]");
1383                         return -1;
1384                 }
1385
1386         }
1387
1388         /* log2_max_frame_num_minus4 0 ue(v) */
1389         dissect_h264_exp_golomb_code(tree, hf_h264_log2_max_frame_num_minus4, tvb, &bit_offset, H264_UE_V);
1390
1391         /* pic_order_cnt_type 0 ue(v) */
1392         offset = bit_offset>>3;
1393         pic_order_cnt_type = dissect_h264_exp_golomb_code(tree,hf_h264_pic_order_cnt_type, tvb, &bit_offset, H264_UE_V);
1394
1395         if(pic_order_cnt_type == 0){
1396                 /* log2_max_pic_order_cnt_lsb_minus4 0 ue(v) */
1397                 dissect_h264_exp_golomb_code(tree, hf_h264_log2_max_pic_order_cnt_lsb_minus4, tvb, &bit_offset, H264_UE_V);
1398         }else if(pic_order_cnt_type == 1) {
1399                 /* delta_pic_order_always_zero_flag 0 u(1) */
1400                 proto_tree_add_bits_item(tree, hf_h264_delta_pic_order_always_zero_flag, tvb, bit_offset, 1, FALSE);
1401                 bit_offset++;
1402
1403                 /* offset_for_non_ref_pic 0 se(v) */
1404                 dissect_h264_exp_golomb_code(tree, hf_h264_offset_for_non_ref_pic, tvb, &bit_offset, H264_SE_V);
1405                 
1406                 /* offset_for_top_to_bottom_field 0 se(v) */
1407                 dissect_h264_exp_golomb_code(tree, hf_h264_offset_for_top_to_bottom_field, tvb, &bit_offset, H264_SE_V);
1408                 
1409                 /* num_ref_frames_in_pic_order_cnt_cycle 0 ue(v) */
1410                 num_ref_frames_in_pic_order_cnt_cycle = dissect_h264_exp_golomb_code(tree, hf_h264_num_ref_frames_in_pic_order_cnt_cycle, tvb, &bit_offset, H264_UE_V);
1411                 for( i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++ ){
1412                         /*offset_for_ref_frame[ i ] 0 se(v)*/
1413                         dissect_h264_exp_golomb_code(tree, hf_h264_offset_for_ref_frame, tvb, &bit_offset, H264_SE_V);
1414                 }
1415         } 
1416         /* num_ref_frames 0 ue(v) */
1417         dissect_h264_exp_golomb_code(tree, hf_h264_num_ref_frames, tvb, &bit_offset, H264_UE_V);
1418
1419         /*      gaps_in_frame_num_value_allowed_flag 0 u(1) */
1420         proto_tree_add_bits_item(tree, hf_h264_gaps_in_frame_num_value_allowed_flag, tvb, bit_offset, 1, FALSE);
1421         bit_offset++;
1422         
1423         /*      pic_width_in_mbs_minus1 0 ue(v) */
1424         dissect_h264_exp_golomb_code(tree, hf_h264_pic_width_in_mbs_minus1, tvb, &bit_offset, H264_UE_V);
1425         
1426         /* pic_height_in_map_units_minus1 0 ue(v) */
1427         dissect_h264_exp_golomb_code(tree, hf_h264_pic_height_in_map_units_minus1, tvb, &bit_offset, H264_UE_V);
1428
1429         /* frame_mbs_only_flag 0 u(1) */
1430         frame_mbs_only_flag = tvb_get_bits8(tvb, bit_offset, 1);
1431         proto_tree_add_bits_item(tree, hf_h264_frame_mbs_only_flag, tvb, bit_offset, 1, FALSE);
1432         bit_offset++;
1433         if( !frame_mbs_only_flag ){
1434                 /* mb_adaptive_frame_field_flag 0 u(1) */
1435                 proto_tree_add_bits_item(tree, hf_h264_mb_adaptive_frame_field_flag, tvb, bit_offset, 1, FALSE);
1436                 bit_offset++;
1437         }
1438         
1439         /* direct_8x8_inference_flag 0 u(1) */
1440         proto_tree_add_bits_item(tree, hf_h264_direct_8x8_inference_flag, tvb, bit_offset, 1, FALSE);
1441         bit_offset++;
1442         
1443         /* frame_cropping_flag 0 u(1) */
1444         frame_cropping_flag = tvb_get_bits8(tvb, bit_offset, 1);
1445         proto_tree_add_bits_item(tree, hf_h264_frame_cropping_flag, tvb, bit_offset, 1, FALSE);
1446         bit_offset++;
1447
1448         if(frame_cropping_flag) {
1449                 /* frame_crop_left_offset 0 ue(v) */
1450                 dissect_h264_exp_golomb_code(tree, hf_h264_frame_crop_left_offset, tvb, &bit_offset, H264_UE_V);
1451                 dissect_h264_exp_golomb_code(tree,hf_h264_frame_crop_right_offset, tvb, &bit_offset, H264_UE_V);
1452                 dissect_h264_exp_golomb_code(tree, hf_h264_frame_crop_top_offset, tvb, &bit_offset, H264_UE_V);
1453                 dissect_h264_exp_golomb_code(tree, hf_h264_frame_crop_bottom_offset, tvb, &bit_offset, H264_UE_V);
1454
1455         }
1456
1457         /*      vui_parameters_present_flag 0 u(1) */
1458         vui_parameters_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1459         proto_tree_add_bits_item(tree, hf_h264_vui_parameters_present_flag, tvb, bit_offset, 1, FALSE);
1460         bit_offset++;
1461         if(vui_parameters_present_flag){
1462                 bit_offset = dissect_h264_vui_parameters(tree, tvb, pinfo, bit_offset);
1463         }
1464         
1465         /*      rbsp_trailing_bits( ) 0 */
1466         bit_offset = dissect_h264_rbsp_trailing_bits(tree, tvb, pinfo, bit_offset); 
1467
1468         offset = bit_offset>>3;
1469
1470         return offset;
1471 }
1472
1473 /* 7.3.2.2 Picture parameter set RBSP syntax */
1474
1475 static void
1476 dissect_h264_pic_parameter_set_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint offset)
1477 {
1478
1479         gint bit_offset;
1480         guint32 num_slice_groups_minus1, slice_group_map_type, pic_scaling_matrix_present_flag;
1481
1482         bit_offset = offset<<3;
1483
1484         /* pic_parameter_set_id 1 ue(v) */
1485         dissect_h264_exp_golomb_code(tree, hf_h264_pic_parameter_set_id, tvb, &bit_offset, H264_UE_V);
1486
1487         /* seq_parameter_set_id 1 ue(v) */
1488         dissect_h264_exp_golomb_code(tree, hf_h264_seq_parameter_set_id, tvb, &bit_offset, H264_UE_V);
1489
1490         /* entropy_coding_mode_flag 1 u(1) */
1491         proto_tree_add_bits_item(tree, hf_h264_entropy_coding_mode_flag, tvb, bit_offset, 1, FALSE);
1492         bit_offset++;
1493
1494         /* pic_order_present_flag 1 u(1)*/
1495         proto_tree_add_bits_item(tree, hf_h264_pic_order_present_flag, tvb, bit_offset, 1, FALSE);
1496         bit_offset++;
1497
1498         /* num_slice_groups_minus1 1 ue(v)*/
1499         num_slice_groups_minus1 = dissect_h264_exp_golomb_code(tree, hf_h264_num_slice_groups_minus1, tvb, &bit_offset, H264_UE_V);
1500         if( num_slice_groups_minus1 > 0 ) {
1501                 /* slice_group_map_type 1 ue(v)*/
1502                 slice_group_map_type = dissect_h264_exp_golomb_code(tree, hf_h264_slice_group_map_type, tvb, &bit_offset, H264_UE_V);
1503         /* if( slice_group_map_type == 0 )*/
1504         /* for( iGroup = 0; iGroup <= num_slice_groups_minus1; iGroup++ )*/
1505         /* run_length_minus1[ iGroup ] 1 ue(v)*/
1506         /* else if( slice_group_map_type == 2 )*/
1507         /* for( iGroup = 0; iGroup < num_slice_groups_minus1; iGroup++ ) {*/
1508         /* top_left[ iGroup ] 1 ue(v)*/
1509         /* bottom_right[ iGroup ] 1 ue(v)*/
1510         /* }*/
1511         /* else if( slice_group_map_type == 3 ||*/
1512         /* slice_group_map_type == 4 ||*/
1513         /* slice_group_map_type == 5 ) {*/
1514         /* slice_group_change_direction_flag 1 u(1)*/
1515         /* slice_group_change_rate_minus1 1 ue(v)*/
1516         /* } else if( slice_group_map_type == 6 ) {*/
1517         /* pic_size_in_map_units_minus1 1 ue(v)*/
1518         /* for( i = 0; i <= pic_size_in_map_units_minus1; i++ )*/
1519         /* slice_group_id[ i ] 1 u(v)*/
1520         /* }*/
1521         /* }*/
1522                 proto_tree_add_text(tree, tvb, bit_offset>>3, -1, "[Not decoded yet]");
1523                 return;
1524         }
1525         /* num_ref_idx_l0_active_minus1 1 ue(v)*/
1526         dissect_h264_exp_golomb_code(tree, hf_h264_num_ref_idx_l0_active_minus1, tvb, &bit_offset, H264_UE_V);
1527         
1528         /* num_ref_idx_l1_active_minus1 1 ue(v)*/
1529         dissect_h264_exp_golomb_code(tree, hf_h264_num_ref_idx_l1_active_minus1, tvb, &bit_offset, H264_UE_V);
1530         
1531         /* weighted_pred_flag 1 u(1)*/
1532         proto_tree_add_bits_item(tree, hf_h264_weighted_pred_flag, tvb, bit_offset, 1, FALSE);
1533         bit_offset++;
1534         
1535         /* weighted_bipred_idc 1 u(2)*/
1536         proto_tree_add_bits_item(tree, hf_h264_weighted_bipred_idc, tvb, bit_offset, 2, FALSE);
1537         bit_offset= bit_offset+2;
1538
1539         /* pic_init_qp_minus26  * relative to 26 * 1 se(v)*/
1540         dissect_h264_exp_golomb_code(tree, hf_h264_pic_init_qp_minus26, tvb, &bit_offset, H264_SE_V);
1541
1542         /* pic_init_qs_minus26  * relative to 26 *  1 se(v)*/
1543         dissect_h264_exp_golomb_code(tree, hf_h264_pic_init_qs_minus26, tvb, &bit_offset, H264_SE_V);
1544
1545         /* chroma_qp_index_offset 1 se(v)*/
1546         dissect_h264_exp_golomb_code(tree, hf_h264_chroma_qp_index_offset, tvb, &bit_offset, H264_SE_V);
1547
1548         /* deblocking_filter_control_present_flag 1 u(1)*/
1549         proto_tree_add_bits_item(tree, hf_h264_deblocking_filter_control_present_flag, tvb, bit_offset, 1, FALSE);
1550         bit_offset++;
1551
1552         /* constrained_intra_pred_flag 1 u(1)*/
1553         proto_tree_add_bits_item(tree, hf_h264_constrained_intra_pred_flag, tvb, bit_offset, 1, FALSE);
1554         bit_offset++;
1555
1556         /* redundant_pic_cnt_present_flag 1 u(1)*/
1557         proto_tree_add_bits_item(tree, hf_h264_redundant_pic_cnt_present_flag, tvb, bit_offset, 1, FALSE);
1558         bit_offset++;
1559
1560         if( more_rbsp_data(tree, tvb, pinfo, bit_offset)){
1561                 /* transform_8x8_mode_flag 1 u(1)*/
1562                 proto_tree_add_bits_item(tree, hf_h264_transform_8x8_mode_flag, tvb, bit_offset, 1, FALSE);
1563                 bit_offset++;
1564
1565                 /* pic_scaling_matrix_present_flag 1 u(1)*/
1566                 pic_scaling_matrix_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1567                 proto_tree_add_bits_item(tree, hf_h264_pic_scaling_matrix_present_flag, tvb, bit_offset, 1, FALSE);
1568                 bit_offset++;
1569
1570                 if( pic_scaling_matrix_present_flag ){
1571                         proto_tree_add_text(tree, tvb, bit_offset>>3, -1, "[Not decoded yet]");
1572                         return;
1573                         /* for( i = 0; i < 6 + 2* transform_8x8_mode_flag; i++ ) {*/
1574                                 /* pic_scaling_list_present_flag[ i ] 1 u(1)*/
1575                                 /* if( pic_scaling_list_present_flag[ i ] )*/
1576                                 /* if( i < 6 )*/
1577                                         /* scaling_list( ScalingList4x4[ i ], 16, UseDefaultScalingMatrix4x4Flag[ i ] )*/
1578                                 /* else*/
1579                                         /* scaling_list( ScalingList8x8[ i - 6 ], 64, UseDefaultScalingMatrix8x8Flag[ i - 6 ] )*/
1580                         /* }*/
1581                         }
1582
1583                 /* second_chroma_qp_index_offset 1 se(v)*/
1584                 dissect_h264_exp_golomb_code(tree, hf_h264_second_chroma_qp_index_offset, tvb, &bit_offset, H264_SE_V);
1585         }
1586         bit_offset = dissect_h264_rbsp_trailing_bits(tree, tvb, pinfo, bit_offset);
1587
1588 }
1589
1590 /*
1591  * 7.3.2.4 Access unit delimiter RBSP syntax
1592  * access_unit_delimiter_rbsp( )
1593  */
1594 static void
1595 dissect_h264_access_unit_delimiter_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1596 {
1597         /* primary_pic_type 6 u(3) */
1598         /* rbsp_trailing_bits( ) 6 */
1599         proto_tree_add_text(tree, tvb, offset, -1, "[Not decoded yet]");
1600
1601 }
1602
1603 /*
1604  * 7.3.2.5 End of sequence RBSP syntax
1605  * end_of_seq_rbsp( ) {}
1606  */
1607 static void
1608 dissect_h264_end_of_seq_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1609 {
1610         proto_tree_add_text(tree, tvb, offset, -1, "[Not decoded yet]");
1611
1612 }
1613
1614 /*
1615  * 7.3.2.6 End of stream RBSP syntax
1616  * end_of_stream_rbsp( ) {}
1617  */
1618 static void
1619 dissect_h264_end_of_stream_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1620 {
1621         proto_tree_add_text(tree, tvb, offset, -1, "[Not decoded yet]");
1622
1623 }
1624
1625 /*
1626  * 7.3.2.7 Filler data RBSP syntax
1627  * filler_data_rbsp( )
1628  */
1629 static void
1630 dissect_h264_filler_data_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1631 {
1632         /* while( next_bits( 8 ) == 0xFF ) */
1633         /* ff_byte * equal to 0xFF * 9 f(8) */
1634         /* rbsp_trailing_bits( ) 9 */
1635         proto_tree_add_text(tree, tvb, offset, -1, "[Not decoded yet]");
1636
1637 }
1638
1639 /*
1640  * 7.3.2.1.2 Sequence parameter set extension RBSP syntax
1641  * seq_parameter_set_extension_rbsp( )
1642  */
1643 static void
1644 dissect_h264_seq_parameter_set_extension_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1645 {
1646         /* seq_parameter_set_id 10 ue(v) */
1647         /* aux_format_idc 10 ue(v) */
1648         /* if( aux_format_idc != 0 ) { */
1649         /* bit_depth_aux_minus8 10 ue(v) */
1650         /* alpha_incr_flag 10 u(1) */
1651         /* alpha_opaque_value 10 u(v) */
1652         /* alpha_transparent_value 10 u(v) */
1653         /* } */
1654         /* additional_extension_flag 10 u(1) */
1655         /* rbsp_trailing_bits() 10 */
1656         proto_tree_add_text(tree, tvb, offset, -1, "[Not decoded yet]");
1657
1658 }
1659
1660
1661 /* 
1662  * Dissect NAL unit as recived in sprop-parameter-sets of SDP
1663  * or "DecoderConfiguration parameter in H.245
1664  */
1665 void
1666 dissect_h264_nal_unit(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
1667 {
1668         proto_item *item;
1669         proto_tree *h264_nal_tree;
1670         gint    offset = 0;
1671         guint8 nal_unit_type;
1672         guint32 dword;
1673         item = proto_tree_add_item(tree, hf_h264_nal_unit, tvb, offset, -1, FALSE);
1674         h264_nal_tree = proto_item_add_subtree(item, ett_h264_nal_unit);
1675
1676 startover:
1677         /* In decoder configuration start code may be pressent 
1678          * B.1.1 Byte stream NAL unit syntax
1679          */
1680         dword = tvb_get_bits32(tvb, offset<<3, 32, FALSE);
1681         if(dword==1){
1682                 /* zero_byte + start_code_prefix_one_3bytes */
1683                 offset+=4;
1684         }else if((dword >> 8)== 1){
1685                 /* start_code_prefix_one_3bytes */
1686                 offset+= 3;
1687         }
1688         /* Ref: 7.3.1 NAL unit syntax */
1689         nal_unit_type = tvb_get_guint8(tvb,offset) & 0x1f;
1690
1691         /* forbidden_zero_bit All f(1) */
1692         proto_tree_add_item(h264_nal_tree, hf_h264_forbidden_zero_bit, tvb, offset, 1, FALSE);
1693         /* nal_ref_idc All u(2) */
1694         proto_tree_add_item(h264_nal_tree, hf_h264_nal_ref_idc, tvb, offset, 1, FALSE);
1695         /* nal_unit_type All u(5) */
1696         proto_tree_add_item(h264_nal_tree, hf_h264_nal_unit_type, tvb, offset, 1, FALSE);
1697         offset++;
1698
1699         switch(nal_unit_type){
1700         case 0: /* Unspecified */
1701                 proto_tree_add_text(h264_nal_tree, tvb, offset, -1, "Unspecified NAL unit type");
1702                 break;
1703         case 1: /* Coded slice of a non-IDR picture */ 
1704                 dissect_h264_slice_layer_without_partitioning_rbsp(h264_nal_tree, tvb, pinfo, offset);
1705                 break;
1706         case 2: /* Coded slice data partition A */
1707                 dissect_h264_slice_data_partition_a_layer_rbsp(h264_nal_tree, tvb, pinfo, offset);
1708                 break;
1709         case 3: /* Coded slice data partition B */
1710                 dissect_h264_slice_data_partition_b_layer_rbsp(h264_nal_tree, tvb, pinfo, offset);
1711                 break;
1712         case 4: /* Coded slice data partition C */
1713                 dissect_h264_slice_data_partition_c_layer_rbsp(h264_nal_tree, tvb, pinfo, offset);
1714                 break;
1715         case 5: /* Coded slice of an IDR picture */
1716                 dissect_h264_slice_layer_without_partitioning_rbsp(h264_nal_tree, tvb, pinfo, offset);
1717                 break;
1718         case 6: /* Supplemental enhancement information (SEI) */
1719                 dissect_h264_sei_rbsp(h264_nal_tree, tvb, pinfo, offset);
1720                 break;
1721         case H264_SEQ_PAR_SET:  /* 7 Sequence parameter set*/
1722                 offset = dissect_h264_seq_parameter_set_rbsp(h264_nal_tree, tvb, pinfo, offset);
1723                 /* A bit ugly */
1724                 if(tvb_length_remaining(tvb,offset) > 0){
1725                         /* In this case length = offset as we start from zero */
1726                         proto_item_set_len(item, offset/*Length */);
1727                         item = proto_tree_add_item(tree, hf_h264_nal_unit, tvb, offset, -1, FALSE);
1728                         h264_nal_tree = proto_item_add_subtree(item, ett_h264_nal_unit);
1729                         goto startover;
1730                 }
1731                 break;
1732         case H264_PIC_PAR_SET:  /* 8 Picture parameter set */
1733                 dissect_h264_pic_parameter_set_rbsp(h264_nal_tree, tvb, pinfo, offset);
1734                 break;
1735         case 9: /* Access unit delimiter */
1736                 dissect_h264_access_unit_delimiter_rbsp(h264_nal_tree, tvb, pinfo, offset);
1737                 break;
1738         case 10:        /* End of sequence */
1739                 dissect_h264_end_of_seq_rbsp(h264_nal_tree, tvb, pinfo, offset);
1740                 break;
1741         case 11:        /* End of stream */
1742                 dissect_h264_end_of_stream_rbsp(h264_nal_tree, tvb, pinfo, offset);
1743                 break;
1744         case 12:        /* Filler data */
1745                 dissect_h264_filler_data_rbsp(h264_nal_tree, tvb, pinfo, offset);
1746                 break;
1747         case 13:        /* Sequence parameter set extension */
1748                 dissect_h264_seq_parameter_set_extension_rbsp(h264_nal_tree, tvb, pinfo, offset);
1749                 break;
1750         case 14:        /* Reserved */
1751         case 15:        /* Reserved */
1752         case 16:        /* Reserved */
1753         case 17:        /* Reserved */
1754         case 18:        /* Reserved */
1755                 proto_tree_add_text(h264_nal_tree, tvb, offset, -1, "Reserved NAL unit type");
1756                 break;
1757         case 19:        /* Coded slice of an auxiliary coded picture without partitioning */
1758                 dissect_h264_slice_layer_without_partitioning_rbsp(tree, tvb, pinfo, offset);
1759                 break;
1760         case 28:
1761                 dissect_h264_slice_layer_without_partitioning_rbsp(tree, tvb, pinfo, offset);
1762                 break;
1763         default:
1764                 /* 24..31 Unspecified */
1765                 proto_tree_add_text(h264_nal_tree, tvb, offset, -1, "Unspecified NAL unit type");
1766                 break;
1767         }
1768
1769 }
1770 /* Code to actually dissect the packets */
1771 static void
1772 dissect_h264(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1773 {
1774         int offset = 0;
1775         proto_item *item, *ti, *stream_item, *fua_item;
1776         proto_tree *h264_tree, *h264_nal_tree, *stream_tree, *fua_tree;
1777         guint8 type;
1778
1779
1780 /* Make entries in Protocol column and Info column on summary display */
1781         col_set_str(pinfo->cinfo, COL_PROTOCOL, "H264");
1782         if (tree) {
1783
1784                 item = proto_tree_add_item(tree, proto_h264, tvb, 0, -1, FALSE);
1785                 h264_tree = proto_item_add_subtree(item, ett_h264);
1786
1787                 type = tvb_get_guint8(tvb,offset)&0x1f;
1788 /* if the type is 28, it would be draw another title */
1789                 if(type == 28)
1790                         ti = proto_tree_add_text(h264_tree, tvb, offset, 1, "FU identifier");
1791                 else
1792                         ti = proto_tree_add_text(h264_tree, tvb, offset, 1, "NAL unit header or first byte of the payload");
1793                 h264_nal_tree = proto_item_add_subtree(ti, ett_h264_nal);
1794
1795                 /* +---------------+
1796                  * |0|1|2|3|4|5|6|7|
1797                  * +-+-+-+-+-+-+-+-+
1798                  * |F|NRI|  Type   |
1799                  * +---------------+
1800                  */
1801
1802                 /* F: 1 bit
1803                  * forbidden_zero_bit.  A value of 0 indicates that the NAL unit type
1804                  * octet and payload should not contain bit errors or other syntax
1805                  * violations.  A value of 1 indicates that the NAL unit type octet
1806                  * and payload may contain bit errors or other syntax violations.
1807                  */
1808                 proto_tree_add_item(h264_nal_tree, hf_h264_nal_f_bit, tvb, offset, 1, FALSE);
1809                 proto_tree_add_item(h264_nal_tree, hf_h264_nal_nri, tvb, offset, 1, FALSE);
1810                 if (check_col(pinfo->cinfo, COL_INFO)){
1811                         col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
1812                                 val_to_str(type, h264_type_values, "Unknown Type (%u)"));
1813                 }
1814
1815                 proto_tree_add_item(h264_nal_tree, hf_h264_type, tvb, offset, 1, FALSE);
1816                 offset++;
1817                 if (type == 28){
1818                         fua_item = proto_tree_add_text(h264_tree, tvb, offset, 1, "FU Header");
1819                         fua_tree = proto_item_add_subtree(fua_item, ett_h264_fua);
1820                         proto_tree_add_item(fua_tree, hf_h264_start_bit, tvb, offset, 1, FALSE);        
1821                         proto_tree_add_item(fua_tree, hf_h264_end_bit, tvb, offset, 1, FALSE);
1822                         proto_tree_add_item(fua_tree, hf_h264_forbidden_bit, tvb, offset, 1, FALSE);
1823                         proto_tree_add_item(fua_tree, hf_h264_nal_unit_type, tvb, offset, 1, FALSE);
1824                         if ( (tvb_get_guint8(tvb,offset)&0x80) == 0x80 ){
1825                                 type = tvb_get_guint8(tvb,offset)&0x1f;
1826                                 offset++;
1827                         }
1828                         else
1829                                 return;
1830                 }
1831                 stream_item =proto_tree_add_text(h264_tree, tvb, offset, -1, "H264 bitstream"); 
1832                 stream_tree = proto_item_add_subtree(stream_item, ett_h264_stream);
1833                 switch(type){
1834                 case 1:                         /* 1 Coded slice of a non-IDR picture */ 
1835                         dissect_h264_slice_layer_without_partitioning_rbsp(stream_tree, tvb, pinfo, offset);
1836                         break;
1837                 case 3: /* Coded slice data partition B */
1838                         dissect_h264_slice_data_partition_b_layer_rbsp(h264_nal_tree, tvb, pinfo, offset);
1839                         break;
1840                 case 4: /* Coded slice data partition C */
1841                         dissect_h264_slice_data_partition_c_layer_rbsp(h264_nal_tree, tvb, pinfo, offset);
1842                         break;
1843                 case 5: /* Coded slice of an IDR picture */
1844                         dissect_h264_slice_layer_without_partitioning_rbsp(stream_tree, tvb, pinfo, offset);
1845                         break;
1846                 case 6: /* Supplemental enhancement information (SEI) */
1847                         dissect_h264_sei_rbsp(stream_tree, tvb, pinfo, offset);
1848                         break;
1849                 case H264_SEQ_PAR_SET:  /* 7 Sequence parameter set*/
1850                         dissect_h264_seq_parameter_set_rbsp(stream_tree, tvb, pinfo, offset);
1851                         break;
1852                 case H264_PIC_PAR_SET:  /* 8 Picture parameter set */
1853                         dissect_h264_pic_parameter_set_rbsp(stream_tree, tvb, pinfo, offset);
1854                         break;
1855                 case 19:        /* Coded slice of an auxiliary coded picture without partitioning */
1856                         dissect_h264_slice_layer_without_partitioning_rbsp(stream_tree, tvb, pinfo, offset);
1857                         break;
1858                 default:
1859                         break;
1860                 }
1861         }/* if tree */
1862
1863 }
1864
1865
1866 /* Capability */
1867
1868 static const int *profile_fields[] = {
1869   &hf_h264_par_profile_b,
1870   &hf_h264_par_profile_m,
1871   &hf_h264_par_profile_e,
1872   &hf_h264_par_profile_h,
1873   &hf_h264_par_profile_h10,
1874   &hf_h264_par_profile_h4_2_2,
1875   &hf_h264_par_profile_h4_4_4,
1876   NULL
1877 };
1878
1879 static int
1880 dissect_h264_par_profile(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
1881 {
1882   int offset = 0;
1883
1884   proto_tree_add_bitmask(tree, tvb, offset, 
1885                          hf_h264_par_profile, ett_h264_par_profile,
1886                          profile_fields, FALSE);
1887   offset += 1;
1888   return offset;
1889 }
1890
1891 static const int *AdditionalModesSupported_fields[] = {
1892   &hf_h264_par_add_mode_sup_rcdo,
1893   NULL
1894 };
1895 static int
1896 dissect_h264_par_AdditionalModesSupported(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
1897 {
1898   int offset = 0;
1899
1900   proto_tree_add_bitmask(tree, tvb, offset, 
1901                          hf_h264_par_AdditionalModesSupported, ett_h264_par_AdditionalModesSupported,
1902                          AdditionalModesSupported_fields, FALSE);
1903   offset += 1;
1904   return offset;
1905 }
1906
1907
1908 static const int *ProfileIOP_fields[] = {
1909   &hf_h264_par_constraint_set0_flag,
1910   &hf_h264_par_constraint_set1_flag,
1911   &hf_h264_par_constraint_set2_flag,
1912   NULL
1913 };
1914
1915
1916 static int
1917 dissect_h264_ProfileIOP(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
1918 {
1919   int offset = 0;
1920
1921   proto_tree_add_bitmask(tree, tvb, offset, 
1922                          hf_h264_par_ProfileIOP, ett_h264_par_ProfileIOP,
1923                          ProfileIOP_fields, FALSE);
1924   offset += 1;
1925   return offset;
1926 }
1927
1928 static const value_string h264_par_level_values[] = {
1929   { 15,         "1" },
1930   { 19,         "1b" },
1931   { 22,         "1.1" },
1932   { 29,         "1.2" },
1933   { 36,         "1.3" },
1934   { 43,         "2" },
1935   { 50,         "2.1" },
1936   { 57,         "2.2" },
1937   { 64,         "3" },
1938   { 71,         "3.1" },
1939   { 78,         "3.2" },
1940   { 85,         "4" },
1941   { 92,         "4.1" },
1942   { 99,         "4.2" },
1943   { 106,        "5" },
1944   { 113 ,       "5.1" },
1945   { 0,  NULL }
1946 };
1947
1948 static int
1949 dissect_h264_par_level(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_)
1950 {
1951   int offset = 0;
1952   guint16 lvl;
1953   const gchar *p = NULL;
1954   asn1_ctx_t *actx;
1955
1956   actx = get_asn1_ctx(pinfo->private_data);
1957   DISSECTOR_ASSERT(actx);
1958
1959   lvl = tvb_get_ntohs(tvb, offset);
1960   p = match_strval(lvl, VALS(h264_par_level_values));
1961   if (p) {
1962     proto_item_append_text(actx->created_item, " - Level %s", p);
1963   }
1964   offset += 2;
1965   return offset;
1966 }
1967 static int
1968 dissect_h264_par_DecoderConfigurationInformation(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree _U_)
1969 {
1970   asn1_ctx_t *actx;
1971
1972   actx = get_asn1_ctx(pinfo->private_data);
1973   DISSECTOR_ASSERT(actx);
1974
1975   dissect_h264_nal_unit(tvb, pinfo, tree);
1976
1977   return tvb_length(tvb);
1978 }
1979
1980 typedef struct _h264_capability_t {
1981   const gchar *id;
1982   const gchar *name;
1983   new_dissector_t content_pdu;
1984 } h264_capability_t;
1985
1986 static h264_capability_t h264_capability_tab[] = {
1987   /* ITU-T H.241 (05/2006), 8.3 H.264 capabilities */
1988   { "GenericCapability/0.0.8.241.0.0.1", "ITU-T Rec. H.241 H.264 Video Capabilities", NULL },
1989   { "GenericCapability/0.0.8.241.0.0.1/collapsing/41", "Profile", dissect_h264_par_profile },
1990   { "GenericCapability/0.0.8.241.0.0.1/collapsing/42", "Level", dissect_h264_par_level },
1991   { "GenericCapability/0.0.8.241.0.0.1/collapsing/3" , "CustomMaxMBPS", NULL },
1992   { "GenericCapability/0.0.8.241.0.0.1/collapsing/4" , "CustomMaxFS", NULL },
1993   { "GenericCapability/0.0.8.241.0.0.1/collapsing/5" , "CustomMaxDPB", NULL },
1994   { "GenericCapability/0.0.8.241.0.0.1/collapsing/6" , "CustomMaxBRandCPB", NULL },
1995   { "GenericCapability/0.0.8.241.0.0.1/collapsing/7" , "MaxStaticMBPS", NULL },
1996   { "GenericCapability/0.0.8.241.0.0.1/collapsing/8" , "max-rcmd-nal-unit-size", NULL },
1997   { "GenericCapability/0.0.8.241.0.0.1/collapsing/9" , "max-nal-unit-size", NULL },
1998   { "GenericCapability/0.0.8.241.0.0.1/collapsing/10", "SampleAspectRatiosSupported", NULL },
1999   { "GenericCapability/0.0.8.241.0.0.1/collapsing/11", "AdditionalModesSupported", dissect_h264_par_AdditionalModesSupported },
2000   { "GenericCapability/0.0.8.241.0.0.1/collapsing/12", "AdditionalDisplayCapabilities", NULL },
2001   /* TS 26.111  H.264 */
2002   { "GenericCapability/0.0.8.241.0.0.1/nonCollapsing/43" , "DecoderConfigurationInformation", dissect_h264_par_DecoderConfigurationInformation },
2003   { "GenericCapability/0.0.8.241.0.0.1/collapsing/44" , "AcceptRedundantSlices", NULL },
2004   { "GenericCapability/0.0.8.241.0.0.1/collapsing/45" , "NalAlignedMode", NULL },
2005   { "GenericCapability/0.0.8.241.0.0.1/collapsing/46" , "ProfileIOP", dissect_h264_ProfileIOP },
2006   { NULL, NULL, NULL },
2007 };                                 
2008
2009 static h264_capability_t *find_cap(const gchar *id) {
2010   h264_capability_t *ftr = NULL;
2011   h264_capability_t *f;
2012
2013   for (f=h264_capability_tab; f->id; f++) {
2014     if (!strcmp(id, f->id)) { ftr = f; break; }
2015   }
2016   return ftr;
2017 }
2018
2019 static void
2020 dissect_h264_name(tvbuff_t *tvb _U_, packet_info *pinfo, proto_tree *tree) 
2021 {
2022   asn1_ctx_t *actx;
2023   h264_capability_t *ftr = NULL;
2024
2025   actx = get_asn1_ctx(pinfo->private_data);
2026   DISSECTOR_ASSERT(actx);
2027   if (tree) {
2028     ftr = find_cap(pinfo->match_string);
2029     if (ftr) {
2030       proto_item_append_text(actx->created_item, " - %s", ftr->name);
2031       proto_item_append_text(proto_item_get_parent(proto_tree_get_parent(tree)), ": %s", ftr->name);
2032     } else {
2033       proto_item_append_text(actx->created_item, " - unknown(%s)", pinfo->match_string);
2034     }
2035   }
2036 }
2037
2038
2039 /* Register the protocol with Wireshark */
2040 /* If this dissector uses sub-dissector registration add a registration routine.
2041    This format is required because a script is used to find these routines and
2042    create the code that calls these routines.
2043 */
2044 void
2045 proto_reg_handoff_h264(void)
2046 {
2047         static dissector_handle_t h264_handle;
2048         static guint dynamic_payload_type;
2049         static gboolean h264_prefs_initialized = FALSE;
2050
2051         if (!h264_prefs_initialized) {
2052                 dissector_handle_t h264_name_handle;
2053                 h264_capability_t *ftr;
2054
2055                 h264_handle = find_dissector("h264");
2056                 dissector_add_string("rtp_dyn_payload_type","H264", h264_handle);
2057
2058                 h264_name_handle = create_dissector_handle(dissect_h264_name, proto_h264);
2059                 for (ftr=h264_capability_tab; ftr->id; ftr++) {
2060                     if (ftr->name) 
2061                                 dissector_add_string("h245.gef.name", ftr->id, h264_name_handle);
2062                         if (ftr->content_pdu)
2063                                 dissector_add_string("h245.gef.content", ftr->id, new_create_dissector_handle(ftr->content_pdu, proto_h264));
2064                 }
2065                 h264_prefs_initialized = TRUE;
2066         } else {
2067                 if ( dynamic_payload_type > 95 )
2068                         dissector_delete("rtp.pt", dynamic_payload_type, h264_handle);
2069         }
2070
2071         dynamic_payload_type = temp_dynamic_payload_type;
2072         if ( dynamic_payload_type > 95 ){
2073                 dissector_add("rtp.pt", dynamic_payload_type, h264_handle);
2074         }
2075 }
2076
2077 /* this format is required because a script is used to build the C function
2078    that calls all the protocol registration.
2079 */
2080
2081 void
2082 proto_register_h264(void)
2083 {                 
2084
2085         module_t *h264_module;
2086
2087 /* Setup list of header fields  See Section 1.6.1 for details*/
2088         static hf_register_info hf[] = {
2089                 { &hf_h264_nal_f_bit,
2090                         { "F bit",           "h264.f",
2091                         FT_BOOLEAN, 8, TFS(&h264_f_bit_vals), 0x80,          
2092                         NULL, HFILL }
2093                 },
2094                 { &hf_h264_nal_nri,
2095                         { "Nal_ref_idc (NRI)",           "h264.nal_nri",
2096                         FT_UINT8, BASE_DEC, NULL, 0x60,          
2097                         NULL, HFILL }
2098                 },
2099                 { &hf_h264_type,
2100                         { "Type",           "h264.nal_unit_hdr",
2101                         FT_UINT8, BASE_DEC, VALS(h264_type_values), 0x1f,          
2102                         NULL, HFILL }
2103                 },
2104                 { &hf_h264_start_bit,
2105                         { "Start bit", "h264.start.bit",
2106                         FT_BOOLEAN, 8, TFS(&h264_start_bit_vals), 0x80,
2107                         NULL, HFILL }
2108                 },
2109                 { &hf_h264_end_bit,
2110                         { "End bit", "h264.end.bit",
2111                         FT_BOOLEAN, 8, TFS(&h264_end_bit_vals), 0x40,
2112                         NULL, HFILL }
2113                 },
2114                 { &hf_h264_forbidden_bit,
2115                         { "Forbidden bit", "h264.forbidden.bit",
2116                         FT_UINT8, BASE_DEC, NULL, 0x20,
2117                         NULL, HFILL }
2118                 },
2119                 { &hf_h264_profile,
2120                         { "Profile",           "h264.profile",
2121                         FT_BYTES, BASE_NONE, NULL, 0x0,          
2122                         NULL, HFILL }
2123                 },
2124                 { &hf_h264_profile_idc,
2125                         { "Profile_idc",           "h264.profile_idc",
2126                         FT_UINT8, BASE_DEC, VALS(h264_profile_idc_values), 0xff,          
2127                         NULL, HFILL }
2128                 },
2129                 { &hf_h264_rbsp_stop_bit,
2130                         { "rbsp_stop_bit",           "h264.rbsp_stop_bit",
2131                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2132                         NULL, HFILL }
2133                 },
2134                 { &hf_h264_rbsp_trailing_bits,
2135                         { "rbsp_trailing_bits",           "h264.rbsp_trailing_bits",
2136                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2137                         NULL, HFILL }
2138                 },
2139                 { &hf_h264_constraint_set0_flag,
2140                         { "Constraint_set0_flag",           "h264.constraint_set0_flag",
2141                         FT_UINT8, BASE_DEC, NULL, 0x80,          
2142                         NULL, HFILL }
2143                 },
2144                 { &hf_h264_constraint_set1_flag,
2145                         { "Constraint_set1_flag",           "h264.constraint_set1_flag",
2146                         FT_UINT8, BASE_DEC, NULL, 0x40,          
2147                         NULL, HFILL }
2148                 },
2149                 { &hf_h264_constraint_set2_flag,
2150                         { "Constraint_set2_flag",           "h264.constraint_set2_flag",
2151                         FT_UINT8, BASE_DEC, NULL, 0x20,          
2152                         NULL, HFILL }
2153                 },
2154                 { &hf_h264_constraint_set3_flag,
2155                         { "Constraint_set3_flag",           "h264.constraint_set3_flag",
2156                         FT_UINT8, BASE_DEC, NULL, 0x10,          
2157                         NULL, HFILL }
2158                 },
2159                 { &hf_h264_reserved_zero_4bits,
2160                         { "Reserved_zero_4bits",           "h264.reserved_zero_4bits",
2161                         FT_UINT8, BASE_DEC, NULL, 0x0f,          
2162                         NULL, HFILL }
2163                 },
2164                 { &hf_h264_level_idc,
2165                         { "Level_id",           "h264.level_id",
2166                         FT_UINT8, BASE_DEC, NULL, 0xff,          
2167                         NULL, HFILL }
2168                 },
2169                 { &hf_h264_nal_unit,
2170                         { "NAL unit",           "h264.nal_unit",
2171                         FT_BYTES, BASE_NONE, NULL, 0x0,          
2172                         NULL, HFILL }
2173                 },
2174                 { &hf_h264_forbidden_zero_bit,
2175                         { "Forbidden_zero_bit",           "h264.forbidden_zero_bit",
2176                         FT_UINT8, BASE_DEC, NULL, 0x80,          
2177                         NULL, HFILL }
2178                 },
2179                 { &hf_h264_nal_ref_idc,
2180                         { "Nal_ref_idc",           "h264.nal_ref_idc",
2181                         FT_UINT8, BASE_DEC, NULL, 0x60,          
2182                         NULL, HFILL }
2183                 },
2184                 {&hf_h264_nal_unit_type,
2185                         { "Nal_unit_type",           "h264.nal_unit_type",
2186                         FT_UINT8, BASE_DEC, VALS(h264_nal_unit_type_vals), 0x1f,          
2187                         NULL, HFILL }
2188                 },
2189                 { &hf_h264_seq_parameter_set_id,
2190                         { "seq_parameter_set_id",           "h264.seq_parameter_set_id",
2191                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2192                         NULL, HFILL }
2193                 },
2194                 { &hf_h264_chroma_format_idc,
2195                         { "chroma_format_id",           "h264.chroma_format_id",
2196                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2197                         NULL, HFILL }
2198                 },
2199                 { &hf_h264_residual_colour_transform_flag,
2200                         { "residual_colour_transform_flag",           "h264.residual_colour_transform_flag",
2201                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2202                         NULL, HFILL }
2203                 },
2204                 { &hf_h264_bit_depth_luma_minus8,
2205                         { "bit_depth_luma_minus8",           "h264.bit_depth_luma_minus8",
2206                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2207                         NULL, HFILL }
2208                 },
2209                 { &hf_h264_bit_depth_chroma_minus8,
2210                         { "bit_depth_chroma_minus8",           "h264.bit_depth_chroma_minus8",
2211                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2212                         NULL, HFILL }
2213                 },
2214                 { &hf_h264_qpprime_y_zero_transform_bypass_flag,
2215                         { "qpprime_y_zero_transform_bypass_flag",           "h264.qpprime_y_zero_transform_bypass_flag",
2216                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2217                         NULL, HFILL }
2218                 },
2219                 { &hf_h264_seq_scaling_matrix_present_flag,
2220                         { "seq_scaling_matrix_present_flag",           "h264.seq_scaling_matrix_present_flag",
2221                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2222                         NULL, HFILL }
2223                 },
2224                 { &hf_h264_log2_max_frame_num_minus4,
2225                         { "log2_max_frame_num_minus4",           "h264.log2_max_frame_num_minus4",
2226                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2227                         NULL, HFILL }
2228                 },
2229                 { &hf_h264_pic_order_cnt_type,
2230                         { "pic_order_cnt_type",           "h264.pic_order_cnt_type",
2231                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2232                         NULL, HFILL }
2233                 },
2234                 { &hf_h264_log2_max_pic_order_cnt_lsb_minus4,
2235                         { "log2_max_pic_order_cnt_lsb_minus4",           "h264.log2_max_pic_order_cnt_lsb_minus4",
2236                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2237                         NULL, HFILL }
2238                 },
2239                 { &hf_h264_delta_pic_order_always_zero_flag,
2240                         { "delta_pic_order_always_zero_flag",           "h264.delta_pic_order_always_zero_flag",
2241                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2242                         NULL, HFILL }
2243                 },
2244                 { &hf_h264_offset_for_non_ref_pic,
2245                         { "offset_for_non_ref_pic",           "h264.offset_for_non_ref_pic",
2246                         FT_INT32, BASE_DEC, NULL, 0x0,          
2247                         NULL, HFILL }
2248                 },
2249                 { &hf_h264_offset_for_top_to_bottom_field,
2250                         { "offset_for_top_to_bottom_field",           "h264.offset_for_top_to_bottom_field",
2251                         FT_INT32, BASE_DEC, NULL, 0x0,          
2252                         NULL, HFILL }
2253                 },
2254                 { &hf_h264_num_ref_frames_in_pic_order_cnt_cycle,
2255                         { "num_ref_frames_in_pic_order_cnt_cycle",           "h264.num_ref_frames_in_pic_order_cnt_cycle",
2256                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2257                         NULL, HFILL }
2258                 },
2259                 { &hf_h264_offset_for_ref_frame,
2260                         { "offset_for_ref_frame",           "h264.offset_for_ref_frame",
2261                         FT_INT32, BASE_DEC, NULL, 0x0,          
2262                         NULL, HFILL }
2263                 },
2264                 { &hf_h264_num_ref_frames,
2265                         { "num_ref_frames",           "h264.num_ref_frames",
2266                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2267                         NULL, HFILL }
2268                 },
2269                 { &hf_h264_gaps_in_frame_num_value_allowed_flag,
2270                         { "gaps_in_frame_num_value_allowed_flag",           "h264.gaps_in_frame_num_value_allowed_flag",
2271                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2272                         NULL, HFILL }
2273                 },
2274                 { &hf_h264_pic_width_in_mbs_minus1,
2275                         { "pic_width_in_mbs_minus1",           "h264.pic_width_in_mbs_minus1",
2276                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2277                         NULL, HFILL }
2278                 },
2279                 { &hf_h264_pic_height_in_map_units_minus1,
2280                         { "pic_height_in_map_units_minus1",           "h264.pic_height_in_map_units_minus1",
2281                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2282                         NULL, HFILL }
2283                 },
2284                 { &hf_h264_frame_mbs_only_flag,
2285                         { "frame_mbs_only_flag",           "h264.frame_mbs_only_flag",
2286                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2287                         NULL, HFILL }
2288                 },
2289                 { &hf_h264_mb_adaptive_frame_field_flag,
2290                         { "mb_adaptive_frame_field_flag",           "h264.mb_adaptive_frame_field_flag",
2291                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2292                         NULL, HFILL }
2293                 },
2294                 { &hf_h264_direct_8x8_inference_flag,
2295                         { "direct_8x8_inference_flag",           "h264.direct_8x8_inference_flag",
2296                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2297                         NULL, HFILL }
2298                 },
2299                 { &hf_h264_frame_cropping_flag,
2300                         { "frame_cropping_flag",           "h264.frame_cropping_flag",
2301                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2302                         NULL, HFILL }
2303                 },
2304                 { &hf_h264_frame_crop_left_offset,
2305                         { "frame_crop_left_offset",           "h264.frame_crop_left_offset",
2306                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2307                         NULL, HFILL }
2308                 },
2309                 { &hf_h264_frame_crop_right_offset,
2310                         { "frame_crop_left_offset",           "h264.frame_crop_right_offset",
2311                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2312                         NULL, HFILL }
2313                 },
2314                 { &hf_h264_frame_crop_top_offset,
2315                         { "frame_crop_top_offset",           "h264.frame_crop_top_offset",
2316                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2317                         NULL, HFILL }
2318                 },
2319                 { &hf_h264_frame_crop_bottom_offset,
2320                         { "frame_crop_bottom_offset",           "h264.frame_crop_bottom_offset",
2321                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2322                         NULL, HFILL }
2323                 },
2324                 { &hf_h264_vui_parameters_present_flag,
2325                         { "vui_parameters_present_flag",           "h264.vui_parameters_present_flag",
2326                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2327                         NULL, HFILL }
2328                 },
2329                 { &hf_h264_pic_parameter_set_id,
2330                         { "pic_parameter_set_id",           "h264.pic_parameter_set_id",
2331                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2332                         NULL, HFILL }
2333                 },
2334                 { &hf_h264_entropy_coding_mode_flag,
2335                         { "entropy_coding_mode_flag",           "h264.entropy_coding_mode_flag",
2336                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2337                         NULL, HFILL }
2338                 },
2339                 { &hf_h264_pic_order_present_flag,
2340                         { "pic_order_present_flag",           "h264.pic_order_present_flag",
2341                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2342                         NULL, HFILL }
2343                 },
2344                 { &hf_h264_num_slice_groups_minus1,
2345                         { "num_slice_groups_minus1",           "h264.num_slice_groups_minus1",
2346                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2347                         NULL, HFILL }
2348                 },
2349                 { &hf_h264_slice_group_map_type,
2350                         { "slice_group_map_type",           "h264.slice_group_map_type",
2351                         FT_UINT32, BASE_DEC, VALS(h264_slice_group_map_type_vals), 0x0,          
2352                         NULL, HFILL }
2353                 },
2354                 { &hf_h264_num_ref_idx_l0_active_minus1,
2355                         { "num_ref_idx_l0_active_minus1",           "h264.num_ref_idx_l0_active_minus1",
2356                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2357                         NULL, HFILL }
2358                 },
2359                 { &hf_h264_num_ref_idx_l1_active_minus1,
2360                         { "num_ref_idx_l1_active_minus1",           "h264.num_ref_idx_l1_active_minus1",
2361                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2362                         NULL, HFILL }
2363                 },
2364                 { &hf_h264_weighted_pred_flag,
2365                         { "weighted_pred_flag",           "h264.weighted_pred_flag",
2366                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2367                         NULL, HFILL }
2368                 },
2369                 { &hf_h264_weighted_bipred_idc,
2370                         { "weighted_bipred_idc",           "h264.weighted_bipred_idc",
2371                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2372                         NULL, HFILL }
2373                 },
2374                 { &hf_h264_pic_init_qp_minus26,
2375                         { "pic_init_qp_minus26",           "h264.pic_init_qp_minus26",
2376                         FT_INT32, BASE_DEC, NULL, 0x0,          
2377                         NULL, HFILL }
2378                 },
2379                 { &hf_h264_pic_init_qs_minus26,
2380                         { "pic_init_qs_minus26",           "h264.pic_init_qs_minus26",
2381                         FT_INT32, BASE_DEC, NULL, 0x0,          
2382                         NULL, HFILL }
2383                 },
2384                 { &hf_h264_chroma_qp_index_offset,
2385                         { "chroma_qp_index_offset",           "h264.chroma_qp_index_offset",
2386                         FT_INT32, BASE_DEC, NULL, 0x0,          
2387                         NULL, HFILL }
2388                 },
2389                 { &hf_h264_deblocking_filter_control_present_flag,
2390                         { "deblocking_filter_control_present_flag",           "h264.deblocking_filter_control_present_flag",
2391                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2392                         NULL, HFILL }
2393                 },
2394                 { &hf_h264_constrained_intra_pred_flag,
2395                         { "constrained_intra_pred_flag",           "h264.constrained_intra_pred_flag",
2396                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2397                         NULL, HFILL }
2398                 },
2399                 { &hf_h264_redundant_pic_cnt_present_flag,
2400                         { "redundant_pic_cnt_present_flag",           "h264.redundant_pic_cnt_present_flag",
2401                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2402                         NULL, HFILL }
2403                 },
2404                 { &hf_h264_transform_8x8_mode_flag,
2405                         { "transform_8x8_mode_flag",           "h264.transform_8x8_mode_flag",
2406                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2407                         NULL, HFILL }
2408                 },
2409                 { &hf_h264_pic_scaling_matrix_present_flag,
2410                         { "pic_scaling_matrix_present_flag",           "h264.pic_scaling_matrix_present_flag",
2411                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2412                         NULL, HFILL }
2413                 },
2414                 { &hf_h264_second_chroma_qp_index_offset,
2415                         { "second_chroma_qp_index_offset",           "h264.second_chroma_qp_index_offset",
2416                         FT_INT32, BASE_DEC, NULL, 0x0,          
2417                         NULL, HFILL }
2418                 },
2419
2420                 { &hf_h264_aspect_ratio_info_present_flag,
2421                         { "aspect_ratio_info_present_flag",           "h264.aspect_ratio_info_present_flag",
2422                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2423                         NULL, HFILL }
2424                 },
2425                 { &hf_h264_aspect_ratio_idc,
2426                         { "aspect_ratio_idc",           "h264.aspect_ratio_idc",
2427                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2428                         NULL, HFILL }
2429                 },
2430                 { &hf_h264_sar_width,
2431                         { "sar_width",           "h264.sar_width",
2432                         FT_UINT16, BASE_DEC, NULL, 0x0,          
2433                         NULL, HFILL }
2434                 },
2435                 { &hf_h264_sar_height,
2436                         { "sar_height",           "h264.sar_height",
2437                         FT_UINT16, BASE_DEC, NULL, 0x0,          
2438                         NULL, HFILL }
2439                 },
2440                 { &hf_h264_overscan_info_present_flag,
2441                         { "overscan_info_present_flag",           "h264.overscan_info_present_flag",
2442                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2443                         NULL, HFILL }
2444                 },
2445                 { &hf_h264_overscan_appropriate_flag,
2446                         { "overscan_appropriate_flag",           "h264.overscan_appropriate_flag",
2447                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2448                         NULL, HFILL }
2449                 },
2450                 { &hf_h264_video_signal_type_present_flag,
2451                         { "video_signal_type_present_flag",           "h264.video_signal_type_present_flag",
2452                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2453                         NULL, HFILL }
2454                 },
2455                 { &hf_h264_video_format,
2456                         { "video_format",           "h264.video_format",
2457                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2458                         NULL, HFILL }
2459                 },
2460                 { &hf_h264_video_full_range_flag,
2461                         { "video_full_range_flag",           "h264.video_full_range_flag",
2462                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2463                         NULL, HFILL }
2464                 },
2465                 { &hf_h264_colour_description_present_flag,
2466                         { "colour_description_present_flag",           "h264.colour_description_present_flag",
2467                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2468                         NULL, HFILL }
2469                 },
2470                 { &hf_h264_colour_primaries,
2471                         { "colour_primaries",           "h264.colour_primaries",
2472                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2473                         NULL, HFILL }
2474                 },
2475                 { &hf_h264_transfer_characteristics,
2476                         { "transfer_characteristics",           "h264.transfer_characteristics",
2477                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2478                         NULL, HFILL }
2479                 },
2480                 { &hf_h264_matrix_coefficients,
2481                         { "matrix_coefficients",           "h264.matrix_coefficients",
2482                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2483                         NULL, HFILL }
2484                 },
2485                 { &hf_h264_chroma_loc_info_present_flag,
2486                         { "chroma_loc_info_present_flag",           "h264.chroma_loc_info_present_flag",
2487                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2488                         NULL, HFILL }
2489                 },
2490                 { &hf_h264_chroma_sample_loc_type_top_field,
2491                         { "chroma_sample_loc_type_top_field",           "h264.chroma_sample_loc_type_top_field",
2492                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2493                         NULL, HFILL }
2494                 },
2495                 { &hf_h264_chroma_sample_loc_type_bottom_field,
2496                         { "chroma_sample_loc_type_bottom_field",           "h264.chroma_sample_loc_type_bottom_field",
2497                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2498                         NULL, HFILL }
2499                 },
2500                 { &hf_h264_timing_info_present_flag,
2501                         { "timing_info_present_flag",           "h264.timing_info_present_flag",
2502                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2503                         NULL, HFILL }
2504                 },
2505                 { &hf_h264_num_units_in_tick,
2506                         { "num_units_in_tick",           "h264.num_units_in_tick",
2507                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2508                         NULL, HFILL }
2509                 },
2510                 { &hf_h264_time_scale,
2511                         { "time_scale",           "h264.time_scale",
2512                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2513                         NULL, HFILL }
2514                 },
2515                 { &hf_h264_fixed_frame_rate_flag,
2516                         { "fixed_frame_rate_flag",           "h264.fixed_frame_rate_flag",
2517                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2518                         NULL, HFILL }
2519                 },
2520                 { &hf_h264_nal_hrd_parameters_present_flag,
2521                         { "nal_hrd_parameters_present_flag",           "h264.nal_hrd_parameters_present_flag",
2522                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2523                         NULL, HFILL }
2524                 },
2525                 { &hf_h264_vcl_hrd_parameters_present_flag,
2526                         { "vcl_hrd_parameters_present_flag",           "h264.vcl_hrd_parameters_present_flag",
2527                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2528                         NULL, HFILL }
2529                 },
2530                 { &hf_h264_low_delay_hrd_flag,
2531                         { "low_delay_hrd_flag",           "h264.low_delay_hrd_flag",
2532                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2533                         NULL, HFILL }
2534                 },
2535                 { &hf_h264_pic_struct_present_flag,
2536                         { "pic_struct_present_flag",           "h264.pic_struct_present_flag",
2537                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2538                         NULL, HFILL }
2539                 },
2540                 { &hf_h264_bitstream_restriction_flag,
2541                         { "bitstream_restriction_flag",           "h264.bitstream_restriction_flag",
2542                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2543                         NULL, HFILL }
2544                 },
2545                 { &hf_h264_motion_vectors_over_pic_boundaries_flag,
2546                         { "motion_vectors_over_pic_boundaries_flag",           "h264.motion_vectors_over_pic_boundaries_flag",
2547                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2548                         NULL, HFILL }
2549                 },
2550                 { &hf_h264_max_bytes_per_pic_denom,
2551                         { "max_bytes_per_pic_denom",           "h264.max_bytes_per_pic_denom",
2552                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2553                         NULL, HFILL }
2554                 },
2555                 { &hf_h264_max_bits_per_mb_denom,
2556                         { "max_bits_per_mb_denom",           "h264.max_bits_per_mb_denom",
2557                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2558                         NULL, HFILL }
2559                 },
2560                 { &hf_h264_log2_max_mv_length_horizontal,
2561                         { "max_mv_length_horizontal",           "h264.max_mv_length_horizontal",
2562                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2563                         NULL, HFILL }
2564                 },
2565                 { &hf_h264_log2_max_mv_length_vertical,
2566                         { "log2_max_mv_length_vertical",           "h264.log2_max_mv_length_vertical",
2567                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2568                         NULL, HFILL }
2569                 },
2570                 { &hf_h264_num_reorder_frames,
2571                         { "num_reorder_frames",           "h264.num_reorder_frames",
2572                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2573                         NULL, HFILL }
2574                 },
2575                 { &hf_h264_max_dec_frame_buffering,
2576                         { "max_dec_frame_buffering",           "h264.max_dec_frame_buffering",
2577                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2578                         NULL, HFILL }
2579                 },
2580                 { &hf_h264_cpb_cnt_minus1,
2581                         { "cpb_cnt_minus1",           "h264.cpb_cnt_minus1",
2582                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2583                         NULL, HFILL }
2584                 },
2585                 { &hf_h264_bit_rate_scale,
2586                         { "bit_rate_scale",           "h264.bit_rate_scale",
2587                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2588                         NULL, HFILL }
2589                 },
2590                 { &hf_h264_cpb_size_scale,
2591                         { "cpb_size_scale",           "h264.cpb_size_scale",
2592                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2593                         NULL, HFILL }
2594                 },
2595                 { &hf_h264_bit_rate_value_minus1,
2596                         { "bit_rate_value_minus1",           "h264.bit_rate_value_minus1",
2597                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2598                         NULL, HFILL }
2599                 },
2600                 { &hf_h264_cpb_size_value_minus1,
2601                         { "cpb_size_value_minus1",           "h264.cpb_size_value_minus1",
2602                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2603                         NULL, HFILL }
2604                 },
2605                 { &hf_h264_cbr_flag,
2606                         { "cbr_flag",           "h264.cbr_flag",
2607                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2608                         NULL, HFILL }
2609                 },
2610                 { &hf_h264_initial_cpb_removal_delay_length_minus1,
2611                         { "initial_cpb_removal_delay_length_minus1",           "h264.initial_cpb_removal_delay_length_minus1",
2612                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2613                         NULL, HFILL }
2614                 },
2615                 { &hf_h264_cpb_removal_delay_length_minus1,
2616                         { "cpb_removal_delay_length_minus1",           "h264.cpb_removal_delay_length_minus1",
2617                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2618                         NULL, HFILL }
2619                 },
2620                 { &hf_h264_dpb_output_delay_length_minus11,
2621                         { "dpb_output_delay_length_minus11",           "h264.dpb_output_delay_length_minus11",
2622                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2623                         NULL, HFILL }
2624                 },
2625                 { &hf_h264_time_offset_length,
2626                         { "time_offset_length",           "h264.time_offset_length",
2627                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2628                         NULL, HFILL }
2629                 },
2630                 { &hf_h264_first_mb_in_slice,
2631                         { "first_mb_in_slice",           "h264.first_mb_in_slice",
2632                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2633                         NULL, HFILL }
2634                 },
2635                 { &hf_h264_slice_type,
2636                         { "slice_type",           "h264.slice_type",
2637                         FT_UINT32, BASE_DEC, VALS(h264_slice_type_vals), 0x0,          
2638                         NULL, HFILL }
2639                 },
2640                 { &hf_h264_slice_id,
2641                         { "slice_id",           "h264.slice_id",
2642                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2643                         NULL, HFILL }
2644                 },
2645                 { &hf_h264_payloadsize,
2646                         { "PayloadSize",           "h264.payloadsize",
2647                         FT_UINT32, BASE_DEC, NULL, 0x0,          
2648                         NULL, HFILL }
2649                 },
2650                 { &hf_h264_payloadtype,
2651                         { "payloadType",           "h264.payloadtype",
2652                         FT_UINT32, BASE_DEC, VALS(h264_sei_payload_vals), 0x0,          
2653                         NULL, HFILL }
2654                 },
2655                 { &hf_h264_frame_num,
2656                         { "frame_num",           "h264.frame_num",
2657                         FT_UINT8, BASE_DEC, NULL, 0x0,          
2658                         NULL, HFILL }
2659                 },
2660                 { &hf_h264_par_profile,
2661                         { "Profile", "h264.profile",
2662                         FT_UINT8, BASE_HEX, NULL, 0x00,
2663                         NULL, HFILL}},
2664                 { &hf_h264_par_profile_b,
2665                         { "Baseline Profile", "h264.profile.base",
2666                         FT_BOOLEAN, 8, NULL, 0x40,
2667                         NULL, HFILL}},
2668                 { &hf_h264_par_profile_m,
2669                         { "Main Profile", "h264.profile.main",
2670                         FT_BOOLEAN, 8, NULL, 0x20,
2671                         NULL, HFILL}},
2672                 { &hf_h264_par_profile_e,
2673                         { "Extended Profile.", "h264.profile.ext",
2674                         FT_BOOLEAN, 8, NULL, 0x10,
2675                         NULL, HFILL}},
2676                 { &hf_h264_par_profile_h,
2677                         { "High Profile", "h264.profile.high",
2678                         FT_BOOLEAN, 8, NULL, 0x08,
2679                         NULL, HFILL}},
2680                 { &hf_h264_par_profile_h10,
2681                         { "High 10 Profile", "h264.profile.high10",
2682                         FT_BOOLEAN, 8, NULL, 0x04,
2683                         NULL, HFILL}},
2684                 { &hf_h264_par_profile_h4_2_2,
2685                         { "High 4:2:2 Profile", "h264.profile.high4_2_2",
2686                         FT_BOOLEAN, 8, NULL, 0x02,
2687                         NULL, HFILL}},
2688                 { &hf_h264_par_profile_h4_4_4,
2689                         { "High 4:4:4 Profile", "h264.profile.high4_4_4",
2690                         FT_BOOLEAN, 8, NULL, 0x01,
2691                         NULL, HFILL}},
2692                 { &hf_h264_par_AdditionalModesSupported,
2693                         { "AdditionalModesSupported", "h264.AdditionalModesSupported",
2694                         FT_UINT8, BASE_HEX, NULL, 0x00,
2695                         NULL, HFILL}},
2696                 { &hf_h264_par_add_mode_sup,
2697                         { "Additional Modes Supported", "h264.add_mode_sup",
2698                         FT_UINT8, BASE_HEX, NULL, 0x00,
2699                         NULL, HFILL}},
2700                 { &hf_h264_par_add_mode_sup_rcdo,
2701                         { "Reduced Complexity Decoding Operation (RCDO) support", "h264.add_mode_sup.rcdo",
2702                         FT_BOOLEAN, 8, NULL, 0x40,
2703                         NULL, HFILL}},
2704                 { &hf_h264_par_ProfileIOP,
2705                         { "ProfileIOP", "h264.ProfileIOP",
2706                         FT_UINT8, BASE_HEX, NULL, 0x00,
2707                         NULL, HFILL}},
2708                 { &hf_h264_par_constraint_set0_flag,
2709                         { "constraint_set0_flag", "h264.par.constraint_set0_flag",
2710                         FT_BOOLEAN, 8, NULL, 0x80,
2711                         NULL, HFILL}},
2712                 { &hf_h264_par_constraint_set1_flag,
2713                         { "constraint_set1_flag", "h264.par.constraint_set1_flag",
2714                         FT_BOOLEAN, 8, NULL, 0x40,
2715                         NULL, HFILL}},
2716                 { &hf_h264_par_constraint_set2_flag,
2717                         { "constraint_set2_flag", "h264.par.constraint_set2_flag",
2718                         FT_BOOLEAN, 8, NULL, 0x20,
2719                         NULL, HFILL}},
2720         };
2721
2722 /* Setup protocol subtree array */
2723         static gint *ett[] = {
2724                 &ett_h264,
2725                 &ett_h264_profile,
2726                 &ett_h264_nal,
2727                 &ett_h264_fua,
2728                 &ett_h264_stream,
2729                 &ett_h264_nal_unit,
2730                 &ett_h264_par_profile,
2731                 &ett_h264_par_AdditionalModesSupported,
2732                 &ett_h264_par_ProfileIOP,
2733         };
2734
2735 /* Register the protocol name and description */
2736         proto_h264 = proto_register_protocol("H.264","H264", "h264");
2737
2738 /* Required function calls to register the header fields and subtrees used */
2739         proto_register_field_array(proto_h264, hf, array_length(hf));
2740         proto_register_subtree_array(ett, array_length(ett));
2741         /* Register a configuration option for port */
2742
2743         
2744         h264_module = prefs_register_protocol(proto_h264, proto_reg_handoff_h264);
2745
2746         prefs_register_uint_preference(h264_module, "dynamic.payload.type",
2747                                                     "H264 dynamic payload type",
2748                                                     "The dynamic payload type which will be interpreted as H264"
2749                                                     "; The value must be greater than 95",
2750                                                     10,
2751                                                     &temp_dynamic_payload_type);
2752
2753         
2754         register_dissector("h264", dissect_h264, proto_h264);
2755 }
2756
2757