h264: Remove unneeded errata checks.
[metze/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  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  *
23  * References:
24  * http://www.ietf.org/rfc/rfc3984.txt?number=3984      Obsolete
25  * http://www.ietf.org/rfc/rfc6184.txt?number=6184
26  * http://www.ietf.org/rfc/rfc6190.txt?number=6190
27  * http://www.itu.int/rec/T-REC-H.264/en
28  * MS-H264PF http://msdn.microsoft.com/en-us/library/hh659565.aspx
29  */
30
31 #include "config.h"
32
33 #include <string.h>
34
35 #include <glib.h>
36
37 #include <epan/packet.h>
38 #include <epan/asn1.h>
39 #include <epan/strutil.h>
40 #include <epan/expert.h>
41 #include <epan/prefs.h>
42 #include <epan/wmem/wmem.h>
43
44 #include "packet-h264.h"
45
46 void proto_register_h264(void);
47 void proto_reg_handoff_h264(void);
48
49 /* Initialize the protocol and registered fields */
50 static int proto_h264                                      = -1;
51 static int hf_h264_type                                    = -1;
52 static int hf_h264_nal_f_bit                               = -1;
53 static int hf_h264_nal_nri                                 = -1;
54 static int hf_h264_start_bit                               = -1;
55 static int hf_h264_forbidden_bit                           = -1;
56 static int hf_h264_end_bit                                 = -1;
57 static int hf_h264_profile                                 = -1;
58 static int hf_h264_profile_idc                             = -1;
59 static int hf_h264_rbsp_stop_bit                           = -1;
60 static int hf_h264_rbsp_trailing_bits                      = -1;
61 static int hf_h264_constraint_set0_flag                    = -1;
62 static int hf_h264_constraint_set1_flag                    = -1;
63 static int hf_h264_constraint_set2_flag                    = -1;
64 static int hf_h264_constraint_set3_flag                    = -1;
65 static int hf_h264_constraint_set4_flag                    = -1;
66 static int hf_h264_constraint_set5_flag                    = -1;
67 static int hf_h264_reserved_zero_2bits                     = -1;
68 static int hf_h264_level_idc                               = -1;
69 static int hf_h264_nal_unit                                = -1;
70 static int hf_h264_forbidden_zero_bit                      = -1;
71 static int hf_h264_nal_ref_idc                             = -1;
72 static int hf_h264_nal_unit_type                           = -1;
73 static int hf_h264_seq_parameter_set_id                    = -1;
74 static int hf_h264_chroma_format_idc                       = -1;
75 static int hf_h264_residual_colour_transform_flag          = -1;
76 static int hf_h264_bit_depth_luma_minus8                   = -1;
77 static int hf_h264_bit_depth_chroma_minus8                 = -1;
78 static int hf_h264_qpprime_y_zero_transform_bypass_flag    = -1;
79 static int hf_h264_seq_scaling_matrix_present_flag         = -1;
80 static int hf_h264_log2_max_frame_num_minus4               = -1;
81 static int hf_h264_pic_order_cnt_type                      = -1;
82 static int hf_h264_log2_max_pic_order_cnt_lsb_minus4       = -1;
83 static int hf_h264_delta_pic_order_always_zero_flag        = -1;
84 static int hf_h264_offset_for_non_ref_pic                  = -1;
85 static int hf_h264_offset_for_top_to_bottom_field          = -1;
86 static int hf_h264_num_ref_frames_in_pic_order_cnt_cycle   = -1;
87 static int hf_h264_offset_for_ref_frame                    = -1;
88 static int hf_h264_num_ref_frames                          = -1;
89 static int hf_h264_gaps_in_frame_num_value_allowed_flag    = -1;
90 static int hf_h264_pic_width_in_mbs_minus1                 = -1;
91 static int hf_h264_pic_height_in_map_units_minus1          = -1;
92 static int hf_h264_frame_mbs_only_flag                     = -1;
93 static int hf_h264_mb_adaptive_frame_field_flag            = -1;
94 static int hf_h264_direct_8x8_inference_flag               = -1;
95 static int hf_h264_frame_cropping_flag                     = -1;
96 static int hf_h264_frame_crop_left_offset                  = -1;
97 static int hf_h264_frame_crop_right_offset                 = -1;
98 static int hf_h264_frame_crop_top_offset                   = -1;
99 static int hf_h264_frame_crop_bottom_offset                = -1;
100 static int hf_h264_vui_parameters_present_flag             = -1;
101 static int hf_h264_pic_parameter_set_id                    = -1;
102 static int hf_h264_entropy_coding_mode_flag                = -1;
103 static int hf_h264_pic_order_present_flag                  = -1;
104 static int hf_h264_num_slice_groups_minus1                 = -1;
105 static int hf_h264_slice_group_map_type                    = -1;
106 static int hf_h264_num_ref_idx_l0_active_minus1            = -1;
107 static int hf_h264_num_ref_idx_l1_active_minus1            = -1;
108 static int hf_h264_weighted_pred_flag                      = -1;
109 static int hf_h264_weighted_bipred_idc                     = -1;
110 static int hf_h264_pic_init_qp_minus26                     = -1;
111 static int hf_h264_pic_init_qs_minus26                     = -1;
112 static int hf_h264_chroma_qp_index_offset                  = -1;
113 static int hf_h264_deblocking_filter_control_present_flag  = -1;
114 static int hf_h264_constrained_intra_pred_flag             = -1;
115 static int hf_h264_redundant_pic_cnt_present_flag          = -1;
116 static int hf_h264_transform_8x8_mode_flag                 = -1;
117 static int hf_h264_pic_scaling_matrix_present_flag         = -1;
118 static int hf_h264_second_chroma_qp_index_offset           = -1;
119 static int hf_h264_par_profile                             = -1;
120 static int hf_h264_par_profile_b                           = -1;
121 static int hf_h264_par_profile_m                           = -1;
122 static int hf_h264_par_profile_e                           = -1;
123 static int hf_h264_par_profile_h                           = -1;
124 static int hf_h264_par_profile_h10                         = -1;
125 static int hf_h264_par_profile_h4_2_2                      = -1;
126 static int hf_h264_par_profile_h4_4_4                      = -1;
127 /* static int hf_h264_par_add_mode_sup                        = -1; */
128 static int hf_h264_par_AdditionalModesSupported            = -1;
129 static int hf_h264_par_add_mode_sup_rcdo                   = -1;
130 static int hf_h264_par_ProfileIOP                          = -1;
131 static int hf_h264_par_constraint_set0_flag                = -1;
132 static int hf_h264_par_constraint_set1_flag                = -1;
133 static int hf_h264_par_constraint_set2_flag                = -1;
134 /* Packetization Values */
135 static int hf_h264_nalu_size                               = -1;
136 static int hf_h264_don                                     = -1;
137 static int hf_h264_dond                                    = -1;
138 static int hf_h264_ts_offset16                             = -1;
139 static int hf_h264_ts_offset24                             = -1;
140 /* Extension Header */
141 static int hf_h264_nal_extension_subtype                   = -1;
142 static int hf_h264_nal_extension_j                         = -1;
143 static int hf_h264_nal_extension_k                         = -1;
144 static int hf_h264_nal_extension_l                         = -1;
145
146 /* SEI Decoding Information */
147 static int hf_h264_sei_uuid                                = -1;
148 /* Microsoft Layout SEI */
149 static int hf_h264_sei_ms_lpb                              = -1;
150 static int hf_h264_sei_ms_layout_p                         = -1;
151 static int hf_h264_sei_ms_layout_ldsize                    = -1;
152 static int hf_h264_sei_ms_layer_desc_coded_width           = -1;
153 static int hf_h264_sei_ms_layer_desc_coded_height          = -1;
154 static int hf_h264_sei_ms_layer_desc_display_width         = -1;
155 static int hf_h264_sei_ms_layer_desc_display_height        = -1;
156 static int hf_h264_sei_ms_layer_desc_bitrate               = -1;
157 static int hf_h264_sei_ms_layer_desc_frame_rate            = -1;
158 static int hf_h264_sei_ms_layer_desc_layer_type            = -1;
159 static int hf_h264_sei_ms_layer_desc_prid                  = -1;
160 static int hf_h264_sei_ms_layer_desc_cb                    = -1;
161 /* Microsoft Bitstream SEI */
162 static int hf_h264_sei_ms_bitstream_ref_frame_cnt          = -1;
163 static int hf_h264_sei_ms_bitstream_num_nalus              = -1;
164 /* Microsoft Crop SEI */
165 static int hf_h264_sei_ms_crop_num_data                    = -1;
166 static int hf_h264_sei_ms_crop_info_type                   = -1;
167 static int hf_h264_sei_ms_crop_confidence_level            = -1;
168 static int hf_h264_sei_ms_crop_frame_left_offset           = -1;
169 static int hf_h264_sei_ms_crop_frame_right_offset          = -1;
170 static int hf_h264_sei_ms_crop_frame_top_offset            = -1;
171 static int hf_h264_sei_ms_crop_frame_bottom_offset         = -1;
172 /* SVC NAL Header Extension Values Annex G.7.3.1.1 */
173 static int hf_h264_nal_hdr_ext_svc                         = -1;
174 static int hf_h264_nal_hdr_ext_i                           = -1;
175 static int hf_h264_nal_hdr_ext_prid                        = -1;
176 static int hf_h264_nal_hdr_ext_n                           = -1;
177 static int hf_h264_nal_hdr_ext_did                         = -1;
178 static int hf_h264_nal_hdr_ext_qid                         = -1;
179 static int hf_h264_nal_hdr_ext_tid                         = -1;
180 static int hf_h264_nal_hdr_ext_u                           = -1;
181 static int hf_h264_nal_hdr_ext_d                           = -1;
182 static int hf_h264_nal_hdr_ext_o                           = -1;
183 static int hf_h264_nal_hdr_ext_rr                          = -1;
184 /* PACSI Values */
185 static int hf_h264_pacsi_x                                 = -1;
186 static int hf_h264_pacsi_y                                 = -1;
187 static int hf_h264_pacsi_t                                 = -1;
188 static int hf_h264_pacsi_a                                 = -1;
189 static int hf_h264_pacsi_p                                 = -1;
190 static int hf_h264_pacsi_c                                 = -1;
191 static int hf_h264_pacsi_s                                 = -1;
192 static int hf_h264_pacsi_e                                 = -1;
193 static int hf_h264_pacsi_tl0picidx                         = -1;
194 static int hf_h264_pacsi_idrpicid                          = -1;
195 static int hf_h264_pacsi_donc                              = -1;
196
197 /* VUI parameters */
198 static int hf_h264_aspect_ratio_info_present_flag          = -1;
199 static int hf_h264_aspect_ratio_idc                        = -1;
200 static int hf_h264_sar_width                               = -1;
201 static int hf_h264_sar_height                              = -1;
202 static int hf_h264_overscan_info_present_flag              = -1;
203 static int hf_h264_overscan_appropriate_flag               = -1;
204 static int hf_h264_video_signal_type_present_flag          = -1;
205 static int hf_h264_video_format                            = -1;
206 static int hf_h264_video_full_range_flag                   = -1;
207 static int hf_h264_colour_description_present_flag         = -1;
208 static int hf_h264_colour_primaries                        = -1;
209 static int hf_h264_transfer_characteristics                = -1;
210 static int hf_h264_matrix_coefficients                     = -1;
211 static int hf_h264_chroma_loc_info_present_flag            = -1;
212 static int hf_h264_chroma_sample_loc_type_top_field        = -1;
213 static int hf_h264_chroma_sample_loc_type_bottom_field     = -1;
214 static int hf_h264_timing_info_present_flag                = -1;
215 static int hf_h264_num_units_in_tick                       = -1;
216 static int hf_h264_time_scale                              = -1;
217 static int hf_h264_fixed_frame_rate_flag                   = -1;
218 static int hf_h264_nal_hrd_parameters_present_flag         = -1;
219 static int hf_h264_vcl_hrd_parameters_present_flag         = -1;
220 static int hf_h264_low_delay_hrd_flag                      = -1;
221 static int hf_h264_pic_struct_present_flag                 = -1;
222 static int hf_h264_bitstream_restriction_flag              = -1;
223 static int hf_h264_motion_vectors_over_pic_boundaries_flag = -1;
224 static int hf_h264_max_bytes_per_pic_denom                 = -1;
225 static int hf_h264_max_bits_per_mb_denom                   = -1;
226 static int hf_h264_log2_max_mv_length_horizontal           = -1;
227 static int hf_h264_log2_max_mv_length_vertical             = -1;
228 static int hf_h264_num_reorder_frames                      = -1;
229 static int hf_h264_max_dec_frame_buffering                 = -1;
230 static int hf_h264_cpb_cnt_minus1                          = -1;
231 static int hf_h264_bit_rate_scale                          = -1;
232 static int hf_h264_cpb_size_scale                          = -1;
233 static int hf_h264_bit_rate_value_minus1                   = -1;
234 static int hf_h264_cpb_size_value_minus1                   = -1;
235 static int hf_h264_cbr_flag                                = -1;
236 static int hf_h264_initial_cpb_removal_delay_length_minus1 = -1;
237 static int hf_h264_cpb_removal_delay_length_minus1         = -1;
238 static int hf_h264_dpb_output_delay_length_minus11         = -1;
239 static int hf_h264_time_offset_length                      = -1;
240
241 static int hf_h264_first_mb_in_slice                       = -1;
242 static int hf_h264_slice_type                              = -1;
243 static int hf_h264_slice_id                                = -1;
244 static int hf_h264_payloadsize                             = -1;
245 static int hf_h264_payloadtype                             = -1;
246 /* static int hf_h264_frame_num                               = -1; */
247
248 /* Initialize the subtree pointers */
249 static int ett_h264                                        = -1;
250 static int ett_h264_profile                                = -1;
251 static int ett_h264_nal                                    = -1;
252 static int ett_h264_fua                                    = -1;
253 static int ett_h264_stream                                 = -1;
254 static int ett_h264_nal_unit                               = -1;
255 static int ett_h264_par_profile                            = -1;
256 static int ett_h264_par_AdditionalModesSupported           = -1;
257 static int ett_h264_par_ProfileIOP                         = -1;
258 static int ett_h264_ms_layer_description                   = -1;
259 static int ett_h264_ms_crop_data                           = -1;
260
261 static expert_field ei_h264_undecoded = EI_INIT;
262 static expert_field ei_h264_ms_layout_wrong_length = EI_INIT;
263 static expert_field ei_h264_bad_nal_length = EI_INIT;
264
265 /* The dynamic payload type range which will be dissected as H.264 */
266
267 #define RTP_PT_DEFAULT_RANGE "0"
268 static range_t *temp_dynamic_payload_type_range = NULL;
269
270 static dissector_handle_t h264_handle;
271
272 /* syntax tables in subclause 7.3 is equal to
273  * ue(v), me(v), se(v), or te(v).
274  */
275 typedef enum {
276     H264_UE_V = 0,
277     H264_ME_V = 1,
278     H264_SE_V = 2,
279     H264_TE_V = 3
280 } h264_golomb_descriptors;
281
282
283 static const true_false_string h264_f_bit_vals = {
284   "Bit errors or other syntax violations",
285   "No bit errors or other syntax violations"
286 };
287
288 static const true_false_string h264_start_bit_vals = {
289   "the first packet of FU-A picture",
290   "Not the first packet of FU-A picture"
291 };
292
293 static const true_false_string h264_end_bit_vals = {
294   "the last packet of FU-A picture",
295   "Not the last packet of FU-A picture"
296 };
297
298 #if 0
299 static const true_false_string h264_forbidden_bit_vals = {
300   "Forbidden Bit of FU-A",
301   "Not Forbidden Bit of FU-A"
302 };
303 #endif
304
305 #define H264_SEQ_PAR_SET        7
306 #define H264_PIC_PAR_SET        8
307 #define H264_PREFIX             14
308 #define H264_STAP_A             24
309 #define H264_STAP_B             25
310 #define H264_MTAP16             26
311 #define H264_MTAP24             27
312 #define H264_PACSI              30
313 #define H264_EXTENSION          31
314
315
316 static const value_string h264_type_values[] = {
317     {  0,   "Undefined" },
318     {  1,   "NAL unit - Coded slice of a non-IDR picture" },    /* Single NAL unit packet per H.264 */
319     {  2,   "NAL unit - Coded slice data partition A" },
320     {  3,   "NAL unit - Coded slice data partition B" },
321     {  4,   "NAL unit - Coded slice data partition C" },
322     {  5,   "NAL unit - Coded slice of an IDR picture" },
323     {  6,   "NAL unit - Supplemental enhancement information (SEI)" },
324     { H264_SEQ_PAR_SET, "NAL unit - Sequence parameter set" },              /* 7 */
325     { H264_PIC_PAR_SET, "NAL unit - Picture parameter set" },               /* 8 */
326     {  9,   "NAL unit - Access unit delimiter" },
327     { 10,   "NAL unit - End of sequence" },
328     { 11,   "NAL unit - End of stream" },
329     { 12,   "NAL unit - Filler data" },
330     { 13,   "NAL unit - Sequence parameter set extension" },
331     { H264_PREFIX,   "NAL unit - Prefix" },
332     { 15,   "NAL unit - Subset sequence parameter set" },
333     { 16,   "NAL unit - Reserved" },
334     { 17,   "NAL unit - Reserved" },
335     { 18,   "NAL unit - Reserved" },
336     { 19,   "NAL unit - Coded slice of an auxiliary coded picture without partitioning" },
337     { 20,   "NAL unit - Coded slice extension" },
338     { 21,   "NAL unit - Coded slice extension for depth view components" },
339     { 22,   "NAL unit - Reserved" },
340     { 23,   "NAL unit - Reserved" },
341     { 24,   "Single-time aggregation packet A (STAP-A)" },
342     { 25,   "Single-time aggregation packet B (STAP-B)" },
343     { 26,   "Multi-time aggregation packet 16 (MTAP16)" },
344     { 27,   "Multi-time aggregation packet 24 (MTAP24)" },
345     { 28,   "Fragmentation unit A (FU-A)" },
346     { 29,   "Fragmentation unit B (FU-B)" },
347     { 30,   "NAL unit - Payload Content Scalability Information (PACSI)" },
348     { 31,   "NAL unit - Extended NAL Header" },
349     { 0,    NULL }
350 };
351
352 static const value_string h264_type_summary_values[] = {
353     {  0,   "Undefined" },
354     {  1,   "non-IDR-Slice" },    /* Single NAL unit packet per H.264 */
355     {  2,   "Slice-A" },
356     {  3,   "Slice-B" },
357     {  4,   "Slice-C" },
358     {  5,   "IDR-Slice" },
359     {  6,   "SEI" },
360     { H264_SEQ_PAR_SET, "SPS" },              /* 7 */
361     { H264_PIC_PAR_SET, "PPS" },               /* 8 */
362     {  9,   "Access-Delimiter" },
363     { 10,   "End-of-Seq" },
364     { 11,   "End-of-Stream" },
365     { 12,   "Filler" },
366     { 13,   "SPS-Ext" },
367     { H264_PREFIX,   "Prefix" },
368     { 15,   "Reserved" },
369     { 16,   "Reserved" },
370     { 17,   "Reserved" },
371     { 18,   "Reserved" },
372     { 19,   "Slice-Aux" },
373     { 20,   "Slice-Ext" },
374     { 21,   "Slice-Ext-Depth" },
375     { 22,   "Reserved" },
376     { 23,   "Reserved" },
377     { 24,   "STAP-A" },
378     { 25,   "STAP-B" },
379     { 26,   "MTAP16" },
380     { 27,   "MTAP24" },
381     { 28,   "FU-A" },
382     { 29,   "FU-B" },
383     { 30,   "PACSI" },
384     { 31,   "EXT" },
385     { 0,    NULL }
386 };
387
388 /* Extension Subtype Strings RFC 6190 4.3 */
389 static const value_string h264_subtype_values[] = {
390     {  0,   "Reserved" },
391     {  1,   "NAL Unit - Empty" },
392     {  2,   "Non-interleaved Multi-Time Aggregation Packet (NI-MTAP)" },
393     { 0,    NULL }
394 };
395 static const value_string h264_subtype_summary_values[] = {
396     {  0,   "Reserved" },
397     {  1,   "Empty" },
398     {  2,   "NI-MTAP" },
399     { 0,    NULL }
400 };
401
402 /* A.2 Profiles */
403 static const value_string h264_profile_idc_values[] = {
404     {  66,  "Baseline profile" },
405     {  77,  "Main profile" },
406     {  83,  "Scalable Baseline" },
407     {  86,  "Scalable High" },
408     {  88,  "Extended profile" },
409     { 100,  "High profile" },
410     { 110,  "High 10 profile" },
411     { 118,  "Multi-view High" },
412     { 122,  "High 4:2:2 profile" },
413     { 128,  "Stereo High" },
414     { 144,  "High 4:4:4 profile" },
415     { 0,    NULL }
416 };
417
418 /* Table A-1 - Level limits */
419 static const value_string h264_level_bitrate_values[] = {
420     { 10,   "64 kb/s" },
421     { 11,   "192 kb/s" },
422     { 12,   "384 kb/s" },
423     { 13,   "768 kb/s" },
424     { 20,   "2 Mb/s" },
425     { 21,   "4 Mb/s" },
426     { 22,   "4 Mb/s" },
427     { 30,   "10 Mb/s" },
428     { 31,   "14 Mb/s" },
429     { 32,   "20 Mb/s" },
430     { 40,   "20 Mb/s" },
431     { 41,   "50 Mb/s" },
432     { 42,   "50 Mb/s" },
433     { 50,   "135 Mb/s" },
434     { 51,   "240 Mb/s" },
435     { 52,   "240 Mb/s" },
436     { 0,    NULL }
437 };
438
439 static const value_string h264_nal_unit_type_vals[] = {
440     {  0,   "Unspecified" },
441     {  1,   "Coded slice of a non-IDR picture" },
442     {  2,   "Coded slice data partition A" },
443     {  3,   "Coded slice data partition B" },
444     {  4,   "Coded slice data partition C" },
445     {  5,   "Coded slice of an IDR picture" },
446     {  6,   "Supplemental enhancement information (SEI)" },
447     {  7,   "Sequence parameter set" },
448     {  8,   "Picture parameter set" },
449     {  9,   "Access unit delimiter" },
450     { 10,   "End of sequence" },
451     { 11,   "End of stream" },
452     { 12,   "Filler data" },
453     { 13,   "Sequence parameter set extension" },
454     { 14,   "Prefix" },
455     { 15,   "Subset sequence parameter set" },
456     { 16,   "Reserved" },
457     { 17,   "Reserved" },
458     { 18,   "Reserved" },
459     { 19,   "Coded slice of an auxiliary coded picture without partitioning" },
460     { 20,   "Coded slice extension" },
461     { 21,   "Coded slice extension for depth view components" },
462     { 22,   "Reserved" },
463     { 23,   "Reserved" },
464     { 24,   "Unspecified" },
465     { 25,   "Unspecified" },
466     { 26,   "Unspecified" },
467     { 27,   "Unspecified" },
468     { 28,   "FU-A" },
469     { 29,   "Unspecified" },
470     { 30,   "Unspecified" },
471     { 31,   "Unspecified" },
472     { 0,    NULL }
473 };
474
475 static const value_string h264_slice_group_map_type_vals[] = {
476     { 0,    "Interleaved slice groups" },
477     { 1,    "Dispersed slice group mapping" },
478     { 2,    "One or more foreground slice groups and a leftover slice group" },
479     { 3,    "Changing slice groups" },
480     { 4,    "Changing slice groups" },
481     { 5,    "Changing slice groups" },
482     { 6,    "Explicit assignment of a slice group to each slice group map unit" },
483     { 0,    NULL }
484 };
485
486 /* Table 7-6 Name association to slice_type */
487 static const value_string h264_slice_type_vals[] = {
488     { 0,    "P (P slice)" },
489     { 1,    "B (B slice)" },
490     { 2,    "I (I slice)" },
491     { 3,    "SP (SP slice)" },
492     { 4,    "SI (SI slice)" },
493     { 5,    "P (P slice)" },
494     { 6,    "B (B slice)" },
495     { 7,    "I (I slice)" },
496     { 8,    "SP (SP slice)" },
497     { 9,    "SI (SI slice)" },
498     { 0,    NULL }
499 };
500
501 /* Microsoft Frame per second index */
502 static const value_string h264_sei_ms_frame_values[] = {
503     { 0,   "7.5 fps" },
504     { 1,   "12.5 fps" },
505     { 2,   "15 fps" },
506     { 3,   "25 fps" },
507     { 4,   "30 fps" },
508     { 5,   "50 fps" },
509     { 6,   "60 fps" },
510     { 0,    NULL }
511 };
512
513 /* Microsoft UUIDs from MS-H264-PF */
514 #define MS_LAYOUT       0
515 #define MS_CROPPING     1
516 #define MS_BITSTREAM    2
517 static const e_guid_t ms_guids[3] = {
518     { 0x139FB1A9, 0x446A, 0x4DEC, {0x8C, 0xBF, 0x65, 0xB1, 0xE1, 0x2D, 0x2C, 0xFD}},    /* Stream Layout */
519     { 0xBB7FC1A0, 0x6986, 0x4052, {0x90, 0xF0, 0x09, 0x29, 0x21, 0x75, 0x39, 0xCF}},    /* Cropping Information*/
520     { 0x05FBC6B9, 0x5A80, 0x40E5, {0xA2, 0x2A, 0xAB, 0x40, 0x20, 0x26, 0x7E, 0x26}}     /* Bitstream Information */
521 };
522
523 static void
524 dissect_h264(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
525
526 /* byte_aligned( ) is specified as follows.
527  * - If the current position in the bitstream is on a byte boundary, i.e.,
528  *   the next bit in the bitstream is the first bit in a byte,
529  *   the return value of byte_aligned( ) is equal to TRUE.
530  * - Otherwise, the return value of byte_aligned( ) is equal to FALSE.
531  */
532 static gboolean
533 h264_byte_aligned(int bit_offset)
534 {
535     if (bit_offset&0x3)
536         return FALSE;
537
538     return TRUE;
539 }
540
541 /* Expect a tvb and a bit offset into the tvb
542  * returns the value and bit_offset
543  */
544 #define cVALS(x) (const value_string*)(x)
545
546 static guint32
547 dissect_h264_exp_golomb_code(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint *start_bit_offset, h264_golomb_descriptors descriptor)
548 /*(tvbuff_t *tvb, gint *start_bit_offset) */
549 {
550     gint     leading_zero_bits, bit_offset, start_offset;
551     guint32  codenum, mask, value, tmp;
552     gint32   se_value = 0;
553     gint     b;
554     char    *str;
555     int      bit;
556     int      i;
557     header_field_info *hf_field = NULL;
558
559     start_offset = *start_bit_offset>>3;
560
561     if (hf_index > -1)
562         hf_field = proto_registrar_get_nth(hf_index);
563
564     bit_offset = *start_bit_offset;
565
566     /* prepare the string */
567     str = (char *)wmem_alloc(wmem_packet_scope(), 256);
568     str[0] = '\0';
569     for (bit=0; bit<((int)(bit_offset&0x07)); bit++) {
570         if (bit && (!(bit%4))) {
571             g_strlcat(str, " ", 256);
572         }
573         g_strlcat(str,".", 256);
574     }
575
576
577     leading_zero_bits = -1;
578     for (b = 0; !b; leading_zero_bits++) {
579         if (bit && (!(bit%4))) {
580             g_strlcat(str, " ", 256);
581         }
582         if (bit && (!(bit%8))) {
583             g_strlcat(str, " ", 256);
584         }
585         b = tvb_get_bits8(tvb, bit_offset, 1);
586         if (b != 0) {
587             g_strlcat(str, "1", 256);
588         } else {
589             g_strlcat(str, "0", 256);
590         }
591         bit++;
592         bit_offset++;
593     }
594
595     if (leading_zero_bits == 0) {
596         codenum = 0;
597         *start_bit_offset = bit_offset;
598         for (; bit%8; bit++) {
599             if (bit && (!(bit%4))) {
600                 g_strlcat(str, " ", 256);
601             }
602         g_strlcat(str,".", 256);
603         }
604         if (hf_field) {
605             g_strlcat(str," = ", 256);
606             g_strlcat(str, hf_field->name, 256);
607             switch (descriptor) {
608             case H264_SE_V:
609                 /* if the syntax element is coded as se(v),
610                  * the value of the syntax element is derived by invoking the
611                  * mapping process for signed Exp-Golomb codes as specified in
612                  * subclause 9.1.1 with codeNum as the input.
613                  */
614                 if (hf_field->type == FT_INT32) {
615                     if (hf_field->strings) {
616                         proto_tree_add_int_format(tree, hf_index, tvb, start_offset, 1, codenum,
617                               "%s: %s (%d)",
618                               str,
619                               val_to_str_const(codenum, cVALS(hf_field->strings), "Unknown "),
620                               codenum);
621                     } else {
622                         switch (hf_field->display) {
623                             case BASE_DEC:
624                                 proto_tree_add_int_format(tree, hf_index, tvb, start_offset, 1, codenum,
625                                      "%s: %d",
626                                       str,
627                                       codenum);
628                                 break;
629                             default:
630                                 DISSECTOR_ASSERT_NOT_REACHED();
631                                 break;
632                         }
633                     }
634                 }
635                 return codenum;
636             default:
637                 break;
638             }
639             if (hf_field->type == FT_UINT32) {
640                 if (hf_field->strings) {
641                     proto_tree_add_uint_format(tree, hf_index, tvb, start_offset, 1, codenum,
642                           "%s: %s (%u)",
643                           str,
644                           val_to_str_const(codenum, cVALS(hf_field->strings), "Unknown "),
645                           codenum);
646                 } else {
647                     switch (hf_field->display) {
648                         case BASE_DEC:
649                             proto_tree_add_uint_format(tree, hf_index, tvb, start_offset, 1, codenum,
650                                  "%s: %u",
651                                   str,
652                                   codenum);
653                             break;
654                         case BASE_HEX:
655                             proto_tree_add_uint_format(tree, hf_index, tvb, start_offset, 1, codenum,
656                                  "%s: 0x%x",
657                                   str,
658                                   codenum);
659                             break;
660                         default:
661                             DISSECTOR_ASSERT_NOT_REACHED();
662                             break;
663                     }
664                 }
665             } else {
666                 /* Only allow guint32 */
667                 DISSECTOR_ASSERT_NOT_REACHED();
668             }
669         }
670         return codenum;
671     }
672
673     /*
674     Syntax elements coded as ue(v), me(v), or se(v) are Exp-Golomb-coded. Syntax elements coded as te(v) are truncated
675     Exp-Golomb-coded. The parsing process for these syntax elements begins with reading the bits starting at the current
676     location in the bitstream up to and including the first non-zero bit, and counting the number of leading bits that are
677     equal to 0. This process is specified as follows:
678     leadingZeroBits = -1;
679     for (b = 0; !b; leadingZeroBits++)
680     b = read_bits( 1 )
681     The variable codeNum is then assigned as follows:
682     codeNum = 2leadingZeroBits - 1 + read_bits( leadingZeroBits )
683     where the value returned from read_bits( leadingZeroBits ) is interpreted as a binary representation of an unsigned
684     integer with most significant bit written first.
685     */
686     codenum = 1;
687     codenum = codenum << leading_zero_bits;
688     mask = codenum>>1;
689     if (leading_zero_bits > 32)
690         DISSECTOR_ASSERT_NOT_REACHED();
691     else if (leading_zero_bits > 16)
692         value = tvb_get_bits32(tvb, bit_offset, leading_zero_bits, ENC_BIG_ENDIAN);
693     else if (leading_zero_bits > 8)
694         value = tvb_get_bits16(tvb, bit_offset, leading_zero_bits, ENC_BIG_ENDIAN);
695     else
696         value = tvb_get_bits8(tvb, bit_offset, leading_zero_bits);
697     codenum = (codenum-1) + value;
698     bit_offset = bit_offset + leading_zero_bits;
699
700     /* read the bits for the int */
701     for (i=0; i<leading_zero_bits; i++) {
702         if (bit && (!(bit%4))) {
703             g_strlcat(str, " ", 256);
704         }
705         if (bit && (!(bit%8))) {
706             g_strlcat(str, " ", 256);
707         }
708         bit++;
709         tmp = value & mask;
710         if (tmp != 0) {
711             g_strlcat(str, "1", 256);
712         } else {
713             g_strlcat(str, "0", 256);
714         }
715         mask = mask>>1;
716     }
717     for ( ; bit%8; bit++) {
718         if (bit && (!(bit%4))) {
719             g_strlcat(str, " ", 256);
720         }
721         g_strlcat(str,".", 256);
722     }
723
724     switch (descriptor) {
725     case H264_SE_V:
726         /* if the syntax element is coded as se(v),
727          * the value of the syntax element is derived by invoking the
728          * mapping process for signed Exp-Golomb codes as specified in
729          * subclause 9.1.1 with codeNum as the input.
730          *      k+1
731          * (-1)    Ceil( k/2 )
732          */
733         se_value = (codenum + 1) >> 1;
734         if (!(se_value & 1)) {
735             se_value =  - se_value;
736         }
737         break;
738     default:
739         break;
740     }
741
742     if (hf_field) {
743         g_strlcat(str," = ", 256);
744         g_strlcat(str, hf_field->name, 256);
745         switch (descriptor) {
746         case H264_SE_V:
747             g_strlcat(str,"(se(v))", 256);
748             /* if the syntax element is coded as se(v),
749              * the value of the syntax element is derived by invoking the
750              * mapping process for signed Exp-Golomb codes as specified in
751              * subclause 9.1.1 with codeNum as the input.
752              */
753             break;
754         default:
755         break;
756         }
757         if ((hf_field->type == FT_UINT32) && (descriptor == H264_UE_V)) {
758             if (hf_field->strings) {
759                 proto_tree_add_uint_format(tree, hf_index, tvb, start_offset, 1, codenum,
760                           "%s: %s (%u)",
761                           str,
762                           val_to_str_const(codenum, cVALS(hf_field->strings), "Unknown "),
763                           codenum);
764             } else {
765                 switch (hf_field->display) {
766                     case BASE_DEC:
767                         proto_tree_add_uint_format(tree, hf_index, tvb, start_offset, 1, codenum,
768                              "%s: %u",
769                               str,
770                               codenum);
771                         break;
772                     case BASE_HEX:
773                         proto_tree_add_uint_format(tree, hf_index, tvb, start_offset, 1, codenum,
774                              "%s: 0x%x",
775                               str,
776                               codenum);
777                         break;
778                     default:
779                         DISSECTOR_ASSERT_NOT_REACHED();
780                         break;
781                 }
782             }
783         } else if ((hf_field->type == FT_INT32) && (descriptor == H264_SE_V)) {
784             if (hf_field->strings) {
785                 proto_tree_add_int_format(tree, hf_index, tvb, start_offset, 1, codenum,
786                           "%s: %s (%d)",
787                           str,
788                           val_to_str_const(codenum, cVALS(hf_field->strings), "Unknown "),
789                           se_value);
790             } else {
791                 switch (hf_field->display) {
792                     case BASE_DEC:
793                         proto_tree_add_int_format(tree, hf_index, tvb, start_offset, 1, codenum,
794                              "%s: %d",
795                               str,
796                               se_value);
797                         break;
798                     default:
799                         DISSECTOR_ASSERT_NOT_REACHED();
800                         break;
801                 }
802             }
803             *start_bit_offset = bit_offset;
804             return se_value;
805
806         } else {
807             /* Only allow guint32 */
808             DISSECTOR_ASSERT_NOT_REACHED();
809         }
810     }
811
812     *start_bit_offset = bit_offset;
813     return codenum;
814 }
815
816 /* This function is adapted to parsing NAL units from SDP data where the
817  * base64 coding may add extra padding
818  */
819
820 static gboolean
821 more_rbsp_data(proto_tree *tree _U_, tvbuff_t *tvb, packet_info *pinfo _U_, gint bit_offset)
822 {
823     int    offset;
824     int    remaining_length;
825     int    last_one_bit;
826     guint8 b = 0;
827
828     /* XXX might not be the best way of doing things but:
829      * Serch from the end of the tvb for the first '1' bit
830      * assuming that it's the RTBSP stop bit
831      */
832
833     /* Set offset to the byte we are treating */
834     offset = bit_offset>>3;
835     remaining_length = tvb_length_remaining(tvb, offset);
836     /* If there is more then 2 bytes left there *should* be more data */
837     if (remaining_length>2) {
838         return TRUE;
839     }
840     /* Start from last bit */
841     last_one_bit = (tvb_length(tvb) << 3);
842
843     for (b = 0; !b; ) {
844         last_one_bit--;
845         b = tvb_get_bits8(tvb, last_one_bit, 1);
846     }
847
848     if (last_one_bit == bit_offset) {
849         return FALSE;
850     }
851
852     return TRUE;
853 }
854
855 static int
856 dissect_h264_rbsp_trailing_bits(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint bit_offset)
857 {
858     gint remaining_bits=0;
859
860     proto_tree_add_bits_item(tree, hf_h264_rbsp_stop_bit, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
861     bit_offset++;
862
863     if ((bit_offset&0x7) != 0) {
864         remaining_bits = 8 - (bit_offset&0x7);
865         proto_tree_add_bits_item(tree, hf_h264_rbsp_trailing_bits, tvb, bit_offset, remaining_bits, ENC_BIG_ENDIAN);
866     }
867
868     return bit_offset+remaining_bits;
869 }
870
871 /*
872  * 7.3.3 Slice header syntax
873  * slice_header( )
874  * XXX Just parse a few bytes
875  */
876 static int
877 dissect_h264_slice_header(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint bit_offset)
878 {
879     /* first_mb_in_slice 2 ue(v) */
880     dissect_h264_exp_golomb_code(tree, hf_h264_first_mb_in_slice, tvb, &bit_offset, H264_UE_V);
881
882     /* slice_type 2 ue(v) */
883     dissect_h264_exp_golomb_code(tree, hf_h264_slice_type, tvb, &bit_offset, H264_UE_V);
884
885     /* pic_parameter_set_id 2 ue(v) */
886     dissect_h264_exp_golomb_code(tree, hf_h264_pic_parameter_set_id, tvb, &bit_offset, H264_UE_V);
887
888     /* frame_num 2 u(v) */
889     /*
890      * represented by log2_max_frame_num_minus4 + 4 bits in
891      * the bitstream
892      * proto_tree_add_bits_item(tree, hf_h264_frame_num, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
893      */
894
895     return bit_offset;
896 }
897
898 /* 7.3.2.1.1 Scaling list syntax
899  *
900  * scaling_list( scalingList, sizeOfScalingList, useDefaultScalingMatrixFlag )
901  */
902 /*
903 static int
904 dissect_h264_scaling_list(proto_tree *tree, tvbuff_t *tvb, gint bit_offset, int hf_index_scalinglist,
905                           guint8 sizeOfScalingList, int hf_index_usedefaultscalingmatrixflag)
906 {
907
908     guint8 lastScale = 8;
909     guint8 nextScale = 8:
910     guint8 delta_scale;
911
912     for (j = 0; j < sizeOfScalingList; j++) {
913       if (nextScale != 0) {
914           / delta_scale 0 | 1 se(v) /
915           delta_scale = dissect_h264_exp_golomb_code(tree, hf_h264_delta_scale, tvb, &bit_offset);
916           nextScale = ( lastScale + delta_scale + 256 ) % 256;
917           useDefaultScalingMatrixFlag = ( j == 0 && nextScale == 0 );
918     }
919     scalingList[ j ] = ( nextScale == 0 ) ? lastScale : nextScale
920     lastScale = scalingList[ j ]
921     }
922 }
923 */
924 /* E.1.2 HRD parameters syntax */
925 static int
926 dissect_h264_hrd_parameters(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint bit_offset)
927 {
928     guint8 cpb_cnt_minus1;
929     int    SchedSelIdx;
930
931
932     /* cpb_cnt_minus1 0 ue(v) */
933     cpb_cnt_minus1 = dissect_h264_exp_golomb_code(tree, hf_h264_cpb_cnt_minus1, tvb, &bit_offset, H264_UE_V);
934
935     /* bit_rate_scale 0 u(4) */
936     proto_tree_add_bits_item(tree, hf_h264_bit_rate_scale, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
937     bit_offset = bit_offset + 4;
938
939     /* cpb_size_scale 0 u(4) */
940     proto_tree_add_bits_item(tree, hf_h264_cpb_size_scale, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
941     bit_offset = bit_offset + 4;
942     /* for (SchedSelIdx = 0; SchedSelIdx <= cpb_cnt_minus1; SchedSelIdx++) { */
943     for (SchedSelIdx = 0; SchedSelIdx <= cpb_cnt_minus1; SchedSelIdx++) {
944
945         /* bit_rate_value_minus1[ SchedSelIdx ] 0 ue(v) */
946         dissect_h264_exp_golomb_code(tree, hf_h264_bit_rate_value_minus1, tvb, &bit_offset, H264_UE_V);
947
948         /* cpb_size_value_minus1[ SchedSelIdx ] 0 ue(v)*/
949         dissect_h264_exp_golomb_code(tree, hf_h264_cpb_size_value_minus1, tvb, &bit_offset, H264_UE_V);
950
951         /* cbr_flag[ SchedSelIdx ] 0 u(1) */
952         proto_tree_add_bits_item(tree, hf_h264_cbr_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
953         bit_offset++;
954     }
955     /* initial_cpb_removal_delay_length_minus1 0 u(5) */
956     proto_tree_add_bits_item(tree, hf_h264_initial_cpb_removal_delay_length_minus1, tvb, bit_offset, 5, ENC_BIG_ENDIAN);
957     bit_offset = bit_offset + 5;
958
959     /* cpb_removal_delay_length_minus1 0 u(5) */
960     proto_tree_add_bits_item(tree, hf_h264_cpb_removal_delay_length_minus1, tvb, bit_offset, 5, ENC_BIG_ENDIAN);
961     bit_offset = bit_offset + 5;
962
963     /* dpb_output_delay_length_minus1 0 u(5) */
964     proto_tree_add_bits_item(tree, hf_h264_dpb_output_delay_length_minus11, tvb, bit_offset, 5, ENC_BIG_ENDIAN);
965     bit_offset = bit_offset + 5;
966
967     /* time_offset_length 0 u(5) */
968     proto_tree_add_bits_item(tree, hf_h264_time_offset_length, tvb, bit_offset, 5, ENC_BIG_ENDIAN);
969     bit_offset = bit_offset + 5;
970
971     return bit_offset;
972 }
973
974 #define EXTENDED_SAR 255
975
976 /* E.1.1 VUI parameters syntax */
977
978 /* Table E-2 - Meaning of video_format */
979 static const value_string h264_video_format_vals[] = {
980     { 22,   "reserved_sei_message)" },
981     {  0,   "Component" },
982     {  1,   "PAL" },
983     {  2,   "NTSC" },
984     {  3,   "SECAM" },
985     {  4,   "MAC" },
986     {  5,   "Unspecified video format" },
987     {  6,   "Reserved" },
988     {  7,   "Reserved" },
989     { 0,    NULL }
990 };
991
992 static int
993 dissect_h264_vui_parameters(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint bit_offset)
994 {
995
996     guint8 aspect_ratio_info_present_flag, aspect_ratio_idc, overscan_info_present_flag;
997     guint8 video_signal_type_present_flag, colour_description_present_flag, chroma_loc_info_present_flag;
998     guint8 timing_info_present_flag, nal_hrd_parameters_present_flag, vcl_hrd_parameters_present_flag;
999     guint8 bitstream_restriction_flag;
1000
1001     /* vui_parameters( ) {
1002      * aspect_ratio_info_present_flag 0 u(1)
1003      */
1004     aspect_ratio_info_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1005     proto_tree_add_bits_item(tree, hf_h264_aspect_ratio_info_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1006     bit_offset++;
1007
1008     if (aspect_ratio_info_present_flag) {
1009         /* aspect_ratio_idc 0 u(8) */
1010         aspect_ratio_idc = tvb_get_bits8(tvb, bit_offset, 8);
1011         proto_tree_add_bits_item(tree, hf_h264_aspect_ratio_idc, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
1012         bit_offset = bit_offset + 8;
1013
1014         if (aspect_ratio_idc == EXTENDED_SAR) {
1015             /* sar_width 0 u(16) */
1016             proto_tree_add_bits_item(tree, hf_h264_sar_width, tvb, bit_offset, 16, ENC_BIG_ENDIAN);
1017             bit_offset = bit_offset + 16;
1018
1019             /* sar_height 0 u(16) */
1020             proto_tree_add_bits_item(tree, hf_h264_sar_height, tvb, bit_offset, 16, ENC_BIG_ENDIAN);
1021             bit_offset = bit_offset + 16;
1022         }
1023     }
1024     /* overscan_info_present_flag 0 u(1) */
1025     overscan_info_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1026     proto_tree_add_bits_item(tree, hf_h264_overscan_info_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1027     bit_offset++;
1028
1029     if (overscan_info_present_flag) {
1030         /* overscan_appropriate_flag 0 u(1) */
1031         proto_tree_add_bits_item(tree, hf_h264_overscan_appropriate_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1032         bit_offset++;
1033     }
1034
1035     /* video_signal_type_present_flag 0 u(1) */
1036     video_signal_type_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1037     proto_tree_add_bits_item(tree, hf_h264_video_signal_type_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1038     bit_offset++;
1039
1040     if (video_signal_type_present_flag) {
1041         /* video_format 0 u(3) > */
1042         proto_tree_add_bits_item(tree, hf_h264_video_format, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
1043         bit_offset = bit_offset + 3;
1044
1045         /* video_full_range_flag 0 u(1)*/
1046         proto_tree_add_bits_item(tree, hf_h264_video_full_range_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1047         bit_offset++;
1048
1049         /* colour_description_present_flag 0 u(1) */
1050         colour_description_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1051         proto_tree_add_bits_item(tree, hf_h264_colour_description_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1052         bit_offset++;
1053
1054         if (colour_description_present_flag) {
1055             /* colour_primaries 0 u(8) */
1056             proto_tree_add_bits_item(tree, hf_h264_colour_primaries, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
1057             bit_offset = bit_offset + 8;
1058
1059             /* transfer_characteristics 0 u(8) */
1060             proto_tree_add_bits_item(tree, hf_h264_transfer_characteristics, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
1061             bit_offset = bit_offset + 8;
1062
1063             /* matrix_coefficients 0 u(8)*/
1064             proto_tree_add_bits_item(tree, hf_h264_matrix_coefficients, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
1065             bit_offset = bit_offset + 8;
1066         }
1067     }
1068
1069     /* chroma_loc_info_present_flag 0 u(1) */
1070     chroma_loc_info_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1071     proto_tree_add_bits_item(tree, hf_h264_chroma_loc_info_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1072     bit_offset++;
1073
1074     if (chroma_loc_info_present_flag) {
1075         /* chroma_sample_loc_type_top_field 0 ue(v) */
1076         dissect_h264_exp_golomb_code(tree, hf_h264_chroma_sample_loc_type_top_field, tvb, &bit_offset, H264_UE_V);
1077
1078         /* chroma_sample_loc_type_bottom_field 0 ue(v) */
1079         dissect_h264_exp_golomb_code(tree, hf_h264_chroma_sample_loc_type_bottom_field, tvb, &bit_offset, H264_UE_V);
1080     }
1081
1082     /* timing_info_present_flag 0 u(1) */
1083     timing_info_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1084     proto_tree_add_bits_item(tree, hf_h264_timing_info_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1085     bit_offset++;
1086
1087     if (timing_info_present_flag) {
1088         /* num_units_in_tick 0 u(32) */
1089         proto_tree_add_bits_item(tree, hf_h264_num_units_in_tick, tvb, bit_offset, 32, ENC_BIG_ENDIAN);
1090         bit_offset = bit_offset + 32;
1091
1092         /* time_scale 0 u(32) */
1093         proto_tree_add_bits_item(tree, hf_h264_time_scale, tvb, bit_offset, 32, ENC_BIG_ENDIAN);
1094         bit_offset = bit_offset + 32;
1095
1096         /* fixed_frame_rate_flag 0 u(1) */
1097         proto_tree_add_bits_item(tree, hf_h264_fixed_frame_rate_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1098         bit_offset++;
1099     }
1100     /* nal_hrd_parameters_present_flag 0 u(1) */
1101     nal_hrd_parameters_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1102     proto_tree_add_bits_item(tree, hf_h264_nal_hrd_parameters_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1103     bit_offset++;
1104
1105     if (nal_hrd_parameters_present_flag) {
1106         /* hrd_parameters( ) */
1107         bit_offset = dissect_h264_hrd_parameters(tree, tvb, pinfo, bit_offset);
1108     }
1109
1110     /* vcl_hrd_parameters_present_flag 0 u(1) */
1111     vcl_hrd_parameters_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1112     proto_tree_add_bits_item(tree, hf_h264_vcl_hrd_parameters_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1113     bit_offset++;
1114
1115     if (vcl_hrd_parameters_present_flag) {
1116         /* hrd_parameters( ) */
1117         bit_offset = dissect_h264_hrd_parameters(tree, tvb, pinfo, bit_offset);
1118     }
1119     if (nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag) {
1120         /* low_delay_hrd_flag 0 u(1) */
1121         proto_tree_add_bits_item(tree, hf_h264_low_delay_hrd_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1122         bit_offset++;
1123     }
1124     /* pic_struct_present_flag 0 u(1) */
1125     proto_tree_add_bits_item(tree, hf_h264_pic_struct_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1126     bit_offset++;
1127
1128     /* bitstream_restriction_flag 0 u(1) */
1129     bitstream_restriction_flag = tvb_get_bits8(tvb, bit_offset, 1);
1130     proto_tree_add_bits_item(tree, hf_h264_bitstream_restriction_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1131     bit_offset++;
1132
1133     if (bitstream_restriction_flag) {
1134         /* motion_vectors_over_pic_boundaries_flag 0 u(1) */
1135         proto_tree_add_bits_item(tree, hf_h264_motion_vectors_over_pic_boundaries_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1136         bit_offset++;
1137
1138         /* max_bytes_per_pic_denom 0 ue(v) */
1139         dissect_h264_exp_golomb_code(tree, hf_h264_max_bytes_per_pic_denom, tvb, &bit_offset, H264_UE_V);
1140
1141         /* max_bits_per_mb_denom 0 ue(v) */
1142         dissect_h264_exp_golomb_code(tree, hf_h264_max_bits_per_mb_denom, tvb, &bit_offset, H264_UE_V);
1143
1144         /* log2_max_mv_length_horizontal 0 ue(v) */
1145         dissect_h264_exp_golomb_code(tree, hf_h264_log2_max_mv_length_horizontal, tvb, &bit_offset, H264_UE_V);
1146
1147         /* log2_max_mv_length_vertical 0 ue(v) */
1148         dissect_h264_exp_golomb_code(tree, hf_h264_log2_max_mv_length_vertical, tvb, &bit_offset, H264_UE_V);
1149
1150         /* num_reorder_frames 0 ue(v) */
1151         dissect_h264_exp_golomb_code(tree, hf_h264_num_reorder_frames, tvb, &bit_offset, H264_UE_V);
1152
1153         /* max_dec_frame_buffering 0 ue(v) */
1154         dissect_h264_exp_golomb_code(tree, hf_h264_max_dec_frame_buffering, tvb, &bit_offset, H264_UE_V);
1155     }
1156
1157     return bit_offset;
1158 }
1159
1160 /* Used To dissect SDP parameter (H.264)profile */
1161 void
1162 dissect_h264_profile(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
1163 {
1164     proto_item *item, *level_item;
1165     proto_tree *h264_profile_tree;
1166     gint        offset = 0;
1167     guint8      constraint_set3_flag;
1168     guint32     level_idc;
1169
1170     item = proto_tree_add_item(tree, hf_h264_profile, tvb, offset, -1, ENC_NA);
1171     h264_profile_tree = proto_item_add_subtree(item, ett_h264_profile);
1172
1173     proto_tree_add_item(h264_profile_tree, hf_h264_profile_idc, tvb, offset, 1, ENC_BIG_ENDIAN);
1174     offset++;
1175
1176     constraint_set3_flag = (tvb_get_guint8(tvb, offset)&0x10)>>4;
1177     proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set0_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1178     proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set1_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1179     proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set2_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1180     proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set3_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1181     proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set4_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1182     proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set5_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1183     proto_tree_add_item(h264_profile_tree, hf_h264_reserved_zero_2bits, tvb, offset, 1, ENC_BIG_ENDIAN);
1184     offset++;
1185
1186     /* A level to which the bitstream conforms shall be indicated by the syntax element level_idc as follows.
1187      *  - If level_idc is equal to 11 and constraint_set3_flag is equal to 1, the indicated level is level 1b.
1188      *  - Otherwise (level_idc is not equal to 11 or constraint_set3_flag is not equal to 1), level_idc shall
1189      *    be set equal to a value of ten times the level number specified in Table A-1 and constraint_set3_flag
1190      *    shall be set equal to 0.
1191      */
1192
1193     level_idc = tvb_get_guint8(tvb, offset);
1194     level_item = proto_tree_add_item(h264_profile_tree, hf_h264_level_idc, tvb, offset, 1, ENC_BIG_ENDIAN);
1195     if ((level_idc == 11) && (constraint_set3_flag == 1)) {
1196         proto_item_append_text(level_item," [Level 1b (128kb/s)]");
1197     } else {
1198         proto_item_append_text(level_item," [Level %.1f %s]", ((double)level_idc/10), val_to_str_const(level_idc, h264_level_bitrate_values, "Unknown "));
1199     }
1200 }
1201
1202 /*
1203  * 7.3.1 NAL unit syntax
1204  * Un escape the NAL tvb
1205  *
1206  *
1207  * nal_unit( NumBytesInNALunit ) { C Descriptor
1208  *   forbidden_zero_bit All f(1)
1209  *   nal_ref_idc All u(2)
1210  *   nal_unit_type All u(5)
1211  *   NumBytesInRBSP = 0
1212  *   for (i = 1; i < NumBytesInNALunit; i++) {
1213  *     if (i + 2 < NumBytesInNALunit && next_bits( 24 ) = = 0x000003 ) {
1214  *       rbsp_byte[ NumBytesInRBSP++ ] All b(8)
1215  *       rbsp_byte[ NumBytesInRBSP++ ] All b(8)
1216  *       i += 2
1217  *       emulation_prevention_three_byte / * equal to 0x03 * / All f(8)
1218  *     } else
1219  *       rbsp_byte[ NumBytesInRBSP++ ] All b(8)
1220  *     }
1221  *   }
1222  */
1223
1224 static tvbuff_t *
1225 dissect_h265_unescap_nal_unit(tvbuff_t *tvb, packet_info *pinfo, int offset)
1226 {
1227     tvbuff_t *tvb_rbsp;
1228     int       length         = tvb_length_remaining(tvb, offset);
1229     int       NumBytesInRBSP = 0;
1230     int       i;
1231     gchar    *buff;
1232
1233     buff = (gchar *)wmem_alloc(pinfo->pool, length);
1234     for (i = 0; i < length; i++) {
1235         if ((i + 2 < length) && (tvb_get_ntoh24(tvb, offset) == 0x000003)) {
1236             buff[NumBytesInRBSP++] = tvb_get_guint8(tvb, offset);
1237             buff[NumBytesInRBSP++] = tvb_get_guint8(tvb, offset+1);
1238             i += 2;
1239             offset+=3;
1240         } else {
1241             buff[ NumBytesInRBSP++] = tvb_get_guint8(tvb, offset);
1242             offset++;
1243         }
1244     }
1245
1246     tvb_rbsp = tvb_new_child_real_data(tvb, buff, NumBytesInRBSP, NumBytesInRBSP);
1247     add_new_data_source(pinfo, tvb_rbsp, "Unescaped RSP Data");
1248
1249     return tvb_rbsp;
1250 }
1251
1252 /*
1253  * 7.3.2.8 Slice layer without partitioning RBSP syntax
1254  * slice_layer_without_partitioning_rbsp( )
1255  */
1256
1257 static void
1258 dissect_h264_slice_layer_without_partitioning_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint offset)
1259 {
1260     gint bit_offset;
1261
1262     bit_offset = offset <<3;
1263
1264     /* slice_header( ) 2 */
1265     bit_offset = dissect_h264_slice_header(tree, tvb, pinfo, bit_offset);
1266     proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, bit_offset>>3, -1);
1267     return;
1268     /* slice_data( ) * all categories of slice_data( ) syntax * 2 | 3 | 4 */
1269     /* rbsp_slice_trailing_bits( ) */
1270 }
1271
1272 /*
1273  * 7.3.2.9.1 Slice data partition A RBSP syntax
1274  * slice_data_partition_a_layer_rbsp( )
1275  */
1276 static void
1277 dissect_h264_slice_data_partition_a_layer_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1278 {
1279     gint bit_offset;
1280
1281     bit_offset = offset <<3;
1282
1283     /* slice_header( ) 2 */
1284     bit_offset = dissect_h264_slice_header(tree, tvb, pinfo, bit_offset);
1285
1286     /* slice_id All ue(v) */
1287     dissect_h264_exp_golomb_code(tree, hf_h264_slice_id, tvb, &bit_offset, H264_UE_V);
1288     proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, bit_offset>>3, -1);
1289     return;
1290     /* slice_data( ) * only category 2 parts of slice_data( ) syntax * 2*/
1291     /* rbsp_slice_trailing_bits( )*/
1292 }
1293
1294 /*
1295  * 7.3.2.9.2 Slice data partition B RBSP syntax
1296  * slice_data_partition_b_layer_rbsp(
1297  */
1298 static void
1299 dissect_h264_slice_data_partition_b_layer_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1300 {
1301     gint bit_offset;
1302
1303     bit_offset = offset <<3;
1304
1305     /* slice_id All ue(v) */
1306     dissect_h264_exp_golomb_code(tree, hf_h264_slice_id, tvb, &bit_offset, H264_UE_V);
1307     /* if (redundant_pic_cnt_present_flag) */
1308     /* redundant_pic_cnt All ue(v) */
1309     /* slice_data( ) * only category 3 parts of slice_data( ) syntax * 3 */
1310     /* rbsp_slice_trailing_bits( ) 3 */
1311     proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, bit_offset>>3, -1);
1312
1313 }
1314
1315 /*
1316  * 7.3.2.9.3 Slice data partition C RBSP syntax
1317  * slice_data_partition_c_layer_rbsp( )
1318  */
1319 static void
1320 dissect_h264_slice_data_partition_c_layer_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1321 {
1322     gint bit_offset;
1323
1324     bit_offset = offset <<3;
1325
1326     /* slice_id All ue(v) */
1327     dissect_h264_exp_golomb_code(tree, hf_h264_slice_id, tvb, &bit_offset, H264_UE_V);
1328     /* if (redundant_pic_cnt_present_flag) */
1329     /* redundant_pic_cnt All ue(v) */
1330     /* slice_data( ) * only category 4 parts of slice_data( ) syntax * 4 */
1331     /* rbsp_slice_trailing_bits( ) 4 */
1332     proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, bit_offset>>3, -1);
1333 }
1334
1335 /* D.1.6 User data unregistered SEI message syntax */
1336
1337 static int
1338 h264_user_data_unregistered(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint bit_offset, guint32 payloadSize)
1339 {
1340     guint8  i;
1341     guint8  ld_size;
1342     guint8  p_flag;
1343     guint8  desc =0;
1344     guint8  num_crops;
1345     gint offset = bit_offset >> 3;
1346     proto_item *item;
1347     proto_item *uuid_item;
1348     proto_tree *h264_ms_layer_desc_tree;
1349     proto_tree *h264_ms_crop_data_tree;
1350     e_guid_t   guid;
1351
1352
1353     /* user_data_unregistered( payloadSize ) { C Descriptor */
1354     /* uuid_iso_iec_11578 5 u(128)
1355      * uuid_iso_iec_11578 shall have a value specified as a UUID
1356      * according to the procedures of ISO/IEC 11578:1996 Annex A.
1357      */
1358
1359     uuid_item = proto_tree_add_item (tree, hf_h264_sei_uuid, tvb, offset, 16, ENC_BIG_ENDIAN);
1360     /* Extract the ISO/IEC value for comparison */
1361     tvb_get_ntohguid(tvb, offset, &guid);
1362     offset+=16;
1363
1364     /* Microsoft MS-H264PF Specification */
1365     if ( memcmp(&guid, &(ms_guids[MS_LAYOUT]), sizeof(e_guid_t)) == 0)
1366     {
1367         col_append_fstr(pinfo->cinfo, COL_INFO, ":MS_Layout");
1368         proto_item_append_text(uuid_item,"  - Microsoft Stream Layout SEI Message");
1369         /* Loop through the layer presence bytes 0-7 */
1370         for (i = 0; i < 8 ; i++)
1371         {
1372             item = proto_tree_add_item (tree, hf_h264_sei_ms_lpb, tvb, offset, 1, ENC_BIG_ENDIAN);
1373             proto_item_append_text (item, "  PRID %2d - %2d", (i+1)*8-1, i*8);
1374             offset++;
1375         }
1376         p_flag = tvb_get_guint8 (tvb, offset);
1377         proto_tree_add_item (tree, hf_h264_sei_ms_layout_p, tvb, offset, 1, ENC_BIG_ENDIAN);
1378         offset++;
1379         if (p_flag == 1)
1380         {
1381             ld_size = tvb_get_guint8 (tvb, offset);
1382             proto_tree_add_item (tree, hf_h264_sei_ms_layout_ldsize, tvb, offset, 1, ENC_BIG_ENDIAN);
1383             offset++;
1384             /* MS Errata - Microsoft seems to be setting the LD size to 16 but then including 2 layer descriptions which should be 32
1385              * To compensate for that, keep decoding layers as long as there are 16 or more bytes left in the SEI message.
1386              */
1387             if (tvb_reported_length_remaining (tvb, offset) != ld_size)
1388             {
1389                 item = proto_tree_add_expert(tree, pinfo, &ei_h264_ms_layout_wrong_length, tvb, offset-1, 1);
1390                 proto_item_append_text(item," Size of %d, remaining size %d",
1391                         ld_size,
1392                         tvb_reported_length_remaining (tvb, offset));
1393             }
1394             while (tvb_reported_length_remaining (tvb, offset) >= 16)
1395             {
1396                 h264_ms_layer_desc_tree = proto_tree_add_subtree_format(tree, tvb, offset, 16, ett_h264_ms_layer_description, NULL, "MS Layer Description  #%d", ++desc);
1397
1398                 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_coded_width,    tvb, offset, 2, ENC_BIG_ENDIAN);
1399                 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_coded_height,   tvb, offset + 2, 2, ENC_BIG_ENDIAN);
1400                 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_display_width,  tvb, offset + 4, 2, ENC_BIG_ENDIAN);
1401                 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_display_height, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
1402                 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_bitrate,        tvb, offset + 8, 4, ENC_BIG_ENDIAN);
1403                 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_frame_rate,     tvb, offset + 12, 1, ENC_BIG_ENDIAN);
1404                 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_layer_type,     tvb, offset + 12, 1, ENC_BIG_ENDIAN);
1405                 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_prid,           tvb, offset + 13, 1, ENC_BIG_ENDIAN);
1406                 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_cb,             tvb, offset + 13, 1, ENC_BIG_ENDIAN);
1407                 offset += 16;
1408             }
1409         }
1410     }
1411     else if ( memcmp(&guid, &(ms_guids[MS_CROPPING]), sizeof(e_guid_t)) == 0)
1412     {
1413         col_append_fstr(pinfo->cinfo, COL_INFO, ":MS_Cropping");
1414         proto_item_append_text(uuid_item,"  - Microsoft Cropping Info SEI Message");
1415         num_crops = tvb_get_guint8 (tvb, offset);
1416         proto_tree_add_item (tree, hf_h264_sei_ms_crop_num_data, tvb, offset, 1, ENC_BIG_ENDIAN);
1417         offset++;
1418         proto_tree_add_item (tree, hf_h264_sei_ms_crop_info_type, tvb, offset, 1, ENC_BIG_ENDIAN);
1419         offset++;
1420         while (num_crops != 0)
1421         {
1422             h264_ms_crop_data_tree = proto_tree_add_subtree_format(tree, tvb, offset, 9, ett_h264_ms_crop_data, NULL, "Crop Data #%d", ++desc);
1423             proto_tree_add_item (h264_ms_crop_data_tree, hf_h264_sei_ms_crop_confidence_level,    tvb, offset,   1, ENC_BIG_ENDIAN);
1424             proto_tree_add_item (h264_ms_crop_data_tree, hf_h264_sei_ms_crop_frame_left_offset,   tvb, offset+1, 2, ENC_BIG_ENDIAN);
1425             proto_tree_add_item (h264_ms_crop_data_tree, hf_h264_sei_ms_crop_frame_right_offset,  tvb, offset+3, 2, ENC_BIG_ENDIAN);
1426             proto_tree_add_item (h264_ms_crop_data_tree, hf_h264_sei_ms_crop_frame_top_offset,    tvb, offset+5, 2, ENC_BIG_ENDIAN);
1427             proto_tree_add_item (h264_ms_crop_data_tree, hf_h264_sei_ms_crop_frame_bottom_offset, tvb, offset+7, 2, ENC_BIG_ENDIAN);
1428             num_crops--;
1429             offset += 9;
1430         }
1431     }
1432     else if ( memcmp(&guid, &(ms_guids[MS_BITSTREAM]), sizeof(e_guid_t)) == 0)
1433     {
1434         col_append_fstr(pinfo->cinfo, COL_INFO, ":MS_Bitstream");
1435         proto_item_append_text(uuid_item,"  - Microsoft Bitstream Info SEI Message");
1436         proto_tree_add_item (tree, hf_h264_sei_ms_bitstream_ref_frame_cnt, tvb, offset, 1, ENC_BIG_ENDIAN);
1437         offset++;
1438         proto_tree_add_item (tree, hf_h264_sei_ms_bitstream_num_nalus, tvb, offset, 1, ENC_BIG_ENDIAN);
1439         offset++;
1440     }
1441     else
1442     {
1443         proto_tree_add_text(tree, tvb, offset, 16, "Unparsed iso_iec information");
1444     /*  for (i = 16; i < payloadSize; i++)
1445      *  user_data_payload_byte 5 b(8)
1446      */
1447         if (payloadSize > 16)
1448         {
1449             proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, offset, payloadSize-16);
1450             offset+=(payloadSize-16);
1451         }
1452     }
1453
1454     return offset << 3;
1455 }
1456
1457 /* D.1 SEI payload syntax */
1458 static const value_string h264_sei_payload_vals[] = {
1459     {  0,   "buffering_period" },
1460     {  1,   "pic_timing" },
1461     {  2,   "pan_scan_rect" },
1462     {  3,   "filler_payload" },
1463     {  4,   "user_data_registered_itu_t_t35" },
1464     {  5,   "user_data_unregistered" },
1465     {  6,   "recovery_point" },
1466     {  7,   "dec_ref_pic_marking_repetition" },
1467     {  8,   "spare_pic" },
1468     {  9,   "scene_inf)" },
1469     { 10,   "sub_seq_info)" },
1470     { 11,   "sub_seq_layer_characteristics" },
1471     { 12,   "sub_seq_characteristics" },
1472     { 13,   "full_frame_freeze_release" },
1473     { 14,   "full_frame_freeze_release" },
1474     { 15,   "full_frame_snapshot" },
1475     { 16,   "progressive_refinement_segment_start" },
1476     { 17,   "progressive_refinement_segment_end" },
1477     { 18,   "motion_constrained_slice_group_set" },
1478     { 19,   "film_grain_characteristics)" },
1479     { 20,   "deblocking_filter_display_preference)" },
1480     { 21,   "stereo_video_info)" },
1481     { 22,   "post_filter_hint" },
1482     { 23,   "tone_mapping_info" },
1483     /* Annex G Values */
1484     { 24,   "scalability_info" },
1485     { 25,   "sub_pic_scalable_layer" },
1486     { 26,   "non_required_layer_rep" },
1487     { 27,   "priority_layer_info" },
1488     { 28,   "layers_not_present" },
1489     { 29,   "layer_dependency_change" },
1490     { 30,   "scalable_nesting" },
1491     { 31,   "base_layer_temporal_hrd" },
1492     { 32,   "quality_layer_integrity_check" },
1493     { 33,   "redundant_pic_property" },
1494     { 34,   "tl0_dep_rep_index" },
1495     { 35,   "tl_switching_point" },
1496     /* Annex H  37 to 46 - Not Decoded*/
1497     /* Annex I  47 to 53 - Not Decoded*/
1498     { 0,    NULL }
1499 };
1500
1501 static int
1502 h264_sei_payload(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint bit_offset, guint32 payloadType, guint32 payloadSize)
1503 {
1504     /* sei_payload( payloadType, payloadSize ) { C Descriptor */
1505     if (payloadType == 0) {
1506         /* buffering_period( payloadSize ) 5 */
1507         bit_offset = bit_offset +(payloadSize<<3);
1508 #if 0
1509     } else if (payloadType == 1) {
1510         /* pic_timing( payloadSize ) 5 */
1511     } else if (payloadType == 2) {
1512         /* pan_scan_rect( payloadSize ) 5 */
1513     } else if (payloadType == 3) {
1514         /* filler_payload( payloadSize ) 5 */
1515     } else if (payloadType == 4) {
1516         /* user_data_registered_itu_t_t35( payloadSize ) 5 */
1517 #endif
1518     } else if (payloadType == 5) {
1519         /* user_data_unregistered( payloadSize ) 5 */
1520         bit_offset = h264_user_data_unregistered( tree, tvb, pinfo, bit_offset, payloadSize);
1521     } else if (payloadType == 6) {
1522         /* recovery_point( payloadSize ) 5 */
1523         bit_offset = bit_offset +(payloadSize<<3);
1524     } else if (payloadType == 7) {
1525         /* dec_ref_pic_marking_repetition( payloadSize ) 5 */
1526         bit_offset = bit_offset +(payloadSize<<3);
1527     }
1528 #if 0
1529 else if (payloadType == 8)
1530 spare_pic( payloadSize ) 5
1531 else if (payloadType == 9)
1532 scene_info( payloadSize ) 5
1533 else if (payloadType == 10)
1534 sub_seq_info( payloadSize ) 5
1535 else if (payloadType == 11)
1536 sub_seq_layer_characteristics( payloadSize ) 5
1537 else if (payloadType == 12)
1538 sub_seq_characteristics( payloadSize ) 5
1539 else if (payloadType == 13)
1540 full_frame_freeze( payloadSize ) 5
1541 else if (payloadType == 14)
1542 full_frame_freeze_release( payloadSize ) 5
1543 else if (payloadType == 15)
1544 full_frame_snapshot( payloadSize ) 5
1545 else if (payloadType == 16)
1546 progressive_refinement_segment_start( payloadSize ) 5
1547 else if (payloadType == 17)
1548 progressive_refinement_segment_end( payloadSize ) 5
1549 else if (payloadType == 18)
1550 motion_constrained_slice_group_set( payloadSize ) 5
1551 else if (payloadType == 19)
1552 film_grain_characteristics( payloadSize ) 5
1553 else if (payloadType == 20)
1554 deblocking_filter_display_preference( payloadSize ) 5
1555 else if (payloadType == 21)
1556 stereo_video_info( payloadSize ) 5
1557 else
1558 reserved_sei_message( payloadSize ) 5
1559     return bit_offset;
1560 #endif
1561     if (!h264_byte_aligned(bit_offset)) {
1562         /* bit_equal_to_one / * equal to 1 * / 5 f(1) */
1563         /* TODO:Display the filler and, error if not 1 ?? */
1564         bit_offset++;
1565         while (!h264_byte_aligned(bit_offset)) {
1566             /* bit_equal_to_zero / * equal to 0 * / 5 f(1) */
1567             /* TODO:Display the filler and, error if not 0 ?? */
1568             bit_offset++;
1569         }
1570     }
1571     return bit_offset;
1572 }
1573
1574 /*
1575  * 7.3.2.3.1 Supplemental enhancement information message syntax
1576  */
1577 static gint
1578 dissect_h264_sei_message(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint bit_offset)
1579 {
1580     /* sei_message( ) { C Descriptor */
1581     guint32 payloadType = 0, payloadSize;
1582     gint    start_bit_offset, length;
1583
1584     start_bit_offset = bit_offset;
1585
1586     /* while (next_bits( 8 ) == 0xFF) { */
1587     while (tvb_get_bits8(tvb, bit_offset, 8) == 0xFF) {
1588         /* ff_byte / * equal to 0xFF * / 5 f(8) */
1589         payloadType += 255;
1590         bit_offset+=8;
1591     }
1592     /* last_payload_type_byte 5 u(8) */
1593     payloadType += tvb_get_bits8(tvb, bit_offset, 8);
1594     bit_offset+=8;
1595     length = (bit_offset - start_bit_offset)>>3;
1596
1597     proto_tree_add_uint(tree, hf_h264_payloadtype, tvb, start_bit_offset>>3, length, payloadType);
1598
1599     payloadSize = 0;
1600     start_bit_offset = bit_offset;
1601     /* while (next_bits( 8 ) == 0xFF) { */
1602     while (tvb_get_bits8(tvb, bit_offset, 8) == 0xFF) {
1603         /* ff_byte / * equal to 0xFF * / 5 f(8) */
1604         payloadSize += 255;
1605         bit_offset+=8;
1606     }
1607     /* last_payload_size_byte 5 u(8) */
1608     /* payloadSize += last_payload_size_byte */
1609     payloadSize += tvb_get_bits8(tvb, bit_offset, 8);
1610     bit_offset+=8;
1611     length = (bit_offset - start_bit_offset)>>3;
1612     proto_tree_add_uint(tree, hf_h264_payloadsize, tvb, start_bit_offset>>3, length, payloadSize);
1613
1614     /*sei_payload( payloadType, payloadSize ) 5 */
1615     bit_offset = h264_sei_payload( tree, tvb, pinfo, bit_offset, payloadType, payloadSize);
1616     return bit_offset;
1617 }
1618
1619 /*
1620  * 7.3.2.3 Supplemental enhancement information RBSP syntax
1621  * sei_rbsp( )
1622  */
1623 static int
1624 dissect_h264_sei_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1625 {
1626     gint bit_offset;
1627
1628     bit_offset = offset <<3;
1629     /* do */
1630     /* sei_message( ) 5*/
1631     bit_offset = dissect_h264_sei_message( tree, tvb, pinfo, bit_offset);
1632
1633     /* while (more_rbsp_data( ))
1634      * If there is more data in an RBSP before rbsp_trailing_bits( ),
1635      * the return value of more_rbsp_data( ) is equal to TRUE.
1636      */
1637     /* rbsp_trailing_bits( ) 5 */
1638     if (tvb_reported_length_remaining (tvb, bit_offset >> 3) != 0 || (bit_offset & 0x7) != 0)
1639     {
1640     bit_offset = dissect_h264_rbsp_trailing_bits(tree, tvb, pinfo, bit_offset);
1641     }
1642
1643     return bit_offset;
1644 }
1645
1646 /* Ref 7.3.2.1 Sequence parameter set RBSP syntax */
1647 static int
1648 dissect_h264_seq_parameter_set_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint offset)
1649 {
1650     proto_item *level_item;
1651     gint        bit_offset;
1652     guint8      constraint_set3_flag;
1653     guint32     level_idc;
1654
1655     gint        i;
1656     guint8      profile_idc, chroma_format_idc, frame_mbs_only_flag, frame_cropping_flag;
1657     guint8      pic_order_cnt_type, vui_parameters_present_flag, num_ref_frames_in_pic_order_cnt_cycle;
1658     guint8      seq_scaling_matrix_present_flag; /* seq_scaling_list_present_flag */
1659
1660     /* profile_idc 0 u(8) */
1661     profile_idc = tvb_get_guint8(tvb, offset);
1662     proto_tree_add_item(tree, hf_h264_profile_idc, tvb, offset, 1, ENC_BIG_ENDIAN);
1663     offset++;
1664
1665     constraint_set3_flag = (tvb_get_guint8(tvb, offset)&0x10)>>4;
1666     /* constraint_set0_flag 0 u(1) */
1667     proto_tree_add_item(tree, hf_h264_constraint_set0_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1668
1669     /* constraint_set1_flag 0 u(1) */
1670     proto_tree_add_item(tree, hf_h264_constraint_set1_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1671
1672     /* constraint_set2_flag 0 u(1) */
1673     proto_tree_add_item(tree, hf_h264_constraint_set2_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1674
1675     /* constraint_set3_flag 0 u(1) */
1676     proto_tree_add_item(tree, hf_h264_constraint_set3_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1677
1678     /* constraint_set4_flag 0 u(1) */
1679     proto_tree_add_item(tree, hf_h264_constraint_set4_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1680
1681     /* constraint_set5_flag 0 u(1) */
1682     proto_tree_add_item(tree, hf_h264_constraint_set5_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1683
1684     /* reserved_zero_4bits  equal to 0  0 u(4)*/
1685     proto_tree_add_item(tree, hf_h264_reserved_zero_2bits, tvb, offset, 1, ENC_BIG_ENDIAN);
1686     offset++;
1687
1688     /* level_idc 0 u(8) */
1689     level_idc = tvb_get_guint8(tvb, offset);
1690     level_item = proto_tree_add_item(tree, hf_h264_level_idc, tvb, offset, 1, ENC_BIG_ENDIAN);
1691     if ((level_idc == 11) && (constraint_set3_flag == 1)) {
1692         proto_item_append_text(level_item,"[Level 1b]");
1693     } else {
1694         proto_item_append_text(level_item," [Level %.1f %s]", ((double)level_idc/10), val_to_str_const(level_idc, h264_level_bitrate_values, "Unknown "));
1695     }
1696     offset++;
1697     /* seq_parameter_set_id 0 ue(v)
1698      * ue(v): unsigned integer Exp-Golomb-coded syntax element with the left bit first.
1699      * The parsing process for this descriptor is specified in subclause 9.1.
1700      */
1701     bit_offset = offset<<3;
1702     dissect_h264_exp_golomb_code(tree, hf_h264_seq_parameter_set_id, tvb, &bit_offset, H264_UE_V);
1703
1704
1705     if ((profile_idc == 100) || (profile_idc == 110) ||
1706         (profile_idc == 122) || (profile_idc == 144) ||
1707         (profile_idc ==  44) || (profile_idc ==  83) ||
1708         (profile_idc ==  86) || (profile_idc == 118) ||
1709         (profile_idc == 128) || (profile_idc == 138))
1710     {
1711
1712         /* chroma_format_idc 0 ue(v) */
1713         chroma_format_idc = dissect_h264_exp_golomb_code(tree, hf_h264_chroma_format_idc, tvb, &bit_offset, H264_UE_V);
1714         if (chroma_format_idc == 3) {
1715             /* residual_colour_transform_flag 0 u(1) */
1716             proto_tree_add_bits_item(tree, hf_h264_residual_colour_transform_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1717             bit_offset++;
1718         }
1719
1720         /* bit_depth_luma_minus8 0 ue(v) */
1721         dissect_h264_exp_golomb_code(tree, hf_h264_bit_depth_luma_minus8, tvb, &bit_offset, H264_UE_V);
1722
1723         /* bit_depth_chroma_minus8 0 ue(v) */
1724         dissect_h264_exp_golomb_code(tree, hf_h264_bit_depth_chroma_minus8, tvb, &bit_offset, H264_UE_V);
1725
1726         /* qpprime_y_zero_transform_bypass_flag 0 u(1) */
1727         proto_tree_add_bits_item(tree, hf_h264_qpprime_y_zero_transform_bypass_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1728         bit_offset++;
1729
1730         /* seq_scaling_matrix_present_flag 0 u(1) */
1731         seq_scaling_matrix_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1732         proto_tree_add_bits_item(tree, hf_h264_seq_scaling_matrix_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1733         bit_offset++;
1734
1735         if (seq_scaling_matrix_present_flag) {
1736             /*
1737             for (i = 0; i < 8; i++) {
1738                 / seq_scaling_list_present_flag[ i ] 0 u(1) /
1739                 seq_scaling_list_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1740                 bit_offset++;
1741                 if (seq_scaling_list_present_flag) {
1742                     if (i < 6)
1743                         scaling_list( ScalingList4x4[ i ], 16, UseDefaultScalingMatrix4x4Flag[ i ])0
1744                         dissect_h264_scaling_list()
1745                     else
1746                         scaling_list( ScalingList8x8[ i - 6 ], 64, UseDefaultScalingMatrix8x8Flag[ i - 6 ] )0
1747                 }
1748             }
1749             */
1750             proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, bit_offset>>3, -1);
1751             return -1;
1752         }
1753
1754     }
1755
1756     /* log2_max_frame_num_minus4 0 ue(v) */
1757     dissect_h264_exp_golomb_code(tree, hf_h264_log2_max_frame_num_minus4, tvb, &bit_offset, H264_UE_V);
1758
1759     /* pic_order_cnt_type 0 ue(v) */
1760     pic_order_cnt_type = dissect_h264_exp_golomb_code(tree, hf_h264_pic_order_cnt_type, tvb, &bit_offset, H264_UE_V);
1761
1762     if (pic_order_cnt_type == 0) {
1763         /* log2_max_pic_order_cnt_lsb_minus4 0 ue(v) */
1764         dissect_h264_exp_golomb_code(tree, hf_h264_log2_max_pic_order_cnt_lsb_minus4, tvb, &bit_offset, H264_UE_V);
1765     } else if (pic_order_cnt_type == 1) {
1766         /* delta_pic_order_always_zero_flag 0 u(1) */
1767         proto_tree_add_bits_item(tree, hf_h264_delta_pic_order_always_zero_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1768         bit_offset++;
1769
1770         /* offset_for_non_ref_pic 0 se(v) */
1771         dissect_h264_exp_golomb_code(tree, hf_h264_offset_for_non_ref_pic, tvb, &bit_offset, H264_SE_V);
1772
1773         /* offset_for_top_to_bottom_field 0 se(v) */
1774         dissect_h264_exp_golomb_code(tree, hf_h264_offset_for_top_to_bottom_field, tvb, &bit_offset, H264_SE_V);
1775
1776         /* num_ref_frames_in_pic_order_cnt_cycle 0 ue(v) */
1777         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);
1778         for (i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) {
1779             /*offset_for_ref_frame[ i ] 0 se(v)*/
1780             dissect_h264_exp_golomb_code(tree, hf_h264_offset_for_ref_frame, tvb, &bit_offset, H264_SE_V);
1781         }
1782     }
1783     /* num_ref_frames 0 ue(v) */
1784     dissect_h264_exp_golomb_code(tree, hf_h264_num_ref_frames, tvb, &bit_offset, H264_UE_V);
1785
1786     /*  gaps_in_frame_num_value_allowed_flag 0 u(1) */
1787     proto_tree_add_bits_item(tree, hf_h264_gaps_in_frame_num_value_allowed_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1788     bit_offset++;
1789
1790     /*  pic_width_in_mbs_minus1 0 ue(v) */
1791     dissect_h264_exp_golomb_code(tree, hf_h264_pic_width_in_mbs_minus1, tvb, &bit_offset, H264_UE_V);
1792
1793     /* pic_height_in_map_units_minus1 0 ue(v) */
1794     dissect_h264_exp_golomb_code(tree, hf_h264_pic_height_in_map_units_minus1, tvb, &bit_offset, H264_UE_V);
1795
1796     /* frame_mbs_only_flag 0 u(1) */
1797     frame_mbs_only_flag = tvb_get_bits8(tvb, bit_offset, 1);
1798     proto_tree_add_bits_item(tree, hf_h264_frame_mbs_only_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1799     bit_offset++;
1800     if (!frame_mbs_only_flag) {
1801         /* mb_adaptive_frame_field_flag 0 u(1) */
1802         proto_tree_add_bits_item(tree, hf_h264_mb_adaptive_frame_field_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1803         bit_offset++;
1804     }
1805
1806     /* direct_8x8_inference_flag 0 u(1) */
1807     proto_tree_add_bits_item(tree, hf_h264_direct_8x8_inference_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1808     bit_offset++;
1809
1810     /* frame_cropping_flag 0 u(1) */
1811     frame_cropping_flag = tvb_get_bits8(tvb, bit_offset, 1);
1812     proto_tree_add_bits_item(tree, hf_h264_frame_cropping_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1813     bit_offset++;
1814
1815     if (frame_cropping_flag) {
1816         /* frame_crop_left_offset 0 ue(v) */
1817         dissect_h264_exp_golomb_code(tree, hf_h264_frame_crop_left_offset, tvb, &bit_offset, H264_UE_V);
1818         dissect_h264_exp_golomb_code(tree, hf_h264_frame_crop_right_offset, tvb, &bit_offset, H264_UE_V);
1819         dissect_h264_exp_golomb_code(tree, hf_h264_frame_crop_top_offset, tvb, &bit_offset, H264_UE_V);
1820         dissect_h264_exp_golomb_code(tree, hf_h264_frame_crop_bottom_offset, tvb, &bit_offset, H264_UE_V);
1821
1822     }
1823
1824     /*  vui_parameters_present_flag 0 u(1) */
1825     vui_parameters_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1826     proto_tree_add_bits_item(tree, hf_h264_vui_parameters_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1827     bit_offset++;
1828     if (vui_parameters_present_flag) {
1829         bit_offset = dissect_h264_vui_parameters(tree, tvb, pinfo, bit_offset);
1830     }
1831
1832     /*  rbsp_trailing_bits( ) 0 */
1833     bit_offset = dissect_h264_rbsp_trailing_bits(tree, tvb, pinfo, bit_offset);
1834
1835     offset = bit_offset>>3;
1836
1837     /* TODO - Add dissector of SPS SVC extension from Annex G*/
1838     return offset;
1839 }
1840
1841 /* 7.3.2.2 Picture parameter set RBSP syntax */
1842
1843 static void
1844 dissect_h264_pic_parameter_set_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint offset)
1845 {
1846     gint    bit_offset;
1847     guint32 num_slice_groups_minus1, pic_scaling_matrix_present_flag;
1848
1849     bit_offset = offset<<3;
1850
1851     /* pic_parameter_set_id 1 ue(v) */
1852     dissect_h264_exp_golomb_code(tree, hf_h264_pic_parameter_set_id, tvb, &bit_offset, H264_UE_V);
1853
1854     /* seq_parameter_set_id 1 ue(v) */
1855     dissect_h264_exp_golomb_code(tree, hf_h264_seq_parameter_set_id, tvb, &bit_offset, H264_UE_V);
1856
1857     /* entropy_coding_mode_flag 1 u(1) */
1858     proto_tree_add_bits_item(tree, hf_h264_entropy_coding_mode_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1859     bit_offset++;
1860
1861     /* pic_order_present_flag 1 u(1)*/
1862     proto_tree_add_bits_item(tree, hf_h264_pic_order_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1863     bit_offset++;
1864
1865     /* num_slice_groups_minus1 1 ue(v)*/
1866     num_slice_groups_minus1 = dissect_h264_exp_golomb_code(tree, hf_h264_num_slice_groups_minus1, tvb, &bit_offset, H264_UE_V);
1867     if (num_slice_groups_minus1 > 0) {
1868         /* slice_group_map_type 1 ue(v)*/
1869         dissect_h264_exp_golomb_code(tree, hf_h264_slice_group_map_type, tvb, &bit_offset, H264_UE_V);
1870     /*  slice_group_map_type = dissect_h264_exp_golomb_code(tree, hf_h264_slice_group_map_type, tvb, &bit_offset, H264_UE_V);*/
1871     /* if (slice_group_map_type == 0)*/
1872     /* for (iGroup = 0; iGroup <= num_slice_groups_minus1; iGroup++)*/
1873     /* run_length_minus1[ iGroup ] 1 ue(v)*/
1874     /* else if (slice_group_map_type == 2)*/
1875     /* for (iGroup = 0; iGroup < num_slice_groups_minus1; iGroup++) {*/
1876     /* top_left[ iGroup ] 1 ue(v)*/
1877     /* bottom_right[ iGroup ] 1 ue(v)*/
1878     /* }*/
1879     /* else if (slice_group_map_type == 3 ||*/
1880     /* slice_group_map_type == 4 ||*/
1881     /* slice_group_map_type == 5 ) {*/
1882     /* slice_group_change_direction_flag 1 u(1)*/
1883     /* slice_group_change_rate_minus1 1 ue(v)*/
1884     /* } else if (slice_group_map_type == 6) {*/
1885     /* pic_size_in_map_units_minus1 1 ue(v)*/
1886     /* for (i = 0; i <= pic_size_in_map_units_minus1; i++)*/
1887     /* slice_group_id[ i ] 1 u(v)*/
1888     /* }*/
1889     /* }*/
1890         proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, bit_offset>>3, -1);
1891         return;
1892     }
1893     /* num_ref_idx_l0_active_minus1 1 ue(v)*/
1894     dissect_h264_exp_golomb_code(tree, hf_h264_num_ref_idx_l0_active_minus1, tvb, &bit_offset, H264_UE_V);
1895
1896     /* num_ref_idx_l1_active_minus1 1 ue(v)*/
1897     dissect_h264_exp_golomb_code(tree, hf_h264_num_ref_idx_l1_active_minus1, tvb, &bit_offset, H264_UE_V);
1898
1899     /* weighted_pred_flag 1 u(1)*/
1900     proto_tree_add_bits_item(tree, hf_h264_weighted_pred_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1901     bit_offset++;
1902
1903     /* weighted_bipred_idc 1 u(2)*/
1904     proto_tree_add_bits_item(tree, hf_h264_weighted_bipred_idc, tvb, bit_offset, 2, ENC_BIG_ENDIAN);
1905     bit_offset= bit_offset+2;
1906
1907     /* pic_init_qp_minus26  * relative to 26 * 1 se(v)*/
1908     dissect_h264_exp_golomb_code(tree, hf_h264_pic_init_qp_minus26, tvb, &bit_offset, H264_SE_V);
1909
1910     /* pic_init_qs_minus26  * relative to 26 *  1 se(v)*/
1911     dissect_h264_exp_golomb_code(tree, hf_h264_pic_init_qs_minus26, tvb, &bit_offset, H264_SE_V);
1912
1913     /* chroma_qp_index_offset 1 se(v)*/
1914     dissect_h264_exp_golomb_code(tree, hf_h264_chroma_qp_index_offset, tvb, &bit_offset, H264_SE_V);
1915
1916     /* deblocking_filter_control_present_flag 1 u(1)*/
1917     proto_tree_add_bits_item(tree, hf_h264_deblocking_filter_control_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1918     bit_offset++;
1919
1920     /* constrained_intra_pred_flag 1 u(1)*/
1921     proto_tree_add_bits_item(tree, hf_h264_constrained_intra_pred_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1922     bit_offset++;
1923
1924     /* redundant_pic_cnt_present_flag 1 u(1)*/
1925     proto_tree_add_bits_item(tree, hf_h264_redundant_pic_cnt_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1926     bit_offset++;
1927
1928     if (more_rbsp_data(tree, tvb, pinfo, bit_offset)) {
1929         /* transform_8x8_mode_flag 1 u(1)*/
1930         proto_tree_add_bits_item(tree, hf_h264_transform_8x8_mode_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1931         bit_offset++;
1932
1933         /* pic_scaling_matrix_present_flag 1 u(1)*/
1934         pic_scaling_matrix_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1935         proto_tree_add_bits_item(tree, hf_h264_pic_scaling_matrix_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1936         bit_offset++;
1937
1938         if (pic_scaling_matrix_present_flag) {
1939             proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, bit_offset>>3, -1);
1940             return;
1941             /* for (i = 0; i < 6 + 2* transform_8x8_mode_flag; i++) {*/
1942                 /* pic_scaling_list_present_flag[ i ] 1 u(1)*/
1943                 /* if (pic_scaling_list_present_flag[ i ])*/
1944                 /* if (i < 6)*/
1945                     /* scaling_list( ScalingList4x4[ i ], 16, UseDefaultScalingMatrix4x4Flag[ i ] )*/
1946                 /* else*/
1947                     /* scaling_list( ScalingList8x8[ i - 6 ], 64, UseDefaultScalingMatrix8x8Flag[ i - 6 ] )*/
1948             /* }*/
1949             }
1950
1951         /* second_chroma_qp_index_offset 1 se(v)*/
1952         dissect_h264_exp_golomb_code(tree, hf_h264_second_chroma_qp_index_offset, tvb, &bit_offset, H264_SE_V);
1953     }
1954     bit_offset = dissect_h264_rbsp_trailing_bits(tree, tvb, pinfo, bit_offset);
1955 }
1956
1957 /*
1958  * 7.3.2.4 Access unit delimiter RBSP syntax
1959  * access_unit_delimiter_rbsp( )
1960  */
1961 static void
1962 dissect_h264_access_unit_delimiter_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1963 {
1964     /* primary_pic_type 6 u(3) */
1965     /* rbsp_trailing_bits( ) 6 */
1966     proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, offset, -1);
1967 }
1968
1969 /*
1970  * 7.3.2.5 End of sequence RBSP syntax
1971  * end_of_seq_rbsp( ) {}
1972  */
1973 static void
1974 dissect_h264_end_of_seq_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1975 {
1976     proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, offset, -1);
1977 }
1978
1979 /*
1980  * 7.3.2.6 End of stream RBSP syntax
1981  * end_of_stream_rbsp( ) {}
1982  */
1983 static void
1984 dissect_h264_end_of_stream_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1985 {
1986     proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, offset, -1);
1987 }
1988
1989 /*
1990  * 7.3.2.7 Filler data RBSP syntax
1991  * filler_data_rbsp( )
1992  */
1993 static void
1994 dissect_h264_filler_data_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
1995 {
1996     /* while (next_bits( 8 ) == 0xFF) */
1997     /* ff_byte * equal to 0xFF * 9 f(8) */
1998     /* rbsp_trailing_bits( ) 9 */
1999     proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, offset, -1);
2000 }
2001
2002 /*
2003  * 7.3.2.1.2 Sequence parameter set extension RBSP syntax
2004  * seq_parameter_set_extension_rbsp( )
2005  */
2006 static void
2007 dissect_h264_seq_parameter_set_extension_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
2008 {
2009     /* seq_parameter_set_id 10 ue(v) */
2010     /* aux_format_idc 10 ue(v) */
2011     /* if (aux_format_idc != 0 ) { */
2012     /* bit_depth_aux_minus8 10 ue(v) */
2013     /* alpha_incr_flag 10 u(1) */
2014     /* alpha_opaque_value 10 u(v) */
2015     /* alpha_transparent_value 10 u(v) */
2016     /* } */
2017     /* additional_extension_flag 10 u(1) */
2018     /* rbsp_trailing_bits() 10 */
2019     proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, offset, -1);
2020 }
2021
2022 /* RFC 6190 Section: 1.1.3 - NAL Unit Header Extension - H.264 Annex G*/
2023 static gint
2024 dissect_h264_svc_nal_header_extension(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
2025 {
2026     proto_tree_add_item(tree, hf_h264_nal_hdr_ext_svc,  tvb, offset,     1, ENC_BIG_ENDIAN);
2027     proto_tree_add_item(tree, hf_h264_nal_hdr_ext_i,    tvb, offset,     1, ENC_BIG_ENDIAN);
2028     proto_tree_add_item(tree, hf_h264_nal_hdr_ext_prid, tvb, offset,     1, ENC_BIG_ENDIAN);
2029
2030     proto_tree_add_item(tree, hf_h264_nal_hdr_ext_n,    tvb, offset + 1, 1, ENC_BIG_ENDIAN);
2031     proto_tree_add_item(tree, hf_h264_nal_hdr_ext_did,  tvb, offset + 1, 1, ENC_BIG_ENDIAN);
2032     proto_tree_add_item(tree, hf_h264_nal_hdr_ext_qid,  tvb, offset + 1, 1, ENC_BIG_ENDIAN);
2033
2034     proto_tree_add_item(tree, hf_h264_nal_hdr_ext_tid,  tvb, offset + 2, 1, ENC_BIG_ENDIAN);
2035     proto_tree_add_item(tree, hf_h264_nal_hdr_ext_u,    tvb, offset + 2, 1, ENC_BIG_ENDIAN);
2036     proto_tree_add_item(tree, hf_h264_nal_hdr_ext_d,    tvb, offset + 2, 1, ENC_BIG_ENDIAN);
2037     proto_tree_add_item(tree, hf_h264_nal_hdr_ext_o,    tvb, offset + 2, 1, ENC_BIG_ENDIAN);
2038     proto_tree_add_item(tree, hf_h264_nal_hdr_ext_rr,   tvb, offset + 2, 1, ENC_BIG_ENDIAN);
2039
2040     return offset + 3;
2041 }
2042 /* H.264 Annex G Prefix NAL Unit */
2043
2044 static int dissect_h264_prefix(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint offset)
2045 {
2046     guint8  svc_extension_flag;
2047
2048     svc_extension_flag = tvb_get_bits8(tvb, offset << 3, 1);
2049     if (svc_extension_flag)
2050     {
2051         /* Annex G NAL Unit Header SVC Extension */
2052         dissect_h264_svc_nal_header_extension (tree, tvb, pinfo, offset);
2053     }
2054     else
2055     {
2056         /* Annex H NAL Unit Header MVC Extension */
2057         /* Not Decoded */
2058         offset +=3;
2059     }
2060     return offset;
2061 }
2062
2063 /* RFC 6190 Section: 4.9 - Payload Content Scalability Information (PACSI) */
2064 static void
2065 dissect_h264_pacsi(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint offset)
2066 {
2067     gint8       pacsi_flags;
2068     guint16     nal_unit_size;
2069     tvbuff_t    *nalu_tvb;
2070     gboolean    error = FALSE;
2071     gboolean    contains_sei = FALSE;
2072
2073     offset = dissect_h264_svc_nal_header_extension(tree, tvb, pinfo, offset);
2074
2075     pacsi_flags = tvb_get_guint8(tvb, offset);
2076     proto_tree_add_item(tree, hf_h264_pacsi_x, tvb, offset, 1, ENC_BIG_ENDIAN);
2077     proto_tree_add_item(tree, hf_h264_pacsi_y, tvb, offset, 1, ENC_BIG_ENDIAN);
2078     proto_tree_add_item(tree, hf_h264_pacsi_t, tvb, offset, 1, ENC_BIG_ENDIAN);
2079     proto_tree_add_item(tree, hf_h264_pacsi_a, tvb, offset, 1, ENC_BIG_ENDIAN);
2080     proto_tree_add_item(tree, hf_h264_pacsi_p, tvb, offset, 1, ENC_BIG_ENDIAN);
2081     proto_tree_add_item(tree, hf_h264_pacsi_c, tvb, offset, 1, ENC_BIG_ENDIAN);
2082     proto_tree_add_item(tree, hf_h264_pacsi_s, tvb, offset, 1, ENC_BIG_ENDIAN);
2083     proto_tree_add_item(tree, hf_h264_pacsi_e, tvb, offset, 1, ENC_BIG_ENDIAN);
2084     offset++;
2085
2086     if (pacsi_flags & 0x40)
2087     {
2088         proto_tree_add_item(tree, hf_h264_pacsi_tl0picidx, tvb, offset, 1, ENC_BIG_ENDIAN);
2089         offset++;
2090         proto_tree_add_item(tree, hf_h264_pacsi_idrpicid, tvb, offset, 2, ENC_BIG_ENDIAN);
2091         offset += 2;
2092     }
2093     if (pacsi_flags & 0x20)
2094     {
2095         proto_tree_add_item(tree, hf_h264_pacsi_donc, tvb, offset, 2, ENC_BIG_ENDIAN);
2096         offset += 2;
2097     }
2098     if (tvb_reported_length_remaining(tvb, offset) > 0)
2099     {
2100         contains_sei = TRUE;
2101         col_append_fstr(pinfo->cinfo, COL_INFO, "(");
2102     }
2103
2104     /* Decode the SEI units that are in the packet. */
2105     while (tvb_reported_length_remaining(tvb, offset) > 0 && !error)
2106     {
2107         nal_unit_size = tvb_get_ntohs(tvb, offset);
2108         proto_tree_add_item(tree, hf_h264_nalu_size, tvb, offset, 2, ENC_NA);
2109         offset += 2;
2110
2111         if (nal_unit_size == 0 || nal_unit_size > tvb_reported_length_remaining(tvb, offset))
2112         {
2113             proto_tree_add_expert(tree, pinfo, &ei_h264_bad_nal_length, tvb, offset-2, 2);
2114             error = TRUE;
2115         }
2116         else
2117         {
2118             /* Make a new subset of the existing buffer for the NAL unit */
2119             nalu_tvb = tvb_new_subset(tvb, offset, tvb_captured_length_remaining(tvb,offset), nal_unit_size);
2120             /* Decode the NAL unit */
2121             dissect_h264(nalu_tvb, pinfo, tree);
2122             offset += nal_unit_size;
2123         }
2124     }
2125     if (contains_sei == TRUE)
2126     {
2127         col_append_fstr(pinfo->cinfo, COL_INFO, ")");
2128     }
2129 }
2130
2131 /*
2132  * RFC 3984 Section 5.7.1 - Single-Time Aggregation Packet (STAP)
2133  */
2134 static void
2135 dissect_h264_stap(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset, gint8 nal_type)
2136 {
2137     guint16     nal_unit_size;
2138     tvbuff_t    *nalu_tvb;
2139     proto_item  *item;
2140
2141     /* If it is a STAP-B then the Decoder Order Number if present before the NAL Units */
2142     if (nal_type == H264_STAP_B)
2143     {
2144         proto_tree_add_item(tree, hf_h264_don, tvb, offset, 2, ENC_NA);
2145         offset += 2;
2146     }
2147
2148     while (tvb_reported_length_remaining(tvb, offset) > 0)
2149     {
2150         /* Get the size of the NAL unit and display */
2151         proto_tree_add_item(tree, hf_h264_nalu_size, tvb, offset, 2, ENC_NA);
2152         nal_unit_size = tvb_get_ntohs(tvb, offset);
2153         offset += 2;
2154
2155         /* Do a sanity check on the unit size versus what is left in the packet. */
2156         if (nal_unit_size == 0 || tvb_reported_length_remaining(tvb, offset) < nal_unit_size)
2157         {
2158             /* Throw an exception if the size is wrong and don't try to decode the rest of the packet. */
2159             col_append_fstr(pinfo->cinfo, COL_INFO, "  [Bad NAL Length]");
2160             item = proto_tree_add_expert (tree, pinfo, &ei_h264_bad_nal_length, tvb, offset-2, 2);
2161             proto_item_append_text(item, " Size of %d, Remaining %d",
2162                     nal_unit_size, tvb_reported_length_remaining(tvb, offset));
2163             offset += tvb_reported_length_remaining(tvb, offset);
2164         }
2165         else
2166         {
2167             /* Make a new subset of the existing buffer for the NAL unit */
2168             nalu_tvb = tvb_new_subset(tvb, offset, tvb_captured_length_remaining(tvb, offset), nal_unit_size);
2169             /* Decode the NAL unit */
2170             dissect_h264(nalu_tvb, pinfo, tree);
2171             offset += nal_unit_size;
2172         }
2173     }
2174 }
2175
2176 /*
2177  * RFC 3984 Section 5.7.2 Multi-Time Aggregation Packet (MTAP)
2178  */
2179 static void
2180 dissect_h264_mtap(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset, gint8 nal_type)
2181 {
2182     gint        size_offset;
2183     guint16     nal_unit_size;
2184     tvbuff_t    *nalu_tvb;
2185     proto_item  *item;
2186
2187     /* Get the DON base value for type MTAP16 & MTAP24 */
2188     proto_tree_add_item(tree, hf_h264_don, tvb, offset, 2, ENC_NA);
2189     offset += 2;
2190
2191     while (tvb_reported_length_remaining(tvb, offset) > 0)
2192     {
2193         proto_tree_add_item(tree, hf_h264_nalu_size, tvb, offset, 2, ENC_NA);
2194         nal_unit_size = tvb_get_ntohs(tvb, offset);
2195         size_offset = offset;
2196         offset += 2;
2197         proto_tree_add_item(tree, hf_h264_dond, tvb, offset, 1, ENC_NA);
2198         offset += 1;
2199
2200         if (nal_type == H264_MTAP16)
2201         {
2202             /* Get the 16 bit DOND value */
2203             proto_tree_add_item(tree, hf_h264_ts_offset16, tvb, offset, 2, ENC_NA);
2204             offset += 2;
2205         }
2206         else
2207         {
2208             /* Get the 24 bit DOND value */
2209             proto_tree_add_item(tree, hf_h264_ts_offset24, tvb, offset, 2, ENC_NA);
2210             offset += 3;
2211         }
2212
2213         if (nal_unit_size == 0 || tvb_reported_length_remaining(tvb, offset) < nal_unit_size)
2214         {
2215             /* Throw an exception if the size is wrong and don't try to decode the rest of the packet. */
2216             col_append_fstr(pinfo->cinfo, COL_INFO, "  [Bad NAL Length]");
2217             item = proto_tree_add_expert (tree, pinfo, &ei_h264_bad_nal_length, tvb, size_offset, 2);
2218             proto_item_append_text(item, " Size of %d, Remaining %d",
2219                     nal_unit_size, tvb_reported_length_remaining(tvb, offset));
2220             offset += tvb_reported_length_remaining(tvb, offset);
2221         }
2222         else
2223         {
2224             /* Make a new subset of the existing buffer for the NAL unit */
2225             nalu_tvb = tvb_new_subset(tvb, offset, tvb_captured_length_remaining(tvb, offset), nal_unit_size);
2226             /* Decode the NAL unit */
2227             dissect_h264(nalu_tvb, pinfo, tree);
2228             offset += nal_unit_size;
2229         }
2230     }
2231 }
2232
2233 /*
2234  * Dissect NAL Header extension and NI-MTAP Subtype defined in RFC 6190
2235  */
2236 static void
2237 dissect_h264_nalu_extension (proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint offset)
2238 {
2239     gint        size_offset;
2240     guint16     nal_unit_size;
2241     tvbuff_t    *nalu_tvb;
2242     guint8      subtype;
2243     guint8      j_flag;
2244     guint8      bit_offset = offset << 3;
2245     guint8      unit = 1;
2246     proto_item  *item;
2247
2248     subtype = tvb_get_bits8(tvb, bit_offset, 5);
2249     j_flag  = tvb_get_bits8(tvb, bit_offset+5, 1);
2250
2251     /* NAL Header Extension Decoding */
2252     proto_tree_add_item(tree, hf_h264_nal_extension_subtype, tvb, offset, 1, ENC_NA);
2253     proto_tree_add_item(tree, hf_h264_nal_extension_j, tvb, offset, 1, ENC_NA);
2254     proto_tree_add_item(tree, hf_h264_nal_extension_k, tvb, offset, 1, ENC_NA);
2255     proto_tree_add_item(tree, hf_h264_nal_extension_l, tvb, offset, 1, ENC_NA);
2256     col_append_fstr(pinfo->cinfo, COL_INFO, "  %s",
2257                     val_to_str(subtype, h264_subtype_summary_values, "Unknown Subtype (%u)"));
2258     offset++;
2259
2260     if (subtype == 2)
2261     {
2262         /* Multi-Time Aggregation Packet (NI-MTAP) - RFC 6190 Section 4.7.1 */
2263         while (tvb_reported_length_remaining(tvb, offset) > 0)
2264         {
2265             proto_tree_add_text(tree, tvb, offset, 1, "NI-MTAP Unit %d", unit++);
2266             proto_tree_add_item(tree, hf_h264_nalu_size, tvb, offset, 2, ENC_NA);
2267             nal_unit_size = tvb_get_ntohs(tvb, offset);
2268             size_offset = offset;
2269             offset += 2;
2270             proto_tree_add_item(tree, hf_h264_ts_offset16, tvb, offset, 2, ENC_NA);
2271             offset += 2;
2272             /* If J flag is set then DON is present in packet */
2273             if (j_flag)
2274             {
2275                 proto_tree_add_item(tree, hf_h264_don, tvb, offset, 2, ENC_NA);
2276                 offset += 2;
2277             }
2278             if (nal_unit_size == 0 || tvb_reported_length_remaining(tvb, offset) < nal_unit_size)
2279             {
2280                 /* Throw an exception if the size is wrong and don't try to decode the rest of the packet. */
2281                 col_append_fstr(pinfo->cinfo, COL_INFO, "  [Bad NAL Length]");
2282                 item = proto_tree_add_expert (tree, pinfo, &ei_h264_bad_nal_length, tvb, size_offset, 2);
2283                 proto_item_append_text(item, " Size of %d, Remaining %d",
2284                         nal_unit_size, tvb_reported_length_remaining(tvb, offset));
2285                 offset += tvb_reported_length_remaining(tvb, offset);
2286             }
2287             else
2288             {
2289                 /* Make a new subset of the existing buffer for the NAL unit */
2290                 nalu_tvb = tvb_new_subset(tvb, offset, tvb_captured_length_remaining(tvb, offset), nal_unit_size);
2291                 /* Decode the NAL unit */
2292                 dissect_h264(nalu_tvb, pinfo, tree);
2293                 offset += nal_unit_size;
2294             }
2295         }
2296     }
2297 }
2298
2299 /*
2300  * Dissect NAL unit as received in sprop-parameter-sets of SDP
2301  * or "DecoderConfiguration parameter in H.245
2302  */
2303 void
2304 dissect_h264_nal_unit(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
2305 {
2306     proto_item *item;
2307     proto_tree *h264_nal_tree;
2308     gint        offset = 0;
2309     guint8      nal_unit_type;
2310     guint32     dword;
2311
2312     item          = proto_tree_add_item(tree, hf_h264_nal_unit, tvb, offset, -1, ENC_NA);
2313     h264_nal_tree = proto_item_add_subtree(item, ett_h264_nal_unit);
2314
2315 startover:
2316     /* In decoder configuration start code may be pressent
2317      * B.1.1 Byte stream NAL unit syntax
2318      */
2319     dword = tvb_get_bits32(tvb, offset<<3, 32, ENC_BIG_ENDIAN);
2320     if (dword == 1) {
2321         /* zero_byte + start_code_prefix_one_3bytes */
2322         offset+=4;
2323     } else if ((dword >> 8) == 1) {
2324         /* start_code_prefix_one_3bytes */
2325         offset+= 3;
2326     }
2327     /* Ref: 7.3.1 NAL unit syntax */
2328     nal_unit_type = tvb_get_guint8(tvb, offset) & 0x1f;
2329
2330     /* forbidden_zero_bit All f(1) */
2331     proto_tree_add_item(h264_nal_tree, hf_h264_forbidden_zero_bit, tvb, offset, 1, ENC_BIG_ENDIAN);
2332     /* nal_ref_idc All u(2) */
2333     proto_tree_add_item(h264_nal_tree, hf_h264_nal_ref_idc, tvb, offset, 1, ENC_BIG_ENDIAN);
2334     /* nal_unit_type All u(5) */
2335     proto_tree_add_item(h264_nal_tree, hf_h264_nal_unit_type, tvb, offset, 1, ENC_BIG_ENDIAN);
2336     offset++;
2337
2338     switch (nal_unit_type) {
2339     case 1: /* Coded slice of a non-IDR picture */
2340         dissect_h264_slice_layer_without_partitioning_rbsp(h264_nal_tree, tvb, pinfo, offset);
2341         break;
2342     case 2: /* Coded slice data partition A */
2343         dissect_h264_slice_data_partition_a_layer_rbsp(h264_nal_tree, tvb, pinfo, offset);
2344         break;
2345     case 3: /* Coded slice data partition B */
2346         dissect_h264_slice_data_partition_b_layer_rbsp(h264_nal_tree, tvb, pinfo, offset);
2347         break;
2348     case 4: /* Coded slice data partition C */
2349         dissect_h264_slice_data_partition_c_layer_rbsp(h264_nal_tree, tvb, pinfo, offset);
2350         break;
2351     case 5: /* Coded slice of an IDR picture */
2352         dissect_h264_slice_layer_without_partitioning_rbsp(h264_nal_tree, tvb, pinfo, offset);
2353         break;
2354     case 6: /* Supplemental enhancement information (SEI) */
2355         dissect_h264_sei_rbsp(h264_nal_tree, tvb, pinfo, offset);
2356         break;
2357     case H264_SEQ_PAR_SET:  /* 7 Sequence parameter set*/
2358         offset = dissect_h264_seq_parameter_set_rbsp(h264_nal_tree, tvb, pinfo, offset);
2359         /* A bit ugly */
2360         if ((offset != -1) && (tvb_length_remaining(tvb, offset) > 0)) {
2361             /* In this case length = offset as we start from zero */
2362             proto_item_set_len(item, offset/*Length */);
2363             item = proto_tree_add_item(tree, hf_h264_nal_unit, tvb, offset, -1, ENC_NA);
2364             h264_nal_tree = proto_item_add_subtree(item, ett_h264_nal_unit);
2365             goto startover;
2366         }
2367         break;
2368     case H264_PIC_PAR_SET:  /* 8 Picture parameter set */
2369         dissect_h264_pic_parameter_set_rbsp(h264_nal_tree, tvb, pinfo, offset);
2370         break;
2371     case 9: /* Access unit delimiter */
2372         dissect_h264_access_unit_delimiter_rbsp(h264_nal_tree, tvb, pinfo, offset);
2373         break;
2374     case 10:    /* End of sequence */
2375         dissect_h264_end_of_seq_rbsp(h264_nal_tree, tvb, pinfo, offset);
2376         break;
2377     case 11:    /* End of stream */
2378         dissect_h264_end_of_stream_rbsp(h264_nal_tree, tvb, pinfo, offset);
2379         break;
2380     case 12:    /* Filler data */
2381         dissect_h264_filler_data_rbsp(h264_nal_tree, tvb, pinfo, offset);
2382         break;
2383     case 13:    /* Sequence parameter set extension */
2384         dissect_h264_seq_parameter_set_extension_rbsp(h264_nal_tree, tvb, pinfo, offset);
2385         break;
2386     case 14:    /* Reserved */
2387     case 15:    /* Reserved */
2388     case 16:    /* Reserved */
2389     case 17:    /* Reserved */
2390     case 18:    /* Reserved */
2391         proto_tree_add_text(h264_nal_tree, tvb, offset, -1, "Reserved NAL unit type");
2392         break;
2393     case 19:    /* Coded slice of an auxiliary coded picture without partitioning */
2394         dissect_h264_slice_layer_without_partitioning_rbsp(tree, tvb, pinfo, offset);
2395         break;
2396     case 28:
2397         dissect_h264_slice_layer_without_partitioning_rbsp(tree, tvb, pinfo, offset);
2398         break;
2399     case 0: /* Unspecified */
2400     default:
2401         /* 24..31 Unspecified */
2402         proto_tree_add_text(h264_nal_tree, tvb, offset, -1, "Unspecified NAL unit type");
2403         break;
2404     }
2405 }
2406
2407 /* Code to actually dissect the packets */
2408 static void
2409 dissect_h264(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2410 {
2411     int         offset = 0;
2412     proto_item *item;
2413     proto_tree *h264_tree, *h264_nal_tree, *stream_tree, *fua_tree;
2414     guint8      type;
2415     tvbuff_t   *rbsp_tvb;
2416
2417
2418     /* Make entries in Protocol column and Info column on summary display */
2419     col_set_str(pinfo->cinfo, COL_PROTOCOL, "H264");
2420
2421     type = tvb_get_guint8(tvb, offset)&0x1f;
2422
2423     col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
2424                     val_to_str(type, h264_type_summary_values, "Unknown Type (%u)"));
2425
2426     if (tree) {
2427         item = proto_tree_add_item(tree, proto_h264, tvb, 0, -1, ENC_NA);
2428         h264_tree = proto_item_add_subtree(item, ett_h264);
2429
2430         /* if the type is 28, it would be draw another title */
2431         if (type == 28)
2432             h264_nal_tree = proto_tree_add_subtree(h264_tree, tvb, offset, 1, ett_h264_nal, NULL, "FU identifier");
2433         else
2434             h264_nal_tree = proto_tree_add_subtree(h264_tree, tvb, offset, 1, ett_h264_nal, NULL, "NAL unit header or first byte of the payload");
2435
2436         /* +---------------+
2437          * |0|1|2|3|4|5|6|7|
2438          * +-+-+-+-+-+-+-+-+
2439          * |F|NRI|  Type   |
2440          * +---------------+
2441          */
2442
2443         /* F: 1 bit
2444          * forbidden_zero_bit.  A value of 0 indicates that the NAL unit type
2445          * octet and payload should not contain bit errors or other syntax
2446          * violations.  A value of 1 indicates that the NAL unit type octet
2447          * and payload may contain bit errors or other syntax violations.
2448          */
2449         proto_tree_add_item(h264_nal_tree, hf_h264_nal_f_bit, tvb, offset, 1, ENC_BIG_ENDIAN);
2450         proto_tree_add_item(h264_nal_tree, hf_h264_nal_nri,   tvb, offset, 1, ENC_BIG_ENDIAN);
2451
2452         proto_tree_add_item(h264_nal_tree, hf_h264_type, tvb, offset, 1, ENC_BIG_ENDIAN);
2453         offset++;
2454         if (type == 28) {
2455             fua_tree = proto_tree_add_subtree(h264_tree, tvb, offset, 1, ett_h264_fua, NULL, "FU Header");
2456             proto_tree_add_item(fua_tree, hf_h264_start_bit,     tvb, offset, 1, ENC_BIG_ENDIAN);
2457             proto_tree_add_item(fua_tree, hf_h264_end_bit,       tvb, offset, 1, ENC_BIG_ENDIAN);
2458             proto_tree_add_item(fua_tree, hf_h264_forbidden_bit, tvb, offset, 1, ENC_BIG_ENDIAN);
2459             proto_tree_add_item(fua_tree, hf_h264_nal_unit_type, tvb, offset, 1, ENC_BIG_ENDIAN);
2460             if ((tvb_get_guint8(tvb, offset)&0x80) == 0x80) {
2461                 type = tvb_get_guint8(tvb, offset)&0x1f;
2462                 col_append_fstr(pinfo->cinfo, COL_INFO, " Start:%s",
2463                                 val_to_str(type, h264_type_summary_values, "Unknown Type (%u)"));
2464                 offset++;
2465             }
2466             else
2467             {
2468                 if ((tvb_get_guint8(tvb, offset)&0x40) == 0x40) {
2469                     col_append_fstr(pinfo->cinfo, COL_INFO, " End");
2470                 }
2471                 return;
2472         }
2473         }
2474
2475         /* Unescape NAL unit */
2476         rbsp_tvb = dissect_h265_unescap_nal_unit(tvb, pinfo, offset);
2477
2478         stream_tree = proto_tree_add_subtree(h264_tree, tvb, offset, -1, ett_h264_stream, NULL, "H264 NAL Unit Payload");
2479         switch (type) {
2480         case 1:             /* 1 Coded slice of a non-IDR picture */
2481             dissect_h264_slice_layer_without_partitioning_rbsp(stream_tree, rbsp_tvb, pinfo, 0);
2482             break;
2483         case 3: /* Coded slice data partition B */
2484             dissect_h264_slice_data_partition_b_layer_rbsp(h264_nal_tree, rbsp_tvb, pinfo, 0);
2485             break;
2486         case 4: /* Coded slice data partition C */
2487             dissect_h264_slice_data_partition_c_layer_rbsp(h264_nal_tree, rbsp_tvb, pinfo, 0);
2488             break;
2489         case 5: /* Coded slice of an IDR picture */
2490             dissect_h264_slice_layer_without_partitioning_rbsp(stream_tree, rbsp_tvb, pinfo, 0);
2491             break;
2492         case 6: /* Supplemental enhancement information (SEI) */
2493             dissect_h264_sei_rbsp(stream_tree, tvb, pinfo, offset);
2494             break;
2495         case H264_SEQ_PAR_SET:  /* 7 Sequence parameter set*/
2496             dissect_h264_seq_parameter_set_rbsp(stream_tree, rbsp_tvb, pinfo, 0);
2497             break;
2498         case H264_PIC_PAR_SET:  /* 8 Picture parameter set */
2499             dissect_h264_pic_parameter_set_rbsp(stream_tree, rbsp_tvb, pinfo, 0);
2500             break;
2501         case H264_PREFIX:
2502             dissect_h264_prefix(stream_tree, rbsp_tvb, pinfo, 0);
2503             break;
2504         case 19:    /* Coded slice of an auxiliary coded picture without partitioning */
2505             dissect_h264_slice_layer_without_partitioning_rbsp(stream_tree, rbsp_tvb, pinfo, 0);
2506             break;
2507         case H264_STAP_A:       /* STAP-A */
2508         case H264_STAP_B:       /* STAP-B */
2509             dissect_h264_stap(stream_tree, tvb, pinfo, offset, type);
2510             break;
2511         case H264_MTAP16:       /* MSTAP16 */
2512         case H264_MTAP24:       /* MSTAP24 */
2513             dissect_h264_mtap(stream_tree, tvb, pinfo, offset, type);
2514             break;
2515         case H264_PACSI:        /* PACSI */
2516             dissect_h264_pacsi(stream_tree, tvb, pinfo, offset);
2517             break;
2518         case H264_EXTENSION:    /* Extension Header */
2519             dissect_h264_nalu_extension(stream_tree, rbsp_tvb, pinfo, 0);
2520             break;
2521         default:
2522             break;
2523         }
2524     } /* if (tree) */
2525 }
2526
2527
2528 /* Capability */
2529
2530 static const int *profile_fields[] = {
2531     &hf_h264_par_profile_b,
2532     &hf_h264_par_profile_m,
2533     &hf_h264_par_profile_e,
2534     &hf_h264_par_profile_h,
2535     &hf_h264_par_profile_h10,
2536     &hf_h264_par_profile_h4_2_2,
2537     &hf_h264_par_profile_h4_4_4,
2538     NULL
2539 };
2540
2541 static int
2542 dissect_h264_par_profile(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
2543 {
2544     int offset = 0;
2545
2546     proto_tree_add_bitmask(tree, tvb, offset,
2547                            hf_h264_par_profile, ett_h264_par_profile,
2548                            profile_fields, ENC_BIG_ENDIAN);
2549     offset += 1;
2550     return offset;
2551 }
2552
2553 static const int *AdditionalModesSupported_fields[] = {
2554     &hf_h264_par_add_mode_sup_rcdo,
2555     NULL
2556 };
2557
2558 static int
2559 dissect_h264_par_AdditionalModesSupported(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
2560 {
2561     int offset = 0;
2562
2563     proto_tree_add_bitmask(tree, tvb, offset,
2564                            hf_h264_par_AdditionalModesSupported, ett_h264_par_AdditionalModesSupported,
2565                            AdditionalModesSupported_fields, ENC_BIG_ENDIAN);
2566     offset += 1;
2567     return offset;
2568 }
2569
2570
2571 static const int *ProfileIOP_fields[] = {
2572     &hf_h264_par_constraint_set0_flag,
2573     &hf_h264_par_constraint_set1_flag,
2574     &hf_h264_par_constraint_set2_flag,
2575     NULL
2576 };
2577
2578
2579 static int
2580 dissect_h264_ProfileIOP(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
2581 {
2582     int offset = 0;
2583
2584     proto_tree_add_bitmask(tree, tvb, offset,
2585                            hf_h264_par_ProfileIOP, ett_h264_par_ProfileIOP,
2586                            ProfileIOP_fields, ENC_BIG_ENDIAN);
2587     offset += 1;
2588     return offset;
2589 }
2590
2591 static const value_string h264_par_level_values[] = {
2592     {  15,    "1" },
2593     {  19,    "1b" },
2594     {  22,    "1.1" },
2595     {  29,    "1.2" },
2596     {  36,    "1.3" },
2597     {  43,    "2" },
2598     {  50,    "2.1" },
2599     {  57,    "2.2" },
2600     {  64,    "3" },
2601     {  71,    "3.1" },
2602     {  78,    "3.2" },
2603     {  85,    "4" },
2604     {  92,    "4.1" },
2605     {  99,    "4.2" },
2606     { 106,    "5" },
2607     { 113 ,   "5.1" },
2608     { 0,  NULL }
2609 };
2610
2611 static int
2612 dissect_h264_par_level(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree _U_, void *data)
2613 {
2614     int          offset = 0;
2615     guint16      lvl;
2616     const gchar *p;
2617     asn1_ctx_t  *actx;
2618
2619     /* Reject the packet if data is NULL */
2620     if (data == NULL)
2621         return 0;
2622     actx = get_asn1_ctx(data);
2623     DISSECTOR_ASSERT(actx);
2624
2625     lvl = tvb_get_ntohs(tvb, offset);
2626     p = try_val_to_str(lvl, VALS(h264_par_level_values));
2627     if (p) {
2628         proto_item_append_text(actx->created_item, " - Level %s", p);
2629     }
2630     offset += 2;
2631     return offset;
2632 }
2633
2634 static int
2635 dissect_h264_par_DecoderConfigurationInformation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
2636 {
2637     asn1_ctx_t *actx;
2638
2639     /* Reject the packet if data is NULL */
2640     if (data == NULL)
2641         return 0;
2642     actx = get_asn1_ctx(data);
2643     DISSECTOR_ASSERT(actx);
2644
2645     dissect_h264_nal_unit(tvb, pinfo, tree);
2646
2647     return tvb_length(tvb);
2648 }
2649
2650 typedef struct _h264_capability_t {
2651     const gchar *id;
2652     const gchar *name;
2653     new_dissector_t content_pdu;
2654 } h264_capability_t;
2655
2656 static h264_capability_t h264_capability_tab[] = {
2657     /* ITU-T H.241 (05/2006), 8.3 H.264 capabilities */
2658     { "GenericCapability/0.0.8.241.0.0.1", "ITU-T Rec. H.241 H.264 Video Capabilities", NULL },
2659     { "GenericCapability/0.0.8.241.0.0.1/collapsing/41", "Profile", dissect_h264_par_profile },
2660     { "GenericCapability/0.0.8.241.0.0.1/collapsing/42", "Level", dissect_h264_par_level },
2661     { "GenericCapability/0.0.8.241.0.0.1/collapsing/3" , "CustomMaxMBPS", NULL },
2662     { "GenericCapability/0.0.8.241.0.0.1/collapsing/4" , "CustomMaxFS", NULL },
2663     { "GenericCapability/0.0.8.241.0.0.1/collapsing/5" , "CustomMaxDPB", NULL },
2664     { "GenericCapability/0.0.8.241.0.0.1/collapsing/6" , "CustomMaxBRandCPB", NULL },
2665     { "GenericCapability/0.0.8.241.0.0.1/collapsing/7" , "MaxStaticMBPS", NULL },
2666     { "GenericCapability/0.0.8.241.0.0.1/collapsing/8" , "max-rcmd-nal-unit-size", NULL },
2667     { "GenericCapability/0.0.8.241.0.0.1/collapsing/9" , "max-nal-unit-size", NULL },
2668     { "GenericCapability/0.0.8.241.0.0.1/collapsing/10", "SampleAspectRatiosSupported", NULL },
2669     { "GenericCapability/0.0.8.241.0.0.1/collapsing/11", "AdditionalModesSupported", dissect_h264_par_AdditionalModesSupported },
2670     { "GenericCapability/0.0.8.241.0.0.1/collapsing/12", "AdditionalDisplayCapabilities", NULL },
2671     /* TS 26.111  H.264 */
2672     { "GenericCapability/0.0.8.241.0.0.1/nonCollapsing/43" , "DecoderConfigurationInformation", dissect_h264_par_DecoderConfigurationInformation },
2673     { "GenericCapability/0.0.8.241.0.0.1/collapsing/44" , "AcceptRedundantSlices", NULL },
2674     { "GenericCapability/0.0.8.241.0.0.1/collapsing/45" , "NalAlignedMode", NULL },
2675     { "GenericCapability/0.0.8.241.0.0.1/collapsing/46" , "ProfileIOP", dissect_h264_ProfileIOP },
2676     { NULL, NULL, NULL },
2677 };
2678
2679 static h264_capability_t *find_cap(const gchar *id) {
2680     h264_capability_t *ftr = NULL;
2681     h264_capability_t *f;
2682
2683     for (f=h264_capability_tab; f->id; f++) {
2684         if (!strcmp(id, f->id)) { ftr = f; break; }
2685     }
2686     return ftr;
2687 }
2688
2689 static int
2690 dissect_h264_name(tvbuff_t *tvb _U_, packet_info *pinfo, proto_tree *tree, void* data)
2691 {
2692     asn1_ctx_t *actx;
2693
2694     /* Reject the packet if data is NULL */
2695     if (data == NULL)
2696         return 0;
2697     actx = get_asn1_ctx(data);
2698     DISSECTOR_ASSERT(actx);
2699
2700     if (tree) {
2701         h264_capability_t *ftr;
2702         ftr = find_cap(pinfo->match_string);
2703         if (ftr) {
2704             proto_item_append_text(actx->created_item, " - %s", ftr->name);
2705             proto_item_append_text(proto_item_get_parent(proto_tree_get_parent(tree)), ": %s", ftr->name);
2706         } else {
2707             proto_item_append_text(actx->created_item, " - unknown(%s)", pinfo->match_string);
2708         }
2709     }
2710
2711     return tvb_length(tvb);
2712 }
2713
2714
2715 static void range_delete_h264_rtp_pt_callback(guint32 rtp_pt) {
2716     if (rtp_pt >= 96 && rtp_pt <= 127)
2717         dissector_delete_uint("rtp.pt", rtp_pt, h264_handle);
2718 }
2719
2720 static void range_add_h264_rtp_pt_callback(guint32 rtp_pt) {
2721     if (rtp_pt >= 96 && rtp_pt <= 127)
2722         dissector_add_uint("rtp.pt", rtp_pt, h264_handle);
2723 }
2724
2725 void
2726 proto_register_h264(void)
2727 {
2728     module_t *h264_module;
2729     expert_module_t* expert_h264;
2730
2731 /* Setup list of header fields  See Section 1.6.1 for details*/
2732     static hf_register_info hf[] = {
2733         { &hf_h264_nal_f_bit,
2734             { "F bit",           "h264.f",
2735             FT_BOOLEAN, 8, TFS(&h264_f_bit_vals), 0x80,
2736             NULL, HFILL }
2737         },
2738         { &hf_h264_nal_nri,
2739             { "Nal_ref_idc (NRI)",           "h264.nal_nri",
2740             FT_UINT8, BASE_DEC, NULL, 0x60,
2741             NULL, HFILL }
2742         },
2743         { &hf_h264_type,
2744             { "Type",           "h264.nal_unit_hdr",
2745             FT_UINT8, BASE_DEC, VALS(h264_type_values), 0x1f,
2746             NULL, HFILL }
2747         },
2748         { &hf_h264_start_bit,
2749             { "Start bit", "h264.start.bit",
2750             FT_BOOLEAN, 8, TFS(&h264_start_bit_vals), 0x80,
2751             NULL, HFILL }
2752         },
2753         { &hf_h264_end_bit,
2754             { "End bit", "h264.end.bit",
2755             FT_BOOLEAN, 8, TFS(&h264_end_bit_vals), 0x40,
2756             NULL, HFILL }
2757         },
2758         { &hf_h264_forbidden_bit,
2759             { "Forbidden bit", "h264.forbidden.bit",
2760             FT_UINT8, BASE_DEC, NULL, 0x20,
2761             NULL, HFILL }
2762         },
2763         { &hf_h264_profile,
2764             { "Profile",           "h264.profile",
2765             FT_BYTES, BASE_NONE, NULL, 0x0,
2766             NULL, HFILL }
2767         },
2768         { &hf_h264_profile_idc,
2769             { "Profile_idc",           "h264.profile_idc",
2770             FT_UINT8, BASE_DEC, VALS(h264_profile_idc_values), 0xff,
2771             NULL, HFILL }
2772         },
2773         { &hf_h264_rbsp_stop_bit,
2774             { "rbsp_stop_bit",           "h264.rbsp_stop_bit",
2775             FT_UINT8, BASE_DEC, NULL, 0x0,
2776             NULL, HFILL }
2777         },
2778         { &hf_h264_rbsp_trailing_bits,
2779             { "rbsp_trailing_bits",           "h264.rbsp_trailing_bits",
2780             FT_UINT8, BASE_DEC, NULL, 0x0,
2781             NULL, HFILL }
2782         },
2783         { &hf_h264_constraint_set0_flag,
2784             { "Constraint_set0_flag",           "h264.constraint_set0_flag",
2785             FT_UINT8, BASE_DEC, NULL, 0x80,
2786             NULL, HFILL }
2787         },
2788         { &hf_h264_constraint_set1_flag,
2789             { "Constraint_set1_flag",           "h264.constraint_set1_flag",
2790             FT_UINT8, BASE_DEC, NULL, 0x40,
2791             NULL, HFILL }
2792         },
2793         { &hf_h264_constraint_set2_flag,
2794             { "Constraint_set2_flag",           "h264.constraint_set2_flag",
2795             FT_UINT8, BASE_DEC, NULL, 0x20,
2796             NULL, HFILL }
2797         },
2798         { &hf_h264_constraint_set3_flag,
2799             { "Constraint_set3_flag",           "h264.constraint_set3_flag",
2800             FT_UINT8, BASE_DEC, NULL, 0x10,
2801             NULL, HFILL }
2802         },
2803         { &hf_h264_constraint_set4_flag,
2804             { "Constraint_set4_flag",           "h264.constraint_set4_flag",
2805             FT_UINT8, BASE_DEC, NULL, 0x08,
2806             NULL, HFILL }
2807         },
2808         { &hf_h264_constraint_set5_flag,
2809             { "Constraint_set5_flag",           "h264.constraint_set5_flag",
2810             FT_UINT8, BASE_DEC, NULL, 0x04,
2811             NULL, HFILL }
2812         },
2813         { &hf_h264_reserved_zero_2bits,
2814             { "Reserved_zero_2bits",           "h264.reserved_zero_2bits",
2815             FT_UINT8, BASE_DEC, NULL, 0x03,
2816             NULL, HFILL }
2817         },
2818         { &hf_h264_level_idc,
2819             { "Level_id",           "h264.level_id",
2820             FT_UINT8, BASE_DEC, NULL, 0xff,
2821             NULL, HFILL }
2822         },
2823         { &hf_h264_nal_unit,
2824             { "NAL unit",           "h264.nal_unit",
2825             FT_BYTES, BASE_NONE, NULL, 0x0,
2826             NULL, HFILL }
2827         },
2828         { &hf_h264_forbidden_zero_bit,
2829             { "Forbidden_zero_bit",           "h264.forbidden_zero_bit",
2830             FT_UINT8, BASE_DEC, NULL, 0x80,
2831             NULL, HFILL }
2832         },
2833         { &hf_h264_nal_ref_idc,
2834             { "Nal_ref_idc",           "h264.nal_ref_idc",
2835             FT_UINT8, BASE_DEC, NULL, 0x60,
2836             NULL, HFILL }
2837         },
2838         {&hf_h264_nal_unit_type,
2839             { "Nal_unit_type",           "h264.nal_unit_type",
2840             FT_UINT8, BASE_DEC, VALS(h264_nal_unit_type_vals), 0x1f,
2841             NULL, HFILL }
2842         },
2843         { &hf_h264_seq_parameter_set_id,
2844             { "seq_parameter_set_id",           "h264.seq_parameter_set_id",
2845             FT_UINT32, BASE_DEC, NULL, 0x0,
2846             NULL, HFILL }
2847         },
2848         { &hf_h264_chroma_format_idc,
2849             { "chroma_format_id",           "h264.chroma_format_id",
2850             FT_UINT32, BASE_DEC, NULL, 0x0,
2851             NULL, HFILL }
2852         },
2853         { &hf_h264_residual_colour_transform_flag,
2854             { "residual_colour_transform_flag",           "h264.residual_colour_transform_flag",
2855             FT_UINT8, BASE_DEC, NULL, 0x0,
2856             NULL, HFILL }
2857         },
2858         { &hf_h264_bit_depth_luma_minus8,
2859             { "bit_depth_luma_minus8",           "h264.bit_depth_luma_minus8",
2860             FT_UINT32, BASE_DEC, NULL, 0x0,
2861             NULL, HFILL }
2862         },
2863         { &hf_h264_bit_depth_chroma_minus8,
2864             { "bit_depth_chroma_minus8",           "h264.bit_depth_chroma_minus8",
2865             FT_UINT32, BASE_DEC, NULL, 0x0,
2866             NULL, HFILL }
2867         },
2868         { &hf_h264_qpprime_y_zero_transform_bypass_flag,
2869             { "qpprime_y_zero_transform_bypass_flag",           "h264.qpprime_y_zero_transform_bypass_flag",
2870             FT_UINT32, BASE_DEC, NULL, 0x0,
2871             NULL, HFILL }
2872         },
2873         { &hf_h264_seq_scaling_matrix_present_flag,
2874             { "seq_scaling_matrix_present_flag",           "h264.seq_scaling_matrix_present_flag",
2875             FT_UINT32, BASE_DEC, NULL, 0x0,
2876             NULL, HFILL }
2877         },
2878         { &hf_h264_log2_max_frame_num_minus4,
2879             { "log2_max_frame_num_minus4",           "h264.log2_max_frame_num_minus4",
2880             FT_UINT32, BASE_DEC, NULL, 0x0,
2881             NULL, HFILL }
2882         },
2883         { &hf_h264_pic_order_cnt_type,
2884             { "pic_order_cnt_type",           "h264.pic_order_cnt_type",
2885             FT_UINT32, BASE_DEC, NULL, 0x0,
2886             NULL, HFILL }
2887         },
2888         { &hf_h264_log2_max_pic_order_cnt_lsb_minus4,
2889             { "log2_max_pic_order_cnt_lsb_minus4",           "h264.log2_max_pic_order_cnt_lsb_minus4",
2890             FT_UINT32, BASE_DEC, NULL, 0x0,
2891             NULL, HFILL }
2892         },
2893         { &hf_h264_delta_pic_order_always_zero_flag,
2894             { "delta_pic_order_always_zero_flag",           "h264.delta_pic_order_always_zero_flag",
2895             FT_UINT8, BASE_DEC, NULL, 0x0,
2896             NULL, HFILL }
2897         },
2898         { &hf_h264_offset_for_non_ref_pic,
2899             { "offset_for_non_ref_pic",           "h264.offset_for_non_ref_pic",
2900             FT_INT32, BASE_DEC, NULL, 0x0,
2901             NULL, HFILL }
2902         },
2903         { &hf_h264_offset_for_top_to_bottom_field,
2904             { "offset_for_top_to_bottom_field",           "h264.offset_for_top_to_bottom_field",
2905             FT_INT32, BASE_DEC, NULL, 0x0,
2906             NULL, HFILL }
2907         },
2908         { &hf_h264_num_ref_frames_in_pic_order_cnt_cycle,
2909             { "num_ref_frames_in_pic_order_cnt_cycle",           "h264.num_ref_frames_in_pic_order_cnt_cycle",
2910             FT_UINT32, BASE_DEC, NULL, 0x0,
2911             NULL, HFILL }
2912         },
2913         { &hf_h264_offset_for_ref_frame,
2914             { "offset_for_ref_frame",           "h264.offset_for_ref_frame",
2915             FT_INT32, BASE_DEC, NULL, 0x0,
2916             NULL, HFILL }
2917         },
2918         { &hf_h264_num_ref_frames,
2919             { "num_ref_frames",           "h264.num_ref_frames",
2920             FT_UINT32, BASE_DEC, NULL, 0x0,
2921             NULL, HFILL }
2922         },
2923         { &hf_h264_gaps_in_frame_num_value_allowed_flag,
2924             { "gaps_in_frame_num_value_allowed_flag",           "h264.gaps_in_frame_num_value_allowed_flag",
2925             FT_UINT8, BASE_DEC, NULL, 0x0,
2926             NULL, HFILL }
2927         },
2928         { &hf_h264_pic_width_in_mbs_minus1,
2929             { "pic_width_in_mbs_minus1",           "h264.pic_width_in_mbs_minus1",
2930             FT_UINT32, BASE_DEC, NULL, 0x0,
2931             NULL, HFILL }
2932         },
2933         { &hf_h264_pic_height_in_map_units_minus1,
2934             { "pic_height_in_map_units_minus1",           "h264.pic_height_in_map_units_minus1",
2935             FT_UINT32, BASE_DEC, NULL, 0x0,
2936             NULL, HFILL }
2937         },
2938         { &hf_h264_frame_mbs_only_flag,
2939             { "frame_mbs_only_flag",           "h264.frame_mbs_only_flag",
2940             FT_UINT8, BASE_DEC, NULL, 0x0,
2941             NULL, HFILL }
2942         },
2943         { &hf_h264_mb_adaptive_frame_field_flag,
2944             { "mb_adaptive_frame_field_flag",           "h264.mb_adaptive_frame_field_flag",
2945             FT_UINT8, BASE_DEC, NULL, 0x0,
2946             NULL, HFILL }
2947         },
2948         { &hf_h264_direct_8x8_inference_flag,
2949             { "direct_8x8_inference_flag",           "h264.direct_8x8_inference_flag",
2950             FT_UINT8, BASE_DEC, NULL, 0x0,
2951             NULL, HFILL }
2952         },
2953         { &hf_h264_frame_cropping_flag,
2954             { "frame_cropping_flag",           "h264.frame_cropping_flag",
2955             FT_UINT8, BASE_DEC, NULL, 0x0,
2956             NULL, HFILL }
2957         },
2958         { &hf_h264_frame_crop_left_offset,
2959             { "frame_crop_left_offset",           "h264.frame_crop_left_offset",
2960             FT_UINT32, BASE_DEC, NULL, 0x0,
2961             NULL, HFILL }
2962         },
2963         { &hf_h264_frame_crop_right_offset,
2964             { "frame_crop_left_offset",           "h264.frame_crop_right_offset",
2965             FT_UINT32, BASE_DEC, NULL, 0x0,
2966             NULL, HFILL }
2967         },
2968         { &hf_h264_frame_crop_top_offset,
2969             { "frame_crop_top_offset",           "h264.frame_crop_top_offset",
2970             FT_UINT32, BASE_DEC, NULL, 0x0,
2971             NULL, HFILL }
2972         },
2973         { &hf_h264_frame_crop_bottom_offset,
2974             { "frame_crop_bottom_offset",           "h264.frame_crop_bottom_offset",
2975             FT_UINT32, BASE_DEC, NULL, 0x0,
2976             NULL, HFILL }
2977         },
2978         { &hf_h264_vui_parameters_present_flag,
2979             { "vui_parameters_present_flag",           "h264.vui_parameters_present_flag",
2980             FT_UINT8, BASE_DEC, NULL, 0x0,
2981             NULL, HFILL }
2982         },
2983         { &hf_h264_pic_parameter_set_id,
2984             { "pic_parameter_set_id",           "h264.pic_parameter_set_id",
2985             FT_UINT32, BASE_DEC, NULL, 0x0,
2986             NULL, HFILL }
2987         },
2988         { &hf_h264_entropy_coding_mode_flag,
2989             { "entropy_coding_mode_flag",           "h264.entropy_coding_mode_flag",
2990             FT_UINT8, BASE_DEC, NULL, 0x0,
2991             NULL, HFILL }
2992         },
2993         { &hf_h264_pic_order_present_flag,
2994             { "pic_order_present_flag",           "h264.pic_order_present_flag",
2995             FT_UINT8, BASE_DEC, NULL, 0x0,
2996             NULL, HFILL }
2997         },
2998         { &hf_h264_num_slice_groups_minus1,
2999             { "num_slice_groups_minus1",           "h264.num_slice_groups_minus1",
3000             FT_UINT32, BASE_DEC, NULL, 0x0,
3001             NULL, HFILL }
3002         },
3003         { &hf_h264_slice_group_map_type,
3004             { "slice_group_map_type",           "h264.slice_group_map_type",
3005             FT_UINT32, BASE_DEC, VALS(h264_slice_group_map_type_vals), 0x0,
3006             NULL, HFILL }
3007         },
3008         { &hf_h264_num_ref_idx_l0_active_minus1,
3009             { "num_ref_idx_l0_active_minus1",           "h264.num_ref_idx_l0_active_minus1",
3010             FT_UINT32, BASE_DEC, NULL, 0x0,
3011             NULL, HFILL }
3012         },
3013         { &hf_h264_num_ref_idx_l1_active_minus1,
3014             { "num_ref_idx_l1_active_minus1",           "h264.num_ref_idx_l1_active_minus1",
3015             FT_UINT32, BASE_DEC, NULL, 0x0,
3016             NULL, HFILL }
3017         },
3018         { &hf_h264_weighted_pred_flag,
3019             { "weighted_pred_flag",           "h264.weighted_pred_flag",
3020             FT_UINT8, BASE_DEC, NULL, 0x0,
3021             NULL, HFILL }
3022         },
3023         { &hf_h264_weighted_bipred_idc,
3024             { "weighted_bipred_idc",           "h264.weighted_bipred_idc",
3025             FT_UINT8, BASE_DEC, NULL, 0x0,
3026             NULL, HFILL }
3027         },
3028         { &hf_h264_pic_init_qp_minus26,
3029             { "pic_init_qp_minus26",           "h264.pic_init_qp_minus26",
3030             FT_INT32, BASE_DEC, NULL, 0x0,
3031             NULL, HFILL }
3032         },
3033         { &hf_h264_pic_init_qs_minus26,
3034             { "pic_init_qs_minus26",           "h264.pic_init_qs_minus26",
3035             FT_INT32, BASE_DEC, NULL, 0x0,
3036             NULL, HFILL }
3037         },
3038         { &hf_h264_chroma_qp_index_offset,
3039             { "chroma_qp_index_offset",           "h264.chroma_qp_index_offset",
3040             FT_INT32, BASE_DEC, NULL, 0x0,
3041             NULL, HFILL }
3042         },
3043         { &hf_h264_deblocking_filter_control_present_flag,
3044             { "deblocking_filter_control_present_flag",           "h264.deblocking_filter_control_present_flag",
3045             FT_UINT8, BASE_DEC, NULL, 0x0,
3046             NULL, HFILL }
3047         },
3048         { &hf_h264_constrained_intra_pred_flag,
3049             { "constrained_intra_pred_flag",           "h264.constrained_intra_pred_flag",
3050             FT_UINT8, BASE_DEC, NULL, 0x0,
3051             NULL, HFILL }
3052         },
3053         { &hf_h264_redundant_pic_cnt_present_flag,
3054             { "redundant_pic_cnt_present_flag",           "h264.redundant_pic_cnt_present_flag",
3055             FT_UINT8, BASE_DEC, NULL, 0x0,
3056             NULL, HFILL }
3057         },
3058         { &hf_h264_transform_8x8_mode_flag,
3059             { "transform_8x8_mode_flag",           "h264.transform_8x8_mode_flag",
3060             FT_UINT8, BASE_DEC, NULL, 0x0,
3061             NULL, HFILL }
3062         },
3063         { &hf_h264_pic_scaling_matrix_present_flag,
3064             { "pic_scaling_matrix_present_flag",           "h264.pic_scaling_matrix_present_flag",
3065             FT_UINT8, BASE_DEC, NULL, 0x0,
3066             NULL, HFILL }
3067         },
3068         { &hf_h264_second_chroma_qp_index_offset,
3069             { "second_chroma_qp_index_offset",           "h264.second_chroma_qp_index_offset",
3070             FT_INT32, BASE_DEC, NULL, 0x0,
3071             NULL, HFILL }
3072         },
3073
3074         { &hf_h264_aspect_ratio_info_present_flag,
3075             { "aspect_ratio_info_present_flag",           "h264.aspect_ratio_info_present_flag",
3076             FT_UINT8, BASE_DEC, NULL, 0x0,
3077             NULL, HFILL }
3078         },
3079         { &hf_h264_aspect_ratio_idc,
3080             { "aspect_ratio_idc",           "h264.aspect_ratio_idc",
3081             FT_UINT8, BASE_DEC, NULL, 0x0,
3082             NULL, HFILL }
3083         },
3084         { &hf_h264_sar_width,
3085             { "sar_width",           "h264.sar_width",
3086             FT_UINT16, BASE_DEC, NULL, 0x0,
3087             NULL, HFILL }
3088         },
3089         { &hf_h264_sar_height,
3090             { "sar_height",           "h264.sar_height",
3091             FT_UINT16, BASE_DEC, NULL, 0x0,
3092             NULL, HFILL }
3093         },
3094         { &hf_h264_overscan_info_present_flag,
3095             { "overscan_info_present_flag",           "h264.overscan_info_present_flag",
3096             FT_UINT8, BASE_DEC, NULL, 0x0,
3097             NULL, HFILL }
3098         },
3099         { &hf_h264_overscan_appropriate_flag,
3100             { "overscan_appropriate_flag",           "h264.overscan_appropriate_flag",
3101             FT_UINT8, BASE_DEC, NULL, 0x0,
3102             NULL, HFILL }
3103         },
3104         { &hf_h264_video_signal_type_present_flag,
3105             { "video_signal_type_present_flag",           "h264.video_signal_type_present_flag",
3106             FT_UINT8, BASE_DEC, NULL, 0x0,
3107             NULL, HFILL }
3108         },
3109         { &hf_h264_video_format,
3110             { "video_format",           "h264.video_format",
3111             FT_UINT8, BASE_DEC, VALS(h264_video_format_vals), 0x0,
3112             NULL, HFILL }
3113         },
3114         { &hf_h264_video_full_range_flag,
3115             { "video_full_range_flag",           "h264.video_full_range_flag",
3116             FT_UINT8, BASE_DEC, NULL, 0x0,
3117             NULL, HFILL }
3118         },
3119         { &hf_h264_colour_description_present_flag,
3120             { "colour_description_present_flag",           "h264.colour_description_present_flag",
3121             FT_UINT8, BASE_DEC, NULL, 0x0,
3122             NULL, HFILL }
3123         },
3124         { &hf_h264_colour_primaries,
3125             { "colour_primaries",           "h264.colour_primaries",
3126             FT_UINT8, BASE_DEC, NULL, 0x0,
3127             NULL, HFILL }
3128         },
3129         { &hf_h264_transfer_characteristics,
3130             { "transfer_characteristics",           "h264.transfer_characteristics",
3131             FT_UINT8, BASE_DEC, NULL, 0x0,
3132             NULL, HFILL }
3133         },
3134         { &hf_h264_matrix_coefficients,
3135             { "matrix_coefficients",           "h264.matrix_coefficients",
3136             FT_UINT8, BASE_DEC, NULL, 0x0,
3137             NULL, HFILL }
3138         },
3139         { &hf_h264_chroma_loc_info_present_flag,
3140             { "chroma_loc_info_present_flag",           "h264.chroma_loc_info_present_flag",
3141             FT_UINT8, BASE_DEC, NULL, 0x0,
3142             NULL, HFILL }
3143         },
3144         { &hf_h264_chroma_sample_loc_type_top_field,
3145             { "chroma_sample_loc_type_top_field",           "h264.chroma_sample_loc_type_top_field",
3146             FT_UINT32, BASE_DEC, NULL, 0x0,
3147             NULL, HFILL }
3148         },
3149         { &hf_h264_chroma_sample_loc_type_bottom_field,
3150             { "chroma_sample_loc_type_bottom_field",           "h264.chroma_sample_loc_type_bottom_field",
3151             FT_UINT32, BASE_DEC, NULL, 0x0,
3152             NULL, HFILL }
3153         },
3154         { &hf_h264_timing_info_present_flag,
3155             { "timing_info_present_flag",           "h264.timing_info_present_flag",
3156             FT_UINT8, BASE_DEC, NULL, 0x0,
3157             NULL, HFILL }
3158         },
3159         { &hf_h264_num_units_in_tick,
3160             { "num_units_in_tick",           "h264.num_units_in_tick",
3161             FT_UINT32, BASE_DEC, NULL, 0x0,
3162             NULL, HFILL }
3163         },
3164         { &hf_h264_time_scale,
3165             { "time_scale",           "h264.time_scale",
3166             FT_UINT32, BASE_DEC, NULL, 0x0,
3167             NULL, HFILL }
3168         },
3169         { &hf_h264_fixed_frame_rate_flag,
3170             { "fixed_frame_rate_flag",           "h264.fixed_frame_rate_flag",
3171             FT_UINT8, BASE_DEC, NULL, 0x0,
3172             NULL, HFILL }
3173         },
3174         { &hf_h264_nal_hrd_parameters_present_flag,
3175             { "nal_hrd_parameters_present_flag",           "h264.nal_hrd_parameters_present_flag",
3176             FT_UINT8, BASE_DEC, NULL, 0x0,
3177             NULL, HFILL }
3178         },
3179         { &hf_h264_vcl_hrd_parameters_present_flag,
3180             { "vcl_hrd_parameters_present_flag",           "h264.vcl_hrd_parameters_present_flag",
3181             FT_UINT8, BASE_DEC, NULL, 0x0,
3182             NULL, HFILL }
3183         },
3184         { &hf_h264_low_delay_hrd_flag,
3185             { "low_delay_hrd_flag",           "h264.low_delay_hrd_flag",
3186             FT_UINT8, BASE_DEC, NULL, 0x0,
3187             NULL, HFILL }
3188         },
3189         { &hf_h264_pic_struct_present_flag,
3190             { "pic_struct_present_flag",           "h264.pic_struct_present_flag",
3191             FT_UINT8, BASE_DEC, NULL, 0x0,
3192             NULL, HFILL }
3193         },
3194         { &hf_h264_bitstream_restriction_flag,
3195             { "bitstream_restriction_flag",           "h264.bitstream_restriction_flag",
3196             FT_UINT8, BASE_DEC, NULL, 0x0,
3197             NULL, HFILL }
3198         },
3199         { &hf_h264_motion_vectors_over_pic_boundaries_flag,
3200             { "motion_vectors_over_pic_boundaries_flag",           "h264.motion_vectors_over_pic_boundaries_flag",
3201             FT_UINT32, BASE_DEC, NULL, 0x0,
3202             NULL, HFILL }
3203         },
3204         { &hf_h264_max_bytes_per_pic_denom,
3205             { "max_bytes_per_pic_denom",           "h264.max_bytes_per_pic_denom",
3206             FT_UINT32, BASE_DEC, NULL, 0x0,
3207             NULL, HFILL }
3208         },
3209         { &hf_h264_max_bits_per_mb_denom,
3210             { "max_bits_per_mb_denom",           "h264.max_bits_per_mb_denom",
3211             FT_UINT32, BASE_DEC, NULL, 0x0,
3212             NULL, HFILL }
3213         },
3214         { &hf_h264_log2_max_mv_length_horizontal,
3215             { "max_mv_length_horizontal",           "h264.max_mv_length_horizontal",
3216             FT_UINT32, BASE_DEC, NULL, 0x0,
3217             NULL, HFILL }
3218         },
3219         { &hf_h264_log2_max_mv_length_vertical,
3220             { "log2_max_mv_length_vertical",           "h264.log2_max_mv_length_vertical",
3221             FT_UINT32, BASE_DEC, NULL, 0x0,
3222             NULL, HFILL }
3223         },
3224         { &hf_h264_num_reorder_frames,
3225             { "num_reorder_frames",           "h264.num_reorder_frames",
3226             FT_UINT32, BASE_DEC, NULL, 0x0,
3227             NULL, HFILL }
3228         },
3229         { &hf_h264_max_dec_frame_buffering,
3230             { "max_dec_frame_buffering",           "h264.max_dec_frame_buffering",
3231             FT_UINT32, BASE_DEC, NULL, 0x0,
3232             NULL, HFILL }
3233         },
3234         { &hf_h264_cpb_cnt_minus1,
3235             { "cpb_cnt_minus1",           "h264.cpb_cnt_minus1",
3236             FT_UINT32, BASE_DEC, NULL, 0x0,
3237             NULL, HFILL }
3238         },
3239         { &hf_h264_bit_rate_scale,
3240             { "bit_rate_scale",           "h264.bit_rate_scale",
3241             FT_UINT8, BASE_DEC, NULL, 0x0,
3242             NULL, HFILL }
3243         },
3244         { &hf_h264_cpb_size_scale,
3245             { "cpb_size_scale",           "h264.cpb_size_scale",
3246             FT_UINT8, BASE_DEC, NULL, 0x0,
3247             NULL, HFILL }
3248         },
3249         { &hf_h264_bit_rate_value_minus1,
3250             { "bit_rate_value_minus1",           "h264.bit_rate_value_minus1",
3251             FT_UINT32, BASE_DEC, NULL, 0x0,
3252             NULL, HFILL }
3253         },
3254         { &hf_h264_cpb_size_value_minus1,
3255             { "cpb_size_value_minus1",           "h264.cpb_size_value_minus1",
3256             FT_UINT32, BASE_DEC, NULL, 0x0,
3257             NULL, HFILL }
3258         },
3259         { &hf_h264_cbr_flag,
3260             { "cbr_flag",           "h264.cbr_flag",
3261             FT_UINT8, BASE_DEC, NULL, 0x0,
3262             NULL, HFILL }
3263         },
3264         { &hf_h264_initial_cpb_removal_delay_length_minus1,
3265             { "initial_cpb_removal_delay_length_minus1",           "h264.initial_cpb_removal_delay_length_minus1",
3266             FT_UINT8, BASE_DEC, NULL, 0x0,
3267             NULL, HFILL }
3268         },
3269         { &hf_h264_cpb_removal_delay_length_minus1,
3270             { "cpb_removal_delay_length_minus1",           "h264.cpb_removal_delay_length_minus1",
3271             FT_UINT8, BASE_DEC, NULL, 0x0,
3272             NULL, HFILL }
3273         },
3274         { &hf_h264_dpb_output_delay_length_minus11,
3275             { "dpb_output_delay_length_minus11",           "h264.dpb_output_delay_length_minus11",
3276             FT_UINT8, BASE_DEC, NULL, 0x0,
3277             NULL, HFILL }
3278         },
3279         { &hf_h264_time_offset_length,
3280             { "time_offset_length",           "h264.time_offset_length",
3281             FT_UINT8, BASE_DEC, NULL, 0x0,
3282             NULL, HFILL }
3283         },
3284         { &hf_h264_first_mb_in_slice,
3285             { "first_mb_in_slice",           "h264.first_mb_in_slice",
3286             FT_UINT32, BASE_DEC, NULL, 0x0,
3287             NULL, HFILL }
3288         },
3289         { &hf_h264_slice_type,
3290             { "slice_type",           "h264.slice_type",
3291             FT_UINT32, BASE_DEC, VALS(h264_slice_type_vals), 0x0,
3292             NULL, HFILL }
3293         },
3294         { &hf_h264_slice_id,
3295             { "slice_id",           "h264.slice_id",
3296             FT_UINT32, BASE_DEC, NULL, 0x0,
3297             NULL, HFILL }
3298         },
3299         { &hf_h264_payloadsize,
3300             { "PayloadSize",           "h264.payloadsize",
3301             FT_UINT32, BASE_DEC, NULL, 0x0,
3302             NULL, HFILL }
3303         },
3304         { &hf_h264_payloadtype,
3305             { "payloadType",           "h264.payloadtype",
3306             FT_UINT32, BASE_DEC, VALS(h264_sei_payload_vals), 0x0,
3307             NULL, HFILL }
3308         },
3309 #if 0
3310         { &hf_h264_frame_num,
3311             { "frame_num",           "h264.frame_num",
3312             FT_UINT8, BASE_DEC, NULL, 0x0,
3313             NULL, HFILL }
3314         },
3315 #endif
3316         { &hf_h264_par_profile,
3317                 { "Profile", "h264.profile",
3318                 FT_UINT8, BASE_HEX, NULL, 0x00,
3319             NULL, HFILL}},
3320         { &hf_h264_par_profile_b,
3321                 { "Baseline Profile", "h264.profile.base",
3322             FT_BOOLEAN, 8, NULL, 0x40,
3323             NULL, HFILL}},
3324         { &hf_h264_par_profile_m,
3325                 { "Main Profile", "h264.profile.main",
3326             FT_BOOLEAN, 8, NULL, 0x20,
3327             NULL, HFILL}},
3328         { &hf_h264_par_profile_e,
3329                 { "Extended Profile.", "h264.profile.ext",
3330             FT_BOOLEAN, 8, NULL, 0x10,
3331             NULL, HFILL}},
3332         { &hf_h264_par_profile_h,
3333                 { "High Profile", "h264.profile.high",
3334             FT_BOOLEAN, 8, NULL, 0x08,
3335             NULL, HFILL}},
3336         { &hf_h264_par_profile_h10,
3337                 { "High 10 Profile", "h264.profile.high10",
3338             FT_BOOLEAN, 8, NULL, 0x04,
3339             NULL, HFILL}},
3340         { &hf_h264_par_profile_h4_2_2,
3341                 { "High 4:2:2 Profile", "h264.profile.high4_2_2",
3342             FT_BOOLEAN, 8, NULL, 0x02,
3343             NULL, HFILL}},
3344         { &hf_h264_par_profile_h4_4_4,
3345                 { "High 4:4:4 Profile", "h264.profile.high4_4_4",
3346             FT_BOOLEAN, 8, NULL, 0x01,
3347             NULL, HFILL}},
3348         { &hf_h264_par_AdditionalModesSupported,
3349                 { "AdditionalModesSupported", "h264.AdditionalModesSupported",
3350             FT_UINT8, BASE_HEX, NULL, 0x00,
3351             NULL, HFILL}},
3352 #if 0
3353         { &hf_h264_par_add_mode_sup,
3354                 { "Additional Modes Supported", "h264.add_mode_sup",
3355             FT_UINT8, BASE_HEX, NULL, 0x00,
3356             NULL, HFILL}},
3357 #endif
3358         { &hf_h264_par_add_mode_sup_rcdo,
3359                 { "Reduced Complexity Decoding Operation (RCDO) support", "h264.add_mode_sup.rcdo",
3360             FT_BOOLEAN, 8, NULL, 0x40,
3361             NULL, HFILL}},
3362         { &hf_h264_par_ProfileIOP,
3363                 { "ProfileIOP", "h264.ProfileIOP",
3364             FT_UINT8, BASE_HEX, NULL, 0x00,
3365             NULL, HFILL}},
3366         { &hf_h264_par_constraint_set0_flag,
3367                 { "constraint_set0_flag", "h264.par.constraint_set0_flag",
3368             FT_BOOLEAN, 8, NULL, 0x80,
3369             NULL, HFILL}},
3370         { &hf_h264_par_constraint_set1_flag,
3371                 { "constraint_set1_flag", "h264.par.constraint_set1_flag",
3372             FT_BOOLEAN, 8, NULL, 0x40,
3373             NULL, HFILL}},
3374         { &hf_h264_par_constraint_set2_flag,
3375                 { "constraint_set2_flag", "h264.par.constraint_set2_flag",
3376             FT_BOOLEAN, 8, NULL, 0x20,
3377             NULL, HFILL}},
3378         /* Packization Values */
3379         { &hf_h264_nalu_size,
3380             { "NAL Unit Size", "h264.nalu_size",
3381             FT_UINT16, BASE_DEC, NULL, 0x0,
3382             NULL, HFILL }
3383         },
3384         { &hf_h264_don,
3385             { "Decoder Order Number", "h264.don",
3386             FT_UINT16, BASE_DEC, NULL, 0x0,
3387             NULL, HFILL }
3388         },
3389         { &hf_h264_dond,
3390             { "MTAP Decoder Order Number Delta", "h264.don_delta",
3391             FT_UINT8, BASE_DEC, NULL, 0x0,
3392             NULL, HFILL }
3393         },
3394         { &hf_h264_ts_offset16,
3395             { "MTAP TS Offset", "h264.ts_offset16",
3396             FT_UINT16, BASE_DEC, NULL, 0x0,
3397             NULL, HFILL }
3398         },
3399         { &hf_h264_ts_offset24,
3400             { "MTAP TS Offset", "h264.ts_offset24",
3401             FT_UINT24, BASE_DEC, NULL, 0x0,
3402             NULL, HFILL }
3403         },
3404         { &hf_h264_nal_extension_subtype,
3405             { "Extension Header Subtype", "h264.nal_hdr_extension.subtype",
3406             FT_UINT8, BASE_DEC, VALS(h264_subtype_values), 0xF8,
3407             NULL, HFILL }
3408         },
3409         { &hf_h264_nal_extension_j,
3410             { "Extension Header J - DON Present Indicator", "h264.nal_hdr_extension.j",
3411             FT_BOOLEAN, 8, NULL, 0x4,
3412             NULL, HFILL }
3413         },
3414         { &hf_h264_nal_extension_k,
3415             { "Extension Header K", "h264.nal_hdr_extension.k",
3416             FT_BOOLEAN, 8, NULL, 0x2,
3417             NULL, HFILL }
3418         },
3419         { &hf_h264_nal_extension_l,
3420             { "Extension Header L", "h264.nal_hdr_extension.l",
3421             FT_BOOLEAN, 8, NULL, 0x1,
3422             NULL, HFILL }
3423         },
3424
3425         /* SEI Parsing values */
3426         { &hf_h264_sei_uuid,
3427             { "UUID", "h264.sei.uuid",
3428             FT_GUID, BASE_NONE, NULL, 0x0,
3429             NULL, HFILL }
3430         },
3431         { &hf_h264_sei_ms_lpb,
3432             { "Layer Presence", "h264.sei.ms.layout.lpb",
3433             FT_UINT8, BASE_HEX, NULL, 0x0,
3434             NULL, HFILL }
3435         },
3436         { &hf_h264_sei_ms_layout_p,
3437             { "Layer Description Present", "h264.sei.ms.layout.p",
3438             FT_BOOLEAN, 8, NULL, 0x01,
3439             NULL, HFILL }
3440         },
3441         { &hf_h264_sei_ms_layout_ldsize,
3442             { "Layer Description Size", "h264.sei.ms.layout.desc.ldsize",
3443             FT_UINT8, BASE_DEC, NULL, 0x0,
3444             NULL, HFILL }
3445         },
3446         { &hf_h264_sei_ms_layer_desc_coded_width,
3447             { "Coded Width", "h264.sei.ms.layout.desc.coded_width",
3448             FT_UINT8, BASE_DEC, NULL, 0x0,
3449             NULL, HFILL }
3450         },
3451         { &hf_h264_sei_ms_layer_desc_coded_height,
3452             { "Coded Height", "h264.sei.ms.layout.desc.coded_height",
3453             FT_UINT8, BASE_DEC, NULL, 0x0,
3454             NULL, HFILL }
3455         },
3456         { &hf_h264_sei_ms_layer_desc_display_width,
3457             { "Display Width", "h264.sei.ms.layout.desc.display_width",
3458             FT_UINT8, BASE_DEC, NULL, 0x0,
3459             NULL, HFILL }
3460         },
3461         { &hf_h264_sei_ms_layer_desc_display_height,
3462             { "Display Height", "h264.sei.ms.layout.desc.display_height",
3463             FT_UINT8, BASE_DEC, NULL, 0x0,
3464             NULL, HFILL }
3465         },
3466         { &hf_h264_sei_ms_layer_desc_bitrate,
3467             { "Bitrate", "h264.sei.ms.layout.desc.bitrate",
3468             FT_UINT32, BASE_DEC, NULL, 0x0,
3469             NULL, HFILL }
3470         },
3471         { &hf_h264_sei_ms_layer_desc_frame_rate,
3472             { "Frame Rate Index", "h264.sei.ms.layout.desc.frame_rate",
3473             FT_UINT8, BASE_DEC, VALS(h264_sei_ms_frame_values), 0xF8,
3474             NULL, HFILL }
3475         },
3476         { &hf_h264_sei_ms_layer_desc_layer_type,
3477             { "Layer Type", "h264.sei.ms.layout.desc.layer_type",
3478             FT_UINT8, BASE_DEC, NULL, 0x07,
3479             NULL, HFILL }
3480         },
3481         { &hf_h264_sei_ms_layer_desc_prid,
3482             { "Priority ID", "h264.sei.ms.layout.desc.prid",
3483             FT_UINT8, BASE_DEC, NULL, 0xFC,
3484             NULL, HFILL }
3485         },
3486         { &hf_h264_sei_ms_layer_desc_cb,
3487             { "Constrained Baseline", "h264.sei.ms.layout.desc.constrained_baseline",
3488             FT_BOOLEAN, 8, NULL, 0x02,
3489             NULL, HFILL }
3490         },
3491         /* MS Bitstream SEI */
3492         { &hf_h264_sei_ms_bitstream_ref_frame_cnt,
3493             { "Reference Frame Count", "h264.sei.ms.bitstream_info.ref_frm_cnt",
3494             FT_UINT8, BASE_DEC, NULL, 0x0,
3495             NULL, HFILL }
3496         },
3497         { &hf_h264_sei_ms_bitstream_num_nalus,
3498             { "Number of NAL units", "h264.sei.ms.bitstrea3416m_info.num_nalus",
3499             FT_UINT8, BASE_DEC, NULL, 0x0,
3500             NULL, HFILL }
3501         },
3502         /* MS Crop SEI */
3503         { &hf_h264_sei_ms_crop_num_data,
3504             { "Number of Data Entries", "h264.sei.ms.crop.num_data",
3505             FT_UINT8, BASE_DEC, NULL, 0x0,
3506             NULL, HFILL }
3507         },
3508         { &hf_h264_sei_ms_crop_info_type,
3509             { "Info Type", "h264.sei.ms.crop.info_type",
3510             FT_UINT8, BASE_DEC, NULL, 0x0,
3511             NULL, HFILL }
3512         },
3513         { &hf_h264_sei_ms_crop_confidence_level,
3514             { "Confidence Level", "h264.sei.ms.crop.confidence_level",
3515             FT_UINT8, BASE_DEC, NULL, 0x0,
3516             NULL, HFILL }
3517         },
3518         { &hf_h264_sei_ms_crop_frame_left_offset,
3519             { "Left Offset", "h264.sei.ms.crop.left_offset",
3520             FT_UINT16, BASE_DEC, NULL, 0x0,
3521             NULL, HFILL }
3522         },
3523         { &hf_h264_sei_ms_crop_frame_right_offset,
3524             { "Right Offset", "h264.sei.ms.crop.right_offset",
3525             FT_UINT16, BASE_DEC, NULL, 0x0,
3526             NULL, HFILL }
3527         },
3528         { &hf_h264_sei_ms_crop_frame_top_offset,
3529             { "Top Offset", "h264.sei.ms.crop.top_offset",
3530             FT_UINT16, BASE_DEC, NULL, 0x0,
3531             NULL, HFILL }
3532         },
3533         { &hf_h264_sei_ms_crop_frame_bottom_offset,
3534             { "Bottom Offset", "h264.sei.ms.crop.bottom_offset",
3535             FT_UINT16, BASE_DEC, NULL, 0x0,
3536             NULL, HFILL }
3537         },
3538         /* NALU Header Extension */
3539         /* Annex G NAL Unit Header SVC Extension */
3540         { &hf_h264_nal_hdr_ext_svc,
3541             { "SVC Extension / Reserved", "h264.nal_hdr_ext.r",
3542             FT_BOOLEAN, 8, NULL, 0x80,
3543             NULL, HFILL }
3544         },
3545         { &hf_h264_nal_hdr_ext_i,
3546             { "IDR Picture", "h264.nal_hdr_ext.i",
3547             FT_BOOLEAN, 8, NULL, 0x40,
3548             NULL, HFILL }
3549         },
3550         { &hf_h264_nal_hdr_ext_prid,
3551             { "Priority ID", "h264.nal_hdr_ext.prid",
3552             FT_UINT8, BASE_DEC, NULL, 0x3f,
3553             NULL, HFILL }
3554         },
3555         { &hf_h264_nal_hdr_ext_n,
3556             { "No Inter Layer Prediction", "h264.nal_hdr_ext.n",
3557             FT_BOOLEAN, 8, NULL, 0x80,
3558             NULL, HFILL }
3559         },
3560         { &hf_h264_nal_hdr_ext_did,
3561             { "Dependency ID", "h264.nal_hdr_ext.did",
3562             FT_UINT8, BASE_DEC, NULL, 0x70,
3563             NULL, HFILL }
3564         },
3565         { &hf_h264_nal_hdr_ext_qid,
3566             { "Quality ID", "h264.nal_hdr_ext.qid",
3567             FT_UINT8, BASE_DEC, NULL, 0x0f,
3568             NULL, HFILL }
3569         },
3570         { &hf_h264_nal_hdr_ext_tid,
3571             { "Temporal ID", "h264.nal_hdr_ext.tid",
3572             FT_UINT8, BASE_DEC, NULL, 0xe0,
3573             NULL, HFILL }
3574         },
3575         { &hf_h264_nal_hdr_ext_u,
3576             { "Use Ref Base Picture", "h264.nal_hdr_ext.u",
3577             FT_BOOLEAN, 8, NULL, 0x10,
3578             NULL, HFILL }
3579         },
3580         { &hf_h264_nal_hdr_ext_d,
3581             { "Discardable", "h264.nal_hdr_ext.d",
3582             FT_BOOLEAN, 8, NULL, 0x08,
3583             NULL, HFILL }
3584         },
3585         { &hf_h264_nal_hdr_ext_o,
3586             { "Output", "h264.nal_hdr_ext.o",
3587             FT_BOOLEAN, 8, NULL, 0x04,
3588             NULL, HFILL }
3589         },
3590         { &hf_h264_nal_hdr_ext_rr,
3591             { "Reserved", "h264.nal_hdr_ext.rr",
3592             FT_UINT8, BASE_HEX, NULL, 0x03,
3593             NULL, HFILL }
3594         },
3595         /* PACSI Values */
3596         { &hf_h264_pacsi_x,
3597             { "X - A,P,C Field Indicator", "h264.pacsi.x",
3598             FT_BOOLEAN, 8, NULL, 0x80,
3599             NULL, HFILL }
3600         },
3601         { &hf_h264_pacsi_y,
3602             { "Y - Pic Fields Indicator", "h264.pacsi.y",
3603             FT_BOOLEAN, 8, NULL, 0x40,
3604             NULL, HFILL }
3605         },
3606         { &hf_h264_pacsi_t,
3607             { "T - DONC Field Indicator", "h264.pacsi.t",
3608             FT_BOOLEAN, 8, NULL, 0x20,
3609             NULL, HFILL }
3610         },
3611         { &hf_h264_pacsi_a,
3612             { "A - Anchor Layer", "h264.pacsi.a",
3613             FT_BOOLEAN, 8, NULL, 0x10,
3614             NULL, HFILL }
3615         },
3616         { &hf_h264_pacsi_p,
3617             { "P - Redundant Slice", "h264.pacsi.p",
3618             FT_BOOLEAN, 8, NULL, 0x08,
3619             NULL, HFILL }
3620         },
3621         { &hf_h264_pacsi_c,
3622             { "C - Intra Slice", "h264.pacsi.c",
3623             FT_BOOLEAN, 8, NULL, 0x04,
3624             NULL, HFILL }
3625         },
3626         { &hf_h264_pacsi_s,
3627             { "S - First Nal Unit of Layer", "h264.pacsi.s",
3628             FT_BOOLEAN, 8, NULL, 0x02,
3629             NULL, HFILL }
3630         },
3631         { &hf_h264_pacsi_e,
3632             { "E - Last Nal Unit of Layer", "h264.pacsi.e",
3633             FT_BOOLEAN, 8, NULL, 0x01,
3634             NULL, HFILL }
3635         },
3636         { &hf_h264_pacsi_tl0picidx,
3637             { "TL0PICIDX", "h264.pacsi.tl0picidx",
3638             FT_UINT8, BASE_DEC, NULL, 0xFF,
3639             NULL, HFILL }
3640         },
3641         { &hf_h264_pacsi_idrpicid,
3642             { "IDRPICID - IDR Picture ID", "h264.pacsi.idrpicid",
3643             FT_UINT16, BASE_DEC, NULL, 0x0,
3644             NULL, HFILL }
3645         },
3646         { &hf_h264_pacsi_donc,
3647             { "DONC - Cross Session Decoder Order Number", "h264.pacsi.donc",
3648             FT_UINT16, BASE_DEC, NULL, 0x0,
3649             NULL, HFILL }
3650         },
3651
3652     };
3653
3654 /* Setup protocol subtree array */
3655     static gint *ett[] = {
3656         &ett_h264,
3657         &ett_h264_profile,
3658         &ett_h264_nal,
3659         &ett_h264_fua,
3660         &ett_h264_stream,
3661         &ett_h264_nal_unit,
3662         &ett_h264_par_profile,
3663         &ett_h264_par_AdditionalModesSupported,
3664         &ett_h264_par_ProfileIOP,
3665         &ett_h264_ms_layer_description,
3666         &ett_h264_ms_crop_data
3667     };
3668
3669     static ei_register_info ei[] = {
3670         { &ei_h264_undecoded, { "h264.undecoded", PI_UNDECODED, PI_WARN, "[Not decoded yet]", EXPFILL }},
3671         { &ei_h264_ms_layout_wrong_length, { "h264.ms_layout.wrong_length", PI_PROTOCOL, PI_WARN, "[Wrong Layer Description Table Length]", EXPFILL }},
3672         { &ei_h264_bad_nal_length, { "h264.bad_nalu_length", PI_MALFORMED, PI_ERROR, "[Bad NAL Unit Length]", EXPFILL }},
3673     };
3674
3675 /* Register the protocol name and description */
3676     proto_h264 = proto_register_protocol("H.264","H264", "h264");
3677
3678 /* Required function calls to register the header fields and subtrees used */
3679     proto_register_field_array(proto_h264, hf, array_length(hf));
3680     proto_register_subtree_array(ett, array_length(ett));
3681     expert_h264 = expert_register_protocol(proto_h264);
3682     expert_register_field_array(expert_h264, ei, array_length(ei));
3683     /* Register a configuration option for port */
3684
3685
3686     h264_module = prefs_register_protocol(proto_h264, proto_reg_handoff_h264);
3687
3688
3689     prefs_register_range_preference(h264_module, "dynamic.payload.type",
3690                             "H264 dynamic payload types",
3691                             "Dynamic payload types which will be interpreted as H264"
3692                             "; Values must be in the range 96 - 127",
3693                             &temp_dynamic_payload_type_range, 127);
3694
3695     register_dissector("h264", dissect_h264, proto_h264);
3696 }
3697
3698
3699 /* Register the protocol with Wireshark */
3700 void
3701 proto_reg_handoff_h264(void)
3702 {
3703     static range_t  *dynamic_payload_type_range = NULL;
3704     static gboolean  h264_prefs_initialized     = FALSE;
3705
3706     if (!h264_prefs_initialized) {
3707         dissector_handle_t h264_name_handle;
3708         h264_capability_t *ftr;
3709
3710         h264_handle = find_dissector("h264");
3711         dissector_add_string("rtp_dyn_payload_type","H264", h264_handle);
3712         dissector_add_string("rtp_dyn_payload_type","H264-SVC", h264_handle);
3713         dissector_add_string("rtp_dyn_payload_type","X-H264UC", h264_handle);
3714
3715         h264_name_handle = new_create_dissector_handle(dissect_h264_name, proto_h264);
3716         for (ftr=h264_capability_tab; ftr->id; ftr++) {
3717             if (ftr->name)
3718                 dissector_add_string("h245.gef.name", ftr->id, h264_name_handle);
3719             if (ftr->content_pdu)
3720                 dissector_add_string("h245.gef.content", ftr->id, new_create_dissector_handle(ftr->content_pdu, proto_h264));
3721         }
3722         h264_prefs_initialized = TRUE;
3723     } else {
3724         range_foreach(dynamic_payload_type_range, range_delete_h264_rtp_pt_callback);
3725         g_free(dynamic_payload_type_range);
3726     }
3727
3728     dynamic_payload_type_range = range_copy(temp_dynamic_payload_type_range);
3729     range_foreach(dynamic_payload_type_range, range_add_h264_rtp_pt_callback);
3730 }
3731
3732