mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
Improve enum_param
Add an argument to pass the result param to the caller instead of having the caller have to pick it up from the builder. Improve docs for node, clock and monitor Pass spa_pod everywhere instead of spa_pod_object. Pass result argument to spa_pod_filter to make things a little nicer.
This commit is contained in:
parent
cd5e697e9f
commit
440f681f4b
70 changed files with 872 additions and 858 deletions
|
|
@ -68,8 +68,8 @@ struct impl {
|
|||
uint32_t index;
|
||||
struct udev_list_entry *devices;
|
||||
|
||||
uint8_t item_buffer[4096];
|
||||
struct spa_monitor_item *item;
|
||||
// uint8_t item_buffer[4096];
|
||||
// struct spa_monitor_item *item;
|
||||
|
||||
snd_ctl_t *ctl_hndl;
|
||||
struct udev_device *dev;
|
||||
|
|
@ -108,10 +108,10 @@ static const char *path_get_card_id(const char *path)
|
|||
}
|
||||
|
||||
static int
|
||||
fill_item(struct impl *this, snd_ctl_card_info_t *card_info, snd_pcm_info_t *dev_info, struct udev_device *dev)
|
||||
fill_item(struct impl *this, snd_ctl_card_info_t *card_info, snd_pcm_info_t *dev_info, struct udev_device *dev,
|
||||
struct spa_pod **item, struct spa_pod_builder *builder)
|
||||
{
|
||||
const char *str, *name, *klass = NULL;
|
||||
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(this->item_buffer, sizeof(this->item_buffer));
|
||||
const struct spa_handle_factory *factory = NULL;
|
||||
char card_name[64];
|
||||
struct type *t = &this->type;
|
||||
|
|
@ -141,7 +141,7 @@ fill_item(struct impl *this, snd_ctl_card_info_t *card_info, snd_pcm_info_t *dev
|
|||
|
||||
snprintf(card_name, 64, "%s,%d", this->card_name, snd_pcm_info_get_device(dev_info));
|
||||
|
||||
spa_pod_builder_add(&b,
|
||||
spa_pod_builder_add(builder,
|
||||
"<", 0, t->monitor.MonitorItem,
|
||||
":", t->monitor.id, "s", name,
|
||||
":", t->monitor.flags, "i", 0,
|
||||
|
|
@ -150,10 +150,10 @@ fill_item(struct impl *this, snd_ctl_card_info_t *card_info, snd_pcm_info_t *dev
|
|||
":", t->monitor.klass, "s", klass,
|
||||
":", t->monitor.factory, "p", t->handle_factory, factory, NULL);
|
||||
|
||||
spa_pod_builder_add(&b,
|
||||
spa_pod_builder_add(builder,
|
||||
":", t->monitor.info, "[", NULL);
|
||||
|
||||
spa_pod_builder_add(&b,
|
||||
spa_pod_builder_add(builder,
|
||||
"s", "alsa.card", "s", card_name,
|
||||
"s", "alsa.card.id", "s", snd_ctl_card_info_get_id(card_info),
|
||||
"s", "alsa.card.components", "s", snd_ctl_card_info_get_components(card_info),
|
||||
|
|
@ -169,29 +169,29 @@ fill_item(struct impl *this, snd_ctl_card_info_t *card_info, snd_pcm_info_t *dev
|
|||
NULL);
|
||||
|
||||
if ((str = udev_device_get_property_value(dev, "SOUND_CLASS")) && *str) {
|
||||
spa_pod_builder_add(&b, "s", "device.class", "s", str, NULL);
|
||||
spa_pod_builder_add(builder, "s", "device.class", "s", str, NULL);
|
||||
}
|
||||
|
||||
str = udev_device_get_property_value(dev, "ID_PATH");
|
||||
if (!(str && *str))
|
||||
str = udev_device_get_syspath(dev);
|
||||
if (str && *str) {
|
||||
spa_pod_builder_add(&b, "s", "device.bus_path", "s", str, 0);
|
||||
spa_pod_builder_add(builder, "s", "device.bus_path", "s", str, 0);
|
||||
}
|
||||
if ((str = udev_device_get_syspath(dev)) && *str) {
|
||||
spa_pod_builder_add(&b, "s", "sysfs.path", "s", str, 0);
|
||||
spa_pod_builder_add(builder, "s", "sysfs.path", "s", str, 0);
|
||||
}
|
||||
if ((str = udev_device_get_property_value(dev, "ID_ID")) && *str) {
|
||||
spa_pod_builder_add(&b, "s", "udev.id", "s", str, 0);
|
||||
spa_pod_builder_add(builder, "s", "udev.id", "s", str, 0);
|
||||
}
|
||||
if ((str = udev_device_get_property_value(dev, "ID_BUS")) && *str) {
|
||||
spa_pod_builder_add(&b, "s", "device.bus", "s", str, 0);
|
||||
spa_pod_builder_add(builder, "s", "device.bus", "s", str, 0);
|
||||
}
|
||||
if ((str = udev_device_get_property_value(dev, "SUBSYSTEM")) && *str) {
|
||||
spa_pod_builder_add(&b, "s", "device.subsystem", "s", str, 0);
|
||||
spa_pod_builder_add(builder, "s", "device.subsystem", "s", str, 0);
|
||||
}
|
||||
if ((str = udev_device_get_property_value(dev, "ID_VENDOR_ID")) && *str) {
|
||||
spa_pod_builder_add(&b, "s", "device.vendor.id", "s", str, 0);
|
||||
spa_pod_builder_add(builder, "s", "device.vendor.id", "s", str, 0);
|
||||
}
|
||||
str = udev_device_get_property_value(dev, "ID_VENDOR_FROM_DATABASE");
|
||||
if (!(str && *str)) {
|
||||
|
|
@ -201,20 +201,20 @@ fill_item(struct impl *this, snd_ctl_card_info_t *card_info, snd_pcm_info_t *dev
|
|||
}
|
||||
}
|
||||
if (str && *str) {
|
||||
spa_pod_builder_add(&b, "s", "device.vendor.name", "s", str, 0);
|
||||
spa_pod_builder_add(builder, "s", "device.vendor.name", "s", str, 0);
|
||||
}
|
||||
if ((str = udev_device_get_property_value(dev, "ID_MODEL_ID")) && *str) {
|
||||
spa_pod_builder_add(&b, "s", "device.product.id", "s", str, 0);
|
||||
spa_pod_builder_add(builder, "s", "device.product.id", "s", str, 0);
|
||||
}
|
||||
spa_pod_builder_add(&b, "s", "device.product.name", "s", name, 0);
|
||||
spa_pod_builder_add(builder, "s", "device.product.name", "s", name, 0);
|
||||
|
||||
if ((str = udev_device_get_property_value(dev, "ID_SERIAL")) && *str) {
|
||||
spa_pod_builder_add(&b, "s", "device.serial", "s", str, 0);
|
||||
spa_pod_builder_add(builder, "s", "device.serial", "s", str, 0);
|
||||
}
|
||||
if ((str = udev_device_get_property_value(dev, "SOUND_FORM_FACTOR")) && *str) {
|
||||
spa_pod_builder_add(&b, "s", "device.form_factor", "s", str, 0);
|
||||
spa_pod_builder_add(builder, "s", "device.form_factor", "s", str, 0);
|
||||
}
|
||||
this->item = spa_pod_builder_add(&b, "]>", NULL);
|
||||
*item = spa_pod_builder_add(builder, "]>", NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -255,7 +255,8 @@ static int open_card(struct impl *this, struct udev_device *dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int get_next_device(struct impl *this, struct udev_device *dev)
|
||||
static int get_next_device(struct impl *this, struct udev_device *dev,
|
||||
struct spa_pod **item, struct spa_pod_builder *builder)
|
||||
{
|
||||
int err;
|
||||
snd_pcm_info_t *dev_info;
|
||||
|
|
@ -299,9 +300,7 @@ static int get_next_device(struct impl *this, struct udev_device *dev)
|
|||
if ((err = snd_ctl_pcm_info(this->ctl_hndl, dev_info)) < 0)
|
||||
goto again;
|
||||
|
||||
fill_item(this, card_info, dev_info, dev);
|
||||
|
||||
return 0;
|
||||
return fill_item(this, card_info, dev_info, dev, item, builder);
|
||||
}
|
||||
|
||||
static void impl_on_fd_events(struct spa_source *source)
|
||||
|
|
@ -332,11 +331,12 @@ static void impl_on_fd_events(struct spa_source *source)
|
|||
uint8_t buffer[4096];
|
||||
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
|
||||
struct spa_event *event;
|
||||
struct spa_pod *item;
|
||||
|
||||
if (get_next_device(this, dev) < 0)
|
||||
event = spa_pod_builder_object(&b, 0, type);
|
||||
if (get_next_device(this, dev, &item, &b) < 0)
|
||||
break;
|
||||
|
||||
event = spa_pod_builder_object(&b, 0, type, "P", this->item);
|
||||
this->callbacks->event(this->callbacks_data, event);
|
||||
}
|
||||
close_card(this);
|
||||
|
|
@ -384,8 +384,9 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor,
|
|||
}
|
||||
|
||||
static int impl_monitor_enum_items(struct spa_monitor *monitor,
|
||||
struct spa_monitor_item **item,
|
||||
uint32_t *index)
|
||||
uint32_t *index,
|
||||
struct spa_pod **item,
|
||||
struct spa_pod_builder *builder)
|
||||
{
|
||||
int res;
|
||||
struct impl *this;
|
||||
|
|
@ -428,7 +429,7 @@ static int impl_monitor_enum_items(struct spa_monitor *monitor,
|
|||
goto again;
|
||||
}
|
||||
}
|
||||
if (get_next_device(this, this->dev) < 0) {
|
||||
if (get_next_device(this, this->dev, item, builder) < 0) {
|
||||
udev_device_unref(this->dev);
|
||||
close_card(this);
|
||||
goto next;
|
||||
|
|
@ -437,8 +438,6 @@ static int impl_monitor_enum_items(struct spa_monitor *monitor,
|
|||
this->index++;
|
||||
(*index)++;
|
||||
|
||||
*item = this->item;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ static void reset_props(struct props *props)
|
|||
|
||||
static int impl_node_enum_params(struct spa_node *node,
|
||||
uint32_t id, uint32_t *index,
|
||||
const struct spa_pod_object *filter,
|
||||
const struct spa_pod *filter,
|
||||
struct spa_pod **result,
|
||||
struct spa_pod_builder *builder)
|
||||
{
|
||||
struct state *this;
|
||||
|
|
@ -93,14 +94,14 @@ static int impl_node_enum_params(struct spa_node *node,
|
|||
(*index)++;
|
||||
|
||||
spa_pod_builder_reset(builder, &state);
|
||||
if (spa_pod_filter(builder, param, (struct spa_pod*)filter) < 0)
|
||||
if (spa_pod_filter(builder, result, param, filter) < 0)
|
||||
goto next;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags,
|
||||
const struct spa_pod_object *param)
|
||||
const struct spa_pod *param)
|
||||
{
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
|
|
@ -274,7 +275,8 @@ static int
|
|||
impl_node_port_enum_params(struct spa_node *node,
|
||||
enum spa_direction direction, uint32_t port_id,
|
||||
uint32_t id, uint32_t *index,
|
||||
const struct spa_pod_object *filter,
|
||||
const struct spa_pod *filter,
|
||||
struct spa_pod **result,
|
||||
struct spa_pod_builder *builder)
|
||||
{
|
||||
|
||||
|
|
@ -308,8 +310,7 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
return 0;
|
||||
}
|
||||
else if (id == t->param.idEnumFormat) {
|
||||
printf("%d\n", *index);
|
||||
return spa_alsa_enum_format(this, index, filter, builder);
|
||||
return spa_alsa_enum_format(this, index, filter, result, builder);
|
||||
}
|
||||
else if (id == t->param.idFormat) {
|
||||
if (!this->have_format)
|
||||
|
|
@ -375,7 +376,7 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
(*index)++;
|
||||
|
||||
spa_pod_builder_reset(builder, &state);
|
||||
if (spa_pod_filter(builder, param, (struct spa_pod*)filter) < 0)
|
||||
if (spa_pod_filter(builder, result, param, filter) < 0)
|
||||
goto next;
|
||||
|
||||
return 1;
|
||||
|
|
@ -393,7 +394,7 @@ static int clear_buffers(struct state *this)
|
|||
static int port_set_format(struct spa_node *node,
|
||||
enum spa_direction direction, uint32_t port_id,
|
||||
uint32_t flags,
|
||||
const struct spa_pod_object *format)
|
||||
const struct spa_pod *format)
|
||||
{
|
||||
struct state *this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
int err;
|
||||
|
|
@ -438,7 +439,7 @@ static int
|
|||
impl_node_port_set_param(struct spa_node *node,
|
||||
enum spa_direction direction, uint32_t port_id,
|
||||
uint32_t id, uint32_t flags,
|
||||
const struct spa_pod_object *param)
|
||||
const struct spa_pod *param)
|
||||
{
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
|
|
@ -509,7 +510,7 @@ static int
|
|||
impl_node_port_alloc_buffers(struct spa_node *node,
|
||||
enum spa_direction direction,
|
||||
uint32_t port_id,
|
||||
struct spa_pod_object **params,
|
||||
struct spa_pod **params,
|
||||
uint32_t n_params,
|
||||
struct spa_buffer **buffers,
|
||||
uint32_t *n_buffers)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ static void reset_props(struct props *props)
|
|||
|
||||
static int impl_node_enum_params(struct spa_node *node,
|
||||
uint32_t id, uint32_t *index,
|
||||
const struct spa_pod_object *filter,
|
||||
const struct spa_pod *filter,
|
||||
struct spa_pod **result,
|
||||
struct spa_pod_builder *builder)
|
||||
{
|
||||
struct state *this;
|
||||
|
|
@ -90,14 +91,14 @@ static int impl_node_enum_params(struct spa_node *node,
|
|||
(*index)++;
|
||||
|
||||
spa_pod_builder_reset(builder, &state);
|
||||
if (spa_pod_filter(builder, param, (struct spa_pod*)filter) < 0)
|
||||
if (spa_pod_filter(builder, result, param, filter) < 0)
|
||||
goto next;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags,
|
||||
const struct spa_pod_object *param)
|
||||
const struct spa_pod *param)
|
||||
{
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
|
|
@ -324,7 +325,8 @@ static int
|
|||
impl_node_port_enum_params(struct spa_node *node,
|
||||
enum spa_direction direction, uint32_t port_id,
|
||||
uint32_t id, uint32_t *index,
|
||||
const struct spa_pod_object *filter,
|
||||
const struct spa_pod *filter,
|
||||
struct spa_pod **result,
|
||||
struct spa_pod_builder *builder)
|
||||
{
|
||||
struct state *this;
|
||||
|
|
@ -358,7 +360,7 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
return 0;
|
||||
}
|
||||
else if (id == t->param.idEnumFormat) {
|
||||
return spa_alsa_enum_format(this, index, filter, builder);
|
||||
return spa_alsa_enum_format(this, index, filter, result, builder);
|
||||
}
|
||||
else if (id == t->param.idFormat) {
|
||||
if ((res = port_get_format(node, direction, port_id, index, ¶m, builder)) <= 0)
|
||||
|
|
@ -399,7 +401,7 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
(*index)++;
|
||||
|
||||
spa_pod_builder_reset(builder, &state);
|
||||
if (spa_pod_filter(builder, param, (struct spa_pod*)filter) < 0)
|
||||
if (spa_pod_filter(builder, result, param, filter) < 0)
|
||||
goto next;
|
||||
|
||||
return 1;
|
||||
|
|
@ -417,7 +419,7 @@ static int clear_buffers(struct state *this)
|
|||
|
||||
static int port_set_format(struct spa_node *node,
|
||||
enum spa_direction direction, uint32_t port_id,
|
||||
uint32_t flags, const struct spa_pod_object *format)
|
||||
uint32_t flags, const struct spa_pod *format)
|
||||
{
|
||||
struct state *this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
int err;
|
||||
|
|
@ -460,7 +462,7 @@ static int
|
|||
impl_node_port_set_param(struct spa_node *node,
|
||||
enum spa_direction direction, uint32_t port_id,
|
||||
uint32_t id, uint32_t flags,
|
||||
const struct spa_pod_object *param)
|
||||
const struct spa_pod *param)
|
||||
{
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
|
|
@ -529,7 +531,7 @@ static int
|
|||
impl_node_port_alloc_buffers(struct spa_node *node,
|
||||
enum spa_direction direction,
|
||||
uint32_t port_id,
|
||||
struct spa_pod_object **params,
|
||||
struct spa_pod **params,
|
||||
uint32_t n_params,
|
||||
struct spa_buffer **buffers,
|
||||
uint32_t *n_buffers)
|
||||
|
|
@ -668,6 +670,7 @@ static const struct spa_node impl_node = {
|
|||
};
|
||||
|
||||
static int impl_clock_enum_params(struct spa_clock *clock, uint32_t id, uint32_t *index,
|
||||
struct spa_pod **param,
|
||||
struct spa_pod_builder *builder)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
|
|
@ -675,7 +678,7 @@ static int impl_clock_enum_params(struct spa_clock *clock, uint32_t id, uint32_t
|
|||
|
||||
static int impl_clock_set_param(struct spa_clock *clock,
|
||||
uint32_t id, uint32_t flags,
|
||||
const struct spa_pod_object *param)
|
||||
const struct spa_pod *param)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,8 @@ static snd_pcm_format_t spa_alsa_format_to_alsa(struct type *map, uint32_t forma
|
|||
|
||||
int
|
||||
spa_alsa_enum_format(struct state *state, uint32_t *index,
|
||||
const struct spa_pod_object *filter,
|
||||
const struct spa_pod *filter,
|
||||
struct spa_pod **result,
|
||||
struct spa_pod_builder *builder)
|
||||
{
|
||||
snd_pcm_t *hndl;
|
||||
|
|
@ -120,7 +121,7 @@ spa_alsa_enum_format(struct state *state, uint32_t *index,
|
|||
uint8_t buffer[4096];
|
||||
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
|
||||
struct spa_pod_prop *prop;
|
||||
struct spa_pod_object *fmt;
|
||||
struct spa_pod *fmt;
|
||||
int res;
|
||||
bool opened;
|
||||
|
||||
|
|
@ -193,7 +194,7 @@ spa_alsa_enum_format(struct state *state, uint32_t *index,
|
|||
|
||||
(*index)++;
|
||||
|
||||
if ((res = spa_pod_filter(builder, (struct spa_pod*)fmt, (struct spa_pod*)filter)) < 0)
|
||||
if ((res = spa_pod_filter(builder, result, fmt, filter)) < 0)
|
||||
goto next;
|
||||
|
||||
if (!opened)
|
||||
|
|
|
|||
|
|
@ -169,7 +169,8 @@ struct state {
|
|||
int
|
||||
spa_alsa_enum_format(struct state *state,
|
||||
uint32_t *index,
|
||||
const struct spa_pod_object *filter,
|
||||
const struct spa_pod *filter,
|
||||
struct spa_pod **result,
|
||||
struct spa_pod_builder *builder);
|
||||
|
||||
int spa_alsa_set_format(struct state *state, struct spa_audio_info *info, uint32_t flags);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue