Refactored ViEChannelManager ViEInputManager.
Pointers/references and types will come in a future CL. Review URL: http://webrtc-codereview.appspot.com/317012 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1202 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
e0e07bbaa0
commit
e8be22c192
@ -8,603 +8,448 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
#include "video_engine/vie_channel_manager.h"
|
||||||
* vie_channel_manager.cc
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "vie_channel_manager.h"
|
|
||||||
#include "engine_configurations.h"
|
#include "engine_configurations.h"
|
||||||
#include "vie_defines.h"
|
#include "modules/utility/interface/process_thread.h"
|
||||||
|
#include "system_wrappers/interface/critical_section_wrapper.h"
|
||||||
|
#include "system_wrappers/interface/trace.h"
|
||||||
|
#include "video_engine/vie_channel.h"
|
||||||
|
#include "video_engine/vie_defines.h"
|
||||||
|
#include "video_engine/vie_encoder.h"
|
||||||
|
#include "voice_engine/main/interface/voe_video_sync.h"
|
||||||
|
|
||||||
#include "critical_section_wrapper.h"
|
namespace webrtc {
|
||||||
#include "trace.h"
|
|
||||||
#include "vie_channel.h"
|
|
||||||
#include "vie_encoder.h"
|
|
||||||
#include "process_thread.h"
|
|
||||||
|
|
||||||
// VoiceEngine
|
ViEChannelManager::ViEChannelManager(
|
||||||
#include "voe_video_sync.h"
|
int engine_id,
|
||||||
|
int number_of_cores,
|
||||||
namespace webrtc
|
ViEPerformanceMonitor& vie_performance_monitor)
|
||||||
{
|
: channel_id_critsect_(CriticalSectionWrapper::CreateCriticalSection()),
|
||||||
|
engine_id_(engine_id),
|
||||||
ViEChannelManagerScoped::ViEChannelManagerScoped(
|
number_of_cores_(number_of_cores),
|
||||||
const ViEChannelManager& vieChannelManager)
|
vie_performance_monitor_(vie_performance_monitor),
|
||||||
: ViEManagerScopedBase(vieChannelManager)
|
free_channel_ids_(new bool[kViEMaxNumberOfChannels]),
|
||||||
{
|
free_channel_ids_size_(kViEMaxNumberOfChannels),
|
||||||
}
|
voice_sync_interface_(NULL),
|
||||||
|
voice_engine_(NULL),
|
||||||
ViEChannel* ViEChannelManagerScoped::Channel(int vieChannelId) const
|
module_process_thread_(NULL) {
|
||||||
{
|
WEBRTC_TRACE(kTraceMemory, kTraceVideo, ViEId(engine_id),
|
||||||
return static_cast<const ViEChannelManager*>(vie_manager_)->ViEChannelPtr(
|
"ViEChannelManager::ViEChannelManager(engine_id: %d)",
|
||||||
vieChannelId);
|
engine_id);
|
||||||
}
|
for (int idx = 0; idx < free_channel_ids_size_; idx++) {
|
||||||
ViEEncoder* ViEChannelManagerScoped::Encoder(int vieChannelId) const
|
free_channel_ids_[idx] = true;
|
||||||
{
|
|
||||||
return static_cast<const ViEChannelManager*>(vie_manager_)->ViEEncoderPtr(
|
|
||||||
vieChannelId);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ViEChannelManagerScoped::ChannelUsingViEEncoder(int channelId) const
|
|
||||||
{
|
|
||||||
return (static_cast<const ViEChannelManager*>(vie_manager_))->
|
|
||||||
ChannelUsingViEEncoder(channelId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// VieChannelManager
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Constructor
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ViEChannelManager::ViEChannelManager(int engineId,
|
|
||||||
int numberOfCores,
|
|
||||||
ViEPerformanceMonitor& viePerformanceMonitor)
|
|
||||||
: _ptrChannelIdCritsect(CriticalSectionWrapper::CreateCriticalSection()),
|
|
||||||
_engineId(engineId), _numberOfCores(numberOfCores),
|
|
||||||
_viePerformanceMonitor(viePerformanceMonitor), _channelMap(),
|
|
||||||
_freeChannelIds(new bool[kViEMaxNumberOfChannels]),
|
|
||||||
_freeChannelIdsSize(kViEMaxNumberOfChannels), _vieEncoderMap(),
|
|
||||||
_voiceSyncInterface(NULL), _voiceEngine(NULL),
|
|
||||||
_moduleProcessThread(NULL)
|
|
||||||
{
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceVideo, ViEId(engineId),
|
|
||||||
"ViEChannelManager::ViEChannelManager(engineId: %d) - Constructor",
|
|
||||||
engineId);
|
|
||||||
|
|
||||||
for (int idx = 0; idx < _freeChannelIdsSize; idx++)
|
|
||||||
{
|
|
||||||
_freeChannelIds[idx] = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// SetModuleProcessThread
|
|
||||||
// Initialize the thread context used by none time critical tasks in video channels.
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
void ViEChannelManager::SetModuleProcessThread( ProcessThread& moduleProcessThread)
|
|
||||||
{
|
|
||||||
assert(!_moduleProcessThread);
|
|
||||||
_moduleProcessThread = &moduleProcessThread;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
ViEChannelManager::~ViEChannelManager() {
|
||||||
// Destructor
|
WEBRTC_TRACE(kTraceMemory, kTraceVideo, ViEId(engine_id_),
|
||||||
// ----------------------------------------------------------------------------
|
"ViEChannelManager Destructor, engine_id: %d", engine_id_);
|
||||||
|
|
||||||
ViEChannelManager::~ViEChannelManager()
|
while (channel_map_.Size() != 0) {
|
||||||
{
|
MapItem* item = channel_map_.First();
|
||||||
WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceVideo, ViEId(_engineId),
|
const int channel_id = item->GetId();
|
||||||
"ViEChannelManager Destructor, engineId: %d", _engineId);
|
|
||||||
|
|
||||||
while (_channelMap.Size() != 0)
|
|
||||||
{
|
|
||||||
MapItem* item = _channelMap.First();
|
|
||||||
const int channelId = item->GetId();
|
|
||||||
item = NULL;
|
item = NULL;
|
||||||
DeleteChannel(channelId);
|
DeleteChannel(channel_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_voiceSyncInterface)
|
if (voice_sync_interface_) {
|
||||||
_voiceSyncInterface->Release();
|
voice_sync_interface_->Release();
|
||||||
if (_ptrChannelIdCritsect)
|
|
||||||
{
|
|
||||||
delete _ptrChannelIdCritsect;
|
|
||||||
_ptrChannelIdCritsect = NULL;
|
|
||||||
}
|
}
|
||||||
if (_freeChannelIds)
|
if (channel_id_critsect_) {
|
||||||
{
|
delete channel_id_critsect_;
|
||||||
delete[] _freeChannelIds;
|
channel_id_critsect_ = NULL;
|
||||||
_freeChannelIds = NULL;
|
}
|
||||||
_freeChannelIdsSize = 0;
|
if (free_channel_ids_) {
|
||||||
|
delete[] free_channel_ids_;
|
||||||
|
free_channel_ids_ = NULL;
|
||||||
|
free_channel_ids_size_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
void ViEChannelManager::SetModuleProcessThread(
|
||||||
// CreateChannel
|
ProcessThread& module_process_thread) {
|
||||||
//
|
assert(!module_process_thread_);
|
||||||
// Creates a new channel. 'channelId' will be the id of the created channel
|
module_process_thread_ = &module_process_thread;
|
||||||
// ----------------------------------------------------------------------------
|
}
|
||||||
int ViEChannelManager::CreateChannel(int& channelId)
|
|
||||||
{
|
|
||||||
CriticalSectionScoped cs(*_ptrChannelIdCritsect);
|
|
||||||
|
|
||||||
// Get a free id for the new channel
|
int ViEChannelManager::CreateChannel(int& channel_id) {
|
||||||
if (GetFreeChannelId(channelId) == false)
|
CriticalSectionScoped cs(*channel_id_critsect_);
|
||||||
{
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId),
|
// Get a free id for the new channel.
|
||||||
"Max number of channels reached: %d", _channelMap.Size());
|
if (!GetFreeChannelId(channel_id)) {
|
||||||
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_),
|
||||||
|
"Max number of channels reached: %d", channel_map_.Size());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ViEChannel* vieChannel = new ViEChannel(channelId, _engineId,
|
ViEChannel* vie_channel = new ViEChannel(channel_id, engine_id_,
|
||||||
_numberOfCores,
|
number_of_cores_,
|
||||||
*_moduleProcessThread);
|
*module_process_thread_);
|
||||||
if (vieChannel == NULL)
|
if (!vie_channel) {
|
||||||
{
|
ReturnChannelId(channel_id);
|
||||||
ReturnChannelId(channelId);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (vieChannel->Init() != 0)
|
if (vie_channel->Init() != 0) {
|
||||||
{
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_),
|
||||||
// Could not init channel
|
"%s could not init channel", __FUNCTION__, channel_id);
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId),
|
ReturnChannelId(channel_id);
|
||||||
"%s could not init channel", __FUNCTION__, channelId);
|
delete vie_channel;
|
||||||
ReturnChannelId(channelId);
|
vie_channel = NULL;
|
||||||
delete vieChannel;
|
|
||||||
vieChannel = NULL;
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
}
|
|
||||||
// There is no ViEEncoder for this channel, create one with default settings
|
|
||||||
ViEEncoder* vieEncoder = new ViEEncoder(_engineId, channelId,
|
|
||||||
_numberOfCores,
|
|
||||||
*_moduleProcessThread);
|
|
||||||
if (vieEncoder == NULL)
|
|
||||||
{
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId),
|
|
||||||
"%s(videoChannelId: %d) - Could not create a new encoder",
|
|
||||||
__FUNCTION__, channelId);
|
|
||||||
delete vieChannel;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to the map
|
// There is no ViEEncoder for this channel, create one with default settings.
|
||||||
if (_vieEncoderMap.Insert(channelId, vieEncoder) != 0)
|
ViEEncoder* vie_encoder = new ViEEncoder(engine_id_, channel_id,
|
||||||
{
|
number_of_cores_,
|
||||||
// Could not add to the map
|
*module_process_thread_);
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId),
|
if (!vie_encoder) {
|
||||||
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_),
|
||||||
|
"%s(video_channel_id: %d) - Could not create a new encoder",
|
||||||
|
__FUNCTION__, channel_id);
|
||||||
|
delete vie_channel;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vie_encoder_map_.Insert(channel_id, vie_encoder) != 0) {
|
||||||
|
// Could not add to the map.
|
||||||
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_),
|
||||||
"%s: Could not add new encoder for video channel %d",
|
"%s: Could not add new encoder for video channel %d",
|
||||||
__FUNCTION__, channelId);
|
__FUNCTION__, channel_id);
|
||||||
delete vieChannel;
|
delete vie_channel;
|
||||||
delete vieEncoder;
|
delete vie_encoder;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
_channelMap.Insert(channelId, vieChannel);
|
channel_map_.Insert(channel_id, vie_channel);
|
||||||
// Register the channel at the encoder
|
// Register the channel at the encoder.
|
||||||
RtpRtcp* ptrSendRtpRtcpModule = vieEncoder->SendRtpRtcpModule();
|
RtpRtcp* send_rtp_rtcp_module = vie_encoder->SendRtpRtcpModule();
|
||||||
if (vieChannel->RegisterSendRtpRtcpModule(*ptrSendRtpRtcpModule) != 0)
|
if (vie_channel->RegisterSendRtpRtcpModule(*send_rtp_rtcp_module) != 0) {
|
||||||
{
|
|
||||||
assert(false);
|
assert(false);
|
||||||
_vieEncoderMap.Erase(channelId);
|
vie_encoder_map_.Erase(channel_id);
|
||||||
_channelMap.Erase(channelId);
|
channel_map_.Erase(channel_id);
|
||||||
ReturnChannelId(channelId);
|
ReturnChannelId(channel_id);
|
||||||
delete vieChannel;
|
delete vie_channel;
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, channelId),
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id),
|
||||||
"%s: Could not register rtp module %d", __FUNCTION__,
|
"%s: Could not register rtp module %d", __FUNCTION__,
|
||||||
channelId);
|
channel_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
int ViEChannelManager::CreateChannel(int& channel_id, int original_channel) {
|
||||||
// CreateChannel
|
CriticalSectionScoped cs(*channel_id_critsect_);
|
||||||
//
|
|
||||||
// Creates a channel and attaches to an already existing ViEEncoder
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
int ViEChannelManager::CreateChannel(int& channelId, int originalChannel)
|
// Check that original_channel already exists.
|
||||||
{
|
ViEEncoder* vie_encoder = ViEEncoderPtr(original_channel);
|
||||||
CriticalSectionScoped cs(*_ptrChannelIdCritsect);
|
if (!vie_encoder) {
|
||||||
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_),
|
||||||
// Check that originalChannel already exists
|
"%s: Original channel doesn't exist", __FUNCTION__,
|
||||||
ViEEncoder* vieEncoder = ViEEncoderPtr(originalChannel);
|
original_channel);
|
||||||
if (vieEncoder == NULL)
|
|
||||||
{
|
|
||||||
// The original channel doesn't exist
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceError,
|
|
||||||
webrtc::kTraceVideo,
|
|
||||||
ViEId(_engineId),
|
|
||||||
"%s: Original channel doesn't exist",
|
|
||||||
__FUNCTION__,
|
|
||||||
originalChannel);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
VideoCodec videoCodec;
|
VideoCodec video_codec;
|
||||||
if (vieEncoder->GetEncoder(videoCodec) == 0)
|
if (vie_encoder->GetEncoder(video_codec) == 0) {
|
||||||
{
|
if (video_codec.numberOfSimulcastStreams > 0) {
|
||||||
if (videoCodec.numberOfSimulcastStreams > 0)
|
WEBRTC_TRACE(kTraceError, kTraceVideo,
|
||||||
{
|
ViEId(engine_id_, original_channel),
|
||||||
WEBRTC_TRACE(webrtc::kTraceError,
|
|
||||||
webrtc::kTraceVideo,
|
|
||||||
ViEId(_engineId, originalChannel),
|
|
||||||
"%s: Can't share a simulcast encoder",
|
"%s: Can't share a simulcast encoder",
|
||||||
__FUNCTION__);
|
__FUNCTION__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a free id for the new channel
|
// Get a free id for the new channel.
|
||||||
if (GetFreeChannelId(channelId) == false)
|
if (GetFreeChannelId(channel_id) == false) {
|
||||||
{
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_),
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId),
|
"Max number of channels reached: %d", channel_map_.Size());
|
||||||
"Max number of channels reached: %d", _channelMap.Size());
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ViEChannel* vieChannel = new ViEChannel(channelId, _engineId,
|
ViEChannel* vie_channel = new ViEChannel(channel_id, engine_id_,
|
||||||
_numberOfCores,
|
number_of_cores_,
|
||||||
*_moduleProcessThread);
|
*module_process_thread_);
|
||||||
if (vieChannel == NULL)
|
if (!vie_channel) {
|
||||||
{
|
ReturnChannelId(channel_id);
|
||||||
ReturnChannelId(channelId);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (vieChannel->Init() != 0)
|
if (vie_channel->Init() != 0) {
|
||||||
{
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_),
|
||||||
// Could not init channel
|
"%s could not init channel", __FUNCTION__, channel_id);
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId),
|
ReturnChannelId(channel_id);
|
||||||
"%s could not init channel", __FUNCTION__, channelId);
|
delete vie_channel;
|
||||||
ReturnChannelId(channelId);
|
vie_channel = NULL;
|
||||||
delete vieChannel;
|
|
||||||
vieChannel = NULL;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (_vieEncoderMap.Insert(channelId, vieEncoder) != 0)
|
if (vie_encoder_map_.Insert(channel_id, vie_encoder) != 0) {
|
||||||
{
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_),
|
||||||
// Could not add to the map
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId),
|
|
||||||
"%s: Could not add new encoder for video channel %d",
|
"%s: Could not add new encoder for video channel %d",
|
||||||
__FUNCTION__, channelId);
|
__FUNCTION__, channel_id);
|
||||||
ReturnChannelId(channelId);
|
ReturnChannelId(channel_id);
|
||||||
delete vieChannel;
|
delete vie_channel;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the same encoder settings for the channel as used by the master channel.
|
// Set the same encoder settings for the channel as used by the master
|
||||||
// Do this before attaching rtp module to ensure all rtp cihldren has the same codec type
|
// channel. Do this before attaching rtp module to ensure all rtp children has
|
||||||
|
// the same codec type.
|
||||||
VideoCodec encoder;
|
VideoCodec encoder;
|
||||||
if (vieEncoder->GetEncoder(encoder) == 0)
|
if (vie_encoder->GetEncoder(encoder) == 0) {
|
||||||
{
|
vie_channel->SetSendCodec(encoder);
|
||||||
vieChannel->SetSendCodec(encoder);
|
|
||||||
}
|
}
|
||||||
_channelMap.Insert(channelId, vieChannel);
|
channel_map_.Insert(channel_id, vie_channel);
|
||||||
|
|
||||||
// Register the channel at the encoder
|
// Register the channel at the encoder.
|
||||||
RtpRtcp* ptrSendRtpRtcpModule = vieEncoder->SendRtpRtcpModule();
|
RtpRtcp* send_rtp_rtcp_module = vie_encoder->SendRtpRtcpModule();
|
||||||
if (vieChannel->RegisterSendRtpRtcpModule(*ptrSendRtpRtcpModule) != 0)
|
if (vie_channel->RegisterSendRtpRtcpModule(*send_rtp_rtcp_module) != 0) {
|
||||||
{
|
|
||||||
assert(false);
|
assert(false);
|
||||||
_vieEncoderMap.Erase(channelId);
|
vie_encoder_map_.Erase(channel_id);
|
||||||
_channelMap.Erase(channelId);
|
channel_map_.Erase(channel_id);
|
||||||
ReturnChannelId(channelId);
|
ReturnChannelId(channel_id);
|
||||||
delete vieChannel;
|
delete vie_channel;
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, channelId),
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id),
|
||||||
"%s: Could not register rtp module %d", __FUNCTION__,
|
"%s: Could not register rtp module %d", __FUNCTION__,
|
||||||
channelId);
|
channel_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
int ViEChannelManager::DeleteChannel(int channel_id) {
|
||||||
// DeleteChannel
|
ViEChannel* vie_channel = NULL;
|
||||||
// ----------------------------------------------------------------------------
|
ViEEncoder* vie_encoder = NULL;
|
||||||
|
|
||||||
int ViEChannelManager::DeleteChannel(int channelId)
|
|
||||||
{
|
|
||||||
ViEChannel* vieChannel = NULL;
|
|
||||||
ViEEncoder* vieEncoder = NULL;
|
|
||||||
{
|
{
|
||||||
// Write lock to make sure no one is using the channel
|
// Write lock to make sure no one is using the channel.
|
||||||
ViEManagerWriteScoped wl(*this);
|
ViEManagerWriteScoped wl(*this);
|
||||||
|
|
||||||
// Protect the map
|
// Protect the map.
|
||||||
CriticalSectionScoped cs(*_ptrChannelIdCritsect);
|
CriticalSectionScoped cs(*channel_id_critsect_);
|
||||||
|
|
||||||
MapItem* mapItem = _channelMap.Find(channelId);
|
MapItem* map_item = channel_map_.Find(channel_id);
|
||||||
if (mapItem == NULL)
|
if (!map_item) {
|
||||||
{
|
// No such channel.
|
||||||
// No such channel
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_),
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId),
|
"%s Channel doesn't exist: %d", __FUNCTION__, channel_id);
|
||||||
"%s Channel doesn't exist: %d", __FUNCTION__, channelId);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
vieChannel = reinterpret_cast<ViEChannel*> (mapItem->GetItem());
|
vie_channel = reinterpret_cast<ViEChannel*>(map_item->GetItem());
|
||||||
_channelMap.Erase(mapItem);
|
channel_map_.Erase(map_item);
|
||||||
// Deregister the channel from the ViEEncoder to stop the media flow
|
// Deregister the channel from the ViEEncoder to stop the media flow.
|
||||||
vieChannel->DeregisterSendRtpRtcpModule();
|
vie_channel->DeregisterSendRtpRtcpModule();
|
||||||
ReturnChannelId(channelId);
|
ReturnChannelId(channel_id);
|
||||||
|
|
||||||
// Find the encoder object
|
// Find the encoder object.
|
||||||
mapItem = _vieEncoderMap.Find(channelId);
|
map_item = vie_encoder_map_.Find(channel_id);
|
||||||
if (mapItem == NULL)
|
if (!map_item) {
|
||||||
{
|
|
||||||
assert(false);
|
assert(false);
|
||||||
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId),
|
WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_),
|
||||||
"%s ViEEncoder not found for channel %d", __FUNCTION__,
|
"%s ViEEncoder not found for channel %d", __FUNCTION__,
|
||||||
channelId);
|
channel_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// Get the ViEEncoder item
|
|
||||||
vieEncoder = reinterpret_cast<ViEEncoder*> (mapItem->GetItem());
|
|
||||||
|
|
||||||
// Check if other channels are using the same encoder
|
// Get the ViEEncoder item.
|
||||||
if (ChannelUsingViEEncoder(channelId))
|
vie_encoder = reinterpret_cast<ViEEncoder*>(map_item->GetItem());
|
||||||
{
|
|
||||||
// Don't delete the ViEEncoder, at least on other channel is using it.
|
// Check if other channels are using the same encoder.
|
||||||
WEBRTC_TRACE(
|
if (ChannelUsingViEEncoder(channel_id)) {
|
||||||
webrtc::kTraceInfo,
|
// Don't delete the ViEEncoder, at least one other channel is using it.
|
||||||
webrtc::kTraceVideo,
|
WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_),
|
||||||
ViEId(_engineId),
|
|
||||||
"%s ViEEncoder removed from map for channel %d, not deleted",
|
"%s ViEEncoder removed from map for channel %d, not deleted",
|
||||||
__FUNCTION__, channelId);
|
__FUNCTION__, channel_id);
|
||||||
vieEncoder = NULL;
|
vie_encoder = NULL;
|
||||||
} else
|
} else {
|
||||||
{
|
WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_),
|
||||||
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId),
|
|
||||||
"%s ViEEncoder deleted for channel %d", __FUNCTION__,
|
"%s ViEEncoder deleted for channel %d", __FUNCTION__,
|
||||||
channelId);
|
channel_id);
|
||||||
// Delete later when we've released the critsect
|
// Delete later when we've released the critsect.
|
||||||
}
|
}
|
||||||
// We can't erase the item before we've checked for other channels using same ViEEncoder
|
|
||||||
_vieEncoderMap.Erase(mapItem);
|
|
||||||
|
|
||||||
|
// We can't erase the item before we've checked for other channels using
|
||||||
|
// same ViEEncoder.
|
||||||
|
vie_encoder_map_.Erase(map_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leave the write critsect before deleting the objects.
|
// Leave the write critsect before deleting the objects.
|
||||||
// Deleting a channel can cause other objects, such as renderers, to be deleted and might take time
|
// Deleting a channel can cause other objects, such as renderers, to be
|
||||||
if (vieEncoder)
|
// deleted, which might take time.
|
||||||
{
|
if (vie_encoder) {
|
||||||
delete vieEncoder;
|
delete vie_encoder;
|
||||||
}
|
}
|
||||||
delete vieChannel;
|
delete vie_channel;
|
||||||
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(_engineId),
|
WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_),
|
||||||
"%s Channel %d deleted", __FUNCTION__, channelId);
|
"%s Channel %d deleted", __FUNCTION__, channel_id);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
int ViEChannelManager::SetVoiceEngine(VoiceEngine* voice_engine) {
|
||||||
// Channel
|
// Write lock to make sure no one is using the channel.
|
||||||
//
|
ViEManagerWriteScoped wl(*this);
|
||||||
// Returns a pointer to the channel with id 'channelId'
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ViEChannel* ViEChannelManager::ViEChannelPtr(int channelId) const
|
CriticalSectionScoped cs(*channel_id_critsect_);
|
||||||
{
|
|
||||||
CriticalSectionScoped cs(*_ptrChannelIdCritsect);
|
VoEVideoSync* sync_interface = NULL;
|
||||||
MapItem* mapItem = _channelMap.Find(channelId);
|
if (voice_engine) {
|
||||||
if (mapItem == NULL)
|
// Get new sync interface.
|
||||||
{
|
sync_interface = VoEVideoSync::GetInterface(voice_engine);
|
||||||
// No such channel
|
if (!sync_interface) {
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId),
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_),
|
||||||
"%s Channel doesn't exist: %d", __FUNCTION__, channelId);
|
"%s Can't get audio sync interface from VoiceEngine.",
|
||||||
return NULL;
|
__FUNCTION__);
|
||||||
|
|
||||||
|
if (sync_interface) {
|
||||||
|
sync_interface->Release();
|
||||||
}
|
}
|
||||||
ViEChannel* vieChannel = reinterpret_cast<ViEChannel*> (mapItem->GetItem());
|
return -1;
|
||||||
return vieChannel;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (MapItem* item = channel_map_.First(); item != NULL;
|
||||||
|
item = channel_map_.Next(item)) {
|
||||||
|
ViEChannel* channel = static_cast<ViEChannel*>(item->GetItem());
|
||||||
|
assert(channel);
|
||||||
|
channel->SetVoiceChannel(-1, sync_interface);
|
||||||
|
}
|
||||||
|
if (voice_sync_interface_) {
|
||||||
|
voice_sync_interface_->Release();
|
||||||
|
}
|
||||||
|
voice_engine_ = voice_engine;
|
||||||
|
voice_sync_interface_ = sync_interface;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
int ViEChannelManager::ConnectVoiceChannel(int channel_id,
|
||||||
// GetChannels
|
int audio_channel_id) {
|
||||||
//
|
CriticalSectionScoped cs(*channel_id_critsect_);
|
||||||
// Adds all channels to channelMap
|
if (!voice_sync_interface_) {
|
||||||
// ----------------------------------------------------------------------------
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, channel_id),
|
||||||
|
"No VoE set");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ViEChannel* channel = ViEChannelPtr(channel_id);
|
||||||
|
if (!channel) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return channel->SetVoiceChannel(audio_channel_id, voice_sync_interface_);
|
||||||
|
}
|
||||||
|
|
||||||
void ViEChannelManager::GetViEChannels(MapWrapper& channelMap)
|
int ViEChannelManager::DisconnectVoiceChannel(int channel_id) {
|
||||||
{
|
CriticalSectionScoped cs(*channel_id_critsect_);
|
||||||
CriticalSectionScoped cs(*_ptrChannelIdCritsect);
|
ViEChannel* channel = ViEChannelPtr(channel_id);
|
||||||
if (channelMap.Size() == 0)
|
if (channel) {
|
||||||
{
|
channel->SetVoiceChannel(-1, NULL);
|
||||||
// No channels
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
VoiceEngine* ViEChannelManager::GetVoiceEngine() {
|
||||||
|
CriticalSectionScoped cs(*channel_id_critsect_);
|
||||||
|
return voice_engine_;
|
||||||
|
}
|
||||||
|
|
||||||
|
ViEChannel* ViEChannelManager::ViEChannelPtr(int channel_id) const {
|
||||||
|
CriticalSectionScoped cs(*channel_id_critsect_);
|
||||||
|
MapItem* map_item = channel_map_.Find(channel_id);
|
||||||
|
if (!map_item) {
|
||||||
|
// No such channel.
|
||||||
|
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_),
|
||||||
|
"%s Channel doesn't exist: %d", __FUNCTION__, channel_id);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ViEChannel* vie_channel = reinterpret_cast<ViEChannel*>(map_item->GetItem());
|
||||||
|
return vie_channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViEChannelManager::GetViEChannels(MapWrapper& channel_map) {
|
||||||
|
CriticalSectionScoped cs(*channel_id_critsect_);
|
||||||
|
if (channel_map.Size() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Add all items to 'channelMap'
|
|
||||||
for (MapItem* item = _channelMap.First(); item != NULL; item
|
// Add all items to 'channelMap'.
|
||||||
= _channelMap.Next(item))
|
for (MapItem* item = channel_map_.First(); item != NULL;
|
||||||
{
|
item = channel_map_.Next(item)) {
|
||||||
channelMap.Insert(item->GetId(), item->GetItem());
|
channel_map.Insert(item->GetId(), item->GetItem());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
ViEEncoder* ViEChannelManager::ViEEncoderPtr(int video_channel_id) const {
|
||||||
// ViEEncoderPtr
|
CriticalSectionScoped cs(*channel_id_critsect_);
|
||||||
//
|
MapItem* map_item = vie_encoder_map_.Find(video_channel_id);
|
||||||
// Gets the ViEEncoder used as input for videoChannelId
|
if (!map_item) {
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ViEEncoder* ViEChannelManager::ViEEncoderPtr(int videoChannelId) const
|
|
||||||
{
|
|
||||||
CriticalSectionScoped cs(*_ptrChannelIdCritsect);
|
|
||||||
MapItem* mapItem = _vieEncoderMap.Find(videoChannelId);
|
|
||||||
if (mapItem == NULL)
|
|
||||||
{
|
|
||||||
// No ViEEncoder for this channel...
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ViEEncoder* vieEncoder = static_cast<ViEEncoder*> (mapItem->GetItem());
|
ViEEncoder* vie_encoder = static_cast<ViEEncoder*>(map_item->GetItem());
|
||||||
return vieEncoder;
|
return vie_encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
bool ViEChannelManager::GetFreeChannelId(int& free_channel_id) {
|
||||||
// GetFreeChannelId
|
CriticalSectionScoped cs(*channel_id_critsect_);
|
||||||
//
|
|
||||||
// Returns true if we found a new channel id, freeChannelId, false otherwise
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
bool ViEChannelManager::GetFreeChannelId(int& freeChannelId)
|
|
||||||
{
|
|
||||||
CriticalSectionScoped cs(*_ptrChannelIdCritsect);
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
while (idx < _freeChannelIdsSize)
|
while (idx < free_channel_ids_size_) {
|
||||||
{
|
if (free_channel_ids_[idx] == true) {
|
||||||
if (_freeChannelIds[idx] == true)
|
// We've found a free id, allocate it and return.
|
||||||
{
|
free_channel_ids_[idx] = false;
|
||||||
// We've found a free id, allocate it and return
|
free_channel_id = idx + kViEChannelIdBase;
|
||||||
_freeChannelIds[idx] = false;
|
|
||||||
freeChannelId = idx + kViEChannelIdBase;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
// No free channel id
|
// No free channel id.
|
||||||
freeChannelId = -1;
|
free_channel_id = -1;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
void ViEChannelManager::ReturnChannelId(int channel_id) {
|
||||||
// ReturnChannelID
|
CriticalSectionScoped cs(*channel_id_critsect_);
|
||||||
//
|
assert(channel_id < kViEMaxNumberOfChannels + kViEChannelIdBase &&
|
||||||
// Returns a previously allocated channel id
|
channel_id >= kViEChannelIdBase);
|
||||||
// ----------------------------------------------------------------------------
|
free_channel_ids_[channel_id - kViEChannelIdBase] = true;
|
||||||
void ViEChannelManager::ReturnChannelId(int channelId)
|
|
||||||
{
|
|
||||||
CriticalSectionScoped cs(*_ptrChannelIdCritsect);
|
|
||||||
assert(channelId < kViEMaxNumberOfChannels+kViEChannelIdBase && channelId>=kViEChannelIdBase);
|
|
||||||
_freeChannelIds[channelId - kViEChannelIdBase] = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
bool ViEChannelManager::ChannelUsingViEEncoder(int channel_id) const {
|
||||||
// ChannelUsingViEEncoder
|
CriticalSectionScoped cs(*channel_id_critsect_);
|
||||||
//
|
MapItem* channel_item = vie_encoder_map_.Find(channel_id);
|
||||||
// Returns true if at least one nother channel is using the same encoder
|
if (!channel_item) {
|
||||||
// ----------------------------------------------------------------------------
|
// No ViEEncoder for this channel.
|
||||||
|
|
||||||
bool ViEChannelManager::ChannelUsingViEEncoder(int channelId) const
|
|
||||||
{
|
|
||||||
CriticalSectionScoped cs(*_ptrChannelIdCritsect);
|
|
||||||
MapItem* channelItem = _vieEncoderMap.Find(channelId);
|
|
||||||
if (channelItem == NULL)
|
|
||||||
{
|
|
||||||
// No ViEEncoder for this channel...
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ViEEncoder* channelEncoder =
|
ViEEncoder* channel_encoder =
|
||||||
static_cast<ViEEncoder*> (channelItem->GetItem());
|
static_cast<ViEEncoder*>(channel_item->GetItem());
|
||||||
|
|
||||||
// Loop through all other channels to see if anyone points at the same ViEEncoder
|
// Loop through all other channels to see if anyone points at the same
|
||||||
MapItem* mapItem = _vieEncoderMap.First();
|
// ViEEncoder.
|
||||||
while (mapItem)
|
MapItem* map_item = vie_encoder_map_.First();
|
||||||
{
|
while (map_item) {
|
||||||
if (mapItem->GetId() != channelId)
|
if (map_item->GetId() != channel_id) {
|
||||||
{
|
if (channel_encoder == static_cast<ViEEncoder*>(map_item->GetItem())) {
|
||||||
if (channelEncoder == static_cast<ViEEncoder*> (mapItem->GetItem()))
|
|
||||||
{
|
|
||||||
// We've found another channel using the same ViEEncoder
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mapItem = _vieEncoderMap.Next(mapItem);
|
map_item = vie_encoder_map_.Next(map_item);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
ViEChannelManagerScoped::ViEChannelManagerScoped(
|
||||||
// SetVoiceEngine
|
const ViEChannelManager& vie_channel_manager)
|
||||||
//
|
: ViEManagerScopedBase(vie_channel_manager) {
|
||||||
// Set the voice engine instance to be used by all video channels. We are interested in the voice engine sync interfaces
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
int ViEChannelManager::SetVoiceEngine(VoiceEngine* voiceEngine)
|
|
||||||
{
|
|
||||||
|
|
||||||
// Write lock to make sure no one is using the channel
|
|
||||||
ViEManagerWriteScoped wl(*this);
|
|
||||||
|
|
||||||
CriticalSectionScoped cs(*_ptrChannelIdCritsect);
|
|
||||||
|
|
||||||
VoEVideoSync* syncInterface = NULL;
|
|
||||||
if (voiceEngine)
|
|
||||||
{
|
|
||||||
// Get new sync interface;
|
|
||||||
syncInterface = VoEVideoSync::GetInterface(voiceEngine);
|
|
||||||
if (!syncInterface)
|
|
||||||
{
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId),
|
|
||||||
"%s Can't get audio sync interface from VoiceEngine.",
|
|
||||||
__FUNCTION__);
|
|
||||||
|
|
||||||
if (syncInterface)
|
|
||||||
{
|
|
||||||
syncInterface->Release();
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (MapItem* item = _channelMap.First(); item != NULL; item
|
|
||||||
= _channelMap.Next(item))
|
|
||||||
{
|
|
||||||
ViEChannel* channel = static_cast<ViEChannel*> (item->GetItem());
|
|
||||||
assert(channel);
|
|
||||||
channel->SetVoiceChannel(-1, syncInterface);
|
|
||||||
}
|
|
||||||
if (_voiceSyncInterface)
|
|
||||||
{
|
|
||||||
_voiceSyncInterface->Release();
|
|
||||||
}
|
|
||||||
_voiceEngine = voiceEngine;
|
|
||||||
_voiceSyncInterface = syncInterface;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
VoiceEngine* ViEChannelManager::GetVoiceEngine()
|
|
||||||
{
|
|
||||||
CriticalSectionScoped cs(*_ptrChannelIdCritsect);
|
|
||||||
return _voiceEngine;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
ViEChannel* ViEChannelManagerScoped::Channel(int vie_channel_id) const {
|
||||||
// ConnectVoiceChannel
|
return static_cast<const ViEChannelManager*>(vie_manager_)->ViEChannelPtr(
|
||||||
//
|
vie_channel_id);
|
||||||
// Enables lip sync of the channel.
|
}
|
||||||
// ----------------------------------------------------------------------------
|
ViEEncoder* ViEChannelManagerScoped::Encoder(int vie_channel_id) const {
|
||||||
int ViEChannelManager::ConnectVoiceChannel(int channelId, int audioChannelId)
|
return static_cast<const ViEChannelManager*>(vie_manager_)->ViEEncoderPtr(
|
||||||
{
|
vie_channel_id);
|
||||||
CriticalSectionScoped cs(*_ptrChannelIdCritsect);
|
|
||||||
|
|
||||||
if (_voiceSyncInterface == NULL)
|
|
||||||
{
|
|
||||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(_engineId, channelId),
|
|
||||||
"No VoE set");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ViEChannel* channel = ViEChannelPtr(channelId);
|
|
||||||
if (!channel)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return channel->SetVoiceChannel(audioChannelId, _voiceSyncInterface);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
bool ViEChannelManagerScoped::ChannelUsingViEEncoder(int channel_id) const {
|
||||||
// DisconnectVoiceChannel
|
return (static_cast<const ViEChannelManager*>(vie_manager_))->
|
||||||
//
|
ChannelUsingViEEncoder(channel_id);
|
||||||
// Disables lip sync of the channel.
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
int ViEChannelManager::DisconnectVoiceChannel(int channelId)
|
|
||||||
{
|
|
||||||
CriticalSectionScoped cs(*_ptrChannelIdCritsect);
|
|
||||||
ViEChannel* channel = ViEChannelPtr(channelId);
|
|
||||||
if (channel)
|
|
||||||
{
|
|
||||||
channel->SetVoiceChannel(-1, NULL);
|
|
||||||
return 0;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
@ -8,95 +8,106 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
#ifndef WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_MANAGER_H_
|
||||||
* vie_channel_manager.h
|
#define WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_MANAGER_H_
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_CHANNEL_MANAGER_H_
|
|
||||||
#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_CHANNEL_MANAGER_H_
|
|
||||||
|
|
||||||
// Defines
|
|
||||||
#include "engine_configurations.h"
|
#include "engine_configurations.h"
|
||||||
#include "vie_defines.h"
|
#include "system_wrappers/interface/map_wrapper.h"
|
||||||
#include "typedefs.h"
|
#include "typedefs.h"
|
||||||
#include "map_wrapper.h"
|
#include "video_engine/vie_defines.h"
|
||||||
#include "vie_manager_base.h"
|
#include "video_engine/vie_manager_base.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
namespace webrtc
|
|
||||||
{
|
|
||||||
class CriticalSectionWrapper;
|
class CriticalSectionWrapper;
|
||||||
//class VoiceEngine;
|
|
||||||
class ProcessThread;
|
class ProcessThread;
|
||||||
class ViEChannel;
|
class ViEChannel;
|
||||||
class VoEVideoSync;
|
|
||||||
class ViEPerformanceMonitor;
|
|
||||||
class ViEEncoder;
|
class ViEEncoder;
|
||||||
|
class ViEPerformanceMonitor;
|
||||||
|
class VoEVideoSync;
|
||||||
class VoiceEngine;
|
class VoiceEngine;
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
class ViEChannelManager: private ViEManagerBase {
|
||||||
// ViEChannelManager
|
|
||||||
// ------------------------------------------------------------------
|
|
||||||
|
|
||||||
class ViEChannelManager: private ViEManagerBase
|
|
||||||
{
|
|
||||||
friend class ViEChannelManagerScoped;
|
friend class ViEChannelManagerScoped;
|
||||||
|
public:
|
||||||
public:
|
ViEChannelManager(int engine_id,
|
||||||
ViEChannelManager(int engineId, int numberOfCores,
|
int number_of_cores,
|
||||||
ViEPerformanceMonitor& viePerformanceMonitor);
|
ViEPerformanceMonitor& vie_performance_monitor);
|
||||||
~ViEChannelManager();
|
~ViEChannelManager();
|
||||||
|
|
||||||
void SetModuleProcessThread(ProcessThread& moduleProcessThread);
|
void SetModuleProcessThread(ProcessThread& module_process_thread);
|
||||||
int CreateChannel(int& channelId);
|
|
||||||
int CreateChannel(int& channelId, int originalChannel);
|
// Creates a new channel. 'channelId' will be the id of the created channel.
|
||||||
int DeleteChannel(int channelId);
|
int CreateChannel(int& channel_id);
|
||||||
int SetVoiceEngine(VoiceEngine* voiceEngine);
|
|
||||||
int ConnectVoiceChannel(int channelId, int audioChannelId);
|
// Creates a channel and attaches to an already existing ViEEncoder.
|
||||||
int DisconnectVoiceChannel(int channelId);
|
int CreateChannel(int& channel_id, int original_channel);
|
||||||
|
|
||||||
|
// Deletes a channel.
|
||||||
|
int DeleteChannel(int channel_id);
|
||||||
|
|
||||||
|
// Set the voice engine instance to be used by all video channels.
|
||||||
|
int SetVoiceEngine(VoiceEngine* voice_engine);
|
||||||
|
|
||||||
|
// Enables lip sync of the channel.
|
||||||
|
int ConnectVoiceChannel(int channel_id, int audio_channel_id);
|
||||||
|
|
||||||
|
// Disables lip sync of the channel.
|
||||||
|
int DisconnectVoiceChannel(int channel_id);
|
||||||
|
|
||||||
VoiceEngine* GetVoiceEngine();
|
VoiceEngine* GetVoiceEngine();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Used by ViEChannelScoped, forcing a manager user to use scoped
|
// Used by ViEChannelScoped, forcing a manager user to use scoped.
|
||||||
ViEChannel* ViEChannelPtr(int channelId) const;
|
// Returns a pointer to the channel with id 'channelId'.
|
||||||
void GetViEChannels(MapWrapper& channelMap);
|
ViEChannel* ViEChannelPtr(int channel_id) const;
|
||||||
|
|
||||||
// Methods used by ViECaptureScoped and ViEEncoderScoped
|
// Adds all channels to channel_map.
|
||||||
ViEEncoder* ViEEncoderPtr(int videoChannelId) const;
|
void GetViEChannels(MapWrapper& channel_map);
|
||||||
|
|
||||||
bool GetFreeChannelId(int& freeChannelId);
|
// Methods used by ViECaptureScoped and ViEEncoderScoped.
|
||||||
void ReturnChannelId(int channelId);
|
// Gets the ViEEncoder used as input for video_channel_id
|
||||||
|
ViEEncoder* ViEEncoderPtr(int video_channel_id) const;
|
||||||
|
|
||||||
// Returns true if at least one other channels uses the same ViEEncoder as channelId
|
// Returns true if we found a new channel id, free_channel_id, false
|
||||||
bool ChannelUsingViEEncoder(int channelId) const;
|
// otherwise.
|
||||||
|
bool GetFreeChannelId(int& free_channel_id);
|
||||||
|
|
||||||
// Members
|
// Returns a previously allocated channel id.
|
||||||
CriticalSectionWrapper* _ptrChannelIdCritsect; // protecting _channelMap and _freeChannelIds
|
void ReturnChannelId(int channel_id);
|
||||||
int _engineId;
|
|
||||||
int _numberOfCores;
|
// Returns true if at least one other channels uses the same ViEEncoder as
|
||||||
ViEPerformanceMonitor& _viePerformanceMonitor;
|
// channel_id.
|
||||||
MapWrapper _channelMap;
|
bool ChannelUsingViEEncoder(int channel_id) const;
|
||||||
bool* _freeChannelIds;
|
|
||||||
int _freeChannelIdsSize;
|
// Protects channel_map_ and free_channel_ids_.
|
||||||
// Encoder
|
CriticalSectionWrapper* channel_id_critsect_;
|
||||||
MapWrapper _vieEncoderMap; // Channel id -> ViEEncoder
|
int engine_id_;
|
||||||
VoEVideoSync* _voiceSyncInterface;
|
int number_of_cores_;
|
||||||
VoiceEngine* _voiceEngine;
|
ViEPerformanceMonitor& vie_performance_monitor_;
|
||||||
ProcessThread* _moduleProcessThread;
|
MapWrapper channel_map_;
|
||||||
|
bool* free_channel_ids_;
|
||||||
|
int free_channel_ids_size_;
|
||||||
|
|
||||||
|
// Maps Channel id -> ViEEncoder.
|
||||||
|
MapWrapper vie_encoder_map_;
|
||||||
|
VoEVideoSync* voice_sync_interface_;
|
||||||
|
VoiceEngine* voice_engine_;
|
||||||
|
ProcessThread* module_process_thread_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
class ViEChannelManagerScoped: private ViEManagerScopedBase {
|
||||||
// ViEChannelManagerScoped
|
public:
|
||||||
// ------------------------------------------------------------------
|
explicit ViEChannelManagerScoped(
|
||||||
class ViEChannelManagerScoped: private ViEManagerScopedBase
|
const ViEChannelManager& vie_channel_manager);
|
||||||
{
|
ViEChannel* Channel(int vie_channel_id) const;
|
||||||
public:
|
ViEEncoder* Encoder(int vie_channel_id) const;
|
||||||
ViEChannelManagerScoped(const ViEChannelManager& vieChannelManager);
|
|
||||||
ViEChannel* Channel(int vieChannelId) const;
|
|
||||||
ViEEncoder* Encoder(int vieChannelId) const;
|
|
||||||
|
|
||||||
// Returns true if at lease one other channels uses the same ViEEncoder as channelId
|
// Returns true if at lease one other channels uses the same ViEEncoder as
|
||||||
bool ChannelUsingViEEncoder(int channelId) const;
|
// channel_id.
|
||||||
|
bool ChannelUsingViEEncoder(int channel_id) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace webrtc
|
} // namespace webrtc
|
||||||
#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_CHANNEL_MANAGER_H_
|
|
||||||
|
#endif // WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_MANAGER_H_
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -8,114 +8,135 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
#ifndef WEBRTC_VIDEO_ENGINE_VIE_INPUT_MANAGER_H_
|
||||||
* vie_input_manager.h
|
#define WEBRTC_VIDEO_ENGINE_VIE_INPUT_MANAGER_H_
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_INPUT_MANAGER_H_
|
#include "modules/video_capture/main/interface/video_capture.h"
|
||||||
#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_INPUT_MANAGER_H_
|
#include "system_wrappers/interface/map_wrapper.h"
|
||||||
|
|
||||||
#include "vie_defines.h"
|
|
||||||
#include "typedefs.h"
|
#include "typedefs.h"
|
||||||
#include "map_wrapper.h"
|
#include "video_engine/main/interface/vie_capture.h"
|
||||||
#include "video_capture.h"
|
#include "video_engine/vie_defines.h"
|
||||||
#include "vie_manager_base.h"
|
#include "video_engine/vie_frame_provider_base.h"
|
||||||
#include "vie_frame_provider_base.h"
|
#include "video_engine/vie_manager_base.h"
|
||||||
#include "vie_capture.h"
|
|
||||||
|
|
||||||
class ViEExternalCapture;
|
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class CriticalSectionWrapper;
|
class CriticalSectionWrapper;
|
||||||
class ProcessThread;
|
class ProcessThread;
|
||||||
class RWLockWrapper;
|
class RWLockWrapper;
|
||||||
class ViECapturer;
|
class ViECapturer;
|
||||||
|
class ViEExternalCapture;
|
||||||
class ViEFilePlayer;
|
class ViEFilePlayer;
|
||||||
class VoiceEngine;
|
class VoiceEngine;
|
||||||
|
|
||||||
class ViEInputManager: private ViEManagerBase
|
class ViEInputManager : private ViEManagerBase {
|
||||||
{
|
|
||||||
friend class ViEInputManagerScoped;
|
friend class ViEInputManagerScoped;
|
||||||
public:
|
public:
|
||||||
ViEInputManager(int engineId);
|
explicit ViEInputManager(int engine_id);
|
||||||
~ViEInputManager();
|
~ViEInputManager();
|
||||||
|
|
||||||
void SetModuleProcessThread(ProcessThread& moduleProcessThread);
|
void SetModuleProcessThread(ProcessThread& module_process_thread);
|
||||||
|
|
||||||
// Capture device information
|
// Returns number of capture devices.
|
||||||
int NumberOfCaptureDevices();
|
int NumberOfCaptureDevices();
|
||||||
int GetDeviceName(WebRtc_UWord32 deviceNumber,
|
|
||||||
WebRtc_UWord8* deviceNameUTF8,
|
// Gets name and id for a capture device.
|
||||||
WebRtc_UWord32 deviceNameLength,
|
int GetDeviceName(WebRtc_UWord32 device_number,
|
||||||
WebRtc_UWord8* deviceUniqueIdUTF8,
|
WebRtc_UWord8* device_nameUTF8,
|
||||||
WebRtc_UWord32 deviceUniqueIdUTF8Length);
|
WebRtc_UWord32 device_name_length,
|
||||||
int NumberOfCaptureCapabilities(const WebRtc_UWord8* deviceUniqueIdUTF8);
|
WebRtc_UWord8* device_unique_idUTF8,
|
||||||
int GetCaptureCapability(const WebRtc_UWord8* deviceUniqueIdUTF8,
|
WebRtc_UWord32 device_unique_idUTF8Length);
|
||||||
const WebRtc_UWord32 deviceCapabilityNumber,
|
|
||||||
|
// Returns the number of capture capabilities for a specified device.
|
||||||
|
int NumberOfCaptureCapabilities(const WebRtc_UWord8* device_unique_idUTF8);
|
||||||
|
|
||||||
|
// Gets a specific capability for a capture device.
|
||||||
|
int GetCaptureCapability(const WebRtc_UWord8* device_unique_idUTF8,
|
||||||
|
const WebRtc_UWord32 device_capability_number,
|
||||||
CaptureCapability& capability);
|
CaptureCapability& capability);
|
||||||
int DisplayCaptureSettingsDialogBox(const WebRtc_UWord8* deviceUniqueIdUTF8,
|
|
||||||
const WebRtc_UWord8* dialogTitleUTF8,
|
// Show OS specific Capture settings.
|
||||||
void* parentWindow,
|
int DisplayCaptureSettingsDialogBox(const WebRtc_UWord8* device_unique_idUTF8,
|
||||||
|
const WebRtc_UWord8* dialog_titleUTF8,
|
||||||
|
void* parent_window,
|
||||||
WebRtc_UWord32 positionX,
|
WebRtc_UWord32 positionX,
|
||||||
WebRtc_UWord32 positionY);
|
WebRtc_UWord32 positionY);
|
||||||
int GetOrientation(const WebRtc_UWord8* deviceUniqueIdUTF8,
|
int GetOrientation(const WebRtc_UWord8* device_unique_idUTF8,
|
||||||
RotateCapturedFrame &orientation);
|
RotateCapturedFrame& orientation);
|
||||||
|
|
||||||
// Create/delete Capture device settings
|
// Creates a capture module for the specified capture device and assigns
|
||||||
// Return zero on success. A ViEError on failure.
|
// a capture device id for the device.
|
||||||
int CreateCaptureDevice(const WebRtc_UWord8* deviceUniqueIdUTF8,
|
// Return zero on success, ViEError on failure.
|
||||||
const WebRtc_UWord32 deviceUniqueIdUTF8Length,
|
int CreateCaptureDevice(const WebRtc_UWord8* device_unique_idUTF8,
|
||||||
int& captureId);
|
const WebRtc_UWord32 device_unique_idUTF8Length,
|
||||||
int CreateCaptureDevice(VideoCaptureModule& captureModule,
|
int& capture_id);
|
||||||
int& captureId);
|
int CreateCaptureDevice(VideoCaptureModule& capture_module,
|
||||||
int CreateExternalCaptureDevice(ViEExternalCapture*& externalCapture,
|
int& capture_id);
|
||||||
int& captureId);
|
int CreateExternalCaptureDevice(ViEExternalCapture*& external_capture,
|
||||||
int DestroyCaptureDevice(int captureId);
|
int& capture_id);
|
||||||
|
int DestroyCaptureDevice(int capture_id);
|
||||||
|
|
||||||
int CreateFilePlayer(const WebRtc_Word8* fileNameUTF8, const bool loop,
|
int CreateFilePlayer(const WebRtc_Word8* file_nameUTF8, const bool loop,
|
||||||
const webrtc::FileFormats fileFormat, VoiceEngine* vePtr,
|
const FileFormats file_format,
|
||||||
int& fileId);
|
VoiceEngine* voe_ptr,
|
||||||
int DestroyFilePlayer(int fileId);
|
int& file_id);
|
||||||
|
int DestroyFilePlayer(int file_id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool GetFreeCaptureId(int& freecaptureId);
|
// Gets and allocates a free capture device id. Assumed protected by caller.
|
||||||
void ReturnCaptureId(int captureId);
|
bool GetFreeCaptureId(int& freecapture_id);
|
||||||
bool GetFreeFileId(int& freeFileId);
|
|
||||||
void ReturnFileId(int fileId);
|
|
||||||
|
|
||||||
ViEFrameProviderBase* ViEFrameProvider(const ViEFrameCallback*
|
// Frees a capture id assigned in GetFreeCaptureId.
|
||||||
captureObserver) const;
|
void ReturnCaptureId(int capture_id);
|
||||||
ViEFrameProviderBase* ViEFrameProvider(int providerId) const;
|
|
||||||
|
|
||||||
ViECapturer* ViECapturePtr(int captureId) const;
|
// Gets and allocates a free file id. Assumed protected by caller.
|
||||||
void GetViECaptures(MapWrapper& vieCaptureMap);
|
bool GetFreeFileId(int& free_file_id);
|
||||||
|
|
||||||
ViEFilePlayer* ViEFilePlayerPtr(int fileId) const;
|
// Frees a file id assigned in GetFreeFileId.
|
||||||
|
void ReturnFileId(int file_id);
|
||||||
|
|
||||||
// Members
|
// Gets the ViEFrameProvider for this capture observer.
|
||||||
int _engineId;
|
ViEFrameProviderBase* ViEFrameProvider(
|
||||||
CriticalSectionWrapper& _mapCritsect;
|
const ViEFrameCallback* capture_observer) const;
|
||||||
MapWrapper _vieFrameProviderMap;
|
|
||||||
|
|
||||||
// Capture devices
|
// Gets the ViEFrameProvider for this capture observer.
|
||||||
VideoCaptureModule::DeviceInfo* _ptrCaptureDeviceInfo;
|
ViEFrameProviderBase* ViEFrameProvider(int provider_id) const;
|
||||||
int _freeCaptureDeviceId[kViEMaxCaptureDevices];
|
|
||||||
//File Players
|
// Gets the ViECapturer for the capture device id.
|
||||||
int _freeFileId[kViEMaxFilePlayers];
|
ViECapturer* ViECapturePtr(int capture_id) const;
|
||||||
//uses
|
|
||||||
ProcessThread* _moduleProcessThread;
|
// Gets the the entire map with GetViECaptures.
|
||||||
|
void GetViECaptures(MapWrapper& vie_capture_map);
|
||||||
|
|
||||||
|
// Gets the ViEFilePlayer for this file_id.
|
||||||
|
ViEFilePlayer* ViEFilePlayerPtr(int file_id) const;
|
||||||
|
|
||||||
|
int engine_id_;
|
||||||
|
CriticalSectionWrapper& map_cs_;
|
||||||
|
MapWrapper vie_frame_provider_map_;
|
||||||
|
|
||||||
|
// Capture devices.
|
||||||
|
VideoCaptureModule::DeviceInfo* capture_device_info_;
|
||||||
|
int free_capture_device_id_[kViEMaxCaptureDevices];
|
||||||
|
|
||||||
|
// File Players.
|
||||||
|
int free_file_id_[kViEMaxFilePlayers];
|
||||||
|
|
||||||
|
ProcessThread* module_process_thread_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ViEInputManagerScoped: private ViEManagerScopedBase
|
// Provides protected access to ViEInputManater.
|
||||||
{
|
class ViEInputManagerScoped: private ViEManagerScopedBase {
|
||||||
public:
|
public:
|
||||||
ViEInputManagerScoped(const ViEInputManager& vieInputManager);
|
explicit ViEInputManagerScoped(const ViEInputManager& vie_input_manager);
|
||||||
|
|
||||||
ViECapturer* Capture(int captureId) const;
|
ViECapturer* Capture(int capture_id) const;
|
||||||
ViEFilePlayer* FilePlayer(int fileId) const;
|
ViEFilePlayer* FilePlayer(int file_id) const;
|
||||||
ViEFrameProviderBase* FrameProvider(int providerId) const;
|
ViEFrameProviderBase* FrameProvider(int provider_id) const;
|
||||||
ViEFrameProviderBase* FrameProvider(const ViEFrameCallback*
|
ViEFrameProviderBase* FrameProvider(const ViEFrameCallback*
|
||||||
captureObserver) const;
|
capture_observer) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_INPUT_MANAGER_H_
|
|
||||||
|
#endif // WEBRTC_VIDEO_ENGINE_VIE_INPUT_MANAGER_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user