TMMBRHelp moved from member object/base class to stack object,
indicating the usage of this helper is local.
With local usage critical section become obvisously useless and removed.

BUG=webrtc:5565
R=åsapersson

Review-Url: https://codereview.webrtc.org/1959013003
Cr-Commit-Position: refs/heads/master@{#12881}
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc
index 3e8e47f..34b2ce3 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc
@@ -20,6 +20,7 @@
 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h"
 #include "webrtc/modules/rtp_rtcp/source/time_util.h"
+#include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
 #include "webrtc/system_wrappers/include/ntp_time.h"
 
 namespace webrtc {
@@ -44,8 +45,7 @@
     RtcpIntraFrameObserver* rtcp_intra_frame_observer,
     TransportFeedbackObserver* transport_feedback_observer,
     ModuleRtpRtcpImpl* owner)
-    : TMMBRHelp(),
-      _clock(clock),
+    : _clock(clock),
       receiver_only_(receiver_only),
       _lastReceived(0),
       _rtpRtcp(*owner),
@@ -1233,22 +1233,20 @@
   rtcp_parser->Iterate();
 }
 int32_t RTCPReceiver::UpdateTMMBR() {
+  TMMBRHelp tmmbr_help;
   int32_t numBoundingSet = 0;
   uint32_t bitrate = 0;
   uint32_t accNumCandidates = 0;
 
   int32_t size = TMMBRReceived(0, 0, NULL);
   if (size > 0) {
-    TMMBRSet* candidateSet = VerifyAndAllocateCandidateSet(size);
+    TMMBRSet* candidateSet = tmmbr_help.VerifyAndAllocateCandidateSet(size);
     // Get candidate set from receiver.
     accNumCandidates = TMMBRReceived(size, accNumCandidates, candidateSet);
-  } else {
-    // Candidate set empty.
-    VerifyAndAllocateCandidateSet(0);  // resets candidate set
   }
   // Find bounding set
   TMMBRSet* boundingSet = NULL;
-  numBoundingSet = FindTMMBRBoundingSet(boundingSet);
+  numBoundingSet = tmmbr_help.FindTMMBRBoundingSet(boundingSet);
   if (numBoundingSet == -1) {
     LOG(LS_WARNING) << "Failed to find TMMBR bounding set.";
     return -1;
@@ -1265,7 +1263,7 @@
     return 0;
   }
   // Get net bitrate from bounding set depending on sent packet rate
-  if (CalcMinBitRate(&bitrate)) {
+  if (tmmbr_help.CalcMinBitRate(&bitrate)) {
     // we have a new bandwidth estimate on this channel
     if (_cbRtcpBandwidthObserver) {
         _cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate(bitrate * 1000);
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h
index 28c28cb6..f64baeb 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h
@@ -21,13 +21,12 @@
 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver_help.h"
 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
-#include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
 #include "webrtc/typedefs.h"
 
 namespace webrtc {
 class ModuleRtpRtcpImpl;
 
-class RTCPReceiver : public TMMBRHelp
+class RTCPReceiver
 {
 public:
  RTCPReceiver(Clock* clock,
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc
index 4a509b0..7113807 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc
@@ -36,6 +36,7 @@
 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h"
 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h"
+#include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
 
 namespace webrtc {
 
@@ -169,7 +170,6 @@
 
       remb_bitrate_(0),
 
-      tmmbr_help_(),
       tmmbr_send_(0),
       packet_oh_send_(0),
       max_payload_length_(IP_PACKET_SIZE - 28),  // IPv4 + UDP by default.
@@ -585,10 +585,11 @@
   // * If the sender is an owner of the TMMBN -> send TMMBR
   // * If not an owner but the TMMBR would enter the TMMBN -> send TMMBR
 
+  TMMBRHelp tmmbr_help;
   // get current bounding set from RTCP receiver
   bool tmmbrOwner = false;
   // store in candidateSet, allocates one extra slot
-  TMMBRSet* candidateSet = tmmbr_help_.CandidateSet();
+  TMMBRSet* candidateSet = tmmbr_help.CandidateSet();
 
   // holding critical_section_rtcp_sender_ while calling RTCPreceiver which
   // will accuire criticalSectionRTCPReceiver_ is a potental deadlock but
@@ -613,9 +614,9 @@
 
       // find bounding set
       TMMBRSet* boundingSet = nullptr;
-      int numBoundingSet = tmmbr_help_.FindTMMBRBoundingSet(boundingSet);
+      int numBoundingSet = tmmbr_help.FindTMMBRBoundingSet(boundingSet);
       if (numBoundingSet > 0 || numBoundingSet <= numCandidates)
-        tmmbrOwner = tmmbr_help_.IsOwner(ssrc_, numBoundingSet);
+        tmmbrOwner = tmmbr_help.IsOwner(ssrc_, numBoundingSet);
       if (!tmmbrOwner) {
         // Did not enter bounding set, no meaning to send this request.
         return nullptr;
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender.h b/webrtc/modules/rtp_rtcp/source/rtcp_sender.h
index 02719aa..6f94de5 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_sender.h
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender.h
@@ -28,8 +28,8 @@
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.h"
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmb_item.h"
 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
-#include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
 #include "webrtc/transport.h"
 #include "webrtc/typedefs.h"
 
@@ -240,7 +240,6 @@
   uint32_t remb_bitrate_ GUARDED_BY(critical_section_rtcp_sender_);
   std::vector<uint32_t> remb_ssrcs_ GUARDED_BY(critical_section_rtcp_sender_);
 
-  TMMBRHelp tmmbr_help_ GUARDED_BY(critical_section_rtcp_sender_);
   std::vector<rtcp::TmmbItem> tmmbn_to_send_
       GUARDED_BY(critical_section_rtcp_sender_);
   uint32_t tmmbr_send_ GUARDED_BY(critical_section_rtcp_sender_);
diff --git a/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc b/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc
index 43d3a82..5e4c6f1 100644
--- a/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc
+++ b/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc
@@ -83,8 +83,6 @@
 TMMBRSet*
 TMMBRHelp::VerifyAndAllocateBoundingSet(uint32_t minimumSize)
 {
-    rtc::CritScope lock(&_criticalSection);
-
     if(minimumSize > _boundingSet.capacity())
     {
         // make sure that our buffers are big enough
@@ -107,8 +105,6 @@
 TMMBRSet*
 TMMBRHelp::VerifyAndAllocateCandidateSet(uint32_t minimumSize)
 {
-    rtc::CritScope lock(&_criticalSection);
-
     _candidateSet.VerifyAndAllocateSet(minimumSize);
     return &_candidateSet;
 }
@@ -122,8 +118,6 @@
 int32_t
 TMMBRHelp::FindTMMBRBoundingSet(TMMBRSet*& boundingSet)
 {
-    rtc::CritScope lock(&_criticalSection);
-
     // Work on local variable, will be modified
     TMMBRSet    candidateSet;
     candidateSet.VerifyAndAllocateSet(_candidateSet.capacity());
@@ -165,8 +159,6 @@
 int32_t
 TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
 {
-    rtc::CritScope lock(&_criticalSection);
-
     uint32_t numBoundingSet = 0;
     VerifyAndAllocateBoundingSet(candidateSet.capacity());
 
@@ -370,8 +362,6 @@
 
 bool TMMBRHelp::IsOwner(const uint32_t ssrc,
                         const uint32_t length) const {
-  rtc::CritScope lock(&_criticalSection);
-
   if (length == 0) {
     // Empty bounding set.
     return false;
@@ -386,8 +376,6 @@
 }
 
 bool TMMBRHelp::CalcMinBitRate( uint32_t* minBitrateKbit) const {
-  rtc::CritScope lock(&_criticalSection);
-
   if (_candidateSet.size() == 0) {
     // Empty bounding set.
     return false;
diff --git a/webrtc/modules/rtp_rtcp/source/tmmbr_help.h b/webrtc/modules/rtp_rtcp/source/tmmbr_help.h
index ffafb14..08b2438 100644
--- a/webrtc/modules/rtp_rtcp/source/tmmbr_help.h
+++ b/webrtc/modules/rtp_rtcp/source/tmmbr_help.h
@@ -12,7 +12,6 @@
 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_TMMBR_HELP_H_
 
 #include <vector>
-#include "webrtc/base/criticalsection.h"
 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmb_item.h"
 #include "webrtc/typedefs.h"
 
@@ -76,7 +75,6 @@
     int32_t FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet);
 
 private:
-    rtc::CriticalSection    _criticalSection;
     TMMBRSet                _candidateSet;
     TMMBRSet                _boundingSet;