blob: 4bc5b3cf2b6140e636677b01e195d722a1cd3563 [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"
Henrik Kjellander98f53512015-10-28 18:17:40 +010014#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
15#include "webrtc/system_wrappers/include/trace.h"
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000016#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
stefan847855b2015-09-11 09:52:15 -070026SharedData::SharedData(const Config& config)
27 : _instanceId(++_gInstanceCounter),
28 _apiCritPtr(CriticalSectionWrapper::CreateCriticalSection()),
29 _channelManager(_gInstanceCounter, config),
30 _engineStatistics(_gInstanceCounter),
31 _audioDevicePtr(NULL),
32 _moduleProcessThreadPtr(ProcessThread::Create("VoiceProcessThread")) {
niklase@google.com470e71d2011-07-07 08:21:25 +000033 Trace::CreateTrace();
niklase@google.com470e71d2011-07-07 08:21:25 +000034 if (OutputMixer::Create(_outputMixerPtr, _gInstanceCounter) == 0)
35 {
36 _outputMixerPtr->SetEngineInformation(_engineStatistics);
37 }
38 if (TransmitMixer::Create(_transmitMixerPtr, _gInstanceCounter) == 0)
39 {
40 _transmitMixerPtr->SetEngineInformation(*_moduleProcessThreadPtr,
41 _engineStatistics,
42 _channelManager);
43 }
44 _audioDeviceLayer = AudioDeviceModule::kPlatformDefaultAudio;
45}
46
47SharedData::~SharedData()
48{
49 OutputMixer::Destroy(_outputMixerPtr);
50 TransmitMixer::Destroy(_transmitMixerPtr);
henrika@google.com73d65512011-09-07 15:11:18 +000051 if (_audioDevicePtr) {
52 _audioDevicePtr->Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000053 }
niklase@google.com470e71d2011-07-07 08:21:25 +000054 delete _apiCritPtr;
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000055 _moduleProcessThreadPtr->Stop();
niklase@google.com470e71d2011-07-07 08:21:25 +000056 Trace::ReturnTrace();
57}
58
tommi@webrtc.org851becd2012-04-04 14:57:19 +000059void SharedData::set_audio_device(AudioDeviceModule* audio_device)
60{
61 // AddRef first in case the pointers are equal.
62 if (audio_device)
63 audio_device->AddRef();
64 if (_audioDevicePtr)
65 _audioDevicePtr->Release();
66 _audioDevicePtr = audio_device;
67}
68
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000069void SharedData::set_audio_processing(AudioProcessing* audioproc) {
70 audioproc_.reset(audioproc);
71 _transmitMixerPtr->SetAudioProcessingModule(audioproc);
72 _outputMixerPtr->SetAudioProcessingModule(audioproc);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000073}
74
xians@webrtc.org675e2602013-10-17 16:15:34 +000075int SharedData::NumOfSendingChannels() {
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000076 ChannelManager::Iterator it(&_channelManager);
xians@webrtc.org675e2602013-10-17 16:15:34 +000077 int sending_channels = 0;
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000078
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000079 for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
80 it.Increment()) {
81 if (it.GetChannel()->Sending())
82 ++sending_channels;
83 }
niklase@google.com470e71d2011-07-07 08:21:25 +000084
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000085 return sending_channels;
niklase@google.com470e71d2011-07-07 08:21:25 +000086}
87
xians@webrtc.org675e2602013-10-17 16:15:34 +000088int SharedData::NumOfPlayingChannels() {
89 ChannelManager::Iterator it(&_channelManager);
90 int playout_channels = 0;
91
92 for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
93 it.Increment()) {
94 if (it.GetChannel()->Playing())
95 ++playout_channels;
96 }
97
98 return playout_channels;
99}
100
pbos@webrtc.org92135212013-05-14 08:31:39 +0000101void SharedData::SetLastError(int32_t error) const {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000102 _engineStatistics.SetLastError(error);
103}
104
pbos@webrtc.org92135212013-05-14 08:31:39 +0000105void SharedData::SetLastError(int32_t error,
106 TraceLevel level) const {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000107 _engineStatistics.SetLastError(error, level);
108}
109
pbos@webrtc.org92135212013-05-14 08:31:39 +0000110void SharedData::SetLastError(int32_t error, TraceLevel level,
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000111 const char* msg) const {
112 _engineStatistics.SetLastError(error, level, msg);
113}
114
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000115} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000117} // namespace webrtc