From 514528f2c77103f28aa945b27c4ea91cff335976 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 29 Aug 2018 15:53:26 +0200 Subject: [PATCH] format: make helper functions to create formats Use helper functions to create a fully specified format. --- spa/include/spa/param/audio/raw.h | 2 + spa/include/spa/param/video/format-utils.h | 14 +++++++ spa/include/spa/param/video/raw.h | 2 + spa/plugins/audioconvert/channelmix.c | 34 +++------------- spa/plugins/audioconvert/fmtconvert.c | 34 +++------------- spa/plugins/audioconvert/merger.c | 34 +++------------- spa/plugins/audioconvert/resample.c | 34 +++------------- spa/plugins/audioconvert/splitter.c | 34 +++------------- spa/plugins/audiomixer/audiomixer.c | 33 +++------------ spa/plugins/audiotestsrc/audiotestsrc.c | 34 ++++------------ spa/plugins/bluez5/a2dp-sink.c | 9 +---- spa/plugins/videotestsrc/videotestsrc.c | 33 +++------------ spa/plugins/volume/volume.c | 38 ++++------------- spa/tests/test-control.c | 14 +++---- spa/tests/test-convert.c | 30 ++++++-------- spa/tests/test-convert2.c | 28 ++++++------- spa/tests/test-graph.c | 14 +++---- spa/tests/test-mixer.c | 14 +++---- spa/tests/test-ringbuffer.c | 14 +++---- spa/tests/test-v4l2.c | 12 +++--- src/examples/audio-src.c | 14 +++---- src/examples/export-sink.c | 30 ++------------ src/examples/export-source.c | 38 ++++------------- src/modules/module-media-session/floatmix.c | 45 +++++---------------- 24 files changed, 158 insertions(+), 430 deletions(-) diff --git a/spa/include/spa/param/audio/raw.h b/spa/include/spa/param/audio/raw.h index 65d3b1429..08208cbe3 100644 --- a/spa/include/spa/param/audio/raw.h +++ b/spa/include/spa/param/audio/raw.h @@ -144,6 +144,8 @@ struct spa_audio_info_raw { uint32_t channel_mask; /*< channel mask */ }; +#define SPA_AUDIO_INFO_RAW_INIT(...) (struct spa_audio_info_raw) { __VA_ARGS__ } + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/include/spa/param/video/format-utils.h b/spa/include/spa/param/video/format-utils.h index 15e796dff..387bea930 100644 --- a/spa/include/spa/param/video/format-utils.h +++ b/spa/include/spa/param/video/format-utils.h @@ -25,6 +25,7 @@ extern "C" { #endif #include +#include #include #include @@ -49,6 +50,19 @@ spa_format_video_raw_parse(const struct spa_pod *format, ":", SPA_FORMAT_VIDEO_colorPrimaries, "?i", &info->color_primaries, NULL); } +static inline struct spa_pod * +spa_format_video_raw_build(struct spa_pod_builder *builder, uint32_t id, + struct spa_video_info_raw *info) +{ + return spa_pod_builder_object(builder, + SPA_TYPE_OBJECT_Format, id, + "I", SPA_MEDIA_TYPE_video, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_VIDEO_format, "I", &info->format, + ":", SPA_FORMAT_VIDEO_size, "R", &info->size, + ":", SPA_FORMAT_VIDEO_framerate, "F", &info->framerate); +} + static inline int spa_format_video_h264_parse(const struct spa_pod *format, struct spa_video_info_h264 *info) diff --git a/spa/include/spa/param/video/raw.h b/spa/include/spa/param/video/raw.h index 7d3cc2f4d..a6da6235a 100644 --- a/spa/include/spa/param/video/raw.h +++ b/spa/include/spa/param/video/raw.h @@ -191,6 +191,8 @@ struct spa_video_info_raw { enum spa_video_color_primaries color_primaries; }; +#define SPA_VIDEO_INFO_RAW_INIT(...) (struct spa_video_info_raw) { __VA_ARGS__ } + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/plugins/audioconvert/channelmix.c b/spa/plugins/audioconvert/channelmix.c index 3b689a917..504191678 100644 --- a/spa/plugins/audioconvert/channelmix.c +++ b/spa/plugins/audioconvert/channelmix.c @@ -335,32 +335,6 @@ static int port_enum_formats(struct spa_node *node, return 1; } -static int port_get_format(struct spa_node *node, - enum spa_direction direction, uint32_t port_id, - uint32_t *index, - struct spa_pod **param, - struct spa_pod_builder *builder) -{ - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct port *port = GET_PORT(this, direction, port_id); - - if (!port->have_format) - return -EIO; - if (*index > 0) - return 0; - - *param = spa_pod_builder_object(builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_Format, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", port->format.info.raw.format, - ":", SPA_FORMAT_AUDIO_layout, "I", port->format.info.raw.layout, - ":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels); - - return 1; -} - static int impl_node_port_enum_params(struct spa_node *node, enum spa_direction direction, uint32_t port_id, @@ -412,8 +386,12 @@ impl_node_port_enum_params(struct spa_node *node, break; case SPA_PARAM_Format: - if ((res = port_get_format(node, direction, port_id, index, ¶m, &b)) <= 0) - return res; + if (!port->have_format) + return -EIO; + if (*index > 0) + return 0; + + param = spa_format_audio_raw_build(&b, id, &port->format.info.raw); break; case SPA_PARAM_Buffers: diff --git a/spa/plugins/audioconvert/fmtconvert.c b/spa/plugins/audioconvert/fmtconvert.c index c124bb003..fb4019133 100644 --- a/spa/plugins/audioconvert/fmtconvert.c +++ b/spa/plugins/audioconvert/fmtconvert.c @@ -465,32 +465,6 @@ static int port_enum_formats(struct spa_node *node, return 1; } -static int port_get_format(struct spa_node *node, - enum spa_direction direction, uint32_t port_id, - uint32_t *index, - struct spa_pod **param, - struct spa_pod_builder *builder) -{ - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct port *port = GET_PORT(this, direction, port_id); - - if (!port->have_format) - return -EIO; - if (*index > 0) - return 0; - - *param = spa_pod_builder_object(builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_Format, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", port->format.info.raw.format, - ":", SPA_FORMAT_AUDIO_layout, "I", port->format.info.raw.layout, - ":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels); - - return 1; -} - static int impl_node_port_enum_params(struct spa_node *node, enum spa_direction direction, uint32_t port_id, @@ -543,8 +517,12 @@ impl_node_port_enum_params(struct spa_node *node, break; case SPA_PARAM_Format: - if ((res = port_get_format(node, direction, port_id, index, ¶m, &b)) <= 0) - return res; + if (!port->have_format) + return -EIO; + if (*index > 0) + return 0; + + param = spa_format_audio_raw_build(&b, id, &port->format.info.raw); break; case SPA_PARAM_Buffers: diff --git a/spa/plugins/audioconvert/merger.c b/spa/plugins/audioconvert/merger.c index 266b306c8..4f20ad13a 100644 --- a/spa/plugins/audioconvert/merger.c +++ b/spa/plugins/audioconvert/merger.c @@ -360,32 +360,6 @@ static int port_enum_formats(struct spa_node *node, return 1; } -static int port_get_format(struct spa_node *node, - enum spa_direction direction, uint32_t port_id, - uint32_t *index, - struct spa_pod **param, - struct spa_pod_builder *builder) -{ - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct port *port = GET_PORT(this, direction, port_id); - - if (!port->have_format) - return -EIO; - if (*index > 0) - return 0; - - *param = spa_pod_builder_object(builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_Format, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", port->format.info.raw.format, - ":", SPA_FORMAT_AUDIO_layout, "I", port->format.info.raw.layout, - ":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels); - - return 1; -} - static int impl_node_port_enum_params(struct spa_node *node, enum spa_direction direction, uint32_t port_id, @@ -436,8 +410,12 @@ impl_node_port_enum_params(struct spa_node *node, return res; break; case SPA_PARAM_Format: - if ((res = port_get_format(node, direction, port_id, index, ¶m, &b)) <= 0) - return res; + if (!port->have_format) + return -EIO; + if (*index > 0) + return 0; + + param = spa_format_audio_raw_build(&b, id, &port->format.info.raw); break; case SPA_PARAM_Buffers: if (!port->have_format) diff --git a/spa/plugins/audioconvert/resample.c b/spa/plugins/audioconvert/resample.c index 6dc2fd137..e21644ecb 100644 --- a/spa/plugins/audioconvert/resample.c +++ b/spa/plugins/audioconvert/resample.c @@ -309,32 +309,6 @@ static int port_enum_formats(struct spa_node *node, return 1; } -static int port_get_format(struct spa_node *node, - enum spa_direction direction, uint32_t port_id, - uint32_t *index, - struct spa_pod **param, - struct spa_pod_builder *builder) -{ - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct port *port = GET_PORT(this, direction, port_id); - - if (!port->have_format) - return -EIO; - if (*index > 0) - return 0; - - *param = spa_pod_builder_object(builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_Format, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", port->format.info.raw.format, - ":", SPA_FORMAT_AUDIO_layout, "I", port->format.info.raw.layout, - ":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels); - - return 1; -} - static int impl_node_port_enum_params(struct spa_node *node, enum spa_direction direction, uint32_t port_id, @@ -385,8 +359,12 @@ impl_node_port_enum_params(struct spa_node *node, return res; break; case SPA_PARAM_Format: - if ((res = port_get_format(node, direction, port_id, index, ¶m, &b)) <= 0) - return res; + if (!port->have_format) + return -EIO; + if (*index > 0) + return 0; + + param = spa_format_audio_raw_build(&b, id, &port->format.info.raw); break; case SPA_PARAM_Buffers: { diff --git a/spa/plugins/audioconvert/splitter.c b/spa/plugins/audioconvert/splitter.c index 5d4b0456f..4730c602f 100644 --- a/spa/plugins/audioconvert/splitter.c +++ b/spa/plugins/audioconvert/splitter.c @@ -360,32 +360,6 @@ static int port_enum_formats(struct spa_node *node, return 1; } -static int port_get_format(struct spa_node *node, - enum spa_direction direction, uint32_t port_id, - uint32_t *index, - struct spa_pod **param, - struct spa_pod_builder *builder) -{ - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct port *port = GET_PORT(this, direction, port_id); - - if (!port->have_format) - return -EIO; - if (*index > 0) - return 0; - - *param = spa_pod_builder_object(builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_Format, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", port->format.info.raw.format, - ":", SPA_FORMAT_AUDIO_layout, "I", port->format.info.raw.layout, - ":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels); - - return 1; -} - static int impl_node_port_enum_params(struct spa_node *node, enum spa_direction direction, uint32_t port_id, @@ -437,8 +411,12 @@ impl_node_port_enum_params(struct spa_node *node, return res; break; case SPA_PARAM_Format: - if ((res = port_get_format(node, direction, port_id, index, ¶m, &b)) <= 0) - return res; + if (!port->have_format) + return -EIO; + if (*index > 0) + return 0; + + param = spa_format_audio_raw_build(&b, id, &port->format.info.raw); break; case SPA_PARAM_Buffers: if (!port->have_format) diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index d82989c38..bcbfd711a 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -353,31 +353,6 @@ static int port_enum_formats(struct spa_node *node, return 1; } -static int port_get_format(struct spa_node *node, - enum spa_direction direction, uint32_t port_id, - uint32_t *index, - struct spa_pod **param, - struct spa_pod_builder *builder) -{ - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct port *port = GET_PORT(this, direction, port_id); - - if (!port->have_format) - return -EIO; - if (*index > 0) - return 0; - - *param = spa_pod_builder_object(builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_Format, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", this->format.info.raw.format, - ":", SPA_FORMAT_AUDIO_rate, "i", this->format.info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "i", this->format.info.raw.channels); - - return 1; -} - static int impl_node_port_enum_params(struct spa_node *node, enum spa_direction direction, uint32_t port_id, @@ -427,8 +402,12 @@ impl_node_port_enum_params(struct spa_node *node, return res; break; case SPA_PARAM_Format: - if ((res = port_get_format(node, direction, port_id, index, ¶m, &b)) <= 0) - return res; + if (!port->have_format) + return -EIO; + if (*index > 0) + return 0; + + param = spa_format_audio_raw_build(&b, id, &this->format.info.raw); break; case SPA_PARAM_Buffers: if (!port->have_format) diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index 62137f0e3..f59d71922 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -534,6 +534,7 @@ port_enum_formats(struct impl *this, SPA_AUDIO_FORMAT_S32, SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_F64), + ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED, ":", SPA_FORMAT_AUDIO_rate, "iru", 44100, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), ":", SPA_FORMAT_AUDIO_channels, "iru", 2, @@ -545,30 +546,6 @@ port_enum_formats(struct impl *this, return 1; } -static int -port_get_format(struct impl *this, - enum spa_direction direction, - uint32_t port_id, - uint32_t *index, - struct spa_pod **param, - struct spa_pod_builder *builder) -{ - if (!this->have_format) - return -EIO; - if (*index > 0) - return 0; - - *param = spa_pod_builder_object(builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_Format, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", this->current_format.info.raw.format, - ":", SPA_FORMAT_AUDIO_rate, "i", this->current_format.info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "i", this->current_format.info.raw.channels); - - return 1; -} - static int impl_node_port_enum_params(struct spa_node *node, enum spa_direction direction, uint32_t port_id, @@ -614,9 +591,14 @@ impl_node_port_enum_params(struct spa_node *node, if ((res = port_enum_formats(this, direction, port_id, index, ¶m, &b)) <= 0) return res; break; + case SPA_PARAM_Format: - if ((res = port_get_format(this, direction, port_id, index, ¶m, &b)) <= 0) - return res; + if (!this->have_format) + return -EIO; + if (*index > 0) + return 0; + + param = spa_format_audio_raw_build(&b, id, &this->current_format.info.raw); break; case SPA_PARAM_Buffers: diff --git a/spa/plugins/bluez5/a2dp-sink.c b/spa/plugins/bluez5/a2dp-sink.c index ecfcd5d30..b0ad5a9d6 100644 --- a/spa/plugins/bluez5/a2dp-sink.c +++ b/spa/plugins/bluez5/a2dp-sink.c @@ -984,14 +984,7 @@ impl_node_port_enum_params(struct spa_node *node, if (*index > 0) return 0; - param = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_Format, id, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", this->current_format.info.raw.format, - ":", SPA_FORMAT_AUDIO_layout, "I", this->current_format.info.raw.layout, - ":", SPA_FORMAT_AUDIO_rate, "i", this->current_format.info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "i", this->current_format.info.raw.channels); + param = spa_format_audio_raw_build(&b, id, &this->current_format.info.raw); break; case SPA_PARAM_Buffers: diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c index af6b6dd65..97f89298b 100644 --- a/spa/plugins/videotestsrc/videotestsrc.c +++ b/spa/plugins/videotestsrc/videotestsrc.c @@ -482,31 +482,6 @@ static int port_enum_formats(struct spa_node *node, return 1; } -static int port_get_format(struct spa_node *node, - enum spa_direction direction, uint32_t port_id, - uint32_t *index, - const struct spa_pod *filter, - struct spa_pod **param, - struct spa_pod_builder *builder) -{ - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - - if (!this->have_format) - return -EIO; - if (*index > 0) - return 0; - - *param = spa_pod_builder_object(builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_Format, - "I", SPA_MEDIA_TYPE_video, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_VIDEO_format, "I", this->current_format.info.raw.format, - ":", SPA_FORMAT_VIDEO_size, "R", &this->current_format.info.raw.size, - ":", SPA_FORMAT_VIDEO_framerate, "F", &this->current_format.info.raw.framerate); - - return 1; -} - static int impl_node_port_enum_params(struct spa_node *node, enum spa_direction direction, uint32_t port_id, @@ -553,8 +528,12 @@ impl_node_port_enum_params(struct spa_node *node, break; case SPA_PARAM_Format: - if ((res = port_get_format(node, direction, port_id, index, filter, ¶m, &b)) <= 0) - return res; + if (!this->have_format) + return -EIO; + if (*index > 0) + return 0; + + param = spa_format_video_raw_build(builder, id, &this->current_format.info.raw); break; case SPA_PARAM_Buffers: diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c index 1de770af2..9b308a355 100644 --- a/spa/plugins/volume/volume.c +++ b/spa/plugins/volume/volume.c @@ -344,34 +344,6 @@ static int port_enum_formats(struct spa_node *node, return 1; } -static int port_get_format(struct spa_node *node, - enum spa_direction direction, uint32_t port_id, - uint32_t *index, - const struct spa_pod *filter, - struct spa_pod **param, - struct spa_pod_builder *builder) -{ - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct port *port; - - port = GET_PORT(this, direction, port_id); - - if (!port->have_format) - return -EIO; - if (*index > 0) - return 0; - - *param = spa_pod_builder_object(builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_Format, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", this->current_format.info.raw.format, - ":", SPA_FORMAT_AUDIO_rate, "i", this->current_format.info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "i", this->current_format.info.raw.channels); - - return 1; -} - static int impl_node_port_enum_params(struct spa_node *node, enum spa_direction direction, uint32_t port_id, @@ -420,10 +392,16 @@ impl_node_port_enum_params(struct spa_node *node, if ((res = port_enum_formats(node, direction, port_id, index, filter, ¶m, &b)) <= 0) return res; break; + case SPA_PARAM_Format: - if ((res = port_get_format(node, direction, port_id, index, filter, ¶m, &b)) <= 0) - return res; + if (!port->have_format) + return -EIO; + if (*index > 0) + return 0; + + param = spa_format_audio_raw_build(&b, id, &this->current_format.info.raw); break; + case SPA_PARAM_Buffers: if (!port->have_format) return -EIO; diff --git a/spa/tests/test-control.c b/spa/tests/test-control.c index 9b84a342a..3ce502c1c 100644 --- a/spa/tests/test-control.c +++ b/spa/tests/test-control.c @@ -379,14 +379,12 @@ static int negotiate_formats(struct data *data) uint8_t buffer[4096]; spa_pod_builder_init(&b, buffer, sizeof(buffer)); - filter = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_Format, 0, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "i", 44100, - ":", SPA_FORMAT_AUDIO_channels, "i", 2); + filter = spa_format_audio_raw_build(&b, 0, + &SPA_AUDIO_INFO_RAW_INIT( + .format = SPA_AUDIO_FORMAT_S16, + .layout = SPA_AUDIO_LAYOUT_INTERLEAVED, + .rate = 44100, + .channels = 2 )); spa_debug_pod(0, spa_debug_types, filter); diff --git a/spa/tests/test-convert.c b/spa/tests/test-convert.c index 25ceb262e..52e2f39c1 100644 --- a/spa/tests/test-convert.c +++ b/spa/tests/test-convert.c @@ -206,14 +206,13 @@ static int negotiate_formats(struct data *data) uint8_t buffer[4096]; spa_pod_builder_init(&b, buffer, sizeof(buffer)); - format = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_Format, 0, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "i", 44100, - ":", SPA_FORMAT_AUDIO_channels, "i", 2); + + format = spa_format_audio_raw_build(&b, 0, + &SPA_AUDIO_INFO_RAW_INIT( + .format = SPA_AUDIO_FORMAT_S16, + .layout = SPA_AUDIO_LAYOUT_INTERLEAVED, + .rate = 44100, + .channels = 2 )); if ((res = spa_node_port_set_param(data->conv, SPA_DIRECTION_INPUT, 0, @@ -235,15 +234,12 @@ static int negotiate_formats(struct data *data) spa_pod_builder_init(&b, buffer, sizeof(buffer)); - format = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_Format, 0, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_NON_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "i", 44100, - ":", SPA_FORMAT_AUDIO_channels, "i", 2); - + format = spa_format_audio_raw_build(&b, 0, + &SPA_AUDIO_INFO_RAW_INIT( + .format = SPA_AUDIO_FORMAT_F32, + .layout = SPA_AUDIO_LAYOUT_NON_INTERLEAVED, + .rate = 44100, + .channels = 2 )); if ((res = spa_node_port_set_param(data->conv, SPA_DIRECTION_OUTPUT, 0, diff --git a/spa/tests/test-convert2.c b/spa/tests/test-convert2.c index 24ff636b8..3d07c2cee 100644 --- a/spa/tests/test-convert2.c +++ b/spa/tests/test-convert2.c @@ -257,27 +257,23 @@ static int negotiate_formats(struct data *data) uint8_t buffer[4096]; spa_pod_builder_init(&b, buffer, sizeof(buffer)); - format = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_Format, 0, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "i", 44100, - ":", SPA_FORMAT_AUDIO_channels, "i", 2); + format = spa_format_audio_raw_build(&b, 0, + &SPA_AUDIO_INFO_RAW_INIT( + .format = SPA_AUDIO_FORMAT_S16, + .layout = SPA_AUDIO_LAYOUT_INTERLEAVED, + .rate = 44100, + .channels = 2 )); if ((res = negotiate_link_format(data, &data->links[0], format)) < 0) return res; spa_pod_builder_init(&b, buffer, sizeof(buffer)); - format = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_Format, 0, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_NON_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "i", 48000, - ":", SPA_FORMAT_AUDIO_channels, "i", 1); + format = spa_format_audio_raw_build(&b, 0, + &SPA_AUDIO_INFO_RAW_INIT( + .format = SPA_AUDIO_FORMAT_S16, + .layout = SPA_AUDIO_LAYOUT_NON_INTERLEAVED, + .rate = 48000, + .channels = 1 )); if ((res = negotiate_link_format(data, &data->links[4], format)) < 0) return res; diff --git a/spa/tests/test-graph.c b/spa/tests/test-graph.c index d89e12de8..4ddd72e3a 100644 --- a/spa/tests/test-graph.c +++ b/spa/tests/test-graph.c @@ -346,14 +346,12 @@ static int negotiate_formats(struct data *data) uint8_t buffer[4096]; spa_pod_builder_init(&b, buffer, sizeof(buffer)); - filter = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_Format, 0, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "i", 44100, - ":", SPA_FORMAT_AUDIO_channels, "i", 2); + filter = spa_format_audio_raw_build(&b, 0, + &SPA_AUDIO_INFO_RAW_INIT( + .format = SPA_AUDIO_FORMAT_S16, + .layout = SPA_AUDIO_LAYOUT_INTERLEAVED, + .rate = 44100, + .channels = 2 )); spa_debug_pod(0, spa_debug_types, filter); diff --git a/spa/tests/test-mixer.c b/spa/tests/test-mixer.c index d2dc53a5c..3efe8af75 100644 --- a/spa/tests/test-mixer.c +++ b/spa/tests/test-mixer.c @@ -472,14 +472,12 @@ static int negotiate_formats(struct data *data) uint8_t buffer[2048]; spa_pod_builder_init(&b, buffer, sizeof(buffer)); - filter = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_Format, 0, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "i", 44100, - ":", SPA_FORMAT_AUDIO_channels, "i", 2); + filter = spa_format_audio_raw_build(&b, 0, + &SPA_AUDIO_INFO_RAW_INIT( + .format = SPA_AUDIO_FORMAT_S16, + .layout = SPA_AUDIO_LAYOUT_INTERLEAVED, + .rate = 44100, + .channels = 2 )); if ((res = spa_node_port_enum_params(data->sink, diff --git a/spa/tests/test-ringbuffer.c b/spa/tests/test-ringbuffer.c index 1dbc88c81..aa7bf3b42 100644 --- a/spa/tests/test-ringbuffer.c +++ b/spa/tests/test-ringbuffer.c @@ -270,14 +270,12 @@ static int negotiate_formats(struct data *data) spa_pod_builder_init(&b, buffer, sizeof(buffer)); - filter = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_Format, 0, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_rate, "i", 44100, - ":", SPA_FORMAT_AUDIO_channels, "i", 2); + filter = spa_format_audio_raw_build(&b, 0, + &SPA_AUDIO_INFO_RAW_INIT( + .format = SPA_AUDIO_FORMAT_S16, + .layout = SPA_AUDIO_LAYOUT_INTERLEAVED, + .rate = 44100, + .channels = 2 )); if ((res = spa_node_port_enum_params(data->sink, SPA_DIRECTION_INPUT, 0, diff --git a/spa/tests/test-v4l2.c b/spa/tests/test-v4l2.c index f5f5084b3..83cf4aba5 100644 --- a/spa/tests/test-v4l2.c +++ b/spa/tests/test-v4l2.c @@ -387,13 +387,11 @@ static int negotiate_formats(struct data *data) &data->source_output[0], sizeof(data->source_output[0]))) < 0) return res; - format = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_Format, 0, - "I", SPA_MEDIA_TYPE_video, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_VIDEO_format, "I", SPA_VIDEO_FORMAT_YUY2, - ":", SPA_FORMAT_VIDEO_size, "R", &SPA_RECTANGLE(320, 240), - ":", SPA_FORMAT_VIDEO_framerate, "F", &SPA_FRACTION(25,1)); + format = spa_format_video_raw_build(&b, 0, + &SPA_VIDEO_INFO_RAW_INIT( + .format = SPA_VIDEO_FORMAT_YUY2, + .size = SPA_RECTANGLE(320, 240), + .framerate = SPA_FRACTION(25,1))); if ((res = spa_node_port_set_param(data->source, SPA_DIRECTION_OUTPUT, 0, diff --git a/src/examples/audio-src.c b/src/examples/audio-src.c index 1d8a62713..741627a00 100644 --- a/src/examples/audio-src.c +++ b/src/examples/audio-src.c @@ -112,14 +112,12 @@ int main(int argc, char *argv[]) data.remote = pw_stream_get_remote(data.stream); - params[0] = spa_pod_builder_object(&b, - SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32, - ":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", SPA_FORMAT_AUDIO_channels, "i", DEFAULT_CHANNELS, - ":", SPA_FORMAT_AUDIO_rate, "i", DEFAULT_RATE); + params[0] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, + &SPA_AUDIO_INFO_RAW_INIT( + .format = SPA_AUDIO_FORMAT_F32, + .layout = SPA_AUDIO_LAYOUT_INTERLEAVED, + .channels = DEFAULT_CHANNELS, + .rate = DEFAULT_RATE )); pw_stream_connect(data.stream, PW_DIRECTION_OUTPUT, diff --git a/src/examples/export-sink.c b/src/examples/export-sink.c index 53c678d6d..d7a186e89 100644 --- a/src/examples/export-sink.c +++ b/src/examples/export-sink.c @@ -205,31 +205,6 @@ static int port_enum_formats(struct spa_node *node, return 1; } -static int port_get_format(struct spa_node *node, - enum spa_direction direction, uint32_t port_id, - uint32_t *index, - const struct spa_pod *filter, - struct spa_pod **result, - struct spa_pod_builder *builder) -{ - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); - - if (*index != 0 || d->format.format == 0) - return 0; - - *result = spa_pod_builder_object(builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_Format, - "I", SPA_MEDIA_TYPE_video, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_VIDEO_format, "I", d->format.format, - ":", SPA_FORMAT_VIDEO_size, "R", &d->format.size, - ":", SPA_FORMAT_VIDEO_framerate, "F", &d->format.framerate); - - (*index)++; - - return 1; -} - static int impl_port_enum_params(struct spa_node *node, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t *index, @@ -261,7 +236,10 @@ static int impl_port_enum_params(struct spa_node *node, return port_enum_formats(node, direction, port_id, index, filter, result, builder); case SPA_PARAM_Format: - return port_get_format(node, direction, port_id, index, filter, result, builder); + if (*index != 0 || d->format.format == 0) + return 0; + param = spa_format_video_raw_build(builder, id, &d->format); + break; case SPA_PARAM_Buffers: if (*index != 0) diff --git a/src/examples/export-source.c b/src/examples/export-source.c index 3322a1b9a..564f4285e 100644 --- a/src/examples/export-source.c +++ b/src/examples/export-source.c @@ -200,35 +200,6 @@ static int port_enum_formats(struct spa_node *node, return 1; } -static int port_get_format(struct spa_node *node, - enum spa_direction direction, uint32_t port_id, - uint32_t *index, - const struct spa_pod *filter, - struct spa_pod **param, - struct spa_pod_builder *builder) -{ - struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); - - if (*index != 0) - return 0; - - if (d->format.format == 0) - return 0; - - *param = spa_pod_builder_object(builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_Format, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", d->format.format, - ":", SPA_FORMAT_AUDIO_layout, "I", d->format.layout, - ":", SPA_FORMAT_AUDIO_channels, "i", d->format.channels, - ":", SPA_FORMAT_AUDIO_rate, "i", d->format.rate); - - (*index)++; - - return 1; -} - static int impl_port_enum_params(struct spa_node *node, enum spa_direction direction, uint32_t port_id, uint32_t id, uint32_t *index, @@ -236,6 +207,7 @@ static int impl_port_enum_params(struct spa_node *node, struct spa_pod **result, struct spa_pod_builder *builder) { + struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node); struct spa_pod *param; switch (id) { @@ -259,7 +231,12 @@ static int impl_port_enum_params(struct spa_node *node, return port_enum_formats(node, direction, port_id, index, filter, result, builder); case SPA_PARAM_Format: - return port_get_format(node, direction, port_id, index, filter, result, builder); + if (*index != 0) + return 0; + if (d->format.format == 0) + return 0; + param = spa_format_audio_raw_build(builder, id, &d->format); + break; case SPA_PARAM_Buffers: if (*index > 0) @@ -275,6 +252,7 @@ static int impl_port_enum_params(struct spa_node *node, ":", SPA_PARAM_BUFFERS_stride, "i", 0, ":", SPA_PARAM_BUFFERS_align, "i", 16); break; + case SPA_PARAM_Meta: switch (*index) { case 0: diff --git a/src/modules/module-media-session/floatmix.c b/src/modules/module-media-session/floatmix.c index 54d13917d..bf9062576 100644 --- a/src/modules/module-media-session/floatmix.c +++ b/src/modules/module-media-session/floatmix.c @@ -324,14 +324,8 @@ static int port_enum_formats(struct spa_node *node, switch (*index) { case 0: if (this->have_format) { - *param = spa_pod_builder_object(builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", this->format.info.raw.format, - ":", SPA_FORMAT_AUDIO_layout, "I", this->format.info.raw.layout, - ":", SPA_FORMAT_AUDIO_rate, "i", this->format.info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "i", this->format.info.raw.channels); + *param = spa_format_audio_raw_build(builder, SPA_PARAM_EnumFormat, + &this->format.info.raw); } else { *param = spa_pod_builder_object(builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, @@ -350,32 +344,6 @@ static int port_enum_formats(struct spa_node *node, return 1; } -static int port_get_format(struct spa_node *node, - enum spa_direction direction, uint32_t port_id, - uint32_t *index, - struct spa_pod **param, - struct spa_pod_builder *builder) -{ - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct port *port = GET_PORT(this, direction, port_id); - - if (!port->have_format) - return -EIO; - if (*index > 0) - return 0; - - *param = spa_pod_builder_object(builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_Format, - "I", SPA_MEDIA_TYPE_audio, - "I", SPA_MEDIA_SUBTYPE_raw, - ":", SPA_FORMAT_AUDIO_format, "I", this->format.info.raw.format, - ":", SPA_FORMAT_AUDIO_layout, "I", this->format.info.raw.layout, - ":", SPA_FORMAT_AUDIO_rate, "i", this->format.info.raw.rate, - ":", SPA_FORMAT_AUDIO_channels, "i", this->format.info.raw.channels); - - return 1; -} - static int impl_node_port_enum_params(struct spa_node *node, enum spa_direction direction, uint32_t port_id, @@ -426,9 +394,14 @@ impl_node_port_enum_params(struct spa_node *node, break; case SPA_PARAM_Format: - if ((res = port_get_format(node, direction, port_id, index, ¶m, &b)) <= 0) - return res; + if (!port->have_format) + return -EIO; + if (*index > 0) + return 0; + + param = spa_format_audio_raw_build(builder, id, &this->format.info.raw); break; + case SPA_PARAM_Buffers: if (!port->have_format) return -EIO;