Move the REMB summation into RemoteBitrateEstimatorSingleStream.

BUG=

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2946 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/src/modules/remote_bitrate_estimator/include/mock/mock_remote_bitrate_observer.h b/src/modules/remote_bitrate_estimator/include/mock/mock_remote_bitrate_observer.h
index 76a9583..31bbcd3 100644
--- a/src/modules/remote_bitrate_estimator/include/mock/mock_remote_bitrate_observer.h
+++ b/src/modules/remote_bitrate_estimator/include/mock/mock_remote_bitrate_observer.h
@@ -19,8 +19,8 @@
 
 class MockRemoteBitrateObserver : public RemoteBitrateObserver {
  public:
-  MOCK_METHOD2(OnReceiveBitrateChanged,
-      void(unsigned int ssrc, unsigned int bitrate));
+  MOCK_METHOD1(OnReceiveBitrateChanged,
+      void(unsigned int bitrate));
 };
 
 }  // namespace webrtc
diff --git a/src/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h b/src/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h
index 10eef95..01d840b 100644
--- a/src/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h
+++ b/src/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h
@@ -24,11 +24,9 @@
 // the incoming streams.
 class RemoteBitrateObserver {
  public:
-  // Called when a receive channel has a new bitrate estimate for the incoming
-  // stream.
-  // TODO(holmer): Remove |ssrc| argument and remove SSRC map from VieRemb.
-  virtual void OnReceiveBitrateChanged(unsigned int ssrc,
-                                       unsigned int bitrate) = 0;
+  // Called when a receive channel group has a new bitrate estimate for the
+  // incoming streams.
+  virtual void OnReceiveBitrateChanged(unsigned int bitrate) = 0;
 
   virtual ~RemoteBitrateObserver() {}
 };
diff --git a/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_multi_stream.cc b/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_multi_stream.cc
index e98c704..6c7fff3 100644
--- a/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_multi_stream.cc
+++ b/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_multi_stream.cc
@@ -122,7 +122,7 @@
   const RateControlRegion region = remote_rate_.Update(&input, time_now);
   unsigned int target_bitrate = remote_rate_.UpdateBandwidthEstimate(time_now);
   if (remote_rate_.ValidEstimate()) {
-    observer_->OnReceiveBitrateChanged(1, target_bitrate);
+    observer_->OnReceiveBitrateChanged(target_bitrate);
   }
   overuse_detector_.SetRateControlRegion(region);
 }
