mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-10 13:30:05 -05:00
Unify props, params and formats
Make enum_params and set_param to configure properties, format and other parameters. This allows us to remove some duplicate code and make the properties and parameters much more extensible. Use the object id to mark the id of the parameter. Remove the spa_format and spa_props. We can now make the client-node easier by merging the various format methods into the params. Make the stream API more powerful now that we can pass params around.
This commit is contained in:
parent
b6ee67905d
commit
f3bca48398
87 changed files with 3773 additions and 3580 deletions
|
|
@ -207,16 +207,20 @@ new_node (GstPipeWireDeviceProvider *self, const struct pw_node_info *info, uint
|
|||
if (info->max_input_ports > 0 && info->max_output_ports == 0) {
|
||||
type = GST_PIPEWIRE_DEVICE_TYPE_SINK;
|
||||
|
||||
for (i = 0; i < info->n_input_formats; i++) {
|
||||
GstCaps *c1 = gst_caps_from_format (info->input_formats[i], t->map);
|
||||
for (i = 0; i < info->n_input_params; i++) {
|
||||
if (info->input_params[i]->body.id != t->param.idEnumFormat)
|
||||
continue;
|
||||
GstCaps *c1 = gst_caps_from_format (info->input_params[i], t->map);
|
||||
if (c1)
|
||||
gst_caps_append (caps, c1);
|
||||
}
|
||||
}
|
||||
else if (info->max_output_ports > 0 && info->max_input_ports == 0) {
|
||||
type = GST_PIPEWIRE_DEVICE_TYPE_SOURCE;
|
||||
for (i = 0; i < info->n_output_formats; i++) {
|
||||
GstCaps *c1 = gst_caps_from_format (info->output_formats[i], t->map);
|
||||
for (i = 0; i < info->n_output_params; i++) {
|
||||
if (info->output_params[i]->body.id != t->param.idEnumFormat)
|
||||
continue;
|
||||
GstCaps *c1 = gst_caps_from_format (info->output_params[i], t->map);
|
||||
if (c1)
|
||||
gst_caps_append (caps, c1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include <gst/video/video.h>
|
||||
#include <gst/audio/audio.h>
|
||||
|
||||
#include <spa/format-builder.h>
|
||||
#include <spa/pod-builder.h>
|
||||
#include <spa/video/format-utils.h>
|
||||
#include <spa/audio/format-utils.h>
|
||||
|
||||
|
|
@ -542,7 +542,7 @@ write_pod (struct spa_pod_builder *b, uint32_t ref, const void *data, uint32_t s
|
|||
return ref;
|
||||
}
|
||||
|
||||
static struct spa_format *
|
||||
static struct spa_pod_object *
|
||||
convert_1 (GstCapsFeatures *cf, GstStructure *cs)
|
||||
{
|
||||
ConvertData d;
|
||||
|
|
@ -557,9 +557,9 @@ convert_1 (GstCapsFeatures *cf, GstStructure *cs)
|
|||
|
||||
d.b.write = write_pod;
|
||||
|
||||
spa_pod_builder_push_format (&d.b, &f, type.format,
|
||||
*d.type->media_type,
|
||||
*d.type->media_subtype);
|
||||
spa_pod_builder_push_object (&d.b, &f, 0, type.format);
|
||||
spa_pod_builder_id(&d.b, *d.type->media_type);
|
||||
spa_pod_builder_id(&d.b, *d.type->media_subtype);
|
||||
|
||||
if (*d.type->media_type == type.media_type.video)
|
||||
handle_video_fields (&d);
|
||||
|
|
@ -568,15 +568,15 @@ convert_1 (GstCapsFeatures *cf, GstStructure *cs)
|
|||
|
||||
spa_pod_builder_pop (&d.b, &f);
|
||||
|
||||
return SPA_MEMBER (d.b.data, 0, struct spa_format);
|
||||
return SPA_MEMBER (d.b.data, 0, struct spa_pod_object);
|
||||
}
|
||||
|
||||
struct spa_format *
|
||||
struct spa_pod_object *
|
||||
gst_caps_to_format (GstCaps *caps, guint index, struct spa_type_map *map)
|
||||
{
|
||||
GstCapsFeatures *f;
|
||||
GstStructure *s;
|
||||
struct spa_format *res;
|
||||
struct spa_pod_object *res;
|
||||
|
||||
g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
|
||||
g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
|
||||
|
|
@ -596,7 +596,7 @@ foreach_func (GstCapsFeatures *features,
|
|||
GstStructure *structure,
|
||||
GPtrArray *array)
|
||||
{
|
||||
struct spa_format *fmt;
|
||||
struct spa_pod_object *fmt;
|
||||
|
||||
if ((fmt = convert_1 (features, structure)))
|
||||
g_ptr_array_insert (array, -1, fmt);
|
||||
|
|
@ -794,7 +794,7 @@ handle_fraction_prop (struct spa_pod_prop *prop, const char *key, GstCaps *res)
|
|||
}
|
||||
}
|
||||
GstCaps *
|
||||
gst_caps_from_format (const struct spa_format *format, struct spa_type_map *map)
|
||||
gst_caps_from_format (const struct spa_pod_object *format, struct spa_type_map *map)
|
||||
{
|
||||
GstCaps *res = NULL;
|
||||
uint32_t media_type, media_subtype;
|
||||
|
|
@ -802,13 +802,13 @@ gst_caps_from_format (const struct spa_format *format, struct spa_type_map *map)
|
|||
|
||||
ensure_types(map);
|
||||
|
||||
media_type = SPA_FORMAT_MEDIA_TYPE (format);
|
||||
media_subtype = SPA_FORMAT_MEDIA_SUBTYPE (format);
|
||||
spa_pod_object_parse(format, "I", &media_type,
|
||||
"I", &media_subtype);
|
||||
|
||||
if (media_type == type.media_type.video) {
|
||||
if (media_subtype == type.media_subtype.raw) {
|
||||
res = gst_caps_new_empty_simple ("video/x-raw");
|
||||
if ((prop = spa_format_find_prop (format, type.format_video.format))) {
|
||||
if ((prop = spa_pod_object_find_prop (format, type.format_video.format))) {
|
||||
handle_id_prop (prop, "format", res);
|
||||
}
|
||||
}
|
||||
|
|
@ -821,13 +821,13 @@ gst_caps_from_format (const struct spa_format *format, struct spa_type_map *map)
|
|||
"alignment", G_TYPE_STRING, "au",
|
||||
NULL);
|
||||
}
|
||||
if ((prop = spa_format_find_prop (format, type.format_video.size))) {
|
||||
if ((prop = spa_pod_object_find_prop (format, type.format_video.size))) {
|
||||
handle_rect_prop (prop, "width", "height", res);
|
||||
}
|
||||
if ((prop = spa_format_find_prop (format, type.format_video.framerate))) {
|
||||
if ((prop = spa_pod_object_find_prop (format, type.format_video.framerate))) {
|
||||
handle_fraction_prop (prop, "framerate", res);
|
||||
}
|
||||
if ((prop = spa_format_find_prop (format, type.format_video.max_framerate))) {
|
||||
if ((prop = spa_pod_object_find_prop (format, type.format_video.max_framerate))) {
|
||||
handle_fraction_prop (prop, "max-framerate", res);
|
||||
}
|
||||
} else if (media_type == type.media_type.audio) {
|
||||
|
|
@ -835,13 +835,13 @@ gst_caps_from_format (const struct spa_format *format, struct spa_type_map *map)
|
|||
res = gst_caps_new_simple ("audio/x-raw",
|
||||
"layout", G_TYPE_STRING, "interleaved",
|
||||
NULL);
|
||||
if ((prop = spa_format_find_prop (format, type.format_audio.format))) {
|
||||
if ((prop = spa_pod_object_find_prop (format, type.format_audio.format))) {
|
||||
handle_id_prop (prop, "format", res);
|
||||
}
|
||||
if ((prop = spa_format_find_prop (format, type.format_audio.rate))) {
|
||||
if ((prop = spa_pod_object_find_prop (format, type.format_audio.rate))) {
|
||||
handle_int_prop (prop, "rate", res);
|
||||
}
|
||||
if ((prop = spa_format_find_prop (format, type.format_audio.channels))) {
|
||||
if ((prop = spa_pod_object_find_prop (format, type.format_audio.channels))) {
|
||||
handle_int_prop (prop, "channels", res);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,10 +27,10 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
struct spa_format * gst_caps_to_format (GstCaps *caps, guint index, struct spa_type_map *map);
|
||||
GPtrArray * gst_caps_to_format_all (GstCaps *caps, struct spa_type_map *map);
|
||||
struct spa_pod_object * gst_caps_to_format (GstCaps *caps, guint index, struct spa_type_map *map);
|
||||
GPtrArray * gst_caps_to_format_all (GstCaps *caps, struct spa_type_map *map);
|
||||
|
||||
GstCaps * gst_caps_from_format (const struct spa_format *format, struct spa_type_map *map);
|
||||
GstCaps * gst_caps_from_format (const struct spa_pod_object *format, struct spa_type_map *map);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ pool_activated (GstPipeWirePool *pool, GstPipeWireSink *sink)
|
|||
guint size;
|
||||
guint min_buffers;
|
||||
guint max_buffers;
|
||||
struct spa_param *port_params[3];
|
||||
struct spa_pod_object *port_params[3];
|
||||
struct spa_pod_builder b = { NULL };
|
||||
uint8_t buffer[1024];
|
||||
struct spa_pod_frame f[1];
|
||||
|
|
@ -237,7 +237,7 @@ pool_activated (GstPipeWirePool *pool, GstPipeWireSink *sink)
|
|||
gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers, &max_buffers);
|
||||
|
||||
spa_pod_builder_init (&b, buffer, sizeof (buffer));
|
||||
spa_pod_builder_push_param (&b, &f[0], t->param_alloc_buffers.Buffers);
|
||||
spa_pod_builder_push_object (&b, &f[0], t->param.idBuffers, t->param_alloc_buffers.Buffers);
|
||||
if (size == 0)
|
||||
spa_pod_builder_add (&b,
|
||||
":", t->param_alloc_buffers.size, "iru", 0, SPA_PROP_RANGE(0, INT32_MAX), NULL);
|
||||
|
|
@ -253,15 +253,15 @@ pool_activated (GstPipeWirePool *pool, GstPipeWireSink *sink)
|
|||
":", t->param_alloc_buffers.align, "i", 16,
|
||||
NULL);
|
||||
spa_pod_builder_pop (&b, &f[0]);
|
||||
port_params[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_param);
|
||||
port_params[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_pod_object);
|
||||
|
||||
port_params[1] = spa_pod_builder_param (&b,
|
||||
t->param_alloc_meta_enable.MetaEnable,
|
||||
port_params[1] = spa_pod_builder_object (&b,
|
||||
t->param.idMeta, t->param_alloc_meta_enable.MetaEnable,
|
||||
":", t->param_alloc_meta_enable.type, "I", t->meta.Header,
|
||||
":", t->param_alloc_meta_enable.size, "i", sizeof (struct spa_meta_header));
|
||||
|
||||
port_params[2] = spa_pod_builder_param (&b,
|
||||
t->param_alloc_meta_enable.MetaEnable,
|
||||
port_params[2] = spa_pod_builder_object (&b,
|
||||
t->param.idMeta, t->param_alloc_meta_enable.MetaEnable,
|
||||
":", t->param_alloc_meta_enable.type, "I", t->meta.Ringbuffer,
|
||||
":", t->param_alloc_meta_enable.size, "i", sizeof (struct spa_meta_ringbuffer),
|
||||
":", t->param_alloc_meta_enable.ringbufferSize, "i", size * SPA_MAX (4,
|
||||
|
|
@ -271,7 +271,7 @@ pool_activated (GstPipeWirePool *pool, GstPipeWireSink *sink)
|
|||
":", t->param_alloc_meta_enable.ringbufferAlign, "i", 16);
|
||||
|
||||
pw_thread_loop_lock (sink->main_loop);
|
||||
pw_stream_finish_format (sink->stream, SPA_RESULT_OK, port_params, 2);
|
||||
pw_stream_finish_format (sink->stream, SPA_RESULT_OK, 2, port_params);
|
||||
pw_thread_loop_unlock (sink->main_loop);
|
||||
}
|
||||
|
||||
|
|
@ -586,7 +586,7 @@ on_state_changed (void *data, enum pw_stream_state old, enum pw_stream_state sta
|
|||
}
|
||||
|
||||
static void
|
||||
on_format_changed (void *data, struct spa_format *format)
|
||||
on_format_changed (void *data, struct spa_pod_object *format)
|
||||
{
|
||||
GstPipeWireSink *pwsink = data;
|
||||
|
||||
|
|
@ -621,11 +621,10 @@ gst_pipewire_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
|
|||
|
||||
pw_stream_connect (pwsink->stream,
|
||||
PW_DIRECTION_OUTPUT,
|
||||
PW_STREAM_MODE_BUFFER,
|
||||
pwsink->path,
|
||||
flags,
|
||||
possible->len,
|
||||
(const struct spa_format **) possible->pdata);
|
||||
(const struct spa_pod_object **) possible->pdata);
|
||||
|
||||
while (TRUE) {
|
||||
state = pw_stream_get_state (pwsink->stream, &error);
|
||||
|
|
|
|||
|
|
@ -663,11 +663,10 @@ gst_pipewire_src_negotiate (GstBaseSrc * basesrc)
|
|||
GST_DEBUG_OBJECT (basesrc, "connect capture with path %s", pwsrc->path);
|
||||
pw_stream_connect (pwsrc->stream,
|
||||
PW_DIRECTION_INPUT,
|
||||
PW_STREAM_MODE_BUFFER,
|
||||
pwsrc->path,
|
||||
PW_STREAM_FLAG_AUTOCONNECT,
|
||||
possible->len,
|
||||
(const struct spa_format **)possible->pdata);
|
||||
(const struct spa_pod_object **)possible->pdata);
|
||||
g_ptr_array_free (possible, TRUE);
|
||||
|
||||
while (TRUE) {
|
||||
|
|
@ -729,8 +728,8 @@ connect_error:
|
|||
#define SPA_PROP_RANGE(min,max) 2,min,max
|
||||
|
||||
static void
|
||||
on_format_changed (void *data,
|
||||
struct spa_format *format)
|
||||
on_format_changed (void *data,
|
||||
struct spa_pod_object *format)
|
||||
{
|
||||
GstPipeWireSrc *pwsrc = data;
|
||||
GstCaps *caps;
|
||||
|
|
@ -740,7 +739,7 @@ on_format_changed (void *data,
|
|||
|
||||
if (format == NULL) {
|
||||
GST_DEBUG_OBJECT (pwsrc, "clear format");
|
||||
pw_stream_finish_format (pwsrc->stream, SPA_RESULT_OK, NULL, 0);
|
||||
pw_stream_finish_format (pwsrc->stream, SPA_RESULT_OK, 0, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -750,28 +749,28 @@ on_format_changed (void *data,
|
|||
gst_caps_unref (caps);
|
||||
|
||||
if (res) {
|
||||
struct spa_param *params[2];
|
||||
struct spa_pod_object *params[2];
|
||||
struct spa_pod_builder b = { NULL };
|
||||
uint8_t buffer[512];
|
||||
|
||||
spa_pod_builder_init (&b, buffer, sizeof (buffer));
|
||||
params[0] = spa_pod_builder_param (&b,
|
||||
t->param_alloc_buffers.Buffers,
|
||||
params[0] = spa_pod_builder_object (&b,
|
||||
0, t->param_alloc_buffers.Buffers,
|
||||
":", t->param_alloc_buffers.size, "ir", 0, SPA_PROP_RANGE(0, INT32_MAX),
|
||||
":", t->param_alloc_buffers.stride, "ir", 0, SPA_PROP_RANGE(0, INT32_MAX),
|
||||
":", t->param_alloc_buffers.buffers, "ir", 16, SPA_PROP_RANGE(1, INT32_MAX),
|
||||
":", t->param_alloc_buffers.align, "i", 16);
|
||||
|
||||
params[1] = spa_pod_builder_param (&b,
|
||||
t->param_alloc_meta_enable.MetaEnable,
|
||||
params[1] = spa_pod_builder_object (&b,
|
||||
0, t->param_alloc_meta_enable.MetaEnable,
|
||||
":", t->param_alloc_meta_enable.type, "I", t->meta.Header,
|
||||
":", t->param_alloc_meta_enable.size, "i", sizeof (struct spa_meta_header));
|
||||
|
||||
GST_DEBUG_OBJECT (pwsrc, "doing finish format");
|
||||
pw_stream_finish_format (pwsrc->stream, SPA_RESULT_OK, params, 2);
|
||||
pw_stream_finish_format (pwsrc->stream, SPA_RESULT_OK, 2, params);
|
||||
} else {
|
||||
GST_WARNING_OBJECT (pwsrc, "finish format with error");
|
||||
pw_stream_finish_format (pwsrc->stream, SPA_RESULT_INVALID_MEDIA_TYPE, NULL, 0);
|
||||
pw_stream_finish_format (pwsrc->stream, SPA_RESULT_INVALID_MEDIA_TYPE, 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue