Chromium Code Reviews| Index: media/audio/win/audio_manager_win.cc |
| diff --git a/media/audio/win/audio_manager_win.cc b/media/audio/win/audio_manager_win.cc |
| index bd809b8c6cd2195cbc12e7fecaed8355444a41cb..fe485f69ebe6719ef1723d715c6cf8ff08ad3af3 100644 |
| --- a/media/audio/win/audio_manager_win.cc |
| +++ b/media/audio/win/audio_manager_win.cc |
| @@ -20,7 +20,7 @@ |
| #include "base/process_util.h" |
| #include "base/string_number_conversions.h" |
| #include "base/string_util.h" |
| -#include "media/audio/audio_util.h" |
| +#include "media/audio/audio_parameters.h" |
| #include "media/audio/win/audio_device_listener_win.h" |
| #include "media/audio/win/audio_low_latency_input_win.h" |
| #include "media/audio/win/audio_low_latency_output_win.h" |
| @@ -31,6 +31,7 @@ |
| #include "media/audio/win/wavein_input_win.h" |
| #include "media/audio/win/waveout_output_win.h" |
| #include "media/base/bind_to_loop.h" |
| +#include "media/base/channel_layout.h" |
| #include "media/base/limits.h" |
| #include "media/base/media_switches.h" |
| @@ -47,6 +48,9 @@ DEFINE_GUID(AM_KSCATEGORY_AUDIO, 0x6994ad04, 0x93ef, 0x11d0, |
| namespace media { |
| +using WASAPIAudioInputStream::HardwareChannelCount; |
|
DaleCurtis
2013/02/27 02:46:11
I think this makes things a little confusing since
no longer working on chromium
2013/03/01 16:44:33
true, done now. Thanks for pointing out.
|
| +using WASAPIAudioInputStream::HardwareSampleRate; |
| + |
| // Maximum number of output streams that can be open simultaneously. |
| static const int kMaxOutputStreams = 50; |
| @@ -61,6 +65,10 @@ static const int kWinMaxChannels = 8; |
| // play. |
| static const int kNumInputBuffers = 3; |
| +// Buffer size to use for input and output stream when a proper size can't be |
| +// determined from the system |
| +static const int kFallbackBufferSize = 2048; |
| + |
| static int GetVersionPartAsInt(DWORDLONG num) { |
| return static_cast<int>(num & 0xffff); |
| } |
| @@ -255,6 +263,62 @@ void AudioManagerWin::GetAudioInputDeviceNames( |
| } |
| } |
| +AudioParameters AudioManagerWin::GetDefaultOutputStreamParameters() { |
| + const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| + ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
| + int sample_rate = 0; |
| + int buffer_size = 0; |
| + if (!CoreAudioUtil::IsSupported()) { |
| + // Fall back to Windows Wave implementation on Windows XP or lower |
| + // and use 48kHz as default input sample rate, kFallbackBufferSize as |
| + // default buffer size. |
| + sample_rate = 48000; |
| + buffer_size = kFallbackBufferSize; |
| + } else if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { |
| + // TODO(crogers): tune these values for best possible WebAudio performance. |
| + // WebRTC works well at 48kHz and a buffer size of 480 samples will be used |
| + // for this case. Note that exclusive mode is experimental. |
| + // This sample rate will be combined with a buffer size of 256 samples, |
| + // which corresponds to an output delay of ~5.33ms. |
| + sample_rate = 48000; |
| + buffer_size = 256; |
| + } else { |
| + // Hardware sample-rate on Windows can be configured, so we must query. |
| + // TODO(henrika): improve possibility to specify an audio endpoint. |
| + // Use the default device (same as for Wave) for now to be compatible. |
| + sample_rate = HardwareSampleRate(); |
| + |
| + AudioParameters params; |
| + HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(eRender, eConsole, |
| + ¶ms); |
| + buffer_size = FAILED(hr) ? kFallbackBufferSize : params.frames_per_buffer(); |
| + channel_layout = WASAPIAudioOutputStream::HardwareChannelLayout(); |
| + } |
| + |
| + return AudioParameters( |
| + AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| + sample_rate, 16, buffer_size); |
| +} |
| + |
| +AudioParameters AudioManagerWin::GetDefaultInputStreamParameters( |
| + const std::string& device_id) { |
| + int sample_rate = 0; |
| + ChannelLayout channel_layout = CHANNEL_LAYOUT_NONE; |
| + if (!CoreAudioUtil::IsSupported()) { |
| + sample_rate = 48000; |
| + channel_layout = CHANNEL_LAYOUT_STEREO; |
| + } else { |
| + sample_rate = HardwareSampleRate(device_id); |
| + channel_layout = HardwareChannelCount(device_id) == 1 ? |
| + CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO; |
| + } |
| + |
| + // TODO(Henrika): improve the default buffer size value for input stream. |
| + return AudioParameters( |
| + AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| + sample_rate, 16, kFallbackBufferSize); |
| +} |
| + |
| // Factory for the implementations of AudioOutputStream for AUDIO_PCM_LINEAR |
| // mode. |
| // - PCMWaveOutAudioOutputStream: Based on the waveOut API. |
| @@ -362,16 +426,19 @@ AudioParameters AudioManagerWin::GetPreferredLowLatencyOutputStreamParameters( |
| int bits_per_sample = input_params.bits_per_sample(); |
| ChannelLayout channel_layout = input_params.channel_layout(); |
| int input_channels = input_params.input_channels(); |
| + int buffer_size = input_params.frames_per_buffer(); |
| if (CoreAudioUtil::IsSupported()) { |
| - sample_rate = GetAudioHardwareSampleRate(); |
| - bits_per_sample = 16; |
| - channel_layout = WASAPIAudioOutputStream::HardwareChannelLayout(); |
| + AudioParameters default_params = GetDefaultOutputStreamParameters(); |
| + sample_rate = default_params.sample_rate(); |
| + bits_per_sample = default_params.bits_per_sample(); |
| + channel_layout = default_params.channel_layout(); |
| + buffer_size = default_params.frames_per_buffer(); |
| } |
| // TODO(dalecurtis): This should include hardware bits per channel eventually. |
| return AudioParameters( |
| AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, |
| - sample_rate, bits_per_sample, GetAudioHardwareBufferSize()); |
| + sample_rate, bits_per_sample, buffer_size); |
| } |
| } // namespace media |