blob: 464374ef31eef1871da1dd4fc6638efae2a6a045 [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
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000011#include "webrtc/voice_engine/shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000013#include "webrtc/modules/audio_processing/include/audio_processing.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010014#include "webrtc/system_wrappers/include/trace.h"
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000015#include "webrtc/voice_engine/channel.h"
16#include "webrtc/voice_engine/output_mixer.h"
17#include "webrtc/voice_engine/transmit_mixer.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000018
19namespace webrtc {
20
21namespace voe {
22
pbos@webrtc.org6141e132013-04-09 10:09:10 +000023static int32_t _gInstanceCounter = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000024
solenberg88499ec2016-09-07 07:34:41 -070025SharedData::SharedData()
stefan847855b2015-09-11 09:52:15 -070026 : _instanceId(++_gInstanceCounter),
solenberg88499ec2016-09-07 07:34:41 -070027 _channelManager(_gInstanceCounter),
stefan847855b2015-09-11 09:52:15 -070028 _engineStatistics(_gInstanceCounter),
29 _audioDevicePtr(NULL),
henrikaec6fbd22017-03-31 05:43:36 -070030 _moduleProcessThreadPtr(ProcessThread::Create("VoiceProcessThread")),
31 encoder_queue_("AudioEncoderQueue") {
32 Trace::CreateTrace();
33 if (OutputMixer::Create(_outputMixerPtr, _gInstanceCounter) == 0) {
34 _outputMixerPtr->SetEngineInformation(_engineStatistics);
35 }
36 if (TransmitMixer::Create(_transmitMixerPtr, _gInstanceCounter) == 0) {
37 _transmitMixerPtr->SetEngineInformation(*_moduleProcessThreadPtr,
38 _engineStatistics, _channelManager);
39 }
niklase@google.com470e71d2011-07-07 08:21:25 +000040}
41
42SharedData::~SharedData()
43{
44 OutputMixer::Destroy(_outputMixerPtr);
45 TransmitMixer::Destroy(_transmitMixerPtr);
henrika@google.com73d65512011-09-07 15:11:18 +000046 if (_audioDevicePtr) {
47 _audioDevicePtr->Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000048 }
tommi@webrtc.org0c3e12b2015-02-06 09:44:12 +000049 _moduleProcessThreadPtr->Stop();
niklase@google.com470e71d2011-07-07 08:21:25 +000050 Trace::ReturnTrace();
51}
52
henrikaec6fbd22017-03-31 05:43:36 -070053rtc::TaskQueue* SharedData::encoder_queue() {
54 RTC_DCHECK_RUN_ON(&construction_thread_);
55 return &encoder_queue_;
56}
57
Peter Boström1d194412016-03-21 16:44:31 +010058void SharedData::set_audio_device(
59 const rtc::scoped_refptr<AudioDeviceModule>& audio_device) {
60 _audioDevicePtr = audio_device;
tommi@webrtc.org851becd2012-04-04 14:57:19 +000061}
62
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000063void SharedData::set_audio_processing(AudioProcessing* audioproc) {
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000064 _transmitMixerPtr->SetAudioProcessingModule(audioproc);
65 _outputMixerPtr->SetAudioProcessingModule(audioproc);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000066}
67
xians@webrtc.org675e2602013-10-17 16:15:34 +000068int SharedData::NumOfSendingChannels() {
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000069 ChannelManager::Iterator it(&_channelManager);
xians@webrtc.org675e2602013-10-17 16:15:34 +000070 int sending_channels = 0;
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000071
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000072 for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
73 it.Increment()) {
74 if (it.GetChannel()->Sending())
75 ++sending_channels;
76 }
niklase@google.com470e71d2011-07-07 08:21:25 +000077
pbos@webrtc.org676ff1e2013-08-07 17:57:36 +000078 return sending_channels;
niklase@google.com470e71d2011-07-07 08:21:25 +000079}
80
xians@webrtc.org675e2602013-10-17 16:15:34 +000081int SharedData::NumOfPlayingChannels() {
82 ChannelManager::Iterator it(&_channelManager);
83 int playout_channels = 0;
84
85 for (ChannelManager::Iterator it(&_channelManager); it.IsValid();
86 it.Increment()) {
87 if (it.GetChannel()->Playing())
88 ++playout_channels;
89 }
90
91 return playout_channels;
92}
93
pbos@webrtc.org92135212013-05-14 08:31:39 +000094void SharedData::SetLastError(int32_t error) const {
tommi@webrtc.org851becd2012-04-04 14:57:19 +000095 _engineStatistics.SetLastError(error);
96}
97
pbos@webrtc.org92135212013-05-14 08:31:39 +000098void SharedData::SetLastError(int32_t error,
99 TraceLevel level) const {
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000100 _engineStatistics.SetLastError(error, level);
101}
102
pbos@webrtc.org92135212013-05-14 08:31:39 +0000103void SharedData::SetLastError(int32_t error, TraceLevel level,
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000104 const char* msg) const {
105 _engineStatistics.SetLastError(error, level, msg);
106}
107
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000108} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000110} // namespace webrtc