OLD | NEW |
---|---|
(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; | |
henrika (OOO until Aug 14)
2014/02/25 07:56:21
How do you define muted? When the volume is low or
| |
20 | |
21 // Lowest volume which is considered to be audible in the range [0, 100]. | |
22 const int kAudibleOutputVolumeThreshold = 10; | |
23 | |
24 } // namespace | |
25 | |
26 namespace ash { | |
27 namespace system { | |
28 | |
29 void TrayAudioDelegateWin::AdjustOutputVolumeToAudibleLevel() { | |
30 if (GetOutputVolumeLevel() < kAudibleOutputVolumeThreshold) | |
31 SetOutputVolumeLevel(kAudibleOutputVolumeThreshold); | |
32 } | |
33 | |
34 int TrayAudioDelegateWin::GetOutputDefaultVolumeMuteLevel() { | |
35 return kMuteThresholdPercent; | |
tommi (sloooow) - chröme
2014/02/25 16:47:38
nit: do you actually need the constant? might as
zturner
2014/02/25 17:19:56
I also used the constant in AdjustOutputVolumeToAu
| |
36 } | |
37 | |
38 int TrayAudioDelegateWin::GetOutputVolumeLevel() { | |
39 ScopedComPtr<ISimpleAudioVolume> volume_control = | |
40 CreateDefaultVolumeControl(); | |
41 | |
42 float level = 0.0f; | |
43 if (FAILED(volume_control->GetMasterVolume(&level))) | |
44 return 0; | |
45 | |
46 return static_cast<int>(std::roundf(level * 100.0f)); | |
47 } | |
48 | |
49 int TrayAudioDelegateWin::GetActiveOutputDeviceIconId() { | |
50 return kNoAudioDeviceIcon; | |
51 } | |
52 | |
tommi (sloooow) - chröme
2014/02/25 16:47:38
one empty line
| |
53 | |
54 bool TrayAudioDelegateWin::HasAlternativeSources() { | |
55 return false; | |
56 } | |
57 | |
58 bool TrayAudioDelegateWin::IsOutputAudioMuted() { | |
tommi (sloooow) - chröme
2014/02/25 16:47:38
Would be good to have thread checks for all of the
zturner
2014/02/25 17:19:56
Is CoreAudio inherently single-threaded? CreateDe
tommi (sloooow) - chröme
2014/02/26 11:10:44
CoreAudio isn't single threaded but not every thre
| |
59 ScopedComPtr<ISimpleAudioVolume> volume_control = | |
60 CreateDefaultVolumeControl(); | |
61 | |
62 BOOL mute = FALSE; | |
63 if (FAILED(volume_control->GetMute(&mute))) | |
64 return false; | |
65 | |
66 return !!mute; | |
67 } | |
68 | |
69 void TrayAudioDelegateWin::SetOutputAudioIsMuted(bool is_muted) { | |
70 ScopedComPtr<ISimpleAudioVolume> volume_control = | |
71 CreateDefaultVolumeControl(); | |
72 | |
73 volume_control->SetMute(is_muted, NULL); | |
74 } | |
75 | |
76 void TrayAudioDelegateWin::SetOutputVolumeLevel(int level) { | |
77 ScopedComPtr<ISimpleAudioVolume> volume_control = | |
78 CreateDefaultVolumeControl(); | |
79 | |
80 float volume_level = static_cast<float>(level) / 100.0f; | |
81 volume_control->SetMasterVolume(volume_level, NULL); | |
82 } | |
83 | |
84 ScopedComPtr<ISimpleAudioVolume> | |
85 TrayAudioDelegateWin::CreateDefaultVolumeControl() { | |
86 ScopedComPtr<ISimpleAudioVolume> volume_control; | |
87 ScopedComPtr<IAudioSessionManager> session_manager; | |
henrika (OOO until Aug 14)
2014/02/25 07:56:21
Why are you using the SessionManager here? What is
| |
88 | |
89 ScopedComPtr<IMMDevice> device = | |
90 media::CoreAudioUtil::CreateDefaultDevice(eRender, eConsole); | |
91 if (FAILED(device->Activate(__uuidof(IAudioSessionManager), CLSCTX_ALL, NULL, | |
92 session_manager.ReceiveVoid()))) { | |
93 return volume_control; | |
94 } | |
95 | |
96 session_manager->GetSimpleAudioVolume(NULL, FALSE, | |
97 volume_control.Receive()); | |
98 | |
99 return volume_control; | |
100 } | |
101 | |
102 } // namespace system | |
103 } // namespace ash | |
OLD | NEW |