diff --git a/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc b/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc
index 45e301f..f1600d8 100644
--- a/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc
+++ b/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc
@@ -28,19 +28,21 @@
     int64_t arrival_time,
     uint32_t rtp_timestamp) {
   CriticalSectionScoped cs(crit_sect_.get());
-  SsrcBitrateControlsMap::iterator it = bitrate_controls_.find(ssrc);
-  if (it == bitrate_controls_.end()) {
+  SsrcOveruseDetectorMap::iterator it = overuse_detectors_.find(ssrc);
+  if (it == overuse_detectors_.end()) {
     // This is a new SSRC. Adding to map.
     // TODO(holmer): If the channel changes SSRC the old SSRC will still be
     // around in this map until the channel is deleted. This is OK since the
     // callback will no longer be called for the old SSRC. This will be
     // automatically cleaned up when we have one RemoteBitrateEstimator per REMB
     // group.
-    bitrate_controls_.insert(std::make_pair(ssrc, BitrateControls(options_)));
-    it = bitrate_controls_.find(ssrc);
+    std::pair<SsrcOveruseDetectorMap::iterator, bool> insert_result =
+        overuse_detectors_.insert(std::make_pair(ssrc, OveruseDetector(
+            options_)));
+    it = insert_result.first;
   }
-  OveruseDetector* overuse_detector = &it->second.overuse_detector;
-  it->second.incoming_bitrate.Update(packet_size, arrival_time);
+  OveruseDetector* overuse_detector = &it->second;
+  incoming_bitrate_.Update(packet_size, arrival_time);
   const BandwidthUsage prior_state = overuse_detector->State();
   overuse_detector->Update(packet_size, -1, rtp_timestamp, arrival_time);
   if (prior_state != overuse_detector->State() &&
@@ -53,49 +55,47 @@
 void RemoteBitrateEstimatorSingleStream::UpdateEstimate(unsigned int ssrc,
                                                         int64_t time_now) {
   CriticalSectionScoped cs(crit_sect_.get());
-  SsrcBitrateControlsMap::iterator it = bitrate_controls_.find(ssrc);
-  if (it == bitrate_controls_.end()) {
+  SsrcOveruseDetectorMap::iterator it = overuse_detectors_.find(ssrc);
+  if (it == overuse_detectors_.end()) {
     return;
   }
-  OveruseDetector* overuse_detector = &it->second.overuse_detector;
-  RemoteRateControl* remote_rate = &it->second.remote_rate;
+  OveruseDetector* overuse_detector = &it->second;
   const RateControlInput input(overuse_detector->State(),
-                               it->second.incoming_bitrate.BitRate(time_now),
+                               incoming_bitrate_.BitRate(time_now),
                                overuse_detector->NoiseVar());
-  const RateControlRegion region = remote_rate->Update(&input, time_now);
-  unsigned int target_bitrate = remote_rate->UpdateBandwidthEstimate(time_now);
-  if (remote_rate->ValidEstimate()) {
-    observer_->OnReceiveBitrateChanged(ssrc, target_bitrate);
+  const RateControlRegion region = remote_rate_.Update(&input, time_now);
+  unsigned int target_bitrate = remote_rate_.UpdateBandwidthEstimate(time_now);
+  if (remote_rate_.ValidEstimate()) {
+    observer_->OnReceiveBitrateChanged(target_bitrate);
   }
   overuse_detector->SetRateControlRegion(region);
 }
 
 void RemoteBitrateEstimatorSingleStream::SetRtt(unsigned int rtt) {
   CriticalSectionScoped cs(crit_sect_.get());
-  for (SsrcBitrateControlsMap::iterator it = bitrate_controls_.begin();
-      it != bitrate_controls_.end(); ++it) {
-    it->second.remote_rate.SetRtt(rtt);
-  }
+  remote_rate_.SetRtt(rtt);
 }
 
 void RemoteBitrateEstimatorSingleStream::RemoveStream(unsigned int ssrc) {
   CriticalSectionScoped cs(crit_sect_.get());
   // Ignoring the return value which is the number of elements erased.
-  bitrate_controls_.erase(ssrc);
+  overuse_detectors_.erase(ssrc);
 }
 
 bool RemoteBitrateEstimatorSingleStream::LatestEstimate(
     unsigned int ssrc, unsigned int* bitrate_bps) const {
   CriticalSectionScoped cs(crit_sect_.get());
   assert(bitrate_bps != NULL);
-  SsrcBitrateControlsMap::const_iterator it = bitrate_controls_.find(ssrc);
-  if (it == bitrate_controls_.end()) {
+  if (!remote_rate_.ValidEstimate()) {
     return false;
   }
-  if (!it->second.remote_rate.ValidEstimate()) {
-    return false;
-  }
-  *bitrate_bps = it->second.remote_rate.LatestEstimate();
+  // TODO(holmer): For now we're returning the estimate bandwidth per stream as
+  // it corresponds better to how the ViE API is designed. Will fix this when
+  // the API changes.
+  if (overuse_detectors_.size() > 0)
+    *bitrate_bps = remote_rate_.LatestEstimate() / overuse_detectors_.size();
+  else
+    *bitrate_bps = 0;
   return true;
 }
 
diff --git a/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h b/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h
index 241bb0d..088b78d 100644
--- a/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h
+++ b/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h
@@ -55,26 +55,12 @@
   bool LatestEstimate(unsigned int ssrc, unsigned int* bitrate_bps) const;
 
  private:
-  struct BitrateControls {
-    explicit BitrateControls(const OverUseDetectorOptions& options)
-        : remote_rate(),
-          overuse_detector(options),
-          incoming_bitrate() {
-    }
-    BitrateControls(const BitrateControls& other)
-        : remote_rate(other.remote_rate),
-          overuse_detector(other.overuse_detector),
-          incoming_bitrate(other.incoming_bitrate) {
-    }
-    RemoteRateControl remote_rate;
-    OveruseDetector overuse_detector;
-    BitRateStats incoming_bitrate;
-  };
-
-  typedef std::map<unsigned int, BitrateControls> SsrcBitrateControlsMap;
+  typedef std::map<unsigned int, OveruseDetector> SsrcOveruseDetectorMap;
 
   const OverUseDetectorOptions& options_;
-  SsrcBitrateControlsMap bitrate_controls_;
+  SsrcOveruseDetectorMap overuse_detectors_;
+  BitRateStats incoming_bitrate_;
+  RemoteRateControl remote_rate_;
   RemoteBitrateObserver* observer_;
   scoped_ptr<CriticalSectionWrapper> crit_sect_;
 };
diff --git a/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_unittest.cc b/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_unittest.cc
index 70f066c..59c1285 100644
--- a/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_unittest.cc
+++ b/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_unittest.cc
@@ -27,7 +27,7 @@
  public:
   TestBitrateObserver() : updated_(false), latest_bitrate_(0) {}
 
-  void OnReceiveBitrateChanged(unsigned int ssrc, unsigned int bitrate) {
+  void OnReceiveBitrateChanged(unsigned int bitrate) {
     latest_bitrate_ = bitrate;
     updated_ = true;
   }
diff --git a/src/video_engine/vie_remb.cc b/src/video_engine/vie_remb.cc
index 496e6ad..07c4f8a 100644
--- a/src/video_engine/vie_remb.cc
+++ b/src/video_engine/vie_remb.cc
@@ -21,8 +21,8 @@
 
 namespace webrtc {
 
-const int kRembSendIntervallMs = 1000;
 const int kRembTimeOutThresholdMs = 2000;
+const int kRembSendIntervallMs = 1000;
 const unsigned int kRembMinimumBitrateKbps = 50;
 
 // % threshold for if we should send a new REMB asap.
@@ -32,7 +32,9 @@
     : process_thread_(process_thread),
       list_crit_(CriticalSectionWrapper::CreateCriticalSection()),
       last_remb_time_(TickTime::MillisecondTimestamp()),
-      last_send_bitrate_(0) {
+      last_send_bitrate_(0),
+      bitrate_(0),
+      bitrate_update_time_ms_(-1) {
   process_thread->RegisterModule(this);
 }
 
@@ -62,7 +64,6 @@
                "VieRemb::RemoveReceiveChannel(%p)", rtp_rtcp);
 
   CriticalSectionScoped cs(list_crit_.get());
-  unsigned int ssrc = rtp_rtcp->RemoteSSRC();
   for (RtpModules::iterator it = receive_modules_.begin();
        it != receive_modules_.end(); ++it) {
     if ((*it) == rtp_rtcp) {
@@ -70,7 +71,6 @@
       break;
     }
   }
-  update_time_bitrates_.erase(ssrc);
 }
 
 void VieRemb::AddRembSender(RtpRtcp* rtp_rtcp) {
@@ -110,23 +110,14 @@
     return true;
 }
 
-void VieRemb::OnReceiveBitrateChanged(unsigned int ssrc, unsigned int bitrate) {
+void VieRemb::OnReceiveBitrateChanged(unsigned int bitrate) {
   WEBRTC_TRACE(kTraceStream, kTraceVideo, -1,
-               "VieRemb::UpdateBitrateEstimate(ssrc: %u, bitrate: %u)",
-               ssrc, bitrate);
+               "VieRemb::UpdateBitrateEstimate(bitrate: %u)", bitrate);
   CriticalSectionScoped cs(list_crit_.get());
-
-  // Check if this is a new ssrc and add it to the map if it is.
-  if (update_time_bitrates_.find(ssrc) == update_time_bitrates_.end()) {
-    update_time_bitrates_[ssrc] = std::make_pair(
-        TickTime::MillisecondTimestamp(), bitrate);
-  }
-
   // If we already have an estimate, check if the new total estimate is below
   // kSendThresholdPercent of the previous estimate.
   if (last_send_bitrate_ > 0) {
-    unsigned int new_remb_bitrate = last_send_bitrate_ -
-        update_time_bitrates_[ssrc].second + bitrate;
+    unsigned int new_remb_bitrate = last_send_bitrate_ - bitrate_ + bitrate;
 
     if (new_remb_bitrate < kSendThresholdPercent * last_send_bitrate_ / 100) {
       // The new bitrate estimate is less than kSendThresholdPercent % of the
@@ -134,8 +125,8 @@
       last_remb_time_ = TickTime::MillisecondTimestamp() - kRembSendIntervallMs;
     }
   }
-  update_time_bitrates_[ssrc] = std::make_pair(
-      TickTime::MillisecondTimestamp(), bitrate);
+  bitrate_ = bitrate;
+  bitrate_update_time_ms_ = TickTime::MillisecondTimestamp();
 }
 
 WebRtc_Word32 VieRemb::ChangeUniqueId(const WebRtc_Word32 id) {
@@ -157,20 +148,14 @@
   // Calculate total receive bitrate estimate.
   list_crit_->Enter();
 
-  // Remove any timed out estimates.
-  SsrcTimeBitrate::iterator it = update_time_bitrates_.begin();
-  while (it != update_time_bitrates_.end()) {
-    if (TickTime::MillisecondTimestamp() - it->second.first >
+  // Reset the estimate if it has timed out.
+  if (TickTime::MillisecondTimestamp() - bitrate_update_time_ms_ >
       kRembTimeOutThresholdMs) {
-      update_time_bitrates_.erase(it++);
-    } else {
-      ++it;
-    }
+    bitrate_ = 0;
+    bitrate_update_time_ms_ = -1;
   }
 
-  int num_bitrates = update_time_bitrates_.size();
-
-  if (num_bitrates == 0 || receive_modules_.empty()) {
+  if (bitrate_update_time_ms_ == -1 || receive_modules_.empty()) {
     list_crit_->Leave();
     return 0;
   }
@@ -178,12 +163,6 @@
   // TODO(mflodman) Use std::vector and change RTP module API.
   unsigned int* ssrcs = new unsigned int[receive_modules_.size()];
 
-  unsigned int total_bitrate = 0;
-  for (it = update_time_bitrates_.begin(); it != update_time_bitrates_.end();
-      ++it) {
-    total_bitrate += it->second.second;
-  }
-
   int idx = 0;
   RtpModules::iterator rtp_it;
   for (rtp_it = receive_modules_.begin(); rtp_it != receive_modules_.end();
@@ -198,7 +177,7 @@
   } else {
     sender = receive_modules_.front();
   }
-  last_send_bitrate_ = total_bitrate;
+  last_send_bitrate_ = bitrate_;
 
   // Never send a REMB lower than last_send_bitrate_.
   if (last_send_bitrate_ < kRembMinimumBitrateKbps) {
@@ -207,7 +186,7 @@
   list_crit_->Leave();
 
   if (sender) {
-    sender->SetREMBData(total_bitrate, num_bitrates, ssrcs);
+    sender->SetREMBData(bitrate_, receive_modules_.size(), ssrcs);
   }
   delete [] ssrcs;
   return 0;
diff --git a/src/video_engine/vie_remb.h b/src/video_engine/vie_remb.h
index 7fe12f8..43f373e 100644
--- a/src/video_engine/vie_remb.h
+++ b/src/video_engine/vie_remb.h
@@ -53,12 +53,12 @@
   // Returns true if the instance is in use, false otherwise.
   bool InUse() const;
 
-  // Called every time there is a new bitrate estimate for the received stream
-  // with given SSRC. This call will trigger a new RTCP REMB packet if the
-  // bitrate estimate has decreased or if no RTCP REMB packet has been sent for
+  // Called every time there is a new bitrate estimate for a receive channel
+  // group. This call will trigger a new RTCP REMB packet if the bitrate
+  // estimate has decreased or if no RTCP REMB packet has been sent for
   // a certain time interval.
   // Implements RtpReceiveBitrateUpdate.
-  virtual void OnReceiveBitrateChanged(unsigned int ssrc, unsigned int bitrate);
+  virtual void OnReceiveBitrateChanged(unsigned int bitrate);
 
   // Implements Module.
   virtual WebRtc_Word32 ChangeUniqueId(const WebRtc_Word32 id);
@@ -67,8 +67,6 @@
 
  private:
   typedef std::list<RtpRtcp*> RtpModules;
-  typedef std::map<unsigned int, std::pair<int64_t, unsigned int> >
-      SsrcTimeBitrate;
 
   ProcessThread* process_thread_;
   scoped_ptr<CriticalSectionWrapper> list_crit_;
@@ -83,8 +81,9 @@
   // All modules that can send REMB RTCP.
   RtpModules rtcp_sender_;
 
-  // The last bitrate update for each SSRC.
-  SsrcTimeBitrate update_time_bitrates_;
+  // The last bitrate update.
+  unsigned int bitrate_;
+  int64_t bitrate_update_time_ms_;
 };
 
 }  // namespace webrtc
diff --git a/src/video_engine/vie_remb_unittest.cc b/src/video_engine/vie_remb_unittest.cc
index b024877..3a7f205 100644
--- a/src/video_engine/vie_remb_unittest.cc
+++ b/src/video_engine/vie_remb_unittest.cc
@@ -55,11 +55,11 @@
   vie_remb_->AddRembSender(&rtp);
 
   const unsigned int bitrate_estimate = 456;
-  unsigned int ssrc[] = { 1234 };
+  unsigned int ssrc = 1234;
 
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate);
   EXPECT_CALL(rtp, RemoteSSRC())
-      .WillRepeatedly(Return(ssrc[0]));
+      .WillRepeatedly(Return(ssrc));
 
   // TODO(mflodman) Add fake clock and remove the lowered bitrate below.
   SleepMs(1010);
@@ -68,7 +68,7 @@
   vie_remb_->Process();
 
   // Lower bitrate to send another REMB packet.
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate - 100);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate - 100);
   EXPECT_CALL(rtp, SetREMBData(bitrate_estimate - 100, 1, _))
         .Times(1);
   vie_remb_->Process();
@@ -83,11 +83,11 @@
   vie_remb_->AddRembSender(&rtp);
 
   unsigned int bitrate_estimate = 456;
-  unsigned int ssrc[] = { 1234 };
+  unsigned int ssrc = 1234;
 
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate);
   EXPECT_CALL(rtp, RemoteSSRC())
-      .WillRepeatedly(Return(ssrc[0]));
+      .WillRepeatedly(Return(ssrc));
   // Call process to get a first estimate.
   SleepMs(1010);
   EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, 1, _))
@@ -99,11 +99,11 @@
   bitrate_estimate = bitrate_estimate - 100;
   EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, 1, _))
       .Times(1);
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate);
   vie_remb_->Process();
 }
 
