mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
types: more work on types
This commit is contained in:
parent
acedfe71c0
commit
5825c62d6d
76 changed files with 1713 additions and 1477 deletions
|
|
@ -28,7 +28,7 @@
|
|||
#include <asoundlib.h>
|
||||
|
||||
#include <spa/log.h>
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/type-map.h>
|
||||
#include <spa/loop.h>
|
||||
#include <spa/monitor.h>
|
||||
#include <lib/debug.h>
|
||||
|
|
@ -45,15 +45,22 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
uint32_t handle_factory;
|
||||
SpaMonitorTypes monitor_types;
|
||||
} URI;
|
||||
SpaTypeMonitor monitor;
|
||||
} Type;
|
||||
|
||||
static inline void
|
||||
init_type (Type *type, SpaTypeMap *map)
|
||||
{
|
||||
type->handle_factory = spa_type_map_get_id (map, SPA_TYPE__HandleFactory);
|
||||
spa_type_monitor_map (map, &type->monitor);
|
||||
}
|
||||
|
||||
struct _SpaALSAMonitor {
|
||||
SpaHandle handle;
|
||||
SpaMonitor monitor;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
Type type;
|
||||
SpaTypeMap *map;
|
||||
SpaLog *log;
|
||||
SpaLoop *main_loop;
|
||||
|
||||
|
|
@ -170,20 +177,20 @@ fill_item (SpaALSAMonitor *this, ALSAItem *item, struct udev_device *udevice)
|
|||
|
||||
spa_pod_builder_init (&b, this->item_buffer, sizeof (this->item_buffer));
|
||||
|
||||
spa_pod_builder_push_object (&b, &f[0], 0, this->uri.monitor_types.MonitorItem);
|
||||
spa_pod_builder_push_object (&b, &f[0], 0, this->type.monitor.MonitorItem);
|
||||
|
||||
spa_pod_builder_add (&b,
|
||||
SPA_POD_PROP (&f[1], this->uri.monitor_types.id, 0, SPA_POD_TYPE_STRING, 1, udev_device_get_syspath (item->udevice)),
|
||||
SPA_POD_PROP (&f[1], this->uri.monitor_types.flags, 0, SPA_POD_TYPE_INT, 1, 0),
|
||||
SPA_POD_PROP (&f[1], this->uri.monitor_types.state, 0, SPA_POD_TYPE_INT, 1, SPA_MONITOR_ITEM_STATE_AVAILABLE),
|
||||
SPA_POD_PROP (&f[1], this->uri.monitor_types.name, 0, SPA_POD_TYPE_STRING, 1, name),
|
||||
SPA_POD_PROP (&f[1], this->uri.monitor_types.klass, 0, SPA_POD_TYPE_STRING, 1, "Audio/Device"),
|
||||
SPA_POD_PROP (&f[1], this->uri.monitor_types.factory, 0, SPA_POD_TYPE_POINTER, 1, this->uri.handle_factory,
|
||||
SPA_POD_PROP (&f[1], this->type.monitor.id, 0, SPA_POD_TYPE_STRING, 1, udev_device_get_syspath (item->udevice)),
|
||||
SPA_POD_PROP (&f[1], this->type.monitor.flags, 0, SPA_POD_TYPE_INT, 1, 0),
|
||||
SPA_POD_PROP (&f[1], this->type.monitor.state, 0, SPA_POD_TYPE_INT, 1, SPA_MONITOR_ITEM_STATE_AVAILABLE),
|
||||
SPA_POD_PROP (&f[1], this->type.monitor.name, 0, SPA_POD_TYPE_STRING, 1, name),
|
||||
SPA_POD_PROP (&f[1], this->type.monitor.klass, 0, SPA_POD_TYPE_STRING, 1, "Audio/Device"),
|
||||
SPA_POD_PROP (&f[1], this->type.monitor.factory, 0, SPA_POD_TYPE_POINTER, 1, this->type.handle_factory,
|
||||
factory),
|
||||
0);
|
||||
|
||||
spa_pod_builder_add (&b,
|
||||
SPA_POD_TYPE_PROP, &f[1], this->uri.monitor_types.info, 0,
|
||||
SPA_POD_TYPE_PROP, &f[1], this->type.monitor.info, 0,
|
||||
SPA_POD_TYPE_STRUCT, 1, &f[2], 0);
|
||||
|
||||
spa_pod_builder_add (&b,
|
||||
|
|
@ -271,11 +278,11 @@ alsa_on_fd_events (SpaSource *source)
|
|||
str = "change";
|
||||
|
||||
if (strcmp (str, "add") == 0) {
|
||||
type = this->uri.monitor_types.Added;
|
||||
type = this->type.monitor.Added;
|
||||
} else if (strcmp (str, "change") == 0) {
|
||||
type = this->uri.monitor_types.Changed;
|
||||
type = this->type.monitor.Changed;
|
||||
} else if (strcmp (str, "remove") == 0) {
|
||||
type = this->uri.monitor_types.Removed;
|
||||
type = this->type.monitor.Removed;
|
||||
} else
|
||||
return;
|
||||
|
||||
|
|
@ -402,7 +409,7 @@ spa_alsa_monitor_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaALSAMonitor *) handle;
|
||||
|
||||
if (interface_id == this->uri.monitor_types.Monitor)
|
||||
if (interface_id == this->type.monitor.Monitor)
|
||||
*interface = &this->monitor;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
|
@ -435,11 +442,11 @@ alsa_monitor_init (const SpaHandleFactory *factory,
|
|||
this = (SpaALSAMonitor *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_TYPE__IDMap) == 0)
|
||||
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_TYPE__Log) == 0)
|
||||
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0)
|
||||
this->log = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_TYPE_LOOP__MainLoop) == 0)
|
||||
else if (strcmp (support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
|
||||
this->main_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
|
|
@ -450,8 +457,8 @@ alsa_monitor_init (const SpaHandleFactory *factory,
|
|||
spa_log_error (this->log, "a main-loop is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.handle_factory = spa_id_map_get_id (this->map, SPA_TYPE__HandleFactory);
|
||||
spa_monitor_types_map (this->map, &this->uri.monitor_types);
|
||||
|
||||
init_type (&this->type, this->map);
|
||||
|
||||
this->monitor = alsamonitor;
|
||||
|
||||
|
|
|
|||
|
|
@ -82,13 +82,13 @@ spa_alsa_sink_node_get_props (SpaNode *node,
|
|||
|
||||
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer));
|
||||
|
||||
spa_pod_builder_props (&b, &f[0], this->uri.props,
|
||||
PROP (&f[1], this->uri.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device)),
|
||||
PROP (&f[1], this->uri.prop_device_name, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
|
||||
PROP (&f[1], this->uri.prop_card_name, -SPA_POD_TYPE_STRING, this->props.card_name, sizeof (this->props.card_name)),
|
||||
PROP_MM (&f[1], this->uri.prop_period_size, SPA_POD_TYPE_INT, this->props.period_size, 1, INT32_MAX),
|
||||
PROP_MM (&f[1], this->uri.prop_periods, SPA_POD_TYPE_INT, this->props.periods, 1, INT32_MAX),
|
||||
PROP (&f[1], this->uri.prop_period_event, SPA_POD_TYPE_BOOL, this->props.period_event));
|
||||
spa_pod_builder_props (&b, &f[0], this->type.props,
|
||||
PROP (&f[1], this->type.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device)),
|
||||
PROP (&f[1], this->type.prop_device_name, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
|
||||
PROP (&f[1], this->type.prop_card_name, -SPA_POD_TYPE_STRING, this->props.card_name, sizeof (this->props.card_name)),
|
||||
PROP_MM (&f[1], this->type.prop_period_size, SPA_POD_TYPE_INT, this->props.period_size, 1, INT32_MAX),
|
||||
PROP_MM (&f[1], this->type.prop_periods, SPA_POD_TYPE_INT, this->props.periods, 1, INT32_MAX),
|
||||
PROP (&f[1], this->type.prop_period_event, SPA_POD_TYPE_BOOL, this->props.period_event));
|
||||
|
||||
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
|
||||
|
||||
|
|
@ -111,10 +111,10 @@ spa_alsa_sink_node_set_props (SpaNode *node,
|
|||
return SPA_RESULT_OK;
|
||||
} else {
|
||||
spa_props_query (props,
|
||||
this->uri.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
|
||||
this->uri.prop_period_size, SPA_POD_TYPE_INT, &this->props.period_size,
|
||||
this->uri.prop_periods, SPA_POD_TYPE_INT, &this->props.periods,
|
||||
this->uri.prop_period_event, SPA_POD_TYPE_BOOL, &this->props.period_event,
|
||||
this->type.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
|
||||
this->type.prop_period_size, SPA_POD_TYPE_INT, &this->props.period_size,
|
||||
this->type.prop_periods, SPA_POD_TYPE_INT, &this->props.periods,
|
||||
this->type.prop_period_event, SPA_POD_TYPE_BOOL, &this->props.period_event,
|
||||
0);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -147,8 +147,8 @@ do_command (SpaLoop *loop,
|
|||
SpaResult res;
|
||||
SpaCommand *cmd = data;
|
||||
|
||||
if (SPA_COMMAND_TYPE (cmd) == this->uri.command_node.Start ||
|
||||
SPA_COMMAND_TYPE (cmd) == this->uri.command_node.Pause) {
|
||||
if (SPA_COMMAND_TYPE (cmd) == this->type.command_node.Start ||
|
||||
SPA_COMMAND_TYPE (cmd) == this->type.command_node.Pause) {
|
||||
res = spa_node_port_send_command (&this->node,
|
||||
SPA_DIRECTION_INPUT,
|
||||
0,
|
||||
|
|
@ -158,7 +158,7 @@ do_command (SpaLoop *loop,
|
|||
res = SPA_RESULT_NOT_IMPLEMENTED;
|
||||
|
||||
if (async) {
|
||||
SpaEventNodeAsyncComplete ac = SPA_EVENT_NODE_ASYNC_COMPLETE_INIT (this->uri.event_node.AsyncComplete,
|
||||
SpaEventNodeAsyncComplete ac = SPA_EVENT_NODE_ASYNC_COMPLETE_INIT (this->type.event_node.AsyncComplete,
|
||||
seq, res);
|
||||
spa_loop_invoke (this->main_loop,
|
||||
do_send_event,
|
||||
|
|
@ -181,8 +181,8 @@ spa_alsa_sink_node_send_command (SpaNode *node,
|
|||
|
||||
this = SPA_CONTAINER_OF (node, SpaALSASink, node);
|
||||
|
||||
if (SPA_COMMAND_TYPE (command) == this->uri.command_node.Start ||
|
||||
SPA_COMMAND_TYPE (command) == this->uri.command_node.Pause) {
|
||||
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start ||
|
||||
SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
|
||||
if (!this->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
|
|
@ -302,17 +302,17 @@ next:
|
|||
|
||||
switch (index++) {
|
||||
case 0:
|
||||
spa_pod_builder_format (&b, &f[0], this->uri.format,
|
||||
this->uri.media_types.audio, this->uri.media_subtypes.raw,
|
||||
PROP_U_EN (&f[1], this->uri.prop_audio.format, SPA_POD_TYPE_URI, 3, this->uri.audio_formats.S16,
|
||||
this->uri.audio_formats.S16,
|
||||
this->uri.audio_formats.S32),
|
||||
PROP_U_MM (&f[1], this->uri.prop_audio.rate, SPA_POD_TYPE_INT, 44100, 1, INT32_MAX),
|
||||
PROP_U_MM (&f[1], this->uri.prop_audio.channels, SPA_POD_TYPE_INT, 2, 1, INT32_MAX));
|
||||
spa_pod_builder_format (&b, &f[0], this->type.format,
|
||||
this->type.media_type.audio, this->type.media_subtype.raw,
|
||||
PROP_U_EN (&f[1], this->type.prop_audio.format, SPA_POD_TYPE_URI, 3, this->type.audio_format.S16,
|
||||
this->type.audio_format.S16,
|
||||
this->type.audio_format.S32),
|
||||
PROP_U_MM (&f[1], this->type.prop_audio.rate, SPA_POD_TYPE_INT, 44100, 1, INT32_MAX),
|
||||
PROP_U_MM (&f[1], this->type.prop_audio.channels, SPA_POD_TYPE_INT, 2, 1, INT32_MAX));
|
||||
break;
|
||||
case 1:
|
||||
spa_pod_builder_format (&b, &f[0], this->uri.format,
|
||||
this->uri.media_types.audio, this->uri.media_subtypes_audio.aac,
|
||||
spa_pod_builder_format (&b, &f[0], this->type.format,
|
||||
this->type.media_type.audio, this->type.media_subtype_audio.aac,
|
||||
SPA_POD_TYPE_NONE);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -385,23 +385,23 @@ spa_alsa_sink_node_port_set_format (SpaNode *node,
|
|||
this->info.params = this->params;
|
||||
|
||||
spa_pod_builder_init (&b, this->params_buffer, sizeof (this->params_buffer));
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->uri.alloc_param_buffers.Buffers,
|
||||
PROP (&f[1], this->uri.alloc_param_buffers.size, SPA_POD_TYPE_INT, this->period_frames * this->frame_size),
|
||||
PROP (&f[1], this->uri.alloc_param_buffers.stride, SPA_POD_TYPE_INT, 0),
|
||||
PROP_MM (&f[1], this->uri.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, 32, 1, 32),
|
||||
PROP (&f[1], this->uri.alloc_param_buffers.align, SPA_POD_TYPE_INT, 16));
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_buffers.Buffers,
|
||||
PROP (&f[1], this->type.alloc_param_buffers.size, SPA_POD_TYPE_INT, this->period_frames * this->frame_size),
|
||||
PROP (&f[1], this->type.alloc_param_buffers.stride, SPA_POD_TYPE_INT, 0),
|
||||
PROP_MM (&f[1], this->type.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, 32, 1, 32),
|
||||
PROP (&f[1], this->type.alloc_param_buffers.align, SPA_POD_TYPE_INT, 16));
|
||||
this->params[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->uri.alloc_param_meta_enable.MetaEnable,
|
||||
PROP (&f[1], this->uri.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_HEADER));
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_meta_enable.MetaEnable,
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_HEADER));
|
||||
this->params[1] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->uri.alloc_param_meta_enable.MetaEnable,
|
||||
PROP (&f[1], this->uri.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_RINGBUFFER),
|
||||
PROP (&f[1], this->uri.alloc_param_meta_enable.ringbufferSize, SPA_POD_TYPE_INT, this->period_frames * this->frame_size * 32),
|
||||
PROP (&f[1], this->uri.alloc_param_meta_enable.ringbufferStride, SPA_POD_TYPE_INT, 0),
|
||||
PROP (&f[1], this->uri.alloc_param_meta_enable.ringbufferBlocks, SPA_POD_TYPE_INT, 1),
|
||||
PROP (&f[1], this->uri.alloc_param_meta_enable.ringbufferAlign, SPA_POD_TYPE_INT, 16));
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_meta_enable.MetaEnable,
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_RINGBUFFER),
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.ringbufferSize, SPA_POD_TYPE_INT, this->period_frames * this->frame_size * 32),
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.ringbufferStride, SPA_POD_TYPE_INT, 0),
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.ringbufferBlocks, SPA_POD_TYPE_INT, 1),
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.ringbufferAlign, SPA_POD_TYPE_INT, 16));
|
||||
this->params[2] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
this->info.extra = NULL;
|
||||
|
||||
|
|
@ -612,12 +612,12 @@ spa_alsa_sink_node_port_send_command (SpaNode *node,
|
|||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (SPA_COMMAND_TYPE (command) == this->uri.command_node.Pause) {
|
||||
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
|
||||
if (SPA_RESULT_IS_OK (res = spa_alsa_pause (this, false))) {
|
||||
update_state (this, SPA_NODE_STATE_PAUSED);
|
||||
}
|
||||
}
|
||||
else if (SPA_COMMAND_TYPE (command) == this->uri.command_node.Start) {
|
||||
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) {
|
||||
if (SPA_RESULT_IS_OK (res = spa_alsa_start (this, false))) {
|
||||
update_state (this, SPA_NODE_STATE_STREAMING);
|
||||
}
|
||||
|
|
@ -720,7 +720,7 @@ spa_alsa_sink_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaALSASink *) handle;
|
||||
|
||||
if (interface_id == this->uri.node)
|
||||
if (interface_id == this->type.node)
|
||||
*interface = &this->node;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
|
@ -753,20 +753,20 @@ alsa_sink_init (const SpaHandleFactory *factory,
|
|||
this = (SpaALSASink *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_TYPE__IDMap) == 0)
|
||||
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_TYPE__Log) == 0)
|
||||
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0)
|
||||
this->log = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_TYPE_LOOP__DataLoop) == 0)
|
||||
else if (strcmp (support[i].type, SPA_TYPE_LOOP__DataLoop) == 0)
|
||||
this->data_loop = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_TYPE_LOOP__MainLoop) == 0)
|
||||
else if (strcmp (support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
|
||||
this->main_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
init_uri (&this->uri, this->map);
|
||||
init_type (&this->type, this->map);
|
||||
|
||||
this->node = alsasink_node;
|
||||
this->stream = SND_PCM_STREAM_PLAYBACK;
|
||||
|
|
|
|||
|
|
@ -84,13 +84,13 @@ spa_alsa_source_node_get_props (SpaNode *node,
|
|||
|
||||
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer));
|
||||
|
||||
spa_pod_builder_props (&b, &f[0], this->uri.props,
|
||||
PROP (&f[1], this->uri.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device)),
|
||||
PROP (&f[1], this->uri.prop_device_name, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
|
||||
PROP (&f[1], this->uri.prop_card_name, -SPA_POD_TYPE_STRING, this->props.card_name, sizeof (this->props.card_name)),
|
||||
PROP_MM (&f[1], this->uri.prop_period_size, SPA_POD_TYPE_INT, this->props.period_size, 1, INT32_MAX),
|
||||
PROP_MM (&f[1], this->uri.prop_periods, SPA_POD_TYPE_INT, this->props.periods, 1, INT32_MAX),
|
||||
PROP (&f[1], this->uri.prop_period_event, SPA_POD_TYPE_BOOL, this->props.period_event));
|
||||
spa_pod_builder_props (&b, &f[0], this->type.props,
|
||||
PROP (&f[1], this->type.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device)),
|
||||
PROP (&f[1], this->type.prop_device_name, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
|
||||
PROP (&f[1], this->type.prop_card_name, -SPA_POD_TYPE_STRING, this->props.card_name, sizeof (this->props.card_name)),
|
||||
PROP_MM (&f[1], this->type.prop_period_size, SPA_POD_TYPE_INT, this->props.period_size, 1, INT32_MAX),
|
||||
PROP_MM (&f[1], this->type.prop_periods, SPA_POD_TYPE_INT, this->props.periods, 1, INT32_MAX),
|
||||
PROP (&f[1], this->type.prop_period_event, SPA_POD_TYPE_BOOL, this->props.period_event));
|
||||
|
||||
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
|
||||
|
||||
|
|
@ -113,10 +113,10 @@ spa_alsa_source_node_set_props (SpaNode *node,
|
|||
return SPA_RESULT_OK;
|
||||
} else {
|
||||
spa_props_query (props,
|
||||
this->uri.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
|
||||
this->uri.prop_period_size, SPA_POD_TYPE_INT, &this->props.period_size,
|
||||
this->uri.prop_periods, SPA_POD_TYPE_INT, &this->props.periods,
|
||||
this->uri.prop_period_event, SPA_POD_TYPE_BOOL, &this->props.period_event,
|
||||
this->type.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
|
||||
this->type.prop_period_size, SPA_POD_TYPE_INT, &this->props.period_size,
|
||||
this->type.prop_periods, SPA_POD_TYPE_INT, &this->props.periods,
|
||||
this->type.prop_period_event, SPA_POD_TYPE_BOOL, &this->props.period_event,
|
||||
0);
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +154,7 @@ do_start (SpaLoop *loop,
|
|||
}
|
||||
|
||||
if (async) {
|
||||
SpaEventNodeAsyncComplete ac = SPA_EVENT_NODE_ASYNC_COMPLETE_INIT (this->uri.event_node.AsyncComplete,
|
||||
SpaEventNodeAsyncComplete ac = SPA_EVENT_NODE_ASYNC_COMPLETE_INIT (this->type.event_node.AsyncComplete,
|
||||
seq, res);
|
||||
spa_loop_invoke (this->main_loop,
|
||||
do_send_event,
|
||||
|
|
@ -182,7 +182,7 @@ do_pause (SpaLoop *loop,
|
|||
}
|
||||
|
||||
if (async) {
|
||||
SpaEventNodeAsyncComplete ac = SPA_EVENT_NODE_ASYNC_COMPLETE_INIT (this->uri.event_node.AsyncComplete,
|
||||
SpaEventNodeAsyncComplete ac = SPA_EVENT_NODE_ASYNC_COMPLETE_INIT (this->type.event_node.AsyncComplete,
|
||||
seq, res);
|
||||
spa_loop_invoke (this->main_loop,
|
||||
do_send_event,
|
||||
|
|
@ -205,7 +205,7 @@ spa_alsa_source_node_send_command (SpaNode *node,
|
|||
|
||||
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
|
||||
|
||||
if (SPA_COMMAND_TYPE (command) == this->uri.command_node.Start) {
|
||||
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) {
|
||||
if (!this->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
|
|
@ -219,7 +219,7 @@ spa_alsa_source_node_send_command (SpaNode *node,
|
|||
NULL,
|
||||
this);
|
||||
}
|
||||
else if (SPA_COMMAND_TYPE (command) == this->uri.command_node.Pause) {
|
||||
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
|
||||
if (!this->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
|
|
@ -340,17 +340,17 @@ next:
|
|||
|
||||
switch (index++) {
|
||||
case 0:
|
||||
spa_pod_builder_format (&b, &f[0], this->uri.format,
|
||||
this->uri.media_types.audio, this->uri.media_subtypes.raw,
|
||||
PROP_U_EN (&f[1], this->uri.prop_audio.format, SPA_POD_TYPE_URI, 3, this->uri.audio_formats.S16,
|
||||
this->uri.audio_formats.S16,
|
||||
this->uri.audio_formats.S32),
|
||||
PROP_U_MM (&f[1], this->uri.prop_audio.rate, SPA_POD_TYPE_INT, 44100, 1, INT32_MAX),
|
||||
PROP_U_MM (&f[1], this->uri.prop_audio.channels, SPA_POD_TYPE_INT, 2, 1, INT32_MAX));
|
||||
spa_pod_builder_format (&b, &f[0], this->type.format,
|
||||
this->type.media_type.audio, this->type.media_subtype.raw,
|
||||
PROP_U_EN (&f[1], this->type.prop_audio.format, SPA_POD_TYPE_URI, 3, this->type.audio_format.S16,
|
||||
this->type.audio_format.S16,
|
||||
this->type.audio_format.S32),
|
||||
PROP_U_MM (&f[1], this->type.prop_audio.rate, SPA_POD_TYPE_INT, 44100, 1, INT32_MAX),
|
||||
PROP_U_MM (&f[1], this->type.prop_audio.channels, SPA_POD_TYPE_INT, 2, 1, INT32_MAX));
|
||||
break;
|
||||
case 1:
|
||||
spa_pod_builder_format (&b, &f[0], this->uri.format,
|
||||
this->uri.media_types.audio, this->uri.media_subtypes_audio.aac,
|
||||
spa_pod_builder_format (&b, &f[0], this->type.format,
|
||||
this->type.media_type.audio, this->type.media_subtype_audio.aac,
|
||||
SPA_POD_TYPE_NONE);
|
||||
default:
|
||||
return SPA_RESULT_ENUM_END;
|
||||
|
|
@ -434,15 +434,15 @@ spa_alsa_source_node_port_set_format (SpaNode *node,
|
|||
this->info.params = this->params;
|
||||
|
||||
spa_pod_builder_init (&b, this->params_buffer, sizeof (this->params_buffer));
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->uri.alloc_param_buffers.Buffers,
|
||||
PROP (&f[1], this->uri.alloc_param_buffers.size, SPA_POD_TYPE_INT, this->period_frames * this->frame_size),
|
||||
PROP (&f[1], this->uri.alloc_param_buffers.stride, SPA_POD_TYPE_INT, 0),
|
||||
PROP_MM (&f[1], this->uri.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, 32, 1, 32),
|
||||
PROP (&f[1], this->uri.alloc_param_buffers.align, SPA_POD_TYPE_INT, 16));
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_buffers.Buffers,
|
||||
PROP (&f[1], this->type.alloc_param_buffers.size, SPA_POD_TYPE_INT, this->period_frames * this->frame_size),
|
||||
PROP (&f[1], this->type.alloc_param_buffers.stride, SPA_POD_TYPE_INT, 0),
|
||||
PROP_MM (&f[1], this->type.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, 32, 1, 32),
|
||||
PROP (&f[1], this->type.alloc_param_buffers.align, SPA_POD_TYPE_INT, 16));
|
||||
this->params[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->uri.alloc_param_meta_enable.MetaEnable,
|
||||
PROP (&f[1], this->uri.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_HEADER));
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_meta_enable.MetaEnable,
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_HEADER));
|
||||
this->params[1] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
|
||||
this->info.extra = NULL;
|
||||
|
|
@ -671,11 +671,11 @@ spa_alsa_source_node_port_send_command (SpaNode *node,
|
|||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (SPA_COMMAND_TYPE (command) == this->uri.command_node.Pause) {
|
||||
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
|
||||
if (SPA_RESULT_IS_OK (res = spa_alsa_pause (this, false))) {
|
||||
update_state (this, SPA_NODE_STATE_PAUSED);
|
||||
}
|
||||
} else if (SPA_COMMAND_TYPE (command) == this->uri.command_node.Start) {
|
||||
} else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) {
|
||||
if (SPA_RESULT_IS_OK (res = spa_alsa_start (this, false))) {
|
||||
update_state (this, SPA_NODE_STATE_STREAMING);
|
||||
}
|
||||
|
|
@ -783,9 +783,9 @@ spa_alsa_source_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaALSASource *) handle;
|
||||
|
||||
if (interface_id == this->uri.node)
|
||||
if (interface_id == this->type.node)
|
||||
*interface = &this->node;
|
||||
else if (interface_id == this->uri.clock)
|
||||
else if (interface_id == this->type.clock)
|
||||
*interface = &this->clock;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
|
@ -818,20 +818,20 @@ alsa_source_init (const SpaHandleFactory *factory,
|
|||
this = (SpaALSASource *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_TYPE__IDMap) == 0)
|
||||
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_TYPE__Log) == 0)
|
||||
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0)
|
||||
this->log = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_TYPE_LOOP__DataLoop) == 0)
|
||||
else if (strcmp (support[i].type, SPA_TYPE_LOOP__DataLoop) == 0)
|
||||
this->data_loop = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_TYPE_LOOP__MainLoop) == 0)
|
||||
else if (strcmp (support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
|
||||
this->main_loop = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
init_uri (&this->uri, this->map);
|
||||
init_type (&this->type, this->map);
|
||||
|
||||
this->node = alsasource_node;
|
||||
this->clock = alsasource_clock;
|
||||
|
|
|
|||
|
|
@ -62,18 +62,18 @@ typedef struct {
|
|||
} FormatInfo;
|
||||
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define _FORMAT_LE(fmt) offsetof(URI, audio_formats. fmt ## _OE)
|
||||
#define _FORMAT_BE(fmt) offsetof(URI, audio_formats. fmt)
|
||||
#define _FORMAT_LE(fmt) offsetof(Type, audio_format. fmt ## _OE)
|
||||
#define _FORMAT_BE(fmt) offsetof(Type, audio_format. fmt)
|
||||
#elif __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define _FORMAT_LE(fmt) offsetof(URI, audio_formats. fmt)
|
||||
#define _FORMAT_BE(fmt) offsetof(URI, audio_formats. fmt ## _OE)
|
||||
#define _FORMAT_LE(fmt) offsetof(Type, audio_format. fmt)
|
||||
#define _FORMAT_BE(fmt) offsetof(Type, audio_format. fmt ## _OE)
|
||||
#endif
|
||||
|
||||
static const FormatInfo format_info[] =
|
||||
{
|
||||
{ offsetof(URI, audio_formats.UNKNOWN), SND_PCM_FORMAT_UNKNOWN },
|
||||
{ offsetof(URI, audio_formats.S8), SND_PCM_FORMAT_S8 },
|
||||
{ offsetof(URI, audio_formats.U8), SND_PCM_FORMAT_U8 },
|
||||
{ offsetof(Type, audio_format.UNKNOWN), SND_PCM_FORMAT_UNKNOWN },
|
||||
{ offsetof(Type, audio_format.S8), SND_PCM_FORMAT_S8 },
|
||||
{ offsetof(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 },
|
||||
|
|
@ -93,12 +93,12 @@ static const FormatInfo format_info[] =
|
|||
};
|
||||
|
||||
static snd_pcm_format_t
|
||||
spa_alsa_format_to_alsa (URI *uri, uint32_t format)
|
||||
spa_alsa_format_to_alsa (Type *map, uint32_t format)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < SPA_N_ELEMENTS (format_info); i++) {
|
||||
uint32_t f = *SPA_MEMBER (uri, format_info[i].format_offset, uint32_t);
|
||||
uint32_t f = *SPA_MEMBER (map, format_info[i].format_offset, uint32_t);
|
||||
if (f == format)
|
||||
return format_info[i].format;
|
||||
}
|
||||
|
|
@ -132,7 +132,7 @@ spa_alsa_set_format (SpaALSAState *state, SpaAudioInfo *fmt, SpaPortFormatFlags
|
|||
CHECK (snd_pcm_hw_params_set_access(hndl, params, SND_PCM_ACCESS_MMAP_INTERLEAVED), "set_access");
|
||||
|
||||
/* set the sample format */
|
||||
format = spa_alsa_format_to_alsa (&state->uri, info->format);
|
||||
format = spa_alsa_format_to_alsa (&state->type, info->format);
|
||||
spa_log_info (state->log, "Stream parameters are %iHz, %s, %i channels", info->rate, snd_pcm_format_name(format), info->channels);
|
||||
CHECK (snd_pcm_hw_params_set_format (hndl, params, format), "set_format");
|
||||
|
||||
|
|
@ -270,7 +270,7 @@ pull_frames_queue (SpaALSAState *state,
|
|||
snd_pcm_uframes_t frames)
|
||||
{
|
||||
if (spa_list_is_empty (&state->ready)) {
|
||||
SpaEvent event = SPA_EVENT_INIT (state->uri.event_node.NeedInput);
|
||||
SpaEvent event = SPA_EVENT_INIT (state->type.event_node.NeedInput);
|
||||
state->event_cb (&state->node, &event, state->user_data);
|
||||
}
|
||||
if (!spa_list_is_empty (&state->ready)) {
|
||||
|
|
@ -294,7 +294,7 @@ pull_frames_queue (SpaALSAState *state,
|
|||
|
||||
state->ready_offset += n_bytes;
|
||||
if (state->ready_offset >= size) {
|
||||
SpaEventNodeReuseBuffer rb = SPA_EVENT_NODE_REUSE_BUFFER_INIT (state->uri.event_node.ReuseBuffer,
|
||||
SpaEventNodeReuseBuffer rb = SPA_EVENT_NODE_REUSE_BUFFER_INIT (state->type.event_node.ReuseBuffer,
|
||||
0, b->outbuf->id);
|
||||
|
||||
spa_list_remove (&b->link);
|
||||
|
|
@ -349,7 +349,7 @@ pull_frames_ringbuffer (SpaALSAState *state,
|
|||
|
||||
b->outstanding = true;
|
||||
{
|
||||
SpaEventNodeReuseBuffer rb = SPA_EVENT_NODE_REUSE_BUFFER_INIT (state->uri.event_node.ReuseBuffer,
|
||||
SpaEventNodeReuseBuffer rb = SPA_EVENT_NODE_REUSE_BUFFER_INIT (state->type.event_node.ReuseBuffer,
|
||||
0, b->outbuf->id);
|
||||
state->event_cb (&state->node, (SpaEvent*)&rb, state->user_data);
|
||||
}
|
||||
|
|
@ -498,7 +498,7 @@ mmap_read (SpaALSAState *state)
|
|||
output->status = SPA_RESULT_OK;
|
||||
}
|
||||
{
|
||||
SpaEvent event = SPA_EVENT_INIT (state->uri.event_node.HaveOutput);
|
||||
SpaEvent event = SPA_EVENT_INIT (state->type.event_node.HaveOutput);
|
||||
state->event_cb (&state->node, &event, state->user_data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ extern "C" {
|
|||
|
||||
#include <asoundlib.h>
|
||||
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/type-map.h>
|
||||
#include <spa/clock.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/list.h>
|
||||
|
|
@ -71,40 +71,40 @@ typedef struct {
|
|||
uint32_t prop_period_size;
|
||||
uint32_t prop_periods;
|
||||
uint32_t prop_period_event;
|
||||
SpaMediaTypes media_types;
|
||||
SpaMediaSubtypes media_subtypes;
|
||||
SpaMediaSubtypesAudio media_subtypes_audio;
|
||||
SpaPropAudio prop_audio;
|
||||
SpaAudioFormats audio_formats;
|
||||
SpaEventNode event_node;
|
||||
SpaCommandNode command_node;
|
||||
SpaAllocParamBuffers alloc_param_buffers;
|
||||
SpaAllocParamMetaEnable alloc_param_meta_enable;
|
||||
} URI;
|
||||
SpaTypeMediaType media_type;
|
||||
SpaTypeMediaSubtype media_subtype;
|
||||
SpaTypeMediaSubtypeAudio media_subtype_audio;
|
||||
SpaTypePropAudio prop_audio;
|
||||
SpaTypeAudioFormat audio_format;
|
||||
SpaTypeEventNode event_node;
|
||||
SpaTypeCommandNode command_node;
|
||||
SpaTypeAllocParamBuffers alloc_param_buffers;
|
||||
SpaTypeAllocParamMetaEnable alloc_param_meta_enable;
|
||||
} Type;
|
||||
|
||||
static inline void
|
||||
init_uri (URI *uri, SpaIDMap *map)
|
||||
init_type (Type *type, SpaTypeMap *map)
|
||||
{
|
||||
uri->node = spa_id_map_get_id (map, SPA_TYPE__Node);
|
||||
uri->clock = spa_id_map_get_id (map, SPA_TYPE__Clock);
|
||||
uri->format = spa_id_map_get_id (map, SPA_TYPE__Format);
|
||||
uri->props = spa_id_map_get_id (map, SPA_TYPE__Props);
|
||||
uri->prop_device = spa_id_map_get_id (map, SPA_TYPE_PROPS__device);
|
||||
uri->prop_device_name = spa_id_map_get_id (map, SPA_TYPE_PROPS__deviceName);
|
||||
uri->prop_card_name = spa_id_map_get_id (map, SPA_TYPE_PROPS__cardName);
|
||||
uri->prop_period_size = spa_id_map_get_id (map, SPA_TYPE_PROPS__periodSize);
|
||||
uri->prop_periods = spa_id_map_get_id (map, SPA_TYPE_PROPS__periods);
|
||||
uri->prop_period_event = spa_id_map_get_id (map, SPA_TYPE_PROPS__periodEvent);
|
||||
type->node = spa_type_map_get_id (map, SPA_TYPE__Node);
|
||||
type->clock = spa_type_map_get_id (map, SPA_TYPE__Clock);
|
||||
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_period_size = spa_type_map_get_id (map, SPA_TYPE_PROPS__periodSize);
|
||||
type->prop_periods = spa_type_map_get_id (map, SPA_TYPE_PROPS__periods);
|
||||
type->prop_period_event = spa_type_map_get_id (map, SPA_TYPE_PROPS__periodEvent);
|
||||
|
||||
spa_media_types_fill (&uri->media_types, map);
|
||||
spa_media_subtypes_map (map, &uri->media_subtypes);
|
||||
spa_media_subtypes_audio_map (map, &uri->media_subtypes_audio);
|
||||
spa_prop_audio_map (map, &uri->prop_audio);
|
||||
spa_audio_formats_map (map, &uri->audio_formats);
|
||||
spa_event_node_map (map, &uri->event_node);
|
||||
spa_command_node_map (map, &uri->command_node);
|
||||
spa_alloc_param_buffers_map (map, &uri->alloc_param_buffers);
|
||||
spa_alloc_param_meta_enable_map (map, &uri->alloc_param_meta_enable);
|
||||
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_prop_audio_map (map, &type->prop_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_alloc_param_buffers_map (map, &type->alloc_param_buffers);
|
||||
spa_type_alloc_param_meta_enable_map (map, &type->alloc_param_meta_enable);
|
||||
}
|
||||
|
||||
struct _SpaALSAState {
|
||||
|
|
@ -114,8 +114,8 @@ struct _SpaALSAState {
|
|||
|
||||
uint32_t seq;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
Type type;
|
||||
SpaTypeMap *map;
|
||||
SpaLog *log;
|
||||
SpaLoop *main_loop;
|
||||
SpaLoop *data_loop;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue