OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 const cricket::VideoFormat*) { | 119 const cricket::VideoFormat*) { |
120 } | 120 } |
121 | 121 |
122 void TriggerMediaFrame(uint32_t ssrc, | 122 void TriggerMediaFrame(uint32_t ssrc, |
123 cricket::VideoFrame* frame, | 123 cricket::VideoFrame* frame, |
124 bool* drop_frame) { | 124 bool* drop_frame) { |
125 T::SignalMediaFrame(ssrc, frame, drop_frame); | 125 T::SignalMediaFrame(ssrc, frame, drop_frame); |
126 } | 126 } |
127 }; | 127 }; |
128 | 128 |
129 template<class E> | |
130 class VideoEngineTest : public testing::Test { | |
131 protected: | |
132 // Tests starting and stopping the engine, and creating a channel. | |
133 void StartupShutdown() { | |
134 EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); | |
135 cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL); | |
136 EXPECT_TRUE(channel != NULL); | |
137 delete channel; | |
138 engine_.Terminate(); | |
139 } | |
140 | |
141 void ConstrainNewCodecBody() { | |
142 cricket::VideoCodec empty, in, out; | |
143 cricket::VideoCodec max_settings(engine_.codecs()[0].id, | |
144 engine_.codecs()[0].name, | |
145 1280, 800, 30, 0); | |
146 | |
147 // set max settings of 1280x800x30 | |
148 EXPECT_TRUE(engine_.SetDefaultEncoderConfig( | |
149 cricket::VideoEncoderConfig(max_settings))); | |
150 | |
151 // don't constrain the max resolution | |
152 in = max_settings; | |
153 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
154 EXPECT_PRED2(IsEqualCodec, out, in); | |
155 | |
156 // constrain resolution greater than the max and wider aspect, | |
157 // picking best aspect (16:10) | |
158 in.width = 1380; | |
159 in.height = 800; | |
160 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
161 EXPECT_PRED4(IsEqualRes, out, 1280, 720, 30); | |
162 | |
163 // constrain resolution greater than the max and narrow aspect, | |
164 // picking best aspect (16:9) | |
165 in.width = 1280; | |
166 in.height = 740; | |
167 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
168 EXPECT_PRED4(IsEqualRes, out, 1280, 720, 30); | |
169 | |
170 // constrain resolution greater than the max, picking equal aspect (4:3) | |
171 in.width = 1280; | |
172 in.height = 960; | |
173 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
174 EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30); | |
175 | |
176 // constrain resolution greater than the max, picking equal aspect (16:10) | |
177 in.width = 1280; | |
178 in.height = 800; | |
179 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
180 EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30); | |
181 | |
182 // reduce max settings to 640x480x30 | |
183 max_settings.width = 640; | |
184 max_settings.height = 480; | |
185 EXPECT_TRUE(engine_.SetDefaultEncoderConfig( | |
186 cricket::VideoEncoderConfig(max_settings))); | |
187 | |
188 // don't constrain the max resolution | |
189 in = max_settings; | |
190 in.width = 640; | |
191 in.height = 480; | |
192 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
193 EXPECT_PRED2(IsEqualCodec, out, in); | |
194 | |
195 // keep 16:10 if they request it | |
196 in.height = 400; | |
197 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
198 EXPECT_PRED2(IsEqualCodec, out, in); | |
199 | |
200 // don't constrain lesser 4:3 resolutions | |
201 in.width = 320; | |
202 in.height = 240; | |
203 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
204 EXPECT_PRED2(IsEqualCodec, out, in); | |
205 | |
206 // don't constrain lesser 16:10 resolutions | |
207 in.width = 320; | |
208 in.height = 200; | |
209 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
210 EXPECT_PRED2(IsEqualCodec, out, in); | |
211 | |
212 // requested resolution of 0x0 succeeds | |
213 in.width = 0; | |
214 in.height = 0; | |
215 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
216 EXPECT_PRED2(IsEqualCodec, out, in); | |
217 | |
218 // constrain resolution lesser than the max and wider aspect, | |
219 // picking best aspect (16:9) | |
220 in.width = 350; | |
221 in.height = 201; | |
222 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
223 EXPECT_PRED4(IsEqualRes, out, 320, 180, 30); | |
224 | |
225 // constrain resolution greater than the max and narrow aspect, | |
226 // picking best aspect (4:3) | |
227 in.width = 350; | |
228 in.height = 300; | |
229 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
230 EXPECT_PRED4(IsEqualRes, out, 320, 240, 30); | |
231 | |
232 // constrain resolution greater than the max and wider aspect, | |
233 // picking best aspect (16:9) | |
234 in.width = 1380; | |
235 in.height = 800; | |
236 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
237 EXPECT_PRED4(IsEqualRes, out, 640, 360, 30); | |
238 | |
239 // constrain resolution greater than the max and narrow aspect, | |
240 // picking best aspect (4:3) | |
241 in.width = 1280; | |
242 in.height = 900; | |
243 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
244 EXPECT_PRED4(IsEqualRes, out, 640, 480, 30); | |
245 | |
246 // constrain resolution greater than the max, picking equal aspect (4:3) | |
247 in.width = 1280; | |
248 in.height = 960; | |
249 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
250 EXPECT_PRED4(IsEqualRes, out, 640, 480, 30); | |
251 | |
252 // constrain resolution greater than the max, picking equal aspect (16:10) | |
253 in.width = 1280; | |
254 in.height = 800; | |
255 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
256 EXPECT_PRED4(IsEqualRes, out, 640, 400, 30); | |
257 | |
258 // constrain res & fps greater than the max | |
259 in.framerate = 50; | |
260 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
261 EXPECT_PRED4(IsEqualRes, out, 640, 400, 30); | |
262 | |
263 // reduce max settings to 160x100x10 | |
264 max_settings.width = 160; | |
265 max_settings.height = 100; | |
266 max_settings.framerate = 10; | |
267 EXPECT_TRUE(engine_.SetDefaultEncoderConfig( | |
268 cricket::VideoEncoderConfig(max_settings))); | |
269 | |
270 // constrain res & fps to new max | |
271 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
272 EXPECT_PRED4(IsEqualRes, out, 160, 100, 10); | |
273 | |
274 // allow 4:3 "comparable" resolutions | |
275 in.width = 160; | |
276 in.height = 120; | |
277 in.framerate = 10; | |
278 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
279 EXPECT_PRED4(IsEqualRes, out, 160, 120, 10); | |
280 } | |
281 | |
282 // This is the new way of constraining codec size, where we no longer maintain | |
283 // a list of the supported formats. Instead, CanSendCodec will just downscale | |
284 // the resolution by 2 until the width is below clamp. | |
285 void ConstrainNewCodec2Body() { | |
286 cricket::VideoCodec empty, in, out; | |
287 cricket::VideoCodec max_settings(engine_.codecs()[0].id, | |
288 engine_.codecs()[0].name, | |
289 1280, 800, 30, 0); | |
290 | |
291 // Set max settings of 1280x800x30 | |
292 EXPECT_TRUE(engine_.SetDefaultEncoderConfig( | |
293 cricket::VideoEncoderConfig(max_settings))); | |
294 | |
295 // Don't constrain the max resolution | |
296 in = max_settings; | |
297 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
298 EXPECT_PRED2(IsEqualCodec, out, in); | |
299 | |
300 // Constrain resolution greater than the max width. | |
301 in.width = 1380; | |
302 in.height = 800; | |
303 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
304 EXPECT_PRED4(IsEqualRes, out, 690, 400, 30); | |
305 | |
306 // Don't constrain resolution when only the height is greater than max. | |
307 in.width = 960; | |
308 in.height = 1280; | |
309 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
310 EXPECT_PRED4(IsEqualRes, out, 960, 1280, 30); | |
311 | |
312 // Don't constrain smaller format. | |
313 in.width = 640; | |
314 in.height = 480; | |
315 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); | |
316 EXPECT_PRED4(IsEqualRes, out, 640, 480, 30); | |
317 } | |
318 | |
319 void ConstrainRunningCodecBody() { | |
320 cricket::VideoCodec in, out, current; | |
321 cricket::VideoCodec max_settings(engine_.codecs()[0].id, | |
322 engine_.codecs()[0].name, | |
323 1280, 800, 30, 0); | |
324 | |
325 // set max settings of 1280x960x30 | |
326 EXPECT_TRUE(engine_.SetDefaultEncoderConfig( | |
327 cricket::VideoEncoderConfig(max_settings))); | |
328 | |
329 // establish current call at 1280x800x30 (16:10) | |
330 current = max_settings; | |
331 current.height = 800; | |
332 | |
333 // Don't constrain current resolution | |
334 in = current; | |
335 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
336 EXPECT_PRED2(IsEqualCodec, out, in); | |
337 | |
338 // requested resolution of 0x0 succeeds | |
339 in.width = 0; | |
340 in.height = 0; | |
341 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
342 EXPECT_PRED2(IsEqualCodec, out, in); | |
343 | |
344 // Reduce an intermediate resolution down to the next lowest one, preserving | |
345 // aspect ratio. | |
346 in.width = 800; | |
347 in.height = 600; | |
348 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
349 EXPECT_PRED4(IsEqualRes, out, 640, 400, 30); | |
350 | |
351 // Clamping by aspect ratio, but still never return a dimension higher than | |
352 // requested. | |
353 in.width = 1280; | |
354 in.height = 720; | |
355 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
356 EXPECT_PRED4(IsEqualRes, out, 1280, 720, 30); | |
357 | |
358 in.width = 1279; | |
359 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
360 EXPECT_PRED4(IsEqualRes, out, 960, 600, 30); | |
361 | |
362 in.width = 1281; | |
363 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
364 EXPECT_PRED4(IsEqualRes, out, 1280, 720, 30); | |
365 | |
366 // Clamp large resolutions down, always preserving aspect | |
367 in.width = 1920; | |
368 in.height = 1080; | |
369 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
370 EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30); | |
371 | |
372 in.width = 1921; | |
373 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
374 EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30); | |
375 | |
376 in.width = 1919; | |
377 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
378 EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30); | |
379 | |
380 // reduce max settings to 640x480x30 | |
381 max_settings.width = 640; | |
382 max_settings.height = 480; | |
383 EXPECT_TRUE(engine_.SetDefaultEncoderConfig( | |
384 cricket::VideoEncoderConfig(max_settings))); | |
385 | |
386 // establish current call at 640x400x30 (16:10) | |
387 current = max_settings; | |
388 current.height = 400; | |
389 | |
390 // Don't constrain current resolution | |
391 in = current; | |
392 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
393 EXPECT_PRED2(IsEqualCodec, out, in); | |
394 | |
395 // requested resolution of 0x0 succeeds | |
396 in.width = 0; | |
397 in.height = 0; | |
398 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
399 EXPECT_PRED2(IsEqualCodec, out, in); | |
400 | |
401 // Reduce an intermediate resolution down to the next lowest one, preserving | |
402 // aspect ratio. | |
403 in.width = 400; | |
404 in.height = 300; | |
405 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
406 EXPECT_PRED4(IsEqualRes, out, 320, 200, 30); | |
407 | |
408 // Clamping by aspect ratio, but still never return a dimension higher than | |
409 // requested. | |
410 in.width = 640; | |
411 in.height = 360; | |
412 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
413 EXPECT_PRED4(IsEqualRes, out, 640, 360, 30); | |
414 | |
415 in.width = 639; | |
416 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
417 EXPECT_PRED4(IsEqualRes, out, 480, 300, 30); | |
418 | |
419 in.width = 641; | |
420 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
421 EXPECT_PRED4(IsEqualRes, out, 640, 360, 30); | |
422 | |
423 // Clamp large resolutions down, always preserving aspect | |
424 in.width = 1280; | |
425 in.height = 800; | |
426 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
427 EXPECT_PRED4(IsEqualRes, out, 640, 400, 30); | |
428 | |
429 in.width = 1281; | |
430 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
431 EXPECT_PRED4(IsEqualRes, out, 640, 400, 30); | |
432 | |
433 in.width = 1279; | |
434 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); | |
435 EXPECT_PRED4(IsEqualRes, out, 640, 400, 30); | |
436 | |
437 // Should fail for any that are smaller than our supported formats | |
438 in.width = 80; | |
439 in.height = 80; | |
440 EXPECT_FALSE(engine_.CanSendCodec(in, current, &out)); | |
441 | |
442 in.height = 50; | |
443 EXPECT_FALSE(engine_.CanSendCodec(in, current, &out)); | |
444 } | |
445 | |
446 VideoEngineOverride<E> engine_; | |
447 rtc::scoped_ptr<cricket::FakeVideoCapturer> video_capturer_; | |
448 }; | |
449 | |
450 template<class E, class C> | 129 template<class E, class C> |
451 class VideoMediaChannelTest : public testing::Test, | 130 class VideoMediaChannelTest : public testing::Test, |
452 public sigslot::has_slots<> { | 131 public sigslot::has_slots<> { |
453 protected: | 132 protected: |
454 VideoMediaChannelTest<E, C>() | 133 VideoMediaChannelTest<E, C>() |
455 : call_(webrtc::Call::Create(webrtc::Call::Config())) {} | 134 : call_(webrtc::Call::Create(webrtc::Call::Config())) {} |
456 | 135 |
457 virtual cricket::VideoCodec DefaultCodec() = 0; | 136 virtual cricket::VideoCodec DefaultCodec() = 0; |
458 | 137 |
459 virtual cricket::StreamParams DefaultSendStreamParams() { | 138 virtual cricket::StreamParams DefaultSendStreamParams() { |
(...skipping 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1810 rtc::scoped_ptr<C> channel_; | 1489 rtc::scoped_ptr<C> channel_; |
1811 cricket::FakeNetworkInterface network_interface_; | 1490 cricket::FakeNetworkInterface network_interface_; |
1812 cricket::FakeVideoRenderer renderer_; | 1491 cricket::FakeVideoRenderer renderer_; |
1813 cricket::VideoMediaChannel::Error media_error_; | 1492 cricket::VideoMediaChannel::Error media_error_; |
1814 | 1493 |
1815 // Used by test cases where 2 streams are run on the same channel. | 1494 // Used by test cases where 2 streams are run on the same channel. |
1816 cricket::FakeVideoRenderer renderer2_; | 1495 cricket::FakeVideoRenderer renderer2_; |
1817 }; | 1496 }; |
1818 | 1497 |
1819 #endif // TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT | 1498 #endif // TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT |
OLD | NEW |