| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <assert.h> | 11 #include <assert.h> |
| 12 | 12 |
| 13 #include "webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.h" | 13 #include "webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.h" |
| 14 #include "webrtc/system_wrappers/include/trace.h" | 14 #include "webrtc/system_wrappers/include/trace.h" |
| 15 | 15 |
| 16 extern webrtc_adm_linux_alsa::AlsaSymbolTable AlsaSymbolTable; | 16 extern webrtc_adm_linux_alsa::AlsaSymbolTable AlsaSymbolTable; |
| 17 | 17 |
| 18 // Accesses ALSA functions through our late-binding symbol table instead of | 18 // Accesses ALSA functions through our late-binding symbol table instead of |
| 19 // directly. This way we don't have to link to libalsa, which means our binary | 19 // directly. This way we don't have to link to libalsa, which means our binary |
| 20 // will work on systems that don't have it. | 20 // will work on systems that don't have it. |
| 21 #define LATE(sym) \ | 21 #define LATE(sym) \ |
| 22 LATESYM_GET(webrtc_adm_linux_alsa::AlsaSymbolTable, &AlsaSymbolTable, sym) | 22 LATESYM_GET(webrtc_adm_linux_alsa::AlsaSymbolTable, &AlsaSymbolTable, sym) |
| 23 | 23 |
| 24 namespace webrtc | 24 namespace webrtc |
| 25 { | 25 { |
| 26 | 26 |
| 27 AudioMixerManagerLinuxALSA::AudioMixerManagerLinuxALSA(const int32_t id) : | 27 AudioMixerManagerLinuxALSA::AudioMixerManagerLinuxALSA(const int32_t id) |
| 28 _critSect(*CriticalSectionWrapper::CreateCriticalSection()), | 28 : _critSect(*CriticalSectionWrapper::CreateCriticalSection()), |
| 29 _id(id), | 29 _id(id), |
| 30 _outputMixerHandle(NULL), | 30 _outputMixerHandle(nullptr), |
| 31 _inputMixerHandle(NULL), | 31 _inputMixerHandle(nullptr), |
| 32 _outputMixerElement(NULL), | 32 _outputMixerElement(nullptr), |
| 33 _inputMixerElement(NULL) | 33 _inputMixerElement(nullptr) { |
| 34 { | 34 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s constructed", |
| 35 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, | 35 __FUNCTION__); |
| 36 "%s constructed", __FUNCTION__); | |
| 37 | 36 |
| 38 memset(_outputMixerStr, 0, kAdmMaxDeviceNameSize); | 37 memset(_outputMixerStr, 0, kAdmMaxDeviceNameSize); |
| 39 memset(_inputMixerStr, 0, kAdmMaxDeviceNameSize); | 38 memset(_inputMixerStr, 0, kAdmMaxDeviceNameSize); |
| 40 } | 39 } |
| 41 | 40 |
| 42 AudioMixerManagerLinuxALSA::~AudioMixerManagerLinuxALSA() | 41 AudioMixerManagerLinuxALSA::~AudioMixerManagerLinuxALSA() |
| 43 { | 42 { |
| 44 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, | 43 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, |
| 45 "%s destructed", __FUNCTION__); | 44 "%s destructed", __FUNCTION__); |
| 46 | 45 |
| 47 Close(); | 46 Close(); |
| 48 | 47 |
| 49 delete &_critSect; | 48 delete &_critSect; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 69 | 68 |
| 70 int32_t AudioMixerManagerLinuxALSA::CloseSpeaker() | 69 int32_t AudioMixerManagerLinuxALSA::CloseSpeaker() |
| 71 { | 70 { |
| 72 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", | 71 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", |
| 73 __FUNCTION__); | 72 __FUNCTION__); |
| 74 | 73 |
| 75 CriticalSectionScoped lock(&_critSect); | 74 CriticalSectionScoped lock(&_critSect); |
| 76 | 75 |
| 77 int errVal = 0; | 76 int errVal = 0; |
| 78 | 77 |
| 79 if (_outputMixerHandle != NULL) | 78 if (_outputMixerHandle != nullptr) { |
| 80 { | 79 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Closing playout mixer"); |
| 81 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 80 LATE(snd_mixer_free)(_outputMixerHandle); |
| 82 "Closing playout mixer"); | 81 if (errVal < 0) { |
| 83 LATE(snd_mixer_free)(_outputMixerHandle); | 82 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 84 if (errVal < 0) | 83 " Error freeing playout mixer: %s", |
| 85 { | 84 LATE(snd_strerror)(errVal)); |
| 86 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 85 } |
| 87 " Error freeing playout mixer: %s", | 86 errVal = LATE(snd_mixer_detach)(_outputMixerHandle, _outputMixerStr); |
| 88 LATE(snd_strerror)(errVal)); | 87 if (errVal < 0) { |
| 89 } | 88 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 90 errVal = LATE(snd_mixer_detach)(_outputMixerHandle, _outputMixerStr); | 89 " Error detachinging playout mixer: %s", |
| 91 if (errVal < 0) | 90 LATE(snd_strerror)(errVal)); |
| 92 { | 91 } |
| 93 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 92 errVal = LATE(snd_mixer_close)(_outputMixerHandle); |
| 94 " Error detachinging playout mixer: %s", | 93 if (errVal < 0) { |
| 95 LATE(snd_strerror)(errVal)); | 94 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 96 } | 95 " Error snd_mixer_close(handleMixer) errVal=%d", |
| 97 errVal = LATE(snd_mixer_close)(_outputMixerHandle); | 96 errVal); |
| 98 if (errVal < 0) | 97 } |
| 99 { | 98 _outputMixerHandle = nullptr; |
| 100 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 99 _outputMixerElement = nullptr; |
| 101 " Error snd_mixer_close(handleMixer) errVal=%d", | |
| 102 errVal); | |
| 103 } | |
| 104 _outputMixerHandle = NULL; | |
| 105 _outputMixerElement = NULL; | |
| 106 } | 100 } |
| 107 memset(_outputMixerStr, 0, kAdmMaxDeviceNameSize); | 101 memset(_outputMixerStr, 0, kAdmMaxDeviceNameSize); |
| 108 | 102 |
| 109 return 0; | 103 return 0; |
| 110 } | 104 } |
| 111 | 105 |
| 112 int32_t AudioMixerManagerLinuxALSA::CloseMicrophone() | 106 int32_t AudioMixerManagerLinuxALSA::CloseMicrophone() |
| 113 { | 107 { |
| 114 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__); | 108 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__); |
| 115 | 109 |
| 116 CriticalSectionScoped lock(&_critSect); | 110 CriticalSectionScoped lock(&_critSect); |
| 117 | 111 |
| 118 int errVal = 0; | 112 int errVal = 0; |
| 119 | 113 |
| 120 if (_inputMixerHandle != NULL) | 114 if (_inputMixerHandle != nullptr) { |
| 121 { | 115 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Closing record mixer"); |
| 122 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | |
| 123 "Closing record mixer"); | |
| 124 | 116 |
| 125 LATE(snd_mixer_free)(_inputMixerHandle); | 117 LATE(snd_mixer_free)(_inputMixerHandle); |
| 126 if (errVal < 0) | 118 if (errVal < 0) { |
| 127 { | 119 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 128 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 120 " Error freeing record mixer: %s", |
| 129 " Error freeing record mixer: %s", | 121 LATE(snd_strerror)(errVal)); |
| 130 LATE(snd_strerror)(errVal)); | 122 } |
| 131 } | 123 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 132 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 124 "Closing record mixer 2"); |
| 133 "Closing record mixer 2"); | |
| 134 | 125 |
| 135 errVal = LATE(snd_mixer_detach)(_inputMixerHandle, _inputMixerStr); | 126 errVal = LATE(snd_mixer_detach)(_inputMixerHandle, _inputMixerStr); |
| 136 if (errVal < 0) | 127 if (errVal < 0) { |
| 137 { | 128 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 138 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 129 " Error detachinging record mixer: %s", |
| 139 " Error detachinging record mixer: %s", | 130 LATE(snd_strerror)(errVal)); |
| 140 LATE(snd_strerror)(errVal)); | 131 } |
| 141 } | 132 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 142 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 133 "Closing record mixer 3"); |
| 143 "Closing record mixer 3"); | |
| 144 | 134 |
| 145 errVal = LATE(snd_mixer_close)(_inputMixerHandle); | 135 errVal = LATE(snd_mixer_close)(_inputMixerHandle); |
| 146 if (errVal < 0) | 136 if (errVal < 0) { |
| 147 { | 137 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 148 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 138 " Error snd_mixer_close(handleMixer) errVal=%d", |
| 149 " Error snd_mixer_close(handleMixer) errVal=%d", | 139 errVal); |
| 150 errVal); | 140 } |
| 151 } | |
| 152 | 141 |
| 153 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 142 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 154 "Closing record mixer 4"); | 143 "Closing record mixer 4"); |
| 155 _inputMixerHandle = NULL; | 144 _inputMixerHandle = nullptr; |
| 156 _inputMixerElement = NULL; | 145 _inputMixerElement = nullptr; |
| 157 } | 146 } |
| 158 memset(_inputMixerStr, 0, kAdmMaxDeviceNameSize); | 147 memset(_inputMixerStr, 0, kAdmMaxDeviceNameSize); |
| 159 | 148 |
| 160 return 0; | 149 return 0; |
| 161 } | 150 } |
| 162 | 151 |
| 163 int32_t AudioMixerManagerLinuxALSA::OpenSpeaker(char* deviceName) | 152 int32_t AudioMixerManagerLinuxALSA::OpenSpeaker(char* deviceName) |
| 164 { | 153 { |
| 165 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 154 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 166 "AudioMixerManagerLinuxALSA::OpenSpeaker(name=%s)", deviceName)
; | 155 "AudioMixerManagerLinuxALSA::OpenSpeaker(name=%s)", deviceName)
; |
| 167 | 156 |
| 168 CriticalSectionScoped lock(&_critSect); | 157 CriticalSectionScoped lock(&_critSect); |
| 169 | 158 |
| 170 int errVal = 0; | 159 int errVal = 0; |
| 171 | 160 |
| 172 // Close any existing output mixer handle | 161 // Close any existing output mixer handle |
| 173 // | 162 // |
| 174 if (_outputMixerHandle != NULL) | 163 if (_outputMixerHandle != nullptr) { |
| 175 { | 164 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Closing playout mixer"); |
| 176 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | |
| 177 "Closing playout mixer"); | |
| 178 | 165 |
| 179 LATE(snd_mixer_free)(_outputMixerHandle); | 166 LATE(snd_mixer_free)(_outputMixerHandle); |
| 180 if (errVal < 0) | 167 if (errVal < 0) { |
| 181 { | 168 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 182 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 169 " Error freeing playout mixer: %s", |
| 183 " Error freeing playout mixer: %s", | 170 LATE(snd_strerror)(errVal)); |
| 184 LATE(snd_strerror)(errVal)); | 171 } |
| 185 } | 172 errVal = LATE(snd_mixer_detach)(_outputMixerHandle, _outputMixerStr); |
| 186 errVal = LATE(snd_mixer_detach)(_outputMixerHandle, _outputMixerStr); | 173 if (errVal < 0) { |
| 187 if (errVal < 0) | 174 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 188 { | 175 " Error detachinging playout mixer: %s", |
| 189 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 176 LATE(snd_strerror)(errVal)); |
| 190 " Error detachinging playout mixer: %s", | 177 } |
| 191 LATE(snd_strerror)(errVal)); | 178 errVal = LATE(snd_mixer_close)(_outputMixerHandle); |
| 192 } | 179 if (errVal < 0) { |
| 193 errVal = LATE(snd_mixer_close)(_outputMixerHandle); | 180 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 194 if (errVal < 0) | 181 " Error snd_mixer_close(handleMixer) errVal=%d", |
| 195 { | 182 errVal); |
| 196 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 183 } |
| 197 " Error snd_mixer_close(handleMixer) errVal=%d", | |
| 198 errVal); | |
| 199 } | |
| 200 } | 184 } |
| 201 _outputMixerHandle = NULL; | 185 _outputMixerHandle = nullptr; |
| 202 _outputMixerElement = NULL; | 186 _outputMixerElement = nullptr; |
| 203 | 187 |
| 204 errVal = LATE(snd_mixer_open)(&_outputMixerHandle, 0); | 188 errVal = LATE(snd_mixer_open)(&_outputMixerHandle, 0); |
| 205 if (errVal < 0) | 189 if (errVal < 0) |
| 206 { | 190 { |
| 207 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 191 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 208 "snd_mixer_open(&_outputMixerHandle, 0) - error"); | 192 "snd_mixer_open(&_outputMixerHandle, 0) - error"); |
| 209 return -1; | 193 return -1; |
| 210 } | 194 } |
| 211 | 195 |
| 212 char controlName[kAdmMaxDeviceNameSize] = { 0 }; | 196 char controlName[kAdmMaxDeviceNameSize] = { 0 }; |
| 213 GetControlName(controlName, deviceName); | 197 GetControlName(controlName, deviceName); |
| 214 | 198 |
| 215 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 199 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 216 " snd_mixer_attach(_outputMixerHandle, %s)", controlName); | 200 " snd_mixer_attach(_outputMixerHandle, %s)", controlName); |
| 217 | 201 |
| 218 errVal = LATE(snd_mixer_attach)(_outputMixerHandle, controlName); | 202 errVal = LATE(snd_mixer_attach)(_outputMixerHandle, controlName); |
| 219 if (errVal < 0) | 203 if (errVal < 0) |
| 220 { | 204 { |
| 221 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 205 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 222 " snd_mixer_attach(_outputMixerHandle, %s) error: %s", | 206 " snd_mixer_attach(_outputMixerHandle, %s) error: %s", |
| 223 controlName, LATE(snd_strerror)(errVal)); | 207 controlName, LATE(snd_strerror)(errVal)); |
| 224 _outputMixerHandle = NULL; | 208 _outputMixerHandle = nullptr; |
| 225 return -1; | 209 return -1; |
| 226 } | 210 } |
| 227 strcpy(_outputMixerStr, controlName); | 211 strcpy(_outputMixerStr, controlName); |
| 228 | 212 |
| 229 errVal = LATE(snd_mixer_selem_register)(_outputMixerHandle, NULL, NULL); | 213 errVal = |
| 214 LATE(snd_mixer_selem_register)(_outputMixerHandle, nullptr, nullptr); |
| 230 if (errVal < 0) | 215 if (errVal < 0) |
| 231 { | 216 { |
| 232 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 217 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 233 " snd_mixer_selem_register(_outputMixerHandle," | 218 " snd_mixer_selem_register(_outputMixerHandle," |
| 234 " NULL, NULL), error: %s", | 219 " null, null), error: %s", |
| 235 LATE(snd_strerror)(errVal)); | 220 LATE(snd_strerror)(errVal)); |
| 236 _outputMixerHandle = NULL; | 221 _outputMixerHandle = nullptr; |
| 237 return -1; | 222 return -1; |
| 238 } | 223 } |
| 239 | 224 |
| 240 // Load and find the proper mixer element | 225 // Load and find the proper mixer element |
| 241 if (LoadSpeakerMixerElement() < 0) | 226 if (LoadSpeakerMixerElement() < 0) |
| 242 { | 227 { |
| 243 return -1; | 228 return -1; |
| 244 } | 229 } |
| 245 | 230 |
| 246 if (_outputMixerHandle != NULL) | 231 if (_outputMixerHandle != nullptr) { |
| 247 { | 232 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 248 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 233 " the output mixer device is now open (0x%x)", |
| 249 " the output mixer device is now open (0x%x)", | 234 _outputMixerHandle); |
| 250 _outputMixerHandle); | |
| 251 } | 235 } |
| 252 | 236 |
| 253 return 0; | 237 return 0; |
| 254 } | 238 } |
| 255 | 239 |
| 256 int32_t AudioMixerManagerLinuxALSA::OpenMicrophone(char *deviceName) | 240 int32_t AudioMixerManagerLinuxALSA::OpenMicrophone(char *deviceName) |
| 257 { | 241 { |
| 258 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 242 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 259 "AudioMixerManagerLinuxALSA::OpenMicrophone(name=%s)", | 243 "AudioMixerManagerLinuxALSA::OpenMicrophone(name=%s)", |
| 260 deviceName); | 244 deviceName); |
| 261 | 245 |
| 262 CriticalSectionScoped lock(&_critSect); | 246 CriticalSectionScoped lock(&_critSect); |
| 263 | 247 |
| 264 int errVal = 0; | 248 int errVal = 0; |
| 265 | 249 |
| 266 // Close any existing input mixer handle | 250 // Close any existing input mixer handle |
| 267 // | 251 // |
| 268 if (_inputMixerHandle != NULL) | 252 if (_inputMixerHandle != nullptr) { |
| 269 { | 253 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Closing record mixer"); |
| 270 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | |
| 271 "Closing record mixer"); | |
| 272 | 254 |
| 273 LATE(snd_mixer_free)(_inputMixerHandle); | 255 LATE(snd_mixer_free)(_inputMixerHandle); |
| 274 if (errVal < 0) | 256 if (errVal < 0) { |
| 275 { | 257 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 276 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 258 " Error freeing record mixer: %s", |
| 277 " Error freeing record mixer: %s", | 259 LATE(snd_strerror)(errVal)); |
| 278 LATE(snd_strerror)(errVal)); | 260 } |
| 279 } | 261 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Closing record mixer"); |
| 280 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | |
| 281 "Closing record mixer"); | |
| 282 | 262 |
| 283 errVal = LATE(snd_mixer_detach)(_inputMixerHandle, _inputMixerStr); | 263 errVal = LATE(snd_mixer_detach)(_inputMixerHandle, _inputMixerStr); |
| 284 if (errVal < 0) | 264 if (errVal < 0) { |
| 285 { | 265 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 286 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 266 " Error detachinging record mixer: %s", |
| 287 " Error detachinging record mixer: %s", | 267 LATE(snd_strerror)(errVal)); |
| 288 LATE(snd_strerror)(errVal)); | 268 } |
| 289 } | 269 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Closing record mixer"); |
| 290 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | |
| 291 "Closing record mixer"); | |
| 292 | 270 |
| 293 errVal = LATE(snd_mixer_close)(_inputMixerHandle); | 271 errVal = LATE(snd_mixer_close)(_inputMixerHandle); |
| 294 if (errVal < 0) | 272 if (errVal < 0) { |
| 295 { | 273 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 296 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 274 " Error snd_mixer_close(handleMixer) errVal=%d", |
| 297 " Error snd_mixer_close(handleMixer) errVal=%d", | 275 errVal); |
| 298 errVal); | 276 } |
| 299 } | 277 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Closing record mixer"); |
| 300 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | |
| 301 "Closing record mixer"); | |
| 302 } | 278 } |
| 303 _inputMixerHandle = NULL; | 279 _inputMixerHandle = nullptr; |
| 304 _inputMixerElement = NULL; | 280 _inputMixerElement = nullptr; |
| 305 | 281 |
| 306 errVal = LATE(snd_mixer_open)(&_inputMixerHandle, 0); | 282 errVal = LATE(snd_mixer_open)(&_inputMixerHandle, 0); |
| 307 if (errVal < 0) | 283 if (errVal < 0) |
| 308 { | 284 { |
| 309 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 285 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 310 " snd_mixer_open(&_inputMixerHandle, 0) - error"); | 286 " snd_mixer_open(&_inputMixerHandle, 0) - error"); |
| 311 return -1; | 287 return -1; |
| 312 } | 288 } |
| 313 | 289 |
| 314 char controlName[kAdmMaxDeviceNameSize] = { 0 }; | 290 char controlName[kAdmMaxDeviceNameSize] = { 0 }; |
| 315 GetControlName(controlName, deviceName); | 291 GetControlName(controlName, deviceName); |
| 316 | 292 |
| 317 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 293 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 318 " snd_mixer_attach(_inputMixerHandle, %s)", controlName); | 294 " snd_mixer_attach(_inputMixerHandle, %s)", controlName); |
| 319 | 295 |
| 320 errVal = LATE(snd_mixer_attach)(_inputMixerHandle, controlName); | 296 errVal = LATE(snd_mixer_attach)(_inputMixerHandle, controlName); |
| 321 if (errVal < 0) | 297 if (errVal < 0) |
| 322 { | 298 { |
| 323 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 299 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 324 " snd_mixer_attach(_inputMixerHandle, %s) error: %s", | 300 " snd_mixer_attach(_inputMixerHandle, %s) error: %s", |
| 325 controlName, LATE(snd_strerror)(errVal)); | 301 controlName, LATE(snd_strerror)(errVal)); |
| 326 | 302 |
| 327 _inputMixerHandle = NULL; | 303 _inputMixerHandle = nullptr; |
| 328 return -1; | 304 return -1; |
| 329 } | 305 } |
| 330 strcpy(_inputMixerStr, controlName); | 306 strcpy(_inputMixerStr, controlName); |
| 331 | 307 |
| 332 errVal = LATE(snd_mixer_selem_register)(_inputMixerHandle, NULL, NULL); | 308 errVal = |
| 309 LATE(snd_mixer_selem_register)(_inputMixerHandle, nullptr, nullptr); |
| 333 if (errVal < 0) | 310 if (errVal < 0) |
| 334 { | 311 { |
| 335 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 312 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 336 " snd_mixer_selem_register(_inputMixerHandle," | 313 " snd_mixer_selem_register(_inputMixerHandle," |
| 337 " NULL, NULL), error: %s", | 314 " null, null), error: %s", |
| 338 LATE(snd_strerror)(errVal)); | 315 LATE(snd_strerror)(errVal)); |
| 339 | 316 |
| 340 _inputMixerHandle = NULL; | 317 _inputMixerHandle = nullptr; |
| 341 return -1; | 318 return -1; |
| 342 } | 319 } |
| 343 // Load and find the proper mixer element | 320 // Load and find the proper mixer element |
| 344 if (LoadMicMixerElement() < 0) | 321 if (LoadMicMixerElement() < 0) |
| 345 { | 322 { |
| 346 return -1; | 323 return -1; |
| 347 } | 324 } |
| 348 | 325 |
| 349 if (_inputMixerHandle != NULL) | 326 if (_inputMixerHandle != nullptr) { |
| 350 { | 327 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 351 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 328 " the input mixer device is now open (0x%x)", |
| 352 " the input mixer device is now open (0x%x)", | 329 _inputMixerHandle); |
| 353 _inputMixerHandle); | |
| 354 } | 330 } |
| 355 | 331 |
| 356 return 0; | 332 return 0; |
| 357 } | 333 } |
| 358 | 334 |
| 359 bool AudioMixerManagerLinuxALSA::SpeakerIsInitialized() const | 335 bool AudioMixerManagerLinuxALSA::SpeakerIsInitialized() const |
| 360 { | 336 { |
| 361 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); | 337 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); |
| 362 | 338 |
| 363 return (_outputMixerHandle != NULL); | 339 return (_outputMixerHandle != nullptr); |
| 364 } | 340 } |
| 365 | 341 |
| 366 bool AudioMixerManagerLinuxALSA::MicrophoneIsInitialized() const | 342 bool AudioMixerManagerLinuxALSA::MicrophoneIsInitialized() const |
| 367 { | 343 { |
| 368 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", | 344 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", |
| 369 __FUNCTION__); | 345 __FUNCTION__); |
| 370 | 346 |
| 371 return (_inputMixerHandle != NULL); | 347 return (_inputMixerHandle != nullptr); |
| 372 } | 348 } |
| 373 | 349 |
| 374 int32_t AudioMixerManagerLinuxALSA::SetSpeakerVolume( | 350 int32_t AudioMixerManagerLinuxALSA::SetSpeakerVolume( |
| 375 uint32_t volume) | 351 uint32_t volume) |
| 376 { | 352 { |
| 377 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 353 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 378 "AudioMixerManagerLinuxALSA::SetSpeakerVolume(volume=%u)", | 354 "AudioMixerManagerLinuxALSA::SetSpeakerVolume(volume=%u)", |
| 379 volume); | 355 volume); |
| 380 | 356 |
| 381 CriticalSectionScoped lock(&_critSect); | 357 CriticalSectionScoped lock(&_critSect); |
| 382 | 358 |
| 383 if (_outputMixerElement == NULL) | 359 if (_outputMixerElement == nullptr) { |
| 384 { | 360 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 385 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 361 " no avaliable output mixer element exists"); |
| 386 " no avaliable output mixer element exists"); | 362 return -1; |
| 387 return -1; | |
| 388 } | 363 } |
| 389 | 364 |
| 390 int errVal = | 365 int errVal = |
| 391 LATE(snd_mixer_selem_set_playback_volume_all)(_outputMixerElement, | 366 LATE(snd_mixer_selem_set_playback_volume_all)(_outputMixerElement, |
| 392 volume); | 367 volume); |
| 393 if (errVal < 0) | 368 if (errVal < 0) |
| 394 { | 369 { |
| 395 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 370 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 396 " Error changing master volume: %s", | 371 " Error changing master volume: %s", |
| 397 LATE(snd_strerror)(errVal)); | 372 LATE(snd_strerror)(errVal)); |
| 398 return -1; | 373 return -1; |
| 399 } | 374 } |
| 400 | 375 |
| 401 return (0); | 376 return (0); |
| 402 } | 377 } |
| 403 | 378 |
| 404 int32_t AudioMixerManagerLinuxALSA::SpeakerVolume( | 379 int32_t AudioMixerManagerLinuxALSA::SpeakerVolume( |
| 405 uint32_t& volume) const | 380 uint32_t& volume) const |
| 406 { | 381 { |
| 407 | 382 if (_outputMixerElement == nullptr) { |
| 408 if (_outputMixerElement == NULL) | 383 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 409 { | 384 " no avaliable output mixer element exists"); |
| 410 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 385 return -1; |
| 411 " no avaliable output mixer element exists"); | |
| 412 return -1; | |
| 413 } | 386 } |
| 414 | 387 |
| 415 long int vol(0); | 388 long int vol(0); |
| 416 | 389 |
| 417 int | 390 int |
| 418 errVal = LATE(snd_mixer_selem_get_playback_volume)( | 391 errVal = LATE(snd_mixer_selem_get_playback_volume)( |
| 419 _outputMixerElement, | 392 _outputMixerElement, |
| 420 (snd_mixer_selem_channel_id_t) 0, | 393 (snd_mixer_selem_channel_id_t) 0, |
| 421 &vol); | 394 &vol); |
| 422 if (errVal < 0) | 395 if (errVal < 0) |
| 423 { | 396 { |
| 424 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 397 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 425 "Error getting outputvolume: %s", | 398 "Error getting outputvolume: %s", |
| 426 LATE(snd_strerror)(errVal)); | 399 LATE(snd_strerror)(errVal)); |
| 427 return -1; | 400 return -1; |
| 428 } | 401 } |
| 429 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 402 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 430 " AudioMixerManagerLinuxALSA::SpeakerVolume() => vol=%i", | 403 " AudioMixerManagerLinuxALSA::SpeakerVolume() => vol=%i", |
| 431 vol); | 404 vol); |
| 432 | 405 |
| 433 volume = static_cast<uint32_t> (vol); | 406 volume = static_cast<uint32_t> (vol); |
| 434 | 407 |
| 435 return 0; | 408 return 0; |
| 436 } | 409 } |
| 437 | 410 |
| 438 int32_t AudioMixerManagerLinuxALSA::MaxSpeakerVolume( | 411 int32_t AudioMixerManagerLinuxALSA::MaxSpeakerVolume( |
| 439 uint32_t& maxVolume) const | 412 uint32_t& maxVolume) const |
| 440 { | 413 { |
| 441 | 414 if (_outputMixerElement == nullptr) { |
| 442 if (_outputMixerElement == NULL) | 415 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 443 { | 416 " no avilable output mixer element exists"); |
| 444 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 417 return -1; |
| 445 " no avilable output mixer element exists"); | |
| 446 return -1; | |
| 447 } | 418 } |
| 448 | 419 |
| 449 long int minVol(0); | 420 long int minVol(0); |
| 450 long int maxVol(0); | 421 long int maxVol(0); |
| 451 | 422 |
| 452 int errVal = | 423 int errVal = |
| 453 LATE(snd_mixer_selem_get_playback_volume_range)(_outputMixerElement, | 424 LATE(snd_mixer_selem_get_playback_volume_range)(_outputMixerElement, |
| 454 &minVol, &maxVol); | 425 &minVol, &maxVol); |
| 455 | 426 |
| 456 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 427 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 457 " Playout hardware volume range, min: %d, max: %d", | 428 " Playout hardware volume range, min: %d, max: %d", |
| 458 minVol, maxVol); | 429 minVol, maxVol); |
| 459 | 430 |
| 460 if (maxVol <= minVol) | 431 if (maxVol <= minVol) |
| 461 { | 432 { |
| 462 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 433 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 463 " Error getting get_playback_volume_range: %s", | 434 " Error getting get_playback_volume_range: %s", |
| 464 LATE(snd_strerror)(errVal)); | 435 LATE(snd_strerror)(errVal)); |
| 465 } | 436 } |
| 466 | 437 |
| 467 maxVolume = static_cast<uint32_t> (maxVol); | 438 maxVolume = static_cast<uint32_t> (maxVol); |
| 468 | 439 |
| 469 return 0; | 440 return 0; |
| 470 } | 441 } |
| 471 | 442 |
| 472 int32_t AudioMixerManagerLinuxALSA::MinSpeakerVolume( | 443 int32_t AudioMixerManagerLinuxALSA::MinSpeakerVolume( |
| 473 uint32_t& minVolume) const | 444 uint32_t& minVolume) const |
| 474 { | 445 { |
| 475 | 446 if (_outputMixerElement == nullptr) { |
| 476 if (_outputMixerElement == NULL) | 447 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 477 { | 448 " no avaliable output mixer element exists"); |
| 478 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 449 return -1; |
| 479 " no avaliable output mixer element exists"); | |
| 480 return -1; | |
| 481 } | 450 } |
| 482 | 451 |
| 483 long int minVol(0); | 452 long int minVol(0); |
| 484 long int maxVol(0); | 453 long int maxVol(0); |
| 485 | 454 |
| 486 int errVal = | 455 int errVal = |
| 487 LATE(snd_mixer_selem_get_playback_volume_range)(_outputMixerElement, | 456 LATE(snd_mixer_selem_get_playback_volume_range)(_outputMixerElement, |
| 488 &minVol, &maxVol); | 457 &minVol, &maxVol); |
| 489 | 458 |
| 490 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 459 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 507 // they were therefore not added | 476 // they were therefore not added |
| 508 /* | 477 /* |
| 509 // ---------------------------------------------------------------------------- | 478 // ---------------------------------------------------------------------------- |
| 510 // SetMaxSpeakerVolume | 479 // SetMaxSpeakerVolume |
| 511 // ---------------------------------------------------------------------------- | 480 // ---------------------------------------------------------------------------- |
| 512 | 481 |
| 513 int32_t AudioMixerManagerLinuxALSA::SetMaxSpeakerVolume( | 482 int32_t AudioMixerManagerLinuxALSA::SetMaxSpeakerVolume( |
| 514 uint32_t maxVolume) | 483 uint32_t maxVolume) |
| 515 { | 484 { |
| 516 | 485 |
| 517 if (_outputMixerElement == NULL) | 486 if (_outputMixerElement == nullptr) |
| 518 { | 487 { |
| 519 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 488 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 520 " no avaliable output mixer element exists"); | 489 " no avaliable output mixer element exists"); |
| 521 return -1; | 490 return -1; |
| 522 } | 491 } |
| 523 | 492 |
| 524 long int minVol(0); | 493 long int minVol(0); |
| 525 long int maxVol(0); | 494 long int maxVol(0); |
| 526 | 495 |
| 527 int errVal = snd_mixer_selem_get_playback_volume_range( | 496 int errVal = snd_mixer_selem_get_playback_volume_range( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 548 } | 517 } |
| 549 | 518 |
| 550 // ---------------------------------------------------------------------------- | 519 // ---------------------------------------------------------------------------- |
| 551 // SetMinSpeakerVolume | 520 // SetMinSpeakerVolume |
| 552 // ---------------------------------------------------------------------------- | 521 // ---------------------------------------------------------------------------- |
| 553 | 522 |
| 554 int32_t AudioMixerManagerLinuxALSA::SetMinSpeakerVolume( | 523 int32_t AudioMixerManagerLinuxALSA::SetMinSpeakerVolume( |
| 555 uint32_t minVolume) | 524 uint32_t minVolume) |
| 556 { | 525 { |
| 557 | 526 |
| 558 if (_outputMixerElement == NULL) | 527 if (_outputMixerElement == nullptr) |
| 559 { | 528 { |
| 560 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 529 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 561 " no avaliable output mixer element exists"); | 530 " no avaliable output mixer element exists"); |
| 562 return -1; | 531 return -1; |
| 563 } | 532 } |
| 564 | 533 |
| 565 long int minVol(0); | 534 long int minVol(0); |
| 566 long int maxVol(0); | 535 long int maxVol(0); |
| 567 | 536 |
| 568 int errVal = snd_mixer_selem_get_playback_volume_range( | 537 int errVal = snd_mixer_selem_get_playback_volume_range( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 585 return -1; | 554 return -1; |
| 586 } | 555 } |
| 587 | 556 |
| 588 return 0; | 557 return 0; |
| 589 } | 558 } |
| 590 */ | 559 */ |
| 591 | 560 |
| 592 int32_t AudioMixerManagerLinuxALSA::SpeakerVolumeStepSize( | 561 int32_t AudioMixerManagerLinuxALSA::SpeakerVolumeStepSize( |
| 593 uint16_t& stepSize) const | 562 uint16_t& stepSize) const |
| 594 { | 563 { |
| 595 | 564 if (_outputMixerHandle == nullptr) { |
| 596 if (_outputMixerHandle == NULL) | 565 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 597 { | 566 " no avaliable output mixer exists"); |
| 598 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 567 return -1; |
| 599 " no avaliable output mixer exists"); | |
| 600 return -1; | |
| 601 } | 568 } |
| 602 | 569 |
| 603 // The step size is always 1 for ALSA | 570 // The step size is always 1 for ALSA |
| 604 stepSize = 1; | 571 stepSize = 1; |
| 605 | 572 |
| 606 return 0; | 573 return 0; |
| 607 } | 574 } |
| 608 | 575 |
| 609 int32_t AudioMixerManagerLinuxALSA::SpeakerVolumeIsAvailable( | 576 int32_t AudioMixerManagerLinuxALSA::SpeakerVolumeIsAvailable( |
| 610 bool& available) | 577 bool& available) |
| 611 { | 578 { |
| 612 if (_outputMixerElement == NULL) | 579 if (_outputMixerElement == nullptr) { |
| 613 { | 580 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 614 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 581 " no avaliable output mixer element exists"); |
| 615 " no avaliable output mixer element exists"); | 582 return -1; |
| 616 return -1; | |
| 617 } | 583 } |
| 618 | 584 |
| 619 available = LATE(snd_mixer_selem_has_playback_volume)(_outputMixerElement); | 585 available = LATE(snd_mixer_selem_has_playback_volume)(_outputMixerElement); |
| 620 | 586 |
| 621 return 0; | 587 return 0; |
| 622 } | 588 } |
| 623 | 589 |
| 624 int32_t AudioMixerManagerLinuxALSA::SpeakerMuteIsAvailable( | 590 int32_t AudioMixerManagerLinuxALSA::SpeakerMuteIsAvailable( |
| 625 bool& available) | 591 bool& available) |
| 626 { | 592 { |
| 627 if (_outputMixerElement == NULL) | 593 if (_outputMixerElement == nullptr) { |
| 628 { | 594 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 629 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 595 " no avaliable output mixer element exists"); |
| 630 " no avaliable output mixer element exists"); | 596 return -1; |
| 631 return -1; | |
| 632 } | 597 } |
| 633 | 598 |
| 634 available = LATE(snd_mixer_selem_has_playback_switch)(_outputMixerElement); | 599 available = LATE(snd_mixer_selem_has_playback_switch)(_outputMixerElement); |
| 635 | 600 |
| 636 return 0; | 601 return 0; |
| 637 } | 602 } |
| 638 | 603 |
| 639 int32_t AudioMixerManagerLinuxALSA::SetSpeakerMute(bool enable) | 604 int32_t AudioMixerManagerLinuxALSA::SetSpeakerMute(bool enable) |
| 640 { | 605 { |
| 641 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 606 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 642 "AudioMixerManagerLinuxALSA::SetSpeakerMute(enable=%u)", | 607 "AudioMixerManagerLinuxALSA::SetSpeakerMute(enable=%u)", |
| 643 enable); | 608 enable); |
| 644 | 609 |
| 645 CriticalSectionScoped lock(&_critSect); | 610 CriticalSectionScoped lock(&_critSect); |
| 646 | 611 |
| 647 if (_outputMixerElement == NULL) | 612 if (_outputMixerElement == nullptr) { |
| 648 { | 613 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 649 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 614 " no avaliable output mixer element exists"); |
| 650 " no avaliable output mixer element exists"); | 615 return -1; |
| 651 return -1; | |
| 652 } | 616 } |
| 653 | 617 |
| 654 // Ensure that the selected speaker destination has a valid mute control. | 618 // Ensure that the selected speaker destination has a valid mute control. |
| 655 bool available(false); | 619 bool available(false); |
| 656 SpeakerMuteIsAvailable(available); | 620 SpeakerMuteIsAvailable(available); |
| 657 if (!available) | 621 if (!available) |
| 658 { | 622 { |
| 659 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 623 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 660 " it is not possible to mute the speaker"); | 624 " it is not possible to mute the speaker"); |
| 661 return -1; | 625 return -1; |
| 662 } | 626 } |
| 663 | 627 |
| 664 // Note value = 0 (off) means muted | 628 // Note value = 0 (off) means muted |
| 665 int errVal = | 629 int errVal = |
| 666 LATE(snd_mixer_selem_set_playback_switch_all)(_outputMixerElement, | 630 LATE(snd_mixer_selem_set_playback_switch_all)(_outputMixerElement, |
| 667 !enable); | 631 !enable); |
| 668 if (errVal < 0) | 632 if (errVal < 0) |
| 669 { | 633 { |
| 670 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 634 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 671 " Error setting playback switch: %s", | 635 " Error setting playback switch: %s", |
| 672 LATE(snd_strerror)(errVal)); | 636 LATE(snd_strerror)(errVal)); |
| 673 return -1; | 637 return -1; |
| 674 } | 638 } |
| 675 | 639 |
| 676 return (0); | 640 return (0); |
| 677 } | 641 } |
| 678 | 642 |
| 679 int32_t AudioMixerManagerLinuxALSA::SpeakerMute(bool& enabled) const | 643 int32_t AudioMixerManagerLinuxALSA::SpeakerMute(bool& enabled) const |
| 680 { | 644 { |
| 681 | 645 if (_outputMixerElement == nullptr) { |
| 682 if (_outputMixerElement == NULL) | 646 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 683 { | 647 " no avaliable output mixer exists"); |
| 684 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 648 return -1; |
| 685 " no avaliable output mixer exists"); | |
| 686 return -1; | |
| 687 } | 649 } |
| 688 | 650 |
| 689 // Ensure that the selected speaker destination has a valid mute control. | 651 // Ensure that the selected speaker destination has a valid mute control. |
| 690 bool available = | 652 bool available = |
| 691 LATE(snd_mixer_selem_has_playback_switch)(_outputMixerElement); | 653 LATE(snd_mixer_selem_has_playback_switch)(_outputMixerElement); |
| 692 if (!available) | 654 if (!available) |
| 693 { | 655 { |
| 694 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 656 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 695 " it is not possible to mute the speaker"); | 657 " it is not possible to mute the speaker"); |
| 696 return -1; | 658 return -1; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 715 | 677 |
| 716 // Note value = 0 (off) means muted | 678 // Note value = 0 (off) means muted |
| 717 enabled = (bool) !value; | 679 enabled = (bool) !value; |
| 718 | 680 |
| 719 return 0; | 681 return 0; |
| 720 } | 682 } |
| 721 | 683 |
| 722 int32_t AudioMixerManagerLinuxALSA::MicrophoneMuteIsAvailable( | 684 int32_t AudioMixerManagerLinuxALSA::MicrophoneMuteIsAvailable( |
| 723 bool& available) | 685 bool& available) |
| 724 { | 686 { |
| 725 if (_inputMixerElement == NULL) | 687 if (_inputMixerElement == nullptr) { |
| 726 { | 688 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 727 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 689 " no avaliable input mixer element exists"); |
| 728 " no avaliable input mixer element exists"); | 690 return -1; |
| 729 return -1; | |
| 730 } | 691 } |
| 731 | 692 |
| 732 available = LATE(snd_mixer_selem_has_capture_switch)(_inputMixerElement); | 693 available = LATE(snd_mixer_selem_has_capture_switch)(_inputMixerElement); |
| 733 return 0; | 694 return 0; |
| 734 } | 695 } |
| 735 | 696 |
| 736 int32_t AudioMixerManagerLinuxALSA::SetMicrophoneMute(bool enable) | 697 int32_t AudioMixerManagerLinuxALSA::SetMicrophoneMute(bool enable) |
| 737 { | 698 { |
| 738 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 699 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 739 "AudioMixerManagerLinuxALSA::SetMicrophoneMute(enable=%u)", | 700 "AudioMixerManagerLinuxALSA::SetMicrophoneMute(enable=%u)", |
| 740 enable); | 701 enable); |
| 741 | 702 |
| 742 CriticalSectionScoped lock(&_critSect); | 703 CriticalSectionScoped lock(&_critSect); |
| 743 | 704 |
| 744 if (_inputMixerElement == NULL) | 705 if (_inputMixerElement == nullptr) { |
| 745 { | 706 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 746 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 707 " no avaliable input mixer element exists"); |
| 747 " no avaliable input mixer element exists"); | 708 return -1; |
| 748 return -1; | |
| 749 } | 709 } |
| 750 | 710 |
| 751 // Ensure that the selected microphone destination has a valid mute control. | 711 // Ensure that the selected microphone destination has a valid mute control. |
| 752 bool available(false); | 712 bool available(false); |
| 753 MicrophoneMuteIsAvailable(available); | 713 MicrophoneMuteIsAvailable(available); |
| 754 if (!available) | 714 if (!available) |
| 755 { | 715 { |
| 756 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 716 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 757 " it is not possible to mute the microphone"); | 717 " it is not possible to mute the microphone"); |
| 758 return -1; | 718 return -1; |
| 759 } | 719 } |
| 760 | 720 |
| 761 // Note value = 0 (off) means muted | 721 // Note value = 0 (off) means muted |
| 762 int errVal = | 722 int errVal = |
| 763 LATE(snd_mixer_selem_set_capture_switch_all)(_inputMixerElement, | 723 LATE(snd_mixer_selem_set_capture_switch_all)(_inputMixerElement, |
| 764 !enable); | 724 !enable); |
| 765 if (errVal < 0) | 725 if (errVal < 0) |
| 766 { | 726 { |
| 767 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 727 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 768 " Error setting capture switch: %s", | 728 " Error setting capture switch: %s", |
| 769 LATE(snd_strerror)(errVal)); | 729 LATE(snd_strerror)(errVal)); |
| 770 return -1; | 730 return -1; |
| 771 } | 731 } |
| 772 | 732 |
| 773 return (0); | 733 return (0); |
| 774 } | 734 } |
| 775 | 735 |
| 776 int32_t AudioMixerManagerLinuxALSA::MicrophoneMute(bool& enabled) const | 736 int32_t AudioMixerManagerLinuxALSA::MicrophoneMute(bool& enabled) const |
| 777 { | 737 { |
| 778 | 738 if (_inputMixerElement == nullptr) { |
| 779 if (_inputMixerElement == NULL) | 739 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 780 { | 740 " no avaliable input mixer exists"); |
| 781 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 741 return -1; |
| 782 " no avaliable input mixer exists"); | |
| 783 return -1; | |
| 784 } | 742 } |
| 785 | 743 |
| 786 // Ensure that the selected microphone destination has a valid mute control. | 744 // Ensure that the selected microphone destination has a valid mute control. |
| 787 bool available = | 745 bool available = |
| 788 LATE(snd_mixer_selem_has_capture_switch)(_inputMixerElement); | 746 LATE(snd_mixer_selem_has_capture_switch)(_inputMixerElement); |
| 789 if (!available) | 747 if (!available) |
| 790 { | 748 { |
| 791 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 749 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 792 " it is not possible to mute the microphone"); | 750 " it is not possible to mute the microphone"); |
| 793 return -1; | 751 return -1; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 812 | 770 |
| 813 // Note value = 0 (off) means muted | 771 // Note value = 0 (off) means muted |
| 814 enabled = (bool) !value; | 772 enabled = (bool) !value; |
| 815 | 773 |
| 816 return 0; | 774 return 0; |
| 817 } | 775 } |
| 818 | 776 |
| 819 int32_t AudioMixerManagerLinuxALSA::MicrophoneBoostIsAvailable( | 777 int32_t AudioMixerManagerLinuxALSA::MicrophoneBoostIsAvailable( |
| 820 bool& available) | 778 bool& available) |
| 821 { | 779 { |
| 822 if (_inputMixerHandle == NULL) | 780 if (_inputMixerHandle == nullptr) { |
| 823 { | 781 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 824 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 782 " no avaliable input mixer exists"); |
| 825 " no avaliable input mixer exists"); | 783 return -1; |
| 826 return -1; | |
| 827 } | 784 } |
| 828 | 785 |
| 829 // Microphone boost cannot be enabled through ALSA Simple Mixer Interface | 786 // Microphone boost cannot be enabled through ALSA Simple Mixer Interface |
| 830 available = false; | 787 available = false; |
| 831 | 788 |
| 832 return 0; | 789 return 0; |
| 833 } | 790 } |
| 834 | 791 |
| 835 int32_t AudioMixerManagerLinuxALSA::SetMicrophoneBoost(bool enable) | 792 int32_t AudioMixerManagerLinuxALSA::SetMicrophoneBoost(bool enable) |
| 836 { | 793 { |
| 837 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 794 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 838 "AudioMixerManagerLinuxALSA::SetMicrophoneBoost(enable=%u)", | 795 "AudioMixerManagerLinuxALSA::SetMicrophoneBoost(enable=%u)", |
| 839 enable); | 796 enable); |
| 840 | 797 |
| 841 CriticalSectionScoped lock(&_critSect); | 798 CriticalSectionScoped lock(&_critSect); |
| 842 | 799 |
| 843 if (_inputMixerHandle == NULL) | 800 if (_inputMixerHandle == nullptr) { |
| 844 { | 801 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 845 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 802 " no avaliable input mixer exists"); |
| 846 " no avaliable input mixer exists"); | 803 return -1; |
| 847 return -1; | |
| 848 } | 804 } |
| 849 | 805 |
| 850 // Ensure that the selected microphone destination has a valid mute control. | 806 // Ensure that the selected microphone destination has a valid mute control. |
| 851 bool available(false); | 807 bool available(false); |
| 852 MicrophoneMuteIsAvailable(available); | 808 MicrophoneMuteIsAvailable(available); |
| 853 if (!available) | 809 if (!available) |
| 854 { | 810 { |
| 855 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 811 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 856 " it is not possible to enable microphone boost"); | 812 " it is not possible to enable microphone boost"); |
| 857 return -1; | 813 return -1; |
| 858 } | 814 } |
| 859 | 815 |
| 860 // It is assumed that the call above fails! | 816 // It is assumed that the call above fails! |
| 861 | 817 |
| 862 return (0); | 818 return (0); |
| 863 } | 819 } |
| 864 | 820 |
| 865 int32_t AudioMixerManagerLinuxALSA::MicrophoneBoost(bool& enabled) const | 821 int32_t AudioMixerManagerLinuxALSA::MicrophoneBoost(bool& enabled) const |
| 866 { | 822 { |
| 867 | 823 if (_inputMixerHandle == nullptr) { |
| 868 if (_inputMixerHandle == NULL) | 824 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 869 { | 825 " no avaliable input mixer exists"); |
| 870 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 826 return -1; |
| 871 " no avaliable input mixer exists"); | |
| 872 return -1; | |
| 873 } | 827 } |
| 874 | 828 |
| 875 // Microphone boost cannot be enabled on this platform! | 829 // Microphone boost cannot be enabled on this platform! |
| 876 enabled = false; | 830 enabled = false; |
| 877 | 831 |
| 878 return 0; | 832 return 0; |
| 879 } | 833 } |
| 880 | 834 |
| 881 int32_t AudioMixerManagerLinuxALSA::MicrophoneVolumeIsAvailable( | 835 int32_t AudioMixerManagerLinuxALSA::MicrophoneVolumeIsAvailable( |
| 882 bool& available) | 836 bool& available) |
| 883 { | 837 { |
| 884 if (_inputMixerElement == NULL) | 838 if (_inputMixerElement == nullptr) { |
| 885 { | 839 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 886 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 840 " no avaliable input mixer element exists"); |
| 887 " no avaliable input mixer element exists"); | 841 return -1; |
| 888 return -1; | |
| 889 } | 842 } |
| 890 | 843 |
| 891 available = LATE(snd_mixer_selem_has_capture_volume)(_inputMixerElement); | 844 available = LATE(snd_mixer_selem_has_capture_volume)(_inputMixerElement); |
| 892 | 845 |
| 893 return 0; | 846 return 0; |
| 894 } | 847 } |
| 895 | 848 |
| 896 int32_t AudioMixerManagerLinuxALSA::SetMicrophoneVolume( | 849 int32_t AudioMixerManagerLinuxALSA::SetMicrophoneVolume( |
| 897 uint32_t volume) | 850 uint32_t volume) |
| 898 { | 851 { |
| 899 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 852 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 900 "AudioMixerManagerLinuxALSA::SetMicrophoneVolume(volume=%u)", | 853 "AudioMixerManagerLinuxALSA::SetMicrophoneVolume(volume=%u)", |
| 901 volume); | 854 volume); |
| 902 | 855 |
| 903 CriticalSectionScoped lock(&_critSect); | 856 CriticalSectionScoped lock(&_critSect); |
| 904 | 857 |
| 905 if (_inputMixerElement == NULL) | 858 if (_inputMixerElement == nullptr) { |
| 906 { | 859 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 907 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 860 " no avaliable input mixer element exists"); |
| 908 " no avaliable input mixer element exists"); | 861 return -1; |
| 909 return -1; | |
| 910 } | 862 } |
| 911 | 863 |
| 912 int | 864 int |
| 913 errVal = | 865 errVal = |
| 914 LATE(snd_mixer_selem_set_capture_volume_all)(_inputMixerElement, | 866 LATE(snd_mixer_selem_set_capture_volume_all)(_inputMixerElement, |
| 915 volume); | 867 volume); |
| 916 if (errVal < 0) | 868 if (errVal < 0) |
| 917 { | 869 { |
| 918 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 870 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 919 " Error changing microphone volume: %s", | 871 " Error changing microphone volume: %s", |
| 920 LATE(snd_strerror)(errVal)); | 872 LATE(snd_strerror)(errVal)); |
| 921 return -1; | 873 return -1; |
| 922 } | 874 } |
| 923 | 875 |
| 924 return (0); | 876 return (0); |
| 925 } | 877 } |
| 926 | 878 |
| 927 // TL: Have done testnig with these but they don't seem reliable and | 879 // TL: Have done testnig with these but they don't seem reliable and |
| 928 // they were therefore not added | 880 // they were therefore not added |
| 929 /* | 881 /* |
| 930 // ---------------------------------------------------------------------------- | 882 // ---------------------------------------------------------------------------- |
| 931 // SetMaxMicrophoneVolume | 883 // SetMaxMicrophoneVolume |
| 932 // ---------------------------------------------------------------------------- | 884 // ---------------------------------------------------------------------------- |
| 933 | 885 |
| 934 int32_t AudioMixerManagerLinuxALSA::SetMaxMicrophoneVolume( | 886 int32_t AudioMixerManagerLinuxALSA::SetMaxMicrophoneVolume( |
| 935 uint32_t maxVolume) | 887 uint32_t maxVolume) |
| 936 { | 888 { |
| 937 | 889 |
| 938 if (_inputMixerElement == NULL) | 890 if (_inputMixerElement == nullptr) |
| 939 { | 891 { |
| 940 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 892 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 941 " no avaliable output mixer element exists"); | 893 " no avaliable output mixer element exists"); |
| 942 return -1; | 894 return -1; |
| 943 } | 895 } |
| 944 | 896 |
| 945 long int minVol(0); | 897 long int minVol(0); |
| 946 long int maxVol(0); | 898 long int maxVol(0); |
| 947 | 899 |
| 948 int errVal = snd_mixer_selem_get_capture_volume_range(_inputMixerElement, | 900 int errVal = snd_mixer_selem_get_capture_volume_range(_inputMixerElement, |
| 949 &minVol, &maxVol); | 901 &minVol, &maxVol); |
| 950 if ((maxVol <= minVol) || (errVal != 0)) | 902 if ((maxVol <= minVol) || (errVal != 0)) |
| 951 { | 903 { |
| 952 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 904 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 953 " Error getting capture volume range: %s", snd_strerror(errVal)); | 905 " Error getting capture volume range: %s", snd_strerror(errVal)); |
| 954 } | 906 } |
| 955 | 907 |
| 956 maxVol = (long int)maxVolume; | 908 maxVol = (long int)maxVolume; |
| 957 printf("min %d max %d", minVol, maxVol); | 909 printf("min %d max %d", minVol, maxVol); |
| 958 errVal = snd_mixer_selem_set_capture_volume_range(_inputMixerElement, minVol, m
axVol); | 910 errVal = snd_mixer_selem_set_capture_volume_range(_inputMixerElement, minVol, |
| 911 maxVol); |
| 959 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 912 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 960 " Capture hardware volume range, min: %d, max: %d", minVol, maxVol); | 913 " Capture hardware volume range, min: %d, max: %d", minVol, maxVol); |
| 961 if (errVal != 0) | 914 if (errVal != 0) |
| 962 { | 915 { |
| 963 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 916 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 964 " Error setting capture volume range: %s", snd_strerror(errVal)); | 917 " Error setting capture volume range: %s", snd_strerror(errVal)); |
| 965 return -1; | 918 return -1; |
| 966 } | 919 } |
| 967 | 920 |
| 968 return 0; | 921 return 0; |
| 969 } | 922 } |
| 970 | 923 |
| 971 // ---------------------------------------------------------------------------- | 924 // ---------------------------------------------------------------------------- |
| 972 // SetMinMicrophoneVolume | 925 // SetMinMicrophoneVolume |
| 973 // ---------------------------------------------------------------------------- | 926 // ---------------------------------------------------------------------------- |
| 974 | 927 |
| 975 int32_t AudioMixerManagerLinuxALSA::SetMinMicrophoneVolume( | 928 int32_t AudioMixerManagerLinuxALSA::SetMinMicrophoneVolume( |
| 976 uint32_t minVolume) | 929 uint32_t minVolume) |
| 977 { | 930 { |
| 978 | 931 |
| 979 if (_inputMixerElement == NULL) | 932 if (_inputMixerElement == nullptr) |
| 980 { | 933 { |
| 981 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 934 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 982 " no avaliable output mixer element exists"); | 935 " no avaliable output mixer element exists"); |
| 983 return -1; | 936 return -1; |
| 984 } | 937 } |
| 985 | 938 |
| 986 long int minVol(0); | 939 long int minVol(0); |
| 987 long int maxVol(0); | 940 long int maxVol(0); |
| 988 | 941 |
| 989 int errVal = snd_mixer_selem_get_capture_volume_range( | 942 int errVal = snd_mixer_selem_get_capture_volume_range( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1008 return -1; | 961 return -1; |
| 1009 } | 962 } |
| 1010 | 963 |
| 1011 return 0; | 964 return 0; |
| 1012 } | 965 } |
| 1013 */ | 966 */ |
| 1014 | 967 |
| 1015 int32_t AudioMixerManagerLinuxALSA::MicrophoneVolume( | 968 int32_t AudioMixerManagerLinuxALSA::MicrophoneVolume( |
| 1016 uint32_t& volume) const | 969 uint32_t& volume) const |
| 1017 { | 970 { |
| 1018 | 971 if (_inputMixerElement == nullptr) { |
| 1019 if (_inputMixerElement == NULL) | 972 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 1020 { | 973 " no avaliable input mixer element exists"); |
| 1021 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 974 return -1; |
| 1022 " no avaliable input mixer element exists"); | |
| 1023 return -1; | |
| 1024 } | 975 } |
| 1025 | 976 |
| 1026 long int vol(0); | 977 long int vol(0); |
| 1027 | 978 |
| 1028 int | 979 int |
| 1029 errVal = | 980 errVal = |
| 1030 LATE(snd_mixer_selem_get_capture_volume)( | 981 LATE(snd_mixer_selem_get_capture_volume)( |
| 1031 _inputMixerElement, | 982 _inputMixerElement, |
| 1032 (snd_mixer_selem_channel_id_t) 0, | 983 (snd_mixer_selem_channel_id_t) 0, |
| 1033 &vol); | 984 &vol); |
| 1034 if (errVal < 0) | 985 if (errVal < 0) |
| 1035 { | 986 { |
| 1036 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 987 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 1037 "Error getting inputvolume: %s", | 988 "Error getting inputvolume: %s", |
| 1038 LATE(snd_strerror)(errVal)); | 989 LATE(snd_strerror)(errVal)); |
| 1039 return -1; | 990 return -1; |
| 1040 } | 991 } |
| 1041 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 992 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 1042 " AudioMixerManagerLinuxALSA::MicrophoneVolume() => vol=%i"
, | 993 " AudioMixerManagerLinuxALSA::MicrophoneVolume() => vol=%i"
, |
| 1043 vol); | 994 vol); |
| 1044 | 995 |
| 1045 volume = static_cast<uint32_t> (vol); | 996 volume = static_cast<uint32_t> (vol); |
| 1046 | 997 |
| 1047 return 0; | 998 return 0; |
| 1048 } | 999 } |
| 1049 | 1000 |
| 1050 int32_t AudioMixerManagerLinuxALSA::MaxMicrophoneVolume( | 1001 int32_t AudioMixerManagerLinuxALSA::MaxMicrophoneVolume( |
| 1051 uint32_t& maxVolume) const | 1002 uint32_t& maxVolume) const |
| 1052 { | 1003 { |
| 1053 | 1004 if (_inputMixerElement == nullptr) { |
| 1054 if (_inputMixerElement == NULL) | 1005 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 1055 { | 1006 " no avaliable input mixer element exists"); |
| 1056 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 1007 return -1; |
| 1057 " no avaliable input mixer element exists"); | |
| 1058 return -1; | |
| 1059 } | 1008 } |
| 1060 | 1009 |
| 1061 long int minVol(0); | 1010 long int minVol(0); |
| 1062 long int maxVol(0); | 1011 long int maxVol(0); |
| 1063 | 1012 |
| 1064 // check if we have mic volume at all | 1013 // check if we have mic volume at all |
| 1065 if (!LATE(snd_mixer_selem_has_capture_volume)(_inputMixerElement)) | 1014 if (!LATE(snd_mixer_selem_has_capture_volume)(_inputMixerElement)) |
| 1066 { | 1015 { |
| 1067 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 1016 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 1068 " No microphone volume available"); | 1017 " No microphone volume available"); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1084 } | 1033 } |
| 1085 | 1034 |
| 1086 maxVolume = static_cast<uint32_t> (maxVol); | 1035 maxVolume = static_cast<uint32_t> (maxVol); |
| 1087 | 1036 |
| 1088 return 0; | 1037 return 0; |
| 1089 } | 1038 } |
| 1090 | 1039 |
| 1091 int32_t AudioMixerManagerLinuxALSA::MinMicrophoneVolume( | 1040 int32_t AudioMixerManagerLinuxALSA::MinMicrophoneVolume( |
| 1092 uint32_t& minVolume) const | 1041 uint32_t& minVolume) const |
| 1093 { | 1042 { |
| 1094 | 1043 if (_inputMixerElement == nullptr) { |
| 1095 if (_inputMixerElement == NULL) | 1044 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 1096 { | 1045 " no avaliable input mixer element exists"); |
| 1097 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 1046 return -1; |
| 1098 " no avaliable input mixer element exists"); | |
| 1099 return -1; | |
| 1100 } | 1047 } |
| 1101 | 1048 |
| 1102 long int minVol(0); | 1049 long int minVol(0); |
| 1103 long int maxVol(0); | 1050 long int maxVol(0); |
| 1104 | 1051 |
| 1105 int errVal = | 1052 int errVal = |
| 1106 LATE(snd_mixer_selem_get_capture_volume_range)(_inputMixerElement, | 1053 LATE(snd_mixer_selem_get_capture_volume_range)(_inputMixerElement, |
| 1107 &minVol, &maxVol); | 1054 &minVol, &maxVol); |
| 1108 | 1055 |
| 1109 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 1056 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 1110 " Microphone hardware volume range, min: %d, max: %d", | 1057 " Microphone hardware volume range, min: %d, max: %d", |
| 1111 minVol, maxVol); | 1058 minVol, maxVol); |
| 1112 if (maxVol <= minVol) | 1059 if (maxVol <= minVol) |
| 1113 { | 1060 { |
| 1114 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 1061 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 1115 " Error getting microphone volume range: %s", | 1062 " Error getting microphone volume range: %s", |
| 1116 LATE(snd_strerror)(errVal)); | 1063 LATE(snd_strerror)(errVal)); |
| 1117 } | 1064 } |
| 1118 | 1065 |
| 1119 minVolume = static_cast<uint32_t> (minVol); | 1066 minVolume = static_cast<uint32_t> (minVol); |
| 1120 | 1067 |
| 1121 return 0; | 1068 return 0; |
| 1122 } | 1069 } |
| 1123 | 1070 |
| 1124 int32_t AudioMixerManagerLinuxALSA::MicrophoneVolumeStepSize( | 1071 int32_t AudioMixerManagerLinuxALSA::MicrophoneVolumeStepSize( |
| 1125 uint16_t& stepSize) const | 1072 uint16_t& stepSize) const |
| 1126 { | 1073 { |
| 1127 | 1074 if (_inputMixerHandle == nullptr) { |
| 1128 if (_inputMixerHandle == NULL) | 1075 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 1129 { | 1076 " no avaliable input mixer exists"); |
| 1130 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 1077 return -1; |
| 1131 " no avaliable input mixer exists"); | |
| 1132 return -1; | |
| 1133 } | 1078 } |
| 1134 | 1079 |
| 1135 // The step size is always 1 for ALSA | 1080 // The step size is always 1 for ALSA |
| 1136 stepSize = 1; | 1081 stepSize = 1; |
| 1137 | 1082 |
| 1138 return 0; | 1083 return 0; |
| 1139 } | 1084 } |
| 1140 | 1085 |
| 1141 // ============================================================================ | 1086 // ============================================================================ |
| 1142 // Private Methods | 1087 // Private Methods |
| 1143 // ============================================================================ | 1088 // ============================================================================ |
| 1144 | 1089 |
| 1145 int32_t AudioMixerManagerLinuxALSA::LoadMicMixerElement() const | 1090 int32_t AudioMixerManagerLinuxALSA::LoadMicMixerElement() const |
| 1146 { | 1091 { |
| 1147 int errVal = LATE(snd_mixer_load)(_inputMixerHandle); | 1092 int errVal = LATE(snd_mixer_load)(_inputMixerHandle); |
| 1148 if (errVal < 0) | 1093 if (errVal < 0) |
| 1149 { | 1094 { |
| 1150 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 1095 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 1151 "snd_mixer_load(_inputMixerHandle), error: %s", | 1096 "snd_mixer_load(_inputMixerHandle), error: %s", |
| 1152 LATE(snd_strerror)(errVal)); | 1097 LATE(snd_strerror)(errVal)); |
| 1153 _inputMixerHandle = NULL; | 1098 _inputMixerHandle = nullptr; |
| 1154 return -1; | 1099 return -1; |
| 1155 } | 1100 } |
| 1156 | 1101 |
| 1157 snd_mixer_elem_t *elem = NULL; | 1102 snd_mixer_elem_t* elem = nullptr; |
| 1158 snd_mixer_elem_t *micElem = NULL; | 1103 snd_mixer_elem_t* micElem = nullptr; |
| 1159 unsigned mixerIdx = 0; | 1104 unsigned mixerIdx = 0; |
| 1160 const char *selemName = NULL; | 1105 const char* selemName = nullptr; |
| 1161 | 1106 |
| 1162 // Find and store handles to the right mixer elements | 1107 // Find and store handles to the right mixer elements |
| 1163 for (elem = LATE(snd_mixer_first_elem)(_inputMixerHandle); elem; elem | 1108 for (elem = LATE(snd_mixer_first_elem)(_inputMixerHandle); elem; elem |
| 1164 = LATE(snd_mixer_elem_next)(elem), mixerIdx++) | 1109 = LATE(snd_mixer_elem_next)(elem), mixerIdx++) |
| 1165 { | 1110 { |
| 1166 if (LATE(snd_mixer_selem_is_active)(elem)) | 1111 if (LATE(snd_mixer_selem_is_active)(elem)) |
| 1167 { | 1112 { |
| 1168 selemName = LATE(snd_mixer_selem_get_name)(elem); | 1113 selemName = LATE(snd_mixer_selem_get_name)(elem); |
| 1169 if (strcmp(selemName, "Capture") == 0) // "Capture", "Mic" | 1114 if (strcmp(selemName, "Capture") == 0) // "Capture", "Mic" |
| 1170 { | 1115 { |
| 1171 _inputMixerElement = elem; | 1116 _inputMixerElement = elem; |
| 1172 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, | 1117 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, |
| 1173 _id, " Capture element set"); | 1118 _id, " Capture element set"); |
| 1174 } else if (strcmp(selemName, "Mic") == 0) | 1119 } else if (strcmp(selemName, "Mic") == 0) |
| 1175 { | 1120 { |
| 1176 micElem = elem; | 1121 micElem = elem; |
| 1177 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, | 1122 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, |
| 1178 _id, " Mic element found"); | 1123 _id, " Mic element found"); |
| 1179 } | 1124 } |
| 1180 } | 1125 } |
| 1181 | 1126 |
| 1182 if (_inputMixerElement) | 1127 if (_inputMixerElement) |
| 1183 { | 1128 { |
| 1184 // Use the first Capture element that is found | 1129 // Use the first Capture element that is found |
| 1185 // The second one may not work | 1130 // The second one may not work |
| 1186 break; | 1131 break; |
| 1187 } | 1132 } |
| 1188 } | 1133 } |
| 1189 | 1134 |
| 1190 if (_inputMixerElement == NULL) | 1135 if (_inputMixerElement == nullptr) { |
| 1191 { | 1136 // We didn't find a Capture handle, use Mic. |
| 1192 // We didn't find a Capture handle, use Mic. | 1137 if (micElem != nullptr) { |
| 1193 if (micElem != NULL) | 1138 _inputMixerElement = micElem; |
| 1194 { | 1139 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 1195 _inputMixerElement = micElem; | 1140 " Using Mic as capture volume."); |
| 1196 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 1141 } else { |
| 1197 " Using Mic as capture volume."); | 1142 _inputMixerElement = nullptr; |
| 1198 } else | 1143 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 1199 { | 1144 "Could not find capture volume on the mixer."); |
| 1200 _inputMixerElement = NULL; | |
| 1201 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | |
| 1202 "Could not find capture volume on the mixer."); | |
| 1203 | 1145 |
| 1204 return -1; | 1146 return -1; |
| 1205 } | 1147 } |
| 1206 } | 1148 } |
| 1207 | 1149 |
| 1208 return 0; | 1150 return 0; |
| 1209 } | 1151 } |
| 1210 | 1152 |
| 1211 int32_t AudioMixerManagerLinuxALSA::LoadSpeakerMixerElement() const | 1153 int32_t AudioMixerManagerLinuxALSA::LoadSpeakerMixerElement() const |
| 1212 { | 1154 { |
| 1213 int errVal = LATE(snd_mixer_load)(_outputMixerHandle); | 1155 int errVal = LATE(snd_mixer_load)(_outputMixerHandle); |
| 1214 if (errVal < 0) | 1156 if (errVal < 0) |
| 1215 { | 1157 { |
| 1216 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 1158 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 1217 " snd_mixer_load(_outputMixerHandle), error: %s", | 1159 " snd_mixer_load(_outputMixerHandle), error: %s", |
| 1218 LATE(snd_strerror)(errVal)); | 1160 LATE(snd_strerror)(errVal)); |
| 1219 _outputMixerHandle = NULL; | 1161 _outputMixerHandle = nullptr; |
| 1220 return -1; | 1162 return -1; |
| 1221 } | 1163 } |
| 1222 | 1164 |
| 1223 snd_mixer_elem_t *elem = NULL; | 1165 snd_mixer_elem_t* elem = nullptr; |
| 1224 snd_mixer_elem_t *masterElem = NULL; | 1166 snd_mixer_elem_t* masterElem = nullptr; |
| 1225 snd_mixer_elem_t *speakerElem = NULL; | 1167 snd_mixer_elem_t* speakerElem = nullptr; |
| 1226 unsigned mixerIdx = 0; | 1168 unsigned mixerIdx = 0; |
| 1227 const char *selemName = NULL; | 1169 const char* selemName = nullptr; |
| 1228 | 1170 |
| 1229 // Find and store handles to the right mixer elements | 1171 // Find and store handles to the right mixer elements |
| 1230 for (elem = LATE(snd_mixer_first_elem)(_outputMixerHandle); elem; elem | 1172 for (elem = LATE(snd_mixer_first_elem)(_outputMixerHandle); elem; elem |
| 1231 = LATE(snd_mixer_elem_next)(elem), mixerIdx++) | 1173 = LATE(snd_mixer_elem_next)(elem), mixerIdx++) |
| 1232 { | 1174 { |
| 1233 if (LATE(snd_mixer_selem_is_active)(elem)) | 1175 if (LATE(snd_mixer_selem_is_active)(elem)) |
| 1234 { | 1176 { |
| 1235 selemName = LATE(snd_mixer_selem_get_name)(elem); | 1177 selemName = LATE(snd_mixer_selem_get_name)(elem); |
| 1236 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 1178 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 1237 "snd_mixer_selem_get_name %d: %s =%x", mixerIdx, | 1179 "snd_mixer_selem_get_name %d: %s =%x", mixerIdx, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1257 } | 1199 } |
| 1258 | 1200 |
| 1259 if (_outputMixerElement) | 1201 if (_outputMixerElement) |
| 1260 { | 1202 { |
| 1261 // We have found the element we want | 1203 // We have found the element we want |
| 1262 break; | 1204 break; |
| 1263 } | 1205 } |
| 1264 } | 1206 } |
| 1265 | 1207 |
| 1266 // If we didn't find a PCM Handle, use Master or Speaker | 1208 // If we didn't find a PCM Handle, use Master or Speaker |
| 1267 if (_outputMixerElement == NULL) | 1209 if (_outputMixerElement == nullptr) { |
| 1268 { | 1210 if (masterElem != nullptr) { |
| 1269 if (masterElem != NULL) | 1211 _outputMixerElement = masterElem; |
| 1270 { | 1212 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 1271 _outputMixerElement = masterElem; | 1213 " Using Master as output volume."); |
| 1272 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 1214 } else if (speakerElem != nullptr) { |
| 1273 " Using Master as output volume."); | 1215 _outputMixerElement = speakerElem; |
| 1274 } else if (speakerElem != NULL) | 1216 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 1275 { | 1217 " Using Speaker as output volume."); |
| 1276 _outputMixerElement = speakerElem; | 1218 } else { |
| 1277 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 1219 _outputMixerElement = nullptr; |
| 1278 " Using Speaker as output volume."); | 1220 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
| 1279 } else | 1221 "Could not find output volume in the mixer."); |
| 1280 { | 1222 return -1; |
| 1281 _outputMixerElement = NULL; | 1223 } |
| 1282 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | |
| 1283 "Could not find output volume in the mixer."); | |
| 1284 return -1; | |
| 1285 } | |
| 1286 } | 1224 } |
| 1287 | 1225 |
| 1288 return 0; | 1226 return 0; |
| 1289 } | 1227 } |
| 1290 | 1228 |
| 1291 void AudioMixerManagerLinuxALSA::GetControlName(char* controlName, | 1229 void AudioMixerManagerLinuxALSA::GetControlName(char* controlName, |
| 1292 char* deviceName) const | 1230 char* deviceName) const |
| 1293 { | 1231 { |
| 1294 // Example | 1232 // Example |
| 1295 // deviceName: "front:CARD=Intel,DEV=0" | 1233 // deviceName: "front:CARD=Intel,DEV=0" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1308 strncpy(&controlName[2], pos1, nChar); | 1246 strncpy(&controlName[2], pos1, nChar); |
| 1309 controlName[2 + nChar] = '\0'; | 1247 controlName[2 + nChar] = '\0'; |
| 1310 } else | 1248 } else |
| 1311 { | 1249 { |
| 1312 strcpy(controlName, deviceName); | 1250 strcpy(controlName, deviceName); |
| 1313 } | 1251 } |
| 1314 | 1252 |
| 1315 } | 1253 } |
| 1316 | 1254 |
| 1317 } | 1255 } |
| OLD | NEW |