1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
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>
24 class PulseSource
: public AudioSource
{
26 pa_stream
*pulse_stream
;
32 void PACork (bool cork
);
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
);
45 void WriteAvailable ();
47 pa_stream_state_t
GetPAState (pa_stream
*pulse_stream
= NULL
);
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 ();
61 PulseSource (PulsePlayer
*player
, MediaPlayer
*mplayer
, AudioStream
*stream
);
64 class PulsePlayer
: public AudioPlayer
{
73 pa_threaded_mainloop
*loop
;
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 ();
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
);
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 ();
103 void WaitForOperation (pa_operation
*op
);
106 static bool IsInstalled ();
109 #endif /* __AUDIO_PULSE_H__ */
111 #endif /* INCLUDE_PULSE */