3 * Routines for ITU-T Recommendation H.263 dissection
5 * Copyright 2003 Niklas Ă–gren <niklas.ogren@7l.se>
6 * Seven Levels Consultants AB
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
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>
47 #include <epan/rtp_pt.h>
48 #include <epan/iax2_codec_type.h>
50 static void dissect_h263_data( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree );
52 /* H.263 header fields */
53 static int proto_h263 = -1;
54 static int proto_h263_data = -1;
57 static int hf_h263_ftype = -1;
58 static int hf_h263_pbframes = -1;
59 static int hf_h263_sbit = -1;
60 static int hf_h263_ebit = -1;
61 static int hf_h263_srcformat = -1;
62 static int hf_h263_picture_coding_type = -1;
63 static int hf_h263_unrestricted_motion_vector = -1;
64 static int hf_h263_syntax_based_arithmetic = -1;
65 static int hf_h263_advanced_prediction = -1;
66 static int hf_h263_r = -1;
67 static int hf_h263_rr = -1;
68 static int hf_h263_dbq = -1;
69 static int hf_h263_trb = -1;
70 static int hf_h263_tr = -1;
71 /* Additional fields for Mode B or C header */
72 static int hf_h263_quant = -1;
73 static int hf_h263_gobn = -1;
74 static int hf_h263_mba = -1;
75 static int hf_h263_hmv1 = -1;
76 static int hf_h263_vmv1 = -1;
77 static int hf_h263_hmv2 = -1;
78 static int hf_h263_vmv2 = -1;
79 /* Fields for the data section */
80 static int hf_h263_psc = -1;
81 static int hf_h263_gbsc = -1;
82 static int hf_h263_TR =-1;
83 static int hf_h263_split_screen_indicator = -1;
84 static int hf_h263_document_camera_indicator = -1;
85 static int hf_h263_full_picture_freeze_release = -1;
86 static int hf_h263_source_format = -1;
87 static int hf_h263_payload_picture_coding_type = -1;
88 static int hf_h263_opt_unres_motion_vector_mode = -1;
89 static int hf_h263_syntax_based_arithmetic_coding_mode = -1;
90 static int hf_h263_optional_advanced_prediction_mode = -1;
91 static int hf_h263_PB_frames_mode = -1;
92 static int hf_h263_data = -1;
93 static int hf_h263_payload = -1;
94 static int hf_h263_GN = -1;
96 /* Source format types */
97 #define SRCFORMAT_FORB 0 /* forbidden */
98 #define SRCFORMAT_SQCIF 1
99 #define SRCFORMAT_QCIF 2
100 #define SRCFORMAT_CIF 3
101 #define SRCFORMAT_4CIF 4
102 #define SRCFORMAT_16CIF 5
104 static const value_string srcformat_vals[] =
106 { SRCFORMAT_FORB, "forbidden" },
107 { SRCFORMAT_SQCIF, "sub-QCIF 128x96" },
108 { SRCFORMAT_QCIF, "QCIF 176x144" },
109 { SRCFORMAT_CIF, "CIF 352x288" },
110 { SRCFORMAT_4CIF, "4CIF 704x576" },
111 { SRCFORMAT_16CIF, "16CIF 1408x1152" },
115 static const true_false_string on_off_flg = {
119 static const true_false_string picture_coding_type_flg = {
124 static const true_false_string PB_frames_mode_flg = {
126 "Normal I- or P-picture"
129 /* H.263 fields defining a sub tree */
130 static gint ett_h263 = -1;
131 static gint ett_h263_payload = -1;
133 dissect_h263( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
135 proto_item *ti = NULL;
136 proto_tree *h263_tree = NULL;
137 unsigned int offset = 0;
138 unsigned int h263_version = 0;
141 h263_version = (tvb_get_guint8( tvb, offset ) & 0xc0 ) >> 6;
143 if ( check_col( pinfo->cinfo, COL_PROTOCOL ) ) {
144 col_set_str( pinfo->cinfo, COL_PROTOCOL, "H.263 " );
147 if( h263_version == 0x00) {
148 if ( check_col( pinfo->cinfo, COL_INFO) ) {
149 col_append_str( pinfo->cinfo, COL_INFO, "MODE A ");
152 else if( h263_version == 0x02) {
153 if ( check_col( pinfo->cinfo, COL_INFO) ) {
154 col_append_str( pinfo->cinfo, COL_INFO, "MODE B ");
157 else if( h263_version == 0x03) {
158 if ( check_col( pinfo->cinfo, COL_INFO) ) {
159 col_append_str( pinfo->cinfo, COL_INFO, "MODE C ");
164 ti = proto_tree_add_item( tree, proto_h263, tvb, offset, -1, FALSE );
165 h263_tree = proto_item_add_subtree( ti, ett_h263 );
167 /* FBIT 1st octet, 1 bit */
168 proto_tree_add_boolean( h263_tree, hf_h263_ftype, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x80 );
169 /* PBIT 1st octet, 1 bit */
170 proto_tree_add_boolean( h263_tree, hf_h263_pbframes, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x40 );
171 /* SBIT 1st octet, 3 bits */
172 proto_tree_add_uint( h263_tree, hf_h263_sbit, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x38 ) >> 3 );
173 /* EBIT 1st octet, 3 bits */
174 proto_tree_add_uint( h263_tree, hf_h263_ebit, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x7 );
178 /* SRC 2nd octet, 3 bits */
179 proto_tree_add_uint( h263_tree, hf_h263_srcformat, tvb, offset, 1, tvb_get_guint8( tvb, offset ) >> 5 );
181 if(h263_version == 0x00) { /* MODE A */
183 proto_tree_add_boolean( h263_tree, hf_h263_picture_coding_type, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x10 );
185 proto_tree_add_boolean( h263_tree, hf_h263_unrestricted_motion_vector, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x08 );
187 proto_tree_add_boolean( h263_tree, hf_h263_syntax_based_arithmetic, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x04 );
189 proto_tree_add_boolean( h263_tree, hf_h263_advanced_prediction, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x02 );
191 /* Reserved 2nd octect, 1 bit + 3rd octect 3 bits */
192 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 ) );
196 /* DBQ 3 octect, 2 bits */
197 proto_tree_add_uint( h263_tree, hf_h263_dbq, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x18 ) >> 3 );
198 /* TRB 3 octect, 3 bits */
199 proto_tree_add_uint( h263_tree, hf_h263_trb, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x07 ) );
203 /* TR 4 octect, 8 bits */
204 proto_tree_add_uint( h263_tree, hf_h263_tr, tvb, offset, 1, tvb_get_guint8( tvb, offset ) );
208 } else { /* MODE B or MODE C */
210 /* QUANT 2 octect, 5 bits */
211 proto_tree_add_uint( h263_tree, hf_h263_quant, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x1f );
215 /* GOBN 3 octect, 5 bits */
216 proto_tree_add_uint( h263_tree, hf_h263_gobn, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0xf8 ) >> 3);
217 /* MBA 3 octect, 3 bits + 4 octect 6 bits */
218 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 ) );
222 /* Reserved 4th octect, 2 bits */
223 proto_tree_add_uint( h263_tree, hf_h263_r, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x3 ) );
228 proto_tree_add_boolean( h263_tree, hf_h263_picture_coding_type, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x80 );
230 proto_tree_add_boolean( h263_tree, hf_h263_unrestricted_motion_vector, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x40 );
232 proto_tree_add_boolean( h263_tree, hf_h263_syntax_based_arithmetic, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x20 );
234 proto_tree_add_boolean( h263_tree, hf_h263_advanced_prediction, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x10 );
236 /* HMV1 5th octect, 4 bits + 6th octect 3 bits*/
237 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) );
241 /* VMV1 6th octect, 5 bits + 7th octect 2 bits*/
242 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) );
246 /* HMV2 7th octect, 6 bits + 8th octect 1 bit*/
247 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) );
251 /* VMV2 8th octect, 7 bits*/
252 proto_tree_add_uint( h263_tree, hf_h263_vmv2, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x7f );
256 if(h263_version == 0x03) { /* MODE C */
257 /* Reserved 9th to 11th octect, 8 + 8 + 3 bits */
258 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 ) );
262 /* DBQ 11th octect, 2 bits */
263 proto_tree_add_uint( h263_tree, hf_h263_dbq, tvb, offset, 1, ( tvb_get_guint8( tvb, offset ) & 0x18 ) >>3 );
264 /* TRB 11th octect, 3 bits */
265 proto_tree_add_uint( h263_tree, hf_h263_trb, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 0x07 );
269 /* TR 12th octect, 8 bits */
270 proto_tree_add_uint( h263_tree, hf_h263_tr, tvb, offset, 1, tvb_get_guint8( tvb, offset ) );
274 } /* end not mode a */
276 /* The rest of the packet is the H.263 stream */
277 next_tvb = tvb_new_subset( tvb, offset, tvb_length(tvb) - offset, tvb_reported_length(tvb) - offset);
278 dissect_h263_data( next_tvb, pinfo, h263_tree );
284 static void dissect_h263_data( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
287 proto_item *h263_payload_item = NULL;
288 proto_tree *h263_payload_tree = NULL;
292 if ( check_col( pinfo->cinfo, COL_INFO) ) {
293 col_append_str( pinfo->cinfo, COL_INFO, "H263 payload ");
297 h263_payload_item = proto_tree_add_item( tree, hf_h263_payload, tvb, offset, -1, FALSE );
298 h263_payload_tree = proto_item_add_subtree( h263_payload_item, ett_h263_payload );
301 /* Check for PSC, PSC is a word of 22 bits. Its value is 0000 0000 0000 0000' 1000 00xx xxxx xxxx. */
302 data = tvb_get_ntohl(tvb, offset);
304 if (( data & 0xffff8000) == 0x00008000 ) { /* PSC or Group of Block Start Code (GBSC) found */
305 if (( data & 0x00007c00) == 0 ) { /* PSC found */
306 if ( check_col( pinfo->cinfo, COL_INFO) )
307 col_append_str( pinfo->cinfo, COL_INFO, "(PSC) ");
309 proto_tree_add_uint(h263_payload_tree, hf_h263_psc,tvb, offset,3,data);
311 proto_tree_add_uint(h263_payload_tree, hf_h263_TR,tvb, offset,2,data);
312 /* Last two bits in the 32 bits fetched
313 * Bit 1: Always "1", in order to avoid start code emulation.
314 * Bit 2: Always "0", for distinction with Recommendation H.261.
317 /* Bit 3: Split screen indicator, "0" off, "1" on. */
318 proto_tree_add_item( h263_payload_tree, hf_h263_split_screen_indicator, tvb, offset, 1, FALSE );
319 /* Bit 4: Document camera indicator, */
320 proto_tree_add_item( h263_payload_tree, hf_h263_document_camera_indicator, tvb, offset, 1, FALSE );
321 /* Bit 5: Full Picture Freeze Release, "0" off, "1" on. */
322 proto_tree_add_item( h263_payload_tree, hf_h263_full_picture_freeze_release, tvb, offset, 1, FALSE );
323 /* Bits 6-8: Source Format, "000" forbidden, "001" sub-QCIF, "010" QCIF, "011" CIF,
324 * "100" 4CIF, "101" 16CIF, "110" reserved, "111" extended PTYPE.
326 proto_tree_add_item( h263_payload_tree, hf_h263_source_format, tvb, offset, 1, TRUE );
327 octet = tvb_get_guint8(tvb,offset);
328 if (( octet & 0x1c) != 0x1c){
329 /* Not extended PTYPE */
330 /* Bit 9: Picture Coding Type, "0" INTRA (I-picture), "1" INTER (P-picture). */
331 proto_tree_add_item( h263_payload_tree, hf_h263_payload_picture_coding_type, tvb, offset, 1, FALSE );
332 /* Bit 10: Optional Unrestricted Motion Vector mode (see Annex D), "0" off, "1" on. */
333 proto_tree_add_item( h263_payload_tree, hf_h263_opt_unres_motion_vector_mode, tvb, offset, 1, FALSE );
335 /* Bit 11: Optional Syntax-based Arithmetic Coding mode (see Annex E), "0" off, "1" on.*/
336 proto_tree_add_item( h263_payload_tree, hf_h263_syntax_based_arithmetic_coding_mode, tvb, offset, 1, FALSE );
337 /* Bit 12: Optional Advanced Prediction mode (see Annex F), "0" off, "1" on.*/
338 proto_tree_add_item( h263_payload_tree, hf_h263_optional_advanced_prediction_mode, tvb, offset, 1, FALSE );
339 /* Bit 13: Optional PB-frames mode (see Annex G), "0" normal I- or P-picture, "1" PB-frame.*/
340 proto_tree_add_item( h263_payload_tree, hf_h263_PB_frames_mode, tvb, offset, 1, FALSE );
343 } else { /* GBSC found */
344 if ( check_col( pinfo->cinfo, COL_INFO) )
345 col_append_str( pinfo->cinfo, COL_INFO, "(GBSC) ");
347 /* Group of Block Start Code (GBSC) (17 bits)
348 * A word of 17 bits. Its value is 0000 0000 0000 0000 1. GOB start codes may be byte aligned. This
349 * can be achieved by inserting GSTUF before the start code such that the first bit of the start code is
350 * the first (most significant) bit of a byte.
353 proto_tree_add_uint(h263_payload_tree, hf_h263_gbsc,tvb, offset,3,data);
354 proto_tree_add_uint(h263_payload_tree, hf_h263_GN, tvb, offset,3,data);
355 /* GN is followed by (optionally) GBSI, then
356 * GFID and GQUANT, but decoding them requires
357 * knowing the value of CPM in the picture
364 proto_tree_add_item( h263_payload_tree, hf_h263_data, tvb, offset, -1, FALSE );
368 proto_register_h263(void)
370 static hf_register_info hf[] =
381 "Indicates the mode of the payload header (MODE A or B/C)", HFILL
393 "Optional PB-frames mode as defined by H.263 (MODE C)", HFILL
399 "Start bit position",
405 "Start bit position specifies number of most significant bits that shall be ignored in the first data byte.", HFILL
417 "End bit position specifies number of least significant bits that shall be ignored in the last data byte.", HFILL
427 VALS(srcformat_vals),
429 "Source format specifies the resolution of the current picture.", HFILL
433 &hf_h263_picture_coding_type,
436 "h263.picture_coding_type",
441 "Picture coding type, intra-coded (false) or inter-coded (true)", HFILL
445 &hf_h263_unrestricted_motion_vector,
448 "h263.unrestricted_motion_vector",
453 "Unrestricted Motion Vector option for current picture", HFILL
457 &hf_h263_syntax_based_arithmetic,
459 "Syntax-based arithmetic coding",
460 "h263.syntax_based_arithmetic",
465 "Syntax-based Arithmetic Coding option for current picture", HFILL
469 &hf_h263_advanced_prediction,
471 "Advanced prediction option",
472 "h263.advanced_prediction",
477 "Advanced Prediction option for current picture", HFILL
483 "Differential quantization parameter",
489 "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
495 "Temporal Reference for B frames",
501 "Temporal Reference for the B frame as defined by H.263", HFILL
507 "Temporal Reference for P frames",
513 "Temporal Reference for the P frame as defined by H.263", HFILL
525 "Quantization value for the first MB coded at the starting of the packet.", HFILL
537 "GOB number in effect at the start of the packet.", HFILL
543 "Macroblock address",
549 "The address within the GOB of the first MB in the packet, counting from zero in scan order.", HFILL
555 "Horizontal motion vector 1",
561 "Horizontal motion vector predictor for the first MB in this packet ", HFILL
567 "Vertical motion vector 1",
573 "Vertical motion vector predictor for the first MB in this packet ", HFILL
579 "Horizontal motion vector 2",
585 "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
591 "Vertical motion vector 2",
597 "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
609 "Reserved field that houls contain zeroes", HFILL
621 "Reserved field that should contain zeroes", HFILL
633 "The actual H.263 data", HFILL
645 "The H.263 stream including its Picture, GOB or Macro block start code.", HFILL
651 "H.263 Picture start Code",
657 "Picture start Code, PSC", HFILL
662 "H.263 Group of Block Start Code",
668 "Group of Block Start Code", HFILL
674 "H.263 Temporal Reference",
680 "Temporal Reference, TR", HFILL
684 &hf_h263_split_screen_indicator,
686 "H.263 Split screen indicator",
687 "h263.split_screen_indicator",
692 "Split screen indicator", HFILL
696 &hf_h263_document_camera_indicator,
698 "H.263 Document camera indicator",
699 "h263.document_camera_indicator",
704 "Document camera indicator", HFILL
708 &hf_h263_full_picture_freeze_release,
710 "H.263 Full Picture Freeze Release",
711 "h263.split_screen_indicator",
716 "Full Picture Freeze Release", HFILL
720 &hf_h263_source_format,
722 "H.263 Source Format",
723 "h263.split_screen_indicator",
726 VALS(srcformat_vals),
728 "Source Format", HFILL
732 &hf_h263_payload_picture_coding_type,
734 "H.263 Picture Coding Type",
735 "h263.picture_coding_type",
738 TFS(&picture_coding_type_flg),
740 "Picture Coding Typet", HFILL
744 &hf_h263_opt_unres_motion_vector_mode,
746 "H.263 Optional Unrestricted Motion Vector mode",
747 "h263.opt_unres_motion_vector_mode",
752 "Optional Unrestricted Motion Vector mode", HFILL
756 &hf_h263_syntax_based_arithmetic_coding_mode,
758 "H.263 Optional Syntax-based Arithmetic Coding mode",
759 "h263.syntax_based_arithmetic_coding_mode",
764 "Optional Syntax-based Arithmetic Coding mode", HFILL
768 &hf_h263_optional_advanced_prediction_mode,
770 "H.263 Optional Advanced Prediction mode",
771 "h263.optional_advanced_prediction_mode",
776 "Optional Advanced Prediction mode", HFILL
780 &hf_h263_PB_frames_mode,
782 "H.263 Optional PB-frames mode",
783 "h263.PB_frames_mode",
786 TFS(&PB_frames_mode_flg),
788 "Optional PB-frames mode", HFILL
794 "H.263 Group Number",
800 "Group Number, GN", HFILL
812 proto_h263 = proto_register_protocol("ITU-T Recommendation H.263 RTP Payload header (RFC2190)",
814 proto_h263_data = proto_register_protocol("ITU-T Recommendation H.263",
815 "H.263 data", "h263data");
816 proto_register_field_array(proto_h263, hf, array_length(hf));
817 proto_register_subtree_array(ett, array_length(ett));
818 register_dissector("h263", dissect_h263, proto_h263);
819 register_dissector("h263data", dissect_h263_data, proto_h263_data);
823 proto_reg_handoff_h263(void)
825 dissector_handle_t h263_handle;
827 h263_handle = find_dissector("h263");
828 dissector_add("rtp.pt", PT_H263, h263_handle);
829 dissector_add("iax2.codec", AST_FORMAT_H263, h263_handle);