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