1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "modules/rtp_rtcp/source/rtp_format_vp8.h"
12
13 #include <memory>
14
15 #include "modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h"
16 #include "test/gmock.h"
17 #include "test/gtest.h"
18
19 namespace webrtc {
20 namespace {
21
22 constexpr RtpPacketizer::PayloadSizeLimits kNoSizeLimits;
23
TEST(RtpPacketizerVp8Test,ResultPacketsAreAlmostEqualSize)24 TEST(RtpPacketizerVp8Test, ResultPacketsAreAlmostEqualSize) {
25 RTPVideoHeaderVP8 hdr_info;
26 hdr_info.InitRTPVideoHeaderVP8();
27 hdr_info.pictureId = 200;
28 RtpFormatVp8TestHelper helper(&hdr_info, /*payload_len=*/30);
29
30 RtpPacketizer::PayloadSizeLimits limits;
31 limits.max_payload_len = 12; // Small enough to produce 4 packets.
32 RtpPacketizerVp8 packetizer(helper.payload(), limits, hdr_info);
33
34 const size_t kExpectedSizes[] = {11, 11, 12, 12};
35 helper.GetAllPacketsAndCheck(&packetizer, kExpectedSizes);
36 }
37
TEST(RtpPacketizerVp8Test,EqualSizeWithLastPacketReduction)38 TEST(RtpPacketizerVp8Test, EqualSizeWithLastPacketReduction) {
39 RTPVideoHeaderVP8 hdr_info;
40 hdr_info.InitRTPVideoHeaderVP8();
41 hdr_info.pictureId = 200;
42 RtpFormatVp8TestHelper helper(&hdr_info, /*payload_len=*/43);
43
44 RtpPacketizer::PayloadSizeLimits limits;
45 limits.max_payload_len = 15; // Small enough to produce 5 packets.
46 limits.last_packet_reduction_len = 5;
47 RtpPacketizerVp8 packetizer(helper.payload(), limits, hdr_info);
48
49 // Calculated by hand. VP8 payload descriptors are 4 byte each. 5 packets is
50 // minimum possible to fit 43 payload bytes into packets with capacity of
51 // 15 - 4 = 11 and leave 5 free bytes in the last packet. All packets are
52 // almost equal in size, even last packet if counted with free space (which
53 // will be filled up the stack by extra long RTP header).
54 const size_t kExpectedSizes[] = {13, 13, 14, 14, 9};
55 helper.GetAllPacketsAndCheck(&packetizer, kExpectedSizes);
56 }
57
58 // Verify that non-reference bit is set.
TEST(RtpPacketizerVp8Test,NonReferenceBit)59 TEST(RtpPacketizerVp8Test, NonReferenceBit) {
60 RTPVideoHeaderVP8 hdr_info;
61 hdr_info.InitRTPVideoHeaderVP8();
62 hdr_info.nonReference = true;
63 RtpFormatVp8TestHelper helper(&hdr_info, /*payload_len=*/30);
64
65 RtpPacketizer::PayloadSizeLimits limits;
66 limits.max_payload_len = 25; // Small enough to produce two packets.
67 RtpPacketizerVp8 packetizer(helper.payload(), limits, hdr_info);
68
69 const size_t kExpectedSizes[] = {16, 16};
70 helper.GetAllPacketsAndCheck(&packetizer, kExpectedSizes);
71 }
72
73 // Verify Tl0PicIdx and TID fields, and layerSync bit.
TEST(RtpPacketizerVp8Test,Tl0PicIdxAndTID)74 TEST(RtpPacketizerVp8Test, Tl0PicIdxAndTID) {
75 RTPVideoHeaderVP8 hdr_info;
76 hdr_info.InitRTPVideoHeaderVP8();
77 hdr_info.tl0PicIdx = 117;
78 hdr_info.temporalIdx = 2;
79 hdr_info.layerSync = true;
80 RtpFormatVp8TestHelper helper(&hdr_info, /*payload_len=*/30);
81
82 RtpPacketizerVp8 packetizer(helper.payload(), kNoSizeLimits, hdr_info);
83
84 const size_t kExpectedSizes[1] = {helper.payload_size() + 4};
85 helper.GetAllPacketsAndCheck(&packetizer, kExpectedSizes);
86 }
87
TEST(RtpPacketizerVp8Test,KeyIdx)88 TEST(RtpPacketizerVp8Test, KeyIdx) {
89 RTPVideoHeaderVP8 hdr_info;
90 hdr_info.InitRTPVideoHeaderVP8();
91 hdr_info.keyIdx = 17;
92 RtpFormatVp8TestHelper helper(&hdr_info, /*payload_len=*/30);
93
94 RtpPacketizerVp8 packetizer(helper.payload(), kNoSizeLimits, hdr_info);
95
96 const size_t kExpectedSizes[1] = {helper.payload_size() + 3};
97 helper.GetAllPacketsAndCheck(&packetizer, kExpectedSizes);
98 }
99
100 // Verify TID field and KeyIdx field in combination.
TEST(RtpPacketizerVp8Test,TIDAndKeyIdx)101 TEST(RtpPacketizerVp8Test, TIDAndKeyIdx) {
102 RTPVideoHeaderVP8 hdr_info;
103 hdr_info.InitRTPVideoHeaderVP8();
104 hdr_info.temporalIdx = 1;
105 hdr_info.keyIdx = 5;
106 RtpFormatVp8TestHelper helper(&hdr_info, /*payload_len=*/30);
107
108 RtpPacketizerVp8 packetizer(helper.payload(), kNoSizeLimits, hdr_info);
109
110 const size_t kExpectedSizes[1] = {helper.payload_size() + 3};
111 helper.GetAllPacketsAndCheck(&packetizer, kExpectedSizes);
112 }
113
114 } // namespace
115 } // namespace webrtc
116