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