props: make properties dynamic keys and values

This commit is contained in:
Wim Taymans 2017-03-23 12:38:00 +01:00
parent 048a4b81a8
commit e28b5f91b8
15 changed files with 271 additions and 223 deletions

View file

@ -308,6 +308,8 @@ pinos_connection_end_write (PinosConnection *conn,
buf->buffer_size += 8 + size;
// spa_debug_pod (p);
pinos_signal_emit (&conn->need_flush, conn);
}

View file

@ -31,19 +31,18 @@
#include "spa-node.h"
static SpaResult
setup_video_node (SpaNode *spa_node, PinosProperties *pinos_props) {
setup_video_node (PinosCore *core, SpaNode *spa_node, PinosProperties *pinos_props) {
SpaResult res;
SpaProps *props;
SpaPODProp *prop;
const char *pattern;
uint32_t pattern_int;
const char *pattern, *pattern_uri;
/* Retrieve pattern property */
pattern = pinos_properties_get (pinos_props, "pattern");
if (strcmp (pattern, "smpte-snow") == 0) {
pattern_int = 0;
pattern_uri = SPA_PROPS__patternType ":smpte-snow";
} else if (strcmp (pattern, "snow") == 0) {
pattern_int = 1;
pattern_uri = SPA_PROPS__patternType ":snow";
} else {
pinos_log_debug ("Unrecognized pattern");
return SPA_RESULT_ERROR;
@ -54,9 +53,9 @@ setup_video_node (SpaNode *spa_node, PinosProperties *pinos_props) {
return SPA_RESULT_ERROR;
}
if ((prop = spa_pod_object_find_prop (props, 2))) {
if (prop->body.value.type == SPA_POD_TYPE_INT)
((SpaPODInt*)&prop->body.value)->value = pattern_int;
if ((prop = spa_pod_object_find_prop (props, spa_id_map_get_id (core->uri.map, SPA_PROPS__patternType)))) {
if (prop->body.value.type == SPA_POD_TYPE_URI)
SPA_POD_VALUE (SpaPODURI, &prop->body.value) = spa_id_map_get_id (core->uri.map, pattern_uri);
}
if ((res = spa_node_set_props (spa_node, props)) != SPA_RESULT_OK) {

View file

@ -101,7 +101,7 @@ pinos_spa_node_load (PinosCore *core,
this = &impl->this;
if (setup_func != NULL) {
if (setup_func (spa_node, properties) != SPA_RESULT_OK) {
if (setup_func (core, spa_node, properties) != SPA_RESULT_OK) {
pinos_log_debug ("Unrecognized properties");
}
}

View file

@ -39,7 +39,8 @@ struct _PinosSpaNode {
PinosSpaNode *node));
};
typedef SpaResult (*SetupNode) (SpaNode *spa_node,
typedef SpaResult (*SetupNode) (PinosCore *core,
SpaNode *spa_node,
PinosProperties *pinos_props);
PinosSpaNode * pinos_spa_node_load (PinosCore *core,
@ -47,7 +48,7 @@ PinosSpaNode * pinos_spa_node_load (PinosCore *core,
const char *factory_name,
const char *name,
PinosProperties *properties,
SetupNode setup_func);
SetupNode setup_func);
#ifdef __cplusplus
}

View file

@ -32,16 +32,31 @@ typedef SpaPODObject SpaProps;
#define SPA_PROPS_URI "http://spaplug.in/ns/props"
#define SPA_PROPS_PREFIX SPA_PROPS_URI "#"
#define SPA_PROPS__device SPA_PROPS_PREFIX "device"
#define SPA_PROPS__deviceName SPA_PROPS_PREFIX "deviceName"
#define SPA_PROPS__deviceFd SPA_PROPS_PREFIX "deviceFd"
#define SPA_PROPS__card SPA_PROPS_PREFIX "card"
#define SPA_PROPS__cardName SPA_PROPS_PREFIX "cardName"
#define SPA_PROPS__periods SPA_PROPS_PREFIX "periods"
#define SPA_PROPS__periodSize SPA_PROPS_PREFIX "periodSize"
#define SPA_PROPS__periodEvent SPA_PROPS_PREFIX "periodEvent"
#define SPA_PROPS__live SPA_PROPS_PREFIX "live"
#define SPA_PROPS__waveType SPA_PROPS_PREFIX "waveType"
#define SPA_PROPS__frequency SPA_PROPS_PREFIX "frequency"
#define SPA_PROPS__volume SPA_PROPS_PREFIX "volume"
#define SPA_PROPS__mute SPA_PROPS_PREFIX "mute"
#define SPA_PROPS__patternType SPA_PROPS_PREFIX "patternType"
static inline uint32_t
spa_pod_builder_push_props (SpaPODBuilder *builder,
SpaPODFrame *frame)
SpaPODFrame *frame,
uint32_t props_type)
{
return spa_pod_builder_push_object (builder, frame, 0, 0);
return spa_pod_builder_push_object (builder, frame, 0, props_type);
}
#define spa_pod_builder_props(b,f,...) \
spa_pod_builder_object(b, f, 0, 0,__VA_ARGS__)
#define spa_pod_builder_props(b,f,props_type,...) \
spa_pod_builder_object(b, f, 0, props_type,__VA_ARGS__)
static inline uint32_t
spa_props_query (const SpaProps *props, uint32_t key, ...)

View file

@ -52,16 +52,6 @@ update_state (SpaALSASink *this, SpaNodeState state)
this->node.state = state;
}
enum {
PROP_ID_NONE,
PROP_ID_DEVICE,
PROP_ID_DEVICE_NAME,
PROP_ID_CARD_NAME,
PROP_ID_PERIOD_SIZE,
PROP_ID_PERIODS,
PROP_ID_PERIOD_EVENT,
};
#define PROP(f,key,type,...) \
SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_READWRITE,type,1,__VA_ARGS__)
#define PROP_MM(f,key,type,...) \
@ -92,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],
PROP (&f[1], PROP_ID_DEVICE, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device)),
PROP (&f[1], PROP_ID_DEVICE_NAME, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
PROP (&f[1], PROP_ID_CARD_NAME, -SPA_POD_TYPE_STRING, this->props.card_name, sizeof (this->props.card_name)),
PROP_MM (&f[1], PROP_ID_PERIOD_SIZE, SPA_POD_TYPE_INT, this->props.period_size, 1, INT32_MAX),
PROP_MM (&f[1], PROP_ID_PERIODS, SPA_POD_TYPE_INT, this->props.periods, 1, INT32_MAX),
PROP (&f[1], PROP_ID_PERIOD_EVENT, SPA_POD_TYPE_BOOL, this->props.period_event));
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));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
@ -121,10 +111,10 @@ spa_alsa_sink_node_set_props (SpaNode *node,
return SPA_RESULT_OK;
} else {
spa_props_query (props,
PROP_ID_DEVICE, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
PROP_ID_PERIOD_SIZE, SPA_POD_TYPE_INT, &this->props.period_size,
PROP_ID_PERIODS, SPA_POD_TYPE_INT, &this->props.periods,
PROP_ID_PERIOD_EVENT, SPA_POD_TYPE_BOOL, &this->props.period_event,
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,
0);
}
return SPA_RESULT_OK;
@ -776,18 +766,7 @@ alsa_sink_init (const SpaHandleFactory *factory,
spa_log_error (this->log, "an id-map is needed");
return SPA_RESULT_ERROR;
}
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
this->uri.format = spa_id_map_get_id (this->map, SPA_FORMAT_URI);
spa_media_types_fill (&this->uri.media_types, this->map);
spa_media_subtypes_map (this->map, &this->uri.media_subtypes);
spa_media_subtypes_audio_map (this->map, &this->uri.media_subtypes_audio);
spa_prop_audio_map (this->map, &this->uri.prop_audio);
spa_audio_formats_map (this->map, &this->uri.audio_formats);
spa_node_events_map (this->map, &this->uri.node_events);
spa_node_commands_map (this->map, &this->uri.node_commands);
spa_alloc_param_buffers_map (this->map, &this->uri.alloc_param_buffers);
spa_alloc_param_meta_enable_map (this->map, &this->uri.alloc_param_meta_enable);
init_uri (&this->uri, this->map);
this->node = alsasink_node;
this->stream = SND_PCM_STREAM_PLAYBACK;

