first working version

This commit is contained in:
Frank Krick 2025-08-15 19:28:16 -04:00
parent 61a5701493
commit 1c53fdbfc0

View file

@ -21,6 +21,9 @@
#include <pipewire/impl.h>
#include "spa/control/control.h"
#include "spa/param/props.h"
#define NAME "filter-chain"
PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
@ -1223,27 +1226,78 @@ static void capture_process(void *d)
}
}
static int apply_props(struct spa_loop *loop, bool async, uint32_t seq, const void *data, size_t size, void *user_data)
{
struct impl *impl = user_data;
const struct spa_pod *props = data;
if (props == NULL) {
fprintf(stdout, "no props\n");
}
//spa_filter_graph_set_props(impl->graph, SPA_DIRECTION_INPUT, props);
spa_filter_graph_set_props(impl->graph, SPA_DIRECTION_OUTPUT, props);
/* props was allocated with spa_pod_copy before invoking */
return 0;
}
static void control_process(void *d)
{
fprintf(stdout, "control process\n");
struct impl *impl = d;
int res;
if ((res = pw_stream_trigger_process(impl->playback)) < 0) {
pw_log_debug("playback trigger error: %s", spa_strerror(res));
struct pw_buffer *control = pw_stream_dequeue_buffer(impl->control);
/*
while (true) {
struct pw_buffer *t;
if ((t = pw_stream_dequeue_buffer(impl->control)) == NULL)
break;
/* playback part is not ready, consume, discard and recycle
* the capture buffers */
pw_stream_queue_buffer(impl->control, t);
if (control)
pw_stream_queue_buffer(impl->control, control);
control = t;
}
*/
if (control == NULL) {
fprintf(stdout, "out of control buffers\n");
goto done;
}
fprintf(stdout, "\n\nprocessing buffer\n");
if (control->buffer->n_datas > 0) {
fprintf(stdout, "creating pod\n");
struct spa_pod *pod = spa_pod_from_data(
control->buffer->datas[0].data,
control->buffer->datas[0].maxsize,
control->buffer->datas[0].chunk->offset,
control->buffer->datas[0].chunk->size);
if (spa_pod_is_sequence(pod)) {
fprintf(stdout, "processing sequence\n");
struct spa_pod_sequence *sequence = (struct spa_pod_sequence *)pod;
struct spa_pod_control *pod_control;
SPA_POD_SEQUENCE_FOREACH(sequence, pod_control) {
fprintf(stdout, "processing sequence item\n");
if (pod_control->type == SPA_CONTROL_Properties) {
fprintf(stdout, "processing properties\n");
struct pw_loop *loop = pw_context_get_main_loop(impl->context);
pw_loop_invoke(loop, apply_props, 0, &pod_control->value, SPA_POD_SIZE(&pod_control->value), false, impl);
} else if (pod_control->type != SPA_CONTROL_OSC) {}
}
} else {
fprintf(stdout, "not a sequence\n");
}
}
done:
pw_stream_queue_buffer(impl->control, control);
}
static void playback_process(void *d)
{
pw_log_error("playback process");
struct impl *impl = d;
struct pw_buffer *in, *out, *control;
struct pw_buffer *in, *out;
uint32_t i, data_size = 0;
int32_t stride = 0;
struct spa_data *bd;
@ -1262,18 +1316,6 @@ static void playback_process(void *d)
if (in == NULL)
pw_log_debug("%p: out of capture buffers: %m", impl);
control = NULL;
while (true) {
struct pw_buffer *t;
if ((t = pw_stream_dequeue_buffer(impl->control)) == NULL)
break;
if (control)
pw_stream_queue_buffer(impl->control, control);
control = t;
}
if (control == NULL)
pw_log_debug("%p: out of control buffers: %m", impl);
if ((out = pw_stream_dequeue_buffer(impl->playback)) == NULL)
pw_log_debug("%p: out of playback buffers: %m", impl);
@ -1321,8 +1363,6 @@ done:
pw_stream_queue_buffer(impl->capture, in);
if (out != NULL)
pw_stream_queue_buffer(impl->playback, out);
if (control != NULL)
pw_stream_queue_buffer(impl->control, control);
}
static int activate_graph(struct impl *impl)
@ -1632,7 +1672,7 @@ static int setup_streams(struct impl *impl)
struct spa_filter_graph *graph = impl->graph;
impl->control = pw_stream_new(impl->core,
"filter control", impl->capture_props);
"filter control", impl->control_props);
impl->control_props = NULL;
if (impl->control == NULL)
return -errno;
@ -1641,6 +1681,24 @@ static int setup_streams(struct impl *impl)
&impl->control_listener,
&control_stream_events, impl);
uint8_t buffer[256];
struct spa_pod_builder bt = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
const struct spa_pod *param[1];
param[0] = spa_pod_builder_add_object(&bt,
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_application),
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_control)
);
pw_stream_connect(impl->control,
PW_DIRECTION_INPUT,
PW_ID_ANY,
PW_STREAM_FLAG_AUTOCONNECT |
PW_STREAM_FLAG_MAP_BUFFERS |
PW_STREAM_FLAG_RT_PROCESS,
param, 1);
impl->capture = pw_stream_new(impl->core,
"filter capture", impl->capture_props);
impl->capture_props = NULL;
@ -1908,6 +1966,8 @@ static void copy_props(struct impl *impl, struct pw_properties *props, const cha
SPA_EXPORT
int pipewire__module_init(struct pw_impl_module *module, const char *args)
{
fprintf(stdout, "module init reached\n");
struct pw_context *context = pw_impl_module_get_context(module);
const struct pw_properties *p;
struct pw_properties *props;
@ -1924,7 +1984,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
if (impl == NULL)
return -errno;
pw_log_debug("module %p: new %s", impl, args);
pw_log_debug("module fk1 %p: new %s", impl, args);
if (args)
props = pw_properties_new_string(args);