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

Side by Side Diff: ash/system/win/audio/tray_audio_delegate_win.cc

Issue 188693004: Revert of Enable the volume slider in Ash for windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « ash/system/win/audio/tray_audio_delegate_win.h ('k') | ash/system/win/audio/tray_audio_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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/system/win/audio/tray_audio_delegate_win.h"
6
7 #include <audiopolicy.h>
8 #include <cmath>
9
10 #include "grit/ash_resources.h"
11 #include "grit/ash_strings.h"
12 #include "media/audio/win/core_audio_util_win.h"
13
14 using base::win::ScopedComPtr;
15
16 namespace {
17
18 // Volume value which should be considered as muted in range [0, 100].
19 const int kMuteThresholdPercent = 1;
20
21 // Lowest volume which is considered to be audible in the range [0, 100].
22 const int kDefaultUnmuteVolumePercent = 4;
23
24 } // namespace
25
26 namespace ash {
27 namespace system {
28
29 void TrayAudioDelegateWin::AdjustOutputVolumeToAudibleLevel() {
30 if (GetOutputVolumeLevel() <= kMuteThresholdPercent)
31 SetOutputVolumeLevel(kDefaultUnmuteVolumePercent);
32 }
33
34 int TrayAudioDelegateWin::GetOutputDefaultVolumeMuteLevel() {
35 return kMuteThresholdPercent;
36 }
37
38 int TrayAudioDelegateWin::GetOutputVolumeLevel() {
39 ScopedComPtr<ISimpleAudioVolume> volume_control =
40 CreateDefaultVolumeControl();
41 if (!volume_control)
42 return 0;
43
44 float level = 0.0f;
45 if (FAILED(volume_control->GetMasterVolume(&level)))
46 return 0;
47
48 // MSVC prior to 2013 doesn't have a round function. The below code is not
49 // conformant to C99 round(), but since we know that 0 <= level <= 100, it
50 // should be ok.
51 return static_cast<int>(level + 0.5);
52 }
53
54 int TrayAudioDelegateWin::GetActiveOutputDeviceIconId() {
55 return kNoAudioDeviceIcon;
56 }
57
58 bool TrayAudioDelegateWin::HasAlternativeSources() {
59 return false;
60 }
61
62 bool TrayAudioDelegateWin::IsOutputAudioMuted() {
63 ScopedComPtr<ISimpleAudioVolume> volume_control =
64 CreateDefaultVolumeControl();
65
66 if (!volume_control)
67 return false;
68
69 BOOL mute = FALSE;
70 if (FAILED(volume_control->GetMute(&mute)))
71 return false;
72
73 return !!mute;
74 }
75
76 void TrayAudioDelegateWin::SetOutputAudioIsMuted(bool is_muted) {
77 ScopedComPtr<ISimpleAudioVolume> volume_control =
78 CreateDefaultVolumeControl();
79
80 if (!volume_control)
81 return;
82
83 volume_control->SetMute(is_muted, NULL);
84 }
85
86 void TrayAudioDelegateWin::SetOutputVolumeLevel(int level) {
87 ScopedComPtr<ISimpleAudioVolume> volume_control =
88 CreateDefaultVolumeControl();
89
90 if (!volume_control)
91 return;
92
93 float volume_level = static_cast<float>(level) / 100.0f;
94 volume_control->SetMasterVolume(volume_level, NULL);
95 }
96
97 ScopedComPtr<ISimpleAudioVolume>
98 TrayAudioDelegateWin::CreateDefaultVolumeControl() {
99 ScopedComPtr<ISimpleAudioVolume> volume_control;
100 ScopedComPtr<IAudioSessionManager> session_manager;
101
102 ScopedComPtr<IMMDevice> device =
103 media::CoreAudioUtil::CreateDefaultDevice(eRender, eConsole);
104 if (!device ||
105 FAILED(device->Activate(__uuidof(IAudioSessionManager), CLSCTX_ALL, NULL,
106 session_manager.ReceiveVoid()))) {
107 return volume_control;
108 }
109
110 session_manager->GetSimpleAudioVolume(NULL, FALSE,
111 volume_control.Receive());
112
113 return volume_control;
114 }
115
116 } // namespace system
117 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/win/audio/tray_audio_delegate_win.h ('k') | ash/system/win/audio/tray_audio_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698