andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | _apiCritPtr(CriticalSectionWrapper::CreateCriticalSection()), |
| 29 | _channelManager(_gInstanceCounter), |
| 30 | _engineStatistics(_gInstanceCounter), |
| 31 | _audioDevicePtr(NULL), |
| 32 | _audioProcessingModulePtr(NULL), |
| 33 | _moduleProcessThreadPtr(ProcessThread::CreateProcessThread()), |
| 34 | _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 | |
| 52 | SharedData::~SharedData() |
| 53 | { |
| 54 | OutputMixer::Destroy(_outputMixerPtr); |
| 55 | TransmitMixer::Destroy(_transmitMixerPtr); |
| 56 | if (_audioDevicePtr) { |
| 57 | _audioDevicePtr->Release(); |
| 58 | } |
| 59 | AudioProcessing::Destroy(_audioProcessingModulePtr); |
| 60 | delete _apiCritPtr; |
| 61 | ProcessThread::DestroyProcessThread(_moduleProcessThreadPtr); |
| 62 | Trace::ReturnTrace(); |
| 63 | } |
| 64 | |
| 65 | void SharedData::set_audio_device(AudioDeviceModule* audio_device) |
| 66 | { |
| 67 | // AddRef first in case the pointers are equal. |
| 68 | if (audio_device) |
| 69 | audio_device->AddRef(); |
| 70 | if (_audioDevicePtr) |
| 71 | _audioDevicePtr->Release(); |
| 72 | _audioDevicePtr = audio_device; |
| 73 | } |
| 74 | |
| 75 | void SharedData::set_audio_processing(AudioProcessing* audio_processing) { |
| 76 | if (_audioProcessingModulePtr) |
| 77 | AudioProcessing::Destroy(_audioProcessingModulePtr); |
| 78 | _audioProcessingModulePtr = audio_processing; |
| 79 | } |
| 80 | |
| 81 | WebRtc_UWord16 SharedData::NumOfSendingChannels() |
| 82 | { |
| 83 | WebRtc_Word32 numOfChannels = _channelManager.NumOfChannels(); |
| 84 | if (numOfChannels <= 0) |
| 85 | { |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | WebRtc_UWord16 nChannelsSending(0); |
| 90 | WebRtc_Word32* channelsArray = new WebRtc_Word32[numOfChannels]; |
| 91 | |
| 92 | _channelManager.GetChannelIds(channelsArray, numOfChannels); |
| 93 | for (int i = 0; i < numOfChannels; i++) |
| 94 | { |
| 95 | voe::ScopedChannel sc(_channelManager, channelsArray[i]); |
| 96 | Channel* chPtr = sc.ChannelPtr(); |
| 97 | if (chPtr) |
| 98 | { |
| 99 | if (chPtr->Sending()) |
| 100 | { |
| 101 | nChannelsSending++; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | delete [] channelsArray; |
| 106 | return nChannelsSending; |
| 107 | } |
| 108 | |
| 109 | void SharedData::SetLastError(const WebRtc_Word32 error) const { |
| 110 | _engineStatistics.SetLastError(error); |
| 111 | } |
| 112 | |
| 113 | void SharedData::SetLastError(const WebRtc_Word32 error, |
| 114 | const TraceLevel level) const { |
| 115 | _engineStatistics.SetLastError(error, level); |
| 116 | } |
| 117 | |
| 118 | void SharedData::SetLastError(const WebRtc_Word32 error, const TraceLevel level, |
| 119 | const char* msg) const { |
| 120 | _engineStatistics.SetLastError(error, level, msg); |
| 121 | } |
| 122 | |
| 123 | } // namespace voe |
| 124 | |
| 125 | } // namespace webrtc |