blob: 2a762bc274496138461e03789256d07d04b76057 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001// libjingle
2// Copyright 2004 Google Inc. All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice,
8// this list of conditions and the following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation
11// and/or other materials provided with the distribution.
12// 3. The name of the author may not be used to endorse or promote products
13// derived from this software without specific prior written permission.
14//
15// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
wu@webrtc.orgcadf9042013-08-30 21:24:16 +000026#ifndef TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ // NOLINT
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027#define TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_
28
29#include <string>
30#include <vector>
31
32#include "talk/base/bytebuffer.h"
33#include "talk/base/gunit.h"
34#include "talk/base/timeutils.h"
35#include "talk/media/base/fakenetworkinterface.h"
36#include "talk/media/base/fakevideocapturer.h"
37#include "talk/media/base/fakevideorenderer.h"
38#include "talk/media/base/mediachannel.h"
39#include "talk/media/base/streamparams.h"
40
41#ifdef WIN32
42#include <objbase.h> // NOLINT
43#endif
44
45#define EXPECT_FRAME_WAIT(c, w, h, t) \
46 EXPECT_EQ_WAIT((c), renderer_.num_rendered_frames(), (t)); \
47 EXPECT_EQ((w), renderer_.width()); \
48 EXPECT_EQ((h), renderer_.height()); \
49 EXPECT_EQ(0, renderer_.errors()); \
50
51#define EXPECT_FRAME_ON_RENDERER_WAIT(r, c, w, h, t) \
52 EXPECT_EQ_WAIT((c), (r).num_rendered_frames(), (t)); \
53 EXPECT_EQ((w), (r).width()); \
54 EXPECT_EQ((h), (r).height()); \
55 EXPECT_EQ(0, (r).errors()); \
56
wu@webrtc.org9caf2762013-12-11 18:25:07 +000057#define EXPECT_GT_FRAME_ON_RENDERER_WAIT(r, c, w, h, t) \
58 EXPECT_TRUE_WAIT((r).num_rendered_frames() >= (c) && \
59 (w) == (r).width() && \
60 (h) == (r).height(), (t)); \
61 EXPECT_EQ(0, (r).errors()); \
62
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063static const uint32 kTimeout = 5000U;
64static const uint32 kSsrc = 1234u;
65static const uint32 kRtxSsrc = 4321u;
66static const uint32 kSsrcs4[] = {1, 2, 3, 4};
67
68inline bool IsEqualRes(const cricket::VideoCodec& a, int w, int h, int fps) {
69 return a.width == w && a.height == h && a.framerate == fps;
70}
71
72inline bool IsEqualCodec(const cricket::VideoCodec& a,
73 const cricket::VideoCodec& b) {
74 return a.id == b.id && a.name == b.name &&
75 IsEqualRes(a, b.width, b.height, b.framerate);
76}
77
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +000078namespace std {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079inline std::ostream& operator<<(std::ostream& s, const cricket::VideoCodec& c) {
80 s << "{" << c.name << "(" << c.id << "), "
81 << c.width << "x" << c.height << "x" << c.framerate << "}";
82 return s;
83}
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +000084} // namespace std
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085
86inline int TimeBetweenSend(const cricket::VideoCodec& codec) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +000087 return static_cast<int>(
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 cricket::VideoFormat::FpsToInterval(codec.framerate) /
89 talk_base::kNumNanosecsPerMillisec);
90}
91
92// Fake video engine that makes it possible to test enabling and disabling
93// capturer (checking that the engine state is updated and that the capturer
94// is indeed capturing) without having to create a channel. It also makes it
95// possible to test that the media processors are indeed being called when
96// registered.
97template<class T>
98class VideoEngineOverride : public T {
99 public:
100 VideoEngineOverride() {
101 }
102 virtual ~VideoEngineOverride() {
103 }
104 bool is_camera_on() const { return T::GetVideoCapturer()->IsRunning(); }
105 void set_has_senders(bool has_senders) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000106 cricket::VideoCapturer* video_capturer = T::GetVideoCapturer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 if (has_senders) {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000108 video_capturer->SignalVideoFrame.connect(this,
109 &VideoEngineOverride<T>::OnLocalFrame);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110 } else {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000111 video_capturer->SignalVideoFrame.disconnect(this);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112 }
113 }
114 void OnLocalFrame(cricket::VideoCapturer*,
115 const cricket::VideoFrame*) {
116 }
117 void OnLocalFrameFormat(cricket::VideoCapturer*,
118 const cricket::VideoFormat*) {
119 }
120
121 void TriggerMediaFrame(
122 uint32 ssrc, cricket::VideoFrame* frame, bool* drop_frame) {
123 T::SignalMediaFrame(ssrc, frame, drop_frame);
124 }
125};
126
127// Macroes that declare test functions for a given test class, before and after
128// Init().
129// To use, define a test function called FooBody and pass Foo to the macro.
130#define TEST_PRE_VIDEOENGINE_INIT(TestClass, func) \
131 TEST_F(TestClass, func##PreInit) { \
132 func##Body(); \
133 }
134#define TEST_POST_VIDEOENGINE_INIT(TestClass, func) \
135 TEST_F(TestClass, func##PostInit) { \
136 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current())); \
137 func##Body(); \
138 engine_.Terminate(); \
139 }
140
141template<class E>
142class VideoEngineTest : public testing::Test {
143 protected:
144 // Tests starting and stopping the engine, and creating a channel.
145 void StartupShutdown() {
146 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
147 cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL);
148 EXPECT_TRUE(channel != NULL);
149 delete channel;
150 engine_.Terminate();
151 }
152
153#ifdef WIN32
154 // Tests that the COM reference count is not munged by the engine.
155 // Test to make sure LMI does not munge the CoInitialize reference count.
156 void CheckCoInitialize() {
157 // Initial refcount should be 0.
158 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
159
160 // Engine should start even with COM already inited.
161 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
162 engine_.Terminate();
163 // Refcount after terminate should be 1; this tests if it is nonzero.
164 EXPECT_EQ(S_FALSE, CoInitializeEx(NULL, COINIT_MULTITHREADED));
165 // Decrement refcount to (hopefully) 0.
166 CoUninitialize();
167 CoUninitialize();
168
169 // Ensure refcount is 0.
170 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED));
171 CoUninitialize();
172 }
173#endif
174
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 void ConstrainNewCodecBody() {
176 cricket::VideoCodec empty, in, out;
177 cricket::VideoCodec max_settings(engine_.codecs()[0].id,
178 engine_.codecs()[0].name,
179 1280, 800, 30, 0);
180
181 // set max settings of 1280x960x30
182 EXPECT_TRUE(engine_.SetDefaultEncoderConfig(
183 cricket::VideoEncoderConfig(max_settings)));
184
185 // don't constrain the max resolution
186 in = max_settings;
187 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
188 EXPECT_PRED2(IsEqualCodec, out, in);
189
190 // constrain resolution greater than the max and wider aspect,
191 // picking best aspect (16:10)
192 in.width = 1380;
193 in.height = 800;
194 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
195 EXPECT_PRED4(IsEqualRes, out, 1280, 720, 30);
196
197 // constrain resolution greater than the max and narrow aspect,
198 // picking best aspect (16:9)
199 in.width = 1280;
200 in.height = 740;
201 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
202 EXPECT_PRED4(IsEqualRes, out, 1280, 720, 30);
203
204 // constrain resolution greater than the max, picking equal aspect (4:3)
205 in.width = 1280;
206 in.height = 960;
207 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
208 EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30);
209
210 // constrain resolution greater than the max, picking equal aspect (16:10)
211 in.width = 1280;
212 in.height = 800;
213 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
214 EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30);
215
216 // reduce max settings to 640x480x30
217 max_settings.width = 640;
218 max_settings.height = 480;
219 EXPECT_TRUE(engine_.SetDefaultEncoderConfig(
220 cricket::VideoEncoderConfig(max_settings)));
221
222 // don't constrain the max resolution
223 in = max_settings;
224 in.width = 640;
225 in.height = 480;
226 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
227 EXPECT_PRED2(IsEqualCodec, out, in);
228
229 // keep 16:10 if they request it
230 in.height = 400;
231 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
232 EXPECT_PRED2(IsEqualCodec, out, in);
233
234 // don't constrain lesser 4:3 resolutions
235 in.width = 320;
236 in.height = 240;
237 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
238 EXPECT_PRED2(IsEqualCodec, out, in);
239
240 // don't constrain lesser 16:10 resolutions
241 in.width = 320;
242 in.height = 200;
243 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
244 EXPECT_PRED2(IsEqualCodec, out, in);
245
246 // requested resolution of 0x0 succeeds
247 in.width = 0;
248 in.height = 0;
249 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
250 EXPECT_PRED2(IsEqualCodec, out, in);
251
252 // constrain resolution lesser than the max and wider aspect,
253 // picking best aspect (16:9)
254 in.width = 350;
255 in.height = 201;
256 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
257 EXPECT_PRED4(IsEqualRes, out, 320, 180, 30);
258
259 // constrain resolution greater than the max and narrow aspect,
260 // picking best aspect (4:3)
261 in.width = 350;
262 in.height = 300;
263 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
264 EXPECT_PRED4(IsEqualRes, out, 320, 240, 30);
265
266 // constrain resolution greater than the max and wider aspect,
267 // picking best aspect (16:9)
268 in.width = 1380;
269 in.height = 800;
270 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
271 EXPECT_PRED4(IsEqualRes, out, 640, 360, 30);
272
273 // constrain resolution greater than the max and narrow aspect,
274 // picking best aspect (4:3)
275 in.width = 1280;
276 in.height = 900;
277 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
278 EXPECT_PRED4(IsEqualRes, out, 640, 480, 30);
279
280 // constrain resolution greater than the max, picking equal aspect (4:3)
281 in.width = 1280;
282 in.height = 960;
283 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
284 EXPECT_PRED4(IsEqualRes, out, 640, 480, 30);
285
286 // constrain resolution greater than the max, picking equal aspect (16:10)
287 in.width = 1280;
288 in.height = 800;
289 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
290 EXPECT_PRED4(IsEqualRes, out, 640, 400, 30);
291
292 // constrain res & fps greater than the max
293 in.framerate = 50;
294 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
295 EXPECT_PRED4(IsEqualRes, out, 640, 400, 30);
296
297 // reduce max settings to 160x100x10
298 max_settings.width = 160;
299 max_settings.height = 100;
300 max_settings.framerate = 10;
301 EXPECT_TRUE(engine_.SetDefaultEncoderConfig(
302 cricket::VideoEncoderConfig(max_settings)));
303
304 // constrain res & fps to new max
305 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
306 EXPECT_PRED4(IsEqualRes, out, 160, 100, 10);
307
308 // allow 4:3 "comparable" resolutions
309 in.width = 160;
310 in.height = 120;
311 in.framerate = 10;
312 EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out));
313 EXPECT_PRED4(IsEqualRes, out, 160, 120, 10);
314 }
315
316 void ConstrainRunningCodecBody() {
317 cricket::VideoCodec in, out, current;
318 cricket::VideoCodec max_settings(engine_.codecs()[0].id,
319 engine_.codecs()[0].name,
320 1280, 800, 30, 0);
321
322 // set max settings of 1280x960x30
323 EXPECT_TRUE(engine_.SetDefaultEncoderConfig(
324 cricket::VideoEncoderConfig(max_settings)));
325
326 // establish current call at 1280x800x30 (16:10)
327 current = max_settings;
328 current.height = 800;
329
330 // Don't constrain current resolution
331 in = current;
332 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
333 EXPECT_PRED2(IsEqualCodec, out, in);
334
335 // requested resolution of 0x0 succeeds
336 in.width = 0;
337 in.height = 0;
338 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
339 EXPECT_PRED2(IsEqualCodec, out, in);
340
341 // Reduce an intermediate resolution down to the next lowest one, preserving
342 // aspect ratio.
343 in.width = 800;
344 in.height = 600;
345 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
346 EXPECT_PRED4(IsEqualRes, out, 640, 400, 30);
347
348 // Clamping by aspect ratio, but still never return a dimension higher than
349 // requested.
350 in.width = 1280;
351 in.height = 720;
352 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
353 EXPECT_PRED4(IsEqualRes, out, 1280, 720, 30);
354
355 in.width = 1279;
356 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
357 EXPECT_PRED4(IsEqualRes, out, 960, 600, 30);
358
359 in.width = 1281;
360 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
361 EXPECT_PRED4(IsEqualRes, out, 1280, 720, 30);
362
363 // Clamp large resolutions down, always preserving aspect
364 in.width = 1920;
365 in.height = 1080;
366 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
367 EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30);
368
369 in.width = 1921;
370 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
371 EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30);
372
373 in.width = 1919;
374 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
375 EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30);
376
377 // reduce max settings to 640x480x30
378 max_settings.width = 640;
379 max_settings.height = 480;
380 EXPECT_TRUE(engine_.SetDefaultEncoderConfig(
381 cricket::VideoEncoderConfig(max_settings)));
382
383 // establish current call at 640x400x30 (16:10)
384 current = max_settings;
385 current.height = 400;
386
387 // Don't constrain current resolution
388 in = current;
389 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
390 EXPECT_PRED2(IsEqualCodec, out, in);
391
392 // requested resolution of 0x0 succeeds
393 in.width = 0;
394 in.height = 0;
395 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
396 EXPECT_PRED2(IsEqualCodec, out, in);
397
398 // Reduce an intermediate resolution down to the next lowest one, preserving
399 // aspect ratio.
400 in.width = 400;
401 in.height = 300;
402 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
403 EXPECT_PRED4(IsEqualRes, out, 320, 200, 30);
404
405 // Clamping by aspect ratio, but still never return a dimension higher than
406 // requested.
407 in.width = 640;
408 in.height = 360;
409 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
410 EXPECT_PRED4(IsEqualRes, out, 640, 360, 30);
411
412 in.width = 639;
413 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
414 EXPECT_PRED4(IsEqualRes, out, 480, 300, 30);
415
416 in.width = 641;
417 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
418 EXPECT_PRED4(IsEqualRes, out, 640, 360, 30);
419
420 // Clamp large resolutions down, always preserving aspect
421 in.width = 1280;
422 in.height = 800;
423 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
424 EXPECT_PRED4(IsEqualRes, out, 640, 400, 30);
425
426 in.width = 1281;
427 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
428 EXPECT_PRED4(IsEqualRes, out, 640, 400, 30);
429
430 in.width = 1279;
431 EXPECT_TRUE(engine_.CanSendCodec(in, current, &out));
432 EXPECT_PRED4(IsEqualRes, out, 640, 400, 30);
433
434 // Should fail for any that are smaller than our supported formats
435 in.width = 80;
436 in.height = 80;
437 EXPECT_FALSE(engine_.CanSendCodec(in, current, &out));
438
439 in.height = 50;
440 EXPECT_FALSE(engine_.CanSendCodec(in, current, &out));
441 }
442
443 VideoEngineOverride<E> engine_;
444 talk_base::scoped_ptr<cricket::FakeVideoCapturer> video_capturer_;
445};
446
447template<class E, class C>
448class VideoMediaChannelTest : public testing::Test,
449 public sigslot::has_slots<> {
450 protected:
451 virtual cricket::VideoCodec DefaultCodec() = 0;
452
453 virtual cricket::StreamParams DefaultSendStreamParams() {
454 return cricket::StreamParams::CreateLegacy(kSsrc);
455 }
456
457 virtual void SetUp() {
458 cricket::Device device("test", "device");
459 EXPECT_TRUE(engine_.Init(talk_base::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460 channel_.reset(engine_.CreateChannel(NULL));
461 EXPECT_TRUE(channel_.get() != NULL);
462 ConnectVideoChannelError();
463 network_interface_.SetDestination(channel_.get());
464 channel_->SetInterface(&network_interface_);
465 SetRendererAsDefault();
466 media_error_ = cricket::VideoMediaChannel::ERROR_NONE;
467 channel_->SetRecvCodecs(engine_.codecs());
468 EXPECT_TRUE(channel_->AddSendStream(DefaultSendStreamParams()));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000469
470 video_capturer_.reset(new cricket::FakeVideoCapturer);
471 cricket::VideoFormat format(640, 480,
472 cricket::VideoFormat::FpsToInterval(30),
473 cricket::FOURCC_I420);
474 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(format));
475 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000476 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, format));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000477 }
478 void SetUpSecondStream() {
479 EXPECT_TRUE(channel_->AddRecvStream(
480 cricket::StreamParams::CreateLegacy(kSsrc)));
481 EXPECT_TRUE(channel_->AddRecvStream(
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000482 cricket::StreamParams::CreateLegacy(kSsrc + 2)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483 // SetUp() already added kSsrc make sure duplicate SSRCs cant be added.
484 EXPECT_FALSE(channel_->AddSendStream(
485 cricket::StreamParams::CreateLegacy(kSsrc)));
486 EXPECT_TRUE(channel_->AddSendStream(
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000487 cricket::StreamParams::CreateLegacy(kSsrc + 2)));
488
489 video_capturer_2_.reset(new cricket::FakeVideoCapturer());
490 cricket::VideoFormat format(640, 480,
491 cricket::VideoFormat::FpsToInterval(30),
492 cricket::FOURCC_I420);
493 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(format));
494
495 EXPECT_TRUE(channel_->SetCapturer(kSsrc + 2, video_capturer_2_.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000496 // Make the second renderer available for use by a new stream.
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000497 EXPECT_TRUE(channel_->SetRenderer(kSsrc + 2, &renderer2_));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000498 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc + 2, format));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499 }
500 virtual void TearDown() {
501 channel_.reset();
502 engine_.Terminate();
503 }
504 void ConnectVideoChannelError() {
505 channel_->SignalMediaError.connect(this,
506 &VideoMediaChannelTest<E, C>::OnVideoChannelError);
507 }
508 bool SetDefaultCodec() {
509 return SetOneCodec(DefaultCodec());
510 }
511 void SetRendererAsDefault() {
512 EXPECT_TRUE(channel_->SetRenderer(0, &renderer_));
513 }
514
515 bool SetOneCodec(int pt, const char* name, int w, int h, int fr) {
516 return SetOneCodec(cricket::VideoCodec(pt, name, w, h, fr, 0));
517 }
518 bool SetOneCodec(const cricket::VideoCodec& codec) {
519 std::vector<cricket::VideoCodec> codecs;
520 codecs.push_back(codec);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000521
522 cricket::VideoFormat capture_format(codec.width, codec.height,
523 cricket::VideoFormat::FpsToInterval(codec.framerate),
524 cricket::FOURCC_I420);
525
526 if (video_capturer_) {
527 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format));
528 }
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000529 if (video_capturer_2_) {
530 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(capture_format));
531 }
532
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 bool sending = channel_->sending();
534 bool success = SetSend(false);
535 if (success)
536 success = channel_->SetSendCodecs(codecs);
537 if (success)
538 success = SetSend(sending);
539 return success;
540 }
541 bool SetSend(bool send) {
542 return channel_->SetSend(send);
543 }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000544 bool SetSendStreamFormat(uint32 ssrc, const cricket::VideoCodec& codec) {
545 return channel_->SetSendStreamFormat(ssrc, cricket::VideoFormat(
546 codec.width, codec.height,
547 cricket::VideoFormat::FpsToInterval(codec.framerate),
548 cricket::FOURCC_ANY));
549 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 int DrainOutgoingPackets() {
551 int packets = 0;
552 do {
553 packets = NumRtpPackets();
554 // 100 ms should be long enough.
555 talk_base::Thread::Current()->ProcessMessages(100);
556 } while (NumRtpPackets() > packets);
557 return NumRtpPackets();
558 }
559 bool SendFrame() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000560 if (video_capturer_2_) {
561 video_capturer_2_->CaptureFrame();
562 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 return video_capturer_.get() &&
564 video_capturer_->CaptureFrame();
565 }
566 bool WaitAndSendFrame(int wait_ms) {
567 bool ret = talk_base::Thread::Current()->ProcessMessages(wait_ms);
568 ret &= SendFrame();
569 return ret;
570 }
571 // Sends frames and waits for the decoder to be fully initialized.
572 // Returns the number of frames that were sent.
573 int WaitForDecoder() {
574#if defined(HAVE_OPENMAX)
575 // Send enough frames for the OpenMAX decoder to continue processing, and
576 // return the number of frames sent.
577 // Send frames for a full kTimeout's worth of 15fps video.
578 int frame_count = 0;
579 while (frame_count < static_cast<int>(kTimeout) / 66) {
580 EXPECT_TRUE(WaitAndSendFrame(66));
581 ++frame_count;
582 }
583 return frame_count;
584#else
585 return 0;
586#endif
587 }
588 bool SendCustomVideoFrame(int w, int h) {
589 if (!video_capturer_.get()) return false;
590 return video_capturer_->CaptureCustomFrame(w, h, cricket::FOURCC_I420);
591 }
592 int NumRtpBytes() {
593 return network_interface_.NumRtpBytes();
594 }
595 int NumRtpBytes(uint32 ssrc) {
596 return network_interface_.NumRtpBytes(ssrc);
597 }
598 int NumRtpPackets() {
599 return network_interface_.NumRtpPackets();
600 }
601 int NumRtpPackets(uint32 ssrc) {
602 return network_interface_.NumRtpPackets(ssrc);
603 }
604 int NumSentSsrcs() {
605 return network_interface_.NumSentSsrcs();
606 }
607 const talk_base::Buffer* GetRtpPacket(int index) {
608 return network_interface_.GetRtpPacket(index);
609 }
610 int NumRtcpPackets() {
611 return network_interface_.NumRtcpPackets();
612 }
613 const talk_base::Buffer* GetRtcpPacket(int index) {
614 return network_interface_.GetRtcpPacket(index);
615 }
616 static int GetPayloadType(const talk_base::Buffer* p) {
617 int pt = -1;
618 ParseRtpPacket(p, NULL, &pt, NULL, NULL, NULL, NULL);
619 return pt;
620 }
621 static bool ParseRtpPacket(const talk_base::Buffer* p, bool* x, int* pt,
622 int* seqnum, uint32* tstamp, uint32* ssrc,
623 std::string* payload) {
624 talk_base::ByteBuffer buf(p->data(), p->length());
625 uint8 u08 = 0;
626 uint16 u16 = 0;
627 uint32 u32 = 0;
628
629 // Read X and CC fields.
630 if (!buf.ReadUInt8(&u08)) return false;
631 bool extension = ((u08 & 0x10) != 0);
632 uint8 cc = (u08 & 0x0F);
633 if (x) *x = extension;
634
635 // Read PT field.
636 if (!buf.ReadUInt8(&u08)) return false;
637 if (pt) *pt = (u08 & 0x7F);
638
639 // Read Sequence Number field.
640 if (!buf.ReadUInt16(&u16)) return false;
641 if (seqnum) *seqnum = u16;
642
643 // Read Timestamp field.
644 if (!buf.ReadUInt32(&u32)) return false;
645 if (tstamp) *tstamp = u32;
646
647 // Read SSRC field.
648 if (!buf.ReadUInt32(&u32)) return false;
649 if (ssrc) *ssrc = u32;
650
651 // Skip CSRCs.
652 for (uint8 i = 0; i < cc; ++i) {
653 if (!buf.ReadUInt32(&u32)) return false;
654 }
655
656 // Skip extension header.
657 if (extension) {
658 // Read Profile-specific extension header ID
659 if (!buf.ReadUInt16(&u16)) return false;
660
661 // Read Extension header length
662 if (!buf.ReadUInt16(&u16)) return false;
663 uint16 ext_header_len = u16;
664
665 // Read Extension header
666 for (uint16 i = 0; i < ext_header_len; ++i) {
667 if (!buf.ReadUInt32(&u32)) return false;
668 }
669 }
670
671 if (payload) {
672 return buf.ReadString(payload, buf.Length());
673 }
674 return true;
675 }
676
677 // Parse all RTCP packet, from start_index to stop_index, and count how many
678 // FIR (PT=206 and FMT=4 according to RFC 5104). If successful, set the count
679 // and return true.
680 bool CountRtcpFir(int start_index, int stop_index, int* fir_count) {
681 int count = 0;
682 for (int i = start_index; i < stop_index; ++i) {
683 talk_base::scoped_ptr<const talk_base::Buffer> p(GetRtcpPacket(i));
684 talk_base::ByteBuffer buf(p->data(), p->length());
685 size_t total_len = 0;
686 // The packet may be a compound RTCP packet.
687 while (total_len < p->length()) {
688 // Read FMT, type and length.
689 uint8 fmt = 0;
690 uint8 type = 0;
691 uint16 length = 0;
692 if (!buf.ReadUInt8(&fmt)) return false;
693 fmt &= 0x1F;
694 if (!buf.ReadUInt8(&type)) return false;
695 if (!buf.ReadUInt16(&length)) return false;
696 buf.Consume(length * 4); // Skip RTCP data.
697 total_len += (length + 1) * 4;
698 if ((192 == type) || ((206 == type) && (4 == fmt))) {
699 ++count;
700 }
701 }
702 }
703
704 if (fir_count) {
705 *fir_count = count;
706 }
707 return true;
708 }
709
710 void OnVideoChannelError(uint32 ssrc,
711 cricket::VideoMediaChannel::Error error) {
712 media_error_ = error;
713 }
714
715 // Test that SetSend works.
716 void SetSend() {
717 EXPECT_FALSE(channel_->sending());
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000718 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
720 EXPECT_FALSE(channel_->sending());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000721 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 EXPECT_TRUE(SetSend(true));
723 EXPECT_TRUE(channel_->sending());
724 EXPECT_TRUE(SendFrame());
725 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
726 EXPECT_TRUE(SetSend(false));
727 EXPECT_FALSE(channel_->sending());
728 }
729 // Test that SetSend fails without codecs being set.
730 void SetSendWithoutCodecs() {
731 EXPECT_FALSE(channel_->sending());
732 EXPECT_FALSE(SetSend(true));
733 EXPECT_FALSE(channel_->sending());
734 }
735 // Test that we properly set the send and recv buffer sizes by the time
736 // SetSend is called.
737 void SetSendSetsTransportBufferSizes() {
738 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
739 EXPECT_TRUE(SetSend(true));
740 // TODO(sriniv): Remove or re-enable this.
741 // As part of b/8030474, send-buffer is size now controlled through
742 // portallocator flags. Its not set by channels.
743 // EXPECT_EQ(64 * 1024, network_interface_.sendbuf_size());
744 EXPECT_EQ(64 * 1024, network_interface_.recvbuf_size());
745 }
746 // Tests that we can send frames and the right payload type is used.
747 void Send(const cricket::VideoCodec& codec) {
748 EXPECT_TRUE(SetOneCodec(codec));
749 EXPECT_TRUE(SetSend(true));
750 EXPECT_TRUE(SendFrame());
751 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
752 talk_base::scoped_ptr<const talk_base::Buffer> p(GetRtpPacket(0));
753 EXPECT_EQ(codec.id, GetPayloadType(p.get()));
754 }
755 // Tests that we can send and receive frames.
756 void SendAndReceive(const cricket::VideoCodec& codec) {
757 EXPECT_TRUE(SetOneCodec(codec));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000758 EXPECT_TRUE(SetSendStreamFormat(kSsrc, codec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 EXPECT_TRUE(SetSend(true));
760 EXPECT_TRUE(channel_->SetRender(true));
761 EXPECT_EQ(0, renderer_.num_rendered_frames());
762 EXPECT_TRUE(SendFrame());
763 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
764 talk_base::scoped_ptr<const talk_base::Buffer> p(GetRtpPacket(0));
765 EXPECT_EQ(codec.id, GetPayloadType(p.get()));
766 }
767 // Tests that we only get a VideoRenderer::SetSize() callback when needed.
768 void SendManyResizeOnce() {
769 cricket::VideoCodec codec(DefaultCodec());
770 EXPECT_TRUE(SetOneCodec(codec));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000771 EXPECT_TRUE(SetSendStreamFormat(kSsrc, codec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772 EXPECT_TRUE(SetSend(true));
773 EXPECT_TRUE(channel_->SetRender(true));
774 EXPECT_EQ(0, renderer_.num_rendered_frames());
775 EXPECT_TRUE(WaitAndSendFrame(30));
776 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
777 EXPECT_TRUE(WaitAndSendFrame(30));
778 EXPECT_FRAME_WAIT(2, codec.width, codec.height, kTimeout);
779 talk_base::scoped_ptr<const talk_base::Buffer> p(GetRtpPacket(0));
780 EXPECT_EQ(codec.id, GetPayloadType(p.get()));
781 EXPECT_EQ(1, renderer_.num_set_sizes());
782
783 codec.width /= 2;
784 codec.height /= 2;
785 EXPECT_TRUE(SetOneCodec(codec));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000786 EXPECT_TRUE(SetSendStreamFormat(kSsrc, codec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 EXPECT_TRUE(WaitAndSendFrame(30));
788 EXPECT_FRAME_WAIT(3, codec.width, codec.height, kTimeout);
789 EXPECT_EQ(2, renderer_.num_set_sizes());
790 }
791 // Test that stats work properly for a 1-1 call.
792 void GetStats() {
793 SendAndReceive(DefaultCodec());
794 cricket::VideoMediaInfo info;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000795 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796
797 ASSERT_EQ(1U, info.senders.size());
798 // TODO(whyuan): bytes_sent and bytes_rcvd are different. Are both payload?
799 EXPECT_GT(info.senders[0].bytes_sent, 0);
800 EXPECT_EQ(NumRtpPackets(), info.senders[0].packets_sent);
801 EXPECT_EQ(0.0, info.senders[0].fraction_lost);
802 EXPECT_EQ(0, info.senders[0].firs_rcvd);
803 EXPECT_EQ(0, info.senders[0].nacks_rcvd);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000804 EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width);
805 EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 EXPECT_GT(info.senders[0].framerate_input, 0);
807 EXPECT_GT(info.senders[0].framerate_sent, 0);
808
809 ASSERT_EQ(1U, info.receivers.size());
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000810 EXPECT_EQ(1U, info.senders[0].ssrcs().size());
811 EXPECT_EQ(1U, info.receivers[0].ssrcs().size());
812 EXPECT_EQ(info.senders[0].ssrcs()[0], info.receivers[0].ssrcs()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 EXPECT_EQ(NumRtpBytes(), info.receivers[0].bytes_rcvd);
814 EXPECT_EQ(NumRtpPackets(), info.receivers[0].packets_rcvd);
815 EXPECT_EQ(0.0, info.receivers[0].fraction_lost);
816 EXPECT_EQ(0, info.receivers[0].packets_lost);
817 EXPECT_EQ(0, info.receivers[0].packets_concealed);
818 EXPECT_EQ(0, info.receivers[0].firs_sent);
819 EXPECT_EQ(0, info.receivers[0].nacks_sent);
820 EXPECT_EQ(DefaultCodec().width, info.receivers[0].frame_width);
821 EXPECT_EQ(DefaultCodec().height, info.receivers[0].frame_height);
822 EXPECT_GT(info.receivers[0].framerate_rcvd, 0);
823 EXPECT_GT(info.receivers[0].framerate_decoded, 0);
824 EXPECT_GT(info.receivers[0].framerate_output, 0);
825 }
826 // Test that stats work properly for a conf call with multiple recv streams.
827 void GetStatsMultipleRecvStreams() {
828 cricket::FakeVideoRenderer renderer1, renderer2;
829 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
830 cricket::VideoOptions vmo;
831 vmo.conference_mode.Set(true);
832 EXPECT_TRUE(channel_->SetOptions(vmo));
833 EXPECT_TRUE(SetSend(true));
834 EXPECT_TRUE(channel_->AddRecvStream(
835 cricket::StreamParams::CreateLegacy(1)));
836 EXPECT_TRUE(channel_->AddRecvStream(
837 cricket::StreamParams::CreateLegacy(2)));
838 EXPECT_TRUE(channel_->SetRenderer(1, &renderer1));
839 EXPECT_TRUE(channel_->SetRenderer(2, &renderer2));
840 EXPECT_TRUE(channel_->SetRender(true));
841 EXPECT_EQ(0, renderer1.num_rendered_frames());
842 EXPECT_EQ(0, renderer2.num_rendered_frames());
843 std::vector<uint32> ssrcs;
844 ssrcs.push_back(1);
845 ssrcs.push_back(2);
846 network_interface_.SetConferenceMode(true, ssrcs);
847 EXPECT_TRUE(SendFrame());
848 EXPECT_FRAME_ON_RENDERER_WAIT(
849 renderer1, 1, DefaultCodec().width, DefaultCodec().height, kTimeout);
850 EXPECT_FRAME_ON_RENDERER_WAIT(
851 renderer2, 1, DefaultCodec().width, DefaultCodec().height, kTimeout);
852 cricket::VideoMediaInfo info;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000853 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854
855 ASSERT_EQ(1U, info.senders.size());
856 // TODO(whyuan): bytes_sent and bytes_rcvd are different. Are both payload?
857 EXPECT_GT(info.senders[0].bytes_sent, 0);
858 EXPECT_EQ(NumRtpPackets(), info.senders[0].packets_sent);
859 EXPECT_EQ(0.0, info.senders[0].fraction_lost);
860 EXPECT_EQ(0, info.senders[0].firs_rcvd);
861 EXPECT_EQ(0, info.senders[0].nacks_rcvd);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000862 EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width);
863 EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 EXPECT_GT(info.senders[0].framerate_input, 0);
865 EXPECT_GT(info.senders[0].framerate_sent, 0);
866
867 ASSERT_EQ(2U, info.receivers.size());
868 for (size_t i = 0; i < info.receivers.size(); ++i) {
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000869 EXPECT_EQ(1U, info.receivers[i].ssrcs().size());
870 EXPECT_EQ(i + 1, info.receivers[i].ssrcs()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 EXPECT_EQ(NumRtpBytes(), info.receivers[i].bytes_rcvd);
872 EXPECT_EQ(NumRtpPackets(), info.receivers[i].packets_rcvd);
873 EXPECT_EQ(0.0, info.receivers[i].fraction_lost);
874 EXPECT_EQ(0, info.receivers[i].packets_lost);
875 EXPECT_EQ(0, info.receivers[i].packets_concealed);
876 EXPECT_EQ(0, info.receivers[i].firs_sent);
877 EXPECT_EQ(0, info.receivers[i].nacks_sent);
878 EXPECT_EQ(DefaultCodec().width, info.receivers[i].frame_width);
879 EXPECT_EQ(DefaultCodec().height, info.receivers[i].frame_height);
880 EXPECT_GT(info.receivers[i].framerate_rcvd, 0);
881 EXPECT_GT(info.receivers[i].framerate_decoded, 0);
882 EXPECT_GT(info.receivers[i].framerate_output, 0);
883 }
884 }
885 // Test that stats work properly for a conf call with multiple send streams.
886 void GetStatsMultipleSendStreams() {
887 // Normal setup; note that we set the SSRC explicitly to ensure that
888 // it will come first in the senders map.
889 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
890 cricket::VideoOptions vmo;
891 vmo.conference_mode.Set(true);
892 EXPECT_TRUE(channel_->SetOptions(vmo));
893 EXPECT_TRUE(channel_->AddRecvStream(
894 cricket::StreamParams::CreateLegacy(1234)));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000895 channel_->UpdateAspectRatio(640, 400);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000896 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 EXPECT_TRUE(SetSend(true));
898 EXPECT_TRUE(channel_->SetRender(true));
899 EXPECT_TRUE(SendFrame());
900 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
901 EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout);
902
903 // Add an additional capturer, and hook up a renderer to receive it.
904 cricket::FakeVideoRenderer renderer1;
905 talk_base::scoped_ptr<cricket::FakeVideoCapturer> capturer(
906 new cricket::FakeVideoCapturer);
907 capturer->SetScreencast(true);
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000908 const int kTestWidth = 160;
909 const int kTestHeight = 120;
910 cricket::VideoFormat format(kTestWidth, kTestHeight,
911 cricket::VideoFormat::FpsToInterval(5),
912 cricket::FOURCC_I420);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format));
914 EXPECT_TRUE(channel_->AddSendStream(
915 cricket::StreamParams::CreateLegacy(5678)));
916 EXPECT_TRUE(channel_->SetCapturer(5678, capturer.get()));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000917 EXPECT_TRUE(channel_->SetSendStreamFormat(5678, format));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 EXPECT_TRUE(channel_->AddRecvStream(
919 cricket::StreamParams::CreateLegacy(5678)));
920 EXPECT_TRUE(channel_->SetRenderer(5678, &renderer1));
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000921 EXPECT_TRUE(capturer->CaptureCustomFrame(
922 kTestWidth, kTestHeight, cricket::FOURCC_I420));
923 EXPECT_FRAME_ON_RENDERER_WAIT(
924 renderer1, 1, kTestWidth, kTestHeight, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925
926 // Get stats, and make sure they are correct for two senders.
927 cricket::VideoMediaInfo info;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000928 EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 ASSERT_EQ(2U, info.senders.size());
930 EXPECT_EQ(NumRtpPackets(),
931 info.senders[0].packets_sent + info.senders[1].packets_sent);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000932 EXPECT_EQ(1U, info.senders[0].ssrcs().size());
933 EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000934 EXPECT_EQ(DefaultCodec().width, info.senders[0].send_frame_width);
935 EXPECT_EQ(DefaultCodec().height, info.senders[0].send_frame_height);
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000936 EXPECT_EQ(1U, info.senders[1].ssrcs().size());
937 EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]);
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +0000938 EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width);
939 EXPECT_EQ(kTestHeight, info.senders[1].send_frame_height);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 // The capturer must be unregistered here as it runs out of it's scope next.
941 EXPECT_TRUE(channel_->SetCapturer(5678, NULL));
942 }
943
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000944 // Test that we can set the bandwidth.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 void SetSendBandwidth() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000946 EXPECT_TRUE(channel_->SetStartSendBandwidth(64 * 1024));
947 EXPECT_TRUE(channel_->SetMaxSendBandwidth(-1)); // <= 0 means unlimited.
948 EXPECT_TRUE(channel_->SetMaxSendBandwidth(128 * 1024));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 }
950 // Test that we can set the SSRC for the default send source.
951 void SetSendSsrc() {
952 EXPECT_TRUE(SetDefaultCodec());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000953 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 EXPECT_TRUE(SetSend(true));
955 EXPECT_TRUE(SendFrame());
956 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
957 uint32 ssrc = 0;
958 talk_base::scoped_ptr<const talk_base::Buffer> p(GetRtpPacket(0));
959 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
960 EXPECT_EQ(kSsrc, ssrc);
961 EXPECT_EQ(NumRtpPackets(), NumRtpPackets(ssrc));
962 EXPECT_EQ(NumRtpBytes(), NumRtpBytes(ssrc));
963 EXPECT_EQ(1, NumSentSsrcs());
964 EXPECT_EQ(0, NumRtpPackets(kSsrc - 1));
965 EXPECT_EQ(0, NumRtpBytes(kSsrc - 1));
966 }
967 // Test that we can set the SSRC even after codecs are set.
968 void SetSendSsrcAfterSetCodecs() {
969 // Remove stream added in Setup.
970 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
971 EXPECT_TRUE(SetDefaultCodec());
972 EXPECT_TRUE(channel_->AddSendStream(
973 cricket::StreamParams::CreateLegacy(999)));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000974 EXPECT_TRUE(channel_->SetCapturer(999u, video_capturer_.get()));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000975 EXPECT_TRUE(SetSendStreamFormat(999u, DefaultCodec()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 EXPECT_TRUE(SetSend(true));
977 EXPECT_TRUE(WaitAndSendFrame(0));
978 EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout);
979 uint32 ssrc = 0;
980 talk_base::scoped_ptr<const talk_base::Buffer> p(GetRtpPacket(0));
981 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
982 EXPECT_EQ(999u, ssrc);
983 EXPECT_EQ(NumRtpPackets(), NumRtpPackets(ssrc));
984 EXPECT_EQ(NumRtpBytes(), NumRtpBytes(ssrc));
985 EXPECT_EQ(1, NumSentSsrcs());
986 EXPECT_EQ(0, NumRtpPackets(kSsrc));
987 EXPECT_EQ(0, NumRtpBytes(kSsrc));
988 }
989 // Test that we can set the default video renderer before and after
990 // media is received.
991 void SetRenderer() {
992 uint8 data1[] = {
993 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
994 };
995
996 talk_base::Buffer packet1(data1, sizeof(data1));
997 talk_base::SetBE32(packet1.data() + 8, kSsrc);
998 channel_->SetRenderer(0, NULL);
999 EXPECT_TRUE(SetDefaultCodec());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001000 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 EXPECT_TRUE(SetSend(true));
1002 EXPECT_TRUE(channel_->SetRender(true));
1003 EXPECT_EQ(0, renderer_.num_rendered_frames());
wu@webrtc.orga9890802013-12-13 00:21:03 +00001004 channel_->OnPacketReceived(&packet1, talk_base::PacketTime());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 SetRendererAsDefault();
1006 EXPECT_TRUE(SendFrame());
1007 EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout);
1008 }
1009
1010 // Tests empty StreamParams is rejected.
1011 void RejectEmptyStreamParams() {
1012 // Remove the send stream that was added during Setup.
1013 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1014
1015 cricket::StreamParams empty;
1016 EXPECT_FALSE(channel_->AddSendStream(empty));
1017 EXPECT_TRUE(channel_->AddSendStream(
1018 cricket::StreamParams::CreateLegacy(789u)));
1019 }
1020
1021 // Tests setting up and configuring a send stream.
1022 void AddRemoveSendStreams() {
1023 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001024 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001025 EXPECT_TRUE(SetSend(true));
1026 EXPECT_TRUE(channel_->SetRender(true));
1027 EXPECT_TRUE(SendFrame());
1028 EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout);
1029 EXPECT_GE(2, NumRtpPackets());
1030 uint32 ssrc = 0;
1031 size_t last_packet = NumRtpPackets() - 1;
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001032 talk_base::scoped_ptr<const talk_base::Buffer>
1033 p(GetRtpPacket(static_cast<int>(last_packet)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
1035 EXPECT_EQ(kSsrc, ssrc);
1036
1037 // Remove the send stream that was added during Setup.
1038 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1039 int rtp_packets = NumRtpPackets();
1040
1041 EXPECT_TRUE(channel_->AddSendStream(
1042 cricket::StreamParams::CreateLegacy(789u)));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001043 EXPECT_TRUE(channel_->SetCapturer(789u, video_capturer_.get()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 EXPECT_EQ(rtp_packets, NumRtpPackets());
1045 // Wait 30ms to guarantee the engine does not drop the frame.
1046 EXPECT_TRUE(WaitAndSendFrame(30));
1047 EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout);
1048
1049 last_packet = NumRtpPackets() - 1;
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001050 p.reset(GetRtpPacket(static_cast<int>(last_packet)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001051 ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL);
1052 EXPECT_EQ(789u, ssrc);
1053 }
1054
1055 // Tests adding streams already exists returns false.
1056 void AddRecvStreamsAlreadyExist() {
1057 cricket::VideoOptions vmo;
1058 vmo.conference_mode.Set(true);
1059 EXPECT_TRUE(channel_->SetOptions(vmo));
1060
1061 EXPECT_FALSE(channel_->AddRecvStream(
1062 cricket::StreamParams::CreateLegacy(0)));
1063
1064 EXPECT_TRUE(channel_->AddRecvStream(
1065 cricket::StreamParams::CreateLegacy(1)));
1066 EXPECT_FALSE(channel_->AddRecvStream(
1067 cricket::StreamParams::CreateLegacy(1)));
1068
1069 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1070 EXPECT_FALSE(channel_->AddRecvStream(
1071 cricket::StreamParams::CreateLegacy(0)));
1072 EXPECT_TRUE(channel_->AddRecvStream(
1073 cricket::StreamParams::CreateLegacy(1)));
1074 }
1075
1076 // Tests setting up and configuring multiple incoming streams.
1077 void AddRemoveRecvStreams() {
1078 cricket::FakeVideoRenderer renderer1, renderer2;
1079 cricket::VideoOptions vmo;
1080 vmo.conference_mode.Set(true);
1081 EXPECT_TRUE(channel_->SetOptions(vmo));
1082 // Ensure we can't set the renderer on a non-existent stream.
1083 EXPECT_FALSE(channel_->SetRenderer(1, &renderer1));
1084 EXPECT_FALSE(channel_->SetRenderer(2, &renderer2));
1085 cricket::VideoRenderer* renderer;
1086 EXPECT_FALSE(channel_->GetRenderer(1, &renderer));
1087 EXPECT_FALSE(channel_->GetRenderer(2, &renderer));
1088
1089 // Ensure we can add streams.
1090 EXPECT_TRUE(channel_->AddRecvStream(
1091 cricket::StreamParams::CreateLegacy(1)));
1092 EXPECT_TRUE(channel_->AddRecvStream(
1093 cricket::StreamParams::CreateLegacy(2)));
1094 EXPECT_TRUE(channel_->GetRenderer(1, &renderer));
1095 // Verify the first AddRecvStream hook up to the default renderer.
1096 EXPECT_EQ(&renderer_, renderer);
1097 EXPECT_TRUE(channel_->GetRenderer(2, &renderer));
1098 EXPECT_TRUE(NULL == renderer);
1099
1100 // Ensure we can now set the renderers.
1101 EXPECT_TRUE(channel_->SetRenderer(1, &renderer1));
1102 EXPECT_TRUE(channel_->SetRenderer(2, &renderer2));
1103 EXPECT_TRUE(channel_->GetRenderer(1, &renderer));
1104 EXPECT_TRUE(&renderer1 == renderer);
1105 EXPECT_TRUE(channel_->GetRenderer(2, &renderer));
1106 EXPECT_TRUE(&renderer2 == renderer);
1107
1108 // Ensure we can change the renderers if needed.
1109 EXPECT_TRUE(channel_->SetRenderer(1, &renderer2));
1110 EXPECT_TRUE(channel_->SetRenderer(2, &renderer1));
1111 EXPECT_TRUE(channel_->GetRenderer(1, &renderer));
1112 EXPECT_TRUE(&renderer2 == renderer);
1113 EXPECT_TRUE(channel_->GetRenderer(2, &renderer));
1114 EXPECT_TRUE(&renderer1 == renderer);
1115
1116 EXPECT_TRUE(channel_->RemoveRecvStream(2));
1117 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1118 EXPECT_FALSE(channel_->GetRenderer(1, &renderer));
1119 EXPECT_FALSE(channel_->GetRenderer(2, &renderer));
1120 }
1121
1122 // Tests setting up and configuring multiple incoming streams in a
1123 // non-conference call.
1124 void AddRemoveRecvStreamsNoConference() {
1125 cricket::FakeVideoRenderer renderer1, renderer2;
1126 // Ensure we can't set the renderer on a non-existent stream.
1127 EXPECT_FALSE(channel_->SetRenderer(1, &renderer1));
1128 EXPECT_FALSE(channel_->SetRenderer(2, &renderer2));
1129 cricket::VideoRenderer* renderer;
1130 EXPECT_FALSE(channel_->GetRenderer(1, &renderer));
1131 EXPECT_FALSE(channel_->GetRenderer(2, &renderer));
1132
1133 // Ensure we can add streams.
1134 EXPECT_TRUE(channel_->AddRecvStream(
1135 cricket::StreamParams::CreateLegacy(1)));
1136 EXPECT_TRUE(channel_->AddRecvStream(
1137 cricket::StreamParams::CreateLegacy(2)));
1138 EXPECT_TRUE(channel_->GetRenderer(1, &renderer));
1139 // Verify the first AddRecvStream hook up to the default renderer.
1140 EXPECT_EQ(&renderer_, renderer);
1141 EXPECT_TRUE(channel_->GetRenderer(2, &renderer));
1142 EXPECT_TRUE(NULL == renderer);
1143
1144 // Ensure we can now set the renderers.
1145 EXPECT_TRUE(channel_->SetRenderer(1, &renderer1));
1146 EXPECT_TRUE(channel_->SetRenderer(2, &renderer2));
1147 EXPECT_TRUE(channel_->GetRenderer(1, &renderer));
1148 EXPECT_TRUE(&renderer1 == renderer);
1149 EXPECT_TRUE(channel_->GetRenderer(2, &renderer));
1150 EXPECT_TRUE(&renderer2 == renderer);
1151
1152 // Ensure we can change the renderers if needed.
1153 EXPECT_TRUE(channel_->SetRenderer(1, &renderer2));
1154 EXPECT_TRUE(channel_->SetRenderer(2, &renderer1));
1155 EXPECT_TRUE(channel_->GetRenderer(1, &renderer));
1156 EXPECT_TRUE(&renderer2 == renderer);
1157 EXPECT_TRUE(channel_->GetRenderer(2, &renderer));
1158 EXPECT_TRUE(&renderer1 == renderer);
1159
1160 EXPECT_TRUE(channel_->RemoveRecvStream(2));
1161 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1162 EXPECT_FALSE(channel_->GetRenderer(1, &renderer));
1163 EXPECT_FALSE(channel_->GetRenderer(2, &renderer));
1164 }
1165
1166 // Test that no frames are rendered after the receive stream have been
1167 // removed.
1168 void AddRemoveRecvStreamAndRender() {
1169 cricket::FakeVideoRenderer renderer1;
1170 EXPECT_TRUE(SetDefaultCodec());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001171 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001172 EXPECT_TRUE(SetSend(true));
1173 EXPECT_TRUE(channel_->SetRender(true));
1174 EXPECT_TRUE(channel_->AddRecvStream(
1175 cricket::StreamParams::CreateLegacy(kSsrc)));
1176 EXPECT_TRUE(channel_->SetRenderer(kSsrc, &renderer1));
1177
1178 EXPECT_TRUE(SendFrame());
1179 EXPECT_FRAME_ON_RENDERER_WAIT(
1180 renderer1, 1, DefaultCodec().width, DefaultCodec().height, kTimeout);
1181 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc));
1182 // Send three more frames. This is to avoid that the test might be flaky
1183 // due to frame dropping.
1184 for (size_t i = 0; i < 3; ++i)
1185 EXPECT_TRUE(WaitAndSendFrame(100));
1186
1187 // Test that no more frames have been rendered.
1188 EXPECT_EQ(1, renderer1.num_rendered_frames());
1189
1190 // Re-add the stream again and make sure it renders.
1191 EXPECT_TRUE(channel_->AddRecvStream(
1192 cricket::StreamParams::CreateLegacy(kSsrc)));
1193 // Force the next frame to be a key frame to make the receiving
1194 // decoder happy.
1195 EXPECT_TRUE(channel_->SendIntraFrame());
1196
1197 EXPECT_TRUE(channel_->SetRenderer(kSsrc, &renderer1));
1198 EXPECT_TRUE(SendFrame());
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001199 // Because the default channel is used, RemoveRecvStream above is not going
1200 // to delete the channel. As a result the engine will continue to receive
1201 // and decode the 3 frames sent above. So it is possible we will receive
1202 // some (e.g. 1) of these 3 frames after the renderer is set again.
1203 EXPECT_GT_FRAME_ON_RENDERER_WAIT(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001204 renderer1, 2, DefaultCodec().width, DefaultCodec().height, kTimeout);
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001205 // Detach |renderer1| before exit as there might be frames come late.
1206 EXPECT_TRUE(channel_->SetRenderer(kSsrc, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001207 }
1208
1209 // Tests the behavior of incoming streams in a conference scenario.
1210 void SimulateConference() {
1211 cricket::FakeVideoRenderer renderer1, renderer2;
1212 EXPECT_TRUE(SetDefaultCodec());
1213 cricket::VideoOptions vmo;
1214 vmo.conference_mode.Set(true);
1215 EXPECT_TRUE(channel_->SetOptions(vmo));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001216 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001217 EXPECT_TRUE(SetSend(true));
1218 EXPECT_TRUE(channel_->SetRender(true));
1219 EXPECT_TRUE(channel_->AddRecvStream(
1220 cricket::StreamParams::CreateLegacy(1)));
1221 EXPECT_TRUE(channel_->AddRecvStream(
1222 cricket::StreamParams::CreateLegacy(2)));
1223 EXPECT_TRUE(channel_->SetRenderer(1, &renderer1));
1224 EXPECT_TRUE(channel_->SetRenderer(2, &renderer2));
1225 EXPECT_EQ(0, renderer1.num_rendered_frames());
1226 EXPECT_EQ(0, renderer2.num_rendered_frames());
1227 std::vector<uint32> ssrcs;
1228 ssrcs.push_back(1);
1229 ssrcs.push_back(2);
1230 network_interface_.SetConferenceMode(true, ssrcs);
1231 EXPECT_TRUE(SendFrame());
1232 EXPECT_FRAME_ON_RENDERER_WAIT(
1233 renderer1, 1, DefaultCodec().width, DefaultCodec().height, kTimeout);
1234 EXPECT_FRAME_ON_RENDERER_WAIT(
1235 renderer2, 1, DefaultCodec().width, DefaultCodec().height, kTimeout);
1236
1237 talk_base::scoped_ptr<const talk_base::Buffer> p(GetRtpPacket(0));
1238 EXPECT_EQ(DefaultCodec().id, GetPayloadType(p.get()));
1239 EXPECT_EQ(DefaultCodec().width, renderer1.width());
1240 EXPECT_EQ(DefaultCodec().height, renderer1.height());
1241 EXPECT_EQ(DefaultCodec().width, renderer2.width());
1242 EXPECT_EQ(DefaultCodec().height, renderer2.height());
1243 EXPECT_TRUE(channel_->RemoveRecvStream(2));
1244 EXPECT_TRUE(channel_->RemoveRecvStream(1));
1245 }
1246
1247 // Tests that we can add and remove capturers and frames are sent out properly
1248 void AddRemoveCapturer() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001249 cricket::VideoCodec codec = DefaultCodec();
1250 codec.width = 320;
1251 codec.height = 240;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252 const int time_between_send = TimeBetweenSend(codec);
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001253 EXPECT_TRUE(SetOneCodec(codec));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001254 EXPECT_TRUE(SetSendStreamFormat(kSsrc, codec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 EXPECT_TRUE(SetSend(true));
1256 EXPECT_TRUE(channel_->SetRender(true));
1257 EXPECT_EQ(0, renderer_.num_rendered_frames());
1258 EXPECT_TRUE(SendFrame());
1259 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
1260 talk_base::scoped_ptr<cricket::FakeVideoCapturer> capturer(
1261 new cricket::FakeVideoCapturer);
1262 capturer->SetScreencast(true);
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001263 cricket::VideoFormat format(480, 360,
1264 cricket::VideoFormat::FpsToInterval(30),
1265 cricket::FOURCC_I420);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001266 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format));
1267 // All capturers start generating frames with the same timestamp. ViE does
1268 // not allow the same timestamp to be used. Capture one frame before
1269 // associating the capturer with the channel.
1270 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height,
1271 cricket::FOURCC_I420));
1272
1273 int captured_frames = 1;
1274 for (int iterations = 0; iterations < 2; ++iterations) {
1275 EXPECT_TRUE(channel_->SetCapturer(kSsrc, capturer.get()));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001276 EXPECT_TRUE(SetSendStreamFormat(kSsrc, codec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277 talk_base::Thread::Current()->ProcessMessages(time_between_send);
1278 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height,
1279 cricket::FOURCC_I420));
1280 ++captured_frames;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001281 // Wait until frame of right size is captured.
1282 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames &&
1283 format.width == renderer_.width() &&
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00001284 format.height == renderer_.height() &&
1285 !renderer_.black_frame(), kTimeout);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001286 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames);
1287 EXPECT_EQ(format.width, renderer_.width());
1288 EXPECT_EQ(format.height, renderer_.height());
1289 captured_frames = renderer_.num_rendered_frames() + 1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 EXPECT_FALSE(renderer_.black_frame());
1291 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001292 // Make sure a black frame is generated within the specified timeout.
1293 // The black frame should be the resolution of the send codec.
1294 EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames &&
1295 codec.width == renderer_.width() &&
1296 codec.height == renderer_.height() &&
1297 renderer_.black_frame(), kTimeout);
1298 EXPECT_GE(renderer_.num_rendered_frames(), captured_frames);
1299 EXPECT_EQ(codec.width, renderer_.width());
1300 EXPECT_EQ(codec.height, renderer_.height());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 EXPECT_TRUE(renderer_.black_frame());
1302
1303 // The black frame has the same timestamp as the next frame since it's
1304 // timestamp is set to the last frame's timestamp + interval. WebRTC will
1305 // not render a frame with the same timestamp so capture another frame
1306 // with the frame capturer to increment the next frame's timestamp.
1307 EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height,
1308 cricket::FOURCC_I420));
1309 }
1310 }
1311
1312 // Tests that if RemoveCapturer is called without a capturer ever being
1313 // added, the plugin shouldn't crash (and no black frame should be sent).
1314 void RemoveCapturerWithoutAdd() {
1315 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001316 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 EXPECT_TRUE(SetSend(true));
1318 EXPECT_TRUE(channel_->SetRender(true));
1319 EXPECT_EQ(0, renderer_.num_rendered_frames());
1320 EXPECT_TRUE(SendFrame());
1321 EXPECT_FRAME_WAIT(1, 640, 400, kTimeout);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001322 // Remove the capturer.
1323 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001324 // Wait for one black frame for removing the capturer.
1325 EXPECT_FRAME_WAIT(2, 640, 400, kTimeout);
1326
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327 // No capturer was added, so this RemoveCapturer should
1328 // fail.
1329 EXPECT_FALSE(channel_->SetCapturer(kSsrc, NULL));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001330 talk_base::Thread::Current()->ProcessMessages(300);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001331 // Verify no more frames were sent.
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001332 EXPECT_EQ(2, renderer_.num_rendered_frames());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001333 }
1334
1335 // Tests that we can add and remove capturer as unique sources.
1336 void AddRemoveCapturerMultipleSources() {
1337 // WebRTC implementation will drop frames if pushed to quickly. Wait the
1338 // interval time to avoid that.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001339 // WebRTC implementation will drop frames if pushed to quickly. Wait the
1340 // interval time to avoid that.
1341 // Set up the stream associated with the engine.
1342 EXPECT_TRUE(channel_->AddRecvStream(
1343 cricket::StreamParams::CreateLegacy(kSsrc)));
1344 EXPECT_TRUE(channel_->SetRenderer(kSsrc, &renderer_));
1345 cricket::VideoFormat capture_format; // default format
1346 capture_format.interval = cricket::VideoFormat::FpsToInterval(30);
1347 // Set up additional stream 1.
1348 cricket::FakeVideoRenderer renderer1;
1349 EXPECT_FALSE(channel_->SetRenderer(1, &renderer1));
1350 EXPECT_TRUE(channel_->AddRecvStream(
1351 cricket::StreamParams::CreateLegacy(1)));
1352 EXPECT_TRUE(channel_->SetRenderer(1, &renderer1));
1353 EXPECT_TRUE(channel_->AddSendStream(
1354 cricket::StreamParams::CreateLegacy(1)));
1355 talk_base::scoped_ptr<cricket::FakeVideoCapturer> capturer1(
1356 new cricket::FakeVideoCapturer);
1357 capturer1->SetScreencast(true);
1358 EXPECT_EQ(cricket::CS_RUNNING, capturer1->Start(capture_format));
1359 // Set up additional stream 2.
1360 cricket::FakeVideoRenderer renderer2;
1361 EXPECT_FALSE(channel_->SetRenderer(2, &renderer2));
1362 EXPECT_TRUE(channel_->AddRecvStream(
1363 cricket::StreamParams::CreateLegacy(2)));
1364 EXPECT_TRUE(channel_->SetRenderer(2, &renderer2));
1365 EXPECT_TRUE(channel_->AddSendStream(
1366 cricket::StreamParams::CreateLegacy(2)));
1367 talk_base::scoped_ptr<cricket::FakeVideoCapturer> capturer2(
1368 new cricket::FakeVideoCapturer);
1369 capturer2->SetScreencast(true);
1370 EXPECT_EQ(cricket::CS_RUNNING, capturer2->Start(capture_format));
1371 // State for all the streams.
1372 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
1373 // A limitation in the lmi implementation requires that SetCapturer() is
1374 // called after SetOneCodec().
1375 // TODO(hellner): this seems like an unnecessary constraint, fix it.
1376 EXPECT_TRUE(channel_->SetCapturer(1, capturer1.get()));
1377 EXPECT_TRUE(channel_->SetCapturer(2, capturer2.get()));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001378 EXPECT_TRUE(SetSendStreamFormat(1, DefaultCodec()));
1379 EXPECT_TRUE(SetSendStreamFormat(2, DefaultCodec()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001380 EXPECT_TRUE(SetSend(true));
1381 EXPECT_TRUE(channel_->SetRender(true));
1382 // Test capturer associated with engine.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001383 const int kTestWidth = 160;
1384 const int kTestHeight = 120;
1385 EXPECT_TRUE(capturer1->CaptureCustomFrame(
1386 kTestWidth, kTestHeight, cricket::FOURCC_I420));
1387 EXPECT_FRAME_ON_RENDERER_WAIT(
1388 renderer1, 1, kTestWidth, kTestHeight, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 // Capture a frame with additional capturer2, frames should be received
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001390 EXPECT_TRUE(capturer2->CaptureCustomFrame(
1391 kTestWidth, kTestHeight, cricket::FOURCC_I420));
1392 EXPECT_FRAME_ON_RENDERER_WAIT(
1393 renderer2, 1, kTestWidth, kTestHeight, kTimeout);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001394 // Successfully remove the capturer.
1395 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
1396 // Fail to re-remove the capturer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 EXPECT_FALSE(channel_->SetCapturer(kSsrc, NULL));
1398 // The capturers must be unregistered here as it runs out of it's scope
1399 // next.
1400 EXPECT_TRUE(channel_->SetCapturer(1, NULL));
1401 EXPECT_TRUE(channel_->SetCapturer(2, NULL));
1402 }
1403
1404 void HighAspectHighHeightCapturer() {
1405 const int kWidth = 80;
1406 const int kHeight = 10000;
1407 const int kScaledWidth = 20;
1408 const int kScaledHeight = 2500;
1409
1410 cricket::VideoCodec codec(DefaultCodec());
1411 EXPECT_TRUE(SetOneCodec(codec));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001412 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 EXPECT_TRUE(SetSend(true));
1414
1415 cricket::FakeVideoRenderer renderer;
1416 EXPECT_TRUE(channel_->AddRecvStream(
1417 cricket::StreamParams::CreateLegacy(kSsrc)));
1418 EXPECT_TRUE(channel_->SetRenderer(kSsrc, &renderer));
1419 EXPECT_TRUE(channel_->SetRender(true));
1420 EXPECT_EQ(0, renderer.num_rendered_frames());
1421
1422 EXPECT_TRUE(SendFrame());
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001423 EXPECT_GT_FRAME_ON_RENDERER_WAIT(
1424 renderer, 1, codec.width, codec.height, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001425
1426 // Registering an external capturer is currently the same as screen casting
1427 // (update the test when this changes).
1428 talk_base::scoped_ptr<cricket::FakeVideoCapturer> capturer(
1429 new cricket::FakeVideoCapturer);
1430 capturer->SetScreencast(true);
1431 const std::vector<cricket::VideoFormat>* formats =
1432 capturer->GetSupportedFormats();
1433 cricket::VideoFormat capture_format = (*formats)[0];
1434 EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(capture_format));
1435 // Capture frame to not get same frame timestamps as previous capturer.
1436 capturer->CaptureFrame();
1437 EXPECT_TRUE(channel_->SetCapturer(kSsrc, capturer.get()));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001438 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, capture_format));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 EXPECT_TRUE(talk_base::Thread::Current()->ProcessMessages(30));
1440 EXPECT_TRUE(capturer->CaptureCustomFrame(kWidth, kHeight,
1441 cricket::FOURCC_ARGB));
1442 EXPECT_TRUE(capturer->CaptureFrame());
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001443 EXPECT_GT_FRAME_ON_RENDERER_WAIT(
1444 renderer, 2, kScaledWidth, kScaledHeight, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001445 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
1446 }
1447
1448 // Tests that we can adapt video resolution with 16:10 aspect ratio properly.
1449 void AdaptResolution16x10() {
1450 cricket::VideoCodec codec(DefaultCodec());
1451 codec.width = 640;
1452 codec.height = 400;
1453 SendAndReceive(codec);
1454 codec.width /= 2;
1455 codec.height /= 2;
1456 // Adapt the resolution.
1457 EXPECT_TRUE(SetOneCodec(codec));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001458 EXPECT_TRUE(SetSendStreamFormat(kSsrc, codec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 EXPECT_TRUE(WaitAndSendFrame(30));
1460 EXPECT_FRAME_WAIT(2, codec.width, codec.height, kTimeout);
1461 }
1462 // Tests that we can adapt video resolution with 4:3 aspect ratio properly.
1463 void AdaptResolution4x3() {
1464 cricket::VideoCodec codec(DefaultCodec());
1465 codec.width = 640;
1466 codec.height = 400;
1467 SendAndReceive(codec);
1468 codec.width /= 2;
1469 codec.height /= 2;
1470 // Adapt the resolution.
1471 EXPECT_TRUE(SetOneCodec(codec));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001472 EXPECT_TRUE(SetSendStreamFormat(kSsrc, codec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473 EXPECT_TRUE(WaitAndSendFrame(30));
1474 EXPECT_FRAME_WAIT(2, codec.width, codec.height, kTimeout);
1475 }
1476 // Tests that we can drop all frames properly.
1477 void AdaptDropAllFrames() {
1478 // Set the channel codec's resolution to 0, which will require the adapter
1479 // to drop all frames.
1480 cricket::VideoCodec codec(DefaultCodec());
1481 codec.width = codec.height = codec.framerate = 0;
1482 EXPECT_TRUE(SetOneCodec(codec));
1483 EXPECT_TRUE(SetSend(true));
1484 EXPECT_TRUE(channel_->SetRender(true));
1485 EXPECT_EQ(0, renderer_.num_rendered_frames());
1486 EXPECT_TRUE(SendFrame());
1487 EXPECT_TRUE(SendFrame());
1488 talk_base::Thread::Current()->ProcessMessages(500);
1489 EXPECT_EQ(0, renderer_.num_rendered_frames());
1490 }
1491 // Tests that we can reduce the frame rate on demand properly.
1492 // TODO(fbarchard): This test is flakey on pulse. Fix and re-enable
1493 void AdaptFramerate() {
1494 cricket::VideoCodec codec(DefaultCodec());
1495 int frame_count = 0;
1496 // The capturer runs at 30 fps. The channel requires 30 fps.
1497 EXPECT_TRUE(SetOneCodec(codec));
1498 EXPECT_TRUE(SetSend(true));
1499 EXPECT_TRUE(channel_->SetRender(true));
1500 EXPECT_EQ(frame_count, renderer_.num_rendered_frames());
1501 EXPECT_TRUE(WaitAndSendFrame(0)); // Should be rendered.
1502 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be rendered.
1503 frame_count += 2;
1504 EXPECT_FRAME_WAIT(frame_count, codec.width, codec.height, kTimeout);
1505 talk_base::scoped_ptr<const talk_base::Buffer> p(GetRtpPacket(0));
1506 EXPECT_EQ(codec.id, GetPayloadType(p.get()));
1507
1508 // The channel requires 15 fps.
1509 codec.framerate = 15;
1510 EXPECT_TRUE(SetOneCodec(codec));
1511 EXPECT_TRUE(WaitAndSendFrame(0)); // Should be rendered.
1512 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be dropped.
1513 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be rendered.
1514 frame_count += 2;
1515 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1516
1517 // The channel requires 10 fps.
1518 codec.framerate = 10;
1519 EXPECT_TRUE(SetOneCodec(codec));
1520 EXPECT_TRUE(WaitAndSendFrame(0)); // Should be rendered.
1521 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be dropped.
1522 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be dropped.
1523 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be rendered.
1524 frame_count += 2;
1525 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1526
1527 // The channel requires 8 fps. The adapter adapts to 10 fps, which is the
1528 // closest factor of 30.
1529 codec.framerate = 8;
1530 EXPECT_TRUE(SetOneCodec(codec));
1531 EXPECT_TRUE(WaitAndSendFrame(0)); // Should be rendered.
1532 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be dropped.
1533 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be dropped.
1534 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be rendered.
1535 frame_count += 2;
1536 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1537 }
1538 // Tests that we can set the send stream format properly.
1539 void SetSendStreamFormat() {
1540 cricket::VideoCodec codec(DefaultCodec());
1541 SendAndReceive(codec);
1542 int frame_count = 1;
1543 EXPECT_FRAME_WAIT(frame_count, codec.width, codec.height, kTimeout);
1544
1545 // Adapt the resolution and frame rate to half.
1546 cricket::VideoFormat format(
1547 codec.width / 2,
1548 codec.height / 2,
1549 cricket::VideoFormat::FpsToInterval(codec.framerate / 2),
1550 cricket::FOURCC_I420);
1551 // The SSRC differs from the send SSRC.
1552 EXPECT_FALSE(channel_->SetSendStreamFormat(kSsrc - 1, format));
1553 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, format));
1554
1555 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be dropped.
1556 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be rendered.
1557 EXPECT_TRUE(WaitAndSendFrame(30)); // Should be dropped.
1558 frame_count += 1;
1559 EXPECT_FRAME_WAIT(frame_count, format.width, format.height, kTimeout);
1560
1561 // Adapt the resolution to 0x0, which should drop all frames.
1562 format.width = 0;
1563 format.height = 0;
1564 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, format));
1565 EXPECT_TRUE(SendFrame());
1566 EXPECT_TRUE(SendFrame());
1567 talk_base::Thread::Current()->ProcessMessages(500);
1568 EXPECT_EQ(frame_count, renderer_.num_rendered_frames());
1569 }
1570 // Test that setting send stream format to 0x0 resolution will result in
1571 // frames being dropped.
1572 void SetSendStreamFormat0x0() {
1573 EXPECT_TRUE(SetOneCodec(DefaultCodec()));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001574 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 EXPECT_TRUE(SetSend(true));
1576 EXPECT_TRUE(channel_->SetRender(true));
1577 EXPECT_EQ(0, renderer_.num_rendered_frames());
1578 // This frame should be received.
1579 EXPECT_TRUE(SendFrame());
1580 EXPECT_FRAME_WAIT(1, DefaultCodec().width, DefaultCodec().height, kTimeout);
1581 const int64 interval = cricket::VideoFormat::FpsToInterval(
1582 DefaultCodec().framerate);
1583 cricket::VideoFormat format(
1584 0,
1585 0,
1586 interval,
1587 cricket::FOURCC_I420);
1588 EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, format));
1589 // This frame should not be received.
1590 EXPECT_TRUE(WaitAndSendFrame(
1591 static_cast<int>(interval/talk_base::kNumNanosecsPerMillisec)));
1592 talk_base::Thread::Current()->ProcessMessages(500);
1593 EXPECT_EQ(1, renderer_.num_rendered_frames());
1594 }
1595
1596 // Tests that we can mute and unmute the channel properly.
1597 void MuteStream() {
1598 int frame_count = 0;
1599 EXPECT_TRUE(SetDefaultCodec());
1600 cricket::FakeVideoCapturer video_capturer;
1601 video_capturer.Start(
1602 cricket::VideoFormat(
1603 640, 480,
1604 cricket::VideoFormat::FpsToInterval(30),
1605 cricket::FOURCC_I420));
1606 EXPECT_TRUE(channel_->SetCapturer(kSsrc, &video_capturer));
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001607 EXPECT_TRUE(SetSendStreamFormat(kSsrc, DefaultCodec()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 EXPECT_TRUE(SetSend(true));
1609 EXPECT_TRUE(channel_->SetRender(true));
1610 EXPECT_EQ(frame_count, renderer_.num_rendered_frames());
1611
1612 // Mute the channel and expect black output frame.
1613 EXPECT_TRUE(channel_->MuteStream(kSsrc, true));
1614 EXPECT_TRUE(video_capturer.CaptureFrame());
1615 ++frame_count;
1616 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1617 EXPECT_TRUE(renderer_.black_frame());
1618
1619 // Unmute the channel and expect non-black output frame.
1620 EXPECT_TRUE(channel_->MuteStream(kSsrc, false));
1621 EXPECT_TRUE(talk_base::Thread::Current()->ProcessMessages(30));
1622 EXPECT_TRUE(video_capturer.CaptureFrame());
1623 ++frame_count;
1624 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1625 EXPECT_FALSE(renderer_.black_frame());
1626
1627 // Test that we can also Mute using the correct send stream SSRC.
1628 EXPECT_TRUE(channel_->MuteStream(kSsrc, true));
1629 EXPECT_TRUE(talk_base::Thread::Current()->ProcessMessages(30));
1630 EXPECT_TRUE(video_capturer.CaptureFrame());
1631 ++frame_count;
1632 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1633 EXPECT_TRUE(renderer_.black_frame());
1634
1635 EXPECT_TRUE(channel_->MuteStream(kSsrc, false));
1636 EXPECT_TRUE(talk_base::Thread::Current()->ProcessMessages(30));
1637 EXPECT_TRUE(video_capturer.CaptureFrame());
1638 ++frame_count;
1639 EXPECT_EQ_WAIT(frame_count, renderer_.num_rendered_frames(), kTimeout);
1640 EXPECT_FALSE(renderer_.black_frame());
1641
1642 // Test that muting an invalid stream fails.
1643 EXPECT_FALSE(channel_->MuteStream(kSsrc+1, true));
1644 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
1645 }
1646
1647 // Test that multiple send streams can be created and deleted properly.
1648 void MultipleSendStreams() {
1649 // Remove stream added in Setup. I.e. remove stream corresponding to default
1650 // channel.
1651 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc));
1652 const unsigned int kSsrcsSize = sizeof(kSsrcs4)/sizeof(kSsrcs4[0]);
1653 for (unsigned int i = 0; i < kSsrcsSize; ++i) {
1654 EXPECT_TRUE(channel_->AddSendStream(
1655 cricket::StreamParams::CreateLegacy(kSsrcs4[i])));
1656 }
1657 // Delete one of the non default channel streams, let the destructor delete
1658 // the remaining ones.
1659 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[kSsrcsSize - 1]));
1660 // Stream should already be deleted.
1661 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[kSsrcsSize - 1]));
1662 }
1663
1664
1665 // Two streams one channel tests.
1666
1667 // Tests that we can send and receive frames.
1668 void TwoStreamsSendAndReceive(const cricket::VideoCodec& codec) {
1669 SetUpSecondStream();
1670 // Test sending and receiving on first stream.
1671 SendAndReceive(codec);
1672 // Test sending and receiving on second stream.
1673 EXPECT_EQ_WAIT(1, renderer2_.num_rendered_frames(), kTimeout);
1674 EXPECT_EQ(2, NumRtpPackets());
1675 EXPECT_EQ(1, renderer2_.num_rendered_frames());
1676 }
1677
1678 // Disconnect the first stream and re-use it with another SSRC
1679 void TwoStreamsReUseFirstStream(const cricket::VideoCodec& codec) {
1680 SetUpSecondStream();
1681 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc));
1682 EXPECT_FALSE(channel_->RemoveRecvStream(kSsrc));
1683 // SSRC 0 should map to the "default" stream. I.e. the first added stream.
1684 EXPECT_TRUE(channel_->RemoveSendStream(0));
1685 // Make sure that the first added stream was indeed the "default" stream.
1686 EXPECT_FALSE(channel_->RemoveSendStream(kSsrc));
1687 // Make sure that the "default" stream is indeed removed and that removing
1688 // the default stream has an effect.
1689 EXPECT_FALSE(channel_->RemoveSendStream(0));
1690
1691 SetRendererAsDefault();
1692 EXPECT_TRUE(channel_->AddSendStream(
1693 cricket::StreamParams::CreateLegacy(kSsrc)));
1694 EXPECT_FALSE(channel_->AddSendStream(
1695 cricket::StreamParams::CreateLegacy(kSsrc)));
1696 EXPECT_TRUE(channel_->AddRecvStream(
1697 cricket::StreamParams::CreateLegacy(kSsrc)));
1698 EXPECT_FALSE(channel_->AddRecvStream(
1699 cricket::StreamParams::CreateLegacy(kSsrc)));
1700
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001701 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
1702
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 SendAndReceive(codec);
1704 EXPECT_TRUE(channel_->RemoveSendStream(0));
1705 }
1706
1707 VideoEngineOverride<E> engine_;
1708 talk_base::scoped_ptr<cricket::FakeVideoCapturer> video_capturer_;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001709 talk_base::scoped_ptr<cricket::FakeVideoCapturer> video_capturer_2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710 talk_base::scoped_ptr<C> channel_;
1711 cricket::FakeNetworkInterface network_interface_;
1712 cricket::FakeVideoRenderer renderer_;
1713 cricket::VideoMediaChannel::Error media_error_;
1714
1715 // Used by test cases where 2 streams are run on the same channel.
1716 cricket::FakeVideoRenderer renderer2_;
1717};
1718
wu@webrtc.orgcadf9042013-08-30 21:24:16 +00001719#endif // TALK_MEDIA_BASE_VIDEOENGINE_UNITTEST_H_ NOLINT