-TEST_F(ViERembTest, VerifyCombinedBitrateEstimate) {
+TEST_F(ViERembTest, VerifyIncreasingAndDecreasing) {
   MockRtpRtcp rtp_0;
   MockRtpRtcp rtp_1;
   vie_remb_->AddReceiveChannel(&rtp_0);
@@ -113,27 +113,32 @@
   unsigned int bitrate_estimate[] = { 456, 789 };
   unsigned int ssrc[] = { 1234, 5678 };
 
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate[0]);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate[0]);
   EXPECT_CALL(rtp_0, RemoteSSRC())
       .Times(AnyNumber())
       .WillRepeatedly(Return(ssrc[0]));
+  EXPECT_CALL(rtp_1, RemoteSSRC())
+      .Times(AnyNumber())
+      .WillRepeatedly(Return(ssrc[1]));
 
   // Call process to get a first estimate.
-  EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate[0], 1, _))
+  EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate[0], 2, _))
         .Times(1);
   SleepMs(1010);
   vie_remb_->Process();
 
-  vie_remb_->OnReceiveBitrateChanged(ssrc[1], bitrate_estimate[1] + 100);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate[1] + 100);
+  EXPECT_CALL(rtp_0, RemoteSSRC())
+      .Times(AnyNumber())
+      .WillRepeatedly(Return(ssrc[0]));
   EXPECT_CALL(rtp_1, RemoteSSRC())
       .Times(AnyNumber())
       .WillRepeatedly(Return(ssrc[1]));
 
   // Lower the estimate to trigger a callback.
