Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: media/audio/mac/audio_auhal_mac.cc

Issue 1487983002: Forward the number of skipped frames by the OS in audio playout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Writing skipped frames to shared memory. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // be contended in the middle of stream processing here (starting and stopping 198 // be contended in the middle of stream processing here (starting and stopping
198 // the stream are ok) because this is running on a real-time thread. 199 // the stream are ok) because this is running on a real-time thread.
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 UpdatePlayoutTimestampAndStats(output_time_stamp);
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 }
208 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.";
(...skipping 23 matching lines...) Expand all
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // the bots, probably less so in the wild. 349 // the bots, probably less so in the wild.
340 if (now_ns > output_time_ns) 350 if (now_ns > output_time_ns)
341 return 0; 351 return 0;
342 352
343 double delay_frames = static_cast<double> 353 double delay_frames = static_cast<double>
344 (1e-9 * (output_time_ns - now_ns) * output_format_.mSampleRate); 354 (1e-9 * (output_time_ns - now_ns) * output_format_.mSampleRate);
345 355
346 return (delay_frames + hardware_latency_frames_); 356 return (delay_frames + hardware_latency_frames_);
347 } 357 }
348 358
349 void AUHALStream::UpdatePlayoutTimestamp(const AudioTimeStamp* timestamp) { 359 void AUHALStream::UpdatePlayoutTimestampAndStats(
tommi (sloooow) - chröme 2015/12/08 08:34:51 nit: I'd just keep the name as it was. "AndStats"
Henrik Grunell 2015/12/08 09:30:34 Yeah, it's not entirely correctly named either. Ch
360 const AudioTimeStamp* timestamp) {
350 if ((timestamp->mFlags & kAudioTimeStampSampleTimeValid) == 0) 361 if ((timestamp->mFlags & kAudioTimeStampSampleTimeValid) == 0)
351 return; 362 return;
352 363
353 if (last_sample_time_) { 364 if (last_sample_time_) {
354 DCHECK_NE(0U, last_number_of_frames_); 365 DCHECK_NE(0U, last_number_of_frames_);
355 UInt32 diff = 366 UInt32 diff =
356 static_cast<UInt32>(timestamp->mSampleTime - last_sample_time_); 367 static_cast<UInt32>(timestamp->mSampleTime - last_sample_time_);
357 if (diff != last_number_of_frames_) { 368 if (diff != last_number_of_frames_) {
358 DCHECK_GT(diff, last_number_of_frames_); 369 DCHECK_GT(diff, last_number_of_frames_);
359 // We're being asked to render samples post what we expected. Update the 370 // 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. 371 // glitch count etc and keep a record of the largest glitch.
361 auto lost_frames = diff - last_number_of_frames_; 372 UInt32 lost_frames = diff - last_number_of_frames_;
362 total_lost_frames_ += lost_frames; 373 total_lost_frames_ += lost_frames;
374 current_lost_frames_ += lost_frames;
363 if (lost_frames > largest_glitch_frames_) 375 if (lost_frames > largest_glitch_frames_)
364 largest_glitch_frames_ = lost_frames; 376 largest_glitch_frames_ = lost_frames;
365 ++glitches_detected_; 377 ++glitches_detected_;
366 } 378 }
367 } 379 }
368 380
369 // Store the last sample time for use next time we get called back. 381 // Store the last sample time for use next time we get called back.
370 last_sample_time_ = timestamp->mSampleTime; 382 last_sample_time_ = timestamp->mSampleTime;
371 } 383 }
372 384
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 OSStatus result = AudioUnitUninitialize(audio_unit_); 550 OSStatus result = AudioUnitUninitialize(audio_unit_);
539 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) 551 OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
540 << "AudioUnitUninitialize() failed."; 552 << "AudioUnitUninitialize() failed.";
541 result = AudioComponentInstanceDispose(audio_unit_); 553 result = AudioComponentInstanceDispose(audio_unit_);
542 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) 554 OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
543 << "AudioComponentInstanceDispose() failed."; 555 << "AudioComponentInstanceDispose() failed.";
544 audio_unit_ = 0; 556 audio_unit_ = 0;
545 } 557 }
546 558
547 } // namespace media 559 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698