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