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:
Wim Taymans 2017-02-01 08:58:21 +01:00
parent 8b84d8fde6
commit b38ecafe81
38 changed files with 363 additions and 330 deletions

View file

@ -81,8 +81,8 @@ connection_add_fd (PinosConnection *conn,
return index; return index;
} }
#if 0 #if 1
#define PINOS_DEBUG_MESSAGE(format,args...) pinos_log_debug(stderr, format,##args) #define PINOS_DEBUG_MESSAGE(format,args...) pinos_log_debug(format,##args)
#else #else
#define PINOS_DEBUG_MESSAGE(format,args...) #define PINOS_DEBUG_MESSAGE(format,args...)
#endif #endif
@ -200,6 +200,7 @@ connection_parse_node_info (PinosConnection *conn, PinosMessageNodeInfo *m)
{ {
void *p; void *p;
PinosNodeInfo *di; PinosNodeInfo *di;
int i;
p = conn->in.data; p = conn->in.data;
memcpy (m, p, sizeof (PinosMessageNodeInfo)); memcpy (m, p, sizeof (PinosMessageNodeInfo));
@ -207,12 +208,32 @@ connection_parse_node_info (PinosConnection *conn, PinosMessageNodeInfo *m)
m->info = SPA_MEMBER (p, SPA_PTR_TO_INT (m->info), PinosNodeInfo); m->info = SPA_MEMBER (p, SPA_PTR_TO_INT (m->info), PinosNodeInfo);
di = m->info; di = m->info;
if (m->info->name) if (di->name)
m->info->name = SPA_MEMBER (di, SPA_PTR_TO_INT (m->info->name), const char); di->name = SPA_MEMBER (di, SPA_PTR_TO_INT (di->name), const char);
if (m->info->error)
m->info->error = SPA_MEMBER (di, SPA_PTR_TO_INT (m->info->error), const char); if (di->input_formats)
if (m->info->props) di->input_formats = SPA_MEMBER (di,
m->info->props = pinos_serialize_dict_deserialize (di, SPA_PTR_TO_INT (m->info->props)); SPA_PTR_TO_INT (di->input_formats), SpaFormat *);
for (i = 0; i < di->n_input_formats; i++) {
if (di->input_formats[i]) {
di->input_formats[i] = pinos_serialize_format_deserialize (di,
SPA_PTR_TO_INT (di->input_formats[i]));
}
}
if (di->output_formats)
di->output_formats = SPA_MEMBER (di,
SPA_PTR_TO_INT (di->output_formats), SpaFormat *);
for (i = 0; i < di->n_output_formats; i++) {
if (di->output_formats[i]) {
di->output_formats[i] = pinos_serialize_format_deserialize (di,
SPA_PTR_TO_INT (di->output_formats[i]));
}
}
if (di->error)
di->error = SPA_MEMBER (di, SPA_PTR_TO_INT (di->error), const char);
if (di->props)
di->props = pinos_serialize_dict_deserialize (di, SPA_PTR_TO_INT (di->props));
} }
} }
@ -359,7 +380,7 @@ connection_add_message (PinosConnection *conn,
buf->buffer_size += 8 + size; buf->buffer_size += 8 + size;
*p++ = dest_id; *p++ = dest_id;
*p++ = (type << 16) | (size & 0xffff); *p++ = (type << 24) | (size & 0xffffff);
return p; return p;
} }
@ -624,12 +645,19 @@ connection_add_node_info (PinosConnection *conn, uint32_t dest_id, PinosMessageN
size_t len, slen; size_t len, slen;
void *p; void *p;
PinosMessageNodeInfo *d; PinosMessageNodeInfo *d;
int i;
/* calc len */ /* calc len */
len = sizeof (PinosMessageNodeInfo); len = sizeof (PinosMessageNodeInfo);
if (m->info) { if (m->info) {
len += sizeof (PinosNodeInfo); len += sizeof (PinosNodeInfo);
len += m->info->name ? strlen (m->info->name) + 1 : 0; len += m->info->name ? strlen (m->info->name) + 1 : 0;
len += m->info->n_input_formats * sizeof (SpaFormat *);
for (i = 0; i < m->info->n_input_formats; i++)
len += pinos_serialize_format_get_size (m->info->input_formats[i]);
len += m->info->n_output_formats * sizeof (SpaFormat *);
for (i = 0; i < m->info->n_output_formats; i++)
len += pinos_serialize_format_get_size (m->info->output_formats[i]);
len += m->info->error ? strlen (m->info->error) + 1 : 0; len += m->info->error ? strlen (m->info->error) + 1 : 0;
len += pinos_serialize_dict_get_size (m->info->props); len += pinos_serialize_dict_get_size (m->info->props);
} }
@ -641,18 +669,43 @@ connection_add_node_info (PinosConnection *conn, uint32_t dest_id, PinosMessageN
p = SPA_MEMBER (d, sizeof (PinosMessageNodeInfo), void); p = SPA_MEMBER (d, sizeof (PinosMessageNodeInfo), void);
if (m->info) { if (m->info) {
PinosNodeInfo *di; PinosNodeInfo *di;
SpaFormat **ifa, **ofa;
memcpy (p, m->info, sizeof (PinosNodeInfo)); memcpy (p, m->info, sizeof (PinosNodeInfo));
d->info = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d)); d->info = SPA_INT_TO_PTR (SPA_PTRDIFF (p, d));
di = p; di = p;
p = SPA_MEMBER (p, sizeof (PinosNodeInfo), void); p = SPA_MEMBER (p, sizeof (PinosNodeInfo), void);
ifa = p;
if (m->info->n_input_formats)
di->input_formats = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di));
else
di->input_formats = 0;
p = SPA_MEMBER (p, sizeof (SpaFormat*) * m->info->n_input_formats, void);
ofa = p;
if (m->info->n_output_formats)
di->output_formats = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di));
else
di->output_formats = 0;
p = SPA_MEMBER (p, sizeof (SpaFormat*) * m->info->n_output_formats, void);
if (m->info->name) { if (m->info->name) {
slen = strlen (m->info->name) + 1; slen = strlen (m->info->name) + 1;
memcpy (p, m->info->name, slen); memcpy (p, m->info->name, slen);
di->name = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di)); di->name = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di));
p += slen; p += slen;
} }
for (i = 0; i < m->info->n_input_formats; i++) {
len = pinos_serialize_format_serialize (p, m->info->input_formats[i]);
ifa[i] = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di));
p = SPA_MEMBER (p, len, void);
}
for (i = 0; i < m->info->n_output_formats; i++) {
len = pinos_serialize_format_serialize (p, m->info->output_formats[i]);
ofa[i] = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di));
p = SPA_MEMBER (p, len, void);
}
if (m->info->error) { if (m->info->error) {
slen = strlen (m->info->error) + 1; slen = strlen (m->info->error) + 1;
memcpy (p, m->info->error, slen); memcpy (p, m->info->error, slen);
@ -662,6 +715,7 @@ connection_add_node_info (PinosConnection *conn, uint32_t dest_id, PinosMessageN
if (m->info->props) { if (m->info->props) {
len = pinos_serialize_dict_serialize (p, m->info->props); len = pinos_serialize_dict_serialize (p, m->info->props);
di->props = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di)); di->props = SPA_INT_TO_PTR (SPA_PTRDIFF (p, di));
p += len;
} }
} }
} }
@ -1084,8 +1138,8 @@ again:
size -= 8; size -= 8;
buf->dest_id = p[0]; buf->dest_id = p[0];
buf->type = p[1] >> 16; buf->type = p[1] >> 24;
len = p[1] & 0xffff; len = p[1] & 0xffffff;
if (len > size) { if (len > size) {
connection_ensure_size (conn, buf, len); connection_ensure_size (conn, buf, len);
@ -1522,11 +1576,11 @@ pinos_connection_flush (PinosConnection *conn)
} }
break; break;
} }
PINOS_DEBUG_MESSAGE ("connection %p: %d written %zd bytes and %u fds", conn, conn->fd, len, buf->n_fds);
buf->buffer_size -= len; buf->buffer_size -= len;
buf->n_fds = 0; buf->n_fds = 0;
PINOS_DEBUG_MESSAGE ("connection %p: %d written %zd bytes and %u fds", conn, conn->fd, len, buf->n_fds);
return true; return true;
/* ERRORS */ /* ERRORS */

View file

