mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
indent
This commit is contained in:
parent
d1a06ae247
commit
5b037661d9
154 changed files with 21017 additions and 23044 deletions
|
|
@ -33,215 +33,208 @@
|
|||
#include <lib/mapper.h>
|
||||
|
||||
struct type {
|
||||
struct spa_type_monitor monitor;
|
||||
struct spa_type_monitor monitor;
|
||||
};
|
||||
|
||||
struct data {
|
||||
struct type type;
|
||||
struct type type;
|
||||
|
||||
struct spa_type_map *map;
|
||||
struct spa_log *log;
|
||||
struct spa_loop main_loop;
|
||||
struct spa_type_map *map;
|
||||
struct spa_log *log;
|
||||
struct spa_loop main_loop;
|
||||
|
||||
struct spa_support support[3];
|
||||
uint32_t n_support;
|
||||
struct spa_support support[3];
|
||||
uint32_t n_support;
|
||||
|
||||
unsigned int n_sources;
|
||||
struct spa_source sources[16];
|
||||
unsigned int n_sources;
|
||||
struct spa_source sources[16];
|
||||
|
||||
bool rebuild_fds;
|
||||
struct pollfd fds[16];
|
||||
unsigned int n_fds;
|
||||
bool rebuild_fds;
|
||||
struct pollfd fds[16];
|
||||
unsigned int n_fds;
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
inspect_item (struct data *data, struct spa_monitor_item *item)
|
||||
static void inspect_item(struct data *data, struct spa_monitor_item *item)
|
||||
{
|
||||
spa_debug_pod (&item->object.pod, data->map);
|
||||
spa_debug_pod(&item->object.pod, data->map);
|
||||
}
|
||||
|
||||
static void
|
||||
on_monitor_event (struct spa_monitor *monitor,
|
||||
struct spa_event *event,
|
||||
void *user_data)
|
||||
static void on_monitor_event(struct spa_monitor *monitor, struct spa_event *event, void *user_data)
|
||||
{
|
||||
struct data *data = user_data;
|
||||
struct data *data = user_data;
|
||||
|
||||
if (SPA_EVENT_TYPE (event) == data->type.monitor.Added) {
|
||||
fprintf (stderr, "added:\n");
|
||||
inspect_item (data, (struct spa_monitor_item*)event);
|
||||
}
|
||||
else if (SPA_EVENT_TYPE (event) == data->type.monitor.Removed) {
|
||||
fprintf (stderr, "removed:\n");
|
||||
inspect_item (data, (struct spa_monitor_item*)event);
|
||||
}
|
||||
else if (SPA_EVENT_TYPE (event) == data->type.monitor.Changed) {
|
||||
fprintf (stderr, "changed:\n");
|
||||
inspect_item (data, (struct spa_monitor_item*)event);
|
||||
}
|
||||
if (SPA_EVENT_TYPE(event) == data->type.monitor.Added) {
|
||||
fprintf(stderr, "added:\n");
|
||||
inspect_item(data, (struct spa_monitor_item *) event);
|
||||
} else if (SPA_EVENT_TYPE(event) == data->type.monitor.Removed) {
|
||||
fprintf(stderr, "removed:\n");
|
||||
inspect_item(data, (struct spa_monitor_item *) event);
|
||||
} else if (SPA_EVENT_TYPE(event) == data->type.monitor.Changed) {
|
||||
fprintf(stderr, "changed:\n");
|
||||
inspect_item(data, (struct spa_monitor_item *) event);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
do_add_source (struct spa_loop *loop,
|
||||
struct spa_source *source)
|
||||
static int do_add_source(struct spa_loop *loop, struct spa_source *source)
|
||||
{
|
||||
struct data *data = SPA_CONTAINER_OF (loop, struct data, main_loop);
|
||||
struct data *data = SPA_CONTAINER_OF(loop, struct data, main_loop);
|
||||
|
||||
data->sources[data->n_sources] = *source;
|
||||
data->n_sources++;
|
||||
data->rebuild_fds = true;
|
||||
data->sources[data->n_sources] = *source;
|
||||
data->n_sources++;
|
||||
data->rebuild_fds = true;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
do_update_source (struct spa_source *source)
|
||||
static int do_update_source(struct spa_source *source)
|
||||
{
|
||||
return SPA_RESULT_OK;
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
do_remove_source (struct spa_source *source)
|
||||
static void do_remove_source(struct spa_source *source)
|
||||
{
|
||||
}
|
||||
|
||||
static const struct spa_monitor_callbacks callbacks = {
|
||||
on_monitor_event,
|
||||
on_monitor_event,
|
||||
};
|
||||
|
||||
static void
|
||||
handle_monitor (struct data *data, struct spa_monitor *monitor)
|
||||
static void handle_monitor(struct data *data, struct spa_monitor *monitor)
|
||||
{
|
||||
int res;
|
||||
uint32_t index;
|
||||
int res;
|
||||
uint32_t index;
|
||||
|
||||
if (monitor->info)
|
||||
spa_debug_dict (monitor->info);
|
||||
if (monitor->info)
|
||||
spa_debug_dict(monitor->info);
|
||||
|
||||
for (index = 0; ; index++) {
|
||||
struct spa_monitor_item *item;
|
||||
for (index = 0;; index++) {
|
||||
struct spa_monitor_item *item;
|
||||
|
||||
if ((res = spa_monitor_enum_items (monitor, &item, index)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
printf ("spa_monitor_enum_items: got error %d\n", res);
|
||||
break;
|
||||
}
|
||||
inspect_item (data, item);
|
||||
}
|
||||
if ((res = spa_monitor_enum_items(monitor, &item, index)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
printf("spa_monitor_enum_items: got error %d\n", res);
|
||||
break;
|
||||
}
|
||||
inspect_item(data, item);
|
||||
}
|
||||
|
||||
spa_monitor_set_callbacks (monitor, &callbacks, sizeof (callbacks), &data);
|
||||
spa_monitor_set_callbacks(monitor, &callbacks, sizeof(callbacks), &data);
|
||||
|
||||
while (true) {
|
||||
int i, r;
|
||||
while (true) {
|
||||
int i, r;
|
||||
|
||||
/* rebuild */
|
||||
if (data->rebuild_fds) {
|
||||
for (i = 0; i < data->n_sources; i++) {
|
||||
struct spa_source *p = &data->sources[i];
|
||||
data->fds[i].fd = p->fd;
|
||||
data->fds[i].events = p->mask;
|
||||
}
|
||||
data->n_fds = data->n_sources;
|
||||
data->rebuild_fds = false;
|
||||
}
|
||||
/* rebuild */
|
||||
if (data->rebuild_fds) {
|
||||
for (i = 0; i < data->n_sources; i++) {
|
||||
struct spa_source *p = &data->sources[i];
|
||||
data->fds[i].fd = p->fd;
|
||||
data->fds[i].events = p->mask;
|
||||
}
|
||||
data->n_fds = data->n_sources;
|
||||
data->rebuild_fds = false;
|
||||
}
|
||||
|
||||
r = poll ((struct pollfd *) data->fds, data->n_fds, -1);
|
||||
if (r < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
if (r == 0) {
|
||||
fprintf (stderr, "monitor %p: select timeout", monitor);
|
||||
break;
|
||||
}
|
||||
r = poll((struct pollfd *) data->fds, data->n_fds, -1);
|
||||
if (r < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
if (r == 0) {
|
||||
fprintf(stderr, "monitor %p: select timeout", monitor);
|
||||
break;
|
||||
}
|
||||
|
||||
/* after */
|
||||
for (i = 0; i < data->n_sources; i++) {
|
||||
struct spa_source *p = &data->sources[i];
|
||||
p->func (p);
|
||||
}
|
||||
}
|
||||
/* after */
|
||||
for (i = 0; i < data->n_sources; i++) {
|
||||
struct spa_source *p = &data->sources[i];
|
||||
p->func(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct data data = { 0 };
|
||||
int res;
|
||||
void *handle;
|
||||
spa_handle_factory_enum_func_t enum_func;
|
||||
uint32_t fidx;
|
||||
struct data data = { 0 };
|
||||
int res;
|
||||
void *handle;
|
||||
spa_handle_factory_enum_func_t enum_func;
|
||||
uint32_t fidx;
|
||||
|
||||
data.map = spa_type_map_get_default ();
|
||||
data.log = NULL;
|
||||
data.main_loop.size = sizeof (struct spa_loop);
|
||||
data.main_loop.add_source = do_add_source;
|
||||
data.main_loop.update_source = do_update_source;
|
||||
data.main_loop.remove_source = do_remove_source;
|
||||
data.map = spa_type_map_get_default();
|
||||
data.log = NULL;
|
||||
data.main_loop.size = sizeof(struct spa_loop);
|
||||
data.main_loop.add_source = do_add_source;
|
||||
data.main_loop.update_source = do_update_source;
|
||||
data.main_loop.remove_source = do_remove_source;
|
||||
|
||||
data.support[0].type = SPA_TYPE__TypeMap;
|
||||
data.support[0].data = data.map;
|
||||
data.support[1].type = SPA_TYPE__Log;
|
||||
data.support[1].data = data.log;
|
||||
data.support[2].type = SPA_TYPE_LOOP__MainLoop;
|
||||
data.support[2].data = &data.main_loop;
|
||||
data.n_support = 3;
|
||||
data.support[0].type = SPA_TYPE__TypeMap;
|
||||
data.support[0].data = data.map;
|
||||
data.support[1].type = SPA_TYPE__Log;
|
||||
data.support[1].data = data.log;
|
||||
data.support[2].type = SPA_TYPE_LOOP__MainLoop;
|
||||
data.support[2].data = &data.main_loop;
|
||||
data.n_support = 3;
|
||||
|
||||
spa_type_monitor_map (data.map, &data.type.monitor);
|
||||
spa_type_monitor_map(data.map, &data.type.monitor);
|
||||
|
||||
if (argc < 2) {
|
||||
printf ("usage: %s <plugin.so>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
if (argc < 2) {
|
||||
printf("usage: %s <plugin.so>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((handle = dlopen (argv[1], RTLD_NOW)) == NULL) {
|
||||
printf ("can't load %s\n", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
if ((enum_func = dlsym (handle, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) {
|
||||
printf ("can't find function\n");
|
||||
return -1;
|
||||
}
|
||||
if ((handle = dlopen(argv[1], RTLD_NOW)) == NULL) {
|
||||
printf("can't load %s\n", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
if ((enum_func = dlsym(handle, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) {
|
||||
printf("can't find function\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (fidx = 0;; fidx++) {
|
||||
const struct spa_handle_factory *factory;
|
||||
uint32_t iidx;
|
||||
for (fidx = 0;; fidx++) {
|
||||
const struct spa_handle_factory *factory;
|
||||
uint32_t iidx;
|
||||
|
||||
if ((res = enum_func (&factory, fidx)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
printf ("can't enumerate factories: %d\n", res);
|
||||
break;
|
||||
}
|
||||
if ((res = enum_func(&factory, fidx)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
printf("can't enumerate factories: %d\n", res);
|
||||
break;
|
||||
}
|
||||
|
||||
for (iidx = 0;; iidx++) {
|
||||
const struct spa_interface_info *info;
|
||||
for (iidx = 0;; iidx++) {
|
||||
const struct spa_interface_info *info;
|
||||
|
||||
if ((res = spa_handle_factory_enum_interface_info (factory, &info, iidx)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
printf ("can't enumerate interfaces: %d\n", res);
|
||||
break;
|
||||
}
|
||||
if ((res =
|
||||
spa_handle_factory_enum_interface_info(factory, &info, iidx)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
printf("can't enumerate interfaces: %d\n", res);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!strcmp (info->type, SPA_TYPE__Monitor)) {
|
||||
struct spa_handle *handle;
|
||||
void *interface;
|
||||
if (!strcmp(info->type, SPA_TYPE__Monitor)) {
|
||||
struct spa_handle *handle;
|
||||
void *interface;
|
||||
|
||||
handle = calloc (1, factory->size);
|
||||
if ((res = spa_handle_factory_init (factory, handle, NULL, data.support, data.n_support)) < 0) {
|
||||
printf ("can't make factory instance: %d\n", res);
|
||||
continue;
|
||||
}
|
||||
handle = calloc(1, factory->size);
|
||||
if ((res =
|
||||
spa_handle_factory_init(factory, handle, NULL, data.support,
|
||||
data.n_support)) < 0) {
|
||||
printf("can't make factory instance: %d\n", res);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((res = spa_handle_get_interface (handle, data.type.monitor.Monitor, &interface)) < 0) {
|
||||
printf ("can't get interface: %d\n", res);
|
||||
continue;
|
||||
}
|
||||
handle_monitor (&data, interface);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((res =
|
||||
spa_handle_get_interface(handle, data.type.monitor.Monitor,
|
||||
&interface)) < 0) {
|
||||
printf("can't get interface: %d\n", res);
|
||||
continue;
|
||||
}
|
||||
handle_monitor(&data, interface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue