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

Side by Side 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 TODOs for Random() and delete dead code from Timing (move to separate cl?) 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h" 11 #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/system_wrappers/include/clock.h" 14 #include "webrtc/system_wrappers/include/tick_util.h"
15 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
16 15
17 namespace webrtc { 16 namespace webrtc {
18 namespace {
19 uint64_t Seed() {
20 return Clock::GetRealTimeClock()->TimeInMicroseconds();
21 }
22 } // namespace
23 17
24 SSRCDatabase* SSRCDatabase::GetSSRCDatabase() { 18 // For initializing the random seed, we don't use TimeInMicroseconds() since it
25 return GetStaticInstance<SSRCDatabase>(kAddRef); 19 // can return 0 on Mac if we're called early on during process startup (e.g.
20 // in tests). This is because when the tick count gets converted into
21 // microseconds, we can end up multiplying with 0 and end up with a seed of 0.
22 // TODO(tommi): Move this into the Random() class itself. At the moment that's
23 // not possible because the Random class is in webrtc/base but TickTime is
24 // in webrtc/system_wrappers/include/.
25 SSRCDatabase::SSRCDatabase() : random_(TickTime::Now().Ticks()) {}
26
27 SSRCDatabase::~SSRCDatabase() {
28 RTC_DCHECK(thread_checker_.CalledOnValidThread());
26 } 29 }
27 30
28 void SSRCDatabase::ReturnSSRCDatabase() { 31 // TODO(tommi, holmer): Look into whether we can eliminate locking in this
29 GetStaticInstance<SSRCDatabase>(kRelease); 32 // class. At the moment voe_auto_test requires it, but it's not clear if that's
30 } 33 // an issue with the test code or if it reflects real world usage or if that's
31 34 // the best design performance wise.
32 uint32_t SSRCDatabase::CreateSSRC() { 35 uint32_t SSRCDatabase::CreateSSRC() {
33 CriticalSectionScoped lock(crit_.get()); 36 rtc::CritScope lock(&crit_);
34 37
35 while (true) { // Try until get a new ssrc. 38 while (true) { // Try until get a new ssrc.
36 // 0 and 0xffffffff are invalid values for SSRC. 39 // 0 and 0xffffffff are invalid values for SSRC.
37 uint32_t ssrc = random_.Rand(1u, 0xfffffffe); 40 uint32_t ssrc = random_.Rand(1u, 0xfffffffe);
38 if (ssrcs_.insert(ssrc).second) { 41 if (ssrcs_.insert(ssrc).second) {
39 return ssrc; 42 return ssrc;
40 } 43 }
41 } 44 }
42 } 45 }
43 46
44 void SSRCDatabase::RegisterSSRC(uint32_t ssrc) { 47 void SSRCDatabase::RegisterSSRC(uint32_t ssrc) {
45 CriticalSectionScoped lock(crit_.get()); 48 rtc::CritScope lock(&crit_);
46 ssrcs_.insert(ssrc); 49 ssrcs_.insert(ssrc);
47 } 50 }
48 51
49 void SSRCDatabase::ReturnSSRC(uint32_t ssrc) { 52 void SSRCDatabase::ReturnSSRC(uint32_t ssrc) {
50 CriticalSectionScoped lock(crit_.get()); 53 rtc::CritScope lock(&crit_);
51 ssrcs_.erase(ssrc); 54 ssrcs_.erase(ssrc);
52 } 55 }
53 56
54 SSRCDatabase::SSRCDatabase()
55 : crit_(CriticalSectionWrapper::CreateCriticalSection()), random_(Seed()) {}
56
57 SSRCDatabase::~SSRCDatabase() {
58 }
59
60 } // namespace webrtc 57 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698