@@ -84,14 +84,16 @@ static OSStatus GetAGCState(AudioUnit audio_unit, UInt32* enabled) {
8484
8585const UInt32 VoiceProcessingAudioUnit::kBytesPerSample = 2 ;
8686
87- bool VoiceProcessingAudioUnit::Init () {
87+ bool VoiceProcessingAudioUnit::Init (OSType audio_unit_sub_type ) {
8888 RTC_DCHECK_EQ (state_, kInitRequired );
8989
90+ audio_unit_sub_type_ = audio_unit_sub_type;
91+
9092 // Create an audio component description to identify the Voice Processing
9193 // I/O audio unit.
9294 AudioComponentDescription vpio_unit_description;
9395 vpio_unit_description.componentType = kAudioUnitType_Output ;
94- vpio_unit_description.componentSubType = kAudioUnitSubType_VoiceProcessingIO ;
96+ vpio_unit_description.componentSubType = audio_unit_sub_type ;
9597 vpio_unit_description.componentManufacturer = kAudioUnitManufacturer_Apple ;
9698 vpio_unit_description.componentFlags = 0 ;
9799 vpio_unit_description.componentFlagsMask = 0 ;
@@ -250,62 +252,64 @@ static OSStatus GetAGCState(AudioUnit audio_unit, UInt32* enabled) {
250252 RTCLog (@" Voice Processing I/O unit is now initialized." );
251253 }
252254
253- // AGC should be enabled by default for Voice Processing I/O units but it is
254- // checked below and enabled explicitly if needed. This scheme is used
255- // to be absolutely sure that the AGC is enabled since we have seen cases
256- // where only zeros are recorded and a disabled AGC could be one of the
257- // reasons why it happens.
258- int agc_was_enabled_by_default = 0 ;
259- UInt32 agc_is_enabled = 0 ;
260- result = GetAGCState (vpio_unit_, &agc_is_enabled);
261- if (result != noErr) {
262- RTCLogError (@" Failed to get AGC state (1st attempt). "
263- " Error=%ld ." ,
264- (long )result);
265- // Example of error code: kAudioUnitErr_NoConnection (-10876).
266- // All error codes related to audio units are negative and are therefore
267- // converted into a postive value to match the UMA APIs.
268- RTC_HISTOGRAM_COUNTS_SPARSE_100000 (
269- " WebRTC.Audio.GetAGCStateErrorCode1" , (-1 ) * result);
270- } else if (agc_is_enabled) {
271- // Remember that the AGC was enabled by default. Will be used in UMA.
272- agc_was_enabled_by_default = 1 ;
273- } else {
274- // AGC was initially disabled => try to enable it explicitly.
275- UInt32 enable_agc = 1 ;
276- result =
277- AudioUnitSetProperty (vpio_unit_,
278- kAUVoiceIOProperty_VoiceProcessingEnableAGC ,
279- kAudioUnitScope_Global , kInputBus , &enable_agc,
280- sizeof (enable_agc));
281- if (result != noErr) {
282- RTCLogError (@" Failed to enable the built-in AGC. "
283- " Error=%ld ." ,
284- (long )result);
285- RTC_HISTOGRAM_COUNTS_SPARSE_100000 (
286- " WebRTC.Audio.SetAGCStateErrorCode" , (-1 ) * result);
287- }
255+ if (audio_unit_sub_type_ == kAudioUnitSubType_VoiceProcessingIO ) {
256+ // AGC should be enabled by default for Voice Processing I/O units but it is
257+ // checked below and enabled explicitly if needed. This scheme is used
258+ // to be absolutely sure that the AGC is enabled since we have seen cases
259+ // where only zeros are recorded and a disabled AGC could be one of the
260+ // reasons why it happens.
261+ int agc_was_enabled_by_default = 0 ;
262+ UInt32 agc_is_enabled = 0 ;
288263 result = GetAGCState (vpio_unit_, &agc_is_enabled);
289264 if (result != noErr) {
290- RTCLogError (@" Failed to get AGC state (2nd attempt). "
265+ RTCLogError (@" Failed to get AGC state (1st attempt). "
291266 " Error=%ld ." ,
292267 (long )result);
268+ // Example of error code: kAudioUnitErr_NoConnection (-10876).
269+ // All error codes related to audio units are negative and are therefore
270+ // converted into a postive value to match the UMA APIs.
293271 RTC_HISTOGRAM_COUNTS_SPARSE_100000 (
294- " WebRTC.Audio.GetAGCStateErrorCode2" , (-1 ) * result);
272+ " WebRTC.Audio.GetAGCStateErrorCode1" , (-1 ) * result);
273+ } else if (agc_is_enabled) {
274+ // Remember that the AGC was enabled by default. Will be used in UMA.
275+ agc_was_enabled_by_default = 1 ;
276+ } else {
277+ // AGC was initially disabled => try to enable it explicitly.
278+ UInt32 enable_agc = 1 ;
279+ result =
280+ AudioUnitSetProperty (vpio_unit_,
281+ kAUVoiceIOProperty_VoiceProcessingEnableAGC ,
282+ kAudioUnitScope_Global , kInputBus , &enable_agc,
283+ sizeof (enable_agc));
284+ if (result != noErr) {
285+ RTCLogError (@" Failed to enable the built-in AGC. "
286+ " Error=%ld ." ,
287+ (long )result);
288+ RTC_HISTOGRAM_COUNTS_SPARSE_100000 (
289+ " WebRTC.Audio.SetAGCStateErrorCode" , (-1 ) * result);
290+ }
291+ result = GetAGCState (vpio_unit_, &agc_is_enabled);
292+ if (result != noErr) {
293+ RTCLogError (@" Failed to get AGC state (2nd attempt). "
294+ " Error=%ld ." ,
295+ (long )result);
296+ RTC_HISTOGRAM_COUNTS_SPARSE_100000 (
297+ " WebRTC.Audio.GetAGCStateErrorCode2" , (-1 ) * result);
298+ }
295299 }
296- }
297300
298- // Track if the built-in AGC was enabled by default (as it should) or not.
299- RTC_HISTOGRAM_BOOLEAN (" WebRTC.Audio.BuiltInAGCWasEnabledByDefault" ,
300- agc_was_enabled_by_default);
301- RTCLog (@" WebRTC.Audio.BuiltInAGCWasEnabledByDefault: %d " ,
302- agc_was_enabled_by_default);
303- // As a final step, add an UMA histogram for tracking the AGC state.
304- // At this stage, the AGC should be enabled, and if it is not, more work is
305- // needed to find out the root cause.
306- RTC_HISTOGRAM_BOOLEAN (" WebRTC.Audio.BuiltInAGCIsEnabled" , agc_is_enabled);
307- RTCLog (@" WebRTC.Audio.BuiltInAGCIsEnabled: %u " ,
308- static_cast <unsigned int >(agc_is_enabled));
301+ // Track if the built-in AGC was enabled by default (as it should) or not.
302+ RTC_HISTOGRAM_BOOLEAN (" WebRTC.Audio.BuiltInAGCWasEnabledByDefault" ,
303+ agc_was_enabled_by_default);
304+ RTCLog (@" WebRTC.Audio.BuiltInAGCWasEnabledByDefault: %d " ,
305+ agc_was_enabled_by_default);
306+ // As a final step, add an UMA histogram for tracking the AGC state.
307+ // At this stage, the AGC should be enabled, and if it is not, more work is
308+ // needed to find out the root cause.
309+ RTC_HISTOGRAM_BOOLEAN (" WebRTC.Audio.BuiltInAGCIsEnabled" , agc_is_enabled);
310+ RTCLog (@" WebRTC.Audio.BuiltInAGCIsEnabled: %u " ,
311+ static_cast <unsigned int >(agc_is_enabled));
312+ }
309313
310314 state_ = kInitialized ;
311315 return true ;
0 commit comments