diff options
author | rkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-01 17:06:31 +0000 |
---|---|---|
committer | rkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-01 17:06:31 +0000 |
commit | 354ff2d5a0875981d47e30b049c98c9880df328a (patch) | |
tree | 2024bbe292104fe660bc4ca830f24ff6177e4f8b /chromeos/audio | |
parent | f8672099deb12fe55724dc6fabf6ded264dec3e7 (diff) | |
download | chromium_src-354ff2d5a0875981d47e30b049c98c9880df328a.zip chromium_src-354ff2d5a0875981d47e30b049c98c9880df328a.tar.gz chromium_src-354ff2d5a0875981d47e30b049c98c9880df328a.tar.bz2 |
cros: Enable new cras audio handler by default
Add separate flag for audio device switcher menu, off by default.
Picking this up from https://codereview.chromium.org/14455012/; only fixed tests.
R=jamescook@chromium.org
TBR=stevenjb@chromium.org,jennyz@chromium.org
BUG=160311
TEST=Audio input/output/mute still works
Review URL: https://chromiumcodereview.appspot.com/14678004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197644 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/audio')
-rw-r--r-- | chromeos/audio/cras_audio_handler.cc | 31 | ||||
-rw-r--r-- | chromeos/audio/cras_audio_handler.h | 40 | ||||
-rw-r--r-- | chromeos/audio/mock_cras_audio_handler.cc | 76 | ||||
-rw-r--r-- | chromeos/audio/mock_cras_audio_handler.h | 42 |
4 files changed, 169 insertions, 20 deletions
diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc index b374402..fc0a2eb 100644 --- a/chromeos/audio/cras_audio_handler.cc +++ b/chromeos/audio/cras_audio_handler.cc @@ -11,6 +11,7 @@ #include "base/bind_helpers.h" #include "base/logging.h" #include "chromeos/audio/audio_pref_handler.h" +#include "chromeos/audio/mock_cras_audio_handler.h" #include "chromeos/dbus/dbus_thread_manager.h" using std::max; @@ -63,6 +64,12 @@ void CrasAudioHandler::Initialize( } // static +void CrasAudioHandler::InitializeForTesting() { + CHECK(!g_cras_audio_handler); + g_cras_audio_handler = new MockCrasAudioHandler(); +} + +// static void CrasAudioHandler::Shutdown() { CHECK(g_cras_audio_handler); delete g_cras_audio_handler; @@ -125,6 +132,14 @@ bool CrasAudioHandler::GetActiveOutputDevice(AudioDevice* device) const { return false; } +bool CrasAudioHandler::has_alternative_input() const { + return has_alternative_input_; +} + +bool CrasAudioHandler::has_alternative_output() const { + return has_alternative_output_; +} + void CrasAudioHandler::SetOutputVolumePercent(int volume_percent) { volume_percent = min(max(volume_percent, 0), 100); if (volume_percent <= kMuteThresholdPercent) @@ -191,16 +206,28 @@ CrasAudioHandler::CrasAudioHandler( has_alternative_output_(false), output_mute_locked_(false), input_mute_locked_(false) { + if (!audio_pref_handler) + return; + // If the DBusThreadManager or the CrasAudioClient aren't available, there + // isn't much we can do. This should only happen when running tests. + if (!chromeos::DBusThreadManager::IsInitialized() || + !chromeos::DBusThreadManager::Get() || + !chromeos::DBusThreadManager::Get()->GetCrasAudioClient()) + return; chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->AddObserver(this); - DCHECK(audio_pref_handler_.get()); audio_pref_handler_->AddAudioPrefObserver(this); SetupInitialAudioState(); } CrasAudioHandler::~CrasAudioHandler() { + if (!chromeos::DBusThreadManager::IsInitialized() || + !chromeos::DBusThreadManager::Get() || + !chromeos::DBusThreadManager::Get()->GetCrasAudioClient()) + return; chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> RemoveObserver(this); - audio_pref_handler_->RemoveAudioPrefObserver(this); + if (audio_pref_handler_) + audio_pref_handler_->RemoveAudioPrefObserver(this); audio_pref_handler_ = NULL; } diff --git a/chromeos/audio/cras_audio_handler.h b/chromeos/audio/cras_audio_handler.h index 61b11f5d..808d0e6 100644 --- a/chromeos/audio/cras_audio_handler.h +++ b/chromeos/audio/cras_audio_handler.h @@ -54,6 +54,9 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, // Sets the global instance. Must be called before any calls to Get(). static void Initialize(scoped_refptr<AudioPrefHandler> audio_pref_handler); + // Sets the global instance for testing. + static void InitializeForTesting(); + // Destroys the global instance. static void Shutdown(); @@ -64,59 +67,60 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, static CrasAudioHandler* Get(); // Adds an audio observer. - void AddAudioObserver(AudioObserver* observer); + virtual void AddAudioObserver(AudioObserver* observer); // Removes an audio observer. - void RemoveAudioObserver(AudioObserver* observer); + virtual void RemoveAudioObserver(AudioObserver* observer); // Returns true if audio output is muted. - bool IsOutputMuted(); + virtual bool IsOutputMuted(); // Returns true if audio input is muted. - bool IsInputMuted(); + virtual bool IsInputMuted(); // Gets volume level in 0-100% range, 0 being pure silence. - int GetOutputVolumePercent(); + virtual int GetOutputVolumePercent(); // Returns node_id of the active output node. - uint64 GetActiveOutputNode() const; + virtual uint64 GetActiveOutputNode() const; // Returns the node_id of the active input node. - uint64 GetActiveInputNode() const; + virtual uint64 GetActiveInputNode() const; // Gets the audio devices back in |device_list|. - void GetAudioDevices(AudioDeviceList* device_list) const; + virtual void GetAudioDevices(AudioDeviceList* device_list) const; - bool GetActiveOutputDevice(AudioDevice* device) const; + virtual bool GetActiveOutputDevice(AudioDevice* device) const; // Whether there is alternative input/output audio device. - bool has_alternative_input() const { return has_alternative_input_; } - bool has_alternative_output() const { return has_alternative_output_; } + virtual bool has_alternative_input() const; + virtual bool has_alternative_output() const; // Sets volume level from 0-100%. If less than kMuteThresholdPercent, then // mutes the sound. If it was muted, and |volume_percent| is larger than // the threshold, then the sound is unmuted. - void SetOutputVolumePercent(int volume_percent); + virtual void SetOutputVolumePercent(int volume_percent); // Adjusts volume up (positive percentage) or down (negative percentage). - void AdjustOutputVolumeByPercent(int adjust_by_percent); + virtual void AdjustOutputVolumeByPercent(int adjust_by_percent); // Mutes or unmutes audio output device. - void SetOutputMute(bool mute_on); + virtual void SetOutputMute(bool mute_on); // Mutes or unmutes audio input device. - void SetInputMute(bool mute_on); + virtual void SetInputMute(bool mute_on); // Sets the active audio output node to the node with |node_id|. - void SetActiveOutputNode(uint64 node_id); + virtual void SetActiveOutputNode(uint64 node_id); // Sets the active audio input node to the node with |node_id|. - void SetActiveInputNode(uint64 node_id); + virtual void SetActiveInputNode(uint64 node_id); - private: + protected: explicit CrasAudioHandler(scoped_refptr<AudioPrefHandler> audio_pref_handler); virtual ~CrasAudioHandler(); + private: // Overriden from CrasAudioHandler::Observer. virtual void AudioClientRestarted() OVERRIDE; virtual void OutputVolumeChanged(int volume) OVERRIDE; diff --git a/chromeos/audio/mock_cras_audio_handler.cc b/chromeos/audio/mock_cras_audio_handler.cc new file mode 100644 index 0000000..84cd207 --- /dev/null +++ b/chromeos/audio/mock_cras_audio_handler.cc @@ -0,0 +1,76 @@ +// Copyright 2013 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 "chromeos/audio/mock_cras_audio_handler.h" + +#include "chromeos/audio/audio_pref_handler.h" + +namespace chromeos { + +void MockCrasAudioHandler::AddAudioObserver(AudioObserver* observer) { +} + +void MockCrasAudioHandler::RemoveAudioObserver(AudioObserver* observer) { +} + +bool MockCrasAudioHandler::IsOutputMuted() { + return false; +} + +bool MockCrasAudioHandler::IsInputMuted() { + return false; +} + +int MockCrasAudioHandler::GetOutputVolumePercent() { + return 0; +} + +uint64 MockCrasAudioHandler::GetActiveOutputNode() const { + return 0; +} + +uint64 MockCrasAudioHandler::GetActiveInputNode() const { + return 0; +} + +void MockCrasAudioHandler::GetAudioDevices(AudioDeviceList* device_list) const { +} + +bool MockCrasAudioHandler::GetActiveOutputDevice(AudioDevice* device) const { + return false; +} + +bool MockCrasAudioHandler::has_alternative_input() const { + return false; +} + +bool MockCrasAudioHandler::has_alternative_output() const { + return false; +} + +void MockCrasAudioHandler::SetOutputVolumePercent(int volume_percent) { +} + +void MockCrasAudioHandler::AdjustOutputVolumeByPercent(int adjust_by_percent) { +} + +void MockCrasAudioHandler::SetOutputMute(bool mute_on) { +} + +void MockCrasAudioHandler::SetInputMute(bool mute_on) { +} + +void MockCrasAudioHandler::SetActiveOutputNode(uint64 node_id) { +} + +void MockCrasAudioHandler::SetActiveInputNode(uint64 node_id) { +} + +MockCrasAudioHandler::MockCrasAudioHandler() : CrasAudioHandler(NULL) { +} + +MockCrasAudioHandler::~MockCrasAudioHandler() { +} + +} // namespace chromeos diff --git a/chromeos/audio/mock_cras_audio_handler.h b/chromeos/audio/mock_cras_audio_handler.h new file mode 100644 index 0000000..c665f0b --- /dev/null +++ b/chromeos/audio/mock_cras_audio_handler.h @@ -0,0 +1,42 @@ +// Copyright 2013 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. + +#ifndef CHROMEOS_AUDIO_MOCK_CRAS_AUDIO_HANDLER_H_ +#define CHROMEOS_AUDIO_MOCK_CRAS_AUDIO_HANDLER_H_ + +#include "chromeos/audio/cras_audio_handler.h" + +namespace chromeos { + +// Mock class for CrasAudioHandler. +class CHROMEOS_EXPORT MockCrasAudioHandler : public CrasAudioHandler { + public: + MockCrasAudioHandler(); + virtual ~MockCrasAudioHandler(); + + virtual void AddAudioObserver(AudioObserver* observer) OVERRIDE; + virtual void RemoveAudioObserver(AudioObserver* observer) OVERRIDE; + virtual bool IsOutputMuted() OVERRIDE; + virtual bool IsInputMuted() OVERRIDE; + virtual int GetOutputVolumePercent() OVERRIDE; + virtual uint64 GetActiveOutputNode() const OVERRIDE; + virtual uint64 GetActiveInputNode() const OVERRIDE; + virtual void GetAudioDevices(AudioDeviceList* device_list) const OVERRIDE; + virtual bool GetActiveOutputDevice(AudioDevice* device) const OVERRIDE; + virtual bool has_alternative_input() const OVERRIDE; + virtual bool has_alternative_output() const OVERRIDE; + virtual void SetOutputVolumePercent(int volume_percent) OVERRIDE; + virtual void AdjustOutputVolumeByPercent(int adjust_by_percent) OVERRIDE; + virtual void SetOutputMute(bool mute_on) OVERRIDE; + virtual void SetInputMute(bool mute_on) OVERRIDE; + virtual void SetActiveOutputNode(uint64 node_id) OVERRIDE; + virtual void SetActiveInputNode(uint64 node_id) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(MockCrasAudioHandler); +}; + +} // namespace chromeos + +#endif // CHROMEOS_AUDIO_MOCK_CRAS_AUDIO_HANDLER_H_ |