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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 kAudioUnitScope_Output, | 188 kAudioUnitScope_Output, |
189 1, | 189 1, |
190 &format_, | 190 &format_, |
191 sizeof(format_)); | 191 sizeof(format_)); |
192 if (result) { | 192 if (result) { |
193 HandleError(result); | 193 HandleError(result); |
194 return false; | 194 return false; |
195 } | 195 } |
196 | 196 |
197 // Set the desired number of frames in the IO buffer (output scope). | 197 // Set the desired number of frames in the IO buffer (output scope). |
198 // WARNING: Setting this value changes the frame size for all audio units in | |
199 // the current process. It's imperative that the input and output frame sizes | |
200 // be the same as audio_util::GetAudioHardwareBufferSize(). | |
201 // TODO(henrika): Due to http://crrev.com/159666 this is currently not true | |
202 // and should be fixed, a CHECK() should be added at that time. | |
198 result = AudioUnitSetProperty(audio_unit_, | 203 result = AudioUnitSetProperty(audio_unit_, |
199 kAudioDevicePropertyBufferFrameSize, | 204 kAudioDevicePropertyBufferFrameSize, |
200 kAudioUnitScope_Output, | 205 kAudioUnitScope_Output, |
201 1, | 206 1, |
202 &number_of_frames_, // size is set in the ctor | 207 &number_of_frames_, // size is set in the ctor |
203 sizeof(number_of_frames_)); | 208 sizeof(number_of_frames_)); |
204 if (result) { | 209 if (result) { |
205 HandleError(result); | 210 HandleError(result); |
206 return false; | 211 return false; |
207 } | 212 } |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 QueryAgcVolume(&normalized_volume); | 458 QueryAgcVolume(&normalized_volume); |
454 | 459 |
455 AudioBuffer& buffer = io_data->mBuffers[0]; | 460 AudioBuffer& buffer = io_data->mBuffers[0]; |
456 uint8* audio_data = reinterpret_cast<uint8*>(buffer.mData); | 461 uint8* audio_data = reinterpret_cast<uint8*>(buffer.mData); |
457 uint32 capture_delay_bytes = static_cast<uint32> | 462 uint32 capture_delay_bytes = static_cast<uint32> |
458 ((capture_latency_frames + 0.5) * format_.mBytesPerFrame); | 463 ((capture_latency_frames + 0.5) * format_.mBytesPerFrame); |
459 DCHECK(audio_data); | 464 DCHECK(audio_data); |
460 if (!audio_data) | 465 if (!audio_data) |
461 return kAudioUnitErr_InvalidElement; | 466 return kAudioUnitErr_InvalidElement; |
462 | 467 |
468 // Unfortunately AUAudioInputStream and AUAudioOutputStream share the frame | |
469 // size set by kAudioDevicePropertyBufferFrameSize above on a per process | |
Chris Rogers
2012/10/08 22:14:31
nit: "process process"
DaleCurtis
2012/10/08 22:21:56
Done.
| |
470 // process basis. What this means is that the |number_of_frames| value may be | |
471 // larger or smaller than the value set during Configure(). In this case | |
472 // either audio input or audio output will be broken, so just do nothing. | |
473 // TODO(henrika): This should never happen so long as we're always using the | |
474 // hardware sample rate and the input/output streams configure the same frame | |
475 // size. This is currently not true. See http://crbug.com/154352. Once | |
476 // fixed, a CHECK() should be added and this wall of text removed. | |
477 if (number_of_frames != static_cast<UInt32>(number_of_frames_)) | |
478 return noErr; | |
479 | |
463 // Deliver data packet, delay estimation and volume level to the user. | 480 // Deliver data packet, delay estimation and volume level to the user. |
464 sink_->OnData(this, | 481 sink_->OnData(this, |
465 audio_data, | 482 audio_data, |
466 buffer.mDataByteSize, | 483 buffer.mDataByteSize, |
467 capture_delay_bytes, | 484 capture_delay_bytes, |
468 normalized_volume); | 485 normalized_volume); |
469 | 486 |
470 return noErr; | 487 return noErr; |
471 } | 488 } |
472 | 489 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 kAudioDevicePropertyScopeInput, | 618 kAudioDevicePropertyScopeInput, |
602 static_cast<UInt32>(channel) | 619 static_cast<UInt32>(channel) |
603 }; | 620 }; |
604 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, | 621 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, |
605 &property_address, | 622 &property_address, |
606 &is_settable); | 623 &is_settable); |
607 return (result == noErr) ? is_settable : false; | 624 return (result == noErr) ? is_settable : false; |
608 } | 625 } |
609 | 626 |
610 } // namespace media | 627 } // namespace media |
OLD | NEW |