-  int total_bitrate = bitrate_estimate[0] + bitrate_estimate[1];
-  EXPECT_CALL(rtp_0, SetREMBData(total_bitrate, 2, _))
+  EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate[1], 2, _))
       .Times(1);
-  vie_remb_->OnReceiveBitrateChanged(ssrc[1], bitrate_estimate[1]);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate[1]);
   vie_remb_->Process();
 
   vie_remb_->RemoveReceiveChannel(&rtp_0);
@@ -148,15 +153,13 @@
   vie_remb_->AddRembSender(&rtp_0);
   vie_remb_->AddReceiveChannel(&rtp_1);
 
-  unsigned int bitrate_estimate[] = { 456, 789 };
+  unsigned int bitrate_estimate = 456;
   unsigned int ssrc[] = { 1234, 5678 };
 
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate[0]);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate);
   EXPECT_CALL(rtp_0, RemoteSSRC())
       .Times(AnyNumber())
       .WillRepeatedly(Return(ssrc[0]));
-
-  vie_remb_->OnReceiveBitrateChanged(ssrc[1], bitrate_estimate[1]);
   EXPECT_CALL(rtp_1, RemoteSSRC())
       .Times(AnyNumber())
       .WillRepeatedly(Return(ssrc[1]));
@@ -164,19 +167,18 @@
   // Trigger a first call to have a running state.
   // TODO(mflodman) Add fake clock.
   SleepMs(1010);
