| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 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 | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h" | |
| 12 #include "webrtc/base/timeutils.h" | |
| 13 #include "webrtc/base/checks.h" | |
| 14 | |
| 15 namespace webrtc { | |
| 16 | |
| 17 SSRCDatabase* SSRCDatabase::GetSSRCDatabase() { | |
| 18 return GetStaticInstance<SSRCDatabase>(kAddRef); | |
| 19 } | |
| 20 | |
| 21 void SSRCDatabase::ReturnSSRCDatabase() { | |
| 22 GetStaticInstance<SSRCDatabase>(kRelease); | |
| 23 } | |
| 24 | |
| 25 uint32_t SSRCDatabase::CreateSSRC() { | |
| 26 rtc::CritScope lock(&crit_); | |
| 27 | |
| 28 while (true) { // Try until get a new ssrc. | |
| 29 // 0 and 0xffffffff are invalid values for SSRC. | |
| 30 uint32_t ssrc = random_.Rand(1u, 0xfffffffe); | |
| 31 if (ssrcs_.insert(ssrc).second) { | |
| 32 return ssrc; | |
| 33 } | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 void SSRCDatabase::RegisterSSRC(uint32_t ssrc) { | |
| 38 rtc::CritScope lock(&crit_); | |
| 39 ssrcs_.insert(ssrc); | |
| 40 } | |
| 41 | |
| 42 void SSRCDatabase::ReturnSSRC(uint32_t ssrc) { | |
| 43 rtc::CritScope lock(&crit_); | |
| 44 ssrcs_.erase(ssrc); | |
| 45 } | |
| 46 | |
| 47 SSRCDatabase::SSRCDatabase() : random_(rtc::TimeMicros()) {} | |
| 48 | |
| 49 SSRCDatabase::~SSRCDatabase() {} | |
| 50 | |
| 51 } // namespace webrtc | |
| OLD | NEW |