diff options
author | henrika@chromium.org <henrika@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-19 14:30:23 +0000 |
---|---|---|
committer | henrika@chromium.org <henrika@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-19 14:30:23 +0000 |
commit | 1ac780fbb82a40fb92fbd785a68bd64fe568e88b (patch) | |
tree | 38bd7952acd260215bd44a5d981192a6efb81049 /media | |
parent | 50903e7c854554957e98e70344d48466da15405a (diff) | |
download | chromium_src-1ac780fbb82a40fb92fbd785a68bd64fe568e88b.zip chromium_src-1ac780fbb82a40fb92fbd785a68bd64fe568e88b.tar.gz chromium_src-1ac780fbb82a40fb92fbd785a68bd64fe568e88b.tar.bz2 |
Adds support for 16kHz input sample rate and mono channel config. in WebRTC.
BUG=WebRTC demo doesn't work with Logitech 9000 as microphone
TEST=content_unittest --gtest_filter=WebRTCAudioDeviceTest*
Review URL: https://chromiumcodereview.appspot.com/9221010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118291 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/audio/audio_util.cc | 16 | ||||
-rw-r--r-- | media/audio/audio_util.h | 3 | ||||
-rw-r--r-- | media/audio/win/audio_low_latency_input_win.cc | 48 | ||||
-rw-r--r-- | media/audio/win/audio_low_latency_input_win.h | 10 |
4 files changed, 59 insertions, 18 deletions
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc index 8989eb9..b4b87518 100644 --- a/media/audio/audio_util.cc +++ b/media/audio/audio_util.cc @@ -337,6 +337,22 @@ size_t GetAudioHardwareBufferSize() { #endif } +uint32 GetAudioInputHardwareChannelCount() { + enum channel_layout { MONO = 1, STEREO = 2 }; +#if defined(OS_MACOSX) + return MONO; +#elif defined(OS_WIN) + if (!IsWASAPISupported()) { + // Fall back to Windows Wave implementation on Windows XP or lower and + // use stereo by default. + return STEREO; + } + return WASAPIAudioInputStream::HardwareChannelCount(eConsole); +#else + return STEREO; +#endif +} + // When transferring data in the shared memory, first word is size of data // in bytes. Actual data starts immediately after it. diff --git a/media/audio/audio_util.h b/media/audio/audio_util.h index 278779a..d8de479 100644 --- a/media/audio/audio_util.h +++ b/media/audio/audio_util.h @@ -90,6 +90,9 @@ MEDIA_EXPORT double GetAudioInputHardwareSampleRate(); // at without glitches. The buffer size is in sample-frames. MEDIA_EXPORT size_t GetAudioHardwareBufferSize(); +// Returns the default number of channels for the audio input hardware. +MEDIA_EXPORT uint32 GetAudioInputHardwareChannelCount(); + // Functions that handle data buffer passed between processes in the shared // memory. Called on both IPC sides. diff --git a/media/audio/win/audio_low_latency_input_win.cc b/media/audio/win/audio_low_latency_input_win.cc index c6bb0ed..95dd425 100644 --- a/media/audio/win/audio_low_latency_input_win.cc +++ b/media/audio/win/audio_low_latency_input_win.cc @@ -184,6 +184,31 @@ void WASAPIAudioInputStream::Close() { // static double WASAPIAudioInputStream::HardwareSampleRate(ERole device_role) { + base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format; + HRESULT hr = GetMixFormat(device_role, &audio_engine_mix_format); + if (FAILED(hr)) { + NOTREACHED() << "error code: " << hr; + return 0.0; + } + + return static_cast<double>(audio_engine_mix_format->nSamplesPerSec); +} + +// static +uint32 WASAPIAudioInputStream::HardwareChannelCount(ERole device_role) { + base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format; + HRESULT hr = GetMixFormat(device_role, &audio_engine_mix_format); + if (FAILED(hr)) { + NOTREACHED() << "error code: " << hr; + return 0; + } + + return static_cast<uint32>(audio_engine_mix_format->nChannels); +} + +// static +HRESULT WASAPIAudioInputStream::GetMixFormat(ERole device_role, + WAVEFORMATEX** device_format) { // It is assumed that this static method is called from a COM thread, i.e., // CoInitializeEx() is not called here to avoid STA/MTA conflicts. ScopedComPtr<IMMDeviceEnumerator> enumerator; @@ -192,10 +217,8 @@ double WASAPIAudioInputStream::HardwareSampleRate(ERole device_role) { CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), enumerator.ReceiveVoid()); - if (FAILED(hr)) { - NOTREACHED() << "error code: " << hr; - return 0.0; - } + if (FAILED(hr)) + return hr; ScopedComPtr<IMMDevice> endpoint_device; hr = enumerator->GetDefaultAudioEndpoint(eCapture, @@ -206,7 +229,7 @@ double WASAPIAudioInputStream::HardwareSampleRate(ERole device_role) { // (e.g. some audio cards that have inputs will still report them as // "not found" when no mic is plugged into the input jack). LOG(WARNING) << "No audio end point: " << std::hex << hr; - return 0.0; + return hr; } ScopedComPtr<IAudioClient> audio_client; @@ -214,19 +237,10 @@ double WASAPIAudioInputStream::HardwareSampleRate(ERole device_role) { CLSCTX_INPROC_SERVER, NULL, audio_client.ReceiveVoid()); - if (FAILED(hr)) { - NOTREACHED() << "error code: " << hr; - return 0.0; - } + if (SUCCEEDED(hr)) + hr = audio_client->GetMixFormat(device_format); - base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format; - hr = audio_client->GetMixFormat(&audio_engine_mix_format); - if (FAILED(hr)) { - NOTREACHED() << "error code: " << hr; - return 0.0; - } - - return static_cast<double>(audio_engine_mix_format->nSamplesPerSec); + return hr; } void WASAPIAudioInputStream::Run() { diff --git a/media/audio/win/audio_low_latency_input_win.h b/media/audio/win/audio_low_latency_input_win.h index ebaab93..e236e44 100644 --- a/media/audio/win/audio_low_latency_input_win.h +++ b/media/audio/win/audio_low_latency_input_win.h @@ -89,10 +89,14 @@ class MEDIA_EXPORT WASAPIAudioInputStream virtual void Stop() OVERRIDE; virtual void Close() OVERRIDE; - // Retrieves the stream format that the audio engine uses for its internal + // Retrieves the sample rate used by the audio engine for its internal // processing/mixing of shared-mode streams. static double HardwareSampleRate(ERole device_role); + // Retrieves the number of audio channels used by the audio engine for its + // internal processing/mixing of shared-mode streams. + static uint32 HardwareChannelCount(ERole device_role); + bool started() const { return started_; } private: @@ -109,6 +113,10 @@ class MEDIA_EXPORT WASAPIAudioInputStream bool DesiredFormatIsSupported(); HRESULT InitializeAudioEngine(); + // Retrieves the stream format that the audio engine uses for its internal + // processing/mixing of shared-mode streams. + static HRESULT GetMixFormat(ERole device_role, WAVEFORMATEX** device_format); + // Initializes the COM library for use by the calling thread and set the // thread's concurrency model to multi-threaded. base::win::ScopedCOMInitializer com_init_; |