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

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

Issue 2075813002: Remove ash_shell audio system tray item on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and rebase. Created 4 years, 6 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
« 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 "media/audio/win/core_audio_util_win.h"
11
12 using base::win::ScopedComPtr;
13
14 namespace {
15
16 // Volume value which should be considered as muted in range [0, 100].
17 const int kMuteThresholdPercent = 1;
18
19 // Lowest volume which is considered to be audible in the range [0, 100].
20 const int kDefaultUnmuteVolumePercent = 4;
21
22 } // namespace
23
24 namespace ash {
25 namespace system {
26
27 void TrayAudioDelegateWin::AdjustOutputVolumeToAudibleLevel() {
28 if (GetOutputVolumeLevel() <= kMuteThresholdPercent)
29 SetOutputVolumeLevel(kDefaultUnmuteVolumePercent);
30 }
31
32 int TrayAudioDelegateWin::GetOutputDefaultVolumeMuteLevel() {
33 return kMuteThresholdPercent;
34 }
35
36 int TrayAudioDelegateWin::GetOutputVolumeLevel() {
37 ScopedComPtr<ISimpleAudioVolume> volume_control =
38 CreateDefaultVolumeControl();
39 if (!volume_control.get())
40 return 0;
41
42 float level = 0.0f;
43 if (FAILED(volume_control->GetMasterVolume(&level)))
44 return 0;
45
46 // MSVC prior to 2013 doesn't have a round function. The below code is not
47 // conformant to C99 round(), but since we know that 0 <= level <= 100, it
48 // should be ok.
49 return static_cast<int>(level + 0.5);
50 }
51
52 int TrayAudioDelegateWin::GetActiveOutputDeviceIconId() {
53 return kNoAudioDeviceIcon;
54 }
55
56 bool TrayAudioDelegateWin::HasAlternativeSources() {
57 return false;
58 }
59
60 bool TrayAudioDelegateWin::IsOutputAudioMuted() {
61 ScopedComPtr<ISimpleAudioVolume> volume_control =
62 CreateDefaultVolumeControl();
63
64 if (!volume_control.get())
65 return false;
66
67 BOOL mute = FALSE;
68 if (FAILED(volume_control->GetMute(&mute)))
69 return false;
70
71 return !!mute;
72 }
73
74 void TrayAudioDelegateWin::SetOutputAudioIsMuted(bool is_muted) {
75 ScopedComPtr<ISimpleAudioVolume> volume_control =
76 CreateDefaultVolumeControl();
77
78 if (!volume_control.get())
79 return;
80
81 volume_control->SetMute(is_muted, NULL);
82 }
83
84 void TrayAudioDelegateWin::SetOutputVolumeLevel(int level) {
85 ScopedComPtr<ISimpleAudioVolume> volume_control =
86 CreateDefaultVolumeControl();
87
88 if (!volume_control.get())
89 return;
90
91 float volume_level = static_cast<float>(level) / 100.0f;
92 volume_control->SetMasterVolume(volume_level, NULL);
93 }
94
95 void TrayAudioDelegateWin::SetInternalSpeakerChannelMode(
96 AudioChannelMode mode) {
97 }
98
99 void TrayAudioDelegateWin::SetActiveHDMIOutoutRediscoveringIfNecessary(
100 bool force_rediscovering) {
101 }
102
103 ScopedComPtr<ISimpleAudioVolume>
104 TrayAudioDelegateWin::CreateDefaultVolumeControl() {
105 ScopedComPtr<ISimpleAudioVolume> volume_control;
106 ScopedComPtr<IAudioSessionManager> session_manager;
107
108 ScopedComPtr<IMMDevice> device =
109 media::CoreAudioUtil::CreateDefaultDevice(eRender, eConsole);
110 if (!device.get() ||
111 FAILED(device->Activate(__uuidof(IAudioSessionManager), CLSCTX_ALL, NULL,
112 session_manager.ReceiveVoid()))) {
113 return volume_control;
114 }
115
116 session_manager->GetSimpleAudioVolume(NULL, FALSE,
117 volume_control.Receive());
118
119 return volume_control;
120 }
121
122 } // namespace system
123 } // 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