View file

@ -52,16 +52,6 @@ reset_alsa_props (SpaALSAProps *props)
props->period_event = default_period_event;
}
enum {
PROP_ID_NONE,
PROP_ID_DEVICE,
PROP_ID_DEVICE_NAME,
PROP_ID_CARD_NAME,
PROP_ID_PERIOD_SIZE,
PROP_ID_PERIODS,
PROP_ID_PERIOD_EVENT,
};
#define PROP(f,key,type,...) \
SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_READWRITE,type,1,__VA_ARGS__)
#define PROP_MM(f,key,type,...) \
@ -94,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],
PROP (&f[1], PROP_ID_DEVICE, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device)),
PROP (&f[1], PROP_ID_DEVICE_NAME, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
PROP (&f[1], PROP_ID_CARD_NAME, -SPA_POD_TYPE_STRING, this->props.card_name, sizeof (this->props.card_name)),
PROP_MM (&f[1], PROP_ID_PERIOD_SIZE, SPA_POD_TYPE_INT, this->props.period_size, 1, INT32_MAX),
PROP_MM (&f[1], PROP_ID_PERIODS, SPA_POD_TYPE_INT, this->props.periods, 1, INT32_MAX),
PROP (&f[1], PROP_ID_PERIOD_EVENT, SPA_POD_TYPE_BOOL, this->props.period_event));
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));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
@ -123,10 +113,10 @@ spa_alsa_source_node_set_props (SpaNode *node,
return SPA_RESULT_OK;
} else {
spa_props_query (props,
PROP_ID_DEVICE, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
PROP_ID_PERIOD_SIZE, SPA_POD_TYPE_INT, &this->props.period_size,
PROP_ID_PERIODS, SPA_POD_TYPE_INT, &this->props.periods,
PROP_ID_PERIOD_EVENT, SPA_POD_TYPE_BOOL, &this->props.period_event,
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,
0);
}
@ -841,19 +831,7 @@ alsa_source_init (const SpaHandleFactory *factory,
spa_log_error (this->log, "an id-map is needed");
return SPA_RESULT_ERROR;
}
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
this->uri.format = spa_id_map_get_id (this->map, SPA_FORMAT_URI);
spa_media_types_fill (&this->uri.media_types, this->map);
spa_media_subtypes_map (this->map, &this->uri.media_subtypes);
spa_media_subtypes_audio_map (this->map, &this->uri.media_subtypes_audio);
spa_prop_audio_map (this->map, &this->uri.prop_audio);
spa_audio_formats_map (this->map, &this->uri.audio_formats);
spa_node_events_map (this->map, &this->uri.node_events);
spa_node_commands_map (this->map, &this->uri.node_commands);
spa_alloc_param_buffers_map (this->map, &this->uri.alloc_param_buffers);
spa_alloc_param_meta_enable_map (this->map, &this->uri.alloc_param_meta_enable);
init_uri (&this->uri, this->map);
this->node = alsasource_node;
this->clock = alsasource_clock;

