Pulseaudio: rewrite the pa backend with the async api

The default async api allow us to set some latency options. The old one (simple API) was the lazy way to go for usual audio where latency doesn't matter.

This also streams audio, so it should be a bit faster then the old one.
This commit is contained in:
degasus
2014-01-31 22:00:33 +01:00
parent 2356e2950f
commit 5c646d334a
3 changed files with 130 additions and 44 deletions

View File

@ -6,8 +6,7 @@
#define _PULSE_AUDIO_STREAM_H
#if defined(HAVE_PULSEAUDIO) && HAVE_PULSEAUDIO
#include <pulse/simple.h>
#include <pulse/error.h>
#include <pulse/pulseaudio.h>
#endif
#include "Common.h"
@ -15,8 +14,6 @@
#include "Thread.h"
#include <vector>
class PulseAudio : public SoundStream
{
#if defined(HAVE_PULSEAUDIO) && HAVE_PULSEAUDIO
@ -32,18 +29,31 @@ public:
virtual void Update();
void StateCallback(pa_context *c);
void WriteCallback(pa_stream *s, size_t length);
void UnderflowCallback(pa_stream *s);
private:
virtual void SoundLoop();
bool PulseInit();
void PulseShutdown();
void Write(const void *data, size_t bytes);
std::vector<s16> mix_buffer;
std::thread thread;
volatile bool run_thread;
// wrapper callback functions, last parameter _must_ be PulseAudio*
static void StateCallback(pa_context *c, void *userdata);
static void WriteCallback(pa_stream *s, size_t length, void *userdata);
static void UnderflowCallback(pa_stream *s, void *userdata);
pa_simple* pa;
std::thread m_thread;
bool m_run_thread;
int m_pa_error;
int m_pa_connected;
pa_mainloop *m_pa_ml;
pa_mainloop_api *m_pa_mlapi;
pa_context *m_pa_ctx;
pa_stream *m_pa_s;
pa_buffer_attr m_pa_ba;
#else
public:
PulseAudio(CMixer *mixer) : SoundStream(mixer) {}