 Chromium Code Reviews
 Chromium Code Reviews Issue 1623543002:
  Refactor RtpSender and SSRCDatabase a bit.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master
    
  
    Issue 1623543002:
  Refactor RtpSender and SSRCDatabase a bit.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master| Index: webrtc/modules/rtp_rtcp/source/ssrc_database.cc | 
| diff --git a/webrtc/modules/rtp_rtcp/source/ssrc_database.cc b/webrtc/modules/rtp_rtcp/source/ssrc_database.cc | 
| index fb02b7ef12cd12f785fd18ed331e1407d3fd38c4..9ffdd1b9869c5dbfa94fc1fcaeb454e6f8892570 100644 | 
| --- a/webrtc/modules/rtp_rtcp/source/ssrc_database.cc | 
| +++ b/webrtc/modules/rtp_rtcp/source/ssrc_database.cc | 
| @@ -11,15 +11,9 @@ | 
| #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h" | 
| #include "webrtc/base/checks.h" | 
| -#include "webrtc/system_wrappers/include/clock.h" | 
| -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 
| +#include "webrtc/system_wrappers/include/tick_util.h" | 
| namespace webrtc { | 
| -namespace { | 
| -uint64_t Seed() { | 
| - return Clock::GetRealTimeClock()->TimeInMicroseconds(); | 
| -} | 
| -} // namespace | 
| SSRCDatabase* SSRCDatabase::GetSSRCDatabase() { | 
| return GetStaticInstance<SSRCDatabase>(kAddRef); | 
| @@ -29,8 +23,12 @@ void SSRCDatabase::ReturnSSRCDatabase() { | 
| GetStaticInstance<SSRCDatabase>(kRelease); | 
| } | 
| +// TODO(tommi, holmer): Look into whether we can eliminate locking in this | 
| +// class. At the moment voe_auto_test requires it, but it's not clear if that's | 
| +// an issue with the test code or if it reflects real world usage or if that's | 
| +// the best design performance wise. | 
| 
stefan-webrtc
2016/01/26 13:19:52
Should this mention getting rid of the static inst
 
tommi
2016/01/30 10:53:41
Comment updated and moved to the header.
 | 
| uint32_t SSRCDatabase::CreateSSRC() { | 
| - CriticalSectionScoped lock(crit_.get()); | 
| + rtc::CritScope lock(&crit_); | 
| while (true) { // Try until get a new ssrc. | 
| // 0 and 0xffffffff are invalid values for SSRC. | 
| @@ -42,19 +40,24 @@ uint32_t SSRCDatabase::CreateSSRC() { | 
| } | 
| void SSRCDatabase::RegisterSSRC(uint32_t ssrc) { | 
| - CriticalSectionScoped lock(crit_.get()); | 
| + rtc::CritScope lock(&crit_); | 
| ssrcs_.insert(ssrc); | 
| } | 
| void SSRCDatabase::ReturnSSRC(uint32_t ssrc) { | 
| - CriticalSectionScoped lock(crit_.get()); | 
| + rtc::CritScope lock(&crit_); | 
| ssrcs_.erase(ssrc); | 
| } | 
| -SSRCDatabase::SSRCDatabase() | 
| - : crit_(CriticalSectionWrapper::CreateCriticalSection()), random_(Seed()) {} | 
| +// For initializing the random seed, we don't use TimeInMicroseconds() since it | 
| +// can return 0 on Mac if we're called early on during process startup (e.g. | 
| +// in tests). This is because when the tick count gets converted into | 
| +// microseconds, we can end up multiplying with 0 and end up with a seed of 0. | 
| +// TODO(tommi): Move this into the Random() class itself. At the moment that's | 
| +// not possible because the Random class is in webrtc/base but TickTime is | 
| +// in webrtc/system_wrappers/include/. | 
| 
stefan-webrtc
2016/01/26 13:19:52
As mentioned in earlier comments, an option would
 
tommi
2016/01/30 10:53:41
Updated comment.  Erik has been making some improv
 | 
| +SSRCDatabase::SSRCDatabase() : random_(TickTime::Now().Ticks()) {} | 
| -SSRCDatabase::~SSRCDatabase() { | 
| -} | 
| +SSRCDatabase::~SSRCDatabase() {} | 
| } // namespace webrtc |