mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
types: more work on types
This commit is contained in:
parent
acedfe71c0
commit
5825c62d6d
76 changed files with 1713 additions and 1477 deletions
|
|
@ -23,7 +23,7 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/timerfd.h>
|
||||
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/type-map.h>
|
||||
#include <spa/clock.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/loop.h>
|
||||
|
|
@ -48,37 +48,37 @@ typedef struct {
|
|||
uint32_t prop_volume;
|
||||
uint32_t wave_sine;
|
||||
uint32_t wave_square;
|
||||
SpaMediaTypes media_types;
|
||||
SpaMediaSubtypes media_subtypes;
|
||||
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;
|
||||
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_live = spa_id_map_get_id (map, SPA_TYPE_PROPS__live);
|
||||
uri->prop_wave = spa_id_map_get_id (map, SPA_TYPE_PROPS__waveType);
|
||||
uri->prop_freq = spa_id_map_get_id (map, SPA_TYPE_PROPS__frequency);
|
||||
uri->prop_volume = spa_id_map_get_id (map, SPA_TYPE_PROPS__volume);
|
||||
uri->wave_sine = spa_id_map_get_id (map, SPA_TYPE_PROPS__waveType ":sine");
|
||||
uri->wave_square = spa_id_map_get_id (map, SPA_TYPE_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_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);
|
||||
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_live = spa_type_map_get_id (map, SPA_TYPE_PROPS__live);
|
||||
type->prop_wave = spa_type_map_get_id (map, SPA_TYPE_PROPS__waveType);
|
||||
type->prop_freq = spa_type_map_get_id (map, SPA_TYPE_PROPS__frequency);
|
||||
type->prop_volume = spa_type_map_get_id (map, SPA_TYPE_PROPS__volume);
|
||||
type->wave_sine = spa_type_map_get_id (map, SPA_TYPE_PROPS__waveType ":sine");
|
||||
type->wave_square = spa_type_map_get_id (map, SPA_TYPE_PROPS__waveType ":square");
|
||||
spa_type_media_type_map (map, &type->media_type);
|
||||
spa_type_media_subtype_map (map, &type->media_subtype);
|
||||
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);
|
||||
}
|
||||
|
||||
typedef struct _SpaAudioTestSrc SpaAudioTestSrc;
|
||||
|
|
@ -108,8 +108,8 @@ struct _SpaAudioTestSrc {
|
|||
SpaNode node;
|
||||
SpaClock clock;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
Type type;
|
||||
SpaTypeMap *map;
|
||||
SpaLog *log;
|
||||
SpaLoop *data_loop;
|
||||
|
||||
|
|
@ -154,7 +154,7 @@ static void
|
|||
reset_audiotestsrc_props (SpaAudioTestSrc *this, SpaAudioTestSrcProps *props)
|
||||
{
|
||||
props->live = DEFAULT_LIVE;
|
||||
props->wave = this->uri. DEFAULT_WAVE;
|
||||
props->wave = this->type. DEFAULT_WAVE;
|
||||
props->freq = DEFAULT_FREQ;
|
||||
props->volume = DEFAULT_VOLUME;
|
||||
}
|
||||
|
|
@ -190,14 +190,14 @@ 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], 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,
|
||||
spa_pod_builder_props (&b, &f[0], this->type.props,
|
||||
PROP (&f[1], this->type.prop_live, SPA_POD_TYPE_BOOL, this->props.live),
|
||||
PROP_EN (&f[1], this->type.prop_wave, SPA_POD_TYPE_URI, 3, this->props.wave,
|
||||
this->type.wave_sine,
|
||||
this->type.wave_square),
|
||||
PROP_MM (&f[1], this->type.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,
|
||||
PROP_MM (&f[1], this->type.prop_volume, SPA_POD_TYPE_DOUBLE, this->props.volume,
|
||||
0.0, 10.0));
|
||||
|
||||
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
|
||||
|
|
@ -220,10 +220,10 @@ spa_audiotestsrc_node_set_props (SpaNode *node,
|
|||
reset_audiotestsrc_props (this, &this->props);
|
||||
} else {
|
||||
spa_props_query (props,
|
||||
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,
|
||||
this->type.prop_live, SPA_POD_TYPE_BOOL, &this->props.live,
|
||||
this->type.prop_wave, SPA_POD_TYPE_URI, &this->props.wave,
|
||||
this->type.prop_freq, SPA_POD_TYPE_DOUBLE, &this->props.freq,
|
||||
this->type.prop_volume, SPA_POD_TYPE_DOUBLE, &this->props.volume,
|
||||
0);
|
||||
}
|
||||
|
||||
|
|
@ -240,7 +240,7 @@ send_have_output (SpaAudioTestSrc *this)
|
|||
{
|
||||
|
||||
if (this->event_cb) {
|
||||
SpaEvent event = SPA_EVENT_INIT (this->uri.event_node.HaveOutput);
|
||||
SpaEvent event = SPA_EVENT_INIT (this->type.event_node.HaveOutput);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
}
|
||||
|
||||
|
|
@ -334,7 +334,7 @@ spa_audiotestsrc_node_send_command (SpaNode *node,
|
|||
|
||||
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
||||
|
||||
if (SPA_COMMAND_TYPE (command) == this->uri.command_node.Start) {
|
||||
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) {
|
||||
struct timespec now;
|
||||
|
||||
if (!this->have_format)
|
||||
|
|
@ -358,7 +358,7 @@ spa_audiotestsrc_node_send_command (SpaNode *node,
|
|||
set_timer (this, true);
|
||||
update_state (this, SPA_NODE_STATE_STREAMING);
|
||||
}
|
||||
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;
|
||||
|
||||
|
|
@ -484,13 +484,13 @@ 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;
|
||||
default:
|
||||
return SPA_RESULT_ENUM_END;
|
||||
|
|
@ -560,15 +560,15 @@ spa_audiotestsrc_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, 1024),
|
||||
PROP (&f[1], this->uri.alloc_param_buffers.stride, SPA_POD_TYPE_INT, 1024),
|
||||
PROP_U_MM (&f[1], this->uri.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, 32, 2, 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, 1024),
|
||||
PROP (&f[1], this->type.alloc_param_buffers.stride, SPA_POD_TYPE_INT, 1024),
|
||||
PROP_U_MM (&f[1], this->type.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, 32, 2, 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;
|
||||
|
|
@ -602,11 +602,11 @@ spa_audiotestsrc_node_port_get_format (SpaNode *node,
|
|||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
spa_pod_builder_init (&b, this->format_buffer, sizeof (this->format_buffer));
|
||||
spa_pod_builder_format (&b, &f[0], this->uri.format,
|
||||
this->uri.media_types.audio, this->uri.media_subtypes.raw,
|
||||
PROP (&f[1], this->uri.prop_audio.format, SPA_POD_TYPE_URI, this->current_format.info.raw.format),
|
||||
PROP (&f[1], this->uri.prop_audio.rate, SPA_POD_TYPE_INT, this->current_format.info.raw.rate),
|
||||
PROP (&f[1], this->uri.prop_audio.channels, SPA_POD_TYPE_INT, this->current_format.info.raw.channels));
|
||||
spa_pod_builder_format (&b, &f[0], this->type.format,
|
||||
this->type.media_type.audio, this->type.media_subtype.raw,
|
||||
PROP (&f[1], this->type.prop_audio.format, SPA_POD_TYPE_URI, this->current_format.info.raw.format),
|
||||
PROP (&f[1], this->type.prop_audio.rate, SPA_POD_TYPE_INT, this->current_format.info.raw.rate),
|
||||
PROP (&f[1], this->type.prop_audio.channels, SPA_POD_TYPE_INT, this->current_format.info.raw.channels));
|
||||
|
||||
*format = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaFormat);
|
||||
|
||||
|
|
@ -909,9 +909,9 @@ spa_audiotestsrc_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaAudioTestSrc *) 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;
|
||||
|
|
@ -953,22 +953,22 @@ audiotestsrc_init (const SpaHandleFactory *factory,
|
|||
this = (SpaAudioTestSrc *) 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;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
spa_log_error (this->log, "a type-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
if (this->data_loop == NULL) {
|
||||
spa_log_error (this->log, "a data_loop is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
init_uri (&this->uri, this->map);
|
||||
init_type (&this->type, this->map);
|
||||
|
||||
this->node = audiotestsrc_node;
|
||||
this->clock = audiotestsrc_clock;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue