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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef VOICE_ENGINE_CHANNEL_MANAGER_H_
|
|
|
|
|
#define VOICE_ENGINE_CHANNEL_MANAGER_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-02-17 10:04:18 -08:00
|
|
|
#include <memory>
|
2013-08-07 17:57:36 +00:00
|
|
|
#include <vector>
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-10-23 14:26:10 +02:00
|
|
|
#include "api/refcountedbase.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/constructormagic.h"
|
|
|
|
|
#include "rtc_base/criticalsection.h"
|
|
|
|
|
#include "rtc_base/random.h"
|
|
|
|
|
#include "rtc_base/scoped_ref_ptr.h"
|
|
|
|
|
#include "system_wrappers/include/atomic32.h"
|
2017-09-15 13:58:09 +02:00
|
|
|
#include "typedefs.h" // NOLINT(build/include)
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "voice_engine/include/voe_base.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
namespace webrtc {
|
2013-09-12 17:03:00 +00:00
|
|
|
|
2016-05-30 08:11:28 -07:00
|
|
|
class AudioDecoderFactory;
|
2013-09-12 17:03:00 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
namespace voe {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
class Channel;
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
// Shared-pointer implementation for keeping track of Channels. The underlying
|
|
|
|
|
// shared instance will be dropped when no more ChannelOwners point to it.
|
|
|
|
|
//
|
|
|
|
|
// One common source of ChannelOwner instances are
|
|
|
|
|
// ChannelManager::CreateChannel() and ChannelManager::GetChannel(...).
|
|
|
|
|
// It has a similar use case to shared_ptr in C++11. Should this move to C++11
|
|
|
|
|
// in the future, this class should be replaced by exactly that.
|
|
|
|
|
//
|
|
|
|
|
// To access the underlying Channel, use .channel().
|
|
|
|
|
// IsValid() implements a convenience method as an alternative for checking
|
|
|
|
|
// whether the underlying pointer is NULL or not.
|
|
|
|
|
//
|
|
|
|
|
// Channel channel_owner = channel_manager.GetChannel(channel_id);
|
|
|
|
|
// if (channel_owner.IsValid())
|
|
|
|
|
// channel_owner.channel()->...;
|
|
|
|
|
//
|
|
|
|
|
class ChannelOwner {
|
|
|
|
|
public:
|
|
|
|
|
explicit ChannelOwner(Channel* channel);
|
2017-10-23 14:26:10 +02:00
|
|
|
ChannelOwner(const ChannelOwner& channel_owner) = default;
|
2013-08-07 17:57:36 +00:00
|
|
|
|
2017-10-23 14:26:10 +02:00
|
|
|
~ChannelOwner() = default;
|
2013-08-07 17:57:36 +00:00
|
|
|
|
2017-10-23 14:26:10 +02:00
|
|
|
ChannelOwner& operator=(const ChannelOwner& other) = default;
|
2013-08-07 17:57:36 +00:00
|
|
|
|
2015-05-13 14:14:42 +02:00
|
|
|
Channel* channel() const { return channel_ref_->channel.get(); }
|
2013-08-07 17:57:36 +00:00
|
|
|
bool IsValid() { return channel_ref_->channel.get() != NULL; }
|
|
|
|
|
private:
|
|
|
|
|
// Shared instance of a Channel. Copying ChannelOwners increase the reference
|
|
|
|
|
// count and destroying ChannelOwners decrease references. Channels are
|
|
|
|
|
// deleted when no references to them are held.
|
2017-10-23 14:26:10 +02:00
|
|
|
struct ChannelRef : public rtc::RefCountedBase {
|
2013-08-07 17:57:36 +00:00
|
|
|
ChannelRef(Channel* channel);
|
2016-02-17 10:04:18 -08:00
|
|
|
const std::unique_ptr<Channel> channel;
|
2013-08-07 17:57:36 +00:00
|
|
|
};
|
|
|
|
|
|
2017-10-23 14:26:10 +02:00
|
|
|
rtc::scoped_refptr<ChannelRef> channel_ref_;
|
2013-08-07 17:57:36 +00:00
|
|
|
};
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
class ChannelManager {
|
|
|
|
|
public:
|
2016-09-07 07:34:41 -07:00
|
|
|
ChannelManager(uint32_t instance_id);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
// Upon construction of an Iterator it will grab a copy of the channel list of
|
|
|
|
|
// the ChannelManager. The iteration will then occur over this state, not the
|
|
|
|
|
// current one of the ChannelManager. As the Iterator holds its own references
|
|
|
|
|
// to the Channels, they will remain valid even if they are removed from the
|
|
|
|
|
// ChannelManager.
|
|
|
|
|
class Iterator {
|
|
|
|
|
public:
|
|
|
|
|
explicit Iterator(ChannelManager* channel_manager);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
Channel* GetChannel();
|
|
|
|
|
bool IsValid();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
void Increment();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
private:
|
|
|
|
|
size_t iterator_pos_;
|
|
|
|
|
std::vector<ChannelOwner> channels_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-09-16 05:37:44 -07:00
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(Iterator);
|
2013-08-07 17:57:36 +00:00
|
|
|
};
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-07 07:34:41 -07:00
|
|
|
// CreateChannel will always return a valid ChannelOwner instance.
|
|
|
|
|
ChannelOwner CreateChannel(const VoEBase::ChannelConfig& config);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
// ChannelOwner.channel() will be NULL if channel_id is invalid or no longer
|
|
|
|
|
// exists. This should be checked with ChannelOwner::IsValid().
|
|
|
|
|
ChannelOwner GetChannel(int32_t channel_id);
|
|
|
|
|
void GetAllChannels(std::vector<ChannelOwner>* channels);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
void DestroyChannel(int32_t channel_id);
|
|
|
|
|
void DestroyAllChannels();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
size_t NumOfChannels() const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
private:
|
|
|
|
|
uint32_t instance_id_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
Atomic32 last_channel_id_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-02-01 09:00:51 -08:00
|
|
|
rtc::CriticalSection lock_;
|
2013-08-07 17:57:36 +00:00
|
|
|
std::vector<ChannelOwner> channels_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
Reland of Delete class SSRCDatabase, and its global ssrc registry. (patchset #1 id:1 of https://codereview.webrtc.org/2700413002/ )
Reason for revert:
Intend to fix perf problem and reland.
Original issue's description:
> Revert of Delete class SSRCDatabase, and its global ssrc registry. (patchset #20 id:370001 of https://codereview.webrtc.org/2644303002/ )
>
> Reason for revert:
> Breaks webrtc_perf_tests reliably:
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/1780
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus4%29/builds/178
>
> We're actively working on getting a quick version of webrtc_perf_tests up on the trybots again to prevent breakages like this: https://bugs.chromium.org/p/webrtc/issues/detail?id=7101
>
> Original issue's description:
> > Delete class SSRCDatabase, and its global ssrc registry,
> > and the method RTPSender::GenerateNewSSRC.
> >
> > It's now mandatory for higher layers to call SetSSRC, RTPSender
> > no longer allocates any ssrc by default.
> >
> > BUG=webrtc:4306,webrtc:6887
> >
> > Review-Url: https://codereview.webrtc.org/2644303002
> > Cr-Commit-Position: refs/heads/master@{#16670}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/b78d4d13835f628e722a57abae2bf06ba3655921
>
> TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,nisse@webrtc.org
> NOTRY=True
> BUG=webrtc:4306,webrtc:6887
>
> Review-Url: https://codereview.webrtc.org/2700413002
> Cr-Commit-Position: refs/heads/master@{#16693}
> Committed: https://chromium.googlesource.com/external/webrtc/+/b5848ecbf5f7b310108546ec6b858fe93452f58e
TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,kjellander@webrtc.org,kjellander@google.com
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:4306,webrtc:6887
Review-Url: https://codereview.webrtc.org/2702203002
Cr-Commit-Position: refs/heads/master@{#16737}
2017-02-21 03:40:24 -08:00
|
|
|
// For generation of random ssrc:s.
|
|
|
|
|
webrtc::Random random_;
|
|
|
|
|
|
2015-09-16 05:37:44 -07:00
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(ChannelManager);
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace voe
|
|
|
|
|
} // namespace webrtc
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // VOICE_ENGINE_CHANNEL_MANAGER_H_
|