HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-mpeg1.c
blobf464aa2ecd72a3729241a1f8e9448bbb8d065567
1 /* packet-mpeg1.c
3 * Routines for RFC 2250 MPEG-1 dissection
5 * $Id$
7 * Copyright 2001,
8 * Francisco Javier Cabello Torres, <fjcabello@vtools.es>
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 * This dissector tries to dissect the MPEG-1 video streams.
34 #include "config.h"
36 #include <glib.h>
37 #include <epan/packet.h>
39 #include <epan/rtp_pt.h>
41 #define RTP_MPG_MBZ(word) ( word >> 11)
42 #define RTP_MPG_T(word) ( (word >> 10) & 1 )
43 #define RTP_MPG_TR(word) ( word & 0x3ff )
45 #define RTP_MPG_AN(octet) ( octet >> 7)
46 #define RTP_MPG_N(octet) ( (octet >> 6) & 1 )
47 #define RTP_MPG_S(octet) ( (octet >> 5) & 1 )
48 #define RTP_MPG_B(octet) ( (octet >> 4) & 1 )
49 #define RTP_MPG_E(octet) ( (octet >> 3) & 1 )
50 #define RTP_MPG_P(octet) ( octet & 7 )
52 #define RTP_MPG_FBV(octet) ( (octet >> 7) & 1 )
53 #define RTP_MPG_BFC(octet) ( (octet >> 4) & 7 )
54 #define RTP_MPG_FFV(octet) ( (octet >> 3) & 1 )
55 #define RTP_MPG_FFC(octet) ( octet & 7 )
58 /* MPEG1 header fields */
61 static int proto_mpg = -1;
63 static int hf_rtp_mpg_mbz = -1;
64 static int hf_rtp_mpg_T = -1;
65 static int hf_rtp_mpg_tr = -1;
66 static int hf_rtp_mpg_an = -1;
67 static int hf_rtp_mpg_n = -1;
68 static int hf_rtp_mpg_s = -1;
69 static int hf_rtp_mpg_b = -1;
70 static int hf_rtp_mpg_e = -1;
71 static int hf_rtp_mpg_p = -1;
74 static int hf_rtp_mpg_fbv = -1;
75 static int hf_rtp_mpg_bfc = -1;
76 static int hf_rtp_mpg_ffv = -1;
77 static int hf_rtp_mpg_ffc = -1;
78 static int hf_rtp_mpg_data = -1;
82 /* MPEG-1 fields defining a sub tree */
83 static gint ett_mpg = -1;
85 static const value_string rtp_mpg_picture_types_vals[] =
87 { 0, "Forbidden" },
88 { 1, "I-Picture" },
89 { 2, "P-Picture" },
90 { 3, "B-Picture" },
91 { 4, "D-Picture" },
92 { 5, "reserved" },
93 { 6, "reserved" },
94 { 7, "reserved" },
95 { 0, NULL },
98 static void
99 dissect_mpeg1( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
101 proto_item *ti = NULL;
102 proto_tree *mpg_tree = NULL;
103 unsigned int offset = 0;
105 guint8 octet;
106 guint16 word;
109 guint16 mpg_mbz;
110 guint16 mpg_T;
111 guint16 mpg_tr;
112 guint16 mpg_an;
113 guint16 mpg_n;
114 gboolean mpg_s;
115 gboolean mpg_b;
116 gboolean mpg_e;
117 guint16 mpg_p;
118 guint16 mpg_fbv;
119 guint16 mpg_bfc;
120 guint16 mpg_ffv;
121 guint16 mpg_ffc;
123 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPEG-1");
125 col_set_str(pinfo->cinfo, COL_INFO, "MPEG-1 message");
127 /* Get MPEG-1 fields */
129 word = tvb_get_guint8( tvb, offset );
130 word = (word << 8) | tvb_get_guint8( tvb, offset +1 );
131 mpg_mbz = RTP_MPG_MBZ(word);
132 mpg_T = RTP_MPG_T(word);
133 mpg_tr = RTP_MPG_TR(word);
135 octet = tvb_get_guint8( tvb, offset + 2 );
136 mpg_an = RTP_MPG_AN(octet);
137 mpg_n = RTP_MPG_N(octet);
138 mpg_s = RTP_MPG_S(octet);
139 mpg_b = RTP_MPG_B(octet);
140 mpg_e = RTP_MPG_E(octet);
141 mpg_p = RTP_MPG_P(octet);
143 octet = tvb_get_guint8( tvb, offset + 3 );
145 mpg_fbv = RTP_MPG_FBV(octet);
146 mpg_bfc = RTP_MPG_BFC(octet);
147 mpg_ffv = RTP_MPG_FFV(octet);
148 mpg_ffc = RTP_MPG_FFC(octet);
151 if ( tree )
153 ti = proto_tree_add_item( tree, proto_mpg, tvb, offset, -1, ENC_NA );
154 mpg_tree = proto_item_add_subtree( ti, ett_mpg );
156 proto_tree_add_uint( mpg_tree, hf_rtp_mpg_mbz, tvb, offset, 1, mpg_mbz );
157 proto_tree_add_uint( mpg_tree, hf_rtp_mpg_T , tvb, offset, 1, mpg_T );
158 proto_tree_add_uint( mpg_tree, hf_rtp_mpg_tr , tvb, offset, 2, mpg_tr );
159 offset += 2;
160 proto_tree_add_uint( mpg_tree, hf_rtp_mpg_an, tvb, offset, 1, mpg_an );
161 proto_tree_add_uint( mpg_tree, hf_rtp_mpg_n , tvb, offset, 1, mpg_n );
162 proto_tree_add_boolean( mpg_tree, hf_rtp_mpg_s , tvb, offset, 1, mpg_s );
163 proto_tree_add_boolean( mpg_tree, hf_rtp_mpg_b , tvb, offset, 1, mpg_b );
164 proto_tree_add_boolean( mpg_tree, hf_rtp_mpg_e , tvb, offset, 1, mpg_e );
166 proto_tree_add_uint( mpg_tree, hf_rtp_mpg_p, tvb , offset, 1, mpg_p );
167 offset += 1;
169 proto_tree_add_uint( mpg_tree, hf_rtp_mpg_fbv, tvb, offset, 1, mpg_fbv );
170 proto_tree_add_uint( mpg_tree, hf_rtp_mpg_bfc, tvb, offset, 1, mpg_bfc );
171 proto_tree_add_uint( mpg_tree, hf_rtp_mpg_ffv, tvb, offset, 1, mpg_ffv );
172 proto_tree_add_uint( mpg_tree, hf_rtp_mpg_ffc, tvb, offset, 1, mpg_ffc );
173 offset += 1;
175 /* The rest of the packet is the MPEG-1 stream */
176 proto_tree_add_item( mpg_tree, hf_rtp_mpg_data, tvb, offset, -1, ENC_NA );
181 void
182 proto_register_mpeg1(void)
184 static hf_register_info hf[] =
187 &hf_rtp_mpg_mbz,
189 "MBZ",
190 "rtp.payload_mpeg_mbz",
191 FT_UINT16,
192 BASE_DEC,
193 NULL,
194 0x0,
195 NULL, HFILL
199 &hf_rtp_mpg_T,
201 "T",
202 "rtp.payload_mpeg_T",
203 FT_UINT16,
204 BASE_DEC,
205 NULL,
206 0x0,
207 NULL, HFILL
211 &hf_rtp_mpg_tr,
213 "Temporal Reference",
214 "rtp.payload_mpeg_tr",
215 FT_UINT16,
216 BASE_DEC,
217 NULL,
218 0x0,
219 NULL, HFILL
223 &hf_rtp_mpg_an,
225 "AN",
226 "rtp.payload_mpeg_an",
227 FT_UINT16,
228 BASE_DEC,
229 NULL,
230 0x0,
231 NULL, HFILL
236 &hf_rtp_mpg_n,
238 "New Picture Header",
239 "rtp.payload_mpeg_n",
240 FT_UINT16,
241 BASE_DEC,
242 NULL,
243 0x0,
244 NULL, HFILL
249 &hf_rtp_mpg_s,
251 "Sequence Header",
252 "rtp.payload_mpeg_s",
253 FT_BOOLEAN,
254 BASE_NONE,
255 NULL,
256 0x0,
257 NULL, HFILL
262 &hf_rtp_mpg_b,
264 "Beginning-of-slice",
265 "rtp.payload_mpeg_b",
266 FT_BOOLEAN,
267 BASE_NONE,
268 NULL,
269 0x0,
270 NULL, HFILL
275 &hf_rtp_mpg_e,
277 "End-of-slice",
278 "rtp.payload_mpeg_an",
279 FT_BOOLEAN,
280 BASE_NONE,
281 NULL,
282 0x0,
283 NULL, HFILL
288 &hf_rtp_mpg_p,
290 "Picture type",
291 "rtp.payload_mpeg_p",
292 FT_UINT16,
293 BASE_DEC,
294 VALS(rtp_mpg_picture_types_vals),
295 0x0,
296 NULL, HFILL
301 &hf_rtp_mpg_fbv,
303 "FBV",
304 "rtp.payload_mpeg_fbv",
305 FT_UINT16,
306 BASE_DEC,
307 NULL,
308 0x0,
309 NULL, HFILL
314 &hf_rtp_mpg_bfc,
316 "BFC",
317 "rtp.payload_mpeg_bfc",
318 FT_UINT16,
319 BASE_DEC,
320 NULL,
321 0x0,
322 NULL, HFILL
326 &hf_rtp_mpg_ffv,
328 "FFV",
329 "rtp.payload_mpeg_ffv",
330 FT_UINT16,
331 BASE_DEC,
332 NULL,
333 0x0,
334 NULL, HFILL
339 &hf_rtp_mpg_ffc,
341 "FFC",
342 "rtp.payload_mpeg_ffc",
343 FT_UINT16,
344 BASE_DEC,
345 NULL,
346 0x0,
347 NULL, HFILL
351 &hf_rtp_mpg_data,
353 "MPEG-1 stream",
354 "mpeg1.stream",
355 FT_BYTES,
356 BASE_NONE,
357 NULL,
358 0x0,
359 NULL, HFILL
365 static gint *ett[] =
367 &ett_mpg,
371 proto_mpg = proto_register_protocol("RFC 2250 MPEG1","MPEG1","mpeg1");
372 proto_register_field_array(proto_mpg, hf, array_length(hf));
373 proto_register_subtree_array(ett, array_length(ett));
376 void
377 proto_reg_handoff_mpeg1(void)
379 dissector_handle_t mpeg1_handle;
381 mpeg1_handle = create_dissector_handle(dissect_mpeg1, proto_mpg);
382 dissector_add_uint("rtp.pt", PT_MPV, mpeg1_handle);