niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +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 "voe_base_impl.h" |
| 12 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 13 | #include "audio_coding_module.h" |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 14 | #include "audio_processing.h" |
| 15 | #include "channel.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | #include "critical_section_wrapper.h" |
| 17 | #include "file_wrapper.h" |
andrew@webrtc.org | 236d5d3 | 2012-09-21 20:46:40 +0000 | [diff] [blame] | 18 | #include "modules/audio_device/audio_device_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | #include "output_mixer.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | #include "signal_processing_library.h" |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 21 | #include "trace.h" |
| 22 | #include "transmit_mixer.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | #include "utility.h" |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 24 | #include "voe_errors.h" |
| 25 | #include "voice_engine_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
| 27 | #if (defined(_WIN32) && defined(_DLL) && (_MSC_VER == 1400)) |
| 28 | // Fix for VS 2005 MD/MDd link problem |
| 29 | #include <stdio.h> |
| 30 | extern "C" |
| 31 | { FILE _iob[3] = { __iob_func()[0], __iob_func()[1], __iob_func()[2]}; } |
| 32 | #endif |
| 33 | |
| 34 | namespace webrtc |
| 35 | { |
| 36 | |
| 37 | VoEBase* VoEBase::GetInterface(VoiceEngine* voiceEngine) |
| 38 | { |
| 39 | if (NULL == voiceEngine) |
| 40 | { |
| 41 | return NULL; |
| 42 | } |
tommi@webrtc.org | 0989fb7 | 2013-02-15 15:07:32 +0000 | [diff] [blame] | 43 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 44 | s->AddRef(); |
| 45 | return s; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | } |
| 47 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 48 | VoEBaseImpl::VoEBaseImpl(voe::SharedData* shared) : |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | _voiceEngineObserverPtr(NULL), |
| 50 | _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()), |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 51 | _voiceEngineObserver(false), _oldVoEMicLevel(0), _oldMicLevel(0), |
| 52 | _shared(shared) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 54 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | "VoEBaseImpl() - ctor"); |
| 56 | } |
| 57 | |
| 58 | VoEBaseImpl::~VoEBaseImpl() |
| 59 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 60 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | "~VoEBaseImpl() - dtor"); |
| 62 | |
| 63 | TerminateInternal(); |
| 64 | |
| 65 | delete &_callbackCritSect; |
| 66 | } |
| 67 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | void VoEBaseImpl::OnErrorIsReported(const ErrorCode error) |
| 69 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 70 | CriticalSectionScoped cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | if (_voiceEngineObserver) |
| 72 | { |
| 73 | if (_voiceEngineObserverPtr) |
| 74 | { |
| 75 | int errCode(0); |
| 76 | if (error == AudioDeviceObserver::kRecordingError) |
| 77 | { |
| 78 | errCode = VE_RUNTIME_REC_ERROR; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 79 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, |
| 80 | VoEId(_shared->instance_id(), -1), |
| 81 | "VoEBaseImpl::OnErrorIsReported() => VE_RUNTIME_REC_ERROR"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | } |
| 83 | else if (error == AudioDeviceObserver::kPlayoutError) |
| 84 | { |
| 85 | errCode = VE_RUNTIME_PLAY_ERROR; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 86 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, |
| 87 | VoEId(_shared->instance_id(), -1), |
| 88 | "VoEBaseImpl::OnErrorIsReported() => " |
| 89 | "VE_RUNTIME_PLAY_ERROR"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | } |
| 91 | // Deliver callback (-1 <=> no channel dependency) |
| 92 | _voiceEngineObserverPtr->CallbackOnError(-1, errCode); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void VoEBaseImpl::OnWarningIsReported(const WarningCode warning) |
| 98 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 99 | CriticalSectionScoped cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | if (_voiceEngineObserver) |
| 101 | { |
| 102 | if (_voiceEngineObserverPtr) |
| 103 | { |
| 104 | int warningCode(0); |
| 105 | if (warning == AudioDeviceObserver::kRecordingWarning) |
| 106 | { |
| 107 | warningCode = VE_RUNTIME_REC_WARNING; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 108 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, |
| 109 | VoEId(_shared->instance_id(), -1), |
| 110 | "VoEBaseImpl::OnErrorIsReported() => " |
| 111 | "VE_RUNTIME_REC_WARNING"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 112 | } |
| 113 | else if (warning == AudioDeviceObserver::kPlayoutWarning) |
| 114 | { |
| 115 | warningCode = VE_RUNTIME_PLAY_WARNING; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 116 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, |
| 117 | VoEId(_shared->instance_id(), -1), |
| 118 | "VoEBaseImpl::OnErrorIsReported() => " |
| 119 | "VE_RUNTIME_PLAY_WARNING"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | } |
| 121 | // Deliver callback (-1 <=> no channel dependency) |
| 122 | _voiceEngineObserverPtr->CallbackOnError(-1, warningCode); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | WebRtc_Word32 VoEBaseImpl::RecordedDataIsAvailable( |
henrika@webrtc.org | 907bc55 | 2012-03-09 08:59:19 +0000 | [diff] [blame] | 128 | const void* audioSamples, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | const WebRtc_UWord32 nSamples, |
| 130 | const WebRtc_UWord8 nBytesPerSample, |
| 131 | const WebRtc_UWord8 nChannels, |
| 132 | const WebRtc_UWord32 samplesPerSec, |
| 133 | const WebRtc_UWord32 totalDelayMS, |
| 134 | const WebRtc_Word32 clockDrift, |
| 135 | const WebRtc_UWord32 currentMicLevel, |
| 136 | WebRtc_UWord32& newMicLevel) |
| 137 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 138 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 139 | "VoEBaseImpl::RecordedDataIsAvailable(nSamples=%u, " |
| 140 | "nBytesPerSample=%u, nChannels=%u, samplesPerSec=%u, " |
| 141 | "totalDelayMS=%u, clockDrift=%d, currentMicLevel=%u)", |
| 142 | nSamples, nBytesPerSample, nChannels, samplesPerSec, |
| 143 | totalDelayMS, clockDrift, currentMicLevel); |
| 144 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 145 | assert(_shared->transmit_mixer() != NULL); |
| 146 | assert(_shared->audio_device() != NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 147 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 148 | bool isAnalogAGC(false); |
| 149 | WebRtc_UWord32 maxVolume(0); |
| 150 | WebRtc_UWord16 currentVoEMicLevel(0); |
| 151 | WebRtc_UWord32 newVoEMicLevel(0); |
| 152 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 153 | if (_shared->audio_processing() && |
| 154 | (_shared->audio_processing()->gain_control()->mode() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 155 | == GainControl::kAdaptiveAnalog)) |
| 156 | { |
| 157 | isAnalogAGC = true; |
| 158 | } |
| 159 | |
| 160 | // Will only deal with the volume in adaptive analog mode |
| 161 | if (isAnalogAGC) |
| 162 | { |
| 163 | // Scale from ADM to VoE level range |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 164 | if (_shared->audio_device()->MaxMicrophoneVolume(&maxVolume) == 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 165 | { |
| 166 | if (0 != maxVolume) |
| 167 | { |
| 168 | currentVoEMicLevel = (WebRtc_UWord16) ((currentMicLevel |
| 169 | * kMaxVolumeLevel + (int) (maxVolume / 2)) |
| 170 | / (maxVolume)); |
| 171 | } |
| 172 | } |
punyabrata@webrtc.org | 6b6d081 | 2011-09-28 17:45:03 +0000 | [diff] [blame] | 173 | // We learned that on certain systems (e.g Linux) the currentVoEMicLevel |
| 174 | // can be greater than the maxVolumeLevel therefore |
| 175 | // we are going to cap the currentVoEMicLevel to the maxVolumeLevel |
xians@webrtc.org | 3ab6dda | 2012-02-16 18:15:54 +0000 | [diff] [blame] | 176 | // and change the maxVolume to currentMicLevel if it turns out that |
| 177 | // the currentVoEMicLevel is indeed greater than the maxVolumeLevel. |
punyabrata@webrtc.org | 6b6d081 | 2011-09-28 17:45:03 +0000 | [diff] [blame] | 178 | if (currentVoEMicLevel > kMaxVolumeLevel) |
| 179 | { |
| 180 | currentVoEMicLevel = kMaxVolumeLevel; |
xians@webrtc.org | 3ab6dda | 2012-02-16 18:15:54 +0000 | [diff] [blame] | 181 | maxVolume = currentMicLevel; |
punyabrata@webrtc.org | 6b6d081 | 2011-09-28 17:45:03 +0000 | [diff] [blame] | 182 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | // Keep track if the MicLevel has been changed by the AGC, if not, |
| 186 | // use the old value AGC returns to let AGC continue its trend, |
| 187 | // so eventually the AGC is able to change the mic level. This handles |
| 188 | // issues with truncation introduced by the scaling. |
| 189 | if (_oldMicLevel == currentMicLevel) |
| 190 | { |
| 191 | currentVoEMicLevel = (WebRtc_UWord16) _oldVoEMicLevel; |
| 192 | } |
| 193 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 194 | // Perform channel-independent operations |
| 195 | // (APM, mix with file, record to file, mute, etc.) |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 196 | _shared->transmit_mixer()->PrepareDemux(audioSamples, nSamples, nChannels, |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 197 | samplesPerSec, static_cast<WebRtc_UWord16>(totalDelayMS), clockDrift, |
| 198 | currentVoEMicLevel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 199 | |
| 200 | // Copy the audio frame to each sending channel and perform |
| 201 | // channel-dependent operations (file mixing, mute, etc.) to prepare |
| 202 | // for encoding. |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 203 | _shared->transmit_mixer()->DemuxAndMix(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 204 | // Do the encoding and packetize+transmit the RTP packet when encoding |
| 205 | // is done. |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 206 | _shared->transmit_mixer()->EncodeAndSend(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | |
| 208 | // Will only deal with the volume in adaptive analog mode |
| 209 | if (isAnalogAGC) |
| 210 | { |
| 211 | // Scale from VoE to ADM level range |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 212 | newVoEMicLevel = _shared->transmit_mixer()->CaptureLevel(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 213 | if (newVoEMicLevel != currentVoEMicLevel) |
| 214 | { |
| 215 | // Add (kMaxVolumeLevel/2) to round the value |
| 216 | newMicLevel = (WebRtc_UWord32) ((newVoEMicLevel * maxVolume |
| 217 | + (int) (kMaxVolumeLevel / 2)) / (kMaxVolumeLevel)); |
| 218 | } |
| 219 | else |
| 220 | { |
| 221 | // Pass zero if the level is unchanged |
| 222 | newMicLevel = 0; |
| 223 | } |
| 224 | |
| 225 | // Keep track of the value AGC returns |
| 226 | _oldVoEMicLevel = newVoEMicLevel; |
| 227 | _oldMicLevel = currentMicLevel; |
| 228 | } |
| 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | WebRtc_Word32 VoEBaseImpl::NeedMorePlayData( |
| 234 | const WebRtc_UWord32 nSamples, |
| 235 | const WebRtc_UWord8 nBytesPerSample, |
| 236 | const WebRtc_UWord8 nChannels, |
| 237 | const WebRtc_UWord32 samplesPerSec, |
henrika@webrtc.org | 907bc55 | 2012-03-09 08:59:19 +0000 | [diff] [blame] | 238 | void* audioSamples, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 239 | WebRtc_UWord32& nSamplesOut) |
| 240 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 241 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 242 | "VoEBaseImpl::NeedMorePlayData(nSamples=%u, " |
| 243 | "nBytesPerSample=%d, nChannels=%d, samplesPerSec=%u)", |
| 244 | nSamples, nBytesPerSample, nChannels, samplesPerSec); |
| 245 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 246 | assert(_shared->output_mixer() != NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 247 | |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 248 | // TODO(andrew): if the device is running in mono, we should tell the mixer |
| 249 | // here so that it will only request mono from AudioCodingModule. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 250 | // Perform mixing of all active participants (channel-based mixing) |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 251 | _shared->output_mixer()->MixActiveChannels(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 252 | |
| 253 | // Additional operations on the combined signal |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 254 | _shared->output_mixer()->DoOperationsOnCombinedSignal(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 255 | |
| 256 | // Retrieve the final output mix (resampled to match the ADM) |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 257 | _shared->output_mixer()->GetMixedAudio(samplesPerSec, nChannels, |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 258 | &_audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 259 | |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 260 | assert(static_cast<int>(nSamples) == _audioFrame.samples_per_channel_); |
xians@google.com | 0b0665a | 2011-08-08 08:18:44 +0000 | [diff] [blame] | 261 | assert(samplesPerSec == |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 262 | static_cast<WebRtc_UWord32>(_audioFrame.sample_rate_hz_)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 263 | |
| 264 | // Deliver audio (PCM) samples to the ADM |
| 265 | memcpy( |
| 266 | (WebRtc_Word16*) audioSamples, |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 267 | (const WebRtc_Word16*) _audioFrame.data_, |
| 268 | sizeof(WebRtc_Word16) * (_audioFrame.samples_per_channel_ |
| 269 | * _audioFrame.num_channels_)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 270 | |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 271 | nSamplesOut = _audioFrame.samples_per_channel_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | int VoEBaseImpl::RegisterVoiceEngineObserver(VoiceEngineObserver& observer) |
| 277 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 278 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 279 | "RegisterVoiceEngineObserver(observer=0x%d)", &observer); |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 280 | CriticalSectionScoped cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 281 | if (_voiceEngineObserverPtr) |
| 282 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 283 | _shared->SetLastError(VE_INVALID_OPERATION, kTraceError, |
| 284 | "RegisterVoiceEngineObserver() observer already enabled"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 285 | return -1; |
| 286 | } |
| 287 | |
| 288 | // Register the observer in all active channels |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 289 | voe::ScopedChannel sc(_shared->channel_manager()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 290 | void* iterator(NULL); |
| 291 | voe::Channel* channelPtr = sc.GetFirstChannel(iterator); |
| 292 | while (channelPtr != NULL) |
| 293 | { |
| 294 | channelPtr->RegisterVoiceEngineObserver(observer); |
| 295 | channelPtr = sc.GetNextChannel(iterator); |
| 296 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 297 | _shared->transmit_mixer()->RegisterVoiceEngineObserver(observer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 298 | |
| 299 | _voiceEngineObserverPtr = &observer; |
| 300 | _voiceEngineObserver = true; |
| 301 | |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | int VoEBaseImpl::DeRegisterVoiceEngineObserver() |
| 306 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 307 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 308 | "DeRegisterVoiceEngineObserver()"); |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 309 | CriticalSectionScoped cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 310 | if (!_voiceEngineObserverPtr) |
| 311 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 312 | _shared->SetLastError(VE_INVALID_OPERATION, kTraceError, |
andrew@webrtc.org | f458916 | 2011-10-03 15:22:28 +0000 | [diff] [blame] | 313 | "DeRegisterVoiceEngineObserver() observer already disabled"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | _voiceEngineObserver = false; |
| 318 | _voiceEngineObserverPtr = NULL; |
| 319 | |
| 320 | // Deregister the observer in all active channels |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 321 | voe::ScopedChannel sc(_shared->channel_manager()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 322 | void* iterator(NULL); |
| 323 | voe::Channel* channelPtr = sc.GetFirstChannel(iterator); |
| 324 | while (channelPtr != NULL) |
| 325 | { |
| 326 | channelPtr->DeRegisterVoiceEngineObserver(); |
| 327 | channelPtr = sc.GetNextChannel(iterator); |
| 328 | } |
| 329 | |
| 330 | return 0; |
| 331 | } |
| 332 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame^] | 333 | int VoEBaseImpl::Init(AudioDeviceModule* external_adm, |
| 334 | AudioProcessing* audioproc) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 335 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 336 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 337 | "Init(external_adm=0x%p)", external_adm); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 338 | CriticalSectionScoped cs(_shared->crit_sec()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 339 | |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 340 | WebRtcSpl_Init(); |
| 341 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 342 | if (_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 343 | { |
| 344 | return 0; |
| 345 | } |
| 346 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 347 | if (_shared->process_thread()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 348 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 349 | if (_shared->process_thread()->Start() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 350 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 351 | _shared->SetLastError(VE_THREAD_ERROR, kTraceError, |
andrew@webrtc.org | f458916 | 2011-10-03 15:22:28 +0000 | [diff] [blame] | 352 | "Init() failed to start module process thread"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 353 | return -1; |
| 354 | } |
| 355 | } |
| 356 | |
andrew@webrtc.org | 3192d65 | 2011-12-21 18:00:59 +0000 | [diff] [blame] | 357 | // Create an internal ADM if the user has not added an external |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 358 | // ADM implementation as input to Init(). |
| 359 | if (external_adm == NULL) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 360 | { |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 361 | // Create the internal ADM implementation. |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 362 | _shared->set_audio_device(AudioDeviceModuleImpl::Create( |
| 363 | VoEId(_shared->instance_id(), -1), _shared->audio_device_layer())); |
andrew@webrtc.org | f458916 | 2011-10-03 15:22:28 +0000 | [diff] [blame] | 364 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 365 | if (_shared->audio_device() == NULL) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 366 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 367 | _shared->SetLastError(VE_NO_MEMORY, kTraceCritical, |
| 368 | "Init() failed to create the ADM"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 369 | return -1; |
| 370 | } |
| 371 | } |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 372 | else |
| 373 | { |
| 374 | // Use the already existing external ADM implementation. |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 375 | _shared->set_audio_device(external_adm); |
| 376 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 377 | "An external ADM implementation will be used in VoiceEngine"); |
| 378 | } |
| 379 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 380 | // Register the ADM to the process thread, which will drive the error |
| 381 | // callback mechanism |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 382 | if (_shared->process_thread() && |
| 383 | _shared->process_thread()->RegisterModule(_shared->audio_device()) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 384 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 385 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
| 386 | "Init() failed to register the ADM"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 387 | return -1; |
| 388 | } |
| 389 | |
| 390 | bool available(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 391 | |
| 392 | // -------------------- |
| 393 | // Reinitialize the ADM |
| 394 | |
| 395 | // Register the AudioObserver implementation |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 396 | if (_shared->audio_device()->RegisterEventObserver(this) != 0) { |
| 397 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, |
| 398 | "Init() failed to register event observer for the ADM"); |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +0000 | [diff] [blame] | 399 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 400 | |
| 401 | // Register the AudioTransport implementation |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 402 | if (_shared->audio_device()->RegisterAudioCallback(this) != 0) { |
| 403 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, |
| 404 | "Init() failed to register audio callback for the ADM"); |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +0000 | [diff] [blame] | 405 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 406 | |
| 407 | // ADM initialization |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 408 | if (_shared->audio_device()->Init() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 409 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 410 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
| 411 | "Init() failed to initialize the ADM"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 412 | return -1; |
| 413 | } |
| 414 | |
| 415 | // Initialize the default speaker |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 416 | if (_shared->audio_device()->SetPlayoutDevice( |
| 417 | WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 418 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 419 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceInfo, |
andrew@webrtc.org | f458916 | 2011-10-03 15:22:28 +0000 | [diff] [blame] | 420 | "Init() failed to set the default output device"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 421 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 422 | if (_shared->audio_device()->SpeakerIsAvailable(&available) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 423 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 424 | _shared->SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, kTraceInfo, |
andrew@webrtc.org | f458916 | 2011-10-03 15:22:28 +0000 | [diff] [blame] | 425 | "Init() failed to check speaker availability, trying to " |
| 426 | "initialize speaker anyway"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 427 | } |
| 428 | else if (!available) |
| 429 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 430 | _shared->SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, kTraceInfo, |
andrew@webrtc.org | f458916 | 2011-10-03 15:22:28 +0000 | [diff] [blame] | 431 | "Init() speaker not available, trying to initialize speaker " |
| 432 | "anyway"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 433 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 434 | if (_shared->audio_device()->InitSpeaker() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 435 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 436 | _shared->SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, kTraceInfo, |
andrew@webrtc.org | f458916 | 2011-10-03 15:22:28 +0000 | [diff] [blame] | 437 | "Init() failed to initialize the speaker"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | // Initialize the default microphone |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 441 | if (_shared->audio_device()->SetRecordingDevice( |
| 442 | WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 443 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 444 | _shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceInfo, |
andrew@webrtc.org | f458916 | 2011-10-03 15:22:28 +0000 | [diff] [blame] | 445 | "Init() failed to set the default input device"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 446 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 447 | if (_shared->audio_device()->MicrophoneIsAvailable(&available) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 448 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 449 | _shared->SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceInfo, |
andrew@webrtc.org | f458916 | 2011-10-03 15:22:28 +0000 | [diff] [blame] | 450 | "Init() failed to check microphone availability, trying to " |
| 451 | "initialize microphone anyway"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 452 | } |
| 453 | else if (!available) |
| 454 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 455 | _shared->SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceInfo, |
andrew@webrtc.org | f458916 | 2011-10-03 15:22:28 +0000 | [diff] [blame] | 456 | "Init() microphone not available, trying to initialize " |
| 457 | "microphone anyway"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 458 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 459 | if (_shared->audio_device()->InitMicrophone() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 460 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 461 | _shared->SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceInfo, |
andrew@webrtc.org | f458916 | 2011-10-03 15:22:28 +0000 | [diff] [blame] | 462 | "Init() failed to initialize the microphone"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 463 | } |
| 464 | |
niklas.enbom@webrtc.org | e33a102 | 2011-11-16 10:33:53 +0000 | [diff] [blame] | 465 | // Set number of channels |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 466 | if (_shared->audio_device()->StereoPlayoutIsAvailable(&available) != 0) { |
| 467 | _shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, |
| 468 | "Init() failed to query stereo playout mode"); |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +0000 | [diff] [blame] | 469 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 470 | if (_shared->audio_device()->SetStereoPlayout(available) != 0) |
niklas.enbom@webrtc.org | e33a102 | 2011-11-16 10:33:53 +0000 | [diff] [blame] | 471 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 472 | _shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, |
niklas.enbom@webrtc.org | e33a102 | 2011-11-16 10:33:53 +0000 | [diff] [blame] | 473 | "Init() failed to set mono/stereo playout mode"); |
| 474 | } |
andrew@webrtc.org | 3192d65 | 2011-12-21 18:00:59 +0000 | [diff] [blame] | 475 | |
| 476 | // TODO(andrew): These functions don't tell us whether stereo recording |
| 477 | // is truly available. We simply set the AudioProcessing input to stereo |
| 478 | // here, because we have to wait until receiving the first frame to |
| 479 | // determine the actual number of channels anyway. |
| 480 | // |
| 481 | // These functions may be changed; tracked here: |
| 482 | // http://code.google.com/p/webrtc/issues/detail?id=204 |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 483 | _shared->audio_device()->StereoRecordingIsAvailable(&available); |
| 484 | if (_shared->audio_device()->SetStereoRecording(available) != 0) |
niklas.enbom@webrtc.org | e33a102 | 2011-11-16 10:33:53 +0000 | [diff] [blame] | 485 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 486 | _shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, |
niklas.enbom@webrtc.org | e33a102 | 2011-11-16 10:33:53 +0000 | [diff] [blame] | 487 | "Init() failed to set mono/stereo recording mode"); |
| 488 | } |
niklas.enbom@webrtc.org | e33a102 | 2011-11-16 10:33:53 +0000 | [diff] [blame] | 489 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame^] | 490 | if (!audioproc) { |
| 491 | audioproc = AudioProcessing::Create(VoEId(_shared->instance_id(), -1)); |
| 492 | if (!audioproc) { |
| 493 | LOG(LS_ERROR) << "Failed to create AudioProcessing."; |
| 494 | _shared->SetLastError(VE_NO_MEMORY); |
| 495 | return -1; |
| 496 | } |
| 497 | } |
| 498 | _shared->set_audio_processing(audioproc); |
niklas.enbom@webrtc.org | e33a102 | 2011-11-16 10:33:53 +0000 | [diff] [blame] | 499 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame^] | 500 | // Set the error state for any failures in this block. |
| 501 | _shared->SetLastError(VE_APM_ERROR); |
| 502 | if (audioproc->echo_cancellation()->set_device_sample_rate_hz(48000)) { |
| 503 | LOG_FERR1(LS_ERROR, set_device_sample_rate_hz, 48000); |
| 504 | return -1; |
| 505 | } |
| 506 | // Assume 16 kHz mono until the audio frames are received from the capture |
| 507 | // device, at which point this can be updated. |
| 508 | if (audioproc->set_sample_rate_hz(16000)) { |
| 509 | LOG_FERR1(LS_ERROR, set_sample_rate_hz, 16000); |
| 510 | return -1; |
| 511 | } |
| 512 | if (audioproc->set_num_channels(1, 1) != 0) { |
| 513 | LOG_FERR2(LS_ERROR, set_num_channels, 1, 1); |
| 514 | return -1; |
| 515 | } |
| 516 | if (audioproc->set_num_reverse_channels(1) != 0) { |
| 517 | LOG_FERR1(LS_ERROR, set_num_reverse_channels, 1); |
| 518 | return -1; |
niklas.enbom@webrtc.org | e33a102 | 2011-11-16 10:33:53 +0000 | [diff] [blame] | 519 | } |
| 520 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame^] | 521 | // Configure AudioProcessing components. All are disabled by default. |
| 522 | if (audioproc->high_pass_filter()->Enable(true) != 0) { |
| 523 | LOG_FERR1(LS_ERROR, high_pass_filter()->Enable, true); |
| 524 | return -1; |
| 525 | } |
| 526 | if (audioproc->echo_cancellation()->enable_drift_compensation(false) != 0) { |
| 527 | LOG_FERR1(LS_ERROR, enable_drift_compensation, false); |
| 528 | return -1; |
| 529 | } |
| 530 | if (audioproc->noise_suppression()->set_level(kDefaultNsMode) != 0) { |
| 531 | LOG_FERR1(LS_ERROR, noise_suppression()->set_level, kDefaultNsMode); |
| 532 | return -1; |
| 533 | } |
| 534 | GainControl* agc = audioproc->gain_control(); |
| 535 | if (agc->set_analog_level_limits(kMinVolumeLevel, kMaxVolumeLevel) != 0) { |
| 536 | LOG_FERR2(LS_ERROR, agc->set_analog_level_limits, kMinVolumeLevel, |
| 537 | kMaxVolumeLevel); |
| 538 | return -1; |
| 539 | } |
| 540 | if (agc->set_mode(kDefaultAgcMode) != 0) { |
| 541 | LOG_FERR1(LS_ERROR, agc->set_mode, kDefaultAgcMode); |
| 542 | return -1; |
| 543 | } |
| 544 | if (agc->Enable(kDefaultAgcState) != 0) { |
| 545 | LOG_FERR1(LS_ERROR, agc->Enable, kDefaultAgcState); |
| 546 | return -1; |
| 547 | } |
| 548 | _shared->SetLastError(0); // Clear error state. |
| 549 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 550 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame^] | 551 | bool agc_enabled = agc->mode() == GainControl::kAdaptiveAnalog && |
| 552 | agc->is_enabled(); |
| 553 | if (_shared->audio_device()->SetAGC(agc_enabled) != 0) { |
| 554 | LOG_FERR1(LS_ERROR, audio_device()->SetAGC, agc_enabled); |
| 555 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR); |
| 556 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 557 | } |
| 558 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 559 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 560 | return _shared->statistics().SetInitialized(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | int VoEBaseImpl::Terminate() |
| 564 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 565 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 566 | "Terminate()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 567 | CriticalSectionScoped cs(_shared->crit_sec()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 568 | return TerminateInternal(); |
| 569 | } |
| 570 | |
| 571 | int VoEBaseImpl::MaxNumOfChannels() |
| 572 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 573 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 574 | "MaxNumOfChannels()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 575 | WebRtc_Word32 maxNumOfChannels = |
| 576 | _shared->channel_manager().MaxNumOfChannels(); |
| 577 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 578 | VoEId(_shared->instance_id(), -1), |
| 579 | "MaxNumOfChannels() => %d", maxNumOfChannels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 580 | return (maxNumOfChannels); |
| 581 | } |
| 582 | |
| 583 | int VoEBaseImpl::CreateChannel() |
| 584 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 585 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 586 | "CreateChannel()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 587 | CriticalSectionScoped cs(_shared->crit_sec()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 588 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 589 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 590 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 591 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 592 | return -1; |
| 593 | } |
| 594 | |
| 595 | WebRtc_Word32 channelId = -1; |
| 596 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 597 | if (!_shared->channel_manager().CreateChannel(channelId)) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 598 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 599 | _shared->SetLastError(VE_CHANNEL_NOT_CREATED, kTraceError, |
| 600 | "CreateChannel() failed to allocate memory for channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 601 | return -1; |
| 602 | } |
| 603 | |
| 604 | bool destroyChannel(false); |
| 605 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 606 | voe::ScopedChannel sc(_shared->channel_manager(), channelId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 607 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 608 | if (channelPtr == NULL) |
| 609 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 610 | _shared->SetLastError(VE_CHANNEL_NOT_CREATED, kTraceError, |
| 611 | "CreateChannel() failed to allocate memory for channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 612 | return -1; |
| 613 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 614 | else if (channelPtr->SetEngineInformation(_shared->statistics(), |
| 615 | *_shared->output_mixer(), |
| 616 | *_shared->transmit_mixer(), |
| 617 | *_shared->process_thread(), |
| 618 | *_shared->audio_device(), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 619 | _voiceEngineObserverPtr, |
| 620 | &_callbackCritSect) != 0) |
| 621 | { |
| 622 | destroyChannel = true; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 623 | _shared->SetLastError(VE_CHANNEL_NOT_CREATED, kTraceError, |
| 624 | "CreateChannel() failed to associate engine and channel." |
| 625 | " Destroying channel."); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 626 | } |
| 627 | else if (channelPtr->Init() != 0) |
| 628 | { |
| 629 | destroyChannel = true; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 630 | _shared->SetLastError(VE_CHANNEL_NOT_CREATED, kTraceError, |
| 631 | "CreateChannel() failed to initialize channel. Destroying" |
| 632 | " channel."); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | if (destroyChannel) |
| 636 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 637 | _shared->channel_manager().DestroyChannel(channelId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 638 | return -1; |
| 639 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 640 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 641 | VoEId(_shared->instance_id(), -1), |
| 642 | "CreateChannel() => %d", channelId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 643 | return channelId; |
| 644 | } |
| 645 | |
| 646 | int VoEBaseImpl::DeleteChannel(int channel) |
| 647 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 648 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 649 | "DeleteChannel(channel=%d)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 650 | CriticalSectionScoped cs(_shared->crit_sec()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 651 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 652 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 653 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 654 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 655 | return -1; |
| 656 | } |
| 657 | |
| 658 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 659 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 660 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 661 | if (channelPtr == NULL) |
| 662 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 663 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 664 | "DeleteChannel() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 665 | return -1; |
| 666 | } |
| 667 | } |
| 668 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 669 | if (_shared->channel_manager().DestroyChannel(channel) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 670 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 671 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 672 | "DeleteChannel() failed to destroy channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 673 | return -1; |
| 674 | } |
| 675 | |
| 676 | if (StopSend() != 0) |
| 677 | { |
| 678 | return -1; |
| 679 | } |
| 680 | |
| 681 | if (StopPlayout() != 0) |
| 682 | { |
| 683 | return -1; |
| 684 | } |
| 685 | |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | int VoEBaseImpl::SetLocalReceiver(int channel, int port, int RTCPport, |
| 690 | const char ipAddr[64], |
| 691 | const char multiCastAddr[64]) |
| 692 | { |
| 693 | // Inititialize local receive sockets (RTP and RTCP). |
| 694 | // |
| 695 | // The sockets are always first closed and then created again by this |
| 696 | // function call. The created sockets are by default also used for |
| 697 | // transmission (unless source port is set in SetSendDestination). |
| 698 | // |
| 699 | // Note that, sockets can also be created automatically if a user calls |
| 700 | // SetSendDestination and StartSend without having called SetLocalReceiver |
| 701 | // first. The sockets are then created at the first packet transmission. |
| 702 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 703 | CriticalSectionScoped cs(_shared->crit_sec()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 704 | if (ipAddr == NULL && multiCastAddr == NULL) |
| 705 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 706 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, |
| 707 | VoEId(_shared->instance_id(), -1), |
| 708 | "SetLocalReceiver(channel=%d, port=%d, RTCPport=%d)", |
| 709 | channel, port, RTCPport); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 710 | } |
| 711 | else if (ipAddr != NULL && multiCastAddr == NULL) |
| 712 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 713 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, |
| 714 | VoEId(_shared->instance_id(), -1), |
| 715 | "SetLocalReceiver(channel=%d, port=%d, RTCPport=%d, ipAddr=%s)", |
| 716 | channel, port, RTCPport, ipAddr); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 717 | } |
| 718 | else if (ipAddr == NULL && multiCastAddr != NULL) |
| 719 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 720 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, |
| 721 | VoEId(_shared->instance_id(), -1), |
| 722 | "SetLocalReceiver(channel=%d, port=%d, RTCPport=%d, " |
| 723 | "multiCastAddr=%s)", channel, port, RTCPport, multiCastAddr); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 724 | } |
| 725 | else |
| 726 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 727 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, |
| 728 | VoEId(_shared->instance_id(), -1), |
| 729 | "SetLocalReceiver(channel=%d, port=%d, RTCPport=%d, " |
| 730 | "ipAddr=%s, multiCastAddr=%s)", channel, port, RTCPport, ipAddr, |
| 731 | multiCastAddr); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 732 | } |
| 733 | #ifndef WEBRTC_EXTERNAL_TRANSPORT |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 734 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 735 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 736 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 737 | return -1; |
| 738 | } |
| 739 | if ((port < 0) || (port > 65535)) |
| 740 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 741 | _shared->SetLastError(VE_INVALID_PORT_NMBR, kTraceError, |
| 742 | "SetLocalReceiver() invalid RTP port"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 743 | return -1; |
| 744 | } |
| 745 | if (((RTCPport != kVoEDefault) && (RTCPport < 0)) || ((RTCPport |
| 746 | != kVoEDefault) && (RTCPport > 65535))) |
| 747 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 748 | _shared->SetLastError(VE_INVALID_PORT_NMBR, kTraceError, |
| 749 | "SetLocalReceiver() invalid RTCP port"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 750 | return -1; |
| 751 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 752 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 753 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 754 | if (channelPtr == NULL) |
| 755 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 756 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 757 | "SetLocalReceiver() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 758 | return -1; |
| 759 | } |
| 760 | |
| 761 | // Cast RTCP port. In the RTP module 0 corresponds to RTP port + 1 in |
| 762 | // the module, which is the default. |
| 763 | WebRtc_UWord16 rtcpPortUW16(0); |
| 764 | if (RTCPport != kVoEDefault) |
| 765 | { |
| 766 | rtcpPortUW16 = static_cast<WebRtc_UWord16> (RTCPport); |
| 767 | } |
| 768 | |
| 769 | return channelPtr->SetLocalReceiver(port, rtcpPortUW16, ipAddr, |
| 770 | multiCastAddr); |
| 771 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 772 | _shared->SetLastError(VE_EXTERNAL_TRANSPORT_ENABLED, |
| 773 | kTraceWarning, "SetLocalReceiver() VoE is built for external " |
| 774 | "transport"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 775 | return -1; |
| 776 | #endif |
| 777 | } |
| 778 | |
| 779 | int VoEBaseImpl::GetLocalReceiver(int channel, int& port, int& RTCPport, |
| 780 | char ipAddr[64]) |
| 781 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 782 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 783 | "GetLocalReceiver(channel=%d, ipAddr[]=?)", channel); |
| 784 | #ifndef WEBRTC_EXTERNAL_TRANSPORT |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 785 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 786 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 787 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 788 | return -1; |
| 789 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 790 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 791 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 792 | if (channelPtr == NULL) |
| 793 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 794 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 795 | "SetLocalReceiver() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 796 | return -1; |
| 797 | } |
| 798 | WebRtc_Word32 ret = channelPtr->GetLocalReceiver(port, RTCPport, ipAddr); |
| 799 | if (ipAddr != NULL) |
| 800 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 801 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 802 | VoEId(_shared->instance_id(), -1), |
| 803 | "GetLocalReceiver() => port=%d, RTCPport=%d, ipAddr=%s", |
| 804 | port, RTCPport, ipAddr); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 805 | } |
| 806 | else |
| 807 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 808 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 809 | VoEId(_shared->instance_id(), -1), |
| 810 | "GetLocalReceiver() => port=%d, RTCPport=%d", port, RTCPport); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 811 | } |
| 812 | return ret; |
| 813 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 814 | _shared->SetLastError(VE_EXTERNAL_TRANSPORT_ENABLED, kTraceWarning, |
| 815 | "SetLocalReceiver() VoE is built for external transport"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 816 | return -1; |
| 817 | #endif |
| 818 | } |
| 819 | |
| 820 | int VoEBaseImpl::SetSendDestination(int channel, int port, const char* ipaddr, |
| 821 | int sourcePort, int RTCPport) |
| 822 | { |
| 823 | WEBRTC_TRACE( |
| 824 | kTraceApiCall, |
| 825 | kTraceVoice, |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 826 | VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 827 | "SetSendDestination(channel=%d, port=%d, ipaddr=%s," |
| 828 | "sourcePort=%d, RTCPport=%d)", |
| 829 | channel, port, ipaddr, sourcePort, RTCPport); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 830 | CriticalSectionScoped cs(_shared->crit_sec()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 831 | #ifndef WEBRTC_EXTERNAL_TRANSPORT |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 832 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 833 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 834 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 835 | return -1; |
| 836 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 837 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 838 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 839 | if (channelPtr == NULL) |
| 840 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 841 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 842 | "SetSendDestination() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 843 | return -1; |
| 844 | } |
| 845 | if ((port < 0) || (port > 65535)) |
| 846 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 847 | _shared->SetLastError(VE_INVALID_PORT_NMBR, kTraceError, |
| 848 | "SetSendDestination() invalid RTP port"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 849 | return -1; |
| 850 | } |
| 851 | if (((RTCPport != kVoEDefault) && (RTCPport < 0)) || ((RTCPport |
| 852 | != kVoEDefault) && (RTCPport > 65535))) |
| 853 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 854 | _shared->SetLastError(VE_INVALID_PORT_NMBR, kTraceError, |
| 855 | "SetSendDestination() invalid RTCP port"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 856 | return -1; |
| 857 | } |
| 858 | if (((sourcePort != kVoEDefault) && (sourcePort < 0)) || ((sourcePort |
| 859 | != kVoEDefault) && (sourcePort > 65535))) |
| 860 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 861 | _shared->SetLastError(VE_INVALID_PORT_NMBR, kTraceError, |
| 862 | "SetSendDestination() invalid source port"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 863 | return -1; |
| 864 | } |
| 865 | |
| 866 | // Cast RTCP port. In the RTP module 0 corresponds to RTP port + 1 in the |
| 867 | // module, which is the default. |
| 868 | WebRtc_UWord16 rtcpPortUW16(0); |
| 869 | if (RTCPport != kVoEDefault) |
| 870 | { |
| 871 | rtcpPortUW16 = static_cast<WebRtc_UWord16> (RTCPport); |
| 872 | WEBRTC_TRACE( |
| 873 | kTraceInfo, |
| 874 | kTraceVoice, |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 875 | VoEId(_shared->instance_id(), channel), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 876 | "SetSendDestination() non default RTCP port %u will be " |
| 877 | "utilized", |
| 878 | rtcpPortUW16); |
| 879 | } |
| 880 | |
| 881 | return channelPtr->SetSendDestination(port, ipaddr, sourcePort, |
| 882 | rtcpPortUW16); |
| 883 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 884 | _shared->SetLastError(VE_EXTERNAL_TRANSPORT_ENABLED, kTraceWarning, |
| 885 | "SetSendDestination() VoE is built for external transport"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 886 | return -1; |
| 887 | #endif |
| 888 | } |
| 889 | |
| 890 | int VoEBaseImpl::GetSendDestination(int channel, int& port, char ipAddr[64], |
| 891 | int& sourcePort, int& RTCPport) |
| 892 | { |
| 893 | WEBRTC_TRACE( |
| 894 | kTraceApiCall, |
| 895 | kTraceVoice, |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 896 | VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 897 | "GetSendDestination(channel=%d, ipAddr[]=?, sourcePort=?," |
| 898 | "RTCPport=?)", |
| 899 | channel); |
| 900 | #ifndef WEBRTC_EXTERNAL_TRANSPORT |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 901 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 902 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 903 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 904 | return -1; |
| 905 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 906 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 907 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 908 | if (channelPtr == NULL) |
| 909 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 910 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 911 | "GetSendDestination() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 912 | return -1; |
| 913 | } |
| 914 | WebRtc_Word32 ret = channelPtr->GetSendDestination(port, ipAddr, |
| 915 | sourcePort, RTCPport); |
| 916 | if (ipAddr != NULL) |
| 917 | { |
| 918 | WEBRTC_TRACE( |
| 919 | kTraceStateInfo, |
| 920 | kTraceVoice, |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 921 | VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 922 | "GetSendDestination() => port=%d, RTCPport=%d, ipAddr=%s, " |
| 923 | "sourcePort=%d, RTCPport=%d", |
| 924 | port, RTCPport, ipAddr, sourcePort, RTCPport); |
| 925 | } |
| 926 | else |
| 927 | { |
| 928 | WEBRTC_TRACE( |
| 929 | kTraceStateInfo, |
| 930 | kTraceVoice, |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 931 | VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 932 | "GetSendDestination() => port=%d, RTCPport=%d, " |
| 933 | "sourcePort=%d, RTCPport=%d", |
| 934 | port, RTCPport, sourcePort, RTCPport); |
| 935 | } |
| 936 | return ret; |
| 937 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 938 | _shared->SetLastError(VE_EXTERNAL_TRANSPORT_ENABLED, kTraceWarning, |
| 939 | "GetSendDestination() VoE is built for external transport"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 940 | return -1; |
| 941 | #endif |
| 942 | } |
| 943 | |
| 944 | int VoEBaseImpl::StartReceive(int channel) |
| 945 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 946 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 947 | "StartReceive(channel=%d)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 948 | CriticalSectionScoped cs(_shared->crit_sec()); |
| 949 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 950 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 951 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 952 | return -1; |
| 953 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 954 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 955 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 956 | if (channelPtr == NULL) |
| 957 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 958 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 959 | "StartReceive() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 960 | return -1; |
| 961 | } |
| 962 | return channelPtr->StartReceiving(); |
| 963 | } |
| 964 | |
| 965 | int VoEBaseImpl::StopReceive(int channel) |
| 966 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 967 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 968 | "StopListen(channel=%d)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 969 | CriticalSectionScoped cs(_shared->crit_sec()); |
| 970 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 971 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 972 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 973 | return -1; |
| 974 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 975 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 976 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 977 | if (channelPtr == NULL) |
| 978 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 979 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 980 | "SetLocalReceiver() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 981 | return -1; |
| 982 | } |
| 983 | return channelPtr->StopReceiving(); |
| 984 | } |
| 985 | |
| 986 | int VoEBaseImpl::StartPlayout(int channel) |
| 987 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 988 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 989 | "StartPlayout(channel=%d)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 990 | CriticalSectionScoped cs(_shared->crit_sec()); |
| 991 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 992 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 993 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 994 | return -1; |
| 995 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 996 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 997 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 998 | if (channelPtr == NULL) |
| 999 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1000 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 1001 | "StartPlayout() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1002 | return -1; |
| 1003 | } |
| 1004 | if (channelPtr->Playing()) |
| 1005 | { |
| 1006 | return 0; |
| 1007 | } |
| 1008 | if (StartPlayout() != 0) |
| 1009 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1010 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
| 1011 | "StartPlayout() failed to start playout"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1012 | return -1; |
| 1013 | } |
| 1014 | return channelPtr->StartPlayout(); |
| 1015 | } |
| 1016 | |
| 1017 | int VoEBaseImpl::StopPlayout(int channel) |
| 1018 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1019 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1020 | "StopPlayout(channel=%d)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1021 | CriticalSectionScoped cs(_shared->crit_sec()); |
| 1022 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1023 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1024 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1025 | return -1; |
| 1026 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1027 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1028 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 1029 | if (channelPtr == NULL) |
| 1030 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1031 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 1032 | "StopPlayout() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1033 | return -1; |
| 1034 | } |
| 1035 | if (channelPtr->StopPlayout() != 0) |
| 1036 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1037 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 1038 | VoEId(_shared->instance_id(), -1), |
| 1039 | "StopPlayout() failed to stop playout for channel %d", channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1040 | } |
| 1041 | return StopPlayout(); |
| 1042 | } |
| 1043 | |
| 1044 | int VoEBaseImpl::StartSend(int channel) |
| 1045 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1046 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1047 | "StartSend(channel=%d)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1048 | CriticalSectionScoped cs(_shared->crit_sec()); |
| 1049 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1050 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1051 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1052 | return -1; |
| 1053 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1054 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1055 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 1056 | if (channelPtr == NULL) |
| 1057 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1058 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 1059 | "StartSend() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1060 | return -1; |
| 1061 | } |
| 1062 | if (channelPtr->Sending()) |
| 1063 | { |
| 1064 | return 0; |
| 1065 | } |
| 1066 | #ifndef WEBRTC_EXTERNAL_TRANSPORT |
| 1067 | if (!channelPtr->ExternalTransport() |
| 1068 | && !channelPtr->SendSocketsInitialized()) |
| 1069 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1070 | _shared->SetLastError(VE_DESTINATION_NOT_INITED, kTraceError, |
| 1071 | "StartSend() must set send destination first"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1072 | return -1; |
| 1073 | } |
| 1074 | #endif |
| 1075 | if (StartSend() != 0) |
| 1076 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1077 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
| 1078 | "StartSend() failed to start recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1079 | return -1; |
| 1080 | } |
| 1081 | return channelPtr->StartSend(); |
| 1082 | } |
| 1083 | |
| 1084 | int VoEBaseImpl::StopSend(int channel) |
| 1085 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1086 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1087 | "StopSend(channel=%d)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1088 | CriticalSectionScoped cs(_shared->crit_sec()); |
| 1089 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1090 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1091 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1092 | return -1; |
| 1093 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1094 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1095 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 1096 | if (channelPtr == NULL) |
| 1097 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1098 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 1099 | "StopSend() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1100 | return -1; |
| 1101 | } |
| 1102 | if (channelPtr->StopSend() != 0) |
| 1103 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1104 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 1105 | VoEId(_shared->instance_id(), -1), |
| 1106 | "StopSend() failed to stop sending for channel %d", channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1107 | } |
| 1108 | return StopSend(); |
| 1109 | } |
| 1110 | |
| 1111 | int VoEBaseImpl::GetVersion(char version[1024]) |
| 1112 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1113 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1114 | "GetVersion(version=?)"); |
| 1115 | assert(kVoiceEngineVersionMaxMessageSize == 1024); |
| 1116 | |
| 1117 | if (version == NULL) |
| 1118 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1119 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1120 | return (-1); |
| 1121 | } |
| 1122 | |
| 1123 | char versionBuf[kVoiceEngineVersionMaxMessageSize]; |
| 1124 | char* versionPtr = versionBuf; |
| 1125 | |
| 1126 | WebRtc_Word32 len = 0; |
| 1127 | WebRtc_Word32 accLen = 0; |
| 1128 | |
| 1129 | len = AddVoEVersion(versionPtr); |
| 1130 | if (len == -1) |
| 1131 | { |
| 1132 | return -1; |
| 1133 | } |
| 1134 | versionPtr += len; |
| 1135 | accLen += len; |
| 1136 | assert(accLen < kVoiceEngineVersionMaxMessageSize); |
| 1137 | |
| 1138 | len = AddBuildInfo(versionPtr); |
| 1139 | if (len == -1) |
| 1140 | { |
| 1141 | return -1; |
| 1142 | } |
| 1143 | versionPtr += len; |
| 1144 | accLen += len; |
| 1145 | assert(accLen < kVoiceEngineVersionMaxMessageSize); |
| 1146 | |
| 1147 | #ifdef WEBRTC_EXTERNAL_TRANSPORT |
| 1148 | len = AddExternalTransportBuild(versionPtr); |
| 1149 | if (len == -1) |
| 1150 | { |
pwestin@webrtc.org | c450a19 | 2012-01-04 15:00:12 +0000 | [diff] [blame] | 1151 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1152 | } |
| 1153 | versionPtr += len; |
| 1154 | accLen += len; |
| 1155 | assert(accLen < kVoiceEngineVersionMaxMessageSize); |
| 1156 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1157 | #ifdef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT |
| 1158 | len = AddExternalRecAndPlayoutBuild(versionPtr); |
| 1159 | if (len == -1) |
| 1160 | { |
| 1161 | return -1; |
| 1162 | } |
| 1163 | versionPtr += len; |
| 1164 | accLen += len; |
| 1165 | assert(accLen < kVoiceEngineVersionMaxMessageSize); |
pwestin@webrtc.org | c450a19 | 2012-01-04 15:00:12 +0000 | [diff] [blame] | 1166 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1167 | |
| 1168 | memcpy(version, versionBuf, accLen); |
| 1169 | version[accLen] = '\0'; |
| 1170 | |
| 1171 | // to avoid the truncation in the trace, split the string into parts |
| 1172 | char partOfVersion[256]; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1173 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 1174 | VoEId(_shared->instance_id(), -1), "GetVersion() =>"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1175 | for (int partStart = 0; partStart < accLen;) |
| 1176 | { |
| 1177 | memset(partOfVersion, 0, sizeof(partOfVersion)); |
| 1178 | int partEnd = partStart + 180; |
| 1179 | while (version[partEnd] != '\n' && version[partEnd] != '\0') |
| 1180 | { |
| 1181 | partEnd--; |
| 1182 | } |
| 1183 | if (partEnd < accLen) |
| 1184 | { |
| 1185 | memcpy(partOfVersion, &version[partStart], partEnd - partStart); |
| 1186 | } |
| 1187 | else |
| 1188 | { |
| 1189 | memcpy(partOfVersion, &version[partStart], accLen - partStart); |
| 1190 | } |
| 1191 | partStart = partEnd; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1192 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 1193 | VoEId(_shared->instance_id(), -1), "%s", partOfVersion); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | WebRtc_Word32 VoEBaseImpl::AddBuildInfo(char* str) const |
| 1200 | { |
leozwang@webrtc.org | 48a5df6 | 2012-04-24 14:50:50 +0000 | [diff] [blame] | 1201 | return sprintf(str, "Build: svn:%s %s\n", WEBRTC_SVNREVISION, BUILDINFO); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | WebRtc_Word32 VoEBaseImpl::AddVoEVersion(char* str) const |
| 1205 | { |
| 1206 | return sprintf(str, "VoiceEngine 4.1.0\n"); |
| 1207 | } |
| 1208 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1209 | #ifdef WEBRTC_EXTERNAL_TRANSPORT |
| 1210 | WebRtc_Word32 VoEBaseImpl::AddExternalTransportBuild(char* str) const |
| 1211 | { |
| 1212 | return sprintf(str, "External transport build\n"); |
| 1213 | } |
| 1214 | #endif |
| 1215 | |
| 1216 | #ifdef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT |
| 1217 | WebRtc_Word32 VoEBaseImpl::AddExternalRecAndPlayoutBuild(char* str) const |
| 1218 | { |
| 1219 | return sprintf(str, "External recording and playout build\n"); |
| 1220 | } |
| 1221 | #endif |
| 1222 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1223 | int VoEBaseImpl::LastError() |
| 1224 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1225 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1226 | "LastError()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1227 | return (_shared->statistics().LastError()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | |
| 1231 | int VoEBaseImpl::SetNetEQPlayoutMode(int channel, NetEqModes mode) |
| 1232 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1233 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1234 | "SetNetEQPlayoutMode(channel=%i, mode=%i)", channel, mode); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1235 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1236 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1237 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1238 | return -1; |
| 1239 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1240 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1241 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 1242 | if (channelPtr == NULL) |
| 1243 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1244 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 1245 | "SetNetEQPlayoutMode() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1246 | return -1; |
| 1247 | } |
| 1248 | return channelPtr->SetNetEQPlayoutMode(mode); |
| 1249 | } |
| 1250 | |
| 1251 | int VoEBaseImpl::GetNetEQPlayoutMode(int channel, NetEqModes& mode) |
| 1252 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1253 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1254 | "GetNetEQPlayoutMode(channel=%i, mode=?)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1255 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1256 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1257 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1258 | return -1; |
| 1259 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1260 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1261 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 1262 | if (channelPtr == NULL) |
| 1263 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1264 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 1265 | "GetNetEQPlayoutMode() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1266 | return -1; |
| 1267 | } |
| 1268 | return channelPtr->GetNetEQPlayoutMode(mode); |
| 1269 | } |
| 1270 | |
| 1271 | int VoEBaseImpl::SetNetEQBGNMode(int channel, NetEqBgnModes mode) |
| 1272 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1273 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1274 | "SetNetEQBGNMode(channel=%i, mode=%i)", channel, mode); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1275 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1276 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1277 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1278 | return -1; |
| 1279 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1280 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1281 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 1282 | if (channelPtr == NULL) |
| 1283 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1284 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 1285 | "SetNetEQBGNMode() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1286 | return -1; |
| 1287 | } |
| 1288 | return channelPtr->SetNetEQBGNMode(mode); |
| 1289 | } |
| 1290 | |
| 1291 | int VoEBaseImpl::GetNetEQBGNMode(int channel, NetEqBgnModes& mode) |
| 1292 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1293 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1294 | "GetNetEQBGNMode(channel=%i, mode=?)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1295 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1296 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1297 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1298 | return -1; |
| 1299 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1300 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1301 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 1302 | if (channelPtr == NULL) |
| 1303 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1304 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 1305 | "GetNetEQBGNMode() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1306 | return -1; |
| 1307 | } |
| 1308 | return channelPtr->GetNetEQBGNMode(mode); |
| 1309 | } |
| 1310 | |
| 1311 | int VoEBaseImpl::SetOnHoldStatus(int channel, bool enable, OnHoldModes mode) |
| 1312 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1313 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1314 | "SetOnHoldStatus(channel=%d, enable=%d, mode=%d)", channel, |
| 1315 | enable, mode); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1316 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1317 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1318 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1319 | return -1; |
| 1320 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1321 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1322 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 1323 | if (channelPtr == NULL) |
| 1324 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1325 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 1326 | "SetOnHoldStatus() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1327 | return -1; |
| 1328 | } |
| 1329 | return channelPtr->SetOnHoldStatus(enable, mode); |
| 1330 | } |
| 1331 | |
| 1332 | int VoEBaseImpl::GetOnHoldStatus(int channel, bool& enabled, OnHoldModes& mode) |
| 1333 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1334 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1335 | "GetOnHoldStatus(channel=%d, enabled=?, mode=?)", channel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1336 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1337 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1338 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1339 | return -1; |
| 1340 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1341 | voe::ScopedChannel sc(_shared->channel_manager(), channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1342 | voe::Channel* channelPtr = sc.ChannelPtr(); |
| 1343 | if (channelPtr == NULL) |
| 1344 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1345 | _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 1346 | "GetOnHoldStatus() failed to locate channel"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1347 | return -1; |
| 1348 | } |
| 1349 | return channelPtr->GetOnHoldStatus(enabled, mode); |
| 1350 | } |
| 1351 | |
| 1352 | WebRtc_Word32 VoEBaseImpl::StartPlayout() |
| 1353 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1354 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1355 | "VoEBaseImpl::StartPlayout()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1356 | if (_shared->audio_device()->Playing()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1357 | { |
| 1358 | return 0; |
| 1359 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1360 | if (!_shared->ext_playout()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1361 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1362 | if (_shared->audio_device()->InitPlayout() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1363 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1364 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 1365 | VoEId(_shared->instance_id(), -1), |
| 1366 | "StartPlayout() failed to initialize playout"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1367 | return -1; |
| 1368 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1369 | if (_shared->audio_device()->StartPlayout() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1370 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1371 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 1372 | VoEId(_shared->instance_id(), -1), |
| 1373 | "StartPlayout() failed to start playout"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1374 | return -1; |
| 1375 | } |
| 1376 | } |
| 1377 | return 0; |
| 1378 | } |
| 1379 | |
| 1380 | WebRtc_Word32 VoEBaseImpl::StopPlayout() |
| 1381 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1382 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1383 | "VoEBaseImpl::StopPlayout()"); |
| 1384 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1385 | WebRtc_Word32 numOfChannels = _shared->channel_manager().NumOfChannels(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1386 | if (numOfChannels <= 0) |
| 1387 | { |
| 1388 | return 0; |
| 1389 | } |
| 1390 | |
| 1391 | WebRtc_UWord16 nChannelsPlaying(0); |
| 1392 | WebRtc_Word32* channelsArray = new WebRtc_Word32[numOfChannels]; |
| 1393 | |
| 1394 | // Get number of playing channels |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1395 | _shared->channel_manager().GetChannelIds(channelsArray, numOfChannels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1396 | for (int i = 0; i < numOfChannels; i++) |
| 1397 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1398 | voe::ScopedChannel sc(_shared->channel_manager(), channelsArray[i]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1399 | voe::Channel* chPtr = sc.ChannelPtr(); |
| 1400 | if (chPtr) |
| 1401 | { |
| 1402 | if (chPtr->Playing()) |
| 1403 | { |
| 1404 | nChannelsPlaying++; |
| 1405 | } |
| 1406 | } |
| 1407 | } |
| 1408 | delete[] channelsArray; |
| 1409 | |
| 1410 | // Stop audio-device playing if no channel is playing out |
| 1411 | if (nChannelsPlaying == 0) |
| 1412 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1413 | if (_shared->audio_device()->StopPlayout() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1414 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1415 | _shared->SetLastError(VE_CANNOT_STOP_PLAYOUT, kTraceError, |
| 1416 | "StopPlayout() failed to stop playout"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1417 | return -1; |
| 1418 | } |
| 1419 | } |
| 1420 | return 0; |
| 1421 | } |
| 1422 | |
| 1423 | WebRtc_Word32 VoEBaseImpl::StartSend() |
| 1424 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1425 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1426 | "VoEBaseImpl::StartSend()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1427 | if (_shared->audio_device()->Recording()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1428 | { |
| 1429 | return 0; |
| 1430 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1431 | if (!_shared->ext_recording()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1432 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1433 | if (_shared->audio_device()->InitRecording() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1434 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1435 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 1436 | VoEId(_shared->instance_id(), -1), |
| 1437 | "StartSend() failed to initialize recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1438 | return -1; |
| 1439 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1440 | if (_shared->audio_device()->StartRecording() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1441 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1442 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 1443 | VoEId(_shared->instance_id(), -1), |
| 1444 | "StartSend() failed to start recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1445 | return -1; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | return 0; |
| 1450 | } |
| 1451 | |
| 1452 | WebRtc_Word32 VoEBaseImpl::StopSend() |
| 1453 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1454 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1455 | "VoEBaseImpl::StopSend()"); |
| 1456 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1457 | if (_shared->NumOfSendingChannels() == 0 && |
| 1458 | !_shared->transmit_mixer()->IsRecordingMic()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1459 | { |
| 1460 | // Stop audio-device recording if no channel is recording |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1461 | if (_shared->audio_device()->StopRecording() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1462 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1463 | _shared->SetLastError(VE_CANNOT_STOP_RECORDING, kTraceError, |
| 1464 | "StopSend() failed to stop recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1465 | return -1; |
| 1466 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1467 | _shared->transmit_mixer()->StopSend(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | return 0; |
| 1471 | } |
| 1472 | |
| 1473 | WebRtc_Word32 VoEBaseImpl::TerminateInternal() |
| 1474 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1475 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1476 | "VoEBaseImpl::TerminateInternal()"); |
| 1477 | |
| 1478 | // Delete any remaining channel objects |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1479 | WebRtc_Word32 numOfChannels = _shared->channel_manager().NumOfChannels(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1480 | if (numOfChannels > 0) |
| 1481 | { |
| 1482 | WebRtc_Word32* channelsArray = new WebRtc_Word32[numOfChannels]; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1483 | _shared->channel_manager().GetChannelIds(channelsArray, numOfChannels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1484 | for (int i = 0; i < numOfChannels; i++) |
| 1485 | { |
| 1486 | DeleteChannel(channelsArray[i]); |
| 1487 | } |
| 1488 | delete[] channelsArray; |
| 1489 | } |
| 1490 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1491 | if (_shared->process_thread()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1492 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1493 | if (_shared->audio_device()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1494 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1495 | if (_shared->process_thread()-> |
| 1496 | DeRegisterModule(_shared->audio_device()) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1497 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1498 | _shared->SetLastError(VE_THREAD_ERROR, kTraceError, |
| 1499 | "TerminateInternal() failed to deregister ADM"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1500 | } |
| 1501 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1502 | if (_shared->process_thread()->Stop() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1503 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1504 | _shared->SetLastError(VE_THREAD_ERROR, kTraceError, |
| 1505 | "TerminateInternal() failed to stop module process thread"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1506 | } |
| 1507 | } |
| 1508 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame^] | 1509 | if (_shared->audio_device()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1510 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1511 | if (_shared->audio_device()->StopPlayout() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1512 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1513 | _shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, |
| 1514 | "TerminateInternal() failed to stop playout"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1515 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1516 | if (_shared->audio_device()->StopRecording() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1517 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1518 | _shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, |
| 1519 | "TerminateInternal() failed to stop recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1520 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1521 | if (_shared->audio_device()->RegisterEventObserver(NULL) != 0) { |
| 1522 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, |
| 1523 | "TerminateInternal() failed to de-register event observer " |
| 1524 | "for the ADM"); |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +0000 | [diff] [blame] | 1525 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1526 | if (_shared->audio_device()->RegisterAudioCallback(NULL) != 0) { |
| 1527 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, |
| 1528 | "TerminateInternal() failed to de-register audio callback " |
| 1529 | "for the ADM"); |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +0000 | [diff] [blame] | 1530 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1531 | if (_shared->audio_device()->Terminate() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1532 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1533 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
| 1534 | "TerminateInternal() failed to terminate the ADM"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1535 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1536 | _shared->set_audio_device(NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame^] | 1539 | if (_shared->audio_processing()) { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1540 | _shared->set_audio_processing(NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 1543 | return _shared->statistics().SetUnInitialized(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | } // namespace webrtc |