diff options
author | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-28 23:27:00 +0000 |
---|---|---|
committer | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-28 23:27:00 +0000 |
commit | 4a897672921049e8e2d6422c688a502ba30f8cd1 (patch) | |
tree | 86c16e5ede06f751aae258cc61f57c9776bd20a0 /chrome/browser/chromeos/audio_handler.h | |
parent | 5bfe52255baf07910a03d48b686675741a15cb9b (diff) | |
download | chromium_src-4a897672921049e8e2d6422c688a502ba30f8cd1.zip chromium_src-4a897672921049e8e2d6422c688a502ba30f8cd1.tar.gz chromium_src-4a897672921049e8e2d6422c688a502ba30f8cd1.tar.bz2 |
chromeos: Simplify audio mixer code.
This cleans up the code that talks to ALSA. All changes are
now made asynchronously on a background thread. The volume
and muting states are now tracked separately, as well.
This makes it possible to make some requested changes to the
behavior of the volume keys. I'm hoping that there's also a
chance that it'll fix some related bugs that people have
been seeing, or at least make it easier to debug them.
BUG=chromium-os:17588,chromium-os:14058,chromium-os:13618,chromium-os:8473
TEST=manual: cleared audio prefs and made sure that reasonable defaults were used; pressed volume keys just after boot and checked that nothing happened; waited a few seconds more and started seeing volume bubble; checked that muting and going to min and max volume worked as expected
Review URL: http://codereview.chromium.org/7508006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94579 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/audio_handler.h')
-rw-r--r-- | chrome/browser/chromeos/audio_handler.h | 58 |
1 files changed, 14 insertions, 44 deletions
diff --git a/chrome/browser/chromeos/audio_handler.h b/chrome/browser/chromeos/audio_handler.h index a6b5c8b..0b286d5 100644 --- a/chrome/browser/chromeos/audio_handler.h +++ b/chrome/browser/chromeos/audio_handler.h @@ -21,54 +21,35 @@ class AudioHandler { public: static AudioHandler* GetInstance(); - // Get volume level in our internal 0-100% range, 0 being pure silence. - // Returns default of 0 on error. This function will block until the volume - // is retrieved or fails. Blocking call. + // Is the mixer initialized? + // TODO(derat): All of the volume-percent methods will produce "interesting" + // results before the mixer is initialized, since the driver's volume range + // isn't known at that point. This could be avoided if AudioMixer objects + // instead took percentages and did their own conversions to decibels. + bool IsInitialized(); + + // Gets volume level in our internal 0-100% range, 0 being pure silence. double GetVolumePercent(); - // Set volume level from 0-100%. Volumes above 100% are OK and boost volume, - // although clipping will occur more at higher volumes. Volume gets quieter - // as the percentage gets lower, and then switches to silence at 0%. + // Sets volume level from 0-100%. void SetVolumePercent(double volume_percent); - // Adjust volume up (positive percentage) or down (negative percentage), - // capping at 100%. GetVolumePercent() will be accurate after this - // blocking call. + // Adjusts volume up (positive percentage) or down (negative percentage). void AdjustVolumeByPercent(double adjust_by_percent); - // Just returns true if mute, false if not or an error occurred. - // Blocking call. - bool IsMute(); + // Is the volume currently muted? + bool IsMuted(); - // Mutes all audio. Non-blocking call. - void SetMute(bool do_mute); - - // Disconnects from mixer. Called during shutdown. - void Disconnect(); + // Mutes or unmutes all audio. + void SetMuted(bool do_mute); private: - enum MixerType { - MIXER_TYPE_ALSA = 0, - MIXER_TYPE_NONE, - }; - // Defines the delete on exit Singleton traits we like. Best to have this // and constructor/destructor private as recommended for Singletons. friend struct DefaultSingletonTraits<AudioHandler>; - friend class ::InProcessBrowserTest; - // Disable audio in browser tests. This is a workaround for the bug - // crosbug.com/17058. Remove this once it's fixed. - static void Disable(); - - // Connect to the current mixer_type_. - bool TryToConnect(bool async); - - void OnMixerInitialized(bool success); - AudioHandler(); virtual ~AudioHandler(); - bool VerifyMixerConnection(); // Conversion between our internal scaling (0-100%) and decibels. double VolumeDbToPercent(double volume_db) const; @@ -76,17 +57,6 @@ class AudioHandler { scoped_ptr<AudioMixer> mixer_; - bool connected_; - int reconnect_tries_; - - // The min and max volume in decibels, limited to the maximum range of the - // audio system being used. - double max_volume_db_; - double min_volume_db_; - - // Which mixer is being used, ALSA or none. - MixerType mixer_type_; - DISALLOW_COPY_AND_ASSIGN(AudioHandler); }; |