#include "stdafx.h"
-#ifdef USEPULSEAUDIO
-
#define _IN_OSS
#include "externals.h"
// SETUP SOUND
////////////////////////////////////////////////////////////////////////
-void SetupSound (void)
+static void pulse_init(void)
{
int error_number;
if (device.mainloop == NULL)
{
fprintf (stderr, "Could not acquire PulseAudio main loop\n");
- return;
+ return -1;
}
// Acquire context ////////////////////////////////////////////////////////
if (device.context == NULL)
{
fprintf (stderr, "Could not acquire PulseAudio device context\n");
- return;
+ return -1;
}
// Connect to PulseAudio server ///////////////////////////////////////////
{
error_number = pa_context_errno (device.context);
fprintf (stderr, "Could not connect to PulseAudio server: %s\n", pa_strerror(error_number));
- return;
+ return -1;
}
// Run mainloop until sever context is ready //////////////////////////////
if (pa_threaded_mainloop_start (device.mainloop) < 0)
{
fprintf (stderr, "Could not start mainloop\n");
- return;
+ return -1;
}
pa_context_state_t context_state;
{
error_number = pa_context_errno (device.context);
fprintf (stderr, "Context state is not good: %s\n", pa_strerror (error_number));
- return;
+ return -1;
}
else if (context_state == PA_CONTEXT_READY)
break;
// Set sample spec ////////////////////////////////////////////////////////
device.spec.format = PA_SAMPLE_S16NE;
- if (iDisStereo)
- device.spec.channels = 1;
- else
- device.spec.channels = 2;
+ device.spec.channels = 2;
device.spec.rate = settings.frequency;
pa_buffer_attr buffer_attributes;
{
error_number = pa_context_errno (device.context);
fprintf (stderr, "Could not acquire new PulseAudio stream: %s\n", pa_strerror (error_number));
- return;
+ return -1;
}
// Set callbacks for server events ////////////////////////////////////////
{
pa_context_errno (device.context);
fprintf (stderr, "Could not connect for playback: %s\n", pa_strerror (error_number));
- return;
+ return -1;
}
// Run mainloop until stream is ready /////////////////////////////////////
{
error_number = pa_context_errno (device.context);
fprintf (stderr, "Stream state is not good: %s\n", pa_strerror (error_number));
- return;
+ return -1;
}
else
fprintf (stderr, "PulseAudio stream state is %d\n", stream_state);
pa_threaded_mainloop_unlock (device.mainloop);
fprintf (stderr, "PulseAudio should be connected\n");
- return;
+ return 0;
}
////////////////////////////////////////////////////////////////////////
// REMOVE SOUND
////////////////////////////////////////////////////////////////////////
-void RemoveSound (void)
+static void pulse_finish(void)
{
if (device.mainloop != NULL)
pa_threaded_mainloop_stop (device.mainloop);
// GET BYTES BUFFERED
////////////////////////////////////////////////////////////////////////
-unsigned long SoundGetBytesBuffered (void)
+static int pulse_busy(void)
{
int free_space;
int error_code;
int playing = 0;
if ((device.mainloop == NULL) || (device.api == NULL) || ( device.context == NULL) || (device.stream == NULL))
- return SOUNDSIZE;
+ return 1;
pa_threaded_mainloop_lock (device.mainloop);
free_space = pa_stream_writable_size (device.stream);
{
// Don't buffer anymore, just play
//fprintf (stderr, "Not buffering.\n");
- return SOUNDSIZE;
+ return 1;
}
else
{
// FEED SOUND DATA
////////////////////////////////////////////////////////////////////////
-void SoundFeedStreamData (unsigned char *pSound, long lBytes)
+static void pulse_feed(void *pSound, int lBytes)
{
int error_code;
int size;
}
}
}
-#endif
+
+void out_register_pulse(struct out_driver *drv)
+{
+ drv->name = "pulseaudio";
+ drv->init = pulse_init;
+ drv->finish = pulse_finish;
+ drv->busy = pulse_busy;
+ drv->feed = pulse_feed;
+}