Implement param filtering

Make a new pod filter function and use it in the plugins to filter
in enum_params.
Small tweaks to the pod_builder
This commit is contained in:
Wim Taymans 2017-11-09 17:07:04 +01:00
parent cc47fb7e3a
commit 58451d626c
35 changed files with 1150 additions and 917 deletions

View file

@ -82,7 +82,6 @@ struct data {
struct spa_video_info_raw format;
int32_t stride;
uint8_t params_buffer[1024];
int counter;
};
@ -240,7 +239,8 @@ on_stream_format_changed(void *_data, struct spa_pod_object *format)
struct data *data = _data;
struct pw_stream *stream = data->stream;
struct pw_type *t = data->t;
struct spa_pod_builder b = { NULL };
uint8_t params_buffer[1024];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer));
struct spa_pod_object *params[2];
Uint32 sdl_format;
void *d;
@ -266,7 +266,6 @@ on_stream_format_changed(void *_data, struct spa_pod_object *format)
SDL_LockTexture(data->texture, NULL, &d, &data->stride);
SDL_UnlockTexture(data->texture);
spa_pod_builder_init(&b, data->params_buffer, sizeof(data->params_buffer));
params[0] = spa_pod_builder_object(&b,
t->param.idBuffers, t->param_alloc_buffers.Buffers,
":", t->param_alloc_buffers.size, "i", data->stride * data->format.size.height,

View file

@ -75,7 +75,6 @@ struct data {
struct spa_video_info_raw format;
int32_t stride;
uint8_t params_buffer[1024];
int counter;
uint32_t seq;
};
@ -172,7 +171,8 @@ on_stream_format_changed(void *_data, struct spa_pod_object *format)
struct data *data = _data;
struct pw_stream *stream = data->stream;
struct pw_type *t = data->t;
struct spa_pod_builder b = { NULL };
uint8_t params_buffer[1024];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer));
struct spa_pod_object *params[2];
if (format == NULL) {
@ -183,7 +183,6 @@ on_stream_format_changed(void *_data, struct spa_pod_object *format)
data->stride = SPA_ROUND_UP_N(data->format.size.width * BPP, 4);
spa_pod_builder_init(&b, data->params_buffer, sizeof(data->params_buffer));
params[0] = spa_pod_builder_object(&b,
t->param.idBuffers, t->param_alloc_buffers.Buffers,
":", t->param_alloc_buffers.size, "i", data->stride * data->format.size.height,

View file

@ -529,10 +529,9 @@ handle_audio_fields (ConvertData *d)
}
static uint32_t
write_pod (struct spa_pod_builder *b, uint32_t ref, const void *data, uint32_t size)
write_pod (struct spa_pod_builder *b, const void *data, uint32_t size)
{
if (ref == -1)
ref = b->offset;
uint32_t ref = b->offset;
if (b->size <= b->offset) {
b->size = SPA_ROUND_UP_N (b->offset + size, 512);

View file

@ -29,7 +29,7 @@
#include <sys/eventfd.h>
#include "spa/node.h"
#include "spa/lib/format.h"
#include "spa/lib/pod.h"
#include "pipewire/pipewire.h"
#include "pipewire/interfaces.h"
@ -57,6 +57,10 @@
#define CHECK_OUT_PORT(this,d,p) (CHECK_OUT_PORT_ID(this,d,p) && (this)->out_ports[p].valid)
#define CHECK_PORT(this,d,p) (CHECK_IN_PORT (this,d,p) || CHECK_OUT_PORT (this,d,p))
#define GET_IN_PORT(this,p) (&this->in_ports[p])
#define GET_OUT_PORT(this,p) (&this->out_ports[p])
#define GET_PORT(this,d,p) (d == SPA_DIRECTION_INPUT ? GET_IN_PORT(this,p) : GET_OUT_PORT(this,p))
#define CHECK_PORT_BUFFER(this,b,p) (b < p->n_buffers)
struct proxy_buffer {
@ -152,6 +156,7 @@ static int spa_proxy_node_enum_params(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct proxy *this;
uint32_t offset;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(index != NULL, SPA_RESULT_INVALID_ARGUMENTS);
@ -159,6 +164,8 @@ static int spa_proxy_node_enum_params(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct proxy, node);
offset = builder->offset;
while (true) {
struct spa_pod_object *param;
@ -167,10 +174,13 @@ static int spa_proxy_node_enum_params(struct spa_node *node,
param = this->params[(*index)++];
if (param->body.id == id) {
spa_pod_builder_primitive(builder, &param->pod);
if (param->body.id != id)
continue;
if (spa_pod_filter(builder, &param->pod, &filter->pod) == SPA_RESULT_OK)
break;
}
spa_pod_builder_reset(builder, offset);
}
return SPA_RESULT_OK;
}
@ -312,11 +322,7 @@ do_update_port(struct proxy *this,
struct proxy_port *port;
struct pw_type *t = this->impl->t;
if (direction == SPA_DIRECTION_INPUT) {
port = &this->in_ports[port_id];
} else {
port = &this->out_ports[port_id];
}
port = GET_PORT(this, direction, port_id);
if (change_mask & PW_CLIENT_NODE_PORT_UPDATE_PARAMS) {
int i;
@ -369,11 +375,12 @@ static void do_uninit_port(struct proxy *this, enum spa_direction direction, uin
struct proxy_port *port;
spa_log_info(this->log, "proxy %p: removing port %d", this, port_id);
if (direction == SPA_DIRECTION_INPUT) {
port = &this->in_ports[port_id];
port = GET_IN_PORT(this, port_id);
this->n_inputs--;
} else {
port = &this->out_ports[port_id];
port = GET_OUT_PORT(this, port_id);
this->n_outputs--;
}
clear_port(this, port, direction, port_id);
@ -394,8 +401,7 @@ spa_proxy_node_add_port(struct spa_node *node, enum spa_direction direction, uin
if (!CHECK_FREE_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port = GET_PORT(this, direction, port_id);
clear_port(this, port, direction, port_id);
return SPA_RESULT_OK;
@ -435,9 +441,7 @@ spa_proxy_node_port_get_info(struct spa_node *node,
if (!CHECK_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port = GET_PORT(this, direction, port_id);
*info = &port->info;
return SPA_RESULT_OK;
@ -452,6 +456,7 @@ spa_proxy_node_port_enum_params(struct spa_node *node,
{
struct proxy *this;
struct proxy_port *port;
uint32_t offset;
spa_return_val_if_fail(node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(index != NULL, SPA_RESULT_INVALID_ARGUMENTS);
@ -461,9 +466,9 @@ spa_proxy_node_port_enum_params(struct spa_node *node,
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), SPA_RESULT_INVALID_PORT);
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port = GET_PORT(this, direction, port_id);
offset = builder->offset;
while (true) {
struct spa_pod_object *param;
@ -472,10 +477,13 @@ spa_proxy_node_port_enum_params(struct spa_node *node,
param = port->params[(*index)++];
if (param->body.id == id) {
spa_pod_builder_primitive(builder, &param->pod);
if (param->body.id != id)
continue;
if (spa_pod_filter(builder, &param->pod, &filter->pod) == SPA_RESULT_OK)
break;
}
spa_pod_builder_reset(builder, offset);
}
return SPA_RESULT_OK;
}
@ -523,8 +531,7 @@ spa_proxy_node_port_set_io(struct spa_node *node,
if (!CHECK_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port = GET_PORT(this, direction, port_id);
port->io = io;
return SPA_RESULT_OK;
@ -555,8 +562,7 @@ spa_proxy_node_port_use_buffers(struct spa_node *node,
if (!CHECK_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port = GET_PORT(this, direction, port_id);
if (!port->have_format)
return SPA_RESULT_NO_FORMAT;
@ -661,8 +667,7 @@ spa_proxy_node_port_alloc_buffers(struct spa_node *node,
if (!CHECK_PORT(this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
port =
direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
port = GET_PORT(this, direction, port_id);
if (!port->have_format)
return SPA_RESULT_NO_FORMAT;

View file

@ -30,9 +30,10 @@
#include <spa/node.h>
#include <spa/hook.h>
#include <spa/lib/format.h>
#include <spa/audio/format-utils.h>
#include <spa/lib/pod.h>
#include "pipewire/pipewire.h"
#include "pipewire/core.h"
#include "pipewire/private.h"
@ -374,61 +375,6 @@ static int port_set_io(struct spa_node *node, enum spa_direction direction, uint
return SPA_RESULT_OK;
}
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
const struct spa_pod_object *filter,
struct spa_pod_builder *builder)
{
struct node_data *nd = SPA_CONTAINER_OF(node, struct node_data, node_impl);
struct port_data *pd = nd->port_data[direction][port_id];
struct type *t = &pd->node->type;
struct spa_pod_builder b = { NULL, };
struct spa_pod_object *fmt;
uint8_t buffer[4096];
int res;
struct jack_engine_control *ctrl = pd->node->node.server->engine_control;
if (index > 0)
return SPA_RESULT_ENUM_END;
spa_pod_builder_init(&b, buffer, sizeof(buffer));
if (pd->port.jack_port) {
if (pd->port.jack_port->type_id == 0) {
fmt = spa_pod_builder_object(&b,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", t->audio_format.F32,
":", t->format_audio.rate, "i", ctrl->sample_rate,
":", t->format_audio.channels, "i", 1);
}
else if (pd->port.jack_port->type_id == 1) {
fmt = spa_pod_builder_object(&b,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype_audio.midi);
}
else
return SPA_RESULT_ENUM_END;
}
else {
fmt = spa_pod_builder_object(&b,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", t->audio_format.S16,
":", t->format_audio.rate, "i", ctrl->sample_rate,
":", t->format_audio.channels, "i", 2);
}
if ((res = spa_pod_object_filter(fmt, filter, builder)) < 0)
return res;
return SPA_RESULT_OK;
}
static int port_get_info(struct spa_node *node, enum spa_direction direction, uint32_t port_id,
const struct spa_port_info **info)
{
@ -446,6 +392,52 @@ static int port_get_info(struct spa_node *node, enum spa_direction direction, ui
return SPA_RESULT_OK;
}
static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
const struct spa_pod_object *filter,
struct spa_pod_builder *builder,
struct spa_pod **param)
{
struct node_data *nd = SPA_CONTAINER_OF(node, struct node_data, node_impl);
struct port_data *pd = nd->port_data[direction][port_id];
struct type *t = &pd->node->type;
struct jack_engine_control *ctrl = pd->node->node.server->engine_control;
if (index > 0)
return SPA_RESULT_ENUM_END;
if (pd->port.jack_port) {
if (pd->port.jack_port->type_id == 0) {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", t->audio_format.F32,
":", t->format_audio.rate, "i", ctrl->sample_rate,
":", t->format_audio.channels, "i", 1);
}
else if (pd->port.jack_port->type_id == 1) {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype_audio.midi);
}
else
return SPA_RESULT_ENUM_END;
}
else {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", t->audio_format.S16,
":", t->format_audio.rate, "i", ctrl->sample_rate,
":", t->format_audio.channels, "i", 2);
}
return SPA_RESULT_OK;
}
static int port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
@ -454,16 +446,30 @@ static int port_enum_params(struct spa_node *node,
{
struct node_data *nd = SPA_CONTAINER_OF(node, struct node_data, node_impl);
struct type *t = &nd->type;
struct spa_pod *param;
uint32_t offset;
int res;
offset = builder->offset;
next:
if (id == t->param.idEnumFormat) {
return port_enum_formats(node, direction, port_id, index, filter, builder);
if ((res = port_enum_formats(node, direction, port_id, index, filter, builder, &param)) < 0)
return res;
}
else if (id == t->param.idFormat) {
return port_enum_formats(node, direction, port_id, index, filter, builder);
if ((res = port_enum_formats(node, direction, port_id, index, filter, builder, &param)) < 0)
return res;
}
else
return SPA_RESULT_UNKNOWN_PARAM;
(*index)++;
spa_pod_builder_reset(builder, offset);
if ((res = spa_pod_filter(builder, param, (struct spa_pod*)filter)) < 0)
goto next;
return SPA_RESULT_ENUM_END;
}

View file

@ -338,12 +338,12 @@ static inline void *begin_write(struct pw_protocol_native_connection *conn, uint
return p + 2;
}
static uint32_t write_pod(struct spa_pod_builder *b, uint32_t ref, const void *data, uint32_t size)
static uint32_t write_pod(struct spa_pod_builder *b, const void *data, uint32_t size)
{
struct impl *impl = SPA_CONTAINER_OF(b, struct impl, builder);
uint32_t ref = b->offset;
if (ref == -1)
ref = b->offset;
ref = b->offset;
if (b->size <= b->offset) {
b->size = SPA_ROUND_UP_N(b->offset + size, 4096);

View file

@ -25,8 +25,6 @@
#include <getopt.h>
#include <limits.h>
#include <spa/lib/props.h>
#include <pipewire/utils.h>
#include <pipewire/log.h>
#include <pipewire/core.h>

View file

@ -25,8 +25,6 @@
#include <getopt.h>
#include <limits.h>
#include <spa/lib/props.h>
#include <pipewire/core.h>
#include <pipewire/log.h>
#include <pipewire/module.h>

View file

@ -787,7 +787,7 @@ int pw_core_find_format(struct pw_core *core,
asprintf(error, "error output enum formats: %d", res);
goto error;
}
format = spa_pod_builder_deref(&fb, 0);
format = spa_pod_builder_deref(builder, 0);
pw_log_debug("Got filtered:");
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))

View file

@ -24,8 +24,7 @@
#include <spa/video/format.h>
#include <spa/pod-utils.h>
#include <spa/lib/format.h>
#include <spa/lib/props.h>
#include <spa/lib/pod.h>
#include "pipewire.h"
#include "private.h"
@ -148,7 +147,7 @@ static int do_negotiate(struct pw_link *this, uint32_t in_state, uint32_t out_st
goto error;
}
current = spa_pod_builder_deref(&b, 0);
if (spa_pod_object_compare(current, format) < 0) {
if (spa_pod_compare((struct spa_pod*)current, (struct spa_pod*)format) != 0) {
pw_log_debug("link %p: output format change, renegotiate", this);
pw_node_set_state(output->node, PW_NODE_STATE_SUSPENDED);
out_state = PW_PORT_STATE_CONFIGURE;
@ -167,7 +166,7 @@ static int do_negotiate(struct pw_link *this, uint32_t in_state, uint32_t out_st
goto error;
}
current = spa_pod_builder_deref(&b, 0);
if (spa_pod_object_compare(current, format) < 0) {
if (spa_pod_compare((struct spa_pod*)current, (struct spa_pod*)format) != 0) {
pw_log_debug("link %p: input format change, renegotiate", this);
pw_node_set_state(input->node, PW_NODE_STATE_SUSPENDED);
in_state = PW_PORT_STATE_CONFIGURE;
@ -399,7 +398,6 @@ param_filter(struct pw_link *this,
uint32_t id,
struct spa_pod_builder *result)
{
int res;
uint8_t ibuf[2048], obuf[2048];
struct spa_pod_builder ib = { 0 }, ob = { 0 };
struct spa_pod_object *oparam, *iparam;
@ -407,44 +405,37 @@ param_filter(struct pw_link *this,
for (iidx = 0;;) {
spa_pod_builder_init(&ib, ibuf, sizeof(ibuf));
pw_log_debug("iparam %d", iidx);
if (spa_node_port_enum_params(in_port->node->node, in_port->direction, in_port->port_id,
id, &iidx, NULL, &ib) < 0)
break;
iparam = spa_pod_builder_deref(&ib, 0);
pw_log_debug("iparam %d", iidx);
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
spa_debug_pod(&iparam->pod, 0);
for (oidx = 0;;) {
uint32_t offset;
spa_pod_builder_init(&ob, obuf, sizeof(obuf));
if (spa_node_port_enum_params(out_port->node->node, out_port->direction,
out_port->port_id, id, &oidx,
NULL, &ob) < 0)
break;
oparam = spa_pod_builder_deref(&ob, 0);
if (iidx == 1 && pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
spa_debug_pod(&oparam->pod, 0);
if (iparam->body.type != oparam->body.type)
continue;
offset = result->offset;
spa_pod_builder_push_object(result, id, iparam->body.type);
if ((res = spa_props_filter(result,
SPA_POD_CONTENTS(struct spa_pod_object, iparam),
SPA_POD_CONTENTS_SIZE(struct spa_pod_object, iparam),
SPA_POD_CONTENTS(struct spa_pod_object, oparam),
SPA_POD_CONTENTS_SIZE(struct spa_pod_object, oparam))) < 0) {
result->offset = offset;
result->depth = 0;
continue;
pw_log_debug("oparam %d %d", oidx, offset);
if (spa_node_port_enum_params(out_port->node->node, out_port->direction,
out_port->port_id, id, &oidx,
iparam, result) < 0) {
break;
}
spa_pod_builder_pop(result);
oparam = spa_pod_builder_deref(result, offset);
pw_log_debug("oparam %d", oidx);
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
spa_debug_pod(&oparam->pod, 0);
num++;
}
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
spa_debug_pod(&iparam->pod, 0);
}
return num;
}