Minor cleanup mostly related to proto_reg_handoff
[obnox/wireshark/wip.git] / asn1 / mpeg-pes / packet-mpeg-pes-template.c
1 /* MPEG Packetized Elementary Stream (PES) packet decoder.
2  * Written by Shaun Jackman <sjackman@gmail.com>.
3  * Copyright 2007 Shaun Jackman
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <stdio.h>
30 #include <string.h>
31
32 #include <glib.h>
33
34 #include <epan/packet.h>
35 #include <epan/prefs.h>
36 #include <epan/asn1.h>
37
38 #include "packet-per.h"
39
40 #include "packet-mpeg-pes-hf.c"
41 #include "packet-mpeg-pes-ett.c"
42 #include "packet-mpeg-pes-fn.c"
43
44 static int proto_mpeg = -1;
45 static int proto_mpeg_pes = -1;
46
47 static int ett_mpeg_pes_pack_header = -1;
48 static int ett_mpeg_pes_header_data = -1;
49
50 static int hf_mpeg_pes_pack_header = -1;
51 static int hf_mpeg_pes_scr = -1;
52 static int hf_mpeg_pes_program_mux_rate = -1;
53 static int hf_mpeg_pes_stuffing_length = -1;
54 static int hf_mpeg_pes_stuffing = -1;
55 static int hf_mpeg_pes_extension = -1;
56 static int hf_mpeg_pes_header_data = -1;
57 static int hf_mpeg_pes_pts = -1;
58 static int hf_mpeg_pes_dts = -1;
59 static int hf_mpeg_pes_escr = -1;
60 static int hf_mpeg_pes_es_rate = -1;
61 static int hf_mpeg_pes_copy_info = -1;
62 static int hf_mpeg_pes_crc = -1;
63 static int hf_mpeg_pes_extension_flags = -1;
64 static int hf_mpeg_pes_private_data = -1;
65 static int hf_mpeg_pes_pack_length = -1;
66 static int hf_mpeg_pes_sequence = -1;
67 static int hf_mpeg_pes_pstd_buffer = -1;
68 static int hf_mpeg_pes_extension2 = -1;
69 static int hf_mpeg_pes_padding = -1;
70 static int hf_mpeg_pes_data = -1;
71
72 static int hf_mpeg_video_sequence_header = -1;
73 static int hf_mpeg_video_sequence_extension = -1;
74 static int hf_mpeg_video_group_of_pictures = -1;
75 static int hf_mpeg_video_picture = -1;
76 static int hf_mpeg_video_quantization_matrix = -1;
77 static int hf_mpeg_video_data = -1;
78
79 enum { PES_PREFIX = 1 };
80
81 enum {
82         STREAM_PICTURE = 0x00,
83         STREAM_SEQUENCE = 0xb3,
84         STREAM_SEQUENCE_EXTENSION = 0xb5,
85         STREAM_GOP = 0xb8,
86         STREAM_END = 0xb9,
87         STREAM_PACK = 0xba,
88         STREAM_SYSTEM = 0xbb,
89         STREAM_PROGRAM = 0xbc,
90         STREAM_PRIVATE1 = 0xbd,
91         STREAM_PADDING = 0xbe,
92         STREAM_PRIVATE2 = 0xbf,
93         STREAM_AUDIO = 0xc0,
94         STREAM_VIDEO = 0xe0
95 };
96
97 enum {
98         PTS_FLAG = 0x80,
99         DTS_FLAG = 0x40,
100         ESCR_FLAG = 0x20,
101         ES_RATE_FLAG = 0x10,
102         DSM_TRICK_MODE_FLAG = 0x08,
103         COPY_INFO_FLAG = 0x04,
104         CRC_FLAG = 0x02,
105         EXTENSION_FLAG = 0x01
106 };
107
108 enum {
109         PRIVATE_DATA_FLAG = 0x80,
110         PACK_LENGTH_FLAG = 0x40,
111         SEQUENCE_FLAG = 0x20,
112         PSTD_BUFFER_FLAG = 0x10,
113         MUST_BE_ONES = 0x07,
114         EXTENSION_FLAG2 = 0x01
115 };
116
117 static guint64 tvb_get_ntoh40(tvbuff_t *tvb, unsigned offset)
118 {
119         return (guint64)tvb_get_guint8(tvb, offset) << 32
120                 | tvb_get_ntohl(tvb, offset + 1);
121 }
122
123 static guint64 tvb_get_ntoh48(tvbuff_t *tvb, unsigned offset)
124 {
125         return (guint64)tvb_get_ntohs(tvb, offset) << 32
126                 | tvb_get_ntohl(tvb, offset + 2);
127 }
128
129 #define TSHZ 90000
130
131 static guint64 decode_time_stamp(tvbuff_t *tvb, unsigned offset, nstime_t *nst)
132 {
133         guint64 bytes = tvb_get_ntoh40(tvb, offset);
134         guint64 ts =
135                 (bytes >> 33 & 0x0007) << 30 |
136                 (bytes >> 17 & 0x7fff) << 15 |
137                 (bytes >>  1 & 0x7fff) << 0;
138         unsigned rem = (unsigned)(ts % TSHZ);
139         nst->secs = (time_t)(ts / TSHZ);
140         nst->nsecs = (int)(G_GINT64_CONSTANT(1000000000) * rem / TSHZ);
141         return ts;
142 }
143
144 #define SCRHZ 27000000
145
146 static guint64 decode_clock_reference(tvbuff_t *tvb, unsigned offset,
147                 nstime_t *nst)
148 {
149         guint64 bytes = tvb_get_ntoh48(tvb, offset);
150         guint64 ts =
151                 (bytes >> 43 & 0x0007) << 30 |
152                 (bytes >> 27 & 0x7fff) << 15 |
153                 (bytes >> 11 & 0x7fff) << 0;
154         unsigned ext = (unsigned)((bytes >> 1) & 0x1ff);
155         guint64 cr = 300 * ts + ext;
156         unsigned rem = (unsigned)(cr % SCRHZ);
157         nst->secs = (time_t)(cr / SCRHZ);
158         nst->nsecs = (int)(G_GINT64_CONSTANT(1000000000) * rem / SCRHZ);
159         return cr;
160 }
161
162 static void
163 dissect_mpeg_pes_header_data(tvbuff_t *tvb, packet_info *pinfo,
164                 proto_tree *root, unsigned flags)
165 {
166         proto_item *item = proto_tree_add_item(root, hf_mpeg_pes_header_data, tvb,
167                         0, -1, FALSE);
168         proto_tree *tree = proto_item_add_subtree(item, ett_mpeg_pes_header_data);
169
170         unsigned offset = 0;
171         if (flags & PTS_FLAG) {
172                 nstime_t nst;
173                 decode_time_stamp(tvb, offset, &nst);
174                 proto_tree_add_time(tree, hf_mpeg_pes_pts, tvb,
175                                 offset, 5, &nst);
176                 offset += 5;
177
178                 if (check_col(pinfo->cinfo, COL_DEF_DST)) {
179                         SET_ADDRESS(&pinfo->dst, AT_NONE, 0, NULL);
180                         col_add_fstr(pinfo->cinfo, COL_DEF_DST,
181                                         "PTS %ld.%09u",
182                                         (long) nst.secs, nst.nsecs);
183                 }
184         }
185         if (flags & DTS_FLAG) {
186                 nstime_t nst;
187                 decode_time_stamp(tvb, offset, &nst);
188                 proto_tree_add_time(tree, hf_mpeg_pes_dts, tvb,
189                                 offset, 5, &nst);
190                 offset += 5;
191
192                 if (check_col(pinfo->cinfo, COL_DEF_SRC)) {
193                         SET_ADDRESS(&pinfo->src, AT_NONE, 0, NULL);
194                         col_add_fstr(pinfo->cinfo, COL_DEF_SRC,
195                                         "DTS %ld.%09u",
196                                         (long) nst.secs, nst.nsecs);
197                 }
198         }
199         if (flags & ESCR_FLAG) {
200                 nstime_t nst;
201                 decode_clock_reference(tvb, offset, &nst);
202                 proto_tree_add_time(tree, hf_mpeg_pes_escr, tvb,
203                                 offset, 6, &nst);
204                 offset += 6;
205         }
206         if (flags & ES_RATE_FLAG) {
207                 unsigned es_rate = (tvb_get_ntohs(tvb, offset) >> 1 & 0x3fff) * 50;
208                 proto_tree_add_uint(tree, hf_mpeg_pes_es_rate, tvb,
209                                 offset, 3, es_rate);
210                 offset += 3;
211         }
212         if (flags & COPY_INFO_FLAG) {
213                 proto_tree_add_item(tree, hf_mpeg_pes_copy_info, tvb,
214                                 offset, 1, FALSE);
215                 offset++;
216         }
217         if (flags & CRC_FLAG) {
218                 proto_tree_add_item(tree, hf_mpeg_pes_crc, tvb,
219                                 offset, 2, FALSE);
220                 offset += 2;
221         }
222
223         if (flags & EXTENSION_FLAG) {
224                 int flags2 = tvb_get_guint8(tvb, offset);
225                 proto_tree_add_item(tree, hf_mpeg_pes_extension_flags, tvb,
226                                 offset, 1, FALSE);
227                 offset++;
228
229                 if (flags2 & PRIVATE_DATA_FLAG) {
230                         proto_tree_add_item(tree, hf_mpeg_pes_private_data, tvb,
231                                         offset, 2, FALSE);
232                         offset += 2;
233                 }
234                 if (flags2 & PACK_LENGTH_FLAG) {
235                         proto_tree_add_item(tree, hf_mpeg_pes_pack_length, tvb,
236                                         offset, 1, FALSE);
237                         offset++;
238                 }
239                 if (flags2 & SEQUENCE_FLAG) {
240                         proto_tree_add_item(tree, hf_mpeg_pes_sequence, tvb,
241                                         offset, 2, FALSE);
242                         offset += 2;
243                 }
244                 if (flags2 & PSTD_BUFFER_FLAG) {
245                         unsigned pstd = tvb_get_ntohs(tvb, offset);
246                         proto_tree_add_uint(tree, hf_mpeg_pes_pstd_buffer, tvb,
247                                         offset, 2, (pstd & 0x2000 ? 1024 : 128) * (pstd & 0x1ff));
248                         offset += 2;
249                 }
250                 if (flags2 & EXTENSION_FLAG2) {
251                         proto_tree_add_item(tree, hf_mpeg_pes_extension2, tvb,
252                                         offset, 2, FALSE);
253                         offset += 2;
254                 }
255         }
256 }
257
258 static unsigned
259 dissect_mpeg_pes_pack_header(tvbuff_t *tvb, unsigned offset,
260                 packet_info *pinfo, proto_tree *root)
261 {
262         unsigned program_mux_rate, stuffing_length;
263
264         proto_item *item = proto_tree_add_item(root, hf_mpeg_pes_pack_header, tvb,
265                         offset / 8, 10, FALSE);
266         proto_tree *tree = proto_item_add_subtree(item, ett_mpeg_pes_pack_header);
267
268         nstime_t nst;
269         decode_clock_reference(tvb, offset / 8, &nst);
270         proto_tree_add_time(tree, hf_mpeg_pes_scr, tvb, offset / 8, 6, &nst);
271         offset += 6 * 8;
272
273         program_mux_rate = (tvb_get_ntoh24(tvb, offset / 8) >> 2) * 50;
274         proto_tree_add_uint(tree, hf_mpeg_pes_program_mux_rate, tvb, offset / 8, 3,
275                         program_mux_rate);
276         offset += 3 * 8;
277
278         if (check_col(pinfo->cinfo, COL_DEF_SRC)) {
279                 SET_ADDRESS(&pinfo->src, AT_NONE, 0, NULL);
280                 col_add_fstr(pinfo->cinfo, COL_DEF_SRC, "%u B/s", program_mux_rate);
281         }
282
283         stuffing_length = tvb_get_guint8(tvb, offset / 8) & 0x07;
284         proto_tree_add_item(tree, hf_mpeg_pes_stuffing_length, tvb,
285                         offset / 8, 1, FALSE);
286         offset += 1 * 8;
287
288         if (stuffing_length > 0) {
289                 proto_tree_add_item(tree, hf_mpeg_pes_stuffing, tvb,
290                                 offset / 8, stuffing_length, FALSE);
291                 offset += stuffing_length * 8;
292         }
293
294         return offset;
295 }
296
297 static void
298 dissect_mpeg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
299
300 static gboolean
301 dissect_mpeg_pes(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
302 {
303         int prefix;
304         int stream;
305         asn1_ctx_t asn1_ctx;
306         unsigned offset = 0;
307
308         if (!tvb_bytes_exist(tvb, 0, 3))
309                 return FALSE;   /* not enough bytes for a PES prefix */
310
311         prefix = tvb_get_ntoh24(tvb, 0);
312         if (prefix != PES_PREFIX)
313                 return FALSE;
314         if (check_col(pinfo->cinfo, COL_PROTOCOL))
315                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPEG PES");
316         if (check_col(pinfo->cinfo, COL_INFO))
317                 col_clear(pinfo->cinfo, COL_INFO);
318
319         stream = tvb_get_guint8(tvb, 3);
320         if (check_col(pinfo->cinfo, COL_INFO)) {
321                 const char *s = match_strval(stream, mpeg_pes_T_stream_vals);
322                 if (s != NULL)
323                         col_set_str(pinfo->cinfo, COL_INFO, s);
324         }
325
326 #if 0
327         if (tree == NULL)
328                 return TRUE;
329 #endif
330         asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, TRUE, pinfo);
331         offset = dissect_mpeg_pes_PES(tvb, offset, &asn1_ctx,
332                         tree, proto_mpeg_pes);
333
334         if (stream == STREAM_PICTURE) {
335                 int frame_type;
336
337                 frame_type = tvb_get_guint8(tvb, 5) >> 3 & 0x07;
338                 if (check_col(pinfo->cinfo, COL_INFO)) {
339                         const char *s = match_strval(frame_type,
340                                         mpeg_pes_T_frame_type_vals);
341                         if (s != NULL)
342                                 col_set_str(pinfo->cinfo, COL_INFO, s);
343                 }
344
345                 offset = dissect_mpeg_pes_Picture(tvb, offset, &asn1_ctx,
346                                 tree, hf_mpeg_video_picture);
347                 proto_tree_add_item(tree, hf_mpeg_video_data, tvb,
348                                 offset / 8, -1, FALSE);
349         } else if (stream == STREAM_SEQUENCE) {
350                 tvbuff_t *es;
351
352                 offset = dissect_mpeg_pes_Sequence_header(tvb, offset, &asn1_ctx,
353                                 tree, hf_mpeg_video_sequence_header);
354
355                 proto_tree_add_item(tree, hf_mpeg_video_quantization_matrix, tvb,
356                                 offset / 8, 64, FALSE);
357                 offset += 64 * 8;
358
359                 es = tvb_new_subset(tvb, offset / 8, -1, -1);
360                 dissect_mpeg_pes(es, pinfo, tree);
361         } else if (stream == STREAM_SEQUENCE_EXTENSION) {
362                 tvbuff_t *es;
363
364                 offset = dissect_mpeg_pes_Sequence_extension(tvb, offset, &asn1_ctx,
365                                 tree, hf_mpeg_video_sequence_extension);
366
367                 es = tvb_new_subset(tvb, offset / 8, -1, -1);
368                 dissect_mpeg_pes(es, pinfo, tree);
369         } else if (stream == STREAM_GOP) {
370                 tvbuff_t *es;
371
372                 offset = dissect_mpeg_pes_Group_of_pictures(tvb, offset, &asn1_ctx,
373                                 tree, hf_mpeg_video_group_of_pictures);
374
375                 es = tvb_new_subset(tvb, offset / 8, -1, -1);
376                 dissect_mpeg_pes(es, pinfo, tree);
377         } else if (stream == STREAM_PACK) {
378                 if (tvb_get_guint8(tvb, offset / 8) >> 6 == 1) {
379                         offset = dissect_mpeg_pes_pack_header(tvb, offset, pinfo, tree);
380                 } else {
381                         proto_tree_add_item(tree, hf_mpeg_pes_data, tvb,
382                                         offset / 8, 8, FALSE);
383                         offset += 8 * 8;
384                 }
385         } else if (stream == STREAM_SYSTEM || stream == STREAM_PRIVATE2) {
386                 unsigned data_length = tvb_get_ntohs(tvb, offset / 8);
387                 proto_tree_add_item(tree, hf_mpeg_pes_length, tvb,
388                                 offset / 8, 2, FALSE);
389                 offset += 2 * 8;
390
391                 proto_tree_add_item(tree, hf_mpeg_pes_data, tvb,
392                                 offset / 8, data_length, FALSE);
393         } else if (stream == STREAM_PADDING) {
394                 unsigned padding_length = tvb_get_ntohs(tvb, offset / 8);
395                 proto_tree_add_item(tree, hf_mpeg_pes_length, tvb,
396                                 offset / 8, 2, FALSE);
397                 offset += 2 * 8;
398
399                 proto_tree_add_item(tree, hf_mpeg_pes_padding, tvb,
400                                 offset / 8, padding_length, FALSE);
401         } else if (stream == STREAM_PRIVATE1
402                         || stream >= STREAM_AUDIO) {
403                 int length = tvb_get_ntohs(tvb, 4);
404
405                 if ((tvb_get_guint8(tvb, 6) & 0xc0) == 0x80) {
406                         int header_length;
407                         tvbuff_t *es;
408
409                         offset = dissect_mpeg_pes_Stream(tvb, offset, &asn1_ctx,
410                                         tree, hf_mpeg_pes_extension);
411                         length -= 5 * 8;
412
413                         header_length = tvb_get_guint8(tvb, 8);
414                         if (header_length > 0) {
415                                 int flags = tvb_get_guint8(tvb, 7);
416                                 tvbuff_t *header_data = tvb_new_subset(tvb, offset / 8,
417                                                 header_length, header_length);
418                                 dissect_mpeg_pes_header_data(header_data, pinfo, tree, flags);
419                                 offset += header_length * 8;
420                                 length -= header_length * 8;
421                         }
422
423                         es = tvb_new_subset(tvb, offset / 8, -1, length / 8);
424                         if (tvb_get_ntoh24(es, 0) == PES_PREFIX)
425                                 dissect_mpeg_pes(es, pinfo, tree);
426                         else if (tvb_get_guint8(es, 0) == 0xff)
427                                 dissect_mpeg(es, pinfo, tree);
428                         else
429                                 proto_tree_add_item(tree, hf_mpeg_pes_data, es,
430                                                 0, -1, FALSE);
431                 } else {
432                         unsigned data_length = tvb_get_ntohs(tvb, offset / 8);
433                         proto_tree_add_item(tree, hf_mpeg_pes_length, tvb,
434                                         offset / 8, 2, FALSE);
435                         offset += 2 * 8;
436
437                         proto_tree_add_item(tree, hf_mpeg_pes_data, tvb,
438                                         offset / 8, data_length, FALSE);
439                 }
440         } else {
441                 proto_tree_add_item(tree, hf_mpeg_pes_data, tvb,
442                                 offset / 8, -1, FALSE);
443         }
444         return TRUE;
445 }
446
447 static heur_dissector_list_t heur_subdissector_list;
448
449 static void
450 dissect_mpeg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
451 {
452     if (!dissector_try_heuristic(heur_subdissector_list, tvb, pinfo, tree)) {
453         if (check_col(pinfo->cinfo, COL_PROTOCOL))
454             col_add_str(pinfo->cinfo, COL_PROTOCOL, "MPEG");
455         if (check_col(pinfo->cinfo, COL_INFO))
456             col_clear(pinfo->cinfo, COL_INFO);
457         if (tree)
458             proto_tree_add_item(tree, proto_mpeg, tvb, 0, -1, FALSE);
459     }
460 }
461
462 void
463 proto_register_mpeg_pes(void)
464 {
465         static hf_register_info hf[] = {
466 #include "packet-mpeg-pes-hfarr.c"
467                 { &hf_mpeg_pes_pack_header,
468                         { "Pack header", "mpeg-pes.pack",
469                                 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
470                 { &hf_mpeg_pes_scr,
471                         { "system clock reference (SCR)", "mpeg-pes.scr",
472                                 FT_RELATIVE_TIME, BASE_NONE, NULL, 0, NULL, HFILL }},
473                 { &hf_mpeg_pes_program_mux_rate,
474                         { "PES program mux rate", "mpeg-pes.program-mux-rate",
475                                 FT_UINT24, BASE_DEC, NULL, 0, NULL, HFILL }},
476                 { &hf_mpeg_pes_stuffing_length,
477                         { "PES stuffing length", "mpeg-pes.stuffing-length",
478                                 FT_UINT8, BASE_DEC, NULL, 0x07, NULL, HFILL }},
479                 { &hf_mpeg_pes_stuffing,
480                         { "PES stuffing bytes", "mpeg-pes.stuffing",
481                                 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
482                 { &hf_mpeg_pes_extension,
483                         { "PES extension", "mpeg-pes.extension",
484                                 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
485                 { &hf_mpeg_pes_header_data,
486                         { "PES header data", "mpeg-pes.header-data",
487                                 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
488                 { &hf_mpeg_pes_pts,
489                         { "presentation time stamp (PTS)", "mpeg-pes.pts",
490                                 FT_RELATIVE_TIME, BASE_NONE, NULL, 0, NULL, HFILL }},
491                 { &hf_mpeg_pes_dts,
492                         { "decode time stamp (DTS)", "mpeg-pes.dts",
493                                 FT_RELATIVE_TIME, BASE_NONE, NULL, 0, NULL, HFILL }},
494                 { &hf_mpeg_pes_escr,
495                         { "elementary stream clock reference (ESCR)", "mpeg-pes.escr",
496                                 FT_RELATIVE_TIME, BASE_NONE, NULL, 0, NULL, HFILL }},
497                 { &hf_mpeg_pes_es_rate,
498                         { "elementary stream rate", "mpeg-pes.es-rate",
499                                 FT_UINT24, BASE_DEC, NULL, 0x7ffe, NULL, HFILL }},
500                 { &hf_mpeg_pes_copy_info,
501                         { "copy info", "mpeg-pes.copy-info",
502                                 FT_UINT8, BASE_DEC, NULL, 0x7f, NULL, HFILL }},
503                 { &hf_mpeg_pes_crc,
504                         { "CRC", "mpeg-pes.crc",
505                                 FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }},
506                 { &hf_mpeg_pes_extension_flags,
507                         { "extension flags", "mpeg-pes.extension-flags",
508                                 FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }},
509                 { &hf_mpeg_pes_private_data,
510                         { "private data", "mpeg-pes.private-data",
511                                 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }},
512                 { &hf_mpeg_pes_pack_length,
513                         { "pack length", "mpeg-pes.pack-length",
514                                 FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
515                 { &hf_mpeg_pes_sequence,
516                         { "sequence", "mpeg-pes.sequence",
517                                 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }},
518                 { &hf_mpeg_pes_pstd_buffer,
519                         { "P-STD buffer size", "mpeg-pes.pstd-buffer",
520                                 FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }},
521                 { &hf_mpeg_pes_extension2,
522                         { "extension2", "mpeg-pes.extension2",
523                                 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }},
524                 { &hf_mpeg_pes_padding,
525                         { "PES padding", "mpeg-pes.padding",
526                                 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
527                 { &hf_mpeg_pes_data,
528                         { "PES data", "mpeg-pes.data",
529                                 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
530                 { &hf_mpeg_video_sequence_header,
531                         { "MPEG sequence header", "mpeg-video.sequence",
532                                 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
533                 { &hf_mpeg_video_sequence_extension,
534                         { "MPEG sequence extension", "mpeg-video.sequence-ext",
535                                 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
536                 { &hf_mpeg_video_group_of_pictures,
537                         { "MPEG group of pictures", "mpeg-video.gop",
538                                 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
539                 { &hf_mpeg_video_picture,
540                         { "MPEG picture", "mpeg-video.picture",
541                                 FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
542                 { &hf_mpeg_video_quantization_matrix,
543                         { "MPEG quantization matrix", "mpeg-video.quant",
544                                 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
545                 { &hf_mpeg_video_data,
546                         { "MPEG picture data", "mpeg-video.data",
547                                 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
548         };
549
550         static gint *ett[] = {
551 #include "packet-mpeg-pes-ettarr.c"
552                 &ett_mpeg_pes_pack_header,
553                 &ett_mpeg_pes_header_data,
554         };
555
556         proto_mpeg = proto_register_protocol(
557                         "Moving Picture Experts Group", "MPEG", "mpeg");
558         register_dissector("mpeg", dissect_mpeg, proto_mpeg);
559         register_heur_dissector_list("mpeg", &heur_subdissector_list);
560
561         proto_mpeg_pes = proto_register_protocol(
562                         "Packetized Elementary Stream", "MPEG PES", "mpeg-pes");
563         proto_register_field_array(proto_mpeg_pes, hf, array_length(hf));
564         proto_register_subtree_array(ett, array_length(ett));
565         new_register_dissector("mpeg-pes", dissect_mpeg_pes, proto_mpeg_pes);
566 }
567
568 void
569 proto_reg_handoff_mpeg_pes(void)
570 {
571         dissector_handle_t mpeg_handle = find_dissector("mpeg");
572
573         dissector_add("wtap_encap", WTAP_ENCAP_MPEG, mpeg_handle);
574         heur_dissector_add("mpeg", dissect_mpeg_pes, proto_mpeg_pes);
575 }