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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 OSStatus AUHALStream::Render( | 200 OSStatus AUHALStream::Render( |
200 AudioUnitRenderActionFlags* flags, | 201 AudioUnitRenderActionFlags* flags, |
201 const AudioTimeStamp* output_time_stamp, | 202 const AudioTimeStamp* output_time_stamp, |
202 UInt32 bus_number, | 203 UInt32 bus_number, |
203 UInt32 number_of_frames, | 204 UInt32 number_of_frames, |
204 AudioBufferList* data) { | 205 AudioBufferList* data) { |
205 TRACE_EVENT0("audio", "AUHALStream::Render"); | 206 TRACE_EVENT0("audio", "AUHALStream::Render"); |
206 | 207 |
207 UpdatePlayoutTimestamp(output_time_stamp); | 208 UpdatePlayoutTimestamp(output_time_stamp); |
208 | 209 |
| 210 // Inform the source about any skipped (lost) frames. If we use a fifo this |
| 211 // will be out of sync with the fifo pulls (different buffer sizes), so we do |
| 212 // it here and not in ProvideInput(). |
| 213 if (lost_frames > 0) { |
| 214 base::AutoLock auto_lock(source_lock_); |
| 215 if (source_) |
| 216 source_->OnSkippedData(lost_frames); |
| 217 } |
| 218 |
209 // If the stream parameters change for any reason, we need to insert a FIFO | 219 // If the stream parameters change for any reason, we need to insert a FIFO |
210 // since the OnMoreData() pipeline can't handle frame size changes. | 220 // since the OnMoreData() pipeline can't handle frame size changes. |
211 if (number_of_frames != number_of_frames_) { | 221 if (number_of_frames != number_of_frames_) { |
212 // Create a FIFO on the fly to handle any discrepancies in callback rates. | 222 // Create a FIFO on the fly to handle any discrepancies in callback rates. |
213 if (!audio_fifo_) { | 223 if (!audio_fifo_) { |
214 number_of_frames_requested_ = number_of_frames; | 224 number_of_frames_requested_ = number_of_frames; |
215 DVLOG(1) << "Audio frame size changed from " << number_of_frames_ | 225 DVLOG(1) << "Audio frame size changed from " << number_of_frames_ |
216 << " to " << number_of_frames | 226 << " to " << number_of_frames |
217 << "; adding FIFO to compensate."; | 227 << "; adding FIFO to compensate."; |
218 audio_fifo_.reset(new AudioPullFifo( | 228 audio_fifo_.reset(new AudioPullFifo( |
(...skipping 22 matching lines...) Expand all Loading... |
241 } | 251 } |
242 | 252 |
243 void AUHALStream::ProvideInput(int frame_delay, AudioBus* dest) { | 253 void AUHALStream::ProvideInput(int frame_delay, AudioBus* dest) { |
244 base::AutoLock auto_lock(source_lock_); | 254 base::AutoLock auto_lock(source_lock_); |
245 if (!source_) { | 255 if (!source_) { |
246 dest->Zero(); | 256 dest->Zero(); |
247 return; | 257 return; |
248 } | 258 } |
249 | 259 |
250 // Supply the input data and render the output data. | 260 // Supply the input data and render the output data. |
251 source_->OnMoreData( | 261 source_->OnMoreData(dest, current_hardware_pending_bytes_ + |
252 dest, | 262 frame_delay * params_.GetBytesPerFrame(), |
253 current_hardware_pending_bytes_ + | 263 current_lost_frames_); |
254 frame_delay * params_.GetBytesPerFrame()); | |
255 dest->Scale(volume_); | 264 dest->Scale(volume_); |
| 265 current_lost_frames_ = 0; |
256 } | 266 } |
257 | 267 |
258 // AUHAL callback. | 268 // AUHAL callback. |
259 OSStatus AUHALStream::InputProc( | 269 OSStatus AUHALStream::InputProc( |
260 void* user_data, | 270 void* user_data, |
261 AudioUnitRenderActionFlags* flags, | 271 AudioUnitRenderActionFlags* flags, |
262 const AudioTimeStamp* output_time_stamp, | 272 const AudioTimeStamp* output_time_stamp, |
263 UInt32 bus_number, | 273 UInt32 bus_number, |
264 UInt32 number_of_frames, | 274 UInt32 number_of_frames, |
265 AudioBufferList* io_data) { | 275 AudioBufferList* io_data) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 return; | 361 return; |
352 | 362 |
353 if (last_sample_time_) { | 363 if (last_sample_time_) { |
354 DCHECK_NE(0U, last_number_of_frames_); | 364 DCHECK_NE(0U, last_number_of_frames_); |
355 UInt32 diff = | 365 UInt32 diff = |
356 static_cast<UInt32>(timestamp->mSampleTime - last_sample_time_); | 366 static_cast<UInt32>(timestamp->mSampleTime - last_sample_time_); |
357 if (diff != last_number_of_frames_) { | 367 if (diff != last_number_of_frames_) { |
358 DCHECK_GT(diff, last_number_of_frames_); | 368 DCHECK_GT(diff, last_number_of_frames_); |
359 // We're being asked to render samples post what we expected. Update the | 369 // We're being asked to render samples post what we expected. Update the |
360 // glitch count etc and keep a record of the largest glitch. | 370 // glitch count etc and keep a record of the largest glitch. |
361 auto lost_frames = diff - last_number_of_frames_; | 371 UInt32 lost_frames = diff - last_number_of_frames_; |
362 total_lost_frames_ += lost_frames; | 372 total_lost_frames_ += lost_frames; |
| 373 current_lost_frames_ += lost_frames; |
363 if (lost_frames > largest_glitch_frames_) | 374 if (lost_frames > largest_glitch_frames_) |
364 largest_glitch_frames_ = lost_frames; | 375 largest_glitch_frames_ = lost_frames; |
365 ++glitches_detected_; | 376 ++glitches_detected_; |
366 } | 377 } |
367 } | 378 } |
368 | 379 |
369 // Store the last sample time for use next time we get called back. | 380 // Store the last sample time for use next time we get called back. |
370 last_sample_time_ = timestamp->mSampleTime; | 381 last_sample_time_ = timestamp->mSampleTime; |
371 } | 382 } |
372 | 383 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 OSStatus result = AudioUnitUninitialize(audio_unit_); | 549 OSStatus result = AudioUnitUninitialize(audio_unit_); |
539 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) | 550 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
540 << "AudioUnitUninitialize() failed."; | 551 << "AudioUnitUninitialize() failed."; |
541 result = AudioComponentInstanceDispose(audio_unit_); | 552 result = AudioComponentInstanceDispose(audio_unit_); |
542 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) | 553 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
543 << "AudioComponentInstanceDispose() failed."; | 554 << "AudioComponentInstanceDispose() failed."; |
544 audio_unit_ = 0; | 555 audio_unit_ = 0; |
545 } | 556 } |
546 | 557 |
547 } // namespace media | 558 } // namespace media |
OLD | NEW |