modules: forward tag param

This commit is contained in:
Wim Taymans 2023-09-07 15:54:28 +02:00
parent ebeae802ad
commit 0da572474f
2 changed files with 39 additions and 9 deletions

View file

@ -20,6 +20,7 @@
#include <spa/utils/json.h> #include <spa/utils/json.h>
#include <spa/support/cpu.h> #include <spa/support/cpu.h>
#include <spa/param/latency-utils.h> #include <spa/param/latency-utils.h>
#include <spa/param/tag-utils.h>
#include <spa/pod/dynamic.h> #include <spa/pod/dynamic.h>
#include <spa/debug/types.h> #include <spa/debug/types.h>
@ -1109,7 +1110,7 @@ static void param_latency_changed(struct impl *impl, const struct spa_pod *param
struct spa_pod_builder b; struct spa_pod_builder b;
const struct spa_pod *params[1]; const struct spa_pod *params[1];
if (spa_latency_parse(param, &latency) < 0) if (param == NULL || spa_latency_parse(param, &latency) < 0)
return; return;
spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -1121,6 +1122,21 @@ static void param_latency_changed(struct impl *impl, const struct spa_pod *param
pw_stream_update_params(impl->playback, params, 1); pw_stream_update_params(impl->playback, params, 1);
} }
static void param_tag_changed(struct impl *impl, const struct spa_pod *param)
{
struct spa_tag_info tag;
const struct spa_pod *params[1] = { param };
void *state = NULL;
if (param == 0 || spa_tag_parse(param, &tag, &state) < 0)
return;
if (tag.direction == SPA_DIRECTION_INPUT)
pw_stream_update_params(impl->capture, params, 1);
else
pw_stream_update_params(impl->playback, params, 1);
}
static void state_changed(void *data, enum pw_stream_state old, static void state_changed(void *data, enum pw_stream_state old,
enum pw_stream_state state, const char *error) enum pw_stream_state state, const char *error)
{ {
@ -1208,6 +1224,9 @@ static void param_changed(void *data, uint32_t id, const struct spa_pod *param)
case SPA_PARAM_Latency: case SPA_PARAM_Latency:
param_latency_changed(impl, param); param_latency_changed(impl, param);
break; break;
case SPA_PARAM_Tag:
param_tag_changed(impl, param);
break;
} }
return; return;

View file

@ -171,13 +171,11 @@ struct impl {
struct pw_stream *capture; struct pw_stream *capture;
struct spa_hook capture_listener; struct spa_hook capture_listener;
struct spa_audio_info_raw capture_info; struct spa_audio_info_raw capture_info;
struct spa_latency_info capture_latency;
struct pw_properties *playback_props; struct pw_properties *playback_props;
struct pw_stream *playback; struct pw_stream *playback;
struct spa_hook playback_listener; struct spa_hook playback_listener;
struct spa_audio_info_raw playback_info; struct spa_audio_info_raw playback_info;
struct spa_latency_info playback_latency;
unsigned int do_disconnect:1; unsigned int do_disconnect:1;
unsigned int recalc_delay:1; unsigned int recalc_delay:1;
@ -317,18 +315,16 @@ static void playback_process(void *d)
} }
static void param_latency_changed(struct impl *impl, const struct spa_pod *param, static void param_latency_changed(struct impl *impl, const struct spa_pod *param,
struct spa_latency_info *info, struct pw_stream *other) struct pw_stream *other)
{ {
struct spa_latency_info latency; struct spa_latency_info latency;
uint8_t buffer[1024]; uint8_t buffer[1024];
struct spa_pod_builder b; struct spa_pod_builder b;
const struct spa_pod *params[1]; const struct spa_pod *params[1];
if (spa_latency_parse(param, &latency) < 0) if (param == NULL || spa_latency_parse(param, &latency) < 0)
return; return;
*info = latency;
spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_builder_init(&b, buffer, sizeof(buffer));
params[0] = spa_latency_build(&b, SPA_PARAM_Latency, &latency); params[0] = spa_latency_build(&b, SPA_PARAM_Latency, &latency);
pw_stream_update_params(other, params, 1); pw_stream_update_params(other, params, 1);
@ -336,6 +332,15 @@ static void param_latency_changed(struct impl *impl, const struct spa_pod *param
impl->recalc_delay = true; impl->recalc_delay = true;
} }
static void param_tag_changed(struct impl *impl, const struct spa_pod *param,
struct pw_stream *other)
{
const struct spa_pod *params[1] = { param };
if (param == NULL)
return;
pw_stream_update_params(other, params, 1);
}
static void recalculate_buffer(struct impl *impl) static void recalculate_buffer(struct impl *impl)
{ {
if (impl->target_delay > 0.0f) { if (impl->target_delay > 0.0f) {
@ -414,7 +419,10 @@ static void capture_param_changed(void *data, uint32_t id, const struct spa_pod
break; break;
} }
case SPA_PARAM_Latency: case SPA_PARAM_Latency:
param_latency_changed(impl, param, &impl->capture_latency, impl->playback); param_latency_changed(impl, param, impl->playback);
break;
case SPA_PARAM_Tag:
param_tag_changed(impl, param, impl->playback);
break; break;
} }
} }
@ -453,7 +461,10 @@ static void playback_param_changed(void *data, uint32_t id, const struct spa_pod
switch (id) { switch (id) {
case SPA_PARAM_Latency: case SPA_PARAM_Latency:
param_latency_changed(impl, param, &impl->playback_latency, impl->capture); param_latency_changed(impl, param, impl->capture);
break;
case SPA_PARAM_Tag:
param_tag_changed(impl, param, impl->capture);
break; break;
} }
} }