blob: 48c8b0f22b333a6763cee46a9d4665baf3e805f2 [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"
14#include "system_wrappers/include/trace.h"
15#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 _engineStatistics(_gInstanceCounter),
28 _audioDevicePtr(NULL),
henrikaec6fbd22017-03-31 05:43:36 -070029 _moduleProcessThreadPtr(ProcessThread::Create("VoiceProcessThread")),
30 encoder_queue_("AudioEncoderQueue") {
31 Trace::CreateTrace();
henrikaec6fbd22017-03-31 05:43:36 -070032 if (TransmitMixer::Create(_transmitMixerPtr, _gInstanceCounter) == 0) {
solenbergfc3a2e32017-09-26 09:35:01 -070033 _transmitMixerPtr->SetEngineInformation(&_channelManager);
henrikaec6fbd22017-03-31 05:43:36 -070034 }
niklase@google.com470e71d2011-07-07 08:21:25 +000035}
36
37SharedData::~SharedData()
38{
niklase@google.com470e71d2011-07-07 08:21:25 +000039 TransmitMixer::Destroy(_transmitMixerPtr);
henrika@google.com73d65512011-09-07 15:11:18 +000040 if (_audioDevicePtr) {
41 _audioDevicePtr->Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000042 }
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000043 _moduleProcessThreadPtr->Stop();
niklase@google.com470e71d2011-07-07 08:21:25 +000044 Trace::ReturnTrace();
45}
46
henrikaec6fbd22017-03-31 05:43:36 -070047rtc::TaskQueue* SharedData::encoder_queue() {
48 RTC_DCHECK_RUN_ON(&construction_thread_);
49 return &encoder_queue_;
50}
51
Peter Boström1d194412016-03-21 16:44:31 +010052void SharedData::set_audio_device(
53 const rtc::scoped_refptr<AudioDeviceModule>& audio_device) {
54 _audioDevicePtr = audio_device;
tommi@webrtc.org851becd2012-04-04 14:57:19 +000055}
56
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000057void SharedData::set_audio_processing(AudioProcessing* audioproc) {
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000058 _transmitMixerPtr->SetAudioProcessingModule(audioproc);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000059}
60
xians@webrtc.org675e2602013-10-17 16:15:34 +000061int SharedData::NumOfSendingChannels() {
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000062 ChannelManager::Iterator it(&_channelManager);
xians@webrtc.org675e2602013-10-17 16:15:34 +000063 int sending_channels = 0;
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000064
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000065 for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
66 it.Increment()) {
67 if (it.GetChannel()->Sending())
68 ++sending_channels;
69 }
niklase@google.com470e71d2011-07-07 08:21:25 +000070
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000071 return sending_channels;
niklase@google.com470e71d2011-07-07 08:21:25 +000072}
73
xians@webrtc.org675e2602013-10-17 16:15:34 +000074int 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.org92135212013-05-14 08:31:39 +000087void SharedData::SetLastError(int32_t error) const {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000088 _engineStatistics.SetLastError(error);
89}
90
pbos@webrtc.org92135212013-05-14 08:31:39 +000091void SharedData::SetLastError(int32_t error,
92 TraceLevel level) const {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000093 _engineStatistics.SetLastError(error, level);
94}
95
pbos@webrtc.org92135212013-05-14 08:31:39 +000096void SharedData::SetLastError(int32_t error, TraceLevel level,
tommi@webrtc.org851becd2012-04-04 14:57:19 +000097 const char* msg) const {
98 _engineStatistics.SetLastError(error, level, msg);
99}
100
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000101} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000103} // namespace webrtc