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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 format_.mReserved = 0; | 60 format_.mReserved = 0; |
61 | 61 |
62 DVLOG(1) << "Desired ouput format: " << format_; | 62 DVLOG(1) << "Desired ouput format: " << format_; |
63 | 63 |
64 // Set number of sample frames per callback used by the internal audio layer. | 64 // Set number of sample frames per callback used by the internal audio layer. |
65 // An internal FIFO is then utilized to adapt the internal size to the size | 65 // An internal FIFO is then utilized to adapt the internal size to the size |
66 // requested by the client. | 66 // requested by the client. |
67 // Note that we use the same native buffer size as for the output side here | 67 // Note that we use the same native buffer size as for the output side here |
68 // since the AUHAL implementation requires that both capture and render side | 68 // since the AUHAL implementation requires that both capture and render side |
69 // use the same buffer size. See http://crbug.com/154352 for more details. | 69 // use the same buffer size. See http://crbug.com/154352 for more details. |
70 number_of_frames_ = GetAudioHardwareBufferSize(); | 70 // TODO(xians): Get the audio parameters from the right device. |
| 71 const AudioParameters parameters = |
| 72 manager_->GetInputStreamParameters(AudioManagerBase::kDefaultDeviceId); |
| 73 number_of_frames_ = parameters.frames_per_buffer(); |
71 DVLOG(1) << "Size of data buffer in frames : " << number_of_frames_; | 74 DVLOG(1) << "Size of data buffer in frames : " << number_of_frames_; |
72 | 75 |
73 // Derive size (in bytes) of the buffers that we will render to. | 76 // Derive size (in bytes) of the buffers that we will render to. |
74 UInt32 data_byte_size = number_of_frames_ * format_.mBytesPerFrame; | 77 UInt32 data_byte_size = number_of_frames_ * format_.mBytesPerFrame; |
75 DVLOG(1) << "Size of data buffer in bytes : " << data_byte_size; | 78 DVLOG(1) << "Size of data buffer in bytes : " << data_byte_size; |
76 | 79 |
77 // Allocate AudioBuffers to be used as storage for the received audio. | 80 // Allocate AudioBuffers to be used as storage for the received audio. |
78 // The AudioBufferList structure works as a placeholder for the | 81 // The AudioBufferList structure works as a placeholder for the |
79 // AudioBuffer structure, which holds a pointer to the actual data buffer. | 82 // AudioBuffer structure, which holds a pointer to the actual data buffer. |
80 audio_data_buffer_.reset(new uint8[data_byte_size]); | 83 audio_data_buffer_.reset(new uint8[data_byte_size]); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 &format_, | 221 &format_, |
219 sizeof(format_)); | 222 sizeof(format_)); |
220 if (result) { | 223 if (result) { |
221 HandleError(result); | 224 HandleError(result); |
222 return false; | 225 return false; |
223 } | 226 } |
224 | 227 |
225 // Set the desired number of frames in the IO buffer (output scope). | 228 // Set the desired number of frames in the IO buffer (output scope). |
226 // WARNING: Setting this value changes the frame size for all audio units in | 229 // WARNING: Setting this value changes the frame size for all audio units in |
227 // the current process. It's imperative that the input and output frame sizes | 230 // the current process. It's imperative that the input and output frame sizes |
228 // be the same as audio_util::GetAudioHardwareBufferSize(). | 231 // be the same as the frames_per_buffer() returned by |
| 232 // GetInputStreamParameters(). |
229 // TODO(henrika): Due to http://crrev.com/159666 this is currently not true | 233 // TODO(henrika): Due to http://crrev.com/159666 this is currently not true |
230 // and should be fixed, a CHECK() should be added at that time. | 234 // and should be fixed, a CHECK() should be added at that time. |
231 result = AudioUnitSetProperty(audio_unit_, | 235 result = AudioUnitSetProperty(audio_unit_, |
232 kAudioDevicePropertyBufferFrameSize, | 236 kAudioDevicePropertyBufferFrameSize, |
233 kAudioUnitScope_Output, | 237 kAudioUnitScope_Output, |
234 1, | 238 1, |
235 &number_of_frames_, // size is set in the ctor | 239 &number_of_frames_, // size is set in the ctor |
236 sizeof(number_of_frames_)); | 240 sizeof(number_of_frames_)); |
237 if (result) { | 241 if (result) { |
238 HandleError(result); | 242 HandleError(result); |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 kAudioDevicePropertyScopeInput, | 651 kAudioDevicePropertyScopeInput, |
648 static_cast<UInt32>(channel) | 652 static_cast<UInt32>(channel) |
649 }; | 653 }; |
650 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, | 654 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, |
651 &property_address, | 655 &property_address, |
652 &is_settable); | 656 &is_settable); |
653 return (result == noErr) ? is_settable : false; | 657 return (result == noErr) ? is_settable : false; |
654 } | 658 } |
655 | 659 |
656 } // namespace media | 660 } // namespace media |
OLD | NEW |