Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Unified Diff: webrtc/modules/rtp_rtcp/source/ssrc_database.cc

Issue 1623543002: Refactor RtpSender and SSRCDatabase a bit. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add locking back for voe_auto_test Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..87c0a897fd49303843b87dba477f903007325e39 100644
--- a/webrtc/modules/rtp_rtcp/source/ssrc_database.cc
+++ b/webrtc/modules/rtp_rtcp/source/ssrc_database.cc
@@ -11,26 +11,26 @@
#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);
-}
+// 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.
+SSRCDatabase::SSRCDatabase() : random_(TickTime::Now().Ticks()) {}
stefan-webrtc 2016/01/23 17:38:40 Would it make sense to have a static metod in Rand
tommi 2016/01/24 11:51:50 Indeed - looks like all users of Random are callin
-void SSRCDatabase::ReturnSSRCDatabase() {
- GetStaticInstance<SSRCDatabase>(kRelease);
+SSRCDatabase::~SSRCDatabase() {
+ RTC_DCHECK(thread_checker_.CalledOnValidThread());
}
+// 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.
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 +42,13 @@ 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()) {}
-
-SSRCDatabase::~SSRCDatabase() {
-}
-
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698