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_VOICE_ENGINE_CHANNEL_MANAGER_H
|
|
|
|
|
#define WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H
|
|
|
|
|
|
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
|
|
|
|
2014-05-21 21:18:46 +00:00
|
|
|
#include "webrtc/base/constructormagic.h"
|
2016-01-21 10:37:37 -08:00
|
|
|
#include "webrtc/base/criticalsection.h"
|
2016-05-30 08:11:28 -07:00
|
|
|
#include "webrtc/base/scoped_ref_ptr.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/atomic32.h"
|
2013-08-07 17:57:36 +00:00
|
|
|
#include "webrtc/typedefs.h"
|
2016-09-07 07:34:41 -07:00
|
|
|
#include "webrtc/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);
|
|
|
|
|
ChannelOwner(const ChannelOwner& channel_owner);
|
|
|
|
|
|
|
|
|
|
~ChannelOwner();
|
|
|
|
|
|
|
|
|
|
ChannelOwner& operator=(const ChannelOwner& other);
|
|
|
|
|
|
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; }
|
2015-05-13 14:14:42 +02:00
|
|
|
int use_count() const { return channel_ref_->ref_count.Value(); }
|
2013-08-07 17:57:36 +00:00
|
|
|
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.
|
|
|
|
|
struct ChannelRef {
|
|
|
|
|
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
|
|
|
Atomic32 ref_count;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ChannelRef* channel_ref_;
|
|
|
|
|
};
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
#endif // WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H
|