Disable accessible touch exploration by default.
[chromium-blink-merge.git] / ash / system / win / audio / tray_audio_delegate_win.cc
blob57c7b56307e86ebff36b63473dbd28ddcb468cee
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.
5 #include "ash/system/win/audio/tray_audio_delegate_win.h"
7 #include <audiopolicy.h>
8 #include <cmath>
10 #include "grit/ash_resources.h"
11 #include "grit/ash_strings.h"
12 #include "media/audio/win/core_audio_util_win.h"
14 using base::win::ScopedComPtr;
16 namespace {
18 // Volume value which should be considered as muted in range [0, 100].
19 const int kMuteThresholdPercent = 1;
21 // Lowest volume which is considered to be audible in the range [0, 100].
22 const int kDefaultUnmuteVolumePercent = 4;
24 } // namespace
26 namespace ash {
27 namespace system {
29 void TrayAudioDelegateWin::AdjustOutputVolumeToAudibleLevel() {
30 if (GetOutputVolumeLevel() <= kMuteThresholdPercent)
31 SetOutputVolumeLevel(kDefaultUnmuteVolumePercent);
34 int TrayAudioDelegateWin::GetOutputDefaultVolumeMuteLevel() {
35 return kMuteThresholdPercent;
38 int TrayAudioDelegateWin::GetOutputVolumeLevel() {
39 ScopedComPtr<ISimpleAudioVolume> volume_control =
40 CreateDefaultVolumeControl();
41 if (!volume_control)
42 return 0;
44 float level = 0.0f;
45 if (FAILED(volume_control->GetMasterVolume(&level)))
46 return 0;
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);
54 int TrayAudioDelegateWin::GetActiveOutputDeviceIconId() {
55 return kNoAudioDeviceIcon;
58 bool TrayAudioDelegateWin::HasAlternativeSources() {
59 return false;
62 bool TrayAudioDelegateWin::IsOutputAudioMuted() {
63 ScopedComPtr<ISimpleAudioVolume> volume_control =
64 CreateDefaultVolumeControl();
66 if (!volume_control)
67 return false;
69 BOOL mute = FALSE;
70 if (FAILED(volume_control->GetMute(&mute)))
71 return false;
73 return !!mute;
76 void TrayAudioDelegateWin::SetOutputAudioIsMuted(bool is_muted) {
77 ScopedComPtr<ISimpleAudioVolume> volume_control =
78 CreateDefaultVolumeControl();
80 if (!volume_control)
81 return;
83 volume_control->SetMute(is_muted, NULL);
86 void TrayAudioDelegateWin::SetOutputVolumeLevel(int level) {
87 ScopedComPtr<ISimpleAudioVolume> volume_control =
88 CreateDefaultVolumeControl();
90 if (!volume_control)
91 return;
93 float volume_level = static_cast<float>(level) / 100.0f;
94 volume_control->SetMasterVolume(volume_level, NULL);
97 ScopedComPtr<ISimpleAudioVolume>
98 TrayAudioDelegateWin::CreateDefaultVolumeControl() {
99 ScopedComPtr<ISimpleAudioVolume> volume_control;
100 ScopedComPtr<IAudioSessionManager> session_manager;
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;
110 session_manager->GetSimpleAudioVolume(NULL, FALSE,
111 volume_control.Receive());
113 return volume_control;
116 } // namespace system
117 } // namespace ash