blob: ac830c7163438bc37a7da1332491ef8cb4d9554c [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"
Fredrik Solenberg39cefdb2017-10-04 08:49:37 +000014#include "system_wrappers/include/trace.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "voice_engine/channel.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "voice_engine/transmit_mixer.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
18namespace webrtc {
19
20namespace voe {
21
pbos@webrtc.org6141e132013-04-09 10:09:10 +000022static int32_t _gInstanceCounter = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000023
solenberg88499ec2016-09-07 07:34:41 -070024SharedData::SharedData()
stefan847855b2015-09-11 09:52:15 -070025 : _instanceId(++_gInstanceCounter),
solenberg88499ec2016-09-07 07:34:41 -070026 _channelManager(_gInstanceCounter),
stefan847855b2015-09-11 09:52:15 -070027 _audioDevicePtr(NULL),
henrikaec6fbd22017-03-31 05:43:36 -070028 _moduleProcessThreadPtr(ProcessThread::Create("VoiceProcessThread")),
29 encoder_queue_("AudioEncoderQueue") {
Fredrik Solenberg39cefdb2017-10-04 08:49:37 +000030 Trace::CreateTrace();
31 if (TransmitMixer::Create(_transmitMixerPtr, _gInstanceCounter) == 0) {
solenbergfc3a2e32017-09-26 09:35:01 -070032 _transmitMixerPtr->SetEngineInformation(&_channelManager);
henrikaec6fbd22017-03-31 05:43:36 -070033 }
niklase@google.com470e71d2011-07-07 08:21:25 +000034}
35
36SharedData::~SharedData()
37{
niklase@google.com470e71d2011-07-07 08:21:25 +000038 TransmitMixer::Destroy(_transmitMixerPtr);
henrika@google.com73d65512011-09-07 15:11:18 +000039 if (_audioDevicePtr) {
40 _audioDevicePtr->Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000041 }
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000042 _moduleProcessThreadPtr->Stop();
Fredrik Solenberg39cefdb2017-10-04 08:49:37 +000043 Trace::ReturnTrace();
niklase@google.com470e71d2011-07-07 08:21:25 +000044}
45
henrikaec6fbd22017-03-31 05:43:36 -070046rtc::TaskQueue* SharedData::encoder_queue() {
47 RTC_DCHECK_RUN_ON(&construction_thread_);
48 return &encoder_queue_;
49}
50
Peter Boström1d194412016-03-21 16:44:31 +010051void SharedData::set_audio_device(
52 const rtc::scoped_refptr<AudioDeviceModule>& audio_device) {
53 _audioDevicePtr = audio_device;
tommi@webrtc.org851becd2012-04-04 14:57:19 +000054}
55
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000056void SharedData::set_audio_processing(AudioProcessing* audioproc) {
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000057 _transmitMixerPtr->SetAudioProcessingModule(audioproc);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000058}
59
xians@webrtc.org675e2602013-10-17 16:15:34 +000060int SharedData::NumOfSendingChannels() {
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000061 ChannelManager::Iterator it(&_channelManager);
xians@webrtc.org675e2602013-10-17 16:15:34 +000062 int sending_channels = 0;
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000063
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000064 for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
65 it.Increment()) {
66 if (it.GetChannel()->Sending())
67 ++sending_channels;
68 }
niklase@google.com470e71d2011-07-07 08:21:25 +000069
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000070 return sending_channels;
niklase@google.com470e71d2011-07-07 08:21:25 +000071}
72
xians@webrtc.org675e2602013-10-17 16:15:34 +000073int SharedData::NumOfPlayingChannels() {
74 ChannelManager::Iterator it(&_channelManager);
75 int playout_channels = 0;
76
77 for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
78 it.Increment()) {
79 if (it.GetChannel()->Playing())
80 ++playout_channels;
81 }
82
83 return playout_channels;
84}
85
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000086} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +000087
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000088} // namespace webrtc