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

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: cleanups Created 10 years 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/thread.h" 13 #include "base/thread.h"
14 14
scherkus (not reviewing) 2010/12/22 22:31:58 nit: no blank line
15 #include "chrome/browser/chromeos/audio_mixer_base.h"
16
15 struct pa_context; 17 struct pa_context;
16 struct pa_cvolume; 18 struct pa_cvolume;
17 struct pa_threaded_mainloop; 19 struct pa_threaded_mainloop;
18 struct pa_operation; 20 struct pa_operation;
19 struct pa_sink_info; 21 struct pa_sink_info;
20 22
21 namespace chromeos { 23 namespace chromeos {
22 24
23 class PulseAudioMixer { 25 class AudioMixerPulse : public AudioMixerBase {
24 public: 26 public:
25 enum State {
26 UNINITIALIZED = 0,
27 INITIALIZING,
28 READY,
29 SHUTTING_DOWN,
30 IN_ERROR
31 };
32 27
33 PulseAudioMixer(); 28 AudioMixerPulse();
34 ~PulseAudioMixer(); 29 ~AudioMixerPulse();
scherkus (not reviewing) 2010/12/22 22:31:58 add virtual
35 30
36 // Non-blocking, connect to PulseAudio and find a default device, and call 31 // Implementation of AudioMixer, see AudioMixerBase for explanations.
37 // callback when complete with success code. 32 virtual bool Init(InitDoneCallback* callback);
38 typedef Callback1<bool>::Type InitDoneCallback; 33 virtual bool InitSync();
39 bool Init(InitDoneCallback* callback); 34 virtual double GetVolumeDb() const;
40 35 virtual void GetVolumeLimits(double* vol_min, double* vol_max);
41 // Blocking init call guarantees PulseAudio is started before returning. 36 virtual void SetVolumeDb(double vol_db);
42 bool InitSync(); 37 virtual bool IsMute() const;
43 38 virtual void SetMute(bool mute);
44 // Blocking call. Returns a default of -inf on error. 39 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 40
67 private: 41 private:
68 struct AudioInfo; 42 struct AudioInfo;
69 43
70 // These are the tasks to be run in the background on the worker thread. 44 // The initialization task is run in the background on the worker thread.
71 void DoInit(InitDoneCallback* callback); 45 void DoInit(InitDoneCallback* callback);
72 void DoGetVolume(GetVolumeCallback* callback, void* user);
73 46
74 static void ConnectToPulseCallbackThunk(pa_context* c, void* userdata); 47 static void ConnectToPulseCallbackThunk(pa_context* c, void* userdata);
75 void OnConnectToPulseCallback(pa_context* c, bool* connect_done); 48 void OnConnectToPulseCallback(pa_context* c, bool* connect_done);
76 49
77 // Helper function to just get our messsage loop thread going. 50 // Helper function to just get our messsage loop thread going.
78 bool InitThread(); 51 bool InitThread();
79 52
80 // This goes through sequence of connecting to the default PulseAudio server. 53 // 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. 54 // 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. 55 // 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 103
131 mutable Lock mixer_state_lock_; 104 mutable Lock mixer_state_lock_;
132 mutable State mixer_state_; 105 mutable State mixer_state_;
133 106
134 // Cached contexts for use in PulseAudio calls. 107 // Cached contexts for use in PulseAudio calls.
135 pa_context* pa_context_; 108 pa_context* pa_context_;
136 pa_threaded_mainloop* pa_mainloop_; 109 pa_threaded_mainloop* pa_mainloop_;
137 110
138 scoped_ptr<base::Thread> thread_; 111 scoped_ptr<base::Thread> thread_;
139 112
140 DISALLOW_COPY_AND_ASSIGN(PulseAudioMixer); 113 DISALLOW_COPY_AND_ASSIGN(AudioMixerPulse);
141 }; 114 };
142 115
143 } // namespace chromeos 116 } // namespace chromeos
144 117
145 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::PulseAudioMixer); 118 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::AudioMixerPulse);
146 119
147 #endif // CHROME_BROWSER_CHROMEOS_PULSE_AUDIO_MIXER_H_ 120 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_PULSE_H_
148 121
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698