mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
Remove dynamic types
Do not use dynamic types anymore. The reason is that it's difficult: - to maintain a shared type database over a network. - the extra overhead when translating between processes and for maintaining the translation tables. - race conditions in translating in RT-threads, this is a problem because we want to make event streams. We now have simple enums with types and extension points for all types. This is also nicer to use in general. We don't need the mapper anymore or pass strings around as types. There is a parallel type info system to get more info about ids and enums and their hierarchy. It can also be used for debugging.
This commit is contained in:
parent
e6977fa178
commit
fca3e1d85d
162 changed files with 5200 additions and 7461 deletions
|
|
@ -28,7 +28,7 @@
|
|||
#include <asoundlib.h>
|
||||
|
||||
#include <spa/support/log.h>
|
||||
#include <spa/support/type-map.h>
|
||||
#include <spa/utils/type.h>
|
||||
#include <spa/support/loop.h>
|
||||
#include <spa/support/plugin.h>
|
||||
#include <spa/monitor/monitor.h>
|
||||
|
|
@ -41,17 +41,6 @@
|
|||
extern const struct spa_handle_factory spa_alsa_sink_factory;
|
||||
extern const struct spa_handle_factory spa_alsa_source_factory;
|
||||
|
||||
struct type {
|
||||
uint32_t handle_factory;
|
||||
struct spa_type_monitor monitor;
|
||||
};
|
||||
|
||||
static inline void init_type(struct type *type, struct spa_type_map *map)
|
||||
{
|
||||
type->handle_factory = spa_type_map_get_id(map, SPA_TYPE__HandleFactory);
|
||||
spa_type_monitor_map(map, &type->monitor);
|
||||
}
|
||||
|
||||
struct device {
|
||||
int id;
|
||||
#define DEVICE_FLAG_VALID (1<<0)
|
||||
|
|
@ -76,8 +65,6 @@ struct impl {
|
|||
struct spa_handle handle;
|
||||
struct spa_monitor monitor;
|
||||
|
||||
struct type type;
|
||||
struct spa_type_map *map;
|
||||
struct spa_log *log;
|
||||
struct spa_loop *main_loop;
|
||||
|
||||
|
|
@ -133,7 +120,6 @@ fill_item(struct impl *this, snd_ctl_card_info_t *card_info,
|
|||
const char *str, *name, *klass = NULL;
|
||||
const struct spa_handle_factory *factory = NULL;
|
||||
char device_name[64], id[66];
|
||||
struct type *t = &this->type;
|
||||
struct udev_device *dev = card->dev;
|
||||
struct device *device;
|
||||
int device_idx = snd_pcm_info_get_device(dev_info);
|
||||
|
|
@ -175,16 +161,14 @@ fill_item(struct impl *this, snd_ctl_card_info_t *card_info,
|
|||
name = "Unknown";
|
||||
|
||||
spa_pod_builder_add(builder,
|
||||
"<", 0, t->monitor.MonitorItem,
|
||||
":", t->monitor.id, "s", id,
|
||||
":", t->monitor.flags, "i", 0,
|
||||
":", t->monitor.state, "i", SPA_MONITOR_ITEM_STATE_AVAILABLE,
|
||||
":", t->monitor.name, "s", name,
|
||||
":", t->monitor.klass, "s", klass,
|
||||
":", t->monitor.factory, "p", t->handle_factory, factory, NULL);
|
||||
|
||||
spa_pod_builder_add(builder,
|
||||
":", t->monitor.info, "[", NULL);
|
||||
"<", 0, SPA_ID_OBJECT_MonitorItem,
|
||||
":", SPA_MONITOR_ITEM_id, "s", id,
|
||||
":", SPA_MONITOR_ITEM_flags, "i", SPA_MONITOR_ITEM_FLAG_NONE,
|
||||
":", SPA_MONITOR_ITEM_state, "i", SPA_MONITOR_ITEM_STATE_AVAILABLE,
|
||||
":", SPA_MONITOR_ITEM_name, "s", name,
|
||||
":", SPA_MONITOR_ITEM_class, "s", klass,
|
||||
":", SPA_MONITOR_ITEM_factory, "p", SPA_ID_INTERFACE_HandleFactory, factory,
|
||||
":", SPA_MONITOR_ITEM_info, "[", NULL);
|
||||
|
||||
spa_pod_builder_add(builder,
|
||||
"s", "alsa.card", "s", card->name,
|
||||
|
|
@ -366,7 +350,6 @@ static void impl_on_fd_events(struct spa_source *source)
|
|||
uint32_t type;
|
||||
struct card *card;
|
||||
struct spa_event *event;
|
||||
struct type *t = &this->type;
|
||||
|
||||
dev = udev_monitor_receive_device(this->umonitor);
|
||||
|
||||
|
|
@ -374,18 +357,18 @@ static void impl_on_fd_events(struct spa_source *source)
|
|||
action = "change";
|
||||
|
||||
if (strcmp(action, "add") == 0) {
|
||||
type = this->type.monitor.Added;
|
||||
type = SPA_ID_EVENT_MONITOR_Added;
|
||||
} else if (strcmp(action, "change") == 0) {
|
||||
type = this->type.monitor.Changed;
|
||||
type = SPA_ID_EVENT_MONITOR_Changed;
|
||||
} else if (strcmp(action, "remove") == 0) {
|
||||
type = this->type.monitor.Removed;
|
||||
type = SPA_ID_EVENT_MONITOR_Removed;
|
||||
} else
|
||||
return;
|
||||
|
||||
if ((card = find_card(this, dev)) == NULL)
|
||||
return;
|
||||
|
||||
if (type == this->type.monitor.Removed) {
|
||||
if (type == SPA_ID_EVENT_MONITOR_Removed) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_DEVICES; i++) {
|
||||
|
|
@ -399,18 +382,18 @@ static void impl_on_fd_events(struct spa_source *source)
|
|||
snprintf(id, 64, "%s,%d/P", card->name, device->id);
|
||||
event = spa_pod_builder_object(&b, 0, type);
|
||||
spa_pod_builder_object(&b,
|
||||
0, t->monitor.MonitorItem,
|
||||
":", t->monitor.id, "s", id,
|
||||
":", t->monitor.name, "s", id);
|
||||
0, SPA_ID_OBJECT_MonitorItem,
|
||||
":", SPA_MONITOR_ITEM_id, "s", id,
|
||||
":", SPA_MONITOR_ITEM_name, "s", id);
|
||||
this->callbacks->event(this->callbacks_data, event);
|
||||
}
|
||||
if (SPA_FLAG_CHECK(device->flags, DEVICE_FLAG_RECORD)) {
|
||||
snprintf(id, 64, "%s,%d/C", card->name, device->id);
|
||||
event = spa_pod_builder_object(&b, 0, type);
|
||||
spa_pod_builder_object(&b,
|
||||
0, t->monitor.MonitorItem,
|
||||
":", t->monitor.id, "s", id,
|
||||
":", t->monitor.name, "s", id);
|
||||
0, SPA_ID_OBJECT_MonitorItem,
|
||||
":", SPA_MONITOR_ITEM_id, "s", id,
|
||||
":", SPA_MONITOR_ITEM_name, "s", id);
|
||||
this->callbacks->event(this->callbacks_data, event);
|
||||
}
|
||||
device->flags = 0;
|
||||
|
|
@ -561,7 +544,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
|
|||
|
||||
this = (struct impl *) handle;
|
||||
|
||||
if (interface_id == this->type.monitor.Monitor)
|
||||
if (interface_id == SPA_ID_INTERFACE_Monitor)
|
||||
*interface = &this->monitor;
|
||||
else
|
||||
return -ENOENT;
|
||||
|
|
@ -613,31 +596,23 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this = (struct impl *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
|
||||
if (support[i].type == SPA_ID_INTERFACE_Log)
|
||||
this->log = support[i].data;
|
||||
else if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
|
||||
else if (support[i].type == SPA_ID_INTERFACE_MainLoop)
|
||||
this->main_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error(this->log, "an id-map is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (this->main_loop == NULL) {
|
||||
spa_log_error(this->log, "a main-loop is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
init_type(&this->type, this->map);
|
||||
|
||||
this->monitor = impl_monitor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct spa_interface_info impl_interfaces[] = {
|
||||
{SPA_TYPE__Monitor,},
|
||||
{SPA_ID_INTERFACE_Monitor,},
|
||||
};
|
||||
|
||||
static int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue