3 * Routines for ITU-T Recommendation H.263 dissection
5 * Copyright 2003 Niklas Ă–gren <niklas.ogren@7l.se>
6 * Seven Levels Consultants AB
8 * $Id: packet-h263.c,v 1.4 2003/08/25 21:48:44 guy Exp $
10 * Ethereal - Network traffic analyzer
11 * By Gerald Combs <gerald@ethereal.com>
12 * Copyright 1998 Gerald Combs
14 * Copied structure from packet-h261.c
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 * This dissector tries to dissect the H.263 protocol according to
33 * ITU-T Recommendations and RFC 2190
42 #include <epan/packet.h>
49 /* H.263 header fields */
50 static int proto_h263 = -1;
53 static int hf_h263_ftype = -1;
54 static int hf_h263_pbframes = -1;
55 static int hf_h263_sbit = -1;
56 static int hf_h263_ebit = -1;
57 static int hf_h263_srcformat = -1;
58 static int hf_h263_picture_coding_type = -1;
59 static int hf_h263_unrestricted_motion_vector = -1;
60 static int hf_h263_syntax_based_arithmetic = -1;
61 static int hf_h263_advanced_prediction = -1;
62 static int hf_h263_r = -1;
63 static int hf_h263_rr = -1;
64 static int hf_h263_dbq = -1;
65 static int hf_h263_trb = -1;
66 static int hf_h263_tr = -1;
67 /* Additional fields for Mode B or C header */
68 static int hf_h263_quant = -1;
69 static int hf_h263_gobn = -1;
70 static int hf_h263_mba = -1;
71 static int hf_h263_hmv1 = -1;
72 static int hf_h263_vmv1 = -1;
73 static int hf_h263_hmv2 = -1;
74 static int hf_h263_vmv2 = -1;
76 static int hf_h263_data = -1;
78 /* Source format types */
79 #define SRCFORMAT_FORB 0 /* forbidden */
80 #define SRCFORMAT_SQCIF 1
81 #define SRCFORMAT_QCIF 2
82 #define SRCFORMAT_CIF 3
83 #define SRCFORMAT_4CIF 4
84 #define SRCFORMAT_16CIF 5
86 static const value_string srcformat_vals[] =
88 { SRCFORMAT_FORB, "forbidden" },
89 { SRCFORMAT_SQCIF, "sub-QCIF 128x96" },
90 { SRCFORMAT_QCIF, "QCIF 176x144" },
91 { SRCFORMAT_CIF, "CIF 352x288" },
92 { SRCFORMAT_4CIF, "4CIF 704x576" },
93 { SRCFORMAT_16CIF, "16CIF 1408x1152" },
97 /* H.263 fields defining a sub tree */
98 static gint ett_h263 = -1;
101 dissect_h263( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
103 proto_item *ti = NULL;
104 proto_tree *h263_tree = NULL;
105 unsigned int offset = 0;
106 unsigned int h263_version = 0;
108 h263_version = (tvb_get_guint8( tvb, offset ) & 0xc0 ) >> 6;
110 if ( check_col( pinfo->cinfo, COL_PROTOCOL ) ) {
111 col_set_str( pinfo->cinfo, COL_PROTOCOL, "H.263" );
114 if( h263_version == 0x00) {
115 if ( check_col( pinfo->cinfo, COL_INFO) ) {
116 col_append_str( pinfo->cinfo, COL_INFO, " MODE A");
119 else if( h263_version == 0x02) {
120 if ( check_col( pinfo->cinfo, COL_INFO) ) {
121 col_append_str( pinfo->cinfo, COL_INFO, " MODE B");
124 else if( h263_version == 0x03) {
125 if ( check_col( pinfo->cinfo, COL_INFO) ) {
126 col_append_str( pinfo->cinfo, COL_INFO, " MODE C");
131 ti = proto_tree_add_item( tree, proto_h263, tvb, offset, -1, FALSE );
132 h263_tree = proto_item_add_subtree( ti, ett_h263 );
134 /* FBIT 1st octet, 1 bit */
135 proto_tree_add_boolean( h263_tree, hf_h263_ftype, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x80 );
136 /* PBIT 1st octet, 1 bit */
137 proto_tree_add_boolean( h263_tree, hf_h263_pbframes, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x40 );
138 /* SBIT 1st octet, 3 bits */
139 proto_tree_add_uint( h263_tree, hf_h263_sbit, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x38 ) >> 3 );
140 /* EBIT 1st octet, 3 bits */
141 proto_tree_add_uint( h263_tree, hf_h263_ebit, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x7 );
145 /* SRC 2nd octet, 3 bits */
146 proto_tree_add_uint( h263_tree, hf_h263_srcformat, tvb, offset, 1, tvb_get_guint8( tvb, offset ) >> 5 );
148 if(h263_version == 0x00) { /* MODE A */
150 proto_tree_add_boolean( h263_tree, hf_h263_picture_coding_type, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x10 );
152 proto_tree_add_boolean( h263_tree, hf_h263_unrestricted_motion_vector, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x08 );
154 proto_tree_add_boolean( h263_tree, hf_h263_syntax_based_arithmetic, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x04 );
156 proto_tree_add_boolean( h263_tree, hf_h263_advanced_prediction, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x02 );
158 /* Reserved 2nd octect, 1 bit + 3rd octect 3 bits */
159 proto_tree_add_uint( h263_tree, hf_h263_r, tvb, offset, 2, ( ( tvb_get_guint8( tvb, offset ) & 0x1 ) << 3 ) + ( ( tvb_get_guint8( tvb, offset + 1 ) & 0xe0 ) >> 5 ) );
163 /* DBQ 3 octect, 2 bits */
164 proto_tree_add_uint( h263_tree, hf_h263_dbq, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x18 ) >> 3 );
165 /* TRB 3 octect, 3 bits */
166 proto_tree_add_uint( h263_tree, hf_h263_trb, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x07 ) );
170 /* TR 4 octect, 8 bits */
171 proto_tree_add_uint( h263_tree, hf_h263_tr, tvb, offset, 1, tvb_get_guint8( tvb, offset ) );
175 } else { /* MODE B or MODE C */
177 /* QUANT 2 octect, 5 bits */
178 proto_tree_add_uint( h263_tree, hf_h263_quant, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x1f );
182 /* GOBN 3 octect, 5 bits */
183 proto_tree_add_uint( h263_tree, hf_h263_gobn, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0xf8 ) >> 3);
184 /* MBA 3 octect, 3 bits + 4 octect 6 bits */
185 proto_tree_add_uint( h263_tree, hf_h263_mba, tvb, offset, 2, ( ( tvb_get_guint8( tvb, offset ) & 0x7 ) << 6 ) + ( ( tvb_get_guint8( tvb, offset + 1 ) & 0xfc ) >> 2 ) );
189 /* Reserved 4th octect, 2 bits */
190 proto_tree_add_uint( h263_tree, hf_h263_r, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x3 ) );
195 proto_tree_add_boolean( h263_tree, hf_h263_picture_coding_type, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x80 );
197 proto_tree_add_boolean( h263_tree, hf_h263_unrestricted_motion_vector, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x40 );
199 proto_tree_add_boolean( h263_tree, hf_h263_syntax_based_arithmetic, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x20 );
201 proto_tree_add_boolean( h263_tree, hf_h263_advanced_prediction, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x10 );
203 /* HMV1 5th octect, 4 bits + 6th octect 3 bits*/
204 proto_tree_add_uint( h263_tree, hf_h263_hmv1, tvb, offset, 2,( ( tvb_get_guint8( tvb, offset ) & 0xf ) << 3 ) + ( ( tvb_get_guint8( tvb, offset+1 ) & 0xe0 ) >> 5) );
208 /* VMV1 6th octect, 5 bits + 7th octect 2 bits*/
209 proto_tree_add_uint( h263_tree, hf_h263_vmv1, tvb, offset, 2,( ( tvb_get_guint8( tvb, offset ) & 0x1f ) << 2 ) + ( ( tvb_get_guint8( tvb, offset+1 ) & 0xc0 ) >> 6) );
213 /* HMV2 7th octect, 6 bits + 8th octect 1 bit*/
214 proto_tree_add_uint( h263_tree, hf_h263_hmv2, tvb, offset, 2,( ( tvb_get_guint8( tvb, offset ) & 0x3f ) << 1 ) + ( ( tvb_get_guint8( tvb, offset+1 ) & 0xf0 ) >> 7) );
218 /* VMV2 8th octect, 7 bits*/
219 proto_tree_add_uint( h263_tree, hf_h263_vmv2, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x7f );
223 if(h263_version == 0x03) { /* MODE C */
224 /* Reserved 9th to 11th octect, 8 + 8 + 3 bits */
225 proto_tree_add_uint( h263_tree, hf_h263_rr, tvb, offset, 3, ( tvb_get_guint8( tvb, offset ) << 11 ) + ( tvb_get_guint8( tvb, offset + 1 ) << 3 ) + ( ( tvb_get_guint8( tvb, offset + 2 ) & 0xe0 ) >> 5 ) );
229 /* DBQ 11th octect, 2 bits */
230 proto_tree_add_uint( h263_tree, hf_h263_dbq, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x18 ) >>3 );
231 /* TRB 11th octect, 3 bits */
232 proto_tree_add_uint( h263_tree, hf_h263_trb, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x07 );
236 /* TR 12th octect, 8 bits */
237 proto_tree_add_uint( h263_tree, hf_h263_tr, tvb, offset, 1, tvb_get_guint8( tvb, offset ) );
241 } /* end not mode a */
243 /* The rest of the packet is the H.263 stream */
244 proto_tree_add_item( h263_tree, hf_h263_data, tvb, offset, -1, FALSE );
249 proto_register_h263(void)
251 static hf_register_info hf[] =
262 "Indicates the mode of the payload header (MODE A or B/C)", HFILL
274 "Optional PB-frames mode as defined by H.263 (MODE C)", HFILL
280 "Start bit position",
286 "Start bit position specifies number of most significant bits that shall be ignored in the first data byte.", HFILL
298 "End bit position specifies number of least significant bits that shall be ignored in the last data byte.", HFILL
308 VALS(srcformat_vals),
310 "Source format specifies the resolution of the current picture.", HFILL
314 &hf_h263_picture_coding_type,
317 "h263.picture_coding_type",
322 "Picture coding type, intra-coded (false) or inter-coded (true)", HFILL
326 &hf_h263_unrestricted_motion_vector,
329 "h263.unrestricted_motion_vector",
334 "Unrestricted Motion Vector option for current picture", HFILL
338 &hf_h263_syntax_based_arithmetic,
340 "Syntax-based arithmetic coding",
341 "h263.syntax_based_arithmetic",
346 "Syntax-based Arithmetic Coding option for current picture", HFILL
350 &hf_h263_advanced_prediction,
352 "Advanced prediction option",
353 "h263.advanced_prediction",
358 "Advanced Prediction option for current picture", HFILL
364 "Differential quantization parameter",
370 "Differential quantization parameter used to calculate quantizer for the B frame based on quantizer for the P frame, when PB-frames option is used.", HFILL
376 "Temporal Reference for B frames",
382 "Temporal Reference for the B frame as defined by H.263", HFILL
388 "Temporal Reference for P frames",
394 "Temporal Reference for the P frame as defined by H.263", HFILL
406 "Quantization value for the first MB coded at the starting of the packet.", HFILL
418 "GOB number in effect at the start of the packet.", HFILL
424 "Macroblock address",
430 "The address within the GOB of the first MB in the packet, counting from zero in scan order.", HFILL
436 "Horizontal motion vector 1",
442 "Horizontal motion vector predictor for the first MB in this packet ", HFILL
448 "Vertical motion vector 1",
454 "Vertical motion vector predictor for the first MB in this packet ", HFILL
460 "Horizontal motion vector 2",
466 "Horizontal motion vector predictor for block number 3 in the first MB in this packet when four motion vectors are used with the advanced prediction option.", HFILL
472 "Vertical motion vector 2",
478 "Vertical motion vector predictor for block number 3 in the first MB in this packet when four motion vectors are used with the advanced prediction option.", HFILL
490 "Reserved field that houls contain zeroes", HFILL
502 "Reserved field that should contain zeroes", HFILL
514 "The H.263 stream including its Picture, GOB or Macro block start code.", HFILL
525 proto_h263 = proto_register_protocol("ITU-T Recommendation H.263 RTP Payload header (RFC2190)",
527 proto_register_field_array(proto_h263, hf, array_length(hf));
528 proto_register_subtree_array(ett, array_length(ett));
532 proto_reg_handoff_h263(void)
534 dissector_handle_t h263_handle;
536 h263_handle = create_dissector_handle(dissect_h263, proto_h263);
537 dissector_add("rtp.pt", PT_H263, h263_handle);