Commit 2f768292 authored by grunell's avatar grunell Committed by Commit bot

Set keyboard mic effect if available.

* Check if keyboard mic is available in MediaStreamManager and inform AudioManager if so.
* AudioManager sets the effect in AudioParameters returned from GetInputStreamParameters if available.

BUG=345296

Review URL: https://codereview.chromium.org/583833008

Cr-Commit-Position: refs/heads/master@{#296368}
parent 773c53fc
......@@ -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 {
......
......@@ -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
......@@ -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_;
......
......@@ -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() {
......
include_rules = [
"+cc/blink",
"+chromeos/audio", # For WebRTC tests.
# Testing utilities can access anything in content/
"+content",
"+media/audio", # For AudioParameters in WebRTC tests.
......
......@@ -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
......@@ -84,6 +84,9 @@ class PPAPITest : public PPAPITestBase {
class OutOfProcessPPAPITest : public PPAPITest {
public:
OutOfProcessPPAPITest();
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
};
} // namespace
......
......@@ -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(
......
......@@ -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
......
......@@ -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();
......
......@@ -400,4 +400,8 @@ scoped_ptr<AudioLog> AudioManagerBase::CreateAudioLog(
return audio_log_factory_->CreateAudioLog(component);
}
void AudioManagerBase::SetHasKeyboardMic() {
NOTREACHED();
}
} // namespace media
......@@ -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_; }
......
......@@ -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(
......
......@@ -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);
};
......
......@@ -104,4 +104,6 @@ scoped_ptr<AudioLog> MockAudioManager::CreateAudioLog(
return scoped_ptr<AudioLog>();
}
void MockAudioManager::SetHasKeyboardMic() {}
} // namespace media.
......@@ -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();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment