mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05: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
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ static int impl_node_enum_params(struct spa_node *node,
|
|||
struct spa_pod_builder *builder)
|
||||
{
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
struct spa_pod *param;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
uint8_t buffer[1024];
|
||||
|
|
@ -59,85 +58,92 @@ static int impl_node_enum_params(struct spa_node *node,
|
|||
spa_return_val_if_fail(builder != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
t = &this->type;
|
||||
|
||||
next:
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
|
||||
if (id == t->param.idList) {
|
||||
uint32_t list[] = { t->param.idPropInfo,
|
||||
t->param.idProps };
|
||||
switch (id) {
|
||||
case SPA_ID_PARAM_List:
|
||||
{
|
||||
uint32_t list[] = { SPA_ID_PARAM_PropInfo,
|
||||
SPA_ID_PARAM_Props };
|
||||
|
||||
if (*index < SPA_N_ELEMENTS(list))
|
||||
param = spa_pod_builder_object(&b, id, t->param.List,
|
||||
":", t->param.listId, "I", list[*index]);
|
||||
param = spa_pod_builder_object(&b, id, SPA_ID_OBJECT_ParamList,
|
||||
":", SPA_PARAM_LIST_id, "I", list[*index]);
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
else if (id == t->param.idPropInfo) {
|
||||
case SPA_ID_PARAM_PropInfo:
|
||||
{
|
||||
struct props *p = &this->props;
|
||||
|
||||
switch (*index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param.PropInfo,
|
||||
":", t->param.propId, "I", t->prop_device,
|
||||
":", t->param.propName, "s", "The ALSA device",
|
||||
":", t->param.propType, "S", p->device, sizeof(p->device));
|
||||
id, SPA_ID_OBJECT_PropInfo,
|
||||
":", SPA_PROP_INFO_id, "I", SPA_PROP_device,
|
||||
":", SPA_PROP_INFO_name, "s", "The ALSA device",
|
||||
":", SPA_PROP_INFO_type, "S", p->device, sizeof(p->device));
|
||||
break;
|
||||
case 1:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param.PropInfo,
|
||||
":", t->param.propId, "I", t->prop_device_name,
|
||||
":", t->param.propName, "s", "The ALSA device name",
|
||||
":", t->param.propType, "S-r", p->device_name, sizeof(p->device_name));
|
||||
id, SPA_ID_OBJECT_PropInfo,
|
||||
":", SPA_PROP_INFO_id, "I", SPA_PROP_deviceName,
|
||||
":", SPA_PROP_INFO_name, "s", "The ALSA device name",
|
||||
":", SPA_PROP_INFO_type, "S-r", p->device_name, sizeof(p->device_name));
|
||||
break;
|
||||
case 2:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param.PropInfo,
|
||||
":", t->param.propId, "I", t->prop_card_name,
|
||||
":", t->param.propName, "s", "The ALSA card name",
|
||||
":", t->param.propType, "S-r", p->card_name, sizeof(p->card_name));
|
||||
id, SPA_ID_OBJECT_PropInfo,
|
||||
":", SPA_PROP_INFO_id, "I", SPA_PROP_cardName,
|
||||
":", SPA_PROP_INFO_name, "s", "The ALSA card name",
|
||||
":", SPA_PROP_INFO_type, "S-r", p->card_name, sizeof(p->card_name));
|
||||
break;
|
||||
case 3:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param.PropInfo,
|
||||
":", t->param.propId, "I", t->prop_min_latency,
|
||||
":", t->param.propName, "s", "The minimum latency",
|
||||
":", t->param.propType, "ir", p->min_latency,
|
||||
id, SPA_ID_OBJECT_PropInfo,
|
||||
":", SPA_PROP_INFO_id, "I", SPA_PROP_minLatency,
|
||||
":", SPA_PROP_INFO_name, "s", "The minimum latency",
|
||||
":", SPA_PROP_INFO_type, "ir", p->min_latency,
|
||||
SPA_POD_PROP_MIN_MAX(1, INT32_MAX));
|
||||
break;
|
||||
case 4:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param.PropInfo,
|
||||
":", t->param.propId, "I", t->prop_max_latency,
|
||||
":", t->param.propName, "s", "The maximum latency",
|
||||
":", t->param.propType, "ir", p->max_latency,
|
||||
id, SPA_ID_OBJECT_PropInfo,
|
||||
":", SPA_PROP_INFO_id, "I", SPA_PROP_maxLatency,
|
||||
":", SPA_PROP_INFO_name, "s", "The maximum latency",
|
||||
":", SPA_PROP_INFO_type, "ir", p->max_latency,
|
||||
SPA_POD_PROP_MIN_MAX(1, INT32_MAX));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (id == t->param.idProps) {
|
||||
case SPA_ID_PARAM_Props:
|
||||
{
|
||||
struct props *p = &this->props;
|
||||
|
||||
switch (*index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->props,
|
||||
":", t->prop_device, "S", p->device, sizeof(p->device),
|
||||
":", t->prop_device_name, "S-r", p->device_name, sizeof(p->device_name),
|
||||
":", t->prop_card_name, "S-r", p->card_name, sizeof(p->card_name),
|
||||
":", t->prop_min_latency, "i", p->min_latency,
|
||||
":", t->prop_max_latency, "i", p->max_latency);
|
||||
id, SPA_ID_OBJECT_Props,
|
||||
":", SPA_PROP_device, "S", p->device, sizeof(p->device),
|
||||
":", SPA_PROP_deviceName, "S-r", p->device_name, sizeof(p->device_name),
|
||||
":", SPA_PROP_cardName, "S-r", p->card_name, sizeof(p->card_name),
|
||||
":", SPA_PROP_minLatency, "i", p->min_latency,
|
||||
":", SPA_PROP_maxLatency, "i", p->max_latency);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
default:
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
(*index)++;
|
||||
|
||||
|
|
@ -151,14 +157,12 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
|
|||
const struct spa_pod *param)
|
||||
{
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
t = &this->type;
|
||||
|
||||
if (id == t->param.idProps) {
|
||||
if (id == SPA_ID_PARAM_Props) {
|
||||
struct props *p = &this->props;
|
||||
|
||||
if (param == NULL) {
|
||||
|
|
@ -166,9 +170,9 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
|
|||
return 0;
|
||||
}
|
||||
spa_pod_object_parse(param,
|
||||
":", t->prop_device, "?S", p->device, sizeof(p->device),
|
||||
":", t->prop_min_latency, "?i", &p->min_latency,
|
||||
":", t->prop_max_latency, "?i", &p->max_latency, NULL);
|
||||
":", SPA_PROP_device, "?S", p->device, sizeof(p->device),
|
||||
":", SPA_PROP_minLatency, "?i", &p->min_latency,
|
||||
":", SPA_PROP_maxLatency, "?i", &p->max_latency, NULL);
|
||||
}
|
||||
else
|
||||
return -ENOENT;
|
||||
|
|
@ -186,7 +190,8 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
|
|||
|
||||
this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
|
||||
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
|
||||
switch (SPA_COMMAND_TYPE(command)) {
|
||||
case SPA_ID_COMMAND_NODE_Start:
|
||||
if (!this->have_format)
|
||||
return -EIO;
|
||||
if (this->n_buffers == 0)
|
||||
|
|
@ -194,12 +199,14 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
|
|||
|
||||
if ((res = spa_alsa_start(this, false)) < 0)
|
||||
return res;
|
||||
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
|
||||
break;
|
||||
case SPA_ID_COMMAND_NODE_Pause:
|
||||
if ((res = spa_alsa_pause(this, false)) < 0)
|
||||
return res;
|
||||
} else
|
||||
break;
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -295,7 +302,6 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
{
|
||||
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
struct spa_pod *param;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
uint8_t buffer[1024];
|
||||
|
|
@ -305,115 +311,110 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
spa_return_val_if_fail(builder != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
t = &this->type;
|
||||
|
||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||
|
||||
next:
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
|
||||
if (id == t->param.idList) {
|
||||
uint32_t list[] = { t->param.idEnumFormat,
|
||||
t->param.idFormat,
|
||||
t->param.idBuffers,
|
||||
t->param.idMeta,
|
||||
t->param_io.idBuffers,
|
||||
t->param_io.idClock, };
|
||||
switch (id) {
|
||||
case SPA_ID_PARAM_List:
|
||||
{
|
||||
uint32_t list[] = { SPA_ID_PARAM_EnumFormat,
|
||||
SPA_ID_PARAM_Format,
|
||||
SPA_ID_PARAM_Buffers,
|
||||
SPA_ID_PARAM_Meta,
|
||||
SPA_ID_PARAM_IO, };
|
||||
|
||||
if (*index < SPA_N_ELEMENTS(list))
|
||||
param = spa_pod_builder_object(&b, id, t->param.List,
|
||||
":", t->param.listId, "I", list[*index]);
|
||||
param = spa_pod_builder_object(&b, id, SPA_ID_OBJECT_ParamList,
|
||||
":", SPA_PARAM_LIST_id, "I", list[*index]);
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
else if (id == t->param.idEnumFormat) {
|
||||
case SPA_ID_PARAM_EnumFormat:
|
||||
return spa_alsa_enum_format(this, index, filter, result, builder);
|
||||
}
|
||||
else if (id == t->param.idFormat) {
|
||||
|
||||
case SPA_ID_PARAM_Format:
|
||||
if (!this->have_format)
|
||||
return -EIO;
|
||||
if (*index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_pod_builder_object(&b,
|
||||
t->param.idFormat, t->format,
|
||||
"I", t->media_type.audio,
|
||||
"I", t->media_subtype.raw,
|
||||
":", t->format_audio.format, "I", this->current_format.info.raw.format,
|
||||
":", t->format_audio.layout, "i", this->current_format.info.raw.layout,
|
||||
":", t->format_audio.rate, "i", this->current_format.info.raw.rate,
|
||||
":", t->format_audio.channels, "i", this->current_format.info.raw.channels);
|
||||
}
|
||||
else if (id == t->param.idBuffers) {
|
||||
id, SPA_ID_OBJECT_Format,
|
||||
"I", SPA_MEDIA_TYPE_audio,
|
||||
"I", SPA_MEDIA_SUBTYPE_raw,
|
||||
":", SPA_FORMAT_AUDIO_format, "I", this->current_format.info.raw.format,
|
||||
":", SPA_FORMAT_AUDIO_layout, "i", this->current_format.info.raw.layout,
|
||||
":", SPA_FORMAT_AUDIO_rate, "i", this->current_format.info.raw.rate,
|
||||
":", SPA_FORMAT_AUDIO_channels, "i", this->current_format.info.raw.channels);
|
||||
break;
|
||||
|
||||
case SPA_ID_PARAM_Buffers:
|
||||
if (!this->have_format)
|
||||
return -EIO;
|
||||
if (*index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_buffers.Buffers,
|
||||
":", t->param_buffers.size, "iru", this->props.max_latency *
|
||||
this->frame_size,
|
||||
id, SPA_ID_OBJECT_ParamBuffers,
|
||||
":", SPA_PARAM_BUFFERS_buffers, "ir", 1,
|
||||
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
|
||||
":", SPA_PARAM_BUFFERS_blocks, "i", 1,
|
||||
":", SPA_PARAM_BUFFERS_size, "iru",
|
||||
this->props.max_latency * this->frame_size,
|
||||
SPA_POD_PROP_MIN_MAX(this->props.min_latency * this->frame_size,
|
||||
INT32_MAX),
|
||||
":", t->param_buffers.stride, "i", 0,
|
||||
":", t->param_buffers.buffers, "ir", 1,
|
||||
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
|
||||
":", t->param_buffers.align, "i", 16);
|
||||
}
|
||||
else if (id == t->param.idMeta) {
|
||||
":", SPA_PARAM_BUFFERS_stride, "i", 0,
|
||||
":", SPA_PARAM_BUFFERS_align, "i", 16);
|
||||
break;
|
||||
|
||||
case SPA_ID_PARAM_Meta:
|
||||
if (!this->have_format)
|
||||
return -EIO;
|
||||
|
||||
switch (*index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_meta.Meta,
|
||||
":", t->param_meta.type, "I", t->meta.Header,
|
||||
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
|
||||
id, SPA_ID_OBJECT_ParamMeta,
|
||||
":", SPA_PARAM_META_type, "I", SPA_META_Header,
|
||||
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (id == t->param_io.idBuffers) {
|
||||
break;
|
||||
|
||||
case SPA_ID_PARAM_IO:
|
||||
switch (*index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_io.Buffers,
|
||||
":", t->param_io.id, "I", t->io.Buffers,
|
||||
":", t->param_io.size, "i", sizeof(struct spa_io_buffers));
|
||||
id, SPA_ID_OBJECT_ParamIO,
|
||||
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Buffers,
|
||||
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (id == t->param_io.idControl) {
|
||||
switch (*index) {
|
||||
case 0:
|
||||
case 1:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_io.Control,
|
||||
":", t->param_io.id, "I", t->io.ControlRange,
|
||||
":", t->param_io.size, "i", sizeof(struct spa_io_control_range));
|
||||
id, SPA_ID_OBJECT_ParamIO,
|
||||
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_ControlRange,
|
||||
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_control_range));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (id == t->param_io.idClock) {
|
||||
switch (*index) {
|
||||
case 0:
|
||||
case 2:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_io.Clock,
|
||||
":", t->param_io.id, "I", t->io.Clock,
|
||||
":", t->param_io.size, "i", sizeof(struct spa_io_clock));
|
||||
id, SPA_ID_OBJECT_ParamIO,
|
||||
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Clock,
|
||||
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_clock));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
default:
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
(*index)++;
|
||||
|
||||
|
|
@ -454,11 +455,11 @@ static int port_set_format(struct spa_node *node,
|
|||
"I", &info.media_subtype)) < 0)
|
||||
return err;
|
||||
|
||||
if (info.media_type != this->type.media_type.audio ||
|
||||
info.media_subtype != this->type.media_subtype.raw)
|
||||
if (info.media_type != SPA_MEDIA_TYPE_audio ||
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
|
||||
return -EINVAL;
|
||||
|
||||
if (spa_format_audio_raw_parse(format, &info.info.raw, &this->type.format_audio) < 0)
|
||||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if ((err = spa_alsa_set_format(this, &info, flags)) < 0)
|
||||
|
|
@ -481,17 +482,11 @@ impl_node_port_set_param(struct spa_node *node,
|
|||
uint32_t id, uint32_t flags,
|
||||
const struct spa_pod *param)
|
||||
{
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
t = &this->type;
|
||||
spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL);
|
||||
|
||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||
|
||||
if (id == t->param.idFormat) {
|
||||
if (id == SPA_ID_PARAM_Format) {
|
||||
return port_set_format(node, direction, port_id, flags, param);
|
||||
}
|
||||
else
|
||||
|
|
@ -531,12 +526,12 @@ impl_node_port_use_buffers(struct spa_node *node,
|
|||
b->buf = buffers[i];
|
||||
b->flags = BUFFER_FLAG_OUT;
|
||||
|
||||
b->h = spa_buffer_find_meta_data(b->buf, this->type.meta.Header, sizeof(*b->h));
|
||||
b->h = spa_buffer_find_meta_data(b->buf, SPA_META_Header, sizeof(*b->h));
|
||||
|
||||
type = d[0].type;
|
||||
if ((type == this->type.data.MemFd ||
|
||||
type == this->type.data.DmaBuf ||
|
||||
type == this->type.data.MemPtr) && d[0].data == NULL) {
|
||||
if ((type == SPA_DATA_MemFd ||
|
||||
type == SPA_DATA_DmaBuf ||
|
||||
type == SPA_DATA_MemPtr) && d[0].data == NULL) {
|
||||
spa_log_error(this->log, NAME " %p: need mapped memory", this);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
@ -580,24 +575,26 @@ impl_node_port_set_io(struct spa_node *node,
|
|||
void *data, size_t size)
|
||||
{
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
t = &this->type;
|
||||
|
||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||
|
||||
if (id == t->io.Buffers)
|
||||
switch (id) {
|
||||
case SPA_ID_IO_Buffers:
|
||||
this->io = data;
|
||||
else if (id == t->io.ControlRange)
|
||||
break;
|
||||
case SPA_ID_IO_ControlRange:
|
||||
this->range = data;
|
||||
else if (id == t->io.Clock)
|
||||
break;
|
||||
case SPA_ID_IO_Clock:
|
||||
this->clock = data;
|
||||
else
|
||||
break;
|
||||
default:
|
||||
return -ENOENT;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -692,7 +689,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
|
|||
|
||||
this = (struct state *) handle;
|
||||
|
||||
if (interface_id == this->type.node)
|
||||
if (interface_id == SPA_ID_INTERFACE_Node)
|
||||
*interface = &this->node;
|
||||
else
|
||||
return -ENOENT;
|
||||
|
|
@ -726,21 +723,14 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
handle->clear = impl_clear;
|
||||
|
||||
this = (struct state *) 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__DataLoop) == 0)
|
||||
else if (support[i].type == SPA_ID_INTERFACE_DataLoop)
|
||||
this->data_loop = 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, "a type-map is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (this->data_loop == NULL) {
|
||||
spa_log_error(this->log, "a data loop is needed");
|
||||
return -EINVAL;
|
||||
|
|
@ -749,7 +739,6 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
spa_log_error(this->log, "a main loop is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
init_type(&this->type, this->map);
|
||||
|
||||
this->node = impl_node;
|
||||
this->stream = SND_PCM_STREAM_PLAYBACK;
|
||||
|
|
@ -772,7 +761,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
}
|
||||
|
||||
static const struct spa_interface_info impl_interfaces[] = {
|
||||
{SPA_TYPE__Node,},
|
||||
{SPA_ID_INTERFACE_Node,},
|
||||
};
|
||||
|
||||
static int
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ static int impl_node_enum_params(struct spa_node *node,
|
|||
struct spa_pod_builder *builder)
|
||||
{
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
struct spa_pod *param;
|
||||
uint8_t buffer[1024];
|
||||
struct spa_pod_builder b = { 0 };
|
||||
|
|
@ -62,82 +61,87 @@ static int impl_node_enum_params(struct spa_node *node,
|
|||
spa_return_val_if_fail(builder != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
t = &this->type;
|
||||
p = &this->props;
|
||||
|
||||
next:
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
|
||||
if (id == t->param.idList) {
|
||||
uint32_t list[] = { t->param.idPropInfo,
|
||||
t->param.idProps };
|
||||
switch (id) {
|
||||
case SPA_ID_PARAM_List:
|
||||
{
|
||||
uint32_t list[] = { SPA_ID_PARAM_PropInfo,
|
||||
SPA_ID_PARAM_Props, };
|
||||
|
||||
if (*index < SPA_N_ELEMENTS(list))
|
||||
param = spa_pod_builder_object(&b, id, t->param.List,
|
||||
":", t->param.listId, "I", list[*index]);
|
||||
param = spa_pod_builder_object(&b, id, SPA_ID_OBJECT_ParamList,
|
||||
":", SPA_PARAM_LIST_id, "I", list[*index]);
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
else if (id == t->param.idPropInfo) {
|
||||
case SPA_ID_PARAM_PropInfo:
|
||||
switch (*index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param.PropInfo,
|
||||
":", t->param.propId, "I", t->prop_device,
|
||||
":", t->param.propName, "s", "The ALSA device",
|
||||
":", t->param.propType, "S", p->device, sizeof(p->device));
|
||||
id, SPA_ID_OBJECT_PropInfo,
|
||||
":", SPA_PROP_INFO_id, "I", SPA_PROP_device,
|
||||
":", SPA_PROP_INFO_name, "s", "The ALSA device",
|
||||
":", SPA_PROP_INFO_type, "S", p->device, sizeof(p->device));
|
||||
break;
|
||||
case 1:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param.PropInfo,
|
||||
":", t->param.propId, "I", t->prop_device_name,
|
||||
":", t->param.propName, "s", "The ALSA device name",
|
||||
":", t->param.propType, "S-r", p->device_name, sizeof(p->device_name));
|
||||
id, SPA_ID_OBJECT_PropInfo,
|
||||
":", SPA_PROP_INFO_id, "I", SPA_PROP_deviceName,
|
||||
":", SPA_PROP_INFO_name, "s", "The ALSA device name",
|
||||
":", SPA_PROP_INFO_type, "S-r", p->device_name, sizeof(p->device_name));
|
||||
break;
|
||||
case 2:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param.PropInfo,
|
||||
":", t->param.propId, "I", t->prop_card_name,
|
||||
":", t->param.propName, "s", "The ALSA card name",
|
||||
":", t->param.propType, "S-r", p->card_name, sizeof(p->card_name));
|
||||
id, SPA_ID_OBJECT_PropInfo,
|
||||
":", SPA_PROP_INFO_id, "I", SPA_PROP_cardName,
|
||||
":", SPA_PROP_INFO_name, "s", "The ALSA card name",
|
||||
":", SPA_PROP_INFO_type, "S-r", p->card_name, sizeof(p->card_name));
|
||||
break;
|
||||
case 3:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param.PropInfo,
|
||||
":", t->param.propId, "I", t->prop_min_latency,
|
||||
":", t->param.propName, "s", "The minimum latency",
|
||||
":", t->param.propType, "ir", p->min_latency,
|
||||
id, SPA_ID_OBJECT_PropInfo,
|
||||
":", SPA_PROP_INFO_id, "I", SPA_PROP_minLatency,
|
||||
":", SPA_PROP_INFO_name, "s", "The minimum latency",
|
||||
":", SPA_PROP_INFO_type, "ir", p->min_latency,
|
||||
SPA_POD_PROP_MIN_MAX(1, INT32_MAX));
|
||||
break;
|
||||
case 4:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param.PropInfo,
|
||||
":", t->param.propId, "I", t->prop_max_latency,
|
||||
":", t->param.propName, "s", "The maximum latency",
|
||||
":", t->param.propType, "ir", p->max_latency,
|
||||
id, SPA_ID_OBJECT_PropInfo,
|
||||
":", SPA_PROP_INFO_id, "I", SPA_PROP_maxLatency,
|
||||
":", SPA_PROP_INFO_name, "s", "The maximum latency",
|
||||
":", SPA_PROP_INFO_type, "ir", p->max_latency,
|
||||
SPA_POD_PROP_MIN_MAX(1, INT32_MAX));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (id == t->param.idProps) {
|
||||
break;
|
||||
|
||||
case SPA_ID_PARAM_Props:
|
||||
switch (*index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->props,
|
||||
":", t->prop_device, "S", p->device, sizeof(p->device),
|
||||
":", t->prop_device_name, "S-r", p->device_name, sizeof(p->device_name),
|
||||
":", t->prop_card_name, "S-r", p->card_name, sizeof(p->card_name),
|
||||
":", t->prop_min_latency, "i", p->min_latency,
|
||||
":", t->prop_max_latency, "i", p->max_latency);
|
||||
id, SPA_ID_OBJECT_Props,
|
||||
":", SPA_PROP_device, "S", p->device, sizeof(p->device),
|
||||
":", SPA_PROP_deviceName, "S-r", p->device_name, sizeof(p->device_name),
|
||||
":", SPA_PROP_cardName, "S-r", p->card_name, sizeof(p->card_name),
|
||||
":", SPA_PROP_minLatency, "i", p->min_latency,
|
||||
":", SPA_PROP_maxLatency, "i", p->max_latency);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
default:
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
(*index)++;
|
||||
|
||||
|
|
@ -151,14 +155,14 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
|
|||
const struct spa_pod *param)
|
||||
{
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
t = &this->type;
|
||||
|
||||
if (id == t->param.idProps) {
|
||||
switch (id) {
|
||||
case SPA_ID_PARAM_Props:
|
||||
{
|
||||
struct props *p = &this->props;
|
||||
|
||||
if (param == NULL) {
|
||||
|
|
@ -166,12 +170,14 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
|
|||
return 0;
|
||||
}
|
||||
spa_pod_object_parse(param,
|
||||
":", t->prop_device, "?S", p->device, sizeof(p->device),
|
||||
":", t->prop_min_latency, "?i", &p->min_latency,
|
||||
":", t->prop_max_latency, "?i", &p->max_latency, NULL);
|
||||
":", SPA_PROP_device, "?S", p->device, sizeof(p->device),
|
||||
":", SPA_PROP_minLatency, "?i", &p->min_latency,
|
||||
":", SPA_PROP_maxLatency, "?i", &p->max_latency, NULL);
|
||||
break;
|
||||
}
|
||||
else
|
||||
default:
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -186,7 +192,8 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
|
|||
|
||||
this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
|
||||
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
|
||||
switch (SPA_COMMAND_TYPE(command)) {
|
||||
case SPA_ID_COMMAND_NODE_Start:
|
||||
if (!this->have_format)
|
||||
return -EIO;
|
||||
if (this->n_buffers == 0)
|
||||
|
|
@ -194,12 +201,14 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
|
|||
|
||||
if ((res = spa_alsa_start(this, false)) < 0)
|
||||
return res;
|
||||
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
|
||||
break;
|
||||
case SPA_ID_COMMAND_NODE_Pause:
|
||||
if ((res = spa_alsa_pause(this, false)) < 0)
|
||||
return res;
|
||||
} else
|
||||
break;
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -303,7 +312,6 @@ static int port_get_format(struct spa_node *node,
|
|||
struct spa_pod_builder *builder)
|
||||
{
|
||||
struct state *this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
struct type *t = &this->type;
|
||||
|
||||
if (!this->have_format)
|
||||
return -EIO;
|
||||
|
|
@ -311,13 +319,13 @@ static int port_get_format(struct spa_node *node,
|
|||
return 0;
|
||||
|
||||
*param = spa_pod_builder_object(builder,
|
||||
t->param.idFormat, t->format,
|
||||
"I", t->media_type.audio,
|
||||
"I", t->media_subtype.raw,
|
||||
":", t->format_audio.format, "I", this->current_format.info.raw.format,
|
||||
":", t->format_audio.layout, "i", this->current_format.info.raw.layout,
|
||||
":", t->format_audio.rate, "i", this->current_format.info.raw.rate,
|
||||
":", t->format_audio.channels, "i", this->current_format.info.raw.channels);
|
||||
SPA_ID_PARAM_Format, SPA_ID_OBJECT_Format,
|
||||
"I", SPA_MEDIA_TYPE_audio,
|
||||
"I", SPA_MEDIA_SUBTYPE_raw,
|
||||
":", SPA_FORMAT_AUDIO_format, "I", this->current_format.info.raw.format,
|
||||
":", SPA_FORMAT_AUDIO_layout, "i", this->current_format.info.raw.layout,
|
||||
":", SPA_FORMAT_AUDIO_rate, "i", this->current_format.info.raw.rate,
|
||||
":", SPA_FORMAT_AUDIO_channels, "i", this->current_format.info.raw.channels);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -331,7 +339,6 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
struct spa_pod_builder *builder)
|
||||
{
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
struct spa_pod *param;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
uint8_t buffer[1024];
|
||||
|
|
@ -342,90 +349,92 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
spa_return_val_if_fail(builder != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
t = &this->type;
|
||||
|
||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||
|
||||
next:
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
|
||||
if (id == t->param.idList) {
|
||||
uint32_t list[] = { t->param.idEnumFormat,
|
||||
t->param.idFormat,
|
||||
t->param.idBuffers,
|
||||
t->param.idMeta };
|
||||
switch (id) {
|
||||
case SPA_ID_PARAM_List:
|
||||
{
|
||||
uint32_t list[] = { SPA_ID_PARAM_EnumFormat,
|
||||
SPA_ID_PARAM_Format,
|
||||
SPA_ID_PARAM_Buffers,
|
||||
SPA_ID_PARAM_Meta };
|
||||
|
||||
if (*index < SPA_N_ELEMENTS(list))
|
||||
param = spa_pod_builder_object(&b, id, t->param.List,
|
||||
":", t->param.listId, "I", list[*index]);
|
||||
param = spa_pod_builder_object(&b, id, SPA_ID_OBJECT_ParamList,
|
||||
":", SPA_PARAM_LIST_id, "I", list[*index]);
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
else if (id == t->param.idEnumFormat) {
|
||||
case SPA_ID_PARAM_EnumFormat:
|
||||
return spa_alsa_enum_format(this, index, filter, result, builder);
|
||||
}
|
||||
else if (id == t->param.idFormat) {
|
||||
|
||||
case SPA_ID_PARAM_Format:
|
||||
if ((res = port_get_format(node, direction, port_id, index, ¶m, &b)) <= 0)
|
||||
return res;
|
||||
}
|
||||
else if (id == t->param.idBuffers) {
|
||||
break;
|
||||
|
||||
case SPA_ID_PARAM_Buffers:
|
||||
if (!this->have_format)
|
||||
return -EIO;
|
||||
if (*index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_buffers.Buffers,
|
||||
":", t->param_buffers.size, "iru", this->props.max_latency *
|
||||
id, SPA_ID_OBJECT_ParamBuffers,
|
||||
":", SPA_PARAM_BUFFERS_buffers, "ir", 2,
|
||||
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
|
||||
":", SPA_PARAM_BUFFERS_blocks, "i", 1,
|
||||
":", SPA_PARAM_BUFFERS_size, "iru", this->props.max_latency *
|
||||
this->frame_size,
|
||||
SPA_POD_PROP_MIN_MAX(this->props.min_latency * this->frame_size,
|
||||
INT32_MAX),
|
||||
":", t->param_buffers.stride, "i", this->frame_size,
|
||||
":", t->param_buffers.buffers, "ir", 2,
|
||||
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
|
||||
":", t->param_buffers.align, "i", 16);
|
||||
}
|
||||
else if (id == t->param.idMeta) {
|
||||
":", SPA_PARAM_BUFFERS_stride, "i", this->frame_size,
|
||||
":", SPA_PARAM_BUFFERS_align, "i", 16);
|
||||
break;
|
||||
|
||||
case SPA_ID_PARAM_Meta:
|
||||
if (!this->have_format)
|
||||
return -EIO;
|
||||
|
||||
switch (*index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_meta.Meta,
|
||||
":", t->param_meta.type, "I", t->meta.Header,
|
||||
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
|
||||
id, SPA_ID_OBJECT_ParamMeta,
|
||||
":", SPA_PARAM_META_type, "I", SPA_META_Header,
|
||||
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (id == t->param_io.idBuffers) {
|
||||
break;
|
||||
|
||||
case SPA_ID_PARAM_IO:
|
||||
switch (*index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_io.Buffers,
|
||||
":", t->param_io.id, "I", t->io.Buffers,
|
||||
":", t->param_io.size, "i", sizeof(struct spa_io_buffers));
|
||||
id, SPA_ID_OBJECT_ParamIO,
|
||||
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Buffers,
|
||||
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (id == t->param_io.idClock) {
|
||||
switch (*index) {
|
||||
case 0:
|
||||
case 1:
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_io.Clock,
|
||||
":", t->param_io.id, "I", t->io.Clock,
|
||||
":", t->param_io.size, "i", sizeof(struct spa_io_clock));
|
||||
id, SPA_ID_OBJECT_ParamIO,
|
||||
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Clock,
|
||||
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_clock));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
default:
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
(*index)++;
|
||||
|
||||
|
|
@ -464,11 +473,11 @@ static int port_set_format(struct spa_node *node,
|
|||
"I", &info.media_type,
|
||||
"I", &info.media_subtype);
|
||||
|
||||
if (info.media_type != this->type.media_type.audio ||
|
||||
info.media_subtype != this->type.media_subtype.raw)
|
||||
if (info.media_type != SPA_MEDIA_TYPE_audio ||
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
|
||||
return -EINVAL;
|
||||
|
||||
if (spa_format_audio_raw_parse(format, &info.info.raw, &this->type.format_audio) < 0)
|
||||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if ((err = spa_alsa_set_format(this, &info, flags)) < 0)
|
||||
|
|
@ -491,17 +500,11 @@ impl_node_port_set_param(struct spa_node *node,
|
|||
uint32_t id, uint32_t flags,
|
||||
const struct spa_pod *param)
|
||||
{
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
t = &this->type;
|
||||
spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL);
|
||||
|
||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||
|
||||
if (id == t->param.idFormat) {
|
||||
if (id == SPA_ID_PARAM_Format) {
|
||||
return port_set_format(node, direction, port_id, flags, param);
|
||||
}
|
||||
else
|
||||
|
|
@ -538,11 +541,11 @@ impl_node_port_use_buffers(struct spa_node *node,
|
|||
b->buf = buffers[i];
|
||||
b->flags = 0;
|
||||
|
||||
b->h = spa_buffer_find_meta_data(b->buf, this->type.meta.Header, sizeof(*b->h));
|
||||
b->h = spa_buffer_find_meta_data(b->buf, SPA_META_Header, sizeof(*b->h));
|
||||
|
||||
if (!((d[0].type == this->type.data.MemFd ||
|
||||
d[0].type == this->type.data.DmaBuf ||
|
||||
d[0].type == this->type.data.MemPtr) && d[0].data != NULL)) {
|
||||
if (!((d[0].type == SPA_DATA_MemFd ||
|
||||
d[0].type == SPA_DATA_DmaBuf ||
|
||||
d[0].type == SPA_DATA_MemPtr) && d[0].data != NULL)) {
|
||||
spa_log_error(this->log, NAME " %p: need mapped memory", this);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
@ -589,18 +592,16 @@ impl_node_port_set_io(struct spa_node *node,
|
|||
void *data, size_t size)
|
||||
{
|
||||
struct state *this;
|
||||
struct type *t;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct state, node);
|
||||
t = &this->type;
|
||||
|
||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||
|
||||
if (id == t->io.Buffers)
|
||||
if (id == SPA_ID_IO_Buffers)
|
||||
this->io = data;
|
||||
else if (id == t->io.Clock)
|
||||
else if (id == SPA_ID_IO_Clock)
|
||||
this->clock = data;
|
||||
else
|
||||
return -ENOENT;
|
||||
|
|
@ -712,7 +713,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
|
|||
|
||||
this = (struct state *) handle;
|
||||
|
||||
if (interface_id == this->type.node)
|
||||
if (interface_id == SPA_ID_INTERFACE_Node)
|
||||
*interface = &this->node;
|
||||
else
|
||||
return -ENOENT;
|
||||
|
|
@ -751,19 +752,13 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this = (struct state *) 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__DataLoop) == 0)
|
||||
else if (support[i].type == SPA_ID_INTERFACE_DataLoop)
|
||||
this->data_loop = 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->data_loop == NULL) {
|
||||
spa_log_error(this->log, "a data loop is needed");
|
||||
return -EINVAL;
|
||||
|
|
@ -772,7 +767,6 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
spa_log_error(this->log, "a main loop is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
init_type(&this->type, this->map);
|
||||
|
||||
this->node = impl_node;
|
||||
this->stream = SND_PCM_STREAM_CAPTURE;
|
||||
|
|
@ -795,7 +789,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
}
|
||||
|
||||
static const struct spa_interface_info impl_interfaces[] = {
|
||||
{SPA_TYPE__Node,},
|
||||
{SPA_ID_INTERFACE_Node,},
|
||||
};
|
||||
|
||||
static int
|
||||
|
|
|
|||
|
|
@ -57,51 +57,42 @@ int spa_alsa_close(struct state *state)
|
|||
}
|
||||
|
||||
struct format_info {
|
||||
off_t format_offset;
|
||||
uint32_t spa_format;
|
||||
snd_pcm_format_t format;
|
||||
};
|
||||
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define _FORMAT_LE(fmt) offsetof(struct type, audio_format. fmt ## _OE)
|
||||
#define _FORMAT_BE(fmt) offsetof(struct type, audio_format. fmt)
|
||||
#elif __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define _FORMAT_LE(fmt) offsetof(struct type, audio_format. fmt)
|
||||
#define _FORMAT_BE(fmt) offsetof(struct type, audio_format. fmt ## _OE)
|
||||
#endif
|
||||
|
||||
static const struct format_info format_info[] = {
|
||||
{offsetof(struct type, audio_format.UNKNOWN), SND_PCM_FORMAT_UNKNOWN},
|
||||
{offsetof(struct type, audio_format.S8), SND_PCM_FORMAT_S8},
|
||||
{offsetof(struct type, audio_format.U8), SND_PCM_FORMAT_U8},
|
||||
{_FORMAT_LE(S16), SND_PCM_FORMAT_S16_LE},
|
||||
{_FORMAT_BE(S16), SND_PCM_FORMAT_S16_BE},
|
||||
{_FORMAT_LE(U16), SND_PCM_FORMAT_U16_LE},
|
||||
{_FORMAT_BE(U16), SND_PCM_FORMAT_U16_BE},
|
||||
{_FORMAT_LE(S24_32), SND_PCM_FORMAT_S24_LE},
|
||||
{_FORMAT_BE(S24_32), SND_PCM_FORMAT_S24_BE},
|
||||
{_FORMAT_LE(U24_32), SND_PCM_FORMAT_U24_LE},
|
||||
{_FORMAT_BE(U24_32), SND_PCM_FORMAT_U24_BE},
|
||||
{_FORMAT_LE(S24), SND_PCM_FORMAT_S24_3LE},
|
||||
{_FORMAT_BE(S24), SND_PCM_FORMAT_S24_3BE},
|
||||
{_FORMAT_LE(U24), SND_PCM_FORMAT_U24_3LE},
|
||||
{_FORMAT_BE(U24), SND_PCM_FORMAT_U24_3BE},
|
||||
{_FORMAT_LE(S32), SND_PCM_FORMAT_S32_LE},
|
||||
{_FORMAT_BE(S32), SND_PCM_FORMAT_S32_BE},
|
||||
{_FORMAT_LE(U32), SND_PCM_FORMAT_U32_LE},
|
||||
{_FORMAT_BE(U32), SND_PCM_FORMAT_U32_BE},
|
||||
{_FORMAT_LE(F32), SND_PCM_FORMAT_FLOAT_LE},
|
||||
{_FORMAT_BE(F32), SND_PCM_FORMAT_FLOAT_BE},
|
||||
{_FORMAT_LE(F64), SND_PCM_FORMAT_FLOAT64_LE},
|
||||
{_FORMAT_BE(F64), SND_PCM_FORMAT_FLOAT64_BE},
|
||||
{ SPA_AUDIO_FORMAT_UNKNOWN, SND_PCM_FORMAT_UNKNOWN},
|
||||
{ SPA_AUDIO_FORMAT_S8, SND_PCM_FORMAT_S8},
|
||||
{ SPA_AUDIO_FORMAT_U8, SND_PCM_FORMAT_U8},
|
||||
{ SPA_AUDIO_FORMAT_S16_LE, SND_PCM_FORMAT_S16_LE},
|
||||
{ SPA_AUDIO_FORMAT_S16_BE, SND_PCM_FORMAT_S16_BE},
|
||||
{ SPA_AUDIO_FORMAT_U16_LE, SND_PCM_FORMAT_U16_LE},
|
||||
{ SPA_AUDIO_FORMAT_U16_BE, SND_PCM_FORMAT_U16_BE},
|
||||
{ SPA_AUDIO_FORMAT_S24_32_LE, SND_PCM_FORMAT_S24_LE},
|
||||
{ SPA_AUDIO_FORMAT_S24_32_BE, SND_PCM_FORMAT_S24_BE},
|
||||
{ SPA_AUDIO_FORMAT_U24_32_LE, SND_PCM_FORMAT_U24_LE},
|
||||
{ SPA_AUDIO_FORMAT_U24_32_BE, SND_PCM_FORMAT_U24_BE},
|
||||
{ SPA_AUDIO_FORMAT_S24_LE, SND_PCM_FORMAT_S24_3LE},
|
||||
{ SPA_AUDIO_FORMAT_S24_BE, SND_PCM_FORMAT_S24_3BE},
|
||||
{ SPA_AUDIO_FORMAT_U24_LE, SND_PCM_FORMAT_U24_3LE},
|
||||
{ SPA_AUDIO_FORMAT_U24_BE, SND_PCM_FORMAT_U24_3BE},
|
||||
{ SPA_AUDIO_FORMAT_S32_LE, SND_PCM_FORMAT_S32_LE},
|
||||
{ SPA_AUDIO_FORMAT_S32_BE, SND_PCM_FORMAT_S32_BE},
|
||||
{ SPA_AUDIO_FORMAT_U32_LE, SND_PCM_FORMAT_U32_LE},
|
||||
{ SPA_AUDIO_FORMAT_U32_BE, SND_PCM_FORMAT_U32_BE},
|
||||
{ SPA_AUDIO_FORMAT_F32_LE, SND_PCM_FORMAT_FLOAT_LE},
|
||||
{ SPA_AUDIO_FORMAT_F32_BE, SND_PCM_FORMAT_FLOAT_BE},
|
||||
{ SPA_AUDIO_FORMAT_F64_LE, SND_PCM_FORMAT_FLOAT64_LE},
|
||||
{ SPA_AUDIO_FORMAT_F64_BE, SND_PCM_FORMAT_FLOAT64_BE},
|
||||
};
|
||||
|
||||
static snd_pcm_format_t spa_alsa_format_to_alsa(struct type *map, uint32_t format)
|
||||
static snd_pcm_format_t spa_format_to_alsa(uint32_t format)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < SPA_N_ELEMENTS(format_info); i++) {
|
||||
uint32_t f = *SPA_MEMBER(map, format_info[i].format_offset, uint32_t);
|
||||
if (f == format)
|
||||
if (format_info[i].spa_format == format)
|
||||
return format_info[i].format;
|
||||
}
|
||||
return SND_PCM_FORMAT_UNKNOWN;
|
||||
|
|
@ -142,26 +133,25 @@ spa_alsa_enum_format(struct state *state, uint32_t *index,
|
|||
snd_pcm_hw_params_alloca(¶ms);
|
||||
CHECK(snd_pcm_hw_params_any(hndl, params), "Broken configuration: no configurations available");
|
||||
|
||||
spa_pod_builder_push_object(&b, state->type.param.idEnumFormat, state->type.format);
|
||||
spa_pod_builder_push_object(&b, SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format);
|
||||
spa_pod_builder_add(&b,
|
||||
"I", state->type.media_type.audio,
|
||||
"I", state->type.media_subtype.raw, 0);
|
||||
"I", SPA_MEDIA_TYPE_audio,
|
||||
"I", SPA_MEDIA_SUBTYPE_raw, 0);
|
||||
|
||||
snd_pcm_format_mask_alloca(&fmask);
|
||||
snd_pcm_hw_params_get_format_mask(params, fmask);
|
||||
|
||||
prop = spa_pod_builder_deref(&b,
|
||||
spa_pod_builder_push_prop(&b, state->type.format_audio.format,
|
||||
spa_pod_builder_push_prop(&b, SPA_FORMAT_AUDIO_format,
|
||||
SPA_POD_PROP_RANGE_NONE));
|
||||
|
||||
for (i = 1, j = 0; i < SPA_N_ELEMENTS(format_info); i++) {
|
||||
const struct format_info *fi = &format_info[i];
|
||||
|
||||
if (snd_pcm_format_mask_test(fmask, fi->format)) {
|
||||
uint32_t f = *SPA_MEMBER(&state->type, fi->format_offset, uint32_t);
|
||||
if (j++ == 0)
|
||||
spa_pod_builder_id(&b, f);
|
||||
spa_pod_builder_id(&b, f);
|
||||
spa_pod_builder_id(&b, fi->spa_format);
|
||||
spa_pod_builder_id(&b, fi->spa_format);
|
||||
}
|
||||
}
|
||||
if (j > 1)
|
||||
|
|
@ -172,7 +162,7 @@ spa_alsa_enum_format(struct state *state, uint32_t *index,
|
|||
snd_pcm_hw_params_get_access_mask(params, amask);
|
||||
|
||||
prop = spa_pod_builder_deref(&b,
|
||||
spa_pod_builder_push_prop(&b, state->type.format_audio.layout,
|
||||
spa_pod_builder_push_prop(&b, SPA_FORMAT_AUDIO_layout,
|
||||
SPA_POD_PROP_RANGE_NONE));
|
||||
j = 0;
|
||||
if (snd_pcm_access_mask_test(amask, SND_PCM_ACCESS_MMAP_INTERLEAVED)) {
|
||||
|
|
@ -193,7 +183,7 @@ spa_alsa_enum_format(struct state *state, uint32_t *index,
|
|||
CHECK(snd_pcm_hw_params_get_rate_max(params, &max, &dir), "get_rate_max");
|
||||
|
||||
prop = spa_pod_builder_deref(&b,
|
||||
spa_pod_builder_push_prop(&b, state->type.format_audio.rate, SPA_POD_PROP_RANGE_NONE));
|
||||
spa_pod_builder_push_prop(&b, SPA_FORMAT_AUDIO_rate, SPA_POD_PROP_RANGE_NONE));
|
||||
|
||||
spa_pod_builder_int(&b, SPA_CLAMP(DEFAULT_RATE, min, max));
|
||||
if (min != max) {
|
||||
|
|
@ -207,7 +197,7 @@ spa_alsa_enum_format(struct state *state, uint32_t *index,
|
|||
CHECK(snd_pcm_hw_params_get_channels_max(params, &max), "get_channels_max");
|
||||
|
||||
prop = spa_pod_builder_deref(&b,
|
||||
spa_pod_builder_push_prop(&b, state->type.format_audio.channels, SPA_POD_PROP_RANGE_NONE));
|
||||
spa_pod_builder_push_prop(&b, SPA_FORMAT_AUDIO_channels, SPA_POD_PROP_RANGE_NONE));
|
||||
|
||||
spa_pod_builder_int(&b, SPA_CLAMP(DEFAULT_CHANNELS, min, max));
|
||||
if (min != max) {
|
||||
|
|
@ -261,7 +251,7 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
|
|||
CHECK(snd_pcm_hw_params_set_period_wakeup(hndl, params, 0), "set_period_wakeup");
|
||||
|
||||
/* set the sample format */
|
||||
format = spa_alsa_format_to_alsa(&state->type, info->format);
|
||||
format = spa_format_to_alsa(info->format);
|
||||
if (format == SND_PCM_FORMAT_UNKNOWN)
|
||||
return -EINVAL;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ extern "C" {
|
|||
|
||||
#include <asoundlib.h>
|
||||
|
||||
#include <spa/support/type-map.h>
|
||||
#include <spa/support/loop.h>
|
||||
#include <spa/support/log.h>
|
||||
#include <spa/utils/list.h>
|
||||
|
|
@ -61,66 +60,12 @@ struct buffer {
|
|||
struct spa_list link;
|
||||
};
|
||||
|
||||
struct type {
|
||||
uint32_t node;
|
||||
uint32_t format;
|
||||
uint32_t props;
|
||||
uint32_t prop_device;
|
||||
uint32_t prop_device_name;
|
||||
uint32_t prop_card_name;
|
||||
uint32_t prop_min_latency;
|
||||
uint32_t prop_max_latency;
|
||||
struct spa_type_io io;
|
||||
struct spa_type_param param;
|
||||
struct spa_type_meta meta;
|
||||
struct spa_type_data data;
|
||||
struct spa_type_media_type media_type;
|
||||
struct spa_type_media_subtype media_subtype;
|
||||
struct spa_type_media_subtype_audio media_subtype_audio;
|
||||
struct spa_type_audio_format audio_format;
|
||||
struct spa_type_event_node event_node;
|
||||
struct spa_type_command_node command_node;
|
||||
struct spa_type_format_audio format_audio;
|
||||
struct spa_type_param_buffers param_buffers;
|
||||
struct spa_type_param_meta param_meta;
|
||||
struct spa_type_param_io param_io;
|
||||
};
|
||||
|
||||
static inline void init_type(struct type *type, struct spa_type_map *map)
|
||||
{
|
||||
type->node = spa_type_map_get_id(map, SPA_TYPE__Node);
|
||||
type->format = spa_type_map_get_id(map, SPA_TYPE__Format);
|
||||
type->props = spa_type_map_get_id(map, SPA_TYPE__Props);
|
||||
type->prop_device = spa_type_map_get_id(map, SPA_TYPE_PROPS__device);
|
||||
type->prop_device_name = spa_type_map_get_id(map, SPA_TYPE_PROPS__deviceName);
|
||||
type->prop_card_name = spa_type_map_get_id(map, SPA_TYPE_PROPS__cardName);
|
||||
type->prop_min_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__minLatency);
|
||||
type->prop_max_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__maxLatency);
|
||||
|
||||
spa_type_io_map(map, &type->io);
|
||||
spa_type_param_map(map, &type->param);
|
||||
spa_type_meta_map(map, &type->meta);
|
||||
spa_type_data_map(map, &type->data);
|
||||
spa_type_media_type_map(map, &type->media_type);
|
||||
spa_type_media_subtype_map(map, &type->media_subtype);
|
||||
spa_type_media_subtype_audio_map(map, &type->media_subtype_audio);
|
||||
spa_type_audio_format_map(map, &type->audio_format);
|
||||
spa_type_event_node_map(map, &type->event_node);
|
||||
spa_type_command_node_map(map, &type->command_node);
|
||||
spa_type_format_audio_map(map, &type->format_audio);
|
||||
spa_type_param_buffers_map(map, &type->param_buffers);
|
||||
spa_type_param_meta_map(map, &type->param_meta);
|
||||
spa_type_param_io_map(map, &type->param_io);
|
||||
}
|
||||
|
||||
struct state {
|
||||
struct spa_handle handle;
|
||||
struct spa_node node;
|
||||
|
||||
uint32_t seq;
|
||||
|
||||
struct type type;
|
||||
struct spa_type_map *map;
|
||||
struct spa_log *log;
|
||||
struct spa_loop *main_loop;
|
||||
struct spa_loop *data_loop;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue