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