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.
15 #ifndef __AUDIO_ALSA_H__
16 #define __AUDIO_ALSA_H__
20 #include <asoundlib.h>
27 class AlsaSource
: public AudioSource
{
30 snd_pcm_uframes_t period_size
;
31 snd_pcm_uframes_t buffer_size
;
41 bool PreparePcm (snd_pcm_sframes_t
*avail
);
44 // Handles EPIPE and ESTRPIPE, prints an error if recovery failed
45 // or if err isn't any of the above values.
46 bool XrunRecovery (int err
);
53 bool InitializeAlsa ();
57 virtual ~AlsaSource ();
59 virtual void Played ();
60 virtual void Paused ();
61 virtual void Stopped ();
62 virtual void StateChanged (AudioState old_state
);
63 virtual guint64
GetDelayInternal ();
65 virtual bool InitializeInternal ();
66 virtual void CloseInternal ();
72 AlsaSource (AlsaPlayer
*player
, MediaPlayer
*mplayer
, AudioStream
*stream
);
74 // Pushes data onto the pcm device if the
75 // device can accept more data, and if the
76 // there is data availabe. The node has to
77 // be locked during playback.
78 // Returns false if nothing has been played.
81 bool IsDropPending () { return drop_pending
; }
85 class AlsaPlayer
: public AudioPlayer
{
87 pthread_t
*audio_thread
;
88 bool shutdown
; // set to true to exit the audio thread.
90 // A list of all the file descriptors in all the
91 // audio nodes. We need to poll on changes in any of the
92 // descriptors, so we create a big list with all of them
97 // We also need to be able to wake up from the poll
98 // whenever we want to, so we create a pipe which we
99 // poll on. This is always the first file descriptor
103 // If UpdatePollList must be called before polling.
104 bool update_poll_pending
;
106 // The audio loop which is executed
107 // on the audio thread.
109 static void *Loop (void *data
);
111 void WakeUp (); // Wakes up the audio thread.
114 virtual ~AlsaPlayer ();
116 virtual void AddInternal (AudioSource
*node
);
117 virtual void RemoveInternal (AudioSource
*node
);
118 virtual void PrepareShutdownInternal ();
119 virtual void FinishShutdownInternal ();
120 virtual bool Initialize ();
121 virtual AudioSource
*CreateNode (MediaPlayer
*mplayer
, AudioStream
*stream
);
126 void UpdatePollList ();
128 static bool IsInstalled ();
131 #endif /* __AUDI_ALSA_H__ */
133 #endif /* INCLUDE_ALSA */