Enable SendAndReceive tests.

Also fixes a crash in ::SetCapturer which wasn't exposed by tests
before.

BUG=1788
R=wu@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/18019005

git-svn-id: http://webrtc.googlecode.com/svn/trunk/talk@6765 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/media/webrtc/webrtcvideoengine2.cc b/media/webrtc/webrtcvideoengine2.cc
index 28bd6f4..86c9acc 100644
--- a/media/webrtc/webrtcvideoengine2.cc
+++ b/media/webrtc/webrtcvideoengine2.cc
@@ -1402,18 +1402,20 @@
   {
     talk_base::CritScope cs(&lock_);
 
-    if (capturer == NULL && stream_ != NULL) {
-      LOG(LS_VERBOSE) << "Disabling capturer, sending black frame.";
-      webrtc::I420VideoFrame black_frame;
+    if (capturer == NULL) {
+      if (stream_ != NULL) {
+        LOG(LS_VERBOSE) << "Disabling capturer, sending black frame.";
+        webrtc::I420VideoFrame black_frame;
 
-      int width = format_.width;
-      int height = format_.height;
-      int half_width = (width + 1) / 2;
-      black_frame.CreateEmptyFrame(
-          width, height, width, half_width, half_width);
-      SetWebRtcFrameToBlack(&black_frame);
-      SetDimensions(width, height);
-      stream_->Input()->SwapFrame(&black_frame);
+        int width = format_.width;
+        int height = format_.height;
+        int half_width = (width + 1) / 2;
+        black_frame.CreateEmptyFrame(
+            width, height, width, half_width, half_width);
+        SetWebRtcFrameToBlack(&black_frame);
+        SetDimensions(width, height);
+        stream_->Input()->SwapFrame(&black_frame);
+      }
 
       capturer_ = NULL;
       return true;
diff --git a/media/webrtc/webrtcvideoengine2_unittest.cc b/media/webrtc/webrtcvideoengine2_unittest.cc
index c6168ea..94c18c7 100644
--- a/media/webrtc/webrtcvideoengine2_unittest.cc
+++ b/media/webrtc/webrtcvideoengine2_unittest.cc
@@ -542,6 +542,18 @@
 // TODO(zhurunz): Fix the flakey test.
 WEBRTC_DISABLED_BASE_TEST(SetSendStreamFormat);
 
+TEST_F(WebRtcVideoChannel2BaseTest, SendAndReceiveVp8Vga) {
+  SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0));
+}
+
+TEST_F(WebRtcVideoChannel2BaseTest, SendAndReceiveVp8Qvga) {
+  SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0));
+}
+
+TEST_F(WebRtcVideoChannel2BaseTest, SendAndReceiveVp8SvcQqvga) {
+  SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0));
+}
+
 TEST_F(WebRtcVideoChannel2BaseTest, TwoStreamsSendAndReceive) {
   Base::TwoStreamsSendAndReceive(kVp8Codec);
 }
@@ -550,6 +562,32 @@
   Base::TwoStreamsReUseFirstStream(kVp8Codec);
 }
 
+WEBRTC_BASE_TEST(SendManyResizeOnce);
+
+// TODO(pbos): Enable and figure out why this fails (or should work).
+TEST_F(WebRtcVideoChannel2BaseTest, DISABLED_SendVp8HdAndReceiveAdaptedVp8Vga) {
+  EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL));
+  EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_));
+  channel_->UpdateAspectRatio(1280, 720);
+  video_capturer_.reset(new cricket::FakeVideoCapturer);
+  const std::vector<cricket::VideoFormat>* formats =
+      video_capturer_->GetSupportedFormats();
+  cricket::VideoFormat capture_format_hd = (*formats)[0];
+  EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd));
+  EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get()));
+
+  // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA.
+  cricket::VideoCodec codec(100, "VP8", 1280, 720, 30, 0);
+  EXPECT_TRUE(SetOneCodec(codec));
+  codec.width /= 2;
+  codec.height /= 2;
+  EXPECT_TRUE(SetSend(true));
+  EXPECT_TRUE(channel_->SetRender(true));
+  EXPECT_EQ(0, renderer_.num_rendered_frames());
+  EXPECT_TRUE(SendFrame());
+  EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout);
+}
+
 class WebRtcVideoChannel2Test : public WebRtcVideoEngine2Test {
  public:
   virtual void SetUp() OVERRIDE {
@@ -1494,26 +1532,6 @@
       << "Send stream created after SetSend(true) not sending initially.";
 }
 
-TEST_F(WebRtcVideoChannel2Test, DISABLED_SendAndReceiveVp8Vga) {
-  FAIL() << "Not implemented.";  // TODO(pbos): Implement.
-}
-
-TEST_F(WebRtcVideoChannel2Test, DISABLED_SendAndReceiveVp8Qvga) {
-  FAIL() << "Not implemented.";  // TODO(pbos): Implement.
-}
-
-TEST_F(WebRtcVideoChannel2Test, DISABLED_SendAndReceiveH264SvcQqvga) {
-  FAIL() << "Not implemented.";  // TODO(pbos): Implement.
-}
-
-TEST_F(WebRtcVideoChannel2Test, DISABLED_SendManyResizeOnce) {
-  FAIL() << "Not implemented.";  // TODO(pbos): Implement.
-}
-
-TEST_F(WebRtcVideoChannel2Test, DISABLED_SendVp8HdAndReceiveAdaptedVp8Vga) {
-  FAIL() << "Not implemented.";  // TODO(pbos): Implement.
-}
-
 TEST_F(WebRtcVideoChannel2Test, DISABLED_TestSetDscpOptions) {
   FAIL() << "Not implemented.";  // TODO(pbos): Implement.
 }