Sets sending status for active RtpRtcp modules.

When a simulcast stream is enabled or disabled, we want this state
change to be reflected properly in the RtpRtcp modules. Each video send
stream can contain multiple rtp_rtcp_modules pertaining to different
simulcast streams. These modules are currently all turned on/off when
the send stream is started and stopped. This change allows for
individual modules to be turned on/off. This means if a module stops
sending it will send a bye message, so the receiving side will not
expect more frames to be sent when the stream is inactive and the
encoder is no longer encoding/sending images.

Bug: webrtc:8653
Change-Id: Ib6d00240f627b4ff1714646e847026f24c7c3aa4
Reviewed-on: https://webrtc-review.googlesource.com/42841
Commit-Queue: Seth Hampson <shampson@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21880}
diff --git a/video/payload_router.cc b/video/payload_router.cc
index 1d16fbd..4ecb620 100644
--- a/video/payload_router.cc
+++ b/video/payload_router.cc
@@ -151,11 +151,22 @@
   rtc::CritScope lock(&crit_);
   if (active_ == active)
     return;
-  active_ = active;
+  const std::vector<bool> active_modules(rtp_modules_.size(), active);
+  SetActiveModules(active_modules);
+}
 
-  for (auto& module : rtp_modules_) {
-    module->SetSendingStatus(active_);
-    module->SetSendingMediaStatus(active_);
+void PayloadRouter::SetActiveModules(const std::vector<bool> active_modules) {
+  rtc::CritScope lock(&crit_);
+  RTC_DCHECK_EQ(rtp_modules_.size(), active_modules.size());
+  active_ = false;
+  for (size_t i = 0; i < active_modules.size(); ++i) {
+    if (active_modules[i]) {
+      active_ = true;
+    }
+    // Sends a kRtcpByeCode when going from true to false.
+    rtp_modules_[i]->SetSendingStatus(active_modules[i]);
+    // If set to false this module won't send media.
+    rtp_modules_[i]->SetSendingMediaStatus(active_modules[i]);
   }
 }
 
@@ -217,6 +228,10 @@
     params_[stream_index].Set(&rtp_video_header);
   }
   uint32_t frame_id;
+  if (!rtp_modules_[stream_index]->Sending()) {
+    // The payload router could be active but this module isn't sending.
+    return Result(Result::ERROR_SEND_FAILED);
+  }
   bool send_result = rtp_modules_[stream_index]->SendOutgoingData(
       encoded_image._frameType, payload_type_, encoded_image._timeStamp,
       encoded_image.capture_time_ms_, encoded_image._buffer,