| 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_, |
| 87 static_cast<size_t>(parameters.frames_per_buffer())); |
| 85 } | 88 } |
| 86 | 89 |
| 87 AUAudioOutputStream::~AUAudioOutputStream() { | 90 AUAudioOutputStream::~AUAudioOutputStream() { |
| 88 } | 91 } |
| 89 | 92 |
| 90 bool AUAudioOutputStream::Open() { | 93 bool AUAudioOutputStream::Open() { |
| 91 // Obtain the current input device selected by the user. | 94 // Obtain the current input device selected by the user. |
| 92 UInt32 size = sizeof(output_device_id_); | 95 UInt32 size = sizeof(output_device_id_); |
| 93 OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, | 96 OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, |
| 94 &kDefaultOutputDeviceAddress, | 97 &kDefaultOutputDeviceAddress, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 sizeof(format_)); | 163 sizeof(format_)); |
| 161 if (result != noErr) { | 164 if (result != noErr) { |
| 162 OSSTATUS_DLOG(WARNING, result) | 165 OSSTATUS_DLOG(WARNING, result) |
| 163 << "AudioUnitSetProperty(kAudioUnitProperty_StreamFormat) failed."; | 166 << "AudioUnitSetProperty(kAudioUnitProperty_StreamFormat) failed."; |
| 164 return false; | 167 return false; |
| 165 } | 168 } |
| 166 | 169 |
| 167 // Set the buffer frame size. | 170 // Set the buffer frame size. |
| 168 // WARNING: Setting this value changes the frame size for all audio units in | 171 // 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 | 172 // the current process. It's imperative that the input and output frame sizes |
| 170 // be the same as audio_util::GetAudioHardwareBufferSize(). | 173 // be the same as the frames_per_buffer() returned by |
| 174 // GetDefaultOutputStreamParameters. |
| 171 // See http://crbug.com/154352 for details. | 175 // See http://crbug.com/154352 for details. |
| 172 UInt32 buffer_size = number_of_frames_; | 176 UInt32 buffer_size = number_of_frames_; |
| 173 result = AudioUnitSetProperty( | 177 result = AudioUnitSetProperty( |
| 174 output_unit_, | 178 output_unit_, |
| 175 kAudioDevicePropertyBufferFrameSize, | 179 kAudioDevicePropertyBufferFrameSize, |
| 176 kAudioUnitScope_Output, | 180 kAudioUnitScope_Output, |
| 177 0, | 181 0, |
| 178 &buffer_size, | 182 &buffer_size, |
| 179 sizeof(buffer_size)); | 183 sizeof(buffer_size)); |
| 180 if (result != noErr) { | 184 if (result != noErr) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 if (now_ns > output_time_ns) | 412 if (now_ns > output_time_ns) |
| 409 return 0; | 413 return 0; |
| 410 | 414 |
| 411 double delay_frames = static_cast<double> | 415 double delay_frames = static_cast<double> |
| 412 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate); | 416 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate); |
| 413 | 417 |
| 414 return (delay_frames + hardware_latency_frames_); | 418 return (delay_frames + hardware_latency_frames_); |
| 415 } | 419 } |
| 416 | 420 |
| 417 } // namespace media | 421 } // namespace media |
| OLD | NEW |