Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: webrtc/video/payload_router_unittest.cc

Issue 1912653002: Remove PayloadRouter dependency from ViEEncoder (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <memory> 11 #include <memory>
12 12
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
16 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" 16 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
17 #include "webrtc/modules/video_coding/include/video_codec_interface.h" 17 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
18 #include "webrtc/video/payload_router.h" 18 #include "webrtc/video/payload_router.h"
19 19
20 using ::testing::_; 20 using ::testing::_;
21 using ::testing::AnyNumber; 21 using ::testing::AnyNumber;
22 using ::testing::NiceMock; 22 using ::testing::NiceMock;
23 using ::testing::Return; 23 using ::testing::Return;
24 24
25 namespace webrtc { 25 namespace webrtc {
26 26
27 TEST(PayloadRouterTest, SendOnOneModule) { 27 TEST(PayloadRouterTest, SendOnOneModule) {
28 MockRtpRtcp rtp; 28 MockRtpRtcp rtp;
29 std::vector<RtpRtcp*> modules(1, &rtp); 29 std::vector<RtpRtcp*> modules(1, &rtp);
30 VideoCodec codec;
31 codec.numberOfSimulcastStreams = 1;
30 32
31 uint8_t payload = 'a'; 33 uint8_t payload = 'a';
32 int8_t payload_type = 96; 34 int8_t payload_type = 96;
33 EncodedImage encoded_image; 35 EncodedImage encoded_image;
34 encoded_image._timeStamp = 1; 36 encoded_image._timeStamp = 1;
35 encoded_image.capture_time_ms_ = 2; 37 encoded_image.capture_time_ms_ = 2;
36 encoded_image._frameType = kVideoFrameKey; 38 encoded_image._frameType = kVideoFrameKey;
37 encoded_image._buffer = &payload; 39 encoded_image._buffer = &payload;
38 encoded_image._length = 1; 40 encoded_image._length = 1;
39 41
40 PayloadRouter payload_router(modules, payload_type); 42 PayloadRouter payload_router(modules, payload_type);
41 payload_router.SetSendingRtpModules(modules.size()); 43 payload_router.SetSendCodec(codec);
42 44
43 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type, 45 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
44 encoded_image._timeStamp, 46 encoded_image._timeStamp,
45 encoded_image.capture_time_ms_, &payload, 47 encoded_image.capture_time_ms_, &payload,
46 encoded_image._length, nullptr, _)) 48 encoded_image._length, nullptr, _))
47 .Times(0); 49 .Times(0);
48 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, nullptr, nullptr)); 50 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, nullptr, nullptr));
49 51
50 payload_router.set_active(true); 52 payload_router.set_active(true);
51 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type, 53 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
(...skipping 12 matching lines...) Expand all
64 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, nullptr, nullptr)); 66 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, nullptr, nullptr));
65 67
66 payload_router.set_active(true); 68 payload_router.set_active(true);
67 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type, 69 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
68 encoded_image._timeStamp, 70 encoded_image._timeStamp,
69 encoded_image.capture_time_ms_, &payload, 71 encoded_image.capture_time_ms_, &payload,
70 encoded_image._length, nullptr, _)) 72 encoded_image._length, nullptr, _))
71 .Times(1); 73 .Times(1);
72 EXPECT_EQ(0, payload_router.Encoded(encoded_image, nullptr, nullptr)); 74 EXPECT_EQ(0, payload_router.Encoded(encoded_image, nullptr, nullptr));
73 75
74 payload_router.SetSendingRtpModules(0); 76 codec.numberOfSimulcastStreams = 0;
77 payload_router.SetSendCodec(codec);
75 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type, 78 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
76 encoded_image._timeStamp, 79 encoded_image._timeStamp,
77 encoded_image.capture_time_ms_, &payload, 80 encoded_image.capture_time_ms_, &payload,
78 encoded_image._length, nullptr, _)) 81 encoded_image._length, nullptr, _))
79 .Times(0); 82 .Times(0);
80 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, nullptr, nullptr)); 83 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, nullptr, nullptr));
81 } 84 }
82 85
83 TEST(PayloadRouterTest, SendSimulcast) { 86 TEST(PayloadRouterTest, SendSimulcast) {
84 MockRtpRtcp rtp_1; 87 MockRtpRtcp rtp_1;
85 MockRtpRtcp rtp_2; 88 MockRtpRtcp rtp_2;
86 std::vector<RtpRtcp*> modules; 89 std::vector<RtpRtcp*> modules;
87 modules.push_back(&rtp_1); 90 modules.push_back(&rtp_1);
88 modules.push_back(&rtp_2); 91 modules.push_back(&rtp_2);
92 VideoCodec codec;
93 codec.numberOfSimulcastStreams = 2;
89 94
90 int8_t payload_type = 96; 95 int8_t payload_type = 96;
91 uint8_t payload = 'a'; 96 uint8_t payload = 'a';
92 EncodedImage encoded_image; 97 EncodedImage encoded_image;
93 encoded_image._timeStamp = 1; 98 encoded_image._timeStamp = 1;
94 encoded_image.capture_time_ms_ = 2; 99 encoded_image.capture_time_ms_ = 2;
95 encoded_image._frameType = kVideoFrameKey; 100 encoded_image._frameType = kVideoFrameKey;
96 encoded_image._buffer = &payload; 101 encoded_image._buffer = &payload;
97 encoded_image._length = 1; 102 encoded_image._length = 1;
98 103
99 PayloadRouter payload_router(modules, payload_type); 104 PayloadRouter payload_router(modules, payload_type);
100 payload_router.SetSendingRtpModules(modules.size()); 105 payload_router.SetSendCodec(codec);
101 106
102 CodecSpecificInfo codec_info_1; 107 CodecSpecificInfo codec_info_1;
103 memset(&codec_info_1, 0, sizeof(CodecSpecificInfo)); 108 memset(&codec_info_1, 0, sizeof(CodecSpecificInfo));
104 codec_info_1.codecType = kVideoCodecVP8; 109 codec_info_1.codecType = kVideoCodecVP8;
105 codec_info_1.codecSpecific.VP8.simulcastIdx = 0; 110 codec_info_1.codecSpecific.VP8.simulcastIdx = 0;
106 111
107 payload_router.set_active(true); 112 payload_router.set_active(true);
108 EXPECT_CALL(rtp_1, SendOutgoingData(encoded_image._frameType, payload_type, 113 EXPECT_CALL(rtp_1, SendOutgoingData(encoded_image._frameType, payload_type,
109 encoded_image._timeStamp, 114 encoded_image._timeStamp,
110 encoded_image.capture_time_ms_, &payload, 115 encoded_image.capture_time_ms_, &payload,
(...skipping 20 matching lines...) Expand all
131 // Inactive. 136 // Inactive.
132 payload_router.set_active(false); 137 payload_router.set_active(false);
133 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _)) 138 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _))
134 .Times(0); 139 .Times(0);
135 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _)) 140 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _))
136 .Times(0); 141 .Times(0);
137 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, &codec_info_1, nullptr)); 142 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, &codec_info_1, nullptr));
138 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, &codec_info_2, nullptr)); 143 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, &codec_info_2, nullptr));
139 144
140 // Invalid simulcast index. 145 // Invalid simulcast index.
141 payload_router.SetSendingRtpModules(1); 146 codec.numberOfSimulcastStreams = 1;
147 payload_router.SetSendCodec(codec);
142 payload_router.set_active(true); 148 payload_router.set_active(true);
143 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _)) 149 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _))
144 .Times(0); 150 .Times(0);
145 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _)) 151 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _))
146 .Times(0); 152 .Times(0);
147 codec_info_2.codecSpecific.VP8.simulcastIdx = 1; 153 codec_info_2.codecSpecific.VP8.simulcastIdx = 1;
148 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, &codec_info_2, nullptr)); 154 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, &codec_info_2, nullptr));
149 } 155 }
150 156
151 TEST(PayloadRouterTest, MaxPayloadLength) { 157 TEST(PayloadRouterTest, MaxPayloadLength) {
152 // Without any limitations from the modules, verify we get the max payload 158 // Without any limitations from the modules, verify we get the max payload
153 // length for IP/UDP/SRTP with a MTU of 150 bytes. 159 // length for IP/UDP/SRTP with a MTU of 150 bytes.
154 const size_t kDefaultMaxLength = 1500 - 20 - 8 - 12 - 4; 160 const size_t kDefaultMaxLength = 1500 - 20 - 8 - 12 - 4;
155 MockRtpRtcp rtp_1; 161 MockRtpRtcp rtp_1;
156 MockRtpRtcp rtp_2; 162 MockRtpRtcp rtp_2;
157 std::vector<RtpRtcp*> modules; 163 std::vector<RtpRtcp*> modules;
158 modules.push_back(&rtp_1); 164 modules.push_back(&rtp_1);
159 modules.push_back(&rtp_2); 165 modules.push_back(&rtp_2);
160 PayloadRouter payload_router(modules, 42); 166 PayloadRouter payload_router(modules, 42);
161 167
162 EXPECT_EQ(kDefaultMaxLength, PayloadRouter::DefaultMaxPayloadLength()); 168 EXPECT_EQ(kDefaultMaxLength, PayloadRouter::DefaultMaxPayloadLength());
163 payload_router.SetSendingRtpModules(modules.size()); 169 VideoCodec codec;
170 codec.numberOfSimulcastStreams = 2;
171 payload_router.SetSendCodec(codec);
164 172
165 // Modules return a higher length than the default value. 173 // Modules return a higher length than the default value.
166 EXPECT_CALL(rtp_1, MaxDataPayloadLength()) 174 EXPECT_CALL(rtp_1, MaxDataPayloadLength())
167 .Times(1) 175 .Times(1)
168 .WillOnce(Return(kDefaultMaxLength + 10)); 176 .WillOnce(Return(kDefaultMaxLength + 10));
169 EXPECT_CALL(rtp_2, MaxDataPayloadLength()) 177 EXPECT_CALL(rtp_2, MaxDataPayloadLength())
170 .Times(1) 178 .Times(1)
171 .WillOnce(Return(kDefaultMaxLength + 10)); 179 .WillOnce(Return(kDefaultMaxLength + 10));
172 EXPECT_EQ(kDefaultMaxLength, payload_router.MaxPayloadLength()); 180 EXPECT_EQ(kDefaultMaxLength, payload_router.MaxPayloadLength());
173 181
174 // The modules return a value lower than default. 182 // The modules return a value lower than default.
175 const size_t kTestMinPayloadLength = 1001; 183 const size_t kTestMinPayloadLength = 1001;
176 EXPECT_CALL(rtp_1, MaxDataPayloadLength()) 184 EXPECT_CALL(rtp_1, MaxDataPayloadLength())
177 .Times(1) 185 .Times(1)
178 .WillOnce(Return(kTestMinPayloadLength + 10)); 186 .WillOnce(Return(kTestMinPayloadLength + 10));
179 EXPECT_CALL(rtp_2, MaxDataPayloadLength()) 187 EXPECT_CALL(rtp_2, MaxDataPayloadLength())
180 .Times(1) 188 .Times(1)
181 .WillOnce(Return(kTestMinPayloadLength)); 189 .WillOnce(Return(kTestMinPayloadLength));
182 EXPECT_EQ(kTestMinPayloadLength, payload_router.MaxPayloadLength()); 190 EXPECT_EQ(kTestMinPayloadLength, payload_router.MaxPayloadLength());
183 } 191 }
184 192
185 TEST(PayloadRouterTest, SetTargetSendBitrates) { 193 TEST(PayloadRouterTest, SetTargetSendBitrates) {
186 MockRtpRtcp rtp_1; 194 MockRtpRtcp rtp_1;
187 MockRtpRtcp rtp_2; 195 MockRtpRtcp rtp_2;
188 std::vector<RtpRtcp*> modules; 196 std::vector<RtpRtcp*> modules;
189 modules.push_back(&rtp_1); 197 modules.push_back(&rtp_1);
190 modules.push_back(&rtp_2); 198 modules.push_back(&rtp_2);
191 PayloadRouter payload_router(modules, 42); 199 PayloadRouter payload_router(modules, 42);
192 payload_router.SetSendingRtpModules(modules.size()); 200 VideoCodec codec;
201 codec.numberOfSimulcastStreams = 2;
202 codec.simulcastStream[0].maxBitrate = 10;
203 codec.simulcastStream[1].maxBitrate = 100;
204 payload_router.SetSendCodec(codec);
193 205
194 const uint32_t bitrate_1 = 10000; 206 const uint32_t bitrate_1 = 10000;
195 const uint32_t bitrate_2 = 76543; 207 const uint32_t bitrate_2 = 76543;
196 std::vector<uint32_t> bitrates(2, bitrate_1);
197 bitrates[1] = bitrate_2;
198 EXPECT_CALL(rtp_1, SetTargetSendBitrate(bitrate_1)) 208 EXPECT_CALL(rtp_1, SetTargetSendBitrate(bitrate_1))
199 .Times(1); 209 .Times(1);
200 EXPECT_CALL(rtp_2, SetTargetSendBitrate(bitrate_2)) 210 EXPECT_CALL(rtp_2, SetTargetSendBitrate(bitrate_2))
201 .Times(1); 211 .Times(1);
202 payload_router.SetTargetSendBitrates(bitrates); 212 payload_router.SetTargetSendBitrate(bitrate_1 + bitrate_2);
203
204 bitrates.resize(1);
205 EXPECT_CALL(rtp_1, SetTargetSendBitrate(bitrate_1))
206 .Times(1);
207 EXPECT_CALL(rtp_2, SetTargetSendBitrate(bitrate_2))
208 .Times(0);
209 payload_router.SetTargetSendBitrates(bitrates);
210 } 213 }
211 } // namespace webrtc 214 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698