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

Side by Side Diff: chrome/browser/chromeos/audio_mixer_pulse.h

Issue 5859003: Add ALSA support to volume keys (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/chromeos
Patch Set: using snd_mixer_selem_id_malloc Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_PULSE_AUDIO_MIXER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_PULSE_H_
6 #define CHROME_BROWSER_CHROMEOS_PULSE_AUDIO_MIXER_H_ 6 #define CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_PULSE_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/lock.h" 11 #include "base/lock.h"
12 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "chrome/browser/chromeos/audio_mixer.h"
14 15
15 struct pa_context; 16 struct pa_context;
16 struct pa_cvolume; 17 struct pa_cvolume;
17 struct pa_threaded_mainloop; 18 struct pa_threaded_mainloop;
18 struct pa_operation; 19 struct pa_operation;
19 struct pa_sink_info; 20 struct pa_sink_info;
20 21
21 namespace chromeos { 22 namespace chromeos {
22 23
23 class PulseAudioMixer { 24 class AudioMixerPulse : public AudioMixer {
24 public: 25 public:
25 enum State {
26 UNINITIALIZED = 0,
27 INITIALIZING,
28 READY,
29 SHUTTING_DOWN,
30 IN_ERROR
31 };
32 26
33 PulseAudioMixer(); 27 AudioMixerPulse();
34 ~PulseAudioMixer(); 28 virtual ~AudioMixerPulse();
35 29
36 // Non-blocking, connect to PulseAudio and find a default device, and call 30 // Implementation of AudioMixer, see AudioMixerBase for explanations.
scherkus (not reviewing) 2011/01/11 00:24:12 ditto on AudioMixerBase comment
37 // callback when complete with success code. 31 virtual bool Init(InitDoneCallback* callback);
38 typedef Callback1<bool>::Type InitDoneCallback; 32 virtual bool InitSync();
39 bool Init(InitDoneCallback* callback); 33 virtual double GetVolumeDb() const;
40 34 virtual bool GetVolumeLimits(double* vol_min, double* vol_max);
41 // Blocking init call guarantees PulseAudio is started before returning. 35 virtual void SetVolumeDb(double vol_db);
42 bool InitSync(); 36 virtual bool IsMute() const;
43 37 virtual void SetMute(bool mute);
44 // Blocking call. Returns a default of -inf on error. 38 virtual State CheckState() const;
45 double GetVolumeDb() const;
46
47 // Non-blocking, volume sent in as first param to callback. The callback is
48 // only called if the function returns true.
49 typedef Callback2<double, void*>::Type GetVolumeCallback;
50 bool GetVolumeDbAsync(GetVolumeCallback* callback, void* user);
51
52 // Non-blocking call.
53 void SetVolumeDb(double vol_db);
54
55 // Gets the mute state of the default device (true == mute). Blocking call.
56 // Returns a default of false on error.
57 bool IsMute() const;
58
59 // Non-Blocking call.
60 void SetMute(bool mute);
61
62 // Returns READY if we have a valid working connection to PulseAudio.
63 // This can return IN_ERROR if we lose the connection, even after an original
64 // successful init. Non-blocking call.
65 State CheckState() const;
66 39
67 private: 40 private:
68 struct AudioInfo; 41 struct AudioInfo;
69 42
70 // These are the tasks to be run in the background on the worker thread. 43 // The initialization task is run in the background on the worker thread.
71 void DoInit(InitDoneCallback* callback); 44 void DoInit(InitDoneCallback* callback);
72 void DoGetVolume(GetVolumeCallback* callback, void* user);
73 45
74 static void ConnectToPulseCallbackThunk(pa_context* c, void* userdata); 46 static void ConnectToPulseCallbackThunk(pa_context* c, void* userdata);
75 void OnConnectToPulseCallback(pa_context* c, bool* connect_done); 47 void OnConnectToPulseCallback(pa_context* c, bool* connect_done);
76 48
77 // Helper function to just get our messsage loop thread going. 49 // Helper function to just get our messsage loop thread going.
78 bool InitThread(); 50 bool InitThread();
79 51
80 // This goes through sequence of connecting to the default PulseAudio server. 52 // This goes through sequence of connecting to the default PulseAudio server.
81 // We will block until we either have a valid connection or something failed. 53 // We will block until we either have a valid connection or something failed.
82 // If a connection is lost for some reason, delete and recreate the object. 54 // If a connection is lost for some reason, delete and recreate the object.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 102
131 mutable Lock mixer_state_lock_; 103 mutable Lock mixer_state_lock_;
132 mutable State mixer_state_; 104 mutable State mixer_state_;
133 105
134 // Cached contexts for use in PulseAudio calls. 106 // Cached contexts for use in PulseAudio calls.
135 pa_context* pa_context_; 107 pa_context* pa_context_;
136 pa_threaded_mainloop* pa_mainloop_; 108 pa_threaded_mainloop* pa_mainloop_;
137 109
138 scoped_ptr<base::Thread> thread_; 110 scoped_ptr<base::Thread> thread_;
139 111
140 DISALLOW_COPY_AND_ASSIGN(PulseAudioMixer); 112 DISALLOW_COPY_AND_ASSIGN(AudioMixerPulse);
141 }; 113 };
142 114
143 } // namespace chromeos 115 } // namespace chromeos
144 116
145 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::PulseAudioMixer); 117 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::AudioMixerPulse);
146 118
147 #endif // CHROME_BROWSER_CHROMEOS_PULSE_AUDIO_MIXER_H_ 119 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_PULSE_H_
148 120
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698