niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | namespace voe { |
| 23 | |
| 24 | static WebRtc_Word32 _gInstanceCounter = 0; |
| 25 | |
| 26 | SharedData::SharedData() : |
| 27 | _instanceId(++_gInstanceCounter), |
| 28 | _channelManager(_gInstanceCounter), |
| 29 | _engineStatistics(_gInstanceCounter), |
| 30 | _usingExternalAudioDevice(false), |
| 31 | _audioDevicePtr(NULL), |
| 32 | _audioProcessingModulePtr(NULL), |
| 33 | _moduleProcessThreadPtr(ProcessThread::CreateProcessThread()), |
| 34 | _apiCritPtr(CriticalSectionWrapper::CreateCriticalSection()), |
| 35 | _externalRecording(false), |
| 36 | _externalPlayout(false) |
| 37 | { |
| 38 | Trace::CreateTrace(); |
| 39 | Trace::SetLevelFilter(WEBRTC_VOICE_ENGINE_DEFAULT_TRACE_FILTER); |
| 40 | if (OutputMixer::Create(_outputMixerPtr, _gInstanceCounter) == 0) |
| 41 | { |
| 42 | _outputMixerPtr->SetEngineInformation(_engineStatistics); |
| 43 | } |
| 44 | if (TransmitMixer::Create(_transmitMixerPtr, _gInstanceCounter) == 0) |
| 45 | { |
| 46 | _transmitMixerPtr->SetEngineInformation(*_moduleProcessThreadPtr, |
| 47 | _engineStatistics, |
| 48 | _channelManager); |
| 49 | } |
| 50 | _audioDeviceLayer = AudioDeviceModule::kPlatformDefaultAudio; |
| 51 | } |
| 52 | |
| 53 | SharedData::~SharedData() |
| 54 | { |
| 55 | OutputMixer::Destroy(_outputMixerPtr); |
| 56 | TransmitMixer::Destroy(_transmitMixerPtr); |
| 57 | if (!_usingExternalAudioDevice) |
| 58 | { |
| 59 | AudioDeviceModule::Destroy(_audioDevicePtr); |
| 60 | } |
| 61 | AudioProcessing::Destroy(_audioProcessingModulePtr); |
| 62 | delete _apiCritPtr; |
| 63 | ProcessThread::DestroyProcessThread(_moduleProcessThreadPtr); |
| 64 | Trace::ReturnTrace(); |
| 65 | } |
| 66 | |
| 67 | WebRtc_UWord16 |
| 68 | SharedData::NumOfSendingChannels() |
| 69 | { |
| 70 | WebRtc_Word32 numOfChannels = _channelManager.NumOfChannels(); |
| 71 | if (numOfChannels <= 0) |
| 72 | { |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | WebRtc_UWord16 nChannelsSending(0); |
| 77 | WebRtc_Word32* channelsArray = new WebRtc_Word32[numOfChannels]; |
| 78 | |
| 79 | _channelManager.GetChannelIds(channelsArray, numOfChannels); |
| 80 | for (int i = 0; i < numOfChannels; i++) |
| 81 | { |
| 82 | voe::ScopedChannel sc(_channelManager, channelsArray[i]); |
| 83 | Channel* chPtr = sc.ChannelPtr(); |
| 84 | if (chPtr) |
| 85 | { |
| 86 | if (chPtr->Sending()) |
| 87 | { |
| 88 | nChannelsSending++; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | delete [] channelsArray; |
| 93 | return nChannelsSending; |
| 94 | } |
| 95 | |
| 96 | } // namespace voe |
| 97 | |
| 98 | } // namespace webrtc |