Index: webrtc/modules/audio_device/ios/voice_processing_audio_unit.mm |
diff --git a/webrtc/modules/audio_device/ios/voice_processing_audio_unit.mm b/webrtc/modules/audio_device/ios/voice_processing_audio_unit.mm |
index 08816a41521b84ddc3dfe333caf683c0ff59d8b2..11e5820455c2d50343b70c9d8a7e83264a6ca249 100644 |
--- a/webrtc/modules/audio_device/ios/voice_processing_audio_unit.mm |
+++ b/webrtc/modules/audio_device/ios/voice_processing_audio_unit.mm |
@@ -175,7 +175,7 @@ VoiceProcessingAudioUnit::State VoiceProcessingAudioUnit::GetState() const { |
bool VoiceProcessingAudioUnit::Initialize(Float64 sample_rate) { |
RTC_DCHECK_GE(state_, kUninitialized); |
- RTCLog(@"Initializing audio unit."); |
+ RTCLog(@"Initializing audio unit with sample rate: %f", sample_rate); |
OSStatus result = noErr; |
AudioStreamBasicDescription format = GetFormat(sample_rate); |
@@ -228,7 +228,9 @@ bool VoiceProcessingAudioUnit::Initialize(Float64 sample_rate) { |
[NSThread sleepForTimeInterval:0.1f]; |
result = AudioUnitInitialize(vpio_unit_); |
} |
- RTCLog(@"Voice Processing I/O unit is now initialized."); |
+ if (result == noErr) { |
+ RTCLog(@"Voice Processing I/O unit is now initialized."); |
+ } |
state_ = kInitialized; |
return true; |
} |
@@ -237,10 +239,20 @@ bool VoiceProcessingAudioUnit::Start() { |
RTC_DCHECK_GE(state_, kUninitialized); |
RTCLog(@"Starting audio unit."); |
- OSStatus result = AudioOutputUnitStart(vpio_unit_); |
+ OSStatus result = |
henrika_webrtc
2016/05/04 12:33:07
Perhaps a comment regarding why we need this liste
tkchin_webrtc
2016/05/05 23:23:28
Removing these changes for now. Will address BT is
henrika_webrtc
2016/05/06 11:22:17
Acknowledged.
|
+ AudioUnitAddPropertyListener(vpio_unit_, kAudioUnitProperty_SampleRate, |
+ OnSampleRateChange, this); |
+ if (result != noErr) { |
+ RTCLogError(@"Failed to add sample rate listener. Error=%ld.", |
+ (long)result); |
+ } |
+ |
+ result = AudioOutputUnitStart(vpio_unit_); |
if (result != noErr) { |
RTCLogError(@"Failed to start audio unit. Error=%ld", (long)result); |
return false; |
+ } else { |
+ RTCLog(@"Started audio unit"); |
} |
state_ = kStarted; |
return true; |
@@ -254,7 +266,19 @@ bool VoiceProcessingAudioUnit::Stop() { |
if (result != noErr) { |
RTCLogError(@"Failed to stop audio unit. Error=%ld", (long)result); |
return false; |
+ } else { |
+ RTCLog(@"Stopped audio unit"); |
+ } |
+ |
+ result = |
henrika_webrtc
2016/05/04 12:33:07
Do we need a check that it is disabled at close?
tkchin_webrtc
2016/05/05 23:23:28
Removing these changes for now. Will address BT is
henrika_webrtc
2016/05/06 11:22:16
Acknowledged.
|
+ AudioUnitRemovePropertyListenerWithUserData(vpio_unit_, |
+ kAudioUnitProperty_SampleRate, |
+ OnSampleRateChange, this); |
+ if (result != noErr) { |
+ RTCLogError(@"Failed to remove sample rate listener. Error=%ld.", |
+ (long)result); |
} |
+ |
state_ = kInitialized; |
return true; |
} |
@@ -267,6 +291,8 @@ bool VoiceProcessingAudioUnit::Uninitialize() { |
if (result != noErr) { |
RTCLogError(@"Failed to uninitialize audio unit. Error=%ld", (long)result); |
return false; |
+ } else { |
+ RTCLog(@"Uninitialized audio unit."); |
} |
return true; |
} |
@@ -312,6 +338,17 @@ OSStatus VoiceProcessingAudioUnit::OnDeliverRecordedData( |
num_frames, io_data); |
} |
+void VoiceProcessingAudioUnit::OnSampleRateChange( |
henrika_webrtc
2016/05/04 12:33:07
Can we now get this callback and the routing chang
tkchin_webrtc
2016/05/05 23:23:28
There shouldn't be conflicts - we are always using
henrika_webrtc
2016/05/06 11:22:17
Acknowledged.
|
+ void* in_ref_con, |
+ AudioUnit audio_unit, |
+ AudioUnitPropertyID property_id, |
+ AudioUnitScope scope, |
+ AudioUnitElement element) { |
+ VoiceProcessingAudioUnit* vp_unit = |
+ static_cast<VoiceProcessingAudioUnit*>(in_ref_con); |
+ vp_unit->NotifySampleRateChange(audio_unit, property_id, scope, element); |
+} |
+ |
OSStatus VoiceProcessingAudioUnit::NotifyGetPlayoutData( |
AudioUnitRenderActionFlags* flags, |
const AudioTimeStamp* time_stamp, |
@@ -332,6 +369,32 @@ OSStatus VoiceProcessingAudioUnit::NotifyDeliverRecordedData( |
num_frames, io_data); |
} |
+void VoiceProcessingAudioUnit::NotifySampleRateChange( |
+ AudioUnit audio_unit, |
+ AudioUnitPropertyID property_id, |
+ AudioUnitScope scope, |
+ AudioUnitElement element) { |
+ RTC_DCHECK_EQ(audio_unit, vpio_unit_); |
+ RTC_DCHECK_EQ(property_id, kAudioUnitProperty_SampleRate); |
+ // We only care about the output. |
henrika_webrtc
2016/05/04 12:33:07
Have you really been able to trigger callback on o
tkchin_webrtc
2016/05/05 23:23:28
Nope. But just in case.
henrika_webrtc
2016/05/06 11:22:17
Acknowledged.
|
+ if (scope != kAudioUnitScope_Output || element != kOutputBus) { |
+ return; |
+ } |
+ Float64 sample_rate = 0; |
+ UInt32 sample_rate_size = sizeof(Float64); |
+ OSStatus status = AudioUnitGetProperty(audio_unit, |
+ kAudioUnitProperty_SampleRate, |
+ kAudioUnitScope_Output, |
+ kOutputBus, |
+ &sample_rate, |
+ &sample_rate_size); |
+ if (status != noErr) { |
+ RTCLogError(@"Failed to get sample rate. Error=%ld.", (long)status); |
+ return; |
+ } |
+ observer_->OnSampleRateChange(sample_rate); |
+} |
+ |
AudioStreamBasicDescription VoiceProcessingAudioUnit::GetFormat( |
Float64 sample_rate) const { |
// Set the application formats for input and output: |