mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
Use int counters for iterating items
Use counters instead of void* to iterate items. This simplifies some things and makes it easier to do over the wire. Add format description to NodeInfo and use this to add format descriptions to pinos devices. Small fixes to fix leaks and crashes.
This commit is contained in:
parent
8b84d8fde6
commit
b38ecafe81
38 changed files with 363 additions and 330 deletions
|
|
@ -61,6 +61,8 @@ struct _SpaV4l2Monitor {
|
|||
struct udev* udev;
|
||||
struct udev_monitor *umonitor;
|
||||
struct udev_enumerate *enumerate;
|
||||
unsigned int index;
|
||||
struct udev_list_entry *devices;
|
||||
|
||||
V4l2Item uitem;
|
||||
|
||||
|
|
@ -251,14 +253,13 @@ spa_v4l2_monitor_set_event_callback (SpaMonitor *monitor,
|
|||
static SpaResult
|
||||
spa_v4l2_monitor_enum_items (SpaMonitor *monitor,
|
||||
SpaMonitorItem **item,
|
||||
void **state)
|
||||
unsigned int index)
|
||||
{
|
||||
SpaResult res;
|
||||
SpaV4l2Monitor *this;
|
||||
struct udev_list_entry *devices;
|
||||
struct udev_device *dev;
|
||||
|
||||
if (monitor == NULL || item == NULL || state == NULL)
|
||||
if (monitor == NULL || item == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = SPA_CONTAINER_OF (monitor, SpaV4l2Monitor, monitor);
|
||||
|
|
@ -266,7 +267,7 @@ spa_v4l2_monitor_enum_items (SpaMonitor *monitor,
|
|||
if ((res = v4l2_udev_open (this)) < 0)
|
||||
return res;
|
||||
|
||||
if (*state == NULL) {
|
||||
if (index == 0) {
|
||||
if (this->enumerate)
|
||||
udev_enumerate_unref (this->enumerate);
|
||||
this->enumerate = udev_enumerate_new (this->udev);
|
||||
|
|
@ -274,20 +275,20 @@ spa_v4l2_monitor_enum_items (SpaMonitor *monitor,
|
|||
udev_enumerate_add_match_subsystem (this->enumerate, "video4linux");
|
||||
udev_enumerate_scan_devices (this->enumerate);
|
||||
|
||||
devices = udev_enumerate_get_list_entry (this->enumerate);
|
||||
if (devices == NULL)
|
||||
return SPA_RESULT_ENUM_END;
|
||||
} else {
|
||||
devices = *state;
|
||||
this->devices = udev_enumerate_get_list_entry (this->enumerate);
|
||||
this->index = 0;
|
||||
}
|
||||
|
||||
if (*state == (void*)1) {
|
||||
while (index > this->index && this->devices) {
|
||||
this->devices = udev_list_entry_get_next (this->devices);
|
||||
this->index++;
|
||||
}
|
||||
if (this->devices == NULL) {
|
||||
fill_item (&this->uitem, NULL);
|
||||
return SPA_RESULT_ENUM_END;
|
||||
}
|
||||
|
||||
dev = udev_device_new_from_syspath (this->udev,
|
||||
udev_list_entry_get_name (devices));
|
||||
udev_list_entry_get_name (this->devices));
|
||||
|
||||
fill_item (&this->uitem, dev);
|
||||
if (dev == NULL)
|
||||
|
|
@ -295,8 +296,8 @@ spa_v4l2_monitor_enum_items (SpaMonitor *monitor,
|
|||
|
||||
*item = &this->uitem.item;
|
||||
|
||||
if ((*state = udev_list_entry_get_next (devices)) == NULL)
|
||||
*state = (void*)1;
|
||||
this->devices = udev_list_entry_get_next (this->devices);
|
||||
this->index++;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -383,20 +384,15 @@ static const SpaInterfaceInfo v4l2_monitor_interfaces[] =
|
|||
static SpaResult
|
||||
v4l2_monitor_enum_interface_info (const SpaHandleFactory *factory,
|
||||
const SpaInterfaceInfo **info,
|
||||
void **state)
|
||||
unsigned int index)
|
||||
{
|
||||
int index;
|
||||
|
||||
if (factory == NULL || info == NULL || state == NULL)
|
||||
if (factory == NULL || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
index = (*state == NULL ? 0 : *(int*)state);
|
||||
|
||||
if (index < 0 || index >= SPA_N_ELEMENTS (v4l2_monitor_interfaces))
|
||||
return SPA_RESULT_ENUM_END;
|
||||
|
||||
*info = &v4l2_monitor_interfaces[index];
|
||||
*(int*)state = ++index;
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -98,7 +98,6 @@ typedef struct {
|
|||
bool next_frmsize;
|
||||
struct v4l2_frmsizeenum frmsize;
|
||||
struct v4l2_frmivalenum frmival;
|
||||
void *cookie;
|
||||
|
||||
V4l2Format format[2];
|
||||
V4l2Format *current_format;
|
||||
|
|
@ -484,8 +483,8 @@ spa_v4l2_source_node_remove_port (SpaNode *node,
|
|||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static void
|
||||
spa_v4l2_format_init (V4l2Format *f)
|
||||
static SpaResult
|
||||
spa_v4l2_format_init (V4l2Format *f, const SpaFormat *sf)
|
||||
{
|
||||
f->fmt.props.n_prop_info = 3;
|
||||
f->fmt.props.prop_info = f->infos;
|
||||
|
|
@ -499,6 +498,11 @@ spa_v4l2_format_init (V4l2Format *f)
|
|||
spa_prop_info_fill_video (&f->infos[2],
|
||||
SPA_PROP_ID_VIDEO_FRAMERATE,
|
||||
offsetof (V4l2Format, framerate));
|
||||
|
||||
f->fmt.media_type = sf->media_type;
|
||||
f->fmt.media_subtype = sf->media_subtype;
|
||||
|
||||
return spa_props_copy_values (&sf->props, &f->fmt.props);
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -507,21 +511,20 @@ spa_v4l2_source_node_port_enum_formats (SpaNode *node,
|
|||
uint32_t port_id,
|
||||
SpaFormat **format,
|
||||
const SpaFormat *filter,
|
||||
void **state)
|
||||
unsigned int index)
|
||||
{
|
||||
SpaV4l2Source *this;
|
||||
SpaResult res;
|
||||
|
||||
if (node == NULL || format == NULL || state == NULL)
|
||||
if (node == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
|
||||
|
||||
spa_log_debug (this->log, "%p %d %d", this, direction, port_id);
|
||||
if (!CHECK_PORT (this, direction, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
res = spa_v4l2_enum_format (this, format, filter, state);
|
||||
res = spa_v4l2_enum_format (this, format, filter, index);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
@ -537,7 +540,6 @@ spa_v4l2_source_node_port_set_format (SpaNode *node,
|
|||
SpaV4l2State *state;
|
||||
SpaResult res;
|
||||
V4l2Format *f, *tf;
|
||||
size_t fs;
|
||||
|
||||
if (node == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -560,13 +562,9 @@ spa_v4l2_source_node_port_set_format (SpaNode *node,
|
|||
|
||||
f = &state->format[0];
|
||||
tf = &state->format[1];
|
||||
fs = sizeof (V4l2Format);
|
||||
|
||||
if ((SpaFormat*)f != format) {
|
||||
spa_v4l2_format_init (f);
|
||||
f->fmt.media_type = format->media_type;
|
||||
f->fmt.media_subtype = format->media_subtype;
|
||||
if ((res = spa_props_copy_values (&format->props, &f->fmt.props) < 0))
|
||||
if ((res = spa_v4l2_format_init (f, format)) < 0)
|
||||
return res;
|
||||
} else {
|
||||
f = (V4l2Format*)format;
|
||||
|
|
@ -590,7 +588,8 @@ spa_v4l2_source_node_port_set_format (SpaNode *node,
|
|||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
|
||||
memcpy (tf, f, fs);
|
||||
if ((res = spa_v4l2_format_init (tf, &f->fmt)) < 0)
|
||||
return res;
|
||||
state->current_format = tf;
|
||||
|
||||
update_state (this, SPA_NODE_STATE_READY);
|
||||
|
|
@ -1019,20 +1018,15 @@ static const SpaInterfaceInfo v4l2_source_interfaces[] =
|
|||
static SpaResult
|
||||
v4l2_source_enum_interface_info (const SpaHandleFactory *factory,
|
||||
const SpaInterfaceInfo **info,
|
||||
void **state)
|
||||
unsigned int index)
|
||||
{
|
||||
int index;
|
||||
|
||||
if (factory == NULL || info == NULL || state == NULL)
|
||||
if (factory == NULL || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
index = (*state == NULL ? 0 : *(int*)state);
|
||||
|
||||
if (index < 0 || index >= SPA_N_ELEMENTS (v4l2_source_interfaces))
|
||||
return SPA_RESULT_ENUM_END;
|
||||
|
||||
*info = &v4l2_source_interfaces[index];
|
||||
*(int*)state = ++index;
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -447,7 +447,10 @@ filter_framerate (struct v4l2_frmivalenum *frmival,
|
|||
#define FOURCC_ARGS(f) (f)&0x7f,((f)>>8)&0x7f,((f)>>16)&0x7f,((f)>>24)&0x7f
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_enum_format (SpaV4l2Source *this, SpaFormat **format, const SpaFormat *filter, void **cookie)
|
||||
spa_v4l2_enum_format (SpaV4l2Source *this,
|
||||
SpaFormat **format,
|
||||
const SpaFormat *filter,
|
||||
unsigned int index)
|
||||
{
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
int res, i, pi;
|
||||
|
|
@ -459,7 +462,7 @@ spa_v4l2_enum_format (SpaV4l2Source *this, SpaFormat **format, const SpaFormat *
|
|||
|
||||
*format = NULL;
|
||||
|
||||
if (*cookie == NULL) {
|
||||
if (index == 0) {
|
||||
CLEAR (state->fmtdesc);
|
||||
state->fmtdesc.index = 0;
|
||||
state->fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
|
|
@ -467,7 +470,6 @@ spa_v4l2_enum_format (SpaV4l2Source *this, SpaFormat **format, const SpaFormat *
|
|||
CLEAR (state->frmsize);
|
||||
state->next_frmsize = true;
|
||||
CLEAR (state->frmival);
|
||||
*cookie = state;
|
||||
}
|
||||
|
||||
if (false) {
|
||||
|
|
|
|||
|
|
@ -25,15 +25,11 @@ extern const SpaHandleFactory spa_v4l2_monitor_factory;
|
|||
|
||||
SpaResult
|
||||
spa_enum_handle_factory (const SpaHandleFactory **factory,
|
||||
void **state)
|
||||
unsigned int index)
|
||||
{
|
||||
int index;
|
||||
|
||||
if (factory == NULL || state == NULL)
|
||||
if (factory == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
index = (*state == NULL ? 0 : *(int*)state);
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
*factory = &spa_v4l2_source_factory;
|
||||
|
|
@ -44,7 +40,5 @@ spa_enum_handle_factory (const SpaHandleFactory **factory,
|
|||
default:
|
||||
return SPA_RESULT_ENUM_END;
|
||||
}
|
||||
*(int*)state = ++index;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue