Switch a bunch of dissectors over to using tvb_new_subset_remaining()
[obnox/wireshark/wip.git] / epan / dissectors / packet-mpeg-pes.c
1 /* Do not modify this file.                                                   */
2 /* It is created automatically by the ASN.1 to Wireshark dissector compiler   */
3 /* packet-mpeg-pes.c                                                          */
4 /* ../../tools/asn2wrs.py -p mpeg-pes -c ./mpeg-pes.cnf -s ./packet-mpeg-pes-template -D . mpeg-pes.asn */
5
6 /* Input file: packet-mpeg-pes-template.c */
7
8 #line 1 "packet-mpeg-pes-template.c"
9 /* MPEG Packetized Elementary Stream (PES) packet decoder.
10  * Written by Shaun Jackman <sjackman@gmail.com>.
11  * Copyright 2007 Shaun Jackman
12  *
13  * $Id$
14  *
15  * Wireshark - Network traffic analyzer
16  * By Gerald Combs <gerald@wireshark.org>
17  *
18  * This program is free software; you can redistribute it and/or
19  * modify it under the terms of the GNU General Public License
20  * as published by the Free Software Foundation; either version 2
21  * of the License, or (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
31  */
32
33 #ifdef HAVE_CONFIG_H
34 # include "config.h"
35 #endif
36
37 #include <stdio.h>
38 #include <string.h>
39
40 #include <glib.h>
41
42 #include <epan/packet.h>
43 #include <epan/asn1.h>
44
45 #include "packet-per.h"
46
47
48 /*--- Included file: packet-mpeg-pes-hf.c ---*/
49 #line 1 "packet-mpeg-pes-hf.c"
50 static int hf_mpeg_pes_prefix = -1;               /* OCTET_STRING_SIZE_3 */
51 static int hf_mpeg_pes_stream = -1;               /* T_stream */
52 static int hf_mpeg_pes_length = -1;               /* INTEGER_0_65535 */
53 static int hf_mpeg_pes_must_be_one = -1;          /* BOOLEAN */
54 static int hf_mpeg_pes_must_be_zero = -1;         /* BOOLEAN */
55 static int hf_mpeg_pes_scrambling_control = -1;   /* T_scrambling_control */
56 static int hf_mpeg_pes_priority = -1;             /* BOOLEAN */
57 static int hf_mpeg_pes_data_alignment = -1;       /* BOOLEAN */
58 static int hf_mpeg_pes_copyright = -1;            /* BOOLEAN */
59 static int hf_mpeg_pes_original = -1;             /* BOOLEAN */
60 static int hf_mpeg_pes_pts_flag = -1;             /* BOOLEAN */
61 static int hf_mpeg_pes_dts_flag = -1;             /* BOOLEAN */
62 static int hf_mpeg_pes_escr_flag = -1;            /* BOOLEAN */
63 static int hf_mpeg_pes_es_rate_flag = -1;         /* BOOLEAN */
64 static int hf_mpeg_pes_dsm_trick_mode_flag = -1;  /* BOOLEAN */
65 static int hf_mpeg_pes_additional_copy_info_flag = -1;  /* BOOLEAN */
66 static int hf_mpeg_pes_crc_flag = -1;             /* BOOLEAN */
67 static int hf_mpeg_pes_extension_flag = -1;       /* BOOLEAN */
68 static int hf_mpeg_pes_header_data_length = -1;   /* INTEGER_0_255 */
69 static int hf_mpeg_pes_horizontal_size = -1;      /* BIT_STRING_SIZE_12 */
70 static int hf_mpeg_pes_vertical_size = -1;        /* BIT_STRING_SIZE_12 */
71 static int hf_mpeg_pes_aspect_ratio = -1;         /* T_aspect_ratio */
72 static int hf_mpeg_pes_frame_rate = -1;           /* T_frame_rate */
73 static int hf_mpeg_pes_bit_rate = -1;             /* BIT_STRING_SIZE_18 */
74 static int hf_mpeg_pes_vbv_buffer_size = -1;      /* BIT_STRING_SIZE_10 */
75 static int hf_mpeg_pes_constrained_parameters_flag = -1;  /* BOOLEAN */
76 static int hf_mpeg_pes_load_intra_quantiser_matrix = -1;  /* BOOLEAN */
77 static int hf_mpeg_pes_load_non_intra_quantiser_matrix = -1;  /* BOOLEAN */
78 static int hf_mpeg_pes_must_be_0001 = -1;         /* BIT_STRING_SIZE_4 */
79 static int hf_mpeg_pes_profile_and_level = -1;    /* INTEGER_0_255 */
80 static int hf_mpeg_pes_progressive_sequence = -1;  /* BOOLEAN */
81 static int hf_mpeg_pes_chroma_format = -1;        /* INTEGER_0_3 */
82 static int hf_mpeg_pes_horizontal_size_extension = -1;  /* INTEGER_0_3 */
83 static int hf_mpeg_pes_vertical_size_extension = -1;  /* INTEGER_0_3 */
84 static int hf_mpeg_pes_bit_rate_extension = -1;   /* BIT_STRING_SIZE_12 */
85 static int hf_mpeg_pes_vbv_buffer_size_extension = -1;  /* INTEGER_0_255 */
86 static int hf_mpeg_pes_low_delay = -1;            /* BOOLEAN */
87 static int hf_mpeg_pes_frame_rate_extension_n = -1;  /* INTEGER_0_3 */
88 static int hf_mpeg_pes_frame_rate_extension_d = -1;  /* INTEGER_0_3 */
89 static int hf_mpeg_pes_drop_frame_flag = -1;      /* BOOLEAN */
90 static int hf_mpeg_pes_hour = -1;                 /* INTEGER_0_32 */
91 static int hf_mpeg_pes_minute = -1;               /* INTEGER_0_64 */
92 static int hf_mpeg_pes_second = -1;               /* INTEGER_0_64 */
93 static int hf_mpeg_pes_frame = -1;                /* INTEGER_0_64 */
94 static int hf_mpeg_pes_closed_gop = -1;           /* BOOLEAN */
95 static int hf_mpeg_pes_broken_gop = -1;           /* BOOLEAN */
96 static int hf_mpeg_pes_must_be_zero_01 = -1;      /* BIT_STRING_SIZE_5 */
97 static int hf_mpeg_pes_temporal_sequence_number = -1;  /* BIT_STRING_SIZE_10 */
98 static int hf_mpeg_pes_frame_type = -1;           /* T_frame_type */
99 static int hf_mpeg_pes_vbv_delay = -1;            /* BIT_STRING_SIZE_16 */
100
101 /*--- End of included file: packet-mpeg-pes-hf.c ---*/
102 #line 40 "packet-mpeg-pes-template.c"
103
104 /*--- Included file: packet-mpeg-pes-ett.c ---*/
105 #line 1 "packet-mpeg-pes-ett.c"
106 static gint ett_mpeg_pes_PES = -1;
107 static gint ett_mpeg_pes_Stream = -1;
108 static gint ett_mpeg_pes_Sequence_header = -1;
109 static gint ett_mpeg_pes_Sequence_extension = -1;
110 static gint ett_mpeg_pes_Group_of_pictures = -1;
111 static gint ett_mpeg_pes_Picture = -1;
112
113 /*--- End of included file: packet-mpeg-pes-ett.c ---*/
114 #line 41 "packet-mpeg-pes-template.c"
115
116 /*--- Included file: packet-mpeg-pes-fn.c ---*/
117 #line 1 "packet-mpeg-pes-fn.c"
118
119
120 static int
121 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_) {
122   offset = dissect_per_octet_string(tvb, offset, actx, tree, hf_index,
123                                        3, 3, FALSE, NULL);
124
125   return offset;
126 }
127
128
129 static const value_string mpeg_pes_T_stream_vals[] = {
130   {   0, "picture" },
131   { 179, "sequence-header" },
132   { 181, "sequence-header-extension" },
133   { 184, "group-of-pictures" },
134   { 185, "program-end" },
135   { 186, "pack-header" },
136   { 187, "system-header" },
137   { 188, "program-stream-map" },
138   { 189, "private-stream-1" },
139   { 190, "padding-stream" },
140   { 191, "private-stream-2" },
141   { 192, "audio-stream" },
142   { 224, "video-stream" },
143   { 0, NULL }
144 };
145
146
147 static int
148 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_) {
149   offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
150                                                             0U, 255U, NULL, FALSE);
151
152   return offset;
153 }
154
155
156 static const per_sequence_t PES_sequence[] = {
157   { &hf_mpeg_pes_prefix     , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_OCTET_STRING_SIZE_3 },
158   { &hf_mpeg_pes_stream     , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_T_stream },
159   { NULL, 0, 0, NULL }
160 };
161
162 static int
163 dissect_mpeg_pes_PES(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
164   offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
165                                    ett_mpeg_pes_PES, PES_sequence);
166
167   return offset;
168 }
169
170
171
172 static int
173 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_) {
174   offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
175                                                             0U, 65535U, NULL, FALSE);
176
177   return offset;
178 }
179
180
181
182 static int
183 dissect_mpeg_pes_BOOLEAN(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
184   offset = dissect_per_boolean(tvb, offset, actx, tree, hf_index, NULL);
185
186   return offset;
187 }
188
189
190 static const value_string mpeg_pes_T_scrambling_control_vals[] = {
191   {   0, "not-scrambled" },
192   { 0, NULL }
193 };
194
195
196 static int
197 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_) {
198   offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
199                                                             0U, 3U, NULL, FALSE);
200
201   return offset;
202 }
203
204
205
206 static int
207 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_) {
208   offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
209                                                             0U, 255U, NULL, FALSE);
210
211   return offset;
212 }
213
214
215 static const per_sequence_t Stream_sequence[] = {
216   { &hf_mpeg_pes_length     , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_65535 },
217   { &hf_mpeg_pes_must_be_one, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
218   { &hf_mpeg_pes_must_be_zero, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
219   { &hf_mpeg_pes_scrambling_control, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_T_scrambling_control },
220   { &hf_mpeg_pes_priority   , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
221   { &hf_mpeg_pes_data_alignment, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
222   { &hf_mpeg_pes_copyright  , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
223   { &hf_mpeg_pes_original   , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
224   { &hf_mpeg_pes_pts_flag   , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
225   { &hf_mpeg_pes_dts_flag   , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
226   { &hf_mpeg_pes_escr_flag  , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
227   { &hf_mpeg_pes_es_rate_flag, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
228   { &hf_mpeg_pes_dsm_trick_mode_flag, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
229   { &hf_mpeg_pes_additional_copy_info_flag, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
230   { &hf_mpeg_pes_crc_flag   , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
231   { &hf_mpeg_pes_extension_flag, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
232   { &hf_mpeg_pes_header_data_length, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_255 },
233   { NULL, 0, 0, NULL }
234 };
235
236 static int
237 dissect_mpeg_pes_Stream(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
238   offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
239                                    ett_mpeg_pes_Stream, Stream_sequence);
240
241   return offset;
242 }
243
244
245
246 static int
247 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_) {
248   offset = dissect_per_bit_string(tvb, offset, actx, tree, hf_index,
249                                      12, 12, FALSE, NULL);
250
251   return offset;
252 }
253
254
255 static const value_string mpeg_pes_T_aspect_ratio_vals[] = {
256   {   1, "aspect-1to1" },
257   {   2, "aspect-4to3" },
258   {   3, "aspect-16to9" },
259   {   4, "aspect-2-21to1" },
260   { 0, NULL }
261 };
262
263
264 static int
265 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_) {
266   offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
267                                                             0U, 15U, NULL, FALSE);
268
269   return offset;
270 }
271
272
273 static const value_string mpeg_pes_T_frame_rate_vals[] = {
274   {   0, "reserved" },
275   { 23976, "fr" },
276   { 24000, "fr" },
277   { 25000, "fr" },
278   { 29970, "fr" },
279   { 30000, "fr" },
280   { 50000, "fr" },
281   { 59940, "fr" },
282   { 60000, "fr" },
283   { 0, NULL }
284 };
285
286 static guint32 T_frame_rate_value_map[9+0] = {0, 23976, 24000, 25000, 29970, 30000, 50000, 59940, 60000};
287
288 static int
289 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_) {
290   offset = dissect_per_enumerated(tvb, offset, actx, tree, hf_index,
291                                      9, NULL, FALSE, 0, T_frame_rate_value_map);
292
293   return offset;
294 }
295
296
297
298 static int
299 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_) {
300   offset = dissect_per_bit_string(tvb, offset, actx, tree, hf_index,
301                                      18, 18, FALSE, NULL);
302
303   return offset;
304 }
305
306
307
308 static int
309 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_) {
310   offset = dissect_per_bit_string(tvb, offset, actx, tree, hf_index,
311                                      10, 10, FALSE, NULL);
312
313   return offset;
314 }
315
316
317 static const per_sequence_t Sequence_header_sequence[] = {
318   { &hf_mpeg_pes_horizontal_size, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_12 },
319   { &hf_mpeg_pes_vertical_size, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_12 },
320   { &hf_mpeg_pes_aspect_ratio, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_T_aspect_ratio },
321   { &hf_mpeg_pes_frame_rate , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_T_frame_rate },
322   { &hf_mpeg_pes_bit_rate   , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_18 },
323   { &hf_mpeg_pes_must_be_one, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
324   { &hf_mpeg_pes_vbv_buffer_size, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_10 },
325   { &hf_mpeg_pes_constrained_parameters_flag, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
326   { &hf_mpeg_pes_load_intra_quantiser_matrix, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
327   { &hf_mpeg_pes_load_non_intra_quantiser_matrix, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
328   { NULL, 0, 0, NULL }
329 };
330
331 static int
332 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_) {
333   offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
334                                    ett_mpeg_pes_Sequence_header, Sequence_header_sequence);
335
336   return offset;
337 }
338
339
340
341 static int
342 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_) {
343   offset = dissect_per_bit_string(tvb, offset, actx, tree, hf_index,
344                                      4, 4, FALSE, NULL);
345
346   return offset;
347 }
348
349
350
351 static int
352 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_) {
353   offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
354                                                             0U, 3U, NULL, FALSE);
355
356   return offset;
357 }
358
359
360 static const per_sequence_t Sequence_extension_sequence[] = {
361   { &hf_mpeg_pes_must_be_0001, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_4 },
362   { &hf_mpeg_pes_profile_and_level, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_255 },
363   { &hf_mpeg_pes_progressive_sequence, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
364   { &hf_mpeg_pes_chroma_format, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_3 },
365   { &hf_mpeg_pes_horizontal_size_extension, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_3 },
366   { &hf_mpeg_pes_vertical_size_extension, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_3 },
367   { &hf_mpeg_pes_bit_rate_extension, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_12 },
368   { &hf_mpeg_pes_must_be_one, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
369   { &hf_mpeg_pes_vbv_buffer_size_extension, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_255 },
370   { &hf_mpeg_pes_low_delay  , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
371   { &hf_mpeg_pes_frame_rate_extension_n, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_3 },
372   { &hf_mpeg_pes_frame_rate_extension_d, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_3 },
373   { NULL, 0, 0, NULL }
374 };
375
376 static int
377 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_) {
378   offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
379                                    ett_mpeg_pes_Sequence_extension, Sequence_extension_sequence);
380
381   return offset;
382 }
383
384
385
386 static int
387 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_) {
388   offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
389                                                             0U, 32U, NULL, FALSE);
390
391   return offset;
392 }
393
394
395
396 static int
397 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_) {
398   offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
399                                                             0U, 64U, NULL, FALSE);
400
401   return offset;
402 }
403
404
405
406 static int
407 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_) {
408   offset = dissect_per_bit_string(tvb, offset, actx, tree, hf_index,
409                                      5, 5, FALSE, NULL);
410
411   return offset;
412 }
413
414
415 static const per_sequence_t Group_of_pictures_sequence[] = {
416   { &hf_mpeg_pes_drop_frame_flag, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
417   { &hf_mpeg_pes_hour       , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_32 },
418   { &hf_mpeg_pes_minute     , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_64 },
419   { &hf_mpeg_pes_must_be_one, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
420   { &hf_mpeg_pes_second     , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_64 },
421   { &hf_mpeg_pes_frame      , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_INTEGER_0_64 },
422   { &hf_mpeg_pes_closed_gop , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
423   { &hf_mpeg_pes_broken_gop , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BOOLEAN },
424   { &hf_mpeg_pes_must_be_zero_01, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_5 },
425   { NULL, 0, 0, NULL }
426 };
427
428 static int
429 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_) {
430   offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
431                                    ett_mpeg_pes_Group_of_pictures, Group_of_pictures_sequence);
432
433   return offset;
434 }
435
436
437 static const value_string mpeg_pes_T_frame_type_vals[] = {
438   {   1, "i-frame" },
439   {   2, "p-frame" },
440   {   3, "b-frame" },
441   {   4, "d-frame" },
442   { 0, NULL }
443 };
444
445
446 static int
447 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_) {
448   offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
449                                                             0U, 7U, NULL, FALSE);
450
451   return offset;
452 }
453
454
455
456 static int
457 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_) {
458   offset = dissect_per_bit_string(tvb, offset, actx, tree, hf_index,
459                                      16, 16, FALSE, NULL);
460
461   return offset;
462 }
463
464
465 static const per_sequence_t Picture_sequence[] = {
466   { &hf_mpeg_pes_temporal_sequence_number, ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_10 },
467   { &hf_mpeg_pes_frame_type , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_T_frame_type },
468   { &hf_mpeg_pes_vbv_delay  , ASN1_NO_EXTENSIONS     , ASN1_NOT_OPTIONAL, dissect_mpeg_pes_BIT_STRING_SIZE_16 },
469   { NULL, 0, 0, NULL }
470 };
471
472 static int
473 dissect_mpeg_pes_Picture(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
474   offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
475                                    ett_mpeg_pes_Picture, Picture_sequence);
476
477   return offset;
478 }
479
480
481 /*--- End of included file: packet-mpeg-pes-fn.c ---*/
482 #line 42 "packet-mpeg-pes-template.c"
483
484 static int proto_mpeg = -1;
485 static int proto_mpeg_pes = -1;
486
487 static int ett_mpeg_pes_pack_header = -1;
488 static int ett_mpeg_pes_header_data = -1;
489
490 static int hf_mpeg_pes_pack_header = -1;
491 static int hf_mpeg_pes_scr = -1;
492 static int hf_mpeg_pes_program_mux_rate = -1;
493 static int hf_mpeg_pes_stuffing_length = -1;
494 static int hf_mpeg_pes_stuffing = -1;
495 static int hf_mpeg_pes_extension = -1;
496 static int hf_mpeg_pes_header_data = -1;
497 static int hf_mpeg_pes_pts = -1;
498 static int hf_mpeg_pes_dts = -1;
499 static int hf_mpeg_pes_escr = -1;
500 static int hf_mpeg_pes_es_rate = -1;
501 static int hf_mpeg_pes_copy_info = -1;
502 static int hf_mpeg_pes_crc = -1;
503 static int hf_mpeg_pes_extension_flags = -1;
504 static int hf_mpeg_pes_private_data = -1;
505 static int hf_mpeg_pes_pack_length = -1;
506 static int hf_mpeg_pes_sequence = -1;
507 static int hf_mpeg_pes_pstd_buffer = -1;
508 static int hf_mpeg_pes_extension2 = -1;
509 static int hf_mpeg_pes_padding = -1;
510 static int hf_mpeg_pes_data = -1;
511
512 static int hf_mpeg_video_sequence_header = -1;
513 static int hf_mpeg_video_sequence_extension = -1;
514 static int hf_mpeg_video_group_of_pictures = -1;
515 static int hf_mpeg_video_picture = -1;
516 static int hf_mpeg_video_quantization_matrix = -1;
517 static int hf_mpeg_video_data = -1;
518
519 enum { PES_PREFIX = 1 };
520
521 enum {
522         STREAM_PICTURE = 0x00,
523         STREAM_SEQUENCE = 0xb3,
524         STREAM_SEQUENCE_EXTENSION = 0xb5,
525         STREAM_GOP = 0xb8,
526         STREAM_END = 0xb9,
527         STREAM_PACK = 0xba,
528         STREAM_SYSTEM = 0xbb,
529         STREAM_PROGRAM = 0xbc,
530         STREAM_PRIVATE1 = 0xbd,
531         STREAM_PADDING = 0xbe,
532         STREAM_PRIVATE2 = 0xbf,
533         STREAM_AUDIO = 0xc0,
534         STREAM_VIDEO = 0xe0
535 };
536
537 enum {
538         PTS_FLAG = 0x80,
539         DTS_FLAG = 0x40,
540         ESCR_FLAG = 0x20,
541         ES_RATE_FLAG = 0x10,
542         DSM_TRICK_MODE_FLAG = 0x08,
543         COPY_INFO_FLAG = 0x04,
544         CRC_FLAG = 0x02,
545         EXTENSION_FLAG = 0x01
546 };
547
548 enum {
549         PRIVATE_DATA_FLAG = 0x80,
550         PACK_LENGTH_FLAG = 0x40,
551         SEQUENCE_FLAG = 0x20,
552         PSTD_BUFFER_FLAG = 0x10,
553         MUST_BE_ONES = 0x07,
554         EXTENSION_FLAG2 = 0x01
555 };
556
557 static guint64 tvb_get_ntoh40(tvbuff_t *tvb, unsigned offset)
558 {
559         return (guint64)tvb_get_guint8(tvb, offset) << 32
560                 | tvb_get_ntohl(tvb, offset + 1);
561 }
562
563 static guint64 tvb_get_ntoh48(tvbuff_t *tvb, unsigned offset)
564 {
565         return (guint64)tvb_get_ntohs(tvb, offset) << 32
566                 | tvb_get_ntohl(tvb, offset + 2);
567 }
568
569 #define TSHZ 90000
570
571 static guint64 decode_time_stamp(tvbuff_t *tvb, unsigned offset, nstime_t *nst)
572 {
573         guint64 bytes = tvb_get_ntoh40(tvb, offset);
574         guint64 ts =
575                 (bytes >> 33 & 0x0007) << 30 |
576                 (bytes >> 17 & 0x7fff) << 15 |
577                 (bytes >>  1 & 0x7fff) << 0;
578         unsigned rem = (unsigned)(ts % TSHZ);
579         nst->secs = (time_t)(ts / TSHZ);
580         nst->nsecs = (int)(G_GINT64_CONSTANT(1000000000) * rem / TSHZ);
581         return ts;
582 }
583
584 #define SCRHZ 27000000
585
586 static guint64 decode_clock_reference(tvbuff_t *tvb, unsigned offset,
587                 nstime_t *nst)
588 {
589         guint64 bytes = tvb_get_ntoh48(tvb, offset);
590         guint64 ts =
591                 (bytes >> 43 & 0x0007) << 30 |
592                 (bytes >> 27 & 0x7fff) << 15 |
593                 (bytes >> 11 & 0x7fff) << 0;
594         unsigned ext = (unsigned)((bytes >> 1) & 0x1ff);
595         guint64 cr = 300 * ts + ext;
596         unsigned rem = (unsigned)(cr % SCRHZ);
597         nst->secs = (time_t)(cr / SCRHZ);
598         nst->nsecs = (int)(G_GINT64_CONSTANT(1000000000) * rem / SCRHZ);
599         return cr;
600 }
601
602 static void
603 dissect_mpeg_pes_header_data(tvbuff_t *tvb, packet_info *pinfo,
604                 proto_tree *root, unsigned flags)
605 {
606         proto_item *item = proto_tree_add_item(root, hf_mpeg_pes_header_data, tvb,
607                         0, -1, FALSE);
608         proto_tree *tree = proto_item_add_subtree(item, ett_mpeg_pes_header_data);
609
610         unsigned offset = 0;
611         if (flags & PTS_FLAG) {
612                 nstime_t nst;
613                 decode_time_stamp(tvb, offset, &nst);
614                 proto_tree_add_time(tree, hf_mpeg_pes_pts, tvb,
615                                 offset, 5, &nst);
616                 offset += 5;
617
618                 if (check_col(pinfo->cinfo, COL_DEF_DST)) {
619                         SET_ADDRESS(&pinfo->dst, AT_NONE, 0, NULL);
620                         col_add_fstr(pinfo->cinfo, COL_DEF_DST,
621                                         "PTS %ld.%09u",
622                                         (long) nst.secs, nst.nsecs);
623                 }
624         }
625         if (flags & DTS_FLAG) {
626                 nstime_t nst;
627                 decode_time_stamp(tvb, offset, &nst);
628                 proto_tree_add_time(tree, hf_mpeg_pes_dts, tvb,
629                                 offset, 5, &nst);
630                 offset += 5;
631
632                 if (check_col(pinfo->cinfo, COL_DEF_SRC)) {
633                         SET_ADDRESS(&pinfo->src, AT_NONE, 0, NULL);
634                         col_add_fstr(pinfo->cinfo, COL_DEF_SRC,
635                                         "DTS %ld.%09u",
636                                         (long) nst.secs, nst.nsecs);
637                 }
638         }
639         if (flags & ESCR_FLAG) {
640                 nstime_t nst;
641                 decode_clock_reference(tvb, offset, &nst);
642                 proto_tree_add_time(tree, hf_mpeg_pes_escr, tvb,
643                                 offset, 6, &nst);
644                 offset += 6;
645         }
646         if (flags & ES_RATE_FLAG) {
647                 unsigned es_rate = (tvb_get_ntohs(tvb, offset) >> 1 & 0x3fff) * 50;
648                 proto_tree_add_uint(tree, hf_mpeg_pes_es_rate, tvb,
649                                 offset, 3, es_rate);
650                 offset += 3;
651         }
652         if (flags & COPY_INFO_FLAG) {
653                 proto_tree_add_item(tree, hf_mpeg_pes_copy_info, tvb,
654                                 offset, 1, FALSE);
655                 offset++;
656         }
657         if (flags & CRC_FLAG) {
658                 proto_tree_add_item(tree, hf_mpeg_pes_crc, tvb,
659                                 offset, 2, FALSE);
660                 offset += 2;
661         }
662
663         if (flags & EXTENSION_FLAG) {
664                 int flags2 = tvb_get_guint8(tvb, offset);
665                 proto_tree_add_item(tree, hf_mpeg_pes_extension_flags, tvb,
666                                 offset, 1, FALSE);
667                 offset++;
668
669                 if (flags2 & PRIVATE_DATA_FLAG) {
670                         proto_tree_add_item(tree, hf_mpeg_pes_private_data, tvb,
671                                         offset, 2, FALSE);
672                         offset += 2;
673                 }
674                 if (flags2 & PACK_LENGTH_FLAG) {
675                         proto_tree_add_item(tree, hf_mpeg_pes_pack_length, tvb,
676                                         offset, 1, FALSE);
677                         offset++;
678                 }
679                 if (flags2 & SEQUENCE_FLAG) {
680                         proto_tree_add_item(tree, hf_mpeg_pes_sequence, tvb,
681                                         offset, 2, FALSE);
682                         offset += 2;
683                 }
684                 if (flags2 & PSTD_BUFFER_FLAG) {
685                         unsigned pstd = tvb_get_ntohs(tvb, offset);
686                         proto_tree_add_uint(tree, hf_mpeg_pes_pstd_buffer, tvb,
687                                         offset, 2, (pstd & 0x2000 ? 1024 : 128) * (pstd & 0x1ff));
688                         offset += 2;
689                 }
690                 if (flags2 & EXTENSION_FLAG2) {
691                         proto_tree_add_item(tree, hf_mpeg_pes_extension2, tvb,
692                                         offset, 2, FALSE);
693                         offset += 2;
694                 }
695         }
696 }
697
698 static unsigned
699 dissect_mpeg_pes_pack_header(tvbuff_t *tvb, unsigned offset,
700                 packet_info *pinfo, proto_tree *root)
701 {
702         unsigned program_mux_rate, stuffing_length;
703
704         proto_item *item = proto_tree_add_item(root, hf_mpeg_pes_pack_header, tvb,
705                         offset / 8, 10, FALSE);
706         proto_tree *tree = proto_item_add_subtree(item, ett_mpeg_pes_pack_header);
707
708         nstime_t nst;
709         decode_clock_reference(tvb, offset / 8, &nst);
710         proto_tree_add_time(tree, hf_mpeg_pes_scr, tvb, offset / 8, 6, &nst);
711         offset += 6 * 8;
712
713         program_mux_rate = (tvb_get_ntoh24(tvb, offset / 8) >> 2) * 50;
714         proto_tree_add_uint(tree, hf_mpeg_pes_program_mux_rate, tvb, offset / 8, 3,
715                         program_mux_rate);
716         offset += 3 * 8;
717
718         if (check_col(pinfo->cinfo, COL_DEF_SRC)) {
719                 SET_ADDRESS(&pinfo->src, AT_NONE, 0, NULL);
720                 col_add_fstr(pinfo->cinfo, COL_DEF_SRC, "%u B/s", program_mux_rate);
721         }
722
723         stuffing_length = tvb_get_guint8(tvb, offset / 8) & 0x07;
724         proto_tree_add_item(tree, hf_mpeg_pes_stuffing_length, tvb,
725                         offset / 8, 1, FALSE);
726         offset += 1 * 8;
727
728         if (stuffing_length > 0) {
729                 proto_tree_add_item(tree, hf_mpeg_pes_stuffing, tvb,
730                                 offset / 8, stuffing_length, FALSE);
731                 offset += stuffing_length * 8;
732         }
733
734         return offset;
735 }
736
737 static void
738 dissect_mpeg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
739
740 static gboolean
741 dissect_mpeg_pes(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
742 {
743         int prefix;
744         int stream;
745         asn1_ctx_t asn1_ctx;
746         unsigned offset = 0;
747
748         if (!tvb_bytes_exist(tvb, 0, 3))
749                 return FALSE;   /* not enough bytes for a PES prefix */
750
751         prefix = tvb_get_ntoh24(tvb, 0);
752         if (prefix != PES_PREFIX)
753                 return FALSE;
754         col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPEG PES");
755         col_clear(pinfo->cinfo, COL_INFO);
756
757         stream = tvb_get_guint8(tvb, 3);
758         if (check_col(pinfo->cinfo, COL_INFO)) {
759                 const char *s = match_strval(stream, mpeg_pes_T_stream_vals);
760                 if (s != NULL)
761                         col_set_str(pinfo->cinfo, COL_INFO, s);
762         }
763
764 #if 0
765         if (tree == NULL)
766                 return TRUE;
767 #endif
768         asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, TRUE, pinfo);
769         offset = dissect_mpeg_pes_PES(tvb, offset, &asn1_ctx,
770                         tree, proto_mpeg_pes);
771
772         if (stream == STREAM_PICTURE) {
773                 int frame_type;
774
775                 frame_type = tvb_get_guint8(tvb, 5) >> 3 & 0x07;
776                 if (check_col(pinfo->cinfo, COL_INFO)) {
777                         const char *s = match_strval(frame_type,
778                                         mpeg_pes_T_frame_type_vals);
779                         if (s != NULL)
780                                 col_set_str(pinfo->cinfo, COL_INFO, s);
781                 }
782
783                 offset = dissect_mpeg_pes_Picture(tvb, offset, &asn1_ctx,
784                                 tree, hf_mpeg_video_picture);
785                 proto_tree_add_item(tree, hf_mpeg_video_data, tvb,
786                                 offset / 8, -1, FALSE);
787         } else if (stream == STREAM_SEQUENCE) {
788                 tvbuff_t *es;
789
790                 offset = dissect_mpeg_pes_Sequence_header(tvb, offset, &asn1_ctx,
791                                 tree, hf_mpeg_video_sequence_header);
792
793                 proto_tree_add_item(tree, hf_mpeg_video_quantization_matrix, tvb,
794                                 offset / 8, 64, FALSE);
795                 offset += 64 * 8;
796
797                 es = tvb_new_subset_remaining(tvb, offset / 8);
798                 dissect_mpeg_pes(es, pinfo, tree);
799         } else if (stream == STREAM_SEQUENCE_EXTENSION) {
800                 tvbuff_t *es;
801
802                 offset = dissect_mpeg_pes_Sequence_extension(tvb, offset, &asn1_ctx,
803                                 tree, hf_mpeg_video_sequence_extension);
804
805                 es = tvb_new_subset_remaining(tvb, offset / 8);
806                 dissect_mpeg_pes(es, pinfo, tree);
807         } else if (stream == STREAM_GOP) {
808                 tvbuff_t *es;
809
810                 offset = dissect_mpeg_pes_Group_of_pictures(tvb, offset, &asn1_ctx,
811                                 tree, hf_mpeg_video_group_of_pictures);
812
813                 es = tvb_new_subset_remaining(tvb, offset / 8);
814                 dissect_mpeg_pes(es, pinfo, tree);
815         } else if (stream == STREAM_PACK) {
816                 if (tvb_get_guint8(tvb, offset / 8) >> 6 == 1) {
817                         offset = dissect_mpeg_pes_pack_header(tvb, offset, pinfo, tree);
818                 } else {
819                         proto_tree_add_item(tree, hf_mpeg_pes_data, tvb,
820                                         offset / 8, 8, FALSE);
821                         offset += 8 * 8;
822                 }
823         } else if (stream == STREAM_SYSTEM || stream == STREAM_PRIVATE2) {
824                 unsigned data_length = tvb_get_ntohs(tvb, offset / 8);
825                 proto_tree_add_item(tree, hf_mpeg_pes_length, tvb,
826                                 offset / 8, 2, FALSE);
827                 offset += 2 * 8;
828
829                 proto_tree_add_item(tree, hf_mpeg_pes_data, tvb,
830                                 offset / 8, data_length, FALSE);
831         } else if (stream == STREAM_PADDING) {
832                 unsigned padding_length = tvb_get_ntohs(tvb, offset / 8);
833                 proto_tree_add_item(tree, hf_mpeg_pes_length, tvb,
834                                 offset / 8, 2, FALSE);
835                 offset += 2 * 8;
836
837                 proto_tree_add_item(tree, hf_mpeg_pes_padding, tvb,
838                                 offset / 8, padding_length, FALSE);
839         } else if (stream == STREAM_PRIVATE1
840                         || stream >= STREAM_AUDIO) {
841                 int length = tvb_get_ntohs(tvb, 4);
842
843                 if ((tvb_get_guint8(tvb, 6) & 0xc0) == 0x80) {
844                         int header_length;
845                         tvbuff_t *es;
846
847                         offset = dissect_mpeg_pes_Stream(tvb, offset, &asn1_ctx,
848                                         tree, hf_mpeg_pes_extension);
849                         /* https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=2229 
850                          * A value of 0 indicates that the PES packet length is neither specified nor 
851                          * bounded and is allowed only in PES packets whose payload is a video elementary 
852                          * stream contained in Transport Stream packets. 
853                          * XXX Some one with access to the spec should check this 
854                          */ 
855                          if(length !=0 && stream != STREAM_VIDEO){
856                                  length -= 5 * 8;
857                          }
858
859                         header_length = tvb_get_guint8(tvb, 8);
860                         if (header_length > 0) {
861                                 int flags = tvb_get_guint8(tvb, 7);
862                                 tvbuff_t *header_data = tvb_new_subset(tvb, offset / 8,
863                                                 header_length, header_length);
864                                 dissect_mpeg_pes_header_data(header_data, pinfo, tree, flags);
865                                 offset += header_length * 8;
866                                  /* lenght may be zero for Video stream */
867                                 if(length !=0 && stream != STREAM_VIDEO){
868                                         length -= header_length * 8;
869                                 }
870                         }
871
872                         /* lenght may be zero for Video stream */ 
873                         if(length==0){ 
874                                 proto_tree_add_item(tree, hf_mpeg_pes_data, tvb, (offset>>3),-1, FALSE);
875                                 return TRUE;
876                         }
877
878                         es = tvb_new_subset(tvb, offset / 8, -1, length / 8);
879                         if (tvb_get_ntoh24(es, 0) == PES_PREFIX)
880                                 dissect_mpeg_pes(es, pinfo, tree);
881                         else if (tvb_get_guint8(es, 0) == 0xff)
882                                 dissect_mpeg(es, pinfo, tree);
883                         else
884                                 proto_tree_add_item(tree, hf_mpeg_pes_data, es,
885                                                 0, -1, FALSE);
886                 } else {
887                         unsigned data_length = tvb_get_ntohs(tvb, offset / 8);
888                         proto_tree_add_item(tree, hf_mpeg_pes_length, tvb,
889                                         offset / 8, 2, FALSE);
890                         offset += 2 * 8;
891
892                         proto_tree_add_item(tree, hf_mpeg_pes_data, tvb,
893                                         offset / 8, data_length, FALSE);
894                 }
895         } else {
896                 proto_tree_add_item(tree, hf_mpeg_pes_data, tvb,
897                                 offset / 8, -1, FALSE);
898         }
899         return TRUE;
900 }
901
902 static heur_dissector_list_t heur_subdissector_list;
903
904 static void
905 dissect_mpeg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
906 {
907     if (!dissector_try_heuristic(heur_subdissector_list, tvb, pinfo, tree)) {
908         col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPEG");
909         col_clear(pinfo->cinfo, COL_INFO);
910         if (tree)
911             proto_tree_add_item(tree, proto_mpeg, tvb, 0, -1, FALSE);
912     }
913 }
914
915 void
916 proto_register_mpeg_pes(void)
917 {
918         static hf_register_info hf[] = {
919
920 /*--- Included file: packet-mpeg-pes-hfarr.c ---*/
921 #line 1 "packet-mpeg-pes-hfarr.c"
922     { &hf_mpeg_pes_prefix,
923       { "prefix", "mpeg-pes.prefix",
924         FT_BYTES, BASE_NONE, NULL, 0,
925         "mpeg_pes.OCTET_STRING_SIZE_3", HFILL }},
926     { &hf_mpeg_pes_stream,
927       { "stream", "mpeg-pes.stream",
928         FT_UINT8, BASE_HEX, VALS(mpeg_pes_T_stream_vals), 0,
929         "mpeg_pes.T_stream", HFILL }},
930     { &hf_mpeg_pes_length,
931       { "length", "mpeg-pes.length",
932         FT_UINT16, BASE_DEC, NULL, 0,
933         "mpeg_pes.INTEGER_0_65535", HFILL }},
934     { &hf_mpeg_pes_must_be_one,
935       { "must-be-one", "mpeg-pes.must_be_one",
936         FT_BOOLEAN, BASE_NONE, NULL, 0,
937         "mpeg_pes.BOOLEAN", HFILL }},
938     { &hf_mpeg_pes_must_be_zero,
939       { "must-be-zero", "mpeg-pes.must_be_zero",
940         FT_BOOLEAN, BASE_NONE, NULL, 0,
941         "mpeg_pes.BOOLEAN", HFILL }},
942     { &hf_mpeg_pes_scrambling_control,
943       { "scrambling-control", "mpeg-pes.scrambling_control",
944         FT_UINT32, BASE_DEC, VALS(mpeg_pes_T_scrambling_control_vals), 0,
945         "mpeg_pes.T_scrambling_control", HFILL }},
946     { &hf_mpeg_pes_priority,
947       { "priority", "mpeg-pes.priority",
948         FT_BOOLEAN, BASE_NONE, NULL, 0,
949         "mpeg_pes.BOOLEAN", HFILL }},
950     { &hf_mpeg_pes_data_alignment,
951       { "data-alignment", "mpeg-pes.data_alignment",
952         FT_BOOLEAN, BASE_NONE, NULL, 0,
953         "mpeg_pes.BOOLEAN", HFILL }},
954     { &hf_mpeg_pes_copyright,
955       { "copyright", "mpeg-pes.copyright",
956         FT_BOOLEAN, BASE_NONE, NULL, 0,
957         "mpeg_pes.BOOLEAN", HFILL }},
958     { &hf_mpeg_pes_original,
959       { "original", "mpeg-pes.original",
960         FT_BOOLEAN, BASE_NONE, NULL, 0,
961         "mpeg_pes.BOOLEAN", HFILL }},
962     { &hf_mpeg_pes_pts_flag,
963       { "pts-flag", "mpeg-pes.pts_flag",
964         FT_BOOLEAN, BASE_NONE, NULL, 0,
965         "mpeg_pes.BOOLEAN", HFILL }},
966     { &hf_mpeg_pes_dts_flag,
967       { "dts-flag", "mpeg-pes.dts_flag",
968         FT_BOOLEAN, BASE_NONE, NULL, 0,
969         "mpeg_pes.BOOLEAN", HFILL }},
970     { &hf_mpeg_pes_escr_flag,
971       { "escr-flag", "mpeg-pes.escr_flag",
972         FT_BOOLEAN, BASE_NONE, NULL, 0,
973         "mpeg_pes.BOOLEAN", HFILL }},
974     { &hf_mpeg_pes_es_rate_flag,
975       { "es-rate-flag", "mpeg-pes.es_rate_flag",
976         FT_BOOLEAN, BASE_NONE, NULL, 0,
977         "mpeg_pes.BOOLEAN", HFILL }},
978     { &hf_mpeg_pes_dsm_trick_mode_flag,
979       { "dsm-trick-mode-flag", "mpeg-pes.dsm_trick_mode_flag",
980         FT_BOOLEAN, BASE_NONE, NULL, 0,
981         "mpeg_pes.BOOLEAN", HFILL }},
982     { &hf_mpeg_pes_additional_copy_info_flag,
983       { "additional-copy-info-flag", "mpeg-pes.additional_copy_info_flag",
984         FT_BOOLEAN, BASE_NONE, NULL, 0,
985         "mpeg_pes.BOOLEAN", HFILL }},
986     { &hf_mpeg_pes_crc_flag,
987       { "crc-flag", "mpeg-pes.crc_flag",
988         FT_BOOLEAN, BASE_NONE, NULL, 0,
989         "mpeg_pes.BOOLEAN", HFILL }},
990     { &hf_mpeg_pes_extension_flag,
991       { "extension-flag", "mpeg-pes.extension_flag",
992         FT_BOOLEAN, BASE_NONE, NULL, 0,
993         "mpeg_pes.BOOLEAN", HFILL }},
994     { &hf_mpeg_pes_header_data_length,
995       { "header-data-length", "mpeg-pes.header_data_length",
996         FT_UINT32, BASE_DEC, NULL, 0,
997         "mpeg_pes.INTEGER_0_255", HFILL }},
998     { &hf_mpeg_pes_horizontal_size,
999       { "horizontal-size", "mpeg-pes.horizontal_size",
1000         FT_BYTES, BASE_NONE, NULL, 0,
1001         "mpeg_pes.BIT_STRING_SIZE_12", HFILL }},
1002     { &hf_mpeg_pes_vertical_size,
1003       { "vertical-size", "mpeg-pes.vertical_size",
1004         FT_BYTES, BASE_NONE, NULL, 0,
1005         "mpeg_pes.BIT_STRING_SIZE_12", HFILL }},
1006     { &hf_mpeg_pes_aspect_ratio,
1007       { "aspect-ratio", "mpeg-pes.aspect_ratio",
1008         FT_UINT32, BASE_DEC, VALS(mpeg_pes_T_aspect_ratio_vals), 0,
1009         "mpeg_pes.T_aspect_ratio", HFILL }},
1010     { &hf_mpeg_pes_frame_rate,
1011       { "frame-rate", "mpeg-pes.frame_rate",
1012         FT_UINT32, BASE_DEC, VALS(mpeg_pes_T_frame_rate_vals), 0,
1013         "mpeg_pes.T_frame_rate", HFILL }},
1014     { &hf_mpeg_pes_bit_rate,
1015       { "bit-rate", "mpeg-pes.bit_rate",
1016         FT_BYTES, BASE_NONE, NULL, 0,
1017         "mpeg_pes.BIT_STRING_SIZE_18", HFILL }},
1018     { &hf_mpeg_pes_vbv_buffer_size,
1019       { "vbv-buffer-size", "mpeg-pes.vbv_buffer_size",
1020         FT_BYTES, BASE_NONE, NULL, 0,
1021         "mpeg_pes.BIT_STRING_SIZE_10", HFILL }},
1022     { &hf_mpeg_pes_constrained_parameters_flag,
1023       { "constrained-parameters-flag", "mpeg-pes.constrained_parameters_flag",
1024         FT_BOOLEAN, BASE_NONE, NULL, 0,
1025         "mpeg_pes.BOOLEAN", HFILL }},
1026     { &hf_mpeg_pes_load_intra_quantiser_matrix,
1027       { "load-intra-quantiser-matrix", "mpeg-pes.load_intra_quantiser_matrix",
1028         FT_BOOLEAN, BASE_NONE, NULL, 0,
1029         "mpeg_pes.BOOLEAN", HFILL }},
1030     { &hf_mpeg_pes_load_non_intra_quantiser_matrix,
1031       { "load-non-intra-quantiser-matrix", "mpeg-pes.load_non_intra_quantiser_matrix",
1032         FT_BOOLEAN, BASE_NONE, NULL, 0,
1033         "mpeg_pes.BOOLEAN", HFILL }},
1034     { &hf_mpeg_pes_must_be_0001,
1035       { "must-be-0001", "mpeg-pes.must_be_0001",
1036         FT_BYTES, BASE_NONE, NULL, 0,
1037         "mpeg_pes.BIT_STRING_SIZE_4", HFILL }},
1038     { &hf_mpeg_pes_profile_and_level,
1039       { "profile-and-level", "mpeg-pes.profile_and_level",
1040         FT_UINT32, BASE_DEC, NULL, 0,
1041         "mpeg_pes.INTEGER_0_255", HFILL }},
1042     { &hf_mpeg_pes_progressive_sequence,
1043       { "progressive-sequence", "mpeg-pes.progressive_sequence",
1044         FT_BOOLEAN, BASE_NONE, NULL, 0,
1045         "mpeg_pes.BOOLEAN", HFILL }},
1046     { &hf_mpeg_pes_chroma_format,
1047       { "chroma-format", "mpeg-pes.chroma_format",
1048         FT_UINT32, BASE_DEC, NULL, 0,
1049         "mpeg_pes.INTEGER_0_3", HFILL }},
1050     { &hf_mpeg_pes_horizontal_size_extension,
1051       { "horizontal-size-extension", "mpeg-pes.horizontal_size_extension",
1052         FT_UINT32, BASE_DEC, NULL, 0,
1053         "mpeg_pes.INTEGER_0_3", HFILL }},
1054     { &hf_mpeg_pes_vertical_size_extension,
1055       { "vertical-size-extension", "mpeg-pes.vertical_size_extension",
1056         FT_UINT32, BASE_DEC, NULL, 0,
1057         "mpeg_pes.INTEGER_0_3", HFILL }},
1058     { &hf_mpeg_pes_bit_rate_extension,
1059       { "bit-rate-extension", "mpeg-pes.bit_rate_extension",
1060         FT_BYTES, BASE_NONE, NULL, 0,
1061         "mpeg_pes.BIT_STRING_SIZE_12", HFILL }},
1062     { &hf_mpeg_pes_vbv_buffer_size_extension,
1063       { "vbv-buffer-size-extension", "mpeg-pes.vbv_buffer_size_extension",
1064         FT_UINT32, BASE_DEC, NULL, 0,
1065         "mpeg_pes.INTEGER_0_255", HFILL }},
1066     { &hf_mpeg_pes_low_delay,
1067       { "low-delay", "mpeg-pes.low_delay",
1068         FT_BOOLEAN, BASE_NONE, NULL, 0,
1069         "mpeg_pes.BOOLEAN", HFILL }},
1070     { &hf_mpeg_pes_frame_rate_extension_n,
1071       { "frame-rate-extension-n", "mpeg-pes.frame_rate_extension_n",
1072         FT_UINT32, BASE_DEC, NULL, 0,
1073         "mpeg_pes.INTEGER_0_3", HFILL }},
1074     { &hf_mpeg_pes_frame_rate_extension_d,
1075       { "frame-rate-extension-d", "mpeg-pes.frame_rate_extension_d",
1076         FT_UINT32, BASE_DEC, NULL, 0,
1077         "mpeg_pes.INTEGER_0_3", HFILL }},
1078     { &hf_mpeg_pes_drop_frame_flag,
1079       { "drop-frame-flag", "mpeg-pes.drop_frame_flag",
1080         FT_BOOLEAN, BASE_NONE, NULL, 0,
1081         "mpeg_pes.BOOLEAN", HFILL }},
1082     { &hf_mpeg_pes_hour,
1083       { "hour", "mpeg-pes.hour",
1084         FT_UINT32, BASE_DEC, NULL, 0,
1085         "mpeg_pes.INTEGER_0_32", HFILL }},
1086     { &hf_mpeg_pes_minute,
1087       { "minute", "mpeg-pes.minute",
1088         FT_UINT32, BASE_DEC, NULL, 0,
1089         "mpeg_pes.INTEGER_0_64", HFILL }},
1090     { &hf_mpeg_pes_second,
1091       { "second", "mpeg-pes.second",
1092         FT_UINT32, BASE_DEC, NULL, 0,
1093         "mpeg_pes.INTEGER_0_64", HFILL }},
1094     { &hf_mpeg_pes_frame,
1095       { "frame", "mpeg-pes.frame",
1096         FT_UINT32, BASE_DEC, NULL, 0,
1097         "mpeg_pes.INTEGER_0_64", HFILL }},
1098     { &hf_mpeg_pes_closed_gop,
1099       { "closed-gop", "mpeg-pes.closed_gop",
1100         FT_BOOLEAN, BASE_NONE, NULL, 0,
1101         "mpeg_pes.BOOLEAN", HFILL }},
1102     { &hf_mpeg_pes_broken_gop,
1103       { "broken-gop", "mpeg-pes.broken_gop",
1104         FT_BOOLEAN, BASE_NONE, NULL, 0,
1105         "mpeg_pes.BOOLEAN", HFILL }},
1106     { &hf_mpeg_pes_must_be_zero_01,
1107       { "must-be-zero", "mpeg-pes.must_be_zero",
1108         FT_BYTES, BASE_NONE, NULL, 0,
1109         "mpeg_pes.BIT_STRING_SIZE_5", HFILL }},
1110     { &hf_mpeg_pes_temporal_sequence_number,
1111       { "temporal-sequence-number", "mpeg-pes.temporal_sequence_number",
1112         FT_BYTES, BASE_NONE, NULL, 0,
1113         "mpeg_pes.BIT_STRING_SIZE_10", HFILL }},
1114     { &hf_mpeg_pes_frame_type,
1115       { "frame-type", "mpeg-pes.frame_type",
1116         FT_UINT32, BASE_DEC, VALS(mpeg_pes_T_frame_type_vals), 0,
1117         "mpeg_pes.T_frame_type", HFILL }},
1118     { &hf_mpeg_pes_vbv_delay,
1119       { "vbv-delay", "mpeg-pes.vbv_delay",
1120         FT_BYTES, BASE_NONE, NULL, 0,
1121         "mpeg_pes.BIT_STRING_SIZE_16", HFILL }},
1122
1123 /*--- End of included file: packet-mpeg-pes-hfarr.c ---*/
1124 #line 483 "packet-mpeg-pes-template.c"
1125                 { &hf_mpeg_pes_pack_header,
1126                         { "Pack header", "mpeg-pes.pack",
1127                                 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
1128                 { &hf_mpeg_pes_scr,
1129                         { "system clock reference (SCR)", "mpeg-pes.scr",
1130                                 FT_RELATIVE_TIME, BASE_NONE, NULL, 0, NULL, HFILL }},
1131                 { &hf_mpeg_pes_program_mux_rate,
1132                         { "PES program mux rate", "mpeg-pes.program-mux-rate",
1133                                 FT_UINT24, BASE_DEC, NULL, 0, NULL, HFILL }},
1134                 { &hf_mpeg_pes_stuffing_length,
1135                         { "PES stuffing length", "mpeg-pes.stuffing-length",
1136                                 FT_UINT8, BASE_DEC, NULL, 0x07, NULL, HFILL }},
1137                 { &hf_mpeg_pes_stuffing,
1138                         { "PES stuffing bytes", "mpeg-pes.stuffing",
1139                                 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1140                 { &hf_mpeg_pes_extension,
1141                         { "PES extension", "mpeg-pes.extension",
1142                                 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
1143                 { &hf_mpeg_pes_header_data,
1144                         { "PES header data", "mpeg-pes.header-data",
1145                                 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1146                 { &hf_mpeg_pes_pts,
1147                         { "presentation time stamp (PTS)", "mpeg-pes.pts",
1148                                 FT_RELATIVE_TIME, BASE_NONE, NULL, 0, NULL, HFILL }},
1149                 { &hf_mpeg_pes_dts,
1150                         { "decode time stamp (DTS)", "mpeg-pes.dts",
1151                                 FT_RELATIVE_TIME, BASE_NONE, NULL, 0, NULL, HFILL }},
1152                 { &hf_mpeg_pes_escr,
1153                         { "elementary stream clock reference (ESCR)", "mpeg-pes.escr",
1154                                 FT_RELATIVE_TIME, BASE_NONE, NULL, 0, NULL, HFILL }},
1155                 { &hf_mpeg_pes_es_rate,
1156                         { "elementary stream rate", "mpeg-pes.es-rate",
1157                                 FT_UINT24, BASE_DEC, NULL, 0x7ffe, NULL, HFILL }},
1158                 { &hf_mpeg_pes_copy_info,
1159                         { "copy info", "mpeg-pes.copy-info",
1160                                 FT_UINT8, BASE_DEC, NULL, 0x7f, NULL, HFILL }},
1161                 { &hf_mpeg_pes_crc,
1162                         { "CRC", "mpeg-pes.crc",
1163                                 FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }},
1164                 { &hf_mpeg_pes_extension_flags,
1165                         { "extension flags", "mpeg-pes.extension-flags",
1166                                 FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }},
1167                 { &hf_mpeg_pes_private_data,
1168                         { "private data", "mpeg-pes.private-data",
1169                                 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }},
1170                 { &hf_mpeg_pes_pack_length,
1171                         { "pack length", "mpeg-pes.pack-length",
1172                                 FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
1173                 { &hf_mpeg_pes_sequence,
1174                         { "sequence", "mpeg-pes.sequence",
1175                                 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }},
1176                 { &hf_mpeg_pes_pstd_buffer,
1177                         { "P-STD buffer size", "mpeg-pes.pstd-buffer",
1178                                 FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }},
1179                 { &hf_mpeg_pes_extension2,
1180                         { "extension2", "mpeg-pes.extension2",
1181                                 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }},
1182                 { &hf_mpeg_pes_padding,
1183                         { "PES padding", "mpeg-pes.padding",
1184                                 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1185                 { &hf_mpeg_pes_data,
1186                         { "PES data", "mpeg-pes.data",
1187                                 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1188                 { &hf_mpeg_video_sequence_header,
1189                         { "MPEG sequence header", "mpeg-video.sequence",
1190                                 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
1191                 { &hf_mpeg_video_sequence_extension,
1192                         { "MPEG sequence extension", "mpeg-video.sequence-ext",
1193                                 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
1194                 { &hf_mpeg_video_group_of_pictures,
1195                         { "MPEG group of pictures", "mpeg-video.gop",
1196                                 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
1197                 { &hf_mpeg_video_picture,
1198                         { "MPEG picture", "mpeg-video.picture",
1199                                 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
1200                 { &hf_mpeg_video_quantization_matrix,
1201                         { "MPEG quantization matrix", "mpeg-video.quant",
1202                                 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1203                 { &hf_mpeg_video_data,
1204                         { "MPEG picture data", "mpeg-video.data",
1205                                 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
1206         };
1207
1208         static gint *ett[] = {
1209
1210 /*--- Included file: packet-mpeg-pes-ettarr.c ---*/
1211 #line 1 "packet-mpeg-pes-ettarr.c"
1212     &ett_mpeg_pes_PES,
1213     &ett_mpeg_pes_Stream,
1214     &ett_mpeg_pes_Sequence_header,
1215     &ett_mpeg_pes_Sequence_extension,
1216     &ett_mpeg_pes_Group_of_pictures,
1217     &ett_mpeg_pes_Picture,
1218
1219 /*--- End of included file: packet-mpeg-pes-ettarr.c ---*/
1220 #line 568 "packet-mpeg-pes-template.c"
1221                 &ett_mpeg_pes_pack_header,
1222                 &ett_mpeg_pes_header_data,
1223         };
1224
1225         proto_mpeg = proto_register_protocol(
1226                         "Moving Picture Experts Group", "MPEG", "mpeg");
1227         register_dissector("mpeg", dissect_mpeg, proto_mpeg);
1228         register_heur_dissector_list("mpeg", &heur_subdissector_list);
1229
1230         proto_mpeg_pes = proto_register_protocol(
1231                         "Packetized Elementary Stream", "MPEG PES", "mpeg-pes");
1232         proto_register_field_array(proto_mpeg_pes, hf, array_length(hf));
1233         proto_register_subtree_array(ett, array_length(ett));
1234         new_register_dissector("mpeg-pes", dissect_mpeg_pes, proto_mpeg_pes);
1235 }
1236
1237 void
1238 proto_reg_handoff_mpeg_pes(void)
1239 {
1240         dissector_handle_t mpeg_handle = find_dissector("mpeg");
1241
1242         dissector_add("wtap_encap", WTAP_ENCAP_MPEG, mpeg_handle);
1243         heur_dissector_add("mpeg", dissect_mpeg_pes, proto_mpeg_pes);
1244 }