-  EXPECT_CALL(rtp_0,
-              SetREMBData(bitrate_estimate[0] + bitrate_estimate[1], 2, _))
+  EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate, 2, _))
       .Times(1);
   vie_remb_->Process();
 
   // Increased estimate shouldn't trigger a callback right away.
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate[0] + 1);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate + 1);
   EXPECT_CALL(rtp_0, SetREMBData(_, _, _))
       .Times(0);
 
-  // Decresing the estimate less than 3% shouldn't trigger a new callback.
-  int lower_estimate = bitrate_estimate[0] * 98 / 100;
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], lower_estimate);
+  // Decreasing the estimate less than 3% shouldn't trigger a new callback.
+  int lower_estimate = bitrate_estimate * 98 / 100;
+  vie_remb_->OnReceiveBitrateChanged(lower_estimate);
   EXPECT_CALL(rtp_0, SetREMBData(_, _, _))
       .Times(0);
 
@@ -193,45 +195,40 @@
   vie_remb_->AddRembSender(&rtp_0);
   vie_remb_->AddReceiveChannel(&rtp_1);
 
-  unsigned int bitrate_estimate[] = { 456, 789 };
+  unsigned int bitrate_estimate = 456;
   unsigned int ssrc[] = { 1234, 5678 };
 
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate[0]);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate);
   EXPECT_CALL(rtp_0, RemoteSSRC())
       .Times(AnyNumber())
       .WillRepeatedly(Return(ssrc[0]));
