OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_auhal_mac.h" | 5 #include "media/audio/mac/audio_auhal_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/bind.h" | 10 #include "base/bind.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 output_channels_(params_.channels()), | 46 output_channels_(params_.channels()), |
47 number_of_frames_(params_.frames_per_buffer()), | 47 number_of_frames_(params_.frames_per_buffer()), |
48 number_of_frames_requested_(0), | 48 number_of_frames_requested_(0), |
49 source_(NULL), | 49 source_(NULL), |
50 device_(device), | 50 device_(device), |
51 audio_unit_(0), | 51 audio_unit_(0), |
52 volume_(1), | 52 volume_(1), |
53 hardware_latency_frames_(0), | 53 hardware_latency_frames_(0), |
54 stopped_(true), | 54 stopped_(true), |
55 current_hardware_pending_bytes_(0), | 55 current_hardware_pending_bytes_(0), |
56 current_lost_frames_(0), | |
57 last_sample_time_(0.0), | 56 last_sample_time_(0.0), |
58 last_number_of_frames_(0), | 57 last_number_of_frames_(0), |
59 total_lost_frames_(0), | 58 total_lost_frames_(0), |
60 largest_glitch_frames_(0), | 59 largest_glitch_frames_(0), |
61 glitches_detected_(0) { | 60 glitches_detected_(0) { |
62 // We must have a manager. | 61 // We must have a manager. |
63 DCHECK(manager_); | 62 DCHECK(manager_); |
64 | 63 |
65 DVLOG(1) << "AUHALStream::AUHALStream()"; | 64 DVLOG(1) << "AUHALStream::AUHALStream()"; |
66 DVLOG(1) << "Device: " << device; | 65 DVLOG(1) << "Device: " << device; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 } | 241 } |
243 | 242 |
244 void AUHALStream::ProvideInput(int frame_delay, AudioBus* dest) { | 243 void AUHALStream::ProvideInput(int frame_delay, AudioBus* dest) { |
245 base::AutoLock auto_lock(source_lock_); | 244 base::AutoLock auto_lock(source_lock_); |
246 if (!source_) { | 245 if (!source_) { |
247 dest->Zero(); | 246 dest->Zero(); |
248 return; | 247 return; |
249 } | 248 } |
250 | 249 |
251 // Supply the input data and render the output data. | 250 // Supply the input data and render the output data. |
252 source_->OnMoreData(dest, current_hardware_pending_bytes_ + | 251 source_->OnMoreData( |
253 frame_delay * params_.GetBytesPerFrame(), | 252 dest, |
254 current_lost_frames_); | 253 current_hardware_pending_bytes_ + |
| 254 frame_delay * params_.GetBytesPerFrame()); |
255 dest->Scale(volume_); | 255 dest->Scale(volume_); |
256 current_lost_frames_ = 0; | |
257 } | 256 } |
258 | 257 |
259 // AUHAL callback. | 258 // AUHAL callback. |
260 OSStatus AUHALStream::InputProc( | 259 OSStatus AUHALStream::InputProc( |
261 void* user_data, | 260 void* user_data, |
262 AudioUnitRenderActionFlags* flags, | 261 AudioUnitRenderActionFlags* flags, |
263 const AudioTimeStamp* output_time_stamp, | 262 const AudioTimeStamp* output_time_stamp, |
264 UInt32 bus_number, | 263 UInt32 bus_number, |
265 UInt32 number_of_frames, | 264 UInt32 number_of_frames, |
266 AudioBufferList* io_data) { | 265 AudioBufferList* io_data) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 if (last_sample_time_) { | 353 if (last_sample_time_) { |
355 DCHECK_NE(0U, last_number_of_frames_); | 354 DCHECK_NE(0U, last_number_of_frames_); |
356 UInt32 diff = | 355 UInt32 diff = |
357 static_cast<UInt32>(timestamp->mSampleTime - last_sample_time_); | 356 static_cast<UInt32>(timestamp->mSampleTime - last_sample_time_); |
358 if (diff != last_number_of_frames_) { | 357 if (diff != last_number_of_frames_) { |
359 DCHECK_GT(diff, last_number_of_frames_); | 358 DCHECK_GT(diff, last_number_of_frames_); |
360 // We're being asked to render samples post what we expected. Update the | 359 // We're being asked to render samples post what we expected. Update the |
361 // glitch count etc and keep a record of the largest glitch. | 360 // glitch count etc and keep a record of the largest glitch. |
362 auto lost_frames = diff - last_number_of_frames_; | 361 auto lost_frames = diff - last_number_of_frames_; |
363 total_lost_frames_ += lost_frames; | 362 total_lost_frames_ += lost_frames; |
364 current_lost_frames_ += lost_frames; | |
365 if (lost_frames > largest_glitch_frames_) | 363 if (lost_frames > largest_glitch_frames_) |
366 largest_glitch_frames_ = lost_frames; | 364 largest_glitch_frames_ = lost_frames; |
367 ++glitches_detected_; | 365 ++glitches_detected_; |
368 } | 366 } |
369 } | 367 } |
370 | 368 |
371 // Store the last sample time for use next time we get called back. | 369 // Store the last sample time for use next time we get called back. |
372 last_sample_time_ = timestamp->mSampleTime; | 370 last_sample_time_ = timestamp->mSampleTime; |
373 } | 371 } |
374 | 372 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 OSStatus result = AudioUnitUninitialize(audio_unit_); | 538 OSStatus result = AudioUnitUninitialize(audio_unit_); |
541 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) | 539 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
542 << "AudioUnitUninitialize() failed."; | 540 << "AudioUnitUninitialize() failed."; |
543 result = AudioComponentInstanceDispose(audio_unit_); | 541 result = AudioComponentInstanceDispose(audio_unit_); |
544 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) | 542 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
545 << "AudioComponentInstanceDispose() failed."; | 543 << "AudioComponentInstanceDispose() failed."; |
546 audio_unit_ = 0; | 544 audio_unit_ = 0; |
547 } | 545 } |
548 | 546 |
549 } // namespace media | 547 } // namespace media |
OLD | NEW |