QSIG fully implemented
[obnox/wireshark/wip.git] / epan / dissectors / packet-mp2t.c
1 /* packet-mp2t.c
2  *
3  * Routines for RFC 2250 MPEG2 (ISO/IEC 13818-1) Transport Stream dissection
4  *
5  * $Id$
6  *
7  * Copyright 2006, Erwin Rol <erwin@erwinrol.com>
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <glib.h>
33 #include <epan/packet.h>
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #include <epan/rtp_pt.h>
39
40 /* The MPEG2 TS packet size */
41 #define MP2T_PACKET_SIZE 188
42
43 static int proto_mp2t = -1;
44 static gint ett_mp2t = -1;
45
46 static int hf_mp2t_header = -1;
47 static int hf_mp2t_sync_byte = -1;
48 static int hf_mp2t_tei = -1;
49 static int hf_mp2t_pusi = -1;
50 static int hf_mp2t_tp = -1;
51 static int hf_mp2t_pid = -1;
52 static int hf_mp2t_tsc = -1;
53 static int hf_mp2t_afc = -1;
54 static int hf_mp2t_cc = -1;
55
56 #define MP2T_SYNC_BYTE_MASK     0xFF000000
57 #define MP2T_TEI_MASK           0x00800000
58 #define MP2T_PUSI_MASK          0x00400000
59 #define MP2T_TP_MASK            0x00200000
60 #define MP2T_PID_MASK           0x001FFF00
61 #define MP2T_TSC_MASK           0x000000C0
62 #define MP2T_AFC_MASK           0x00000030
63 #define MP2T_CC_MASK            0x0000000F
64
65 #define MP2T_SYNC_BYTE_SHIFT    24
66 #define MP2T_TEI_SHIFT          23
67 #define MP2T_PUSI_SHIFT         22
68 #define MP2T_TP_SHIFT           21
69 #define MP2T_PID_SHIFT          8
70 #define MP2T_TSC_SHIFT          6
71 #define MP2T_AFC_SHIFT          4
72 #define MP2T_CC_SHIFT           0
73
74 static int hf_mp2t_af = -1;
75 static int hf_mp2t_af_length = -1;
76 static int hf_mp2t_af_di = -1;
77 static int hf_mp2t_af_rai = -1;
78 static int hf_mp2t_af_espi = -1;
79 static int hf_mp2t_af_pcr_flag = -1;
80 static int hf_mp2t_af_opcr_flag = -1;
81 static int hf_mp2t_af_sp_flag = -1;
82 static int hf_mp2t_af_tpd_flag = -1;
83 static int hf_mp2t_af_afe_flag = -1;
84
85 #define MP2T_AF_DI_MASK         0x80
86 #define MP2T_AF_RAI_MASK        0x40
87 #define MP2T_AF_ESPI_MASK       0x20
88 #define MP2T_AF_PCR_MASK        0x10
89 #define MP2T_AF_OPCR_MASK       0x08
90 #define MP2T_AF_SP_MASK         0x04
91 #define MP2T_AF_TPD_MASK        0x02
92 #define MP2T_AF_AFE_MASK        0x01
93
94 #define MP2T_AF_DI_SHIFT        7
95 #define MP2T_AF_RAI_SHIFT       6
96 #define MP2T_AF_ESPI_SHIFT      5
97 #define MP2T_AF_PCR_SHIFT       4
98 #define MP2T_AF_OPCR_SHIFT      3
99 #define MP2T_AF_SP_SHIFT        2
100 #define MP2T_AF_TPD_SHIFT       1
101 #define MP2T_AF_AFE_SHIFT       0
102
103 static int hf_mp2t_af_pcr = -1;
104 static int hf_mp2t_af_opcr = -1;
105
106 static int hf_mp2t_af_sc = -1;
107
108 static int hf_mp2t_af_tpd_length = -1;
109 static int hf_mp2t_af_tpd = -1;
110
111 static int hf_mp2t_af_e_length = -1;
112 static int hf_mp2t_af_e_ltw_flag = -1;
113 static int hf_mp2t_af_e_pr_flag = -1;
114 static int hf_mp2t_af_e_ss_flag = -1;
115 static int hf_mp2t_af_e_reserved = -1;
116
117 #define MP2T_AF_E_LTW_FLAG_MASK 0x80 
118 #define MP2T_AF_E_PR_FLAG_MASK  0x40
119 #define MP2T_AF_E_SS_FLAG_MASK  0x20
120
121 static int hf_mp2t_af_e_reserved_bytes = -1;
122 static int hf_mp2t_af_stuffing_bytes = -1;
123
124 static int hf_mp2t_af_e_ltwv_flag = -1;
125 static int hf_mp2t_af_e_ltwo = -1;
126
127 static int hf_mp2t_af_e_pr_reserved = -1;
128 static int hf_mp2t_af_e_pr = -1;
129
130 static int hf_mp2t_af_e_st = -1;
131 static int hf_mp2t_af_e_dnau_32_30 = -1;
132 static int hf_mp2t_af_e_m_1 = -1;
133 static int hf_mp2t_af_e_dnau_29_15 = -1;
134 static int hf_mp2t_af_e_m_2 = -1;
135 static int hf_mp2t_af_e_dnau_14_0 = -1;
136 static int hf_mp2t_af_e_m_3 = -1;
137
138 static int hf_mp2t_payload = -1;
139 static int hf_mp2t_malformed_payload = -1;
140
141 static const value_string mp2t_sync_byte_vals[] = {
142         { 0x47, "Correct" },
143         { 0, NULL},
144 };
145
146
147 static const value_string mp2t_pid_vals[] = {
148         { 0x0000, "Program Association Table" },
149         { 0x0001, "Conditional Access Table" },
150         { 0x0002, "Transport Stream Description Table" },
151         { 0x0003, "Reserved" },
152         { 0x0004, "Reserved" },
153         { 0x0005, "Reserved" },
154         { 0x0006, "Reserved" },
155         { 0x0007, "Reserved" },
156         { 0x0008, "Reserved" },
157         { 0x0009, "Reserved" },
158         { 0x000A, "Reserved" },
159         { 0x000B, "Reserved" },
160         { 0x000C, "Reserved" },
161         { 0x000D, "Reserved" },
162         { 0x000E, "Reserved" },
163         { 0x000F, "Reserved" },
164         { 0x1FFF, "Null packet" },
165         { 0, NULL },
166 };
167
168 static const value_string mp2t_tsc_vals[] = {
169         { 0, "Not scrambled" },
170         { 1, "User-defined" },
171         { 2, "User-defined" },
172         { 3, "User-defined" },
173         { 0, NULL },
174 };
175
176 static const value_string mp2t_afc_vals[] = {
177         { 0, "Reserved" },
178         { 1, "Payload only" },
179         { 2, "Adaptation Field only" },
180         { 3, "Adaptation Field and Payload" },
181         { 0, NULL },
182 };
183
184 static gint
185 dissect_tsp( tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, proto_tree *tree ) 
186 {
187         guint32 header;
188         guint afc;
189         gint start_offset = offset;
190         gint payload_len;
191
192         proto_item *ti = NULL;
193         proto_item *hi = NULL;
194         proto_tree *mp2t_tree = NULL;
195         proto_tree *mp2t_header_tree = NULL;
196         proto_tree *mp2t_af_tree = NULL;
197
198         ti = proto_tree_add_item( tree, proto_mp2t, tvb, offset, MP2T_PACKET_SIZE, FALSE );
199         mp2t_tree = proto_item_add_subtree( ti, ett_mp2t );
200         
201         header = tvb_get_ntohl(tvb, offset);
202
203         proto_item_append_text(ti, " PID=0x%x CC=%d", (header & MP2T_PID_MASK) >> MP2T_PID_SHIFT, (header & MP2T_CC_MASK) >> MP2T_CC_SHIFT );
204
205
206         hi = proto_tree_add_item( mp2t_tree, hf_mp2t_header, tvb, offset, 4, FALSE);
207         mp2t_header_tree = proto_item_add_subtree( hi, ett_mp2t );
208
209         proto_tree_add_item( mp2t_header_tree, hf_mp2t_sync_byte, tvb, offset, 4, FALSE);
210         proto_tree_add_item( mp2t_header_tree, hf_mp2t_tei, tvb, offset, 4, FALSE);
211         proto_tree_add_item( mp2t_header_tree, hf_mp2t_pusi, tvb, offset, 4, FALSE);
212         proto_tree_add_item( mp2t_header_tree, hf_mp2t_tp, tvb, offset, 4, FALSE);
213         proto_tree_add_item( mp2t_header_tree, hf_mp2t_pid, tvb, offset, 4, FALSE);
214         proto_tree_add_item( mp2t_header_tree, hf_mp2t_tsc, tvb, offset, 4, FALSE);
215         proto_tree_add_item( mp2t_header_tree, hf_mp2t_afc, tvb, offset, 4, FALSE);
216         proto_tree_add_item( mp2t_header_tree, hf_mp2t_cc, tvb, offset, 4, FALSE);
217         offset += 4;
218
219         afc = (header & MP2T_AFC_MASK) >> MP2T_AFC_SHIFT;
220
221         if (afc == 2 || afc == 3) 
222         {
223                 gint af_start_offset = offset;
224         
225                 guint8 af_length;
226                 guint8 af_flags;
227                 gint stuffing_len;
228
229
230                 af_length = tvb_get_guint8(tvb, offset);
231
232                 proto_tree_add_item( mp2t_tree, hf_mp2t_af_length, tvb, offset, 1, FALSE);
233                 offset += 1;
234
235                 hi = proto_tree_add_item( mp2t_tree, hf_mp2t_af, tvb, offset, af_length, FALSE);
236                 mp2t_af_tree = proto_item_add_subtree( hi, ett_mp2t );
237
238                 af_flags = tvb_get_guint8(tvb, offset);
239
240                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_di, tvb, offset, 1, FALSE);
241                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_rai, tvb, offset, 1, FALSE);
242                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_espi, tvb, offset, 1, FALSE);
243                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_pcr_flag, tvb, offset, 1, FALSE);
244                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_opcr_flag, tvb, offset, 1, FALSE);
245                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_sp_flag, tvb, offset, 1, FALSE);
246                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_tpd_flag, tvb, offset, 1, FALSE);
247                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_afe_flag, tvb, offset, 1, FALSE);
248
249                 offset += 1;
250
251                 if (af_flags &  MP2T_AF_PCR_MASK) {
252                         guint64 pcr_base = 0;
253                         guint32 pcr_ext = 0;
254                         guint8 tmp;
255
256                         tmp = tvb_get_guint8(tvb, offset);
257                         pcr_base = (pcr_base << 8) | tmp;
258                         offset += 1;
259                         
260                         tmp = tvb_get_guint8(tvb, offset);
261                         pcr_base = (pcr_base << 8) | tmp;
262                         offset += 1;
263                         
264                         tmp = tvb_get_guint8(tvb, offset);
265                         pcr_base = (pcr_base << 8) | tmp;
266                         offset += 1;
267         
268                         tmp = tvb_get_guint8(tvb, offset);
269                         pcr_base = (pcr_base << 8) | tmp;
270                         offset += 1;
271
272                         tmp = tvb_get_guint8(tvb, offset);
273                         pcr_base = (pcr_base << 1) | ((tmp >> 7) & 0x01);
274                         pcr_ext = (tmp & 0x01);
275                         offset += 1;
276
277                         tmp = tvb_get_guint8(tvb, offset);
278                         pcr_ext = (pcr_ext << 8) | tmp;
279                         offset += 1;
280
281                         proto_tree_add_none_format(mp2t_af_tree, hf_mp2t_af_pcr, tvb, offset - 6, 6, 
282                                                 "Program Clock Reference: base(%" G_GINT64_MODIFIER "u) * 300 + ext(%u) = %" G_GINT64_MODIFIER "u", 
283                                                 pcr_base, pcr_ext, pcr_base * 300 + pcr_ext);
284                 }
285
286                 if (af_flags &  MP2T_AF_OPCR_MASK) {
287                         guint64 opcr_base = 0;
288                         guint32 opcr_ext = 0;
289                         guint8 tmp = 0;
290
291                         tmp = tvb_get_guint8(tvb, offset);
292                         opcr_base = (opcr_base << 8) | tmp;
293                         offset += 1;
294                         
295                         tmp = tvb_get_guint8(tvb, offset);
296                         opcr_base = (opcr_base << 8) | tmp;
297                         offset += 1;
298                         
299                         tmp = tvb_get_guint8(tvb, offset);
300                         opcr_base = (opcr_base << 8) | tmp;
301                         offset += 1;
302         
303                         tmp = tvb_get_guint8(tvb, offset);
304                         opcr_base = (opcr_base << 8) | tmp;
305                         offset += 1;
306
307                         tmp = tvb_get_guint8(tvb, offset);
308                         opcr_base = (opcr_base << 1) | ((tmp >> 7) & 0x01);
309                         opcr_ext = (tmp & 0x01);
310                         offset += 1;
311
312                         tmp = tvb_get_guint8(tvb, offset);
313                         opcr_ext = (opcr_ext << 8) | tmp;
314                         offset += 1;
315
316                         proto_tree_add_none_format(mp2t_af_tree, hf_mp2t_af_opcr, tvb, offset - 6, 6, 
317                                                 "Original Program Clock Reference: base(%" G_GINT64_MODIFIER "u) * 300 + ext(%u) = %" G_GINT64_MODIFIER "u", 
318                                                 opcr_base, opcr_ext, opcr_base * 300 + opcr_ext);
319         
320                         offset += 6;
321                 }
322
323                 if (af_flags &  MP2T_AF_SP_MASK) {
324                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_sc, tvb, offset, 1, FALSE);
325                         offset += 1;
326                 }
327
328                 if (af_flags &  MP2T_AF_TPD_MASK) {
329                         guint8 tpd_len;
330                 
331                         tpd_len = tvb_get_guint8(tvb, offset);
332                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_tpd_length, tvb, offset, 1, FALSE);
333                         offset += 1;
334
335                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_tpd, tvb, offset, tpd_len, FALSE);
336                         offset += tpd_len;
337                 }
338
339                 if (af_flags &  MP2T_AF_AFE_MASK) {
340                         guint8 e_len;
341                         guint8 e_flags;
342                         gint e_start_offset = offset;
343                         gint reserved_len = 0;
344
345                         e_len = tvb_get_guint8(tvb, offset);
346                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_length, tvb, offset, 1, FALSE);
347                         offset += 1;
348
349                         e_flags = tvb_get_guint8(tvb, offset);
350                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_ltw_flag, tvb, offset, 1, FALSE);
351                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_pr_flag, tvb, offset, 1, FALSE);
352                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_ss_flag, tvb, offset, 1, FALSE);
353                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_reserved, tvb, offset, 1, FALSE);                       
354                         offset += 1;
355                         
356                         if (e_flags & MP2T_AF_E_LTW_FLAG_MASK) {
357                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_ltwv_flag, tvb, offset, 2, FALSE);
358                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_ltwo, tvb, offset, 2, FALSE);
359                                 offset += 2;
360                         }
361
362                         if (e_flags & MP2T_AF_E_PR_FLAG_MASK) {
363                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_pr_reserved, tvb, offset, 3, FALSE);
364                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_pr, tvb, offset, 3, FALSE);
365                                 offset += 3;
366                         }
367
368                         if (e_flags & MP2T_AF_E_SS_FLAG_MASK) {
369                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_st, tvb, offset, 1, FALSE);
370                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_dnau_32_30, tvb, offset, 1, FALSE);
371                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_m_1, tvb, offset, 1, FALSE);
372                                 offset += 1;
373                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_dnau_29_15, tvb, offset, 2, FALSE);
374                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_m_2, tvb, offset, 2, FALSE);
375                                 offset += 2;
376                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_dnau_14_0, tvb, offset, 2, FALSE);
377                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_m_3, tvb, offset, 2, FALSE);
378                                 offset += 2;
379                         }
380
381                         reserved_len = (e_len + 1) - (offset - e_start_offset);
382                         if (reserved_len > 0) {
383                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_reserved_bytes, tvb, offset, reserved_len, FALSE);
384                                 offset += reserved_len;
385                         }
386                 }
387
388                 stuffing_len = (af_length + 1) - (offset - af_start_offset);
389                 if (stuffing_len > 0) {
390                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_stuffing_bytes, tvb, offset, stuffing_len, FALSE);
391                         offset += stuffing_len;
392                 }
393         }
394
395         payload_len = MP2T_PACKET_SIZE - (offset - start_offset);
396         if (payload_len > 0) {
397                 if (afc == 2) { /* AF only */
398                         /* Packet is malformed */
399                         proto_tree_add_item( mp2t_tree, hf_mp2t_malformed_payload, tvb, offset, payload_len, FALSE);
400                         offset += payload_len;
401                 } else {
402                         proto_tree_add_item( mp2t_tree, hf_mp2t_payload, tvb, offset, payload_len, FALSE);
403                         offset += payload_len;
404                 }
405         }
406
407         return offset;
408 }
409
410
411 static void
412 dissect_mp2t( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
413 {
414         guint offset = 0;
415
416         if (tree) {
417                 while ( tvb_reported_length_remaining(tvb, offset) >= MP2T_PACKET_SIZE ) {
418                         offset = dissect_tsp( tvb, offset, pinfo, tree);
419                 }
420         }
421 }
422
423 void
424 proto_register_mp2t(void)
425 {
426         static hf_register_info hf[] = { 
427                 { &hf_mp2t_header, {
428                         "Header", "mp2t.header",
429                         FT_UINT32, BASE_HEX, NULL, 0, "", HFILL
430                 } } ,
431                 { &hf_mp2t_sync_byte, {
432                         "Sync Byte", "mp2t.sync_byte",
433                         FT_UINT32, BASE_HEX, VALS(mp2t_sync_byte_vals), MP2T_SYNC_BYTE_MASK, "", HFILL
434                 } } ,
435                 { &hf_mp2t_tei, { 
436                         "Transport Error Indicator", "mp2t.tei",
437                         FT_UINT32, BASE_DEC, NULL, MP2T_TEI_MASK, "", HFILL
438                 } } ,
439                 { &hf_mp2t_pusi, {
440                         "Payload Unit Start Indicator", "mp2s.pusi",
441                         FT_UINT32, BASE_DEC, NULL, MP2T_PUSI_MASK, "", HFILL
442                 } } ,
443                 { &hf_mp2t_tp, {
444                         "Transport Priority", "mp2t.tp",
445                         FT_UINT32, BASE_DEC, NULL, MP2T_TP_MASK, "", HFILL
446                 } } ,
447                 { &hf_mp2t_pid, {
448                         "PID", "mp2s.pid",
449                         FT_UINT32, BASE_HEX, VALS(mp2t_pid_vals), MP2T_PID_MASK, "", HFILL
450                 } } ,
451                 { &hf_mp2t_tsc, {
452                         "Transport Scrambling Control", "mp2t.tsc",
453                         FT_UINT32, BASE_HEX, VALS(mp2t_tsc_vals), MP2T_TSC_MASK, "", HFILL
454                 } } ,
455                 { &hf_mp2t_afc, {
456                         "Adaption Field Control", "mp2t.afc",
457                         FT_UINT32, BASE_HEX, VALS(mp2t_afc_vals) , MP2T_AFC_MASK, "", HFILL
458                 } } ,
459                 { &hf_mp2t_cc, {
460                         "Continuity Counter", "mp2t.cc",
461                         FT_UINT32, BASE_DEC, NULL, MP2T_CC_MASK, "", HFILL
462                 } } ,
463                 { &hf_mp2t_af, {
464                         "Adaption field", "mp2t.af",
465                         FT_NONE, BASE_HEX, NULL, 0, "", HFILL
466                 } } ,
467                 { &hf_mp2t_af_length, {
468                         "Adaptation Field Length", "mp2t.af.length",
469                         FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL
470                 } } ,
471                 { &hf_mp2t_af_di, {
472                         "Discontinuity Indicator", "mp2t.af.di",
473                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_DI_MASK, "", HFILL
474                 } } ,
475                 { &hf_mp2t_af_rai, {
476                         "Random Access Indicator", "mp2t.af.rai",
477                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_RAI_MASK, "", HFILL
478                 } } ,
479                 { &hf_mp2t_af_espi, {
480                         "Elementary Stream Priority Indicator", "mp2t.af.espi",
481                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_ESPI_MASK, "", HFILL
482                 } } ,
483                 { &hf_mp2t_af_pcr_flag, {
484                         "PCR Flag", "mp2t.af.pcr_flag",
485                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_PCR_MASK, "", HFILL
486                 } } ,
487                 { &hf_mp2t_af_opcr_flag, {
488                         "OPCR Flag", "mp2t.af.opcr_flag",
489                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_OPCR_MASK, "", HFILL
490                 } } ,
491                 { &hf_mp2t_af_sp_flag, {
492                         "Splicing Point Flag", "mp2t.af.sp_flag",
493                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_SP_MASK, "", HFILL
494                 } } ,
495                 { &hf_mp2t_af_tpd_flag, {
496                         "Transport Private Data Flag", "mp2t.af.tpd_flag",
497                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_TPD_MASK, "", HFILL
498                 } } ,
499                 { &hf_mp2t_af_afe_flag, {
500                         "Adaptation Field Extension Flag", "mp2t.af.afe_flag",
501                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_AFE_MASK, "", HFILL
502                 } } ,
503                 { &hf_mp2t_af_pcr, {
504                         "Program Clock Reference", "mp2t.af.pcr",
505                         FT_NONE, BASE_DEC, NULL, 0, "", HFILL
506                 } } ,
507                 { &hf_mp2t_af_opcr, {
508                         "Original Program Clock Reference", "mp2t.af.opcr",
509                         FT_NONE, BASE_DEC, NULL, 0, "", HFILL
510                 } } ,
511                 { &hf_mp2t_af_sc, {
512                         "Splice Countdown", "mp2t.af.sc",
513                         FT_UINT8, BASE_DEC, NULL, 0, "", HFILL
514                 } } ,
515                 { &hf_mp2t_af_tpd_length, {
516                         "Transport Private Data Length", "mp2t.af.tpd_length",
517                         FT_UINT8, BASE_DEC, NULL, 0, "", HFILL
518                 } } ,
519                 { &hf_mp2t_af_tpd, {
520                         "Transport Private Data", "mp2t.af.tpd",
521                         FT_BYTES, BASE_DEC, NULL, 0, "", HFILL
522                 } } ,
523                 { &hf_mp2t_af_e_length, {
524                         "Adaptation Field Extension Length", "mp2t.af.e_length",
525                         FT_UINT8, BASE_DEC, NULL, 0, "", HFILL
526                 } } ,
527                 { &hf_mp2t_af_e_ltw_flag, {
528                         "LTW Flag", "mp2t.af.e.ltw_flag",
529                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_E_LTW_FLAG_MASK, "", HFILL
530                 } } ,
531                 { &hf_mp2t_af_e_pr_flag, {
532                         "Piecewise Rate Flag", "mp2t.af.e.pr_flag",
533                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_E_PR_FLAG_MASK, "", HFILL
534                 } } ,
535                 { &hf_mp2t_af_e_ss_flag, {
536                         "Seamless Splice Flag", "mp2t.af.e.ss_flag",
537                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_E_SS_FLAG_MASK, "", HFILL
538                 } } ,
539                 { &hf_mp2t_af_e_reserved, {
540                         "Reserved", "mp2t.af.e.reserved",
541                         FT_UINT8, BASE_DEC, NULL, 0x1F, "", HFILL
542                 } } ,
543                 { &hf_mp2t_af_e_reserved_bytes, {
544                         "Reserved", "mp2t.af.e.reserved_bytes",
545                         FT_BYTES, BASE_DEC, NULL, 0x0, "", HFILL
546                 } } ,
547                 { &hf_mp2t_af_stuffing_bytes, {
548                         "Stuffing", "mp2t.af.stuffing_bytes",
549                         FT_BYTES, BASE_DEC, NULL, 0x0, "", HFILL
550                 } } ,
551                 { &hf_mp2t_af_e_ltwv_flag, {
552                         "LTW Valid Flag", "mp2t.af.e.ltwv_flag",
553                         FT_UINT16, BASE_DEC, NULL, 0x8000, "", HFILL
554                 } } ,
555                 { &hf_mp2t_af_e_ltwo, {
556                         "LTW Offset", "mp2t.af.e.ltwo",
557                         FT_UINT16, BASE_DEC, NULL, 0x7FFF, "", HFILL
558                 } } ,
559                 { &hf_mp2t_af_e_pr_reserved, {
560                         "Reserved", "mp2t.af.e.pr_reserved",
561                         FT_UINT24, BASE_DEC, NULL, 0xC00000, "", HFILL
562                 } } ,
563                 { &hf_mp2t_af_e_pr, {
564                         "Piecewise Rate", "mp2t.af.e.pr",
565                         FT_UINT24, BASE_DEC, NULL, 0x3FFFFF, "", HFILL
566                 } } ,
567                 { &hf_mp2t_af_e_st, {
568                         "Splice Type", "mp2t.af.e.st",
569                         FT_UINT8, BASE_DEC, NULL, 0xF0, "", HFILL
570                 } } ,
571                 { &hf_mp2t_af_e_dnau_32_30, {
572                         "DTS Next AU[32...30]", "mp2t.af.e.dnau_32_30",
573                         FT_UINT8, BASE_DEC, NULL, 0x0E, "", HFILL
574                 } } ,
575                 { &hf_mp2t_af_e_m_1, {
576                         "Marker Bit", "mp2t.af.e.m_1",
577                         FT_UINT8, BASE_DEC, NULL, 0x01, "", HFILL
578                 } } ,
579                 { &hf_mp2t_af_e_dnau_29_15, {
580                         "DTS Next AU[29...15]", "mp2t.af.e.dnau_29_15",
581                         FT_UINT16, BASE_DEC, NULL, 0xFFFE, "", HFILL
582                 } } ,
583                 { &hf_mp2t_af_e_m_2, {
584                         "Marker Bit", "mp2t.af.e.m_2",
585                         FT_UINT16, BASE_DEC, NULL, 0x0001, "", HFILL
586                 } } ,
587                 { &hf_mp2t_af_e_dnau_14_0, {
588                         "DTS Next AU[14...0]", "mp2t.af.e.dnau_14_0",
589                         FT_UINT16, BASE_DEC, NULL, 0xFFFE, "", HFILL
590                 } } ,
591                 { &hf_mp2t_af_e_m_3, {
592                         "Marker Bit", "mp2t.af.e.m_3",
593                         FT_UINT16, BASE_DEC, NULL, 0x0001, "", HFILL
594                 } } ,
595                 { &hf_mp2t_payload, {
596                         "Payload", "mp2t.payload",
597                         FT_BYTES, BASE_DEC, NULL, 0x0, "", HFILL
598                 } } ,
599                 { &hf_mp2t_malformed_payload, {
600                         "Malformed Payload", "mp2t.malformed_payload",
601                         FT_BYTES, BASE_DEC, NULL, 0x0, "", HFILL
602                 } } ,
603         };
604
605         static gint *ett[] =
606         {
607                 &ett_mp2t,
608         };
609
610         proto_mp2t = proto_register_protocol("ISO/IEC 13818-1", "MP2T", "mp2t");
611         proto_register_field_array(proto_mp2t, hf, array_length(hf));
612         proto_register_subtree_array(ett, array_length(ett));
613 }
614
615
616
617 void
618 proto_reg_handoff_mp2t(void)
619 {
620         dissector_handle_t mp2t_handle;
621
622         mp2t_handle = create_dissector_handle(dissect_mp2t, proto_mp2t);
623         dissector_add("rtp.pt", PT_MP2T, mp2t_handle);
624 }
625