View file

@ -64,6 +64,13 @@ typedef struct {
uint32_t node;
uint32_t clock;
uint32_t format;
uint32_t props;
uint32_t prop_device;
uint32_t prop_device_name;
uint32_t prop_card_name;
uint32_t prop_period_size;
uint32_t prop_periods;
uint32_t prop_period_event;
SpaMediaTypes media_types;
SpaMediaSubtypes media_subtypes;
SpaMediaSubtypesAudio media_subtypes_audio;
@ -75,6 +82,31 @@ typedef struct {
SpaAllocParamMetaEnable alloc_param_meta_enable;
} URI;
static inline void
init_uri (URI *uri, SpaIDMap *map)
{
uri->node = spa_id_map_get_id (map, SPA_NODE_URI);
uri->clock = spa_id_map_get_id (map, SPA_CLOCK_URI);
uri->format = spa_id_map_get_id (map, SPA_FORMAT_URI);
uri->props = spa_id_map_get_id (map, SPA_PROPS_URI);
uri->prop_device = spa_id_map_get_id (map, SPA_PROPS__device);
uri->prop_device_name = spa_id_map_get_id (map, SPA_PROPS__deviceName);
uri->prop_card_name = spa_id_map_get_id (map, SPA_PROPS__cardName);
uri->prop_period_size = spa_id_map_get_id (map, SPA_PROPS__periodSize);
uri->prop_periods = spa_id_map_get_id (map, SPA_PROPS__periods);
uri->prop_period_event = spa_id_map_get_id (map, SPA_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_node_events_map (map, &uri->node_events);
spa_node_commands_map (map, &uri->node_commands);
spa_alloc_param_buffers_map (map, &uri->alloc_param_buffers);
spa_alloc_param_meta_enable_map (map, &uri->alloc_param_meta_enable);
}
struct _SpaALSAState {
SpaHandle handle;
SpaNode node;

View file

@ -61,6 +61,13 @@ typedef struct {
SpaNodeCommands node_commands;
} URI;
static inline void
init_uri (URI *uri, SpaIDMap *map)
{
uri->node = spa_id_map_get_id (map, SPA_NODE_URI);
spa_node_commands_map (map, &uri->node_commands);
}
struct _SpaAudioMixer {
SpaHandle handle;
SpaNode node;
@ -694,8 +701,7 @@ spa_audiomixer_init (const SpaHandleFactory *factory,
spa_log_error (this->log, "an id-map is needed");
return SPA_RESULT_ERROR;
}
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
spa_node_commands_map (this->map, &this->uri.node_commands);
init_uri (&this->uri, this->map);
this->node = audiomixer_node;

View file

@ -41,6 +41,13 @@ typedef struct {
uint32_t node;
uint32_t clock;
uint32_t format;
uint32_t props;
uint32_t prop_live;
uint32_t prop_wave;
uint32_t prop_freq;
uint32_t prop_volume;
uint32_t wave_sine;
uint32_t wave_square;
SpaMediaTypes media_types;
SpaMediaSubtypes media_subtypes;
SpaPropAudio prop_audio;
@ -51,6 +58,29 @@ typedef struct {
SpaAllocParamMetaEnable alloc_param_meta_enable;
} URI;
static inline void
init_uri (URI *uri, SpaIDMap *map)
{
uri->node = spa_id_map_get_id (map, SPA_NODE_URI);
uri->clock = spa_id_map_get_id (map, SPA_CLOCK_URI);
uri->format = spa_id_map_get_id (map, SPA_FORMAT_URI);
uri->props = spa_id_map_get_id (map, SPA_PROPS_URI);
uri->prop_live = spa_id_map_get_id (map, SPA_PROPS__live);
uri->prop_wave = spa_id_map_get_id (map, SPA_PROPS__waveType);
uri->prop_freq = spa_id_map_get_id (map, SPA_PROPS__frequency);
uri->prop_volume = spa_id_map_get_id (map, SPA_PROPS__volume);
uri->wave_sine = spa_id_map_get_id (map, SPA_PROPS__waveType ":Sine");
uri->wave_square = spa_id_map_get_id (map, SPA_PROPS__waveType ":Square");
spa_media_types_fill (&uri->media_types, map);
spa_media_subtypes_map (map, &uri->media_subtypes);
spa_prop_audio_map (map, &uri->prop_audio);
spa_audio_formats_map (map, &uri->audio_formats);
spa_node_events_map (map, &uri->node_events);
spa_node_commands_map (map, &uri->node_commands);
spa_alloc_param_buffers_map (map, &uri->alloc_param_buffers);
spa_alloc_param_meta_enable_map (map, &uri->alloc_param_meta_enable);
}
typedef struct _SpaAudioTestSrc SpaAudioTestSrc;
typedef struct {
@ -116,26 +146,15 @@ struct _SpaAudioTestSrc {
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) == 0)
#define DEFAULT_LIVE true
#define DEFAULT_WAVE 0
#define DEFAULT_WAVE wave_sine
#define DEFAULT_FREQ 440.0
#define DEFAULT_VOLUME 1.0
static const uint32_t wave_val_sine = 0;
static const uint32_t wave_val_square = 1;
enum {
PROP_ID_NONE,
PROP_ID_LIVE,
PROP_ID_WAVE,
PROP_ID_FREQ,
PROP_ID_VOLUME,
};
static void
reset_audiotestsrc_props (SpaAudioTestSrcProps *props)
reset_audiotestsrc_props (SpaAudioTestSrc *this, SpaAudioTestSrcProps *props)
{
props->live = DEFAULT_LIVE;
props->wave = DEFAULT_WAVE;
props->wave = this->uri. DEFAULT_WAVE;
props->freq = DEFAULT_FREQ;
props->volume = DEFAULT_VOLUME;
}
@ -171,15 +190,15 @@ spa_audiotestsrc_node_get_props (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer));
spa_pod_builder_props (&b, &f[0],
PROP (&f[1], PROP_ID_LIVE, SPA_POD_TYPE_BOOL, this->props.live),
PROP_EN (&f[1], PROP_ID_WAVE, SPA_POD_TYPE_INT, 3, this->props.wave,
wave_val_sine,
wave_val_square),
PROP_MM (&f[1], PROP_ID_FREQ, SPA_POD_TYPE_DOUBLE, this->props.freq,
0.0, 50000000.0),
PROP_MM (&f[1], PROP_ID_VOLUME, SPA_POD_TYPE_DOUBLE, this->props.volume,
0.0, 10.0));
spa_pod_builder_props (&b, &f[0], this->uri.props,
PROP (&f[1], this->uri.prop_live, SPA_POD_TYPE_BOOL, this->props.live),
PROP_EN (&f[1], this->uri.prop_wave, SPA_POD_TYPE_URI, 3, this->props.wave,
this->uri.wave_sine,
this->uri.wave_square),
PROP_MM (&f[1], this->uri.prop_freq, SPA_POD_TYPE_DOUBLE, this->props.freq,
0.0, 50000000.0),
PROP_MM (&f[1], this->uri.prop_volume, SPA_POD_TYPE_DOUBLE, this->props.volume,
0.0, 10.0));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
@ -198,13 +217,13 @@ spa_audiotestsrc_node_set_props (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
if (props == NULL) {
reset_audiotestsrc_props (&this->props);
reset_audiotestsrc_props (this, &this->props);
} else {
spa_props_query (props,
PROP_ID_LIVE, SPA_POD_TYPE_BOOL, &this->props.live,
PROP_ID_WAVE, SPA_POD_TYPE_INT, &this->props.wave,
PROP_ID_FREQ, SPA_POD_TYPE_DOUBLE, &this->props.freq,
PROP_ID_VOLUME, SPA_POD_TYPE_DOUBLE, &this->props.volume,
this->uri.prop_live, SPA_POD_TYPE_BOOL, &this->props.live,
this->uri.prop_wave, SPA_POD_TYPE_URI, &this->props.wave,
this->uri.prop_freq, SPA_POD_TYPE_DOUBLE, &this->props.freq,
this->uri.prop_volume, SPA_POD_TYPE_DOUBLE, &this->props.volume,
0);
}
@ -949,21 +968,11 @@ audiotestsrc_init (const SpaHandleFactory *factory,
spa_log_error (this->log, "a data_loop is needed");
return SPA_RESULT_ERROR;
}
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
this->uri.format = spa_id_map_get_id (this->map, SPA_FORMAT_URI);
spa_media_types_fill (&this->uri.media_types, this->map);
spa_media_subtypes_map (this->map, &this->uri.media_subtypes);
spa_prop_audio_map (this->map, &this->uri.prop_audio);
spa_audio_formats_map (this->map, &this->uri.audio_formats);
spa_node_events_map (this->map, &this->uri.node_events);
spa_node_commands_map (this->map, &this->uri.node_commands);
spa_alloc_param_buffers_map (this->map, &this->uri.alloc_param_buffers);
spa_alloc_param_meta_enable_map (this->map, &this->uri.alloc_param_meta_enable);
init_uri (&this->uri, this->map);
this->node = audiotestsrc_node;
this->clock = audiotestsrc_clock;
reset_audiotestsrc_props (&this->props);
reset_audiotestsrc_props (this, &this->props);
spa_list_init (&this->empty);

View file

@ -67,6 +67,10 @@ typedef struct {
uint32_t node;
uint32_t clock;
uint32_t format;
uint32_t props;
uint32_t prop_device;
uint32_t prop_device_name;
uint32_t prop_device_fd;
SpaMediaTypes media_types;
SpaMediaSubtypes media_subtypes;
SpaMediaSubtypesVideo media_subtypes_video;
@ -78,6 +82,27 @@ typedef struct {
SpaAllocParamMetaEnable alloc_param_meta_enable;
} URI;
static inline void
init_uri (URI *uri, SpaIDMap *map)
{
uri->node = spa_id_map_get_id (map, SPA_NODE_URI);
uri->clock = spa_id_map_get_id (map, SPA_CLOCK_URI);
uri->format = spa_id_map_get_id (map, SPA_FORMAT_URI);
uri->props = spa_id_map_get_id (map, SPA_PROPS_URI);
uri->prop_device = spa_id_map_get_id (map, SPA_PROPS__device);
uri->prop_device_name = spa_id_map_get_id (map, SPA_PROPS__deviceName);
uri->prop_device_fd = spa_id_map_get_id (map, SPA_PROPS__deviceFd);
spa_media_types_fill (&uri->media_types, map);
spa_media_subtypes_map (map, &uri->media_subtypes);
spa_media_subtypes_video_map (map, &uri->media_subtypes_video);
spa_prop_video_map (map, &uri->prop_video);
spa_video_formats_map (map, &uri->video_formats);
spa_node_events_map (map, &uri->node_events);
spa_node_commands_map (map, &uri->node_commands);
spa_alloc_param_buffers_map (map, &uri->alloc_param_buffers);
spa_alloc_param_meta_enable_map (map, &uri->alloc_param_meta_enable);
}
typedef struct {
SpaLog *log;
SpaLoop *main_loop;
@ -167,13 +192,6 @@ update_state (SpaV4l2Source *this, SpaNodeState state)
SPA_POD_PROP_RANGE_ENUM,type,n,__VA_ARGS__)
#include "v4l2-utils.c"
enum {
PROP_ID_NONE,
PROP_ID_DEVICE,
PROP_ID_DEVICE_NAME,
PROP_ID_DEVICE_FD,
};
static SpaResult
spa_v4l2_source_node_get_props (SpaNode *node,
SpaProps **props)
@ -188,10 +206,10 @@ spa_v4l2_source_node_get_props (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer));
spa_pod_builder_props (&b, &f[0],
PROP (&f[1], PROP_ID_DEVICE, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device)),
PROP_R (&f[1], PROP_ID_DEVICE_NAME, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
PROP_R (&f[1], PROP_ID_DEVICE_FD, SPA_POD_TYPE_INT, this->props.device_fd));
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_R (&f[1], this->uri.prop_device_name, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
PROP_R (&f[1], this->uri.prop_device_fd, SPA_POD_TYPE_INT, this->props.device_fd));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
return SPA_RESULT_OK;
@ -213,7 +231,7 @@ spa_v4l2_source_node_set_props (SpaNode *node,
return SPA_RESULT_OK;
} else {
spa_props_query (props,
PROP_ID_DEVICE, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
this->uri.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
0);
}
return SPA_RESULT_OK;
@ -957,18 +975,7 @@ v4l2_source_init (const SpaHandleFactory *factory,
spa_log_error (this->log, "a data_loop is needed");
return SPA_RESULT_ERROR;
}
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
this->uri.format = spa_id_map_get_id (this->map, SPA_FORMAT_URI);
spa_media_types_fill (&this->uri.media_types, this->map);
spa_media_subtypes_map (this->map, &this->uri.media_subtypes);
spa_media_subtypes_video_map (this->map, &this->uri.media_subtypes_video);
spa_prop_video_map (this->map, &this->uri.prop_video);
spa_video_formats_map (this->map, &this->uri.video_formats);
spa_node_events_map (this->map, &this->uri.node_events);
spa_node_commands_map (this->map, &this->uri.node_commands);
spa_alloc_param_buffers_map (this->map, &this->uri.alloc_param_buffers);
spa_alloc_param_meta_enable_map (this->map, &this->uri.alloc_param_meta_enable);
init_uri (&this->uri, this->map);
this->node = v4l2source_node;
this->clock = v4l2source_clock;

View file

@ -282,9 +282,9 @@ draw (SpaVideoTestSrc *this, char *data)
return res;
pattern = this->props.pattern;
if (pattern == pattern_val_smpte_snow)
if (pattern == this->uri.pattern_smpte_snow)
draw_smpte_snow (&dd);
else if (pattern == pattern_val_snow)
else if (pattern == this->uri.pattern_snow)
draw_snow (&dd);
else
return SPA_RESULT_NOT_IMPLEMENTED;

View file

@ -41,6 +41,11 @@ typedef struct {
uint32_t node;
uint32_t clock;
uint32_t format;
uint32_t props;
uint32_t prop_live;
uint32_t prop_pattern;
uint32_t pattern_smpte_snow;
uint32_t pattern_snow;
SpaMediaTypes media_types;
SpaMediaSubtypes media_subtypes;
SpaPropVideo prop_video;
@ -51,6 +56,27 @@ typedef struct {
SpaAllocParamMetaEnable alloc_param_meta_enable;
} URI;
static inline void
init_uri (URI *uri, SpaIDMap *map)
{
uri->node = spa_id_map_get_id (map, SPA_NODE_URI);
uri->clock = spa_id_map_get_id (map, SPA_CLOCK_URI);
uri->format = spa_id_map_get_id (map, SPA_FORMAT_URI);
uri->props = spa_id_map_get_id (map, SPA_PROPS_URI);
uri->prop_live = spa_id_map_get_id (map, SPA_PROPS__live);
uri->prop_pattern = spa_id_map_get_id (map, SPA_PROPS__patternType);
uri->pattern_smpte_snow = spa_id_map_get_id (map, SPA_PROPS__patternType ":smpte-snow");
uri->pattern_snow = spa_id_map_get_id (map, SPA_PROPS__patternType ":snow");
spa_media_types_fill (&uri->media_types, map);
spa_media_subtypes_map (map, &uri->media_subtypes);
spa_prop_video_map (map, &uri->prop_video);
spa_video_formats_map (map, &uri->video_formats);
spa_node_events_map (map, &uri->node_events);
spa_node_commands_map (map, &uri->node_commands);
spa_alloc_param_buffers_map (map, &uri->alloc_param_buffers);
spa_alloc_param_meta_enable_map (map, &uri->alloc_param_meta_enable);
}
typedef struct _SpaVideoTestSrc SpaVideoTestSrc;
typedef struct {
@ -115,22 +141,13 @@ struct _SpaVideoTestSrc {
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) == 0)
#define DEFAULT_LIVE true
#define DEFAULT_PATTERN 0
static const uint32_t pattern_val_smpte_snow = 0;
static const uint32_t pattern_val_snow = 1;
enum {
PROP_ID_NONE = 0,
PROP_ID_LIVE,
PROP_ID_PATTERN,
};
#define DEFAULT_PATTERN pattern_smpte_snow
static void
reset_videotestsrc_props (SpaVideoTestSrcProps *props)
reset_videotestsrc_props (SpaVideoTestSrc *this, SpaVideoTestSrcProps *props)
{
props->live = DEFAULT_LIVE;
props->pattern = DEFAULT_PATTERN;
props->pattern = this->uri. DEFAULT_PATTERN;
}
#define PROP(f,key,type,...) \
@ -165,12 +182,12 @@ spa_videotestsrc_node_get_props (SpaNode *node,
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer));
spa_pod_builder_props (&b, &f[0],
PROP (&f[1], PROP_ID_LIVE, SPA_POD_TYPE_BOOL, this->props.live),
PROP_EN (&f[1], PROP_ID_PATTERN, SPA_POD_TYPE_INT, 3,
spa_pod_builder_props (&b, &f[0], this->uri.props,
PROP (&f[1], this->uri.prop_live, SPA_POD_TYPE_BOOL, this->props.live),
PROP_EN (&f[1], this->uri.prop_pattern, SPA_POD_TYPE_URI, 3,
this->props.pattern,
pattern_val_smpte_snow,
pattern_val_snow));
this->uri.pattern_smpte_snow,
this->uri.pattern_snow));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
@ -189,11 +206,11 @@ spa_videotestsrc_node_set_props (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaVideoTestSrc, node);
if (props == NULL) {
reset_videotestsrc_props (&this->props);
reset_videotestsrc_props (this, &this->props);
} else {
spa_props_query (props,
PROP_ID_LIVE, SPA_POD_TYPE_BOOL, &this->props.live,
PROP_ID_PATTERN, SPA_POD_TYPE_INT, &this->props.pattern,
this->uri.prop_live, SPA_POD_TYPE_BOOL, &this->props.live,
this->uri.prop_pattern, SPA_POD_TYPE_URI, &this->props.pattern,
0);
}
@ -951,21 +968,11 @@ videotestsrc_init (const SpaHandleFactory *factory,
spa_log_error (this->log, "a data_loop is needed");
return SPA_RESULT_ERROR;
}
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
this->uri.format = spa_id_map_get_id (this->map, SPA_FORMAT_URI);
spa_media_types_fill (&this->uri.media_types, this->map);
spa_media_subtypes_map (this->map, &this->uri.media_subtypes);
spa_prop_video_map (this->map, &this->uri.prop_video);
spa_video_formats_map (this->map, &this->uri.video_formats);
spa_node_events_map (this->map, &this->uri.node_events);
spa_node_commands_map (this->map, &this->uri.node_commands);
spa_alloc_param_buffers_map (this->map, &this->uri.alloc_param_buffers);
spa_alloc_param_meta_enable_map (this->map, &this->uri.alloc_param_meta_enable);
init_uri (&this->uri, this->map);
this->node = videotestsrc_node;
this->clock = videotestsrc_clock;
reset_videotestsrc_props (&this->props);
reset_videotestsrc_props (this, &this->props);
spa_list_init (&this->empty);

View file

@ -64,6 +64,9 @@ typedef struct {
typedef struct {
uint32_t node;
uint32_t format;
uint32_t props;
uint32_t prop_volume;
uint32_t prop_mute;
SpaMediaTypes media_types;
SpaMediaSubtypes media_subtypes;
SpaPropAudio prop_audio;
@ -74,6 +77,24 @@ typedef struct {
SpaAllocParamMetaEnable alloc_param_meta_enable;
} URI;
static inline void
init_uri (URI *uri, SpaIDMap *map)
{
uri->node = spa_id_map_get_id (map, SPA_NODE_URI);
uri->format = spa_id_map_get_id (map, SPA_FORMAT_URI);
uri->props = spa_id_map_get_id (map, SPA_PROPS_URI);
uri->prop_volume = spa_id_map_get_id (map, SPA_PROPS__volume);
uri->prop_mute = spa_id_map_get_id (map, SPA_PROPS__mute);
spa_media_types_fill (&uri->media_types, map);
spa_media_subtypes_map (map, &uri->media_subtypes);
spa_prop_audio_map (map, &uri->prop_audio);
spa_audio_formats_map (map, &uri->audio_formats);
spa_node_events_map (map, &uri->node_events);
spa_node_commands_map (map, &uri->node_commands);
spa_alloc_param_buffers_map (map, &uri->alloc_param_buffers);
spa_alloc_param_meta_enable_map (map, &uri->alloc_param_meta_enable);
}
struct _SpaVolume {
SpaHandle handle;
SpaNode node;
@ -99,20 +120,14 @@ struct _SpaVolume {
#define CHECK_OUT_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) == 0)
#define CHECK_PORT(this,d,p) ((p) == 0)
static const double default_volume = 1.0;
static const bool default_mute = false;
enum {
PROP_ID_NONE,
PROP_ID_VOLUME,
PROP_ID_MUTE,
};
#define DEFAULT_VOLUME 1.0
#define DEFAULT_MUTE false
static void
reset_volume_props (SpaVolumeProps *props)
{
props->volume = default_volume;
props->mute = default_mute;
props->volume = DEFAULT_VOLUME;
props->mute = DEFAULT_MUTE;
}
static void
@ -150,9 +165,9 @@ spa_volume_node_get_props (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaVolume, node);
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer));
spa_pod_builder_props (&b, &f[0],
PROP_MM (&f[1], PROP_ID_VOLUME, SPA_POD_TYPE_DOUBLE, this->props.volume, 0.0, 10.0),
PROP (&f[1], PROP_ID_MUTE, SPA_POD_TYPE_BOOL, this->props.mute));
spa_pod_builder_props (&b, &f[0], this->uri.props,
PROP_MM (&f[1], this->uri.prop_volume, SPA_POD_TYPE_DOUBLE, this->props.volume, 0.0, 10.0),
PROP (&f[1], this->uri.prop_mute, SPA_POD_TYPE_BOOL, this->props.mute));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
@ -174,8 +189,8 @@ spa_volume_node_set_props (SpaNode *node,
reset_volume_props (&this->props);
} else {
spa_props_query (props,
PROP_ID_VOLUME, SPA_POD_TYPE_DOUBLE, &this->props.volume,
PROP_ID_MUTE, SPA_POD_TYPE_BOOL, &this->props.mute,
this->uri.prop_volume, SPA_POD_TYPE_DOUBLE, &this->props.volume,
this->uri.prop_mute, SPA_POD_TYPE_BOOL, &this->props.mute,
0);
}
return SPA_RESULT_OK;
@ -838,16 +853,7 @@ volume_init (const SpaHandleFactory *factory,
spa_log_error (this->log, "an id-map is needed");
return SPA_RESULT_ERROR;
}
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
this->uri.format = spa_id_map_get_id (this->map, SPA_FORMAT_URI);
spa_media_types_fill (&this->uri.media_types, this->map);
spa_media_subtypes_map (this->map, &this->uri.media_subtypes);
spa_prop_audio_map (this->map, &this->uri.prop_audio);
spa_audio_formats_map (this->map, &this->uri.audio_formats);
spa_node_events_map (this->map, &this->uri.node_events);
spa_node_commands_map (this->map, &this->uri.node_commands);
spa_alloc_param_buffers_map (this->map, &this->uri.alloc_param_buffers);
spa_alloc_param_meta_enable_map (this->map, &this->uri.alloc_param_meta_enable);
init_uri (&this->uri, this->map);
this->node = volume_node;
reset_volume_props (&this->props);

View file

@ -71,11 +71,28 @@ typedef struct {
typedef struct {
uint32_t node;
uint32_t props;
uint32_t prop_device;
uint32_t prop_device_name;
uint32_t prop_device_fd;
SpaMediaTypes media_types;
SpaMediaSubtypes media_subtypes;
SpaNodeCommands node_commands;
} URI;
static inline void
init_uri (URI *uri, SpaIDMap *map)
{
uri->node = spa_id_map_get_id (map, SPA_NODE_URI);
uri->props = spa_id_map_get_id (map, SPA_PROPS_URI);
uri->prop_device = spa_id_map_get_id (map, SPA_PROPS__device);
uri->prop_device_name = spa_id_map_get_id (map, SPA_PROPS__deviceName);
uri->prop_device_fd = spa_id_map_get_id (map, SPA_PROPS__deviceFd);
spa_media_types_fill (&uri->media_types, map);
spa_media_subtypes_map (map, &uri->media_subtypes);
spa_node_commands_map (map, &uri->node_commands);
}
struct _SpaXvSink {
SpaHandle handle;
SpaNode node;
@ -104,13 +121,6 @@ struct _SpaXvSink {
#include "xv-utils.c"
enum {
PROP_ID_NONE,
PROP_ID_DEVICE,
PROP_ID_DEVICE_NAME,
PROP_ID_DEVICE_FD,
};
static void
update_state (SpaXvSink *this, SpaNodeState state)
{
@ -136,10 +146,10 @@ spa_xv_sink_node_get_props (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaXvSink, node);
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer));
spa_pod_builder_props (&b, &f[0],
PROP (&f[1], PROP_ID_DEVICE, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device)),
PROP_R (&f[1], PROP_ID_DEVICE_NAME, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
PROP_R (&f[1], PROP_ID_DEVICE_FD, SPA_POD_TYPE_INT, this->props.device_fd));
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_R (&f[1], this->uri.prop_device_name, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
PROP_R (&f[1], this->uri.prop_device_fd, SPA_POD_TYPE_INT, this->props.device_fd));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
return SPA_RESULT_OK;
@ -160,7 +170,7 @@ spa_xv_sink_node_set_props (SpaNode *node,
reset_xv_sink_props (&this->props);
} else {
spa_props_query (props,
PROP_ID_DEVICE, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
this->uri.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
0);
}
return SPA_RESULT_OK;
@ -563,10 +573,7 @@ xv_sink_init (const SpaHandleFactory *factory,
spa_log_error (this->log, "an id-map is needed");
return SPA_RESULT_ERROR;
}
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
spa_media_types_fill (&this->uri.media_types, this->map);
spa_media_subtypes_map (this->map, &this->uri.media_subtypes);
spa_node_commands_map (this->map, &this->uri.node_commands);
init_uri (&this->uri, this->map);
this->node = xvsink_node;
reset_xv_sink_props (&this->props);