blob: 754368b3d8e44353df030b0f8627aa6b87f36498 [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
minyue@webrtc.orge509f942013-09-12 17:03:00 +000026SharedData::SharedData(const Config& config) :
niklase@google.com470e71d2011-07-07 08:21:25 +000027 _instanceId(++_gInstanceCounter),
xians@google.com22963ab2011-08-03 12:40:23 +000028 _apiCritPtr(CriticalSectionWrapper::CreateCriticalSection()),
minyue@webrtc.orge509f942013-09-12 17:03:00 +000029 _channelManager(_gInstanceCounter, config),
niklase@google.com470e71d2011-07-07 08:21:25 +000030 _engineStatistics(_gInstanceCounter),
niklase@google.com470e71d2011-07-07 08:21:25 +000031 _audioDevicePtr(NULL),
solenberge313e022015-09-08 02:16:04 -070032 _moduleProcessThreadPtr(ProcessThread::Create())
niklase@google.com470e71d2011-07-07 08:21:25 +000033{
34 Trace::CreateTrace();
niklase@google.com470e71d2011-07-07 08:21:25 +000035 if (OutputMixer::Create(_outputMixerPtr, _gInstanceCounter) == 0)
36 {
37 _outputMixerPtr->SetEngineInformation(_engineStatistics);
38 }
39 if (TransmitMixer::Create(_transmitMixerPtr, _gInstanceCounter) == 0)
40 {
41 _transmitMixerPtr->SetEngineInformation(*_moduleProcessThreadPtr,
42 _engineStatistics,
43 _channelManager);
44 }
45 _audioDeviceLayer = AudioDeviceModule::kPlatformDefaultAudio;
46}
47
48SharedData::~SharedData()
49{
50 OutputMixer::Destroy(_outputMixerPtr);
51 TransmitMixer::Destroy(_transmitMixerPtr);
henrika@google.com73d65512011-09-07 15:11:18 +000052 if (_audioDevicePtr) {
53 _audioDevicePtr->Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000054 }
niklase@google.com470e71d2011-07-07 08:21:25 +000055 delete _apiCritPtr;
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000056 _moduleProcessThreadPtr->Stop();
niklase@google.com470e71d2011-07-07 08:21:25 +000057 Trace::ReturnTrace();
58}
59
tommi@webrtc.org851becd2012-04-04 14:57:19 +000060void SharedData::set_audio_device(AudioDeviceModule* audio_device)
61{
62 // AddRef first in case the pointers are equal.
63 if (audio_device)
64 audio_device->AddRef();
65 if (_audioDevicePtr)
66 _audioDevicePtr->Release();
67 _audioDevicePtr = audio_device;
68}
69
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000070void SharedData::set_audio_processing(AudioProcessing* audioproc) {
71 audioproc_.reset(audioproc);
72 _transmitMixerPtr->SetAudioProcessingModule(audioproc);
73 _outputMixerPtr->SetAudioProcessingModule(audioproc);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000074}
75
xians@webrtc.org675e2602013-10-17 16:15:34 +000076int SharedData::NumOfSendingChannels() {
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000077 ChannelManager::Iterator it(&_channelManager);
xians@webrtc.org675e2602013-10-17 16:15:34 +000078 int sending_channels = 0;
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000079
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000080 for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
81 it.Increment()) {
82 if (it.GetChannel()->Sending())
83 ++sending_channels;
84 }
niklase@google.com470e71d2011-07-07 08:21:25 +000085
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000086 return sending_channels;
niklase@google.com470e71d2011-07-07 08:21:25 +000087}
88
xians@webrtc.org675e2602013-10-17 16:15:34 +000089int SharedData::NumOfPlayingChannels() {
90 ChannelManager::Iterator it(&_channelManager);
91 int playout_channels = 0;
92
93 for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
94 it.Increment()) {
95 if (it.GetChannel()->Playing())
96 ++playout_channels;
97 }
98
99 return playout_channels;
100}
101
pbos@webrtc.org92135212013-05-14 08:31:39 +0000102void SharedData::SetLastError(int32_t error) const {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000103 _engineStatistics.SetLastError(error);
104}
105
pbos@webrtc.org92135212013-05-14 08:31:39 +0000106void SharedData::SetLastError(int32_t error,
107 TraceLevel level) const {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000108 _engineStatistics.SetLastError(error, level);
109}
110
pbos@webrtc.org92135212013-05-14 08:31:39 +0000111void SharedData::SetLastError(int32_t error, TraceLevel level,
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000112 const char* msg) const {
113 _engineStatistics.SetLastError(error, level, msg);
114}
115
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000116} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +0000117
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000118} // namespace webrtc