| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 state_ = kUninitialized; | 168 state_ = kUninitialized; |
| 169 return true; | 169 return true; |
| 170 } | 170 } |
| 171 | 171 |
| 172 VoiceProcessingAudioUnit::State VoiceProcessingAudioUnit::GetState() const { | 172 VoiceProcessingAudioUnit::State VoiceProcessingAudioUnit::GetState() const { |
| 173 return state_; | 173 return state_; |
| 174 } | 174 } |
| 175 | 175 |
| 176 bool VoiceProcessingAudioUnit::Initialize(Float64 sample_rate) { | 176 bool VoiceProcessingAudioUnit::Initialize(Float64 sample_rate) { |
| 177 RTC_DCHECK_GE(state_, kUninitialized); | 177 RTC_DCHECK_GE(state_, kUninitialized); |
| 178 RTCLog(@"Initializing audio unit."); | 178 RTCLog(@"Initializing audio unit with sample rate: %f", sample_rate); |
| 179 | 179 |
| 180 OSStatus result = noErr; | 180 OSStatus result = noErr; |
| 181 AudioStreamBasicDescription format = GetFormat(sample_rate); | 181 AudioStreamBasicDescription format = GetFormat(sample_rate); |
| 182 UInt32 size = sizeof(format); | 182 UInt32 size = sizeof(format); |
| 183 #if !defined(NDEBUG) | 183 #if !defined(NDEBUG) |
| 184 LogStreamDescription(format); | 184 LogStreamDescription(format); |
| 185 #endif | 185 #endif |
| 186 | 186 |
| 187 // Set the format on the output scope of the input element/bus. | 187 // Set the format on the output scope of the input element/bus. |
| 188 result = | 188 result = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 ++failed_initalize_attempts; | 221 ++failed_initalize_attempts; |
| 222 if (failed_initalize_attempts == kMaxNumberOfAudioUnitInitializeAttempts) { | 222 if (failed_initalize_attempts == kMaxNumberOfAudioUnitInitializeAttempts) { |
| 223 // Max number of initialization attempts exceeded, hence abort. | 223 // Max number of initialization attempts exceeded, hence abort. |
| 224 RTCLogError(@"Too many initialization attempts."); | 224 RTCLogError(@"Too many initialization attempts."); |
| 225 return false; | 225 return false; |
| 226 } | 226 } |
| 227 RTCLog(@"Pause 100ms and try audio unit initialization again..."); | 227 RTCLog(@"Pause 100ms and try audio unit initialization again..."); |
| 228 [NSThread sleepForTimeInterval:0.1f]; | 228 [NSThread sleepForTimeInterval:0.1f]; |
| 229 result = AudioUnitInitialize(vpio_unit_); | 229 result = AudioUnitInitialize(vpio_unit_); |
| 230 } | 230 } |
| 231 RTCLog(@"Voice Processing I/O unit is now initialized."); | 231 if (result == noErr) { |
| 232 RTCLog(@"Voice Processing I/O unit is now initialized."); |
| 233 } |
| 232 state_ = kInitialized; | 234 state_ = kInitialized; |
| 233 return true; | 235 return true; |
| 234 } | 236 } |
| 235 | 237 |
| 236 bool VoiceProcessingAudioUnit::Start() { | 238 bool VoiceProcessingAudioUnit::Start() { |
| 237 RTC_DCHECK_GE(state_, kUninitialized); | 239 RTC_DCHECK_GE(state_, kUninitialized); |
| 238 RTCLog(@"Starting audio unit."); | 240 RTCLog(@"Starting audio unit."); |
| 239 | 241 |
| 240 OSStatus result = AudioOutputUnitStart(vpio_unit_); | 242 OSStatus result = AudioOutputUnitStart(vpio_unit_); |
| 241 if (result != noErr) { | 243 if (result != noErr) { |
| 242 RTCLogError(@"Failed to start audio unit. Error=%ld", (long)result); | 244 RTCLogError(@"Failed to start audio unit. Error=%ld", (long)result); |
| 243 return false; | 245 return false; |
| 246 } else { |
| 247 RTCLog(@"Started audio unit"); |
| 244 } | 248 } |
| 245 state_ = kStarted; | 249 state_ = kStarted; |
| 246 return true; | 250 return true; |
| 247 } | 251 } |
| 248 | 252 |
| 249 bool VoiceProcessingAudioUnit::Stop() { | 253 bool VoiceProcessingAudioUnit::Stop() { |
| 250 RTC_DCHECK_GE(state_, kUninitialized); | 254 RTC_DCHECK_GE(state_, kUninitialized); |
| 251 RTCLog(@"Stopping audio unit."); | 255 RTCLog(@"Stopping audio unit."); |
| 252 | 256 |
| 253 OSStatus result = AudioOutputUnitStop(vpio_unit_); | 257 OSStatus result = AudioOutputUnitStop(vpio_unit_); |
| 254 if (result != noErr) { | 258 if (result != noErr) { |
| 255 RTCLogError(@"Failed to stop audio unit. Error=%ld", (long)result); | 259 RTCLogError(@"Failed to stop audio unit. Error=%ld", (long)result); |
| 256 return false; | 260 return false; |
| 261 } else { |
| 262 RTCLog(@"Stopped audio unit"); |
| 257 } | 263 } |
| 264 |
| 258 state_ = kInitialized; | 265 state_ = kInitialized; |
| 259 return true; | 266 return true; |
| 260 } | 267 } |
| 261 | 268 |
| 262 bool VoiceProcessingAudioUnit::Uninitialize() { | 269 bool VoiceProcessingAudioUnit::Uninitialize() { |
| 263 RTC_DCHECK_GE(state_, kUninitialized); | 270 RTC_DCHECK_GE(state_, kUninitialized); |
| 264 RTCLog(@"Unintializing audio unit."); | 271 RTCLog(@"Unintializing audio unit."); |
| 265 | 272 |
| 266 OSStatus result = AudioUnitUninitialize(vpio_unit_); | 273 OSStatus result = AudioUnitUninitialize(vpio_unit_); |
| 267 if (result != noErr) { | 274 if (result != noErr) { |
| 268 RTCLogError(@"Failed to uninitialize audio unit. Error=%ld", (long)result); | 275 RTCLogError(@"Failed to uninitialize audio unit. Error=%ld", (long)result); |
| 269 return false; | 276 return false; |
| 277 } else { |
| 278 RTCLog(@"Uninitialized audio unit."); |
| 270 } | 279 } |
| 280 |
| 281 state_ = kUninitialized; |
| 271 return true; | 282 return true; |
| 272 } | 283 } |
| 273 | 284 |
| 274 OSStatus VoiceProcessingAudioUnit::Render(AudioUnitRenderActionFlags* flags, | 285 OSStatus VoiceProcessingAudioUnit::Render(AudioUnitRenderActionFlags* flags, |
| 275 const AudioTimeStamp* time_stamp, | 286 const AudioTimeStamp* time_stamp, |
| 276 UInt32 output_bus_number, | 287 UInt32 output_bus_number, |
| 277 UInt32 num_frames, | 288 UInt32 num_frames, |
| 278 AudioBufferList* io_data) { | 289 AudioBufferList* io_data) { |
| 279 RTC_DCHECK(vpio_unit_) << "Init() not called."; | 290 RTC_DCHECK(vpio_unit_) << "Init() not called."; |
| 280 | 291 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 OSStatus result = AudioComponentInstanceDispose(vpio_unit_); | 381 OSStatus result = AudioComponentInstanceDispose(vpio_unit_); |
| 371 if (result != noErr) { | 382 if (result != noErr) { |
| 372 RTCLogError(@"AudioComponentInstanceDispose failed. Error=%ld.", | 383 RTCLogError(@"AudioComponentInstanceDispose failed. Error=%ld.", |
| 373 (long)result); | 384 (long)result); |
| 374 } | 385 } |
| 375 vpio_unit_ = nullptr; | 386 vpio_unit_ = nullptr; |
| 376 } | 387 } |
| 377 } | 388 } |
| 378 | 389 |
| 379 } // namespace webrtc | 390 } // namespace webrtc |
| OLD | NEW |