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

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

Issue 1507313005: [rtp_rtcp] SSRCDatabase class cleaned (including all lint errors) (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: removed incorrect ssrc validations: SSRC is not prohibited to be 0 or -1 Created 5 years 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
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/ssrc_database.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c9572cd1b7c26ae6617031043a521a55f2b7a7c7..fb02b7ef12cd12f785fd18ed331e1407d3fd38c4 100644
--- a/webrtc/modules/rtp_rtcp/source/ssrc_database.cc
+++ b/webrtc/modules/rtp_rtcp/source/ssrc_database.cc
@@ -10,92 +10,51 @@
#include "webrtc/modules/rtp_rtcp/source/ssrc_database.h"
-#include <assert.h>
-#include <stdlib.h>
-
+#include "webrtc/base/checks.h"
+#include "webrtc/system_wrappers/include/clock.h"
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-#ifdef _WIN32
-#include <windows.h>
-#include <MMSystem.h> // timeGetTime
-
-// TODO(hellner): investigate if it is necessary to disable these warnings.
-#pragma warning(disable : 4311)
-#pragma warning(disable : 4312)
-#else
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <sys/time.h>
-#endif
-
namespace webrtc {
-SSRCDatabase* SSRCDatabase::StaticInstance(CountOperation count_operation) {
- SSRCDatabase* impl = GetStaticInstance<SSRCDatabase>(count_operation);
- return impl;
+namespace {
+uint64_t Seed() {
+ return Clock::GetRealTimeClock()->TimeInMicroseconds();
}
+} // namespace
SSRCDatabase* SSRCDatabase::GetSSRCDatabase() {
- return StaticInstance(kAddRef);
+ return GetStaticInstance<SSRCDatabase>(kAddRef);
}
void SSRCDatabase::ReturnSSRCDatabase() {
- StaticInstance(kRelease);
+ GetStaticInstance<SSRCDatabase>(kRelease);
}
uint32_t SSRCDatabase::CreateSSRC() {
- CriticalSectionScoped lock(_critSect);
-
- uint32_t ssrc = GenerateRandom();
-
- while (_ssrcMap.find(ssrc) != _ssrcMap.end()) {
- ssrc = GenerateRandom();
+ CriticalSectionScoped lock(crit_.get());
+
+ while (true) { // Try until get a new ssrc.
+ // 0 and 0xffffffff are invalid values for SSRC.
+ uint32_t ssrc = random_.Rand(1u, 0xfffffffe);
+ if (ssrcs_.insert(ssrc).second) {
+ return ssrc;
+ }
}
- _ssrcMap[ssrc] = 0;
-
- return ssrc;
}
-int32_t SSRCDatabase::RegisterSSRC(const uint32_t ssrc) {
- CriticalSectionScoped lock(_critSect);
- _ssrcMap[ssrc] = 0;
- return 0;
+void SSRCDatabase::RegisterSSRC(uint32_t ssrc) {
+ CriticalSectionScoped lock(crit_.get());
+ ssrcs_.insert(ssrc);
}
-int32_t SSRCDatabase::ReturnSSRC(const uint32_t ssrc) {
- CriticalSectionScoped lock(_critSect);
- _ssrcMap.erase(ssrc);
- return 0;
+void SSRCDatabase::ReturnSSRC(uint32_t ssrc) {
+ CriticalSectionScoped lock(crit_.get());
+ ssrcs_.erase(ssrc);
}
-SSRCDatabase::SSRCDatabase() {
-// we need to seed the random generator, otherwise we get 26500 each time,
-// hardly a random value :)
-#ifdef _WIN32
- srand(timeGetTime());
-#else
- struct timeval tv;
- struct timezone tz;
- gettimeofday(&tv, &tz);
- srand(tv.tv_usec);
-#endif
-
- _critSect = CriticalSectionWrapper::CreateCriticalSection();
-}
+SSRCDatabase::SSRCDatabase()
+ : crit_(CriticalSectionWrapper::CreateCriticalSection()), random_(Seed()) {}
SSRCDatabase::~SSRCDatabase() {
- _ssrcMap.clear();
- delete _critSect;
}
-uint32_t SSRCDatabase::GenerateRandom() {
- uint32_t ssrc = 0;
- do {
- ssrc = rand();
- ssrc = ssrc << 16;
- ssrc += rand();
- } while (ssrc == 0 || ssrc == 0xffffffff);
-
- return ssrc;
-}
} // namespace webrtc
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/ssrc_database.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698