blob: 2f6357aec061022a3b5328a11168b4bac79ee93b [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_SSRC_DATABASE_H_
12#define WEBRTC_MODULES_RTP_RTCP_SOURCE_SSRC_DATABASE_H_
13
danilchape005cf22015-12-15 01:59:47 -080014#include <set>
niklase@google.com470e71d2011-07-07 08:21:25 +000015
tommiae695e92016-02-02 08:31:45 -080016#include "webrtc/base/criticalsection.h"
danilchape005cf22015-12-15 01:59:47 -080017#include "webrtc/base/random.h"
tommiae695e92016-02-02 08:31:45 -080018#include "webrtc/base/thread_annotations.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010019#include "webrtc/system_wrappers/include/static_instance.h"
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000020#include "webrtc/typedefs.h"
henrike@webrtc.org315282c2011-12-09 17:46:20 +000021
niklase@google.com470e71d2011-07-07 08:21:25 +000022namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000023
tommiae695e92016-02-02 08:31:45 -080024// TODO(tommi, holmer): Look into whether we can eliminate locking in this
25// class or the class itself completely once voice engine doesn't rely on it.
26// At the moment voe_auto_test requires locking, but it's not clear if that's
27// an issue with the test code or if it reflects real world usage or if that's
28// the best design performance wise.
29// If we do decide to keep the class, we should at least get rid of using
30// StaticInstance.
danilchap162abd32015-12-10 02:39:40 -080031class SSRCDatabase {
32 public:
33 static SSRCDatabase* GetSSRCDatabase();
34 static void ReturnSSRCDatabase();
niklase@google.com470e71d2011-07-07 08:21:25 +000035
danilchap162abd32015-12-10 02:39:40 -080036 uint32_t CreateSSRC();
danilchape005cf22015-12-15 01:59:47 -080037 void RegisterSSRC(uint32_t ssrc);
38 void ReturnSSRC(uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +000039
danilchap162abd32015-12-10 02:39:40 -080040 protected:
41 SSRCDatabase();
tommiae695e92016-02-02 08:31:45 -080042 ~SSRCDatabase();
niklase@google.com470e71d2011-07-07 08:21:25 +000043
danilchap162abd32015-12-10 02:39:40 -080044 static SSRCDatabase* CreateInstance() { return new SSRCDatabase(); }
henrike@webrtc.org315282c2011-12-09 17:46:20 +000045
danilchap162abd32015-12-10 02:39:40 -080046 // Friend function to allow the SSRC destructor to be accessed from the
47 // template class.
48 friend SSRCDatabase* GetStaticInstance<SSRCDatabase>(
49 CountOperation count_operation);
henrike@webrtc.org315282c2011-12-09 17:46:20 +000050
tommiae695e92016-02-02 08:31:45 -080051 private:
52 rtc::CriticalSection crit_;
danilchape005cf22015-12-15 01:59:47 -080053 Random random_ GUARDED_BY(crit_);
54 std::set<uint32_t> ssrcs_ GUARDED_BY(crit_);
tommiae695e92016-02-02 08:31:45 -080055 // TODO(tommi): Use a thread checker to ensure the object is created and
56 // deleted on the same thread. At the moment this isn't possible due to
57 // voe::ChannelOwner in voice engine. To reproduce, run:
58 // voe_auto_test --automated --gtest_filter=*MixManyChannelsForStressOpus
niklase@google.com470e71d2011-07-07 08:21:25 +000059};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000060} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000061
danilchap162abd32015-12-10 02:39:40 -080062#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_SSRC_DATABASE_H_