in plugin/:
[moon.git] / src / audio-pulse.h
blob28fee93cab9d9126c2e1325a1da5cf3d02e20ab6
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * audio-pulse.h:
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2008 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
13 #if INCLUDE_PULSEAUDIO
15 #ifndef __AUDIO_PULSE_H__
16 #define __AUDIO_PULSE_H__
18 #include <pulse/pulseaudio.h>
20 #include "audio.h"
22 class PulsePlayer;
24 class PulseSource: public AudioSource {
25 PulsePlayer *player;
26 pa_stream *pulse_stream;
27 bool triggered;
28 bool is_ready;
29 bool initialized;
30 bool play_pending;
32 void PACork (bool cork);
33 void PATrigger ();
34 void PAFlush ();
35 void OnUnderflow ();
36 void OnStateChanged (pa_stream *stream);
37 void OnWrite (size_t length);
39 static void OnUnderflow (pa_stream *pulse_stream, void *userdata);
40 static void OnWrite (pa_stream *pulse_stream, size_t length, void *userdata);
41 static void OnStateChanged (pa_stream *pulse_stream, void *userdata);
43 bool InitializePA ();
44 void ClosePA ();
45 void WriteAvailable ();
47 pa_stream_state_t GetPAState (pa_stream *pulse_stream = NULL);
49 protected:
50 virtual ~PulseSource ();
52 virtual void Played ();
53 virtual void Paused ();
54 virtual void Stopped ();
55 virtual void StateChanged (AudioState old_state);
56 virtual guint64 GetDelayInternal ();
57 virtual bool InitializeInternal ();
58 virtual void CloseInternal ();
60 public:
61 PulseSource (PulsePlayer *player, MediaPlayer *mplayer, AudioStream *stream);
64 class PulsePlayer : public AudioPlayer {
65 private:
66 enum ConnectedState {
67 ConnectionUnknown,
68 ConnectionFailed,
69 ConnectionSuccess
71 private:
72 pa_context *context;
73 pa_threaded_mainloop *loop;
74 pa_mainloop_api *api;
75 pthread_cond_t cond;
76 pthread_mutex_t mutex;
78 ConnectedState connected; // 0 = don't know, 1 = failed to connect, 2 = connected
80 static void OnContextStateChanged (pa_context *context, void *userdata);
81 void OnContextStateChanged ();
83 protected:
84 virtual void AddInternal (AudioSource *node);
85 virtual void RemoveInternal (AudioSource *node);
86 virtual void PrepareShutdownInternal ();
87 virtual void FinishShutdownInternal ();
88 virtual bool Initialize ();
89 virtual AudioSource *CreateNode (MediaPlayer *mplayer, AudioStream *stream);
91 public:
92 PulsePlayer ();
93 virtual ~PulsePlayer ();
95 pa_context *GetPAContext () { return context; }
96 pa_threaded_mainloop *GetPALoop () { return loop; }
97 pa_mainloop_api *GetPAApi () { return api; }
98 pa_context_state_t GetPAState ();
100 void LockLoop ();
101 void UnlockLoop ();
102 void WaitLoop ();
103 void WaitForOperation (pa_operation *op);
104 void SignalLoop ();
106 static bool IsInstalled ();
109 #endif /* __AUDIO_PULSE_H__ */
111 #endif /* INCLUDE_PULSE */