blob: 01e163b394a12c4f9fa27ea7dd045e9dcf84c1da [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "voice_engine/shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "modules/audio_processing/include/audio_processing.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "voice_engine/channel.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "voice_engine/transmit_mixer.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016
17namespace webrtc {
18
19namespace voe {
20
pbos@webrtc.org6141e132013-04-09 10:09:10 +000021static int32_t _gInstanceCounter = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000022
solenberg88499ec2016-09-07 07:34:41 -070023SharedData::SharedData()
stefan847855b2015-09-11 09:52:15 -070024 : _instanceId(++_gInstanceCounter),
solenberg88499ec2016-09-07 07:34:41 -070025 _channelManager(_gInstanceCounter),
stefan847855b2015-09-11 09:52:15 -070026 _audioDevicePtr(NULL),
henrikaec6fbd22017-03-31 05:43:36 -070027 _moduleProcessThreadPtr(ProcessThread::Create("VoiceProcessThread")),
28 encoder_queue_("AudioEncoderQueue") {
Fredrik Solenberg68007e92017-10-04 09:53:35 +020029 if (TransmitMixer::Create(_transmitMixerPtr) == 0) {
solenbergfc3a2e32017-09-26 09:35:01 -070030 _transmitMixerPtr->SetEngineInformation(&_channelManager);
henrikaec6fbd22017-03-31 05:43:36 -070031 }
niklase@google.com470e71d2011-07-07 08:21:25 +000032}
33
34SharedData::~SharedData()
35{
niklase@google.com470e71d2011-07-07 08:21:25 +000036 TransmitMixer::Destroy(_transmitMixerPtr);
henrika@google.com73d65512011-09-07 15:11:18 +000037 if (_audioDevicePtr) {
38 _audioDevicePtr->Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000039 }
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000040 _moduleProcessThreadPtr->Stop();
niklase@google.com470e71d2011-07-07 08:21:25 +000041}
42
henrikaec6fbd22017-03-31 05:43:36 -070043rtc::TaskQueue* SharedData::encoder_queue() {
44 RTC_DCHECK_RUN_ON(&construction_thread_);
45 return &encoder_queue_;
46}
47
Peter Boström1d194412016-03-21 16:44:31 +010048void SharedData::set_audio_device(
49 const rtc::scoped_refptr<AudioDeviceModule>& audio_device) {
50 _audioDevicePtr = audio_device;
tommi@webrtc.org851becd2012-04-04 14:57:19 +000051}
52
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000053void SharedData::set_audio_processing(AudioProcessing* audioproc) {
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000054 _transmitMixerPtr->SetAudioProcessingModule(audioproc);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000055}
56
xians@webrtc.org675e2602013-10-17 16:15:34 +000057int SharedData::NumOfSendingChannels() {
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000058 ChannelManager::Iterator it(&_channelManager);
xians@webrtc.org675e2602013-10-17 16:15:34 +000059 int sending_channels = 0;
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000060
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000061 for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
62 it.Increment()) {
63 if (it.GetChannel()->Sending())
64 ++sending_channels;
65 }
niklase@google.com470e71d2011-07-07 08:21:25 +000066
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000067 return sending_channels;
niklase@google.com470e71d2011-07-07 08:21:25 +000068}
69
xians@webrtc.org675e2602013-10-17 16:15:34 +000070int 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.orgd900e8b2013-07-03 15:12:26 +000083} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +000084
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000085} // namespace webrtc