blob: 2362da5bb6c308082f466ec015262d26544fe0d6 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
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),
32 _audioProcessingModulePtr(NULL),
33 _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 }
59 AudioProcessing::Destroy(_audioProcessingModulePtr);
60 delete _apiCritPtr;
61 ProcessThread::DestroyProcessThread(_moduleProcessThreadPtr);
62 Trace::ReturnTrace();
63}
64
65WebRtc_UWord16
66SharedData::NumOfSendingChannels()
67{
68 WebRtc_Word32 numOfChannels = _channelManager.NumOfChannels();
69 if (numOfChannels <= 0)
70 {
71 return 0;
72 }
73
74 WebRtc_UWord16 nChannelsSending(0);
75 WebRtc_Word32* channelsArray = new WebRtc_Word32[numOfChannels];
76
77 _channelManager.GetChannelIds(channelsArray, numOfChannels);
78 for (int i = 0; i < numOfChannels; i++)
79 {
80 voe::ScopedChannel sc(_channelManager, channelsArray[i]);
81 Channel* chPtr = sc.ChannelPtr();
82 if (chPtr)
83 {
84 if (chPtr->Sending())
85 {
86 nChannelsSending++;
87 }
88 }
89 }
90 delete [] channelsArray;
91 return nChannelsSending;
92}
93
94} // namespace voe
95
96} // namespace webrtc