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_output_mac.h" | 5 #include "media/audio/mac/audio_low_latency_output_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/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 format_.mFramesPerPacket = 1; | 74 format_.mFramesPerPacket = 1; |
75 format_.mBytesPerPacket = (format_.mBitsPerChannel * params.channels()) / 8; | 75 format_.mBytesPerPacket = (format_.mBitsPerChannel * params.channels()) / 8; |
76 format_.mBytesPerFrame = format_.mBytesPerPacket; | 76 format_.mBytesPerFrame = format_.mBytesPerPacket; |
77 format_.mReserved = 0; | 77 format_.mReserved = 0; |
78 | 78 |
79 DVLOG(1) << "Desired ouput format: " << format_; | 79 DVLOG(1) << "Desired ouput format: " << format_; |
80 | 80 |
81 // Calculate the number of sample frames per callback. | 81 // Calculate the number of sample frames per callback. |
82 number_of_frames_ = params.GetBytesPerBuffer() / format_.mBytesPerPacket; | 82 number_of_frames_ = params.GetBytesPerBuffer() / format_.mBytesPerPacket; |
83 DVLOG(1) << "Number of frames per callback: " << number_of_frames_; | 83 DVLOG(1) << "Number of frames per callback: " << number_of_frames_; |
84 CHECK_EQ(number_of_frames_, GetAudioHardwareBufferSize()); | 84 const AudioParameters parameters = |
| 85 manager_->GetDefaultOutputStreamParameters(); |
| 86 CHECK_EQ(number_of_frames_, parameters.frames_per_buffer()); |
85 } | 87 } |
86 | 88 |
87 AUAudioOutputStream::~AUAudioOutputStream() { | 89 AUAudioOutputStream::~AUAudioOutputStream() { |
88 } | 90 } |
89 | 91 |
90 bool AUAudioOutputStream::Open() { | 92 bool AUAudioOutputStream::Open() { |
91 // Obtain the current input device selected by the user. | 93 // Obtain the current input device selected by the user. |
92 UInt32 size = sizeof(output_device_id_); | 94 UInt32 size = sizeof(output_device_id_); |
93 OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, | 95 OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, |
94 &kDefaultOutputDeviceAddress, | 96 &kDefaultOutputDeviceAddress, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 sizeof(format_)); | 162 sizeof(format_)); |
161 if (result != noErr) { | 163 if (result != noErr) { |
162 OSSTATUS_DLOG(WARNING, result) | 164 OSSTATUS_DLOG(WARNING, result) |
163 << "AudioUnitSetProperty(kAudioUnitProperty_StreamFormat) failed."; | 165 << "AudioUnitSetProperty(kAudioUnitProperty_StreamFormat) failed."; |
164 return false; | 166 return false; |
165 } | 167 } |
166 | 168 |
167 // Set the buffer frame size. | 169 // Set the buffer frame size. |
168 // WARNING: Setting this value changes the frame size for all audio units in | 170 // WARNING: Setting this value changes the frame size for all audio units in |
169 // the current process. It's imperative that the input and output frame sizes | 171 // the current process. It's imperative that the input and output frame sizes |
170 // be the same as audio_util::GetAudioHardwareBufferSize(). | 172 // be the same as the frames_per_buffer() returned by |
| 173 // GetDefaultOutputStreamParameters. |
171 // See http://crbug.com/154352 for details. | 174 // See http://crbug.com/154352 for details. |
172 UInt32 buffer_size = number_of_frames_; | 175 UInt32 buffer_size = number_of_frames_; |
173 result = AudioUnitSetProperty( | 176 result = AudioUnitSetProperty( |
174 output_unit_, | 177 output_unit_, |
175 kAudioDevicePropertyBufferFrameSize, | 178 kAudioDevicePropertyBufferFrameSize, |
176 kAudioUnitScope_Output, | 179 kAudioUnitScope_Output, |
177 0, | 180 0, |
178 &buffer_size, | 181 &buffer_size, |
179 sizeof(buffer_size)); | 182 sizeof(buffer_size)); |
180 if (result != noErr) { | 183 if (result != noErr) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 if (now_ns > output_time_ns) | 411 if (now_ns > output_time_ns) |
409 return 0; | 412 return 0; |
410 | 413 |
411 double delay_frames = static_cast<double> | 414 double delay_frames = static_cast<double> |
412 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate); | 415 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate); |
413 | 416 |
414 return (delay_frames + hardware_latency_frames_); | 417 return (delay_frames + hardware_latency_frames_); |
415 } | 418 } |
416 | 419 |
417 } // namespace media | 420 } // namespace media |
OLD | NEW |