/src/mozilla-central/media/webrtc/signaling/gtest/videoconduit_unittests.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
4 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #define GTEST_HAS_RTTI 0 |
7 | | #include "gtest/gtest.h" |
8 | | |
9 | | #include "nspr.h" |
10 | | #include "nss.h" |
11 | | #include "ssl.h" |
12 | | |
13 | | #include "VideoConduit.h" |
14 | | #include "WebrtcGmpVideoCodec.h" |
15 | | |
16 | | #include "webrtc/media/base/videoadapter.h" |
17 | | #include "webrtc/media/base/videosinkinterface.h" |
18 | | |
19 | | #include "MockCall.h" |
20 | | |
21 | | using namespace mozilla; |
22 | | |
23 | | namespace test { |
24 | | |
25 | | class MockVideoSink : public rtc::VideoSinkInterface<webrtc::VideoFrame> |
26 | | { |
27 | | public: |
28 | 0 | ~MockVideoSink() override = default; |
29 | | |
30 | | void OnFrame(const webrtc::VideoFrame& frame) override |
31 | 0 | { |
32 | 0 | mVideoFrame = frame; |
33 | 0 | ++mOnFrameCount; |
34 | 0 | } |
35 | | |
36 | | size_t mOnFrameCount = 0; |
37 | | webrtc::VideoFrame mVideoFrame; |
38 | | }; |
39 | | |
40 | | class VideoConduitTest : public ::testing::Test { |
41 | | public: |
42 | | |
43 | | VideoConduitTest() |
44 | | : mCall(new MockCall()) |
45 | 0 | { |
46 | 0 | NSS_NoDB_Init(nullptr); |
47 | 0 |
|
48 | 0 | mVideoConduit = new WebrtcVideoConduit( |
49 | 0 | WebRtcCallWrapper::Create(UniquePtr<MockCall>(mCall)), |
50 | 0 | GetCurrentThreadEventTarget()); |
51 | 0 | std::vector<unsigned int> ssrcs = {42}; |
52 | 0 | mVideoConduit->SetLocalSSRCs(ssrcs); |
53 | 0 | } |
54 | | |
55 | | ~VideoConduitTest() override |
56 | 0 | { |
57 | 0 | mVideoConduit->DeleteStreams(); |
58 | 0 | } |
59 | | |
60 | | MediaConduitErrorCode SendVideoFrame(unsigned short width, |
61 | | unsigned short height, |
62 | | uint64_t capture_time_ms) |
63 | 0 | { |
64 | 0 | rtc::scoped_refptr<webrtc::I420Buffer> buffer = |
65 | 0 | webrtc::I420Buffer::Create(width, height); |
66 | 0 | memset(buffer->MutableDataY(), 0x10, buffer->StrideY() * buffer->height()); |
67 | 0 | memset(buffer->MutableDataU(), 0x80, buffer->StrideU() * ((buffer->height() + 1) / 2)); |
68 | 0 | memset(buffer->MutableDataV(), 0x80, buffer->StrideV() * ((buffer->height() + 1) / 2)); |
69 | 0 |
|
70 | 0 | webrtc::VideoFrame frame(buffer, |
71 | 0 | capture_time_ms, |
72 | 0 | capture_time_ms, |
73 | 0 | webrtc::kVideoRotation_0); |
74 | 0 | return mVideoConduit->SendVideoFrame(frame); |
75 | 0 | } |
76 | | |
77 | | MockCall* mCall; |
78 | | RefPtr<mozilla::WebrtcVideoConduit> mVideoConduit; |
79 | | }; |
80 | | |
81 | | TEST_F(VideoConduitTest, TestConfigureReceiveMediaCodecs) |
82 | 0 | { |
83 | 0 | MediaConduitErrorCode ec; |
84 | 0 | EncodingConstraints constraints; |
85 | 0 |
|
86 | 0 | // Defaults |
87 | 0 | std::vector<VideoCodecConfig *> codecs; |
88 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
89 | 0 | codecs.push_back(&codecConfig); |
90 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
91 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
92 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
93 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_type, 120); |
94 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_name, "VP8"); |
95 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.local_ssrc, 0U); |
96 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.remote_ssrc, 0U); |
97 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
98 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.nack.rtp_history_ms, 0); |
99 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.remb); |
100 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.tmmbr); |
101 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqPliRtcp); |
102 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.ulpfec_payload_type, -1); |
103 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_payload_type, -1); |
104 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_rtx_payload_type, -1); |
105 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtx.size(), 0U); |
106 | 0 |
|
107 | 0 | // No codecs |
108 | 0 | codecs.clear(); |
109 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
110 | 0 | ASSERT_EQ(ec, kMediaConduitMalformedArgument); |
111 | 0 |
|
112 | 0 | // null codec |
113 | 0 | codecs.clear(); |
114 | 0 | codecs.push_back(nullptr); |
115 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
116 | 0 | ASSERT_EQ(ec, kMediaConduitMalformedArgument); |
117 | 0 |
|
118 | 0 | // empty codec name |
119 | 0 | codecs.clear(); |
120 | 0 | VideoCodecConfig codecConfigBadName(120, "", constraints); |
121 | 0 | codecs.push_back(&codecConfigBadName); |
122 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
123 | 0 | ASSERT_EQ(ec, kMediaConduitMalformedArgument); |
124 | 0 |
|
125 | 0 | // long codec name |
126 | 0 | codecs.clear(); |
127 | 0 | size_t longNameLength = WebrtcVideoConduit::CODEC_PLNAME_SIZE + 2; |
128 | 0 | char* longName = new char[longNameLength]; |
129 | 0 | memset(longName, 'A', longNameLength - 2); |
130 | 0 | longName[longNameLength - 1] = 0; |
131 | 0 | VideoCodecConfig codecConfigLongName(120, longName, constraints); |
132 | 0 | codecs.push_back(&codecConfigLongName); |
133 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
134 | 0 | ASSERT_EQ(ec, kMediaConduitMalformedArgument); |
135 | 0 | delete[] longName; |
136 | 0 | } |
137 | | |
138 | | TEST_F(VideoConduitTest, TestConfigureReceiveMediaCodecsFEC) |
139 | 0 | { |
140 | 0 | MediaConduitErrorCode ec; |
141 | 0 | EncodingConstraints constraints; |
142 | 0 | std::vector<VideoCodecConfig *> codecs; |
143 | 0 |
|
144 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
145 | 0 | codecConfig.mFECFbSet = true; |
146 | 0 | codecs.push_back(&codecConfig); |
147 | 0 | VideoCodecConfig codecConfigFEC(1, "ulpfec", constraints); |
148 | 0 | codecs.push_back(&codecConfigFEC); |
149 | 0 | VideoCodecConfig codecConfigRED(2, "red", constraints); |
150 | 0 | codecs.push_back(&codecConfigRED); |
151 | 0 |
|
152 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
153 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
154 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
155 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_type, 120); |
156 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_name, "VP8"); |
157 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.local_ssrc, 0U); |
158 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.remote_ssrc, 0U); |
159 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
160 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.nack.rtp_history_ms, 0); |
161 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.remb); |
162 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.tmmbr); |
163 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqPliRtcp); |
164 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.ulpfec_payload_type, 1); |
165 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_payload_type, 2); |
166 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_rtx_payload_type, -1); |
167 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtx.size(), 0U); |
168 | 0 | } |
169 | | |
170 | | TEST_F(VideoConduitTest, TestConfigureReceiveMediaCodecsH264) |
171 | 0 | { |
172 | 0 | MediaConduitErrorCode ec; |
173 | 0 | EncodingConstraints constraints; |
174 | 0 |
|
175 | 0 | WebrtcGmpPCHandleSetter setter("hi there"); |
176 | 0 |
|
177 | 0 | std::vector<VideoCodecConfig *> codecs; |
178 | 0 | VideoCodecConfig codecConfig(120, "H264", constraints); |
179 | 0 | codecs.push_back(&codecConfig); |
180 | 0 |
|
181 | 0 | // Insert twice to test that only one H264 codec is used at a time |
182 | 0 | codecs.push_back(&codecConfig); |
183 | 0 |
|
184 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
185 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
186 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
187 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_type, 120); |
188 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_name, "H264"); |
189 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.local_ssrc, 0U); |
190 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.remote_ssrc, 0U); |
191 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
192 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.nack.rtp_history_ms, 0); |
193 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.remb); |
194 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.tmmbr); |
195 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqPliRtcp); |
196 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.ulpfec_payload_type, -1); |
197 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_payload_type, -1); |
198 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_rtx_payload_type, -1); |
199 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtx.size(), 0U); |
200 | 0 | } |
201 | | |
202 | | TEST_F(VideoConduitTest, TestConfigureReceiveMediaCodecsKeyframeRequestType) |
203 | 0 | { |
204 | 0 | MediaConduitErrorCode ec; |
205 | 0 | EncodingConstraints constraints; |
206 | 0 | std::vector<VideoCodecConfig *> codecs; |
207 | 0 |
|
208 | 0 | // PLI should be preferred to FIR |
209 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
210 | 0 | codecConfig.mNackFbTypes.push_back("pli"); |
211 | 0 | codecConfig.mCcmFbTypes.push_back("fir"); |
212 | 0 | codecs.push_back(&codecConfig); |
213 | 0 |
|
214 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
215 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
216 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
217 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqPliRtcp); |
218 | 0 |
|
219 | 0 | // Just FIR |
220 | 0 | codecs.clear(); |
221 | 0 | codecConfig.mNackFbTypes.clear(); |
222 | 0 | codecs.push_back(&codecConfig); |
223 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
224 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
225 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
226 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqFirRtcp); |
227 | 0 | } |
228 | | |
229 | | TEST_F(VideoConduitTest, TestConfigureReceiveMediaCodecsNack) |
230 | 0 | { |
231 | 0 | MediaConduitErrorCode ec; |
232 | 0 | EncodingConstraints constraints; |
233 | 0 | std::vector<VideoCodecConfig *> codecs; |
234 | 0 |
|
235 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
236 | 0 | codecConfig.mNackFbTypes.push_back(""); |
237 | 0 | codecs.push_back(&codecConfig); |
238 | 0 |
|
239 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
240 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
241 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
242 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_type, 120); |
243 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_name, "VP8"); |
244 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.local_ssrc, 0U); |
245 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.remote_ssrc, 0U); |
246 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
247 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.nack.rtp_history_ms, 1000); |
248 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.remb); |
249 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.tmmbr); |
250 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqPliRtcp); |
251 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.ulpfec_payload_type, -1); |
252 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_payload_type, -1); |
253 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_rtx_payload_type, -1); |
254 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtx.size(), 0U); |
255 | 0 | } |
256 | | |
257 | | TEST_F(VideoConduitTest, TestConfigureReceiveMediaCodecsRemb) |
258 | 0 | { |
259 | 0 | MediaConduitErrorCode ec; |
260 | 0 | EncodingConstraints constraints; |
261 | 0 | std::vector<VideoCodecConfig *> codecs; |
262 | 0 |
|
263 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
264 | 0 | codecConfig.mRembFbSet = true; |
265 | 0 | codecs.push_back(&codecConfig); |
266 | 0 |
|
267 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
268 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
269 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
270 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_type, 120); |
271 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_name, "VP8"); |
272 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.local_ssrc, 0U); |
273 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.remote_ssrc, 0U); |
274 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
275 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.nack.rtp_history_ms, 0); |
276 | 0 | ASSERT_TRUE(mCall->mVideoReceiveConfig.rtp.remb); |
277 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.tmmbr); |
278 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqPliRtcp); |
279 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.ulpfec_payload_type, -1); |
280 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_payload_type, -1); |
281 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_rtx_payload_type, -1); |
282 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtx.size(), 0U); |
283 | 0 | } |
284 | | |
285 | | TEST_F(VideoConduitTest, TestConfigureReceiveMediaCodecsTmmbr) |
286 | 0 | { |
287 | 0 | MediaConduitErrorCode ec; |
288 | 0 | EncodingConstraints constraints; |
289 | 0 | std::vector<VideoCodecConfig *> codecs; |
290 | 0 |
|
291 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
292 | 0 | codecConfig.mCcmFbTypes.push_back("tmmbr"); |
293 | 0 | codecs.push_back(&codecConfig); |
294 | 0 |
|
295 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
296 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
297 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
298 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_type, 120); |
299 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_name, "VP8"); |
300 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.local_ssrc, 0U); |
301 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.remote_ssrc, 0U); |
302 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
303 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.nack.rtp_history_ms, 0); |
304 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.remb); |
305 | 0 | ASSERT_TRUE(mCall->mVideoReceiveConfig.rtp.tmmbr); |
306 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqPliRtcp); |
307 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.ulpfec_payload_type, -1); |
308 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_payload_type, -1); |
309 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_rtx_payload_type, -1); |
310 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtx.size(), 0U); |
311 | 0 | } |
312 | | |
313 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodec) |
314 | 0 | { |
315 | 0 | MediaConduitErrorCode ec; |
316 | 0 | EncodingConstraints constraints; |
317 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
318 | 0 |
|
319 | 0 | // defaults |
320 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
321 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
322 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
323 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
324 | 0 | mVideoConduit->StartTransmitting(); |
325 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.payload_name, "VP8"); |
326 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.payload_type, 120); |
327 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.internal_source, false); |
328 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.full_overuse_time, false); |
329 | 0 | ASSERT_NE(mCall->mVideoSendConfig.encoder_settings.encoder, nullptr); |
330 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
331 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.max_packet_size, kVideoMtu); |
332 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.content_type, |
333 | 0 | VideoEncoderConfig::ContentType::kRealtimeVideo); |
334 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.min_transmit_bitrate_bps, 0); |
335 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.max_bitrate_bps, 0); |
336 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.number_of_streams, 1U); |
337 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.resolution_divisor, 1); |
338 | 0 | mVideoConduit->StopTransmitting(); |
339 | 0 |
|
340 | 0 | // null codec |
341 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(nullptr); |
342 | 0 | ASSERT_EQ(ec, kMediaConduitMalformedArgument); |
343 | 0 |
|
344 | 0 | // empty codec name |
345 | 0 | VideoCodecConfig codecConfigBadName(120, "", constraints); |
346 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigBadName); |
347 | 0 | ASSERT_EQ(ec, kMediaConduitMalformedArgument); |
348 | 0 |
|
349 | 0 | // long codec name |
350 | 0 | size_t longNameLength = WebrtcVideoConduit::CODEC_PLNAME_SIZE + 2; |
351 | 0 | char* longName = new char[longNameLength]; |
352 | 0 | memset(longName, 'A', longNameLength - 2); |
353 | 0 | longName[longNameLength - 1] = 0; |
354 | 0 | VideoCodecConfig codecConfigLongName(120, longName, constraints); |
355 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigBadName); |
356 | 0 | ASSERT_EQ(ec, kMediaConduitMalformedArgument); |
357 | 0 | delete[] longName; |
358 | 0 | } |
359 | | |
360 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodecMaxFps) |
361 | 0 | { |
362 | 0 | MediaConduitErrorCode ec; |
363 | 0 | EncodingConstraints constraints; |
364 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
365 | 0 |
|
366 | 0 | constraints.maxFps = 0; |
367 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
368 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
369 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
370 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
371 | 0 | mVideoConduit->StartTransmitting(); |
372 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
373 | 0 | videoStreams = mCall->CreateEncoderStreams(640, 480); |
374 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
375 | 0 | ASSERT_EQ(videoStreams[0].max_framerate, 30); // DEFAULT_VIDEO_MAX_FRAMERATE |
376 | 0 | mVideoConduit->StopTransmitting(); |
377 | 0 |
|
378 | 0 | constraints.maxFps = 42; |
379 | 0 | VideoCodecConfig codecConfig2(120, "VP8", constraints); |
380 | 0 | codecConfig2.mSimulcastEncodings.push_back(encoding); |
381 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig2); |
382 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
383 | 0 | mVideoConduit->StartTransmitting(); |
384 | 0 | videoStreams = mCall->CreateEncoderStreams(640, 480); |
385 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
386 | 0 | ASSERT_EQ(videoStreams[0].max_framerate, 42); |
387 | 0 | mVideoConduit->StopTransmitting(); |
388 | 0 | } |
389 | | |
390 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodecMaxMbps) |
391 | 0 | { |
392 | 0 | MediaConduitErrorCode ec; |
393 | 0 | EncodingConstraints constraints; |
394 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
395 | 0 |
|
396 | 0 | constraints.maxMbps = 0; |
397 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
398 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
399 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
400 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
401 | 0 | mVideoConduit->StartTransmitting(); |
402 | 0 | SendVideoFrame(640, 480, 1); |
403 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
404 | 0 | videoStreams = mCall->CreateEncoderStreams(640, 480); |
405 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
406 | 0 | ASSERT_EQ(videoStreams[0].max_framerate, 30); // DEFAULT_VIDEO_MAX_FRAMERATE |
407 | 0 | mVideoConduit->StopTransmitting(); |
408 | 0 |
|
409 | 0 | constraints.maxMbps = 10000; |
410 | 0 | VideoCodecConfig codecConfig2(120, "VP8", constraints); |
411 | 0 | codecConfig2.mSimulcastEncodings.push_back(encoding); |
412 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig2); |
413 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
414 | 0 | mVideoConduit->StartTransmitting(); |
415 | 0 | SendVideoFrame(640, 480, 1); |
416 | 0 | videoStreams = mCall->CreateEncoderStreams(640, 480); |
417 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
418 | 0 | ASSERT_EQ(videoStreams[0].max_framerate, 8); |
419 | 0 | mVideoConduit->StopTransmitting(); |
420 | 0 | } |
421 | | |
422 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodecDefaults) |
423 | 0 | { |
424 | 0 | MediaConduitErrorCode ec; |
425 | 0 | EncodingConstraints constraints; |
426 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
427 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
428 | 0 |
|
429 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
430 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
431 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
432 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
433 | 0 | mVideoConduit->StartTransmitting(); |
434 | 0 | videoStreams = mCall->CreateEncoderStreams(640, 480); |
435 | 0 | EXPECT_EQ(videoStreams.size(), 1U); |
436 | 0 | EXPECT_EQ(videoStreams[0].min_bitrate_bps, 150000); |
437 | 0 | EXPECT_EQ(videoStreams[0].target_bitrate_bps, 500000); |
438 | 0 | EXPECT_EQ(videoStreams[0].max_bitrate_bps, 2000000); |
439 | 0 |
|
440 | 0 | // SelectBitrates not called until we send a frame |
441 | 0 | SendVideoFrame(1280, 720, 1); |
442 | 0 | videoStreams = mCall->CreateEncoderStreams(1280, 720); |
443 | 0 | EXPECT_EQ(videoStreams.size(), 1U); |
444 | 0 | EXPECT_EQ(videoStreams[0].min_bitrate_bps, 600000); |
445 | 0 | EXPECT_EQ(videoStreams[0].target_bitrate_bps, 800000); |
446 | 0 | EXPECT_EQ(videoStreams[0].max_bitrate_bps, 2500000); |
447 | 0 | mVideoConduit->StopTransmitting(); |
448 | 0 | } |
449 | | |
450 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodecTias) |
451 | 0 | { |
452 | 0 | MediaConduitErrorCode ec; |
453 | 0 | EncodingConstraints constraints; |
454 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
455 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
456 | 0 |
|
457 | 0 | // TIAS |
458 | 0 | VideoCodecConfig codecConfigTias(120, "VP8", constraints); |
459 | 0 | codecConfigTias.mSimulcastEncodings.push_back(encoding); |
460 | 0 | codecConfigTias.mTias = 1000000; |
461 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigTias); |
462 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
463 | 0 | mVideoConduit->StartTransmitting(); |
464 | 0 | SendVideoFrame(1280, 720, 1); |
465 | 0 | videoStreams = mCall->CreateEncoderStreams(1280, 720); |
466 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
467 | 0 | ASSERT_EQ(videoStreams[0].min_bitrate_bps, 600000); |
468 | 0 | ASSERT_EQ(videoStreams[0].target_bitrate_bps, 800000); |
469 | 0 | ASSERT_EQ(videoStreams[0].max_bitrate_bps, 1000000); |
470 | 0 | mVideoConduit->StopTransmitting(); |
471 | 0 |
|
472 | 0 | // TIAS (too low) |
473 | 0 | VideoCodecConfig codecConfigTiasLow(120, "VP8", constraints); |
474 | 0 | codecConfigTiasLow.mSimulcastEncodings.push_back(encoding); |
475 | 0 | codecConfigTiasLow.mTias = 1000; |
476 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigTiasLow); |
477 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
478 | 0 | mVideoConduit->StartTransmitting(); |
479 | 0 | SendVideoFrame(1280, 720, 1); |
480 | 0 | videoStreams = mCall->CreateEncoderStreams(1280, 720); |
481 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
482 | 0 | ASSERT_EQ(videoStreams[0].min_bitrate_bps, 30000); |
483 | 0 | ASSERT_EQ(videoStreams[0].target_bitrate_bps, 30000); |
484 | 0 | ASSERT_EQ(videoStreams[0].max_bitrate_bps, 30000); |
485 | 0 | mVideoConduit->StopTransmitting(); |
486 | 0 | } |
487 | | |
488 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodecMaxBr) |
489 | 0 | { |
490 | 0 | MediaConduitErrorCode ec; |
491 | 0 | EncodingConstraints constraints; |
492 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
493 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
494 | 0 |
|
495 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
496 | 0 | encoding.constraints.maxBr = 50000; |
497 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
498 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
499 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
500 | 0 | mVideoConduit->StartTransmitting(); |
501 | 0 | SendVideoFrame(1280, 720, 1); |
502 | 0 | videoStreams = mCall->CreateEncoderStreams(1280, 720); |
503 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
504 | 0 | ASSERT_LE(videoStreams[0].min_bitrate_bps, 50000); |
505 | 0 | ASSERT_LE(videoStreams[0].target_bitrate_bps, 50000); |
506 | 0 | ASSERT_EQ(videoStreams[0].max_bitrate_bps, 50000); |
507 | 0 | mVideoConduit->StopTransmitting(); |
508 | 0 | } |
509 | | |
510 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodecScaleResolutionBy) |
511 | 0 | { |
512 | 0 | MediaConduitErrorCode ec; |
513 | 0 | EncodingConstraints constraints; |
514 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
515 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
516 | 0 |
|
517 | 0 | std::vector<unsigned int> ssrcs = {42, 1729}; |
518 | 0 | mVideoConduit->SetLocalSSRCs(ssrcs); |
519 | 0 |
|
520 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
521 | 0 | encoding.constraints.scaleDownBy = 2; |
522 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
523 | 0 | encoding.constraints.scaleDownBy = 4; |
524 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
525 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
526 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
527 | 0 |
|
528 | 0 | UniquePtr<MockVideoSink> sink(new MockVideoSink()); |
529 | 0 | rtc::VideoSinkWants wants; |
530 | 0 | mVideoConduit->AddOrUpdateSink(sink.get(), wants); |
531 | 0 |
|
532 | 0 | mVideoConduit->StartTransmitting(); |
533 | 0 | SendVideoFrame(640, 360, 1); |
534 | 0 | videoStreams = mCall->CreateEncoderStreams( |
535 | 0 | sink->mVideoFrame.width(), sink->mVideoFrame.height()); |
536 | 0 | ASSERT_EQ(videoStreams.size(), 2U); |
537 | 0 | ASSERT_EQ(videoStreams[0].width, 160U); |
538 | 0 | ASSERT_EQ(videoStreams[0].height, 88U); |
539 | 0 | ASSERT_EQ(videoStreams[1].width, 320U); |
540 | 0 | ASSERT_EQ(videoStreams[1].height, 176U); |
541 | 0 | mVideoConduit->StopTransmitting(); |
542 | 0 | } |
543 | | |
544 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodecCodecMode) |
545 | 0 | { |
546 | 0 | MediaConduitErrorCode ec; |
547 | 0 | EncodingConstraints constraints; |
548 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
549 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
550 | 0 |
|
551 | 0 | mVideoConduit->ConfigureCodecMode(webrtc::VideoCodecMode::kScreensharing); |
552 | 0 |
|
553 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
554 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
555 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
556 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
557 | 0 | mVideoConduit->StartTransmitting(); |
558 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.content_type, |
559 | 0 | VideoEncoderConfig::ContentType::kScreen); |
560 | 0 | mVideoConduit->StopTransmitting(); |
561 | 0 | } |
562 | | |
563 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodecFEC) |
564 | 0 | { |
565 | 0 | MediaConduitErrorCode ec; |
566 | 0 | EncodingConstraints constraints; |
567 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
568 | 0 |
|
569 | 0 | WebrtcGmpPCHandleSetter setter("hi there"); |
570 | 0 |
|
571 | 0 | // H264 + FEC |
572 | 0 | VideoCodecConfig codecConfig(120, "H264", constraints); |
573 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
574 | 0 | codecConfig.mFECFbSet = true; |
575 | 0 | codecConfig.mULPFECPayloadType = 1; |
576 | 0 | codecConfig.mREDPayloadType = 2; |
577 | 0 | codecConfig.mREDRTXPayloadType = 3; |
578 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
579 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
580 | 0 | mVideoConduit->StartTransmitting(); |
581 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.ulpfec.ulpfec_payload_type, codecConfig.mULPFECPayloadType); |
582 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.ulpfec.red_payload_type, codecConfig.mREDPayloadType); |
583 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.ulpfec.red_rtx_payload_type, codecConfig.mREDRTXPayloadType); |
584 | 0 | mVideoConduit->StopTransmitting(); |
585 | 0 |
|
586 | 0 | // H264 + FEC + Nack |
587 | 0 | codecConfig.mFECFbSet = true; |
588 | 0 | codecConfig.mNackFbTypes.push_back(""); |
589 | 0 | codecConfig.mULPFECPayloadType = 1; |
590 | 0 | codecConfig.mREDPayloadType = 2; |
591 | 0 | codecConfig.mREDRTXPayloadType = 3; |
592 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
593 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
594 | 0 | mVideoConduit->StartTransmitting(); |
595 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.ulpfec.ulpfec_payload_type, -1); |
596 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.ulpfec.red_payload_type, -1); |
597 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.ulpfec.red_rtx_payload_type, -1); |
598 | 0 | mVideoConduit->StopTransmitting(); |
599 | 0 |
|
600 | 0 | // VP8 + FEC + Nack |
601 | 0 | VideoCodecConfig codecConfig2(120, "VP8", constraints); |
602 | 0 | codecConfig2.mSimulcastEncodings.push_back(encoding); |
603 | 0 | codecConfig2.mFECFbSet = true; |
604 | 0 | codecConfig2.mNackFbTypes.push_back(""); |
605 | 0 | codecConfig2.mULPFECPayloadType = 1; |
606 | 0 | codecConfig2.mREDPayloadType = 2; |
607 | 0 | codecConfig2.mREDRTXPayloadType = 3; |
608 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig2); |
609 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
610 | 0 | mVideoConduit->StartTransmitting(); |
611 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.ulpfec.ulpfec_payload_type, codecConfig.mULPFECPayloadType); |
612 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.ulpfec.red_payload_type, codecConfig.mREDPayloadType); |
613 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.ulpfec.red_rtx_payload_type, codecConfig.mREDRTXPayloadType); |
614 | 0 | mVideoConduit->StopTransmitting(); |
615 | 0 | } |
616 | | |
617 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodecNack) |
618 | 0 | { |
619 | 0 | MediaConduitErrorCode ec; |
620 | 0 | EncodingConstraints constraints; |
621 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
622 | 0 |
|
623 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
624 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
625 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
626 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
627 | 0 | mVideoConduit->StartTransmitting(); |
628 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.nack.rtp_history_ms, 0); |
629 | 0 | mVideoConduit->StopTransmitting(); |
630 | 0 |
|
631 | 0 | codecConfig.mNackFbTypes.push_back(""); |
632 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
633 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
634 | 0 | mVideoConduit->StartTransmitting(); |
635 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.nack.rtp_history_ms, 1000); |
636 | 0 | mVideoConduit->StopTransmitting(); |
637 | 0 | } |
638 | | |
639 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodecRids) |
640 | 0 | { |
641 | 0 | MediaConduitErrorCode ec; |
642 | 0 | EncodingConstraints constraints; |
643 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
644 | 0 |
|
645 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
646 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
647 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
648 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
649 | 0 | mVideoConduit->StartTransmitting(); |
650 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.rids.size(), 0U); |
651 | 0 | mVideoConduit->StopTransmitting(); |
652 | 0 |
|
653 | 0 | std::vector<unsigned int> ssrcs = {42, 1729}; |
654 | 0 | mVideoConduit->SetLocalSSRCs(ssrcs); |
655 | 0 |
|
656 | 0 | codecConfig.mSimulcastEncodings.clear(); |
657 | 0 | encoding.rid = "1"; |
658 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
659 | 0 | encoding.rid = "2"; |
660 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
661 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
662 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
663 | 0 | mVideoConduit->StartTransmitting(); |
664 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.rids.size(), 2U); |
665 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.rids[0], "2"); |
666 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.rids[1], "1"); |
667 | 0 | mVideoConduit->StopTransmitting(); |
668 | 0 | } |
669 | | |
670 | | TEST_F(VideoConduitTest, TestOnSinkWantsChanged) |
671 | 0 | { |
672 | 0 | UniquePtr<MockVideoSink> sink(new MockVideoSink()); |
673 | 0 | rtc::VideoSinkWants wants; |
674 | 0 | mVideoConduit->AddOrUpdateSink(sink.get(), wants); |
675 | 0 |
|
676 | 0 | wants.max_pixel_count = rtc::Optional<int>(256000); |
677 | 0 | EncodingConstraints constraints; |
678 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
679 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
680 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
681 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
682 | 0 |
|
683 | 0 | codecConfig.mEncodingConstraints.maxFs = 0; |
684 | 0 | mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
685 | 0 | mVideoConduit->StartTransmitting(); |
686 | 0 | mVideoConduit->OnSinkWantsChanged(wants); |
687 | 0 | SendVideoFrame(1920, 1080, 1); |
688 | 0 | EXPECT_LE(sink->mVideoFrame.width() * sink->mVideoFrame.height(), 256000); |
689 | 0 | videoStreams = mCall->CreateEncoderStreams( |
690 | 0 | sink->mVideoFrame.width(), sink->mVideoFrame.height()); |
691 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
692 | 0 | EXPECT_EQ(videoStreams[0].width, 480U); |
693 | 0 | EXPECT_EQ(videoStreams[0].height, 270U); |
694 | 0 |
|
695 | 0 | codecConfig.mEncodingConstraints.maxFs = 500; |
696 | 0 | mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
697 | 0 | mVideoConduit->OnSinkWantsChanged(wants); |
698 | 0 | SendVideoFrame(1920, 1080, 2); |
699 | 0 | EXPECT_LE(sink->mVideoFrame.width() * sink->mVideoFrame.height(), 500 * 16 * 16); |
700 | 0 | videoStreams = mCall->CreateEncoderStreams( |
701 | 0 | sink->mVideoFrame.width(), sink->mVideoFrame.height()); |
702 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
703 | 0 | EXPECT_EQ(videoStreams[0].width, 360U); |
704 | 0 | EXPECT_EQ(videoStreams[0].height, 201U); |
705 | 0 |
|
706 | 0 | codecConfig.mEncodingConstraints.maxFs = 1000; |
707 | 0 | mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
708 | 0 | mVideoConduit->OnSinkWantsChanged(wants); |
709 | 0 | SendVideoFrame(1920, 1080, 3); |
710 | 0 | EXPECT_LE(sink->mVideoFrame.width() * sink->mVideoFrame.height(), 1000 * 16 * 16); |
711 | 0 | videoStreams = mCall->CreateEncoderStreams( |
712 | 0 | sink->mVideoFrame.width(), sink->mVideoFrame.height()); |
713 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
714 | 0 | EXPECT_EQ(videoStreams[0].width, 480U); |
715 | 0 | EXPECT_EQ(videoStreams[0].height, 270U); |
716 | 0 |
|
717 | 0 | wants.max_pixel_count = rtc::Optional<int>(64000); |
718 | 0 | codecConfig.mEncodingConstraints.maxFs = 500; |
719 | 0 | mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
720 | 0 | mVideoConduit->OnSinkWantsChanged(wants); |
721 | 0 | SendVideoFrame(1920, 1080, 4); |
722 | 0 | EXPECT_LE(sink->mVideoFrame.width() * sink->mVideoFrame.height(), 64000); |
723 | 0 | videoStreams = mCall->CreateEncoderStreams( |
724 | 0 | sink->mVideoFrame.width(), sink->mVideoFrame.height()); |
725 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
726 | 0 | EXPECT_EQ(videoStreams[0].width, 240U); |
727 | 0 | EXPECT_EQ(videoStreams[0].height, 135U); |
728 | 0 |
|
729 | 0 | mVideoConduit->StopTransmitting(); |
730 | 0 | } |
731 | | |
732 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodecSimulcastOddScreen) |
733 | 0 | { |
734 | 0 | std::vector<unsigned int> ssrcs = {42, 43, 44}; |
735 | 0 | mVideoConduit->SetLocalSSRCs(ssrcs); |
736 | 0 |
|
737 | 0 | MediaConduitErrorCode ec; |
738 | 0 | EncodingConstraints constraints; |
739 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
740 | 0 | VideoCodecConfig::SimulcastEncoding encoding2; |
741 | 0 | VideoCodecConfig::SimulcastEncoding encoding3; |
742 | 0 | encoding2.constraints.scaleDownBy = 2; |
743 | 0 | encoding3.constraints.scaleDownBy = 4; |
744 | 0 |
|
745 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
746 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
747 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding2); |
748 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding3); |
749 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
750 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
751 | 0 |
|
752 | 0 | UniquePtr<MockVideoSink> sink(new MockVideoSink()); |
753 | 0 | rtc::VideoSinkWants wants; |
754 | 0 | mVideoConduit->AddOrUpdateSink(sink.get(), wants); |
755 | 0 | mVideoConduit->StartTransmitting(); |
756 | 0 |
|
757 | 0 | // This should crop to 16-alignment to help with scaling |
758 | 0 | SendVideoFrame(26, 24, 1); |
759 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
760 | 0 | videoStreams = mCall->CreateEncoderStreams( |
761 | 0 | sink->mVideoFrame.width(), sink->mVideoFrame.height()); |
762 | 0 | ASSERT_EQ(videoStreams.size(), 3U); |
763 | 0 | EXPECT_EQ(videoStreams[2].width, 16U); |
764 | 0 | EXPECT_EQ(videoStreams[2].height, 16U); |
765 | 0 | EXPECT_EQ(videoStreams[1].width, 8U); |
766 | 0 | EXPECT_EQ(videoStreams[1].height, 8U); |
767 | 0 | EXPECT_EQ(videoStreams[0].width, 4U); |
768 | 0 | EXPECT_EQ(videoStreams[0].height, 4U); |
769 | 0 |
|
770 | 0 | // Test that we are able to remove the 16-alignment cropping (non-simulcast) |
771 | 0 | codecConfig.mSimulcastEncodings.clear(); |
772 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
773 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
774 | 0 | mVideoConduit->SetLocalSSRCs({42}); |
775 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
776 | 0 | SendVideoFrame(26, 24, 2); |
777 | 0 | videoStreams = mCall->CreateEncoderStreams( |
778 | 0 | sink->mVideoFrame.width(), sink->mVideoFrame.height()); |
779 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
780 | 0 | EXPECT_EQ(videoStreams[0].width, 26U); |
781 | 0 | EXPECT_EQ(videoStreams[0].height, 24U); |
782 | 0 |
|
783 | 0 | mVideoConduit->StopTransmitting(); |
784 | 0 | } |
785 | | |
786 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodecSimulcastAllScaling) |
787 | 0 | { |
788 | 0 | std::vector<unsigned int> ssrcs = {42, 43, 44}; |
789 | 0 | mVideoConduit->SetLocalSSRCs(ssrcs); |
790 | 0 |
|
791 | 0 | MediaConduitErrorCode ec; |
792 | 0 | EncodingConstraints constraints; |
793 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
794 | 0 | VideoCodecConfig::SimulcastEncoding encoding2; |
795 | 0 | VideoCodecConfig::SimulcastEncoding encoding3; |
796 | 0 | encoding.constraints.scaleDownBy = 2; |
797 | 0 | encoding2.constraints.scaleDownBy = 4; |
798 | 0 | encoding3.constraints.scaleDownBy = 6; |
799 | 0 |
|
800 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
801 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
802 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding2); |
803 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding3); |
804 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
805 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
806 | 0 |
|
807 | 0 | UniquePtr<MockVideoSink> sink(new MockVideoSink()); |
808 | 0 | rtc::VideoSinkWants wants; |
809 | 0 | mVideoConduit->AddOrUpdateSink(sink.get(), wants); |
810 | 0 |
|
811 | 0 | mVideoConduit->StartTransmitting(); |
812 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
813 | 0 |
|
814 | 0 | SendVideoFrame(1281, 721, 1); |
815 | 0 | videoStreams = mCall->CreateEncoderStreams( |
816 | 0 | sink->mVideoFrame.width(), sink->mVideoFrame.height()); |
817 | 0 | ASSERT_EQ(videoStreams.size(), 3U); |
818 | 0 | EXPECT_EQ(videoStreams[2].width, 480U); |
819 | 0 | EXPECT_EQ(videoStreams[2].height, 240U); |
820 | 0 | EXPECT_EQ(videoStreams[1].width, 240U); |
821 | 0 | EXPECT_EQ(videoStreams[1].height, 120U); |
822 | 0 | EXPECT_EQ(videoStreams[0].width, 120U); |
823 | 0 | EXPECT_EQ(videoStreams[0].height, 60U); |
824 | 0 |
|
825 | 0 | SendVideoFrame(1281, 721, 2); |
826 | 0 | videoStreams = mCall->CreateEncoderStreams( |
827 | 0 | sink->mVideoFrame.width(), sink->mVideoFrame.height()); |
828 | 0 | ASSERT_EQ(videoStreams.size(), 3U); |
829 | 0 | EXPECT_EQ(videoStreams[2].width, 480U); |
830 | 0 | EXPECT_EQ(videoStreams[2].height, 240U); |
831 | 0 | EXPECT_EQ(videoStreams[1].width, 240U); |
832 | 0 | EXPECT_EQ(videoStreams[1].height, 120U); |
833 | 0 | EXPECT_EQ(videoStreams[0].width, 120U); |
834 | 0 | EXPECT_EQ(videoStreams[0].height, 60U); |
835 | 0 |
|
836 | 0 | SendVideoFrame(1280, 720, 3); |
837 | 0 | videoStreams = mCall->CreateEncoderStreams( |
838 | 0 | sink->mVideoFrame.width(), sink->mVideoFrame.height()); |
839 | 0 | ASSERT_EQ(videoStreams.size(), 3U); |
840 | 0 | EXPECT_EQ(videoStreams[2].width, 640U); |
841 | 0 | EXPECT_EQ(videoStreams[2].height, 352U); |
842 | 0 | EXPECT_EQ(videoStreams[1].width, 320U); |
843 | 0 | EXPECT_EQ(videoStreams[1].height, 176U); |
844 | 0 | EXPECT_EQ(videoStreams[0].width, 160U); |
845 | 0 | EXPECT_EQ(videoStreams[0].height, 88U); |
846 | 0 |
|
847 | 0 | codecConfig.mSimulcastEncodings[0].constraints.scaleDownBy = 1; |
848 | 0 | codecConfig.mSimulcastEncodings[1].constraints.scaleDownBy = 2; |
849 | 0 | codecConfig.mSimulcastEncodings[2].constraints.scaleDownBy = 4; |
850 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
851 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
852 | 0 | SendVideoFrame(1280, 720, 4); |
853 | 0 | videoStreams = mCall->CreateEncoderStreams( |
854 | 0 | sink->mVideoFrame.width(), sink->mVideoFrame.height()); |
855 | 0 | ASSERT_EQ(videoStreams.size(), 3U); |
856 | 0 | EXPECT_EQ(videoStreams[2].width, 1280U); |
857 | 0 | EXPECT_EQ(videoStreams[2].height, 720U); |
858 | 0 | EXPECT_EQ(videoStreams[1].width, 640U); |
859 | 0 | EXPECT_EQ(videoStreams[1].height, 360U); |
860 | 0 | EXPECT_EQ(videoStreams[0].width, 320U); |
861 | 0 | EXPECT_EQ(videoStreams[0].height, 180U); |
862 | 0 |
|
863 | 0 | mVideoConduit->StopTransmitting(); |
864 | 0 | } |
865 | | |
866 | | TEST_F(VideoConduitTest, TestConfigureSendMediaCodecSimulcastScreenshare) |
867 | 0 | { |
868 | 0 | std::vector<unsigned int> ssrcs = {42, 43, 44}; |
869 | 0 | mVideoConduit->SetLocalSSRCs(ssrcs); |
870 | 0 |
|
871 | 0 | MediaConduitErrorCode ec; |
872 | 0 | EncodingConstraints constraints; |
873 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
874 | 0 | VideoCodecConfig::SimulcastEncoding encoding2; |
875 | 0 | VideoCodecConfig::SimulcastEncoding encoding3; |
876 | 0 | encoding2.constraints.scaleDownBy = 2; |
877 | 0 | encoding3.constraints.scaleDownBy = 4; |
878 | 0 |
|
879 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
880 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
881 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding2); |
882 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding3); |
883 | 0 | ec = mVideoConduit->ConfigureCodecMode(webrtc::VideoCodecMode::kScreensharing); |
884 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
885 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
886 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
887 | 0 | mVideoConduit->StartTransmitting(); |
888 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
889 | 0 | videoStreams = mCall->CreateEncoderStreams(640, 480); |
890 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
891 | 0 | mVideoConduit->StopTransmitting(); |
892 | 0 | } |
893 | | |
894 | | TEST_F(VideoConduitTest, TestReconfigureReceiveMediaCodecs) |
895 | 0 | { |
896 | 0 | MediaConduitErrorCode ec; |
897 | 0 | EncodingConstraints constraints; |
898 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
899 | 0 | std::vector<VideoCodecConfig*> codecs; |
900 | 0 |
|
901 | 0 | WebrtcGmpPCHandleSetter setter("hi there"); |
902 | 0 |
|
903 | 0 | // Defaults |
904 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
905 | 0 | codecs.push_back(&codecConfig); |
906 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
907 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
908 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
909 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_type, 120); |
910 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_name, "VP8"); |
911 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.local_ssrc, 0U); |
912 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.remote_ssrc, 0U); |
913 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
914 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.nack.rtp_history_ms, 0); |
915 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.remb); |
916 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.tmmbr); |
917 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqPliRtcp); |
918 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.ulpfec_payload_type, -1); |
919 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_payload_type, -1); |
920 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_rtx_payload_type, -1); |
921 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtx.size(), 0U); |
922 | 0 |
|
923 | 0 | // FEC |
924 | 0 | codecs.clear(); |
925 | 0 | VideoCodecConfig codecConfigFecFb(120, "VP8", constraints); |
926 | 0 | codecConfigFecFb.mFECFbSet = true; |
927 | 0 | codecs.push_back(&codecConfigFecFb); |
928 | 0 | VideoCodecConfig codecConfigFEC(1, "ulpfec", constraints); |
929 | 0 | codecs.push_back(&codecConfigFEC); |
930 | 0 | VideoCodecConfig codecConfigRED(2, "red", constraints); |
931 | 0 | codecs.push_back(&codecConfigRED); |
932 | 0 |
|
933 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
934 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
935 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
936 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_type, 120); |
937 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_name, "VP8"); |
938 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.local_ssrc, 0U); |
939 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.remote_ssrc, 0U); |
940 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
941 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.nack.rtp_history_ms, 0); |
942 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.remb); |
943 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.tmmbr); |
944 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqPliRtcp); |
945 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.ulpfec_payload_type, 1); |
946 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_payload_type, 2); |
947 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_rtx_payload_type, -1); |
948 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtx.size(), 0U); |
949 | 0 |
|
950 | 0 | // H264 |
951 | 0 | codecs.clear(); |
952 | 0 | VideoCodecConfig codecConfigH264(120, "H264", constraints); |
953 | 0 | codecs.push_back(&codecConfigH264); |
954 | 0 |
|
955 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
956 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
957 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
958 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_type, 120); |
959 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_name, "H264"); |
960 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.local_ssrc, 0U); |
961 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.remote_ssrc, 0U); |
962 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
963 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.nack.rtp_history_ms, 0); |
964 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.remb); |
965 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.tmmbr); |
966 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqPliRtcp); |
967 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.ulpfec_payload_type, -1); |
968 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_payload_type, -1); |
969 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_rtx_payload_type, -1); |
970 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtx.size(), 0U); |
971 | 0 |
|
972 | 0 | // Nack |
973 | 0 | codecs.clear(); |
974 | 0 | VideoCodecConfig codecConfigNack(120, "VP8", constraints); |
975 | 0 | codecConfigNack.mNackFbTypes.push_back(""); |
976 | 0 | codecs.push_back(&codecConfigNack); |
977 | 0 |
|
978 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
979 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
980 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
981 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_type, 120); |
982 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_name, "VP8"); |
983 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.local_ssrc, 0U); |
984 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.remote_ssrc, 0U); |
985 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
986 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.nack.rtp_history_ms, 1000); |
987 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.remb); |
988 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.tmmbr); |
989 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqPliRtcp); |
990 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.ulpfec_payload_type, -1); |
991 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_payload_type, -1); |
992 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_rtx_payload_type, -1); |
993 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtx.size(), 0U); |
994 | 0 |
|
995 | 0 | // Remb |
996 | 0 | codecs.clear(); |
997 | 0 | VideoCodecConfig codecConfigRemb(120, "VP8", constraints); |
998 | 0 | codecConfigRemb.mRembFbSet = true; |
999 | 0 | codecs.push_back(&codecConfigRemb); |
1000 | 0 |
|
1001 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
1002 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1003 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
1004 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_type, 120); |
1005 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_name, "VP8"); |
1006 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.local_ssrc, 0U); |
1007 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.remote_ssrc, 0U); |
1008 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
1009 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.nack.rtp_history_ms, 0); |
1010 | 0 | ASSERT_TRUE(mCall->mVideoReceiveConfig.rtp.remb); |
1011 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.tmmbr); |
1012 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqPliRtcp); |
1013 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.ulpfec_payload_type, -1); |
1014 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_payload_type, -1); |
1015 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_rtx_payload_type, -1); |
1016 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtx.size(), 0U); |
1017 | 0 |
|
1018 | 0 | // Tmmbr |
1019 | 0 | codecs.clear(); |
1020 | 0 | VideoCodecConfig codecConfigTmmbr(120, "VP8", constraints); |
1021 | 0 | codecConfigTmmbr.mCcmFbTypes.push_back("tmmbr"); |
1022 | 0 | codecs.push_back(&codecConfigTmmbr); |
1023 | 0 |
|
1024 | 0 | ec = mVideoConduit->ConfigureRecvMediaCodecs(codecs); |
1025 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1026 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders.size(), 1U); |
1027 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_type, 120); |
1028 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.decoders[0].payload_name, "VP8"); |
1029 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.local_ssrc, 0U); |
1030 | 0 | ASSERT_NE(mCall->mVideoReceiveConfig.rtp.remote_ssrc, 0U); |
1031 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
1032 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.nack.rtp_history_ms, 0); |
1033 | 0 | ASSERT_FALSE(mCall->mVideoReceiveConfig.rtp.remb); |
1034 | 0 | ASSERT_TRUE(mCall->mVideoReceiveConfig.rtp.tmmbr); |
1035 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.keyframe_method, webrtc::kKeyFrameReqPliRtcp); |
1036 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.ulpfec_payload_type, -1); |
1037 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_payload_type, -1); |
1038 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.ulpfec.red_rtx_payload_type, -1); |
1039 | 0 | ASSERT_EQ(mCall->mVideoReceiveConfig.rtp.rtx.size(), 0U); |
1040 | 0 | } |
1041 | | |
1042 | | TEST_F(VideoConduitTest, TestReconfigureSendMediaCodec) |
1043 | 0 | { |
1044 | 0 | MediaConduitErrorCode ec; |
1045 | 0 | EncodingConstraints constraints; |
1046 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
1047 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
1048 | 0 |
|
1049 | 0 | WebrtcGmpPCHandleSetter setter("hi there"); |
1050 | 0 |
|
1051 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
1052 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
1053 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
1054 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1055 | 0 |
|
1056 | 0 | // Defaults |
1057 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
1058 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1059 | 0 | mVideoConduit->StartTransmitting(); |
1060 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.payload_name, "VP8"); |
1061 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.payload_type, 120); |
1062 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.internal_source, false); |
1063 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.full_overuse_time, false); |
1064 | 0 | ASSERT_NE(mCall->mVideoSendConfig.encoder_settings.encoder, nullptr); |
1065 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
1066 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.max_packet_size, kVideoMtu); |
1067 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.content_type, |
1068 | 0 | VideoEncoderConfig::ContentType::kRealtimeVideo); |
1069 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.min_transmit_bitrate_bps, 0); |
1070 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.max_bitrate_bps, 0); |
1071 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.number_of_streams, 1U); |
1072 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.resolution_divisor, 1); |
1073 | 0 | mVideoConduit->StopTransmitting(); |
1074 | 0 |
|
1075 | 0 | // FEC |
1076 | 0 | VideoCodecConfig codecConfigFEC(120, "VP8", constraints); |
1077 | 0 | codecConfigFEC.mSimulcastEncodings.push_back(encoding); |
1078 | 0 | codecConfigFEC.mFECFbSet = true; |
1079 | 0 | codecConfigFEC.mNackFbTypes.push_back(""); |
1080 | 0 | codecConfigFEC.mULPFECPayloadType = 1; |
1081 | 0 | codecConfigFEC.mREDPayloadType = 2; |
1082 | 0 | codecConfigFEC.mREDRTXPayloadType = 3; |
1083 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigFEC); |
1084 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1085 | 0 | mVideoConduit->StartTransmitting(); |
1086 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.ulpfec.ulpfec_payload_type, codecConfigFEC.mULPFECPayloadType); |
1087 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.ulpfec.red_payload_type, codecConfigFEC.mREDPayloadType); |
1088 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.ulpfec.red_rtx_payload_type, codecConfigFEC.mREDRTXPayloadType); |
1089 | 0 | mVideoConduit->StopTransmitting(); |
1090 | 0 |
|
1091 | 0 | // H264 |
1092 | 0 | VideoCodecConfig codecConfigH264(120, "H264", constraints); |
1093 | 0 | codecConfigH264.mSimulcastEncodings.push_back(encoding); |
1094 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigH264); |
1095 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1096 | 0 | mVideoConduit->StartTransmitting(); |
1097 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.payload_name, "H264"); |
1098 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.payload_type, 120); |
1099 | 0 | mVideoConduit->StopTransmitting(); |
1100 | 0 |
|
1101 | 0 | // TIAS |
1102 | 0 | VideoCodecConfig codecConfigTias(120, "VP8", constraints); |
1103 | 0 | codecConfigTias.mSimulcastEncodings.push_back(encoding); |
1104 | 0 | codecConfigTias.mTias = 1000000; |
1105 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigTias); |
1106 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1107 | 0 | mVideoConduit->StartTransmitting(); |
1108 | 0 | SendVideoFrame(1280, 720, 1); |
1109 | 0 |
|
1110 | 0 | videoStreams = mCall->CreateEncoderStreams(1280, 720); |
1111 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
1112 | 0 | ASSERT_EQ(videoStreams[0].min_bitrate_bps, 600000); |
1113 | 0 | ASSERT_EQ(videoStreams[0].target_bitrate_bps, 800000); |
1114 | 0 | ASSERT_EQ(videoStreams[0].max_bitrate_bps, 1000000); |
1115 | 0 | mVideoConduit->StopTransmitting(); |
1116 | 0 |
|
1117 | 0 | // MaxBr |
1118 | 0 | VideoCodecConfig codecConfigMaxBr(120, "VP8", constraints); |
1119 | 0 | encoding.constraints.maxBr = 50000; |
1120 | 0 | codecConfigMaxBr.mSimulcastEncodings.push_back(encoding); |
1121 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigMaxBr); |
1122 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1123 | 0 | mVideoConduit->StartTransmitting(); |
1124 | 0 | SendVideoFrame(1280, 720, 1); |
1125 | 0 | videoStreams = mCall->CreateEncoderStreams(1280, 720); |
1126 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
1127 | 0 | ASSERT_LE(videoStreams[0].min_bitrate_bps, 50000); |
1128 | 0 | ASSERT_LE(videoStreams[0].target_bitrate_bps, 50000); |
1129 | 0 | ASSERT_EQ(videoStreams[0].max_bitrate_bps, 50000); |
1130 | 0 | mVideoConduit->StopTransmitting(); |
1131 | 0 |
|
1132 | 0 | // MaxFs |
1133 | 0 | VideoCodecConfig codecConfigMaxFs(120, "VP8", constraints); |
1134 | 0 | codecConfigMaxFs.mEncodingConstraints.maxFs = 3600; |
1135 | 0 | encoding.constraints.maxBr = 0; |
1136 | 0 | codecConfigMaxFs.mSimulcastEncodings.push_back(encoding); |
1137 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigMaxFs); |
1138 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1139 | 0 |
|
1140 | 0 | UniquePtr<MockVideoSink> sink(new MockVideoSink()); |
1141 | 0 | rtc::VideoSinkWants wants; |
1142 | 0 | mVideoConduit->AddOrUpdateSink(sink.get(), wants); |
1143 | 0 |
|
1144 | 0 | mVideoConduit->StartTransmitting(); |
1145 | 0 | SendVideoFrame(1280, 720, 1); |
1146 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 1280); |
1147 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 720); |
1148 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 1000U); |
1149 | 0 | ASSERT_EQ(sink->mOnFrameCount, 1U); |
1150 | 0 |
|
1151 | 0 | SendVideoFrame(640, 360, 2); |
1152 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 640); |
1153 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 360); |
1154 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 2000U); |
1155 | 0 | ASSERT_EQ(sink->mOnFrameCount, 2U); |
1156 | 0 |
|
1157 | 0 | SendVideoFrame(1920, 1280, 3); |
1158 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 960); |
1159 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 640); |
1160 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 3000U); |
1161 | 0 | ASSERT_EQ(sink->mOnFrameCount, 3U); |
1162 | 0 | mVideoConduit->StopTransmitting(); |
1163 | 0 | } |
1164 | | |
1165 | | TEST_F(VideoConduitTest, TestReconfigureSendMediaCodecWhileTransmitting) |
1166 | 0 | { |
1167 | 0 | MediaConduitErrorCode ec; |
1168 | 0 | EncodingConstraints constraints; |
1169 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
1170 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
1171 | 0 |
|
1172 | 0 | WebrtcGmpPCHandleSetter setter("hi there"); |
1173 | 0 |
|
1174 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
1175 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
1176 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
1177 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1178 | 0 |
|
1179 | 0 | // Defaults |
1180 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
1181 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1182 | 0 | mVideoConduit->StartTransmitting(); |
1183 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.payload_name, "VP8"); |
1184 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.payload_type, 120); |
1185 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.internal_source, false); |
1186 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.encoder_settings.full_overuse_time, false); |
1187 | 0 | ASSERT_NE(mCall->mVideoSendConfig.encoder_settings.encoder, nullptr); |
1188 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.rtcp_mode, webrtc::RtcpMode::kCompound); |
1189 | 0 | ASSERT_EQ(mCall->mVideoSendConfig.rtp.max_packet_size, kVideoMtu); |
1190 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.content_type, |
1191 | 0 | VideoEncoderConfig::ContentType::kRealtimeVideo); |
1192 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.min_transmit_bitrate_bps, 0); |
1193 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.max_bitrate_bps, 0); |
1194 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.number_of_streams, 1U); |
1195 | 0 | ASSERT_EQ(mCall->mCurrentVideoSendStream->mEncoderConfig.resolution_divisor, 1); |
1196 | 0 |
|
1197 | 0 | // Changing these parameters should not require a call to StartTransmitting |
1198 | 0 | // for the changes to take effect. |
1199 | 0 |
|
1200 | 0 | // TIAS |
1201 | 0 | VideoCodecConfig codecConfigTias(120, "VP8", constraints); |
1202 | 0 | codecConfigTias.mSimulcastEncodings.push_back(encoding); |
1203 | 0 | codecConfigTias.mTias = 1000000; |
1204 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigTias); |
1205 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1206 | 0 | SendVideoFrame(1280, 720, 1); |
1207 | 0 |
|
1208 | 0 | videoStreams = mCall->CreateEncoderStreams(1280, 720); |
1209 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
1210 | 0 | ASSERT_EQ(videoStreams[0].min_bitrate_bps, 600000); |
1211 | 0 | ASSERT_EQ(videoStreams[0].target_bitrate_bps, 800000); |
1212 | 0 | ASSERT_EQ(videoStreams[0].max_bitrate_bps, 1000000); |
1213 | 0 |
|
1214 | 0 | // MaxBr |
1215 | 0 | VideoCodecConfig codecConfigMaxBr(120, "VP8", constraints); |
1216 | 0 | encoding.constraints.maxBr = 50000; |
1217 | 0 | codecConfigMaxBr.mSimulcastEncodings.push_back(encoding); |
1218 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigMaxBr); |
1219 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1220 | 0 | SendVideoFrame(1280, 720, 1); |
1221 | 0 | videoStreams = mCall->CreateEncoderStreams(1280, 720); |
1222 | 0 | ASSERT_EQ(videoStreams.size(), 1U); |
1223 | 0 | ASSERT_LE(videoStreams[0].min_bitrate_bps, 50000); |
1224 | 0 | ASSERT_LE(videoStreams[0].target_bitrate_bps, 50000); |
1225 | 0 | ASSERT_EQ(videoStreams[0].max_bitrate_bps, 50000); |
1226 | 0 |
|
1227 | 0 | // MaxFs |
1228 | 0 | VideoCodecConfig codecConfigMaxFs(120, "VP8", constraints); |
1229 | 0 | codecConfigMaxFs.mEncodingConstraints.maxFs = 3600; |
1230 | 0 | encoding.constraints.maxBr = 0; |
1231 | 0 | codecConfigMaxFs.mSimulcastEncodings.push_back(encoding); |
1232 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigMaxFs); |
1233 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1234 | 0 |
|
1235 | 0 | UniquePtr<MockVideoSink> sink(new MockVideoSink()); |
1236 | 0 | rtc::VideoSinkWants wants; |
1237 | 0 | mVideoConduit->AddOrUpdateSink(sink.get(), wants); |
1238 | 0 |
|
1239 | 0 | SendVideoFrame(1280, 720, 1); |
1240 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 1280); |
1241 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 720); |
1242 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 1000U); |
1243 | 0 | ASSERT_EQ(sink->mOnFrameCount, 1U); |
1244 | 0 |
|
1245 | 0 | SendVideoFrame(640, 360, 2); |
1246 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 640); |
1247 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 360); |
1248 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 2000U); |
1249 | 0 | ASSERT_EQ(sink->mOnFrameCount, 2U); |
1250 | 0 |
|
1251 | 0 | SendVideoFrame(1920, 1280, 3); |
1252 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 960); |
1253 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 640); |
1254 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 3000U); |
1255 | 0 | ASSERT_EQ(sink->mOnFrameCount, 3U); |
1256 | 0 |
|
1257 | 0 | // ScaleResolutionDownBy |
1258 | 0 | VideoCodecConfig codecConfigScaleDownBy(120, "VP8", constraints); |
1259 | 0 | encoding.constraints.maxFs = 0; |
1260 | 0 | encoding.constraints.scaleDownBy = 3.7; |
1261 | 0 | codecConfigScaleDownBy.mSimulcastEncodings.push_back(encoding); |
1262 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigScaleDownBy); |
1263 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1264 | 0 |
|
1265 | 0 | SendVideoFrame(1280, 720, 4); |
1266 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 320); |
1267 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 180); |
1268 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 4000U); |
1269 | 0 | ASSERT_EQ(sink->mOnFrameCount, 4U); |
1270 | 0 |
|
1271 | 0 | codecConfigScaleDownBy.mSimulcastEncodings[0].constraints.scaleDownBy = 1.3; |
1272 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfigScaleDownBy); |
1273 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1274 | 0 |
|
1275 | 0 | SendVideoFrame(641, 359, 5); |
1276 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 480); |
1277 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 267); |
1278 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 5000U); |
1279 | 0 | ASSERT_EQ(sink->mOnFrameCount, 5U); |
1280 | 0 |
|
1281 | 0 | mVideoConduit->StopTransmitting(); |
1282 | 0 | } |
1283 | | |
1284 | | TEST_F(VideoConduitTest, TestVideoEncode) |
1285 | 0 | { |
1286 | 0 | MediaConduitErrorCode ec; |
1287 | 0 | EncodingConstraints constraints; |
1288 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
1289 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
1290 | 0 |
|
1291 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
1292 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
1293 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
1294 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1295 | 0 |
|
1296 | 0 | UniquePtr<MockVideoSink> sink(new MockVideoSink()); |
1297 | 0 | rtc::VideoSinkWants wants; |
1298 | 0 | mVideoConduit->AddOrUpdateSink(sink.get(), wants); |
1299 | 0 |
|
1300 | 0 | mVideoConduit->StartTransmitting(); |
1301 | 0 | SendVideoFrame(1280, 720, 1); |
1302 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 1280); |
1303 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 720); |
1304 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 1000U); |
1305 | 0 | ASSERT_EQ(sink->mOnFrameCount, 1U); |
1306 | 0 |
|
1307 | 0 | SendVideoFrame(640, 360, 2); |
1308 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 640); |
1309 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 360); |
1310 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 2000U); |
1311 | 0 | ASSERT_EQ(sink->mOnFrameCount, 2U); |
1312 | 0 |
|
1313 | 0 | SendVideoFrame(1920, 1280, 3); |
1314 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 1920); |
1315 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 1280); |
1316 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 3000U); |
1317 | 0 | ASSERT_EQ(sink->mOnFrameCount, 3U); |
1318 | 0 |
|
1319 | 0 | mVideoConduit->StopTransmitting(); |
1320 | 0 | mVideoConduit->RemoveSink(sink.get()); |
1321 | 0 | } |
1322 | | |
1323 | | TEST_F(VideoConduitTest, TestVideoEncodeMaxFs) |
1324 | 0 | { |
1325 | 0 | MediaConduitErrorCode ec; |
1326 | 0 | EncodingConstraints constraints; |
1327 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
1328 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
1329 | 0 |
|
1330 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
1331 | 0 | codecConfig.mEncodingConstraints.maxFs = 3600; |
1332 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
1333 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
1334 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1335 | 0 |
|
1336 | 0 | UniquePtr<MockVideoSink> sink(new MockVideoSink()); |
1337 | 0 | rtc::VideoSinkWants wants; |
1338 | 0 | mVideoConduit->AddOrUpdateSink(sink.get(), wants); |
1339 | 0 |
|
1340 | 0 | mVideoConduit->StartTransmitting(); |
1341 | 0 | SendVideoFrame(1280, 720, 1); |
1342 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 1280); |
1343 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 720); |
1344 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 1000U); |
1345 | 0 | ASSERT_EQ(sink->mOnFrameCount, 1U); |
1346 | 0 |
|
1347 | 0 | SendVideoFrame(640, 360, 2); |
1348 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 640); |
1349 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 360); |
1350 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 2000U); |
1351 | 0 | ASSERT_EQ(sink->mOnFrameCount, 2U); |
1352 | 0 |
|
1353 | 0 | SendVideoFrame(1920, 1280, 3); |
1354 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 960); |
1355 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 640); |
1356 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 3000U); |
1357 | 0 | ASSERT_EQ(sink->mOnFrameCount, 3U); |
1358 | 0 |
|
1359 | 0 | // maxFs should not force pixel count above what a sink has requested. |
1360 | 0 | // We set 3600 macroblocks (16x16 pixels), so we request 3500 here. |
1361 | 0 | wants.max_pixel_count = rtc::Optional<int>(3500*16*16); |
1362 | 0 | mVideoConduit->AddOrUpdateSink(sink.get(), wants); |
1363 | 0 |
|
1364 | 0 | SendVideoFrame(1280, 720, 4); |
1365 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 960); |
1366 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 540); |
1367 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 4000U); |
1368 | 0 | ASSERT_EQ(sink->mOnFrameCount, 4U); |
1369 | 0 |
|
1370 | 0 | SendVideoFrame(640, 360, 5); |
1371 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 640); |
1372 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 360); |
1373 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 5000U); |
1374 | 0 | ASSERT_EQ(sink->mOnFrameCount, 5U); |
1375 | 0 |
|
1376 | 0 | SendVideoFrame(1920, 1280, 6); |
1377 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 960); |
1378 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 640); |
1379 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 6000U); |
1380 | 0 | ASSERT_EQ(sink->mOnFrameCount, 6U); |
1381 | 0 |
|
1382 | 0 | mVideoConduit->StopTransmitting(); |
1383 | 0 | mVideoConduit->RemoveSink(sink.get()); |
1384 | 0 | } |
1385 | | |
1386 | | // Disabled: See Bug 1420493 |
1387 | | TEST_F(VideoConduitTest, DISABLED_TestVideoEncodeMaxWidthAndHeight) |
1388 | 0 | { |
1389 | 0 | MediaConduitErrorCode ec; |
1390 | 0 | EncodingConstraints constraints; |
1391 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
1392 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
1393 | 0 |
|
1394 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
1395 | 0 | codecConfig.mEncodingConstraints.maxWidth = 1280; |
1396 | 0 | codecConfig.mEncodingConstraints.maxHeight = 720; |
1397 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
1398 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
1399 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1400 | 0 |
|
1401 | 0 | UniquePtr<MockVideoSink> sink(new MockVideoSink()); |
1402 | 0 | rtc::VideoSinkWants wants; |
1403 | 0 | mVideoConduit->AddOrUpdateSink(sink.get(), wants); |
1404 | 0 |
|
1405 | 0 | mVideoConduit->StartTransmitting(); |
1406 | 0 | SendVideoFrame(1280, 720, 1); |
1407 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 1280); |
1408 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 720); |
1409 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 1000U); |
1410 | 0 | ASSERT_EQ(sink->mOnFrameCount, 1U); |
1411 | 0 |
|
1412 | 0 | SendVideoFrame(640, 360, 2); |
1413 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 640); |
1414 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 360); |
1415 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 2000U); |
1416 | 0 | ASSERT_EQ(sink->mOnFrameCount, 2U); |
1417 | 0 |
|
1418 | 0 | SendVideoFrame(1920, 1280, 3); |
1419 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 1080); |
1420 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 720); |
1421 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 3000U); |
1422 | 0 | ASSERT_EQ(sink->mOnFrameCount, 3U); |
1423 | 0 |
|
1424 | 0 | mVideoConduit->StopTransmitting(); |
1425 | 0 | mVideoConduit->RemoveSink(sink.get()); |
1426 | 0 | } |
1427 | | |
1428 | | TEST_F(VideoConduitTest, TestVideoEncodeScaleResolutionBy) |
1429 | 0 | { |
1430 | 0 | MediaConduitErrorCode ec; |
1431 | 0 | EncodingConstraints constraints; |
1432 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
1433 | 0 | encoding.constraints.scaleDownBy = 2; |
1434 | 0 | std::vector<webrtc::VideoStream> videoStreams; |
1435 | 0 |
|
1436 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
1437 | 0 | codecConfig.mEncodingConstraints.maxFs = 3600; |
1438 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
1439 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
1440 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1441 | 0 |
|
1442 | 0 | UniquePtr<MockVideoSink> sink(new MockVideoSink()); |
1443 | 0 | rtc::VideoSinkWants wants; |
1444 | 0 | mVideoConduit->AddOrUpdateSink(sink.get(), wants); |
1445 | 0 |
|
1446 | 0 | mVideoConduit->StartTransmitting(); |
1447 | 0 | SendVideoFrame(1280, 720, 1); |
1448 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 640); |
1449 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 360); |
1450 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 1000U); |
1451 | 0 | ASSERT_EQ(sink->mOnFrameCount, 1U); |
1452 | 0 |
|
1453 | 0 | SendVideoFrame(640, 360, 2); |
1454 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 320); |
1455 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 180); |
1456 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 2000U); |
1457 | 0 | ASSERT_EQ(sink->mOnFrameCount, 2U); |
1458 | 0 | mVideoConduit->StopTransmitting(); |
1459 | 0 | mVideoConduit->RemoveSink(sink.get()); |
1460 | 0 | } |
1461 | | |
1462 | | TEST_F(VideoConduitTest, TestVideoEncodeSimulcastScaleResolutionBy) |
1463 | 0 | { |
1464 | 0 | std::vector<unsigned int> ssrcs = {42, 43, 44}; |
1465 | 0 | mVideoConduit->SetLocalSSRCs(ssrcs); |
1466 | 0 |
|
1467 | 0 | MediaConduitErrorCode ec; |
1468 | 0 | EncodingConstraints constraints; |
1469 | 0 | VideoCodecConfig::SimulcastEncoding encoding; |
1470 | 0 | VideoCodecConfig::SimulcastEncoding encoding2; |
1471 | 0 | VideoCodecConfig::SimulcastEncoding encoding3; |
1472 | 0 | encoding.constraints.scaleDownBy = 2; |
1473 | 0 | encoding2.constraints.scaleDownBy = 3; |
1474 | 0 | encoding3.constraints.scaleDownBy = 4; |
1475 | 0 |
|
1476 | 0 | VideoCodecConfig codecConfig(120, "VP8", constraints); |
1477 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding); |
1478 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding2); |
1479 | 0 | codecConfig.mSimulcastEncodings.push_back(encoding3); |
1480 | 0 | ec = mVideoConduit->ConfigureSendMediaCodec(&codecConfig); |
1481 | 0 | ASSERT_EQ(ec, kMediaConduitNoError); |
1482 | 0 |
|
1483 | 0 | UniquePtr<MockVideoSink> sink(new MockVideoSink()); |
1484 | 0 | rtc::VideoSinkWants wants; |
1485 | 0 | mVideoConduit->AddOrUpdateSink(sink.get(), wants); |
1486 | 0 |
|
1487 | 0 | mVideoConduit->StartTransmitting(); |
1488 | 0 | SendVideoFrame(640, 480, 1); |
1489 | 0 | // Check actually configured streams in encoder sink. |
1490 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 320); |
1491 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 240); |
1492 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 1000U); |
1493 | 0 | ASSERT_EQ(sink->mOnFrameCount, 1U); |
1494 | 0 |
|
1495 | 0 | SendVideoFrame(1280, 720, 2); |
1496 | 0 | ASSERT_EQ(sink->mVideoFrame.width(), 640); |
1497 | 0 | ASSERT_EQ(sink->mVideoFrame.height(), 352); |
1498 | 0 | ASSERT_EQ(sink->mVideoFrame.timestamp_us(), 2000U); |
1499 | 0 | ASSERT_EQ(sink->mOnFrameCount, 2U); |
1500 | 0 | mVideoConduit->StopTransmitting(); |
1501 | 0 | mVideoConduit->RemoveSink(sink.get()); |
1502 | 0 | } |
1503 | | |
1504 | | } // End namespace test. |