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

Unified Diff: media/audio/win/audio_manager_win.cc

Issue 155863003: Add basic support for "googDucking" to getUserMedia on Windows. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 10 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
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 ec963a702a843a420cca6d4160e60c6b5e666806..baa33e2ae011ad9a31da7381b41b235791ff827d 100644
--- a/media/audio/win/audio_manager_win.cc
+++ b/media/audio/win/audio_manager_win.cc
@@ -129,7 +129,12 @@ static int NumberOfWaveOutBuffers() {
AudioManagerWin::AudioManagerWin(AudioLogFactory* audio_log_factory)
: AudioManagerBase(audio_log_factory),
- enumeration_type_(kUninitializedEnumeration) {
+ enumeration_type_(kUninitializedEnumeration),
+ // |CoreAudioUtil::IsSupported()| uses static variables to avoid doing
+ // multiple initializations. This is however not thread safe.
+ // So, here we call it explicitly before we kick off the audio thread
+ // or do any other work.
+ core_audio_supported_(CoreAudioUtil::IsSupported()) {
DaleCurtis 2014/02/05 22:15:43 Heh, I just removed this from the startup path las
tommi (sloooow) - chröme 2014/02/06 11:50:34 Did you measure this impact? It's not clear to me
tommi (sloooow) - chröme 2014/02/06 12:55:34 Henrik - maybe you can weigh in here as well with
henrika (OOO until Aug 14) 2014/02/06 13:11:28 Link to original issue which triggered the change:
DaleCurtis 2014/02/06 19:09:21 Here's the CL I moved it off in: https://coderevie
SetMaxOutputStreamsAllowed(kMaxOutputStreams);
// WARNING: This is executed on the UI loop, do not add any code here which
@@ -161,7 +166,7 @@ bool AudioManagerWin::HasAudioInputDevices() {
void AudioManagerWin::InitializeOnAudioThread() {
DCHECK(GetTaskRunner()->BelongsToCurrentThread());
- if (CoreAudioUtil::IsSupported()) {
+ if (core_audio_supported_) {
// Use the MMDevice API for device enumeration if Vista or higher.
enumeration_type_ = kMMDeviceEnumeration;
@@ -248,7 +253,7 @@ base::string16 AudioManagerWin::GetAudioInputDeviceModel() {
void AudioManagerWin::ShowAudioInputSettings() {
std::wstring program;
std::string argument;
- if (!CoreAudioUtil::IsSupported()) {
+ if (!core_audio_supported_) {
program = L"sndvol32.exe";
argument = "-R";
} else {
@@ -304,26 +309,18 @@ void AudioManagerWin::GetAudioOutputDeviceNames(
AudioParameters AudioManagerWin::GetInputStreamParameters(
const std::string& device_id) {
- int sample_rate = 48000;
- ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
- if (CoreAudioUtil::IsSupported()) {
- int hw_sample_rate = WASAPIAudioInputStream::HardwareSampleRate(device_id);
- if (hw_sample_rate)
- sample_rate = hw_sample_rate;
- channel_layout =
- WASAPIAudioInputStream::HardwareChannelCount(device_id) == 1 ?
- CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO;
+ if (!core_audio_supported_) {
+ return AudioParameters(
+ AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 0, 48000,
+ 16, kFallbackBufferSize, AudioParameters::NO_EFFECTS);
}
- // TODO(Henrika): improve the default buffer size value for input stream.
- return AudioParameters(
- AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
- sample_rate, 16, kFallbackBufferSize);
+ return WASAPIAudioInputStream::GetInputStreamParameters(device_id);
}
std::string AudioManagerWin::GetAssociatedOutputDeviceID(
const std::string& input_device_id) {
- if (!CoreAudioUtil::IsSupported()) {
+ if (!core_audio_supported_) {
NOTIMPLEMENTED()
<< "GetAssociatedOutputDeviceID is not supported on this OS";
return std::string();
@@ -359,7 +356,7 @@ AudioOutputStream* AudioManagerWin::MakeLowLatencyOutputStream(
if (params.channels() > kWinMaxChannels)
return NULL;
- if (!CoreAudioUtil::IsSupported()) {
+ if (!core_audio_supported_) {
// Fall back to Windows Wave implementation on Windows XP or lower.
DLOG_IF(ERROR, !device_id.empty() &&
device_id != AudioManagerBase::kDefaultDeviceId)
@@ -401,7 +398,7 @@ AudioInputStream* AudioManagerWin::MakeLowLatencyInputStream(
const AudioParameters& params, const std::string& device_id) {
DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
AudioInputStream* stream = NULL;
- if (!CoreAudioUtil::IsSupported()) {
+ if (!core_audio_supported_) {
// Fall back to Windows Wave implementation on Windows XP or lower.
DVLOG(1) << "Using WaveIn since WASAPI requires at least Vista.";
stream = CreatePCMWaveInAudioInputStream(params, device_id);
@@ -413,7 +410,7 @@ AudioInputStream* AudioManagerWin::MakeLowLatencyInputStream(
}
std::string AudioManagerWin::GetDefaultOutputDeviceID() {
- if (!CoreAudioUtil::IsSupported())
+ if (!core_audio_supported_)
return std::string();
return CoreAudioUtil::GetDefaultOutputDeviceID();
}
@@ -421,8 +418,7 @@ std::string AudioManagerWin::GetDefaultOutputDeviceID() {
AudioParameters AudioManagerWin::GetPreferredOutputStreamParameters(
const std::string& output_device_id,
const AudioParameters& input_params) {
- const bool core_audio_supported = CoreAudioUtil::IsSupported();
- DLOG_IF(ERROR, !core_audio_supported && !output_device_id.empty())
+ DLOG_IF(ERROR, !core_audio_supported_ && !output_device_id.empty())
<< "CoreAudio is required to open non-default devices.";
const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
@@ -431,8 +427,8 @@ AudioParameters AudioManagerWin::GetPreferredOutputStreamParameters(
int buffer_size = kFallbackBufferSize;
int bits_per_sample = 16;
int input_channels = 0;
- bool use_input_params = !core_audio_supported;
- if (core_audio_supported) {
+ bool use_input_params = !core_audio_supported_;
+ if (core_audio_supported_) {
if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) {
// TODO(rtoy): tune these values for best possible WebAudio
// performance. WebRTC works well at 48kHz and a buffer size of 480
@@ -464,7 +460,7 @@ AudioParameters AudioManagerWin::GetPreferredOutputStreamParameters(
// If the user has enabled checking supported channel layouts or we don't
// have a valid channel layout yet, try to use the input layout. See bugs
// http://crbug.com/259165 and http://crbug.com/311906 for more details.
- if (core_audio_supported &&
+ if (core_audio_supported_ &&
(cmd_line->HasSwitch(switches::kTrySupportedChannelLayouts) ||
channel_layout == CHANNEL_LAYOUT_UNSUPPORTED)) {
// Check if it is possible to open up at the specified input channel

Powered by Google App Engine
This is Rietveld 408576698