Type changes

Only allow properties inside objects, this makes it easier to
iterate the object, which is needed for efficiently processing
control streams.
Add a choice type to mark variable properties.
SPA_TYPE_Enum -> SPA_TYPE_Id to avoid confusion with choice enum
Make it easier to allocate and initialize properties on the stack
Make more efficient methods to make objects.
This commit is contained in:
Wim Taymans 2018-09-05 16:41:07 +02:00
parent 03fdabd155
commit cc842cbdc8
63 changed files with 2253 additions and 1880 deletions

View file

@ -73,6 +73,12 @@ static int impl_udev_open(struct impl *this)
return 0;
}
static inline void add_dict(struct spa_pod_builder *builder, const char *key, const char *val)
{
spa_pod_builder_string(builder, key);
spa_pod_builder_string(builder, val);
}
static void fill_item(struct impl *this, struct item *item, struct udev_device *udevice,
struct spa_pod **result, struct spa_pod_builder *builder)
{
@ -97,43 +103,43 @@ static void fill_item(struct impl *this, struct item *item, struct udev_device *
if (!(name && *name))
name = "Unknown";
spa_pod_builder_add(builder,
"{", SPA_TYPE_OBJECT_MonitorItem, 0,
":", SPA_MONITOR_ITEM_id, "s", udev_device_get_syspath(item->udevice),
":", SPA_MONITOR_ITEM_flags, "I", SPA_MONITOR_ITEM_FLAG_NONE,
":", SPA_MONITOR_ITEM_state, "I", SPA_MONITOR_ITEM_STATE_Available,
":", SPA_MONITOR_ITEM_name, "s", name,
":", SPA_MONITOR_ITEM_class, "s", "Video/Source",
":", SPA_MONITOR_ITEM_factory, "p", SPA_TYPE_INTERFACE_HandleFactory, &spa_v4l2_source_factory,
":", SPA_MONITOR_ITEM_info, "[",
NULL);
spa_pod_builder_push_object(builder, SPA_TYPE_OBJECT_MonitorItem, 0);
spa_pod_builder_props(builder,
SPA_MONITOR_ITEM_id, &SPA_POD_Stringv(udev_device_get_syspath(item->udevice)),
SPA_MONITOR_ITEM_flags, &SPA_POD_Id(SPA_MONITOR_ITEM_FLAG_NONE),
SPA_MONITOR_ITEM_state, &SPA_POD_Id(SPA_MONITOR_ITEM_STATE_Available),
SPA_MONITOR_ITEM_name, &SPA_POD_Stringv(name),
SPA_MONITOR_ITEM_class, &SPA_POD_Stringc("Video/Source"),
SPA_MONITOR_ITEM_factory, &SPA_POD_Pointer(SPA_TYPE_INTERFACE_HandleFactory, &spa_v4l2_source_factory),
0);
spa_pod_builder_prop(builder, SPA_MONITOR_ITEM_info, 0);
spa_pod_builder_push_struct(builder);
add_dict(builder, "udev-probed", "1");
add_dict(builder, "device.api", "v4l2");
add_dict(builder, "device.path", udev_device_get_devnode(item->udevice));
spa_pod_builder_add(builder,
"s", "udev-probed", "s", "1",
"s", "device.api", "s", "v4l2",
"s", "device.path", "s", udev_device_get_devnode(item->udevice),
NULL);
str = udev_device_get_property_value(item->udevice, "ID_PATH");
if (!(str && *str))
str = udev_device_get_syspath(item->udevice);
if (str && *str) {
spa_pod_builder_add(builder, "s", "device.bus_path", "s", str, 0);
add_dict(builder, "device.bus_path", str);
}
if ((str = udev_device_get_syspath(item->udevice)) && *str) {
spa_pod_builder_add(builder, "s", "sysfs.path", "s", str, 0);
add_dict(builder, "sysfs.path", str);
}
if ((str = udev_device_get_property_value(item->udevice, "ID_ID")) && *str) {
spa_pod_builder_add(builder, "s", "udev.id", "s", str, 0);
add_dict(builder, "udev.id", str);
}
if ((str = udev_device_get_property_value(item->udevice, "ID_BUS")) && *str) {
spa_pod_builder_add(builder, "s", "device.bus", "s", str, 0);
add_dict(builder, "device.bus", str);
}
if ((str = udev_device_get_property_value(item->udevice, "SUBSYSTEM")) && *str) {
spa_pod_builder_add(builder, "s", "device.subsystem", "s", str, 0);
add_dict(builder, "device.subsystem", str);
}
if ((str = udev_device_get_property_value(item->udevice, "ID_VENDOR_ID")) && *str) {
spa_pod_builder_add(builder, "s", "device.vendor.id", "s", str, 0);
add_dict(builder, "device.vendor.id", str);
}
str = udev_device_get_property_value(item->udevice, "ID_VENDOR_FROM_DATABASE");
if (!(str && *str)) {
@ -143,20 +149,21 @@ static void fill_item(struct impl *this, struct item *item, struct udev_device *
}
}
if (str && *str) {
spa_pod_builder_add(builder, "s", "device.vendor.name", "s", str, 0);
add_dict(builder, "device.vendor.name", str);
}
if ((str = udev_device_get_property_value(item->udevice, "ID_MODEL_ID")) && *str) {
spa_pod_builder_add(builder, "s", "device.product.id", "s", str, 0);
add_dict(builder, "device.product.id", str);
}
spa_pod_builder_add(builder, "s", "device.product.name", "s", name, 0);
add_dict(builder, "device.product.name", name);
if ((str = udev_device_get_property_value(item->udevice, "ID_SERIAL")) && *str) {
spa_pod_builder_add(builder, "s", "device.serial", "s", str, 0);
add_dict(builder, "device.serial", str);
}
if ((str = udev_device_get_property_value(item->udevice, "ID_V4L_CAPABILITIES")) && *str) {
spa_pod_builder_add(builder, "s", "device.capabilities", "s", str, 0);
add_dict(builder, "device.capabilities", str);
}
*result = spa_pod_builder_add(builder, "]}", NULL);
spa_pod_builder_pop(builder);
*result = spa_pod_builder_pop(builder);
}
static void impl_on_fd_events(struct spa_source *source)
@ -187,7 +194,7 @@ static void impl_on_fd_events(struct spa_source *source)
return;
spa_pod_builder_init(&b, buffer, sizeof(buffer));
event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, id);
event = spa_pod_builder_object(&b, SPA_TYPE_EVENT_Monitor, id, 0);
fill_item(this, &this->uitem, dev, &item, &b);
this->callbacks->event(this->callbacks_data, event);

