blob: 0426ecaa4e34801969933c10fd17e8100992a0b0 [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
11#include "shared_data.h"
12
13#include "audio_processing.h"
14#include "critical_section_wrapper.h"
15#include "channel.h"
16#include "output_mixer.h"
17#include "trace.h"
18#include "transmit_mixer.h"
19
20namespace webrtc {
21
22namespace voe {
23
24static WebRtc_Word32 _gInstanceCounter = 0;
25
26SharedData::SharedData() :
27 _instanceId(++_gInstanceCounter),
xians@google.com22963ab2011-08-03 12:40:23 +000028 _apiCritPtr(CriticalSectionWrapper::CreateCriticalSection()),
niklase@google.com470e71d2011-07-07 08:21:25 +000029 _channelManager(_gInstanceCounter),
30 _engineStatistics(_gInstanceCounter),
niklase@google.com470e71d2011-07-07 08:21:25 +000031 _audioDevicePtr(NULL),
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000032 audioproc_(NULL),
niklase@google.com470e71d2011-07-07 08:21:25 +000033 _moduleProcessThreadPtr(ProcessThread::CreateProcessThread()),
niklase@google.com470e71d2011-07-07 08:21:25 +000034 _externalRecording(false),
35 _externalPlayout(false)
36{
37 Trace::CreateTrace();
38 Trace::SetLevelFilter(WEBRTC_VOICE_ENGINE_DEFAULT_TRACE_FILTER);
39 if (OutputMixer::Create(_outputMixerPtr, _gInstanceCounter) == 0)
40 {
41 _outputMixerPtr->SetEngineInformation(_engineStatistics);
42 }
43 if (TransmitMixer::Create(_transmitMixerPtr, _gInstanceCounter) == 0)
44 {
45 _transmitMixerPtr->SetEngineInformation(*_moduleProcessThreadPtr,
46 _engineStatistics,
47 _channelManager);
48 }
49 _audioDeviceLayer = AudioDeviceModule::kPlatformDefaultAudio;
50}
51
52SharedData::~SharedData()
53{
54 OutputMixer::Destroy(_outputMixerPtr);
55 TransmitMixer::Destroy(_transmitMixerPtr);
henrika@google.com73d65512011-09-07 15:11:18 +000056 if (_audioDevicePtr) {
57 _audioDevicePtr->Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000058 }
niklase@google.com470e71d2011-07-07 08:21:25 +000059 delete _apiCritPtr;
60 ProcessThread::DestroyProcessThread(_moduleProcessThreadPtr);
61 Trace::ReturnTrace();
62}
63
tommi@webrtc.org851becd2012-04-04 14:57:19 +000064void SharedData::set_audio_device(AudioDeviceModule* audio_device)
65{
66 // AddRef first in case the pointers are equal.
67 if (audio_device)
68 audio_device->AddRef();
69 if (_audioDevicePtr)
70 _audioDevicePtr->Release();
71 _audioDevicePtr = audio_device;
72}
73
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000074void SharedData::set_audio_processing(AudioProcessing* audioproc) {
75 audioproc_.reset(audioproc);
76 _transmitMixerPtr->SetAudioProcessingModule(audioproc);
77 _outputMixerPtr->SetAudioProcessingModule(audioproc);
tommi@webrtc.org851becd2012-04-04 14:57:19 +000078}
79
80WebRtc_UWord16 SharedData::NumOfSendingChannels()
niklase@google.com470e71d2011-07-07 08:21:25 +000081{
82 WebRtc_Word32 numOfChannels = _channelManager.NumOfChannels();
83 if (numOfChannels <= 0)
84 {
85 return 0;
86 }
andrew@webrtc.org4ecea3e2012-06-27 03:25:31 +000087
niklase@google.com470e71d2011-07-07 08:21:25 +000088 WebRtc_UWord16 nChannelsSending(0);
89 WebRtc_Word32* channelsArray = new WebRtc_Word32[numOfChannels];
90
91 _channelManager.GetChannelIds(channelsArray, numOfChannels);
92 for (int i = 0; i < numOfChannels; i++)
93 {
94 voe::ScopedChannel sc(_channelManager, channelsArray[i]);
95 Channel* chPtr = sc.ChannelPtr();
96 if (chPtr)
97 {
98 if (chPtr->Sending())
99 {
100 nChannelsSending++;
101 }
102 }
103 }
104 delete [] channelsArray;
105 return nChannelsSending;
106}
107
tommi@webrtc.org851becd2012-04-04 14:57:19 +0000108void SharedData::SetLastError(const WebRtc_Word32 error) const {
109 _engineStatistics.SetLastError(error);
110}
111
112void SharedData::SetLastError(const WebRtc_Word32 error,
113 const TraceLevel level) const {
114 _engineStatistics.SetLastError(error, level);
115}
116
117void SharedData::SetLastError(const WebRtc_Word32 error, const TraceLevel level,
118 const char* msg) const {
119 _engineStatistics.SetLastError(error, level, msg);
120}
121
niklase@google.com470e71d2011-07-07 08:21:25 +0000122} // namespace voe
123
124} // namespace webrtc