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

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

Issue 13403002: Add OSX aggregate audio device support for best performance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 8 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) 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_manager_mac.h" 5 #include "media/audio/mac/audio_manager_mac.h"
6 6
7 #include <CoreAudio/AudioHardware.h> 7 #include <CoreAudio/AudioHardware.h>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 buffer_size); 419 buffer_size);
420 } 420 }
421 421
422 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream( 422 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream(
423 const AudioParameters& params) { 423 const AudioParameters& params) {
424 return MakeLowLatencyOutputStream(params); 424 return MakeLowLatencyOutputStream(params);
425 } 425 }
426 426
427 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( 427 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream(
428 const AudioParameters& params) { 428 const AudioParameters& params) {
429 // Handle basic output with no input channels.
430 if (params.input_channels() == 0) {
431 AudioDeviceID device = kAudioObjectUnknown;
432 GetDefaultOutputDevice(&device);
433 return new AUHALStream(this, params, device);
434 }
435
429 // TODO(crogers): support more than stereo input. 436 // TODO(crogers): support more than stereo input.
430 if (params.input_channels() == 2) { 437 if (params.input_channels() != 2) {
431 if (HasUnifiedDefaultIO()) 438 // WebAudio is currently hard-coded to 2 channels so we should not
432 return new AudioHardwareUnifiedStream(this, params); 439 // see this case.
433 440 NOTREACHED() << "Only stereo input is currently supported!";
434 // TODO(crogers): use aggregate devices along with AUHALStream 441 return NULL;
435 // to get better performance for built-in hardware.
436
437 // kAudioDeviceUnknown translates to "use default" here.
438 return new AudioSynchronizedStream(this,
439 params,
440 kAudioDeviceUnknown,
441 kAudioDeviceUnknown);
442 } 442 }
443 443
444 AudioDeviceID device = kAudioObjectUnknown; 444 AudioDeviceID device = kAudioObjectUnknown;
445 GetDefaultOutputDevice(&device); 445 if (HasUnifiedDefaultIO()) {
446 return new AUHALStream(this, params, device); 446 // For I/O, the simplest case is when the default input and output
447 // devices are the same.
448 GetDefaultOutputDevice(&device);
449 LOG(INFO) << "UNIFIED: default input and output devices are identical";
no longer working on chromium 2013/04/17 09:16:22 just a thought, do you want to use uma to record t
Chris Rogers 2013/04/17 20:42:31 Not a bad idea - for now added TODO
450 } else {
451 // Some audio hardware is presented as separate input and output devices
452 // even though they are really the same physical hardware and
453 // share the same "clock domain" at the lowest levels of the driver.
454 // A common of example of this is the "built-in" audio hardware:
455 // "Built-in Line Input"
456 // "Built-in Output"
457 // We would like to use an "aggregate" device for these situations, since
458 // CoreAudio will make the most efficient use of the shared "clock domain"
459 // so we get the lowest latency and use fewer threads.
460 device = aggregate_device_manager_.GetDefaultAggregateDevice();
461 if (device != kAudioObjectUnknown)
462 LOG(INFO) << "Using AGGREGATE audio device";
463 }
464
465 if (device != kAudioObjectUnknown)
466 return new AUHALStream(this, params, device);
467
468 // Fallback to AudioSynchronizedStream which will handle completely
469 // different and arbitrary combinations of input and output devices
470 // even running at different sample-rates.
471 // kAudioDeviceUnknown translates to "use default" here.
472 return new AudioSynchronizedStream(this,
473 params,
474 kAudioDeviceUnknown,
475 kAudioDeviceUnknown);
447 } 476 }
448 477
449 AudioInputStream* AudioManagerMac::MakeLinearInputStream( 478 AudioInputStream* AudioManagerMac::MakeLinearInputStream(
450 const AudioParameters& params, const std::string& device_id) { 479 const AudioParameters& params, const std::string& device_id) {
451 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); 480 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format());
452 return new PCMQueueInAudioInputStream(this, params); 481 return new PCMQueueInAudioInputStream(this, params);
453 } 482 }
454 483
455 AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream( 484 AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream(
456 const AudioParameters& params, const std::string& device_id) { 485 const AudioParameters& params, const std::string& device_id) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 current_sample_rate_ = new_sample_rate; 566 current_sample_rate_ = new_sample_rate;
538 current_output_device_ = new_output_device; 567 current_output_device_ = new_output_device;
539 NotifyAllOutputDeviceChangeListeners(); 568 NotifyAllOutputDeviceChangeListeners();
540 } 569 }
541 570
542 AudioManager* CreateAudioManager() { 571 AudioManager* CreateAudioManager() {
543 return new AudioManagerMac(); 572 return new AudioManagerMac();
544 } 573 }
545 574
546 } // namespace media 575 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698