Set NACK/REMB when setting receive codecs.

Enabling an additional test to ensure that REMB can be both enabled and
disabled by setting VideoCodecs.

BUG=1788
R=wu@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6785 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/talk/media/webrtc/webrtcvideoengine2.cc b/talk/media/webrtc/webrtcvideoengine2.cc
index 86c9acc..aeba897 100644
--- a/talk/media/webrtc/webrtcvideoengine2.cc
+++ b/talk/media/webrtc/webrtcvideoengine2.cc
@@ -99,6 +99,11 @@
       FeedbackParam(kRtcpFbParamNack, kParamValueEmpty));
 }
 
+static bool IsRembEnabled(const VideoCodec& codec) {
+  return codec.HasFeedbackParam(
+      FeedbackParam(kRtcpFbParamRemb, kParamValueEmpty));
+}
+
 static VideoCodec DefaultVideoCodec() {
   VideoCodec default_codec(kDefaultVideoCodecPref.payload_type,
                            kDefaultVideoCodecPref.name,
@@ -736,8 +741,6 @@
 }  // namespace
 
 bool WebRtcVideoChannel2::SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
-  // TODO(pbos): Must these receive codecs propagate to existing receive
-  // streams?
   LOG(LS_INFO) << "SetRecvCodecs: " << CodecVectorToString(codecs);
   if (!ValidateCodecFormats(codecs)) {
     return false;
@@ -951,11 +954,8 @@
   config->rtp.remote_ssrc = ssrc;
   config->rtp.local_ssrc = rtcp_receiver_report_ssrc_;
 
-  if (IsNackEnabled(recv_codecs_.begin()->codec)) {
-    config->rtp.nack.rtp_history_ms = kNackHistoryMs;
-  }
-  config->rtp.remb = true;
   config->rtp.extensions = recv_rtp_extensions_;
+
   // TODO(pbos): This protection is against setting the same local ssrc as
   // remote which is not permitted by the lower-level API. RTCP requires a
   // corresponding sender SSRC. Figure out what to do when we don't have
@@ -1705,6 +1705,10 @@
 
   config_.rtp.fec = recv_codecs.front().fec;
 
+  config_.rtp.nack.rtp_history_ms =
+      IsNackEnabled(recv_codecs.begin()->codec) ? kNackHistoryMs : 0;
+  config_.rtp.remb = IsRembEnabled(recv_codecs.begin()->codec);
+
   RecreateWebRtcStream();
 }
 
diff --git a/talk/media/webrtc/webrtcvideoengine2_unittest.cc b/talk/media/webrtc/webrtcvideoengine2_unittest.cc
index 94c18c7..c2f36d0 100644
--- a/talk/media/webrtc/webrtcvideoengine2_unittest.cc
+++ b/talk/media/webrtc/webrtcvideoengine2_unittest.cc
@@ -793,24 +793,6 @@
 #endif
 }
 
-TEST_F(WebRtcVideoChannel2Test, DISABLED_RtcpEnabled) {
-  // Note(pbos): This is a receiver-side setting, dumbo.
-  FAIL() << "Not implemented.";  // TODO(pbos): Implement.
-}
-
-TEST_F(WebRtcVideoChannel2Test, DISABLED_KeyFrameRequestEnabled) {
-  FAIL() << "Not implemented.";  // TODO(pbos): Implement.
-}
-
-TEST_F(WebRtcVideoChannel2Test, RembIsEnabledByDefault) {
-  FakeVideoReceiveStream* stream = AddRecvStream();
-  EXPECT_TRUE(stream->GetConfig().rtp.remb);
-}
-
-TEST_F(WebRtcVideoChannel2Test, DISABLED_RembEnabledOnReceiveChannels) {
-  FAIL() << "Not implemented.";  // TODO(pbos): Implement.
-}
-
 TEST_F(WebRtcVideoChannel2Test, RecvStreamWithSimAndRtx) {
   EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs()));
   EXPECT_TRUE(channel_->SetSend(true));
@@ -1010,12 +992,28 @@
   EXPECT_EQ(1u, fake_channel_->GetFakeCall()->GetVideoReceiveStreams().size());
 }
 
-TEST_F(WebRtcVideoChannel2Test, DISABLED_NoRembChangeAfterAddRecvStream) {
-  FAIL() << "Not implemented.";  // TODO(pbos): Implement.
+TEST_F(WebRtcVideoChannel2Test, RembIsEnabledByDefault) {
+  FakeVideoReceiveStream* stream = AddRecvStream();
+  EXPECT_TRUE(stream->GetConfig().rtp.remb);
 }
 
-TEST_F(WebRtcVideoChannel2Test, DISABLED_RembOnOff) {
-  FAIL() << "Not implemented.";  // TODO(pbos): Implement.
+TEST_F(WebRtcVideoChannel2Test, RembCanBeEnabledAndDisabled) {
+  FakeVideoReceiveStream* stream = AddRecvStream();
+  EXPECT_TRUE(stream->GetConfig().rtp.remb);
+
+  // Verify that REMB is turned off when codecs without REMB are set.
+  std::vector<VideoCodec> codecs;
+  codecs.push_back(kVp8Codec);
+  EXPECT_TRUE(codecs[0].feedback_params.params().empty());
+  EXPECT_TRUE(channel_->SetRecvCodecs(codecs));
+  stream = fake_channel_->GetFakeCall()->GetVideoReceiveStreams()[0];
+  EXPECT_FALSE(stream->GetConfig().rtp.remb);
+
+  // Verify that REMB is turned on when setting default codecs since the
+  // default codecs have REMB enabled.
+  EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs()));
+  stream = fake_channel_->GetFakeCall()->GetVideoReceiveStreams()[0];
+  EXPECT_TRUE(stream->GetConfig().rtp.remb);
 }
 
 TEST_F(WebRtcVideoChannel2Test, NackIsEnabledByDefault) {