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

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

Issue 1864313003: Move Ownership of RtpModules to VideoSendStream. (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
« no previous file with comments | « webrtc/video/payload_router.cc ('k') | webrtc/video/video_receive_stream.cc » ('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/video/payload_router.h" 17 #include "webrtc/video/payload_router.h"
18 18
19 using ::testing::_; 19 using ::testing::_;
20 using ::testing::AnyNumber; 20 using ::testing::AnyNumber;
21 using ::testing::NiceMock; 21 using ::testing::NiceMock;
22 using ::testing::Return; 22 using ::testing::Return;
23 23
24 namespace webrtc { 24 namespace webrtc {
25 25
26 class PayloadRouterTest : public ::testing::Test { 26 TEST(PayloadRouterTest, SendOnOneModule) {
27 protected:
28 virtual void SetUp() {
29 payload_router_.reset(new PayloadRouter());
30 }
31 std::unique_ptr<PayloadRouter> payload_router_;
32 };
33
34 TEST_F(PayloadRouterTest, SendOnOneModule) {
35 MockRtpRtcp rtp; 27 MockRtpRtcp rtp;
36 std::vector<RtpRtcp*> modules(1, &rtp); 28 std::vector<RtpRtcp*> modules(1, &rtp);
37 29
38 payload_router_->Init(modules); 30 PayloadRouter payload_router(modules);
39 payload_router_->SetSendingRtpModules(modules.size()); 31 payload_router.SetSendingRtpModules(modules.size());
40 32
41 uint8_t payload = 'a'; 33 uint8_t payload = 'a';
42 FrameType frame_type = kVideoFrameKey; 34 FrameType frame_type = kVideoFrameKey;
43 int8_t payload_type = 96; 35 int8_t payload_type = 96;
44 36
45 EXPECT_CALL(rtp, SendOutgoingData(frame_type, payload_type, 0, 0, _, 1, 37 EXPECT_CALL(rtp, SendOutgoingData(frame_type, payload_type, 0, 0, _, 1,
46 nullptr, nullptr)) 38 nullptr, nullptr))
47 .Times(0); 39 .Times(0);
48 EXPECT_FALSE(payload_router_->RoutePayload(frame_type, payload_type, 0, 0, 40 EXPECT_FALSE(payload_router.RoutePayload(frame_type, payload_type, 0, 0,
49 &payload, 1, nullptr, nullptr)); 41 &payload, 1, nullptr, nullptr));
50 42
51 payload_router_->set_active(true); 43 payload_router.set_active(true);
52 EXPECT_CALL(rtp, SendOutgoingData(frame_type, payload_type, 0, 0, _, 1, 44 EXPECT_CALL(rtp, SendOutgoingData(frame_type, payload_type, 0, 0, _, 1,
53 nullptr, nullptr)) 45 nullptr, nullptr))
54 .Times(1); 46 .Times(1);
55 EXPECT_TRUE(payload_router_->RoutePayload(frame_type, payload_type, 0, 0, 47 EXPECT_TRUE(payload_router.RoutePayload(frame_type, payload_type, 0, 0,
56 &payload, 1, nullptr, nullptr)); 48 &payload, 1, nullptr, nullptr));
57 49
58 payload_router_->set_active(false); 50 payload_router.set_active(false);
59 EXPECT_CALL(rtp, SendOutgoingData(frame_type, payload_type, 0, 0, _, 1, 51 EXPECT_CALL(rtp, SendOutgoingData(frame_type, payload_type, 0, 0, _, 1,
60 nullptr, nullptr)) 52 nullptr, nullptr))
61 .Times(0); 53 .Times(0);
62 EXPECT_FALSE(payload_router_->RoutePayload(frame_type, payload_type, 0, 0, 54 EXPECT_FALSE(payload_router.RoutePayload(frame_type, payload_type, 0, 0,
63 &payload, 1, nullptr, nullptr)); 55 &payload, 1, nullptr, nullptr));
64 56
65 payload_router_->set_active(true); 57 payload_router.set_active(true);
66 EXPECT_CALL(rtp, SendOutgoingData(frame_type, payload_type, 0, 0, _, 1, 58 EXPECT_CALL(rtp, SendOutgoingData(frame_type, payload_type, 0, 0, _, 1,
67 nullptr, nullptr)) 59 nullptr, nullptr))
68 .Times(1); 60 .Times(1);
69 EXPECT_TRUE(payload_router_->RoutePayload(frame_type, payload_type, 0, 0, 61 EXPECT_TRUE(payload_router.RoutePayload(frame_type, payload_type, 0, 0,
70 &payload, 1, nullptr, nullptr)); 62 &payload, 1, nullptr, nullptr));
71 63
72 payload_router_->SetSendingRtpModules(0); 64 payload_router.SetSendingRtpModules(0);
73 EXPECT_CALL(rtp, SendOutgoingData(frame_type, payload_type, 0, 0, _, 1, 65 EXPECT_CALL(rtp, SendOutgoingData(frame_type, payload_type, 0, 0, _, 1,
74 nullptr, nullptr)) 66 nullptr, nullptr))
75 .Times(0); 67 .Times(0);
76 EXPECT_FALSE(payload_router_->RoutePayload(frame_type, payload_type, 0, 0, 68 EXPECT_FALSE(payload_router.RoutePayload(frame_type, payload_type, 0, 0,
77 &payload, 1, nullptr, nullptr)); 69 &payload, 1, nullptr, nullptr));
78 } 70 }
79 71
80 TEST_F(PayloadRouterTest, SendSimulcast) { 72 TEST(PayloadRouterTest, SendSimulcast) {
81 MockRtpRtcp rtp_1; 73 MockRtpRtcp rtp_1;
82 MockRtpRtcp rtp_2; 74 MockRtpRtcp rtp_2;
83 std::vector<RtpRtcp*> modules; 75 std::vector<RtpRtcp*> modules;
84 modules.push_back(&rtp_1); 76 modules.push_back(&rtp_1);
85 modules.push_back(&rtp_2); 77 modules.push_back(&rtp_2);
86 78
87 payload_router_->Init(modules); 79 PayloadRouter payload_router(modules);
88 payload_router_->SetSendingRtpModules(modules.size()); 80 payload_router.SetSendingRtpModules(modules.size());
89 81
90 uint8_t payload_1 = 'a'; 82 uint8_t payload_1 = 'a';
91 FrameType frame_type_1 = kVideoFrameKey; 83 FrameType frame_type_1 = kVideoFrameKey;
92 int8_t payload_type_1 = 96; 84 int8_t payload_type_1 = 96;
93 RTPVideoHeader rtp_hdr_1; 85 RTPVideoHeader rtp_hdr_1;
94 rtp_hdr_1.simulcastIdx = 0; 86 rtp_hdr_1.simulcastIdx = 0;
95 87
96 payload_router_->set_active(true); 88 payload_router.set_active(true);
97 EXPECT_CALL(rtp_1, SendOutgoingData(frame_type_1, payload_type_1, 0, 0, _, 1, 89 EXPECT_CALL(rtp_1, SendOutgoingData(frame_type_1, payload_type_1, 0, 0, _, 1,
98 nullptr, &rtp_hdr_1)) 90 nullptr, &rtp_hdr_1))
99 .Times(1); 91 .Times(1);
100 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _)) 92 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _))
101 .Times(0); 93 .Times(0);
102 EXPECT_TRUE(payload_router_->RoutePayload( 94 EXPECT_TRUE(payload_router.RoutePayload(frame_type_1, payload_type_1, 0, 0,
103 frame_type_1, payload_type_1, 0, 0, &payload_1, 1, nullptr, &rtp_hdr_1)); 95 &payload_1, 1, nullptr, &rtp_hdr_1));
104 96
105 uint8_t payload_2 = 'b'; 97 uint8_t payload_2 = 'b';
106 FrameType frame_type_2 = kVideoFrameDelta; 98 FrameType frame_type_2 = kVideoFrameDelta;
107 int8_t payload_type_2 = 97; 99 int8_t payload_type_2 = 97;
108 RTPVideoHeader rtp_hdr_2; 100 RTPVideoHeader rtp_hdr_2;
109 rtp_hdr_2.simulcastIdx = 1; 101 rtp_hdr_2.simulcastIdx = 1;
110 EXPECT_CALL(rtp_2, SendOutgoingData(frame_type_2, payload_type_2, 0, 0, _, 1, 102 EXPECT_CALL(rtp_2, SendOutgoingData(frame_type_2, payload_type_2, 0, 0, _, 1,
111 nullptr, &rtp_hdr_2)) 103 nullptr, &rtp_hdr_2))
112 .Times(1); 104 .Times(1);
113 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _)) 105 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _))
114 .Times(0); 106 .Times(0);
115 EXPECT_TRUE(payload_router_->RoutePayload( 107 EXPECT_TRUE(payload_router.RoutePayload(frame_type_2, payload_type_2, 0, 0,
116 frame_type_2, payload_type_2, 0, 0, &payload_2, 1, nullptr, &rtp_hdr_2)); 108 &payload_2, 1, nullptr, &rtp_hdr_2));
117 109
118 // Inactive. 110 // Inactive.
119 payload_router_->set_active(false); 111 payload_router.set_active(false);
120 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _)) 112 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _))
121 .Times(0); 113 .Times(0);
122 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _)) 114 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _))
123 .Times(0); 115 .Times(0);
124 EXPECT_FALSE(payload_router_->RoutePayload( 116 EXPECT_FALSE(payload_router.RoutePayload(frame_type_1, payload_type_1, 0, 0,
125 frame_type_1, payload_type_1, 0, 0, &payload_1, 1, nullptr, &rtp_hdr_1)); 117 &payload_1, 1, nullptr, &rtp_hdr_1));
126 EXPECT_FALSE(payload_router_->RoutePayload( 118 EXPECT_FALSE(payload_router.RoutePayload(frame_type_2, payload_type_2, 0, 0,
127 frame_type_2, payload_type_2, 0, 0, &payload_2, 1, nullptr, &rtp_hdr_2)); 119 &payload_2, 1, nullptr, &rtp_hdr_2));
128 120
129 // Invalid simulcast index. 121 // Invalid simulcast index.
130 payload_router_->SetSendingRtpModules(1); 122 payload_router.SetSendingRtpModules(1);
131 payload_router_->set_active(true); 123 payload_router.set_active(true);
132 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _)) 124 EXPECT_CALL(rtp_1, SendOutgoingData(_, _, _, _, _, _, _, _))
133 .Times(0); 125 .Times(0);
134 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _)) 126 EXPECT_CALL(rtp_2, SendOutgoingData(_, _, _, _, _, _, _, _))
135 .Times(0); 127 .Times(0);
136 rtp_hdr_1.simulcastIdx = 1; 128 rtp_hdr_1.simulcastIdx = 1;
137 EXPECT_FALSE(payload_router_->RoutePayload( 129 EXPECT_FALSE(payload_router.RoutePayload(frame_type_1, payload_type_1, 0, 0,
138 frame_type_1, payload_type_1, 0, 0, &payload_1, 1, nullptr, &rtp_hdr_1)); 130 &payload_1, 1, nullptr, &rtp_hdr_1));
139 } 131 }
140 132
141 TEST_F(PayloadRouterTest, MaxPayloadLength) { 133 TEST(PayloadRouterTest, MaxPayloadLength) {
142 // Without any limitations from the modules, verify we get the max payload 134 // Without any limitations from the modules, verify we get the max payload
143 // length for IP/UDP/SRTP with a MTU of 150 bytes. 135 // length for IP/UDP/SRTP with a MTU of 150 bytes.
144 const size_t kDefaultMaxLength = 1500 - 20 - 8 - 12 - 4; 136 const size_t kDefaultMaxLength = 1500 - 20 - 8 - 12 - 4;
145 EXPECT_EQ(kDefaultMaxLength, payload_router_->DefaultMaxPayloadLength());
146 EXPECT_EQ(kDefaultMaxLength, payload_router_->MaxPayloadLength());
147
148 MockRtpRtcp rtp_1; 137 MockRtpRtcp rtp_1;
149 MockRtpRtcp rtp_2; 138 MockRtpRtcp rtp_2;
150 std::vector<RtpRtcp*> modules; 139 std::vector<RtpRtcp*> modules;
151 modules.push_back(&rtp_1); 140 modules.push_back(&rtp_1);
152 modules.push_back(&rtp_2); 141 modules.push_back(&rtp_2);
153 payload_router_->Init(modules); 142 PayloadRouter payload_router(modules);
154 payload_router_->SetSendingRtpModules(modules.size()); 143
144 EXPECT_EQ(kDefaultMaxLength, PayloadRouter::DefaultMaxPayloadLength());
145 payload_router.SetSendingRtpModules(modules.size());
155 146
156 // Modules return a higher length than the default value. 147 // Modules return a higher length than the default value.
157 EXPECT_CALL(rtp_1, MaxDataPayloadLength()) 148 EXPECT_CALL(rtp_1, MaxDataPayloadLength())
158 .Times(1) 149 .Times(1)
159 .WillOnce(Return(kDefaultMaxLength + 10)); 150 .WillOnce(Return(kDefaultMaxLength + 10));
160 EXPECT_CALL(rtp_2, MaxDataPayloadLength()) 151 EXPECT_CALL(rtp_2, MaxDataPayloadLength())
161 .Times(1) 152 .Times(1)
162 .WillOnce(Return(kDefaultMaxLength + 10)); 153 .WillOnce(Return(kDefaultMaxLength + 10));
163 EXPECT_EQ(kDefaultMaxLength, payload_router_->MaxPayloadLength()); 154 EXPECT_EQ(kDefaultMaxLength, payload_router.MaxPayloadLength());
164 155
165 // The modules return a value lower than default. 156 // The modules return a value lower than default.
166 const size_t kTestMinPayloadLength = 1001; 157 const size_t kTestMinPayloadLength = 1001;
167 EXPECT_CALL(rtp_1, MaxDataPayloadLength()) 158 EXPECT_CALL(rtp_1, MaxDataPayloadLength())
168 .Times(1) 159 .Times(1)
169 .WillOnce(Return(kTestMinPayloadLength + 10)); 160 .WillOnce(Return(kTestMinPayloadLength + 10));
170 EXPECT_CALL(rtp_2, MaxDataPayloadLength()) 161 EXPECT_CALL(rtp_2, MaxDataPayloadLength())
171 .Times(1) 162 .Times(1)
172 .WillOnce(Return(kTestMinPayloadLength)); 163 .WillOnce(Return(kTestMinPayloadLength));
173 EXPECT_EQ(kTestMinPayloadLength, payload_router_->MaxPayloadLength()); 164 EXPECT_EQ(kTestMinPayloadLength, payload_router.MaxPayloadLength());
174 } 165 }
175 166
176 TEST_F(PayloadRouterTest, SetTargetSendBitrates) { 167 TEST(PayloadRouterTest, SetTargetSendBitrates) {
177 MockRtpRtcp rtp_1; 168 MockRtpRtcp rtp_1;
178 MockRtpRtcp rtp_2; 169 MockRtpRtcp rtp_2;
179 std::vector<RtpRtcp*> modules; 170 std::vector<RtpRtcp*> modules;
180 modules.push_back(&rtp_1); 171 modules.push_back(&rtp_1);
181 modules.push_back(&rtp_2); 172 modules.push_back(&rtp_2);
182 payload_router_->Init(modules); 173 PayloadRouter payload_router(modules);
183 payload_router_->SetSendingRtpModules(modules.size()); 174 payload_router.SetSendingRtpModules(modules.size());
184 175
185 const uint32_t bitrate_1 = 10000; 176 const uint32_t bitrate_1 = 10000;
186 const uint32_t bitrate_2 = 76543; 177 const uint32_t bitrate_2 = 76543;
187 std::vector<uint32_t> bitrates(2, bitrate_1); 178 std::vector<uint32_t> bitrates(2, bitrate_1);
188 bitrates[1] = bitrate_2; 179 bitrates[1] = bitrate_2;
189 EXPECT_CALL(rtp_1, SetTargetSendBitrate(bitrate_1)) 180 EXPECT_CALL(rtp_1, SetTargetSendBitrate(bitrate_1))
190 .Times(1); 181 .Times(1);
191 EXPECT_CALL(rtp_2, SetTargetSendBitrate(bitrate_2)) 182 EXPECT_CALL(rtp_2, SetTargetSendBitrate(bitrate_2))
192 .Times(1); 183 .Times(1);
193 payload_router_->SetTargetSendBitrates(bitrates); 184 payload_router.SetTargetSendBitrates(bitrates);
194 185
195 bitrates.resize(1); 186 bitrates.resize(1);
196 EXPECT_CALL(rtp_1, SetTargetSendBitrate(bitrate_1)) 187 EXPECT_CALL(rtp_1, SetTargetSendBitrate(bitrate_1))
197 .Times(1); 188 .Times(1);
198 EXPECT_CALL(rtp_2, SetTargetSendBitrate(bitrate_2)) 189 EXPECT_CALL(rtp_2, SetTargetSendBitrate(bitrate_2))
199 .Times(0); 190 .Times(0);
200 payload_router_->SetTargetSendBitrates(bitrates); 191 payload_router.SetTargetSendBitrates(bitrates);
201 } 192 }
202 } // namespace webrtc 193 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/payload_router.cc ('k') | webrtc/video/video_receive_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698