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" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 14 | #include "webrtc/system_wrappers/include/trace.h" |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 15 | #include "webrtc/voice_engine/channel.h" |
| 16 | #include "webrtc/voice_engine/output_mixer.h" |
| 17 | #include "webrtc/voice_engine/transmit_mixer.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | namespace voe { |
| 22 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 23 | static int32_t _gInstanceCounter = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 25 | SharedData::SharedData() |
stefan | 847855b | 2015-09-11 09:52:15 -0700 | [diff] [blame] | 26 | : _instanceId(++_gInstanceCounter), |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 27 | _channelManager(_gInstanceCounter), |
stefan | 847855b | 2015-09-11 09:52:15 -0700 | [diff] [blame] | 28 | _engineStatistics(_gInstanceCounter), |
| 29 | _audioDevicePtr(NULL), |
henrika | ec6fbd2 | 2017-03-31 05:43:36 -0700 | [diff] [blame] | 30 | _moduleProcessThreadPtr(ProcessThread::Create("VoiceProcessThread")), |
| 31 | encoder_queue_("AudioEncoderQueue") { |
| 32 | Trace::CreateTrace(); |
| 33 | if (OutputMixer::Create(_outputMixerPtr, _gInstanceCounter) == 0) { |
| 34 | _outputMixerPtr->SetEngineInformation(_engineStatistics); |
| 35 | } |
| 36 | if (TransmitMixer::Create(_transmitMixerPtr, _gInstanceCounter) == 0) { |
| 37 | _transmitMixerPtr->SetEngineInformation(*_moduleProcessThreadPtr, |
| 38 | _engineStatistics, _channelManager); |
| 39 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | SharedData::~SharedData() |
| 43 | { |
| 44 | OutputMixer::Destroy(_outputMixerPtr); |
| 45 | TransmitMixer::Destroy(_transmitMixerPtr); |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 46 | if (_audioDevicePtr) { |
| 47 | _audioDevicePtr->Release(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | } |
tommi@webrtc.org | 0c3e12b | 2015-02-06 09:44:12 +0000 | [diff] [blame] | 49 | _moduleProcessThreadPtr->Stop(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | Trace::ReturnTrace(); |
| 51 | } |
| 52 | |
henrika | ec6fbd2 | 2017-03-31 05:43:36 -0700 | [diff] [blame] | 53 | rtc::TaskQueue* SharedData::encoder_queue() { |
| 54 | RTC_DCHECK_RUN_ON(&construction_thread_); |
| 55 | return &encoder_queue_; |
| 56 | } |
| 57 | |
Peter Boström | 1d19441 | 2016-03-21 16:44:31 +0100 | [diff] [blame] | 58 | void SharedData::set_audio_device( |
| 59 | const rtc::scoped_refptr<AudioDeviceModule>& audio_device) { |
| 60 | _audioDevicePtr = audio_device; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 61 | } |
| 62 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 63 | void SharedData::set_audio_processing(AudioProcessing* audioproc) { |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 64 | _transmitMixerPtr->SetAudioProcessingModule(audioproc); |
| 65 | _outputMixerPtr->SetAudioProcessingModule(audioproc); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 66 | } |
| 67 | |
xians@webrtc.org | 675e260 | 2013-10-17 16:15:34 +0000 | [diff] [blame] | 68 | int SharedData::NumOfSendingChannels() { |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 69 | ChannelManager::Iterator it(&_channelManager); |
xians@webrtc.org | 675e260 | 2013-10-17 16:15:34 +0000 | [diff] [blame] | 70 | int sending_channels = 0; |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 71 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 72 | for (ChannelManager::Iterator it(&_channelManager); it.IsValid(); |
| 73 | it.Increment()) { |
| 74 | if (it.GetChannel()->Sending()) |
| 75 | ++sending_channels; |
| 76 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 78 | return sending_channels; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | } |
| 80 | |
xians@webrtc.org | 675e260 | 2013-10-17 16:15:34 +0000 | [diff] [blame] | 81 | int SharedData::NumOfPlayingChannels() { |
| 82 | ChannelManager::Iterator it(&_channelManager); |
| 83 | int playout_channels = 0; |
| 84 | |
| 85 | for (ChannelManager::Iterator it(&_channelManager); it.IsValid(); |
| 86 | it.Increment()) { |
| 87 | if (it.GetChannel()->Playing()) |
| 88 | ++playout_channels; |
| 89 | } |
| 90 | |
| 91 | return playout_channels; |
| 92 | } |
| 93 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 94 | void SharedData::SetLastError(int32_t error) const { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 95 | _engineStatistics.SetLastError(error); |
| 96 | } |
| 97 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 98 | void SharedData::SetLastError(int32_t error, |
| 99 | TraceLevel level) const { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 100 | _engineStatistics.SetLastError(error, level); |
| 101 | } |
| 102 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 103 | void SharedData::SetLastError(int32_t error, TraceLevel level, |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 104 | const char* msg) const { |
| 105 | _engineStatistics.SetLastError(error, level, msg); |
| 106 | } |
| 107 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 108 | } // namespace voe |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 110 | } // namespace webrtc |