| 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), |
| 56 last_sample_time_(0.0), | 57 last_sample_time_(0.0), |
| 57 last_number_of_frames_(0), | 58 last_number_of_frames_(0), |
| 58 total_lost_frames_(0), | 59 total_lost_frames_(0), |
| 59 largest_glitch_frames_(0), | 60 largest_glitch_frames_(0), |
| 60 glitches_detected_(0) { | 61 glitches_detected_(0) { |
| 61 // We must have a manager. | 62 // We must have a manager. |
| 62 DCHECK(manager_); | 63 DCHECK(manager_); |
| 63 | 64 |
| 64 DVLOG(1) << "AUHALStream::AUHALStream()"; | 65 DVLOG(1) << "AUHALStream::AUHALStream()"; |
| 65 DVLOG(1) << "Device: " << device; | 66 DVLOG(1) << "Device: " << device; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 } | 254 } |
| 254 | 255 |
| 255 void AUHALStream::ProvideInput(int frame_delay, AudioBus* dest) { | 256 void AUHALStream::ProvideInput(int frame_delay, AudioBus* dest) { |
| 256 base::AutoLock auto_lock(source_lock_); | 257 base::AutoLock auto_lock(source_lock_); |
| 257 if (!source_) { | 258 if (!source_) { |
| 258 dest->Zero(); | 259 dest->Zero(); |
| 259 return; | 260 return; |
| 260 } | 261 } |
| 261 | 262 |
| 262 // Supply the input data and render the output data. | 263 // Supply the input data and render the output data. |
| 263 source_->OnMoreData( | 264 source_->OnMoreData(dest, current_hardware_pending_bytes_ + |
| 264 dest, | 265 frame_delay * params_.GetBytesPerFrame(), |
| 265 current_hardware_pending_bytes_ + | 266 current_lost_frames_); |
| 266 frame_delay * params_.GetBytesPerFrame()); | |
| 267 dest->Scale(volume_); | 267 dest->Scale(volume_); |
| 268 current_lost_frames_ = 0; |
| 268 } | 269 } |
| 269 | 270 |
| 270 // AUHAL callback. | 271 // AUHAL callback. |
| 271 OSStatus AUHALStream::InputProc( | 272 OSStatus AUHALStream::InputProc( |
| 272 void* user_data, | 273 void* user_data, |
| 273 AudioUnitRenderActionFlags* flags, | 274 AudioUnitRenderActionFlags* flags, |
| 274 const AudioTimeStamp* output_time_stamp, | 275 const AudioTimeStamp* output_time_stamp, |
| 275 UInt32 bus_number, | 276 UInt32 bus_number, |
| 276 UInt32 number_of_frames, | 277 UInt32 number_of_frames, |
| 277 AudioBufferList* io_data) { | 278 AudioBufferList* io_data) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 if (last_sample_time_) { | 366 if (last_sample_time_) { |
| 366 DCHECK_NE(0U, last_number_of_frames_); | 367 DCHECK_NE(0U, last_number_of_frames_); |
| 367 UInt32 diff = | 368 UInt32 diff = |
| 368 static_cast<UInt32>(timestamp->mSampleTime - last_sample_time_); | 369 static_cast<UInt32>(timestamp->mSampleTime - last_sample_time_); |
| 369 if (diff != last_number_of_frames_) { | 370 if (diff != last_number_of_frames_) { |
| 370 DCHECK_GT(diff, last_number_of_frames_); | 371 DCHECK_GT(diff, last_number_of_frames_); |
| 371 // We're being asked to render samples post what we expected. Update the | 372 // We're being asked to render samples post what we expected. Update the |
| 372 // glitch count etc and keep a record of the largest glitch. | 373 // glitch count etc and keep a record of the largest glitch. |
| 373 auto lost_frames = diff - last_number_of_frames_; | 374 auto lost_frames = diff - last_number_of_frames_; |
| 374 total_lost_frames_ += lost_frames; | 375 total_lost_frames_ += lost_frames; |
| 376 current_lost_frames_ += lost_frames; |
| 375 if (lost_frames > largest_glitch_frames_) | 377 if (lost_frames > largest_glitch_frames_) |
| 376 largest_glitch_frames_ = lost_frames; | 378 largest_glitch_frames_ = lost_frames; |
| 377 ++glitches_detected_; | 379 ++glitches_detected_; |
| 378 } | 380 } |
| 379 } | 381 } |
| 380 | 382 |
| 381 // Store the last sample time for use next time we get called back. | 383 // Store the last sample time for use next time we get called back. |
| 382 last_sample_time_ = timestamp->mSampleTime; | 384 last_sample_time_ = timestamp->mSampleTime; |
| 383 } | 385 } |
| 384 | 386 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 OSStatus result = AudioUnitUninitialize(audio_unit_); | 545 OSStatus result = AudioUnitUninitialize(audio_unit_); |
| 544 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) | 546 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
| 545 << "AudioUnitUninitialize() failed."; | 547 << "AudioUnitUninitialize() failed."; |
| 546 result = AudioComponentInstanceDispose(audio_unit_); | 548 result = AudioComponentInstanceDispose(audio_unit_); |
| 547 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) | 549 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
| 548 << "AudioComponentInstanceDispose() failed."; | 550 << "AudioComponentInstanceDispose() failed."; |
| 549 audio_unit_ = 0; | 551 audio_unit_ = 0; |
| 550 } | 552 } |
| 551 | 553 |
| 552 } // namespace media | 554 } // namespace media |
| OLD | NEW |