@ -492,6 +492,8 @@ pinos_context_new (PinosLoop *loop,
if (impl == NULL) if (impl == NULL)
return NULL; return NULL;
impl->fd = -1;
this = &impl->this; this = &impl->this;
pinos_log_debug ("context %p: new", impl); pinos_log_debug ("context %p: new", impl);
@ -686,10 +688,21 @@ pinos_context_disconnect (PinosContext *context)
impl->disconnecting = true; impl->disconnecting = true;
pinos_proxy_destroy (context->registry_proxy); if (context->registry_proxy)
pinos_proxy_destroy (context->core_proxy); pinos_proxy_destroy (context->registry_proxy);
pinos_connection_destroy (impl->connection); context->registry_proxy = NULL;
close (impl->fd);
if (context->core_proxy)
pinos_proxy_destroy (context->core_proxy);
context->core_proxy = NULL;
if (impl->connection)
pinos_connection_destroy (impl->connection);
impl->connection = NULL;
if (impl->fd != -1)
close (impl->fd);
impl->fd = -1;
context_set_state (context, PINOS_CONTEXT_STATE_UNCONNECTED, NULL); context_set_state (context, PINOS_CONTEXT_STATE_UNCONNECTED, NULL);

View file

@ -20,6 +20,7 @@
#include <string.h> #include <string.h>
#include "pinos/client/pinos.h" #include "pinos/client/pinos.h"
#include "pinos/client/serialize.h"
#include "pinos/client/context.h" #include "pinos/client/context.h"
#include "pinos/client/subscribe.h" #include "pinos/client/subscribe.h"
@ -218,6 +219,8 @@ pinos_node_info_update (PinosNodeInfo *info,
const PinosNodeInfo *update) const PinosNodeInfo *update)
{ {
uint64_t change_mask; uint64_t change_mask;
int i;
size_t size;
if (update == NULL) if (update == NULL)
return info; return info;
@ -240,13 +243,38 @@ pinos_node_info_update (PinosNodeInfo *info,
} }
if (update->change_mask & (1 << 1)) if (update->change_mask & (1 << 1))
info->max_inputs = update->max_inputs; info->max_inputs = update->max_inputs;
if (update->change_mask & (1 << 2)) if (update->change_mask & (1 << 2)) {
for (i = 0; i < info->n_input_formats; i++)
free (info->input_formats[i]);
info->n_input_formats = update->n_input_formats; info->n_input_formats = update->n_input_formats;
if (info->n_input_formats)
info->input_formats = realloc (info->input_formats, info->n_input_formats * sizeof (SpaFormat *));
else {
free (info->input_formats);
info->input_formats = NULL;
}
for (i = 0; i < info->n_input_formats; i++) {
size = pinos_serialize_format_get_size (update->input_formats[i]);
info->input_formats[i] = size ? pinos_serialize_format_copy_into (malloc (size), update->input_formats[i]) : NULL;
}
}
if (update->change_mask & (1 << 3)) if (update->change_mask & (1 << 3))
info->max_outputs = update->max_outputs; info->max_outputs = update->max_outputs;
if (update->change_mask & (1 << 4)) if (update->change_mask & (1 << 4)) {
for (i = 0; i < info->n_output_formats; i++)
free (info->output_formats[i]);
info->n_output_formats = update->n_output_formats; info->n_output_formats = update->n_output_formats;
if (info->n_output_formats)
info->output_formats = realloc (info->output_formats, info->n_output_formats * sizeof (SpaFormat *));
else {
free (info->output_formats);
info->output_formats = NULL;
}
for (i = 0; i < info->n_output_formats; i++) {
size = pinos_serialize_format_get_size (update->output_formats[i]);
info->output_formats[i] = size ? pinos_serialize_format_copy_into (malloc (size), update->output_formats[i]) : NULL;
}
}
if (update->change_mask & (1 << 5)) { if (update->change_mask & (1 << 5)) {
info->state = update->state; info->state = update->state;
@ -265,10 +293,22 @@ pinos_node_info_update (PinosNodeInfo *info,
void void
pinos_node_info_free (PinosNodeInfo *info) pinos_node_info_free (PinosNodeInfo *info)
{ {
int i;
if (info == NULL) if (info == NULL)
return; return;
if (info->name) if (info->name)
free ((void*)info->name); free ((void*)info->name);
if (info->input_formats) {
for (i = 0; i < info->n_input_formats; i++)
free (info->input_formats[i]);
free (info->input_formats);
}
if (info->output_formats) {
for (i = 0; i < info->n_output_formats; i++)
free (info->output_formats[i]);
free (info->output_formats);
}
if (info->error) if (info->error)
free ((void*)info->error); free ((void*)info->error);
if (info->props) if (info->props)

View file

@ -119,6 +119,8 @@ pinos_thread_main_loop_destroy (PinosThreadMainLoop *loop)
pinos_signal_emit (&loop->destroy_signal, loop); pinos_signal_emit (&loop->destroy_signal, loop);
pinos_thread_main_loop_stop (loop);
if (loop->name) if (loop->name)
free (loop->name); free (loop->name);
pthread_mutex_destroy (&impl->lock); pthread_mutex_destroy (&impl->lock);
@ -187,9 +189,11 @@ pinos_thread_main_loop_stop (PinosThreadMainLoop *loop)
{ {
PinosThreadMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosThreadMainLoopImpl, this); PinosThreadMainLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosThreadMainLoopImpl, this);
pinos_loop_signal_event (loop->loop, impl->event); if (impl->running) {
pinos_loop_signal_event (loop->loop, impl->event);
pthread_join (impl->thread, NULL); pthread_join (impl->thread, NULL);
impl->running = false;
}
} }
/** /**

View file

@ -28,6 +28,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#include "gstpinosformat.h"
#include "gstpinosdeviceprovider.h" #include "gstpinosdeviceprovider.h"
#include "gstpinossrc.h" #include "gstpinossrc.h"
#include "gstpinossink.h" #include "gstpinossink.h"
@ -194,19 +195,29 @@ enum
static GstDevice * static GstDevice *
new_node (const PinosNodeInfo *info) new_node (const PinosNodeInfo *info)
{ {
GstCaps *caps; GstCaps *caps = NULL;
GstStructure *props; GstStructure *props;
const gchar *klass = NULL; const gchar *klass = NULL;
SpaDictItem *item; SpaDictItem *item;
GstPinosDeviceType type;
int i;
/* FIXME, iterate ports */ caps = gst_caps_new_empty();
#if 0 if (info->max_inputs > 0 && info->max_outputs == 0) {
if (info->possible_formats) type = GST_PINOS_DEVICE_TYPE_SINK;
caps = gst_caps_from_string (g_bytes_get_data (info->possible_formats, NULL));
else for (i = 0; i < info->n_input_formats; i++) {
caps = gst_caps_new_any(); gst_caps_append (caps, gst_caps_from_format (info->input_formats[i]));
#endif }
caps = gst_caps_from_string ("video/x-raw,width=320,height=240,framerate=15/1"); }
else if (info->max_outputs > 0 && info->max_inputs == 0) {
type = GST_PINOS_DEVICE_TYPE_SOURCE;
for (i = 0; i < info->n_output_formats; i++) {
gst_caps_append (caps, gst_caps_from_format (info->output_formats[i]));
}
} else {
type = GST_PINOS_DEVICE_TYPE_UNKNOWN;
}
props = gst_structure_new_empty ("pinos-proplist"); props = gst_structure_new_empty ("pinos-proplist");
if (info->props) { if (info->props) {
@ -222,7 +233,7 @@ new_node (const PinosNodeInfo *info)
info->name, info->name,
caps, caps,
klass, klass,
GST_PINOS_DEVICE_TYPE_SOURCE, type,
props); props);
} }
@ -500,7 +511,7 @@ failed_start:
failed_main_loop: failed_main_loop:
pinos_loop_destroy (self->loop); pinos_loop_destroy (self->loop);
self->loop = NULL; self->loop = NULL;
return FALSE; return TRUE;
} }
static void static void

View file

@ -46,6 +46,7 @@ typedef struct _GstPinosDeviceClass GstPinosDeviceClass;
#define GST_PINOS_DEVICE_CAST(obj) ((GstPinosDevice *)(obj)) #define GST_PINOS_DEVICE_CAST(obj) ((GstPinosDevice *)(obj))
typedef enum { typedef enum {
GST_PINOS_DEVICE_TYPE_UNKNOWN,
GST_PINOS_DEVICE_TYPE_SOURCE, GST_PINOS_DEVICE_TYPE_SOURCE,
GST_PINOS_DEVICE_TYPE_SINK, GST_PINOS_DEVICE_TYPE_SINK,
} GstPinosDeviceType; } GstPinosDeviceType;

View file

