summaryrefslogtreecommitdiff
path: root/chromium/media/audio/mac/audio_manager_mac.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/media/audio/mac/audio_manager_mac.cc')
-rw-r--r--chromium/media/audio/mac/audio_manager_mac.cc83
1 files changed, 54 insertions, 29 deletions
diff --git a/chromium/media/audio/mac/audio_manager_mac.cc b/chromium/media/audio/mac/audio_manager_mac.cc
index 8e4b969854e..be7dddd5bb6 100644
--- a/chromium/media/audio/mac/audio_manager_mac.cc
+++ b/chromium/media/audio/mac/audio_manager_mac.cc
@@ -13,7 +13,6 @@
#include "base/mac/scoped_cftyperef.h"
#include "base/strings/sys_string_conversions.h"
#include "media/audio/audio_parameters.h"
-#include "media/audio/audio_util.h"
#include "media/audio/mac/audio_auhal_mac.h"
#include "media/audio/mac/audio_input_mac.h"
#include "media/audio/mac/audio_low_latency_input_mac.h"
@@ -36,23 +35,6 @@ static const int kDefaultLowLatencyBufferSize = 128;
// Default sample-rate on most Apple hardware.
static const int kFallbackSampleRate = 44100;
-static int ChooseBufferSize(int output_sample_rate) {
- int buffer_size = kDefaultLowLatencyBufferSize;
- const int user_buffer_size = GetUserBufferSize();
- if (user_buffer_size) {
- buffer_size = user_buffer_size;
- } else if (output_sample_rate > 48000) {
- // The default buffer size is too small for higher sample rates and may lead
- // to glitching. Adjust upwards by multiples of the default size.
- if (output_sample_rate <= 96000)
- buffer_size = 2 * kDefaultLowLatencyBufferSize;
- else if (output_sample_rate <= 192000)
- buffer_size = 4 * kDefaultLowLatencyBufferSize;
- }
-
- return buffer_size;
-}
-
static bool HasAudioHardware(AudioObjectPropertySelector selector) {
AudioDeviceID output_device_id = kAudioObjectUnknown;
const AudioObjectPropertyAddress property_address = {
@@ -238,8 +220,9 @@ static AudioDeviceID GetAudioDeviceIdByUId(bool is_input,
return audio_device_id;
}
-AudioManagerMac::AudioManagerMac()
- : current_sample_rate_(0) {
+AudioManagerMac::AudioManagerMac(AudioLogFactory* audio_log_factory)
+ : AudioManagerBase(audio_log_factory),
+ current_sample_rate_(0) {
current_output_device_ = kAudioDeviceUnknown;
SetMaxOutputStreamsAllowed(kMaxOutputStreams);
@@ -474,6 +457,7 @@ std::string AudioManagerMac::GetAssociatedOutputDeviceID(
if (result)
return std::string();
+ std::vector<std::string> associated_devices;
for (int i = 0; i < device_count; ++i) {
// Get the number of output channels of the device.
pa.mSelector = kAudioDevicePropertyStreams;
@@ -501,10 +485,30 @@ std::string AudioManagerMac::GetAssociatedOutputDeviceID(
std::string ret(base::SysCFStringRefToUTF8(uid));
CFRelease(uid);
- return ret;
+ associated_devices.push_back(ret);
}
// No matching device found.
+ if (associated_devices.empty())
+ return std::string();
+
+ // Return the device if there is only one associated device.
+ if (associated_devices.size() == 1)
+ return associated_devices[0];
+
+ // When there are multiple associated devices, we currently do not have a way
+ // to detect if a device (e.g. a digital output device) is actually connected
+ // to an endpoint, so we cannot randomly pick a device.
+ // We pick the device iff the associated device is the default output device.
+ const std::string default_device = GetDefaultOutputDeviceID();
+ for (std::vector<std::string>::const_iterator iter =
+ associated_devices.begin();
+ iter != associated_devices.end(); ++iter) {
+ if (default_device == *iter)
+ return *iter;
+ }
+
+ // Failed to figure out which is the matching device, return an emtpy string.
return std::string();
}
@@ -542,7 +546,7 @@ AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream(
// For I/O, the simplest case is when the default input and output
// devices are the same.
GetDefaultOutputDevice(&device);
- LOG(INFO) << "UNIFIED: default input and output devices are identical";
+ VLOG(0) << "UNIFIED: default input and output devices are identical";
} else {
// Some audio hardware is presented as separate input and output devices
// even though they are really the same physical hardware and
@@ -555,7 +559,7 @@ AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream(
// so we get the lowest latency and use fewer threads.
device = aggregate_device_manager_.GetDefaultAggregateDevice();
if (device != kAudioObjectUnknown)
- LOG(INFO) << "Using AGGREGATE audio device";
+ VLOG(0) << "Using AGGREGATE audio device";
}
if (device != kAudioObjectUnknown &&
@@ -670,16 +674,20 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
}
}
+ if (channel_layout == CHANNEL_LAYOUT_UNSUPPORTED)
+ channel_layout = CHANNEL_LAYOUT_DISCRETE;
+ else
+ hardware_channels = ChannelLayoutToChannelCount(channel_layout);
+
AudioParameters params(
AudioParameters::AUDIO_PCM_LOW_LATENCY,
channel_layout,
+ hardware_channels,
input_channels,
hardware_sample_rate,
16,
- buffer_size);
-
- if (channel_layout == CHANNEL_LAYOUT_UNSUPPORTED)
- params.SetDiscreteChannels(hardware_channels);
+ buffer_size,
+ AudioParameters::NO_EFFECTS);
return params;
}
@@ -722,8 +730,25 @@ void AudioManagerMac::HandleDeviceChanges() {
NotifyAllOutputDeviceChangeListeners();
}
-AudioManager* CreateAudioManager() {
- return new AudioManagerMac();
+int AudioManagerMac::ChooseBufferSize(int output_sample_rate) {
+ int buffer_size = kDefaultLowLatencyBufferSize;
+ const int user_buffer_size = GetUserBufferSize();
+ if (user_buffer_size) {
+ buffer_size = user_buffer_size;
+ } else if (output_sample_rate > 48000) {
+ // The default buffer size is too small for higher sample rates and may lead
+ // to glitching. Adjust upwards by multiples of the default size.
+ if (output_sample_rate <= 96000)
+ buffer_size = 2 * kDefaultLowLatencyBufferSize;
+ else if (output_sample_rate <= 192000)
+ buffer_size = 4 * kDefaultLowLatencyBufferSize;
+ }
+
+ return buffer_size;
+}
+
+AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) {
+ return new AudioManagerMac(audio_log_factory);
}
} // namespace media