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

Side by Side Diff: media/audio/win/audio_low_latency_input_win.cc

Issue 645923002: Add support for audio input mute detection on all platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « media/audio/win/audio_low_latency_input_win.h ('k') | media/audio/win/wavein_input_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/audio/win/audio_low_latency_input_win.h" 5 #include "media/audio/win/audio_low_latency_input_win.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "media/audio/win/audio_manager_win.h" 10 #include "media/audio/win/audio_manager_win.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 246
247 // Update the AGC volume level based on the last setting above. Note that, 247 // Update the AGC volume level based on the last setting above. Note that,
248 // the volume-level resolution is not infinite and it is therefore not 248 // the volume-level resolution is not infinite and it is therefore not
249 // possible to assume that the volume provided as input parameter can be 249 // possible to assume that the volume provided as input parameter can be
250 // used directly. Instead, a new query to the audio hardware is required. 250 // used directly. Instead, a new query to the audio hardware is required.
251 // This method does nothing if AGC is disabled. 251 // This method does nothing if AGC is disabled.
252 UpdateAgcVolume(); 252 UpdateAgcVolume();
253 } 253 }
254 254
255 double WASAPIAudioInputStream::GetVolume() { 255 double WASAPIAudioInputStream::GetVolume() {
256 DLOG_IF(ERROR, !opened_) << "Open() has not been called successfully"; 256 DCHECK(opened_) << "Open() has not been called successfully";
257 if (!opened_) 257 if (!opened_)
258 return 0.0; 258 return 0.0;
259 259
260 // Retrieve the current volume level. The value is in the range 0.0 to 1.0. 260 // Retrieve the current volume level. The value is in the range 0.0 to 1.0.
261 float level = 0.0f; 261 float level = 0.0f;
262 HRESULT hr = simple_audio_volume_->GetMasterVolume(&level); 262 HRESULT hr = simple_audio_volume_->GetMasterVolume(&level);
263 DLOG_IF(WARNING, FAILED(hr)) << "Failed to get input master volume."; 263 DLOG_IF(WARNING, FAILED(hr)) << "Failed to get input master volume.";
264 264
265 return static_cast<double>(level); 265 return static_cast<double>(level);
266 } 266 }
267 267
268 bool WASAPIAudioInputStream::IsMuted() {
269 DCHECK(opened_) << "Open() has not been called successfully";
270 DCHECK(CalledOnValidThread());
271 if (!opened_)
272 return false;
273
274 // Retrieves the current muting state for the audio session.
275 BOOL is_muted = FALSE;
276 HRESULT hr = simple_audio_volume_->GetMute(&is_muted);
277 DLOG_IF(WARNING, FAILED(hr)) << "Failed to get input master volume.";
278
279 return is_muted != FALSE;
280 }
281
268 // static 282 // static
269 AudioParameters WASAPIAudioInputStream::GetInputStreamParameters( 283 AudioParameters WASAPIAudioInputStream::GetInputStreamParameters(
270 const std::string& device_id) { 284 const std::string& device_id) {
271 int sample_rate = 48000; 285 int sample_rate = 48000;
272 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; 286 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
273 287
274 base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format; 288 base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format;
275 int effects = AudioParameters::NO_EFFECTS; 289 int effects = AudioParameters::NO_EFFECTS;
276 if (SUCCEEDED(GetMixFormat(device_id, &audio_engine_mix_format, &effects))) { 290 if (SUCCEEDED(GetMixFormat(device_id, &audio_engine_mix_format, &effects))) {
277 sample_rate = static_cast<int>(audio_engine_mix_format->nSamplesPerSec); 291 sample_rate = static_cast<int>(audio_engine_mix_format->nSamplesPerSec);
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 return hr; 756 return hr;
743 757
744 // Obtain a reference to the ISimpleAudioVolume interface which enables 758 // Obtain a reference to the ISimpleAudioVolume interface which enables
745 // us to control the master volume level of an audio session. 759 // us to control the master volume level of an audio session.
746 hr = audio_client_->GetService(__uuidof(ISimpleAudioVolume), 760 hr = audio_client_->GetService(__uuidof(ISimpleAudioVolume),
747 simple_audio_volume_.ReceiveVoid()); 761 simple_audio_volume_.ReceiveVoid());
748 return hr; 762 return hr;
749 } 763 }
750 764
751 } // namespace media 765 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/win/audio_low_latency_input_win.h ('k') | media/audio/win/wavein_input_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698