OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/audio/mac/audio_low_latency_input_mac.h" | 5 #include "media/audio/mac/audio_low_latency_input_mac.h" |
6 | 6 |
7 #include <CoreServices/CoreServices.h> | 7 #include <CoreServices/CoreServices.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 261 |
262 return true; | 262 return true; |
263 } | 263 } |
264 | 264 |
265 void AUAudioInputStream::Start(AudioInputCallback* callback) { | 265 void AUAudioInputStream::Start(AudioInputCallback* callback) { |
266 DCHECK(callback); | 266 DCHECK(callback); |
267 DLOG_IF(ERROR, !audio_unit_) << "Open() has not been called successfully"; | 267 DLOG_IF(ERROR, !audio_unit_) << "Open() has not been called successfully"; |
268 if (started_ || !audio_unit_) | 268 if (started_ || !audio_unit_) |
269 return; | 269 return; |
270 sink_ = callback; | 270 sink_ = callback; |
| 271 StartAgc(); |
271 OSStatus result = AudioOutputUnitStart(audio_unit_); | 272 OSStatus result = AudioOutputUnitStart(audio_unit_); |
272 if (result == noErr) { | 273 if (result == noErr) { |
273 started_ = true; | 274 started_ = true; |
274 } | 275 } |
275 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) | 276 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
276 << "Failed to start acquiring data"; | 277 << "Failed to start acquiring data"; |
277 } | 278 } |
278 | 279 |
279 void AUAudioInputStream::Stop() { | 280 void AUAudioInputStream::Stop() { |
280 if (!started_) | 281 if (!started_) |
281 return; | 282 return; |
| 283 StopAgc(); |
282 OSStatus result = AudioOutputUnitStop(audio_unit_); | 284 OSStatus result = AudioOutputUnitStop(audio_unit_); |
283 if (result == noErr) { | 285 if (result == noErr) { |
284 started_ = false; | 286 started_ = false; |
285 } | 287 } |
286 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) | 288 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
287 << "Failed to stop acquiring data"; | 289 << "Failed to stop acquiring data"; |
288 } | 290 } |
289 | 291 |
290 void AUAudioInputStream::Close() { | 292 void AUAudioInputStream::Close() { |
291 // It is valid to call Close() before calling open or Start(). | 293 // It is valid to call Close() before calling open or Start(). |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 audio_input->audio_buffer_list(), | 478 audio_input->audio_buffer_list(), |
477 time_stamp); | 479 time_stamp); |
478 } | 480 } |
479 | 481 |
480 OSStatus AUAudioInputStream::Provide(UInt32 number_of_frames, | 482 OSStatus AUAudioInputStream::Provide(UInt32 number_of_frames, |
481 AudioBufferList* io_data, | 483 AudioBufferList* io_data, |
482 const AudioTimeStamp* time_stamp) { | 484 const AudioTimeStamp* time_stamp) { |
483 // Update the capture latency. | 485 // Update the capture latency. |
484 double capture_latency_frames = GetCaptureLatency(time_stamp); | 486 double capture_latency_frames = GetCaptureLatency(time_stamp); |
485 | 487 |
486 // Update the AGC volume level once every second. Note that, |volume| is | 488 // The AGC volume level is updated once every second on a separate thread. |
487 // also updated each time SetVolume() is called through IPC by the | 489 // Note that, |volume| is also updated each time SetVolume() is called |
488 // render-side AGC. | 490 // through IPC by the render-side AGC. |
489 double normalized_volume = 0.0; | 491 double normalized_volume = 0.0; |
490 QueryAgcVolume(&normalized_volume); | 492 GetAgcVolume(&normalized_volume); |
491 | 493 |
492 AudioBuffer& buffer = io_data->mBuffers[0]; | 494 AudioBuffer& buffer = io_data->mBuffers[0]; |
493 uint8* audio_data = reinterpret_cast<uint8*>(buffer.mData); | 495 uint8* audio_data = reinterpret_cast<uint8*>(buffer.mData); |
494 uint32 capture_delay_bytes = static_cast<uint32> | 496 uint32 capture_delay_bytes = static_cast<uint32> |
495 ((capture_latency_frames + 0.5) * format_.mBytesPerFrame); | 497 ((capture_latency_frames + 0.5) * format_.mBytesPerFrame); |
496 DCHECK(audio_data); | 498 DCHECK(audio_data); |
497 if (!audio_data) | 499 if (!audio_data) |
498 return kAudioUnitErr_InvalidElement; | 500 return kAudioUnitErr_InvalidElement; |
499 | 501 |
500 // Accumulate captured audio in FIFO until we can match the output size | 502 // Accumulate captured audio in FIFO until we can match the output size |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 kAudioDevicePropertyScopeInput, | 652 kAudioDevicePropertyScopeInput, |
651 static_cast<UInt32>(channel) | 653 static_cast<UInt32>(channel) |
652 }; | 654 }; |
653 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, | 655 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, |
654 &property_address, | 656 &property_address, |
655 &is_settable); | 657 &is_settable); |
656 return (result == noErr) ? is_settable : false; | 658 return (result == noErr) ? is_settable : false; |
657 } | 659 } |
658 | 660 |
659 } // namespace media | 661 } // namespace media |
OLD | NEW |