View file

@ -164,8 +164,10 @@ static int impl_node_enum_params(struct spa_node *node,
SPA_PARAM_Props };
if (*index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id,
":", SPA_PARAM_LIST_id, "I", list[*index]);
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]),
0);
else
return 0;
break;
@ -178,23 +180,26 @@ static int impl_node_enum_params(struct spa_node *node,
case 0:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_PropInfo, id,
":", SPA_PROP_INFO_id, "I", SPA_PROP_device,
":", SPA_PROP_INFO_name, "s", "The V4L2 device",
":", SPA_PROP_INFO_type, "S", p->device, sizeof(p->device));
SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_device),
SPA_PROP_INFO_name, &SPA_POD_Stringc("The V4L2 device"),
SPA_PROP_INFO_type, &SPA_POD_Stringv(p->device),
0);
break;
case 1:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_PropInfo, id,
":", SPA_PROP_INFO_id, "I", SPA_PROP_deviceName,
":", SPA_PROP_INFO_name, "s", "The V4L2 device name",
":", SPA_PROP_INFO_type, "S-r", p->device_name, sizeof(p->device_name));
SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_deviceName),
SPA_PROP_INFO_name, &SPA_POD_Stringc("The V4L2 device name"),
SPA_PROP_INFO_type, &SPA_POD_Stringv(p->device_name),
0);
break;
case 2:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_PropInfo, id,
":", SPA_PROP_INFO_id, "I", SPA_PROP_deviceFd,
":", SPA_PROP_INFO_name, "s", "The V4L2 fd",
":", SPA_PROP_INFO_type, "i-r", p->device_fd);
SPA_PROP_INFO_id, &SPA_POD_Id(SPA_PROP_deviceFd),
SPA_PROP_INFO_name, &SPA_POD_Stringc("The V4L2 fd"),
SPA_PROP_INFO_type, &SPA_POD_Int(p->device_fd),
0);
break;
default:
return 0;
@ -209,9 +214,10 @@ static int impl_node_enum_params(struct spa_node *node,
case 0:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_Props, id,
":", SPA_PROP_device, "S", p->device, sizeof(p->device),
":", SPA_PROP_deviceName, "S-r", p->device_name, sizeof(p->device_name),
":", SPA_PROP_deviceFd, "i-r", p->device_fd);
SPA_PROP_device, &SPA_POD_Stringv(p->device),
SPA_PROP_deviceName, &SPA_POD_Stringv(p->device_name),
SPA_PROP_deviceFd, &SPA_POD_Int(p->device_fd),
0);
break;
default:
return 0;
@ -250,7 +256,7 @@ static int impl_node_set_param(struct spa_node *node,
return 0;
}
spa_pod_object_parse(param,
":", SPA_PROP_device, "?S", p->device, sizeof(p->device), NULL);
SPA_PROP_device, "?S", p->device, sizeof(p->device), NULL);
break;
}
default:
@ -395,28 +401,31 @@ static int port_get_format(struct spa_node *node,
return 0;
spa_pod_builder_push_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_Format);
spa_pod_builder_add(builder,
":", SPA_FORMAT_mediaType, "I", port->current_format.media_type,
":", SPA_FORMAT_mediaSubtype, "I", port->current_format.media_subtype, 0);
spa_pod_builder_props(builder,
SPA_FORMAT_mediaType, &SPA_POD_Id(port->current_format.media_type),
SPA_FORMAT_mediaSubtype, &SPA_POD_Id(port->current_format.media_subtype),
0);
switch (port->current_format.media_subtype) {
case SPA_MEDIA_SUBTYPE_raw:
spa_pod_builder_add(builder,
":", SPA_FORMAT_VIDEO_format, "I", port->current_format.info.raw.format,
":", SPA_FORMAT_VIDEO_size, "R", &port->current_format.info.raw.size,
":", SPA_FORMAT_VIDEO_framerate, "F", &port->current_format.info.raw.framerate, 0);
spa_pod_builder_props(builder,
SPA_FORMAT_VIDEO_format, &SPA_POD_Id(port->current_format.info.raw.format),
SPA_FORMAT_VIDEO_size, &SPA_POD_Rectangle(port->current_format.info.raw.size),
SPA_FORMAT_VIDEO_framerate, &SPA_POD_Fraction(port->current_format.info.raw.framerate),
0);
break;
case SPA_MEDIA_SUBTYPE_mjpg:
case SPA_MEDIA_SUBTYPE_jpeg:
spa_pod_builder_add(builder,
":", SPA_FORMAT_VIDEO_size, "R", &port->current_format.info.mjpg.size,
":", SPA_FORMAT_VIDEO_framerate, "F", &port->current_format.info.mjpg.framerate, 0);
spa_pod_builder_props(builder,
SPA_FORMAT_VIDEO_size, &SPA_POD_Rectangle(port->current_format.info.mjpg.size),
SPA_FORMAT_VIDEO_framerate, &SPA_POD_Fraction(port->current_format.info.mjpg.framerate),
0);
break;
case SPA_MEDIA_SUBTYPE_h264:
spa_pod_builder_add(builder,
":", SPA_FORMAT_VIDEO_size, "R", &port->current_format.info.h264.size,
":", SPA_FORMAT_VIDEO_framerate, "F", &port->current_format.info.h264.framerate, 0);
spa_pod_builder_props(builder,
SPA_FORMAT_VIDEO_size, &SPA_POD_Rectangle(port->current_format.info.h264.size),
SPA_FORMAT_VIDEO_framerate, &SPA_POD_Fraction(port->current_format.info.h264.framerate),
0);
break;
default:
return -EIO;
@ -467,8 +476,10 @@ static int impl_node_port_enum_params(struct spa_node *node,
SPA_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_object(&b, SPA_TYPE_OBJECT_ParamList, id,
":", SPA_PARAM_LIST_id, "I", list[*index]);
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamList, id,
SPA_PARAM_LIST_id, &SPA_POD_Id(list[*index]),
0);
else
return 0;
break;
@ -491,12 +502,12 @@ static int impl_node_port_enum_params(struct spa_node *node,
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamBuffers, id,
":", SPA_PARAM_BUFFERS_buffers, "iru", MAX_BUFFERS,
SPA_POD_PROP_MIN_MAX(2, MAX_BUFFERS),
":", SPA_PARAM_BUFFERS_blocks, "i", 1,
":", SPA_PARAM_BUFFERS_size, "i", port->fmt.fmt.pix.sizeimage,
":", SPA_PARAM_BUFFERS_stride, "i", port->fmt.fmt.pix.bytesperline,
":", SPA_PARAM_BUFFERS_align, "i", 16);
SPA_PARAM_BUFFERS_buffers, &SPA_POD_CHOICE_RANGE_Int(MAX_BUFFERS, 2, MAX_BUFFERS),
SPA_PARAM_BUFFERS_blocks, &SPA_POD_Int(1),
SPA_PARAM_BUFFERS_size, &SPA_POD_Int(port->fmt.fmt.pix.sizeimage),
SPA_PARAM_BUFFERS_stride, &SPA_POD_Int(port->fmt.fmt.pix.bytesperline),
SPA_PARAM_BUFFERS_align, &SPA_POD_Int(16),
0);
break;
case SPA_PARAM_Meta:
@ -504,8 +515,9 @@ static int impl_node_port_enum_params(struct spa_node *node,
case 0:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamMeta, id,
":", SPA_PARAM_META_type, "I", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
SPA_PARAM_META_type, &SPA_POD_Id(SPA_META_Header),
SPA_PARAM_META_size, &SPA_POD_Int(sizeof(struct spa_meta_header)),
0);
break;
default:
return 0;
@ -516,20 +528,23 @@ static int impl_node_port_enum_params(struct spa_node *node,
case 0:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
":", SPA_PARAM_IO_id, "I", SPA_IO_Buffers,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers));
SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Buffers),
SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_buffers)),
0);
break;
case 1:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
":", SPA_PARAM_IO_id, "I", SPA_IO_Clock,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_clock));
SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Clock),
SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_clock)),
0);
break;
case 2:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
":", SPA_PARAM_IO_id, "I", SPA_IO_Control,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_sequence));
SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Control),
SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_sequence)),
0);
break;
default:
return 0;
@ -813,20 +828,19 @@ static int process_control(struct impl *this, struct port *port, struct spa_pod_
switch (c->type) {
case SPA_CONTROL_Properties:
{
struct spa_pod *pod;
struct spa_pod_prop *prop;
struct spa_pod_object *obj = (struct spa_pod_object *) &c->value;
SPA_POD_OBJECT_FOREACH(obj, pod) {
struct spa_pod_prop *prop = (struct spa_pod_prop *)pod;
SPA_POD_OBJECT_FOREACH(obj, prop) {
struct v4l2_control c;
uint32_t control_id;
if ((control_id = prop_to_control_id(prop->body.key)) == 0)
if ((control_id = prop_to_control_id(prop->key)) == 0)
continue;
memset (&c, 0, sizeof (c));
c.id = control_id;
c.value = SPA_POD_VALUE(struct spa_pod_float, &prop->body.value);
c.value = SPA_POD_VALUE(struct spa_pod_float, &prop->value);
if (ioctl(port->fd, VIDIOC_S_CTRL, &c) < 0)
spa_log_error(port->log, "VIDIOC_S_CTRL %m");

View file

@ -403,24 +403,26 @@ enum_filter_format(uint32_t media_type, int32_t media_subtype,
case SPA_MEDIA_TYPE_image:
if (media_subtype == SPA_MEDIA_SUBTYPE_raw) {
struct spa_pod_prop *p;
uint32_t n_values;
const struct spa_pod *val;
uint32_t n_values, choice;
const uint32_t *values;
if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_format)))
return SPA_VIDEO_FORMAT_UNKNOWN;
if (p->body.value.type != SPA_TYPE_Enum)
val = spa_pod_get_values(&p->value, &n_values, &choice);
if (val->type != SPA_TYPE_Id)
return SPA_VIDEO_FORMAT_UNKNOWN;
values = SPA_POD_BODY_CONST(&p->body.value);
n_values = SPA_POD_PROP_N_VALUES(p);
values = SPA_POD_BODY(val);
if (p->body.flags & SPA_POD_PROP_FLAG_UNSET) {
if (index + 1 < n_values)
video_format = values[index + 1];
} else {
if (choice == SPA_CHOICE_None) {
if (index == 0)
video_format = values[0];
} else {
if (index + 1 < n_values)
video_format = values[index + 1];
}
} else {
if (index == 0)
@ -527,7 +529,7 @@ spa_v4l2_enum_format(struct impl *this,
struct port *port = &this->out_ports[0];
int res, n_fractions;
const struct format_info *info;
struct spa_pod_prop *prop;
struct spa_pod_choice *choice;
uint32_t filter_media_type, filter_media_subtype, video_format;
if ((res = spa_v4l2_open(this)) < 0)
@ -590,18 +592,19 @@ spa_v4l2_enum_format(struct impl *this,
while (port->next_frmsize) {
if (filter) {
struct spa_pod_prop *p;
struct spa_pod *val;
uint32_t n_vals, choice;
/* check if we have a fixed frame size */
if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_size)))
goto do_frmsize;
if (p->body.value.type != SPA_TYPE_Rectangle) {
val = spa_pod_get_values(&p->value, &n_vals, &choice);
if (val->type != SPA_TYPE_Rectangle)
goto enum_end;
}
if (!(p->body.flags & SPA_POD_PROP_FLAG_UNSET)) {
const struct spa_rectangle *values =
SPA_POD_BODY_CONST(&p->body.value);
if (choice == SPA_CHOICE_None) {
const struct spa_rectangle *values = SPA_POD_BODY(val);
if (port->frmsize.index > 0)
goto next_fmtdesc;
@ -623,25 +626,27 @@ spa_v4l2_enum_format(struct impl *this,
}
if (filter) {
struct spa_pod_prop *p;
struct spa_pod *val;
const struct spa_rectangle step = { 1, 1 }, *values;
uint32_t range;
uint32_t i, n_values;
uint32_t choice, i, n_values;
/* check if we have a fixed frame size */
if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_size)))
goto have_size;
range = p->body.flags & SPA_POD_PROP_RANGE_MASK;
values = SPA_POD_BODY_CONST(&p->body.value);
n_values = SPA_POD_PROP_N_VALUES(p);
val = spa_pod_get_values(&p->value, &n_values, &choice);
if (val->type != SPA_TYPE_Rectangle)
goto have_size;
if (range == SPA_POD_PROP_RANGE_MIN_MAX && n_values > 2) {
values = SPA_POD_BODY_CONST(val);
if (choice == SPA_CHOICE_Range && n_values > 2) {
if (filter_framesize(&port->frmsize, &values[1], &values[2], &step))
goto have_size;
} else if (range == SPA_POD_PROP_RANGE_STEP && n_values > 3) {
} else if (choice == SPA_CHOICE_Step && n_values > 3) {
if (filter_framesize(&port->frmsize, &values[1], &values[2], &values[3]))
goto have_size;
} else if (range == SPA_POD_PROP_RANGE_ENUM) {
} else if (choice == SPA_CHOICE_Enum) {
for (i = 1; i < n_values; i++) {
if (filter_framesize(&port->frmsize, &values[i], &values[i], &step))
goto have_size;
@ -675,23 +680,24 @@ spa_v4l2_enum_format(struct impl *this,
}
spa_pod_builder_push_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat);
spa_pod_builder_add(builder,
":", SPA_FORMAT_mediaType, "I", info->media_type,
":", SPA_FORMAT_mediaSubtype, "I", info->media_subtype, 0);
spa_pod_builder_props(builder,
SPA_FORMAT_mediaType, &SPA_POD_Id(info->media_type),
SPA_FORMAT_mediaSubtype, &SPA_POD_Id(info->media_subtype),
0);
if (info->media_subtype == SPA_MEDIA_SUBTYPE_raw) {
spa_pod_builder_add(builder,
":", SPA_FORMAT_VIDEO_format, "I", info->format, 0);
spa_pod_builder_prop(builder, SPA_FORMAT_VIDEO_format, 0);
spa_pod_builder_id(builder, info->format);
}
spa_pod_builder_add(builder,
":", SPA_FORMAT_VIDEO_size, "R", &SPA_RECTANGLE(port->frmsize.discrete.width,
port->frmsize.discrete.height), 0);
spa_pod_builder_prop(builder, SPA_FORMAT_VIDEO_size, 0);
spa_pod_builder_rectangle(builder, port->frmsize.discrete.width, port->frmsize.discrete.height);
spa_pod_builder_prop(builder, SPA_FORMAT_VIDEO_framerate, 0);
prop = spa_pod_builder_deref(builder,
spa_pod_builder_push_prop(builder, SPA_FORMAT_VIDEO_framerate,
SPA_POD_PROP_RANGE_NONE | SPA_POD_PROP_FLAG_UNSET));
n_fractions = 0;
choice = spa_pod_builder_deref(builder,
spa_pod_builder_push_choice(builder, SPA_CHOICE_None, 0));
port->frmival.index = 0;
while (true) {
@ -709,34 +715,44 @@ spa_v4l2_enum_format(struct impl *this,
}
if (filter) {
struct spa_pod_prop *p;
uint32_t range;
uint32_t i, n_values;
struct spa_pod *val;
uint32_t i, n_values, choice;
const struct spa_fraction step = { 1, 1 }, *values;
if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_framerate)))
goto have_framerate;
if (p->body.value.type != SPA_TYPE_Fraction)
val = spa_pod_get_values(&p->value, &n_values, &choice);
if (val->type != SPA_TYPE_Fraction)
goto enum_end;
range = p->body.flags & SPA_POD_PROP_RANGE_MASK;
values = SPA_POD_BODY_CONST(&p->body.value);
n_values = SPA_POD_PROP_N_VALUES(p);
values = SPA_POD_BODY(val);
if (!(p->body.flags & SPA_POD_PROP_FLAG_UNSET)) {
switch (choice) {
case SPA_CHOICE_None:
if (filter_framerate(&port->frmival, &values[0], &values[0], &step))
goto have_framerate;
} else if (range == SPA_POD_PROP_RANGE_MIN_MAX && n_values > 2) {
if (filter_framerate(&port->frmival, &values[1], &values[2], &step))
break;
case SPA_CHOICE_Range:
if (n_values > 2 && filter_framerate(&port->frmival, &values[1], &values[2], &step))
goto have_framerate;
} else if (range == SPA_POD_PROP_RANGE_STEP && n_values > 3) {
if (filter_framerate(&port->frmival, &values[1], &values[2], &values[3]))
break;
case SPA_CHOICE_Step:
if (n_values > 3 && filter_framerate(&port->frmival, &values[1], &values[2], &values[3]))
goto have_framerate;
} else if (range == SPA_POD_PROP_RANGE_ENUM) {
break;
case SPA_CHOICE_Enum:
for (i = 1; i < n_values; i++) {
if (filter_framerate(&port->frmival, &values[i], &values[i], &step))
goto have_framerate;
}
break;
default:
break;
}
port->frmival.index++;
continue;
@ -745,7 +761,7 @@ spa_v4l2_enum_format(struct impl *this,
have_framerate:
if (port->frmival.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
prop->body.flags |= SPA_POD_PROP_RANGE_ENUM;
choice->body.type = SPA_CHOICE_Enum;
if (n_fractions == 0)
spa_pod_builder_fraction(builder,
port->frmival.discrete.denominator,
@ -766,9 +782,9 @@ spa_v4l2_enum_format(struct impl *this,
port->frmival.stepwise.max.numerator);
if (port->frmival.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) {
prop->body.flags |= SPA_POD_PROP_RANGE_MIN_MAX;
choice->body.type = SPA_CHOICE_Range;
} else {
prop->body.flags |= SPA_POD_PROP_RANGE_STEP;
choice->body.type = SPA_CHOICE_Step;
spa_pod_builder_fraction(builder,
port->frmival.stepwise.step.denominator,
port->frmival.stepwise.step.numerator);
@ -780,9 +796,9 @@ spa_v4l2_enum_format(struct impl *this,
}
n_fractions++;
}
if (n_fractions <= 1) {
prop->body.flags &= ~(SPA_POD_PROP_RANGE_MASK | SPA_POD_PROP_FLAG_UNSET);
}
if (n_fractions <= 1)
choice->body.type = SPA_CHOICE_None;
spa_pod_builder_pop(builder);
*result = spa_pod_builder_pop(builder);
@ -1052,35 +1068,38 @@ spa_v4l2_enum_controls(struct impl *this,
case V4L2_CTRL_TYPE_INTEGER:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo,
":", SPA_PROP_INFO_id, "I", prop_id,
":", SPA_PROP_INFO_type, "isu", queryctrl.default_value,
SPA_POD_PROP_STEP(queryctrl.minimum,
queryctrl.maximum,
queryctrl.step),
":", SPA_PROP_INFO_name, "s", queryctrl.name);
SPA_PROP_INFO_id, &SPA_POD_Id(prop_id),
SPA_PROP_INFO_type, &SPA_POD_CHOICE_STEP_Int(
queryctrl.default_value,
queryctrl.minimum,
queryctrl.maximum,
queryctrl.step),
SPA_PROP_INFO_name, &SPA_POD_Stringv(queryctrl.name),
0);
break;
case V4L2_CTRL_TYPE_BOOLEAN:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo,
":", SPA_PROP_INFO_id, "I", prop_id,
":", SPA_PROP_INFO_type, "b-u", queryctrl.default_value,
":", SPA_PROP_INFO_name, "s", queryctrl.name);
SPA_PROP_INFO_id, &SPA_POD_Id(prop_id),
SPA_PROP_INFO_type, &SPA_POD_CHOICE_Bool(queryctrl.default_value),
SPA_PROP_INFO_name, &SPA_POD_Stringv(queryctrl.name),
0);
break;
case V4L2_CTRL_TYPE_MENU:
{
struct v4l2_querymenu querymenu;
spa_pod_builder_push_object(&b, SPA_TYPE_OBJECT_PropInfo, SPA_PARAM_PropInfo);
spa_pod_builder_add(&b,
":", SPA_PROP_INFO_id, "I", prop_id,
":", SPA_PROP_INFO_type, "i-u", queryctrl.default_value,
":", SPA_PROP_INFO_name, "s", queryctrl.name,
NULL);
spa_pod_builder_props(&b,
SPA_PROP_INFO_id, &SPA_POD_Id(prop_id),
SPA_PROP_INFO_type, &SPA_POD_CHOICE_ENUM_Int(1, queryctrl.default_value),
SPA_PROP_INFO_name, &SPA_POD_Stringv(queryctrl.name),
0);
spa_zero(querymenu);
querymenu.id = queryctrl.id;
spa_pod_builder_push_prop(&b, SPA_PROP_INFO_labels, 0);
spa_pod_builder_prop(&b, SPA_PROP_INFO_labels, 0);
spa_pod_builder_push_struct(&b);
for (querymenu.index = queryctrl.minimum;
querymenu.index <= queryctrl.maximum;
@ -1091,7 +1110,6 @@ spa_v4l2_enum_controls(struct impl *this,
}
}
spa_pod_builder_pop(&b);
spa_pod_builder_pop(&b);
param = spa_pod_builder_pop(&b);
break;
}