blob: 843d5db6e36d198382182bd0f40cb70734aee4b5 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
tommi@webrtc.org851becd2012-04-04 14:57:19 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000011#include "webrtc/voice_engine/shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000013#include "webrtc/modules/audio_processing/include/audio_processing.h"
14#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
15#include "webrtc/system_wrappers/interface/trace.h"
16#include "webrtc/voice_engine/channel.h"
17#include "webrtc/voice_engine/output_mixer.h"
18#include "webrtc/voice_engine/transmit_mixer.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019
20namespace webrtc {
21
22namespace voe {
23
pbos@webrtc.org6141e132013-04-09 10:09:10 +000024static int32_t _gInstanceCounter = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000025
26SharedData::SharedData() :
27 _instanceId(++_gInstanceCounter),
xians@google.com22963ab2011-08-03 12:40:23 +000028 _apiCritPtr(CriticalSectionWrapper::CreateCriticalSection()),
niklase@google.com470e71d2011-07-07 08:21:25 +000029 _channelManager(_gInstanceCounter),
30 _engineStatistics(_gInstanceCounter),
niklase@google.com470e71d2011-07-07 08:21:25 +000031 _audioDevicePtr(NULL),
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000032 audioproc_(NULL),
niklase@google.com470e71d2011-07-07 08:21:25 +000033 _moduleProcessThreadPtr(ProcessThread::CreateProcessThread()),
niklase@google.com470e71d2011-07-07 08:21:25 +000034 _externalRecording(false),
35 _externalPlayout(false)
36{
37 Trace::CreateTrace();
niklase@google.com470e71d2011-07-07 08:21:25 +000038 if (OutputMixer::Create(_outputMixerPtr, _gInstanceCounter) == 0)
39 {
40 _outputMixerPtr->SetEngineInformation(_engineStatistics);
41 }
42 if (TransmitMixer::Create(_transmitMixerPtr, _gInstanceCounter) == 0)
43 {
44 _transmitMixerPtr->SetEngineInformation(*_moduleProcessThreadPtr,
45 _engineStatistics,
46 _channelManager);
47 }
48 _audioDeviceLayer = AudioDeviceModule::kPlatformDefaultAudio;
49}
50
51SharedData::~SharedData()
52{
53 OutputMixer::Destroy(_outputMixerPtr);
54 TransmitMixer::Destroy(_transmitMixerPtr);
henrika@google.com73d65512011-09-07 15:11:18 +000055 if (_audioDevicePtr) {
56 _audioDevicePtr->Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000057 }
niklase@google.com470e71d2011-07-07 08:21:25 +000058 delete _apiCritPtr;
59 ProcessThread::DestroyProcessThread(_moduleProcessThreadPtr);
60 Trace::ReturnTrace();
61}
62
tommi@webrtc.org851becd2012-04-04 14:57:19 +000063void SharedData::set_audio_device(AudioDeviceModule* audio_device)
64{
65 // AddRef first in case the pointers are equal.
66 if (audio_device)
67 audio_device->AddRef();
68 if (_audioDevicePtr)
69 _audioDevicePtr->Release();
70 _audioDevicePtr = audio_device;
71}
72
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000073void SharedData::set_audio_processing(AudioProcessing* audioproc) {
74 audioproc_.reset(audioproc);
75 _transmitMixerPtr->SetAudioProcessingModule(audioproc);
76 _outputMixerPtr->SetAudioProcessingModule(audioproc);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000077}
78
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000079uint16_t SharedData::NumOfSendingChannels() {
80 ChannelManager::Iterator it(&_channelManager);
81 uint16_t sending_channels = 0;
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000082
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000083 for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
84 it.Increment()) {
85 if (it.GetChannel()->Sending())
86 ++sending_channels;
87 }
niklase@google.com470e71d2011-07-07 08:21:25 +000088
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000089 return sending_channels;
niklase@google.com470e71d2011-07-07 08:21:25 +000090}
91
pbos@webrtc.org92135212013-05-14 08:31:39 +000092void SharedData::SetLastError(int32_t error) const {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000093 _engineStatistics.SetLastError(error);
94}
95
pbos@webrtc.org92135212013-05-14 08:31:39 +000096void SharedData::SetLastError(int32_t error,
97 TraceLevel level) const {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000098 _engineStatistics.SetLastError(error, level);
99}
100
pbos@webrtc.org92135212013-05-14 08:31:39 +0000101void SharedData::SetLastError(int32_t error, TraceLevel level,
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000102 const char* msg) const {
103 _engineStatistics.SetLastError(error, level, msg);
104}
105
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000106} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000108} // namespace webrtc