diff options
author | Wim Taymans <wtaymans@redhat.com> | 2018-08-29 15:53:26 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2018-08-29 15:53:26 +0200 |
commit | 514528f2c77103f28aa945b27c4ea91cff335976 (patch) | |
tree | 5cfef604fd205b3f4661e479f945690ac983d9f2 | |
parent | 80de83f38a43b51a990ea042eddb9b981813e41d (diff) |
format: make helper functions to create formats
Use helper functions to create a fully specified format.
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 65d3b142..08208cbe 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 15e796df..387bea93 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 <spa/pod/parser.h> +#include <spa/pod/builder.h> #include <spa/param/video/format.h> #include <spa/param/format-utils.h> @@ -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 7d3cc2f4..a6da6235 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 3b689a91..50419167 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 c124bb00..fb401913 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 266b306c..4f20ad13 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 6dc2fd13..e21644ec 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 5d4b0456..4730c602 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 d82989c3..bcbfd711 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 62137f0e..f59d7192 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, @@ -546,30 +547,6 @@ port_enum_formats(struct impl *this, } 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, uint32_t id, uint32_t *index, @@ -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 ecfcd5d3..b0ad5a9d 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 af6b6dd6..97f89298 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 1de770af..9b308a35 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 9b84a342..3ce502c1 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 25ceb262..52e2f39c 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 24ff636b..3d07c2ce 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 d89e12de..4ddd72e3 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 d2dc53a5..3efe8af7 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 1dbc88c8..aa7bf3b4 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 f5f5084b..83cf4aba 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 1d8a6271..741627a0 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 53c678d6..d7a186e8 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 3322a1b9..564f4285 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 54d13917..bf906257 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; |