diff options
-rw-r--r-- | content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc | 11 | ||||
-rw-r--r-- | content/browser/renderer_host/media/media_stream_manager.cc | 41 | ||||
-rw-r--r-- | content/browser/renderer_host/media/media_stream_manager.h | 17 | ||||
-rw-r--r-- | content/browser/renderer_host/media/video_capture_host_unittest.cc | 13 | ||||
-rw-r--r-- | content/test/DEPS | 1 | ||||
-rw-r--r-- | content/test/ppapi/ppapi_test.cc | 18 | ||||
-rw-r--r-- | content/test/ppapi/ppapi_test.h | 3 | ||||
-rw-r--r-- | content/test/webrtc_content_browsertest_base.cc | 14 | ||||
-rw-r--r-- | content/test/webrtc_content_browsertest_base.h | 1 | ||||
-rw-r--r-- | media/audio/audio_manager.h | 5 | ||||
-rw-r--r-- | media/audio/audio_manager_base.cc | 4 | ||||
-rw-r--r-- | media/audio/audio_manager_base.h | 2 | ||||
-rw-r--r-- | media/audio/cras/audio_manager_cras.cc | 15 | ||||
-rw-r--r-- | media/audio/cras/audio_manager_cras.h | 3 | ||||
-rw-r--r-- | media/audio/mock_audio_manager.cc | 2 | ||||
-rw-r--r-- | media/audio/mock_audio_manager.h | 2 |
16 files changed, 150 insertions, 2 deletions
diff --git a/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc b/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc index ba78d44..9000971 100644 --- a/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc +++ b/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc @@ -33,6 +33,10 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +#if defined(OS_CHROMEOS) +#include "chromeos/audio/cras_audio_handler.h" +#endif + using ::testing::_; using ::testing::DeleteArg; using ::testing::DoAll; @@ -244,9 +248,16 @@ class MediaStreamDispatcherHostTest : public testing::Test { content_client_.reset(new TestContentClient()); SetContentClient(content_client_.get()); old_browser_client_ = SetBrowserClientForTesting(host_.get()); + +#if defined(OS_CHROMEOS) + chromeos::CrasAudioHandler::InitializeForTesting(); +#endif } virtual ~MediaStreamDispatcherHostTest() { +#if defined(OS_CHROMEOS) + chromeos::CrasAudioHandler::Shutdown(); +#endif } virtual void SetUp() OVERRIDE { diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc index 4080cbe..c07c4f2 100644 --- a/content/browser/renderer_host/media/media_stream_manager.cc +++ b/content/browser/renderer_host/media/media_stream_manager.cc @@ -45,6 +45,10 @@ #include "base/win/scoped_com_initializer.h" #endif +#if defined(OS_CHROMEOS) +#include "chromeos/audio/cras_audio_handler.h" +#endif + namespace content { // Forward declaration of DeviceMonitorMac and its only useable method. @@ -358,12 +362,18 @@ MediaStreamManager::EnumerationCache::~EnumerationCache() { MediaStreamManager::MediaStreamManager() : audio_manager_(NULL), monitoring_started_(false), +#if defined(OS_CHROMEOS) + has_checked_keyboard_mic_(false), +#endif io_loop_(NULL), use_fake_ui_(false) {} MediaStreamManager::MediaStreamManager(media::AudioManager* audio_manager) : audio_manager_(audio_manager), monitoring_started_(false), +#if defined(OS_CHROMEOS) + has_checked_keyboard_mic_(false), +#endif io_loop_(NULL), use_fake_ui_(false) { DCHECK(audio_manager_); @@ -1072,6 +1082,16 @@ void MediaStreamManager::StartEnumeration(DeviceRequest* request) { // Start monitoring the devices when doing the first enumeration. StartMonitoring(); +#if defined(OS_CHROMEOS) + if (!has_checked_keyboard_mic_) { + has_checked_keyboard_mic_ = true; + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&MediaStreamManager::CheckKeyboardMicOnUIThread, + base::Unretained(this))); + } +#endif + // Start enumeration for devices of all requested device types. const MediaStreamType streams[] = { request->audio_type(), request->video_type() }; @@ -2077,4 +2097,25 @@ void MediaStreamManager::OnMediaStreamUIWindowId(MediaStreamType video_type, } } +#if defined(OS_CHROMEOS) +void MediaStreamManager::CheckKeyboardMicOnUIThread() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + + // We will post this on the device thread before the media media access + // request is posted on the UI thread, so setting the keyboard mic info will + // be done before any stream is created. + if (chromeos::CrasAudioHandler::Get()->HasKeyboardMic()) { + device_task_runner_->PostTask( + FROM_HERE, + base::Bind(&MediaStreamManager::SetKeyboardMicOnDeviceThread, + base::Unretained(this))); + } +} + +void MediaStreamManager::SetKeyboardMicOnDeviceThread() { + DCHECK(device_task_runner_->BelongsToCurrentThread()); + audio_manager_->SetHasKeyboardMic(); +} +#endif + } // namespace content diff --git a/content/browser/renderer_host/media/media_stream_manager.h b/content/browser/renderer_host/media/media_stream_manager.h index 1eba375..a8c8592 100644 --- a/content/browser/renderer_host/media/media_stream_manager.h +++ b/content/browser/renderer_host/media/media_stream_manager.h @@ -363,6 +363,15 @@ class CONTENT_EXPORT MediaStreamManager StreamDeviceInfoArray devices, gfx::NativeViewId window_id); +#if defined(OS_CHROMEOS) + // Checks if the system has a keyboard mic, and if so, inform the audio + // manager via SetKeyboardMicOnDeviceThread(). + void CheckKeyboardMicOnUIThread(); + + // Tells the audio mananger that the system supports a keyboard mic. + void SetKeyboardMicOnDeviceThread(); +#endif + // Task runner shared by VideoCaptureManager and AudioInputDeviceManager and // used for enumerating audio output devices. // Note: Enumeration tasks may take seconds to complete so must never be run @@ -376,6 +385,14 @@ class CONTENT_EXPORT MediaStreamManager // Indicator of device monitoring state. bool monitoring_started_; +#if defined(OS_CHROMEOS) + // Flag that's set when we have checked if the system has a keyboard mic. We + // only need to check it once, and not when constructing since that will + // affect startup time. + // Must be accessed on the IO thread; + bool has_checked_keyboard_mic_; +#endif + // Stores most recently enumerated device lists. The cache is cleared when // monitoring is stopped or there is no request for that type of device. EnumerationCache audio_enumeration_cache_; diff --git a/content/browser/renderer_host/media/video_capture_host_unittest.cc b/content/browser/renderer_host/media/video_capture_host_unittest.cc index 3b94007..933e7f0 100644 --- a/content/browser/renderer_host/media/video_capture_host_unittest.cc +++ b/content/browser/renderer_host/media/video_capture_host_unittest.cc @@ -34,6 +34,10 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +#if defined(OS_CHROMEOS) +#include "chromeos/audio/cras_audio_handler.h" +#endif + using ::testing::_; using ::testing::AtLeast; using ::testing::AnyNumber; @@ -285,6 +289,11 @@ class VideoCaptureHostTest : public testing::Test { virtual void SetUp() OVERRIDE { SetBrowserClientForTesting(&browser_client_); + +#if defined(OS_CHROMEOS) + chromeos::CrasAudioHandler::InitializeForTesting(); +#endif + // Create our own MediaStreamManager. audio_manager_.reset(media::AudioManager::CreateForTesting()); #ifndef TEST_REAL_CAPTURE_DEVICE @@ -315,6 +324,10 @@ class VideoCaptureHostTest : public testing::Test { // Release the reference to the mock object. The object will be destructed // on the current message loop. host_ = NULL; + +#if defined(OS_CHROMEOS) + chromeos::CrasAudioHandler::Shutdown(); +#endif } void OpenSession() { diff --git a/content/test/DEPS b/content/test/DEPS index dc9be12..4a3e002 100644 --- a/content/test/DEPS +++ b/content/test/DEPS @@ -1,5 +1,6 @@ include_rules = [ "+cc/blink", + "+chromeos/audio", # For WebRTC tests. # Testing utilities can access anything in content/ "+content", "+media/audio", # For AudioParameters in WebRTC tests. diff --git a/content/test/ppapi/ppapi_test.cc b/content/test/ppapi/ppapi_test.cc index 0807b61..96a4ec2 100644 --- a/content/test/ppapi/ppapi_test.cc +++ b/content/test/ppapi/ppapi_test.cc @@ -17,6 +17,10 @@ #include "ppapi/shared_impl/ppapi_switches.h" #include "ppapi/shared_impl/test_harness_utils.h" +#if defined(OS_CHROMEOS) +#include "chromeos/audio/cras_audio_handler.h" +#endif + namespace content { PPAPITestMessageHandler::PPAPITestMessageHandler() { @@ -129,4 +133,18 @@ OutOfProcessPPAPITest::OutOfProcessPPAPITest() { in_process_ = false; } +void OutOfProcessPPAPITest::SetUp() { +#if defined(OS_CHROMEOS) + chromeos::CrasAudioHandler::InitializeForTesting(); +#endif + ContentBrowserTest::SetUp(); +} + +void OutOfProcessPPAPITest::TearDown() { + ContentBrowserTest::TearDown(); +#if defined(OS_CHROMEOS) + chromeos::CrasAudioHandler::Shutdown(); +#endif +} + } // namespace content diff --git a/content/test/ppapi/ppapi_test.h b/content/test/ppapi/ppapi_test.h index d02ca3e..345ad21 100644 --- a/content/test/ppapi/ppapi_test.h +++ b/content/test/ppapi/ppapi_test.h @@ -84,6 +84,9 @@ class PPAPITest : public PPAPITestBase { class OutOfProcessPPAPITest : public PPAPITest { public: OutOfProcessPPAPITest(); + + virtual void SetUp() OVERRIDE; + virtual void TearDown() OVERRIDE; }; } // namespace diff --git a/content/test/webrtc_content_browsertest_base.cc b/content/test/webrtc_content_browsertest_base.cc index b2885db..db83501 100644 --- a/content/test/webrtc_content_browsertest_base.cc +++ b/content/test/webrtc_content_browsertest_base.cc @@ -13,6 +13,10 @@ #include "content/shell/browser/shell.h" #include "media/base/media_switches.h" +#if defined(OS_CHROMEOS) +#include "chromeos/audio/cras_audio_handler.h" +#endif + namespace content { void WebRtcContentBrowserTest::SetUpCommandLine(CommandLine* command_line) { @@ -31,9 +35,19 @@ void WebRtcContentBrowserTest::SetUpCommandLine(CommandLine* command_line) { void WebRtcContentBrowserTest::SetUp() { EnablePixelOutput(); +#if defined(OS_CHROMEOS) + chromeos::CrasAudioHandler::InitializeForTesting(); +#endif ContentBrowserTest::SetUp(); } +void WebRtcContentBrowserTest::TearDown() { + ContentBrowserTest::TearDown(); +#if defined(OS_CHROMEOS) + chromeos::CrasAudioHandler::Shutdown(); +#endif +} + // Executes |javascript|. The script is required to use // window.domAutomationController.send to send a string value back to here. std::string WebRtcContentBrowserTest::ExecuteJavascriptAndReturnResult( diff --git a/content/test/webrtc_content_browsertest_base.h b/content/test/webrtc_content_browsertest_base.h index 05f2ec2..94b7b6a 100644 --- a/content/test/webrtc_content_browsertest_base.h +++ b/content/test/webrtc_content_browsertest_base.h @@ -15,6 +15,7 @@ class WebRtcContentBrowserTest: public ContentBrowserTest { public: virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE; virtual void SetUp() OVERRIDE; + virtual void TearDown() OVERRIDE; protected: // Executes |javascript|. The script is required to use diff --git a/media/audio/audio_manager.h b/media/audio/audio_manager.h index 915308e..7705cdb 100644 --- a/media/audio/audio_manager.h +++ b/media/audio/audio_manager.h @@ -177,6 +177,11 @@ class MEDIA_EXPORT AudioManager { virtual scoped_ptr<AudioLog> CreateAudioLog( AudioLogFactory::AudioComponent component) = 0; + // Informs the audio manager that the system has support for a keyboard mic. + // This information will be passed on in the return value of + // GetInputStreamParameters as an effect. Only supported on ChromeOS. + virtual void SetHasKeyboardMic() = 0; + protected: AudioManager(); diff --git a/media/audio/audio_manager_base.cc b/media/audio/audio_manager_base.cc index 363a91b..275ec33 100644 --- a/media/audio/audio_manager_base.cc +++ b/media/audio/audio_manager_base.cc @@ -400,4 +400,8 @@ scoped_ptr<AudioLog> AudioManagerBase::CreateAudioLog( return audio_log_factory_->CreateAudioLog(component); } +void AudioManagerBase::SetHasKeyboardMic() { + NOTREACHED(); +} + } // namespace media diff --git a/media/audio/audio_manager_base.h b/media/audio/audio_manager_base.h index bc13ee5..40fb6c3 100644 --- a/media/audio/audio_manager_base.h +++ b/media/audio/audio_manager_base.h @@ -115,6 +115,8 @@ class MEDIA_EXPORT AudioManagerBase : public AudioManager { virtual scoped_ptr<AudioLog> CreateAudioLog( AudioLogFactory::AudioComponent component) OVERRIDE; + virtual void SetHasKeyboardMic() OVERRIDE; + // Get number of input or output streams. int input_stream_count() const { return num_input_streams_; } int output_stream_count() const { return num_output_streams_; } diff --git a/media/audio/cras/audio_manager_cras.cc b/media/audio/cras/audio_manager_cras.cc index ef46176..befd3df 100644 --- a/media/audio/cras/audio_manager_cras.cc +++ b/media/audio/cras/audio_manager_cras.cc @@ -53,7 +53,8 @@ bool AudioManagerCras::HasAudioInputDevices() { } AudioManagerCras::AudioManagerCras(AudioLogFactory* audio_log_factory) - : AudioManagerBase(audio_log_factory) { + : AudioManagerBase(audio_log_factory), + has_keyboard_mic_(false) { SetMaxOutputStreamsAllowed(kMaxOutputStreams); } @@ -77,15 +78,25 @@ void AudioManagerCras::GetAudioOutputDeviceNames( AudioParameters AudioManagerCras::GetInputStreamParameters( const std::string& device_id) { + DCHECK(GetTaskRunner()->BelongsToCurrentThread()); + int user_buffer_size = GetUserBufferSize(); int buffer_size = user_buffer_size ? user_buffer_size : kDefaultInputBufferSize; + AudioParameters::PlatformEffectsMask effects = + has_keyboard_mic_ ? AudioParameters::KEYBOARD_MIC + : AudioParameters::NO_EFFECTS; // TODO(hshi): Fine-tune audio parameters based on |device_id|. The optimal // parameters for the loopback stream may differ from the default. return AudioParameters( AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, - kDefaultSampleRate, 16, buffer_size); + kDefaultSampleRate, 16, buffer_size, effects); +} + +void AudioManagerCras::SetHasKeyboardMic() { + DCHECK(GetTaskRunner()->BelongsToCurrentThread()); + has_keyboard_mic_ = true; } AudioOutputStream* AudioManagerCras::MakeLinearOutputStream( diff --git a/media/audio/cras/audio_manager_cras.h b/media/audio/cras/audio_manager_cras.h index a9abd6c..2bf1c0d 100644 --- a/media/audio/cras/audio_manager_cras.h +++ b/media/audio/cras/audio_manager_cras.h @@ -29,6 +29,7 @@ class MEDIA_EXPORT AudioManagerCras : public AudioManagerBase { AudioDeviceNames* device_names) OVERRIDE; virtual AudioParameters GetInputStreamParameters( const std::string& device_id) OVERRIDE; + virtual void SetHasKeyboardMic() OVERRIDE; // AudioManagerBase implementation. virtual AudioOutputStream* MakeLinearOutputStream( @@ -58,6 +59,8 @@ class MEDIA_EXPORT AudioManagerCras : public AudioManagerBase { AudioInputStream* MakeInputStream(const AudioParameters& params, const std::string& device_id); + bool has_keyboard_mic_; + DISALLOW_COPY_AND_ASSIGN(AudioManagerCras); }; diff --git a/media/audio/mock_audio_manager.cc b/media/audio/mock_audio_manager.cc index 7183405..5cf00d1 100644 --- a/media/audio/mock_audio_manager.cc +++ b/media/audio/mock_audio_manager.cc @@ -104,4 +104,6 @@ scoped_ptr<AudioLog> MockAudioManager::CreateAudioLog( return scoped_ptr<AudioLog>(); } +void MockAudioManager::SetHasKeyboardMic() {} + } // namespace media. diff --git a/media/audio/mock_audio_manager.h b/media/audio/mock_audio_manager.h index 520205d..0933b508 100644 --- a/media/audio/mock_audio_manager.h +++ b/media/audio/mock_audio_manager.h @@ -70,6 +70,8 @@ class MockAudioManager : public media::AudioManager { virtual scoped_ptr<AudioLog> CreateAudioLog( AudioLogFactory::AudioComponent component) OVERRIDE; + virtual void SetHasKeyboardMic() OVERRIDE; + protected: virtual ~MockAudioManager(); |