niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 11 | #include "webrtc/voice_engine/shared_data.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 13 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | namespace voe { |
| 23 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 24 | static int32_t _gInstanceCounter = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
minyue@webrtc.org | e509f94 | 2013-09-12 17:03:00 +0000 | [diff] [blame] | 26 | SharedData::SharedData(const Config& config) : |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | _instanceId(++_gInstanceCounter), |
xians@google.com | 22963ab | 2011-08-03 12:40:23 +0000 | [diff] [blame] | 28 | _apiCritPtr(CriticalSectionWrapper::CreateCriticalSection()), |
minyue@webrtc.org | e509f94 | 2013-09-12 17:03:00 +0000 | [diff] [blame] | 29 | _channelManager(_gInstanceCounter, config), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | _engineStatistics(_gInstanceCounter), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | _audioDevicePtr(NULL), |
tommi@webrtc.org | 0c3e12b | 2015-02-06 09:44:12 +0000 | [diff] [blame] | 32 | _moduleProcessThreadPtr(ProcessThread::Create()), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | _externalRecording(false), |
| 34 | _externalPlayout(false) |
| 35 | { |
| 36 | Trace::CreateTrace(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | if (OutputMixer::Create(_outputMixerPtr, _gInstanceCounter) == 0) |
| 38 | { |
| 39 | _outputMixerPtr->SetEngineInformation(_engineStatistics); |
| 40 | } |
| 41 | if (TransmitMixer::Create(_transmitMixerPtr, _gInstanceCounter) == 0) |
| 42 | { |
| 43 | _transmitMixerPtr->SetEngineInformation(*_moduleProcessThreadPtr, |
| 44 | _engineStatistics, |
| 45 | _channelManager); |
| 46 | } |
| 47 | _audioDeviceLayer = AudioDeviceModule::kPlatformDefaultAudio; |
| 48 | } |
| 49 | |
| 50 | SharedData::~SharedData() |
| 51 | { |
| 52 | OutputMixer::Destroy(_outputMixerPtr); |
| 53 | TransmitMixer::Destroy(_transmitMixerPtr); |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 54 | if (_audioDevicePtr) { |
| 55 | _audioDevicePtr->Release(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | delete _apiCritPtr; |
tommi@webrtc.org | 0c3e12b | 2015-02-06 09:44:12 +0000 | [diff] [blame] | 58 | _moduleProcessThreadPtr->Stop(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | Trace::ReturnTrace(); |
| 60 | } |
| 61 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 62 | void SharedData::set_audio_device(AudioDeviceModule* audio_device) |
| 63 | { |
| 64 | // AddRef first in case the pointers are equal. |
| 65 | if (audio_device) |
| 66 | audio_device->AddRef(); |
| 67 | if (_audioDevicePtr) |
| 68 | _audioDevicePtr->Release(); |
| 69 | _audioDevicePtr = audio_device; |
| 70 | } |
| 71 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 72 | void SharedData::set_audio_processing(AudioProcessing* audioproc) { |
| 73 | audioproc_.reset(audioproc); |
| 74 | _transmitMixerPtr->SetAudioProcessingModule(audioproc); |
| 75 | _outputMixerPtr->SetAudioProcessingModule(audioproc); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 76 | } |
| 77 | |
xians@webrtc.org | 675e260 | 2013-10-17 16:15:34 +0000 | [diff] [blame] | 78 | int SharedData::NumOfSendingChannels() { |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 79 | ChannelManager::Iterator it(&_channelManager); |
xians@webrtc.org | 675e260 | 2013-10-17 16:15:34 +0000 | [diff] [blame] | 80 | int sending_channels = 0; |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 81 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 82 | for (ChannelManager::Iterator it(&_channelManager); it.IsValid(); |
| 83 | it.Increment()) { |
| 84 | if (it.GetChannel()->Sending()) |
| 85 | ++sending_channels; |
| 86 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 88 | return sending_channels; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | } |
| 90 | |
xians@webrtc.org | 675e260 | 2013-10-17 16:15:34 +0000 | [diff] [blame] | 91 | int SharedData::NumOfPlayingChannels() { |
| 92 | ChannelManager::Iterator it(&_channelManager); |
| 93 | int playout_channels = 0; |
| 94 | |
| 95 | for (ChannelManager::Iterator it(&_channelManager); it.IsValid(); |
| 96 | it.Increment()) { |
| 97 | if (it.GetChannel()->Playing()) |
| 98 | ++playout_channels; |
| 99 | } |
| 100 | |
| 101 | return playout_channels; |
| 102 | } |
| 103 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 104 | void SharedData::SetLastError(int32_t error) const { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 105 | _engineStatistics.SetLastError(error); |
| 106 | } |
| 107 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 108 | void SharedData::SetLastError(int32_t error, |
| 109 | TraceLevel level) const { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 110 | _engineStatistics.SetLastError(error, level); |
| 111 | } |
| 112 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 113 | void SharedData::SetLastError(int32_t error, TraceLevel level, |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 114 | const char* msg) const { |
| 115 | _engineStatistics.SetLastError(error, level, msg); |
| 116 | } |
| 117 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 118 | } // namespace voe |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 120 | } // namespace webrtc |