Chromium Code Reviews| Index: media/audio/win/audio_low_latency_input_win.cc |
| diff --git a/media/audio/win/audio_low_latency_input_win.cc b/media/audio/win/audio_low_latency_input_win.cc |
| index 949d681945f058919e25758b9509bfb3aaa295b9..98f692f6b74f2db1d636f2a0be39da12a3358e37 100644 |
| --- a/media/audio/win/audio_low_latency_input_win.cc |
| +++ b/media/audio/win/audio_low_latency_input_win.cc |
| @@ -4,6 +4,7 @@ |
| #include "media/audio/win/audio_low_latency_input_win.h" |
| +#include <endpointvolume.h> |
| #include <memory> |
| #include "base/logging.h" |
| @@ -35,7 +36,8 @@ WASAPIAudioInputStream::WASAPIAudioInputStream(AudioManagerWin* manager, |
| perf_count_to_100ns_units_(0.0), |
| ms_to_frame_count_(0.0), |
| sink_(NULL), |
| - audio_bus_(media::AudioBus::Create(params)) { |
| + audio_bus_(media::AudioBus::Create(params)), |
| + mute_done_(false) { |
| DCHECK(manager_); |
| // Load the Avrt DLL if not already loaded. Required to support MMCSS. |
| @@ -165,6 +167,19 @@ void WASAPIAudioInputStream::Stop() { |
| if (!started_) |
| return; |
| + if (device_id_ == AudioDeviceDescription::kLoopbackWithMuteDeviceId && |
|
henrika (OOO until Aug 14)
2016/07/25 08:38:19
Add a comment on 169 explaining what you do here.
qiangchen
2016/07/25 22:42:22
Done.
|
| + mute_done_) { |
| + IAudioEndpointVolume* pVolume = NULL; |
| + HRESULT hr = |
| + endpoint_device_->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, |
| + NULL, reinterpret_cast<void**>(&pVolume)); |
|
henrika (OOO until Aug 14)
2016/07/25 08:38:19
Can you use base::win::ScopedComPtr<IAudioEndpoint
qiangchen
2016/07/25 22:42:22
Done.
|
| + |
| + if (SUCCEEDED(hr)) { |
| + hr = pVolume->SetMute(false, NULL); |
| + mute_done_ = false; |
| + } |
| + } |
| + |
| // Stops periodic AGC microphone measurements. |
| StopAgc(); |
| @@ -471,6 +486,23 @@ HRESULT WASAPIAudioInputStream::SetCaptureDevice() { |
| } else if (device_id_ == AudioDeviceDescription::kCommunicationsDeviceId) { |
| hr = enumerator->GetDefaultAudioEndpoint(eCapture, eCommunications, |
| endpoint_device_.Receive()); |
| + } else if (device_id_ == AudioDeviceDescription::kLoopbackWithMuteDeviceId) { |
| + // Capture the default playback stream. |
| + hr = enumerator->GetDefaultAudioEndpoint(eRender, eConsole, |
| + endpoint_device_.Receive()); |
| + |
| + IAudioEndpointVolume* pVolume = NULL; |
|
henrika (OOO until Aug 14)
2016/07/25 08:38:19
See comments above. Also, you duplicate code here.
qiangchen
2016/07/25 22:42:22
Done.
|
| + HRESULT hr2 = |
|
henrika (OOO until Aug 14)
2016/07/25 08:38:19
Try to clean this up and avoid using a second HRES
qiangchen
2016/07/25 22:42:22
Done.
|
| + endpoint_device_->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, |
| + NULL, reinterpret_cast<void**>(&pVolume)); |
| + if (SUCCEEDED(hr2) && pVolume) { |
| + BOOL muted = false; |
| + hr2 = pVolume->GetMute(&muted); |
| + if (SUCCEEDED(hr2) && !muted) { |
|
henrika (OOO until Aug 14)
2016/07/25 08:38:19
Improve comments and explain why you always mute h
qiangchen
2016/07/25 22:42:22
Done.
|
| + hr2 = pVolume->SetMute(true, NULL); |
| + mute_done_ = true; |
| + } |
| + } |
| } else if (device_id_ == AudioDeviceDescription::kLoopbackInputDeviceId) { |
| // Capture the default playback stream. |
| hr = enumerator->GetDefaultAudioEndpoint(eRender, eConsole, |
| @@ -572,7 +604,8 @@ HRESULT WASAPIAudioInputStream::InitializeAudioEngine() { |
| // Use event-driven mode only fo regular input devices. For loopback the |
| // EVENTCALLBACK flag is specified when intializing |
| // |audio_render_client_for_loopback_|. |
| - if (device_id_ == AudioDeviceDescription::kLoopbackInputDeviceId) { |
| + if (device_id_ == AudioDeviceDescription::kLoopbackInputDeviceId || |
| + device_id_ == AudioDeviceDescription::kLoopbackWithMuteDeviceId) { |
| flags = AUDCLNT_STREAMFLAGS_LOOPBACK | AUDCLNT_STREAMFLAGS_NOPERSIST; |
| } else { |
| flags = AUDCLNT_STREAMFLAGS_EVENTCALLBACK | AUDCLNT_STREAMFLAGS_NOPERSIST; |
| @@ -646,7 +679,8 @@ HRESULT WASAPIAudioInputStream::InitializeAudioEngine() { |
| // samples from the capture endpoint buffer. |
| // |
| // http://msdn.microsoft.com/en-us/library/windows/desktop/dd316551(v=vs.85).aspx |
| - if (device_id_ == AudioDeviceDescription::kLoopbackInputDeviceId) { |
| + if (device_id_ == AudioDeviceDescription::kLoopbackInputDeviceId || |
| + device_id_ == AudioDeviceDescription::kLoopbackWithMuteDeviceId) { |
| hr = endpoint_device_->Activate( |
| __uuidof(IAudioClient), CLSCTX_INPROC_SERVER, NULL, |
| audio_render_client_for_loopback_.ReceiveVoid()); |