HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-h263.c
blobff98dfca9304ccf70bf642549d2fdc84922abbaa
1 /* packet-h263.c
3 * Routines for ITU-T Recommendation 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>
11 * $Id$
13 * Wireshark - Network traffic analyzer
14 * By Gerald Combs <gerald@wireshark.org>
15 * Copyright 1998 Gerald Combs
17 * Copied structure from packet-h261.c
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version 2
22 * of the License, or (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35 #include "config.h"
37 #include <glib.h>
38 #include <epan/packet.h>
40 #include "packet-h263.h"
42 static int proto_h263_data = -1;
44 /* Fields for the data section */
45 static int hf_h263_psc = -1;
46 static int hf_h263_gbsc = -1;
47 static int hf_h263_TR =-1;
48 static int hf_h263_split_screen_indicator = -1;
49 static int hf_h263_document_camera_indicator = -1;
50 static int hf_h263_full_picture_freeze_release = -1;
51 static int hf_h263_source_format = -1;
52 static int hf_h263_payload_picture_coding_type = -1;
53 static int hf_h263_opt_unres_motion_vector_mode = -1;
54 static int hf_h263_syntax_based_arithmetic_coding_mode = -1;
55 static int hf_h263_optional_advanced_prediction_mode = -1;
56 static int hf_h263_PB_frames_mode = -1;
57 static int hf_h263_data = -1;
58 static int hf_h263_GN = -1;
59 static int hf_h263_UFEP = -1;
60 static int hf_h263_opptype = -1;
61 static int hf_h263_pquant = -1;
62 static int hf_h263_cpm = -1;
63 static int hf_h263_psbi = -1;
64 static int hf_h263_picture_type_code = -1;
65 static int hf_h263_ext_source_format = -1;
66 static int hf_h263_custom_pcf = -1;
67 static int hf_h263_pei = -1;
68 static int hf_h263_psupp = -1;
69 static int hf_h263_trb = -1;
70 static int hf_h263_not_dissected = -1;
72 /* H.263 fields defining a sub tree */
73 static gint ett_h263_payload = -1;
74 static gint ett_h263_optype = -1;
77 /* Source format types */
78 #define H263_SRCFORMAT_FORB 0 /* forbidden */
79 #define H263_SRCFORMAT_SQCIF 1
80 #define H263_SRCFORMAT_QCIF 2
81 #define H263_SRCFORMAT_CIF 3
82 #define H263_SRCFORMAT_4CIF 4
83 #define H263_SRCFORMAT_16CIF 5
84 #define H263_PLUSPTYPE 7
86 const value_string h263_srcformat_vals[] =
88 { H263_SRCFORMAT_FORB, "forbidden" },
89 { H263_SRCFORMAT_SQCIF, "sub-QCIF 128x96" },
90 { H263_SRCFORMAT_QCIF, "QCIF 176x144" },
91 { H263_SRCFORMAT_CIF, "CIF 352x288" },
92 { H263_SRCFORMAT_4CIF, "4CIF 704x576" },
93 { H263_SRCFORMAT_16CIF, "16CIF 1408x1152" },
94 { 6, "Reserved",},
95 { H263_PLUSPTYPE, "extended PTYPE" },
96 { 0, NULL },
100 * If UFEP is "001", then the following bits are present in PLUSPTYPE:
101 * Bits 1-3 Source Format, "000" reserved, "001" sub-QCIF, "010" QCIF, "011" CIF,
102 * "100" 4CIF, "101" 16CIF, "110" custom source format, "111" reserved;
104 static const value_string ext_srcformat_vals[] =
106 { 0, "reserved" },
107 { H263_SRCFORMAT_SQCIF, "sub-QCIF 128x96" },
108 { H263_SRCFORMAT_QCIF, "QCIF 176x144" },
109 { H263_SRCFORMAT_CIF, "CIF 352x288" },
110 { H263_SRCFORMAT_4CIF, "4CIF 704x576" },
111 { H263_SRCFORMAT_16CIF, "16CIF 1408x1152" },
112 { 6, "Custom source format",},
113 { 7, "Reserved" },
114 { 0, NULL },
117 static const value_string h263_ufep_vals[] =
119 { 0, "Only MPPTYPE included" },
120 { 1, "All extended PTYPE fields are included" },
121 { 0, NULL },
124 static const true_false_string on_off_flg = {
125 "On",
126 "Off"
128 static const true_false_string picture_coding_type_flg = {
129 "INTER (P-picture)",
130 "INTRA (I-picture)"
133 static const value_string picture_coding_type_vals[] =
135 { 0, "I-Frame" },
136 { 1, "P-frame" },
137 { 0, NULL },
140 static const true_false_string PB_frames_mode_flg = {
141 "PB-frame",
142 "Normal I- or P-picture"
145 static const true_false_string cpm_flg = {
146 "On",
147 "Off"
150 static const true_false_string custom_pcf_flg = {
151 "Custom PCF",
152 "CIF PCF"
155 /* Bits 1-3 Picture Type Code:*/
156 static const value_string picture_type_code_vals[] =
158 { 0, "I-picture (INTRA)" },
159 { 1, "P-picture (INTER)" },
160 { 2, "Improved PB-frame (see Annex M)" },
161 { 3, "B-picture (see Annex O)" },
162 { 4, "EI-picture (see Annex O)" },
163 { 5, "EP-picture (see Annex O)" },
164 { 6, "Reserved" },
165 { 7, "Reserved" },
166 { 0, NULL },
171 * 5.3 Macroblock layer
172 static int
173 dissect_h263_macroblock_layer( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
181 dissect_h263_group_of_blocks_layer( tvbuff_t *tvb, proto_tree *tree, gint offset, gboolean is_rfc4626)
184 unsigned int offset_in_bits = offset << 3;
186 if(is_rfc4626){
187 /* GBSC 1xxx xxxx */
188 proto_tree_add_bits_item(tree, hf_h263_gbsc, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
189 offset_in_bits++;
190 }else{
191 /* Group of Block Start Code (GBSC) (17 bits)
192 * A word of 17 bits. Its value is 0000 0000 0000 0000 1.
194 proto_tree_add_bits_item(tree, hf_h263_gbsc, tvb, offset_in_bits, 17, ENC_BIG_ENDIAN);
195 offset_in_bits = offset_in_bits +17;
198 * Group Number (GN) (5 bits)
200 proto_tree_add_bits_item(tree, hf_h263_GN, tvb, offset_in_bits, 5, ENC_BIG_ENDIAN);
201 offset_in_bits = offset_in_bits +5;
202 /* 5.2.4 GOB Sub-Bitstream Indicator (GSBI) (2 bits)
203 * A fixed length codeword of 2 bits that is only present if CPM is "1" in the picture header.
206 * 5.2.5 GOB Frame ID (GFID) (2 bits)
209 * 5.2.6 Quantizer Information (GQUANT) (5 bits)
212 * 5.3 Macroblock layer
215 return offset_in_bits>>3;
220 * Length is used for the "Extra header" otherwise set to -1.
223 dissect_h263_picture_layer( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset, gint length _U_, gboolean is_rfc4626)
225 proto_tree *h263_opptype_tree = NULL;
226 proto_item *opptype_item = NULL;
227 unsigned int offset_in_bits = offset << 3;
228 unsigned int saved_bit_offset;
229 guint64 source_format;
230 guint64 ufep;
231 guint64 picture_coding_type;
232 guint64 PB_frames_mode = 0;
233 guint64 custom_pcf = 0;
234 guint64 picture_type_code =0;
235 guint64 cpm;
236 guint64 pei;
238 if(is_rfc4626){
239 /* PC 1000 00xx */
240 proto_tree_add_bits_item(tree, hf_h263_psc, tvb, offset_in_bits, 6, ENC_BIG_ENDIAN);
241 offset_in_bits = offset_in_bits +6;
243 }else{
244 /* Check for PSC, PSC is a word of 22 bits.
245 * Its value is 0000 0000 0000 0000' 1000 00xx xxxx xxxx.
247 proto_tree_add_bits_item(tree, hf_h263_psc, tvb, offset_in_bits, 22, ENC_BIG_ENDIAN);
248 offset_in_bits = offset_in_bits +22;
251 proto_tree_add_bits_item(tree, hf_h263_TR, tvb, offset_in_bits, 8, ENC_BIG_ENDIAN);
252 offset_in_bits = offset_in_bits +8;
254 * Bit 1: Always "1", in order to avoid start code emulation.
255 * Bit 2: Always "0", for distinction with Recommendation H.261.
257 offset_in_bits = offset_in_bits +2;
258 /* Bit 3: Split screen indicator, "0" off, "1" on. */
259 proto_tree_add_bits_item( tree, hf_h263_split_screen_indicator, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
260 offset_in_bits++;
261 /* Bit 4: Document camera indicator, */
262 proto_tree_add_bits_item( tree, hf_h263_document_camera_indicator, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
263 offset_in_bits++;
264 /* Bit 5: Full Picture Freeze Release, "0" off, "1" on. */
265 proto_tree_add_bits_item( tree, hf_h263_full_picture_freeze_release, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
266 offset_in_bits++;
267 /* Bits 6-8: Source Format, "000" forbidden, "001" sub-QCIF, "010" QCIF, "011" CIF,
268 * "100" 4CIF, "101" 16CIF, "110" reserved, "111" extended PTYPE.
270 proto_tree_add_bits_ret_val( tree, hf_h263_source_format, tvb, offset_in_bits, 3 ,&source_format, ENC_BIG_ENDIAN);
271 offset_in_bits = offset_in_bits +3;
272 if (source_format != H263_PLUSPTYPE){
273 /* Not extended PTYPE */
274 /* Bit 9: Picture Coding Type, "0" INTRA (I-picture), "1" INTER (P-picture). */
275 proto_tree_add_bits_ret_val( tree, hf_h263_payload_picture_coding_type, tvb, offset_in_bits, 1, &picture_coding_type, ENC_BIG_ENDIAN);
276 col_append_str(pinfo->cinfo, COL_INFO, val_to_str((guint32)picture_coding_type, picture_coding_type_vals, "Unknown (%u)"));
277 offset_in_bits++;
278 /* Bit 10: Optional Unrestricted Motion Vector mode (see Annex D), "0" off, "1" on. */
279 proto_tree_add_bits_item( tree, hf_h263_opt_unres_motion_vector_mode, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
280 offset_in_bits++;
281 /* Bit 11: Optional Syntax-based Arithmetic Coding mode (see Annex E), "0" off, "1" on.*/
282 proto_tree_add_bits_item( tree, hf_h263_syntax_based_arithmetic_coding_mode, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
283 offset_in_bits++;
284 /* Bit 12: Optional Advanced Prediction mode (see Annex F), "0" off, "1" on.*/
285 proto_tree_add_bits_item( tree, hf_h263_optional_advanced_prediction_mode, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
286 offset_in_bits++;
287 /* Bit 13: Optional PB-frames mode (see Annex G), "0" normal I- or P-picture, "1" PB-frame.*/
288 proto_tree_add_bits_ret_val( tree, hf_h263_PB_frames_mode, tvb, offset_in_bits, 1, &PB_frames_mode, ENC_BIG_ENDIAN);
289 offset_in_bits++;
290 }else{
291 /* Extended PTYPE
292 * Update Full Extended PTYPE (UFEP) (3 bits)
294 /* .... ..xx x... .... */
295 proto_tree_add_bits_ret_val( tree, hf_h263_UFEP, tvb, offset_in_bits, 3, &ufep, ENC_BIG_ENDIAN);
296 offset_in_bits = offset_in_bits +3;
297 if(ufep==1){
298 /* The Optional Part of PLUSPTYPE (OPPTYPE) (18 bits)
300 /* .xxx xxxx xxxx xxxx xxx. .... */
301 opptype_item = proto_tree_add_bits_item( tree, hf_h263_opptype, tvb, offset_in_bits, 18, ENC_BIG_ENDIAN);
302 h263_opptype_tree = proto_item_add_subtree( opptype_item, ett_h263_optype );
304 * If UFEP is "001", then the following bits are present in PLUSPTYPE:
305 * Bits 1-3 Source Format, "000" reserved, "001" sub-QCIF, "010" QCIF, "011" CIF,
306 * "100" 4CIF, "101" 16CIF, "110" custom source format, "111" reserved;
308 proto_tree_add_bits_item( h263_opptype_tree, hf_h263_ext_source_format, tvb, offset_in_bits, 3, ENC_BIG_ENDIAN);
309 offset_in_bits+=3;
312 * Bit 4 Optional Custom PCF, "0" CIF PCF, "1" custom PCF;
314 proto_tree_add_bits_ret_val( h263_opptype_tree, hf_h263_custom_pcf, tvb, offset_in_bits, 1, &custom_pcf, ENC_BIG_ENDIAN);
315 offset_in_bits++;
316 saved_bit_offset=offset_in_bits;
318 * Bit 5 Optional Unrestricted Motion Vector (UMV) mode (see Annex D), "0" off, "1" on;
320 offset_in_bits++;
322 * Bit 6 Optional Syntax-based Arithmetic Coding (SAC) mode (see Annex E), "0" off, "1" on;
324 offset_in_bits++;
326 * Bit 7 Optional Advanced Prediction (AP) mode (see Annex F), "0" off, "1" on;
328 offset_in_bits++;
330 * Bit 8 Optional Advanced INTRA Coding (AIC) mode (see Annex I), "0" off, "1" on;
332 offset_in_bits++;
334 * Bit 9 Optional Deblocking Filter (DF) mode (see Annex J), "0" off, "1" on;
336 offset_in_bits++;
338 * Bit 10 Optional Slice Structured (SS) mode (see Annex K), "0" off, "1" on;
340 offset_in_bits++;
342 * Bit 11 Optional Reference Picture Selection (RPS) mode (see Annex N), "0" off, "1" on;
344 offset_in_bits++;
346 * Bit 12 Optional Independent Segment Decoding (ISD) mode (see Annex R), "0" off,"1" on;
348 offset_in_bits++;
350 * Bit 13 Optional Alternative INTER VLC (AIV) mode (see Annex S), "0" off, "1" on;
352 offset_in_bits++;
354 * Bit 14 Optional Modified Quantization (MQ) mode (see Annex T), "0" off, "1" on;
356 offset_in_bits++;
358 * Bit 15 Equal to "1" to prevent start code emulation;
360 offset_in_bits++;
362 * Bit 16 Reserved, shall be equal to "0";
364 offset_in_bits++;
366 * Bit 17 Reserved, shall be equal to "0";
368 offset_in_bits++;
370 * Bit 18 Reserved, shall be equal to "0".
372 offset_in_bits++;
373 proto_tree_add_bits_item( h263_opptype_tree, hf_h263_not_dissected, tvb, saved_bit_offset, offset_in_bits-saved_bit_offset, ENC_BIG_ENDIAN);
377 * 5.1.4.3 The mandatory part of PLUSPTYPE when PLUSPTYPE present (MPPTYPE) (9 bits)
378 * Regardless of the value of UFEP, the following 9 bits are also present in PLUSPTYPE:
379 * - Bits 1-3 Picture Type Code:
380 * "000" I-picture (INTRA);
381 * "001" P-picture (INTER);
382 * "010" Improved PB-frame (see Annex M);
383 * "011" B-picture (see Annex O);
384 * "100" EI-picture (see Annex O);
385 * "101" EP-picture (see Annex O);
386 * "110" Reserved;
387 * "111" Reserved;
389 proto_tree_add_bits_ret_val( tree, hf_h263_picture_type_code, tvb, offset_in_bits, 3, &picture_type_code, ENC_BIG_ENDIAN);
390 offset_in_bits+=3;
391 saved_bit_offset=offset_in_bits;
393 * Bit 4 Optional Reference Picture Resampling (RPR) mode (see Annex P), "0" off, "1" on;
395 offset_in_bits++;
397 * Bit 5 Optional Reduced-Resolution Update (RRU) mode (see Annex Q), "0" off, "1" on;
399 offset_in_bits++;
401 * Bit 6 Rounding Type (RTYPE) (see 6.1.2);
403 offset_in_bits++;
405 * Bit 7 Reserved, shall be equal to "0";
407 offset_in_bits++;
409 * Bit 8 Reserved, shall be equal to "0";
411 offset_in_bits++;
413 * Bit 9 Equal to "1" to prevent start code emulation.
415 offset_in_bits++;
416 proto_tree_add_bits_item( tree, hf_h263_not_dissected, tvb, saved_bit_offset, offset_in_bits-saved_bit_offset, ENC_BIG_ENDIAN);
417 /* The picture header location of CPM (1 bit) and PSBI (2 bits)
418 * the picture header depends on whether or not PLUSPTYPE is present
419 * (see 5.1.20 and 5.1.21). If PLUSPTYPE is present, then CPM follows
420 * immediately after PLUSPTYPE in the picture header.
422 proto_tree_add_bits_ret_val( tree, hf_h263_cpm, tvb, offset_in_bits, 1, &cpm, ENC_BIG_ENDIAN);
423 offset_in_bits++;
424 /* 5.1.21 Picture Sub-Bitstream Indicator (PSBI) (2 bits)
425 * only present if Continuous Presence Multipoint and Video
426 * Multiplex mode is indicated by CPM.
428 if(cpm==1){
429 proto_tree_add_bits_item( tree, hf_h263_psbi, tvb, offset_in_bits, 2, ENC_BIG_ENDIAN);
430 offset_in_bits+=2;
432 return offset_in_bits>>3;
433 /* TODO Add the rest of the fields */
434 /* 5.1.5 Custom Picture Format (CPFMT) (23 bits)
435 * present only if the use of a custom picture format is
436 * signalled in PLUSPTYPE and UFEP is '001'. When present, CPFMT consists of:
437 * Bits 1-4 Pixel Aspect Ratio Code: A 4-bit index to the PAR value in Table 5. For
438 * extended PAR, the exact pixel aspect ratio shall be specified in EPAR
439 * (see 5.1.6);
440 * Bits 5-13 Picture Width Indication: Range [0, ... , 511]; Number of pixels per
441 * line = (PWI + 1) * 4;
442 * Bit 14 Equal to "1" to prevent start code emulation;
443 * Bits 15-23 Picture Height Indication: Range [1, ... , 288]; Number of lines = PHI * 4.
445 /* 5.1.6 Extended Pixel Aspect Ratio (EPAR) (16 bits)
446 * A fixed length codeword of 16 bits that is present only if CPFMT is present and extended PAR is
447 * indicated therein. When present, EPAR consists of:
448 * Bits 1-8 PAR Width: "0" is forbidden. The natural binary representation of the PAR
449 * width;
450 * Bits 9-16 PAR Height: "0" is forbidden. The natural binary representation of the PAR
451 * height.
453 /* 5.1.7 Custom Picture Clock Frequency Code (CPCFC) (8 bits)
454 * A fixed length codeword of 8 bits that is present only if PLUSPTYPE is present and UFEP is 001
455 * and a custom picture clock frequency is signalled in PLUSPTYPE. When present, CPCFC consists of:
456 * Bit 1 Clock Conversion Code: "0" indicates a clock conversion factor of 1000 and
457 * "1" indicates 1001;
458 * Bits 2-8 Clock Divisor: "0" is forbidden. The natural binary representation of the value
459 * of the clock divisor.
461 /* 5.1.8 Extended Temporal Reference (ETR) (2 bits)
462 * A fixed length codeword of 2 bits which is present only if a custom picture clock frequency is in
463 * use (regardless of the value of UFEP). It is the two MSBs of the 10-bit number defined in 5.1.2.
465 /* 5.1.9 Unlimited Unrestricted Motion Vectors Indicator (UUI) (Variable length)
466 * A variable length codeword of 1 or 2 bits that is present only if the optional Unrestricted Motion
467 * Vector mode is indicated in PLUSPTYPE and UFEP is 001. When UUI is present it indicates the
468 * effective limitation of the range of the motion vectors being used.
469 * UUI = "1" The motion vector range is limited according to Tables D.1 and D.2.
470 * UUI = "01" The motion vector range is not limited except by the picture size.
473 * 5.1.10 Slice Structured Submode bits (SSS) (2 bits)
474 * A fixed length codeword of 2 bits which is present only if the optional Slice Structured mode
475 * (see Annex K) is indicated in PLUSPTYPE and UFEP is 001. If the Slice Structured mode is in use
476 * but UFEP is not 001, the last values sent for SSS shall remain in effect.
477 * - Bit 1 Rectangular Slices, "0" indicates free-running slices, "1" indicates rectangular
478 * slices;
479 * - Bit 2 Arbitrary Slice Ordering, "0" indicates sequential order, "1" indicates arbitrary
480 * order.
481 * 5.1.11 Enhancement Layer Number (ELNUM) (4 bits)
482 * A fixed length codeword of 4 bits which is present only if the optional Temporal, SNR, and Spatial
483 * Scalability mode is in use (regardless of the value of UFEP). The particular enhancement layer is
484 * identified by an enhancement layer number, ELNUM. Picture correspondence between layers is
485 * achieved via the temporal reference. Picture size is either indicated within each enhancement layer
486 * using the existing source format fields or is inferred by the relationship to the reference layer. The
487 * first enhancement layer above the base layer is designated as Enhancement Layer Number 2, and
488 * the base layer has number 1.
489 * 5.1.12 Reference Layer Number (RLNUM) (4 bits)
490 * A fixed length codeword of 4 bits which is present only if the optional Temporal, SNR, and Spatial
491 * Scalability mode is in use (see Annex O) and UFEP is 001. The layer number for the pictures used
492 * as reference anchors is identified by a Reference Layer Number (RLNUM). Time correspondence
493 * between layers is achieved via the temporal reference.
494 * Note that for B-pictures in an enhancement layer having temporally surrounding EI- or EP-pictures
495 * which are present in the same enhancement layer, RLNUM shall be equal to ELNUM
496 * (see Annex O).
497 * 5.1.13 Reference Picture Selection Mode Flags (RPSMF) (3 bits)
498 * A fixed length codeword of 3 bits that is present only if the Reference Picture Selection mode is in
499 * use and UFEP is 001. When present, RPSMF indicates which type of back-channel messages are
500 * needed by the encoder. If the Reference Picture Selection mode is in use but RPSMF is not present,
501 * the last value of RPSMF that was sent shall remain in effect.
502 * - 100: neither ACK nor NACK signals needed;
503 * - 101: need ACK signals to be returned;
504 * - 110: need NACK signals to be returned;
505 * - 111: need both ACK and NACK signals to be returned;
506 * - 000-011: Reserved.
507 * 5.1.14 Temporal Reference for Prediction Indication (TRPI) (1 bit)
508 * A fixed length codeword of 1 bit that is present only if the optional Reference Picture Selection
509 * mode is in use (regardless of the value of UFEP). When present, TRPI indicates the presence of the
510 * following TRP field:
511 * - 0: TRP field is not present;
512 * - 1: TRP field is present.
513 * TRPI shall be 0 whenever the picture header indicates an I- or EI-picture.
514 * 5.1.15 Temporal Reference for Prediction (TRP) (10 bits)
515 * When present (as indicated in TRPI), TRP indicates the Temporal Reference which is used for
516 * prediction of the encoding, except for in the case of B-pictures. For B-pictures, the picture having
517 * the temporal reference TRP is used for the prediction in the forward direction. (Prediction in the
518 * reverse-temporal direction always uses the immediately temporally subsequent picture.) TRP is a
519 * ten-bit number. If a custom picture clock frequency was not in use for the reference picture, the two
520 * MSBs of TRP are zero and the LSBs contain the eight-bit TR found in the picture header of the
521 * reference picture. If a custom picture clock frequency was in use for the reference picture, TRP is a
522 * ten-bit number consisting of the concatenation of ETR and TR from the reference picture header.
523 * When TRP is not present, the most recent temporally previous anchor picture shall be used for
524 * prediction, as when not in the Reference Picture Selection mode. TRP is valid until the next PSC,
525 * GSC, or SSC.
526 * 5.1.16 Back-Channel message Indication (BCI) (Variable length)
527 * A variable length field of one or two bits that is present only if the optional Reference Picture
528 * Selection mode is in use. When set to "1", this signals the presence of the following optional video
529 * Back-Channel Message (BCM) field. "01" indicates the absence or the end of the video backchannel
530 * message field. Combinations of BCM and BCI may not be present, and may be repeated
531 * when present. BCI shall be set to "01" if the videomux submode of the optional Reference Picture
532 * Selection mode is not in use.
533 * 5.1.17 Back-Channel Message (BCM) (Variable length)
534 * The Back-Channel message with syntax as specified in N.4.2, which is present only if the preceding
535 * BCI field is present and is set to "1".
536 * 5.1.18 Reference Picture Resampling Parameters (RPRP) (Variable length)
537 * A variable length field that is present only if the optional Reference Picture Resampling mode bit is
538 * set in PLUSPTYPE. This field carries the parameters of the Reference Picture Resampling mode
539 * (see Annex P). Note that the Reference Picture Resampling mode can also be invoked implicitly by
540 * the occurrence of a picture header for an INTER coded picture having a picture size which differs
541 * from that of the previous encoded picture, in which case the RPRP field is not present and the
542 * Reference Picture Resampling mode bit is not set.
545 /* 5.1.19 Quantizer Information (PQUANT) (5 bits) */
546 proto_tree_add_bits_item( tree, hf_h263_pquant, tvb, offset_in_bits, 5, ENC_BIG_ENDIAN);
547 offset_in_bits = offset_in_bits +5;
548 if (source_format != H263_PLUSPTYPE){
549 proto_tree_add_bits_ret_val( tree, hf_h263_cpm, tvb, offset_in_bits, 1, &cpm, ENC_BIG_ENDIAN);
550 offset_in_bits++;
551 /* 5.1.21 Picture Sub-Bitstream Indicator (PSBI) (2 bits)
552 * only present if Continuous Presence Multipoint and Video
553 * Multiplex mode is indicated by CPM.
555 if(cpm==1){
556 proto_tree_add_bits_item( tree, hf_h263_psbi, tvb, offset_in_bits, 2, ENC_BIG_ENDIAN);
557 offset_in_bits = offset_in_bits +2;
560 /* 5.1.22 Temporal Reference for B-pictures in PB-frames (TRB) (3/5 bits)
561 * TRB is present if PTYPE or PLUSPTYPE indicates "PB-frame" or "Improved PB-frame"
562 * It is 3 bits long for standard CIF picture clock frequency and is
563 * extended to 5 bits when a custom picture clock frequency is in use.
565 if((PB_frames_mode == 1)||(picture_type_code == 2 )){
566 if(custom_pcf == 0){
567 proto_tree_add_bits_item( tree, hf_h263_trb, tvb, offset_in_bits, 3, ENC_BIG_ENDIAN);
568 offset_in_bits = offset_in_bits +3;
569 }else{
570 proto_tree_add_bits_item( tree, hf_h263_trb, tvb, offset_in_bits, 5, ENC_BIG_ENDIAN);
571 offset_in_bits = offset_in_bits +5;
574 /* 5.1.23 Quantization information for B-pictures in PB-frames (DBQUANT) (2 bits)
575 * DBQUANT is present if PTYPE or PLUSPTYPE indicates "PB-frame" or "Improved PB-frame"
577 if((PB_frames_mode == 1)||(picture_type_code == 2 )){
578 offset_in_bits = offset_in_bits +2;
580 /* 5.1.24 Extra Insertion Information (PEI) (1 bit)
581 * A bit which when set to "1" signals the presence of the following optional data field.
583 proto_tree_add_bits_ret_val( tree, hf_h263_pei, tvb, offset_in_bits, 1, &pei, ENC_BIG_ENDIAN);
584 offset_in_bits++;
585 while(pei==1)
587 /*5.1.25 Supplemental Enhancement Information (PSUPP) (0/8/16 ... bits)
588 * If PEI is set to "1", then 9 bits follow consisting of 8 bits of data (PSUPP) and then another PEI bit
589 * to indicate if a further 9 bits follow and so on. Encoders shall use PSUPP as specified in Annex L.
591 proto_tree_add_bits_item( tree, hf_h263_psupp, tvb, offset_in_bits, 8, ENC_BIG_ENDIAN);
592 offset_in_bits+=8;
593 proto_tree_add_bits_ret_val( tree, hf_h263_pei, tvb, offset_in_bits, 1, &pei, ENC_BIG_ENDIAN);
594 offset_in_bits++;
596 /* For the first GOB in each picture (with number 0), no GOB header shall be transmitted.
597 * For all other GOBs, the GOB header may be empty, depending on the encoder strategy.
601 * 5.3 Macroblock layer
602 * dissect_h263_macroblock_layer( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
605 return offset_in_bits>>3;
610 5.1.1 Picture Start Code (PSC) (22 bits)
611 PSC is a word of 22 bits. Its value is 0000 0000 0000 0000 1 00000. All picture start codes shall be
612 byte aligned.
613 ( 1000 00xx)
615 End Of Sequence (EOS) (22 bits)
616 A codeword of 22 bits. Its value is 0000 0000 0000 0000 1 11111.
617 ( 1111 11xx )
619 Group of Block Start Code (GBSC) (17 bits)
620 A word of 17 bits. Its value is 0000 0000 0000 0000 1.
621 ( 1xxx xxxx )
623 End Of Sub-Bitstream code (EOSBS) (23 bits)
624 The EOSBS code is a codeword of 23 bits. Its value is 0000 0000 0000 0000 1 11110 0.
625 ( 1111 100x )
627 Slice Start Code (SSC) (17 bits)
628 A word of 17 bits. Its value is 0000 0000 0000 0000 1.
629 ( 1xxx xxxx )
631 static void dissect_h263_data( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
633 guint offset = 0;
634 proto_item *h263_payload_item = NULL;
635 proto_tree *h263_payload_tree = NULL;
636 guint32 data;
637 guint8 startcode;
638 int length;
640 col_append_str( pinfo->cinfo, COL_INFO, "H263 payload ");
642 if( tree ) {
643 h263_payload_item = proto_tree_add_item( tree, proto_h263_data, tvb, offset, -1, ENC_NA );
644 h263_payload_tree = proto_item_add_subtree( h263_payload_item, ett_h263_payload );
647 length = tvb_reported_length_remaining(tvb,0);
648 if(length<4){
649 if( tree )
650 proto_tree_add_item( h263_payload_tree, hf_h263_data, tvb, offset, -1, ENC_NA );
651 return;
653 /* Check for PSC, PSC is a word of 22 bits. Its value is 0000 0000 0000 0000' 1000 00xx xxxx xxxx. */
654 data = tvb_get_ntohl(tvb, offset);
656 if (( data & 0xffff8000) == 0x00008000 ) {
657 /* Start Code found
659 * Startc code holds bit 17 -23 of the codeword
661 startcode = tvb_get_guint8(tvb,offset+2)&0xfe;
662 if (startcode & 0x80){
663 switch(startcode){
664 case 0xf8:
665 /* End Of Sub-Bitstream code (EOSBS)
666 * ( 1111 100. )
668 break;
669 case 0x80:
670 case 0x82:
671 /* Picture Start Code (PSC)
672 * ( 1000 00x.)
674 col_append_str( pinfo->cinfo, COL_INFO, "(PSC) ");
675 offset = dissect_h263_picture_layer( tvb, pinfo, h263_payload_tree, offset, -1, ENC_NA);
676 break;
677 case 0xfc:
678 case 0xfe:
679 /* End Of Sequence (EOS)
680 * ( 1111 11x. )
682 default:
683 /* Group of Block Start Code (GBSC) or
684 * Slice Start Code (SSC)
686 col_append_str( pinfo->cinfo, COL_INFO, "(GBSC) ");
687 offset = dissect_h263_group_of_blocks_layer( tvb, h263_payload_tree, offset,FALSE);
688 break;
690 }else{
691 /* Error */
694 if( tree )
695 proto_tree_add_item( h263_payload_tree, hf_h263_data, tvb, offset, -1, ENC_NA );
698 void
699 proto_register_h263_data(void)
701 static hf_register_info hf[] =
704 &hf_h263_psc,
706 "H.263 Picture start Code",
707 "h263.psc",
708 FT_UINT32,
709 BASE_HEX,
710 NULL,
711 0x0,
712 "Picture start Code, PSC", HFILL
715 { &hf_h263_gbsc,
717 "H.263 Group of Block Start Code",
718 "h263.gbsc",
719 FT_UINT32,
720 BASE_HEX,
721 NULL,
722 0x0,
723 "Group of Block Start Code", HFILL
727 &hf_h263_TR,
729 "H.263 Temporal Reference",
730 "h263.tr2",
731 FT_UINT32,
732 BASE_DEC,
733 NULL,
734 0x0,
735 "Temporal Reference, TR", HFILL
739 &hf_h263_trb,
741 "Temporal Reference for B frames",
742 "h263.trb",
743 FT_UINT8,
744 BASE_DEC,
745 NULL,
746 0x0,
747 "Temporal Reference for the B frame as defined by H.263", HFILL
751 &hf_h263_split_screen_indicator,
753 "H.263 Split screen indicator",
754 "h263.split_screen_indicator",
755 FT_BOOLEAN,
756 BASE_NONE,
757 TFS(&on_off_flg),
758 0x0,
759 "Split screen indicator", HFILL
763 &hf_h263_document_camera_indicator,
765 "H.263 Document camera indicator",
766 "h263.document_camera_indicator",
767 FT_BOOLEAN,
768 BASE_NONE,
769 TFS(&on_off_flg),
770 0x0,
771 "Document camera indicator", HFILL
775 &hf_h263_full_picture_freeze_release,
777 "H.263 Full Picture Freeze Release",
778 "h263.split_screen_indicator",
779 FT_BOOLEAN,
780 BASE_NONE,
781 TFS(&on_off_flg),
782 0x0,
783 "Full Picture Freeze Release", HFILL
787 &hf_h263_source_format,
789 "H.263 Source Format",
790 "h263.source_format",
791 FT_UINT8,
792 BASE_HEX,
793 VALS(h263_srcformat_vals),
794 0x0,
795 "Source Format", HFILL
799 &hf_h263_ext_source_format,
801 "H.263 Source Format",
802 "h263.ext_source_format",
803 FT_UINT8,
804 BASE_HEX,
805 VALS(ext_srcformat_vals),
806 0x0,
807 "Source Format", HFILL
811 &hf_h263_UFEP,
813 "H.263 Update Full Extended PTYPE",
814 "h263.ufep",
815 FT_UINT16,
816 BASE_DEC,
817 VALS(h263_ufep_vals),
818 0x0,
819 "Update Full Extended PTYPE", HFILL
823 &hf_h263_opptype,
825 "H.263 Optional Part of PLUSPTYPE",
826 "h263.opptype",
827 FT_UINT24,
828 BASE_DEC,
829 NULL,
830 0x0,
831 "Optional Part of PLUSPTYPE", HFILL
835 &hf_h263_payload_picture_coding_type,
837 "H.263 Picture Coding Type",
838 "h263.picture_coding_type",
839 FT_BOOLEAN,
840 BASE_NONE,
841 TFS(&picture_coding_type_flg),
842 0x0,
843 "Picture Coding Type", HFILL
847 &hf_h263_opt_unres_motion_vector_mode,
849 "H.263 Optional Unrestricted Motion Vector mode",
850 "h263.opt_unres_motion_vector_mode",
851 FT_BOOLEAN,
852 BASE_NONE,
853 TFS(&on_off_flg),
854 0x0,
855 "Optional Unrestricted Motion Vector mode", HFILL
859 &hf_h263_syntax_based_arithmetic_coding_mode,
861 "H.263 Optional Syntax-based Arithmetic Coding mode",
862 "h263.syntax_based_arithmetic_coding_mode",
863 FT_BOOLEAN,
864 BASE_NONE,
865 TFS(&on_off_flg),
866 0x0,
867 "Optional Syntax-based Arithmetic Coding mode", HFILL
871 &hf_h263_optional_advanced_prediction_mode,
873 "H.263 Optional Advanced Prediction mode",
874 "h263.optional_advanced_prediction_mode",
875 FT_BOOLEAN,
876 BASE_NONE,
877 TFS(&on_off_flg),
878 0x0,
879 "Optional Advanced Prediction mode", HFILL
883 &hf_h263_PB_frames_mode,
885 "H.263 Optional PB-frames mode",
886 "h263.PB_frames_mode",
887 FT_BOOLEAN,
888 BASE_NONE,
889 TFS(&PB_frames_mode_flg),
890 0x0,
891 "Optional PB-frames mode", HFILL
895 &hf_h263_GN,
897 "H.263 Group Number",
898 "h263.gn",
899 FT_UINT32,
900 BASE_DEC,
901 NULL,
902 0x0,
903 "Group Number, GN", HFILL
907 &hf_h263_pquant,
909 "H.263 Quantizer Information (PQUANT)",
910 "h263.pquant",
911 FT_UINT32,
912 BASE_DEC,
913 NULL,
914 0x0,
915 "Quantizer Information (PQUANT)", HFILL
919 &hf_h263_cpm,
921 "H.263 Continuous Presence Multipoint and Video Multiplex (CPM)",
922 "h263.cpm",
923 FT_BOOLEAN,
924 BASE_NONE,
925 TFS(&cpm_flg),
926 0x0,
927 "Continuous Presence Multipoint and Video Multiplex (CPM)", HFILL
931 &hf_h263_psbi,
933 "H.263 Picture Sub-Bitstream Indicator (PSBI)",
934 "h263.psbi",
935 FT_UINT32,
936 BASE_DEC,
937 NULL,
938 0x0,
939 "Picture Sub-Bitstream Indicator (PSBI)", HFILL
943 &hf_h263_picture_type_code,
945 "H.263 Picture Type Code",
946 "h263.psi",
947 FT_UINT32,
948 BASE_DEC,
949 VALS(picture_type_code_vals),
950 0x0,
951 "Picture Type Code", HFILL
955 &hf_h263_custom_pcf,
957 "H.263 Custom PCF",
958 "h263.custom_pcf",
959 FT_BOOLEAN,
960 BASE_NONE,
961 TFS(&custom_pcf_flg),
962 0x0,
963 "Custom PCF", HFILL
967 &hf_h263_pei,
969 "H.263 Extra Insertion Information (PEI)",
970 "h263.pei",
971 FT_BOOLEAN,
972 BASE_NONE,
973 NULL,
974 0x0,
975 "Extra Insertion Information (PEI)", HFILL
979 &hf_h263_psupp,
981 "H.263 Supplemental Enhancement Information (PSUPP)",
982 "h263.psupp",
983 FT_UINT32,
984 BASE_DEC,
985 NULL,
986 0x0,
987 "Supplemental Enhancement Information (PSUPP)", HFILL
991 &hf_h263_data,
993 "H.263 stream",
994 "h263.stream",
995 FT_BYTES,
996 BASE_NONE,
997 NULL,
998 0x0,
999 "The H.263 stream including its Picture, GOB or Macro block start code.", HFILL
1003 &hf_h263_not_dissected,
1005 "H.263 Bits currently not dissected",
1006 "h263.not_dis",
1007 FT_UINT32,
1008 BASE_DEC,
1009 NULL,
1010 0x0,
1011 "These bits are not dissected(yet), displayed for clarity", HFILL
1016 static gint *ett[] =
1018 &ett_h263_payload,
1019 &ett_h263_optype,
1022 proto_register_subtree_array(ett, array_length(ett));
1024 proto_h263_data = proto_register_protocol("ITU-T Recommendation H.263",
1025 "H.263", "h263");
1026 proto_register_field_array(proto_h263_data, hf, array_length(hf));
1027 register_dissector("h263data", dissect_h263_data, proto_h263_data);