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