niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_SSRC_DATABASE_H_ |
| 12 | #define WEBRTC_MODULES_RTP_RTCP_SOURCE_SSRC_DATABASE_H_ |
| 13 | |
danilchap | e005cf2 | 2015-12-15 01:59:47 -0800 | [diff] [blame] | 14 | #include <set> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
tommi | ae695e9 | 2016-02-02 08:31:45 -0800 | [diff] [blame] | 16 | #include "webrtc/base/criticalsection.h" |
danilchap | e005cf2 | 2015-12-15 01:59:47 -0800 | [diff] [blame] | 17 | #include "webrtc/base/random.h" |
tommi | ae695e9 | 2016-02-02 08:31:45 -0800 | [diff] [blame] | 18 | #include "webrtc/base/thread_annotations.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 19 | #include "webrtc/system_wrappers/include/static_instance.h" |
pbos@webrtc.org | a048d7c | 2013-05-29 14:27:38 +0000 | [diff] [blame] | 20 | #include "webrtc/typedefs.h" |
henrike@webrtc.org | 315282c | 2011-12-09 17:46:20 +0000 | [diff] [blame] | 21 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
tommi | ae695e9 | 2016-02-02 08:31:45 -0800 | [diff] [blame] | 24 | // 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. |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 31 | class SSRCDatabase { |
| 32 | public: |
| 33 | static SSRCDatabase* GetSSRCDatabase(); |
| 34 | static void ReturnSSRCDatabase(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 36 | uint32_t CreateSSRC(); |
danilchap | e005cf2 | 2015-12-15 01:59:47 -0800 | [diff] [blame] | 37 | void RegisterSSRC(uint32_t ssrc); |
| 38 | void ReturnSSRC(uint32_t ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 40 | protected: |
| 41 | SSRCDatabase(); |
tommi | ae695e9 | 2016-02-02 08:31:45 -0800 | [diff] [blame] | 42 | ~SSRCDatabase(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 44 | static SSRCDatabase* CreateInstance() { return new SSRCDatabase(); } |
henrike@webrtc.org | 315282c | 2011-12-09 17:46:20 +0000 | [diff] [blame] | 45 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 46 | // 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.org | 315282c | 2011-12-09 17:46:20 +0000 | [diff] [blame] | 50 | |
tommi | ae695e9 | 2016-02-02 08:31:45 -0800 | [diff] [blame] | 51 | private: |
| 52 | rtc::CriticalSection crit_; |
danilchap | e005cf2 | 2015-12-15 01:59:47 -0800 | [diff] [blame] | 53 | Random random_ GUARDED_BY(crit_); |
| 54 | std::set<uint32_t> ssrcs_ GUARDED_BY(crit_); |
tommi | ae695e9 | 2016-02-02 08:31:45 -0800 | [diff] [blame] | 55 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | }; |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 60 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
danilchap | 162abd3 | 2015-12-10 02:39:40 -0800 | [diff] [blame] | 62 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_SSRC_DATABASE_H_ |