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

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: Addressed comments. Created 4 years, 7 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
« no previous file with comments | « webrtc/video/payload_router.cc ('k') | webrtc/video/video_send_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 NiceMock<MockRtpRtcp> rtp;
29 std::vector<RtpRtcp*> modules(1, &rtp); 29 std::vector<RtpRtcp*> modules(1, &rtp);
30 std::vector<VideoStream> streams(1);
30 31
31 uint8_t payload = 'a'; 32 uint8_t payload = 'a';
32 int8_t payload_type = 96; 33 int8_t payload_type = 96;
33 EncodedImage encoded_image; 34 EncodedImage encoded_image;
34 encoded_image._timeStamp = 1; 35 encoded_image._timeStamp = 1;
35 encoded_image.capture_time_ms_ = 2; 36 encoded_image.capture_time_ms_ = 2;
36 encoded_image._frameType = kVideoFrameKey; 37 encoded_image._frameType = kVideoFrameKey;
37 encoded_image._buffer = &payload; 38 encoded_image._buffer = &payload;
38 encoded_image._length = 1; 39 encoded_image._length = 1;
39 40
40 PayloadRouter payload_router(modules, payload_type); 41 PayloadRouter payload_router(modules, payload_type);
41 payload_router.SetSendingRtpModules(modules.size()); 42 payload_router.SetSendStreams(streams);
42 43
43 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type, 44 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
44 encoded_image._timeStamp, 45 encoded_image._timeStamp,
45 encoded_image.capture_time_ms_, &payload, 46 encoded_image.capture_time_ms_, &payload,
46 encoded_image._length, nullptr, _)) 47 encoded_image._length, nullptr, _))
47 .Times(0); 48 .Times(0);
48 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, nullptr, nullptr)); 49 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, nullptr, nullptr));
49 50
50 payload_router.set_active(true); 51 payload_router.set_active(true);
51 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type, 52 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)); 65 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, nullptr, nullptr));
65 66
66 payload_router.set_active(true); 67 payload_router.set_active(true);
67 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type, 68 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
68 encoded_image._timeStamp, 69 encoded_image._timeStamp,
69 encoded_image.capture_time_ms_, &payload, 70 encoded_image.capture_time_ms_, &payload,
70 encoded_image._length, nullptr, _)) 71 encoded_image._length, nullptr, _))
71 .Times(1); 72 .Times(1);
72 EXPECT_EQ(0, payload_router.Encoded(encoded_image, nullptr, nullptr)); 73 EXPECT_EQ(0, payload_router.Encoded(encoded_image, nullptr, nullptr));
73 74
74 payload_router.SetSendingRtpModules(0); 75 streams.clear();
76 payload_router.SetSendStreams(streams);
75 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type, 77 EXPECT_CALL(rtp, SendOutgoingData(encoded_image._frameType, payload_type,
76 encoded_image._timeStamp, 78 encoded_image._timeStamp,
77 encoded_image.capture_time_ms_, &payload, 79 encoded_image.capture_time_ms_, &payload,
78 encoded_image._length, nullptr, _)) 80 encoded_image._length, nullptr, _))
79 .Times(0); 81 .Times(0);
80 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, nullptr, nullptr)); 82 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, nullptr, nullptr));
81 } 83 }
82 84
83 TEST(PayloadRouterTest, SendSimulcast) { 85 TEST(PayloadRouterTest, SendSimulcast) {
84 MockRtpRtcp rtp_1; 86 NiceMock<MockRtpRtcp> rtp_1;
85 MockRtpRtcp rtp_2; 87 NiceMock<MockRtpRtcp> rtp_2;
86 std::vector<RtpRtcp*> modules; 88 std::vector<RtpRtcp*> modules;
87 modules.push_back(&rtp_1); 89 modules.push_back(&rtp_1);
88 modules.push_back(&rtp_2); 90 modules.push_back(&rtp_2);
91 std::vector<VideoStream> streams(2);
89 92
90 int8_t payload_type = 96; 93 int8_t payload_type = 96;
91 uint8_t payload = 'a'; 94 uint8_t payload = 'a';
92 EncodedImage encoded_image; 95 EncodedImage encoded_image;
93 encoded_image._timeStamp = 1; 96 encoded_image._timeStamp = 1;
94 encoded_image.capture_time_ms_ = 2; 97 encoded_image.capture_time_ms_ = 2;
95 encoded_image._frameType = kVideoFrameKey; 98 encoded_image._frameType = kVideoFrameKey;
96 encoded_image._buffer = &payload; 99 encoded_image._buffer = &payload;
97 encoded_image._length = 1; 100 encoded_image._length = 1;
98 101
99 PayloadRouter payload_router(modules, payload_type); 102 PayloadRouter payload_router(modules, payload_type);
100 payload_router.SetSendingRtpModules(modules.size()); 103 payload_router.SetSendStreams(streams);
101 104
102 CodecSpecificInfo codec_info_1; 105 CodecSpecificInfo codec_info_1;
103 memset(&codec_info_1, 0, sizeof(CodecSpecificInfo)); 106 memset(&codec_info_1, 0, sizeof(CodecSpecificInfo));
104 codec_info_1.codecType = kVideoCodecVP8; 107 codec_info_1.codecType = kVideoCodecVP8;
105 codec_info_1.codecSpecific.VP8.simulcastIdx = 0; 108 codec_info_1.codecSpecific.VP8.simulcastIdx = 0;
106 109
107 payload_router.set_active(true); 110 payload_router.set_active(true);
108 EXPECT_CALL(rtp_1, SendOutgoingData(encoded_image._frameType, payload_type, 111 EXPECT_CALL(rtp_1, SendOutgoingData(encoded_image._frameType, payload_type,
109 encoded_image._timeStamp, 112 encoded_image._timeStamp,
110 encoded_image.capture_time_ms_, &payload, 113 encoded_image.capture_time_ms_, &payload,
(...skipping 20 matching lines...) Expand all
131 // Inactive. 134 // Inactive.
132 payload_router.set_active(false); 135 payload_router.set_active(false);
133 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _)) 136 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _))
134 .Times(0); 137 .Times(0);
135 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _)) 138 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _))
136 .Times(0); 139 .Times(0);
137 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, &codec_info_1, nullptr)); 140 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)); 141 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, &codec_info_2, nullptr));
139 142
140 // Invalid simulcast index. 143 // Invalid simulcast index.
141 payload_router.SetSendingRtpModules(1); 144 streams.pop_back(); // Remove a stream.
145 payload_router.SetSendStreams(streams);
142 payload_router.set_active(true); 146 payload_router.set_active(true);
143 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _)) 147 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _))
144 .Times(0); 148 .Times(0);
145 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _)) 149 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _))
146 .Times(0); 150 .Times(0);
147 codec_info_2.codecSpecific.VP8.simulcastIdx = 1; 151 codec_info_2.codecSpecific.VP8.simulcastIdx = 1;
148 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, &codec_info_2, nullptr)); 152 EXPECT_EQ(-1, payload_router.Encoded(encoded_image, &codec_info_2, nullptr));
149 } 153 }
150 154
151 TEST(PayloadRouterTest, MaxPayloadLength) { 155 TEST(PayloadRouterTest, MaxPayloadLength) {
152 // Without any limitations from the modules, verify we get the max payload 156 // Without any limitations from the modules, verify we get the max payload
153 // length for IP/UDP/SRTP with a MTU of 150 bytes. 157 // length for IP/UDP/SRTP with a MTU of 150 bytes.
154 const size_t kDefaultMaxLength = 1500 - 20 - 8 - 12 - 4; 158 const size_t kDefaultMaxLength = 1500 - 20 - 8 - 12 - 4;
155 MockRtpRtcp rtp_1; 159 NiceMock<MockRtpRtcp> rtp_1;
156 MockRtpRtcp rtp_2; 160 NiceMock<MockRtpRtcp> rtp_2;
157 std::vector<RtpRtcp*> modules; 161 std::vector<RtpRtcp*> modules;
158 modules.push_back(&rtp_1); 162 modules.push_back(&rtp_1);
159 modules.push_back(&rtp_2); 163 modules.push_back(&rtp_2);
160 PayloadRouter payload_router(modules, 42); 164 PayloadRouter payload_router(modules, 42);
161 165
162 EXPECT_EQ(kDefaultMaxLength, PayloadRouter::DefaultMaxPayloadLength()); 166 EXPECT_EQ(kDefaultMaxLength, PayloadRouter::DefaultMaxPayloadLength());
163 payload_router.SetSendingRtpModules(modules.size()); 167 std::vector<VideoStream> streams(2);
168 payload_router.SetSendStreams(streams);
164 169
165 // Modules return a higher length than the default value. 170 // Modules return a higher length than the default value.
166 EXPECT_CALL(rtp_1, MaxDataPayloadLength()) 171 EXPECT_CALL(rtp_1, MaxDataPayloadLength())
167 .Times(1) 172 .Times(1)
168 .WillOnce(Return(kDefaultMaxLength + 10)); 173 .WillOnce(Return(kDefaultMaxLength + 10));
169 EXPECT_CALL(rtp_2, MaxDataPayloadLength()) 174 EXPECT_CALL(rtp_2, MaxDataPayloadLength())
170 .Times(1) 175 .Times(1)
171 .WillOnce(Return(kDefaultMaxLength + 10)); 176 .WillOnce(Return(kDefaultMaxLength + 10));
172 EXPECT_EQ(kDefaultMaxLength, payload_router.MaxPayloadLength()); 177 EXPECT_EQ(kDefaultMaxLength, payload_router.MaxPayloadLength());
173 178
174 // The modules return a value lower than default. 179 // The modules return a value lower than default.
175 const size_t kTestMinPayloadLength = 1001; 180 const size_t kTestMinPayloadLength = 1001;
176 EXPECT_CALL(rtp_1, MaxDataPayloadLength()) 181 EXPECT_CALL(rtp_1, MaxDataPayloadLength())
177 .Times(1) 182 .Times(1)
178 .WillOnce(Return(kTestMinPayloadLength + 10)); 183 .WillOnce(Return(kTestMinPayloadLength + 10));
179 EXPECT_CALL(rtp_2, MaxDataPayloadLength()) 184 EXPECT_CALL(rtp_2, MaxDataPayloadLength())
180 .Times(1) 185 .Times(1)
181 .WillOnce(Return(kTestMinPayloadLength)); 186 .WillOnce(Return(kTestMinPayloadLength));
182 EXPECT_EQ(kTestMinPayloadLength, payload_router.MaxPayloadLength()); 187 EXPECT_EQ(kTestMinPayloadLength, payload_router.MaxPayloadLength());
183 } 188 }
184 189
185 TEST(PayloadRouterTest, SetTargetSendBitrates) { 190 TEST(PayloadRouterTest, SetTargetSendBitrates) {
186 MockRtpRtcp rtp_1; 191 NiceMock<MockRtpRtcp> rtp_1;
187 MockRtpRtcp rtp_2; 192 NiceMock<MockRtpRtcp> rtp_2;
188 std::vector<RtpRtcp*> modules; 193 std::vector<RtpRtcp*> modules;
189 modules.push_back(&rtp_1); 194 modules.push_back(&rtp_1);
190 modules.push_back(&rtp_2); 195 modules.push_back(&rtp_2);
191 PayloadRouter payload_router(modules, 42); 196 PayloadRouter payload_router(modules, 42);
192 payload_router.SetSendingRtpModules(modules.size()); 197 std::vector<VideoStream> streams(2);
198 streams[0].max_bitrate_bps = 10000;
199 streams[1].max_bitrate_bps = 100000;
200 payload_router.SetSendStreams(streams);
193 201
194 const uint32_t bitrate_1 = 10000; 202 const uint32_t bitrate_1 = 10000;
195 const uint32_t bitrate_2 = 76543; 203 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)) 204 EXPECT_CALL(rtp_1, SetTargetSendBitrate(bitrate_1))
199 .Times(1); 205 .Times(1);
200 EXPECT_CALL(rtp_2, SetTargetSendBitrate(bitrate_2)) 206 EXPECT_CALL(rtp_2, SetTargetSendBitrate(bitrate_2))
201 .Times(1); 207 .Times(1);
202 payload_router.SetTargetSendBitrates(bitrates); 208 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 } 209 }
211 } // namespace webrtc 210 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/payload_router.cc ('k') | webrtc/video/video_send_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698