mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2024-12-03 09:32:02 +00:00
Format Pipewire driver
This commit is contained in:
parent
3bc4e88903
commit
69113aad89
1 changed files with 43 additions and 26 deletions
|
@ -66,6 +66,7 @@ static void fluid_pipewire_event_process(void *data)
|
|||
float *dest;
|
||||
|
||||
pwb = pw_stream_dequeue_buffer(drv->pw_stream);
|
||||
|
||||
if(!pwb)
|
||||
{
|
||||
FLUID_LOG(FLUID_WARN, "No buffers!");
|
||||
|
@ -74,6 +75,7 @@ static void fluid_pipewire_event_process(void *data)
|
|||
|
||||
buf = pwb->buffer;
|
||||
dest = buf->datas[0].data;
|
||||
|
||||
if(!dest)
|
||||
{
|
||||
return;
|
||||
|
@ -98,6 +100,7 @@ static void fluid_pipewire_event_process2(void *data)
|
|||
int i;
|
||||
|
||||
pwb = pw_stream_dequeue_buffer(drv->pw_stream);
|
||||
|
||||
if(!pwb)
|
||||
{
|
||||
FLUID_LOG(FLUID_WARN, "No buffers!");
|
||||
|
@ -106,6 +109,7 @@ static void fluid_pipewire_event_process2(void *data)
|
|||
|
||||
buf = pwb->buffer;
|
||||
dest = buf->datas[0].data;
|
||||
|
||||
if(!dest)
|
||||
{
|
||||
return;
|
||||
|
@ -152,11 +156,13 @@ new_fluid_pipewire_audio_driver2(fluid_settings_t *settings, fluid_audio_func_t
|
|||
const struct spa_pod *params[1];
|
||||
|
||||
drv = FLUID_NEW(fluid_pipewire_audio_driver_t);
|
||||
|
||||
if(!drv)
|
||||
{
|
||||
FLUID_LOG(FLUID_ERR, "Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FLUID_MEMSET(drv, 0, sizeof(*drv));
|
||||
|
||||
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->events = FLUID_NEW(struct pw_stream_events);
|
||||
|
||||
if(!drv->events)
|
||||
{
|
||||
FLUID_LOG(FLUID_ERR, "Out of memory");
|
||||
goto driver_cleanup;
|
||||
}
|
||||
|
||||
FLUID_MEMSET(drv->events, 0, sizeof(*drv->events));
|
||||
drv->events->version = PW_VERSION_STREAM_EVENTS;
|
||||
drv->events->process = func ? fluid_pipewire_event_process2 : fluid_pipewire_event_process;
|
||||
|
||||
drv->pw_loop = pw_thread_loop_new("fluid_pipewire", NULL);
|
||||
|
||||
if(!drv->pw_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),
|
||||
drv->events,
|
||||
drv);
|
||||
|
||||
if(!drv->pw_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);
|
||||
|
||||
if(!buffer)
|
||||
{
|
||||
FLUID_LOG(FLUID_ERR, "Out of memory");
|
||||
goto driver_cleanup;
|
||||
}
|
||||
|
||||
buffer_length = period_size * sizeof(float) * NUM_CHANNELS;
|
||||
|
||||
drv->builder = FLUID_NEW(struct spa_pod_builder);
|
||||
|
||||
if(!drv->builder)
|
||||
{
|
||||
FLUID_LOG(FLUID_ERR, "Out of memory");
|
||||
goto driver_cleanup;
|
||||
}
|
||||
|
||||
FLUID_MEMSET(drv->builder, 0, sizeof(*drv->builder));
|
||||
drv->builder->data = buffer;
|
||||
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 |= 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);
|
||||
|
||||
if(res < 0)
|
||||
{
|
||||
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);
|
||||
|
||||
if(res != 0)
|
||||
{
|
||||
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);
|
||||
|
||||
FLUID_FREE(drv->events);
|
||||
|
|
Loading…
Reference in a new issue