-
-  vie_remb_->OnReceiveBitrateChanged(ssrc[1], bitrate_estimate[1]);
   EXPECT_CALL(rtp_1, RemoteSSRC())
       .Times(AnyNumber())
       .WillRepeatedly(Return(ssrc[1]));
 
   // Call process to get a first estimate.
   SleepMs(1010);
-  EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate[0] + bitrate_estimate[1], 2,
-                                 _))
+  EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate, 2, _))
       .Times(1);
   vie_remb_->Process();
 
   // Decrease estimate to trigger a REMB.
-  bitrate_estimate[0] = bitrate_estimate[0] - 100;
-  EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate[0] + bitrate_estimate[1], 2,
-                                 _))
+  bitrate_estimate = bitrate_estimate - 100;
+  EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate, 2, _))
       .Times(1);
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate[0]);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate);
   vie_remb_->Process();
 
   // Remove the sending module, add it again -> should get remb on the second
   // module.
   vie_remb_->RemoveRembSender(&rtp_0);
   vie_remb_->AddRembSender(&rtp_1);
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate[0]);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate);
 
-  bitrate_estimate[1] = bitrate_estimate[1] - 100;
-  EXPECT_CALL(rtp_1, SetREMBData(bitrate_estimate[0] + bitrate_estimate[1], 2,
-                                 _))
+  bitrate_estimate = bitrate_estimate - 100;
+  EXPECT_CALL(rtp_1, SetREMBData(bitrate_estimate, 2, _))
         .Times(1);
