3 * Routines for ITU-T Recommendation H.263 dissection
5 * Copyright 2003 Niklas Ă–gren <niklas.ogren@7l.se>
6 * Seven Levels Consultants AB
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>
48 #include "iax2_codec_type.h"
50 /* H.263 header fields */
51 static int proto_h263 = -1;
54 static int hf_h263_ftype = -1;
55 static int hf_h263_pbframes = -1;
56 static int hf_h263_sbit = -1;
57 static int hf_h263_ebit = -1;
58 static int hf_h263_srcformat = -1;
59 static int hf_h263_picture_coding_type = -1;
60 static int hf_h263_unrestricted_motion_vector = -1;
61 static int hf_h263_syntax_based_arithmetic = -1;
62 static int hf_h263_advanced_prediction = -1;
63 static int hf_h263_r = -1;
64 static int hf_h263_rr = -1;
65 static int hf_h263_dbq = -1;
66 static int hf_h263_trb = -1;
67 static int hf_h263_tr = -1;
68 /* Additional fields for Mode B or C header */
69 static int hf_h263_quant = -1;
70 static int hf_h263_gobn = -1;
71 static int hf_h263_mba = -1;
72 static int hf_h263_hmv1 = -1;
73 static int hf_h263_vmv1 = -1;
74 static int hf_h263_hmv2 = -1;
75 static int hf_h263_vmv2 = -1;
77 static int hf_h263_data = -1;
79 /* Source format types */
80 #define SRCFORMAT_FORB 0 /* forbidden */
81 #define SRCFORMAT_SQCIF 1
82 #define SRCFORMAT_QCIF 2
83 #define SRCFORMAT_CIF 3
84 #define SRCFORMAT_4CIF 4
85 #define SRCFORMAT_16CIF 5
87 static const value_string srcformat_vals[] =
89 { SRCFORMAT_FORB, "forbidden" },
90 { SRCFORMAT_SQCIF, "sub-QCIF 128x96" },
91 { SRCFORMAT_QCIF, "QCIF 176x144" },
92 { SRCFORMAT_CIF, "CIF 352x288" },
93 { SRCFORMAT_4CIF, "4CIF 704x576" },
94 { SRCFORMAT_16CIF, "16CIF 1408x1152" },
98 /* H.263 fields defining a sub tree */
99 static gint ett_h263 = -1;
102 dissect_h263( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
104 proto_item *ti = NULL;
105 proto_tree *h263_tree = NULL;
106 unsigned int offset = 0;
107 unsigned int h263_version = 0;
109 h263_version = (tvb_get_guint8( tvb, offset ) & 0xc0 ) >> 6;
111 if ( check_col( pinfo->cinfo, COL_PROTOCOL ) ) {
112 col_set_str( pinfo->cinfo, COL_PROTOCOL, "H.263" );
115 if( h263_version == 0x00) {
116 if ( check_col( pinfo->cinfo, COL_INFO) ) {
117 col_append_str( pinfo->cinfo, COL_INFO, " MODE A");
120 else if( h263_version == 0x02) {
121 if ( check_col( pinfo->cinfo, COL_INFO) ) {
122 col_append_str( pinfo->cinfo, COL_INFO, " MODE B");
125 else if( h263_version == 0x03) {
126 if ( check_col( pinfo->cinfo, COL_INFO) ) {
127 col_append_str( pinfo->cinfo, COL_INFO, " MODE C");
132 ti = proto_tree_add_item( tree, proto_h263, tvb, offset, -1, FALSE );
133 h263_tree = proto_item_add_subtree( ti, ett_h263 );
135 /* FBIT 1st octet, 1 bit */
136 proto_tree_add_boolean( h263_tree, hf_h263_ftype, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x80 );
137 /* PBIT 1st octet, 1 bit */
138 proto_tree_add_boolean( h263_tree, hf_h263_pbframes, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x40 );
139 /* SBIT 1st octet, 3 bits */
140 proto_tree_add_uint( h263_tree, hf_h263_sbit, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x38 ) >> 3 );
141 /* EBIT 1st octet, 3 bits */
142 proto_tree_add_uint( h263_tree, hf_h263_ebit, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x7 );
146 /* SRC 2nd octet, 3 bits */
147 proto_tree_add_uint( h263_tree, hf_h263_srcformat, tvb, offset, 1, tvb_get_guint8( tvb, offset ) >> 5 );
149 if(h263_version == 0x00) { /* MODE A */
151 proto_tree_add_boolean( h263_tree, hf_h263_picture_coding_type, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x10 );
153 proto_tree_add_boolean( h263_tree, hf_h263_unrestricted_motion_vector, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x08 );
155 proto_tree_add_boolean( h263_tree, hf_h263_syntax_based_arithmetic, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x04 );
157 proto_tree_add_boolean( h263_tree, hf_h263_advanced_prediction, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x02 );
159 /* Reserved 2nd octect, 1 bit + 3rd octect 3 bits */
160 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 ) );
164 /* DBQ 3 octect, 2 bits */
165 proto_tree_add_uint( h263_tree, hf_h263_dbq, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x18 ) >> 3 );
166 /* TRB 3 octect, 3 bits */
167 proto_tree_add_uint( h263_tree, hf_h263_trb, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x07 ) );
171 /* TR 4 octect, 8 bits */
172 proto_tree_add_uint( h263_tree, hf_h263_tr, tvb, offset, 1, tvb_get_guint8( tvb, offset ) );
176 } else { /* MODE B or MODE C */
178 /* QUANT 2 octect, 5 bits */
179 proto_tree_add_uint( h263_tree, hf_h263_quant, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x1f );
183 /* GOBN 3 octect, 5 bits */
184 proto_tree_add_uint( h263_tree, hf_h263_gobn, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0xf8 ) >> 3);
185 /* MBA 3 octect, 3 bits + 4 octect 6 bits */
186 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 ) );
190 /* Reserved 4th octect, 2 bits */
191 proto_tree_add_uint( h263_tree, hf_h263_r, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x3 ) );
196 proto_tree_add_boolean( h263_tree, hf_h263_picture_coding_type, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x80 );
198 proto_tree_add_boolean( h263_tree, hf_h263_unrestricted_motion_vector, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x40 );
200 proto_tree_add_boolean( h263_tree, hf_h263_syntax_based_arithmetic, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x20 );
202 proto_tree_add_boolean( h263_tree, hf_h263_advanced_prediction, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x10 );
204 /* HMV1 5th octect, 4 bits + 6th octect 3 bits*/
205 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) );
209 /* VMV1 6th octect, 5 bits + 7th octect 2 bits*/
210 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) );
214 /* HMV2 7th octect, 6 bits + 8th octect 1 bit*/
215 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) );
219 /* VMV2 8th octect, 7 bits*/
220 proto_tree_add_uint( h263_tree, hf_h263_vmv2, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x7f );
224 if(h263_version == 0x03) { /* MODE C */
225 /* Reserved 9th to 11th octect, 8 + 8 + 3 bits */
226 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 ) );
230 /* DBQ 11th octect, 2 bits */
231 proto_tree_add_uint( h263_tree, hf_h263_dbq, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x18 ) >>3 );
232 /* TRB 11th octect, 3 bits */
233 proto_tree_add_uint( h263_tree, hf_h263_trb, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x07 );
237 /* TR 12th octect, 8 bits */
238 proto_tree_add_uint( h263_tree, hf_h263_tr, tvb, offset, 1, tvb_get_guint8( tvb, offset ) );
242 } /* end not mode a */
244 /* The rest of the packet is the H.263 stream */
245 proto_tree_add_item( h263_tree, hf_h263_data, tvb, offset, -1, FALSE );
250 proto_register_h263(void)
252 static hf_register_info hf[] =
263 "Indicates the mode of the payload header (MODE A or B/C)", HFILL
275 "Optional PB-frames mode as defined by H.263 (MODE C)", HFILL
281 "Start bit position",
287 "Start bit position specifies number of most significant bits that shall be ignored in the first data byte.", HFILL
299 "End bit position specifies number of least significant bits that shall be ignored in the last data byte.", HFILL
309 VALS(srcformat_vals),
311 "Source format specifies the resolution of the current picture.", HFILL
315 &hf_h263_picture_coding_type,
318 "h263.picture_coding_type",
323 "Picture coding type, intra-coded (false) or inter-coded (true)", HFILL
327 &hf_h263_unrestricted_motion_vector,
330 "h263.unrestricted_motion_vector",
335 "Unrestricted Motion Vector option for current picture", HFILL
339 &hf_h263_syntax_based_arithmetic,
341 "Syntax-based arithmetic coding",
342 "h263.syntax_based_arithmetic",
347 "Syntax-based Arithmetic Coding option for current picture", HFILL
351 &hf_h263_advanced_prediction,
353 "Advanced prediction option",
354 "h263.advanced_prediction",
359 "Advanced Prediction option for current picture", HFILL
365 "Differential quantization parameter",
371 "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
377 "Temporal Reference for B frames",
383 "Temporal Reference for the B frame as defined by H.263", HFILL
389 "Temporal Reference for P frames",
395 "Temporal Reference for the P frame as defined by H.263", HFILL
407 "Quantization value for the first MB coded at the starting of the packet.", HFILL
419 "GOB number in effect at the start of the packet.", HFILL
425 "Macroblock address",
431 "The address within the GOB of the first MB in the packet, counting from zero in scan order.", HFILL
437 "Horizontal motion vector 1",
443 "Horizontal motion vector predictor for the first MB in this packet ", HFILL
449 "Vertical motion vector 1",
455 "Vertical motion vector predictor for the first MB in this packet ", HFILL
461 "Horizontal motion vector 2",
467 "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
473 "Vertical motion vector 2",
479 "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
491 "Reserved field that houls contain zeroes", HFILL
503 "Reserved field that should contain zeroes", HFILL
515 "The H.263 stream including its Picture, GOB or Macro block start code.", HFILL
526 proto_h263 = proto_register_protocol("ITU-T Recommendation H.263 RTP Payload header (RFC2190)",
528 proto_register_field_array(proto_h263, hf, array_length(hf));
529 proto_register_subtree_array(ett, array_length(ett));
530 register_dissector("h263", dissect_h263, proto_h263);
534 proto_reg_handoff_h263(void)
536 dissector_handle_t h263_handle;
538 h263_handle = find_dissector("h263");
539 dissector_add("rtp.pt", PT_H263, h263_handle);
540 dissector_add("iax2.codec", AST_FORMAT_H263, h263_handle);