2011-07-07 08:21:25 +00:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_SSRC_DATABASE_H_
|
|
|
|
|
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_SSRC_DATABASE_H_
|
|
|
|
|
|
2015-12-15 01:59:47 -08:00
|
|
|
#include <set>
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-02-02 08:31:45 -08:00
|
|
|
#include "webrtc/base/criticalsection.h"
|
2015-12-15 01:59:47 -08:00
|
|
|
#include "webrtc/base/random.h"
|
2016-02-02 08:31:45 -08:00
|
|
|
#include "webrtc/base/thread_annotations.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/static_instance.h"
|
2013-05-29 14:27:38 +00:00
|
|
|
#include "webrtc/typedefs.h"
|
2011-12-09 17:46:20 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
|
2016-02-02 08:31:45 -08:00
|
|
|
// TODO(tommi, holmer): Look into whether we can eliminate locking in this
|
|
|
|
|
// class or the class itself completely once voice engine doesn't rely on it.
|
|
|
|
|
// At the moment voe_auto_test requires locking, but it's not clear if that's
|
|
|
|
|
// an issue with the test code or if it reflects real world usage or if that's
|
|
|
|
|
// the best design performance wise.
|
|
|
|
|
// If we do decide to keep the class, we should at least get rid of using
|
|
|
|
|
// StaticInstance.
|
2015-12-10 02:39:40 -08:00
|
|
|
class SSRCDatabase {
|
|
|
|
|
public:
|
|
|
|
|
static SSRCDatabase* GetSSRCDatabase();
|
|
|
|
|
static void ReturnSSRCDatabase();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
uint32_t CreateSSRC();
|
2015-12-15 01:59:47 -08:00
|
|
|
void RegisterSSRC(uint32_t ssrc);
|
|
|
|
|
void ReturnSSRC(uint32_t ssrc);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
protected:
|
|
|
|
|
SSRCDatabase();
|
2016-02-02 08:31:45 -08:00
|
|
|
~SSRCDatabase();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
static SSRCDatabase* CreateInstance() { return new SSRCDatabase(); }
|
2011-12-09 17:46:20 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
// Friend function to allow the SSRC destructor to be accessed from the
|
|
|
|
|
// template class.
|
|
|
|
|
friend SSRCDatabase* GetStaticInstance<SSRCDatabase>(
|
|
|
|
|
CountOperation count_operation);
|
2011-12-09 17:46:20 +00:00
|
|
|
|
2016-02-02 08:31:45 -08:00
|
|
|
private:
|
|
|
|
|
rtc::CriticalSection crit_;
|
2015-12-15 01:59:47 -08:00
|
|
|
Random random_ GUARDED_BY(crit_);
|
|
|
|
|
std::set<uint32_t> ssrcs_ GUARDED_BY(crit_);
|
2016-02-02 08:31:45 -08:00
|
|
|
// TODO(tommi): Use a thread checker to ensure the object is created and
|
|
|
|
|
// deleted on the same thread. At the moment this isn't possible due to
|
|
|
|
|
// voe::ChannelOwner in voice engine. To reproduce, run:
|
|
|
|
|
// voe_auto_test --automated --gtest_filter=*MixManyChannelsForStressOpus
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_SSRC_DATABASE_H_
|