3 * Routines for RFC-4629-encapsulated H.263 dissection
5 * Copyright 2003 Niklas Ogren <niklas.ogren@7l.se>
6 * Seven Levels Consultants AB
8 * Copyright 2008 Richard van der Hoff, MX Telecom
9 * <richardv@mxtelecom.com>
13 * Wireshark - Network traffic analyzer
14 * By Gerald Combs <gerald@wireshark.org>
15 * Copyright 1998 Gerald Combs
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 #include <epan/packet.h>
42 #include <epan/prefs.h>
44 #include "packet-h263.h"
46 static int proto_h263P = -1;
48 /* H.263 RFC 4629 fields */
49 static int hf_h263P_payload = -1;
50 static int hf_h263P_rr = -1;
51 static int hf_h263P_pbit = -1;
52 static int hf_h263P_vbit = -1;
53 static int hf_h263P_plen = -1;
54 static int hf_h263P_pebit = -1;
55 static int hf_h263P_tid = -1;
56 static int hf_h263P_trun = -1;
57 static int hf_h263P_s = -1;
58 static int hf_h263P_extra_hdr = -1;
59 static int hf_h263P_PSC = -1;
60 static int hf_h263P_TR = -1;
63 /* H.263-1998 fields defining a sub tree */
64 static gint ett_h263P = -1;
65 static gint ett_h263P_extra_hdr = -1;
66 static gint ett_h263P_payload = -1;
67 static gint ett_h263P_data = -1;
69 /* The dynamic payload type which will be dissected as H.263-1998/H263-2000 */
71 static guint temp_dynamic_payload_type = 0;
75 dissect_h263P( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
77 proto_item *ti = NULL;
78 proto_item *data_item = NULL;
79 proto_item *extra_hdr_item = NULL;
80 proto_tree *h263P_tree = NULL;
81 proto_tree *h263P_extr_hdr_tree = NULL;
82 proto_tree *h263P_data_tree = NULL;
83 unsigned int offset = 0;
91 col_set_str(pinfo->cinfo, COL_PROTOCOL, "H.263 RFC4629 ");
94 ti = proto_tree_add_item( tree, proto_h263P, tvb, offset, -1, FALSE );
95 h263P_tree = proto_item_add_subtree( ti, ett_h263P );
97 data16 = tvb_get_ntohs(tvb,offset);
98 proto_tree_add_item( h263P_tree, hf_h263P_rr, tvb, offset, 2, FALSE );
99 proto_tree_add_item( h263P_tree, hf_h263P_pbit, tvb, offset, 2, FALSE );
100 proto_tree_add_item( h263P_tree, hf_h263P_vbit, tvb, offset, 2, FALSE );
101 proto_tree_add_item( h263P_tree, hf_h263P_plen, tvb, offset, 2, FALSE );
102 proto_tree_add_item( h263P_tree, hf_h263P_pebit, tvb, offset, 2, FALSE );
107 * Indicates the presence of an 8-bit field containing information
108 * for Video Redundancy Coding (VRC), which follows immediately after
109 * the initial 16 bits of the payload header, if present. For syntax
110 * and semantics of that 8-bit VRC field, see Section 5.2.
113 if ((data16&0x0200)==0x0200){
115 * The format of the VRC header extension is as follows:
124 * Thread ID. Up to 7 threads are allowed. Each frame of H.263+ VRC
125 * data will use as reference information only sync frames or frames
126 * within the same thread. By convention, thread 0 is expected to be
127 * the "canonical" thread, which is the thread from which the sync frame
128 * should ideally be used. In the case of corruption or loss of the
129 * thread 0 representation, a representation of the sync frame with a
130 * higher thread number can be used by the decoder. Lower thread
131 * numbers are expected to contain representations of the sync frames
132 * equal to or better than higher thread numbers in the absence of data
133 * corruption or loss. See [Vredun] for a detailed discussion of VRC.
137 * Monotonically increasing (modulo 16) 4-bit number counting the packet
138 * number within each thread.
142 * A bit that indicates that the packet content is for a sync frame.
145 proto_tree_add_item( h263P_tree, hf_h263P_tid, tvb, offset, 1, FALSE );
146 proto_tree_add_item( h263P_tree, hf_h263P_trun, tvb, offset, 1, FALSE );
147 proto_tree_add_item( h263P_tree, hf_h263P_s, tvb, offset, 1, FALSE );
151 /* Length, in bytes, of the extra picture header. */
152 plen = (data16 & 0x01f8) >> 3;
154 extra_hdr_item = proto_tree_add_item( h263P_tree, hf_h263P_extra_hdr, tvb, offset, plen, FALSE );
155 h263P_extr_hdr_tree = proto_item_add_subtree( extra_hdr_item, ett_h263P_extra_hdr );
156 dissect_h263_picture_layer( tvb, pinfo, h263P_extr_hdr_tree, offset, plen, TRUE);
159 if ((data16&0x0400)!=0){
161 data_item = proto_tree_add_item( h263P_tree, hf_h263P_payload, tvb, offset, -1, FALSE );
162 h263P_data_tree = proto_item_add_subtree( data_item, ett_h263P_data );
163 /* Startc code holds bit 17 -23 of the codeword */
164 startcode = tvb_get_guint8(tvb,offset)&0xfe;
165 if (startcode & 0x80){
166 /* All picture, slice, and EOSBS start codes
167 * shall be byte aligned, and GOB and EOS start codes may be byte aligned.
171 /* End Of Sub-Bitstream code (EOSBS)
172 * EOSBS codes shall be byte aligned
178 /* Picture Start Code (PSC)
181 col_append_str( pinfo->cinfo, COL_INFO, "(PSC) ");
182 offset = dissect_h263_picture_layer( tvb, pinfo, h263P_data_tree, offset, -1, TRUE);
186 /* End Of Sequence (EOS)
190 /* Group of Block Start Code (GBSC) or
191 * Slice Start Code (SSC)
193 col_append_str( pinfo->cinfo, COL_INFO, "(GBSC) ");
194 dissect_h263_group_of_blocks_layer( tvb, h263P_data_tree, offset,TRUE);
202 proto_tree_add_item( h263P_tree, hf_h263P_payload, tvb, offset, -1, FALSE );
207 proto_reg_handoff_h263P(void)
209 static dissector_handle_t h263P_handle;
210 static guint dynamic_payload_type;
211 static gboolean h263P_prefs_initialized = FALSE;
213 if (!h263P_prefs_initialized) {
214 h263P_handle = find_dissector("h263P");
215 dissector_add_string("rtp_dyn_payload_type","H263-1998", h263P_handle);
216 dissector_add_string("rtp_dyn_payload_type","H263-2000", h263P_handle);
217 h263P_prefs_initialized = TRUE;
220 if ( dynamic_payload_type > 95 )
221 dissector_delete("rtp.pt", dynamic_payload_type, h263P_handle);
223 dynamic_payload_type = temp_dynamic_payload_type;
225 if ( dynamic_payload_type > 95 ){
226 dissector_add("rtp.pt", dynamic_payload_type, h263P_handle);
232 proto_register_h263P(void)
234 module_t *h263P_module;
236 static hf_register_info hf[] =
241 "H.263 RFC4629 payload",
247 "The actual H.263 RFC4629 data", HFILL
259 "Reserved SHALL be zero", HFILL
271 "Indicates (GOB/Slice) start or (EOS or EOSBS)", HFILL
283 "presence of Video Redundancy Coding (VRC) field", HFILL
295 "Length, in bytes, of the extra picture header", HFILL
307 "number of bits that shall be ignored in the last byte of the picture header", HFILL
333 "Monotonically increasing (modulo 16) 4-bit number counting the packet number within each thread", HFILL
345 "Indicates that the packet content is for a sync frame", HFILL
351 "Extra picture header",
369 "Picture Start Code(PSC)", HFILL
375 "H.263 Temporal Reference",
381 "Temporal Reference, TR", HFILL
390 &ett_h263P_extra_hdr,
396 proto_h263P = proto_register_protocol("ITU-T Recommendation H.263 RTP Payload header (RFC4629)",
399 proto_register_field_array(proto_h263P, hf, array_length(hf));
400 proto_register_subtree_array(ett, array_length(ett));
402 h263P_module = prefs_register_protocol(proto_h263P, proto_reg_handoff_h263P);
404 prefs_register_uint_preference(h263P_module, "dynamic.payload.type",
405 "H263-1998 and H263-2000 dynamic payload type",
406 "The dynamic payload type which will be interpreted as H264"
407 "; The value must be greater than 95",
409 &temp_dynamic_payload_type);
411 register_dissector("h263P", dissect_h263P, proto_h263P);