| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 249 |
| 250 AudioBuffer& buffer = io_data->mBuffers[0]; | 250 AudioBuffer& buffer = io_data->mBuffers[0]; |
| 251 uint8* audio_data = reinterpret_cast<uint8*>(buffer.mData); | 251 uint8* audio_data = reinterpret_cast<uint8*>(buffer.mData); |
| 252 uint32 hardware_pending_bytes = static_cast<uint32> | 252 uint32 hardware_pending_bytes = static_cast<uint32> |
| 253 ((playout_latency_frames + 0.5) * format_.mBytesPerFrame); | 253 ((playout_latency_frames + 0.5) * format_.mBytesPerFrame); |
| 254 | 254 |
| 255 // Unfortunately AUAudioInputStream and AUAudioOutputStream share the frame | 255 // Unfortunately AUAudioInputStream and AUAudioOutputStream share the frame |
| 256 // size set by kAudioDevicePropertyBufferFrameSize above on a per process | 256 // size set by kAudioDevicePropertyBufferFrameSize above on a per process |
| 257 // basis. What this means is that the |number_of_frames| value may be larger | 257 // basis. What this means is that the |number_of_frames| value may be larger |
| 258 // or smaller than the value set during Configure(). In this case either | 258 // or smaller than the value set during Configure(). In this case either |
| 259 // audio input or audio output will be broken. | 259 // audio input or audio output will be broken, so just output silence. |
| 260 // See http://crbug.com/154352 for details. | 260 // TODO(crogers): Figure out what can trigger a change in |number_of_frames|. |
| 261 CHECK_EQ(number_of_frames, static_cast<UInt32>(audio_bus_->frames())); | 261 // See http://crbug.com/1543 for details. |
| 262 if (number_of_frames != static_cast<UInt32>(audio_bus_->frames())) { |
| 263 memset(audio_data, 0, number_of_frames * format_.mBytesPerFrame); |
| 264 return noErr; |
| 265 } |
| 262 | 266 |
| 263 int frames_filled = source_->OnMoreData( | 267 int frames_filled = source_->OnMoreData( |
| 264 audio_bus_.get(), AudioBuffersState(0, hardware_pending_bytes)); | 268 audio_bus_.get(), AudioBuffersState(0, hardware_pending_bytes)); |
| 265 | 269 |
| 266 // Note: If this ever changes to output raw float the data must be clipped and | 270 // Note: If this ever changes to output raw float the data must be clipped and |
| 267 // sanitized since it may come from an untrusted source such as NaCl. | 271 // sanitized since it may come from an untrusted source such as NaCl. |
| 268 audio_bus_->ToInterleaved( | 272 audio_bus_->ToInterleaved( |
| 269 frames_filled, format_.mBitsPerChannel / 8, audio_data); | 273 frames_filled, format_.mBitsPerChannel / 8, audio_data); |
| 270 uint32 filled = frames_filled * format_.mBytesPerFrame; | 274 uint32 filled = frames_filled * format_.mBytesPerFrame; |
| 271 | 275 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 UInt64 output_time_ns = AudioConvertHostTimeToNanos( | 392 UInt64 output_time_ns = AudioConvertHostTimeToNanos( |
| 389 output_time_stamp->mHostTime); | 393 output_time_stamp->mHostTime); |
| 390 UInt64 now_ns = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime()); | 394 UInt64 now_ns = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime()); |
| 391 double delay_frames = static_cast<double> | 395 double delay_frames = static_cast<double> |
| 392 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate); | 396 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate); |
| 393 | 397 |
| 394 return (delay_frames + hardware_latency_frames_); | 398 return (delay_frames + hardware_latency_frames_); |
| 395 } | 399 } |
| 396 | 400 |
| 397 } // namespace media | 401 } // namespace media |
| OLD | NEW |