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

Unified Diff: remoting/host/win/audio_volume_applier_win.cc

Issue 2840773004: [Chromoting] Add AudioVolumeApplier to reduce the complexity and the dependency of kChannels (Closed)
Patch Set: Created 3 years, 8 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: remoting/host/win/audio_volume_applier_win.cc
diff --git a/remoting/host/win/audio_volume_applier_win.cc b/remoting/host/win/audio_volume_applier_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d147b593665ff934f64a18b01e6ce9cd83fce846
--- /dev/null
+++ b/remoting/host/win/audio_volume_applier_win.cc
@@ -0,0 +1,58 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/host/win/audio_volume_applier_win.h"
+
+#include "base/logging.h"
+
+namespace remoting {
+
+AudioVolumeApplierWin::AudioVolumeApplierWin(int silence_threshold)
+ : AudioVolumeApplier(silence_threshold) {}
+AudioVolumeApplierWin::~AudioVolumeApplierWin() = default;
+
+bool AudioVolumeApplierWin::ActivateBy(IMMDevice* mm_device) {
+ DCHECK(mm_device);
+ audio_volume_.Reset();
+ // TODO(zijiehe): Do we need to control the volume per process?
+ HRESULT hr = mm_device->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL,
+ nullptr, audio_volume_.ReceiveVoid());
+ if (FAILED(hr)) {
+ LOG(WARNING) << "Failed to get an IAudioEndpointVolume. Error " << hr;
+ return false;
+ }
+ return true;
+}
+
+float AudioVolumeApplierWin::GetAudioLevel() {
+ if (!audio_volume_) {
+ return 1;
+ }
+
+ BOOL mute;
+ HRESULT hr = audio_volume_->GetMute(&mute);
+ if (FAILED(hr)) {
+ LOG(ERROR) << "Failed to get mute status from IAudioEndpointVolume, error "
+ << hr;
+ return 1;
+ }
+ if (mute) {
+ return 0;
+ }
+
+ float level;
+ hr = audio_volume_->GetMasterVolumeLevelScalar(&level);
+ if (FAILED(hr) || level > 1) {
+ LOG(ERROR) << "Failed to get master volume from IAudioEndpointVolume, "
+ "error "
+ << hr;
+ return 1;
+ }
+ if (level < 0) {
+ return 0;
+ }
+ return level;
+}
+
+} // namespace remoting
« remoting/host/audio_volume_applier.cc ('K') | « remoting/host/win/audio_volume_applier_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698