Format Pipewire driver

This commit is contained in:
derselbst 2021-12-11 17:00:30 +01:00
parent 3bc4e88903
commit 69113aad89

View file

@ -66,6 +66,7 @@ static void fluid_pipewire_event_process(void *data)
float *dest; float *dest;
pwb = pw_stream_dequeue_buffer(drv->pw_stream); pwb = pw_stream_dequeue_buffer(drv->pw_stream);
if(!pwb) if(!pwb)
{ {
FLUID_LOG(FLUID_WARN, "No buffers!"); FLUID_LOG(FLUID_WARN, "No buffers!");
@ -74,6 +75,7 @@ static void fluid_pipewire_event_process(void *data)
buf = pwb->buffer; buf = pwb->buffer;
dest = buf->datas[0].data; dest = buf->datas[0].data;
if(!dest) if(!dest)
{ {
return; return;
@ -98,6 +100,7 @@ static void fluid_pipewire_event_process2(void *data)
int i; int i;
pwb = pw_stream_dequeue_buffer(drv->pw_stream); pwb = pw_stream_dequeue_buffer(drv->pw_stream);
if(!pwb) if(!pwb)
{ {
FLUID_LOG(FLUID_WARN, "No buffers!"); FLUID_LOG(FLUID_WARN, "No buffers!");
@ -106,6 +109,7 @@ static void fluid_pipewire_event_process2(void *data)
buf = pwb->buffer; buf = pwb->buffer;
dest = buf->datas[0].data; dest = buf->datas[0].data;
if(!dest) if(!dest)
{ {
return; return;
@ -152,11 +156,13 @@ new_fluid_pipewire_audio_driver2(fluid_settings_t *settings, fluid_audio_func_t
const struct spa_pod *params[1]; const struct spa_pod *params[1];
drv = FLUID_NEW(fluid_pipewire_audio_driver_t); drv = FLUID_NEW(fluid_pipewire_audio_driver_t);
if(!drv) if(!drv)
{ {
FLUID_LOG(FLUID_ERR, "Out of memory"); FLUID_LOG(FLUID_ERR, "Out of memory");
return NULL; return NULL;
} }
FLUID_MEMSET(drv, 0, sizeof(*drv)); FLUID_MEMSET(drv, 0, sizeof(*drv));
fluid_settings_getint(settings, "audio.period-size", &period_size); fluid_settings_getint(settings, "audio.period-size", &period_size);
@ -171,16 +177,19 @@ new_fluid_pipewire_audio_driver2(fluid_settings_t *settings, fluid_audio_func_t
drv->buffer_period = period_size; drv->buffer_period = period_size;
drv->events = FLUID_NEW(struct pw_stream_events); drv->events = FLUID_NEW(struct pw_stream_events);
if(!drv->events) if(!drv->events)
{ {
FLUID_LOG(FLUID_ERR, "Out of memory"); FLUID_LOG(FLUID_ERR, "Out of memory");
goto driver_cleanup; goto driver_cleanup;
} }
FLUID_MEMSET(drv->events, 0, sizeof(*drv->events)); FLUID_MEMSET(drv->events, 0, sizeof(*drv->events));
drv->events->version = PW_VERSION_STREAM_EVENTS; drv->events->version = PW_VERSION_STREAM_EVENTS;
drv->events->process = func ? fluid_pipewire_event_process2 : fluid_pipewire_event_process; drv->events->process = func ? fluid_pipewire_event_process2 : fluid_pipewire_event_process;
drv->pw_loop = pw_thread_loop_new("fluid_pipewire", NULL); drv->pw_loop = pw_thread_loop_new("fluid_pipewire", NULL);
if(!drv->pw_loop) if(!drv->pw_loop)
{ {
FLUID_LOG(FLUID_ERR, "Failed to allocate PipeWire loop"); FLUID_LOG(FLUID_ERR, "Failed to allocate PipeWire loop");
@ -193,6 +202,7 @@ new_fluid_pipewire_audio_driver2(fluid_settings_t *settings, fluid_audio_func_t
pw_properties_new(PW_KEY_MEDIA_TYPE, media_type, PW_KEY_MEDIA_CATEGORY, media_category, PW_KEY_MEDIA_ROLE, media_role, NULL), pw_properties_new(PW_KEY_MEDIA_TYPE, media_type, PW_KEY_MEDIA_CATEGORY, media_category, PW_KEY_MEDIA_ROLE, media_role, NULL),
drv->events, drv->events,
drv); drv);
if(!drv->pw_stream) if(!drv->pw_stream)
{ {
FLUID_LOG(FLUID_ERR, "Failed to allocate PipeWire stream"); FLUID_LOG(FLUID_ERR, "Failed to allocate PipeWire stream");
@ -200,19 +210,23 @@ new_fluid_pipewire_audio_driver2(fluid_settings_t *settings, fluid_audio_func_t
} }
buffer = FLUID_ARRAY(float, NUM_CHANNELS * period_size); buffer = FLUID_ARRAY(float, NUM_CHANNELS * period_size);
if(!buffer) if(!buffer)
{ {
FLUID_LOG(FLUID_ERR, "Out of memory"); FLUID_LOG(FLUID_ERR, "Out of memory");
goto driver_cleanup; goto driver_cleanup;
} }
buffer_length = period_size * sizeof(float) * NUM_CHANNELS; buffer_length = period_size * sizeof(float) * NUM_CHANNELS;
drv->builder = FLUID_NEW(struct spa_pod_builder); drv->builder = FLUID_NEW(struct spa_pod_builder);
if(!drv->builder) if(!drv->builder)
{ {
FLUID_LOG(FLUID_ERR, "Out of memory"); FLUID_LOG(FLUID_ERR, "Out of memory");
goto driver_cleanup; goto driver_cleanup;
} }
FLUID_MEMSET(drv->builder, 0, sizeof(*drv->builder)); FLUID_MEMSET(drv->builder, 0, sizeof(*drv->builder));
drv->builder->data = buffer; drv->builder->data = buffer;
drv->builder->size = buffer_length; drv->builder->size = buffer_length;
@ -238,6 +252,7 @@ new_fluid_pipewire_audio_driver2(fluid_settings_t *settings, fluid_audio_func_t
pw_flags = PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS; pw_flags = PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS;
pw_flags |= realtime_prio ? PW_STREAM_FLAG_RT_PROCESS : 0; pw_flags |= realtime_prio ? PW_STREAM_FLAG_RT_PROCESS : 0;
res = pw_stream_connect(drv->pw_stream, PW_DIRECTION_OUTPUT, PW_ID_ANY, pw_flags, params, 1); res = pw_stream_connect(drv->pw_stream, PW_DIRECTION_OUTPUT, PW_ID_ANY, pw_flags, params, 1);
if(res < 0) if(res < 0)
{ {
FLUID_LOG(FLUID_ERR, "PipeWire stream connection failed"); FLUID_LOG(FLUID_ERR, "PipeWire stream connection failed");
@ -245,6 +260,7 @@ new_fluid_pipewire_audio_driver2(fluid_settings_t *settings, fluid_audio_func_t
} }
res = pw_thread_loop_start(drv->pw_loop); res = pw_thread_loop_start(drv->pw_loop);
if(res != 0) if(res != 0)
{ {
FLUID_LOG(FLUID_ERR, "Failed starting PipeWire loop"); FLUID_LOG(FLUID_ERR, "Failed starting PipeWire loop");
@ -290,6 +306,7 @@ void delete_fluid_pipewire_audio_driver(fluid_audio_driver_t *p)
{ {
FLUID_FREE(drv->builder->data); FLUID_FREE(drv->builder->data);
} }
FLUID_FREE(drv->builder); FLUID_FREE(drv->builder);
FLUID_FREE(drv->events); FLUID_FREE(drv->events);