Coverage Report

Created: 2026-09-28 06:52

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