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

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

Issue 9310004: Fix crash on Mac OS X caused by querying audio stream latency. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/logging.h" 10 #include "base/logging.h"
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 size = sizeof(device_latency_frames); 321 size = sizeof(device_latency_frames);
322 result = AudioObjectGetPropertyData(output_device_id_, 322 result = AudioObjectGetPropertyData(output_device_id_,
323 &property_address, 323 &property_address,
324 0, 324 0,
325 NULL, 325 NULL,
326 &size, 326 &size,
327 &device_latency_frames); 327 &device_latency_frames);
328 OSSTATUS_DLOG_IF(WARNING, result != noErr, result) 328 OSSTATUS_DLOG_IF(WARNING, result != noErr, result)
329 << "Could not get audio device latency"; 329 << "Could not get audio device latency";
330 330
331 // Get the stream latency.
332 property_address.mSelector = kAudioDevicePropertyStreams;
333 UInt32 stream_latency_frames = 0;
334 result = AudioObjectGetPropertyDataSize(output_device_id_,
335 &property_address,
336 0,
337 NULL,
338 &size);
339 if (!result) {
340 scoped_ptr_malloc<AudioStreamID>
341 streams(reinterpret_cast<AudioStreamID*>(malloc(size)));
342 AudioStreamID* stream_ids = streams.get();
343 result = AudioObjectGetPropertyData(output_device_id_,
344 &property_address,
345 0,
346 NULL,
347 &size,
348 stream_ids);
349 if (!result) {
350 property_address.mSelector = kAudioStreamPropertyLatency;
351 result = AudioObjectGetPropertyData(stream_ids[0],
352 &property_address,
353 0,
354 NULL,
355 &size,
356 &stream_latency_frames);
357 }
358 }
359 OSSTATUS_DLOG_IF(WARNING, result != noErr, result)
360 << "Could not get audio stream latency";
361
362 return static_cast<double>((audio_unit_latency_sec * 331 return static_cast<double>((audio_unit_latency_sec *
363 format_.mSampleRate) + device_latency_frames + stream_latency_frames); 332 format_.mSampleRate) + device_latency_frames);
364 } 333 }
365 334
366 double AUAudioOutputStream::GetPlayoutLatency( 335 double AUAudioOutputStream::GetPlayoutLatency(
367 const AudioTimeStamp* output_time_stamp) { 336 const AudioTimeStamp* output_time_stamp) {
368 // Get the delay between the moment getting the callback and the scheduled 337 // Get the delay between the moment getting the callback and the scheduled
369 // time stamp that tells when the data is going to be played out. 338 // time stamp that tells when the data is going to be played out.
370 UInt64 output_time_ns = AudioConvertHostTimeToNanos( 339 UInt64 output_time_ns = AudioConvertHostTimeToNanos(
371 output_time_stamp->mHostTime); 340 output_time_stamp->mHostTime);
372 UInt64 now_ns = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime()); 341 UInt64 now_ns = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime());
373 double delay_frames = static_cast<double> 342 double delay_frames = static_cast<double>
374 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate); 343 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate);
375 344
376 return (delay_frames + hardware_latency_frames_); 345 return (delay_frames + hardware_latency_frames_);
377 } 346 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698