Chromium Code Reviews| 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; | |
| 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 | |
| 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 | |
| 53 bool TrayAudioDelegateWin::HasAlternativeSources() { | |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 bool TrayAudioDelegateWin::IsOutputAudioMuted() { | |
| 58 ScopedComPtr<ISimpleAudioVolume> volume_control = | |
| 59 CreateDefaultVolumeControl(); | |
| 60 | |
| 61 BOOL mute = FALSE; | |
| 62 if (FAILED(volume_control->GetMute(&mute))) | |
| 63 return false; | |
| 64 | |
| 65 return !!mute; | |
| 66 } | |
| 67 | |
| 68 void TrayAudioDelegateWin::SetOutputAudioIsMuted(bool is_muted) { | |
| 69 ScopedComPtr<ISimpleAudioVolume> volume_control = | |
| 70 CreateDefaultVolumeControl(); | |
| 71 | |
| 72 volume_control->SetMute(is_muted, NULL); | |
| 73 } | |
| 74 | |
| 75 void TrayAudioDelegateWin::SetOutputVolumeLevel(int level) { | |
| 76 ScopedComPtr<ISimpleAudioVolume> volume_control = | |
| 77 CreateDefaultVolumeControl(); | |
| 78 | |
| 79 float volume_level = static_cast<float>(level) / 100.0f; | |
| 80 volume_control->SetMasterVolume(volume_level, NULL); | |
| 81 } | |
| 82 | |
| 83 ScopedComPtr<ISimpleAudioVolume> | |
|
henrika (OOO until Aug 14)
2014/02/26 09:10:05
It is not clear to me why you call this method in
tommi (sloooow) - chröme
2014/02/26 11:10:44
If these methods are infrequently called, then I t
zturner
2014/02/26 17:50:29
Yes, the default device changing is exactly the re
| |
| 84 TrayAudioDelegateWin::CreateDefaultVolumeControl() { | |
| 85 ScopedComPtr<ISimpleAudioVolume> volume_control; | |
| 86 ScopedComPtr<IAudioSessionManager> session_manager; | |
| 87 | |
| 88 ScopedComPtr<IMMDevice> device = | |
| 89 media::CoreAudioUtil::CreateDefaultDevice(eRender, eConsole); | |
| 90 if (FAILED(device->Activate(__uuidof(IAudioSessionManager), CLSCTX_ALL, NULL, | |
| 91 session_manager.ReceiveVoid()))) { | |
| 92 return volume_control; | |
| 93 } | |
| 94 | |
| 95 session_manager->GetSimpleAudioVolume(NULL, FALSE, | |
| 96 volume_control.Receive()); | |
| 97 | |
| 98 return volume_control; | |
| 99 } | |
| 100 | |
| 101 } // namespace system | |
| 102 } // namespace ash | |
| OLD | NEW |