-  vie_remb_->OnReceiveBitrateChanged(ssrc[1], bitrate_estimate[1]);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate);
   vie_remb_->Process();
 
   vie_remb_->RemoveReceiveChannel(&rtp_0);
@@ -241,13 +238,13 @@
 TEST_F(ViERembTest, OnlyOneRembForDoubleProcess) {
   MockRtpRtcp rtp;
   unsigned int bitrate_estimate = 456;
-  unsigned int ssrc[] = { 1234 };
+  unsigned int ssrc = 1234;
 
   vie_remb_->AddReceiveChannel(&rtp);
   vie_remb_->AddRembSender(&rtp);
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate);
   EXPECT_CALL(rtp, RemoteSSRC())
-      .WillRepeatedly(Return(ssrc[0]));
+      .WillRepeatedly(Return(ssrc));
 
   // Call process to get a first estimate.
   SleepMs(1010);
@@ -259,7 +256,7 @@
   bitrate_estimate = bitrate_estimate - 100;
   EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, 1, _))
       .Times(1);
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate);
   vie_remb_->Process();
 
   // Call Process again, this should not trigger a new callback.
@@ -295,11 +292,11 @@
   vie_remb_->AddReceiveChannel(&rtp);
 
   unsigned int bitrate_estimate = 456;
-  unsigned int ssrc[] = { 1234 };
+  unsigned int ssrc = 1234;
 
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate);
   EXPECT_CALL(rtp, RemoteSSRC())
-      .WillRepeatedly(Return(ssrc[0]));
+      .WillRepeatedly(Return(ssrc));
 
   // Call process to get a first estimate.
   SleepMs(1010);
@@ -311,7 +308,7 @@
   bitrate_estimate = bitrate_estimate - 100;
   EXPECT_CALL(rtp, SetREMBData(_, _, _))
       .Times(1);
-  vie_remb_->OnReceiveBitrateChanged(ssrc[0], bitrate_estimate);
+  vie_remb_->OnReceiveBitrateChanged(bitrate_estimate);
   vie_remb_->Process();
 }