Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-h264.c
blobf261626eed86c973f34c85273c8f7f958e0d2f48
1 /* packet-h264.c
2 * Routines for H.264 dissection
3 * Copyright 2007 - 2009, Anders Broman <anders.broman[at]ericsson.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
11 * References:
12 * https://tools.ietf.org/html/rfc3984 Obsolete
13 * https://tools.ietf.org/html/rfc6184
14 * https://tools.ietf.org/html/rfc6190
15 * https://www.itu.int/rec/T-REC-H.264/en
16 * MS-H264PF https://docs.microsoft.com/en-us/openspecs/office_protocols/ms-h264pf
19 #include "config.h"
22 #include <epan/packet.h>
23 #include <epan/asn1.h>
24 #include <epan/expert.h>
25 #include <epan/prefs.h>
26 #include <epan/tfs.h>
27 #include "packet-h264.h"
29 void proto_register_h264(void);
30 void proto_reg_handoff_h264(void);
32 /* Initialize the protocol and registered fields */
33 static int proto_h264;
34 static int hf_h264_type;
35 static int hf_h264_nal_f_bit;
36 static int hf_h264_nal_nri;
37 static int hf_h264_start_bit;
38 static int hf_h264_forbidden_bit;
39 static int hf_h264_end_bit;
40 static int hf_h264_profile;
41 static int hf_h264_profile_idc;
42 static int hf_h264_rbsp_stop_bit;
43 static int hf_h264_rbsp_trailing_bits;
44 static int hf_h264_constraint_set0_flag;
45 static int hf_h264_constraint_set1_flag;
46 static int hf_h264_constraint_set2_flag;
47 static int hf_h264_constraint_set3_flag;
48 static int hf_h264_constraint_set4_flag;
49 static int hf_h264_constraint_set5_flag;
50 static int hf_h264_reserved_zero_2bits;
51 static int hf_h264_level_idc;
52 static int hf_h264_nal_unit;
53 static int hf_h264_forbidden_zero_bit;
54 static int hf_h264_nal_ref_idc;
55 static int hf_h264_nal_unit_type;
56 static int hf_h264_seq_parameter_set_id;
57 static int hf_h264_chroma_format_idc;
58 static int hf_h264_residual_colour_transform_flag;
59 static int hf_h264_bit_depth_luma_minus8;
60 static int hf_h264_bit_depth_chroma_minus8;
61 static int hf_h264_qpprime_y_zero_transform_bypass_flag;
62 static int hf_h264_seq_scaling_matrix_present_flag;
63 static int hf_h264_seq_scaling_list_present_flag;
64 static int hf_h264_delta_scale;
65 static int hf_h264_log2_max_frame_num_minus4;
66 static int hf_h264_pic_order_cnt_type;
67 static int hf_h264_log2_max_pic_order_cnt_lsb_minus4;
68 static int hf_h264_delta_pic_order_always_zero_flag;
69 static int hf_h264_offset_for_non_ref_pic;
70 static int hf_h264_offset_for_top_to_bottom_field;
71 static int hf_h264_num_ref_frames_in_pic_order_cnt_cycle;
72 static int hf_h264_offset_for_ref_frame;
73 static int hf_h264_num_ref_frames;
74 static int hf_h264_gaps_in_frame_num_value_allowed_flag;
75 static int hf_h264_pic_width_in_mbs_minus1;
76 static int hf_h264_pic_height_in_map_units_minus1;
77 static int hf_h264_frame_mbs_only_flag;
78 static int hf_h264_mb_adaptive_frame_field_flag;
79 static int hf_h264_direct_8x8_inference_flag;
80 static int hf_h264_frame_cropping_flag;
81 static int hf_h264_frame_crop_left_offset;
82 static int hf_h264_frame_crop_right_offset;
83 static int hf_h264_frame_crop_top_offset;
84 static int hf_h264_frame_crop_bottom_offset;
85 static int hf_h264_vui_parameters_present_flag;
86 static int hf_h264_pic_parameter_set_id;
87 static int hf_h264_entropy_coding_mode_flag;
88 static int hf_h264_pic_order_present_flag;
89 static int hf_h264_num_slice_groups_minus1;
90 static int hf_h264_slice_group_map_type;
91 static int hf_h264_num_ref_idx_l0_active_minus1;
92 static int hf_h264_num_ref_idx_l1_active_minus1;
93 static int hf_h264_weighted_pred_flag;
94 static int hf_h264_weighted_bipred_idc;
95 static int hf_h264_pic_init_qp_minus26;
96 static int hf_h264_pic_init_qs_minus26;
97 static int hf_h264_chroma_qp_index_offset;
98 static int hf_h264_deblocking_filter_control_present_flag;
99 static int hf_h264_constrained_intra_pred_flag;
100 static int hf_h264_redundant_pic_cnt_present_flag;
101 static int hf_h264_transform_8x8_mode_flag;
102 static int hf_h264_pic_scaling_matrix_present_flag;
103 static int hf_h264_second_chroma_qp_index_offset;
104 static int hf_h264_primary_pic_type;
105 static int hf_h264_par_profile;
106 static int hf_h264_par_profile_b;
107 static int hf_h264_par_profile_m;
108 static int hf_h264_par_profile_e;
109 static int hf_h264_par_profile_h;
110 static int hf_h264_par_profile_h10;
111 static int hf_h264_par_profile_h4_2_2;
112 static int hf_h264_par_profile_h4_4_4;
113 /* static int hf_h264_par_add_mode_sup; */
114 static int hf_h264_par_AdditionalModesSupported;
115 static int hf_h264_par_add_mode_sup_rcdo;
116 static int hf_h264_par_ProfileIOP;
117 static int hf_h264_par_constraint_set0_flag;
118 static int hf_h264_par_constraint_set1_flag;
119 static int hf_h264_par_constraint_set2_flag;
120 /* Packetization Values */
121 static int hf_h264_nalu_size;
122 static int hf_h264_don;
123 static int hf_h264_dond;
124 static int hf_h264_ts_offset16;
125 static int hf_h264_ts_offset24;
126 /* Extension Header */
127 static int hf_h264_nal_extension_subtype;
128 static int hf_h264_nal_extension_j;
129 static int hf_h264_nal_extension_k;
130 static int hf_h264_nal_extension_l;
132 /* SEI Decoding Information */
133 static int hf_h264_sei_uuid;
134 /* Microsoft Layout SEI */
135 static int hf_h264_sei_ms_lpb;
136 static int hf_h264_sei_ms_layout_p;
137 static int hf_h264_sei_ms_layout_ldsize;
138 static int hf_h264_sei_ms_layer_desc_coded_width;
139 static int hf_h264_sei_ms_layer_desc_coded_height;
140 static int hf_h264_sei_ms_layer_desc_display_width;
141 static int hf_h264_sei_ms_layer_desc_display_height;
142 static int hf_h264_sei_ms_layer_desc_bitrate;
143 static int hf_h264_sei_ms_layer_desc_frame_rate;
144 static int hf_h264_sei_ms_layer_desc_layer_type;
145 static int hf_h264_sei_ms_layer_desc_prid;
146 static int hf_h264_sei_ms_layer_desc_cb;
147 /* Microsoft Bitstream SEI */
148 static int hf_h264_sei_ms_bitstream_ref_frame_cnt;
149 static int hf_h264_sei_ms_bitstream_num_nalus;
150 static int hf_h264_sei_iso_sec_info;
151 /* Microsoft Crop SEI */
152 static int hf_h264_sei_ms_crop_num_data;
153 static int hf_h264_sei_ms_crop_info_type;
154 static int hf_h264_sei_ms_crop_confidence_level;
155 static int hf_h264_sei_ms_crop_frame_left_offset;
156 static int hf_h264_sei_ms_crop_frame_right_offset;
157 static int hf_h264_sei_ms_crop_frame_top_offset;
158 static int hf_h264_sei_ms_crop_frame_bottom_offset;
159 /* SVC NAL Header Extension Values Annex G.7.3.1.1 */
160 static int hf_h264_nal_hdr_ext_svc;
161 static int hf_h264_nal_hdr_ext_i;
162 static int hf_h264_nal_hdr_ext_prid;
163 static int hf_h264_nal_hdr_ext_n;
164 static int hf_h264_nal_hdr_ext_did;
165 static int hf_h264_nal_hdr_ext_qid;
166 static int hf_h264_nal_hdr_ext_tid;
167 static int hf_h264_nal_hdr_ext_u;
168 static int hf_h264_nal_hdr_ext_d;
169 static int hf_h264_nal_hdr_ext_o;
170 static int hf_h264_nal_hdr_ext_rr;
171 /* PACSI Values */
172 static int hf_h264_pacsi_x;
173 static int hf_h264_pacsi_y;
174 static int hf_h264_pacsi_t;
175 static int hf_h264_pacsi_a;
176 static int hf_h264_pacsi_p;
177 static int hf_h264_pacsi_c;
178 static int hf_h264_pacsi_s;
179 static int hf_h264_pacsi_e;
180 static int hf_h264_pacsi_tl0picidx;
181 static int hf_h264_pacsi_idrpicid;
182 static int hf_h264_pacsi_donc;
184 /* VUI parameters */
185 static int hf_h264_aspect_ratio_info_present_flag;
186 static int hf_h264_aspect_ratio_idc;
187 static int hf_h264_sar_width;
188 static int hf_h264_sar_height;
189 static int hf_h264_overscan_info_present_flag;
190 static int hf_h264_overscan_appropriate_flag;
191 static int hf_h264_video_signal_type_present_flag;
192 static int hf_h264_video_format;
193 static int hf_h264_video_full_range_flag;
194 static int hf_h264_colour_description_present_flag;
195 static int hf_h264_colour_primaries;
196 static int hf_h264_transfer_characteristics;
197 static int hf_h264_matrix_coefficients;
198 static int hf_h264_chroma_loc_info_present_flag;
199 static int hf_h264_chroma_sample_loc_type_top_field;
200 static int hf_h264_chroma_sample_loc_type_bottom_field;
201 static int hf_h264_timing_info_present_flag;
202 static int hf_h264_num_units_in_tick;
203 static int hf_h264_time_scale;
204 static int hf_h264_fixed_frame_rate_flag;
205 static int hf_h264_nal_hrd_parameters_present_flag;
206 static int hf_h264_vcl_hrd_parameters_present_flag;
207 static int hf_h264_low_delay_hrd_flag;
208 static int hf_h264_pic_struct_present_flag;
209 static int hf_h264_bitstream_restriction_flag;
210 static int hf_h264_motion_vectors_over_pic_boundaries_flag;
211 static int hf_h264_max_bytes_per_pic_denom;
212 static int hf_h264_max_bits_per_mb_denom;
213 static int hf_h264_log2_max_mv_length_horizontal;
214 static int hf_h264_log2_max_mv_length_vertical;
215 static int hf_h264_num_reorder_frames;
216 static int hf_h264_max_dec_frame_buffering;
217 static int hf_h264_cpb_cnt_minus1;
218 static int hf_h264_bit_rate_scale;
219 static int hf_h264_cpb_size_scale;
220 static int hf_h264_bit_rate_value_minus1;
221 static int hf_h264_cpb_size_value_minus1;
222 static int hf_h264_cbr_flag;
223 static int hf_h264_initial_cpb_removal_delay_length_minus1;
224 static int hf_h264_cpb_removal_delay_length_minus1;
225 static int hf_h264_dpb_output_delay_length_minus11;
226 static int hf_h264_time_offset_length;
228 static int hf_h264_first_mb_in_slice;
229 static int hf_h264_slice_type;
230 static int hf_h264_slice_id;
231 static int hf_h264_payloadsize;
232 static int hf_h264_payloadtype;
233 /* static int hf_h264_frame_num; */
235 /* Initialize the subtree pointers */
236 static int ett_h264;
237 static int ett_h264_profile;
238 static int ett_h264_nal;
239 static int ett_h264_fua;
240 static int ett_h264_stream;
241 static int ett_h264_nal_unit;
242 static int ett_h264_par_profile;
243 static int ett_h264_par_AdditionalModesSupported;
244 static int ett_h264_par_ProfileIOP;
245 static int ett_h264_ms_layer_description;
246 static int ett_h264_ms_crop_data;
247 static int ett_h264_ni_mtap;
249 static expert_field ei_h264_undecoded;
250 static expert_field ei_h264_ms_layout_wrong_length;
251 static expert_field ei_h264_oversized_exp_golomb_code;
252 static expert_field ei_h264_bad_nal_length;
253 static expert_field ei_h264_nal_unit_type_reserved;
254 static expert_field ei_h264_nal_unit_type_unspecified;
256 static dissector_handle_t h264_name_handle;
258 static dissector_handle_t h264_handle;
260 /* syntax tables in subclause 7.3 is equal to
261 * ue(v), me(v), se(v), or te(v).
263 typedef enum {
264 H264_UE_V = 0,
265 H264_ME_V = 1,
266 H264_SE_V = 2,
267 H264_TE_V = 3
268 } h264_golomb_descriptors;
271 static const true_false_string h264_f_bit_vals = {
272 "Bit errors or other syntax violations",
273 "No bit errors or other syntax violations"
276 static const true_false_string h264_start_bit_vals = {
277 "the first packet of FU-A picture",
278 "Not the first packet of FU-A picture"
281 static const true_false_string h264_end_bit_vals = {
282 "the last packet of FU-A picture",
283 "Not the last packet of FU-A picture"
286 #if 0
287 static const true_false_string h264_forbidden_bit_vals = {
288 "Forbidden Bit of FU-A",
289 "Not Forbidden Bit of FU-A"
291 #endif
293 #define H264_SEQ_PAR_SET 7
294 #define H264_PIC_PAR_SET 8
295 #define H264_PREFIX 14
296 #define H264_STAP_A 24
297 #define H264_STAP_B 25
298 #define H264_MTAP16 26
299 #define H264_MTAP24 27
300 #define H264_PACSI 30
301 #define H264_EXTENSION 31
304 static const value_string h264_type_values[] = {
305 { 0, "Undefined" },
306 { 1, "NAL unit - Coded slice of a non-IDR picture" }, /* Single NAL unit packet per H.264 */
307 { 2, "NAL unit - Coded slice data partition A" },
308 { 3, "NAL unit - Coded slice data partition B" },
309 { 4, "NAL unit - Coded slice data partition C" },
310 { 5, "NAL unit - Coded slice of an IDR picture" },
311 { 6, "NAL unit - Supplemental enhancement information (SEI)" },
312 { H264_SEQ_PAR_SET, "NAL unit - Sequence parameter set" }, /* 7 */
313 { H264_PIC_PAR_SET, "NAL unit - Picture parameter set" }, /* 8 */
314 { 9, "NAL unit - Access unit delimiter" },
315 { 10, "NAL unit - End of sequence" },
316 { 11, "NAL unit - End of stream" },
317 { 12, "NAL unit - Filler data" },
318 { 13, "NAL unit - Sequence parameter set extension" },
319 { H264_PREFIX, "NAL unit - Prefix" },
320 { 15, "NAL unit - Subset sequence parameter set" },
321 { 16, "NAL unit - Reserved" },
322 { 17, "NAL unit - Reserved" },
323 { 18, "NAL unit - Reserved" },
324 { 19, "NAL unit - Coded slice of an auxiliary coded picture without partitioning" },
325 { 20, "NAL unit - Coded slice extension" },
326 { 21, "NAL unit - Coded slice extension for depth view components" },
327 { 22, "NAL unit - Reserved" },
328 { 23, "NAL unit - Reserved" },
329 { 24, "Single-time aggregation packet A (STAP-A)" },
330 { 25, "Single-time aggregation packet B (STAP-B)" },
331 { 26, "Multi-time aggregation packet 16 (MTAP16)" },
332 { 27, "Multi-time aggregation packet 24 (MTAP24)" },
333 { 28, "Fragmentation unit A (FU-A)" },
334 { 29, "Fragmentation unit B (FU-B)" },
335 { 30, "NAL unit - Payload Content Scalability Information (PACSI)" },
336 { 31, "NAL unit - Extended NAL Header" },
337 { 0, NULL }
340 static const value_string h264_type_summary_values[] = {
341 { 0, "Undefined" },
342 { 1, "non-IDR-Slice" }, /* Single NAL unit packet per H.264 */
343 { 2, "Slice-A" },
344 { 3, "Slice-B" },
345 { 4, "Slice-C" },
346 { 5, "IDR-Slice" },
347 { 6, "SEI" },
348 { H264_SEQ_PAR_SET, "SPS" }, /* 7 */
349 { H264_PIC_PAR_SET, "PPS" }, /* 8 */
350 { 9, "Access-Delimiter" },
351 { 10, "End-of-Seq" },
352 { 11, "End-of-Stream" },
353 { 12, "Filler" },
354 { 13, "SPS-Ext" },
355 { H264_PREFIX, "Prefix" },
356 { 15, "Reserved" },
357 { 16, "Reserved" },
358 { 17, "Reserved" },
359 { 18, "Reserved" },
360 { 19, "Slice-Aux" },
361 { 20, "Slice-Ext" },
362 { 21, "Slice-Ext-Depth" },
363 { 22, "Reserved" },
364 { 23, "Reserved" },
365 { 24, "STAP-A" },
366 { 25, "STAP-B" },
367 { 26, "MTAP16" },
368 { 27, "MTAP24" },
369 { 28, "FU-A" },
370 { 29, "FU-B" },
371 { 30, "PACSI" },
372 { 31, "EXT" },
373 { 0, NULL }
376 /* Extension Subtype Strings RFC 6190 4.3 */
377 static const value_string h264_subtype_values[] = {
378 { 0, "Reserved" },
379 { 1, "NAL Unit - Empty" },
380 { 2, "Non-interleaved Multi-Time Aggregation Packet (NI-MTAP)" },
381 { 0, NULL }
383 static const value_string h264_subtype_summary_values[] = {
384 { 0, "Reserved" },
385 { 1, "Empty" },
386 { 2, "NI-MTAP" },
387 { 0, NULL }
390 /* A.2 Profiles */
391 static const value_string h264_profile_idc_values[] = {
392 { 66, "Baseline profile" },
393 { 77, "Main profile" },
394 { 83, "Scalable Baseline" },
395 { 86, "Scalable High" },
396 { 88, "Extended profile" },
397 { 100, "High profile" },
398 { 110, "High 10 profile" },
399 { 118, "Multi-view High" },
400 { 122, "High 4:2:2 profile" },
401 { 128, "Stereo High" },
402 { 144, "High 4:4:4 profile" },
403 { 0, NULL }
406 /* Table A-1 - Level limits */
407 static const value_string h264_level_bitrate_values[] = {
408 { 10, "64 kb/s" },
409 { 11, "192 kb/s" },
410 { 12, "384 kb/s" },
411 { 13, "768 kb/s" },
412 { 20, "2 Mb/s" },
413 { 21, "4 Mb/s" },
414 { 22, "4 Mb/s" },
415 { 30, "10 Mb/s" },
416 { 31, "14 Mb/s" },
417 { 32, "20 Mb/s" },
418 { 40, "20 Mb/s" },
419 { 41, "50 Mb/s" },
420 { 42, "50 Mb/s" },
421 { 50, "135 Mb/s" },
422 { 51, "240 Mb/s" },
423 { 52, "240 Mb/s" },
424 { 0, NULL }
427 static const value_string h264_nal_unit_type_vals[] = {
428 { 0, "Unspecified" },
429 { 1, "Coded slice of a non-IDR picture" },
430 { 2, "Coded slice data partition A" },
431 { 3, "Coded slice data partition B" },
432 { 4, "Coded slice data partition C" },
433 { 5, "Coded slice of an IDR picture" },
434 { 6, "Supplemental enhancement information (SEI)" },
435 { 7, "Sequence parameter set" },
436 { 8, "Picture parameter set" },
437 { 9, "Access unit delimiter" },
438 { 10, "End of sequence" },
439 { 11, "End of stream" },
440 { 12, "Filler data" },
441 { 13, "Sequence parameter set extension" },
442 { 14, "Prefix" },
443 { 15, "Subset sequence parameter set" },
444 { 16, "Reserved" },
445 { 17, "Reserved" },
446 { 18, "Reserved" },
447 { 19, "Coded slice of an auxiliary coded picture without partitioning" },
448 { 20, "Coded slice extension" },
449 { 21, "Coded slice extension for depth view components" },
450 { 22, "Reserved" },
451 { 23, "Reserved" },
452 { 24, "Unspecified" },
453 { 25, "Unspecified" },
454 { 26, "Unspecified" },
455 { 27, "Unspecified" },
456 { 28, "FU-A" },
457 { 29, "Unspecified" },
458 { 30, "Unspecified" },
459 { 31, "Unspecified" },
460 { 0, NULL }
463 static const value_string h264_slice_group_map_type_vals[] = {
464 { 0, "Interleaved slice groups" },
465 { 1, "Dispersed slice group mapping" },
466 { 2, "One or more foreground slice groups and a leftover slice group" },
467 { 3, "Changing slice groups" },
468 { 4, "Changing slice groups" },
469 { 5, "Changing slice groups" },
470 { 6, "Explicit assignment of a slice group to each slice group map unit" },
471 { 0, NULL }
474 /* Table 7-5 Meaning of primary_pic_type */
475 static const value_string h264_primary_pic_type_vals[] = {
476 { 0, "2, 7" },
477 { 1, "0, 2, 5, 7" },
478 { 2, "0, 1, 2, 5, 6, 7" },
479 { 3, "4, 9" },
480 { 4, "3, 4, 8, 9" },
481 { 5, "2, 4, 7, 9" },
482 { 6, "0, 2, 3, 4, 5, 7, 8, 9" },
483 { 7, "0, 1, 2, 3, 4, 5, 6, 7, 8, 9" },
484 { 0, NULL }
487 /* Table 7-6 Name association to slice_type */
488 static const value_string h264_slice_type_vals[] = {
489 { 0, "P (P slice)" },
490 { 1, "B (B slice)" },
491 { 2, "I (I slice)" },
492 { 3, "SP (SP slice)" },
493 { 4, "SI (SI slice)" },
494 { 5, "P (P slice)" },
495 { 6, "B (B slice)" },
496 { 7, "I (I slice)" },
497 { 8, "SP (SP slice)" },
498 { 9, "SI (SI slice)" },
499 { 0, NULL }
502 /* Microsoft Frame per second index */
503 static const value_string h264_sei_ms_frame_values[] = {
504 { 0, "7.5 fps" },
505 { 1, "12.5 fps" },
506 { 2, "15 fps" },
507 { 3, "25 fps" },
508 { 4, "30 fps" },
509 { 5, "50 fps" },
510 { 6, "60 fps" },
511 { 0, NULL }
514 /* Microsoft UUIDs from MS-H264-PF */
515 #define MS_LAYOUT 0
516 #define MS_CROPPING 1
517 #define MS_BITSTREAM 2
518 static const e_guid_t ms_guids[3] = {
519 { 0x139FB1A9, 0x446A, 0x4DEC, {0x8C, 0xBF, 0x65, 0xB1, 0xE1, 0x2D, 0x2C, 0xFD}}, /* Stream Layout */
520 { 0xBB7FC1A0, 0x6986, 0x4052, {0x90, 0xF0, 0x09, 0x29, 0x21, 0x75, 0x39, 0xCF}}, /* Cropping Information*/
521 { 0x05FBC6B9, 0x5A80, 0x40E5, {0xA2, 0x2A, 0xAB, 0x40, 0x20, 0x26, 0x7E, 0x26}} /* Bitstream Information */
524 static int
525 dissect_h264(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_);
527 /* byte_aligned( ) is specified as follows.
528 * - If the current position in the bitstream is on a byte boundary, i.e.,
529 * the next bit in the bitstream is the first bit in a byte,
530 * the return value of byte_aligned( ) is equal to true.
531 * - Otherwise, the return value of byte_aligned( ) is equal to false.
533 static bool
534 h264_byte_aligned(int bit_offset)
536 if (bit_offset&0x3)
537 return false;
539 return true;
542 /* Expect a tvb and a bit offset into the tvb
543 * returns the value and bit_offset
545 #define cVALS(x) (const value_string*)(x)
547 static uint32_t
548 dissect_h264_exp_golomb_code(proto_tree *tree, packet_info *pinfo, int hf_index, tvbuff_t *tvb, int *start_bit_offset, h264_golomb_descriptors descriptor)
549 /*(tvbuff_t *tvb, int *start_bit_offset) */
551 proto_item *ti;
553 int leading_zero_bits, bit_offset, start_offset;
554 uint32_t codenum, mask, value, tmp;
555 int32_t se_value = 0;
556 int b;
557 char *str;
558 int bit;
559 int i;
560 bool overflow = false;
561 header_field_info *hf_field = NULL;
563 start_offset = *start_bit_offset>>3;
565 if (hf_index > 0) {
566 hf_field = proto_registrar_get_nth(hf_index);
569 if (hf_field) {
570 switch (descriptor) {
571 case H264_SE_V:
572 DISSECTOR_ASSERT_FIELD_TYPE(hf_field, FT_INT32);
573 break;
575 default:
576 DISSECTOR_ASSERT_FIELD_TYPE(hf_field, FT_UINT32);
577 break;
581 bit_offset = *start_bit_offset;
583 /* prepare the string */
584 str = (char *)wmem_alloc(pinfo->pool, 256);
585 str[0] = '\0';
586 for (bit=0; bit<((int)(bit_offset&0x07)); bit++) {
587 if (bit && (!(bit%4))) {
588 (void) g_strlcat(str, " ", 256);
590 (void) g_strlcat(str,".", 256);
594 leading_zero_bits = -1;
595 for (b = 0; !b; leading_zero_bits++) {
596 if (bit && (!(bit%4))) {
597 (void) g_strlcat(str, " ", 256);
599 if (bit && (!(bit%8))) {
600 (void) g_strlcat(str, " ", 256);
602 b = tvb_get_bits8(tvb, bit_offset, 1);
603 if (b != 0) {
604 (void) g_strlcat(str, "1", 256);
605 } else {
606 (void) g_strlcat(str, "0", 256);
608 bit++;
609 bit_offset++;
612 /* XXX: This could be handled in the general case and reduce code
613 * duplication. */
614 if (leading_zero_bits == 0) {
615 codenum = 0;
616 *start_bit_offset = bit_offset;
617 for (; bit%8; bit++) {
618 if (bit && (!(bit%4))) {
619 (void) g_strlcat(str, " ", 256);
621 (void) g_strlcat(str,".", 256);
623 if (hf_field) {
624 (void) g_strlcat(str," = ", 256);
625 (void) g_strlcat(str, hf_field->name, 256);
626 switch (descriptor) {
627 case H264_SE_V:
628 /* if the syntax element is coded as se(v),
629 * the value of the syntax element is derived by invoking the
630 * mapping process for signed Exp-Golomb codes as specified in
631 * subclause 9.1.1 with codeNum as the input.
633 if (hf_field->type == FT_INT32) {
634 if (hf_field->strings) {
635 proto_tree_add_int_format(tree, hf_index, tvb, start_offset, 1, codenum,
636 "%s: %s (%d)",
637 str,
638 val_to_str_const(codenum, cVALS(hf_field->strings), "Unknown "),
639 codenum);
640 } else {
641 switch (hf_field->display) {
642 case BASE_DEC:
643 proto_tree_add_int_format(tree, hf_index, tvb, start_offset, 1, codenum,
644 "%s: %d",
645 str,
646 codenum);
647 break;
648 default:
649 DISSECTOR_ASSERT_NOT_REACHED();
650 break;
654 return codenum;
655 default:
656 break;
658 if (hf_field->type == FT_UINT32) {
659 if (hf_field->strings) {
660 proto_tree_add_uint_format(tree, hf_index, tvb, start_offset, 1, codenum,
661 "%s: %s (%u)",
662 str,
663 val_to_str_const(codenum, cVALS(hf_field->strings), "Unknown "),
664 codenum);
665 } else {
666 switch (hf_field->display) {
667 case BASE_DEC:
668 proto_tree_add_uint_format(tree, hf_index, tvb, start_offset, 1, codenum,
669 "%s: %u",
670 str,
671 codenum);
672 break;
673 case BASE_HEX:
674 proto_tree_add_uint_format(tree, hf_index, tvb, start_offset, 1, codenum,
675 "%s: 0x%x",
676 str,
677 codenum);
678 break;
679 default:
680 DISSECTOR_ASSERT_NOT_REACHED();
681 break;
684 } else {
685 /* Only allow uint32_t */
686 DISSECTOR_ASSERT_NOT_REACHED();
689 return codenum;
693 Syntax elements coded as ue(v), me(v), or se(v) are Exp-Golomb-coded. Syntax elements coded as te(v) are truncated
694 Exp-Golomb-coded. The parsing process for these syntax elements begins with reading the bits starting at the current
695 location in the bitstream up to and including the first non-zero bit, and counting the number of leading bits that are
696 equal to 0. This process is specified as follows:
697 leadingZeroBits = -1;
698 for (b = 0; !b; leadingZeroBits++)
699 b = read_bits( 1 )
700 The variable codeNum is then assigned as follows:
701 codeNum = 2leadingZeroBits - 1 + read_bits( leadingZeroBits )
702 where the value returned from read_bits( leadingZeroBits ) is interpreted as a binary representation of an unsigned
703 integer with most significant bit written first.
705 if (leading_zero_bits > 32) {
706 overflow = true;
707 codenum = UINT32_MAX;
708 if (descriptor == H264_SE_V) {
709 value = tvb_get_bits32(tvb, bit_offset + 32*(leading_zero_bits / 32), leading_zero_bits % 32, ENC_BIG_ENDIAN);
710 if (value % 2) {
711 se_value = INT32_MIN;
712 } else {
713 se_value = INT32_MAX;
716 } else if (leading_zero_bits == 32) {
717 value = tvb_get_bits32(tvb, bit_offset, leading_zero_bits, ENC_BIG_ENDIAN);
718 codenum = UINT32_MAX;
719 /* Only one value doesn't overflow a 32 bit integer, but they're
720 * different for unsigned and signed (because codenum UINT32_MAX maps
721 * to INT32_MAX + 1 and UINT32_MAX + 1 maps to INT32_MIN.) */
722 if (descriptor == H264_SE_V) {
723 if (value != 1) {
724 overflow = true;
726 if (value % 2) {
727 se_value = INT32_MIN;
728 } else {
729 se_value = INT32_MAX;
731 } else {
732 if (value != 0) {
733 overflow = true;
736 mask = 1U << 31;
737 } else {
738 if (leading_zero_bits > 16)
739 value = tvb_get_bits32(tvb, bit_offset, leading_zero_bits, ENC_BIG_ENDIAN);
740 else if (leading_zero_bits > 8)
741 value = tvb_get_bits16(tvb, bit_offset, leading_zero_bits, ENC_BIG_ENDIAN);
742 else
743 value = tvb_get_bits8(tvb, bit_offset, leading_zero_bits);
745 codenum = 1;
746 codenum = codenum << leading_zero_bits;
747 mask = codenum>>1;
748 codenum = (codenum-1) + value;
750 if (descriptor == H264_SE_V) {
751 /* if the syntax element is coded as se(v),
752 * the value of the syntax element is derived by invoking the
753 * mapping process for signed Exp-Golomb codes as specified in
754 * subclause 9.1.1 with codeNum as the input.
755 * k+1
756 * (-1) Ceil( k/2 )
758 if (codenum & 1) {
759 se_value = (codenum + 1) >> 1;
760 } else {
761 se_value = 0 - (codenum >> 1);
766 bit_offset = bit_offset + leading_zero_bits;
768 if (overflow) {
769 *start_bit_offset = bit_offset;
770 /* We will probably get a BoundsError later in the packet. */
771 if (descriptor == H264_SE_V) {
772 ti = proto_tree_add_int_format_value(tree, hf_index, tvb, start_offset, (bit_offset >> 3) - start_offset + 1, codenum, "Invalid value (%d leading zero bits), clamped to %" PRId32, leading_zero_bits, se_value);
773 expert_add_info(NULL, ti, &ei_h264_oversized_exp_golomb_code);
774 return se_value;
775 } else {
776 ti = proto_tree_add_uint_format_value(tree, hf_index, tvb, start_offset, (bit_offset >> 3) - start_offset + 1, codenum, "Invalid value (%d leading zero bits), clamped to %" PRIu32, leading_zero_bits, codenum);
777 expert_add_info(NULL, ti, &ei_h264_oversized_exp_golomb_code);
778 return codenum;
782 /* read the bits for the int */
783 for (i=0; i<leading_zero_bits; i++) {
784 if (bit && (!(bit%4))) {
785 (void) g_strlcat(str, " ", 256);
787 if (bit && (!(bit%8))) {
788 (void) g_strlcat(str, " ", 256);
790 bit++;
791 tmp = value & mask;
792 if (tmp != 0) {
793 (void) g_strlcat(str, "1", 256);
794 } else {
795 (void) g_strlcat(str, "0", 256);
797 mask = mask>>1;
799 for ( ; bit%8; bit++) {
800 if (bit && (!(bit%4))) {
801 (void) g_strlcat(str, " ", 256);
803 (void) g_strlcat(str,".", 256);
806 if (hf_field) {
807 (void) g_strlcat(str," = ", 256);
808 (void) g_strlcat(str, hf_field->name, 256);
809 switch (descriptor) {
810 case H264_SE_V:
811 (void) g_strlcat(str,"(se(v))", 256);
812 /* if the syntax element is coded as se(v),
813 * the value of the syntax element is derived by invoking the
814 * mapping process for signed Exp-Golomb codes as specified in
815 * subclause 9.1.1 with codeNum as the input.
817 break;
818 default:
819 break;
821 if (descriptor == H264_UE_V) {
822 if (hf_field->strings) {
823 proto_tree_add_uint_format(tree, hf_index, tvb, start_offset, 1, codenum,
824 "%s: %s (%u)",
825 str,
826 val_to_str_const(codenum, cVALS(hf_field->strings), "Unknown "),
827 codenum);
828 } else {
829 switch (hf_field->display) {
830 case BASE_DEC:
831 proto_tree_add_uint_format(tree, hf_index, tvb, start_offset, 1, codenum,
832 "%s: %u",
833 str,
834 codenum);
835 break;
836 case BASE_HEX:
837 proto_tree_add_uint_format(tree, hf_index, tvb, start_offset, 1, codenum,
838 "%s: 0x%x",
839 str,
840 codenum);
841 break;
842 default:
843 DISSECTOR_ASSERT_NOT_REACHED();
844 break;
847 } else if (descriptor == H264_SE_V) {
848 if (hf_field->strings) {
849 proto_tree_add_int_format(tree, hf_index, tvb, start_offset, 1, codenum,
850 "%s: %s (%d)",
851 str,
852 val_to_str_const(codenum, cVALS(hf_field->strings), "Unknown "),
853 se_value);
854 } else {
855 switch (hf_field->display) {
856 case BASE_DEC:
857 proto_tree_add_int_format(tree, hf_index, tvb, start_offset, 1, codenum,
858 "%s: %d",
859 str,
860 se_value);
861 break;
862 default:
863 DISSECTOR_ASSERT_NOT_REACHED();
864 break;
867 *start_bit_offset = bit_offset;
868 return se_value;
870 } else {
871 DISSECTOR_ASSERT_NOT_REACHED();
875 *start_bit_offset = bit_offset;
876 return codenum;
879 /* This function is adapted to parsing NAL units from SDP data where the
880 * base64 coding may add extra padding
881 * Returns true if there is a non-zero bit in remaining of tvb (skipping the current bit)
882 * false if the rest of the tvb is zeros
885 static bool
886 more_rbsp_data(proto_tree *tree _U_, tvbuff_t *tvb, packet_info *pinfo _U_, int bit_offset)
888 int current_bit_offset;
889 int byte_offset;
890 int tvb_length;
891 int significant_bits_mask;
892 int i;
893 uint8_t current_byte;
895 /* XXX might not be the best way of doing things but:
896 * Search in the tvb for the first '1' bit
897 * assuming that it's the RTBSP stop bit or
898 * some data representation
901 /*Skip current treating bit*/
902 current_bit_offset = bit_offset + 1;
904 /*Mask for non processed bits of the current byte*/
905 significant_bits_mask = (1 << (8 - (current_bit_offset & 0x07))) - 1;
907 /* Set offset to the byte we are treating */
908 byte_offset = current_bit_offset >> 3;
910 tvb_length = tvb_reported_length(tvb);
912 for (i = byte_offset; i < tvb_length; i++) {
913 current_byte = tvb_get_uint8(tvb, i);
915 if ((current_byte & significant_bits_mask) != 0) {
916 return true;
919 /* For the rest of bytes every bits are significant*/
920 significant_bits_mask = 0xFF;
923 return false;
926 static int
927 dissect_h264_rbsp_trailing_bits(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int bit_offset)
929 int remaining_bits=0;
931 proto_tree_add_bits_item(tree, hf_h264_rbsp_stop_bit, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
932 bit_offset++;
934 if ((bit_offset&0x7) != 0) {
935 remaining_bits = 8 - (bit_offset&0x7);
936 proto_tree_add_bits_item(tree, hf_h264_rbsp_trailing_bits, tvb, bit_offset, remaining_bits, ENC_BIG_ENDIAN);
939 return bit_offset+remaining_bits;
943 * 7.3.3 Slice header syntax
944 * slice_header( )
945 * XXX Just parse a few bytes
947 static int
948 dissect_h264_slice_header(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int bit_offset)
950 /* first_mb_in_slice 2 ue(v) */
951 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_first_mb_in_slice, tvb, &bit_offset, H264_UE_V);
953 /* slice_type 2 ue(v) */
954 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_slice_type, tvb, &bit_offset, H264_UE_V);
956 /* pic_parameter_set_id 2 ue(v) */
957 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_pic_parameter_set_id, tvb, &bit_offset, H264_UE_V);
959 /* frame_num 2 u(v) */
961 * represented by log2_max_frame_num_minus4 + 4 bits in
962 * the bitstream
963 * proto_tree_add_bits_item(tree, hf_h264_frame_num, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
966 return bit_offset;
969 /* 7.3.2.1.1 Scaling list syntax
971 * scaling_list( scalingList, sizeOfScalingList, useDefaultScalingMatrixFlag )
973 static int
974 dissect_h264_scaling_list(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, int bit_offset, int* hf_index_scalinglist,
975 uint8_t sizeOfScalingList)
977 uint8_t j;
978 int32_t lastScale = 8;
979 int32_t nextScale = 8;
980 int32_t delta_scale;
982 for (j = 0; j < sizeOfScalingList; j++) {
983 if (nextScale != 0) {
984 /* delta_scale 0 | 1 se(v) */
985 delta_scale = dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_delta_scale, tvb, &bit_offset, H264_SE_V);
986 nextScale = ( lastScale + delta_scale + 256 ) % 256;
987 /* hf_index_usedefaultscalingmatrixflag = ( j == 0 && nextScale == 0 ); */
989 hf_index_scalinglist[ j ] = ( nextScale == 0 ) ? lastScale : nextScale;
990 lastScale = hf_index_scalinglist[ j ];
993 return bit_offset;
996 /* E.1.2 HRD parameters syntax */
997 static int
998 dissect_h264_hrd_parameters(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int bit_offset)
1000 uint8_t cpb_cnt_minus1;
1001 int SchedSelIdx;
1004 /* cpb_cnt_minus1 0 ue(v) */
1005 cpb_cnt_minus1 = dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_cpb_cnt_minus1, tvb, &bit_offset, H264_UE_V);
1007 /* bit_rate_scale 0 u(4) */
1008 proto_tree_add_bits_item(tree, hf_h264_bit_rate_scale, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
1009 bit_offset = bit_offset + 4;
1011 /* cpb_size_scale 0 u(4) */
1012 proto_tree_add_bits_item(tree, hf_h264_cpb_size_scale, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
1013 bit_offset = bit_offset + 4;
1014 /* for (SchedSelIdx = 0; SchedSelIdx <= cpb_cnt_minus1; SchedSelIdx++) { */
1015 for (SchedSelIdx = 0; SchedSelIdx <= cpb_cnt_minus1; SchedSelIdx++) {
1017 /* bit_rate_value_minus1[ SchedSelIdx ] 0 ue(v) */
1018 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_bit_rate_value_minus1, tvb, &bit_offset, H264_UE_V);
1020 /* cpb_size_value_minus1[ SchedSelIdx ] 0 ue(v)*/
1021 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_cpb_size_value_minus1, tvb, &bit_offset, H264_UE_V);
1023 /* cbr_flag[ SchedSelIdx ] 0 u(1) */
1024 proto_tree_add_bits_item(tree, hf_h264_cbr_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1025 bit_offset++;
1027 /* initial_cpb_removal_delay_length_minus1 0 u(5) */
1028 proto_tree_add_bits_item(tree, hf_h264_initial_cpb_removal_delay_length_minus1, tvb, bit_offset, 5, ENC_BIG_ENDIAN);
1029 bit_offset = bit_offset + 5;
1031 /* cpb_removal_delay_length_minus1 0 u(5) */
1032 proto_tree_add_bits_item(tree, hf_h264_cpb_removal_delay_length_minus1, tvb, bit_offset, 5, ENC_BIG_ENDIAN);
1033 bit_offset = bit_offset + 5;
1035 /* dpb_output_delay_length_minus1 0 u(5) */
1036 proto_tree_add_bits_item(tree, hf_h264_dpb_output_delay_length_minus11, tvb, bit_offset, 5, ENC_BIG_ENDIAN);
1037 bit_offset = bit_offset + 5;
1039 /* time_offset_length 0 u(5) */
1040 proto_tree_add_bits_item(tree, hf_h264_time_offset_length, tvb, bit_offset, 5, ENC_BIG_ENDIAN);
1041 bit_offset = bit_offset + 5;
1043 return bit_offset;
1046 #define EXTENDED_SAR 255
1048 /* E.1.1 VUI parameters syntax */
1050 /* Table E-2 - Meaning of video_format */
1051 static const value_string h264_video_format_vals[] = {
1052 { 22, "reserved_sei_message)" },
1053 { 0, "Component" },
1054 { 1, "PAL" },
1055 { 2, "NTSC" },
1056 { 3, "SECAM" },
1057 { 4, "MAC" },
1058 { 5, "Unspecified video format" },
1059 { 6, "Reserved" },
1060 { 7, "Reserved" },
1061 { 0, NULL }
1064 static int
1065 dissect_h264_vui_parameters(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int bit_offset)
1068 uint8_t aspect_ratio_info_present_flag, aspect_ratio_idc, overscan_info_present_flag;
1069 uint8_t video_signal_type_present_flag, colour_description_present_flag, chroma_loc_info_present_flag;
1070 uint8_t timing_info_present_flag, nal_hrd_parameters_present_flag, vcl_hrd_parameters_present_flag;
1071 uint8_t bitstream_restriction_flag;
1073 /* vui_parameters( ) {
1074 * aspect_ratio_info_present_flag 0 u(1)
1076 aspect_ratio_info_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1077 proto_tree_add_bits_item(tree, hf_h264_aspect_ratio_info_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1078 bit_offset++;
1080 if (aspect_ratio_info_present_flag) {
1081 /* aspect_ratio_idc 0 u(8) */
1082 aspect_ratio_idc = tvb_get_bits8(tvb, bit_offset, 8);
1083 proto_tree_add_bits_item(tree, hf_h264_aspect_ratio_idc, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
1084 bit_offset = bit_offset + 8;
1086 if (aspect_ratio_idc == EXTENDED_SAR) {
1087 /* sar_width 0 u(16) */
1088 proto_tree_add_bits_item(tree, hf_h264_sar_width, tvb, bit_offset, 16, ENC_BIG_ENDIAN);
1089 bit_offset = bit_offset + 16;
1091 /* sar_height 0 u(16) */
1092 proto_tree_add_bits_item(tree, hf_h264_sar_height, tvb, bit_offset, 16, ENC_BIG_ENDIAN);
1093 bit_offset = bit_offset + 16;
1096 /* overscan_info_present_flag 0 u(1) */
1097 overscan_info_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1098 proto_tree_add_bits_item(tree, hf_h264_overscan_info_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1099 bit_offset++;
1101 if (overscan_info_present_flag) {
1102 /* overscan_appropriate_flag 0 u(1) */
1103 proto_tree_add_bits_item(tree, hf_h264_overscan_appropriate_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1104 bit_offset++;
1107 /* video_signal_type_present_flag 0 u(1) */
1108 video_signal_type_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1109 proto_tree_add_bits_item(tree, hf_h264_video_signal_type_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1110 bit_offset++;
1112 if (video_signal_type_present_flag) {
1113 /* video_format 0 u(3) > */
1114 proto_tree_add_bits_item(tree, hf_h264_video_format, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
1115 bit_offset = bit_offset + 3;
1117 /* video_full_range_flag 0 u(1)*/
1118 proto_tree_add_bits_item(tree, hf_h264_video_full_range_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1119 bit_offset++;
1121 /* colour_description_present_flag 0 u(1) */
1122 colour_description_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1123 proto_tree_add_bits_item(tree, hf_h264_colour_description_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1124 bit_offset++;
1126 if (colour_description_present_flag) {
1127 /* colour_primaries 0 u(8) */
1128 proto_tree_add_bits_item(tree, hf_h264_colour_primaries, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
1129 bit_offset = bit_offset + 8;
1131 /* transfer_characteristics 0 u(8) */
1132 proto_tree_add_bits_item(tree, hf_h264_transfer_characteristics, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
1133 bit_offset = bit_offset + 8;
1135 /* matrix_coefficients 0 u(8)*/
1136 proto_tree_add_bits_item(tree, hf_h264_matrix_coefficients, tvb, bit_offset, 8, ENC_BIG_ENDIAN);
1137 bit_offset = bit_offset + 8;
1141 /* chroma_loc_info_present_flag 0 u(1) */
1142 chroma_loc_info_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1143 proto_tree_add_bits_item(tree, hf_h264_chroma_loc_info_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1144 bit_offset++;
1146 if (chroma_loc_info_present_flag) {
1147 /* chroma_sample_loc_type_top_field 0 ue(v) */
1148 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_chroma_sample_loc_type_top_field, tvb, &bit_offset, H264_UE_V);
1150 /* chroma_sample_loc_type_bottom_field 0 ue(v) */
1151 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_chroma_sample_loc_type_bottom_field, tvb, &bit_offset, H264_UE_V);
1154 /* timing_info_present_flag 0 u(1) */
1155 timing_info_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1156 proto_tree_add_bits_item(tree, hf_h264_timing_info_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1157 bit_offset++;
1159 if (timing_info_present_flag) {
1160 /* num_units_in_tick 0 u(32) */
1161 proto_tree_add_bits_item(tree, hf_h264_num_units_in_tick, tvb, bit_offset, 32, ENC_BIG_ENDIAN);
1162 bit_offset = bit_offset + 32;
1164 /* time_scale 0 u(32) */
1165 proto_tree_add_bits_item(tree, hf_h264_time_scale, tvb, bit_offset, 32, ENC_BIG_ENDIAN);
1166 bit_offset = bit_offset + 32;
1168 /* fixed_frame_rate_flag 0 u(1) */
1169 proto_tree_add_bits_item(tree, hf_h264_fixed_frame_rate_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1170 bit_offset++;
1172 /* nal_hrd_parameters_present_flag 0 u(1) */
1173 nal_hrd_parameters_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1174 proto_tree_add_bits_item(tree, hf_h264_nal_hrd_parameters_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1175 bit_offset++;
1177 if (nal_hrd_parameters_present_flag) {
1178 /* hrd_parameters( ) */
1179 bit_offset = dissect_h264_hrd_parameters(tree, tvb, pinfo, bit_offset);
1182 /* vcl_hrd_parameters_present_flag 0 u(1) */
1183 vcl_hrd_parameters_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1184 proto_tree_add_bits_item(tree, hf_h264_vcl_hrd_parameters_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1185 bit_offset++;
1187 if (vcl_hrd_parameters_present_flag) {
1188 /* hrd_parameters( ) */
1189 bit_offset = dissect_h264_hrd_parameters(tree, tvb, pinfo, bit_offset);
1191 if (nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag) {
1192 /* low_delay_hrd_flag 0 u(1) */
1193 proto_tree_add_bits_item(tree, hf_h264_low_delay_hrd_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1194 bit_offset++;
1196 /* pic_struct_present_flag 0 u(1) */
1197 proto_tree_add_bits_item(tree, hf_h264_pic_struct_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1198 bit_offset++;
1200 /* bitstream_restriction_flag 0 u(1) */
1201 bitstream_restriction_flag = tvb_get_bits8(tvb, bit_offset, 1);
1202 proto_tree_add_bits_item(tree, hf_h264_bitstream_restriction_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1203 bit_offset++;
1205 if (bitstream_restriction_flag) {
1206 /* motion_vectors_over_pic_boundaries_flag 0 u(1) */
1207 proto_tree_add_bits_item(tree, hf_h264_motion_vectors_over_pic_boundaries_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1208 bit_offset++;
1210 /* max_bytes_per_pic_denom 0 ue(v) */
1211 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_max_bytes_per_pic_denom, tvb, &bit_offset, H264_UE_V);
1213 /* max_bits_per_mb_denom 0 ue(v) */
1214 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_max_bits_per_mb_denom, tvb, &bit_offset, H264_UE_V);
1216 /* log2_max_mv_length_horizontal 0 ue(v) */
1217 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_log2_max_mv_length_horizontal, tvb, &bit_offset, H264_UE_V);
1219 /* log2_max_mv_length_vertical 0 ue(v) */
1220 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_log2_max_mv_length_vertical, tvb, &bit_offset, H264_UE_V);
1222 /* num_reorder_frames 0 ue(v) */
1223 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_num_reorder_frames, tvb, &bit_offset, H264_UE_V);
1225 /* max_dec_frame_buffering 0 ue(v) */
1226 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_max_dec_frame_buffering, tvb, &bit_offset, H264_UE_V);
1229 return bit_offset;
1232 /* Used To dissect SDP parameter (H.264)profile */
1233 void
1234 dissect_h264_profile(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
1236 proto_item *item, *level_item;
1237 proto_tree *h264_profile_tree;
1238 int offset = 0;
1239 uint8_t constraint_set3_flag;
1240 uint32_t level_idc;
1242 item = proto_tree_add_item(tree, hf_h264_profile, tvb, offset, -1, ENC_NA);
1243 h264_profile_tree = proto_item_add_subtree(item, ett_h264_profile);
1245 proto_tree_add_item(h264_profile_tree, hf_h264_profile_idc, tvb, offset, 1, ENC_BIG_ENDIAN);
1246 offset++;
1248 constraint_set3_flag = (tvb_get_uint8(tvb, offset)&0x10)>>4;
1249 proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set0_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1250 proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set1_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1251 proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set2_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1252 proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set3_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1253 proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set4_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1254 proto_tree_add_item(h264_profile_tree, hf_h264_constraint_set5_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1255 proto_tree_add_item(h264_profile_tree, hf_h264_reserved_zero_2bits, tvb, offset, 1, ENC_BIG_ENDIAN);
1256 offset++;
1258 /* A level to which the bitstream conforms shall be indicated by the syntax element level_idc as follows.
1259 * - If level_idc is equal to 11 and constraint_set3_flag is equal to 1, the indicated level is level 1b.
1260 * - Otherwise (level_idc is not equal to 11 or constraint_set3_flag is not equal to 1), level_idc shall
1261 * be set equal to a value of ten times the level number specified in Table A-1 and constraint_set3_flag
1262 * shall be set equal to 0.
1265 level_idc = tvb_get_uint8(tvb, offset);
1266 level_item = proto_tree_add_item(h264_profile_tree, hf_h264_level_idc, tvb, offset, 1, ENC_BIG_ENDIAN);
1267 if ((level_idc == 11) && (constraint_set3_flag == 1)) {
1268 proto_item_append_text(level_item," [Level 1b (128kb/s)]");
1269 } else {
1270 proto_item_append_text(level_item," [Level %.1f %s]", ((double)level_idc/10), val_to_str_const(level_idc, h264_level_bitrate_values, "Unknown "));
1275 * 7.3.1 NAL unit syntax
1276 * Un escape the NAL tvb
1279 * nal_unit( NumBytesInNALunit ) { C Descriptor
1280 * forbidden_zero_bit All f(1)
1281 * nal_ref_idc All u(2)
1282 * nal_unit_type All u(5)
1283 * NumBytesInRBSP = 0
1284 * for (i = 1; i < NumBytesInNALunit; i++) {
1285 * if (i + 2 < NumBytesInNALunit && next_bits( 24 ) = = 0x000003 ) {
1286 * rbsp_byte[ NumBytesInRBSP++ ] All b(8)
1287 * rbsp_byte[ NumBytesInRBSP++ ] All b(8)
1288 * i += 2
1289 * emulation_prevention_three_byte / * equal to 0x03 * / All f(8)
1290 * } else
1291 * rbsp_byte[ NumBytesInRBSP++ ] All b(8)
1296 static tvbuff_t *
1297 dissect_h265_unescap_nal_unit(tvbuff_t *tvb, packet_info *pinfo, int offset)
1299 tvbuff_t *tvb_rbsp;
1300 int length = tvb_reported_length_remaining(tvb, offset);
1301 int NumBytesInRBSP = 0;
1302 int i;
1303 char *buff;
1305 buff = (char *)wmem_alloc(pinfo->pool, length);
1306 for (i = 0; i < length; i++) {
1307 if ((i + 2 < length) && (tvb_get_ntoh24(tvb, offset) == 0x000003)) {
1308 buff[NumBytesInRBSP++] = tvb_get_uint8(tvb, offset);
1309 buff[NumBytesInRBSP++] = tvb_get_uint8(tvb, offset+1);
1310 i += 2;
1311 offset+=3;
1312 } else {
1313 buff[ NumBytesInRBSP++] = tvb_get_uint8(tvb, offset);
1314 offset++;
1318 tvb_rbsp = tvb_new_child_real_data(tvb, buff, NumBytesInRBSP, NumBytesInRBSP);
1319 add_new_data_source(pinfo, tvb_rbsp, "Unescaped RSP Data");
1321 return tvb_rbsp;
1325 * 7.3.2.8 Slice layer without partitioning RBSP syntax
1326 * slice_layer_without_partitioning_rbsp( )
1329 static void
1330 dissect_h264_slice_layer_without_partitioning_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int offset)
1332 int bit_offset;
1334 bit_offset = offset <<3;
1336 /* slice_header( ) 2 */
1337 bit_offset = dissect_h264_slice_header(tree, tvb, pinfo, bit_offset);
1338 proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, bit_offset>>3, -1);
1339 return;
1340 /* slice_data( ) * all categories of slice_data( ) syntax * 2 | 3 | 4 */
1341 /* rbsp_slice_trailing_bits( ) */
1345 * 7.3.2.9.1 Slice data partition A RBSP syntax
1346 * slice_data_partition_a_layer_rbsp( )
1348 static void
1349 dissect_h264_slice_data_partition_a_layer_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int offset)
1351 int bit_offset;
1353 bit_offset = offset <<3;
1355 /* slice_header( ) 2 */
1356 bit_offset = dissect_h264_slice_header(tree, tvb, pinfo, bit_offset);
1358 /* slice_id All ue(v) */
1359 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_slice_id, tvb, &bit_offset, H264_UE_V);
1360 proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, bit_offset>>3, -1);
1361 return;
1362 /* slice_data( ) * only category 2 parts of slice_data( ) syntax * 2*/
1363 /* rbsp_slice_trailing_bits( )*/
1367 * 7.3.2.9.2 Slice data partition B RBSP syntax
1368 * slice_data_partition_b_layer_rbsp(
1370 static void
1371 dissect_h264_slice_data_partition_b_layer_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int offset)
1373 int bit_offset;
1375 bit_offset = offset <<3;
1377 /* slice_id All ue(v) */
1378 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_slice_id, tvb, &bit_offset, H264_UE_V);
1379 /* if (redundant_pic_cnt_present_flag) */
1380 /* redundant_pic_cnt All ue(v) */
1381 /* slice_data( ) * only category 3 parts of slice_data( ) syntax * 3 */
1382 /* rbsp_slice_trailing_bits( ) 3 */
1383 proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, bit_offset>>3, -1);
1388 * 7.3.2.9.3 Slice data partition C RBSP syntax
1389 * slice_data_partition_c_layer_rbsp( )
1391 static void
1392 dissect_h264_slice_data_partition_c_layer_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int offset)
1394 int bit_offset;
1396 bit_offset = offset <<3;
1398 /* slice_id All ue(v) */
1399 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_slice_id, tvb, &bit_offset, H264_UE_V);
1400 /* if (redundant_pic_cnt_present_flag) */
1401 /* redundant_pic_cnt All ue(v) */
1402 /* slice_data( ) * only category 4 parts of slice_data( ) syntax * 4 */
1403 /* rbsp_slice_trailing_bits( ) 4 */
1404 proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, bit_offset>>3, -1);
1407 /* D.1.6 User data unregistered SEI message syntax */
1409 static int
1410 h264_user_data_unregistered(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int bit_offset, uint32_t payloadSize)
1412 uint8_t i;
1413 uint8_t ld_size;
1414 uint8_t p_flag;
1415 uint8_t desc =0;
1416 uint8_t num_crops;
1417 int offset = bit_offset >> 3;
1418 proto_item *item;
1419 proto_item *uuid_item;
1420 proto_tree *h264_ms_layer_desc_tree;
1421 proto_tree *h264_ms_crop_data_tree;
1422 e_guid_t guid;
1425 /* user_data_unregistered( payloadSize ) { C Descriptor */
1426 /* uuid_iso_iec_11578 5 u(128)
1427 * uuid_iso_iec_11578 shall have a value specified as a UUID
1428 * according to the procedures of ISO/IEC 11578:1996 Annex A.
1431 uuid_item = proto_tree_add_item (tree, hf_h264_sei_uuid, tvb, offset, 16, ENC_BIG_ENDIAN);
1432 /* Extract the ISO/IEC value for comparison */
1433 tvb_get_ntohguid(tvb, offset, &guid);
1434 offset+=16;
1436 /* Microsoft MS-H264PF Specification */
1437 if ( memcmp(&guid, &(ms_guids[MS_LAYOUT]), sizeof(e_guid_t)) == 0)
1439 col_append_str(pinfo->cinfo, COL_INFO, ":MS_Layout");
1440 proto_item_append_text(uuid_item," - Microsoft Stream Layout SEI Message");
1441 /* Loop through the layer presence bytes 0-7 */
1442 for (i = 0; i < 8 ; i++)
1444 item = proto_tree_add_item (tree, hf_h264_sei_ms_lpb, tvb, offset, 1, ENC_BIG_ENDIAN);
1445 proto_item_append_text (item, " PRID %2d - %2d", (i+1)*8-1, i*8);
1446 offset++;
1448 p_flag = tvb_get_uint8 (tvb, offset);
1449 proto_tree_add_item (tree, hf_h264_sei_ms_layout_p, tvb, offset, 1, ENC_BIG_ENDIAN);
1450 offset++;
1451 if (p_flag == 1)
1453 ld_size = tvb_get_uint8 (tvb, offset);
1454 proto_tree_add_item (tree, hf_h264_sei_ms_layout_ldsize, tvb, offset, 1, ENC_BIG_ENDIAN);
1455 offset++;
1456 /* MS Errata - Microsoft seems to be setting the LD size to 16 but then including 2 layer descriptions which should be 32
1457 * To compensate for that, keep decoding layers as long as there are 16 or more bytes left in the SEI message.
1459 if (tvb_reported_length_remaining (tvb, offset) != ld_size)
1461 item = proto_tree_add_expert(tree, pinfo, &ei_h264_ms_layout_wrong_length, tvb, offset-1, 1);
1462 proto_item_append_text(item," Size of %d, remaining size %d",
1463 ld_size,
1464 tvb_reported_length_remaining (tvb, offset));
1466 while (tvb_reported_length_remaining (tvb, offset) >= 16)
1468 h264_ms_layer_desc_tree = proto_tree_add_subtree_format(tree, tvb, offset, 16, ett_h264_ms_layer_description, NULL, "MS Layer Description #%d", ++desc);
1470 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_coded_width, tvb, offset, 2, ENC_BIG_ENDIAN);
1471 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_coded_height, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
1472 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_display_width, tvb, offset + 4, 2, ENC_BIG_ENDIAN);
1473 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_display_height, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
1474 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_bitrate, tvb, offset + 8, 4, ENC_BIG_ENDIAN);
1475 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_frame_rate, tvb, offset + 12, 1, ENC_BIG_ENDIAN);
1476 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_layer_type, tvb, offset + 12, 1, ENC_BIG_ENDIAN);
1477 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_prid, tvb, offset + 13, 1, ENC_BIG_ENDIAN);
1478 proto_tree_add_item (h264_ms_layer_desc_tree, hf_h264_sei_ms_layer_desc_cb, tvb, offset + 13, 1, ENC_BIG_ENDIAN);
1479 offset += 16;
1483 else if ( memcmp(&guid, &(ms_guids[MS_CROPPING]), sizeof(e_guid_t)) == 0)
1485 col_append_str(pinfo->cinfo, COL_INFO, ":MS_Cropping");
1486 proto_item_append_text(uuid_item," - Microsoft Cropping Info SEI Message");
1487 num_crops = tvb_get_uint8 (tvb, offset);
1488 proto_tree_add_item (tree, hf_h264_sei_ms_crop_num_data, tvb, offset, 1, ENC_BIG_ENDIAN);
1489 offset++;
1490 proto_tree_add_item (tree, hf_h264_sei_ms_crop_info_type, tvb, offset, 1, ENC_BIG_ENDIAN);
1491 offset++;
1492 while (num_crops != 0)
1494 h264_ms_crop_data_tree = proto_tree_add_subtree_format(tree, tvb, offset, 9, ett_h264_ms_crop_data, NULL, "Crop Data #%d", ++desc);
1495 proto_tree_add_item (h264_ms_crop_data_tree, hf_h264_sei_ms_crop_confidence_level, tvb, offset, 1, ENC_BIG_ENDIAN);
1496 proto_tree_add_item (h264_ms_crop_data_tree, hf_h264_sei_ms_crop_frame_left_offset, tvb, offset+1, 2, ENC_BIG_ENDIAN);
1497 proto_tree_add_item (h264_ms_crop_data_tree, hf_h264_sei_ms_crop_frame_right_offset, tvb, offset+3, 2, ENC_BIG_ENDIAN);
1498 proto_tree_add_item (h264_ms_crop_data_tree, hf_h264_sei_ms_crop_frame_top_offset, tvb, offset+5, 2, ENC_BIG_ENDIAN);
1499 proto_tree_add_item (h264_ms_crop_data_tree, hf_h264_sei_ms_crop_frame_bottom_offset, tvb, offset+7, 2, ENC_BIG_ENDIAN);
1500 num_crops--;
1501 offset += 9;
1504 else if ( memcmp(&guid, &(ms_guids[MS_BITSTREAM]), sizeof(e_guid_t)) == 0)
1506 col_append_str(pinfo->cinfo, COL_INFO, ":MS_Bitstream");
1507 proto_item_append_text(uuid_item," - Microsoft Bitstream Info SEI Message");
1508 proto_tree_add_item (tree, hf_h264_sei_ms_bitstream_ref_frame_cnt, tvb, offset, 1, ENC_BIG_ENDIAN);
1509 offset++;
1510 proto_tree_add_item (tree, hf_h264_sei_ms_bitstream_num_nalus, tvb, offset, 1, ENC_BIG_ENDIAN);
1511 offset++;
1513 else
1515 proto_tree_add_item(tree, hf_h264_sei_iso_sec_info, tvb, offset, 16, ENC_NA);
1516 /* for (i = 16; i < payloadSize; i++)
1517 * user_data_payload_byte 5 b(8)
1519 if (payloadSize > 16)
1521 proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, offset, payloadSize-16);
1522 offset+=(payloadSize-16);
1526 return offset << 3;
1529 /* D.1 SEI payload syntax */
1530 static const value_string h264_sei_payload_vals[] = {
1531 { 0, "buffering_period" },
1532 { 1, "pic_timing" },
1533 { 2, "pan_scan_rect" },
1534 { 3, "filler_payload" },
1535 { 4, "user_data_registered_itu_t_t35" },
1536 { 5, "user_data_unregistered" },
1537 { 6, "recovery_point" },
1538 { 7, "dec_ref_pic_marking_repetition" },
1539 { 8, "spare_pic" },
1540 { 9, "scene_inf)" },
1541 { 10, "sub_seq_info)" },
1542 { 11, "sub_seq_layer_characteristics" },
1543 { 12, "sub_seq_characteristics" },
1544 { 13, "full_frame_freeze_release" },
1545 { 14, "full_frame_freeze_release" },
1546 { 15, "full_frame_snapshot" },
1547 { 16, "progressive_refinement_segment_start" },
1548 { 17, "progressive_refinement_segment_end" },
1549 { 18, "motion_constrained_slice_group_set" },
1550 { 19, "film_grain_characteristics)" },
1551 { 20, "deblocking_filter_display_preference)" },
1552 { 21, "stereo_video_info)" },
1553 { 22, "post_filter_hint" },
1554 { 23, "tone_mapping_info" },
1555 /* Annex G Values */
1556 { 24, "scalability_info" },
1557 { 25, "sub_pic_scalable_layer" },
1558 { 26, "non_required_layer_rep" },
1559 { 27, "priority_layer_info" },
1560 { 28, "layers_not_present" },
1561 { 29, "layer_dependency_change" },
1562 { 30, "scalable_nesting" },
1563 { 31, "base_layer_temporal_hrd" },
1564 { 32, "quality_layer_integrity_check" },
1565 { 33, "redundant_pic_property" },
1566 { 34, "tl0_dep_rep_index" },
1567 { 35, "tl_switching_point" },
1568 /* Annex H 37 to 46 - Not Decoded*/
1569 /* Annex I 47 to 53 - Not Decoded*/
1570 { 0, NULL }
1573 static int
1574 h264_sei_payload(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int bit_offset, uint32_t payloadType, uint32_t payloadSize)
1576 /* sei_payload( payloadType, payloadSize ) { C Descriptor */
1577 if (payloadType == 0) {
1578 /* buffering_period( payloadSize ) 5 */
1579 bit_offset = bit_offset +(payloadSize<<3);
1580 #if 0
1581 } else if (payloadType == 1) {
1582 /* pic_timing( payloadSize ) 5 */
1583 } else if (payloadType == 2) {
1584 /* pan_scan_rect( payloadSize ) 5 */
1585 } else if (payloadType == 3) {
1586 /* filler_payload( payloadSize ) 5 */
1587 } else if (payloadType == 4) {
1588 /* user_data_registered_itu_t_t35( payloadSize ) 5 */
1589 #endif
1590 } else if (payloadType == 5) {
1591 /* user_data_unregistered( payloadSize ) 5 */
1592 bit_offset = h264_user_data_unregistered( tree, tvb, pinfo, bit_offset, payloadSize);
1593 } else if (payloadType == 6) {
1594 /* recovery_point( payloadSize ) 5 */
1595 bit_offset = bit_offset +(payloadSize<<3);
1596 } else if (payloadType == 7) {
1597 /* dec_ref_pic_marking_repetition( payloadSize ) 5 */
1598 bit_offset = bit_offset +(payloadSize<<3);
1600 #if 0
1601 else if (payloadType == 8)
1602 spare_pic( payloadSize ) 5
1603 else if (payloadType == 9)
1604 scene_info( payloadSize ) 5
1605 else if (payloadType == 10)
1606 sub_seq_info( payloadSize ) 5
1607 else if (payloadType == 11)
1608 sub_seq_layer_characteristics( payloadSize ) 5
1609 else if (payloadType == 12)
1610 sub_seq_characteristics( payloadSize ) 5
1611 else if (payloadType == 13)
1612 full_frame_freeze( payloadSize ) 5
1613 else if (payloadType == 14)
1614 full_frame_freeze_release( payloadSize ) 5
1615 else if (payloadType == 15)
1616 full_frame_snapshot( payloadSize ) 5
1617 else if (payloadType == 16)
1618 progressive_refinement_segment_start( payloadSize ) 5
1619 else if (payloadType == 17)
1620 progressive_refinement_segment_end( payloadSize ) 5
1621 else if (payloadType == 18)
1622 motion_constrained_slice_group_set( payloadSize ) 5
1623 else if (payloadType == 19)
1624 film_grain_characteristics( payloadSize ) 5
1625 else if (payloadType == 20)
1626 deblocking_filter_display_preference( payloadSize ) 5
1627 else if (payloadType == 21)
1628 stereo_video_info( payloadSize ) 5
1629 else
1630 reserved_sei_message( payloadSize ) 5
1631 return bit_offset;
1632 #endif
1633 if (!h264_byte_aligned(bit_offset)) {
1634 /* bit_equal_to_one / * equal to 1 * / 5 f(1) */
1635 /* TODO:Display the filler and, error if not 1 ?? */
1636 bit_offset++;
1637 while (!h264_byte_aligned(bit_offset)) {
1638 /* bit_equal_to_zero / * equal to 0 * / 5 f(1) */
1639 /* TODO:Display the filler and, error if not 0 ?? */
1640 bit_offset++;
1643 return bit_offset;
1647 * 7.3.2.3.1 Supplemental enhancement information message syntax
1649 static int
1650 dissect_h264_sei_message(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int bit_offset)
1652 /* sei_message( ) { C Descriptor */
1653 uint32_t payloadType = 0, payloadSize;
1654 int start_bit_offset, length;
1656 start_bit_offset = bit_offset;
1658 /* while (next_bits( 8 ) == 0xFF) { */
1659 while (tvb_get_bits8(tvb, bit_offset, 8) == 0xFF) {
1660 /* ff_byte / * equal to 0xFF * / 5 f(8) */
1661 payloadType += 255;
1662 bit_offset+=8;
1664 /* last_payload_type_byte 5 u(8) */
1665 payloadType += tvb_get_bits8(tvb, bit_offset, 8);
1666 bit_offset+=8;
1667 length = (bit_offset - start_bit_offset)>>3;
1669 proto_tree_add_uint(tree, hf_h264_payloadtype, tvb, start_bit_offset>>3, length, payloadType);
1671 payloadSize = 0;
1672 start_bit_offset = bit_offset;
1673 /* while (next_bits( 8 ) == 0xFF) { */
1674 while (tvb_get_bits8(tvb, bit_offset, 8) == 0xFF) {
1675 /* ff_byte / * equal to 0xFF * / 5 f(8) */
1676 payloadSize += 255;
1677 bit_offset+=8;
1679 /* last_payload_size_byte 5 u(8) */
1680 /* payloadSize += last_payload_size_byte */
1681 payloadSize += tvb_get_bits8(tvb, bit_offset, 8);
1682 bit_offset+=8;
1683 length = (bit_offset - start_bit_offset)>>3;
1684 proto_tree_add_uint(tree, hf_h264_payloadsize, tvb, start_bit_offset>>3, length, payloadSize);
1686 /*sei_payload( payloadType, payloadSize ) 5 */
1687 bit_offset = h264_sei_payload( tree, tvb, pinfo, bit_offset, payloadType, payloadSize);
1688 return bit_offset;
1692 * 7.3.2.3 Supplemental enhancement information RBSP syntax
1693 * sei_rbsp( )
1695 static int
1696 dissect_h264_sei_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int offset)
1698 int bit_offset;
1700 bit_offset = offset <<3;
1701 /* do */
1702 /* sei_message( ) 5*/
1703 bit_offset = dissect_h264_sei_message( tree, tvb, pinfo, bit_offset);
1705 /* while (more_rbsp_data( ))
1706 * If there is more data in an RBSP before rbsp_trailing_bits( ),
1707 * the return value of more_rbsp_data( ) is equal to true.
1709 /* rbsp_trailing_bits( ) 5 */
1710 if (tvb_reported_length_remaining (tvb, bit_offset >> 3) != 0 || (bit_offset & 0x7) != 0)
1712 bit_offset = dissect_h264_rbsp_trailing_bits(tree, tvb, pinfo, bit_offset);
1715 return bit_offset;
1718 /* Ref 7.3.2.1 Sequence parameter set RBSP syntax */
1719 static int
1720 dissect_h264_seq_parameter_set_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int offset)
1722 proto_item *level_item;
1723 int bit_offset;
1724 uint8_t constraint_set3_flag;
1725 uint32_t level_idc;
1727 int i;
1728 uint8_t profile_idc, chroma_format_idc, frame_mbs_only_flag, frame_cropping_flag;
1729 uint8_t pic_order_cnt_type, vui_parameters_present_flag, num_ref_frames_in_pic_order_cnt_cycle;
1730 uint8_t seq_scaling_matrix_present_flag, seq_scaling_list_present_flag;
1731 int ScalingList4x4[6][16], ScalingList8x8[2][64];
1733 /* profile_idc 0 u(8) */
1734 profile_idc = tvb_get_uint8(tvb, offset);
1735 proto_tree_add_item(tree, hf_h264_profile_idc, tvb, offset, 1, ENC_BIG_ENDIAN);
1736 offset++;
1738 constraint_set3_flag = (tvb_get_uint8(tvb, offset)&0x10)>>4;
1739 /* constraint_set0_flag 0 u(1) */
1740 proto_tree_add_item(tree, hf_h264_constraint_set0_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1742 /* constraint_set1_flag 0 u(1) */
1743 proto_tree_add_item(tree, hf_h264_constraint_set1_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1745 /* constraint_set2_flag 0 u(1) */
1746 proto_tree_add_item(tree, hf_h264_constraint_set2_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1748 /* constraint_set3_flag 0 u(1) */
1749 proto_tree_add_item(tree, hf_h264_constraint_set3_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1751 /* constraint_set4_flag 0 u(1) */
1752 proto_tree_add_item(tree, hf_h264_constraint_set4_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1754 /* constraint_set5_flag 0 u(1) */
1755 proto_tree_add_item(tree, hf_h264_constraint_set5_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
1757 /* reserved_zero_4bits equal to 0 0 u(4)*/
1758 proto_tree_add_item(tree, hf_h264_reserved_zero_2bits, tvb, offset, 1, ENC_BIG_ENDIAN);
1759 offset++;
1761 /* level_idc 0 u(8) */
1762 level_idc = tvb_get_uint8(tvb, offset);
1763 level_item = proto_tree_add_item(tree, hf_h264_level_idc, tvb, offset, 1, ENC_BIG_ENDIAN);
1764 if ((level_idc == 11) && (constraint_set3_flag == 1)) {
1765 proto_item_append_text(level_item,"[Level 1b]");
1766 } else {
1767 proto_item_append_text(level_item," [Level %.1f %s]", ((double)level_idc/10), val_to_str_const(level_idc, h264_level_bitrate_values, "Unknown "));
1769 offset++;
1770 /* seq_parameter_set_id 0 ue(v)
1771 * ue(v): unsigned integer Exp-Golomb-coded syntax element with the left bit first.
1772 * The parsing process for this descriptor is specified in subclause 9.1.
1774 bit_offset = offset<<3;
1775 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_seq_parameter_set_id, tvb, &bit_offset, H264_UE_V);
1778 if ((profile_idc == 100) || (profile_idc == 110) ||
1779 (profile_idc == 122) || (profile_idc == 144) ||
1780 (profile_idc == 44) || (profile_idc == 83) ||
1781 (profile_idc == 86) || (profile_idc == 118) ||
1782 (profile_idc == 128) || (profile_idc == 138))
1785 /* chroma_format_idc 0 ue(v) */
1786 chroma_format_idc = dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_chroma_format_idc, tvb, &bit_offset, H264_UE_V);
1787 if (chroma_format_idc == 3) {
1788 /* residual_colour_transform_flag 0 u(1) */
1789 proto_tree_add_bits_item(tree, hf_h264_residual_colour_transform_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1790 bit_offset++;
1793 /* bit_depth_luma_minus8 0 ue(v) */
1794 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_bit_depth_luma_minus8, tvb, &bit_offset, H264_UE_V);
1796 /* bit_depth_chroma_minus8 0 ue(v) */
1797 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_bit_depth_chroma_minus8, tvb, &bit_offset, H264_UE_V);
1799 /* qpprime_y_zero_transform_bypass_flag 0 u(1) */
1800 proto_tree_add_bits_item(tree, hf_h264_qpprime_y_zero_transform_bypass_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1801 bit_offset++;
1803 /* seq_scaling_matrix_present_flag 0 u(1) */
1804 seq_scaling_matrix_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1805 proto_tree_add_bits_item(tree, hf_h264_seq_scaling_matrix_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1806 bit_offset++;
1808 if (seq_scaling_matrix_present_flag) {
1809 for (i = 0; i < 8; i++) {
1810 /* seq_scaling_list_present_flag[ i ] 0 u(1) */
1811 seq_scaling_list_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1812 proto_tree_add_bits_item(tree, hf_h264_seq_scaling_list_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1813 bit_offset++;
1814 if (seq_scaling_list_present_flag) {
1815 if (i < 6)
1816 bit_offset = dissect_h264_scaling_list(tree, pinfo, tvb, bit_offset, ScalingList4x4[ i ], 16);
1817 else
1818 bit_offset = dissect_h264_scaling_list(tree, pinfo, tvb, bit_offset, ScalingList8x8[ i - 6 ], 64);
1825 /* log2_max_frame_num_minus4 0 ue(v) */
1826 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_log2_max_frame_num_minus4, tvb, &bit_offset, H264_UE_V);
1828 /* pic_order_cnt_type 0 ue(v) */
1829 pic_order_cnt_type = dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_pic_order_cnt_type, tvb, &bit_offset, H264_UE_V);
1831 if (pic_order_cnt_type == 0) {
1832 /* log2_max_pic_order_cnt_lsb_minus4 0 ue(v) */
1833 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_log2_max_pic_order_cnt_lsb_minus4, tvb, &bit_offset, H264_UE_V);
1834 } else if (pic_order_cnt_type == 1) {
1835 /* delta_pic_order_always_zero_flag 0 u(1) */
1836 proto_tree_add_bits_item(tree, hf_h264_delta_pic_order_always_zero_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1837 bit_offset++;
1839 /* offset_for_non_ref_pic 0 se(v) */
1840 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_offset_for_non_ref_pic, tvb, &bit_offset, H264_SE_V);
1842 /* offset_for_top_to_bottom_field 0 se(v) */
1843 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_offset_for_top_to_bottom_field, tvb, &bit_offset, H264_SE_V);
1845 /* num_ref_frames_in_pic_order_cnt_cycle 0 ue(v) */
1846 num_ref_frames_in_pic_order_cnt_cycle = dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_num_ref_frames_in_pic_order_cnt_cycle, tvb, &bit_offset, H264_UE_V);
1847 for (i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) {
1848 /*offset_for_ref_frame[ i ] 0 se(v)*/
1849 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_offset_for_ref_frame, tvb, &bit_offset, H264_SE_V);
1852 /* num_ref_frames 0 ue(v) */
1853 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_num_ref_frames, tvb, &bit_offset, H264_UE_V);
1855 /* gaps_in_frame_num_value_allowed_flag 0 u(1) */
1856 proto_tree_add_bits_item(tree, hf_h264_gaps_in_frame_num_value_allowed_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1857 bit_offset++;
1859 /* pic_width_in_mbs_minus1 0 ue(v) */
1860 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_pic_width_in_mbs_minus1, tvb, &bit_offset, H264_UE_V);
1862 /* pic_height_in_map_units_minus1 0 ue(v) */
1863 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_pic_height_in_map_units_minus1, tvb, &bit_offset, H264_UE_V);
1865 /* frame_mbs_only_flag 0 u(1) */
1866 frame_mbs_only_flag = tvb_get_bits8(tvb, bit_offset, 1);
1867 proto_tree_add_bits_item(tree, hf_h264_frame_mbs_only_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1868 bit_offset++;
1869 if (!frame_mbs_only_flag) {
1870 /* mb_adaptive_frame_field_flag 0 u(1) */
1871 proto_tree_add_bits_item(tree, hf_h264_mb_adaptive_frame_field_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1872 bit_offset++;
1875 /* direct_8x8_inference_flag 0 u(1) */
1876 proto_tree_add_bits_item(tree, hf_h264_direct_8x8_inference_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1877 bit_offset++;
1879 /* frame_cropping_flag 0 u(1) */
1880 frame_cropping_flag = tvb_get_bits8(tvb, bit_offset, 1);
1881 proto_tree_add_bits_item(tree, hf_h264_frame_cropping_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1882 bit_offset++;
1884 if (frame_cropping_flag) {
1885 /* frame_crop_left_offset 0 ue(v) */
1886 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_frame_crop_left_offset, tvb, &bit_offset, H264_UE_V);
1887 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_frame_crop_right_offset, tvb, &bit_offset, H264_UE_V);
1888 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_frame_crop_top_offset, tvb, &bit_offset, H264_UE_V);
1889 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_frame_crop_bottom_offset, tvb, &bit_offset, H264_UE_V);
1893 /* vui_parameters_present_flag 0 u(1) */
1894 vui_parameters_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
1895 proto_tree_add_bits_item(tree, hf_h264_vui_parameters_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1896 bit_offset++;
1897 if (vui_parameters_present_flag) {
1898 bit_offset = dissect_h264_vui_parameters(tree, tvb, pinfo, bit_offset);
1901 /* rbsp_trailing_bits( ) 0 */
1902 bit_offset = dissect_h264_rbsp_trailing_bits(tree, tvb, pinfo, bit_offset);
1904 offset = bit_offset>>3;
1906 /* TODO - Add dissector of SPS SVC extension from Annex G*/
1907 return offset;
1910 /* 7.3.2.2 Picture parameter set RBSP syntax */
1912 static void
1913 dissect_h264_pic_parameter_set_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int offset)
1915 int bit_offset;
1916 uint32_t num_slice_groups_minus1, pic_scaling_matrix_present_flag;
1918 bit_offset = offset<<3;
1920 /* pic_parameter_set_id 1 ue(v) */
1921 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_pic_parameter_set_id, tvb, &bit_offset, H264_UE_V);
1923 /* seq_parameter_set_id 1 ue(v) */
1924 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_seq_parameter_set_id, tvb, &bit_offset, H264_UE_V);
1926 /* entropy_coding_mode_flag 1 u(1) */
1927 proto_tree_add_bits_item(tree, hf_h264_entropy_coding_mode_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1928 bit_offset++;
1930 /* pic_order_present_flag 1 u(1)*/
1931 proto_tree_add_bits_item(tree, hf_h264_pic_order_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1932 bit_offset++;
1934 /* num_slice_groups_minus1 1 ue(v)*/
1935 num_slice_groups_minus1 = dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_num_slice_groups_minus1, tvb, &bit_offset, H264_UE_V);
1936 if (num_slice_groups_minus1 > 0) {
1937 /* slice_group_map_type 1 ue(v)*/
1938 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_slice_group_map_type, tvb, &bit_offset, H264_UE_V);
1939 /* slice_group_map_type = dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_slice_group_map_type, tvb, &bit_offset, H264_UE_V);*/
1940 /* if (slice_group_map_type == 0)*/
1941 /* for (iGroup = 0; iGroup <= num_slice_groups_minus1; iGroup++)*/
1942 /* run_length_minus1[ iGroup ] 1 ue(v)*/
1943 /* else if (slice_group_map_type == 2)*/
1944 /* for (iGroup = 0; iGroup < num_slice_groups_minus1; iGroup++) {*/
1945 /* top_left[ iGroup ] 1 ue(v)*/
1946 /* bottom_right[ iGroup ] 1 ue(v)*/
1947 /* }*/
1948 /* else if (slice_group_map_type == 3 ||*/
1949 /* slice_group_map_type == 4 ||*/
1950 /* slice_group_map_type == 5 ) {*/
1951 /* slice_group_change_direction_flag 1 u(1)*/
1952 /* slice_group_change_rate_minus1 1 ue(v)*/
1953 /* } else if (slice_group_map_type == 6) {*/
1954 /* pic_size_in_map_units_minus1 1 ue(v)*/
1955 /* for (i = 0; i <= pic_size_in_map_units_minus1; i++)*/
1956 /* slice_group_id[ i ] 1 u(v)*/
1957 /* }*/
1958 /* }*/
1959 proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, bit_offset>>3, -1);
1960 return;
1962 /* num_ref_idx_l0_active_minus1 1 ue(v)*/
1963 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_num_ref_idx_l0_active_minus1, tvb, &bit_offset, H264_UE_V);
1965 /* num_ref_idx_l1_active_minus1 1 ue(v)*/
1966 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_num_ref_idx_l1_active_minus1, tvb, &bit_offset, H264_UE_V);
1968 /* weighted_pred_flag 1 u(1)*/
1969 proto_tree_add_bits_item(tree, hf_h264_weighted_pred_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1970 bit_offset++;
1972 /* weighted_bipred_idc 1 u(2)*/
1973 proto_tree_add_bits_item(tree, hf_h264_weighted_bipred_idc, tvb, bit_offset, 2, ENC_BIG_ENDIAN);
1974 bit_offset= bit_offset+2;
1976 /* pic_init_qp_minus26 * relative to 26 * 1 se(v)*/
1977 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_pic_init_qp_minus26, tvb, &bit_offset, H264_SE_V);
1979 /* pic_init_qs_minus26 * relative to 26 * 1 se(v)*/
1980 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_pic_init_qs_minus26, tvb, &bit_offset, H264_SE_V);
1982 /* chroma_qp_index_offset 1 se(v)*/
1983 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_chroma_qp_index_offset, tvb, &bit_offset, H264_SE_V);
1985 /* deblocking_filter_control_present_flag 1 u(1)*/
1986 proto_tree_add_bits_item(tree, hf_h264_deblocking_filter_control_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1987 bit_offset++;
1989 /* constrained_intra_pred_flag 1 u(1)*/
1990 proto_tree_add_bits_item(tree, hf_h264_constrained_intra_pred_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1991 bit_offset++;
1993 /* redundant_pic_cnt_present_flag 1 u(1)*/
1994 proto_tree_add_bits_item(tree, hf_h264_redundant_pic_cnt_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1995 bit_offset++;
1997 if (more_rbsp_data(tree, tvb, pinfo, bit_offset)) {
1998 /* transform_8x8_mode_flag 1 u(1)*/
1999 proto_tree_add_bits_item(tree, hf_h264_transform_8x8_mode_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
2000 bit_offset++;
2002 /* pic_scaling_matrix_present_flag 1 u(1)*/
2003 pic_scaling_matrix_present_flag = tvb_get_bits8(tvb, bit_offset, 1);
2004 proto_tree_add_bits_item(tree, hf_h264_pic_scaling_matrix_present_flag, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
2005 bit_offset++;
2007 if (pic_scaling_matrix_present_flag) {
2008 proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, bit_offset>>3, -1);
2009 return;
2010 /* for (i = 0; i < 6 + 2* transform_8x8_mode_flag; i++) {*/
2011 /* pic_scaling_list_present_flag[ i ] 1 u(1)*/
2012 /* if (pic_scaling_list_present_flag[ i ])*/
2013 /* if (i < 6)*/
2014 /* scaling_list( ScalingList4x4[ i ], 16, UseDefaultScalingMatrix4x4Flag[ i ] )*/
2015 /* else*/
2016 /* scaling_list( ScalingList8x8[ i - 6 ], 64, UseDefaultScalingMatrix8x8Flag[ i - 6 ] )*/
2017 /* }*/
2020 /* second_chroma_qp_index_offset 1 se(v)*/
2021 dissect_h264_exp_golomb_code(tree, pinfo, hf_h264_second_chroma_qp_index_offset, tvb, &bit_offset, H264_SE_V);
2023 dissect_h264_rbsp_trailing_bits(tree, tvb, pinfo, bit_offset);
2027 * 7.3.2.4 Access unit delimiter RBSP syntax
2028 * access_unit_delimiter_rbsp( )
2030 static void
2031 dissect_h264_access_unit_delimiter_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int offset)
2033 int bit_offset = offset << 3;
2034 /* primary_pic_type 6 u(3) */
2035 proto_tree_add_bits_item(tree, hf_h264_primary_pic_type, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
2036 bit_offset += 3;
2038 /* rbsp_trailing_bits( ) 6 */
2039 dissect_h264_rbsp_trailing_bits(tree, tvb, pinfo, bit_offset);
2043 * 7.3.2.5 End of sequence RBSP syntax
2044 * end_of_seq_rbsp( ) {}
2046 static void
2047 dissect_h264_end_of_seq_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int offset)
2049 proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, offset, -1);
2053 * 7.3.2.6 End of stream RBSP syntax
2054 * end_of_stream_rbsp( ) {}
2056 static void
2057 dissect_h264_end_of_stream_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int offset)
2059 proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, offset, -1);
2063 * 7.3.2.7 Filler data RBSP syntax
2064 * filler_data_rbsp( )
2066 static void
2067 dissect_h264_filler_data_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int offset)
2069 /* while (next_bits( 8 ) == 0xFF) */
2070 /* ff_byte * equal to 0xFF * 9 f(8) */
2071 /* rbsp_trailing_bits( ) 9 */
2072 proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, offset, -1);
2076 * 7.3.2.1.2 Sequence parameter set extension RBSP syntax
2077 * seq_parameter_set_extension_rbsp( )
2079 static void
2080 dissect_h264_seq_parameter_set_extension_rbsp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int offset)
2082 /* seq_parameter_set_id 10 ue(v) */
2083 /* aux_format_idc 10 ue(v) */
2084 /* if (aux_format_idc != 0 ) { */
2085 /* bit_depth_aux_minus8 10 ue(v) */
2086 /* alpha_incr_flag 10 u(1) */
2087 /* alpha_opaque_value 10 u(v) */
2088 /* alpha_transparent_value 10 u(v) */
2089 /* } */
2090 /* additional_extension_flag 10 u(1) */
2091 /* rbsp_trailing_bits() 10 */
2092 proto_tree_add_expert(tree, pinfo, &ei_h264_undecoded, tvb, offset, -1);
2095 /* RFC 6190 Section: 1.1.3 - NAL Unit Header Extension - H.264 Annex G*/
2096 static int
2097 dissect_h264_svc_nal_header_extension(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int offset)
2099 proto_tree_add_item(tree, hf_h264_nal_hdr_ext_svc, tvb, offset, 1, ENC_BIG_ENDIAN);
2100 proto_tree_add_item(tree, hf_h264_nal_hdr_ext_i, tvb, offset, 1, ENC_BIG_ENDIAN);
2101 proto_tree_add_item(tree, hf_h264_nal_hdr_ext_prid, tvb, offset, 1, ENC_BIG_ENDIAN);
2103 proto_tree_add_item(tree, hf_h264_nal_hdr_ext_n, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
2104 proto_tree_add_item(tree, hf_h264_nal_hdr_ext_did, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
2105 proto_tree_add_item(tree, hf_h264_nal_hdr_ext_qid, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
2107 proto_tree_add_item(tree, hf_h264_nal_hdr_ext_tid, tvb, offset + 2, 1, ENC_BIG_ENDIAN);
2108 proto_tree_add_item(tree, hf_h264_nal_hdr_ext_u, tvb, offset + 2, 1, ENC_BIG_ENDIAN);
2109 proto_tree_add_item(tree, hf_h264_nal_hdr_ext_d, tvb, offset + 2, 1, ENC_BIG_ENDIAN);
2110 proto_tree_add_item(tree, hf_h264_nal_hdr_ext_o, tvb, offset + 2, 1, ENC_BIG_ENDIAN);
2111 proto_tree_add_item(tree, hf_h264_nal_hdr_ext_rr, tvb, offset + 2, 1, ENC_BIG_ENDIAN);
2113 return offset + 3;
2115 /* H.264 Annex G Prefix NAL Unit */
2117 static int dissect_h264_prefix(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int offset)
2119 uint8_t svc_extension_flag;
2121 svc_extension_flag = tvb_get_bits8(tvb, offset << 3, 1);
2122 if (svc_extension_flag)
2124 /* Annex G NAL Unit Header SVC Extension */
2125 dissect_h264_svc_nal_header_extension (tree, tvb, pinfo, offset);
2127 else
2129 /* Annex H NAL Unit Header MVC Extension */
2130 /* Not Decoded */
2131 offset +=3;
2133 return offset;
2136 /* RFC 6190 Section: 4.9 - Payload Content Scalability Information (PACSI) */
2137 static void
2138 // NOLINTNEXTLINE(misc-no-recursion)
2139 dissect_h264_pacsi(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int offset)
2141 int8_t pacsi_flags;
2142 uint16_t nal_unit_size;
2143 tvbuff_t *nalu_tvb;
2144 bool error = false;
2145 bool contains_sei = false;
2147 offset = dissect_h264_svc_nal_header_extension(tree, tvb, pinfo, offset);
2149 pacsi_flags = tvb_get_uint8(tvb, offset);
2150 proto_tree_add_item(tree, hf_h264_pacsi_x, tvb, offset, 1, ENC_BIG_ENDIAN);
2151 proto_tree_add_item(tree, hf_h264_pacsi_y, tvb, offset, 1, ENC_BIG_ENDIAN);
2152 proto_tree_add_item(tree, hf_h264_pacsi_t, tvb, offset, 1, ENC_BIG_ENDIAN);
2153 proto_tree_add_item(tree, hf_h264_pacsi_a, tvb, offset, 1, ENC_BIG_ENDIAN);
2154 proto_tree_add_item(tree, hf_h264_pacsi_p, tvb, offset, 1, ENC_BIG_ENDIAN);
2155 proto_tree_add_item(tree, hf_h264_pacsi_c, tvb, offset, 1, ENC_BIG_ENDIAN);
2156 proto_tree_add_item(tree, hf_h264_pacsi_s, tvb, offset, 1, ENC_BIG_ENDIAN);
2157 proto_tree_add_item(tree, hf_h264_pacsi_e, tvb, offset, 1, ENC_BIG_ENDIAN);
2158 offset++;
2160 if (pacsi_flags & 0x40)
2162 proto_tree_add_item(tree, hf_h264_pacsi_tl0picidx, tvb, offset, 1, ENC_BIG_ENDIAN);
2163 offset++;
2164 proto_tree_add_item(tree, hf_h264_pacsi_idrpicid, tvb, offset, 2, ENC_BIG_ENDIAN);
2165 offset += 2;
2167 if (pacsi_flags & 0x20)
2169 proto_tree_add_item(tree, hf_h264_pacsi_donc, tvb, offset, 2, ENC_BIG_ENDIAN);
2170 offset += 2;
2172 if (tvb_reported_length_remaining(tvb, offset) > 0)
2174 contains_sei = true;
2175 col_append_str(pinfo->cinfo, COL_INFO, "(");
2178 /* Decode the SEI units that are in the packet. */
2179 while (tvb_reported_length_remaining(tvb, offset) > 0 && !error)
2181 nal_unit_size = tvb_get_ntohs(tvb, offset);
2182 proto_tree_add_item(tree, hf_h264_nalu_size, tvb, offset, 2, ENC_BIG_ENDIAN);
2183 offset += 2;
2185 if (nal_unit_size == 0 || nal_unit_size > tvb_reported_length_remaining(tvb, offset))
2187 proto_tree_add_expert(tree, pinfo, &ei_h264_bad_nal_length, tvb, offset-2, 2);
2188 error = true;
2190 else
2192 /* Make a new subset of the existing buffer for the NAL unit */
2193 nalu_tvb = tvb_new_subset_length_caplen(tvb, offset, tvb_captured_length_remaining(tvb,offset), nal_unit_size);
2194 /* Decode the NAL unit */
2195 dissect_h264(nalu_tvb, pinfo, tree, NULL);
2196 offset += nal_unit_size;
2199 if (contains_sei == true)
2201 col_append_str(pinfo->cinfo, COL_INFO, ")");
2206 * RFC 3984 Section 5.7.1 - Single-Time Aggregation Packet (STAP)
2208 static void
2209 // NOLINTNEXTLINE(misc-no-recursion)
2210 dissect_h264_stap(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int offset, int8_t nal_type)
2212 uint16_t nal_unit_size;
2213 tvbuff_t *nalu_tvb;
2214 proto_item *item;
2216 /* If it is a STAP-B then the Decoder Order Number if present before the NAL Units */
2217 if (nal_type == H264_STAP_B)
2219 proto_tree_add_item(tree, hf_h264_don, tvb, offset, 2, ENC_BIG_ENDIAN);
2220 offset += 2;
2223 while (tvb_reported_length_remaining(tvb, offset) > 0)
2225 /* Get the size of the NAL unit and display */
2226 proto_tree_add_item(tree, hf_h264_nalu_size, tvb, offset, 2, ENC_BIG_ENDIAN);
2227 nal_unit_size = tvb_get_ntohs(tvb, offset);
2228 offset += 2;
2230 /* Do a sanity check on the unit size versus what is left in the packet. */
2231 if (nal_unit_size == 0 || tvb_reported_length_remaining(tvb, offset) < nal_unit_size)
2233 /* Throw an exception if the size is wrong and don't try to decode the rest of the packet. */
2234 col_append_str(pinfo->cinfo, COL_INFO, " [Bad NAL Length]");
2235 item = proto_tree_add_expert (tree, pinfo, &ei_h264_bad_nal_length, tvb, offset-2, 2);
2236 proto_item_append_text(item, " Size of %d, Remaining %d",
2237 nal_unit_size, tvb_reported_length_remaining(tvb, offset));
2238 offset += tvb_reported_length_remaining(tvb, offset);
2240 else
2242 /* Make a new subset of the existing buffer for the NAL unit */
2243 nalu_tvb = tvb_new_subset_length_caplen(tvb, offset, tvb_captured_length_remaining(tvb, offset), nal_unit_size);
2244 /* Decode the NAL unit */
2245 dissect_h264(nalu_tvb, pinfo, tree, NULL);
2246 offset += nal_unit_size;
2252 * RFC 3984 Section 5.7.2 Multi-Time Aggregation Packet (MTAP)
2254 static void
2255 // NOLINTNEXTLINE(misc-no-recursion)
2256 dissect_h264_mtap(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int offset, int8_t nal_type)
2258 int size_offset;
2259 uint16_t nal_unit_size;
2260 tvbuff_t *nalu_tvb;
2261 proto_item *item;
2263 /* Get the DON base value for type MTAP16 & MTAP24 */
2264 proto_tree_add_item(tree, hf_h264_don, tvb, offset, 2, ENC_BIG_ENDIAN);
2265 offset += 2;
2267 while (tvb_reported_length_remaining(tvb, offset) > 0)
2269 proto_tree_add_item(tree, hf_h264_nalu_size, tvb, offset, 2, ENC_BIG_ENDIAN);
2270 nal_unit_size = tvb_get_ntohs(tvb, offset);
2271 size_offset = offset;
2272 offset += 2;
2273 proto_tree_add_item(tree, hf_h264_dond, tvb, offset, 1, ENC_BIG_ENDIAN);
2274 offset += 1;
2276 if (nal_type == H264_MTAP16)
2278 /* Get the 16 bit DOND value */
2279 proto_tree_add_item(tree, hf_h264_ts_offset16, tvb, offset, 2, ENC_BIG_ENDIAN);
2280 offset += 2;
2282 else
2284 /* Get the 24 bit DOND value */
2285 proto_tree_add_item(tree, hf_h264_ts_offset24, tvb, offset, 2, ENC_BIG_ENDIAN);
2286 offset += 3;
2289 if (nal_unit_size == 0 || tvb_reported_length_remaining(tvb, offset) < nal_unit_size)
2291 /* Throw an exception if the size is wrong and don't try to decode the rest of the packet. */
2292 col_append_str(pinfo->cinfo, COL_INFO, " [Bad NAL Length]");
2293 item = proto_tree_add_expert (tree, pinfo, &ei_h264_bad_nal_length, tvb, size_offset, 2);
2294 proto_item_append_text(item, " Size of %d, Remaining %d",
2295 nal_unit_size, tvb_reported_length_remaining(tvb, offset));
2296 offset += tvb_reported_length_remaining(tvb, offset);
2298 else
2300 /* Make a new subset of the existing buffer for the NAL unit */
2301 nalu_tvb = tvb_new_subset_length_caplen(tvb, offset, tvb_captured_length_remaining(tvb, offset), nal_unit_size);
2302 /* Decode the NAL unit */
2303 dissect_h264(nalu_tvb, pinfo, tree, NULL);
2304 offset += nal_unit_size;
2310 * Dissect NAL Header extension and NI-MTAP Subtype defined in RFC 6190
2312 static void
2313 // NOLINTNEXTLINE(misc-no-recursion)
2314 dissect_h264_nalu_extension (proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, int offset)
2316 int size_offset;
2317 uint16_t nal_unit_size;
2318 tvbuff_t *nalu_tvb;
2319 uint8_t subtype;
2320 uint8_t j_flag;
2321 uint8_t bit_offset = offset << 3;
2322 uint8_t unit = 1;
2323 proto_item *item;
2324 proto_tree *nimtap_tree;
2326 subtype = tvb_get_bits8(tvb, bit_offset, 5);
2327 j_flag = tvb_get_bits8(tvb, bit_offset+5, 1);
2329 /* NAL Header Extension Decoding */
2330 proto_tree_add_item(tree, hf_h264_nal_extension_subtype, tvb, offset, 1, ENC_BIG_ENDIAN);
2331 proto_tree_add_item(tree, hf_h264_nal_extension_j, tvb, offset, 1, ENC_NA);
2332 proto_tree_add_item(tree, hf_h264_nal_extension_k, tvb, offset, 1, ENC_NA);
2333 proto_tree_add_item(tree, hf_h264_nal_extension_l, tvb, offset, 1, ENC_NA);
2334 col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
2335 val_to_str(subtype, h264_subtype_summary_values, "Unknown Subtype (%u)"));
2336 offset++;
2338 if (subtype == 2)
2340 /* Multi-Time Aggregation Packet (NI-MTAP) - RFC 6190 Section 4.7.1 */
2341 while (tvb_reported_length_remaining(tvb, offset) > 0)
2343 nimtap_tree = proto_tree_add_subtree_format(tree, tvb, offset, 1, ett_h264_ni_mtap, NULL, "NI-MTAP Unit %d", unit++);
2344 proto_tree_add_item(nimtap_tree, hf_h264_nalu_size, tvb, offset, 2, ENC_BIG_ENDIAN);
2345 nal_unit_size = tvb_get_ntohs(tvb, offset);
2346 size_offset = offset;
2347 offset += 2;
2348 proto_tree_add_item(nimtap_tree, hf_h264_ts_offset16, tvb, offset, 2, ENC_BIG_ENDIAN);
2349 offset += 2;
2350 /* If J flag is set then DON is present in packet */
2351 if (j_flag)
2353 proto_tree_add_item(nimtap_tree, hf_h264_don, tvb, offset, 2, ENC_BIG_ENDIAN);
2354 offset += 2;
2356 if (nal_unit_size == 0 || tvb_reported_length_remaining(tvb, offset) < nal_unit_size)
2358 /* Throw an exception if the size is wrong and don't try to decode the rest of the packet. */
2359 col_append_str(pinfo->cinfo, COL_INFO, " [Bad NAL Length]");
2360 item = proto_tree_add_expert (nimtap_tree, pinfo, &ei_h264_bad_nal_length, tvb, size_offset, 2);
2361 proto_item_append_text(item, " Size of %d, Remaining %d",
2362 nal_unit_size, tvb_reported_length_remaining(tvb, offset));
2363 offset += tvb_reported_length_remaining(tvb, offset);
2365 else
2367 /* Make a new subset of the existing buffer for the NAL unit */
2368 nalu_tvb = tvb_new_subset_length_caplen(tvb, offset, tvb_captured_length_remaining(tvb, offset), nal_unit_size);
2369 /* Decode the NAL unit */
2370 dissect_h264(nalu_tvb, pinfo, nimtap_tree, NULL);
2371 offset += nal_unit_size;
2378 * Dissect NAL unit as received in sprop-parameter-sets of SDP
2379 * or "DecoderConfiguration parameter in H.245
2381 void
2382 dissect_h264_nal_unit(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
2384 proto_item *item, *nal_item;
2385 proto_tree *h264_nal_tree;
2386 int offset = 0;
2387 uint8_t nal_unit_type;
2388 uint32_t dword;
2390 item = proto_tree_add_item(tree, hf_h264_nal_unit, tvb, offset, -1, ENC_NA);
2391 h264_nal_tree = proto_item_add_subtree(item, ett_h264_nal_unit);
2393 startover:
2394 /* In decoder configuration start code may be pressent
2395 * B.1.1 Byte stream NAL unit syntax
2397 if (tvb_reported_length_remaining(tvb, offset<<3) >= 4) {
2398 dword = tvb_get_bits32(tvb, offset<<3, 32, ENC_BIG_ENDIAN);
2399 if (dword == 1) {
2400 /* zero_byte + start_code_prefix_one_3bytes */
2401 offset+=4;
2402 } else if ((dword >> 8) == 1) {
2403 /* start_code_prefix_one_3bytes */
2404 offset+= 3;
2407 /* Ref: 7.3.1 NAL unit syntax */
2408 nal_unit_type = tvb_get_uint8(tvb, offset) & 0x1f;
2410 /* forbidden_zero_bit All f(1) */
2411 proto_tree_add_item(h264_nal_tree, hf_h264_forbidden_zero_bit, tvb, offset, 1, ENC_BIG_ENDIAN);
2412 /* nal_ref_idc All u(2) */
2413 proto_tree_add_item(h264_nal_tree, hf_h264_nal_ref_idc, tvb, offset, 1, ENC_BIG_ENDIAN);
2414 /* nal_unit_type All u(5) */
2415 nal_item = proto_tree_add_item(h264_nal_tree, hf_h264_nal_unit_type, tvb, offset, 1, ENC_BIG_ENDIAN);
2416 offset++;
2418 switch (nal_unit_type) {
2419 case 1: /* Coded slice of a non-IDR picture */
2420 dissect_h264_slice_layer_without_partitioning_rbsp(h264_nal_tree, tvb, pinfo, offset);
2421 break;
2422 case 2: /* Coded slice data partition A */
2423 dissect_h264_slice_data_partition_a_layer_rbsp(h264_nal_tree, tvb, pinfo, offset);
2424 break;
2425 case 3: /* Coded slice data partition B */
2426 dissect_h264_slice_data_partition_b_layer_rbsp(h264_nal_tree, tvb, pinfo, offset);
2427 break;
2428 case 4: /* Coded slice data partition C */
2429 dissect_h264_slice_data_partition_c_layer_rbsp(h264_nal_tree, tvb, pinfo, offset);
2430 break;
2431 case 5: /* Coded slice of an IDR picture */
2432 dissect_h264_slice_layer_without_partitioning_rbsp(h264_nal_tree, tvb, pinfo, offset);
2433 break;
2434 case 6: /* Supplemental enhancement information (SEI) */
2435 dissect_h264_sei_rbsp(h264_nal_tree, tvb, pinfo, offset);
2436 break;
2437 case H264_SEQ_PAR_SET: /* 7 Sequence parameter set*/
2438 offset = dissect_h264_seq_parameter_set_rbsp(h264_nal_tree, tvb, pinfo, offset);
2439 /* A bit ugly */
2440 if ((offset != -1) && (tvb_reported_length_remaining(tvb, offset) > 0)) {
2441 /* In this case length = offset as we start from zero */
2442 proto_item_set_len(item, offset/*Length */);
2443 item = proto_tree_add_item(tree, hf_h264_nal_unit, tvb, offset, -1, ENC_NA);
2444 h264_nal_tree = proto_item_add_subtree(item, ett_h264_nal_unit);
2445 goto startover;
2447 break;
2448 case H264_PIC_PAR_SET: /* 8 Picture parameter set */
2449 dissect_h264_pic_parameter_set_rbsp(h264_nal_tree, tvb, pinfo, offset);
2450 break;
2451 case 9: /* Access unit delimiter */
2452 dissect_h264_access_unit_delimiter_rbsp(h264_nal_tree, tvb, pinfo, offset);
2453 break;
2454 case 10: /* End of sequence */
2455 dissect_h264_end_of_seq_rbsp(h264_nal_tree, tvb, pinfo, offset);
2456 break;
2457 case 11: /* End of stream */
2458 dissect_h264_end_of_stream_rbsp(h264_nal_tree, tvb, pinfo, offset);
2459 break;
2460 case 12: /* Filler data */
2461 dissect_h264_filler_data_rbsp(h264_nal_tree, tvb, pinfo, offset);
2462 break;
2463 case 13: /* Sequence parameter set extension */
2464 dissect_h264_seq_parameter_set_extension_rbsp(h264_nal_tree, tvb, pinfo, offset);
2465 break;
2466 case 14: /* Reserved */
2467 case 15: /* Reserved */
2468 case 16: /* Reserved */
2469 case 17: /* Reserved */
2470 case 18: /* Reserved */
2471 expert_add_info(pinfo, nal_item, &ei_h264_nal_unit_type_reserved);
2472 break;
2473 case 19: /* Coded slice of an auxiliary coded picture without partitioning */
2474 dissect_h264_slice_layer_without_partitioning_rbsp(tree, tvb, pinfo, offset);
2475 break;
2476 case 28:
2477 dissect_h264_slice_layer_without_partitioning_rbsp(tree, tvb, pinfo, offset);
2478 break;
2479 case 0: /* Unspecified */
2480 default:
2481 /* 24..31 Unspecified */
2482 expert_add_info(pinfo, nal_item, &ei_h264_nal_unit_type_unspecified);
2483 break;
2487 /* Annex B "Byte stream format" */
2488 static int
2489 dissect_h264_bytestream(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
2491 proto_tree *h264_tree;
2492 proto_item *item;
2494 tvbuff_t *next_tvb, *rbsp_tvb;
2495 int offset = 0, end_offset;
2496 uint32_t dword;
2498 /* Look for the first start word. Assume byte aligned. */
2499 while (1) {
2500 if (tvb_reported_length(tvb) < 4) {
2501 return 0;
2503 dword = tvb_get_uint32(tvb, offset, ENC_BIG_ENDIAN);
2504 if ((dword >> 8) == 1 || dword == 1) {
2505 break;
2506 } else if (dword != 0) {
2507 return 0;
2509 offset += 2;
2512 col_set_str(pinfo->cinfo, COL_PROTOCOL, "H.264");
2513 item = proto_tree_add_item(tree, proto_h264, tvb, 0, -1, ENC_NA);
2514 h264_tree = proto_item_add_subtree(item, ett_h264);
2516 while (tvb_reported_length_remaining(tvb, offset)) {
2517 dword = tvb_get_uint32(tvb, offset, ENC_BIG_ENDIAN);
2518 if ((dword >> 8) != 1) {
2519 /* zero_byte */
2520 offset++;
2522 /* start_code_prefix_one_3bytes */
2523 offset += 3;
2524 int nal_length = tvb_reported_length_remaining(tvb, offset);
2525 /* Search for either \0\0\1 or \0\0\0\1:
2526 * Find \0\0 and then check if \0\1 is in the next offset or
2527 * the one after that. (Note none of this throws exceptions.)
2529 end_offset = tvb_find_uint16(tvb, offset, -1, 0);
2530 while (end_offset != -1) {
2531 if (tvb_find_uint16(tvb, end_offset + 1, 3, 1) != -1) {
2532 nal_length = end_offset - offset;
2533 break;
2535 end_offset = tvb_find_uint16(tvb, end_offset + 1, -1, 0);
2538 /* If end_offset is -1, we got to the end; assume this is the end
2539 * of the NAL. To handle a bytestream that fragments NALs across
2540 * lower level packets (does any implementation do this?), we would
2541 * need to use epan/stream.h
2544 /* Unescape NAL unit */
2545 next_tvb = tvb_new_subset_length(tvb, offset, nal_length);
2546 rbsp_tvb = dissect_h265_unescap_nal_unit(next_tvb, pinfo, 0);
2548 dissect_h264_nal_unit(rbsp_tvb, pinfo, h264_tree);
2549 offset += nal_length;
2551 return tvb_reported_length(tvb);
2554 /* Code to actually dissect the packets */
2555 static int
2556 // NOLINTNEXTLINE(misc-no-recursion)
2557 dissect_h264(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
2559 int offset = 0;
2560 proto_item *item;
2561 proto_tree *h264_tree, *h264_nal_tree, *stream_tree, *fua_tree;
2562 uint8_t type;
2563 tvbuff_t *rbsp_tvb;
2566 /* Make entries in Protocol column and Info column on summary display */
2567 col_set_str(pinfo->cinfo, COL_PROTOCOL, "H.264");
2569 type = tvb_get_uint8(tvb, offset)&0x1f;
2571 col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
2572 val_to_str(type, h264_type_summary_values, "Unknown Type (%u)"));
2574 /* if (tree) */ {
2575 item = proto_tree_add_item(tree, proto_h264, tvb, 0, -1, ENC_NA);
2576 h264_tree = proto_item_add_subtree(item, ett_h264);
2578 /* if the type is 28, it would be draw another title */
2579 if (type == 28)
2580 h264_nal_tree = proto_tree_add_subtree(h264_tree, tvb, offset, 1, ett_h264_nal, NULL, "FU identifier");
2581 else
2582 h264_nal_tree = proto_tree_add_subtree(h264_tree, tvb, offset, 1, ett_h264_nal, NULL, "NAL unit header or first byte of the payload");
2584 /* +---------------+
2585 * |0|1|2|3|4|5|6|7|
2586 * +-+-+-+-+-+-+-+-+
2587 * |F|NRI| Type |
2588 * +---------------+
2591 /* F: 1 bit
2592 * forbidden_zero_bit. A value of 0 indicates that the NAL unit type
2593 * octet and payload should not contain bit errors or other syntax
2594 * violations. A value of 1 indicates that the NAL unit type octet
2595 * and payload may contain bit errors or other syntax violations.
2597 proto_tree_add_item(h264_nal_tree, hf_h264_nal_f_bit, tvb, offset, 1, ENC_BIG_ENDIAN);
2598 proto_tree_add_item(h264_nal_tree, hf_h264_nal_nri, tvb, offset, 1, ENC_BIG_ENDIAN);
2600 proto_tree_add_item(h264_nal_tree, hf_h264_type, tvb, offset, 1, ENC_BIG_ENDIAN);
2601 offset++;
2602 if (type == 28) {
2603 fua_tree = proto_tree_add_subtree(h264_tree, tvb, offset, 1, ett_h264_fua, NULL, "FU Header");
2604 proto_tree_add_item(fua_tree, hf_h264_start_bit, tvb, offset, 1, ENC_BIG_ENDIAN);
2605 proto_tree_add_item(fua_tree, hf_h264_end_bit, tvb, offset, 1, ENC_BIG_ENDIAN);
2606 proto_tree_add_item(fua_tree, hf_h264_forbidden_bit, tvb, offset, 1, ENC_BIG_ENDIAN);
2607 proto_tree_add_item(fua_tree, hf_h264_nal_unit_type, tvb, offset, 1, ENC_BIG_ENDIAN);
2608 if ((tvb_get_uint8(tvb, offset)&0x80) == 0x80) {
2609 type = tvb_get_uint8(tvb, offset)&0x1f;
2610 col_append_fstr(pinfo->cinfo, COL_INFO, " Start:%s",
2611 val_to_str(type, h264_type_summary_values, "Unknown Type (%u)"));
2612 offset++;
2614 else
2616 if ((tvb_get_uint8(tvb, offset)&0x40) == 0x40) {
2617 col_append_str(pinfo->cinfo, COL_INFO, " End");
2619 return offset;
2623 /* Unescape NAL unit */
2624 rbsp_tvb = dissect_h265_unescap_nal_unit(tvb, pinfo, offset);
2626 stream_tree = proto_tree_add_subtree(h264_tree, tvb, offset, -1, ett_h264_stream, NULL, "H264 NAL Unit Payload");
2627 increment_dissection_depth(pinfo);
2628 switch (type) {
2629 case 1: /* 1 Coded slice of a non-IDR picture */
2630 dissect_h264_slice_layer_without_partitioning_rbsp(stream_tree, rbsp_tvb, pinfo, 0);
2631 break;
2632 case 3: /* Coded slice data partition B */
2633 dissect_h264_slice_data_partition_b_layer_rbsp(stream_tree, rbsp_tvb, pinfo, 0);
2634 break;
2635 case 4: /* Coded slice data partition C */
2636 dissect_h264_slice_data_partition_c_layer_rbsp(stream_tree, rbsp_tvb, pinfo, 0);
2637 break;
2638 case 5: /* Coded slice of an IDR picture */
2639 dissect_h264_slice_layer_without_partitioning_rbsp(stream_tree, rbsp_tvb, pinfo, 0);
2640 break;
2641 case 6: /* Supplemental enhancement information (SEI) */
2642 dissect_h264_sei_rbsp(stream_tree, tvb, pinfo, offset);
2643 break;
2644 case H264_SEQ_PAR_SET: /* 7 Sequence parameter set*/
2645 dissect_h264_seq_parameter_set_rbsp(stream_tree, rbsp_tvb, pinfo, 0);
2646 break;
2647 case H264_PIC_PAR_SET: /* 8 Picture parameter set */
2648 dissect_h264_pic_parameter_set_rbsp(stream_tree, rbsp_tvb, pinfo, 0);
2649 break;
2650 case H264_PREFIX:
2651 dissect_h264_prefix(stream_tree, rbsp_tvb, pinfo, 0);
2652 break;
2653 case 19: /* Coded slice of an auxiliary coded picture without partitioning */
2654 dissect_h264_slice_layer_without_partitioning_rbsp(stream_tree, rbsp_tvb, pinfo, 0);
2655 break;
2656 case H264_STAP_A: /* STAP-A */
2657 case H264_STAP_B: /* STAP-B */
2658 dissect_h264_stap(stream_tree, tvb, pinfo, offset, type);
2659 break;
2660 case H264_MTAP16: /* MSTAP16 */
2661 case H264_MTAP24: /* MSTAP24 */
2662 dissect_h264_mtap(stream_tree, tvb, pinfo, offset, type);
2663 break;
2664 case H264_PACSI: /* PACSI */
2665 dissect_h264_pacsi(stream_tree, tvb, pinfo, offset);
2666 break;
2667 case H264_EXTENSION: /* Extension Header */
2668 dissect_h264_nalu_extension(stream_tree, rbsp_tvb, pinfo, 0);
2669 break;
2670 default:
2671 break;
2673 decrement_dissection_depth(pinfo);
2674 } /* if (tree) */
2675 return tvb_captured_length(tvb);
2679 /* Capability */
2681 static int * const profile_fields[] = {
2682 &hf_h264_par_profile_b,
2683 &hf_h264_par_profile_m,
2684 &hf_h264_par_profile_e,
2685 &hf_h264_par_profile_h,
2686 &hf_h264_par_profile_h10,
2687 &hf_h264_par_profile_h4_2_2,
2688 &hf_h264_par_profile_h4_4_4,
2689 NULL
2692 static int
2693 dissect_h264_par_profile(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
2695 int offset = 0;
2697 proto_tree_add_bitmask(tree, tvb, offset,
2698 hf_h264_par_profile, ett_h264_par_profile,
2699 profile_fields, ENC_BIG_ENDIAN);
2700 offset += 1;
2701 return offset;
2704 static int * const AdditionalModesSupported_fields[] = {
2705 &hf_h264_par_add_mode_sup_rcdo,
2706 NULL
2709 static int
2710 dissect_h264_par_AdditionalModesSupported(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
2712 int offset = 0;
2714 proto_tree_add_bitmask(tree, tvb, offset,
2715 hf_h264_par_AdditionalModesSupported, ett_h264_par_AdditionalModesSupported,
2716 AdditionalModesSupported_fields, ENC_BIG_ENDIAN);
2717 offset += 1;
2718 return offset;
2722 static int * const ProfileIOP_fields[] = {
2723 &hf_h264_par_constraint_set0_flag,
2724 &hf_h264_par_constraint_set1_flag,
2725 &hf_h264_par_constraint_set2_flag,
2726 NULL
2730 static int
2731 dissect_h264_ProfileIOP(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
2733 int offset = 0;
2735 proto_tree_add_bitmask(tree, tvb, offset,
2736 hf_h264_par_ProfileIOP, ett_h264_par_ProfileIOP,
2737 ProfileIOP_fields, ENC_BIG_ENDIAN);
2738 offset += 1;
2739 return offset;
2742 static const value_string h264_par_level_values[] = {
2743 { 15, "1" },
2744 { 19, "1b" },
2745 { 22, "1.1" },
2746 { 29, "1.2" },
2747 { 36, "1.3" },
2748 { 43, "2" },
2749 { 50, "2.1" },
2750 { 57, "2.2" },
2751 { 64, "3" },
2752 { 71, "3.1" },
2753 { 78, "3.2" },
2754 { 85, "4" },
2755 { 92, "4.1" },
2756 { 99, "4.2" },
2757 { 106, "5" },
2758 { 113 , "5.1" },
2759 { 0, NULL }
2762 static int
2763 dissect_h264_par_level(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree _U_, void *data)
2765 int offset = 0;
2766 uint16_t lvl;
2767 const char *p;
2768 asn1_ctx_t *actx;
2770 /* Reject the packet if data is NULL */
2771 if (data == NULL)
2772 return 0;
2773 actx = get_asn1_ctx(data);
2774 DISSECTOR_ASSERT(actx);
2776 lvl = tvb_get_ntohs(tvb, offset);
2777 p = try_val_to_str(lvl, VALS(h264_par_level_values));
2778 if (p) {
2779 proto_item_append_text(actx->created_item, " - Level %s", p);
2781 offset += 2;
2782 return offset;
2785 static int
2786 dissect_h264_par_DecoderConfigurationInformation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
2788 asn1_ctx_t *actx;
2790 /* Reject the packet if data is NULL */
2791 if (data == NULL)
2792 return 0;
2793 actx = get_asn1_ctx(data);
2794 DISSECTOR_ASSERT(actx);
2796 dissect_h264_nal_unit(tvb, pinfo, tree);
2798 return tvb_reported_length(tvb);
2801 typedef struct _h264_capability_t {
2802 const char *id;
2803 const char *name;
2804 dissector_t content_pdu;
2805 } h264_capability_t;
2807 static h264_capability_t h264_capability_tab[] = {
2808 /* ITU-T H.241 (05/2006), 8.3 H.264 capabilities */
2809 { "GenericCapability/0.0.8.241.0.0.1", "ITU-T Rec. H.241 H.264 Video Capabilities", NULL },
2810 { "GenericCapability/0.0.8.241.0.0.1/collapsing/41", "Profile", dissect_h264_par_profile },
2811 { "GenericCapability/0.0.8.241.0.0.1/collapsing/42", "Level", dissect_h264_par_level },
2812 { "GenericCapability/0.0.8.241.0.0.1/collapsing/3" , "CustomMaxMBPS", NULL },
2813 { "GenericCapability/0.0.8.241.0.0.1/collapsing/4" , "CustomMaxFS", NULL },
2814 { "GenericCapability/0.0.8.241.0.0.1/collapsing/5" , "CustomMaxDPB", NULL },
2815 { "GenericCapability/0.0.8.241.0.0.1/collapsing/6" , "CustomMaxBRandCPB", NULL },
2816 { "GenericCapability/0.0.8.241.0.0.1/collapsing/7" , "MaxStaticMBPS", NULL },
2817 { "GenericCapability/0.0.8.241.0.0.1/collapsing/8" , "max-rcmd-nal-unit-size", NULL },
2818 { "GenericCapability/0.0.8.241.0.0.1/collapsing/9" , "max-nal-unit-size", NULL },
2819 { "GenericCapability/0.0.8.241.0.0.1/collapsing/10", "SampleAspectRatiosSupported", NULL },
2820 { "GenericCapability/0.0.8.241.0.0.1/collapsing/11", "AdditionalModesSupported", dissect_h264_par_AdditionalModesSupported },
2821 { "GenericCapability/0.0.8.241.0.0.1/collapsing/12", "AdditionalDisplayCapabilities", NULL },
2822 /* TS 26.111 H.264 */
2823 { "GenericCapability/0.0.8.241.0.0.1/nonCollapsing/43" , "DecoderConfigurationInformation", dissect_h264_par_DecoderConfigurationInformation },
2824 { "GenericCapability/0.0.8.241.0.0.1/collapsing/44" , "AcceptRedundantSlices", NULL },
2825 { "GenericCapability/0.0.8.241.0.0.1/collapsing/45" , "NalAlignedMode", NULL },
2826 { "GenericCapability/0.0.8.241.0.0.1/collapsing/46" , "ProfileIOP", dissect_h264_ProfileIOP },
2827 { NULL, NULL, NULL },
2830 static h264_capability_t *find_cap(const char *id) {
2831 h264_capability_t *ftr = NULL;
2832 h264_capability_t *f;
2834 for (f=h264_capability_tab; f->id; f++) {
2835 if (!strcmp(id, f->id)) { ftr = f; break; }
2837 return ftr;
2840 static int
2841 dissect_h264_name(tvbuff_t *tvb _U_, packet_info *pinfo, proto_tree *tree, void* data)
2843 asn1_ctx_t *actx;
2845 /* Reject the packet if data is NULL */
2846 if (data == NULL)
2847 return 0;
2848 actx = get_asn1_ctx(data);
2849 DISSECTOR_ASSERT(actx);
2851 if (tree) {
2852 h264_capability_t *ftr;
2853 ftr = find_cap(pinfo->match_string);
2854 if (ftr) {
2855 proto_item_append_text(actx->created_item, " - %s", ftr->name);
2856 proto_item_append_text(proto_item_get_parent(proto_tree_get_parent(tree)), ": %s", ftr->name);
2857 } else {
2858 proto_item_append_text(actx->created_item, " - unknown(%s)", pinfo->match_string);
2862 return tvb_reported_length(tvb);
2866 void
2867 proto_register_h264(void)
2869 module_t *h264_module;
2870 expert_module_t* expert_h264;
2872 /* Setup list of header fields See Section 1.6.1 for details*/
2873 static hf_register_info hf[] = {
2874 { &hf_h264_nal_f_bit,
2875 { "F bit", "h264.f",
2876 FT_BOOLEAN, 8, TFS(&h264_f_bit_vals), 0x80,
2877 NULL, HFILL }
2879 { &hf_h264_nal_nri,
2880 { "Nal_ref_idc (NRI)", "h264.nal_nri",
2881 FT_UINT8, BASE_DEC, NULL, 0x60,
2882 NULL, HFILL }
2884 { &hf_h264_type,
2885 { "Type", "h264.nal_unit_hdr",
2886 FT_UINT8, BASE_DEC, VALS(h264_type_values), 0x1f,
2887 NULL, HFILL }
2889 { &hf_h264_start_bit,
2890 { "Start bit", "h264.start.bit",
2891 FT_BOOLEAN, 8, TFS(&h264_start_bit_vals), 0x80,
2892 NULL, HFILL }
2894 { &hf_h264_end_bit,
2895 { "End bit", "h264.end.bit",
2896 FT_BOOLEAN, 8, TFS(&h264_end_bit_vals), 0x40,
2897 NULL, HFILL }
2899 { &hf_h264_forbidden_bit,
2900 { "Forbidden bit", "h264.forbidden.bit",
2901 FT_UINT8, BASE_DEC, NULL, 0x20,
2902 NULL, HFILL }
2904 { &hf_h264_profile,
2905 { "Profile", "h264.profile",
2906 FT_BYTES, BASE_NONE, NULL, 0x0,
2907 NULL, HFILL }
2909 { &hf_h264_profile_idc,
2910 { "Profile_idc", "h264.profile_idc",
2911 FT_UINT8, BASE_DEC, VALS(h264_profile_idc_values), 0x0,
2912 NULL, HFILL }
2914 { &hf_h264_rbsp_stop_bit,
2915 { "rbsp_stop_bit", "h264.rbsp_stop_bit",
2916 FT_UINT8, BASE_DEC, NULL, 0x0,
2917 NULL, HFILL }
2919 { &hf_h264_rbsp_trailing_bits,
2920 { "rbsp_trailing_bits", "h264.rbsp_trailing_bits",
2921 FT_UINT8, BASE_DEC, NULL, 0x0,
2922 NULL, HFILL }
2924 { &hf_h264_constraint_set0_flag,
2925 { "Constraint_set0_flag", "h264.constraint_set0_flag",
2926 FT_UINT8, BASE_DEC, NULL, 0x80,
2927 NULL, HFILL }
2929 { &hf_h264_constraint_set1_flag,
2930 { "Constraint_set1_flag", "h264.constraint_set1_flag",
2931 FT_UINT8, BASE_DEC, NULL, 0x40,
2932 NULL, HFILL }
2934 { &hf_h264_constraint_set2_flag,
2935 { "Constraint_set2_flag", "h264.constraint_set2_flag",
2936 FT_UINT8, BASE_DEC, NULL, 0x20,
2937 NULL, HFILL }
2939 { &hf_h264_constraint_set3_flag,
2940 { "Constraint_set3_flag", "h264.constraint_set3_flag",
2941 FT_UINT8, BASE_DEC, NULL, 0x10,
2942 NULL, HFILL }
2944 { &hf_h264_constraint_set4_flag,
2945 { "Constraint_set4_flag", "h264.constraint_set4_flag",
2946 FT_UINT8, BASE_DEC, NULL, 0x08,
2947 NULL, HFILL }
2949 { &hf_h264_constraint_set5_flag,
2950 { "Constraint_set5_flag", "h264.constraint_set5_flag",
2951 FT_UINT8, BASE_DEC, NULL, 0x04,
2952 NULL, HFILL }
2954 { &hf_h264_reserved_zero_2bits,
2955 { "Reserved_zero_2bits", "h264.reserved_zero_2bits",
2956 FT_UINT8, BASE_DEC, NULL, 0x03,
2957 NULL, HFILL }
2959 { &hf_h264_level_idc,
2960 { "Level_id", "h264.level_id",
2961 FT_UINT8, BASE_DEC, NULL, 0x0,
2962 NULL, HFILL }
2964 { &hf_h264_nal_unit,
2965 { "NAL unit", "h264.nal_unit",
2966 FT_BYTES, BASE_NONE, NULL, 0x0,
2967 NULL, HFILL }
2969 { &hf_h264_forbidden_zero_bit,
2970 { "Forbidden_zero_bit", "h264.forbidden_zero_bit",
2971 FT_UINT8, BASE_DEC, NULL, 0x80,
2972 NULL, HFILL }
2974 { &hf_h264_nal_ref_idc,
2975 { "Nal_ref_idc", "h264.nal_ref_idc",
2976 FT_UINT8, BASE_DEC, NULL, 0x60,
2977 NULL, HFILL }
2979 {&hf_h264_nal_unit_type,
2980 { "Nal_unit_type", "h264.nal_unit_type",
2981 FT_UINT8, BASE_DEC, VALS(h264_nal_unit_type_vals), 0x1f,
2982 NULL, HFILL }
2984 { &hf_h264_seq_parameter_set_id,
2985 { "seq_parameter_set_id", "h264.seq_parameter_set_id",
2986 FT_UINT32, BASE_DEC, NULL, 0x0,
2987 NULL, HFILL }
2989 { &hf_h264_chroma_format_idc,
2990 { "chroma_format_id", "h264.chroma_format_id",
2991 FT_UINT32, BASE_DEC, NULL, 0x0,
2992 NULL, HFILL }
2994 { &hf_h264_residual_colour_transform_flag,
2995 { "residual_colour_transform_flag", "h264.residual_colour_transform_flag",
2996 FT_UINT8, BASE_DEC, NULL, 0x0,
2997 NULL, HFILL }
2999 { &hf_h264_bit_depth_luma_minus8,
3000 { "bit_depth_luma_minus8", "h264.bit_depth_luma_minus8",
3001 FT_UINT32, BASE_DEC, NULL, 0x0,
3002 NULL, HFILL }
3004 { &hf_h264_bit_depth_chroma_minus8,
3005 { "bit_depth_chroma_minus8", "h264.bit_depth_chroma_minus8",
3006 FT_UINT32, BASE_DEC, NULL, 0x0,
3007 NULL, HFILL }
3009 { &hf_h264_qpprime_y_zero_transform_bypass_flag,
3010 { "qpprime_y_zero_transform_bypass_flag", "h264.qpprime_y_zero_transform_bypass_flag",
3011 FT_UINT32, BASE_DEC, NULL, 0x0,
3012 NULL, HFILL }
3014 { &hf_h264_seq_scaling_matrix_present_flag,
3015 { "seq_scaling_matrix_present_flag", "h264.seq_scaling_matrix_present_flag",
3016 FT_UINT32, BASE_DEC, NULL, 0x0,
3017 NULL, HFILL }
3019 { &hf_h264_seq_scaling_list_present_flag,
3020 { "seq_scaling_list_present_flag", "h264.seq_scaling_list_present_flag",
3021 FT_UINT8, BASE_DEC, NULL, 0x0,
3022 NULL, HFILL }
3024 { &hf_h264_delta_scale,
3025 { "delta_scale", "h264.delta_scale",
3026 FT_INT32, BASE_DEC, NULL, 0x0,
3027 NULL, HFILL }
3029 { &hf_h264_log2_max_frame_num_minus4,
3030 { "log2_max_frame_num_minus4", "h264.log2_max_frame_num_minus4",
3031 FT_UINT32, BASE_DEC, NULL, 0x0,
3032 NULL, HFILL }
3034 { &hf_h264_pic_order_cnt_type,
3035 { "pic_order_cnt_type", "h264.pic_order_cnt_type",
3036 FT_UINT32, BASE_DEC, NULL, 0x0,
3037 NULL, HFILL }
3039 { &hf_h264_log2_max_pic_order_cnt_lsb_minus4,
3040 { "log2_max_pic_order_cnt_lsb_minus4", "h264.log2_max_pic_order_cnt_lsb_minus4",
3041 FT_UINT32, BASE_DEC, NULL, 0x0,
3042 NULL, HFILL }
3044 { &hf_h264_delta_pic_order_always_zero_flag,
3045 { "delta_pic_order_always_zero_flag", "h264.delta_pic_order_always_zero_flag",
3046 FT_UINT8, BASE_DEC, NULL, 0x0,
3047 NULL, HFILL }
3049 { &hf_h264_offset_for_non_ref_pic,
3050 { "offset_for_non_ref_pic", "h264.offset_for_non_ref_pic",
3051 FT_INT32, BASE_DEC, NULL, 0x0,
3052 NULL, HFILL }
3054 { &hf_h264_offset_for_top_to_bottom_field,
3055 { "offset_for_top_to_bottom_field", "h264.offset_for_top_to_bottom_field",
3056 FT_INT32, BASE_DEC, NULL, 0x0,
3057 NULL, HFILL }
3059 { &hf_h264_num_ref_frames_in_pic_order_cnt_cycle,
3060 { "num_ref_frames_in_pic_order_cnt_cycle", "h264.num_ref_frames_in_pic_order_cnt_cycle",
3061 FT_UINT32, BASE_DEC, NULL, 0x0,
3062 NULL, HFILL }
3064 { &hf_h264_offset_for_ref_frame,
3065 { "offset_for_ref_frame", "h264.offset_for_ref_frame",
3066 FT_INT32, BASE_DEC, NULL, 0x0,
3067 NULL, HFILL }
3069 { &hf_h264_num_ref_frames,
3070 { "num_ref_frames", "h264.num_ref_frames",
3071 FT_UINT32, BASE_DEC, NULL, 0x0,
3072 NULL, HFILL }
3074 { &hf_h264_gaps_in_frame_num_value_allowed_flag,
3075 { "gaps_in_frame_num_value_allowed_flag", "h264.gaps_in_frame_num_value_allowed_flag",
3076 FT_UINT8, BASE_DEC, NULL, 0x0,
3077 NULL, HFILL }
3079 { &hf_h264_pic_width_in_mbs_minus1,
3080 { "pic_width_in_mbs_minus1", "h264.pic_width_in_mbs_minus1",
3081 FT_UINT32, BASE_DEC, NULL, 0x0,
3082 NULL, HFILL }
3084 { &hf_h264_pic_height_in_map_units_minus1,
3085 { "pic_height_in_map_units_minus1", "h264.pic_height_in_map_units_minus1",
3086 FT_UINT32, BASE_DEC, NULL, 0x0,
3087 NULL, HFILL }
3089 { &hf_h264_frame_mbs_only_flag,
3090 { "frame_mbs_only_flag", "h264.frame_mbs_only_flag",
3091 FT_UINT8, BASE_DEC, NULL, 0x0,
3092 NULL, HFILL }
3094 { &hf_h264_mb_adaptive_frame_field_flag,
3095 { "mb_adaptive_frame_field_flag", "h264.mb_adaptive_frame_field_flag",
3096 FT_UINT8, BASE_DEC, NULL, 0x0,
3097 NULL, HFILL }
3099 { &hf_h264_direct_8x8_inference_flag,
3100 { "direct_8x8_inference_flag", "h264.direct_8x8_inference_flag",
3101 FT_UINT8, BASE_DEC, NULL, 0x0,
3102 NULL, HFILL }
3104 { &hf_h264_frame_cropping_flag,
3105 { "frame_cropping_flag", "h264.frame_cropping_flag",
3106 FT_UINT8, BASE_DEC, NULL, 0x0,
3107 NULL, HFILL }
3109 { &hf_h264_frame_crop_left_offset,
3110 { "frame_crop_left_offset", "h264.frame_crop_left_offset",
3111 FT_UINT32, BASE_DEC, NULL, 0x0,
3112 NULL, HFILL }
3114 { &hf_h264_frame_crop_right_offset,
3115 { "frame_crop_right_offset", "h264.frame_crop_right_offset",
3116 FT_UINT32, BASE_DEC, NULL, 0x0,
3117 NULL, HFILL }
3119 { &hf_h264_frame_crop_top_offset,
3120 { "frame_crop_top_offset", "h264.frame_crop_top_offset",
3121 FT_UINT32, BASE_DEC, NULL, 0x0,
3122 NULL, HFILL }
3124 { &hf_h264_frame_crop_bottom_offset,
3125 { "frame_crop_bottom_offset", "h264.frame_crop_bottom_offset",
3126 FT_UINT32, BASE_DEC, NULL, 0x0,
3127 NULL, HFILL }
3129 { &hf_h264_vui_parameters_present_flag,
3130 { "vui_parameters_present_flag", "h264.vui_parameters_present_flag",
3131 FT_UINT8, BASE_DEC, NULL, 0x0,
3132 NULL, HFILL }
3134 { &hf_h264_pic_parameter_set_id,
3135 { "pic_parameter_set_id", "h264.pic_parameter_set_id",
3136 FT_UINT32, BASE_DEC, NULL, 0x0,
3137 NULL, HFILL }
3139 { &hf_h264_entropy_coding_mode_flag,
3140 { "entropy_coding_mode_flag", "h264.entropy_coding_mode_flag",
3141 FT_UINT8, BASE_DEC, NULL, 0x0,
3142 NULL, HFILL }
3144 { &hf_h264_pic_order_present_flag,
3145 { "pic_order_present_flag", "h264.pic_order_present_flag",
3146 FT_UINT8, BASE_DEC, NULL, 0x0,
3147 NULL, HFILL }
3149 { &hf_h264_num_slice_groups_minus1,
3150 { "num_slice_groups_minus1", "h264.num_slice_groups_minus1",
3151 FT_UINT32, BASE_DEC, NULL, 0x0,
3152 NULL, HFILL }
3154 { &hf_h264_slice_group_map_type,
3155 { "slice_group_map_type", "h264.slice_group_map_type",
3156 FT_UINT32, BASE_DEC, VALS(h264_slice_group_map_type_vals), 0x0,
3157 NULL, HFILL }
3159 { &hf_h264_num_ref_idx_l0_active_minus1,
3160 { "num_ref_idx_l0_active_minus1", "h264.num_ref_idx_l0_active_minus1",
3161 FT_UINT32, BASE_DEC, NULL, 0x0,
3162 NULL, HFILL }
3164 { &hf_h264_num_ref_idx_l1_active_minus1,
3165 { "num_ref_idx_l1_active_minus1", "h264.num_ref_idx_l1_active_minus1",
3166 FT_UINT32, BASE_DEC, NULL, 0x0,
3167 NULL, HFILL }
3169 { &hf_h264_weighted_pred_flag,
3170 { "weighted_pred_flag", "h264.weighted_pred_flag",
3171 FT_UINT8, BASE_DEC, NULL, 0x0,
3172 NULL, HFILL }
3174 { &hf_h264_weighted_bipred_idc,
3175 { "weighted_bipred_idc", "h264.weighted_bipred_idc",
3176 FT_UINT8, BASE_DEC, NULL, 0x0,
3177 NULL, HFILL }
3179 { &hf_h264_pic_init_qp_minus26,
3180 { "pic_init_qp_minus26", "h264.pic_init_qp_minus26",
3181 FT_INT32, BASE_DEC, NULL, 0x0,
3182 NULL, HFILL }
3184 { &hf_h264_pic_init_qs_minus26,
3185 { "pic_init_qs_minus26", "h264.pic_init_qs_minus26",
3186 FT_INT32, BASE_DEC, NULL, 0x0,
3187 NULL, HFILL }
3189 { &hf_h264_chroma_qp_index_offset,
3190 { "chroma_qp_index_offset", "h264.chroma_qp_index_offset",
3191 FT_INT32, BASE_DEC, NULL, 0x0,
3192 NULL, HFILL }
3194 { &hf_h264_deblocking_filter_control_present_flag,
3195 { "deblocking_filter_control_present_flag", "h264.deblocking_filter_control_present_flag",
3196 FT_UINT8, BASE_DEC, NULL, 0x0,
3197 NULL, HFILL }
3199 { &hf_h264_constrained_intra_pred_flag,
3200 { "constrained_intra_pred_flag", "h264.constrained_intra_pred_flag",
3201 FT_UINT8, BASE_DEC, NULL, 0x0,
3202 NULL, HFILL }
3204 { &hf_h264_redundant_pic_cnt_present_flag,
3205 { "redundant_pic_cnt_present_flag", "h264.redundant_pic_cnt_present_flag",
3206 FT_UINT8, BASE_DEC, NULL, 0x0,
3207 NULL, HFILL }
3209 { &hf_h264_transform_8x8_mode_flag,
3210 { "transform_8x8_mode_flag", "h264.transform_8x8_mode_flag",
3211 FT_UINT8, BASE_DEC, NULL, 0x0,
3212 NULL, HFILL }
3214 { &hf_h264_pic_scaling_matrix_present_flag,
3215 { "pic_scaling_matrix_present_flag", "h264.pic_scaling_matrix_present_flag",
3216 FT_UINT8, BASE_DEC, NULL, 0x0,
3217 NULL, HFILL }
3219 { &hf_h264_second_chroma_qp_index_offset,
3220 { "second_chroma_qp_index_offset", "h264.second_chroma_qp_index_offset",
3221 FT_INT32, BASE_DEC, NULL, 0x0,
3222 NULL, HFILL }
3225 { &hf_h264_primary_pic_type,
3226 { "primary_pic_type", "h264.primary_pic_type",
3227 FT_INT8, BASE_DEC, VALS(h264_primary_pic_type_vals), 0x0,
3228 "slice_type values that may be present in the primary coded picture", HFILL }
3231 { &hf_h264_aspect_ratio_info_present_flag,
3232 { "aspect_ratio_info_present_flag", "h264.aspect_ratio_info_present_flag",
3233 FT_UINT8, BASE_DEC, NULL, 0x0,
3234 NULL, HFILL }
3236 { &hf_h264_aspect_ratio_idc,
3237 { "aspect_ratio_idc", "h264.aspect_ratio_idc",
3238 FT_UINT8, BASE_DEC, NULL, 0x0,
3239 NULL, HFILL }
3241 { &hf_h264_sar_width,
3242 { "sar_width", "h264.sar_width",
3243 FT_UINT16, BASE_DEC, NULL, 0x0,
3244 NULL, HFILL }
3246 { &hf_h264_sar_height,
3247 { "sar_height", "h264.sar_height",
3248 FT_UINT16, BASE_DEC, NULL, 0x0,
3249 NULL, HFILL }
3251 { &hf_h264_overscan_info_present_flag,
3252 { "overscan_info_present_flag", "h264.overscan_info_present_flag",
3253 FT_UINT8, BASE_DEC, NULL, 0x0,
3254 NULL, HFILL }
3256 { &hf_h264_overscan_appropriate_flag,
3257 { "overscan_appropriate_flag", "h264.overscan_appropriate_flag",
3258 FT_UINT8, BASE_DEC, NULL, 0x0,
3259 NULL, HFILL }
3261 { &hf_h264_video_signal_type_present_flag,
3262 { "video_signal_type_present_flag", "h264.video_signal_type_present_flag",
3263 FT_UINT8, BASE_DEC, NULL, 0x0,
3264 NULL, HFILL }
3266 { &hf_h264_video_format,
3267 { "video_format", "h264.video_format",
3268 FT_UINT8, BASE_DEC, VALS(h264_video_format_vals), 0x0,
3269 NULL, HFILL }
3271 { &hf_h264_video_full_range_flag,
3272 { "video_full_range_flag", "h264.video_full_range_flag",
3273 FT_UINT8, BASE_DEC, NULL, 0x0,
3274 NULL, HFILL }
3276 { &hf_h264_colour_description_present_flag,
3277 { "colour_description_present_flag", "h264.colour_description_present_flag",
3278 FT_UINT8, BASE_DEC, NULL, 0x0,
3279 NULL, HFILL }
3281 { &hf_h264_colour_primaries,
3282 { "colour_primaries", "h264.colour_primaries",
3283 FT_UINT8, BASE_DEC, NULL, 0x0,
3284 NULL, HFILL }
3286 { &hf_h264_transfer_characteristics,
3287 { "transfer_characteristics", "h264.transfer_characteristics",
3288 FT_UINT8, BASE_DEC, NULL, 0x0,
3289 NULL, HFILL }
3291 { &hf_h264_matrix_coefficients,
3292 { "matrix_coefficients", "h264.matrix_coefficients",
3293 FT_UINT8, BASE_DEC, NULL, 0x0,
3294 NULL, HFILL }
3296 { &hf_h264_chroma_loc_info_present_flag,
3297 { "chroma_loc_info_present_flag", "h264.chroma_loc_info_present_flag",
3298 FT_UINT8, BASE_DEC, NULL, 0x0,
3299 NULL, HFILL }
3301 { &hf_h264_chroma_sample_loc_type_top_field,
3302 { "chroma_sample_loc_type_top_field", "h264.chroma_sample_loc_type_top_field",
3303 FT_UINT32, BASE_DEC, NULL, 0x0,
3304 NULL, HFILL }
3306 { &hf_h264_chroma_sample_loc_type_bottom_field,
3307 { "chroma_sample_loc_type_bottom_field", "h264.chroma_sample_loc_type_bottom_field",
3308 FT_UINT32, BASE_DEC, NULL, 0x0,
3309 NULL, HFILL }
3311 { &hf_h264_timing_info_present_flag,
3312 { "timing_info_present_flag", "h264.timing_info_present_flag",
3313 FT_UINT8, BASE_DEC, NULL, 0x0,
3314 NULL, HFILL }
3316 { &hf_h264_num_units_in_tick,
3317 { "num_units_in_tick", "h264.num_units_in_tick",
3318 FT_UINT32, BASE_DEC, NULL, 0x0,
3319 NULL, HFILL }
3321 { &hf_h264_time_scale,
3322 { "time_scale", "h264.time_scale",
3323 FT_UINT32, BASE_DEC, NULL, 0x0,
3324 NULL, HFILL }
3326 { &hf_h264_fixed_frame_rate_flag,
3327 { "fixed_frame_rate_flag", "h264.fixed_frame_rate_flag",
3328 FT_UINT8, BASE_DEC, NULL, 0x0,
3329 NULL, HFILL }
3331 { &hf_h264_nal_hrd_parameters_present_flag,
3332 { "nal_hrd_parameters_present_flag", "h264.nal_hrd_parameters_present_flag",
3333 FT_UINT8, BASE_DEC, NULL, 0x0,
3334 NULL, HFILL }
3336 { &hf_h264_vcl_hrd_parameters_present_flag,
3337 { "vcl_hrd_parameters_present_flag", "h264.vcl_hrd_parameters_present_flag",
3338 FT_UINT8, BASE_DEC, NULL, 0x0,
3339 NULL, HFILL }
3341 { &hf_h264_low_delay_hrd_flag,
3342 { "low_delay_hrd_flag", "h264.low_delay_hrd_flag",
3343 FT_UINT8, BASE_DEC, NULL, 0x0,
3344 NULL, HFILL }
3346 { &hf_h264_pic_struct_present_flag,
3347 { "pic_struct_present_flag", "h264.pic_struct_present_flag",
3348 FT_UINT8, BASE_DEC, NULL, 0x0,
3349 NULL, HFILL }
3351 { &hf_h264_bitstream_restriction_flag,
3352 { "bitstream_restriction_flag", "h264.bitstream_restriction_flag",
3353 FT_UINT8, BASE_DEC, NULL, 0x0,
3354 NULL, HFILL }
3356 { &hf_h264_motion_vectors_over_pic_boundaries_flag,
3357 { "motion_vectors_over_pic_boundaries_flag", "h264.motion_vectors_over_pic_boundaries_flag",
3358 FT_UINT32, BASE_DEC, NULL, 0x0,
3359 NULL, HFILL }
3361 { &hf_h264_max_bytes_per_pic_denom,
3362 { "max_bytes_per_pic_denom", "h264.max_bytes_per_pic_denom",
3363 FT_UINT32, BASE_DEC, NULL, 0x0,
3364 NULL, HFILL }
3366 { &hf_h264_max_bits_per_mb_denom,
3367 { "max_bits_per_mb_denom", "h264.max_bits_per_mb_denom",
3368 FT_UINT32, BASE_DEC, NULL, 0x0,
3369 NULL, HFILL }
3371 { &hf_h264_log2_max_mv_length_horizontal,
3372 { "max_mv_length_horizontal", "h264.max_mv_length_horizontal",
3373 FT_UINT32, BASE_DEC, NULL, 0x0,
3374 NULL, HFILL }
3376 { &hf_h264_log2_max_mv_length_vertical,
3377 { "log2_max_mv_length_vertical", "h264.log2_max_mv_length_vertical",
3378 FT_UINT32, BASE_DEC, NULL, 0x0,
3379 NULL, HFILL }
3381 { &hf_h264_num_reorder_frames,
3382 { "num_reorder_frames", "h264.num_reorder_frames",
3383 FT_UINT32, BASE_DEC, NULL, 0x0,
3384 NULL, HFILL }
3386 { &hf_h264_max_dec_frame_buffering,
3387 { "max_dec_frame_buffering", "h264.max_dec_frame_buffering",
3388 FT_UINT32, BASE_DEC, NULL, 0x0,
3389 NULL, HFILL }
3391 { &hf_h264_cpb_cnt_minus1,
3392 { "cpb_cnt_minus1", "h264.cpb_cnt_minus1",
3393 FT_UINT32, BASE_DEC, NULL, 0x0,
3394 NULL, HFILL }
3396 { &hf_h264_bit_rate_scale,
3397 { "bit_rate_scale", "h264.bit_rate_scale",
3398 FT_UINT8, BASE_DEC, NULL, 0x0,
3399 NULL, HFILL }
3401 { &hf_h264_cpb_size_scale,
3402 { "cpb_size_scale", "h264.cpb_size_scale",
3403 FT_UINT8, BASE_DEC, NULL, 0x0,
3404 NULL, HFILL }
3406 { &hf_h264_bit_rate_value_minus1,
3407 { "bit_rate_value_minus1", "h264.bit_rate_value_minus1",
3408 FT_UINT32, BASE_DEC, NULL, 0x0,
3409 NULL, HFILL }
3411 { &hf_h264_cpb_size_value_minus1,
3412 { "cpb_size_value_minus1", "h264.cpb_size_value_minus1",
3413 FT_UINT32, BASE_DEC, NULL, 0x0,
3414 NULL, HFILL }
3416 { &hf_h264_cbr_flag,
3417 { "cbr_flag", "h264.cbr_flag",
3418 FT_UINT8, BASE_DEC, NULL, 0x0,
3419 NULL, HFILL }
3421 { &hf_h264_initial_cpb_removal_delay_length_minus1,
3422 { "initial_cpb_removal_delay_length_minus1", "h264.initial_cpb_removal_delay_length_minus1",
3423 FT_UINT8, BASE_DEC, NULL, 0x0,
3424 NULL, HFILL }
3426 { &hf_h264_cpb_removal_delay_length_minus1,
3427 { "cpb_removal_delay_length_minus1", "h264.cpb_removal_delay_length_minus1",
3428 FT_UINT8, BASE_DEC, NULL, 0x0,
3429 NULL, HFILL }
3431 { &hf_h264_dpb_output_delay_length_minus11,
3432 { "dpb_output_delay_length_minus11", "h264.dpb_output_delay_length_minus11",
3433 FT_UINT8, BASE_DEC, NULL, 0x0,
3434 NULL, HFILL }
3436 { &hf_h264_time_offset_length,
3437 { "time_offset_length", "h264.time_offset_length",
3438 FT_UINT8, BASE_DEC, NULL, 0x0,
3439 NULL, HFILL }
3441 { &hf_h264_first_mb_in_slice,
3442 { "first_mb_in_slice", "h264.first_mb_in_slice",
3443 FT_UINT32, BASE_DEC, NULL, 0x0,
3444 NULL, HFILL }
3446 { &hf_h264_slice_type,
3447 { "slice_type", "h264.slice_type",
3448 FT_UINT32, BASE_DEC, VALS(h264_slice_type_vals), 0x0,
3449 NULL, HFILL }
3451 { &hf_h264_slice_id,
3452 { "slice_id", "h264.slice_id",
3453 FT_UINT32, BASE_DEC, NULL, 0x0,
3454 NULL, HFILL }
3456 { &hf_h264_payloadsize,
3457 { "PayloadSize", "h264.payloadsize",
3458 FT_UINT32, BASE_DEC, NULL, 0x0,
3459 NULL, HFILL }
3461 { &hf_h264_payloadtype,
3462 { "payloadType", "h264.payloadtype",
3463 FT_UINT32, BASE_DEC, VALS(h264_sei_payload_vals), 0x0,
3464 NULL, HFILL }
3466 #if 0
3467 { &hf_h264_frame_num,
3468 { "frame_num", "h264.frame_num",
3469 FT_UINT8, BASE_DEC, NULL, 0x0,
3470 NULL, HFILL }
3472 #endif
3473 { &hf_h264_par_profile,
3474 { "Profile", "h264.par_profile",
3475 FT_UINT8, BASE_HEX, NULL, 0x00,
3476 NULL, HFILL}},
3477 { &hf_h264_par_profile_b,
3478 { "Baseline Profile", "h264.par_profile.base",
3479 FT_BOOLEAN, 8, NULL, 0x40,
3480 NULL, HFILL}},
3481 { &hf_h264_par_profile_m,
3482 { "Main Profile", "h264.par_profile.main",
3483 FT_BOOLEAN, 8, NULL, 0x20,
3484 NULL, HFILL}},
3485 { &hf_h264_par_profile_e,
3486 { "Extended Profile.", "h264.par_profile.ext",
3487 FT_BOOLEAN, 8, NULL, 0x10,
3488 NULL, HFILL}},
3489 { &hf_h264_par_profile_h,
3490 { "High Profile", "h264.par_profile.high",
3491 FT_BOOLEAN, 8, NULL, 0x08,
3492 NULL, HFILL}},
3493 { &hf_h264_par_profile_h10,
3494 { "High 10 Profile", "h264.par_profile.high10",
3495 FT_BOOLEAN, 8, NULL, 0x04,
3496 NULL, HFILL}},
3497 { &hf_h264_par_profile_h4_2_2,
3498 { "High 4:2:2 Profile", "h264.par_profile.high4_2_2",
3499 FT_BOOLEAN, 8, NULL, 0x02,
3500 NULL, HFILL}},
3501 { &hf_h264_par_profile_h4_4_4,
3502 { "High 4:4:4 Profile", "h264.par_profile.high4_4_4",
3503 FT_BOOLEAN, 8, NULL, 0x01,
3504 NULL, HFILL}},
3505 { &hf_h264_par_AdditionalModesSupported,
3506 { "AdditionalModesSupported", "h264.AdditionalModesSupported",
3507 FT_UINT8, BASE_HEX, NULL, 0x00,
3508 NULL, HFILL}},
3509 #if 0
3510 { &hf_h264_par_add_mode_sup,
3511 { "Additional Modes Supported", "h264.add_mode_sup",
3512 FT_UINT8, BASE_HEX, NULL, 0x00,
3513 NULL, HFILL}},
3514 #endif
3515 { &hf_h264_par_add_mode_sup_rcdo,
3516 { "Reduced Complexity Decoding Operation (RCDO) support", "h264.add_mode_sup.rcdo",
3517 FT_BOOLEAN, 8, NULL, 0x40,
3518 NULL, HFILL}},
3519 { &hf_h264_par_ProfileIOP,
3520 { "ProfileIOP", "h264.ProfileIOP",
3521 FT_UINT8, BASE_HEX, NULL, 0x00,
3522 NULL, HFILL}},
3523 { &hf_h264_par_constraint_set0_flag,
3524 { "constraint_set0_flag", "h264.par.constraint_set0_flag",
3525 FT_BOOLEAN, 8, NULL, 0x80,
3526 NULL, HFILL}},
3527 { &hf_h264_par_constraint_set1_flag,
3528 { "constraint_set1_flag", "h264.par.constraint_set1_flag",
3529 FT_BOOLEAN, 8, NULL, 0x40,
3530 NULL, HFILL}},
3531 { &hf_h264_par_constraint_set2_flag,
3532 { "constraint_set2_flag", "h264.par.constraint_set2_flag",
3533 FT_BOOLEAN, 8, NULL, 0x20,
3534 NULL, HFILL}},
3535 /* Packization Values */
3536 { &hf_h264_nalu_size,
3537 { "NAL Unit Size", "h264.nalu_size",
3538 FT_UINT16, BASE_DEC, NULL, 0x0,
3539 NULL, HFILL }
3541 { &hf_h264_don,
3542 { "Decoder Order Number", "h264.don",
3543 FT_UINT16, BASE_DEC, NULL, 0x0,
3544 NULL, HFILL }
3546 { &hf_h264_dond,
3547 { "MTAP Decoder Order Number Delta", "h264.don_delta",
3548 FT_UINT8, BASE_DEC, NULL, 0x0,
3549 NULL, HFILL }
3551 { &hf_h264_ts_offset16,
3552 { "MTAP TS Offset", "h264.ts_offset16",
3553 FT_UINT16, BASE_DEC, NULL, 0x0,
3554 NULL, HFILL }
3556 { &hf_h264_ts_offset24,
3557 { "MTAP TS Offset", "h264.ts_offset24",
3558 FT_UINT24, BASE_DEC, NULL, 0x0,
3559 NULL, HFILL }
3561 { &hf_h264_nal_extension_subtype,
3562 { "Extension Header Subtype", "h264.nal_hdr_extension.subtype",
3563 FT_UINT8, BASE_DEC, VALS(h264_subtype_values), 0xF8,
3564 NULL, HFILL }
3566 { &hf_h264_nal_extension_j,
3567 { "Extension Header J - DON Present Indicator", "h264.nal_hdr_extension.j",
3568 FT_BOOLEAN, 8, NULL, 0x4,
3569 NULL, HFILL }
3571 { &hf_h264_nal_extension_k,
3572 { "Extension Header K", "h264.nal_hdr_extension.k",
3573 FT_BOOLEAN, 8, NULL, 0x2,
3574 NULL, HFILL }
3576 { &hf_h264_nal_extension_l,
3577 { "Extension Header L", "h264.nal_hdr_extension.l",
3578 FT_BOOLEAN, 8, NULL, 0x1,
3579 NULL, HFILL }
3582 /* SEI Parsing values */
3583 { &hf_h264_sei_uuid,
3584 { "UUID", "h264.sei.uuid",
3585 FT_GUID, BASE_NONE, NULL, 0x0,
3586 NULL, HFILL }
3588 { &hf_h264_sei_ms_lpb,
3589 { "Layer Presence", "h264.sei.ms.layout.lpb",
3590 FT_UINT8, BASE_HEX, NULL, 0x0,
3591 NULL, HFILL }
3593 { &hf_h264_sei_ms_layout_p,
3594 { "Layer Description Present", "h264.sei.ms.layout.p",
3595 FT_BOOLEAN, 8, NULL, 0x01,
3596 NULL, HFILL }
3598 { &hf_h264_sei_ms_layout_ldsize,
3599 { "Layer Description Size", "h264.sei.ms.layout.desc.ldsize",
3600 FT_UINT8, BASE_DEC, NULL, 0x0,
3601 NULL, HFILL }
3603 { &hf_h264_sei_ms_layer_desc_coded_width,
3604 { "Coded Width", "h264.sei.ms.layout.desc.coded_width",
3605 FT_UINT16, BASE_DEC, NULL, 0x0,
3606 NULL, HFILL }
3608 { &hf_h264_sei_ms_layer_desc_coded_height,
3609 { "Coded Height", "h264.sei.ms.layout.desc.coded_height",
3610 FT_UINT16, BASE_DEC, NULL, 0x0,
3611 NULL, HFILL }
3613 { &hf_h264_sei_ms_layer_desc_display_width,
3614 { "Display Width", "h264.sei.ms.layout.desc.display_width",
3615 FT_UINT16, BASE_DEC, NULL, 0x0,
3616 NULL, HFILL }
3618 { &hf_h264_sei_ms_layer_desc_display_height,
3619 { "Display Height", "h264.sei.ms.layout.desc.display_height",
3620 FT_UINT16, BASE_DEC, NULL, 0x0,
3621 NULL, HFILL }
3623 { &hf_h264_sei_ms_layer_desc_bitrate,
3624 { "Bitrate", "h264.sei.ms.layout.desc.bitrate",
3625 FT_UINT32, BASE_DEC, NULL, 0x0,
3626 NULL, HFILL }
3628 { &hf_h264_sei_ms_layer_desc_frame_rate,
3629 { "Frame Rate Index", "h264.sei.ms.layout.desc.frame_rate",
3630 FT_UINT8, BASE_DEC, VALS(h264_sei_ms_frame_values), 0xF8,
3631 NULL, HFILL }
3633 { &hf_h264_sei_ms_layer_desc_layer_type,
3634 { "Layer Type", "h264.sei.ms.layout.desc.layer_type",
3635 FT_UINT8, BASE_DEC, NULL, 0x07,
3636 NULL, HFILL }
3638 { &hf_h264_sei_ms_layer_desc_prid,
3639 { "Priority ID", "h264.sei.ms.layout.desc.prid",
3640 FT_UINT8, BASE_DEC, NULL, 0xFC,
3641 NULL, HFILL }
3643 { &hf_h264_sei_ms_layer_desc_cb,
3644 { "Constrained Baseline", "h264.sei.ms.layout.desc.constrained_baseline",
3645 FT_BOOLEAN, 8, NULL, 0x02,
3646 NULL, HFILL }
3648 /* MS Bitstream SEI */
3649 { &hf_h264_sei_ms_bitstream_ref_frame_cnt,
3650 { "Reference Frame Count", "h264.sei.ms.bitstream_info.ref_frm_cnt",
3651 FT_UINT8, BASE_DEC, NULL, 0x0,
3652 NULL, HFILL }
3654 { &hf_h264_sei_ms_bitstream_num_nalus,
3655 { "Number of NAL units", "h264.sei.ms.bitstrea3416m_info.num_nalus",
3656 FT_UINT8, BASE_DEC, NULL, 0x0,
3657 NULL, HFILL }
3659 { &hf_h264_sei_iso_sec_info,
3660 { "Unparsed iso_iec information", "h264.sei.iso_sec_info",
3661 FT_BYTES, BASE_NONE, NULL, 0x0,
3662 NULL, HFILL }
3664 /* MS Crop SEI */
3665 { &hf_h264_sei_ms_crop_num_data,
3666 { "Number of Data Entries", "h264.sei.ms.crop.num_data",
3667 FT_UINT8, BASE_DEC, NULL, 0x0,
3668 NULL, HFILL }
3670 { &hf_h264_sei_ms_crop_info_type,
3671 { "Info Type", "h264.sei.ms.crop.info_type",
3672 FT_UINT8, BASE_DEC, NULL, 0x0,
3673 NULL, HFILL }
3675 { &hf_h264_sei_ms_crop_confidence_level,
3676 { "Confidence Level", "h264.sei.ms.crop.confidence_level",
3677 FT_UINT8, BASE_DEC, NULL, 0x0,
3678 NULL, HFILL }
3680 { &hf_h264_sei_ms_crop_frame_left_offset,
3681 { "Left Offset", "h264.sei.ms.crop.left_offset",
3682 FT_UINT16, BASE_DEC, NULL, 0x0,
3683 NULL, HFILL }
3685 { &hf_h264_sei_ms_crop_frame_right_offset,
3686 { "Right Offset", "h264.sei.ms.crop.right_offset",
3687 FT_UINT16, BASE_DEC, NULL, 0x0,
3688 NULL, HFILL }
3690 { &hf_h264_sei_ms_crop_frame_top_offset,
3691 { "Top Offset", "h264.sei.ms.crop.top_offset",
3692 FT_UINT16, BASE_DEC, NULL, 0x0,
3693 NULL, HFILL }
3695 { &hf_h264_sei_ms_crop_frame_bottom_offset,
3696 { "Bottom Offset", "h264.sei.ms.crop.bottom_offset",
3697 FT_UINT16, BASE_DEC, NULL, 0x0,
3698 NULL, HFILL }
3700 /* NALU Header Extension */
3701 /* Annex G NAL Unit Header SVC Extension */
3702 { &hf_h264_nal_hdr_ext_svc,
3703 { "SVC Extension / Reserved", "h264.nal_hdr_ext.r",
3704 FT_BOOLEAN, 8, NULL, 0x80,
3705 NULL, HFILL }
3707 { &hf_h264_nal_hdr_ext_i,
3708 { "IDR Picture", "h264.nal_hdr_ext.i",
3709 FT_BOOLEAN, 8, NULL, 0x40,
3710 NULL, HFILL }
3712 { &hf_h264_nal_hdr_ext_prid,
3713 { "Priority ID", "h264.nal_hdr_ext.prid",
3714 FT_UINT8, BASE_DEC, NULL, 0x3f,
3715 NULL, HFILL }
3717 { &hf_h264_nal_hdr_ext_n,
3718 { "No Inter Layer Prediction", "h264.nal_hdr_ext.n",
3719 FT_BOOLEAN, 8, NULL, 0x80,
3720 NULL, HFILL }
3722 { &hf_h264_nal_hdr_ext_did,
3723 { "Dependency ID", "h264.nal_hdr_ext.did",
3724 FT_UINT8, BASE_DEC, NULL, 0x70,
3725 NULL, HFILL }
3727 { &hf_h264_nal_hdr_ext_qid,
3728 { "Quality ID", "h264.nal_hdr_ext.qid",
3729 FT_UINT8, BASE_DEC, NULL, 0x0f,
3730 NULL, HFILL }
3732 { &hf_h264_nal_hdr_ext_tid,
3733 { "Temporal ID", "h264.nal_hdr_ext.tid",
3734 FT_UINT8, BASE_DEC, NULL, 0xe0,
3735 NULL, HFILL }
3737 { &hf_h264_nal_hdr_ext_u,
3738 { "Use Ref Base Picture", "h264.nal_hdr_ext.u",
3739 FT_BOOLEAN, 8, NULL, 0x10,
3740 NULL, HFILL }
3742 { &hf_h264_nal_hdr_ext_d,
3743 { "Discardable", "h264.nal_hdr_ext.d",
3744 FT_BOOLEAN, 8, NULL, 0x08,
3745 NULL, HFILL }
3747 { &hf_h264_nal_hdr_ext_o,
3748 { "Output", "h264.nal_hdr_ext.o",
3749 FT_BOOLEAN, 8, NULL, 0x04,
3750 NULL, HFILL }
3752 { &hf_h264_nal_hdr_ext_rr,
3753 { "Reserved", "h264.nal_hdr_ext.rr",
3754 FT_UINT8, BASE_HEX, NULL, 0x03,
3755 NULL, HFILL }
3757 /* PACSI Values */
3758 { &hf_h264_pacsi_x,
3759 { "X - A,P,C Field Indicator", "h264.pacsi.x",
3760 FT_BOOLEAN, 8, NULL, 0x80,
3761 NULL, HFILL }
3763 { &hf_h264_pacsi_y,
3764 { "Y - Pic Fields Indicator", "h264.pacsi.y",
3765 FT_BOOLEAN, 8, NULL, 0x40,
3766 NULL, HFILL }
3768 { &hf_h264_pacsi_t,
3769 { "T - DONC Field Indicator", "h264.pacsi.t",
3770 FT_BOOLEAN, 8, NULL, 0x20,
3771 NULL, HFILL }
3773 { &hf_h264_pacsi_a,
3774 { "A - Anchor Layer", "h264.pacsi.a",
3775 FT_BOOLEAN, 8, NULL, 0x10,
3776 NULL, HFILL }
3778 { &hf_h264_pacsi_p,
3779 { "P - Redundant Slice", "h264.pacsi.p",
3780 FT_BOOLEAN, 8, NULL, 0x08,
3781 NULL, HFILL }
3783 { &hf_h264_pacsi_c,
3784 { "C - Intra Slice", "h264.pacsi.c",
3785 FT_BOOLEAN, 8, NULL, 0x04,
3786 NULL, HFILL }
3788 { &hf_h264_pacsi_s,
3789 { "S - First Nal Unit of Layer", "h264.pacsi.s",
3790 FT_BOOLEAN, 8, NULL, 0x02,
3791 NULL, HFILL }
3793 { &hf_h264_pacsi_e,
3794 { "E - Last Nal Unit of Layer", "h264.pacsi.e",
3795 FT_BOOLEAN, 8, NULL, 0x01,
3796 NULL, HFILL }
3798 { &hf_h264_pacsi_tl0picidx,
3799 { "TL0PICIDX", "h264.pacsi.tl0picidx",
3800 FT_UINT8, BASE_DEC, NULL, 0x0,
3801 NULL, HFILL }
3803 { &hf_h264_pacsi_idrpicid,
3804 { "IDRPICID - IDR Picture ID", "h264.pacsi.idrpicid",
3805 FT_UINT16, BASE_DEC, NULL, 0x0,
3806 NULL, HFILL }
3808 { &hf_h264_pacsi_donc,
3809 { "DONC - Cross Session Decoder Order Number", "h264.pacsi.donc",
3810 FT_UINT16, BASE_DEC, NULL, 0x0,
3811 NULL, HFILL }
3816 /* Setup protocol subtree array */
3817 static int *ett[] = {
3818 &ett_h264,
3819 &ett_h264_profile,
3820 &ett_h264_nal,
3821 &ett_h264_fua,
3822 &ett_h264_stream,
3823 &ett_h264_nal_unit,
3824 &ett_h264_par_profile,
3825 &ett_h264_par_AdditionalModesSupported,
3826 &ett_h264_par_ProfileIOP,
3827 &ett_h264_ms_layer_description,
3828 &ett_h264_ms_crop_data,
3829 &ett_h264_ni_mtap
3832 static ei_register_info ei[] = {
3833 { &ei_h264_undecoded, { "h264.undecoded", PI_UNDECODED, PI_WARN, "[Not decoded yet]", EXPFILL }},
3834 { &ei_h264_ms_layout_wrong_length, { "h264.ms_layout.wrong_length", PI_PROTOCOL, PI_WARN, "[Wrong Layer Description Table Length]", EXPFILL }},
3835 { &ei_h264_oversized_exp_golomb_code, {"h264.oversized_exp_golomb_code", PI_MALFORMED, PI_ERROR, "Exponential Golomb encoded value greater than 32 bit integer, clamped", EXPFILL }},
3836 { &ei_h264_bad_nal_length, { "h264.bad_nalu_length", PI_MALFORMED, PI_ERROR, "[Bad NAL Unit Length]", EXPFILL }},
3837 { &ei_h264_nal_unit_type_reserved, { "h264.nal_unit_type.reserved", PI_PROTOCOL, PI_WARN, "Reserved NAL unit type", EXPFILL }},
3838 { &ei_h264_nal_unit_type_unspecified, { "h264.nal_unit_type.unspecified", PI_PROTOCOL, PI_WARN, "Unspecified NAL unit type", EXPFILL }},
3841 /* Register the protocol name and description */
3842 proto_h264 = proto_register_protocol("H.264", "H.264", "h264");
3844 /* Required function calls to register the header fields and subtrees used */
3845 proto_register_field_array(proto_h264, hf, array_length(hf));
3846 proto_register_subtree_array(ett, array_length(ett));
3847 expert_h264 = expert_register_protocol(proto_h264);
3848 expert_register_field_array(expert_h264, ei, array_length(ei));
3849 /* Register a configuration option for port */
3852 h264_module = prefs_register_protocol(proto_h264, NULL);
3854 prefs_register_obsolete_preference(h264_module, "dynamic.payload.type");
3856 h264_handle = register_dissector("h264", dissect_h264, proto_h264);
3857 register_dissector_with_description("h264_bytestream", "H.264 Annex B Byte stream format", dissect_h264_bytestream, proto_h264);
3861 /* Register the protocol with Wireshark */
3862 void
3863 proto_reg_handoff_h264(void)
3865 h264_capability_t *ftr;
3867 dissector_add_string("rtp_dyn_payload_type","H264", h264_handle);
3868 dissector_add_string("rtp_dyn_payload_type","H264-SVC", h264_handle);
3869 dissector_add_string("rtp_dyn_payload_type","X-H264UC", h264_handle);
3871 h264_name_handle = create_dissector_handle(dissect_h264_name, proto_h264);
3872 for (ftr=h264_capability_tab; ftr->id; ftr++) {
3873 if (ftr->name)
3874 dissector_add_string("h245.gef.name", ftr->id, h264_name_handle);
3875 if (ftr->content_pdu)
3876 dissector_add_string("h245.gef.content", ftr->id, create_dissector_handle(ftr->content_pdu, proto_h264));
3879 dissector_add_uint_range_with_preference("rtp.pt", "", h264_handle);
3884 * Editor modelines - https://www.wireshark.org/tools/modelines.html
3886 * Local variables:
3887 * c-basic-offset: 4
3888 * tab-width: 8
3889 * indent-tabs-mode: nil
3890 * End:
3892 * vi: set shiftwidth=4 tabstop=8 expandtab:
3893 * :indentSize=4:tabSize=8:noTabs=true: