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
23 #include <epan/packet.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" },
83 { H263_PLUSPTYPE
, "extended PTYPE" },
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
[] =
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",},
105 static const value_string h263_ufep_vals
[] =
107 { 0, "Only MPPTYPE included" },
108 { 1, "All extended PTYPE fields are included" },
112 static const true_false_string picture_coding_type_flg
= {
117 static const value_string picture_coding_type_vals
[] =
124 static const true_false_string PB_frames_mode_flg
= {
126 "Normal I- or P-picture"
130 static const true_false_string custom_pcf_flg
= {
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)" },
151 * 5.3 Macroblock layer
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;
168 proto_tree_add_bits_item(tree
, hf_h263_gbsc
, tvb
, offset_in_bits
, 1, ENC_BIG_ENDIAN
);
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
;
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;
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;
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
);
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
);
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
);
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)"));
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
);
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
);
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
);
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
);
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;
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
);
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
);
296 saved_bit_offset
=offset_in_bits
;
298 * Bit 5 Optional Unrestricted Motion Vector (UMV) mode (see Annex D), "0" off, "1" on;
302 * Bit 6 Optional Syntax-based Arithmetic Coding (SAC) mode (see Annex E), "0" off, "1" on;
306 * Bit 7 Optional Advanced Prediction (AP) mode (see Annex F), "0" off, "1" on;
310 * Bit 8 Optional Advanced INTRA Coding (AIC) mode (see Annex I), "0" off, "1" on;
314 * Bit 9 Optional Deblocking Filter (DF) mode (see Annex J), "0" off, "1" on;
318 * Bit 10 Optional Slice Structured (SS) mode (see Annex K), "0" off, "1" on;
322 * Bit 11 Optional Reference Picture Selection (RPS) mode (see Annex N), "0" off, "1" on;
326 * Bit 12 Optional Independent Segment Decoding (ISD) mode (see Annex R), "0" off,"1" on;
330 * Bit 13 Optional Alternative INTER VLC (AIV) mode (see Annex S), "0" off, "1" on;
334 * Bit 14 Optional Modified Quantization (MQ) mode (see Annex T), "0" off, "1" on;
338 * Bit 15 Equal to "1" to prevent start code emulation;
342 * Bit 16 Reserved, shall be equal to "0";
346 * Bit 17 Reserved, shall be equal to "0";
350 * Bit 18 Reserved, shall be equal to "0".
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);
369 proto_tree_add_bits_ret_val( tree
, hf_h263_picture_type_code
, tvb
, offset_in_bits
, 3, &picture_type_code
, ENC_BIG_ENDIAN
);
371 saved_bit_offset
=offset_in_bits
;
373 * Bit 4 Optional Reference Picture Resampling (RPR) mode (see Annex P), "0" off, "1" on;
377 * Bit 5 Optional Reduced-Resolution Update (RRU) mode (see Annex Q), "0" off, "1" on;
381 * Bit 6 Rounding Type (RTYPE) (see 6.1.2);
385 * Bit 7 Reserved, shall be equal to "0";
389 * Bit 8 Reserved, shall be equal to "0";
393 * Bit 9 Equal to "1" to prevent start code emulation.
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
);
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.
409 proto_tree_add_bits_item( tree
, hf_h263_psbi
, tvb
, offset_in_bits
, 2, ENC_BIG_ENDIAN
);
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
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
430 * Bits 9-16 PAR Height: "0" is forbidden. The natural binary representation of the PAR
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
459 * - Bit 2 Arbitrary Slice Ordering, "0" indicates sequential order, "1" indicates arbitrary
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
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,
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
);
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.
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 )){
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;
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
);
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
);
573 proto_tree_add_bits_ret_val( tree
, hf_h263_pei
, tvb
, offset_in_bits
, 1, &pei
, ENC_BIG_ENDIAN
);
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
595 End Of Sequence (EOS) (22 bits)
596 A codeword of 22 bits. Its value is 0000 0000 0000 0000 1 11111.
599 Group of Block Start Code (GBSC) (17 bits)
600 A word of 17 bits. Its value is 0000 0000 0000 0000 1.
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.
607 Slice Start Code (SSC) (17 bits)
608 A word of 17 bits. Its value is 0000 0000 0000 0000 1.
611 static int dissect_h263_data( tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* dissector_data _U_
)
614 proto_item
*h263_payload_item
= NULL
;
615 proto_tree
*h263_payload_tree
= NULL
;
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);
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 ) {
637 * Startc code holds bit 17 -23 of the codeword
639 startcode
= tvb_get_uint8(tvb
,offset
+2)&0xfe;
640 if (startcode
& 0x80){
643 /* End Of Sub-Bitstream code (EOSBS)
649 /* Picture Start Code (PSC)
652 col_append_str( pinfo
->cinfo
, COL_INFO
, "(PSC) ");
653 offset
= dissect_h263_picture_layer( tvb
, pinfo
, h263_payload_tree
, offset
, -1, ENC_NA
);
657 /* End Of Sequence (EOS)
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);
673 proto_tree_add_item( h263_payload_tree
, hf_h263_data
, tvb
, offset
, -1, ENC_NA
);
675 return tvb_captured_length(tvb
);
679 proto_register_h263_data(void)
681 static hf_register_info hf
[] =
686 "H.263 Picture start Code",
692 "Picture start Code, PSC", HFILL
697 "H.263 Group of Block Start Code",
709 "H.263 Temporal Reference",
715 "Temporal Reference, TR", HFILL
721 "Temporal Reference for B frames",
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",
743 &hf_h263_document_camera_indicator
,
745 "H.263 Document camera indicator",
746 "h263.document_camera_indicator",
755 &hf_h263_full_picture_freeze_release
,
757 "H.263 Full Picture Freeze Release",
758 "h263.full_picture_freeze_release",
767 &hf_h263_source_format
,
769 "H.263 Source Format",
770 "h263.source_format",
773 VALS(h263_srcformat_vals
),
779 &hf_h263_ext_source_format
,
781 "H.263 Source Format",
782 "h263.ext_source_format",
785 VALS(ext_srcformat_vals
),
793 "H.263 Update Full Extended PTYPE",
797 VALS(h263_ufep_vals
),
805 "H.263 Optional Part of PLUSPTYPE",
815 &hf_h263_payload_picture_coding_type
,
817 "H.263 Picture Coding Type",
818 "h263.picture_coding_type",
821 TFS(&picture_coding_type_flg
),
827 &hf_h263_opt_unres_motion_vector_mode
,
829 "H.263 Optional Unrestricted Motion Vector mode",
830 "h263.opt_unres_motion_vector_mode",
839 &hf_h263_syntax_based_arithmetic_coding_mode
,
841 "H.263 Optional Syntax-based Arithmetic Coding mode",
842 "h263.syntax_based_arithmetic_coding_mode",
851 &hf_h263_optional_advanced_prediction_mode
,
853 "H.263 Optional Advanced Prediction mode",
854 "h263.optional_advanced_prediction_mode",
863 &hf_h263_PB_frames_mode
,
865 "H.263 Optional PB-frames mode",
866 "h263.PB_frames_mode",
869 TFS(&PB_frames_mode_flg
),
877 "H.263 Group Number",
883 "Group Number, GN", HFILL
889 "H.263 Quantizer Information (PQUANT)",
901 "H.263 Continuous Presence Multipoint and Video Multiplex (CPM)",
913 "H.263 Picture Sub-Bitstream Indicator (PSBI)",
923 &hf_h263_picture_type_code
,
925 "H.263 Picture Type Code",
929 VALS(picture_type_code_vals
),
941 TFS(&custom_pcf_flg
),
949 "H.263 Extra Insertion Information (PEI)",
961 "H.263 Supplemental Enhancement Information (PSUPP)",
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",
991 "These bits are not dissected(yet), displayed for clarity", HFILL
1002 proto_register_subtree_array(ett
, array_length(ett
));
1004 proto_h263_data
= proto_register_protocol("ITU-T Recommendation H.263",
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
1016 * indent-tabs-mode: t
1019 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
1020 * :indentSize=8:tabSize=8:noTabs=false: