Chromium Code Reviews| Index: ash/system/win/audio/tray_audio_delegate_win.cc |
| diff --git a/ash/system/win/audio/tray_audio_delegate_win.cc b/ash/system/win/audio/tray_audio_delegate_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7e1826cdcfc10d568b5ceee860c251bfceeb2bed |
| --- /dev/null |
| +++ b/ash/system/win/audio/tray_audio_delegate_win.cc |
| @@ -0,0 +1,103 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/system/win/audio/tray_audio_delegate_win.h" |
| + |
| +#include <audiopolicy.h> |
| +#include <cmath> |
| + |
| +#include "grit/ash_resources.h" |
| +#include "grit/ash_strings.h" |
| +#include "media/audio/win/core_audio_util_win.h" |
| + |
| +using base::win::ScopedComPtr; |
| + |
| +namespace { |
| + |
| +// Volume value which should be considered as muted in range [0, 100]. |
| +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
|
| + |
| +// Lowest volume which is considered to be audible in the range [0, 100]. |
| +const int kAudibleOutputVolumeThreshold = 10; |
| + |
| +} // namespace |
| + |
| +namespace ash { |
| +namespace system { |
| + |
| +void TrayAudioDelegateWin::AdjustOutputVolumeToAudibleLevel() { |
| + if (GetOutputVolumeLevel() < kAudibleOutputVolumeThreshold) |
| + SetOutputVolumeLevel(kAudibleOutputVolumeThreshold); |
| +} |
| + |
| +int TrayAudioDelegateWin::GetOutputDefaultVolumeMuteLevel() { |
| + 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
|
| +} |
| + |
| +int TrayAudioDelegateWin::GetOutputVolumeLevel() { |
| + ScopedComPtr<ISimpleAudioVolume> volume_control = |
| + CreateDefaultVolumeControl(); |
| + |
| + float level = 0.0f; |
| + if (FAILED(volume_control->GetMasterVolume(&level))) |
| + return 0; |
| + |
| + return static_cast<int>(std::roundf(level * 100.0f)); |
| +} |
| + |
| +int TrayAudioDelegateWin::GetActiveOutputDeviceIconId() { |
| + return kNoAudioDeviceIcon; |
| +} |
| + |
|
tommi (sloooow) - chröme
2014/02/25 16:47:38
one empty line
|
| + |
| +bool TrayAudioDelegateWin::HasAlternativeSources() { |
| + return false; |
| +} |
| + |
| +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
|
| + ScopedComPtr<ISimpleAudioVolume> volume_control = |
| + CreateDefaultVolumeControl(); |
| + |
| + BOOL mute = FALSE; |
| + if (FAILED(volume_control->GetMute(&mute))) |
| + return false; |
| + |
| + return !!mute; |
| +} |
| + |
| +void TrayAudioDelegateWin::SetOutputAudioIsMuted(bool is_muted) { |
| + ScopedComPtr<ISimpleAudioVolume> volume_control = |
| + CreateDefaultVolumeControl(); |
| + |
| + volume_control->SetMute(is_muted, NULL); |
| +} |
| + |
| +void TrayAudioDelegateWin::SetOutputVolumeLevel(int level) { |
| + ScopedComPtr<ISimpleAudioVolume> volume_control = |
| + CreateDefaultVolumeControl(); |
| + |
| + float volume_level = static_cast<float>(level) / 100.0f; |
| + volume_control->SetMasterVolume(volume_level, NULL); |
| +} |
| + |
| +ScopedComPtr<ISimpleAudioVolume> |
| +TrayAudioDelegateWin::CreateDefaultVolumeControl() { |
| + ScopedComPtr<ISimpleAudioVolume> volume_control; |
| + ScopedComPtr<IAudioSessionManager> session_manager; |
|
henrika (OOO until Aug 14)
2014/02/25 07:56:21
Why are you using the SessionManager here? What is
|
| + |
| + ScopedComPtr<IMMDevice> device = |
| + media::CoreAudioUtil::CreateDefaultDevice(eRender, eConsole); |
| + if (FAILED(device->Activate(__uuidof(IAudioSessionManager), CLSCTX_ALL, NULL, |
| + session_manager.ReceiveVoid()))) { |
| + return volume_control; |
| + } |
| + |
| + session_manager->GetSimpleAudioVolume(NULL, FALSE, |
| + volume_control.Receive()); |
| + |
| + return volume_control; |
| +} |
| + |
| +} // namespace system |
| +} // namespace ash |