blob: 3b3f17f20bca367662e200a7972faa3d8f740d9e [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) {
33 _transmitMixerPtr->SetEngineInformation(*_moduleProcessThreadPtr,
34 _engineStatistics, _channelManager);
35 }
niklase@google.com470e71d2011-07-07 08:21:25 +000036}
37
38SharedData::~SharedData()
39{
niklase@google.com470e71d2011-07-07 08:21:25 +000040 TransmitMixer::Destroy(_transmitMixerPtr);
henrika@google.com73d65512011-09-07 15:11:18 +000041 if (_audioDevicePtr) {
42 _audioDevicePtr->Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000043 }
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000044 _moduleProcessThreadPtr->Stop();
niklase@google.com470e71d2011-07-07 08:21:25 +000045 Trace::ReturnTrace();
46}
47
henrikaec6fbd22017-03-31 05:43:36 -070048rtc::TaskQueue* SharedData::encoder_queue() {
49 RTC_DCHECK_RUN_ON(&construction_thread_);
50 return &encoder_queue_;
51}
52
Peter Boström1d194412016-03-21 16:44:31 +010053void SharedData::set_audio_device(
54 const rtc::scoped_refptr<AudioDeviceModule>& audio_device) {
55 _audioDevicePtr = audio_device;
tommi@webrtc.org851becd2012-04-04 14:57:19 +000056}
57
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000058void SharedData::set_audio_processing(AudioProcessing* audioproc) {
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000059 _transmitMixerPtr->SetAudioProcessingModule(audioproc);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000060}
61
xians@webrtc.org675e2602013-10-17 16:15:34 +000062int SharedData::NumOfSendingChannels() {
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000063 ChannelManager::Iterator it(&_channelManager);
xians@webrtc.org675e2602013-10-17 16:15:34 +000064 int sending_channels = 0;
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000065
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000066 for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
67 it.Increment()) {
68 if (it.GetChannel()->Sending())
69 ++sending_channels;
70 }
niklase@google.com470e71d2011-07-07 08:21:25 +000071
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000072 return sending_channels;
niklase@google.com470e71d2011-07-07 08:21:25 +000073}
74
xians@webrtc.org675e2602013-10-17 16:15:34 +000075int SharedData::NumOfPlayingChannels() {
76 ChannelManager::Iterator it(&_channelManager);
77 int playout_channels = 0;
78
79 for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
80 it.Increment()) {
81 if (it.GetChannel()->Playing())
82 ++playout_channels;
83 }
84
85 return playout_channels;
86}
87
pbos@webrtc.org92135212013-05-14 08:31:39 +000088void SharedData::SetLastError(int32_t error) const {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000089 _engineStatistics.SetLastError(error);
90}
91
pbos@webrtc.org92135212013-05-14 08:31:39 +000092void SharedData::SetLastError(int32_t error,
93 TraceLevel level) const {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000094 _engineStatistics.SetLastError(error, level);
95}
96
pbos@webrtc.org92135212013-05-14 08:31:39 +000097void SharedData::SetLastError(int32_t error, TraceLevel level,
tommi@webrtc.org851becd2012-04-04 14:57:19 +000098 const char* msg) const {
99 _engineStatistics.SetLastError(error, level, msg);
100}
101
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000102} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000104} // namespace webrtc