@ -201,7 +201,8 @@ pinos_spa_monitor_load (PinosCore *core,
SpaHandle *handle; SpaHandle *handle;
SpaResult res; SpaResult res;
void *iface; void *iface;
void *hnd, *state = NULL; void *hnd;
unsigned int index;
SpaEnumHandleFactoryFunc enum_func; SpaEnumHandleFactoryFunc enum_func;
const SpaHandleFactory *factory; const SpaHandleFactory *factory;
@ -214,8 +215,8 @@ pinos_spa_monitor_load (PinosCore *core,
goto no_symbol; goto no_symbol;
} }
while (true) { for (index = 0;; index++) {
if ((res = enum_func (&factory, &state)) < 0) { if ((res = enum_func (&factory, index)) < 0) {
if (res != SPA_RESULT_ENUM_END) if (res != SPA_RESULT_ENUM_END)
pinos_log_error ("can't enumerate factories: %d", res); pinos_log_error ("can't enumerate factories: %d", res);
goto enum_failed; goto enum_failed;
@ -256,12 +257,11 @@ pinos_spa_monitor_load (PinosCore *core,
spa_list_init (&impl->item_list); spa_list_init (&impl->item_list);
state = NULL; for (index = 0;; index++) {
while (true) {
SpaMonitorItem *item; SpaMonitorItem *item;
SpaResult res; SpaResult res;
if ((res = spa_monitor_enum_items (this->monitor, &item, &state)) < 0) { if ((res = spa_monitor_enum_items (this->monitor, &item, index)) < 0) {
if (res != SPA_RESULT_ENUM_END) if (res != SPA_RESULT_ENUM_END)
pinos_log_debug ("spa_monitor_enum_items: got error %d\n", res); pinos_log_debug ("spa_monitor_enum_items: got error %d\n", res);
break; break;

View file

@ -46,7 +46,8 @@ pinos_spa_node_load (PinosCore *core,
SpaClock *spa_clock; SpaClock *spa_clock;
SpaResult res; SpaResult res;
SpaHandle *handle; SpaHandle *handle;
void *hnd, *state = NULL; void *hnd;
unsigned int index;
SpaEnumHandleFactoryFunc enum_func; SpaEnumHandleFactoryFunc enum_func;
const SpaHandleFactory *factory; const SpaHandleFactory *factory;
void *iface; void *iface;
@ -60,8 +61,8 @@ pinos_spa_node_load (PinosCore *core,
goto no_symbol; goto no_symbol;
} }
while (true) { for (index = 0; ; index++) {
if ((res = enum_func (&factory, &state)) < 0) { if ((res = enum_func (&factory, index)) < 0) {
if (res != SPA_RESULT_ENUM_END) if (res != SPA_RESULT_ENUM_END)
pinos_log_error ("can't enumerate factories: %d", res); pinos_log_error ("can't enumerate factories: %d", res);
goto enum_failed; goto enum_failed;

View file

@ -472,13 +472,12 @@ spa_proxy_node_port_enum_formats (SpaNode *node,
uint32_t port_id, uint32_t port_id,
SpaFormat **format, SpaFormat **format,
const SpaFormat *filter, const SpaFormat *filter,
void **state) unsigned int index)
{ {
SpaProxy *this; SpaProxy *this;
SpaProxyPort *port; SpaProxyPort *port;
int index;
if (node == NULL || format == NULL || state == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, SpaProxy, node); this = SPA_CONTAINER_OF (node, SpaProxy, node);
@ -488,13 +487,10 @@ spa_proxy_node_port_enum_formats (SpaNode *node,
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
index = (*state == NULL ? 0 : *(int*)state);
if (index >= port->n_formats) if (index >= port->n_formats)
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
*format = port->formats[index]; *format = port->formats[index];
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -78,7 +78,7 @@ do_negotiate (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this); PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this);
SpaResult res; SpaResult res;
SpaFormat *filter = NULL, *format; SpaFormat *filter = NULL, *format;
void *istate = NULL, *ostate = NULL; unsigned int iidx = 0, oidx = 0;
char *error = NULL; char *error = NULL;
if (in_state != SPA_NODE_STATE_CONFIGURE && out_state != SPA_NODE_STATE_CONFIGURE) if (in_state != SPA_NODE_STATE_CONFIGURE && out_state != SPA_NODE_STATE_CONFIGURE)
@ -95,8 +95,8 @@ again:
this->input->port_id, this->input->port_id,
&filter, &filter,
NULL, NULL,
&istate)) < 0) { iidx)) < 0) {
if (res == SPA_RESULT_ENUM_END && istate != NULL) { if (res == SPA_RESULT_ENUM_END && iidx != 0) {
asprintf (&error, "error input enum formats: %d", res); asprintf (&error, "error input enum formats: %d", res);
goto error; goto error;
} }
@ -110,9 +110,10 @@ again:
this->output->port_id, this->output->port_id,
&format, &format,
filter, filter,
&ostate)) < 0) { oidx)) < 0) {
if (res == SPA_RESULT_ENUM_END) { if (res == SPA_RESULT_ENUM_END) {
ostate = NULL; oidx = 0;
iidx++;
goto again; goto again;
} }
asprintf (&error, "error output enum formats: %d", res); asprintf (&error, "error output enum formats: %d", res);

View file

@ -22,6 +22,7 @@
#include <errno.h> #include <errno.h>
#include "pinos/client/pinos.h" #include "pinos/client/pinos.h"
#include "pinos/client/serialize.h"
#include "pinos/server/node.h" #include "pinos/server/node.h"
#include "pinos/server/data-loop.h" #include "pinos/server/data-loop.h"
@ -423,8 +424,44 @@ node_bind_func (PinosGlobal *global,
info.name = this->name; info.name = this->name;
info.max_inputs = this->transport->area->max_inputs; info.max_inputs = this->transport->area->max_inputs;
info.n_inputs = this->transport->area->n_inputs; info.n_inputs = this->transport->area->n_inputs;
info.input_formats = NULL;
for (info.n_input_formats = 0; ; info.n_input_formats++) {
SpaFormat *fmt;
void *p;
if (spa_node_port_enum_formats (this->node,
SPA_DIRECTION_INPUT,
0,
&fmt,
NULL,
info.n_input_formats) < 0)
break;
info.input_formats = realloc (info.input_formats, sizeof (SpaFormat*) * (info.n_input_formats + 1));
p = malloc (pinos_serialize_format_get_size (fmt));
info.input_formats[info.n_input_formats] = pinos_serialize_format_copy_into (p, fmt);
}
info.max_outputs = this->transport->area->max_outputs; info.max_outputs = this->transport->area->max_outputs;
info.n_outputs = this->transport->area->n_outputs; info.n_outputs = this->transport->area->n_outputs;
info.output_formats = NULL;
for (info.n_output_formats = 0; ; info.n_output_formats++) {
SpaFormat *fmt;
void *p;
if (spa_node_port_enum_formats (this->node,
SPA_DIRECTION_OUTPUT,
0,
&fmt,
NULL,
info.n_output_formats) < 0)
break;
info.output_formats = realloc (info.output_formats, sizeof (SpaFormat*) * (info.n_output_formats + 1));
p = malloc (pinos_serialize_format_get_size (fmt));
info.output_formats[info.n_output_formats] = pinos_serialize_format_copy_into (p, fmt);
}
info.state = this->state; info.state = this->state;
info.error = this->error; info.error = this->error;
info.props = this->properties ? &this->properties->dict : NULL; info.props = this->properties ? &this->properties->dict : NULL;
@ -667,9 +704,9 @@ pinos_node_destroy (PinosNode * this)
* @node: a #PinosNode * @node: a #PinosNode
* @direction: a #PinosDirection * @direction: a #PinosDirection
* *
* Find a new unused port id in @node with @direction * Find a new unused port in @node with @direction
* *
* Returns: the new port id or %SPA_ID_INVALID on error * Returns: the new port or %NULL on error
*/ */
PinosPort * PinosPort *
pinos_node_get_free_port (PinosNode *node, pinos_node_get_free_port (PinosNode *node,
@ -698,12 +735,8 @@ pinos_node_get_free_port (PinosNode *node,
} }
} }
if (port == NULL) { if (port == NULL && !spa_list_is_empty (ports))
if (!spa_list_is_empty (ports)) port = spa_list_first (ports, PinosPort, link);
port = spa_list_first (ports, PinosPort, link);
else
return NULL;
}
return port; return port;
@ -812,7 +845,7 @@ pinos_node_update_state (PinosNode *node,
spa_zero (info); spa_zero (info);
m.info = &info; m.info = &info;
info.change_mask = 1 << 1; info.change_mask = 1 << 5;
info.state = node->state; info.state = node->state;
info.error = node->error; info.error = node->error;

View file

@ -110,15 +110,25 @@ dump_node_info (PinosContext *c,
printf ("\tid: %u\n", info->id); printf ("\tid: %u\n", info->id);
printf ("\ttype: %s\n", PINOS_NODE_URI); printf ("\ttype: %s\n", PINOS_NODE_URI);
if (data->print_all) { if (data->print_all) {
int i;
printf ("%c\tname: \"%s\"\n", MARK_CHANGE (0), info->name); printf ("%c\tname: \"%s\"\n", MARK_CHANGE (0), info->name);
printf ("%c\tinputs: %u/%u\n", MARK_CHANGE (1), info->n_inputs, info->max_inputs); printf ("%c\tinputs: %u/%u\n", MARK_CHANGE (1), info->n_inputs, info->max_inputs);
printf ("%c\toutputs: %u/%u\n", MARK_CHANGE (2), info->n_outputs, info->max_outputs); printf ("%c\tinput formats:\n", MARK_CHANGE (2));
printf ("%c\tstate: \"%s\"", MARK_CHANGE (3), pinos_node_state_as_string (info->state)); for (i = 0; i < info->n_input_formats; i++)
spa_debug_format (info->input_formats[i]);
printf ("%c\toutputs: %u/%u\n", MARK_CHANGE (3), info->n_outputs, info->max_outputs);
printf ("%c\toutput formats:\n", MARK_CHANGE (4));
for (i = 0; i < info->n_output_formats; i++)
spa_debug_format (info->output_formats[i]);
printf ("%c\tstate: \"%s\"", MARK_CHANGE (5), pinos_node_state_as_string (info->state));
if (info->state == PINOS_NODE_STATE_ERROR && info->error) if (info->state == PINOS_NODE_STATE_ERROR && info->error)
printf (" \"%s\"\n", info->error); printf (" \"%s\"\n", info->error);
else else
printf ("\n"); printf ("\n");
print_properties (info->props, MARK_CHANGE (4)); print_properties (info->props, MARK_CHANGE (6));
} }
} }

View file

@ -126,7 +126,7 @@ struct _SpaMonitor {
SpaResult (*enum_items) (SpaMonitor *monitor, SpaResult (*enum_items) (SpaMonitor *monitor,
SpaMonitorItem **item, SpaMonitorItem **item,
void **state); unsigned int index);
}; };

View file

@ -325,12 +325,12 @@ struct _SpaNode {
* @port_id: the port to query * @port_id: the port to query
* @format: pointer to a format * @format: pointer to a format
* @filter: a format filter * @filter: a format filter
* @state: a state variable, %NULL to get the first item * @index: an index variable, 0 to get the first item
* *
* Enumerate all possible formats on @port_id of @node that are compatible * Enumerate all possible formats on @port_id of @node that are compatible
* with @filter.. * with @filter..
* *
* Use @state to retrieve the formats one by one until the function * Use @index to retrieve the formats one by one until the function
* returns #SPA_RESULT_ENUM_END. * returns #SPA_RESULT_ENUM_END.
* *
* The result format can be queried and modified and ultimately be used * The result format can be queried and modified and ultimately be used
@ -348,7 +348,7 @@ struct _SpaNode {
uint32_t port_id, uint32_t port_id,
SpaFormat **format, SpaFormat **format,
const SpaFormat *filter, const SpaFormat *filter,
void **state); unsigned int index);
/** /**
* SpaNode::port_set_format: * SpaNode::port_set_format:
* @node: a #SpaNode * @node: a #SpaNode

View file

@ -136,7 +136,7 @@ struct _SpaHandleFactory {
* SpaHandle::enum_interface_info: * SpaHandle::enum_interface_info:
* @factory: a #SpaHandleFactory * @factory: a #SpaHandleFactory
* @info: result to hold SpaInterfaceInfo. * @info: result to hold SpaInterfaceInfo.
* @state: state to keep track of the enumeration, %NULL for first item * @index: index to keep track of the enumeration, 0 for first item
* *
* Enumerate the interface information for @factory. * Enumerate the interface information for @factory.
* *
@ -147,7 +147,7 @@ struct _SpaHandleFactory {
*/ */
SpaResult (*enum_interface_info) (const SpaHandleFactory *factory, SpaResult (*enum_interface_info) (const SpaHandleFactory *factory,
const SpaInterfaceInfo **info, const SpaInterfaceInfo **info,
void **state); unsigned int index);
}; };
#define spa_handle_factory_init(h,...) (h)->init((h),__VA_ARGS__) #define spa_handle_factory_init(h,...) (h)->init((h),__VA_ARGS__)
@ -156,7 +156,7 @@ struct _SpaHandleFactory {
/** /**
* SpaEnumHandleFactoryFunc: * SpaEnumHandleFactoryFunc:
* @factory: a location to hold the factory result * @factory: a location to hold the factory result
* @state: state to keep track of the enumeration * @index: index to keep track of the enumeration
* *
* The function signature of the entry point in a plugin. * The function signature of the entry point in a plugin.
* *
@ -165,12 +165,12 @@ struct _SpaHandleFactory {
* #SPA_RESULT_ENUM_END when there are no more factories * #SPA_RESULT_ENUM_END when there are no more factories
*/ */
typedef SpaResult (*SpaEnumHandleFactoryFunc) (const SpaHandleFactory **factory, typedef SpaResult (*SpaEnumHandleFactoryFunc) (const SpaHandleFactory **factory,
void **state); unsigned int index);
/** /**
* spa_enum_handle_factory: * spa_enum_handle_factory:
* @factory: a location to hold the factory result * @factory: a location to hold the factory result
* @state: state to keep track of the enumeration * @index: index to keep track of the enumeration
* *
* The entry point in a plugin. * The entry point in a plugin.
* *
@ -179,7 +179,7 @@ typedef SpaResult (*SpaEnumHandleFactoryFunc) (const SpaHandleFactory **factory,
* #SPA_RESULT_ENUM_END when there are no more factories * #SPA_RESULT_ENUM_END when there are no more factories
*/ */
SpaResult spa_enum_handle_factory (const SpaHandleFactory **factory, SpaResult spa_enum_handle_factory (const SpaHandleFactory **factory,
void **state); unsigned int index);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View file

@ -64,6 +64,8 @@ struct _SpaALSAMonitor {
struct udev* udev; struct udev* udev;
struct udev_monitor *umonitor; struct udev_monitor *umonitor;
struct udev_enumerate *enumerate; struct udev_enumerate *enumerate;
unsigned int index;
struct udev_list_entry *devices;
ALSAItem uitem; ALSAItem uitem;
@ -317,14 +319,13 @@ spa_alsa_monitor_set_event_callback (SpaMonitor *monitor,
static SpaResult static SpaResult
spa_alsa_monitor_enum_items (SpaMonitor *monitor, spa_alsa_monitor_enum_items (SpaMonitor *monitor,
SpaMonitorItem **item, SpaMonitorItem **item,
void **state) unsigned int index)
{ {
SpaResult res; SpaResult res;
SpaALSAMonitor *this; SpaALSAMonitor *this;
struct udev_list_entry *devices;
struct udev_device *dev; struct udev_device *dev;
if (monitor == NULL || item == NULL || state == NULL) if (monitor == NULL || item == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (monitor, SpaALSAMonitor, monitor); this = SPA_CONTAINER_OF (monitor, SpaALSAMonitor, monitor);
@ -333,7 +334,7 @@ spa_alsa_monitor_enum_items (SpaMonitor *monitor,
return res; return res;
again: again:
if (*state == NULL) { if (index == 0 || this->index > index) {
if (this->enumerate) if (this->enumerate)
udev_enumerate_unref (this->enumerate); udev_enumerate_unref (this->enumerate);
this->enumerate = udev_enumerate_new (this->udev); this->enumerate = udev_enumerate_new (this->udev);
@ -341,27 +342,28 @@ again:
udev_enumerate_add_match_subsystem (this->enumerate, "sound"); udev_enumerate_add_match_subsystem (this->enumerate, "sound");
udev_enumerate_scan_devices (this->enumerate); udev_enumerate_scan_devices (this->enumerate);
devices = udev_enumerate_get_list_entry (this->enumerate); this->devices = udev_enumerate_get_list_entry (this->enumerate);
if (devices == NULL) this->index = 0;
return SPA_RESULT_ENUM_END;
} else {
devices = *state;
} }
while (index > this->index && this->devices) {
if (*state == (void*)1) { this->devices = udev_list_entry_get_next (this->devices);
this->index++;
}
if (this->devices == NULL) {
fill_item (this, &this->uitem, NULL); fill_item (this, &this->uitem, NULL);
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
dev = udev_device_new_from_syspath (this->udev, dev = udev_device_new_from_syspath (this->udev,
udev_list_entry_get_name (devices)); udev_list_entry_get_name (this->devices));
if ((*state = udev_list_entry_get_next (devices)) == NULL) this->devices = udev_list_entry_get_next (this->devices);
*state = (void*)1;
if (fill_item (this, &this->uitem, dev) < 0) if (fill_item (this, &this->uitem, dev) < 0)
goto again; goto again;
this->index++;
*item = &this->uitem.item; *item = &this->uitem.item;
return SPA_RESULT_OK; return SPA_RESULT_OK;
@ -449,20 +451,15 @@ static const SpaInterfaceInfo alsa_monitor_interfaces[] =
static SpaResult static SpaResult
alsa_monitor_enum_interface_info (const SpaHandleFactory *factory, alsa_monitor_enum_interface_info (const SpaHandleFactory *factory,
const SpaInterfaceInfo **info, const SpaInterfaceInfo **info,
void **state) unsigned int index)
{ {
int index; if (factory == NULL || info == NULL)
if (factory == NULL || info == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
if (index < 0 || index >= SPA_N_ELEMENTS (alsa_monitor_interfaces)) if (index < 0 || index >= SPA_N_ELEMENTS (alsa_monitor_interfaces))
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
*info = &alsa_monitor_interfaces[index]; *info = &alsa_monitor_interfaces[index];
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -327,12 +327,11 @@ spa_alsa_sink_node_port_enum_formats (SpaNode *node,
uint32_t port_id, uint32_t port_id,
SpaFormat **format, SpaFormat **format,
const SpaFormat *filter, const SpaFormat *filter,
void **state) unsigned int index)
{ {
SpaALSASink *this; SpaALSASink *this;
int index;
if (node == NULL || format == NULL || state == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, SpaALSASink, node); this = SPA_CONTAINER_OF (node, SpaALSASink, node);
@ -340,8 +339,6 @@ spa_alsa_sink_node_port_enum_formats (SpaNode *node,
if (!CHECK_PORT (this, direction, port_id)) if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
spa_format_audio_init (SPA_MEDIA_TYPE_AUDIO, spa_format_audio_init (SPA_MEDIA_TYPE_AUDIO,
@ -357,7 +354,6 @@ spa_alsa_sink_node_port_enum_formats (SpaNode *node,
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*format = &this->query_format.format; *format = &this->query_format.format;
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -832,15 +828,11 @@ static const SpaInterfaceInfo alsa_sink_interfaces[] =
static SpaResult static SpaResult
alsa_sink_enum_interface_info (const SpaHandleFactory *factory, alsa_sink_enum_interface_info (const SpaHandleFactory *factory,
const SpaInterfaceInfo **info, const SpaInterfaceInfo **info,
void **state) unsigned int index)
{ {
int index; if (factory == NULL || info == NULL)
if (factory == NULL || info == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
*info = &alsa_sink_interfaces[index]; *info = &alsa_sink_interfaces[index];
@ -848,8 +840,6 @@ alsa_sink_enum_interface_info (const SpaHandleFactory *factory,
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -363,12 +363,11 @@ spa_alsa_source_node_port_enum_formats (SpaNode *node,
uint32_t port_id, uint32_t port_id,
SpaFormat **format, SpaFormat **format,
const SpaFormat *filter, const SpaFormat *filter,
void **state) unsigned int index)
{ {
SpaALSASource *this; SpaALSASource *this;
int index;
if (node == NULL || format == NULL || state == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, SpaALSASource, node); this = SPA_CONTAINER_OF (node, SpaALSASource, node);
@ -376,8 +375,6 @@ spa_alsa_source_node_port_enum_formats (SpaNode *node,
if (!CHECK_PORT (this, direction, port_id)) if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
spa_format_audio_init (SPA_MEDIA_TYPE_AUDIO, spa_format_audio_init (SPA_MEDIA_TYPE_AUDIO,
@ -393,7 +390,6 @@ spa_alsa_source_node_port_enum_formats (SpaNode *node,
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*format = &this->query_format.format; *format = &this->query_format.format;
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -902,22 +898,16 @@ static const SpaInterfaceInfo alsa_source_interfaces[] =
static SpaResult static SpaResult
alsa_source_enum_interface_info (const SpaHandleFactory *factory, alsa_source_enum_interface_info (const SpaHandleFactory *factory,
const SpaInterfaceInfo **info, const SpaInterfaceInfo **info,
void **state) unsigned int index)
{ {
int index; if (factory == NULL || info == NULL)
if (factory == NULL || info == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
if (index < 0 || index >= SPA_N_ELEMENTS (alsa_source_interfaces)) if (index < 0 || index >= SPA_N_ELEMENTS (alsa_source_interfaces))
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
*info = &alsa_source_interfaces[index]; *info = &alsa_source_interfaces[index];
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -26,14 +26,10 @@ extern const SpaHandleFactory spa_alsa_monitor_factory;
SpaResult SpaResult
spa_enum_handle_factory (const SpaHandleFactory **factory, spa_enum_handle_factory (const SpaHandleFactory **factory,
void **state) unsigned int index)
{ {
int index; if (factory == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (factory == NULL || state == NULL)
return SPA_RESULT_ENUM_END;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
@ -48,7 +44,5 @@ spa_enum_handle_factory (const SpaHandleFactory **factory,
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -311,13 +311,12 @@ spa_audiomixer_node_port_enum_formats (SpaNode *node,
uint32_t port_id, uint32_t port_id,
SpaFormat **format, SpaFormat **format,
const SpaFormat *filter, const SpaFormat *filter,
void **state) unsigned int index)
{ {
SpaAudioMixer *this; SpaAudioMixer *this;
SpaAudioMixerPort *port; SpaAudioMixerPort *port;
int index;
if (node == NULL || format == NULL || state == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node); this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
@ -327,8 +326,6 @@ spa_audiomixer_node_port_enum_formats (SpaNode *node,
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[0]; port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[0];
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
spa_format_audio_init (SPA_MEDIA_TYPE_AUDIO, spa_format_audio_init (SPA_MEDIA_TYPE_AUDIO,
@ -339,7 +336,6 @@ spa_audiomixer_node_port_enum_formats (SpaNode *node,
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*format = &port->format[0].format; *format = &port->format[0].format;
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -781,15 +777,11 @@ static const SpaInterfaceInfo audiomixer_interfaces[] =
static SpaResult static SpaResult
audiomixer_enum_interface_info (const SpaHandleFactory *factory, audiomixer_enum_interface_info (const SpaHandleFactory *factory,
const SpaInterfaceInfo **info, const SpaInterfaceInfo **info,
void **state) unsigned int index)
{ {
int index; if (factory == NULL || info == NULL)
if (factory == NULL || info == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
*info = &audiomixer_interfaces[index]; *info = &audiomixer_interfaces[index];
@ -797,7 +789,6 @@ audiomixer_enum_interface_info (const SpaHandleFactory *factory,
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -24,15 +24,11 @@ extern const SpaHandleFactory spa_audiomixer_factory;
SpaResult SpaResult
spa_enum_handle_factory (const SpaHandleFactory **factory, spa_enum_handle_factory (const SpaHandleFactory **factory,
void **state) unsigned int index)
{ {
int index; if (factory == NULL)
if (factory == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
*factory = &spa_audiomixer_factory; *factory = &spa_audiomixer_factory;
@ -40,6 +36,5 @@ spa_enum_handle_factory (const SpaHandleFactory **factory,
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -465,12 +465,11 @@ spa_audiotestsrc_node_port_enum_formats (SpaNode *node,
uint32_t port_id, uint32_t port_id,
SpaFormat **format, SpaFormat **format,
const SpaFormat *filter, const SpaFormat *filter,
void **state) unsigned int index)
{ {
SpaAudioTestSrc *this; SpaAudioTestSrc *this;
int index;
if (node == NULL || format == NULL || state == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node); this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
@ -478,8 +477,6 @@ spa_audiotestsrc_node_port_enum_formats (SpaNode *node,
if (!CHECK_PORT (this, direction, port_id)) if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
if (filter) if (filter)
@ -493,7 +490,6 @@ spa_audiotestsrc_node_port_enum_formats (SpaNode *node,
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*format = &this->query_format.format; *format = &this->query_format.format;
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -984,15 +980,11 @@ static const SpaInterfaceInfo audiotestsrc_interfaces[] =
static SpaResult static SpaResult
audiotestsrc_enum_interface_info (const SpaHandleFactory *factory, audiotestsrc_enum_interface_info (const SpaHandleFactory *factory,
const SpaInterfaceInfo **info, const SpaInterfaceInfo **info,
void **state) unsigned int index)
{ {
int index; if (factory == NULL || info == NULL)
if (factory == NULL || info == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
*info = &audiotestsrc_interfaces[index]; *info = &audiotestsrc_interfaces[index];
@ -1000,7 +992,6 @@ audiotestsrc_enum_interface_info (const SpaHandleFactory *factory,
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -24,15 +24,11 @@ extern const SpaHandleFactory spa_audiotestsrc_factory;
SpaResult SpaResult
spa_enum_handle_factory (const SpaHandleFactory **factory, spa_enum_handle_factory (const SpaHandleFactory **factory,
void **state) unsigned int index)
{ {
int index; if (factory == NULL)
if (factory == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
*factory = &spa_audiotestsrc_factory; *factory = &spa_audiotestsrc_factory;
@ -40,6 +36,5 @@ spa_enum_handle_factory (const SpaHandleFactory **factory,
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -251,13 +251,12 @@ spa_ffmpeg_dec_node_port_enum_formats (SpaNode *node,
uint32_t port_id, uint32_t port_id,
SpaFormat **format, SpaFormat **format,
const SpaFormat *filter, const SpaFormat *filter,
void **state) unsigned int index)
{ {
SpaFFMpegDec *this; SpaFFMpegDec *this;
SpaFFMpegPort *port; SpaFFMpegPort *port;
int index;
if (node == NULL || format == NULL || state == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, SpaFFMpegDec, node); this = SPA_CONTAINER_OF (node, SpaFFMpegDec, node);
@ -267,8 +266,6 @@ spa_ffmpeg_dec_node_port_enum_formats (SpaNode *node,
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
spa_format_video_init (SPA_MEDIA_TYPE_VIDEO, spa_format_video_init (SPA_MEDIA_TYPE_VIDEO,
@ -279,7 +276,6 @@ spa_ffmpeg_dec_node_port_enum_formats (SpaNode *node,
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*format = &port->format[0].format; *format = &port->format[0].format;
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -256,11 +256,10 @@ spa_ffmpeg_enc_node_port_enum_formats (SpaNode *node,
uint32_t port_id, uint32_t port_id,
SpaFormat **format, SpaFormat **format,
const SpaFormat *filter, const SpaFormat *filter,
void **state) unsigned int index)
{ {
SpaFFMpegEnc *this; SpaFFMpegEnc *this;
SpaFFMpegPort *port; SpaFFMpegPort *port;
int index;
if (node == NULL || format == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
@ -272,8 +271,6 @@ spa_ffmpeg_enc_node_port_enum_formats (SpaNode *node,
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id]; port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
spa_format_video_init (SPA_MEDIA_TYPE_VIDEO, spa_format_video_init (SPA_MEDIA_TYPE_VIDEO,
@ -284,7 +281,6 @@ spa_ffmpeg_enc_node_port_enum_formats (SpaNode *node,
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*format = &port->format[0].format; *format = &port->format[0].format;
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -63,39 +63,31 @@ static const SpaInterfaceInfo ffmpeg_interfaces[] =
static SpaResult static SpaResult
ffmpeg_enum_interface_info (const SpaHandleFactory *factory, ffmpeg_enum_interface_info (const SpaHandleFactory *factory,
const SpaInterfaceInfo **info, const SpaInterfaceInfo **info,
void **state) unsigned int index)
{ {
int index; if (factory == NULL || info == NULL)
if (factory == NULL || state == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
if (index >= 1) if (index >= 1)
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
*info = &ffmpeg_interfaces[index]; *info = &ffmpeg_interfaces[index];
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
SpaResult SpaResult
spa_enum_handle_factory (const SpaHandleFactory **factory, spa_enum_handle_factory (const SpaHandleFactory **factory,
void **state) unsigned int index)
{ {
static const AVCodec *c = NULL; static const AVCodec *c = NULL;
static int ci = 0; static int ci = 0;
static SpaHandleFactory f; static SpaHandleFactory f;
static char name[128]; static char name[128];
int index;
index = (*state == NULL ? 0 : *(int*)state);
av_register_all(); av_register_all();
if (index == 0 || index < ci) { if (index == 0) {
c = av_codec_next (NULL); c = av_codec_next (NULL);
ci = 0; ci = 0;
} }
@ -106,8 +98,6 @@ spa_enum_handle_factory (const SpaHandleFactory **factory,
if (c == NULL) if (c == NULL)
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
*(int*)state = ++index;
if (av_codec_is_encoder (c)) { if (av_codec_is_encoder (c)) {
snprintf (name, 128, "ffenc_%s", c->name); snprintf (name, 128, "ffenc_%s", c->name);
f.init = ffmpeg_enc_init; f.init = ffmpeg_enc_init;

View file

@ -61,6 +61,8 @@ struct _SpaV4l2Monitor {
struct udev* udev; struct udev* udev;
struct udev_monitor *umonitor; struct udev_monitor *umonitor;
struct udev_enumerate *enumerate; struct udev_enumerate *enumerate;
unsigned int index;
struct udev_list_entry *devices;
V4l2Item uitem; V4l2Item uitem;
@ -251,14 +253,13 @@ spa_v4l2_monitor_set_event_callback (SpaMonitor *monitor,
static SpaResult static SpaResult
spa_v4l2_monitor_enum_items (SpaMonitor *monitor, spa_v4l2_monitor_enum_items (SpaMonitor *monitor,
SpaMonitorItem **item, SpaMonitorItem **item,
void **state) unsigned int index)
{ {
SpaResult res; SpaResult res;
SpaV4l2Monitor *this; SpaV4l2Monitor *this;
struct udev_list_entry *devices;
struct udev_device *dev; struct udev_device *dev;
if (monitor == NULL || item == NULL || state == NULL) if (monitor == NULL || item == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (monitor, SpaV4l2Monitor, monitor); 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) if ((res = v4l2_udev_open (this)) < 0)
return res; return res;
if (*state == NULL) { if (index == 0) {
if (this->enumerate) if (this->enumerate)
udev_enumerate_unref (this->enumerate); udev_enumerate_unref (this->enumerate);
this->enumerate = udev_enumerate_new (this->udev); 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_add_match_subsystem (this->enumerate, "video4linux");
udev_enumerate_scan_devices (this->enumerate); udev_enumerate_scan_devices (this->enumerate);
devices = udev_enumerate_get_list_entry (this->enumerate); this->devices = udev_enumerate_get_list_entry (this->enumerate);
if (devices == NULL) this->index = 0;
return SPA_RESULT_ENUM_END;
} else {
devices = *state;
} }
while (index > this->index && this->devices) {
if (*state == (void*)1) { this->devices = udev_list_entry_get_next (this->devices);
this->index++;
}
if (this->devices == NULL) {
fill_item (&this->uitem, NULL); fill_item (&this->uitem, NULL);
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
dev = udev_device_new_from_syspath (this->udev, 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); fill_item (&this->uitem, dev);
if (dev == NULL) if (dev == NULL)
@ -295,8 +296,8 @@ spa_v4l2_monitor_enum_items (SpaMonitor *monitor,
*item = &this->uitem.item; *item = &this->uitem.item;
if ((*state = udev_list_entry_get_next (devices)) == NULL) this->devices = udev_list_entry_get_next (this->devices);
*state = (void*)1; this->index++;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -383,20 +384,15 @@ static const SpaInterfaceInfo v4l2_monitor_interfaces[] =
static SpaResult static SpaResult
v4l2_monitor_enum_interface_info (const SpaHandleFactory *factory, v4l2_monitor_enum_interface_info (const SpaHandleFactory *factory,
const SpaInterfaceInfo **info, const SpaInterfaceInfo **info,
void **state) unsigned int index)
{ {
int index; if (factory == NULL || info == NULL)
if (factory == NULL || info == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
if (index < 0 || index >= SPA_N_ELEMENTS (v4l2_monitor_interfaces)) if (index < 0 || index >= SPA_N_ELEMENTS (v4l2_monitor_interfaces))
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
*info = &v4l2_monitor_interfaces[index]; *info = &v4l2_monitor_interfaces[index];
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -98,7 +98,6 @@ typedef struct {
bool next_frmsize; bool next_frmsize;
struct v4l2_frmsizeenum frmsize; struct v4l2_frmsizeenum frmsize;
struct v4l2_frmivalenum frmival; struct v4l2_frmivalenum frmival;
void *cookie;
V4l2Format format[2]; V4l2Format format[2];
V4l2Format *current_format; V4l2Format *current_format;
@ -484,8 +483,8 @@ spa_v4l2_source_node_remove_port (SpaNode *node,
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
} }
static void static SpaResult
spa_v4l2_format_init (V4l2Format *f) spa_v4l2_format_init (V4l2Format *f, const SpaFormat *sf)
{ {
f->fmt.props.n_prop_info = 3; f->fmt.props.n_prop_info = 3;
f->fmt.props.prop_info = f->infos; 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_info_fill_video (&f->infos[2],
SPA_PROP_ID_VIDEO_FRAMERATE, SPA_PROP_ID_VIDEO_FRAMERATE,
offsetof (V4l2Format, 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 static SpaResult
@ -507,21 +511,20 @@ spa_v4l2_source_node_port_enum_formats (SpaNode *node,
uint32_t port_id, uint32_t port_id,
SpaFormat **format, SpaFormat **format,
const SpaFormat *filter, const SpaFormat *filter,
void **state) unsigned int index)
{ {
SpaV4l2Source *this; SpaV4l2Source *this;
SpaResult res; SpaResult res;
if (node == NULL || format == NULL || state == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node); 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)) if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT; 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; return res;
} }
@ -537,7 +540,6 @@ spa_v4l2_source_node_port_set_format (SpaNode *node,
SpaV4l2State *state; SpaV4l2State *state;
SpaResult res; SpaResult res;
V4l2Format *f, *tf; V4l2Format *f, *tf;
size_t fs;
if (node == NULL) if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
@ -560,13 +562,9 @@ spa_v4l2_source_node_port_set_format (SpaNode *node,
f = &state->format[0]; f = &state->format[0];
tf = &state->format[1]; tf = &state->format[1];
fs = sizeof (V4l2Format);
if ((SpaFormat*)f != format) { if ((SpaFormat*)f != format) {
spa_v4l2_format_init (f); if ((res = spa_v4l2_format_init (f, format)) < 0)
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))
return res; return res;
} else { } else {
f = (V4l2Format*)format; f = (V4l2Format*)format;
@ -590,7 +588,8 @@ spa_v4l2_source_node_port_set_format (SpaNode *node,
return SPA_RESULT_INVALID_MEDIA_TYPE; return SPA_RESULT_INVALID_MEDIA_TYPE;
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) { 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; state->current_format = tf;
update_state (this, SPA_NODE_STATE_READY); update_state (this, SPA_NODE_STATE_READY);
@ -1019,20 +1018,15 @@ static const SpaInterfaceInfo v4l2_source_interfaces[] =
static SpaResult static SpaResult
v4l2_source_enum_interface_info (const SpaHandleFactory *factory, v4l2_source_enum_interface_info (const SpaHandleFactory *factory,
const SpaInterfaceInfo **info, const SpaInterfaceInfo **info,
void **state) unsigned int index)
{ {
int index; if (factory == NULL || info == NULL)
if (factory == NULL || info == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
if (index < 0 || index >= SPA_N_ELEMENTS (v4l2_source_interfaces)) if (index < 0 || index >= SPA_N_ELEMENTS (v4l2_source_interfaces))
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
*info = &v4l2_source_interfaces[index]; *info = &v4l2_source_interfaces[index];
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -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 #define FOURCC_ARGS(f) (f)&0x7f,((f)>>8)&0x7f,((f)>>16)&0x7f,((f)>>24)&0x7f
static SpaResult 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]; SpaV4l2State *state = &this->state[0];
int res, i, pi; int res, i, pi;
@ -459,7 +462,7 @@ spa_v4l2_enum_format (SpaV4l2Source *this, SpaFormat **format, const SpaFormat *
*format = NULL; *format = NULL;
if (*cookie == NULL) { if (index == 0) {
CLEAR (state->fmtdesc); CLEAR (state->fmtdesc);
state->fmtdesc.index = 0; state->fmtdesc.index = 0;
state->fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 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); CLEAR (state->frmsize);
state->next_frmsize = true; state->next_frmsize = true;
CLEAR (state->frmival); CLEAR (state->frmival);
*cookie = state;
} }
if (false) { if (false) {

View file

@ -25,15 +25,11 @@ extern const SpaHandleFactory spa_v4l2_monitor_factory;
SpaResult SpaResult
spa_enum_handle_factory (const SpaHandleFactory **factory, spa_enum_handle_factory (const SpaHandleFactory **factory,
void **state) unsigned int index)
{ {
int index; if (factory == NULL)
if (factory == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
*factory = &spa_v4l2_source_factory; *factory = &spa_v4l2_source_factory;
@ -44,7 +40,5 @@ spa_enum_handle_factory (const SpaHandleFactory **factory,
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -24,15 +24,11 @@ extern const SpaHandleFactory spa_videotestsrc_factory;
SpaResult SpaResult
spa_enum_handle_factory (const SpaHandleFactory **factory, spa_enum_handle_factory (const SpaHandleFactory **factory,
void **state) unsigned int index)
{ {
int index; if (factory == NULL)
if (factory == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
*factory = &spa_videotestsrc_factory; *factory = &spa_videotestsrc_factory;
@ -40,6 +36,5 @@ spa_enum_handle_factory (const SpaHandleFactory **factory,
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -425,12 +425,11 @@ spa_videotestsrc_node_port_enum_formats (SpaNode *node,
uint32_t port_id, uint32_t port_id,
SpaFormat **format, SpaFormat **format,
const SpaFormat *filter, const SpaFormat *filter,
void **state) unsigned int index)
{ {
SpaVideoTestSrc *this; SpaVideoTestSrc *this;
int index;
if (node == NULL || format == NULL || state == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, SpaVideoTestSrc, node); this = SPA_CONTAINER_OF (node, SpaVideoTestSrc, node);
@ -438,8 +437,6 @@ spa_videotestsrc_node_port_enum_formats (SpaNode *node,
if (!CHECK_PORT (this, direction, port_id)) if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
if (filter) if (filter)
@ -453,7 +450,6 @@ spa_videotestsrc_node_port_enum_formats (SpaNode *node,
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*format = &this->query_format.format; *format = &this->query_format.format;
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -956,15 +952,11 @@ static const SpaInterfaceInfo videotestsrc_interfaces[] =
static SpaResult static SpaResult
videotestsrc_enum_interface_info (const SpaHandleFactory *factory, videotestsrc_enum_interface_info (const SpaHandleFactory *factory,
const SpaInterfaceInfo **info, const SpaInterfaceInfo **info,
void **state) unsigned int index)
{ {
int index; if (factory == NULL || info == NULL)
if (factory == NULL || info == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
*info = &videotestsrc_interfaces[index]; *info = &videotestsrc_interfaces[index];
@ -972,7 +964,6 @@ videotestsrc_enum_interface_info (const SpaHandleFactory *factory,
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -24,15 +24,11 @@ extern const SpaHandleFactory spa_volume_factory;
SpaResult SpaResult
spa_enum_handle_factory (const SpaHandleFactory **factory, spa_enum_handle_factory (const SpaHandleFactory **factory,
void **state) unsigned int index)
{ {
int index; if (factory == NULL)
if (factory == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
*factory = &spa_volume_factory; *factory = &spa_volume_factory;
@ -40,7 +36,5 @@ spa_enum_handle_factory (const SpaHandleFactory **factory,
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -288,12 +288,11 @@ spa_volume_node_port_enum_formats (SpaNode *node,
uint32_t port_id, uint32_t port_id,
SpaFormat **format, SpaFormat **format,
const SpaFormat *filter, const SpaFormat *filter,
void **state) unsigned int index)
{ {
SpaVolume *this; SpaVolume *this;
int index;
if (node == NULL || format == NULL || state == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, SpaVolume, node); this = SPA_CONTAINER_OF (node, SpaVolume, node);
@ -301,8 +300,6 @@ spa_volume_node_port_enum_formats (SpaNode *node,
if (!CHECK_PORT (this, direction, port_id)) if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
spa_format_audio_init (SPA_MEDIA_TYPE_AUDIO, spa_format_audio_init (SPA_MEDIA_TYPE_AUDIO,
@ -313,7 +310,6 @@ spa_volume_node_port_enum_formats (SpaNode *node,
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*format = &this->query_format.format; *format = &this->query_format.format;
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -851,15 +847,11 @@ static const SpaInterfaceInfo volume_interfaces[] =
static SpaResult static SpaResult
volume_enum_interface_info (const SpaHandleFactory *factory, volume_enum_interface_info (const SpaHandleFactory *factory,
const SpaInterfaceInfo **info, const SpaInterfaceInfo **info,
void **state) unsigned int index)
{ {
int index; if (factory == NULL || info == NULL)
if (factory == NULL || info == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
*info = &volume_interfaces[index]; *info = &volume_interfaces[index];
@ -867,8 +859,6 @@ volume_enum_interface_info (const SpaHandleFactory *factory,
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -290,12 +290,11 @@ spa_xv_sink_node_port_enum_formats (SpaNode *node,
uint32_t port_id, uint32_t port_id,
SpaFormat **format, SpaFormat **format,
const SpaFormat *filter, const SpaFormat *filter,
void **state) unsigned int index)
{ {
SpaXvSink *this; SpaXvSink *this;
int index;
if (node == NULL || format == NULL || state == NULL) if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
this = SPA_CONTAINER_OF (node, SpaXvSink, node); this = SPA_CONTAINER_OF (node, SpaXvSink, node);
@ -303,8 +302,6 @@ spa_xv_sink_node_port_enum_formats (SpaNode *node,
if (!CHECK_PORT (this, direction, port_id)) if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT; return SPA_RESULT_INVALID_PORT;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
spa_format_video_init (SPA_MEDIA_TYPE_VIDEO, spa_format_video_init (SPA_MEDIA_TYPE_VIDEO,
@ -315,7 +312,6 @@ spa_xv_sink_node_port_enum_formats (SpaNode *node,
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*format = &this->format[0].format; *format = &this->format[0].format;
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
@ -613,15 +609,11 @@ static const SpaInterfaceInfo xv_sink_interfaces[] =
static SpaResult static SpaResult
xv_sink_enum_interface_info (const SpaHandleFactory *factory, xv_sink_enum_interface_info (const SpaHandleFactory *factory,
const SpaInterfaceInfo **info, const SpaInterfaceInfo **info,
void **state) unsigned int index)
{ {
int index; if (factory == NULL || info == NULL)
if (factory == NULL || info == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
*info = &xv_sink_interfaces[index]; *info = &xv_sink_interfaces[index];
@ -629,7 +621,6 @@ xv_sink_enum_interface_info (const SpaHandleFactory *factory,
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -24,15 +24,11 @@ extern const SpaHandleFactory spa_xv_sink_factory;
SpaResult SpaResult
spa_enum_handle_factory (const SpaHandleFactory **factory, spa_enum_handle_factory (const SpaHandleFactory **factory,
void **state) unsigned int index)
{ {
int index; if (factory == NULL)
if (factory == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS; return SPA_RESULT_INVALID_ARGUMENTS;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) { switch (index) {
case 0: case 0:
*factory = &spa_xv_sink_factory; *factory = &spa_xv_sink_factory;
@ -40,7 +36,5 @@ spa_enum_handle_factory (const SpaHandleFactory **factory,
default: default:
return SPA_RESULT_ENUM_END; return SPA_RESULT_ENUM_END;
} }
*(int*)state = ++index;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -50,17 +50,18 @@ inspect_port (SpaNode *node, SpaDirection direction, uint32_t port_id)
{ {
SpaResult res; SpaResult res;
SpaFormat *format; SpaFormat *format;
void *state = NULL; unsigned int index = 0;
SpaProps *props; SpaProps *props;
while (true) { while (true) {
if ((res = spa_node_port_enum_formats (node, direction, port_id, &format, NULL, &state)) < 0) { if ((res = spa_node_port_enum_formats (node, direction, port_id, &format, NULL, index)) < 0) {
if (res != SPA_RESULT_ENUM_END) if (res != SPA_RESULT_ENUM_END)
printf ("got error %d\n", res); printf ("got error %d\n", res);
break; break;
} }
if (format) if (format)
spa_debug_format (format); spa_debug_format (format);
index++;
} }
if ((res = spa_node_port_get_props (node, direction, port_id, &props)) < 0) if ((res = spa_node_port_get_props (node, direction, port_id, &props)) < 0)
printf ("port_get_props error: %d\n", res); printf ("port_get_props error: %d\n", res);
@ -113,7 +114,7 @@ inspect_factory (AppData *data, const SpaHandleFactory *factory)
SpaResult res; SpaResult res;
SpaHandle *handle; SpaHandle *handle;
void *interface; void *interface;
void *state = NULL; unsigned int index = 0;
printf ("factory name:\t\t'%s'\n", factory->name); printf ("factory name:\t\t'%s'\n", factory->name);
printf ("factory info:\n"); printf ("factory info:\n");
@ -134,12 +135,13 @@ inspect_factory (AppData *data, const SpaHandleFactory *factory)
const SpaInterfaceInfo *info; const SpaInterfaceInfo *info;
uint32_t interface_id; uint32_t interface_id;
if ((res = spa_handle_factory_enum_interface_info (factory, &info, &state)) < 0) { if ((res = spa_handle_factory_enum_interface_info (factory, &info, index)) < 0) {
if (res == SPA_RESULT_ENUM_END) if (res == SPA_RESULT_ENUM_END)
break; break;
else else
printf ("can't enumerate interfaces: %d\n", res); printf ("can't enumerate interfaces: %d\n", res);
} }
index++;
printf (" interface: '%s'\n", info->uri); printf (" interface: '%s'\n", info->uri);
interface_id = spa_id_map_get_id (data->map, info->uri); interface_id = spa_id_map_get_id (data->map, info->uri);
@ -179,7 +181,7 @@ main (int argc, char *argv[])
SpaResult res; SpaResult res;
void *handle; void *handle;
SpaEnumHandleFactoryFunc enum_func; SpaEnumHandleFactoryFunc enum_func;
void *state = NULL; unsigned int index = 0;
if (argc < 2) { if (argc < 2) {
printf ("usage: %s <plugin.so>\n", argv[0]); printf ("usage: %s <plugin.so>\n", argv[0]);
@ -218,12 +220,13 @@ main (int argc, char *argv[])
while (true) { while (true) {
const SpaHandleFactory *factory; const SpaHandleFactory *factory;
if ((res = enum_func (&factory, &state)) < 0) { if ((res = enum_func (&factory, index)) < 0) {
if (res != SPA_RESULT_ENUM_END) if (res != SPA_RESULT_ENUM_END)
printf ("can't enumerate factories: %d\n", res); printf ("can't enumerate factories: %d\n", res);
break; break;
} }
inspect_factory (&data, factory); inspect_factory (&data, factory);
index++;
} }
return 0; return 0;

View file

@ -123,15 +123,15 @@ static void
handle_monitor (AppData *data, SpaMonitor *monitor) handle_monitor (AppData *data, SpaMonitor *monitor)
{ {
SpaResult res; SpaResult res;
void *state = NULL; unsigned int index;
if (monitor->info) if (monitor->info)
spa_debug_dict (monitor->info); spa_debug_dict (monitor->info);
while (true) { for (index = 0; ; index++) {
SpaMonitorItem *item; SpaMonitorItem *item;
if ((res = spa_monitor_enum_items (monitor, &item, &state)) < 0) { if ((res = spa_monitor_enum_items (monitor, &item, index)) < 0) {
if (res != SPA_RESULT_ENUM_END) if (res != SPA_RESULT_ENUM_END)
printf ("spa_monitor_enum_items: got error %d\n", res); printf ("spa_monitor_enum_items: got error %d\n", res);
break; break;
@ -181,7 +181,7 @@ main (int argc, char *argv[])
SpaResult res; SpaResult res;
void *handle; void *handle;
SpaEnumHandleFactoryFunc enum_func; SpaEnumHandleFactoryFunc enum_func;
void *fstate = NULL; unsigned int fidx;
data.map = spa_id_map_get_default (); data.map = spa_id_map_get_default ();
data.log = NULL; data.log = NULL;
@ -214,20 +214,20 @@ main (int argc, char *argv[])
return -1; return -1;
} }
while (true) { for (fidx = 0;; fidx++) {
const SpaHandleFactory *factory; const SpaHandleFactory *factory;
void *istate = NULL; unsigned int iidx;
if ((res = enum_func (&factory, &fstate)) < 0) { if ((res = enum_func (&factory, fidx)) < 0) {
if (res != SPA_RESULT_ENUM_END) if (res != SPA_RESULT_ENUM_END)
printf ("can't enumerate factories: %d\n", res); printf ("can't enumerate factories: %d\n", res);
break; break;
} }
while (true) { for (iidx = 0;; iidx++) {
const SpaInterfaceInfo *info; const SpaInterfaceInfo *info;
if ((res = spa_handle_factory_enum_interface_info (factory, &info, &istate)) < 0) { if ((res = spa_handle_factory_enum_interface_info (factory, &info, iidx)) < 0) {
if (res != SPA_RESULT_ENUM_END) if (res != SPA_RESULT_ENUM_END)
printf ("can't enumerate interfaces: %d\n", res); printf ("can't enumerate interfaces: %d\n", res);
break; break;