Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-h263.c
blobfeb3b6cbfd9967676f8ce9c29d547688dbc37641
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 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * Copied structure from packet-h261.c
17 * SPDX-License-Identifier: GPL-2.0-or-later
21 #include "config.h"
23 #include <epan/packet.h>
24 #include <epan/tfs.h>
26 #include "packet-h263.h"
28 void proto_register_h263_data(void);
30 static int proto_h263_data;
32 /* Fields for the data section */
33 static int hf_h263_psc;
34 static int hf_h263_gbsc;
35 static int hf_h263_TR;
36 static int hf_h263_split_screen_indicator;
37 static int hf_h263_document_camera_indicator;
38 static int hf_h263_full_picture_freeze_release;
39 static int hf_h263_source_format;
40 static int hf_h263_payload_picture_coding_type;
41 static int hf_h263_opt_unres_motion_vector_mode;
42 static int hf_h263_syntax_based_arithmetic_coding_mode;
43 static int hf_h263_optional_advanced_prediction_mode;
44 static int hf_h263_PB_frames_mode;
45 static int hf_h263_data;
46 static int hf_h263_GN;
47 static int hf_h263_UFEP;
48 static int hf_h263_opptype;
49 static int hf_h263_pquant;
50 static int hf_h263_cpm;
51 static int hf_h263_psbi;
52 static int hf_h263_picture_type_code;
53 static int hf_h263_ext_source_format;
54 static int hf_h263_custom_pcf;
55 static int hf_h263_pei;
56 static int hf_h263_psupp;
57 static int hf_h263_trb;
58 static int hf_h263_not_dissected;
60 /* H.263 fields defining a sub tree */
61 static int ett_h263_payload;
62 static int ett_h263_optype;
65 /* Source format types */
66 #define H263_SRCFORMAT_FORB 0 /* forbidden */
67 #define H263_SRCFORMAT_SQCIF 1
68 #define H263_SRCFORMAT_QCIF 2
69 #define H263_SRCFORMAT_CIF 3
70 #define H263_SRCFORMAT_4CIF 4
71 #define H263_SRCFORMAT_16CIF 5
72 #define H263_PLUSPTYPE 7
74 const value_string h263_srcformat_vals[] =
76 { H263_SRCFORMAT_FORB, "forbidden" },
77 { H263_SRCFORMAT_SQCIF, "sub-QCIF 128x96" },
78 { H263_SRCFORMAT_QCIF, "QCIF 176x144" },
79 { H263_SRCFORMAT_CIF, "CIF 352x288" },
80 { H263_SRCFORMAT_4CIF, "4CIF 704x576" },
81 { H263_SRCFORMAT_16CIF, "16CIF 1408x1152" },
82 { 6, "Reserved",},
83 { H263_PLUSPTYPE, "extended PTYPE" },
84 { 0, NULL },
88 * If UFEP is "001", then the following bits are present in PLUSPTYPE:
89 * Bits 1-3 Source Format, "000" reserved, "001" sub-QCIF, "010" QCIF, "011" CIF,
90 * "100" 4CIF, "101" 16CIF, "110" custom source format, "111" reserved;
92 static const value_string ext_srcformat_vals[] =
94 { 0, "reserved" },
95 { H263_SRCFORMAT_SQCIF, "sub-QCIF 128x96" },
96 { H263_SRCFORMAT_QCIF, "QCIF 176x144" },
97 { H263_SRCFORMAT_CIF, "CIF 352x288" },
98 { H263_SRCFORMAT_4CIF, "4CIF 704x576" },
99 { H263_SRCFORMAT_16CIF, "16CIF 1408x1152" },
100 { 6, "Custom source format",},
101 { 7, "Reserved" },
102 { 0, NULL },
105 static const value_string h263_ufep_vals[] =
107 { 0, "Only MPPTYPE included" },
108 { 1, "All extended PTYPE fields are included" },
109 { 0, NULL },
112 static const true_false_string picture_coding_type_flg = {
113 "INTER (P-picture)",
114 "INTRA (I-picture)"
117 static const value_string picture_coding_type_vals[] =
119 { 0, "I-Frame" },
120 { 1, "P-frame" },
121 { 0, NULL },
124 static const true_false_string PB_frames_mode_flg = {
125 "PB-frame",
126 "Normal I- or P-picture"
130 static const true_false_string custom_pcf_flg = {
131 "Custom PCF",
132 "CIF PCF"
135 /* Bits 1-3 Picture Type Code:*/
136 static const value_string picture_type_code_vals[] =
138 { 0, "I-picture (INTRA)" },
139 { 1, "P-picture (INTER)" },
140 { 2, "Improved PB-frame (see Annex M)" },
141 { 3, "B-picture (see Annex O)" },
142 { 4, "EI-picture (see Annex O)" },
143 { 5, "EP-picture (see Annex O)" },
144 { 6, "Reserved" },
145 { 7, "Reserved" },
146 { 0, NULL },
151 * 5.3 Macroblock layer
152 static int
153 dissect_h263_macroblock_layer( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
161 dissect_h263_group_of_blocks_layer( tvbuff_t *tvb, proto_tree *tree, int offset, bool is_rfc4626)
164 unsigned int offset_in_bits = offset << 3;
166 if(is_rfc4626){
167 /* GBSC 1xxx xxxx */
168 proto_tree_add_bits_item(tree, hf_h263_gbsc, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
169 offset_in_bits++;
170 }else{
171 /* Group of Block Start Code (GBSC) (17 bits)
172 * A word of 17 bits. Its value is 0000 0000 0000 0000 1.
174 proto_tree_add_bits_item(tree, hf_h263_gbsc, tvb, offset_in_bits, 17, ENC_BIG_ENDIAN);
175 offset_in_bits = offset_in_bits +17;
178 * Group Number (GN) (5 bits)
180 proto_tree_add_bits_item(tree, hf_h263_GN, tvb, offset_in_bits, 5, ENC_BIG_ENDIAN);
181 offset_in_bits = offset_in_bits +5;
182 /* 5.2.4 GOB Sub-Bitstream Indicator (GSBI) (2 bits)
183 * A fixed length codeword of 2 bits that is only present if CPM is "1" in the picture header.
186 * 5.2.5 GOB Frame ID (GFID) (2 bits)
189 * 5.2.6 Quantizer Information (GQUANT) (5 bits)
192 * 5.3 Macroblock layer
195 return offset_in_bits>>3;
200 * Length is used for the "Extra header" otherwise set to -1.
203 dissect_h263_picture_layer( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, int length _U_, bool is_rfc4626)
205 proto_tree *h263_opptype_tree = NULL;
206 proto_item *opptype_item = NULL;
207 unsigned int offset_in_bits = offset << 3;
208 unsigned int saved_bit_offset;
209 uint64_t source_format;
210 uint64_t ufep;
211 uint64_t picture_coding_type;
212 uint64_t PB_frames_mode = 0;
213 uint64_t custom_pcf = 0;
214 uint64_t picture_type_code =0;
215 uint64_t cpm;
216 uint64_t pei;
218 if(is_rfc4626){
219 /* PC 1000 00xx */
220 proto_tree_add_bits_item(tree, hf_h263_psc, tvb, offset_in_bits, 6, ENC_BIG_ENDIAN);
221 offset_in_bits = offset_in_bits +6;
223 }else{
224 /* Check for PSC, PSC is a word of 22 bits.
225 * Its value is 0000 0000 0000 0000' 1000 00xx xxxx xxxx.
227 proto_tree_add_bits_item(tree, hf_h263_psc, tvb, offset_in_bits, 22, ENC_BIG_ENDIAN);
228 offset_in_bits = offset_in_bits +22;
231 proto_tree_add_bits_item(tree, hf_h263_TR, tvb, offset_in_bits, 8, ENC_BIG_ENDIAN);
232 offset_in_bits = offset_in_bits +8;
234 * Bit 1: Always "1", in order to avoid start code emulation.
235 * Bit 2: Always "0", for distinction with Recommendation H.261.
237 offset_in_bits = offset_in_bits +2;
238 /* Bit 3: Split screen indicator, "0" off, "1" on. */
239 proto_tree_add_bits_item( tree, hf_h263_split_screen_indicator, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
240 offset_in_bits++;
241 /* Bit 4: Document camera indicator, */
242 proto_tree_add_bits_item( tree, hf_h263_document_camera_indicator, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
243 offset_in_bits++;
244 /* Bit 5: Full Picture Freeze Release, "0" off, "1" on. */
245 proto_tree_add_bits_item( tree, hf_h263_full_picture_freeze_release, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
246 offset_in_bits++;
247 /* Bits 6-8: Source Format, "000" forbidden, "001" sub-QCIF, "010" QCIF, "011" CIF,
248 * "100" 4CIF, "101" 16CIF, "110" reserved, "111" extended PTYPE.
250 proto_tree_add_bits_ret_val( tree, hf_h263_source_format, tvb, offset_in_bits, 3 ,&source_format, ENC_BIG_ENDIAN);
251 offset_in_bits = offset_in_bits +3;
252 if (source_format != H263_PLUSPTYPE){
253 /* Not extended PTYPE */
254 /* Bit 9: Picture Coding Type, "0" INTRA (I-picture), "1" INTER (P-picture). */
255 proto_tree_add_bits_ret_val( tree, hf_h263_payload_picture_coding_type, tvb, offset_in_bits, 1, &picture_coding_type, ENC_BIG_ENDIAN);
256 col_append_str(pinfo->cinfo, COL_INFO, val_to_str((uint32_t)picture_coding_type, picture_coding_type_vals, "Unknown (%u)"));
257 offset_in_bits++;
258 /* Bit 10: Optional Unrestricted Motion Vector mode (see Annex D), "0" off, "1" on. */
259 proto_tree_add_bits_item( tree, hf_h263_opt_unres_motion_vector_mode, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
260 offset_in_bits++;
261 /* Bit 11: Optional Syntax-based Arithmetic Coding mode (see Annex E), "0" off, "1" on.*/
262 proto_tree_add_bits_item( tree, hf_h263_syntax_based_arithmetic_coding_mode, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
263 offset_in_bits++;
264 /* Bit 12: Optional Advanced Prediction mode (see Annex F), "0" off, "1" on.*/
265 proto_tree_add_bits_item( tree, hf_h263_optional_advanced_prediction_mode, tvb, offset_in_bits, 1, ENC_BIG_ENDIAN);
266 offset_in_bits++;
267 /* Bit 13: Optional PB-frames mode (see Annex G), "0" normal I- or P-picture, "1" PB-frame.*/
268 proto_tree_add_bits_ret_val( tree, hf_h263_PB_frames_mode, tvb, offset_in_bits, 1, &PB_frames_mode, ENC_BIG_ENDIAN);
269 offset_in_bits++;
270 }else{
271 /* Extended PTYPE
272 * Update Full Extended PTYPE (UFEP) (3 bits)
274 /* .... ..xx x... .... */
275 proto_tree_add_bits_ret_val( tree, hf_h263_UFEP, tvb, offset_in_bits, 3, &ufep, ENC_BIG_ENDIAN);
276 offset_in_bits = offset_in_bits +3;
277 if(ufep==1){
278 /* The Optional Part of PLUSPTYPE (OPPTYPE) (18 bits)
280 /* .xxx xxxx xxxx xxxx xxx. .... */
281 opptype_item = proto_tree_add_bits_item( tree, hf_h263_opptype, tvb, offset_in_bits, 18, ENC_BIG_ENDIAN);
282 h263_opptype_tree = proto_item_add_subtree( opptype_item, ett_h263_optype );
284 * If UFEP is "001", then the following bits are present in PLUSPTYPE:
285 * Bits 1-3 Source Format, "000" reserved, "001" sub-QCIF, "010" QCIF, "011" CIF,
286 * "100" 4CIF, "101" 16CIF, "110" custom source format, "111" reserved;
288 proto_tree_add_bits_item( h263_opptype_tree, hf_h263_ext_source_format, tvb, offset_in_bits, 3, ENC_BIG_ENDIAN);
289 offset_in_bits+=3;
292 * Bit 4 Optional Custom PCF, "0" CIF PCF, "1" custom PCF;
294 proto_tree_add_bits_ret_val( h263_opptype_tree, hf_h263_custom_pcf, tvb, offset_in_bits, 1, &custom_pcf, ENC_BIG_ENDIAN);
295 offset_in_bits++;
296 saved_bit_offset=offset_in_bits;
298 * Bit 5 Optional Unrestricted Motion Vector (UMV) mode (see Annex D), "0" off, "1" on;
300 offset_in_bits++;
302 * Bit 6 Optional Syntax-based Arithmetic Coding (SAC) mode (see Annex E), "0" off, "1" on;
304 offset_in_bits++;
306 * Bit 7 Optional Advanced Prediction (AP) mode (see Annex F), "0" off, "1" on;
308 offset_in_bits++;
310 * Bit 8 Optional Advanced INTRA Coding (AIC) mode (see Annex I), "0" off, "1" on;
312 offset_in_bits++;
314 * Bit 9 Optional Deblocking Filter (DF) mode (see Annex J), "0" off, "1" on;
316 offset_in_bits++;
318 * Bit 10 Optional Slice Structured (SS) mode (see Annex K), "0" off, "1" on;
320 offset_in_bits++;
322 * Bit 11 Optional Reference Picture Selection (RPS) mode (see Annex N), "0" off, "1" on;
324 offset_in_bits++;
326 * Bit 12 Optional Independent Segment Decoding (ISD) mode (see Annex R), "0" off,"1" on;
328 offset_in_bits++;
330 * Bit 13 Optional Alternative INTER VLC (AIV) mode (see Annex S), "0" off, "1" on;
332 offset_in_bits++;
334 * Bit 14 Optional Modified Quantization (MQ) mode (see Annex T), "0" off, "1" on;
336 offset_in_bits++;
338 * Bit 15 Equal to "1" to prevent start code emulation;
340 offset_in_bits++;
342 * Bit 16 Reserved, shall be equal to "0";
344 offset_in_bits++;
346 * Bit 17 Reserved, shall be equal to "0";
348 offset_in_bits++;
350 * Bit 18 Reserved, shall be equal to "0".
352 offset_in_bits++;
353 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);
357 * 5.1.4.3 The mandatory part of PLUSPTYPE when PLUSPTYPE present (MPPTYPE) (9 bits)
358 * Regardless of the value of UFEP, the following 9 bits are also present in PLUSPTYPE:
359 * - Bits 1-3 Picture Type Code:
360 * "000" I-picture (INTRA);
361 * "001" P-picture (INTER);
362 * "010" Improved PB-frame (see Annex M);
363 * "011" B-picture (see Annex O);
364 * "100" EI-picture (see Annex O);
365 * "101" EP-picture (see Annex O);
366 * "110" Reserved;
367 * "111" Reserved;
369 proto_tree_add_bits_ret_val( tree, hf_h263_picture_type_code, tvb, offset_in_bits, 3, &picture_type_code, ENC_BIG_ENDIAN);
370 offset_in_bits+=3;
371 saved_bit_offset=offset_in_bits;
373 * Bit 4 Optional Reference Picture Resampling (RPR) mode (see Annex P), "0" off, "1" on;
375 offset_in_bits++;
377 * Bit 5 Optional Reduced-Resolution Update (RRU) mode (see Annex Q), "0" off, "1" on;
379 offset_in_bits++;
381 * Bit 6 Rounding Type (RTYPE) (see 6.1.2);
383 offset_in_bits++;
385 * Bit 7 Reserved, shall be equal to "0";
387 offset_in_bits++;
389 * Bit 8 Reserved, shall be equal to "0";
391 offset_in_bits++;
393 * Bit 9 Equal to "1" to prevent start code emulation.
395 offset_in_bits++;
396 proto_tree_add_bits_item( tree, hf_h263_not_dissected, tvb, saved_bit_offset, offset_in_bits-saved_bit_offset, ENC_BIG_ENDIAN);
397 /* The picture header location of CPM (1 bit) and PSBI (2 bits)
398 * the picture header depends on whether or not PLUSPTYPE is present
399 * (see 5.1.20 and 5.1.21). If PLUSPTYPE is present, then CPM follows
400 * immediately after PLUSPTYPE in the picture header.
402 proto_tree_add_bits_ret_val( tree, hf_h263_cpm, tvb, offset_in_bits, 1, &cpm, ENC_BIG_ENDIAN);
403 offset_in_bits++;
404 /* 5.1.21 Picture Sub-Bitstream Indicator (PSBI) (2 bits)
405 * only present if Continuous Presence Multipoint and Video
406 * Multiplex mode is indicated by CPM.
408 if(cpm==1){
409 proto_tree_add_bits_item( tree, hf_h263_psbi, tvb, offset_in_bits, 2, ENC_BIG_ENDIAN);
410 offset_in_bits+=2;
412 return offset_in_bits>>3;
413 /* TODO Add the rest of the fields */
414 /* 5.1.5 Custom Picture Format (CPFMT) (23 bits)
415 * present only if the use of a custom picture format is
416 * signalled in PLUSPTYPE and UFEP is '001'. When present, CPFMT consists of:
417 * Bits 1-4 Pixel Aspect Ratio Code: A 4-bit index to the PAR value in Table 5. For
418 * extended PAR, the exact pixel aspect ratio shall be specified in EPAR
419 * (see 5.1.6);
420 * Bits 5-13 Picture Width Indication: Range [0, ... , 511]; Number of pixels per
421 * line = (PWI + 1) * 4;
422 * Bit 14 Equal to "1" to prevent start code emulation;
423 * Bits 15-23 Picture Height Indication: Range [1, ... , 288]; Number of lines = PHI * 4.
425 /* 5.1.6 Extended Pixel Aspect Ratio (EPAR) (16 bits)
426 * A fixed length codeword of 16 bits that is present only if CPFMT is present and extended PAR is
427 * indicated therein. When present, EPAR consists of:
428 * Bits 1-8 PAR Width: "0" is forbidden. The natural binary representation of the PAR
429 * width;
430 * Bits 9-16 PAR Height: "0" is forbidden. The natural binary representation of the PAR
431 * height.
433 /* 5.1.7 Custom Picture Clock Frequency Code (CPCFC) (8 bits)
434 * A fixed length codeword of 8 bits that is present only if PLUSPTYPE is present and UFEP is 001
435 * and a custom picture clock frequency is signalled in PLUSPTYPE. When present, CPCFC consists of:
436 * Bit 1 Clock Conversion Code: "0" indicates a clock conversion factor of 1000 and
437 * "1" indicates 1001;
438 * Bits 2-8 Clock Divisor: "0" is forbidden. The natural binary representation of the value
439 * of the clock divisor.
441 /* 5.1.8 Extended Temporal Reference (ETR) (2 bits)
442 * A fixed length codeword of 2 bits which is present only if a custom picture clock frequency is in
443 * use (regardless of the value of UFEP). It is the two MSBs of the 10-bit number defined in 5.1.2.
445 /* 5.1.9 Unlimited Unrestricted Motion Vectors Indicator (UUI) (Variable length)
446 * A variable length codeword of 1 or 2 bits that is present only if the optional Unrestricted Motion
447 * Vector mode is indicated in PLUSPTYPE and UFEP is 001. When UUI is present it indicates the
448 * effective limitation of the range of the motion vectors being used.
449 * UUI = "1" The motion vector range is limited according to Tables D.1 and D.2.
450 * UUI = "01" The motion vector range is not limited except by the picture size.
453 * 5.1.10 Slice Structured Submode bits (SSS) (2 bits)
454 * A fixed length codeword of 2 bits which is present only if the optional Slice Structured mode
455 * (see Annex K) is indicated in PLUSPTYPE and UFEP is 001. If the Slice Structured mode is in use
456 * but UFEP is not 001, the last values sent for SSS shall remain in effect.
457 * - Bit 1 Rectangular Slices, "0" indicates free-running slices, "1" indicates rectangular
458 * slices;
459 * - Bit 2 Arbitrary Slice Ordering, "0" indicates sequential order, "1" indicates arbitrary
460 * order.
461 * 5.1.11 Enhancement Layer Number (ELNUM) (4 bits)
462 * A fixed length codeword of 4 bits which is present only if the optional Temporal, SNR, and Spatial
463 * Scalability mode is in use (regardless of the value of UFEP). The particular enhancement layer is
464 * identified by an enhancement layer number, ELNUM. Picture correspondence between layers is
465 * achieved via the temporal reference. Picture size is either indicated within each enhancement layer
466 * using the existing source format fields or is inferred by the relationship to the reference layer. The
467 * first enhancement layer above the base layer is designated as Enhancement Layer Number 2, and
468 * the base layer has number 1.
469 * 5.1.12 Reference Layer Number (RLNUM) (4 bits)
470 * A fixed length codeword of 4 bits which is present only if the optional Temporal, SNR, and Spatial
471 * Scalability mode is in use (see Annex O) and UFEP is 001. The layer number for the pictures used
472 * as reference anchors is identified by a Reference Layer Number (RLNUM). Time correspondence
473 * between layers is achieved via the temporal reference.
474 * Note that for B-pictures in an enhancement layer having temporally surrounding EI- or EP-pictures
475 * which are present in the same enhancement layer, RLNUM shall be equal to ELNUM
476 * (see Annex O).
477 * 5.1.13 Reference Picture Selection Mode Flags (RPSMF) (3 bits)
478 * A fixed length codeword of 3 bits that is present only if the Reference Picture Selection mode is in
479 * use and UFEP is 001. When present, RPSMF indicates which type of back-channel messages are
480 * needed by the encoder. If the Reference Picture Selection mode is in use but RPSMF is not present,
481 * the last value of RPSMF that was sent shall remain in effect.
482 * - 100: neither ACK nor NACK signals needed;
483 * - 101: need ACK signals to be returned;
484 * - 110: need NACK signals to be returned;
485 * - 111: need both ACK and NACK signals to be returned;
486 * - 000-011: Reserved.
487 * 5.1.14 Temporal Reference for Prediction Indication (TRPI) (1 bit)
488 * A fixed length codeword of 1 bit that is present only if the optional Reference Picture Selection
489 * mode is in use (regardless of the value of UFEP). When present, TRPI indicates the presence of the
490 * following TRP field:
491 * - 0: TRP field is not present;
492 * - 1: TRP field is present.
493 * TRPI shall be 0 whenever the picture header indicates an I- or EI-picture.
494 * 5.1.15 Temporal Reference for Prediction (TRP) (10 bits)
495 * When present (as indicated in TRPI), TRP indicates the Temporal Reference which is used for
496 * prediction of the encoding, except for in the case of B-pictures. For B-pictures, the picture having
497 * the temporal reference TRP is used for the prediction in the forward direction. (Prediction in the
498 * reverse-temporal direction always uses the immediately temporally subsequent picture.) TRP is a
499 * ten-bit number. If a custom picture clock frequency was not in use for the reference picture, the two
500 * MSBs of TRP are zero and the LSBs contain the eight-bit TR found in the picture header of the
501 * reference picture. If a custom picture clock frequency was in use for the reference picture, TRP is a
502 * ten-bit number consisting of the concatenation of ETR and TR from the reference picture header.
503 * When TRP is not present, the most recent temporally previous anchor picture shall be used for
504 * prediction, as when not in the Reference Picture Selection mode. TRP is valid until the next PSC,
505 * GSC, or SSC.
506 * 5.1.16 Back-Channel message Indication (BCI) (Variable length)
507 * A variable length field of one or two bits that is present only if the optional Reference Picture
508 * Selection mode is in use. When set to "1", this signals the presence of the following optional video
509 * Back-Channel Message (BCM) field. "01" indicates the absence or the end of the video backchannel
510 * message field. Combinations of BCM and BCI may not be present, and may be repeated
511 * when present. BCI shall be set to "01" if the videomux submode of the optional Reference Picture
512 * Selection mode is not in use.
513 * 5.1.17 Back-Channel Message (BCM) (Variable length)
514 * The Back-Channel message with syntax as specified in N.4.2, which is present only if the preceding
515 * BCI field is present and is set to "1".
516 * 5.1.18 Reference Picture Resampling Parameters (RPRP) (Variable length)
517 * A variable length field that is present only if the optional Reference Picture Resampling mode bit is
518 * set in PLUSPTYPE. This field carries the parameters of the Reference Picture Resampling mode
519 * (see Annex P). Note that the Reference Picture Resampling mode can also be invoked implicitly by
520 * the occurrence of a picture header for an INTER coded picture having a picture size which differs
521 * from that of the previous encoded picture, in which case the RPRP field is not present and the
522 * Reference Picture Resampling mode bit is not set.
525 /* 5.1.19 Quantizer Information (PQUANT) (5 bits) */
526 proto_tree_add_bits_item( tree, hf_h263_pquant, tvb, offset_in_bits, 5, ENC_BIG_ENDIAN);
527 offset_in_bits = offset_in_bits +5;
528 if (source_format != H263_PLUSPTYPE){
529 proto_tree_add_bits_ret_val( tree, hf_h263_cpm, tvb, offset_in_bits, 1, &cpm, ENC_BIG_ENDIAN);
530 offset_in_bits++;
531 /* 5.1.21 Picture Sub-Bitstream Indicator (PSBI) (2 bits)
532 * only present if Continuous Presence Multipoint and Video
533 * Multiplex mode is indicated by CPM.
535 if(cpm==1){
536 proto_tree_add_bits_item( tree, hf_h263_psbi, tvb, offset_in_bits, 2, ENC_BIG_ENDIAN);
537 offset_in_bits = offset_in_bits +2;
540 /* 5.1.22 Temporal Reference for B-pictures in PB-frames (TRB) (3/5 bits)
541 * TRB is present if PTYPE or PLUSPTYPE indicates "PB-frame" or "Improved PB-frame"
542 * It is 3 bits long for standard CIF picture clock frequency and is
543 * extended to 5 bits when a custom picture clock frequency is in use.
545 if((PB_frames_mode == 1)||(picture_type_code == 2 )){
546 if(custom_pcf == 0){
547 proto_tree_add_bits_item( tree, hf_h263_trb, tvb, offset_in_bits, 3, ENC_BIG_ENDIAN);
548 offset_in_bits = offset_in_bits +3;
549 }else{
550 proto_tree_add_bits_item( tree, hf_h263_trb, tvb, offset_in_bits, 5, ENC_BIG_ENDIAN);
551 offset_in_bits = offset_in_bits +5;
554 /* 5.1.23 Quantization information for B-pictures in PB-frames (DBQUANT) (2 bits)
555 * DBQUANT is present if PTYPE or PLUSPTYPE indicates "PB-frame" or "Improved PB-frame"
557 if((PB_frames_mode == 1)||(picture_type_code == 2 )){
558 offset_in_bits = offset_in_bits +2;
560 /* 5.1.24 Extra Insertion Information (PEI) (1 bit)
561 * A bit which when set to "1" signals the presence of the following optional data field.
563 proto_tree_add_bits_ret_val( tree, hf_h263_pei, tvb, offset_in_bits, 1, &pei, ENC_BIG_ENDIAN);
564 offset_in_bits++;
565 while(pei==1)
567 /*5.1.25 Supplemental Enhancement Information (PSUPP) (0/8/16 ... bits)
568 * If PEI is set to "1", then 9 bits follow consisting of 8 bits of data (PSUPP) and then another PEI bit
569 * to indicate if a further 9 bits follow and so on. Encoders shall use PSUPP as specified in Annex L.
571 proto_tree_add_bits_item( tree, hf_h263_psupp, tvb, offset_in_bits, 8, ENC_BIG_ENDIAN);
572 offset_in_bits+=8;
573 proto_tree_add_bits_ret_val( tree, hf_h263_pei, tvb, offset_in_bits, 1, &pei, ENC_BIG_ENDIAN);
574 offset_in_bits++;
576 /* For the first GOB in each picture (with number 0), no GOB header shall be transmitted.
577 * For all other GOBs, the GOB header may be empty, depending on the encoder strategy.
581 * 5.3 Macroblock layer
582 * dissect_h263_macroblock_layer( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
585 return offset_in_bits>>3;
590 5.1.1 Picture Start Code (PSC) (22 bits)
591 PSC is a word of 22 bits. Its value is 0000 0000 0000 0000 1 00000. All picture start codes shall be
592 byte aligned.
593 ( 1000 00xx)
595 End Of Sequence (EOS) (22 bits)
596 A codeword of 22 bits. Its value is 0000 0000 0000 0000 1 11111.
597 ( 1111 11xx )
599 Group of Block Start Code (GBSC) (17 bits)
600 A word of 17 bits. Its value is 0000 0000 0000 0000 1.
601 ( 1xxx xxxx )
603 End Of Sub-Bitstream code (EOSBS) (23 bits)
604 The EOSBS code is a codeword of 23 bits. Its value is 0000 0000 0000 0000 1 11110 0.
605 ( 1111 100x )
607 Slice Start Code (SSC) (17 bits)
608 A word of 17 bits. Its value is 0000 0000 0000 0000 1.
609 ( 1xxx xxxx )
611 static int dissect_h263_data( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* dissector_data _U_ )
613 unsigned offset = 0;
614 proto_item *h263_payload_item = NULL;
615 proto_tree *h263_payload_tree = NULL;
616 uint32_t data;
617 uint8_t startcode;
618 int length;
620 col_append_str( pinfo->cinfo, COL_INFO, "H263 payload ");
622 h263_payload_item = proto_tree_add_item( tree, proto_h263_data, tvb, offset, -1, ENC_NA );
623 h263_payload_tree = proto_item_add_subtree( h263_payload_item, ett_h263_payload );
625 length = tvb_reported_length_remaining(tvb,0);
626 if(length<4){
627 if( tree )
628 proto_tree_add_item( h263_payload_tree, hf_h263_data, tvb, offset, -1, ENC_NA );
629 return tvb_captured_length(tvb);
631 /* Check for PSC, PSC is a word of 22 bits. Its value is 0000 0000 0000 0000' 1000 00xx xxxx xxxx. */
632 data = tvb_get_ntohl(tvb, offset);
634 if (( data & 0xffff8000) == 0x00008000 ) {
635 /* Start Code found
637 * Startc code holds bit 17 -23 of the codeword
639 startcode = tvb_get_uint8(tvb,offset+2)&0xfe;
640 if (startcode & 0x80){
641 switch(startcode){
642 case 0xf8:
643 /* End Of Sub-Bitstream code (EOSBS)
644 * ( 1111 100. )
646 break;
647 case 0x80:
648 case 0x82:
649 /* Picture Start Code (PSC)
650 * ( 1000 00x.)
652 col_append_str( pinfo->cinfo, COL_INFO, "(PSC) ");
653 offset = dissect_h263_picture_layer( tvb, pinfo, h263_payload_tree, offset, -1, ENC_NA);
654 break;
655 case 0xfc:
656 case 0xfe:
657 /* End Of Sequence (EOS)
658 * ( 1111 11x. )
660 default:
661 /* Group of Block Start Code (GBSC) or
662 * Slice Start Code (SSC)
664 col_append_str( pinfo->cinfo, COL_INFO, "(GBSC) ");
665 offset = dissect_h263_group_of_blocks_layer( tvb, h263_payload_tree, offset,false);
666 break;
668 }else{
669 /* Error */
672 if( tree )
673 proto_tree_add_item( h263_payload_tree, hf_h263_data, tvb, offset, -1, ENC_NA );
675 return tvb_captured_length(tvb);
678 void
679 proto_register_h263_data(void)
681 static hf_register_info hf[] =
684 &hf_h263_psc,
686 "H.263 Picture start Code",
687 "h263.psc",
688 FT_UINT32,
689 BASE_HEX,
690 NULL,
691 0x0,
692 "Picture start Code, PSC", HFILL
695 { &hf_h263_gbsc,
697 "H.263 Group of Block Start Code",
698 "h263.gbsc",
699 FT_UINT32,
700 BASE_HEX,
701 NULL,
702 0x0,
703 NULL, HFILL
707 &hf_h263_TR,
709 "H.263 Temporal Reference",
710 "h263.tr2",
711 FT_UINT32,
712 BASE_DEC,
713 NULL,
714 0x0,
715 "Temporal Reference, TR", HFILL
719 &hf_h263_trb,
721 "Temporal Reference for B frames",
722 "h263.trb",
723 FT_UINT8,
724 BASE_DEC,
725 NULL,
726 0x0,
727 "Temporal Reference for the B frame as defined by H.263", HFILL
731 &hf_h263_split_screen_indicator,
733 "H.263 Split screen indicator",
734 "h263.split_screen_indicator",
735 FT_BOOLEAN,
736 BASE_NONE,
737 TFS(&tfs_on_off),
738 0x0,
739 NULL, HFILL
743 &hf_h263_document_camera_indicator,
745 "H.263 Document camera indicator",
746 "h263.document_camera_indicator",
747 FT_BOOLEAN,
748 BASE_NONE,
749 TFS(&tfs_on_off),
750 0x0,
751 NULL, HFILL
755 &hf_h263_full_picture_freeze_release,
757 "H.263 Full Picture Freeze Release",
758 "h263.full_picture_freeze_release",
759 FT_BOOLEAN,
760 BASE_NONE,
761 TFS(&tfs_on_off),
762 0x0,
763 NULL, HFILL
767 &hf_h263_source_format,
769 "H.263 Source Format",
770 "h263.source_format",
771 FT_UINT8,
772 BASE_HEX,
773 VALS(h263_srcformat_vals),
774 0x0,
775 NULL, HFILL
779 &hf_h263_ext_source_format,
781 "H.263 Source Format",
782 "h263.ext_source_format",
783 FT_UINT8,
784 BASE_HEX,
785 VALS(ext_srcformat_vals),
786 0x0,
787 NULL, HFILL
791 &hf_h263_UFEP,
793 "H.263 Update Full Extended PTYPE",
794 "h263.ufep",
795 FT_UINT16,
796 BASE_DEC,
797 VALS(h263_ufep_vals),
798 0x0,
799 NULL, HFILL
803 &hf_h263_opptype,
805 "H.263 Optional Part of PLUSPTYPE",
806 "h263.opptype",
807 FT_UINT24,
808 BASE_DEC,
809 NULL,
810 0x0,
811 NULL, HFILL
815 &hf_h263_payload_picture_coding_type,
817 "H.263 Picture Coding Type",
818 "h263.picture_coding_type",
819 FT_BOOLEAN,
820 BASE_NONE,
821 TFS(&picture_coding_type_flg),
822 0x0,
823 NULL, HFILL
827 &hf_h263_opt_unres_motion_vector_mode,
829 "H.263 Optional Unrestricted Motion Vector mode",
830 "h263.opt_unres_motion_vector_mode",
831 FT_BOOLEAN,
832 BASE_NONE,
833 TFS(&tfs_on_off),
834 0x0,
835 NULL, HFILL
839 &hf_h263_syntax_based_arithmetic_coding_mode,
841 "H.263 Optional Syntax-based Arithmetic Coding mode",
842 "h263.syntax_based_arithmetic_coding_mode",
843 FT_BOOLEAN,
844 BASE_NONE,
845 TFS(&tfs_on_off),
846 0x0,
847 NULL, HFILL
851 &hf_h263_optional_advanced_prediction_mode,
853 "H.263 Optional Advanced Prediction mode",
854 "h263.optional_advanced_prediction_mode",
855 FT_BOOLEAN,
856 BASE_NONE,
857 TFS(&tfs_on_off),
858 0x0,
859 NULL, HFILL
863 &hf_h263_PB_frames_mode,
865 "H.263 Optional PB-frames mode",
866 "h263.PB_frames_mode",
867 FT_BOOLEAN,
868 BASE_NONE,
869 TFS(&PB_frames_mode_flg),
870 0x0,
871 NULL, HFILL
875 &hf_h263_GN,
877 "H.263 Group Number",
878 "h263.gn",
879 FT_UINT32,
880 BASE_DEC,
881 NULL,
882 0x0,
883 "Group Number, GN", HFILL
887 &hf_h263_pquant,
889 "H.263 Quantizer Information (PQUANT)",
890 "h263.pquant",
891 FT_UINT32,
892 BASE_DEC,
893 NULL,
894 0x0,
895 NULL, HFILL
899 &hf_h263_cpm,
901 "H.263 Continuous Presence Multipoint and Video Multiplex (CPM)",
902 "h263.cpm",
903 FT_BOOLEAN,
904 BASE_NONE,
905 TFS(&tfs_on_off),
906 0x0,
907 NULL, HFILL
911 &hf_h263_psbi,
913 "H.263 Picture Sub-Bitstream Indicator (PSBI)",
914 "h263.psbi",
915 FT_UINT32,
916 BASE_DEC,
917 NULL,
918 0x0,
919 NULL, HFILL
923 &hf_h263_picture_type_code,
925 "H.263 Picture Type Code",
926 "h263.psi",
927 FT_UINT32,
928 BASE_DEC,
929 VALS(picture_type_code_vals),
930 0x0,
931 NULL, HFILL
935 &hf_h263_custom_pcf,
937 "H.263 Custom PCF",
938 "h263.custom_pcf",
939 FT_BOOLEAN,
940 BASE_NONE,
941 TFS(&custom_pcf_flg),
942 0x0,
943 NULL, HFILL
947 &hf_h263_pei,
949 "H.263 Extra Insertion Information (PEI)",
950 "h263.pei",
951 FT_BOOLEAN,
952 BASE_NONE,
953 NULL,
954 0x0,
955 NULL, HFILL
959 &hf_h263_psupp,
961 "H.263 Supplemental Enhancement Information (PSUPP)",
962 "h263.psupp",
963 FT_UINT32,
964 BASE_DEC,
965 NULL,
966 0x0,
967 NULL, HFILL
971 &hf_h263_data,
973 "H.263 stream",
974 "h263.stream",
975 FT_BYTES,
976 BASE_NONE,
977 NULL,
978 0x0,
979 "The H.263 stream including its Picture, GOB or Macro block start code.", HFILL
983 &hf_h263_not_dissected,
985 "H.263 Bits currently not dissected",
986 "h263.not_dis",
987 FT_UINT32,
988 BASE_DEC,
989 NULL,
990 0x0,
991 "These bits are not dissected(yet), displayed for clarity", HFILL
996 static int *ett[] =
998 &ett_h263_payload,
999 &ett_h263_optype,
1002 proto_register_subtree_array(ett, array_length(ett));
1004 proto_h263_data = proto_register_protocol("ITU-T Recommendation H.263",
1005 "H.263", "h263");
1006 proto_register_field_array(proto_h263_data, hf, array_length(hf));
1007 register_dissector("h263data", dissect_h263_data, proto_h263_data);
1011 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1013 * Local variables:
1014 * c-basic-offset: 8
1015 * tab-width: 8
1016 * indent-tabs-mode: t
1017 * End:
1019 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
1020 * :indentSize=8:tabSize=8:noTabs=false: