niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 24 | static int32_t _gInstanceCounter = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
| 26 | SharedData::SharedData() : |
| 27 | _instanceId(++_gInstanceCounter), |
xians@google.com | 22963ab | 2011-08-03 12:40:23 +0000 | [diff] [blame] | 28 | _apiCritPtr(CriticalSectionWrapper::CreateCriticalSection()), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | _channelManager(_gInstanceCounter), |
| 30 | _engineStatistics(_gInstanceCounter), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | _audioDevicePtr(NULL), |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 32 | audioproc_(NULL), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | _moduleProcessThreadPtr(ProcessThread::CreateProcessThread()), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | _externalRecording(false), |
| 35 | _externalPlayout(false) |
| 36 | { |
| 37 | Trace::CreateTrace(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | if (OutputMixer::Create(_outputMixerPtr, _gInstanceCounter) == 0) |
| 39 | { |
| 40 | _outputMixerPtr->SetEngineInformation(_engineStatistics); |
| 41 | } |
| 42 | if (TransmitMixer::Create(_transmitMixerPtr, _gInstanceCounter) == 0) |
| 43 | { |
| 44 | _transmitMixerPtr->SetEngineInformation(*_moduleProcessThreadPtr, |
| 45 | _engineStatistics, |
| 46 | _channelManager); |
| 47 | } |
| 48 | _audioDeviceLayer = AudioDeviceModule::kPlatformDefaultAudio; |
| 49 | } |
| 50 | |
| 51 | SharedData::~SharedData() |
| 52 | { |
| 53 | OutputMixer::Destroy(_outputMixerPtr); |
| 54 | TransmitMixer::Destroy(_transmitMixerPtr); |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 55 | if (_audioDevicePtr) { |
| 56 | _audioDevicePtr->Release(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | delete _apiCritPtr; |
| 59 | ProcessThread::DestroyProcessThread(_moduleProcessThreadPtr); |
| 60 | Trace::ReturnTrace(); |
| 61 | } |
| 62 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 63 | void SharedData::set_audio_device(AudioDeviceModule* audio_device) |
| 64 | { |
| 65 | // AddRef first in case the pointers are equal. |
| 66 | if (audio_device) |
| 67 | audio_device->AddRef(); |
| 68 | if (_audioDevicePtr) |
| 69 | _audioDevicePtr->Release(); |
| 70 | _audioDevicePtr = audio_device; |
| 71 | } |
| 72 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 73 | void SharedData::set_audio_processing(AudioProcessing* audioproc) { |
| 74 | audioproc_.reset(audioproc); |
| 75 | _transmitMixerPtr->SetAudioProcessingModule(audioproc); |
| 76 | _outputMixerPtr->SetAudioProcessingModule(audioproc); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 77 | } |
| 78 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 79 | uint16_t SharedData::NumOfSendingChannels() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | { |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 81 | int32_t numOfChannels = _channelManager.NumOfChannels(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | if (numOfChannels <= 0) |
| 83 | { |
| 84 | return 0; |
| 85 | } |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 86 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 87 | uint16_t nChannelsSending(0); |
| 88 | int32_t* channelsArray = new int32_t[numOfChannels]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
| 90 | _channelManager.GetChannelIds(channelsArray, numOfChannels); |
| 91 | for (int i = 0; i < numOfChannels; i++) |
| 92 | { |
| 93 | voe::ScopedChannel sc(_channelManager, channelsArray[i]); |
| 94 | Channel* chPtr = sc.ChannelPtr(); |
| 95 | if (chPtr) |
| 96 | { |
| 97 | if (chPtr->Sending()) |
| 98 | { |
| 99 | nChannelsSending++; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | delete [] channelsArray; |
| 104 | return nChannelsSending; |
| 105 | } |
| 106 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 107 | void SharedData::SetLastError(const int32_t error) const { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 108 | _engineStatistics.SetLastError(error); |
| 109 | } |
| 110 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 111 | void SharedData::SetLastError(const int32_t error, |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 112 | const TraceLevel level) const { |
| 113 | _engineStatistics.SetLastError(error, level); |
| 114 | } |
| 115 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 116 | void SharedData::SetLastError(const int32_t error, const TraceLevel level, |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 117 | const char* msg) const { |
| 118 | _engineStatistics.SetLastError(error, level, msg); |
| 119 | } |
| 120 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | } // namespace voe |
| 122 | |
| 123 | } // namespace webrtc |