Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-mpeg-pes.c
blob125c170f5d64c7539cb3499667a2138bdc1e3b04
1 /* Do not modify this file. Changes will be overwritten. */
2 /* Generated automatically by the ASN.1 to Wireshark dissector compiler */
3 /* packet-mpeg-pes.c */
4 /* asn2wrs.py -q -L -p mpeg-pes -c ./mpeg-pes.cnf -s ./packet-mpeg-pes-template -D . -O ../.. mpeg-pes.asn */
6 /* MPEG Packetized Elementary Stream (PES) packet decoder.
7 * Written by Shaun Jackman <sjackman@gmail.com>.
8 * Copyright 2007 Shaun Jackman
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include "config.h"
19 #include <epan/packet.h>
20 #include <epan/asn1.h>
21 #include <epan/expert.h>
22 #include <epan/tap.h>
23 #include <epan/addr_resolv.h>
24 #include <epan/follow.h>
26 #include <wsutil/array.h>
28 #include <wiretap/wtap.h>
30 #include "packet-per.h"
31 #include "packet-mp2t.h"
32 #include "packet-udp.h"
34 static int hf_mpeg_pes_prefix; /* OCTET_STRING_SIZE_3 */
35 static int hf_mpeg_pes_stream; /* T_stream */
36 static int hf_mpeg_pes_length; /* INTEGER_0_65535 */
37 static int hf_mpeg_pes_must_be_one; /* BOOLEAN */
38 static int hf_mpeg_pes_stream_must_be_zero; /* BOOLEAN */
39 static int hf_mpeg_pes_scrambling_control; /* T_scrambling_control */
40 static int hf_mpeg_pes_priority; /* BOOLEAN */
41 static int hf_mpeg_pes_data_alignment; /* BOOLEAN */
42 static int hf_mpeg_pes_copyright; /* BOOLEAN */
43 static int hf_mpeg_pes_original; /* BOOLEAN */
44 static int hf_mpeg_pes_pts_flag; /* BOOLEAN */
45 static int hf_mpeg_pes_dts_flag; /* BOOLEAN */
46 static int hf_mpeg_pes_escr_flag; /* BOOLEAN */
47 static int hf_mpeg_pes_es_rate_flag; /* BOOLEAN */
48 static int hf_mpeg_pes_dsm_trick_mode_flag; /* BOOLEAN */
49 static int hf_mpeg_pes_additional_copy_info_flag; /* BOOLEAN */
50 static int hf_mpeg_pes_crc_flag; /* BOOLEAN */
51 static int hf_mpeg_pes_extension_flag; /* BOOLEAN */
52 static int hf_mpeg_pes_header_data_length; /* INTEGER_0_255 */
53 static int hf_mpeg_pes_horizontal_size; /* BIT_STRING_SIZE_12 */
54 static int hf_mpeg_pes_vertical_size; /* BIT_STRING_SIZE_12 */
55 static int hf_mpeg_pes_aspect_ratio; /* T_aspect_ratio */
56 static int hf_mpeg_pes_frame_rate; /* T_frame_rate */
57 static int hf_mpeg_pes_bit_rate; /* BIT_STRING_SIZE_18 */
58 static int hf_mpeg_pes_vbv_buffer_size; /* BIT_STRING_SIZE_10 */
59 static int hf_mpeg_pes_constrained_parameters_flag; /* BOOLEAN */
60 static int hf_mpeg_pes_load_intra_quantiser_matrix; /* BOOLEAN */
61 static int hf_mpeg_pes_load_non_intra_quantiser_matrix; /* BOOLEAN */
62 static int hf_mpeg_pes_must_be_0001; /* BIT_STRING_SIZE_4 */
63 static int hf_mpeg_pes_profile_and_level; /* INTEGER_0_255 */
64 static int hf_mpeg_pes_progressive_sequence; /* BOOLEAN */
65 static int hf_mpeg_pes_chroma_format; /* INTEGER_0_3 */
66 static int hf_mpeg_pes_horizontal_size_extension; /* INTEGER_0_3 */
67 static int hf_mpeg_pes_vertical_size_extension; /* INTEGER_0_3 */
68 static int hf_mpeg_pes_bit_rate_extension; /* BIT_STRING_SIZE_12 */
69 static int hf_mpeg_pes_vbv_buffer_size_extension; /* INTEGER_0_255 */
70 static int hf_mpeg_pes_low_delay; /* BOOLEAN */
71 static int hf_mpeg_pes_frame_rate_extension_n; /* INTEGER_0_3 */
72 static int hf_mpeg_pes_frame_rate_extension_d; /* INTEGER_0_3 */
73 static int hf_mpeg_pes_drop_frame_flag; /* BOOLEAN */
74 static int hf_mpeg_pes_hour; /* INTEGER_0_32 */
75 static int hf_mpeg_pes_minute; /* INTEGER_0_64 */
76 static int hf_mpeg_pes_second; /* INTEGER_0_64 */
77 static int hf_mpeg_pes_frame; /* INTEGER_0_64 */
78 static int hf_mpeg_pes_closed_gop; /* BOOLEAN */
79 static int hf_mpeg_pes_broken_gop; /* BOOLEAN */
80 static int hf_mpeg_pes_must_be_zero; /* BIT_STRING_SIZE_5 */
81 static int hf_mpeg_pes_temporal_sequence_number; /* BIT_STRING_SIZE_10 */
82 static int hf_mpeg_pes_frame_type; /* T_frame_type */
83 static int hf_mpeg_pes_vbv_delay; /* BIT_STRING_SIZE_16 */
84 static int ett_mpeg_pes_PES;
85 static int ett_mpeg_pes_Stream;
86 static int ett_mpeg_pes_Sequence_header;
87 static int ett_mpeg_pes_Sequence_extension;
88 static int ett_mpeg_pes_Group_of_pictures;
89 static int ett_mpeg_pes_Picture;
92 static int
93 dissect_mpeg_pes_OCTET_STRING_SIZE_3(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
94 offset = dissect_per_octet_string(tvb, offset, actx, tree, hf_index,
95 3, 3, false, NULL);
97 return offset;
101 static const value_string mpeg_pes_T_stream_vals[] = {
102 { 0, "picture" },
103 { 179, "sequence-header" },
104 { 181, "sequence-header-extension" },
105 { 184, "group-of-pictures" },
106 { 185, "program-end" },
107 { 186, "pack-header" },
108 { 187, "system-header" },
109 { 188, "program-stream-map" },
110 { 189, "private-stream-1" },
111 { 190, "padding-stream" },
112 { 191, "private-stream-2" },
113 { 192, "audio-stream" },
114 { 193, "audio-stream-1" },
115 { 194, "audio-stream-2" },
116 { 195, "audio-stream-3" },
117 { 196, "audio-stream-4" },
118 { 197, "audio-stream-5" },
119 { 198, "audio-stream-6" },
120 { 199, "audio-stream-7" },
121 { 200, "audio-stream-8" },
122 { 201, "audio-stream-9" },
123 { 202, "audio-stream-10" },
124 { 203, "audio-stream-11" },
125 { 204, "audio-stream-12" },
126 { 205, "audio-stream-13" },
127 { 206, "audio-stream-14" },
128 { 207, "audio-stream-15" },
129 { 208, "audio-stream-16" },
130 { 209, "audio-stream-17" },
131 { 210, "audio-stream-18" },
132 { 211, "audio-stream-19" },
133 { 212, "audio-stream-20" },
134 { 213, "audio-stream-21" },
135 { 214, "audio-stream-22" },
136 { 215, "audio-stream-23" },
137 { 216, "audio-stream-24" },
138 { 217, "audio-stream-25" },
139 { 218, "audio-stream-26" },
140 { 219, "audio-stream-27" },
141 { 220, "audio-stream-28" },
142 { 221, "audio-stream-29" },
143 { 222, "audio-stream-30" },
144 { 223, "audio-stream-31" },
145 { 224, "video-stream" },
146 { 225, "video-stream-1" },
147 { 226, "video-stream-2" },
148 { 227, "video-stream-3" },
149 { 228, "video-stream-4" },
150 { 229, "video-stream-5" },
151 { 230, "video-stream-6" },
152 { 231, "video-stream-7" },
153 { 232, "video-stream-8" },
154 { 233, "video-stream-9" },
155 { 234, "video-stream-10" },
156 { 235, "video-stream-11" },
157 { 236, "video-stream-12" },
158 { 237, "video-stream-13" },
159 { 238, "video-stream-14" },
160 { 239, "video-stream-15" },
161 { 0, NULL }
165 static int
166 dissect_mpeg_pes_T_stream(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
167 offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
168 0U, 255U, NULL, false);
170 return offset;
174 static const per_sequence_t PES_sequence[] = {
175 { &hf_mpeg_pes_prefix , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_OCTET_STRING_SIZE_3 },
176 { &hf_mpeg_pes_stream , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_T_stream },
177 { NULL, 0, 0, NULL }
180 static int
181 dissect_mpeg_pes_PES(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
182 offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
183 ett_mpeg_pes_PES, PES_sequence);
185 return offset;
190 static int
191 dissect_mpeg_pes_INTEGER_0_65535(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
192 offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
193 0U, 65535U, NULL, false);
195 return offset;
200 static int
201 dissect_mpeg_pes_BOOLEAN(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
202 offset = dissect_per_boolean(tvb, offset, actx, tree, hf_index, NULL);
204 return offset;
208 static const value_string mpeg_pes_T_scrambling_control_vals[] = {
209 { 0, "not-scrambled" },
210 { 0, NULL }
214 static int
215 dissect_mpeg_pes_T_scrambling_control(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
216 offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
217 0U, 3U, NULL, false);
219 return offset;
224 static int
225 dissect_mpeg_pes_INTEGER_0_255(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
226 offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
227 0U, 255U, NULL, false);
229 return offset;
233 static const per_sequence_t Stream_sequence[] = {
234 { &hf_mpeg_pes_length , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_65535 },
235 { &hf_mpeg_pes_must_be_one, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
236 { &hf_mpeg_pes_stream_must_be_zero, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
237 { &hf_mpeg_pes_scrambling_control, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_T_scrambling_control },
238 { &hf_mpeg_pes_priority , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
239 { &hf_mpeg_pes_data_alignment, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
240 { &hf_mpeg_pes_copyright , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
241 { &hf_mpeg_pes_original , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
242 { &hf_mpeg_pes_pts_flag , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
243 { &hf_mpeg_pes_dts_flag , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
244 { &hf_mpeg_pes_escr_flag , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
245 { &hf_mpeg_pes_es_rate_flag, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
246 { &hf_mpeg_pes_dsm_trick_mode_flag, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
247 { &hf_mpeg_pes_additional_copy_info_flag, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
248 { &hf_mpeg_pes_crc_flag , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
249 { &hf_mpeg_pes_extension_flag, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
250 { &hf_mpeg_pes_header_data_length, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_255 },
251 { NULL, 0, 0, NULL }
254 static int
255 dissect_mpeg_pes_Stream(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
256 offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
257 ett_mpeg_pes_Stream, Stream_sequence);
259 return offset;
264 static int
265 dissect_mpeg_pes_BIT_STRING_SIZE_12(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
266 offset = dissect_per_bit_string(tvb, offset, actx, tree, hf_index,
267 12, 12, false, NULL, 0, NULL, NULL);
269 return offset;
273 static const value_string mpeg_pes_T_aspect_ratio_vals[] = {
274 { 1, "aspect-1to1" },
275 { 2, "aspect-4to3" },
276 { 3, "aspect-16to9" },
277 { 4, "aspect-2-21to1" },
278 { 0, NULL }
282 static int
283 dissect_mpeg_pes_T_aspect_ratio(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
284 offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
285 0U, 15U, NULL, false);
287 return offset;
291 static const value_string mpeg_pes_T_frame_rate_vals[] = {
292 { 0, "reserved" },
293 { 23976, "fr" },
294 { 24000, "fr" },
295 { 25000, "fr" },
296 { 29970, "fr" },
297 { 30000, "fr" },
298 { 50000, "fr" },
299 { 59940, "fr" },
300 { 60000, "fr" },
301 { 0, NULL }
304 static uint32_t T_frame_rate_value_map[9+0] = {0, 23976, 24000, 25000, 29970, 30000, 50000, 59940, 60000};
306 static int
307 dissect_mpeg_pes_T_frame_rate(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
308 offset = dissect_per_enumerated(tvb, offset, actx, tree, hf_index,
309 9, NULL, false, 0, T_frame_rate_value_map);
311 return offset;
316 static int
317 dissect_mpeg_pes_BIT_STRING_SIZE_18(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
318 offset = dissect_per_bit_string(tvb, offset, actx, tree, hf_index,
319 18, 18, false, NULL, 0, NULL, NULL);
321 return offset;
326 static int
327 dissect_mpeg_pes_BIT_STRING_SIZE_10(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
328 offset = dissect_per_bit_string(tvb, offset, actx, tree, hf_index,
329 10, 10, false, NULL, 0, NULL, NULL);
331 return offset;
335 static const per_sequence_t Sequence_header_sequence[] = {
336 { &hf_mpeg_pes_horizontal_size, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_12 },
337 { &hf_mpeg_pes_vertical_size, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_12 },
338 { &hf_mpeg_pes_aspect_ratio, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_T_aspect_ratio },
339 { &hf_mpeg_pes_frame_rate , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_T_frame_rate },
340 { &hf_mpeg_pes_bit_rate , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_18 },
341 { &hf_mpeg_pes_must_be_one, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
342 { &hf_mpeg_pes_vbv_buffer_size, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_10 },
343 { &hf_mpeg_pes_constrained_parameters_flag, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
344 { &hf_mpeg_pes_load_intra_quantiser_matrix, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
345 { &hf_mpeg_pes_load_non_intra_quantiser_matrix, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
346 { NULL, 0, 0, NULL }
349 static int
350 dissect_mpeg_pes_Sequence_header(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
351 offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
352 ett_mpeg_pes_Sequence_header, Sequence_header_sequence);
354 return offset;
359 static int
360 dissect_mpeg_pes_BIT_STRING_SIZE_4(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
361 offset = dissect_per_bit_string(tvb, offset, actx, tree, hf_index,
362 4, 4, false, NULL, 0, NULL, NULL);
364 return offset;
369 static int
370 dissect_mpeg_pes_INTEGER_0_3(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
371 offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
372 0U, 3U, NULL, false);
374 return offset;
378 static const per_sequence_t Sequence_extension_sequence[] = {
379 { &hf_mpeg_pes_must_be_0001, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_4 },
380 { &hf_mpeg_pes_profile_and_level, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_255 },
381 { &hf_mpeg_pes_progressive_sequence, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
382 { &hf_mpeg_pes_chroma_format, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_3 },
383 { &hf_mpeg_pes_horizontal_size_extension, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_3 },
384 { &hf_mpeg_pes_vertical_size_extension, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_3 },
385 { &hf_mpeg_pes_bit_rate_extension, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_12 },
386 { &hf_mpeg_pes_must_be_one, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
387 { &hf_mpeg_pes_vbv_buffer_size_extension, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_255 },
388 { &hf_mpeg_pes_low_delay , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
389 { &hf_mpeg_pes_frame_rate_extension_n, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_3 },
390 { &hf_mpeg_pes_frame_rate_extension_d, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_3 },
391 { NULL, 0, 0, NULL }
394 static int
395 dissect_mpeg_pes_Sequence_extension(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
396 offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
397 ett_mpeg_pes_Sequence_extension, Sequence_extension_sequence);
399 return offset;
404 static int
405 dissect_mpeg_pes_INTEGER_0_32(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
406 offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
407 0U, 32U, NULL, false);
409 return offset;
414 static int
415 dissect_mpeg_pes_INTEGER_0_64(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
416 offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
417 0U, 64U, NULL, false);
419 return offset;
424 static int
425 dissect_mpeg_pes_BIT_STRING_SIZE_5(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
426 offset = dissect_per_bit_string(tvb, offset, actx, tree, hf_index,
427 5, 5, false, NULL, 0, NULL, NULL);
429 return offset;
433 static const per_sequence_t Group_of_pictures_sequence[] = {
434 { &hf_mpeg_pes_drop_frame_flag, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
435 { &hf_mpeg_pes_hour , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_32 },
436 { &hf_mpeg_pes_minute , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_64 },
437 { &hf_mpeg_pes_must_be_one, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
438 { &hf_mpeg_pes_second , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_64 },
439 { &hf_mpeg_pes_frame , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_64 },
440 { &hf_mpeg_pes_closed_gop , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
441 { &hf_mpeg_pes_broken_gop , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
442 { &hf_mpeg_pes_must_be_zero, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_5 },
443 { NULL, 0, 0, NULL }
446 static int
447 dissect_mpeg_pes_Group_of_pictures(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
448 offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
449 ett_mpeg_pes_Group_of_pictures, Group_of_pictures_sequence);
451 return offset;
455 static const value_string mpeg_pes_T_frame_type_vals[] = {
456 { 1, "i-frame" },
457 { 2, "p-frame" },
458 { 3, "b-frame" },
459 { 4, "d-frame" },
460 { 0, NULL }
464 static int
465 dissect_mpeg_pes_T_frame_type(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
466 offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
467 0U, 7U, NULL, false);
469 return offset;
474 static int
475 dissect_mpeg_pes_BIT_STRING_SIZE_16(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
476 offset = dissect_per_bit_string(tvb, offset, actx, tree, hf_index,
477 16, 16, false, NULL, 0, NULL, NULL);
479 return offset;
483 static const per_sequence_t Picture_sequence[] = {
484 { &hf_mpeg_pes_temporal_sequence_number, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_10 },
485 { &hf_mpeg_pes_frame_type , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_T_frame_type },
486 { &hf_mpeg_pes_vbv_delay , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_16 },
487 { NULL, 0, 0, NULL }
490 static int
491 dissect_mpeg_pes_Picture(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
492 offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
493 ett_mpeg_pes_Picture, Picture_sequence);
495 return offset;
499 void proto_register_mpeg_pes(void);
500 void proto_reg_handoff_mpeg_pes(void);
502 static int proto_mpeg;
503 static int proto_mpeg_pes;
505 static int ett_mpeg_pes_pack_header;
506 static int ett_mpeg_pes_header_data;
507 static int ett_mpeg_pes_trick_mode;
509 static int hf_mpeg_pes_pack_header;
510 static int hf_mpeg_pes_scr;
511 static int hf_mpeg_pes_program_mux_rate;
512 static int hf_mpeg_pes_stuffing_length;
513 static int hf_mpeg_pes_stuffing;
514 static int hf_mpeg_pes_extension;
515 static int hf_mpeg_pes_header_data;
516 static int hf_mpeg_pes_pts;
517 static int hf_mpeg_pes_dts;
518 static int hf_mpeg_pes_escr;
519 static int hf_mpeg_pes_es_rate;
520 static int hf_mpeg_pes_dsm_trick_mode;
521 static int hf_mpeg_pes_dsm_trick_mode_control;
522 static int hf_mpeg_pes_dsm_trick_mode_field_id;
523 static int hf_mpeg_pes_dsm_trick_mode_intra_slice_refresh;
524 static int hf_mpeg_pes_dsm_trick_mode_frequency_truncation;
525 static int hf_mpeg_pes_dsm_trick_mode_rep_cntrl;
526 static int hf_mpeg_pes_copy_info;
527 static int hf_mpeg_pes_crc;
528 static int hf_mpeg_pes_extension_flags;
529 static int hf_mpeg_pes_private_data;
530 static int hf_mpeg_pes_pack_length;
531 static int hf_mpeg_pes_sequence;
532 static int hf_mpeg_pes_pstd_buffer;
533 static int hf_mpeg_pes_extension2;
534 static int hf_mpeg_pes_padding;
535 static int hf_mpeg_pes_data;
537 static int hf_mpeg_video_sequence_header;
538 static int hf_mpeg_video_sequence_extension;
539 static int hf_mpeg_video_group_of_pictures;
540 static int hf_mpeg_video_picture;
541 static int hf_mpeg_video_quantization_matrix;
542 static int hf_mpeg_video_data;
544 static expert_field ei_mpeg_pes_length_zero;
546 static dissector_handle_t mpeg_handle;
548 static dissector_table_t stream_type_table;
550 static int mpeg_pes_follow_tap;
552 enum { PES_PREFIX = 1 };
555 * MPEG uses 32-bit start codes that all begin with the three byte sequence
556 * 00 00 01 (the start code prefix) for bit and byte alignment, among other
557 * purposes.
559 * The values from 0xb9 through 0xff are "system start codes" and described in
560 * ISO/IEC 13818-1:2019 / ITU-T H.222.0. The bulk of them, 0xbc through 0xff,
561 * are stream_id values and documented in Table 2-22 "Stream_id assignments".
562 * The remaining three are used by Program Streams and found as follows:
563 * 0xb9, the MPEG_program_end_code, in 2.5.3.2 "Semantic definition of fields
564 * in program stream"
565 * 0xba, the pack_start_code, in 2.5.3.4 "Semantic definition of fields in
566 * program stream pack"
567 * 0xbb, the system_header_start_code, in 2.5.3.6 "Semantic definition of fields
568 * in system header"
570 * The remaining 185 values from 0x00 to 0xb8 are used by MPEG-2 video
571 * (backwards compatible with MPEG-1 video) and documented in ISO/IEC 13818-2 /
572 * ITU-T H.262 (2000), in Table 6-1 "Start code values". These are not stream
573 * id values and do not mark PES packets, but rather demarcate elements in the
574 * coded MPEG-1/2 video bitstream, at a different hierarchical level than the
575 * PES packets. The sets of values used for video start codes and for stream
576 * ids are disjoint to avoid any ambiguity when resynchronizing. Note the
577 * dissector currently conflates MPEG video with MPEG PES.
579 * Care is taken to ensure that the start code prefix 0x000001 does not occur
580 * elsewhere in the structure (avoiding "emulation of start codes").
582 * The video can have other formats, given by the stream type, carried on
583 * TS in the PMT and in PS from the similar Program Stream Map. AVC/H.264 and
584 * HEVC/H.265 carried in PES also use the start code prefix, before each NAL,
585 * and escape the raw byte sequence with bytes that prevent internal start code
586 * prefixes. The byte following the prefix (the first byte of the NAL header)
587 * has high bit zero, so the values of the NAL header are in the range used by
588 * the MPEG-2 video bitstream, not the range used by stream ids, allowing for
589 * synchronization in the same way. See Annex B "Byte Stream Format" of H.264
590 * and H.265.
592 enum {
593 STREAM_PICTURE = 0x00,
594 STREAM_SEQUENCE = 0xb3,
595 STREAM_SEQUENCE_EXTENSION = 0xb5,
596 STREAM_GOP = 0xb8,
597 STREAM_END = 0xb9,
598 STREAM_PACK = 0xba,
599 STREAM_SYSTEM = 0xbb,
600 STREAM_PROGRAM = 0xbc,
601 STREAM_PRIVATE1 = 0xbd,
602 STREAM_PADDING = 0xbe,
603 STREAM_PRIVATE2 = 0xbf,
604 STREAM_AUDIO = 0xc0,
605 STREAM_AUDIO_MAX = 0xdf,
606 STREAM_VIDEO = 0xe0,
607 STREAM_VIDEO_MAX = 0xef
610 enum {
611 PTS_FLAG = 0x80,
612 DTS_FLAG = 0x40,
613 ESCR_FLAG = 0x20,
614 ES_RATE_FLAG = 0x10,
615 DSM_TRICK_MODE_FLAG = 0x08,
616 COPY_INFO_FLAG = 0x04,
617 CRC_FLAG = 0x02,
618 EXTENSION_FLAG = 0x01
621 enum {
622 PRIVATE_DATA_FLAG = 0x80,
623 PACK_LENGTH_FLAG = 0x40,
624 SEQUENCE_FLAG = 0x20,
625 PSTD_BUFFER_FLAG = 0x10,
626 MUST_BE_ONES = 0x07,
627 EXTENSION_FLAG2 = 0x01
630 enum {
631 FAST_FORWARD_CONTROL = 0x00,
632 SLOW_MOTION_CONTROL = 0x01,
633 FREEZE_FRAME_CONTROL = 0x02,
634 FAST_REVERSE_CONTROL = 0x03,
635 SLOW_REVERSE_CONTROL = 0x04
638 static const value_string mpeg_pes_TrickModeControl_vals[] = {
639 { FAST_FORWARD_CONTROL, "fast-forward" },
640 { SLOW_MOTION_CONTROL, "slow-motion" },
641 { FREEZE_FRAME_CONTROL, "freeze-frame" },
642 { FAST_REVERSE_CONTROL, "fast-reverse" },
643 { SLOW_REVERSE_CONTROL, "slow-reverse" },
644 { 5, "reserved" },
645 { 6, "reserved" },
646 { 7, "reserved" },
647 { 0, NULL }
650 static const value_string mpeg_pes_TrickModeFieldId_vals[] = {
651 { 0, "display-from-top-field-only" },
652 { 1, "display-from-bottom-field-only" },
653 { 2, "display-complete-frame" },
654 { 3, "reserved" },
655 { 0, NULL }
658 static const value_string mpeg_pes_TrickModeIntraSliceRefresh_vals[] = {
659 { 0, "macroblocks-may-not-be-missing" },
660 { 1, "macroblocks-may-be-missing" },
661 { 0, NULL }
664 static const value_string mpeg_pes_TrickModeFrequencyTruncation_vals[] = {
665 { 0, "only-DC-coefficients-are-non-zero" },
666 { 1, "only-the-first-three-coefficients-are-non-zero" },
667 { 2, "only-the-first-six-coefficients-are-non-zero" },
668 { 3, "all-coefficients-may-be-non-zero" },
669 { 0, NULL }
672 #define TSHZ 90000
674 static uint64_t decode_time_stamp(tvbuff_t *tvb, int offset, nstime_t *nst)
676 uint64_t bytes = tvb_get_ntoh40(tvb, offset);
677 uint64_t ts =
678 (bytes >> 33 & 0x0007) << 30 |
679 (bytes >> 17 & 0x7fff) << 15 |
680 (bytes >> 1 & 0x7fff) << 0;
681 unsigned int rem = (unsigned int)(ts % TSHZ);
682 nst->secs = (time_t)(ts / TSHZ);
683 nst->nsecs = (int)(INT64_C(1000000000) * rem / TSHZ);
684 return ts;
687 #define SCRHZ 27000000
689 static uint64_t decode_clock_reference(tvbuff_t *tvb, int offset,
690 nstime_t *nst)
692 uint64_t bytes = tvb_get_ntoh48(tvb, offset);
693 uint64_t ts =
694 (bytes >> 43 & 0x0007) << 30 |
695 (bytes >> 27 & 0x7fff) << 15 |
696 (bytes >> 11 & 0x7fff) << 0;
697 unsigned int ext = (unsigned int)((bytes >> 1) & 0x1ff);
698 uint64_t cr = 300 * ts + ext;
699 unsigned int rem = (unsigned int)(cr % SCRHZ);
700 nst->secs = (time_t)(cr / SCRHZ);
701 nst->nsecs = (int)(INT64_C(1000000000) * rem / SCRHZ);
702 return cr;
705 static int
706 dissect_mpeg_pes_header_data(tvbuff_t *tvb, packet_info *pinfo _U_,
707 proto_tree *root, unsigned int flags)
709 proto_item *item = proto_tree_add_item(root, hf_mpeg_pes_header_data, tvb,
710 0, -1, ENC_NA);
711 proto_tree *tree = proto_item_add_subtree(item, ett_mpeg_pes_header_data);
713 int offset = 0;
714 if (flags & PTS_FLAG) {
715 nstime_t nst;
716 decode_time_stamp(tvb, offset, &nst);
717 proto_tree_add_time(tree, hf_mpeg_pes_pts, tvb,
718 offset, 5, &nst);
719 offset += 5;
721 if (flags & DTS_FLAG) {
722 nstime_t nst;
723 decode_time_stamp(tvb, offset, &nst);
724 proto_tree_add_time(tree, hf_mpeg_pes_dts, tvb,
725 offset, 5, &nst);
726 offset += 5;
728 if (flags & ESCR_FLAG) {
729 nstime_t nst;
730 decode_clock_reference(tvb, offset, &nst);
731 proto_tree_add_time(tree, hf_mpeg_pes_escr, tvb,
732 offset, 6, &nst);
733 offset += 6;
735 if (flags & ES_RATE_FLAG) {
736 unsigned int es_rate = (tvb_get_ntohs(tvb, offset) >> 1 & 0x3fff) * 50;
737 proto_tree_add_uint(tree, hf_mpeg_pes_es_rate, tvb,
738 offset, 3, es_rate);
739 offset += 3;
741 if (flags & DSM_TRICK_MODE_FLAG)
743 uint8_t value = tvb_get_uint8(tvb, offset);
744 uint8_t control;
745 proto_tree *trick_tree;
746 proto_item *trick_item;
748 trick_item = proto_tree_add_item(item,
749 hf_mpeg_pes_dsm_trick_mode, tvb,
750 offset, 1, ENC_NA);
752 trick_tree = proto_item_add_subtree(trick_item,
753 ett_mpeg_pes_trick_mode);
755 control = (value >> 5);
756 proto_tree_add_uint(trick_tree,
757 hf_mpeg_pes_dsm_trick_mode_control, tvb,
758 offset, 1,
759 control);
761 if (control == FAST_FORWARD_CONTROL
762 || control == FAST_REVERSE_CONTROL)
764 proto_tree_add_uint(trick_tree,
765 hf_mpeg_pes_dsm_trick_mode_field_id, tvb,
766 offset, 1,
767 (value & 0x18) >> 3);
769 proto_tree_add_uint(trick_tree,
770 hf_mpeg_pes_dsm_trick_mode_intra_slice_refresh, tvb,
771 offset, 1,
772 (value & 0x04) >> 2);
774 proto_tree_add_uint(trick_tree,
775 hf_mpeg_pes_dsm_trick_mode_frequency_truncation, tvb,
776 offset, 1,
777 (value & 0x03));
779 else if (control == SLOW_MOTION_CONTROL
780 || control == SLOW_REVERSE_CONTROL)
782 proto_tree_add_uint(trick_tree,
783 hf_mpeg_pes_dsm_trick_mode_rep_cntrl, tvb,
784 offset, 1,
785 (value & 0x1F));
787 else if (control == FREEZE_FRAME_CONTROL)
789 proto_tree_add_uint(trick_tree,
790 hf_mpeg_pes_dsm_trick_mode_field_id, tvb,
791 offset, 1,
792 (value & 0x18) >> 3);
795 offset += 1;
797 if (flags & COPY_INFO_FLAG) {
798 proto_tree_add_item(tree, hf_mpeg_pes_copy_info, tvb,
799 offset, 1, ENC_BIG_ENDIAN);
800 offset++;
802 if (flags & CRC_FLAG) {
803 proto_tree_add_item(tree, hf_mpeg_pes_crc, tvb,
804 offset, 2, ENC_BIG_ENDIAN);
805 offset += 2;
808 if (flags & EXTENSION_FLAG) {
809 int flags2 = tvb_get_uint8(tvb, offset);
810 proto_tree_add_item(tree, hf_mpeg_pes_extension_flags, tvb,
811 offset, 1, ENC_BIG_ENDIAN);
812 offset++;
814 if (flags2 & PRIVATE_DATA_FLAG) {
815 proto_tree_add_item(tree, hf_mpeg_pes_private_data, tvb,
816 offset, 16, ENC_NA);
817 offset += 16;
819 if (flags2 & PACK_LENGTH_FLAG) {
820 proto_tree_add_item(tree, hf_mpeg_pes_pack_length, tvb,
821 offset, 1, ENC_BIG_ENDIAN);
822 offset++;
824 if (flags2 & SEQUENCE_FLAG) {
825 proto_tree_add_item(tree, hf_mpeg_pes_sequence, tvb,
826 offset, 2, ENC_BIG_ENDIAN);
827 offset += 2;
829 if (flags2 & PSTD_BUFFER_FLAG) {
830 unsigned int pstd = tvb_get_ntohs(tvb, offset);
831 proto_tree_add_uint(tree, hf_mpeg_pes_pstd_buffer, tvb,
832 offset, 2, (pstd & 0x2000 ? 1024 : 128) * (pstd & 0x1ff));
833 offset += 2;
835 if (flags2 & EXTENSION_FLAG2) {
836 proto_tree_add_item(tree, hf_mpeg_pes_extension2, tvb,
837 offset, 2, ENC_BIG_ENDIAN);
838 offset += 2;
841 return offset;
844 static int
845 dissect_mpeg_pes_pack_header(tvbuff_t *tvb, int offset,
846 packet_info *pinfo _U_, proto_tree *root)
848 unsigned int program_mux_rate, stuffing_length;
850 proto_item *item = proto_tree_add_item(root, hf_mpeg_pes_pack_header, tvb,
851 offset / 8, 10, ENC_NA);
852 proto_tree *tree = proto_item_add_subtree(item, ett_mpeg_pes_pack_header);
854 nstime_t nst;
855 decode_clock_reference(tvb, offset / 8, &nst);
856 proto_tree_add_time(tree, hf_mpeg_pes_scr, tvb, offset / 8, 6, &nst);
857 offset += 6 * 8;
859 program_mux_rate = (tvb_get_ntoh24(tvb, offset / 8) >> 2) * 50;
860 proto_tree_add_uint(tree, hf_mpeg_pes_program_mux_rate, tvb, offset / 8, 3,
861 program_mux_rate);
862 offset += 3 * 8;
864 stuffing_length = tvb_get_uint8(tvb, offset / 8) & 0x07;
865 proto_tree_add_item(tree, hf_mpeg_pes_stuffing_length, tvb,
866 offset / 8, 1, ENC_BIG_ENDIAN);
867 offset += 1 * 8;
869 if (stuffing_length > 0) {
870 proto_tree_add_item(tree, hf_mpeg_pes_stuffing, tvb,
871 offset / 8, stuffing_length, ENC_NA);
872 offset += stuffing_length * 8;
875 return offset;
878 static int
879 dissect_mpeg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data);
881 static int
882 // NOLINTNEXTLINE(misc-no-recursion)
883 dissect_mpeg_pes(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
885 int prefix;
886 int stream;
887 asn1_ctx_t asn1_ctx;
888 int offset = 0;
889 uint8_t stream_type;
891 if (!tvb_bytes_exist(tvb, 0, 3))
892 return 0; /* not enough bytes for a PES prefix */
894 prefix = tvb_get_ntoh24(tvb, 0);
895 if (prefix != PES_PREFIX)
896 return 0;
897 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPEG PES");
898 col_clear(pinfo->cinfo, COL_INFO);
900 stream = tvb_get_uint8(tvb, 3);
901 col_add_fstr(pinfo->cinfo, COL_INFO, "%s ", val_to_str(stream, mpeg_pes_T_stream_vals, "Unknown stream: %d"));
903 /* Were we called from MP2T providing a stream type from a PMT? */
904 stream_type = GPOINTER_TO_UINT(data);
905 /* Luckily, stream_type 0 is reserved, so a null value is fine.
906 * XXX: Implement Program Stream Map for Program Stream (similar
907 * to PMT but maps stream_ids to stream_types instead of PIDs.)
910 asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, true, pinfo);
911 offset = dissect_mpeg_pes_PES(tvb, offset, &asn1_ctx,
912 tree, proto_mpeg_pes);
914 increment_dissection_depth(pinfo);
915 if (stream == STREAM_PICTURE) {
916 int frame_type;
918 frame_type = tvb_get_uint8(tvb, 5) >> 3 & 0x07;
919 col_add_fstr(pinfo->cinfo, COL_INFO, "%s ", val_to_str(frame_type, mpeg_pes_T_frame_type_vals, "Unknown frame type: %d"));
921 offset = dissect_mpeg_pes_Picture(tvb, offset, &asn1_ctx,
922 tree, hf_mpeg_video_picture);
923 proto_tree_add_item(tree, hf_mpeg_video_data, tvb,
924 offset / 8, -1, ENC_NA);
925 } else if (stream == STREAM_SEQUENCE) {
926 tvbuff_t *es;
928 offset = dissect_mpeg_pes_Sequence_header(tvb, offset, &asn1_ctx,
929 tree, hf_mpeg_video_sequence_header);
931 proto_tree_add_item(tree, hf_mpeg_video_quantization_matrix, tvb,
932 offset / 8, 64, ENC_NA);
933 offset += 64 * 8;
935 es = tvb_new_subset_remaining(tvb, offset / 8);
936 dissect_mpeg_pes(es, pinfo, tree, NULL);
937 } else if (stream == STREAM_SEQUENCE_EXTENSION) {
938 tvbuff_t *es;
940 offset = dissect_mpeg_pes_Sequence_extension(tvb, offset, &asn1_ctx,
941 tree, hf_mpeg_video_sequence_extension);
943 es = tvb_new_subset_remaining(tvb, offset / 8);
944 dissect_mpeg_pes(es, pinfo, tree, NULL);
945 } else if (stream == STREAM_GOP) {
946 tvbuff_t *es;
948 offset = dissect_mpeg_pes_Group_of_pictures(tvb, offset, &asn1_ctx,
949 tree, hf_mpeg_video_group_of_pictures);
951 es = tvb_new_subset_remaining(tvb, offset / 8);
952 dissect_mpeg_pes(es, pinfo, tree, NULL);
953 } else if (stream == STREAM_PACK) {
954 if (tvb_get_uint8(tvb, offset / 8) >> 6 == 1) {
955 dissect_mpeg_pes_pack_header(tvb, offset, pinfo, tree);
956 } else {
957 proto_tree_add_item(tree, hf_mpeg_pes_data, tvb,
958 offset / 8, 8, ENC_NA);
960 } else if (stream == STREAM_SYSTEM || stream == STREAM_PRIVATE2) {
961 unsigned int data_length = tvb_get_ntohs(tvb, offset / 8);
962 proto_tree_add_item(tree, hf_mpeg_pes_length, tvb,
963 offset / 8, 2, ENC_BIG_ENDIAN);
964 offset += 2 * 8;
966 proto_tree_add_item(tree, hf_mpeg_pes_data, tvb,
967 offset / 8, data_length, ENC_NA);
968 } else if (stream == STREAM_PADDING) {
969 unsigned int padding_length = tvb_get_ntohs(tvb, offset / 8);
970 proto_tree_add_item(tree, hf_mpeg_pes_length, tvb,
971 offset / 8, 2, ENC_BIG_ENDIAN);
972 offset += 2 * 8;
974 proto_tree_add_item(tree, hf_mpeg_pes_padding, tvb,
975 offset / 8, padding_length, ENC_NA);
976 } else if (stream == STREAM_PRIVATE1
977 || stream >= STREAM_AUDIO) {
978 int length = tvb_get_ntohs(tvb, offset / 8);
980 if ((tvb_get_uint8(tvb, 6) & 0xc0) == 0x80) {
981 int header_length;
982 tvbuff_t *es;
983 int save_offset = offset;
985 offset = dissect_mpeg_pes_Stream(tvb, offset, &asn1_ctx,
986 tree, hf_mpeg_pes_extension);
987 /* https://gitlab.com/wireshark/wireshark/-/issues/2229
988 * A value of 0 indicates that the PES packet length
989 * is neither specified nor bounded and is allowed
990 * only in PES packets whose payload is a video
991 * elementary stream contained in Transport Stream
992 * packets.
994 * See ISO/IEC 13818-1:2007, section 2.4.3.7
995 * "Semantic definition of fields in PES packet",
996 * which says of the PES_packet_length that "A value
997 * of 0 indicates that the PES packet length is
998 * neither specified nor bounded and is allowed only
999 * in PES packets whose payload consists of bytes
1000 * from a video elementary stream contained in
1001 * Transport Stream packets."
1003 if (length !=0) {
1005 * XXX - note that ISO/IEC 13818-1:2007
1006 * says that the length field is *not*
1007 * part of the above extension.
1009 * This means that the length of the length
1010 * field itself should *not* be subtracted
1011 * from the length field; ISO/IEC 13818-1:2007
1012 * says that the PES_packet_length field is
1013 * "A 16-bit field specifying the number of
1014 * bytes in the PES packet following the
1015 * last byte of the field."
1017 * So we calculate the size of the extension,
1018 * in bytes, by subtracting the saved bit
1019 * offset value from the current bit offset
1020 * value, divide by 8 to convert to a size
1021 * in bytes, and then subtract 2 to remove
1022 * the length field's length from the total
1023 * length.
1025 * (In addition, ISO/IEC 13818-1:2007
1026 * suggests that the length field is
1027 * always present, but this code, when
1028 * processing some stream ID types, doesn't
1029 * treat it as being present. Where are
1030 * the formats of those payloads specified?)
1032 length -= ((offset - save_offset) / 8) - 2;
1033 } else if (stream < STREAM_VIDEO || stream > STREAM_VIDEO_MAX) {
1034 proto_tree_add_expert(tree, pinfo, &ei_mpeg_pes_length_zero, tvb, save_offset / 8, 2);
1037 header_length = tvb_get_uint8(tvb, 8);
1038 if (header_length > 0) {
1039 int flags = tvb_get_uint8(tvb, 7);
1040 tvbuff_t *header_data = tvb_new_subset_length(tvb, offset / 8,
1041 header_length);
1042 dissect_mpeg_pes_header_data(header_data, pinfo, tree, flags);
1043 offset += header_length * 8;
1044 /* length may be zero for Video stream */
1045 if (length !=0) {
1046 length -= header_length;
1050 /* length may be zero for Video stream */
1051 if(length==0){
1052 es = tvb_new_subset_remaining(tvb, offset / 8);
1053 } else {
1054 es = tvb_new_subset_length(tvb, offset / 8, length);
1056 if (have_tap_listener(mpeg_pes_follow_tap)) {
1057 tap_queue_packet(mpeg_pes_follow_tap, pinfo, es);
1059 /* Try to dissect according to the stream type, if
1060 * we have it. For video in DVB an access unit starts
1061 * immediately after the PES header, access units are
1062 * contained within one PES packet and multiple access
1063 * units shall not be sent per PES packet unless they
1064 * fit in the same transport packet (ETSI TS 101 154).
1065 * This is not guaranteed for audio frames, so proper
1066 * dissction there should involve looking for frame
1067 * sync and reassembling across PES packet boundaries
1068 * if necessary.
1070 if (!dissector_try_uint_with_data(stream_type_table, stream_type, es, pinfo, tree, true, NULL)) {
1071 /* If we didn't get a stream type, then assume
1072 * MPEG-1/2 Audio or Video.
1074 if (tvb_get_ntoh24(es, 0) == PES_PREFIX)
1075 dissect_mpeg_pes(es, pinfo, tree, NULL);
1076 else if (tvb_get_uint8(es, 0) == 0xff)
1077 dissect_mpeg(es, pinfo, tree, NULL);
1078 else
1079 proto_tree_add_item(tree, hf_mpeg_pes_data, es,
1080 0, -1, ENC_NA);
1082 } else {
1083 proto_tree_add_item(tree, hf_mpeg_pes_length, tvb,
1084 offset / 8, 2, ENC_BIG_ENDIAN);
1085 offset += 2 * 8;
1087 proto_tree_add_item(tree, hf_mpeg_pes_data, tvb,
1088 offset / 8, length, ENC_NA);
1090 } else if (stream != STREAM_END) {
1091 proto_tree_add_item(tree, hf_mpeg_pes_data, tvb,
1092 offset / 8, -1, ENC_NA);
1094 decrement_dissection_depth(pinfo);
1095 return tvb_reported_length(tvb);
1098 static heur_dissector_list_t heur_subdissector_list;
1100 static int
1101 dissect_mpeg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
1103 heur_dtbl_entry_t *hdtbl_entry;
1105 if (!dissector_try_heuristic(heur_subdissector_list, tvb, pinfo, tree, &hdtbl_entry, NULL)) {
1106 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPEG");
1107 col_clear(pinfo->cinfo, COL_INFO);
1109 proto_tree_add_item(tree, proto_mpeg, tvb, 0, -1, ENC_NA);
1111 return tvb_captured_length(tvb);
1114 static bool
1115 dissect_mpeg_pes_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) {
1116 return dissect_mpeg_pes(tvb, pinfo, tree, data) > 0;
1119 void
1120 proto_register_mpeg_pes(void)
1122 static hf_register_info hf[] = {
1123 { &hf_mpeg_pes_prefix,
1124 { "prefix", "mpeg-pes.prefix",
1125 FT_BYTES, BASE_NONE, NULL, 0,
1126 "OCTET_STRING_SIZE_3", HFILL }},
1127 { &hf_mpeg_pes_stream,
1128 { "stream", "mpeg-pes.stream",
1129 FT_UINT8, BASE_HEX, VALS(mpeg_pes_T_stream_vals), 0,
1130 NULL, HFILL }},
1131 { &hf_mpeg_pes_length,
1132 { "length", "mpeg-pes.length",
1133 FT_UINT16, BASE_DEC, NULL, 0,
1134 "INTEGER_0_65535", HFILL }},
1135 { &hf_mpeg_pes_must_be_one,
1136 { "must-be-one", "mpeg-pes.must_be_one",
1137 FT_BOOLEAN, BASE_NONE, NULL, 0,
1138 "BOOLEAN", HFILL }},
1139 { &hf_mpeg_pes_stream_must_be_zero,
1140 { "must-be-zero", "mpeg-pes.stream.must-be-zero",
1141 FT_BOOLEAN, BASE_NONE, NULL, 0,
1142 "BOOLEAN", HFILL }},
1143 { &hf_mpeg_pes_scrambling_control,
1144 { "scrambling-control", "mpeg-pes.scrambling_control",
1145 FT_UINT8, BASE_DEC, VALS(mpeg_pes_T_scrambling_control_vals), 0x30,
1146 NULL, HFILL }},
1147 { &hf_mpeg_pes_priority,
1148 { "priority", "mpeg-pes.priority",
1149 FT_BOOLEAN, BASE_NONE, NULL, 0,
1150 "BOOLEAN", HFILL }},
1151 { &hf_mpeg_pes_data_alignment,
1152 { "data-alignment", "mpeg-pes.data_alignment",
1153 FT_BOOLEAN, BASE_NONE, NULL, 0,
1154 "BOOLEAN", HFILL }},
1155 { &hf_mpeg_pes_copyright,
1156 { "copyright", "mpeg-pes.copyright",
1157 FT_BOOLEAN, BASE_NONE, NULL, 0,
1158 "BOOLEAN", HFILL }},
1159 { &hf_mpeg_pes_original,
1160 { "original", "mpeg-pes.original",
1161 FT_BOOLEAN, BASE_NONE, NULL, 0,
1162 "BOOLEAN", HFILL }},
1163 { &hf_mpeg_pes_pts_flag,
1164 { "pts-flag", "mpeg-pes.pts_flag",
1165 FT_BOOLEAN, BASE_NONE, NULL, 0,
1166 "BOOLEAN", HFILL }},
1167 { &hf_mpeg_pes_dts_flag,
1168 { "dts-flag", "mpeg-pes.dts_flag",
1169 FT_BOOLEAN, BASE_NONE, NULL, 0,
1170 "BOOLEAN", HFILL }},
1171 { &hf_mpeg_pes_escr_flag,
1172 { "escr-flag", "mpeg-pes.escr_flag",
1173 FT_BOOLEAN, BASE_NONE, NULL, 0,
1174 "BOOLEAN", HFILL }},
1175 { &hf_mpeg_pes_es_rate_flag,
1176 { "es-rate-flag", "mpeg-pes.es_rate_flag",
1177 FT_BOOLEAN, BASE_NONE, NULL, 0,
1178 "BOOLEAN", HFILL }},
1179 { &hf_mpeg_pes_dsm_trick_mode_flag,
1180 { "dsm-trick-mode-flag", "mpeg-pes.dsm_trick_mode_flag",
1181 FT_BOOLEAN, BASE_NONE, NULL, 0,
1182 "BOOLEAN", HFILL }},
1183 { &hf_mpeg_pes_additional_copy_info_flag,
1184 { "additional-copy-info-flag", "mpeg-pes.additional_copy_info_flag",
1185 FT_BOOLEAN, BASE_NONE, NULL, 0,
1186 "BOOLEAN", HFILL }},
1187 { &hf_mpeg_pes_crc_flag,
1188 { "crc-flag", "mpeg-pes.crc_flag",
1189 FT_BOOLEAN, BASE_NONE, NULL, 0,
1190 "BOOLEAN", HFILL }},
1191 { &hf_mpeg_pes_extension_flag,
1192 { "extension-flag", "mpeg-pes.extension_flag",
1193 FT_BOOLEAN, BASE_NONE, NULL, 0,
1194 "BOOLEAN", HFILL }},
1195 { &hf_mpeg_pes_header_data_length,
1196 { "header-data-length", "mpeg-pes.header_data_length",
1197 FT_UINT32, BASE_DEC, NULL, 0,
1198 "INTEGER_0_255", HFILL }},
1199 { &hf_mpeg_pes_horizontal_size,
1200 { "horizontal-size", "mpeg-pes.horizontal_size",
1201 FT_BYTES, BASE_NONE, NULL, 0,
1202 "BIT_STRING_SIZE_12", HFILL }},
1203 { &hf_mpeg_pes_vertical_size,
1204 { "vertical-size", "mpeg-pes.vertical_size",
1205 FT_BYTES, BASE_NONE, NULL, 0,
1206 "BIT_STRING_SIZE_12", HFILL }},
1207 { &hf_mpeg_pes_aspect_ratio,
1208 { "aspect-ratio", "mpeg-pes.aspect_ratio",
1209 FT_UINT32, BASE_DEC, VALS(mpeg_pes_T_aspect_ratio_vals), 0,
1210 "T_aspect_ratio", HFILL }},
1211 { &hf_mpeg_pes_frame_rate,
1212 { "frame-rate", "mpeg-pes.frame_rate",
1213 FT_UINT32, BASE_DEC, VALS(mpeg_pes_T_frame_rate_vals), 0,
1214 NULL, HFILL }},
1215 { &hf_mpeg_pes_bit_rate,
1216 { "bit-rate", "mpeg-pes.bit_rate",
1217 FT_BYTES, BASE_NONE, NULL, 0,
1218 "BIT_STRING_SIZE_18", HFILL }},
1219 { &hf_mpeg_pes_vbv_buffer_size,
1220 { "vbv-buffer-size", "mpeg-pes.vbv_buffer_size",
1221 FT_BYTES, BASE_NONE, NULL, 0,
1222 "BIT_STRING_SIZE_10", HFILL }},
1223 { &hf_mpeg_pes_constrained_parameters_flag,
1224 { "constrained-parameters-flag", "mpeg-pes.constrained_parameters_flag",
1225 FT_BOOLEAN, BASE_NONE, NULL, 0,
1226 "BOOLEAN", HFILL }},
1227 { &hf_mpeg_pes_load_intra_quantiser_matrix,
1228 { "load-intra-quantiser-matrix", "mpeg-pes.load_intra_quantiser_matrix",
1229 FT_BOOLEAN, BASE_NONE, NULL, 0,
1230 "BOOLEAN", HFILL }},
1231 { &hf_mpeg_pes_load_non_intra_quantiser_matrix,
1232 { "load-non-intra-quantiser-matrix", "mpeg-pes.load_non_intra_quantiser_matrix",
1233 FT_BOOLEAN, BASE_NONE, NULL, 0,
1234 "BOOLEAN", HFILL }},
1235 { &hf_mpeg_pes_must_be_0001,
1236 { "must-be-0001", "mpeg-pes.must_be_0001",
1237 FT_BYTES, BASE_NONE, NULL, 0,
1238 "BIT_STRING_SIZE_4", HFILL }},
1239 { &hf_mpeg_pes_profile_and_level,
1240 { "profile-and-level", "mpeg-pes.profile_and_level",
1241 FT_UINT32, BASE_DEC, NULL, 0,
1242 "INTEGER_0_255", HFILL }},
1243 { &hf_mpeg_pes_progressive_sequence,
1244 { "progressive-sequence", "mpeg-pes.progressive_sequence",
1245 FT_BOOLEAN, BASE_NONE, NULL, 0,
1246 "BOOLEAN", HFILL }},
1247 { &hf_mpeg_pes_chroma_format,
1248 { "chroma-format", "mpeg-pes.chroma_format",
1249 FT_UINT32, BASE_DEC, NULL, 0,
1250 "INTEGER_0_3", HFILL }},
1251 { &hf_mpeg_pes_horizontal_size_extension,
1252 { "horizontal-size-extension", "mpeg-pes.horizontal_size_extension",
1253 FT_UINT32, BASE_DEC, NULL, 0,
1254 "INTEGER_0_3", HFILL }},
1255 { &hf_mpeg_pes_vertical_size_extension,
1256 { "vertical-size-extension", "mpeg-pes.vertical_size_extension",
1257 FT_UINT32, BASE_DEC, NULL, 0,
1258 "INTEGER_0_3", HFILL }},
1259 { &hf_mpeg_pes_bit_rate_extension,
1260 { "bit-rate-extension", "mpeg-pes.bit_rate_extension",
1261 FT_BYTES, BASE_NONE, NULL, 0,
1262 "BIT_STRING_SIZE_12", HFILL }},
1263 { &hf_mpeg_pes_vbv_buffer_size_extension,
1264 { "vbv-buffer-size-extension", "mpeg-pes.vbv_buffer_size_extension",
1265 FT_UINT32, BASE_DEC, NULL, 0,
1266 "INTEGER_0_255", HFILL }},
1267 { &hf_mpeg_pes_low_delay,
1268 { "low-delay", "mpeg-pes.low_delay",
1269 FT_BOOLEAN, BASE_NONE, NULL, 0,
1270 "BOOLEAN", HFILL }},
1271 { &hf_mpeg_pes_frame_rate_extension_n,
1272 { "frame-rate-extension-n", "mpeg-pes.frame_rate_extension_n",
1273 FT_UINT32, BASE_DEC, NULL, 0,
1274 "INTEGER_0_3", HFILL }},
1275 { &hf_mpeg_pes_frame_rate_extension_d,
1276 { "frame-rate-extension-d", "mpeg-pes.frame_rate_extension_d",
1277 FT_UINT32, BASE_DEC, NULL, 0,
1278 "INTEGER_0_3", HFILL }},
1279 { &hf_mpeg_pes_drop_frame_flag,
1280 { "drop-frame-flag", "mpeg-pes.drop_frame_flag",
1281 FT_BOOLEAN, BASE_NONE, NULL, 0,
1282 "BOOLEAN", HFILL }},
1283 { &hf_mpeg_pes_hour,
1284 { "hour", "mpeg-pes.hour",
1285 FT_UINT32, BASE_DEC, NULL, 0,
1286 "INTEGER_0_32", HFILL }},
1287 { &hf_mpeg_pes_minute,
1288 { "minute", "mpeg-pes.minute",
1289 FT_UINT32, BASE_DEC, NULL, 0,
1290 "INTEGER_0_64", HFILL }},
1291 { &hf_mpeg_pes_second,
1292 { "second", "mpeg-pes.second",
1293 FT_UINT32, BASE_DEC, NULL, 0,
1294 "INTEGER_0_64", HFILL }},
1295 { &hf_mpeg_pes_frame,
1296 { "frame", "mpeg-pes.frame",
1297 FT_UINT32, BASE_DEC, NULL, 0,
1298 "INTEGER_0_64", HFILL }},
1299 { &hf_mpeg_pes_closed_gop,
1300 { "closed-gop", "mpeg-pes.closed_gop",
1301 FT_BOOLEAN, BASE_NONE, NULL, 0,
1302 "BOOLEAN", HFILL }},
1303 { &hf_mpeg_pes_broken_gop,
1304 { "broken-gop", "mpeg-pes.broken_gop",
1305 FT_BOOLEAN, BASE_NONE, NULL, 0,
1306 "BOOLEAN", HFILL }},
1307 { &hf_mpeg_pes_must_be_zero,
1308 { "must-be-zero", "mpeg-pes.must_be_zero",
1309 FT_BYTES, BASE_NONE, NULL, 0,
1310 "BIT_STRING_SIZE_5", HFILL }},
1311 { &hf_mpeg_pes_temporal_sequence_number,
1312 { "temporal-sequence-number", "mpeg-pes.temporal_sequence_number",
1313 FT_BYTES, BASE_NONE, NULL, 0,
1314 "BIT_STRING_SIZE_10", HFILL }},
1315 { &hf_mpeg_pes_frame_type,
1316 { "frame-type", "mpeg-pes.frame_type",
1317 FT_UINT32, BASE_DEC, VALS(mpeg_pes_T_frame_type_vals), 0,
1318 NULL, HFILL }},
1319 { &hf_mpeg_pes_vbv_delay,
1320 { "vbv-delay", "mpeg-pes.vbv_delay",
1321 FT_BYTES, BASE_NONE, NULL, 0,
1322 "BIT_STRING_SIZE_16", HFILL }},
1323 { &hf_mpeg_pes_pack_header,
1324 { "Pack header", "mpeg-pes.pack",
1325 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
1326 { &hf_mpeg_pes_scr,
1327 { "system clock reference (SCR)", "mpeg-pes.scr",
1328 FT_RELATIVE_TIME, BASE_NONE, NULL, 0, NULL, HFILL }},
1329 { &hf_mpeg_pes_program_mux_rate,
1330 { "PES program mux rate", "mpeg-pes.program-mux-rate",
1331 FT_UINT24, BASE_DEC, NULL, 0, NULL, HFILL }},
1332 { &hf_mpeg_pes_stuffing_length,
1333 { "PES stuffing length", "mpeg-pes.stuffing-length",
1334 FT_UINT8, BASE_DEC, NULL, 0x07, NULL, HFILL }},
1335 { &hf_mpeg_pes_stuffing,
1336 { "PES stuffing bytes", "mpeg-pes.stuffing",
1337 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1338 { &hf_mpeg_pes_extension,
1339 { "PES extension", "mpeg-pes.extension",
1340 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
1341 { &hf_mpeg_pes_header_data,
1342 { "PES header data", "mpeg-pes.header-data",
1343 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1344 { &hf_mpeg_pes_pts,
1345 { "presentation time stamp (PTS)", "mpeg-pes.pts",
1346 FT_RELATIVE_TIME, BASE_NONE, NULL, 0, NULL, HFILL }},
1347 { &hf_mpeg_pes_dts,
1348 { "decode time stamp (DTS)", "mpeg-pes.dts",
1349 FT_RELATIVE_TIME, BASE_NONE, NULL, 0, NULL, HFILL }},
1350 { &hf_mpeg_pes_escr,
1351 { "elementary stream clock reference (ESCR)", "mpeg-pes.escr",
1352 FT_RELATIVE_TIME, BASE_NONE, NULL, 0, NULL, HFILL }},
1353 { &hf_mpeg_pes_es_rate,
1354 { "elementary stream rate", "mpeg-pes.es-rate",
1355 FT_UINT24, BASE_DEC, NULL, 0x7ffe, NULL, HFILL }},
1356 { &hf_mpeg_pes_dsm_trick_mode,
1357 { "Trick mode", "mpeg-pes.trick-mode",
1358 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1359 { &hf_mpeg_pes_dsm_trick_mode_control,
1360 { "control", "mpeg-pes.trick-mode-control",
1361 FT_UINT8, BASE_HEX, VALS(mpeg_pes_TrickModeControl_vals), 0,
1362 "mpeg_pes trick mode control", HFILL }},
1363 { &hf_mpeg_pes_dsm_trick_mode_field_id,
1364 { "field id", "mpeg-pes.trick-mode-field-id",
1365 FT_UINT8, BASE_HEX, VALS(mpeg_pes_TrickModeFieldId_vals), 0,
1366 "mpeg_pes trick mode field id", HFILL }},
1367 { &hf_mpeg_pes_dsm_trick_mode_intra_slice_refresh,
1368 { "intra slice refresh", "mpeg-pes.trick-mode-intra-slice-refresh",
1369 FT_UINT8, BASE_HEX, VALS(mpeg_pes_TrickModeIntraSliceRefresh_vals), 0,
1370 "mpeg_pes trick mode intra slice refresh", HFILL }},
1371 { &hf_mpeg_pes_dsm_trick_mode_frequency_truncation,
1372 { "frequency truncation", "mpeg-pes.trick-mode-frequency-truncation",
1373 FT_UINT8, BASE_HEX, VALS(mpeg_pes_TrickModeFrequencyTruncation_vals), 0,
1374 "mpeg_pes trick mode frequency truncation", HFILL }},
1375 { &hf_mpeg_pes_dsm_trick_mode_rep_cntrl,
1376 { "rep cntrl", "mpeg-pes.trick-mode-rep-cntrl",
1377 FT_UINT8, BASE_HEX, NULL, 0, "mpeg_pes trick mode rep cntrl", HFILL }},
1378 { &hf_mpeg_pes_copy_info,
1379 { "copy info", "mpeg-pes.copy-info",
1380 FT_UINT8, BASE_DEC, NULL, 0x7f, NULL, HFILL }},
1381 { &hf_mpeg_pes_crc,
1382 { "CRC", "mpeg-pes.crc",
1383 FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }},
1384 { &hf_mpeg_pes_extension_flags,
1385 { "extension flags", "mpeg-pes.extension-flags",
1386 FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }},
1387 { &hf_mpeg_pes_private_data,
1388 { "private data", "mpeg-pes.private-data",
1389 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1390 { &hf_mpeg_pes_pack_length,
1391 { "pack length", "mpeg-pes.pack-length",
1392 FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
1393 { &hf_mpeg_pes_sequence,
1394 { "sequence", "mpeg-pes.sequence",
1395 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }},
1396 { &hf_mpeg_pes_pstd_buffer,
1397 { "P-STD buffer size", "mpeg-pes.pstd-buffer",
1398 FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }},
1399 { &hf_mpeg_pes_extension2,
1400 { "extension2", "mpeg-pes.extension2",
1401 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }},
1402 { &hf_mpeg_pes_padding,
1403 { "PES padding", "mpeg-pes.padding",
1404 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1405 { &hf_mpeg_pes_data,
1406 { "PES data", "mpeg-pes.data",
1407 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1408 { &hf_mpeg_video_sequence_header,
1409 { "MPEG sequence header", "mpeg-video.sequence",
1410 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
1411 { &hf_mpeg_video_sequence_extension,
1412 { "MPEG sequence extension", "mpeg-video.sequence-ext",
1413 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
1414 { &hf_mpeg_video_group_of_pictures,
1415 { "MPEG group of pictures", "mpeg-video.gop",
1416 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
1417 { &hf_mpeg_video_picture,
1418 { "MPEG picture", "mpeg-video.picture",
1419 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
1420 { &hf_mpeg_video_quantization_matrix,
1421 { "MPEG quantization matrix", "mpeg-video.quant",
1422 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1423 { &hf_mpeg_video_data,
1424 { "MPEG picture data", "mpeg-video.data",
1425 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1428 static int *ett[] = {
1429 &ett_mpeg_pes_PES,
1430 &ett_mpeg_pes_Stream,
1431 &ett_mpeg_pes_Sequence_header,
1432 &ett_mpeg_pes_Sequence_extension,
1433 &ett_mpeg_pes_Group_of_pictures,
1434 &ett_mpeg_pes_Picture,
1435 &ett_mpeg_pes_pack_header,
1436 &ett_mpeg_pes_header_data,
1437 &ett_mpeg_pes_trick_mode
1440 static ei_register_info ei_pes[] = {
1441 { &ei_mpeg_pes_length_zero, { "mpeg-pes.length.zero", PI_PROTOCOL, PI_WARN, "Length 0 is allowed only in packets whose payload is from a video elementary stream", EXPFILL }},
1444 expert_module_t* expert_mpeg_pes;
1446 proto_mpeg = proto_register_protocol("Moving Picture Experts Group", "MPEG", "mpeg");
1447 mpeg_handle = register_dissector("mpeg", dissect_mpeg, proto_mpeg);
1448 heur_subdissector_list = register_heur_dissector_list_with_description("mpeg", "MPEG payload", proto_mpeg);
1450 proto_mpeg_pes = proto_register_protocol("Packetized Elementary Stream", "MPEG PES", "mpeg-pes");
1451 proto_register_field_array(proto_mpeg_pes, hf, array_length(hf));
1452 proto_register_subtree_array(ett, array_length(ett));
1453 register_dissector("mpeg-pes", dissect_mpeg_pes, proto_mpeg_pes);
1454 expert_mpeg_pes = expert_register_protocol(proto_mpeg_pes);
1455 expert_register_field_array(expert_mpeg_pes, ei_pes, array_length(ei_pes));
1457 stream_type_table = register_dissector_table("mpeg-pes.stream", "MPEG PES stream type", proto_mpeg_pes, FT_UINT8, BASE_HEX);
1459 mpeg_pes_follow_tap = register_tap("mpeg-pes_follow");
1461 /* MPEG2 TS is sometimes carried on UDP or RTP on UDP, so using the UDP
1462 * address filter is better than nothing for tshark. */
1463 register_follow_stream(proto_mpeg_pes, "mpeg-pes_follow", mp2t_follow_conv_filter, mp2t_follow_index_filter, udp_follow_address_filter, udp_port_to_display, follow_tvb_tap_listener, mp2t_get_stream_count, mp2t_get_sub_stream_id);
1466 void
1467 proto_reg_handoff_mpeg_pes(void)
1469 dissector_add_uint("wtap_encap", WTAP_ENCAP_MPEG, mpeg_handle);
1470 heur_dissector_add("mpeg", dissect_mpeg_pes_heur, "MPEG PES", "mpeg_pes", proto_mpeg_pes, HEURISTIC_ENABLE);
1472 dissector_add_uint("mpeg-pes.stream", 0x1B, find_dissector_add_dependency("h264_bytestream", proto_mpeg_pes));
1473 dissector_add_uint("mpeg-pes.stream", 0x24, find_dissector_add_dependency("h265_bytestream", proto_mpeg_pes));