2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-04-04 14:57:19 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-21 13:52:32 +00:00
|
|
|
#include "webrtc/voice_engine/shared_data.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-05-21 13:52:32 +00:00
|
|
|
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
|
|
|
|
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
|
|
|
|
|
#include "webrtc/system_wrappers/interface/trace.h"
|
|
|
|
|
#include "webrtc/voice_engine/channel.h"
|
|
|
|
|
#include "webrtc/voice_engine/output_mixer.h"
|
|
|
|
|
#include "webrtc/voice_engine/transmit_mixer.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
namespace voe {
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
static int32_t _gInstanceCounter = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-09-12 17:03:00 +00:00
|
|
|
SharedData::SharedData(const Config& config) :
|
2011-07-07 08:21:25 +00:00
|
|
|
_instanceId(++_gInstanceCounter),
|
2011-08-03 12:40:23 +00:00
|
|
|
_apiCritPtr(CriticalSectionWrapper::CreateCriticalSection()),
|
2013-09-12 17:03:00 +00:00
|
|
|
_channelManager(_gInstanceCounter, config),
|
2011-07-07 08:21:25 +00:00
|
|
|
_engineStatistics(_gInstanceCounter),
|
|
|
|
|
_audioDevicePtr(NULL),
|
|
|
|
|
_moduleProcessThreadPtr(ProcessThread::CreateProcessThread()),
|
|
|
|
|
_externalRecording(false),
|
|
|
|
|
_externalPlayout(false)
|
|
|
|
|
{
|
|
|
|
|
Trace::CreateTrace();
|
|
|
|
|
if (OutputMixer::Create(_outputMixerPtr, _gInstanceCounter) == 0)
|
|
|
|
|
{
|
|
|
|
|
_outputMixerPtr->SetEngineInformation(_engineStatistics);
|
|
|
|
|
}
|
|
|
|
|
if (TransmitMixer::Create(_transmitMixerPtr, _gInstanceCounter) == 0)
|
|
|
|
|
{
|
|
|
|
|
_transmitMixerPtr->SetEngineInformation(*_moduleProcessThreadPtr,
|
|
|
|
|
_engineStatistics,
|
|
|
|
|
_channelManager);
|
|
|
|
|
}
|
|
|
|
|
_audioDeviceLayer = AudioDeviceModule::kPlatformDefaultAudio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SharedData::~SharedData()
|
|
|
|
|
{
|
|
|
|
|
OutputMixer::Destroy(_outputMixerPtr);
|
|
|
|
|
TransmitMixer::Destroy(_transmitMixerPtr);
|
2011-09-07 15:11:18 +00:00
|
|
|
if (_audioDevicePtr) {
|
|
|
|
|
_audioDevicePtr->Release();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
delete _apiCritPtr;
|
|
|
|
|
ProcessThread::DestroyProcessThread(_moduleProcessThreadPtr);
|
|
|
|
|
Trace::ReturnTrace();
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-04 14:57:19 +00:00
|
|
|
void SharedData::set_audio_device(AudioDeviceModule* audio_device)
|
|
|
|
|
{
|
|
|
|
|
// AddRef first in case the pointers are equal.
|
|
|
|
|
if (audio_device)
|
|
|
|
|
audio_device->AddRef();
|
|
|
|
|
if (_audioDevicePtr)
|
|
|
|
|
_audioDevicePtr->Release();
|
|
|
|
|
_audioDevicePtr = audio_device;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 01:12:49 +00:00
|
|
|
void SharedData::set_audio_processing(AudioProcessing* audioproc) {
|
|
|
|
|
audioproc_.reset(audioproc);
|
|
|
|
|
_transmitMixerPtr->SetAudioProcessingModule(audioproc);
|
|
|
|
|
_outputMixerPtr->SetAudioProcessingModule(audioproc);
|
2012-04-04 14:57:19 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-17 16:15:34 +00:00
|
|
|
int SharedData::NumOfSendingChannels() {
|
2013-08-07 17:57:36 +00:00
|
|
|
ChannelManager::Iterator it(&_channelManager);
|
2013-10-17 16:15:34 +00:00
|
|
|
int sending_channels = 0;
|
2012-06-27 03:25:31 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
|
|
|
|
|
it.Increment()) {
|
|
|
|
|
if (it.GetChannel()->Sending())
|
|
|
|
|
++sending_channels;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
return sending_channels;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-17 16:15:34 +00:00
|
|
|
int SharedData::NumOfPlayingChannels() {
|
|
|
|
|
ChannelManager::Iterator it(&_channelManager);
|
|
|
|
|
int playout_channels = 0;
|
|
|
|
|
|
|
|
|
|
for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
|
|
|
|
|
it.Increment()) {
|
|
|
|
|
if (it.GetChannel()->Playing())
|
|
|
|
|
++playout_channels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return playout_channels;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-14 08:31:39 +00:00
|
|
|
void SharedData::SetLastError(int32_t error) const {
|
2012-04-04 14:57:19 +00:00
|
|
|
_engineStatistics.SetLastError(error);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-14 08:31:39 +00:00
|
|
|
void SharedData::SetLastError(int32_t error,
|
|
|
|
|
TraceLevel level) const {
|
2012-04-04 14:57:19 +00:00
|
|
|
_engineStatistics.SetLastError(error, level);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-14 08:31:39 +00:00
|
|
|
void SharedData::SetLastError(int32_t error, TraceLevel level,
|
2012-04-04 14:57:19 +00:00
|
|
|
const char* msg) const {
|
|
|
|
|
_engineStatistics.SetLastError(error, level, msg);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace voe
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|