mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
Remove dynamic types
Do not use dynamic types anymore. The reason is that it's difficult: - to maintain a shared type database over a network. - the extra overhead when translating between processes and for maintaining the translation tables. - race conditions in translating in RT-threads, this is a problem because we want to make event streams. We now have simple enums with types and extension points for all types. This is also nicer to use in general. We don't need the mapper anymore or pass strings around as types. There is a parallel type info system to get more info about ids and enums and their hierarchy. It can also be used for debugging.
This commit is contained in:
parent
e6977fa178
commit
fca3e1d85d
162 changed files with 5200 additions and 7461 deletions
|
|
@ -27,9 +27,9 @@
|
|||
#include <libudev.h>
|
||||
|
||||
#include <spa/support/log.h>
|
||||
#include <spa/support/type-map.h>
|
||||
#include <spa/support/loop.h>
|
||||
#include <spa/support/plugin.h>
|
||||
#include <spa/utils/type.h>
|
||||
#include <spa/monitor/monitor.h>
|
||||
|
||||
#define NAME "v4l2-monitor"
|
||||
|
|
@ -40,23 +40,10 @@ struct item {
|
|||
struct udev_device *udevice;
|
||||
};
|
||||
|
||||
struct type {
|
||||
uint32_t handle_factory;
|
||||
struct spa_type_monitor monitor;
|
||||
};
|
||||
|
||||
static inline void init_type(struct type *type, struct spa_type_map *map)
|
||||
{
|
||||
type->handle_factory = spa_type_map_get_id(map, SPA_TYPE__HandleFactory);
|
||||
spa_type_monitor_map(map, &type->monitor);
|
||||
}
|
||||
|
||||
struct impl {
|
||||
struct spa_handle handle;
|
||||
struct spa_monitor monitor;
|
||||
|
||||
struct type type;
|
||||
struct spa_type_map *map;
|
||||
struct spa_log *log;
|
||||
struct spa_loop *main_loop;
|
||||
|
||||
|
|
@ -90,7 +77,6 @@ static void fill_item(struct impl *this, struct item *item, struct udev_device *
|
|||
struct spa_pod **result, struct spa_pod_builder *builder)
|
||||
{
|
||||
const char *str, *name;
|
||||
struct type *t = &this->type;
|
||||
|
||||
if (item->udevice)
|
||||
udev_device_unref(item->udevice);
|
||||
|
|
@ -112,14 +98,14 @@ static void fill_item(struct impl *this, struct item *item, struct udev_device *
|
|||
name = "Unknown";
|
||||
|
||||
spa_pod_builder_add(builder,
|
||||
"<", 0, t->monitor.MonitorItem,
|
||||
":", t->monitor.id, "s", udev_device_get_syspath(item->udevice),
|
||||
":", t->monitor.flags, "i", 0,
|
||||
":", t->monitor.state, "i", SPA_MONITOR_ITEM_STATE_AVAILABLE,
|
||||
":", t->monitor.name, "s", name,
|
||||
":", t->monitor.klass, "s", "Video/Source",
|
||||
":", t->monitor.factory, "p", t->handle_factory, &spa_v4l2_source_factory,
|
||||
":", t->monitor.info, "[",
|
||||
"<", 0, SPA_ID_OBJECT_MonitorItem,
|
||||
":", 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_ID_INTERFACE_HandleFactory, &spa_v4l2_source_factory,
|
||||
":", SPA_MONITOR_ITEM_info, "[",
|
||||
NULL);
|
||||
|
||||
spa_pod_builder_add(builder,
|
||||
|
|
@ -192,11 +178,11 @@ static void impl_on_fd_events(struct spa_source *source)
|
|||
action = "change";
|
||||
|
||||
if (strcmp(action, "add") == 0) {
|
||||
type = this->type.monitor.Added;
|
||||
type = SPA_ID_EVENT_MONITOR_Added;
|
||||
} else if (strcmp(action, "change") == 0) {
|
||||
type = this->type.monitor.Changed;
|
||||
type = SPA_ID_EVENT_MONITOR_Changed;
|
||||
} else if (strcmp(action, "remove") == 0) {
|
||||
type = this->type.monitor.Removed;
|
||||
type = SPA_ID_EVENT_MONITOR_Removed;
|
||||
} else
|
||||
return;
|
||||
|
||||
|
|
@ -314,7 +300,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
|
|||
|
||||
this = (struct impl *) handle;
|
||||
|
||||
if (interface_id == this->type.monitor.Monitor)
|
||||
if (interface_id == SPA_ID_INTERFACE_Monitor)
|
||||
*interface = &this->monitor;
|
||||
else
|
||||
return -ENOENT;
|
||||
|
|
@ -364,22 +350,15 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this = (struct impl *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
|
||||
if (support[i].type == SPA_ID_INTERFACE_Log)
|
||||
this->log = support[i].data;
|
||||
else if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
|
||||
else if (support[i].type == SPA_ID_INTERFACE_MainLoop)
|
||||
this->main_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error(this->log, "a type-map is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (this->main_loop == NULL) {
|
||||
spa_log_error(this->log, "a main-loop is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
init_type(&this->type, this->map);
|
||||
|
||||
this->monitor = impl_monitor;
|
||||
|
||||
|
|
@ -387,7 +366,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
}
|
||||
|
||||
static const struct spa_interface_info impl_interfaces[] = {
|
||||
{SPA_TYPE__Monitor,},
|
||||
{SPA_ID_INTERFACE_Monitor,},
|
||||
};
|
||||
|
||||
static int
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
#include <spa/support/type-map.h>
|
||||
#include <spa/support/log.h>
|
||||
#include <spa/support/loop.h>
|
||||
#include <spa/utils/list.h>
|
||||
|
|
@ -66,71 +65,6 @@ struct buffer {
|
|||
void *ptr;
|
||||
};
|
||||
|
||||
struct type {
|
||||
uint32_t node;
|
||||
uint32_t format;
|
||||
uint32_t props;
|
||||
uint32_t prop_unknown;
|
||||
uint32_t prop_device;
|
||||
uint32_t prop_device_name;
|
||||
uint32_t prop_device_fd;
|
||||
uint32_t prop_brightness;
|
||||
uint32_t prop_contrast;
|
||||
uint32_t prop_saturation;
|
||||
uint32_t prop_hue;
|
||||
uint32_t prop_gamma;
|
||||
uint32_t prop_exposure;
|
||||
uint32_t prop_gain;
|
||||
uint32_t prop_sharpness;
|
||||
struct spa_type_io io;
|
||||
struct spa_type_param param;
|
||||
struct spa_type_media_type media_type;
|
||||
struct spa_type_media_subtype media_subtype;
|
||||
struct spa_type_media_subtype_video media_subtype_video;
|
||||
struct spa_type_format_video format_video;
|
||||
struct spa_type_video_format video_format;
|
||||
struct spa_type_event_node event_node;
|
||||
struct spa_type_command_node command_node;
|
||||
struct spa_type_param_buffers param_buffers;
|
||||
struct spa_type_param_meta param_meta;
|
||||
struct spa_type_param_io param_io;
|
||||
struct spa_type_meta meta;
|
||||
struct spa_type_data data;
|
||||
};
|
||||
|
||||
static inline void init_type(struct type *type, struct spa_type_map *map)
|
||||
{
|
||||
type->node = spa_type_map_get_id(map, SPA_TYPE__Node);
|
||||
type->format = spa_type_map_get_id(map, SPA_TYPE__Format);
|
||||
type->props = spa_type_map_get_id(map, SPA_TYPE__Props);
|
||||
type->prop_unknown = spa_type_map_get_id(map, SPA_TYPE_PROPS__unknown);
|
||||
type->prop_device = spa_type_map_get_id(map, SPA_TYPE_PROPS__device);
|
||||
type->prop_device_name = spa_type_map_get_id(map, SPA_TYPE_PROPS__deviceName);
|
||||
type->prop_device_fd = spa_type_map_get_id(map, SPA_TYPE_PROPS__deviceFd);
|
||||
type->prop_brightness = spa_type_map_get_id(map, SPA_TYPE_PROPS__brightness);
|
||||
type->prop_contrast = spa_type_map_get_id(map, SPA_TYPE_PROPS__contrast);
|
||||
type->prop_saturation = spa_type_map_get_id(map, SPA_TYPE_PROPS__saturation);
|
||||
type->prop_hue = spa_type_map_get_id(map, SPA_TYPE_PROPS__hue);
|
||||
type->prop_gamma = spa_type_map_get_id(map, SPA_TYPE_PROPS__gamma);
|
||||
type->prop_exposure = spa_type_map_get_id(map, SPA_TYPE_PROPS__exposure);
|
||||
type->prop_gain = spa_type_map_get_id(map, SPA_TYPE_PROPS__gain);
|
||||
type->prop_sharpness = spa_type_map_get_id(map, SPA_TYPE_PROPS__sharpness);
|
||||
spa_type_meta_map(map, &type->meta);
|
||||
spa_type_data_map(map, &type->data);
|
||||
spa_type_media_type_map(map, &type->media_type);
|
||||
spa_type_media_subtype_map(map, &type->media_subtype);
|
||||
spa_type_media_subtype_video_map(map, &type->media_subtype_video);
|
||||
spa_type_format_video_map(map, &type->format_video);
|
||||
spa_type_video_format_map(map, &type->video_format);
|
||||
spa_type_event_node_map(map, &type->event_node);
|
||||
spa_type_command_node_map(map, &type->command_node);
|
||||
spa_type_param_map(map, &type->param);
|
||||
spa_type_param_buffers_map(map, &type->param_buffers);
|
||||
spa_type_param_meta_map(map, &type->param_meta);
|
||||
spa_type_io_map(map, &type->io);
|
||||
spa_type_param_io_map(map, &type->param_io);
|
||||
}
|
||||
|
||||
#define MAX_CONTROLS 64
|
||||
|
||||
struct control {
|
||||
|
|
@ -184,9 +118,7 @@ struct impl {
|
|||
struct spa_handle handle;
|
||||
struct spa_node node;
|
||||
|
||||
struct spa_type_map *map;
|
||||
struct spa_log *log;
|
||||
struct type type;
|
||||
|
||||
uint32_t seq;
|
||||
|
||||
|
|
@ -212,7 +144,6 @@ static int impl_node_enum_params(struct spa_node *node,
|
|||
struct spa_pod_builder *builder)
|
||||
{
|
||||
struct impl *this;
|
||||
struct type *t;
|
||||
struct spa_pod *param;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
uint8_t buffer[1024];
|
||||
|
|
@ -222,67 +153,74 @@ static int impl_node_enum_params(struct spa_node *node,
|
|||
spa_return_val_if_fail(builder != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
t = &this->type;
|
||||
|
||||
next:
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
|
||||
if (id == t->param.idList) {
|
||||
uint32_t list[] = { t->param.idPropInfo,
|
||||
t->param.idProps };
|
||||
switch (id) {
|
||||
case SPA_ID_PARAM_List:
|
||||
{
|
||||
uint32_t list[] = { SPA_ID_PARAM_PropInfo,
|
||||
SPA_ID_PARAM_Props };
|
||||
|
||||
if (*index < SPA_N_ELEMENTS(list))
|
||||
param = spa_pod_builder_object(&b, id, t->param.List,
|
||||
":", t->param.listId, "I", list[*index]);
|
||||
param = spa_pod_builder_object(&b, id, SPA_ID_OBJECT_ParamList,
|
||||
":", SPA_PARAM_LIST_id, "I", list[*index]);
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
else if (id == t->param.idPropInfo) {
|
||||
case SPA_ID_PARAM_PropInfo:
|
||||
{
|
||||
struct props *p = &this->props;
|
||||
|
||||
switch (*index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param.PropInfo,
|
||||
":", t->param.propId, "I", t->prop_device,
|
||||
":", t->param.propName, "s", "The V4L2 device",
|
||||
":", t->param.propType, "S", p->device, sizeof(p->device));
|
||||
id, SPA_ID_OBJECT_PropInfo,
|
||||
":", 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));
|
||||
break;
|
||||
case 1:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param.PropInfo,
|
||||
":", t->param.propId, "I", t->prop_device_name,
|
||||
":", t->param.propName, "s", "The V4L2 device name",
|
||||
":", t->param.propType, "S-r", p->device_name, sizeof(p->device_name));
|
||||
id, SPA_ID_OBJECT_PropInfo,
|
||||
":", 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));
|
||||
break;
|
||||
case 2:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param.PropInfo,
|
||||
":", t->param.propId, "I", t->prop_device_fd,
|
||||
":", t->param.propName, "s", "The V4L2 fd",
|
||||
":", t->param.propType, "i-r", p->device_fd);
|
||||
id, SPA_ID_OBJECT_PropInfo,
|
||||
":", 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);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (id == t->param.idProps) {
|
||||
case SPA_ID_PARAM_Props:
|
||||
{
|
||||
struct props *p = &this->props;
|
||||
|
||||
switch (*index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->props,
|
||||
":", t->prop_device, "S", p->device, sizeof(p->device),
|
||||
":", t->prop_device_name, "S-r", p->device_name, sizeof(p->device_name),
|
||||
":", t->prop_device_fd, "i-r", p->device_fd);
|
||||
id, SPA_ID_OBJECT_Props,
|
||||
":", 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);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
default:
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
(*index)++;
|
||||
|
||||
|
|
@ -297,14 +235,14 @@ static int impl_node_set_param(struct spa_node *node,
|
|||
const struct spa_pod *param)
|
||||
{
|
||||
struct impl *this;
|
||||
struct type *t;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
t = &this->type;
|
||||
|
||||
if (id == t->param.idProps) {
|
||||
switch (id) {
|
||||
case SPA_ID_PARAM_Props:
|
||||
{
|
||||
struct props *p = &this->props;
|
||||
|
||||
if (param == NULL) {
|
||||
|
|
@ -312,11 +250,12 @@ static int impl_node_set_param(struct spa_node *node,
|
|||
return 0;
|
||||
}
|
||||
spa_pod_object_parse(param,
|
||||
":", t->prop_device, "?S", p->device, sizeof(p->device), NULL);
|
||||
":", SPA_PROP_device, "?S", p->device, sizeof(p->device), NULL);
|
||||
break;
|
||||
}
|
||||
else
|
||||
default:
|
||||
return -ENOENT;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -330,7 +269,9 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
|
|||
|
||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
|
||||
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
|
||||
switch (SPA_COMMAND_TYPE(command)) {
|
||||
case SPA_ID_COMMAND_NODE_Start:
|
||||
{
|
||||
struct port *port = GET_OUT_PORT(this, 0);
|
||||
|
||||
if (!port->have_format)
|
||||
|
|
@ -340,12 +281,15 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
|
|||
|
||||
if ((res = spa_v4l2_stream_on(this)) < 0)
|
||||
return res;
|
||||
|
||||
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
|
||||
break;
|
||||
}
|
||||
case SPA_ID_COMMAND_NODE_Pause:
|
||||
if ((res = spa_v4l2_stream_off(this)) < 0)
|
||||
return res;
|
||||
} else
|
||||
break;
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -443,7 +387,6 @@ static int port_get_format(struct spa_node *node,
|
|||
struct spa_pod_builder *builder)
|
||||
{
|
||||
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
struct type *t = &this->type;
|
||||
struct port *port = GET_PORT(this, direction, port_id);
|
||||
|
||||
if (!port->have_format)
|
||||
|
|
@ -451,28 +394,33 @@ static int port_get_format(struct spa_node *node,
|
|||
if (*index > 0)
|
||||
return 0;
|
||||
|
||||
spa_pod_builder_push_object(builder, t->param.idFormat, t->format);
|
||||
spa_pod_builder_push_object(builder, SPA_ID_PARAM_Format, SPA_ID_OBJECT_Format);
|
||||
|
||||
spa_pod_builder_add(builder,
|
||||
"I", port->current_format.media_type,
|
||||
"I", port->current_format.media_subtype, 0);
|
||||
|
||||
if (port->current_format.media_subtype == t->media_subtype.raw) {
|
||||
switch (port->current_format.media_subtype) {
|
||||
case SPA_MEDIA_SUBTYPE_raw:
|
||||
spa_pod_builder_add(builder,
|
||||
":", t->format_video.format, "I", port->current_format.info.raw.format,
|
||||
":", t->format_video.size, "R", &port->current_format.info.raw.size,
|
||||
":", t->format_video.framerate, "F", &port->current_format.info.raw.framerate, 0);
|
||||
} else if (port->current_format.media_subtype == t->media_subtype_video.mjpg ||
|
||||
port->current_format.media_subtype == t->media_subtype_video.jpeg) {
|
||||
":", 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);
|
||||
break;
|
||||
case SPA_MEDIA_SUBTYPE_mjpg:
|
||||
case SPA_MEDIA_SUBTYPE_jpeg:
|
||||
spa_pod_builder_add(builder,
|
||||
":", t->format_video.size, "R", &port->current_format.info.mjpg.size,
|
||||
":", t->format_video.framerate, "F", &port->current_format.info.mjpg.framerate, 0);
|
||||
} else if (port->current_format.media_subtype == t->media_subtype_video.h264) {
|
||||
":", SPA_FORMAT_VIDEO_size, "R", &port->current_format.info.mjpg.size,
|
||||
":", SPA_FORMAT_VIDEO_framerate, "F", &port->current_format.info.mjpg.framerate, 0);
|
||||
break;
|
||||
case SPA_MEDIA_SUBTYPE_h264:
|
||||
spa_pod_builder_add(builder,
|
||||
":", t->format_video.size, "R", &port->current_format.info.h264.size,
|
||||
":", t->format_video.framerate, "F", &port->current_format.info.h264.framerate, 0);
|
||||
} else
|
||||
":", SPA_FORMAT_VIDEO_size, "R", &port->current_format.info.h264.size,
|
||||
":", SPA_FORMAT_VIDEO_framerate, "F", &port->current_format.info.h264.framerate, 0);
|
||||
break;
|
||||
default:
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
*param = spa_pod_builder_pop(builder);
|
||||
|
||||
|
|
@ -490,7 +438,6 @@ static int impl_node_port_enum_params(struct spa_node *node,
|
|||
|
||||
struct impl *this;
|
||||
struct port *port;
|
||||
struct type *t;
|
||||
struct spa_pod *param;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
uint8_t buffer[1024];
|
||||
|
|
@ -501,7 +448,6 @@ static int impl_node_port_enum_params(struct spa_node *node,
|
|||
spa_return_val_if_fail(builder != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
t = &this->type;
|
||||
|
||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||
|
||||
|
|
@ -510,81 +456,87 @@ static int impl_node_port_enum_params(struct spa_node *node,
|
|||
next:
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
|
||||
if (id == t->param.idList) {
|
||||
uint32_t list[] = { t->param.idEnumFormat,
|
||||
t->param.idFormat,
|
||||
t->param.idBuffers,
|
||||
t->param.idMeta,
|
||||
t->param_io.idPropsIn };
|
||||
switch (id) {
|
||||
case SPA_ID_PARAM_List:
|
||||
{
|
||||
uint32_t list[] = { SPA_ID_PARAM_PropInfo,
|
||||
SPA_ID_PARAM_EnumFormat,
|
||||
SPA_ID_PARAM_Format,
|
||||
SPA_ID_PARAM_Buffers,
|
||||
SPA_ID_PARAM_Meta,
|
||||
SPA_ID_PARAM_IO };
|
||||
|
||||
if (*index < SPA_N_ELEMENTS(list))
|
||||
param = spa_pod_builder_object(&b, id, t->param.List,
|
||||
":", t->param.listId, "I", list[*index]);
|
||||
param = spa_pod_builder_object(&b, id, SPA_ID_OBJECT_ParamList,
|
||||
":", SPA_PARAM_LIST_id, "I", list[*index]);
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
else if (id == t->param.idEnumFormat) {
|
||||
case SPA_ID_PARAM_PropInfo:
|
||||
return spa_v4l2_enum_controls(this, index, filter, result, builder);
|
||||
|
||||
case SPA_ID_PARAM_EnumFormat:
|
||||
return spa_v4l2_enum_format(this, index, filter, result, builder);
|
||||
}
|
||||
else if (id == t->param.idFormat) {
|
||||
|
||||
case SPA_ID_PARAM_Format:
|
||||
if((res = port_get_format(node, direction, port_id, index, filter, ¶m, &b)) <= 0)
|
||||
return res;
|
||||
}
|
||||
else if (id == t->param.idBuffers) {
|
||||
break;
|
||||
case SPA_ID_PARAM_Buffers:
|
||||
if (!port->have_format)
|
||||
return -EIO;
|
||||
if (*index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_buffers.Buffers,
|
||||
":", t->param_buffers.size, "i", port->fmt.fmt.pix.sizeimage,
|
||||
":", t->param_buffers.stride, "i", port->fmt.fmt.pix.bytesperline,
|
||||
":", t->param_buffers.buffers, "iru", MAX_BUFFERS,
|
||||
id, SPA_ID_OBJECT_ParamBuffers,
|
||||
":", SPA_PARAM_BUFFERS_buffers, "iru", MAX_BUFFERS,
|
||||
SPA_POD_PROP_MIN_MAX(2, MAX_BUFFERS),
|
||||
":", t->param_buffers.align, "i", 16);
|
||||
}
|
||||
else if (id == t->param.idMeta) {
|
||||
":", 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);
|
||||
break;
|
||||
|
||||
case SPA_ID_PARAM_Meta:
|
||||
switch (*index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_meta.Meta,
|
||||
":", t->param_meta.type, "I", t->meta.Header,
|
||||
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
|
||||
id, SPA_ID_OBJECT_ParamMeta,
|
||||
":", SPA_PARAM_META_type, "I", SPA_META_Header,
|
||||
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#if 0
|
||||
else if (id == t->param_io.idPropsIn) {
|
||||
return spa_v4l2_enum_controls(this, index, filter, result, builder);
|
||||
}
|
||||
else if (id == t->param_io.idBuffers) {
|
||||
#endif
|
||||
case SPA_ID_PARAM_IO:
|
||||
switch (*index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_io.Buffers,
|
||||
":", t->param_io.id, "I", t->io.Buffers,
|
||||
":", t->param_io.size, "i", sizeof(struct spa_io_buffers));
|
||||
id, SPA_ID_OBJECT_ParamIO,
|
||||
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Buffers,
|
||||
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers));
|
||||
break;
|
||||
case 1:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, SPA_ID_OBJECT_ParamIO,
|
||||
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Clock,
|
||||
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_clock));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (id == t->param_io.idClock) {
|
||||
switch (*index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_io.Clock,
|
||||
":", t->param_io.id, "I", t->io.Clock,
|
||||
":", t->param_io.size, "i", sizeof(struct spa_io_clock));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
default:
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
(*index)++;
|
||||
|
||||
|
|
@ -601,7 +553,6 @@ static int port_set_format(struct spa_node *node,
|
|||
{
|
||||
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
struct spa_video_info info;
|
||||
struct type *t = &this->type;
|
||||
struct port *port = GET_PORT(this, direction, port_id);
|
||||
|
||||
if (format == NULL) {
|
||||
|
|
@ -615,13 +566,14 @@ static int port_set_format(struct spa_node *node,
|
|||
"I", &info.media_type,
|
||||
"I", &info.media_subtype);
|
||||
|
||||
if (info.media_type != t->media_type.video) {
|
||||
if (info.media_type != SPA_MEDIA_TYPE_video) {
|
||||
spa_log_error(this->log, "media type must be video");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (info.media_subtype == t->media_subtype.raw) {
|
||||
if (spa_format_video_raw_parse(format, &info.info.raw, &t->format_video) < 0) {
|
||||
switch (info.media_subtype) {
|
||||
case SPA_MEDIA_SUBTYPE_raw:
|
||||
if (spa_format_video_raw_parse(format, &info.info.raw) < 0) {
|
||||
spa_log_error(this->log, "can't parse video raw");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
@ -632,8 +584,9 @@ static int port_set_format(struct spa_node *node,
|
|||
info.info.raw.size.width == port->current_format.info.raw.size.width &&
|
||||
info.info.raw.size.height == port->current_format.info.raw.size.height)
|
||||
return 0;
|
||||
} else if (info.media_subtype == t->media_subtype_video.mjpg) {
|
||||
if (spa_format_video_mjpg_parse(format, &info.info.mjpg, &t->format_video) < 0)
|
||||
break;
|
||||
case SPA_MEDIA_SUBTYPE_mjpg:
|
||||
if (spa_format_video_mjpg_parse(format, &info.info.mjpg) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (port->have_format && info.media_type == port->current_format.media_type &&
|
||||
|
|
@ -641,8 +594,9 @@ static int port_set_format(struct spa_node *node,
|
|||
info.info.mjpg.size.width == port->current_format.info.mjpg.size.width &&
|
||||
info.info.mjpg.size.height == port->current_format.info.mjpg.size.height)
|
||||
return 0;
|
||||
} else if (info.media_subtype == t->media_subtype_video.h264) {
|
||||
if (spa_format_video_h264_parse(format, &info.info.h264, &t->format_video) < 0)
|
||||
break;
|
||||
case SPA_MEDIA_SUBTYPE_h264:
|
||||
if (spa_format_video_h264_parse(format, &info.info.h264) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (port->have_format && info.media_type == port->current_format.media_type &&
|
||||
|
|
@ -650,6 +604,9 @@ static int port_set_format(struct spa_node *node,
|
|||
info.info.h264.size.width == port->current_format.info.h264.size.width &&
|
||||
info.info.h264.size.height == port->current_format.info.h264.size.height)
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -674,17 +631,11 @@ static int impl_node_port_set_param(struct spa_node *node,
|
|||
uint32_t id, uint32_t flags,
|
||||
const struct spa_pod *param)
|
||||
{
|
||||
struct impl *this;
|
||||
struct type *t;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
t = &this->type;
|
||||
spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL);
|
||||
|
||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||
|
||||
if (id == t->param.idFormat) {
|
||||
if (id == SPA_ID_PARAM_Format) {
|
||||
return port_set_format(node, direction, port_id, flags, param);
|
||||
}
|
||||
else
|
||||
|
|
@ -772,23 +723,21 @@ static int impl_node_port_set_io(struct spa_node *node,
|
|||
void *data, size_t size)
|
||||
{
|
||||
struct impl *this;
|
||||
struct type *t;
|
||||
struct port *port;
|
||||
struct control *control;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
t = &this->type;
|
||||
|
||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||
|
||||
port = GET_PORT(this, direction, port_id);
|
||||
|
||||
if (id == t->io.Buffers) {
|
||||
if (id == SPA_ID_IO_Buffers) {
|
||||
port->io = data;
|
||||
}
|
||||
else if (id == t->io.Clock) {
|
||||
else if (id == SPA_ID_IO_Clock) {
|
||||
port->clock = data;
|
||||
}
|
||||
else if ((control = find_control(port, id))) {
|
||||
|
|
@ -934,7 +883,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
|
|||
|
||||
this = (struct impl *) handle;
|
||||
|
||||
if (interface_id == this->type.node)
|
||||
if (interface_id == SPA_ID_INTERFACE_Node)
|
||||
*interface = &this->node;
|
||||
else
|
||||
return -ENOENT;
|
||||
|
|
@ -976,19 +925,13 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
port = GET_OUT_PORT(this, 0);
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
|
||||
if (support[i].type == SPA_ID_INTERFACE_Log)
|
||||
this->log = support[i].data;
|
||||
else if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
|
||||
else if (support[i].type == SPA_ID_INTERFACE_MainLoop)
|
||||
port->main_loop = support[i].data;
|
||||
else if (strcmp(support[i].type, SPA_TYPE_LOOP__DataLoop) == 0)
|
||||
else if (support[i].type == SPA_ID_INTERFACE_DataLoop)
|
||||
port->data_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error(this->log, "a type-map is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (port->main_loop == NULL) {
|
||||
spa_log_error(this->log, "a main_loop is needed");
|
||||
return -EINVAL;
|
||||
|
|
@ -997,7 +940,6 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
spa_log_error(this->log, "a data_loop is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
init_type(&this->type, this->map);
|
||||
|
||||
this->node = impl_node;
|
||||
|
||||
|
|
@ -1023,7 +965,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
}
|
||||
|
||||
static const struct spa_interface_info impl_interfaces[] = {
|
||||
{SPA_TYPE__Node,},
|
||||
{SPA_ID_INTERFACE_Node,},
|
||||
};
|
||||
|
||||
static int impl_enum_interface_info(const struct spa_handle_factory *factory,
|
||||
|
|
|
|||
|
|
@ -190,59 +190,59 @@ static int spa_v4l2_close(struct impl *this)
|
|||
|
||||
struct format_info {
|
||||
uint32_t fourcc;
|
||||
off_t format_offset;
|
||||
off_t media_type_offset;
|
||||
off_t media_subtype_offset;
|
||||
uint32_t format;
|
||||
uint32_t media_type;
|
||||
uint32_t media_subtype;
|
||||
};
|
||||
|
||||
#define VIDEO offsetof(struct type, media_type.video)
|
||||
#define IMAGE offsetof(struct type, media_type.image)
|
||||
#define VIDEO SPA_MEDIA_TYPE_video
|
||||
#define IMAGE SPA_MEDIA_TYPE_image
|
||||
|
||||
#define RAW offsetof(struct type, media_subtype.raw)
|
||||
#define RAW SPA_MEDIA_SUBTYPE_raw
|
||||
|
||||
#define BAYER offsetof(struct type, media_subtype_video.bayer)
|
||||
#define MJPG offsetof(struct type, media_subtype_video.mjpg)
|
||||
#define JPEG offsetof(struct type, media_subtype_video.jpeg)
|
||||
#define DV offsetof(struct type, media_subtype_video.dv)
|
||||
#define MPEGTS offsetof(struct type, media_subtype_video.mpegts)
|
||||
#define H264 offsetof(struct type, media_subtype_video.h264)
|
||||
#define H263 offsetof(struct type, media_subtype_video.h263)
|
||||
#define MPEG1 offsetof(struct type, media_subtype_video.mpeg1)
|
||||
#define MPEG2 offsetof(struct type, media_subtype_video.mpeg2)
|
||||
#define MPEG4 offsetof(struct type, media_subtype_video.mpeg4)
|
||||
#define XVID offsetof(struct type, media_subtype_video.xvid)
|
||||
#define VC1 offsetof(struct type, media_subtype_video.vc1)
|
||||
#define VP8 offsetof(struct type, media_subtype_video.vp8)
|
||||
#define BAYER SPA_MEDIA_SUBTYPE_bayer
|
||||
#define MJPG SPA_MEDIA_SUBTYPE_mjpg
|
||||
#define JPEG SPA_MEDIA_SUBTYPE_jpeg
|
||||
#define DV SPA_MEDIA_SUBTYPE_dv
|
||||
#define MPEGTS SPA_MEDIA_SUBTYPE_mpegts
|
||||
#define H264 SPA_MEDIA_SUBTYPE_h264
|
||||
#define H263 SPA_MEDIA_SUBTYPE_h263
|
||||
#define MPEG1 SPA_MEDIA_SUBTYPE_mpeg1
|
||||
#define MPEG2 SPA_MEDIA_SUBTYPE_mpeg2
|
||||
#define MPEG4 SPA_MEDIA_SUBTYPE_mpeg4
|
||||
#define XVID SPA_MEDIA_SUBTYPE_xvid
|
||||
#define VC1 SPA_MEDIA_SUBTYPE_vc1
|
||||
#define VP8 SPA_MEDIA_SUBTYPE_vp8
|
||||
|
||||
#define FORMAT_UNKNOWN offsetof(struct type, video_format.UNKNOWN)
|
||||
#define FORMAT_ENCODED offsetof(struct type, video_format.ENCODED)
|
||||
#define FORMAT_RGB15 offsetof(struct type, video_format.RGB15)
|
||||
#define FORMAT_BGR15 offsetof(struct type, video_format.BGR15)
|
||||
#define FORMAT_RGB16 offsetof(struct type, video_format.RGB16)
|
||||
#define FORMAT_BGR offsetof(struct type, video_format.BGR)
|
||||
#define FORMAT_RGB offsetof(struct type, video_format.RGB)
|
||||
#define FORMAT_BGRA offsetof(struct type, video_format.BGRA)
|
||||
#define FORMAT_BGRx offsetof(struct type, video_format.BGRx)
|
||||
#define FORMAT_ARGB offsetof(struct type, video_format.ARGB)
|
||||
#define FORMAT_xRGB offsetof(struct type, video_format.xRGB)
|
||||
#define FORMAT_GRAY8 offsetof(struct type, video_format.GRAY8)
|
||||
#define FORMAT_GRAY16_LE offsetof(struct type, video_format.GRAY16_LE)
|
||||
#define FORMAT_GRAY16_BE offsetof(struct type, video_format.GRAY16_BE)
|
||||
#define FORMAT_YVU9 offsetof(struct type, video_format.YVU9)
|
||||
#define FORMAT_YV12 offsetof(struct type, video_format.YV12)
|
||||
#define FORMAT_YUY2 offsetof(struct type, video_format.YUY2)
|
||||
#define FORMAT_YVYU offsetof(struct type, video_format.YVYU)
|
||||
#define FORMAT_UYVY offsetof(struct type, video_format.UYVY)
|
||||
#define FORMAT_Y42B offsetof(struct type, video_format.Y42B)
|
||||
#define FORMAT_Y41B offsetof(struct type, video_format.Y41B)
|
||||
#define FORMAT_YUV9 offsetof(struct type, video_format.YUV9)
|
||||
#define FORMAT_I420 offsetof(struct type, video_format.I420)
|
||||
#define FORMAT_NV12 offsetof(struct type, video_format.NV12)
|
||||
#define FORMAT_NV12_64Z32 offsetof(struct type, video_format.NV12_64Z32)
|
||||
#define FORMAT_NV21 offsetof(struct type, video_format.NV21)
|
||||
#define FORMAT_NV16 offsetof(struct type, video_format.NV16)
|
||||
#define FORMAT_NV61 offsetof(struct type, video_format.NV61)
|
||||
#define FORMAT_NV24 offsetof(struct type, video_format.NV24)
|
||||
#define FORMAT_UNKNOWN SPA_VIDEO_FORMAT_UNKNOWN
|
||||
#define FORMAT_ENCODED SPA_VIDEO_FORMAT_ENCODED
|
||||
#define FORMAT_RGB15 SPA_VIDEO_FORMAT_RGB15
|
||||
#define FORMAT_BGR15 SPA_VIDEO_FORMAT_BGR15
|
||||
#define FORMAT_RGB16 SPA_VIDEO_FORMAT_RGB16
|
||||
#define FORMAT_BGR SPA_VIDEO_FORMAT_BGR
|
||||
#define FORMAT_RGB SPA_VIDEO_FORMAT_RGB
|
||||
#define FORMAT_BGRA SPA_VIDEO_FORMAT_BGRA
|
||||
#define FORMAT_BGRx SPA_VIDEO_FORMAT_BGRx
|
||||
#define FORMAT_ARGB SPA_VIDEO_FORMAT_ARGB
|
||||
#define FORMAT_xRGB SPA_VIDEO_FORMAT_xRGB
|
||||
#define FORMAT_GRAY8 SPA_VIDEO_FORMAT_GRAY8
|
||||
#define FORMAT_GRAY16_LE SPA_VIDEO_FORMAT_GRAY16_LE
|
||||
#define FORMAT_GRAY16_BE SPA_VIDEO_FORMAT_GRAY16_BE
|
||||
#define FORMAT_YVU9 SPA_VIDEO_FORMAT_YVU9
|
||||
#define FORMAT_YV12 SPA_VIDEO_FORMAT_YV12
|
||||
#define FORMAT_YUY2 SPA_VIDEO_FORMAT_YUY2
|
||||
#define FORMAT_YVYU SPA_VIDEO_FORMAT_YVYU
|
||||
#define FORMAT_UYVY SPA_VIDEO_FORMAT_UYVY
|
||||
#define FORMAT_Y42B SPA_VIDEO_FORMAT_Y42B
|
||||
#define FORMAT_Y41B SPA_VIDEO_FORMAT_Y41B
|
||||
#define FORMAT_YUV9 SPA_VIDEO_FORMAT_YUV9
|
||||
#define FORMAT_I420 SPA_VIDEO_FORMAT_I420
|
||||
#define FORMAT_NV12 SPA_VIDEO_FORMAT_NV12
|
||||
#define FORMAT_NV12_64Z32 SPA_VIDEO_FORMAT_NV12_64Z32
|
||||
#define FORMAT_NV21 SPA_VIDEO_FORMAT_NV21
|
||||
#define FORMAT_NV16 SPA_VIDEO_FORMAT_NV16
|
||||
#define FORMAT_NV61 SPA_VIDEO_FORMAT_NV61
|
||||
#define FORMAT_NV24 SPA_VIDEO_FORMAT_NV24
|
||||
|
||||
static const struct format_info format_info[] = {
|
||||
/* RGB formats */
|
||||
|
|
@ -376,8 +376,7 @@ static const struct format_info *video_format_to_format_info(uint32_t format)
|
|||
}
|
||||
#endif
|
||||
|
||||
static const struct format_info *find_format_info_by_media_type(struct type *types,
|
||||
uint32_t type,
|
||||
static const struct format_info *find_format_info_by_media_type(uint32_t type,
|
||||
uint32_t subtype,
|
||||
uint32_t format,
|
||||
int startidx)
|
||||
|
|
@ -385,37 +384,33 @@ static const struct format_info *find_format_info_by_media_type(struct type *typ
|
|||
int i;
|
||||
|
||||
for (i = startidx; i < SPA_N_ELEMENTS(format_info); i++) {
|
||||
uint32_t media_type, media_subtype, media_format;
|
||||
|
||||
media_type = *SPA_MEMBER(types, format_info[i].media_type_offset, uint32_t);
|
||||
media_subtype = *SPA_MEMBER(types, format_info[i].media_subtype_offset, uint32_t);
|
||||
media_format = *SPA_MEMBER(types, format_info[i].format_offset, uint32_t);
|
||||
|
||||
if ((media_type == type) &&
|
||||
(media_subtype == subtype) && (format == 0 || media_format == format))
|
||||
if ((format_info[i].media_type == type) &&
|
||||
(format_info[i].media_subtype == subtype) &&
|
||||
(format == 0 || format_info[i].format == format))
|
||||
return &format_info[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
enum_filter_format(struct type *type, uint32_t media_type, int32_t media_subtype,
|
||||
enum_filter_format(uint32_t media_type, int32_t media_subtype,
|
||||
const struct spa_pod *filter, uint32_t index)
|
||||
{
|
||||
uint32_t video_format = 0;
|
||||
|
||||
if ((media_type == type->media_type.video ||
|
||||
media_type == type->media_type.image)) {
|
||||
if (media_subtype == type->media_subtype.raw) {
|
||||
switch (media_type) {
|
||||
case SPA_MEDIA_TYPE_video:
|
||||
case SPA_MEDIA_TYPE_image:
|
||||
if (media_subtype == SPA_MEDIA_SUBTYPE_raw) {
|
||||
struct spa_pod_prop *p;
|
||||
uint32_t n_values;
|
||||
const uint32_t *values;
|
||||
|
||||
if (!(p = spa_pod_find_prop(filter, type->format_video.format)))
|
||||
return type->video_format.UNKNOWN;
|
||||
if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_format)))
|
||||
return SPA_VIDEO_FORMAT_UNKNOWN;
|
||||
|
||||
if (p->body.value.type != SPA_POD_TYPE_ID)
|
||||
return type->video_format.UNKNOWN;
|
||||
return SPA_VIDEO_FORMAT_UNKNOWN;
|
||||
|
||||
values = SPA_POD_BODY_CONST(&p->body.value);
|
||||
n_values = SPA_POD_PROP_N_VALUES(p);
|
||||
|
|
@ -429,7 +424,7 @@ enum_filter_format(struct type *type, uint32_t media_type, int32_t media_subtype
|
|||
}
|
||||
} else {
|
||||
if (index == 0)
|
||||
video_format = type->video_format.ENCODED;
|
||||
video_format = SPA_VIDEO_FORMAT_ENCODED;
|
||||
}
|
||||
}
|
||||
return video_format;
|
||||
|
|
@ -533,9 +528,7 @@ spa_v4l2_enum_format(struct impl *this,
|
|||
int res, n_fractions;
|
||||
const struct format_info *info;
|
||||
struct spa_pod_prop *prop;
|
||||
uint32_t media_type, media_subtype, video_format;
|
||||
uint32_t filter_media_type, filter_media_subtype;
|
||||
struct type *t = &this->type;
|
||||
uint32_t filter_media_type, filter_media_subtype, video_format;
|
||||
|
||||
if ((res = spa_v4l2_open(this)) < 0)
|
||||
return res;
|
||||
|
|
@ -564,16 +557,14 @@ spa_v4l2_enum_format(struct impl *this,
|
|||
|
||||
while (port->next_fmtdesc) {
|
||||
if (filter) {
|
||||
video_format = enum_filter_format(t,
|
||||
filter_media_type,
|
||||
video_format = enum_filter_format(filter_media_type,
|
||||
filter_media_subtype,
|
||||
filter, port->fmtdesc.index);
|
||||
|
||||
if (video_format == t->video_format.UNKNOWN)
|
||||
if (video_format == SPA_VIDEO_FORMAT_UNKNOWN)
|
||||
goto enum_end;
|
||||
|
||||
info = find_format_info_by_media_type(t,
|
||||
filter_media_type,
|
||||
info = find_format_info_by_media_type(filter_media_type,
|
||||
filter_media_subtype,
|
||||
video_format, 0);
|
||||
if (info == NULL)
|
||||
|
|
@ -602,7 +593,7 @@ spa_v4l2_enum_format(struct impl *this,
|
|||
struct spa_pod_prop *p;
|
||||
|
||||
/* check if we have a fixed frame size */
|
||||
if (!(p = spa_pod_find_prop(filter, t->format_video.size)))
|
||||
if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_size)))
|
||||
goto do_frmsize;
|
||||
|
||||
if (p->body.value.type != SPA_POD_TYPE_RECTANGLE) {
|
||||
|
|
@ -638,7 +629,7 @@ spa_v4l2_enum_format(struct impl *this,
|
|||
uint32_t i, n_values;
|
||||
|
||||
/* check if we have a fixed frame size */
|
||||
if (!(p = spa_pod_find_prop(filter, t->format_video.size)))
|
||||
if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_size)))
|
||||
goto have_size;
|
||||
|
||||
range = p->body.flags & SPA_POD_PROP_RANGE_MASK;
|
||||
|
|
@ -684,25 +675,21 @@ spa_v4l2_enum_format(struct impl *this,
|
|||
}
|
||||
}
|
||||
|
||||
media_type = *SPA_MEMBER(t, info->media_type_offset, uint32_t);
|
||||
media_subtype = *SPA_MEMBER(t, info->media_subtype_offset, uint32_t);
|
||||
video_format = *SPA_MEMBER(t, info->format_offset, uint32_t);
|
||||
|
||||
spa_pod_builder_push_object(builder, t->param.idEnumFormat, t->format);
|
||||
spa_pod_builder_push_object(builder, SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format);
|
||||
spa_pod_builder_add(builder,
|
||||
"I", media_type,
|
||||
"I", media_subtype, 0);
|
||||
"I", info->media_type,
|
||||
"I", info->media_subtype, 0);
|
||||
|
||||
if (media_subtype == t->media_subtype.raw) {
|
||||
if (info->media_subtype == SPA_MEDIA_SUBTYPE_raw) {
|
||||
spa_pod_builder_add(builder,
|
||||
":", t->format_video.format, "I", video_format, 0);
|
||||
":", SPA_FORMAT_VIDEO_format, "I", info->format, 0);
|
||||
}
|
||||
spa_pod_builder_add(builder,
|
||||
":", t->format_video.size, "R", &SPA_RECTANGLE(port->frmsize.discrete.width,
|
||||
port->frmsize.discrete.height), 0);
|
||||
":", SPA_FORMAT_VIDEO_size, "R", &SPA_RECTANGLE(port->frmsize.discrete.width,
|
||||
port->frmsize.discrete.height), 0);
|
||||
|
||||
prop = spa_pod_builder_deref(builder,
|
||||
spa_pod_builder_push_prop(builder, t->format_video.framerate,
|
||||
spa_pod_builder_push_prop(builder, SPA_FORMAT_VIDEO_framerate,
|
||||
SPA_POD_PROP_RANGE_NONE | SPA_POD_PROP_FLAG_UNSET));
|
||||
n_fractions = 0;
|
||||
|
||||
|
|
@ -727,7 +714,7 @@ spa_v4l2_enum_format(struct impl *this,
|
|||
uint32_t i, n_values;
|
||||
const struct spa_fraction step = { 1, 1 }, *values;
|
||||
|
||||
if (!(p = spa_pod_find_prop(filter, t->format_video.framerate)))
|
||||
if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_framerate)))
|
||||
goto have_framerate;
|
||||
|
||||
if (p->body.value.type != SPA_POD_TYPE_FRACTION)
|
||||
|
|
@ -824,32 +811,35 @@ static int spa_v4l2_set_format(struct impl *this, struct spa_video_info *format,
|
|||
uint32_t video_format;
|
||||
struct spa_rectangle *size = NULL;
|
||||
struct spa_fraction *framerate = NULL;
|
||||
struct type *t = &this->type;
|
||||
|
||||
spa_zero(fmt);
|
||||
spa_zero(streamparm);
|
||||
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
|
||||
if (format->media_subtype == this->type.media_subtype.raw) {
|
||||
switch (format->media_subtype) {
|
||||
case SPA_MEDIA_SUBTYPE_raw:
|
||||
video_format = format->info.raw.format;
|
||||
size = &format->info.raw.size;
|
||||
framerate = &format->info.raw.framerate;
|
||||
} else if (format->media_subtype == this->type.media_subtype_video.mjpg ||
|
||||
format->media_subtype == this->type.media_subtype_video.jpeg) {
|
||||
video_format = this->type.video_format.ENCODED;
|
||||
break;
|
||||
case SPA_MEDIA_SUBTYPE_mjpg:
|
||||
case SPA_MEDIA_SUBTYPE_jpeg:
|
||||
video_format = SPA_VIDEO_FORMAT_ENCODED;
|
||||
size = &format->info.mjpg.size;
|
||||
framerate = &format->info.mjpg.framerate;
|
||||
} else if (format->media_subtype == this->type.media_subtype_video.h264) {
|
||||
video_format = this->type.video_format.ENCODED;
|
||||
break;
|
||||
case SPA_MEDIA_SUBTYPE_h264:
|
||||
video_format = SPA_VIDEO_FORMAT_ENCODED;
|
||||
size = &format->info.h264.size;
|
||||
framerate = &format->info.h264.framerate;
|
||||
} else {
|
||||
video_format = this->type.video_format.ENCODED;
|
||||
break;
|
||||
default:
|
||||
video_format = SPA_VIDEO_FORMAT_ENCODED;
|
||||
break;
|
||||
}
|
||||
|
||||
info = find_format_info_by_media_type(t,
|
||||
format->media_type,
|
||||
info = find_format_info_by_media_type(format->media_type,
|
||||
format->media_subtype, video_format, 0);
|
||||
if (info == NULL || size == NULL || framerate == NULL) {
|
||||
spa_log_error(port->log, "v4l2: unknown media type %d %d %d", format->media_type,
|
||||
|
|
@ -965,23 +955,23 @@ static uint32_t control_to_prop_id(struct impl *impl, uint32_t control_id)
|
|||
{
|
||||
switch (control_id) {
|
||||
case V4L2_CID_BRIGHTNESS:
|
||||
return impl->type.prop_brightness;
|
||||
return SPA_PROP_brightness;
|
||||
case V4L2_CID_CONTRAST:
|
||||
return impl->type.prop_contrast;
|
||||
return SPA_PROP_contrast;
|
||||
case V4L2_CID_SATURATION:
|
||||
return impl->type.prop_saturation;
|
||||
return SPA_PROP_saturation;
|
||||
case V4L2_CID_HUE:
|
||||
return impl->type.prop_hue;
|
||||
return SPA_PROP_hue;
|
||||
case V4L2_CID_GAMMA:
|
||||
return impl->type.prop_gamma;
|
||||
return SPA_PROP_gamma;
|
||||
case V4L2_CID_EXPOSURE:
|
||||
return impl->type.prop_exposure;
|
||||
return SPA_PROP_exposure;
|
||||
case V4L2_CID_GAIN:
|
||||
return impl->type.prop_gain;
|
||||
return SPA_PROP_gain;
|
||||
case V4L2_CID_SHARPNESS:
|
||||
return impl->type.prop_sharpness;
|
||||
return SPA_PROP_sharpness;
|
||||
default:
|
||||
return impl->type.prop_unknown;
|
||||
return SPA_PROP_unknown;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -993,12 +983,10 @@ spa_v4l2_enum_controls(struct impl *this,
|
|||
struct spa_pod_builder *builder)
|
||||
{
|
||||
struct port *port = &this->out_ports[0];
|
||||
struct type *t = &this->type;
|
||||
struct v4l2_query_ext_ctrl queryctrl;
|
||||
struct spa_pod *param;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
char type_id[128];
|
||||
uint32_t id, prop_id, ctrl_id;
|
||||
uint32_t prop_id, ctrl_id;
|
||||
uint8_t buffer[1024];
|
||||
int res;
|
||||
const unsigned next_fl = V4L2_CTRL_FLAG_NEXT_CTRL | V4L2_CTRL_FLAG_NEXT_COMPOUND;
|
||||
|
|
@ -1051,12 +1039,9 @@ spa_v4l2_enum_controls(struct impl *this,
|
|||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
|
||||
snprintf(type_id, sizeof(type_id), SPA_TYPE_PARAM_IO_PROP_BASE"%08x", ctrl_id);
|
||||
id = spa_type_map_get_id(this->map, type_id);
|
||||
|
||||
prop_id = control_to_prop_id(this, ctrl_id);
|
||||
|
||||
port->controls[port->n_controls].id = id;
|
||||
port->controls[port->n_controls].id = prop_id;
|
||||
port->controls[port->n_controls].ctrl_id = ctrl_id;
|
||||
port->controls[port->n_controls].value = queryctrl.default_value;
|
||||
|
||||
|
|
@ -1067,42 +1052,36 @@ spa_v4l2_enum_controls(struct impl *this,
|
|||
switch (queryctrl.type) {
|
||||
case V4L2_CTRL_TYPE_INTEGER:
|
||||
param = spa_pod_builder_object(&b,
|
||||
t->param_io.idPropsIn, t->param_io.Prop,
|
||||
":", t->param_io.id, "I", id,
|
||||
":", t->param_io.size, "i", sizeof(struct spa_pod_int),
|
||||
":", t->param.propId, "I", prop_id,
|
||||
":", t->param.propType, "isu", queryctrl.default_value,
|
||||
3, queryctrl.minimum,
|
||||
queryctrl.maximum,
|
||||
queryctrl.step,
|
||||
":", t->param.propName, "s", queryctrl.name);
|
||||
SPA_ID_PARAM_PropInfo, SPA_ID_OBJECT_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);
|
||||
break;
|
||||
case V4L2_CTRL_TYPE_BOOLEAN:
|
||||
param = spa_pod_builder_object(&b,
|
||||
t->param_io.idPropsIn, t->param_io.Prop,
|
||||
":", t->param_io.id, "I", id,
|
||||
":", t->param_io.size, "i", sizeof(struct spa_pod_bool),
|
||||
":", t->param.propId, "I", prop_id,
|
||||
":", t->param.propType, "b-u", queryctrl.default_value,
|
||||
":", t->param.propName, "s", queryctrl.name);
|
||||
SPA_ID_PARAM_PropInfo, SPA_ID_OBJECT_PropInfo,
|
||||
":", SPA_PROP_INFO_id, "I", prop_id,
|
||||
":", SPA_PROP_INFO_type, "b-u", queryctrl.default_value,
|
||||
":", SPA_PROP_INFO_name, "s", queryctrl.name);
|
||||
break;
|
||||
case V4L2_CTRL_TYPE_MENU:
|
||||
{
|
||||
struct v4l2_querymenu querymenu;
|
||||
|
||||
spa_pod_builder_push_object(&b, t->param_io.idPropsIn, t->param_io.Prop);
|
||||
spa_pod_builder_push_object(&b, SPA_ID_PARAM_PropInfo, SPA_ID_OBJECT_PropInfo);
|
||||
spa_pod_builder_add(&b,
|
||||
":", t->param_io.id, "I", id,
|
||||
":", t->param_io.size, "i", sizeof(struct spa_pod_double),
|
||||
":", t->param.propId, "I", prop_id,
|
||||
":", t->param.propName, "s", queryctrl.name,
|
||||
":", t->param.propType, "i-u", queryctrl.default_value,
|
||||
":", 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_zero(querymenu);
|
||||
querymenu.id = queryctrl.id;
|
||||
|
||||
spa_pod_builder_push_prop(&b, t->param.propLabels, 0);
|
||||
spa_pod_builder_push_prop(&b, SPA_PROP_INFO_labels, 0);
|
||||
spa_pod_builder_push_struct(&b);
|
||||
for (querymenu.index = queryctrl.minimum;
|
||||
querymenu.index <= queryctrl.maximum;
|
||||
|
|
@ -1218,14 +1197,13 @@ static int spa_v4l2_use_buffers(struct impl *this, struct spa_buffer **buffers,
|
|||
if (n_buffers > 0) {
|
||||
d = buffers[0]->datas;
|
||||
|
||||
if (d[0].type == this->type.data.MemFd ||
|
||||
(d[0].type == this->type.data.MemPtr && d[0].data != NULL)) {
|
||||
if (d[0].type == SPA_DATA_MemFd ||
|
||||
(d[0].type == SPA_DATA_MemPtr && d[0].data != NULL)) {
|
||||
port->memtype = V4L2_MEMORY_USERPTR;
|
||||
} else if (d[0].type == this->type.data.DmaBuf) {
|
||||
} else if (d[0].type == SPA_DATA_DmaBuf) {
|
||||
port->memtype = V4L2_MEMORY_DMABUF;
|
||||
} else {
|
||||
spa_log_error(port->log, "v4l2: can't use buffers of type %s (%d)",
|
||||
spa_type_map_get_type (this->map, d[0].type), d[0].type);
|
||||
spa_log_error(port->log, "v4l2: can't use buffers of type %d", d[0].type);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
|
@ -1251,7 +1229,7 @@ static int spa_v4l2_use_buffers(struct impl *this, struct spa_buffer **buffers,
|
|||
b = &port->buffers[i];
|
||||
b->outbuf = buffers[i];
|
||||
b->flags = BUFFER_FLAG_OUTSTANDING;
|
||||
b->h = spa_buffer_find_meta_data(buffers[i], this->type.meta.Header, sizeof(*b->h));
|
||||
b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h));
|
||||
|
||||
spa_log_info(port->log, "v4l2: import buffer %p", buffers[i]);
|
||||
|
||||
|
|
@ -1345,7 +1323,7 @@ mmap_init(struct impl *this,
|
|||
b = &port->buffers[i];
|
||||
b->outbuf = buffers[i];
|
||||
b->flags = BUFFER_FLAG_OUTSTANDING;
|
||||
b->h = spa_buffer_find_meta_data(buffers[i], this->type.meta.Header, sizeof(*b->h));
|
||||
b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h));
|
||||
|
||||
spa_zero(b->v4l2_buffer);
|
||||
b->v4l2_buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
|
|
@ -1375,12 +1353,12 @@ mmap_init(struct impl *this,
|
|||
spa_log_error(port->log, "VIDIOC_EXPBUF: %m");
|
||||
continue;
|
||||
}
|
||||
d[0].type = this->type.data.DmaBuf;
|
||||
d[0].type = SPA_DATA_DmaBuf;
|
||||
d[0].fd = expbuf.fd;
|
||||
d[0].data = NULL;
|
||||
SPA_FLAG_SET(b->flags, BUFFER_FLAG_ALLOCATED);
|
||||
} else {
|
||||
d[0].type = this->type.data.MemPtr;
|
||||
d[0].type = SPA_DATA_MemPtr;
|
||||
d[0].fd = -1;
|
||||
d[0].data = mmap(NULL,
|
||||
b->v4l2_buffer.length,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue