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_hardware_impl.h" |
| 12 | |
| 13 | #include <cassert> |
| 14 | |
| 15 | #include "cpu_wrapper.h" |
| 16 | #include "critical_section_wrapper.h" |
| 17 | #include "trace.h" |
| 18 | #include "voe_errors.h" |
| 19 | #include "voice_engine_impl.h" |
| 20 | |
| 21 | namespace webrtc |
| 22 | { |
| 23 | |
| 24 | VoEHardware* VoEHardware::GetInterface(VoiceEngine* voiceEngine) |
| 25 | { |
| 26 | #ifndef WEBRTC_VOICE_ENGINE_HARDWARE_API |
| 27 | return NULL; |
| 28 | #else |
| 29 | if (NULL == voiceEngine) |
| 30 | { |
| 31 | return NULL; |
| 32 | } |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 33 | VoiceEngineImpl* s = reinterpret_cast<VoiceEngineImpl*>(voiceEngine); |
| 34 | s->AddRef(); |
| 35 | return s; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | #endif |
| 37 | } |
| 38 | |
| 39 | #ifdef WEBRTC_VOICE_ENGINE_HARDWARE_API |
| 40 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 41 | VoEHardwareImpl::VoEHardwareImpl(voe::SharedData* shared) : |
| 42 | _cpu(NULL), _shared(shared) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 44 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | "VoEHardwareImpl() - ctor"); |
| 46 | |
| 47 | _cpu = CpuWrapper::CreateCpu(); |
| 48 | if (_cpu) |
| 49 | { |
| 50 | _cpu->CpuUsage(); // init cpu usage |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | VoEHardwareImpl::~VoEHardwareImpl() |
| 55 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 56 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | "~VoEHardwareImpl() - dtor"); |
| 58 | |
| 59 | if (_cpu) |
| 60 | { |
| 61 | delete _cpu; |
| 62 | _cpu = NULL; |
| 63 | } |
| 64 | } |
| 65 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | int VoEHardwareImpl::SetAudioDeviceLayer(AudioLayers audioLayer) |
| 67 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 68 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | "SetAudioDeviceLayer(audioLayer=%d)", audioLayer); |
| 70 | |
| 71 | // Don't allow a change if VoE is initialized |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 72 | if (_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 74 | _shared->SetLastError(VE_ALREADY_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | return -1; |
| 76 | } |
| 77 | |
| 78 | // Map to AudioDeviceModule::AudioLayer |
| 79 | AudioDeviceModule::AudioLayer |
| 80 | wantedLayer(AudioDeviceModule::kPlatformDefaultAudio); |
| 81 | switch (audioLayer) |
| 82 | { |
| 83 | case kAudioPlatformDefault: |
| 84 | // already set above |
| 85 | break; |
| 86 | case kAudioWindowsCore: |
| 87 | wantedLayer = AudioDeviceModule::kWindowsCoreAudio; |
| 88 | break; |
| 89 | case kAudioWindowsWave: |
| 90 | wantedLayer = AudioDeviceModule::kWindowsWaveAudio; |
| 91 | break; |
| 92 | case kAudioLinuxAlsa: |
| 93 | wantedLayer = AudioDeviceModule::kLinuxAlsaAudio; |
| 94 | break; |
| 95 | case kAudioLinuxPulse: |
| 96 | wantedLayer = AudioDeviceModule::kLinuxPulseAudio; |
| 97 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | // Save the audio device layer for Init() |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 101 | _shared->set_audio_device_layer(wantedLayer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | int VoEHardwareImpl::GetAudioDeviceLayer(AudioLayers& audioLayer) |
| 107 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 108 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | "GetAudioDeviceLayer(devices=?)"); |
| 110 | |
| 111 | // Can always be called regardless of VoE state |
| 112 | |
| 113 | AudioDeviceModule::AudioLayer |
| 114 | activeLayer(AudioDeviceModule::kPlatformDefaultAudio); |
| 115 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 116 | if (_shared->audio_device()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | { |
| 118 | // Get active audio layer from ADM |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 119 | if (_shared->audio_device()->ActiveAudioLayer(&activeLayer) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 121 | _shared->SetLastError(VE_UNDEFINED_SC_ERR, kTraceError, |
| 122 | " Audio Device error"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 123 | return -1; |
| 124 | } |
| 125 | } |
| 126 | else |
| 127 | { |
| 128 | // Return VoE's internal layer setting |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 129 | activeLayer = _shared->audio_device_layer(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | // Map to AudioLayers |
| 133 | switch (activeLayer) |
| 134 | { |
| 135 | case AudioDeviceModule::kPlatformDefaultAudio: |
| 136 | audioLayer = kAudioPlatformDefault; |
| 137 | break; |
| 138 | case AudioDeviceModule::kWindowsCoreAudio: |
| 139 | audioLayer = kAudioWindowsCore; |
| 140 | break; |
| 141 | case AudioDeviceModule::kWindowsWaveAudio: |
| 142 | audioLayer = kAudioWindowsWave; |
| 143 | break; |
| 144 | case AudioDeviceModule::kLinuxAlsaAudio: |
| 145 | audioLayer = kAudioLinuxAlsa; |
| 146 | break; |
| 147 | case AudioDeviceModule::kLinuxPulseAudio: |
| 148 | audioLayer = kAudioLinuxPulse; |
| 149 | break; |
| 150 | default: |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 151 | _shared->SetLastError(VE_UNDEFINED_SC_ERR, kTraceError, |
| 152 | " unknown audio layer"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | } |
| 154 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 155 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 156 | VoEId(_shared->instance_id(), -1), |
| 157 | " Output: audioLayer=%d", audioLayer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | int VoEHardwareImpl::GetNumOfRecordingDevices(int& devices) |
| 162 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 163 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 164 | "GetNumOfRecordingDevices(devices=?)"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 165 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 166 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 167 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 168 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 170 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 171 | return -1; |
| 172 | } |
| 173 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 174 | devices = static_cast<int> (_shared->audio_device()->RecordingDevices()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 175 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 176 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 177 | VoEId(_shared->instance_id(), -1), " Output: devices=%d", devices); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | int VoEHardwareImpl::GetNumOfPlayoutDevices(int& devices) |
| 183 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 184 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 185 | "GetNumOfPlayoutDevices(devices=?)"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 186 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 187 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 188 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 189 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 190 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 191 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 192 | return -1; |
| 193 | } |
| 194 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 195 | devices = static_cast<int> (_shared->audio_device()->PlayoutDevices()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 196 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 197 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 198 | VoEId(_shared->instance_id(), -1), |
| 199 | " Output: devices=%d", devices); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | int VoEHardwareImpl::GetRecordingDeviceName(int index, |
| 205 | char strNameUTF8[128], |
| 206 | char strGuidUTF8[128]) |
| 207 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 208 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 209 | "GetRecordingDeviceName(index=%d)", index); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 210 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 211 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 212 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 213 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 214 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 215 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 216 | return -1; |
| 217 | } |
| 218 | if (strNameUTF8 == NULL) |
| 219 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 220 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 221 | "GetRecordingDeviceName() invalid argument"); |
| 222 | return -1; |
| 223 | } |
| 224 | |
| 225 | // Note that strGuidUTF8 is allowed to be NULL |
| 226 | |
| 227 | // Init len variable to length of supplied vectors |
| 228 | const WebRtc_UWord16 strLen = 128; |
| 229 | |
| 230 | // Check if length has been changed in module |
| 231 | assert(strLen == kAdmMaxDeviceNameSize); |
| 232 | assert(strLen == kAdmMaxGuidSize); |
| 233 | |
leozwang@webrtc.org | 813e4b0 | 2012-03-01 18:34:25 +0000 | [diff] [blame] | 234 | char name[strLen]; |
| 235 | char guid[strLen]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 236 | |
| 237 | // Get names from module |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 238 | if (_shared->audio_device()->RecordingDeviceName(index, name, guid) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 239 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 240 | _shared->SetLastError(VE_CANNOT_RETRIEVE_DEVICE_NAME, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 241 | "GetRecordingDeviceName() failed to get device name"); |
| 242 | return -1; |
| 243 | } |
| 244 | |
| 245 | // Copy to vectors supplied by user |
| 246 | strncpy(strNameUTF8, name, strLen); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 247 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 248 | VoEId(_shared->instance_id(), -1), |
| 249 | " Output: strNameUTF8=%s", strNameUTF8); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 250 | |
| 251 | if (strGuidUTF8 != NULL) |
| 252 | { |
xians@google.com | 49d025f | 2011-09-27 14:43:06 +0000 | [diff] [blame] | 253 | strncpy(strGuidUTF8, guid, strLen); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 254 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 255 | VoEId(_shared->instance_id(), -1), |
| 256 | " Output: strGuidUTF8=%s", strGuidUTF8); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | int VoEHardwareImpl::GetPlayoutDeviceName(int index, |
| 263 | char strNameUTF8[128], |
| 264 | char strGuidUTF8[128]) |
| 265 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 266 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 267 | "GetPlayoutDeviceName(index=%d)", index); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 268 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 269 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 270 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 271 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 272 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 273 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 274 | return -1; |
| 275 | } |
| 276 | if (strNameUTF8 == NULL) |
| 277 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 278 | _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 279 | "GetPlayoutDeviceName() invalid argument"); |
| 280 | return -1; |
| 281 | } |
| 282 | |
| 283 | // Note that strGuidUTF8 is allowed to be NULL |
| 284 | |
| 285 | // Init len variable to length of supplied vectors |
| 286 | const WebRtc_UWord16 strLen = 128; |
| 287 | |
| 288 | // Check if length has been changed in module |
| 289 | assert(strLen == kAdmMaxDeviceNameSize); |
| 290 | assert(strLen == kAdmMaxGuidSize); |
| 291 | |
leozwang@webrtc.org | 813e4b0 | 2012-03-01 18:34:25 +0000 | [diff] [blame] | 292 | char name[strLen]; |
| 293 | char guid[strLen]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 294 | |
| 295 | // Get names from module |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 296 | if (_shared->audio_device()->PlayoutDeviceName(index, name, guid) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 297 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 298 | _shared->SetLastError(VE_CANNOT_RETRIEVE_DEVICE_NAME, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 299 | "GetPlayoutDeviceName() failed to get device name"); |
| 300 | return -1; |
| 301 | } |
| 302 | |
| 303 | // Copy to vectors supplied by user |
| 304 | strncpy(strNameUTF8, name, strLen); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 305 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 306 | VoEId(_shared->instance_id(), -1), |
| 307 | " Output: strNameUTF8=%s", strNameUTF8); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 308 | |
| 309 | if (strGuidUTF8 != NULL) |
| 310 | { |
xians@google.com | b875349 | 2011-09-05 12:17:30 +0000 | [diff] [blame] | 311 | strncpy(strGuidUTF8, guid, strLen); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 312 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 313 | VoEId(_shared->instance_id(), -1), |
| 314 | " Output: strGuidUTF8=%s", strGuidUTF8); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | int VoEHardwareImpl::SetRecordingDevice(int index, |
| 321 | StereoChannel recordingChannel) |
| 322 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 323 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 324 | "SetRecordingDevice(index=%d, recordingChannel=%d)", |
| 325 | index, (int) recordingChannel); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 326 | CriticalSectionScoped cs(_shared->crit_sec()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 327 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
leozwang@webrtc.org | 81cd447 | 2012-09-20 17:18:51 +0000 | [diff] [blame] | 328 | // TODO(leozwang): Add this api to Android OpenSL ES implementation. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 329 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 330 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 331 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 332 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 333 | return -1; |
| 334 | } |
| 335 | |
| 336 | bool isRecording(false); |
| 337 | |
| 338 | // Store state about activated recording to be able to restore it after the |
| 339 | // recording device has been modified. |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 340 | if (_shared->audio_device()->Recording()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 341 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 342 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 343 | "SetRecordingDevice() device is modified while recording" |
| 344 | " is active..."); |
| 345 | isRecording = true; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 346 | if (_shared->audio_device()->StopRecording() == -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 347 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 348 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 349 | "SetRecordingDevice() unable to stop recording"); |
| 350 | return -1; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | // We let the module do the index sanity |
| 355 | |
| 356 | // Set recording channel |
| 357 | AudioDeviceModule::ChannelType recCh = |
| 358 | AudioDeviceModule::kChannelBoth; |
| 359 | switch (recordingChannel) |
| 360 | { |
| 361 | case kStereoLeft: |
| 362 | recCh = AudioDeviceModule::kChannelLeft; |
| 363 | break; |
| 364 | case kStereoRight: |
| 365 | recCh = AudioDeviceModule::kChannelRight; |
| 366 | break; |
| 367 | case kStereoBoth: |
| 368 | // default setting kChannelBoth (<=> mono) |
| 369 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 370 | } |
| 371 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 372 | if (_shared->audio_device()->SetRecordingChannel(recCh) != 0) { |
| 373 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +0000 | [diff] [blame] | 374 | "SetRecordingChannel() unable to set the recording channel"); |
| 375 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 376 | |
| 377 | // Map indices to unsigned since underlying functions need that |
| 378 | WebRtc_UWord16 indexU = static_cast<WebRtc_UWord16> (index); |
| 379 | |
| 380 | WebRtc_Word32 res(0); |
| 381 | |
| 382 | if (index == -1) |
| 383 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 384 | res = _shared->audio_device()->SetRecordingDevice( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 385 | AudioDeviceModule::kDefaultCommunicationDevice); |
| 386 | } |
| 387 | else if (index == -2) |
| 388 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 389 | res = _shared->audio_device()->SetRecordingDevice( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 390 | AudioDeviceModule::kDefaultDevice); |
| 391 | } |
| 392 | else |
| 393 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 394 | res = _shared->audio_device()->SetRecordingDevice(indexU); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | if (res != 0) |
| 398 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 399 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 400 | "SetRecordingDevice() unable to set the recording device"); |
| 401 | return -1; |
| 402 | } |
| 403 | |
| 404 | // Init microphone, so user can do volume settings etc |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 405 | if (_shared->audio_device()->InitMicrophone() == -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 406 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 407 | _shared->SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceWarning, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 408 | "SetRecordingDevice() cannot access microphone"); |
| 409 | } |
| 410 | |
| 411 | // Set number of channels |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 412 | bool available = false; |
| 413 | if (_shared->audio_device()->StereoRecordingIsAvailable(&available) != 0) { |
| 414 | _shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +0000 | [diff] [blame] | 415 | "StereoRecordingIsAvailable() failed to query stereo recording"); |
| 416 | } |
| 417 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 418 | if (_shared->audio_device()->SetStereoRecording(available) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 419 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 420 | _shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 421 | "SetRecordingDevice() failed to set mono recording mode"); |
| 422 | } |
| 423 | |
| 424 | // Restore recording if it was enabled already when calling this function. |
| 425 | if (isRecording) |
| 426 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 427 | if (!_shared->ext_recording()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 428 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 429 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, |
| 430 | VoEId(_shared->instance_id(), -1), |
| 431 | "SetRecordingDevice() recording is now being restored..."); |
| 432 | if (_shared->audio_device()->InitRecording() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 433 | { |
| 434 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 435 | VoEId(_shared->instance_id(), -1), |
| 436 | "SetRecordingDevice() failed to initialize recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 437 | return -1; |
| 438 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 439 | if (_shared->audio_device()->StartRecording() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 440 | { |
| 441 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 442 | VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 443 | "SetRecordingDevice() failed to start recording"); |
| 444 | return -1; |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | int VoEHardwareImpl::SetPlayoutDevice(int index) |
| 453 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 454 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 455 | "SetPlayoutDevice(index=%d)", index); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 456 | CriticalSectionScoped cs(_shared->crit_sec()); |
| 457 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 458 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 459 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 460 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 461 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 462 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 463 | return -1; |
| 464 | } |
| 465 | |
| 466 | bool isPlaying(false); |
| 467 | |
| 468 | // Store state about activated playout to be able to restore it after the |
| 469 | // playout device has been modified. |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 470 | if (_shared->audio_device()->Playing()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 471 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 472 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 473 | "SetPlayoutDevice() device is modified while playout is " |
| 474 | "active..."); |
| 475 | isPlaying = true; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 476 | if (_shared->audio_device()->StopPlayout() == -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 477 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 478 | _shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 479 | "SetPlayoutDevice() unable to stop playout"); |
| 480 | return -1; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | // We let the module do the index sanity |
| 485 | |
| 486 | // Map indices to unsigned since underlying functions need that |
| 487 | WebRtc_UWord16 indexU = static_cast<WebRtc_UWord16> (index); |
| 488 | |
| 489 | WebRtc_Word32 res(0); |
| 490 | |
| 491 | if (index == -1) |
| 492 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 493 | res = _shared->audio_device()->SetPlayoutDevice( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 494 | AudioDeviceModule::kDefaultCommunicationDevice); |
| 495 | } |
| 496 | else if (index == -2) |
| 497 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 498 | res = _shared->audio_device()->SetPlayoutDevice( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 499 | AudioDeviceModule::kDefaultDevice); |
| 500 | } |
| 501 | else |
| 502 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 503 | res = _shared->audio_device()->SetPlayoutDevice(indexU); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | if (res != 0) |
| 507 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 508 | _shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceError, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 509 | "SetPlayoutDevice() unable to set the playout device"); |
| 510 | return -1; |
| 511 | } |
| 512 | |
| 513 | // Init speaker, so user can do volume settings etc |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 514 | if (_shared->audio_device()->InitSpeaker() == -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 515 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 516 | _shared->SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, kTraceWarning, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 517 | "SetPlayoutDevice() cannot access speaker"); |
| 518 | } |
| 519 | |
| 520 | // Set number of channels |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 521 | bool available = false; |
| 522 | _shared->audio_device()->StereoPlayoutIsAvailable(&available); |
| 523 | if (_shared->audio_device()->SetStereoPlayout(available) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 524 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 525 | _shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 526 | "SetPlayoutDevice() failed to set stereo playout mode"); |
| 527 | } |
| 528 | |
| 529 | // Restore playout if it was enabled already when calling this function. |
| 530 | if (isPlaying) |
| 531 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 532 | if (!_shared->ext_playout()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 533 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 534 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, |
| 535 | VoEId(_shared->instance_id(), -1), |
| 536 | "SetPlayoutDevice() playout is now being restored..."); |
| 537 | if (_shared->audio_device()->InitPlayout() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 538 | { |
| 539 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 540 | VoEId(_shared->instance_id(), -1), |
| 541 | "SetPlayoutDevice() failed to initialize playout"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 542 | return -1; |
| 543 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 544 | if (_shared->audio_device()->StartPlayout() != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 545 | { |
| 546 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 547 | VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 548 | "SetPlayoutDevice() failed to start playout"); |
| 549 | return -1; |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | int VoEHardwareImpl::GetRecordingDeviceStatus(bool& isAvailable) |
| 558 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 559 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 560 | "GetRecordingDeviceStatus()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 561 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 562 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 563 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 564 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 565 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 566 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 567 | return -1; |
| 568 | } |
| 569 | |
| 570 | // We let the module do isRecording sanity |
| 571 | |
| 572 | bool available(false); |
| 573 | |
| 574 | // Check availability |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 575 | if (_shared->audio_device()->RecordingIsAvailable(&available) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 576 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 577 | _shared->SetLastError(VE_UNDEFINED_SC_REC_ERR, kTraceError, |
| 578 | " Audio Device error"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 579 | return -1; |
| 580 | } |
| 581 | |
| 582 | isAvailable = available; |
| 583 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 584 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 585 | VoEId(_shared->instance_id(), -1), |
| 586 | " Output: isAvailable = %d)", (int) isAvailable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 587 | |
| 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | int VoEHardwareImpl::GetPlayoutDeviceStatus(bool& isAvailable) |
| 592 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 593 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 594 | "GetPlayoutDeviceStatus()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 595 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 596 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 597 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 598 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 599 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 600 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 601 | return -1; |
| 602 | } |
| 603 | |
| 604 | // We let the module do isPlaying sanity |
| 605 | |
| 606 | bool available(false); |
| 607 | |
| 608 | // Check availability |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 609 | if (_shared->audio_device()->PlayoutIsAvailable(&available) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 610 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 611 | _shared->SetLastError(VE_PLAY_UNDEFINED_SC_ERR, kTraceError, |
| 612 | " Audio Device error"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 613 | return -1; |
| 614 | } |
| 615 | |
| 616 | isAvailable = available; |
| 617 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 618 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 619 | VoEId(_shared->instance_id(), -1), |
| 620 | " Output: isAvailable = %d)", (int) isAvailable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 621 | |
| 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | int VoEHardwareImpl::ResetAudioDevice() |
| 626 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 627 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 628 | "ResetAudioDevice()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 629 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 630 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 631 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 632 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 633 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 634 | return -1; |
| 635 | } |
| 636 | |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 637 | #if defined(WEBRTC_IOS) |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 638 | if (_shared->audio_device()->ResetAudioDevice() < 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 639 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 640 | _shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceError, |
| 641 | " Failed to reset sound device"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 642 | return -1; |
| 643 | } |
| 644 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 645 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
| 646 | " no support for resetting sound device"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 647 | return -1; |
| 648 | #endif |
| 649 | |
| 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | int VoEHardwareImpl::AudioDeviceControl(unsigned int par1, unsigned int par2, |
| 654 | unsigned int par3) |
| 655 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 656 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 657 | "AudioDeviceControl(%i, %i, %i)", par1, par2, par3); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 658 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 659 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 660 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 661 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 662 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 663 | return -1; |
| 664 | } |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 665 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
| 666 | " no support for resetting sound device"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 667 | return -1; |
| 668 | } |
| 669 | |
| 670 | int VoEHardwareImpl::SetLoudspeakerStatus(bool enable) |
| 671 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 672 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 673 | "SetLoudspeakerStatus(enable=%i)", (int) enable); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 674 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 675 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 676 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 677 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 678 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 679 | return -1; |
| 680 | } |
leozwang@google.com | f1ed5ad | 2011-08-01 17:36:09 +0000 | [diff] [blame] | 681 | #if defined(WEBRTC_ANDROID) |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 682 | if (_shared->audio_device()->SetLoudspeakerStatus(enable) < 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 683 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 684 | _shared->SetLastError(VE_IGNORED_FUNCTION, kTraceError, |
| 685 | " Failed to set loudspeaker status"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 686 | return -1; |
| 687 | } |
| 688 | |
| 689 | return 0; |
| 690 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 691 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
| 692 | " no support for setting loudspeaker status"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 693 | return -1; |
| 694 | #endif |
| 695 | } |
| 696 | |
| 697 | int VoEHardwareImpl::GetLoudspeakerStatus(bool& enabled) |
| 698 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 699 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 700 | "GetLoudspeakerStatus()"); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 701 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 702 | |
leozwang@google.com | f1ed5ad | 2011-08-01 17:36:09 +0000 | [diff] [blame] | 703 | #if defined(WEBRTC_ANDROID) |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 704 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 705 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 706 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 707 | return -1; |
| 708 | } |
| 709 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 710 | if (_shared->audio_device()->GetLoudspeakerStatus(&enabled) < 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 711 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 712 | _shared->SetLastError(VE_IGNORED_FUNCTION, kTraceError, |
| 713 | " Failed to get loudspeaker status"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 714 | return -1; |
| 715 | } |
| 716 | |
| 717 | return 0; |
| 718 | #else |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 719 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
| 720 | " no support for setting loudspeaker status"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 721 | return -1; |
| 722 | #endif |
| 723 | } |
| 724 | |
| 725 | int VoEHardwareImpl::GetCPULoad(int& loadPercent) |
| 726 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 727 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 728 | "GetCPULoad()"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 729 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 730 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 731 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 732 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 733 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 734 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 735 | return -1; |
| 736 | } |
| 737 | |
| 738 | // Get CPU load from ADM |
| 739 | WebRtc_UWord16 load(0); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 740 | if (_shared->audio_device()->CPULoad(&load) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 741 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 742 | _shared->SetLastError(VE_CPU_INFO_ERROR, kTraceError, |
| 743 | " error getting system CPU load"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 744 | return -1; |
| 745 | } |
| 746 | |
| 747 | loadPercent = static_cast<int> (load); |
| 748 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 749 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 750 | VoEId(_shared->instance_id(), -1), |
| 751 | " Output: loadPercent = %d", loadPercent); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 752 | |
| 753 | return 0; |
| 754 | } |
| 755 | |
| 756 | int VoEHardwareImpl::GetSystemCPULoad(int& loadPercent) |
| 757 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 758 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 759 | "GetSystemCPULoad(loadPercent=?)"); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 760 | ANDROID_NOT_SUPPORTED(_shared->statistics()); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 761 | IPHONE_NOT_SUPPORTED(_shared->statistics()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 762 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 763 | if (!_shared->statistics().Initialized()) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 764 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 765 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 766 | return -1; |
| 767 | } |
| 768 | |
| 769 | // Check if implemented for this platform |
| 770 | if (!_cpu) |
| 771 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 772 | _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, |
| 773 | " no support for getting system CPU load"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 774 | return -1; |
| 775 | } |
| 776 | |
| 777 | // Get CPU load |
| 778 | WebRtc_Word32 load = _cpu->CpuUsage(); |
| 779 | if (load < 0) |
| 780 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 781 | _shared->SetLastError(VE_CPU_INFO_ERROR, kTraceError, |
| 782 | " error getting system CPU load"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 783 | return -1; |
| 784 | } |
| 785 | |
| 786 | loadPercent = static_cast<int> (load); |
| 787 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 788 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 789 | VoEId(_shared->instance_id(), -1), |
| 790 | " Output: loadPercent = %d", loadPercent); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 791 | |
| 792 | return 0; |
| 793 | } |
| 794 | |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 795 | int VoEHardwareImpl::EnableBuiltInAEC(bool enable) |
| 796 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 797 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 798 | "%s", __FUNCTION__); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 799 | if (!_shared->statistics().Initialized()) |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 800 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 801 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 802 | return -1; |
| 803 | } |
| 804 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 805 | return _shared->audio_device()->EnableBuiltInAEC(enable); |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | bool VoEHardwareImpl::BuiltInAECIsEnabled() const |
| 809 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 810 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 811 | "%s", __FUNCTION__); |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 812 | if (!_shared->statistics().Initialized()) |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 813 | { |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 814 | _shared->SetLastError(VE_NOT_INITED, kTraceError); |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 815 | return false; |
| 816 | } |
| 817 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 818 | return _shared->audio_device()->BuiltInAECIsEnabled(); |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 819 | } |
| 820 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 821 | #endif // WEBRTC_VOICE_ENGINE_HARDWARE_API |
| 822 | |
| 823 | } // namespace webrtc |