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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 kAudioOutputUnitProperty_CurrentDevice, | 158 kAudioOutputUnitProperty_CurrentDevice, |
159 kAudioUnitScope_Global, | 159 kAudioUnitScope_Global, |
160 0, | 160 0, |
161 &input_device_id_, | 161 &input_device_id_, |
162 sizeof(input_device_id_)); | 162 sizeof(input_device_id_)); |
163 if (result) { | 163 if (result) { |
164 HandleError(result); | 164 HandleError(result); |
165 return false; | 165 return false; |
166 } | 166 } |
167 | 167 |
168 // Register the input procedure for the AUHAL. | |
169 // This procedure will be called when the AUHAL has received new data | |
170 // from the input device. | |
171 AURenderCallbackStruct callback; | |
172 callback.inputProc = InputProc; | |
173 callback.inputProcRefCon = this; | |
174 result = AudioUnitSetProperty(audio_unit_, | |
175 kAudioOutputUnitProperty_SetInputCallback, | |
176 kAudioUnitScope_Global, | |
177 0, | |
178 &callback, | |
179 sizeof(callback)); | |
180 if (result) { | |
181 HandleError(result); | |
182 return false; | |
183 } | |
184 | |
185 // Set up the the desired (output) format. | 168 // Set up the the desired (output) format. |
186 // For obtaining input from a device, the device format is always expressed | 169 // For obtaining input from a device, the device format is always expressed |
187 // on the output scope of the AUHAL's Element 1. | 170 // on the output scope of the AUHAL's Element 1. |
188 result = AudioUnitSetProperty(audio_unit_, | 171 result = AudioUnitSetProperty(audio_unit_, |
189 kAudioUnitProperty_StreamFormat, | 172 kAudioUnitProperty_StreamFormat, |
190 kAudioUnitScope_Output, | 173 kAudioUnitScope_Output, |
191 1, | 174 1, |
192 &format_, | 175 &format_, |
193 sizeof(format_)); | 176 sizeof(format_)); |
194 if (result) { | 177 if (result) { |
(...skipping 27 matching lines...) Expand all Loading... |
222 kAudioUnitScope_Output, | 205 kAudioUnitScope_Output, |
223 1, | 206 1, |
224 &buffer_size, | 207 &buffer_size, |
225 sizeof(buffer_size)); | 208 sizeof(buffer_size)); |
226 if (result != noErr) { | 209 if (result != noErr) { |
227 HandleError(result); | 210 HandleError(result); |
228 return false; | 211 return false; |
229 } | 212 } |
230 } | 213 } |
231 | 214 |
| 215 // Register the input procedure for the AUHAL. |
| 216 // This procedure will be called when the AUHAL has received new data |
| 217 // from the input device. |
| 218 AURenderCallbackStruct callback; |
| 219 callback.inputProc = InputProc; |
| 220 callback.inputProcRefCon = this; |
| 221 result = AudioUnitSetProperty(audio_unit_, |
| 222 kAudioOutputUnitProperty_SetInputCallback, |
| 223 kAudioUnitScope_Global, |
| 224 0, |
| 225 &callback, |
| 226 sizeof(callback)); |
| 227 if (result) { |
| 228 HandleError(result); |
| 229 return false; |
| 230 } |
| 231 |
232 // Finally, initialize the audio unit and ensure that it is ready to render. | 232 // Finally, initialize the audio unit and ensure that it is ready to render. |
233 // Allocates memory according to the maximum number of audio frames | 233 // Allocates memory according to the maximum number of audio frames |
234 // it can produce in response to a single render call. | 234 // it can produce in response to a single render call. |
235 result = AudioUnitInitialize(audio_unit_); | 235 result = AudioUnitInitialize(audio_unit_); |
236 if (result) { | 236 if (result) { |
237 HandleError(result); | 237 HandleError(result); |
238 return false; | 238 return false; |
239 } | 239 } |
240 | 240 |
241 // The hardware latency is fixed and will not change during the call. | 241 // The hardware latency is fixed and will not change during the call. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 292 } |
293 | 293 |
294 void AUAudioInputStream::Close() { | 294 void AUAudioInputStream::Close() { |
295 // It is valid to call Close() before calling open or Start(). | 295 // It is valid to call Close() before calling open or Start(). |
296 // It is also valid to call Close() after Start() has been called. | 296 // It is also valid to call Close() after Start() has been called. |
297 if (started_) { | 297 if (started_) { |
298 Stop(); | 298 Stop(); |
299 } | 299 } |
300 if (audio_unit_) { | 300 if (audio_unit_) { |
301 // Deallocate the audio unit’s resources. | 301 // Deallocate the audio unit’s resources. |
302 AudioUnitUninitialize(audio_unit_); | 302 OSStatus result = AudioUnitUninitialize(audio_unit_); |
| 303 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
| 304 << "AudioUnitUninitialize() failed."; |
303 | 305 |
304 // Terminates our connection to the AUHAL component. | 306 result = AudioComponentInstanceDispose(audio_unit_); |
305 CloseComponent(audio_unit_); | 307 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
| 308 << "AudioComponentInstanceDispose() failed."; |
| 309 |
306 audio_unit_ = 0; | 310 audio_unit_ = 0; |
307 } | 311 } |
308 | 312 |
309 // Inform the audio manager that we have been closed. This can cause our | 313 // Inform the audio manager that we have been closed. This can cause our |
310 // destruction. | 314 // destruction. |
311 manager_->ReleaseInputStream(this); | 315 manager_->ReleaseInputStream(this); |
312 } | 316 } |
313 | 317 |
314 double AUAudioInputStream::GetMaxVolume() { | 318 double AUAudioInputStream::GetMaxVolume() { |
315 // Verify that we have a valid device. | 319 // Verify that we have a valid device. |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 kAudioDevicePropertyScopeInput, | 646 kAudioDevicePropertyScopeInput, |
643 static_cast<UInt32>(channel) | 647 static_cast<UInt32>(channel) |
644 }; | 648 }; |
645 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, | 649 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, |
646 &property_address, | 650 &property_address, |
647 &is_settable); | 651 &is_settable); |
648 return (result == noErr) ? is_settable : false; | 652 return (result == noErr) ? is_settable : false; |
649 } | 653 } |
650 | 654 |
651 } // namespace media | 655 } // namespace media |
OLD | NEW |