tommi ae695e95a6 Refactor RtpSender and SSRCDatabase.
* SSRCDatabase doesn't need to be a global instance, so I've changed it to be a "regular" class (i.e. construct via ctor, not maybe via GetSSRCDatabase( + release via ReturnSSRCDatabase())).  If we ever have parallel tests running in the same process, they won't have the problem of using the same ssrc database.

* Made RtpSender a more const.  Also added some todos for myself and holmer to look into clarifying the threading model.

* Switched from CriticalSectionWrapper to rtc::CriticalSection

* Changed the random seeding to use TickTime::Now().Ticks() since TimeInMicroseconds() could return 0 when the process was starting.  This is what TimeInMicroseconds() does anyway but now we don't need to access a global clock object.

BUG=webrtc:3062

Review URL: https://codereview.webrtc.org/1623543002

Cr-Commit-Position: refs/heads/master@{#11462}
2016-02-02 16:34:16 +00:00

53 lines
1.4 KiB
C++

/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/rtp_rtcp/source/ssrc_database.h"
#include "webrtc/base/checks.h"
#include "webrtc/system_wrappers/include/tick_util.h"
namespace webrtc {
SSRCDatabase* SSRCDatabase::GetSSRCDatabase() {
return GetStaticInstance<SSRCDatabase>(kAddRef);
}
void SSRCDatabase::ReturnSSRCDatabase() {
GetStaticInstance<SSRCDatabase>(kRelease);
}
uint32_t SSRCDatabase::CreateSSRC() {
rtc::CritScope lock(&crit_);
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;
}
}
}
void SSRCDatabase::RegisterSSRC(uint32_t ssrc) {
rtc::CritScope lock(&crit_);
ssrcs_.insert(ssrc);
}
void SSRCDatabase::ReturnSSRC(uint32_t ssrc) {
rtc::CritScope lock(&crit_);
ssrcs_.erase(ssrc);
}
SSRCDatabase::SSRCDatabase() : random_(TickTime::Now().Ticks()) {}
SSRCDatabase::~SSRCDatabase() {}
} // namespace webrtc