| 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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 // and notify the audio manager, which likely will destroy this object. | 46 // and notify the audio manager, which likely will destroy this object. |
| 47 | 47 |
| 48 AUAudioOutputStream::AUAudioOutputStream( | 48 AUAudioOutputStream::AUAudioOutputStream( |
| 49 AudioManagerMac* manager, const AudioParameters& params) | 49 AudioManagerMac* manager, const AudioParameters& params) |
| 50 : manager_(manager), | 50 : manager_(manager), |
| 51 source_(NULL), | 51 source_(NULL), |
| 52 output_unit_(0), | 52 output_unit_(0), |
| 53 output_device_id_(kAudioObjectUnknown), | 53 output_device_id_(kAudioObjectUnknown), |
| 54 volume_(1), | 54 volume_(1), |
| 55 hardware_latency_frames_(0), | 55 hardware_latency_frames_(0), |
| 56 stopped_(false) { | 56 stopped_(false), |
| 57 audio_bus_(AudioBus::Create(params)) { |
| 57 // We must have a manager. | 58 // We must have a manager. |
| 58 DCHECK(manager_); | 59 DCHECK(manager_); |
| 59 // A frame is one sample across all channels. In interleaved audio the per | 60 // A frame is one sample across all channels. In interleaved audio the per |
| 60 // frame fields identify the set of n |channels|. In uncompressed audio, a | 61 // frame fields identify the set of n |channels|. In uncompressed audio, a |
| 61 // packet is always one frame. | 62 // packet is always one frame. |
| 62 format_.mSampleRate = params.sample_rate(); | 63 format_.mSampleRate = params.sample_rate(); |
| 63 format_.mFormatID = kAudioFormatLinearPCM; | 64 format_.mFormatID = kAudioFormatLinearPCM; |
| 64 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked | | 65 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked | |
| 65 kLinearPCMFormatFlagIsSignedInteger; | 66 kLinearPCMFormatFlagIsSignedInteger; |
| 66 format_.mBitsPerChannel = params.bits_per_sample(); | 67 format_.mBitsPerChannel = params.bits_per_sample(); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 OSStatus AUAudioOutputStream::Render(UInt32 number_of_frames, | 220 OSStatus AUAudioOutputStream::Render(UInt32 number_of_frames, |
| 220 AudioBufferList* io_data, | 221 AudioBufferList* io_data, |
| 221 const AudioTimeStamp* output_time_stamp) { | 222 const AudioTimeStamp* output_time_stamp) { |
| 222 // Update the playout latency. | 223 // Update the playout latency. |
| 223 double playout_latency_frames = GetPlayoutLatency(output_time_stamp); | 224 double playout_latency_frames = GetPlayoutLatency(output_time_stamp); |
| 224 | 225 |
| 225 AudioBuffer& buffer = io_data->mBuffers[0]; | 226 AudioBuffer& buffer = io_data->mBuffers[0]; |
| 226 uint8* audio_data = reinterpret_cast<uint8*>(buffer.mData); | 227 uint8* audio_data = reinterpret_cast<uint8*>(buffer.mData); |
| 227 uint32 hardware_pending_bytes = static_cast<uint32> | 228 uint32 hardware_pending_bytes = static_cast<uint32> |
| 228 ((playout_latency_frames + 0.5) * format_.mBytesPerFrame); | 229 ((playout_latency_frames + 0.5) * format_.mBytesPerFrame); |
| 229 uint32 filled = source_->OnMoreData( | 230 |
| 230 audio_data, buffer.mDataByteSize, | 231 DCHECK_EQ(number_of_frames, static_cast<UInt32>(audio_bus_->frames())); |
| 231 AudioBuffersState(0, hardware_pending_bytes)); | 232 int frames_filled = source_->OnMoreData( |
| 233 audio_bus_.get(), AudioBuffersState(0, hardware_pending_bytes)); |
| 234 audio_bus_->ToInterleaved( |
| 235 frames_filled, format_.mBitsPerChannel / 8, audio_data); |
| 236 uint32 filled = frames_filled * format_.mBytesPerFrame; |
| 232 | 237 |
| 233 // Handle channel order for 5.1 audio. | 238 // Handle channel order for 5.1 audio. |
| 239 // TODO(dalecurtis): Channel downmixing, upmixing, should be done in mixer; |
| 240 // volume adjust should use SSE optimized vector_fmul() prior to interleave. |
| 234 if (format_.mChannelsPerFrame == 6) { | 241 if (format_.mChannelsPerFrame == 6) { |
| 235 if (format_.mBitsPerChannel == 8) { | 242 if (format_.mBitsPerChannel == 8) { |
| 236 SwizzleCoreAudioLayout5_1(reinterpret_cast<uint8*>(audio_data), filled); | 243 SwizzleCoreAudioLayout5_1(reinterpret_cast<uint8*>(audio_data), filled); |
| 237 } else if (format_.mBitsPerChannel == 16) { | 244 } else if (format_.mBitsPerChannel == 16) { |
| 238 SwizzleCoreAudioLayout5_1(reinterpret_cast<int16*>(audio_data), filled); | 245 SwizzleCoreAudioLayout5_1(reinterpret_cast<int16*>(audio_data), filled); |
| 239 } else if (format_.mBitsPerChannel == 32) { | 246 } else if (format_.mBitsPerChannel == 32) { |
| 240 SwizzleCoreAudioLayout5_1(reinterpret_cast<int32*>(audio_data), filled); | 247 SwizzleCoreAudioLayout5_1(reinterpret_cast<int32*>(audio_data), filled); |
| 241 } | 248 } |
| 242 } | 249 } |
| 243 | 250 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 UInt64 output_time_ns = AudioConvertHostTimeToNanos( | 354 UInt64 output_time_ns = AudioConvertHostTimeToNanos( |
| 348 output_time_stamp->mHostTime); | 355 output_time_stamp->mHostTime); |
| 349 UInt64 now_ns = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime()); | 356 UInt64 now_ns = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime()); |
| 350 double delay_frames = static_cast<double> | 357 double delay_frames = static_cast<double> |
| 351 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate); | 358 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate); |
| 352 | 359 |
| 353 return (delay_frames + hardware_latency_frames_); | 360 return (delay_frames + hardware_latency_frames_); |
| 354 } | 361 } |
| 355 | 362 |
| 356 } // namespace media | 363 } // namespace media |
| OLD | NEW |