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

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

View file

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

View file

@ -363,12 +363,11 @@ spa_alsa_source_node_port_enum_formats (SpaNode *node,
uint32_t port_id,
SpaFormat **format,
const SpaFormat *filter,
void **state)
unsigned int index)
{
SpaALSASource *this;
int index;
if (node == NULL || format == NULL || state == NULL)
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
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))
return SPA_RESULT_INVALID_PORT;
index = (*state == NULL ? 0 : *(int*)state);
switch (index) {
case 0:
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;
}
*format = &this->query_format.format;
*(int*)state = ++index;
return SPA_RESULT_OK;
}
@ -902,22 +898,16 @@ static const SpaInterfaceInfo alsa_source_interfaces[] =
static SpaResult
alsa_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 (alsa_source_interfaces))
return SPA_RESULT_ENUM_END;
*info = &alsa_source_interfaces[index];
*(int*)state = ++index;
return SPA_RESULT_OK;
}

View file

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