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