OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 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 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 246 } |
247 if (result == noErr) { | 247 if (result == noErr) { |
248 RTCLog(@"Voice Processing I/O unit is now initialized."); | 248 RTCLog(@"Voice Processing I/O unit is now initialized."); |
249 } | 249 } |
250 | 250 |
251 // AGC should be enabled by default for Voice Processing I/O units but it is | 251 // AGC should be enabled by default for Voice Processing I/O units but it is |
252 // checked below and enabled explicitly if needed. This scheme is used | 252 // checked below and enabled explicitly if needed. This scheme is used |
253 // to be absolutely sure that the AGC is enabled since we have seen cases | 253 // to be absolutely sure that the AGC is enabled since we have seen cases |
254 // where only zeros are recorded and a disabled AGC could be one of the | 254 // where only zeros are recorded and a disabled AGC could be one of the |
255 // reasons why it happens. | 255 // reasons why it happens. |
256 int agc_was_enabled_by_default = 1; | 256 int agc_was_enabled_by_default = 0; |
257 UInt32 agc_is_enabled = 0; | 257 UInt32 agc_is_enabled = 0; |
258 result = GetAGCState(vpio_unit_, &agc_is_enabled); | 258 result = GetAGCState(vpio_unit_, &agc_is_enabled); |
259 if (result != noErr) { | 259 if (result != noErr) { |
260 RTCLogError(@"Failed to get AGC state (1st attempt). " | 260 RTCLogError(@"Failed to get AGC state (1st attempt). " |
261 "Error=%ld.", | 261 "Error=%ld.", |
262 (long)result); | 262 (long)result); |
263 } else if (!agc_is_enabled) { | 263 UMA_HISTOGRAM_SPARSE_SLOWLY("WebRTC.Audio.GetAGCStateErrorCode", result); |
264 // Remember that the AGC was disabled by default. Will be used in UMA. | 264 } else if (agc_is_enabled) { |
265 agc_was_enabled_by_default = 0; | 265 // Remember that the AGC was enabled by default. Will be used in UMA. |
266 // Try to enable the AGC. | 266 agc_was_enabled_by_default = 1; |
| 267 } else { |
| 268 // AGC was initially disabled => try to enable it explicitly. |
267 UInt32 enable_agc = 1; | 269 UInt32 enable_agc = 1; |
268 result = | 270 result = |
269 AudioUnitSetProperty(vpio_unit_, | 271 AudioUnitSetProperty(vpio_unit_, |
270 kAUVoiceIOProperty_VoiceProcessingEnableAGC, | 272 kAUVoiceIOProperty_VoiceProcessingEnableAGC, |
271 kAudioUnitScope_Global, kInputBus, &enable_agc, | 273 kAudioUnitScope_Global, kInputBus, &enable_agc, |
272 sizeof(enable_agc)); | 274 sizeof(enable_agc)); |
273 if (result != noErr) { | 275 if (result != noErr) { |
274 RTCLogError(@"Failed to enable the built-in AGC. " | 276 RTCLogError(@"Failed to enable the built-in AGC. " |
275 "Error=%ld.", | 277 "Error=%ld.", |
276 (long)result); | 278 (long)result); |
| 279 UMA_HISTOGRAM_SPARSE_SLOWLY("WebRTC.Audio.SetAGCStateErrorCode", result); |
277 } | 280 } |
278 result = GetAGCState(vpio_unit_, &agc_is_enabled); | 281 result = GetAGCState(vpio_unit_, &agc_is_enabled); |
279 if (result != noErr) { | 282 if (result != noErr) { |
280 RTCLogError(@"Failed to get AGC state (2nd attempt). " | 283 RTCLogError(@"Failed to get AGC state (2nd attempt). " |
281 "Error=%ld.", | 284 "Error=%ld.", |
282 (long)result); | 285 (long)result); |
| 286 // Use same histogram as earlier but multiply error code with -1 to |
| 287 // make each case unique. Example: kAudioUnitErr_NoConnection (-10876) |
| 288 // will be converted to +10876 here. |
| 289 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 290 "WebRTC.Audio.GetAGCStateErrorCode", (-1) * result); |
283 } | 291 } |
284 } | 292 } |
285 | 293 |
286 // Track if the built-in AGC was enabled by default (as it should) or not. | 294 // Track if the built-in AGC was enabled by default (as it should) or not. |
287 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.BuiltInAGCWasEnabledByDefault", | 295 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.BuiltInAGCWasEnabledByDefault", |
288 agc_was_enabled_by_default); | 296 agc_was_enabled_by_default); |
289 RTCLog(@"WebRTC.Audio.BuiltInAGCWasEnabledByDefault: %d", | 297 RTCLog(@"WebRTC.Audio.BuiltInAGCWasEnabledByDefault: %d", |
290 agc_was_enabled_by_default); | 298 agc_was_enabled_by_default); |
291 // As a final step, add an UMA histogram for tracking the AGC state. | 299 // As a final step, add an UMA histogram for tracking the AGC state. |
292 // At this stage, the AGC should be enabled, and if it is not, more work is | 300 // At this stage, the AGC should be enabled, and if it is not, more work is |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 OSStatus result = AudioComponentInstanceDispose(vpio_unit_); | 456 OSStatus result = AudioComponentInstanceDispose(vpio_unit_); |
449 if (result != noErr) { | 457 if (result != noErr) { |
450 RTCLogError(@"AudioComponentInstanceDispose failed. Error=%ld.", | 458 RTCLogError(@"AudioComponentInstanceDispose failed. Error=%ld.", |
451 (long)result); | 459 (long)result); |
452 } | 460 } |
453 vpio_unit_ = nullptr; | 461 vpio_unit_ = nullptr; |
454 } | 462 } |
455 } | 463 } |
456 | 464 |
457 } // namespace webrtc | 465 } // namespace webrtc |
OLD | NEW |