2 * Routines for VP8 dissection
3 * Copyright 2014, Owen Williams williams.owen@gmail.com
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
13 * RFC 6386 - VP8 Data Format and Decoding Guide
14 * RFC 7741 - RTP Payload Format for VP8 Video
20 #include <epan/packet.h>
21 #include <epan/prefs.h>
22 #include <epan/expert.h>
24 #include <wsutil/array.h>
26 void proto_reg_handoff_vp8(void);
27 void proto_register_vp8(void);
29 #define BIT_1_MASK 0x80
30 #define BIT_2_MASK 0x40
31 #define BIT_3_MASK 0x20
32 #define BIT_4_MASK 0x10
33 #define BIT_5_MASK 0x08
34 #define BIT_6_MASK 0x04
35 #define BIT_7_MASK 0x02
36 #define BIT_8_MASK 0x01
37 #define BIT_123_MASK 0xE0
38 #define BIT_234_MASK 0x70
39 #define BIT_5678_MASK 0x0F
40 #define BIT_567_MASK 0x0E
41 #define BIT_45678_MASK 0x1F
42 #define BIT_12_MASK 0xC0
43 #define BIT_NO_MASK 0x0
45 #define BIT_2BYTE_NO_MASK 0x0
46 #define BIT_3BYTE_NO_MASK 0x0
47 #define BIT_EXT_PICTURE_MASK 0x7FFF
48 #define BIT_PARTITION_SIZE_MASK 0xFFFFE0
50 static dissector_handle_t vp8_handle
;
52 /* Initialize the protocol and registered fields */
54 static int hf_vp8_pld_x_bit
;
55 static int hf_vp8_pld_r_bit
;
56 static int hf_vp8_pld_n_bit
;
57 static int hf_vp8_pld_s_bit
;
58 static int hf_vp8_pld_part_id
;
59 static int hf_vp8_pld_i_bit
;
60 static int hf_vp8_pld_l_bit
;
61 static int hf_vp8_pld_t_bit
;
62 static int hf_vp8_pld_k_bit
;
63 static int hf_vp8_pld_rsv_a
;
64 static int hf_vp8_pld_picture_id
;
65 static int hf_vp8_pld_extended_picture_id
;
66 static int hf_vp8_pld_tl0picidx
;
67 static int hf_vp8_pld_tid
;
68 static int hf_vp8_pld_y_bit
;
69 static int hf_vp8_pld_keyidx
;
71 /* payload header fields */
72 static int hf_vp8_hdr_frametype
;
73 static int hf_vp8_hdr_version
;
74 static int hf_vp8_hdr_show_bit
;
75 static int hf_vp8_hdr_first_partition_size
;
78 static int hf_vp8_keyframe_start_code
;
79 static int hf_vp8_keyframe_width
;
80 static int hf_vp8_keyframe_horizontal_scale
;
81 static int hf_vp8_keyframe_height
;
82 static int hf_vp8_keyframe_vertical_scale
;
84 /* Initialize the subtree pointers */
86 static int ett_vp8_payload_descriptor
;
87 static int ett_vp8_payload_header
;
88 static int ett_vp8_payload
;
89 static int ett_vp8_keyframe
;
91 static expert_field ei_vp8_startcode
;
92 static expert_field ei_vp8_undecoded
;
93 static expert_field ei_vp8_continuation
;
94 static expert_field ei_vp8_first_partition_split
;
95 static expert_field ei_vp8_first_partition_plus
;
98 dissect_vp8_payload_descriptor(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*vp8_tree
, int *offset
, bool *hasHeader
);
101 dissect_vp8_payload_header(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*vp8_tree
, int *offset
, int *frametype
, int *partition1_size
);
104 dissect_vp8_payload(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*vp8_tree
, int *offset
, int *frametype
, int *partition1_size
);
106 static int *ett
[] = {
108 &ett_vp8_payload_descriptor
,
109 &ett_vp8_payload_header
,
114 static const value_string vp8_type_values
[] = {
117 { 2, "Continuation" },
121 static const range_string vp8_hdr_version_vals
[] = {
122 { 0, 0, "Bicubic (Loop Filter=Normal)" },
123 { 1, 1, "Bilinear (Loop Filter=Simple)" },
124 { 2, 2, "Bilinear (Loop Filter=None)" },
125 { 3, 3, "No filters" },
126 { 4, 7, "Reserved for future use" },
130 static const true_false_string vp8_x_bit_vals
= {
131 "Extended control bits present (I L T K)",
132 "Extended control bits not present"
135 static const true_false_string vp8_r_bit_vals
= {
136 "Reserved for future use (error: should be zero)",
137 "Reserved for future use"
140 static const true_false_string vp8_n_bit_vals
= {
141 "Non-reference frame",
145 static const true_false_string vp8_s_bit_vals
= {
146 "Start of VP8 partition",
147 "Continuation of VP8 partition"
150 static const true_false_string vp8_i_bit_vals
= {
151 "Picture ID byte present",
155 static const true_false_string vp8_l_bit_vals
= {
156 "TL0PICIDX byte present",
157 "TL0PICIDX byte not present"
160 static const true_false_string vp8_t_bit_vals
= {
161 "TID (temporal layer index) present",
162 "TID (temporal layer index) not present"
165 static const true_false_string vp8_k_bit_vals
= {
170 static const true_false_string vp8_hdr_frametype_vals
= {
176 dissect_vp8(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
180 int offset
= 0, frametype
= 0, partition1_size
= -1;
181 proto_tree
*vp8_tree
;
182 bool hasHeader
= false;
184 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "VP8");
186 item
= proto_tree_add_item(tree
, proto_vp8
, tvb
, 0, -1, ENC_NA
);
187 vp8_tree
= proto_item_add_subtree(item
, ett_vp8
);
189 frametype
= 2; /*continuation, will get overridden if there is a payload header*/
191 dissect_vp8_payload_descriptor(tvb
, pinfo
, vp8_tree
, &offset
, &hasHeader
);
194 dissect_vp8_payload_header(tvb
, pinfo
, vp8_tree
, &offset
, &frametype
, &partition1_size
);
197 dissect_vp8_payload(tvb
, pinfo
, vp8_tree
, &offset
, &frametype
, &partition1_size
);
199 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - %s",
200 val_to_str(frametype
, vp8_type_values
, "Unknown Type (%u)"));
202 return tvb_captured_length(tvb
);
206 dissect_vp8_payload_descriptor(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*vp8_tree
, int *offset
, bool *hasHeader
)
208 proto_item
*item_descriptor
;
209 uint8_t extended_bit
, s_bit
, partId
;
210 proto_tree
*vp8_payload_descriptor_tree
;
213 The first octets after the RTP header are the VP8 payload descriptor,
214 with the following structure.
218 |X|R|N|S|R| PID | (REQUIRED), second R bit is parsed as part of PID
220 X: |I|L|T|K| RSV | (OPTIONAL)
222 I: |M| PictureID | (OPTIONAL)
224 L: | TL0PICIDX | (OPTIONAL)
226 T/K: |TID|Y| KEYIDX | (OPTIONAL)
230 vp8_payload_descriptor_tree
= proto_tree_add_subtree(vp8_tree
, tvb
, *offset
, -1, ett_vp8_payload_descriptor
,
231 &item_descriptor
, "Payload descriptor");
233 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_x_bit
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
234 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_r_bit
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
235 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_n_bit
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
236 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_s_bit
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
237 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_part_id
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
238 extended_bit
= tvb_get_uint8(tvb
, *offset
) & BIT_1_MASK
;
239 s_bit
= tvb_get_uint8(tvb
, *offset
) & BIT_4_MASK
;
240 partId
= tvb_get_uint8(tvb
, *offset
) & BIT_5678_MASK
;
242 if ((s_bit
> 0) && (partId
== 0)) {
248 uint8_t i_bit
, l_bit
, t_bit
, k_bit
;
250 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_i_bit
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
251 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_l_bit
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
252 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_t_bit
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
253 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_k_bit
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
254 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_rsv_a
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
256 i_bit
= tvb_get_uint8(tvb
, *offset
) & BIT_1_MASK
;
257 l_bit
= tvb_get_uint8(tvb
, *offset
) & BIT_2_MASK
;
258 t_bit
= tvb_get_uint8(tvb
, *offset
) & BIT_3_MASK
;
259 k_bit
= tvb_get_uint8(tvb
, *offset
) & BIT_4_MASK
;
263 if(tvb_get_uint8(tvb
, *offset
) & BIT_1_MASK
)
265 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_extended_picture_id
, tvb
, *offset
, 2, ENC_BIG_ENDIAN
);
270 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_picture_id
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
277 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_tl0picidx
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
282 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_tid
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
283 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_y_bit
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
284 proto_tree_add_item(vp8_payload_descriptor_tree
, hf_vp8_pld_keyidx
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
288 /* now we know the length of payload descriptor */
289 proto_item_set_len(item_descriptor
, *offset
);
293 dissect_vp8_payload_header(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*vp8_tree
, int *offset
, int *frametype
, int *partition1_size
)
295 proto_item
*item_header
;
296 proto_tree
*vp8_payload_header_tree
;
297 int size0
, size1
, size2
;
300 The first three octets of an encoded VP8 frame are referred to as an
301 "uncompressed data chunk" in [RFC6386], and co-serve as payload
302 header in this RTP format. The codec bitstream format specifies two
303 different variants of the uncompressed data chunk: a 3 octet version
304 for interframes and a 10 octet version for key frames. The first 3
305 octets are common to both variants. In the case of a key frame the
306 remaining 7 octets are considered to be part of the remaining payload
307 in this RTP format. Note that the header is present only in packets
308 which have the S bit equal to one and the PartID equal to zero in the
309 payload descriptor. Subsequent packets for the same frame do not
310 carry the payload header.
332 vp8_payload_header_tree
= proto_tree_add_subtree(vp8_tree
, tvb
, *offset
, 3, ett_vp8_payload_header
, &item_header
, "Payload header");
333 proto_tree_add_item(vp8_payload_header_tree
, hf_vp8_hdr_frametype
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
334 proto_tree_add_item(vp8_payload_header_tree
, hf_vp8_hdr_version
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
335 proto_tree_add_item(vp8_payload_header_tree
, hf_vp8_hdr_show_bit
, tvb
, *offset
, 1, ENC_BIG_ENDIAN
);
337 *frametype
= tvb_get_uint8(tvb
, *offset
) & BIT_8_MASK
;
339 size0
= (tvb_get_uint8(tvb
, *offset
) & BIT_123_MASK
) >> 5;
340 size1
= tvb_get_uint8(tvb
, *offset
+ 1);
341 size2
= tvb_get_uint8(tvb
, *offset
+ 2);
342 (*partition1_size
) = size0
+ (size1
*8) + (size2
*2048);
343 proto_tree_add_uint(vp8_payload_header_tree
, hf_vp8_hdr_first_partition_size
, tvb
, *offset
, 3, *partition1_size
);
348 dissect_vp8_payload(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*vp8_tree
, int *offset
, int *frametype
, int *partition1_size
)
350 proto_tree
*vp8_payload_tree
;
351 proto_item
*payload_item
;
354 vp8_payload_tree
= proto_tree_add_subtree(vp8_tree
, tvb
, *offset
, -1, ett_vp8_payload
, &payload_item
, "Payload");
358 uint16_t width
, height
;
359 int start1
, start2
, start3
, horizontal_scale
, vertical_scale
;
360 proto_tree
*vp8_keyframe_tree
;
362 vp8_keyframe_tree
= proto_tree_add_subtree(vp8_payload_tree
, tvb
, *offset
, -1, ett_vp8_keyframe
, NULL
, "Keyframe header");
364 proto_tree_add_item(vp8_keyframe_tree
, hf_vp8_keyframe_start_code
, tvb
, *offset
, 3, ENC_BIG_ENDIAN
);
365 start1
= tvb_get_uint8(tvb
, *offset
);
366 start2
= tvb_get_uint8(tvb
, *offset
+ 1);
367 start3
= tvb_get_uint8(tvb
, *offset
+ 2);
369 /* check start code is correct */
370 if ((start1
!= 0x9d) || (start2
!= 0x01) || (start3
!= 0x2a))
372 expert_add_info(pinfo
, vp8_keyframe_tree
, &ei_vp8_startcode
);
378 width
= tvb_get_letohs(tvb
, *offset
) & 0x3FFF;
379 horizontal_scale
= tvb_get_letohs(tvb
, *offset
)>>14;
381 proto_tree_add_uint(vp8_keyframe_tree
, hf_vp8_keyframe_horizontal_scale
, tvb
, *offset
, 2, horizontal_scale
);
382 proto_tree_add_uint(vp8_keyframe_tree
, hf_vp8_keyframe_width
, tvb
, *offset
, 2, width
);
386 height
= tvb_get_letohs(tvb
, *offset
) & 0x3FFF;
387 vertical_scale
= tvb_get_letohs(tvb
, *offset
)>>14;
388 proto_tree_add_uint(vp8_keyframe_tree
, hf_vp8_keyframe_vertical_scale
, tvb
, *offset
, 2, vertical_scale
);
389 proto_tree_add_uint(vp8_keyframe_tree
, hf_vp8_keyframe_height
, tvb
, *offset
, 2, height
);
394 remainder
= tvb_reported_length_remaining(tvb
, (*offset
));
395 if ((*partition1_size
) == -1)
397 /*no header, continuation?*/
398 proto_tree_add_expert_format(vp8_payload_tree
, pinfo
, &ei_vp8_continuation
, tvb
, *offset
, -1, "Continuation of partition fragment (%d bytes)", remainder
);
402 if (remainder
< *partition1_size
)
404 /* partition size has already been added to vp8 header tree, but it would be useful to provide additional explanation */
405 proto_tree_add_expert_format(vp8_payload_tree
, pinfo
, &ei_vp8_first_partition_split
, tvb
, *offset
, -1,
406 "First partition is split with %d bytes in this packet and %d bytes in subsequent frames", remainder
, ((*partition1_size
)-remainder
));
410 (*offset
)= (*offset
) + (*partition1_size
);
411 proto_tree_add_expert_format(vp8_payload_tree
, pinfo
, &ei_vp8_first_partition_plus
, tvb
, *offset
, -1,
412 "This frame contains all of first partition (%d bytes) and also %d bytes from other partitions",
413 *partition1_size
, remainder
);
416 expert_add_info(pinfo
, payload_item
, &ei_vp8_undecoded
);
420 proto_register_vp8(void)
422 module_t
*vp8_module
;
423 expert_module_t
* expert_vp8
;
425 static hf_register_info hf
[] = {
427 { "X bit", "vp8.pld.x",
428 FT_BOOLEAN
, 8, TFS(&vp8_x_bit_vals
), BIT_1_MASK
,
432 { "R bit", "vp8.pld.r",
433 FT_BOOLEAN
, 8, TFS(&vp8_r_bit_vals
), BIT_2_MASK
,
437 { "N bit", "vp8.pld.n",
438 FT_BOOLEAN
, 8, TFS(&vp8_n_bit_vals
), BIT_3_MASK
,
442 { "S bit", "vp8.pld.s",
443 FT_BOOLEAN
, 8, TFS(&vp8_s_bit_vals
), BIT_4_MASK
,
446 { &hf_vp8_pld_part_id
,
447 { "2nd R bit and Part Id", "vp8.pld.partid",
448 FT_UINT8
, BASE_DEC
, NULL
, BIT_5678_MASK
,
452 { "I bit", "vp8.pld.i",
453 FT_BOOLEAN
, 8, TFS(&vp8_i_bit_vals
), BIT_1_MASK
,
457 { "L bit", "vp8.pld.l",
458 FT_BOOLEAN
, 8, TFS(&vp8_l_bit_vals
), BIT_2_MASK
,
462 { "T bit", "vp8.pld.t",
463 FT_BOOLEAN
, 8, TFS(&vp8_t_bit_vals
), BIT_3_MASK
,
467 { "K bit", "vp8.pld.k",
468 FT_BOOLEAN
, 8, TFS(&vp8_k_bit_vals
), BIT_4_MASK
,
472 { "Reserved A", "vp8.pld.rsva",
473 FT_UINT8
, BASE_DEC
, NULL
, BIT_5678_MASK
,
476 { &hf_vp8_pld_picture_id
,
477 { "Picture ID", "vp8.pld.pictureid",
478 FT_UINT8
, BASE_DEC
, NULL
, BIT_NO_MASK
,
481 { &hf_vp8_pld_extended_picture_id
,
482 { "Extended Picture ID", "vp8.pld.pictureid",
483 FT_UINT16
, BASE_DEC
, NULL
, BIT_EXT_PICTURE_MASK
,
486 { &hf_vp8_pld_tl0picidx
,
487 { "Temporal layer zero Picture Index (TL0PICIDX)", "vp8.pld.tl0picidx",
488 FT_UINT8
, BASE_DEC
, NULL
, BIT_NO_MASK
,
492 { "Temporal layer Index (TID)", "vp8.pld.tid",
493 FT_UINT8
, BASE_DEC
, NULL
, BIT_12_MASK
,
497 { "1 layer sync bit (Y)", "vp8.pld.y",
498 FT_BOOLEAN
, 8, NULL
, BIT_3_MASK
,
501 { &hf_vp8_pld_keyidx
,
502 { "Temporal Key Frame Index (KEYIDX)", "vp8.pld.keyidx",
503 FT_UINT8
, BASE_DEC
, NULL
, BIT_45678_MASK
,
506 { &hf_vp8_hdr_frametype
,
507 { "frametype", "vp8.hdr.frametype",
508 FT_BOOLEAN
, 8, TFS(&vp8_hdr_frametype_vals
), BIT_8_MASK
,
511 { &hf_vp8_hdr_version
,
512 { "version", "vp8.hdr.version",
513 FT_UINT8
, BASE_DEC
| BASE_RANGE_STRING
, RVALS(vp8_hdr_version_vals
), BIT_567_MASK
,
516 { &hf_vp8_hdr_show_bit
,
517 { "Show bit", "vp8.hdr.show",
518 FT_BOOLEAN
, 8, NULL
, BIT_4_MASK
,
519 "Set when current frame is for display", HFILL
}
521 { &hf_vp8_hdr_first_partition_size
,
522 { "First partition size", "vp8.hdr.partition_size",
523 FT_UINT24
, BASE_DEC
, NULL
, BIT_PARTITION_SIZE_MASK
,
526 { &hf_vp8_keyframe_start_code
,
527 { "VP8 Start code", "vp8.keyframe.start_code",
528 FT_UINT24
, BASE_HEX
, NULL
, BIT_3BYTE_NO_MASK
,
531 { &hf_vp8_keyframe_width
,
532 { "Width", "vp8.keyframe.width",
533 FT_UINT16
, BASE_DEC
, NULL
, BIT_2BYTE_NO_MASK
,
536 { &hf_vp8_keyframe_height
,
537 { "Height", "vp8.keyframe.height",
538 FT_UINT16
, BASE_DEC
, NULL
, BIT_2BYTE_NO_MASK
,
541 { &hf_vp8_keyframe_horizontal_scale
,
542 { "Horizontal Scale", "vp8.keyframe.horizontal_scale",
543 FT_UINT8
, BASE_DEC
, NULL
, BIT_12_MASK
,
546 { &hf_vp8_keyframe_vertical_scale
,
547 { "Vertical Scale", "vp8.keyframe.vertical_scale",
548 FT_UINT8
, BASE_DEC
, NULL
, BIT_12_MASK
,
554 static ei_register_info ei
[] = {
555 { &ei_vp8_startcode
, { "vp8.keyframe.startcode", PI_PROTOCOL
, PI_ERROR
, "Startcode is incorrect", EXPFILL
}},
556 { &ei_vp8_undecoded
, { "vp8.undecoded", PI_UNDECODED
, PI_NOTE
, "Payload not fully decoded", EXPFILL
}},
557 { &ei_vp8_continuation
, { "vp8.continuation", PI_REASSEMBLE
, PI_CHAT
, "Continuation of partition fragment", EXPFILL
}},
558 { &ei_vp8_first_partition_split
, { "vp8.first_partition_split", PI_REASSEMBLE
, PI_CHAT
, "First partition is split", EXPFILL
}},
559 { &ei_vp8_first_partition_plus
, { "vp8.first_partition_plus", PI_REASSEMBLE
, PI_CHAT
, "This frame contains all of first partition and also bytes from other partitions", EXPFILL
}},
562 proto_vp8
= proto_register_protocol (
564 "VP8", /* short name */
568 proto_register_field_array(proto_vp8
, hf
, array_length(hf
));
569 proto_register_subtree_array(ett
, array_length(ett
));
571 vp8_module
= prefs_register_protocol(proto_vp8
, NULL
);
573 expert_vp8
= expert_register_protocol(proto_vp8
);
574 expert_register_field_array(expert_vp8
, ei
, array_length(ei
));
576 prefs_register_obsolete_preference(vp8_module
, "dynamic.payload.type");
578 vp8_handle
= register_dissector("vp8", dissect_vp8
, proto_vp8
);
582 proto_reg_handoff_vp8(void)
584 dissector_add_string("rtp_dyn_payload_type" , "VP8", vp8_handle
);
586 dissector_add_uint_range_with_preference("rtp.pt", "", vp8_handle
);
590 * Editor modelines - https://www.wireshark.org/tools/modelines.html
595 * indent-tabs-mode: nil
598 * vi: set shiftwidth=4 tabstop=8 expandtab:
599 * :indentSize=4:tabSize=8:noTabs=true: