Prevent sender RTCP signals for receive-only channels.

Since RTCP packets are delivered to both senders and receivers that
correspond the receivers currently log that NACKed packets are missing,
since they have no direct connection to the sending side or the RTP
packet history. Also preventing triggering on SR requests and PLI/FIR.

BUG=
R=asapersson@webrtc.org, stefan@webrtc.org

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

Cr-Commit-Position: refs/heads/master@{#9071}
diff --git a/webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h b/webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h
index 1623554..fb47a2b 100644
--- a/webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h
+++ b/webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h
@@ -54,6 +54,7 @@
     */
     int32_t id;
     bool audio;
+    bool receiver_only;
     Clock* clock;
     ReceiveStatistics* receive_statistics;
     Transport* outgoing_transport;
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_format_remb_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_format_remb_unittest.cc
index 3c1a9a3..ea50ffa 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_format_remb_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_format_remb_unittest.cc
@@ -96,7 +96,7 @@
   dummy_rtp_rtcp_impl_ = new ModuleRtpRtcpImpl(configuration);
   rtcp_sender_ = new RTCPSender(0, false, system_clock_,
                                 receive_statistics_.get(), NULL);
-  rtcp_receiver_ = new RTCPReceiver(0, system_clock_, NULL, NULL, NULL,
+  rtcp_receiver_ = new RTCPReceiver(0, system_clock_, false, NULL, NULL, NULL,
                                     dummy_rtp_rtcp_impl_);
   test_transport_ = new TestTransport(rtcp_receiver_);
 
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc
index 02f1fa3..f50ce17 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc
@@ -10,11 +10,12 @@
 
 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h"
 
-#include <assert.h> //assert
-#include <string.h> //memset
+#include <assert.h>
+#include <string.h>
 
 #include <algorithm>
 
+#include "webrtc/base/checks.h"
 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h"
 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
@@ -31,12 +32,14 @@
 RTCPReceiver::RTCPReceiver(
     int32_t id,
     Clock* clock,
+    bool receiver_only,
     RtcpPacketTypeCounterObserver* packet_type_counter_observer,
     RtcpBandwidthObserver* rtcp_bandwidth_observer,
     RtcpIntraFrameObserver* rtcp_intra_frame_observer,
     ModuleRtpRtcpImpl* owner)
     : TMMBRHelp(),
       _clock(clock),
+      receiver_only_(receiver_only),
       _method(kRtcpOff),
       _lastReceived(0),
       _rtpRtcp(*owner),
@@ -781,7 +784,7 @@
 void RTCPReceiver::HandleNACK(RTCPUtility::RTCPParserV2& rtcpParser,
                               RTCPPacketInformation& rtcpPacketInformation) {
   const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet();
-  if (main_ssrc_ != rtcpPacket.NACK.MediaSSRC) {
+  if (receiver_only_ || main_ssrc_ != rtcpPacket.NACK.MediaSSRC) {
     // Not to us.
     rtcpParser.Iterate();
     return;
@@ -1311,16 +1314,18 @@
     // Might trigger a OnReceivedBandwidthEstimateUpdate.
     UpdateTMMBR();
   }
-  unsigned int local_ssrc = 0;
+  unsigned int local_ssrc;
   {
     // We don't want to hold this critsect when triggering the callbacks below.
     CriticalSectionScoped lock(_criticalSectionRTCPReceiver);
     local_ssrc = main_ssrc_;
   }
-  if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSrReq) {
+  if (!receiver_only_ &&
+      rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSrReq) {
     _rtpRtcp.OnRequestSendReport();
   }
-  if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpNack) {
+  if (!receiver_only_ &&
+      rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpNack) {
     if (rtcpPacketInformation.nackSequenceNumbers.size() > 0) {
       LOG(LS_VERBOSE) << "Incoming NACK length: "
                    << rtcpPacketInformation.nackSequenceNumbers.size();
@@ -1333,6 +1338,7 @@
     // report can generate several RTCP packets, based on number relayed/mixed
     // a send report block should go out to all receivers.
     if (_cbRtcpIntraFrameObserver) {
+      DCHECK(!receiver_only_);
       if ((rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpPli) ||
           (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpFir)) {
         if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpPli) {
@@ -1354,6 +1360,7 @@
       }
     }
     if (_cbRtcpBandwidthObserver) {
+      DCHECK(!receiver_only_);
       if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRemb) {
         LOG(LS_VERBOSE) << "Incoming REMB: "
                         << rtcpPacketInformation.receiverEstimatedMaxBitrate;
@@ -1371,7 +1378,7 @@
     }
   }
 
-  {
+  if (!receiver_only_) {
     CriticalSectionScoped cs(_criticalSectionFeedbacks);
     if (stats_callback_) {
       for (ReportBlockList::const_iterator it =
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h
index 2086afc..569af90 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h
@@ -31,6 +31,7 @@
 public:
  RTCPReceiver(int32_t id,
               Clock* clock,
+              bool receiver_only,
               RtcpPacketTypeCounterObserver* packet_type_counter_observer,
               RtcpBandwidthObserver* rtcp_bandwidth_observer,
               RtcpIntraFrameObserver* rtcp_intra_frame_observer,
@@ -231,7 +232,8 @@
       uint32_t remote_ssrc, uint32_t source_ssrc) const
           EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
 
-  Clock* _clock;
+  Clock* const _clock;
+  const bool receiver_only_;
   RTCPMethod _method;
   int64_t _lastReceived;
   ModuleRtpRtcpImpl& _rtpRtcp;
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc
index f2ea04b..1082b30 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc
@@ -84,8 +84,8 @@
     configuration.outgoing_transport = test_transport_;
     configuration.remote_bitrate_estimator = remote_bitrate_estimator_.get();
     rtp_rtcp_impl_ = new ModuleRtpRtcpImpl(configuration);
-    rtcp_receiver_ = new RTCPReceiver(0, &system_clock_, NULL, NULL, NULL,
-                                      rtp_rtcp_impl_);
+    rtcp_receiver_ = new RTCPReceiver(0, &system_clock_, false, NULL, NULL,
+                                      NULL, rtp_rtcp_impl_);
     test_transport_->SetRTCPReceiver(rtcp_receiver_);
   }
   ~RtcpReceiverTest() {
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc
index a35b7c3..6def724 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc
@@ -303,8 +303,8 @@
         0, &clock_, test_transport_, NULL, rtp_payload_registry_.get()));
     rtcp_sender_ =
         new RTCPSender(0, false, &clock_, receive_statistics_.get(), NULL);
-    rtcp_receiver_ = new RTCPReceiver(0, &clock_, NULL, NULL, NULL,
-                                      rtp_rtcp_impl_);
+    rtcp_receiver_ =
+        new RTCPReceiver(0, &clock_, false, NULL, NULL, NULL, rtp_rtcp_impl_);
     test_transport_->SetRTCPReceiver(rtcp_receiver_);
     // Initialize
     EXPECT_EQ(0, rtcp_sender_->RegisterSendTransport(test_transport_));
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
index 93b5f54..611e0c0 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
@@ -29,6 +29,7 @@
 RtpRtcp::Configuration::Configuration()
     : id(-1),
       audio(false),
+      receiver_only(false),
       clock(NULL),
       receive_statistics(NullObjectReceiveStatistics()),
       outgoing_transport(NULL),
@@ -74,6 +75,7 @@
                    configuration.rtcp_packet_type_counter_observer),
       rtcp_receiver_(configuration.id,
                      configuration.clock,
+                     configuration.receiver_only,
                      configuration.rtcp_packet_type_counter_observer,
                      configuration.bandwidth_callback,
                      configuration.intra_frame_callback,
@@ -85,7 +87,7 @@
       last_process_time_(configuration.clock->TimeInMilliseconds()),
       last_bitrate_process_time_(configuration.clock->TimeInMilliseconds()),
       last_rtt_process_time_(configuration.clock->TimeInMilliseconds()),
-      packet_overhead_(28),  // IPV4 UDP.
+      packet_overhead_(28),                     // IPV4 UDP.
       padding_index_(static_cast<size_t>(-1)),  // Start padding at first child.
       nack_method_(kNackOff),
       nack_last_time_sent_full_(0),
diff --git a/webrtc/video_engine/vie_channel.cc b/webrtc/video_engine/vie_channel.cc
index 557f14d..0dbefc3 100644
--- a/webrtc/video_engine/vie_channel.cc
+++ b/webrtc/video_engine/vie_channel.cc
@@ -1851,8 +1851,10 @@
   RtpRtcp::Configuration configuration;
   configuration.id = ViEModuleId(engine_id_, channel_id_);
   configuration.audio = false;
+  configuration.receiver_only = !sender_;
   configuration.outgoing_transport = &vie_sender_;
-  configuration.intra_frame_callback = intra_frame_observer_;
+  if (sender_)
+    configuration.intra_frame_callback = intra_frame_observer_;
   configuration.rtt_stats = rtt_stats_;
   configuration.rtcp_packet_type_counter_observer =
       &rtcp_packet_type_counter_observer_;