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

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

Issue 9235084: Add OSSTATUS_LOG API (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
OLDNEW
1 // Copyright (c) 2011 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_input_mac.h" 5 #include "media/audio/mac/audio_low_latency_input_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"
11 #include "base/mac/mac_logging.h"
11 #include "media/audio/audio_util.h" 12 #include "media/audio/audio_util.h"
12 #include "media/audio/mac/audio_manager_mac.h" 13 #include "media/audio/mac/audio_manager_mac.h"
13 14
14 static std::ostream& operator<<(std::ostream& os, 15 static std::ostream& operator<<(std::ostream& os,
15 const AudioStreamBasicDescription& format) { 16 const AudioStreamBasicDescription& format) {
16 os << "sample rate : " << format.mSampleRate << std::endl 17 os << "sample rate : " << format.mSampleRate << std::endl
17 << "format ID : " << format.mFormatID << std::endl 18 << "format ID : " << format.mFormatID << std::endl
18 << "format flags : " << format.mFormatFlags << std::endl 19 << "format flags : " << format.mFormatFlags << std::endl
19 << "bytes per packet : " << format.mBytesPerPacket << std::endl 20 << "bytes per packet : " << format.mBytesPerPacket << std::endl
20 << "frames per packet : " << format.mFramesPerPacket << std::endl 21 << "frames per packet : " << format.mFramesPerPacket << std::endl
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 void AUAudioInputStream::Start(AudioInputCallback* callback) { 217 void AUAudioInputStream::Start(AudioInputCallback* callback) {
217 DCHECK(callback); 218 DCHECK(callback);
218 DLOG_IF(ERROR, !audio_unit_) << "Open() has not been called successfully"; 219 DLOG_IF(ERROR, !audio_unit_) << "Open() has not been called successfully";
219 if (started_ || !audio_unit_) 220 if (started_ || !audio_unit_)
220 return; 221 return;
221 sink_ = callback; 222 sink_ = callback;
222 OSStatus result = AudioOutputUnitStart(audio_unit_); 223 OSStatus result = AudioOutputUnitStart(audio_unit_);
223 if (result == noErr) { 224 if (result == noErr) {
224 started_ = true; 225 started_ = true;
225 } 226 }
226 DLOG_IF(ERROR, result != noErr) << "Failed to start acquiring data"; 227 OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
228 << "Failed to start acquiring data";
227 } 229 }
228 230
229 void AUAudioInputStream::Stop() { 231 void AUAudioInputStream::Stop() {
230 if (!started_) 232 if (!started_)
231 return; 233 return;
232 OSStatus result; 234 OSStatus result = AudioOutputUnitStop(audio_unit_);
233 result = AudioOutputUnitStop(audio_unit_);
234 if (result == noErr) { 235 if (result == noErr) {
235 started_ = false; 236 started_ = false;
236 } 237 }
237 DLOG_IF(ERROR, result != noErr) << "Failed to stop acquiring data"; 238 OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
239 << "Failed to stop acquiring data";
238 } 240 }
239 241
240 void AUAudioInputStream::Close() { 242 void AUAudioInputStream::Close() {
241 // It is valid to call Close() before calling open or Start(). 243 // It is valid to call Close() before calling open or Start().
242 // It is also valid to call Close() after Start() has been called. 244 // It is also valid to call Close() after Start() has been called.
243 if (started_) { 245 if (started_) {
244 Stop(); 246 Stop();
245 } 247 }
246 if (audio_unit_) { 248 if (audio_unit_) {
247 // Deallocate the audio unit’s resources. 249 // Deallocate the audio unit’s resources.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 kAudioHardwarePropertyDefaultInputDevice, 322 kAudioHardwarePropertyDefaultInputDevice,
321 kAudioObjectPropertyScopeGlobal, 323 kAudioObjectPropertyScopeGlobal,
322 kAudioObjectPropertyElementMaster 324 kAudioObjectPropertyElementMaster
323 }; 325 };
324 OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, 326 OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
325 &default_input_device_address, 327 &default_input_device_address,
326 0, 328 0,
327 0, 329 0,
328 &info_size, 330 &info_size,
329 &device_id); 331 &device_id);
330 DCHECK_EQ(result, 0); 332 OSSTATUS_DCHECK(result == noErr, result);
331 if (result) 333 if (result)
332 return 0.0; 334 return 0.0;
333 335
334 Float64 nominal_sample_rate; 336 Float64 nominal_sample_rate;
335 info_size = sizeof(nominal_sample_rate); 337 info_size = sizeof(nominal_sample_rate);
336 338
337 AudioObjectPropertyAddress nominal_sample_rate_address = { 339 AudioObjectPropertyAddress nominal_sample_rate_address = {
338 kAudioDevicePropertyNominalSampleRate, 340 kAudioDevicePropertyNominalSampleRate,
339 kAudioObjectPropertyScopeGlobal, 341 kAudioObjectPropertyScopeGlobal,
340 kAudioObjectPropertyElementMaster 342 kAudioObjectPropertyElementMaster
(...skipping 19 matching lines...) Expand all
360 362
361 // Get audio unit latency. 363 // Get audio unit latency.
362 Float64 audio_unit_latency_sec = 0.0; 364 Float64 audio_unit_latency_sec = 0.0;
363 UInt32 size = sizeof(audio_unit_latency_sec); 365 UInt32 size = sizeof(audio_unit_latency_sec);
364 OSStatus result = AudioUnitGetProperty(audio_unit_, 366 OSStatus result = AudioUnitGetProperty(audio_unit_,
365 kAudioUnitProperty_Latency, 367 kAudioUnitProperty_Latency,
366 kAudioUnitScope_Global, 368 kAudioUnitScope_Global,
367 0, 369 0,
368 &audio_unit_latency_sec, 370 &audio_unit_latency_sec,
369 &size); 371 &size);
370 DLOG_IF(WARNING, result != noErr) << "Could not get audio unit latency."; 372 OSSTATUS_DLOG_IF(WARNING, result != noErr, result)
373 << "Could not get audio unit latency";
371 374
372 // Get input audio device latency. 375 // Get input audio device latency.
373 AudioObjectPropertyAddress property_address = { 376 AudioObjectPropertyAddress property_address = {
374 kAudioDevicePropertyLatency, 377 kAudioDevicePropertyLatency,
375 kAudioDevicePropertyScopeInput, 378 kAudioDevicePropertyScopeInput,
376 kAudioObjectPropertyElementMaster 379 kAudioObjectPropertyElementMaster
377 }; 380 };
378 UInt32 device_latency_frames = 0; 381 UInt32 device_latency_frames = 0;
379 size = sizeof(device_latency_frames); 382 size = sizeof(device_latency_frames);
380 result = AudioObjectGetPropertyData(input_device_id_, 383 result = AudioObjectGetPropertyData(input_device_id_,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 UInt64 now_ns = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime()); 432 UInt64 now_ns = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime());
430 double delay_frames = static_cast<double> 433 double delay_frames = static_cast<double>
431 (1e-9 * (now_ns - capture_time_ns) * format_.mSampleRate); 434 (1e-9 * (now_ns - capture_time_ns) * format_.mSampleRate);
432 435
433 // Total latency is composed by the dynamic latency and the fixed 436 // Total latency is composed by the dynamic latency and the fixed
434 // hardware latency. 437 // hardware latency.
435 return (delay_frames + hardware_latency_frames_); 438 return (delay_frames + hardware_latency_frames_);
436 } 439 }
437 440
438 void AUAudioInputStream::HandleError(OSStatus err) { 441 void AUAudioInputStream::HandleError(OSStatus err) {
439 NOTREACHED() << "error code: " << err; 442 NOTREACHED() << "error " << GetMacOSStatusErrorString(err)
443 << " (" << err << ")";
440 if (sink_) 444 if (sink_)
441 sink_->OnError(this, static_cast<int>(err)); 445 sink_->OnError(this, static_cast<int>(err));
442 } 446 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698