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

Unified Diff: media/audio/mac/audio_manager_mac.cc

Issue 132873002: Pass through channel layout on OSX if hardware supports it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup. Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/mac/audio_manager_mac.cc
diff --git a/media/audio/mac/audio_manager_mac.cc b/media/audio/mac/audio_manager_mac.cc
index 75af5167b194c0777e74a0b6acc8faec6e3d198f..ca7e783a49ebec5a0c038a971e611ffa37e288d7 100644
--- a/media/audio/mac/audio_manager_mac.cc
+++ b/media/audio/mac/audio_manager_mac.cc
@@ -644,7 +644,7 @@ AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream(
AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
const std::string& output_device_id,
const AudioParameters& input_params) {
- AudioDeviceID device = GetAudioDeviceIdByUId(false, output_device_id);
+ const AudioDeviceID device = GetAudioDeviceIdByUId(false, output_device_id);
if (device == kAudioObjectUnknown) {
DLOG(ERROR) << "Invalid output device " << output_device_id;
return input_params.IsValid() ? input_params : AudioParameters(
@@ -652,47 +652,42 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
kFallbackSampleRate, 16, ChooseBufferSize(kFallbackSampleRate));
}
- int hardware_channels = 2;
+ const bool valid_input_params = input_params.IsValid();
xhwang 2014/01/10 22:05:05 valid_input_params vs input_params.IsValid() I fo
DaleCurtis 2014/01/10 22:08:39 Since it's a "complex" method which isn't suitable
xhwang 2014/01/10 22:40:43 That's a valid point :) How about name is to is_in
DaleCurtis 2014/01/10 22:49:50 Renamed to "has_valid_input_params"
+ const int hardware_sample_rate = HardwareSampleRateForDevice(device);
+ const int buffer_size = ChooseBufferSize(hardware_sample_rate);
+
+ int hardware_channels;
if (!GetDeviceChannels(device, kAudioDevicePropertyScopeOutput,
&hardware_channels)) {
- // Fallback to stereo.
hardware_channels = 2;
}
- ChannelLayout channel_layout = GuessChannelLayout(hardware_channels);
-
- const int hardware_sample_rate = HardwareSampleRateForDevice(device);
- const int buffer_size = ChooseBufferSize(hardware_sample_rate);
-
- int input_channels = 0;
- if (input_params.IsValid()) {
- input_channels = input_params.input_channels();
+ // Use the input channel count and channel layout if possible. Let OSX take
+ // care of remapping the channels; this lets user specified channel layouts
+ // work correctly.
+ int output_channels = input_params.channels();
+ ChannelLayout channel_layout = input_params.channel_layout();
+ if (!valid_input_params || output_channels > hardware_channels) {
+ output_channels = hardware_channels;
+ channel_layout = GuessChannelLayout(output_channels);
+ if (channel_layout == CHANNEL_LAYOUT_UNSUPPORTED)
+ channel_layout = CHANNEL_LAYOUT_DISCRETE;
+ }
- if (input_channels > 0) {
- // TODO(xians): given the limitations of the AudioOutputStream
- // back-ends used with synchronized I/O, we hard-code to stereo.
- // Specifically, this is a limitation of AudioSynchronizedStream which
- // can be removed as part of the work to consolidate these back-ends.
- channel_layout = CHANNEL_LAYOUT_STEREO;
- }
+ const int input_channels =
+ valid_input_params ? input_params.input_channels() : 0;
+ if (input_channels > 0) {
+ // TODO(xians): given the limitations of the AudioOutputStream
+ // back-ends used with synchronized I/O, we hard-code to stereo.
+ // Specifically, this is a limitation of AudioSynchronizedStream which
+ // can be removed as part of the work to consolidate these back-ends.
+ channel_layout = CHANNEL_LAYOUT_STEREO;
}
- 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,
+ return AudioParameters(
+ AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, output_channels,
+ input_channels, hardware_sample_rate, 16, buffer_size,
AudioParameters::NO_EFFECTS);
-
- return params;
}
void AudioManagerMac::CreateDeviceListener() {
« 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