blob: 5e52f07528d085872f6585ca5e5162c7b0b429a8 [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
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000014#include <map>
niklase@google.com470e71d2011-07-07 08:21:25 +000015
Henrik Kjellander98f53512015-10-28 18:17:40 +010016#include "webrtc/system_wrappers/include/static_instance.h"
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000017#include "webrtc/typedefs.h"
henrike@webrtc.org315282c2011-12-09 17:46:20 +000018
niklase@google.com470e71d2011-07-07 08:21:25 +000019namespace webrtc {
20class CriticalSectionWrapper;
21
danilchap162abd32015-12-10 02:39:40 -080022class SSRCDatabase {
23 public:
24 static SSRCDatabase* GetSSRCDatabase();
25 static void ReturnSSRCDatabase();
niklase@google.com470e71d2011-07-07 08:21:25 +000026
danilchap162abd32015-12-10 02:39:40 -080027 uint32_t CreateSSRC();
28 int32_t RegisterSSRC(const uint32_t ssrc);
29 int32_t ReturnSSRC(const uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +000030
danilchap162abd32015-12-10 02:39:40 -080031 protected:
32 SSRCDatabase();
33 virtual ~SSRCDatabase();
niklase@google.com470e71d2011-07-07 08:21:25 +000034
danilchap162abd32015-12-10 02:39:40 -080035 static SSRCDatabase* CreateInstance() { return new SSRCDatabase(); }
henrike@webrtc.org315282c2011-12-09 17:46:20 +000036
danilchap162abd32015-12-10 02:39:40 -080037 private:
38 // Friend function to allow the SSRC destructor to be accessed from the
39 // template class.
40 friend SSRCDatabase* GetStaticInstance<SSRCDatabase>(
41 CountOperation count_operation);
42 static SSRCDatabase* StaticInstance(CountOperation count_operation);
henrike@webrtc.org315282c2011-12-09 17:46:20 +000043
danilchap162abd32015-12-10 02:39:40 -080044 uint32_t GenerateRandom();
niklase@google.com470e71d2011-07-07 08:21:25 +000045
danilchap162abd32015-12-10 02:39:40 -080046 std::map<uint32_t, uint32_t> _ssrcMap;
niklase@google.com470e71d2011-07-07 08:21:25 +000047
danilchap162abd32015-12-10 02:39:40 -080048 CriticalSectionWrapper* _critSect;
niklase@google.com470e71d2011-07-07 08:21:25 +000049};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000050} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000051
danilchap162abd32015-12-10 02:39:40 -080052#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_SSRC_DATABASE_H_