diff --git a/spa/include/spa/param/audio/format-utils.h b/spa/include/spa/param/audio/format-utils.h index 6ee8f9335..55ccec329 100644 --- a/spa/include/spa/param/audio/format-utils.h +++ b/spa/include/spa/param/audio/format-utils.h @@ -47,9 +47,9 @@ spa_format_audio_raw_parse(const struct spa_pod *format, struct spa_audio_info_r info->flags = 0; res = spa_pod_parse_object(format, SPA_TYPE_OBJECT_Format, NULL, - SPA_FORMAT_AUDIO_format, SPA_POD_Id(&info->format), - SPA_FORMAT_AUDIO_rate, SPA_POD_Int(&info->rate), - SPA_FORMAT_AUDIO_channels, SPA_POD_Int(&info->channels), + SPA_FORMAT_AUDIO_format, SPA_POD_OPT_Id(&info->format), + SPA_FORMAT_AUDIO_rate, SPA_POD_OPT_Int(&info->rate), + SPA_FORMAT_AUDIO_channels, SPA_POD_OPT_Int(&info->channels), SPA_FORMAT_AUDIO_position, SPA_POD_OPT_Pod(&position)); if (position == NULL || !spa_pod_copy_array(position, SPA_TYPE_Id, info->position, SPA_AUDIO_MAX_CHANNELS)) @@ -64,7 +64,7 @@ spa_format_audio_dsp_parse(const struct spa_pod *format, struct spa_audio_info_d int res; res = spa_pod_parse_object(format, SPA_TYPE_OBJECT_Format, NULL, - SPA_FORMAT_AUDIO_format, SPA_POD_Id(&info->format)); + SPA_FORMAT_AUDIO_format, SPA_POD_OPT_Id(&info->format)); return res; } @@ -74,8 +74,8 @@ spa_format_audio_iec958_parse(const struct spa_pod *format, struct spa_audio_inf int res; res = spa_pod_parse_object(format, SPA_TYPE_OBJECT_Format, NULL, - SPA_FORMAT_AUDIO_iec958Codec, SPA_POD_Id(&info->codec), - SPA_FORMAT_AUDIO_rate, SPA_POD_Int(&info->rate)); + SPA_FORMAT_AUDIO_iec958Codec, SPA_POD_OPT_Id(&info->codec), + SPA_FORMAT_AUDIO_rate, SPA_POD_OPT_Int(&info->rate)); return res; } @@ -87,10 +87,10 @@ spa_format_audio_dsd_parse(const struct spa_pod *format, struct spa_audio_info_d info->flags = 0; res = spa_pod_parse_object(format, SPA_TYPE_OBJECT_Format, NULL, - SPA_FORMAT_AUDIO_bitorder, SPA_POD_Id(&info->bitorder), - SPA_FORMAT_AUDIO_interleave, SPA_POD_Int(&info->interleave), - SPA_FORMAT_AUDIO_rate, SPA_POD_Int(&info->rate), - SPA_FORMAT_AUDIO_channels, SPA_POD_Int(&info->channels), + SPA_FORMAT_AUDIO_bitorder, SPA_POD_OPT_Id(&info->bitorder), + SPA_FORMAT_AUDIO_interleave, SPA_POD_OPT_Int(&info->interleave), + SPA_FORMAT_AUDIO_rate, SPA_POD_OPT_Int(&info->rate), + SPA_FORMAT_AUDIO_channels, SPA_POD_OPT_Int(&info->channels), SPA_FORMAT_AUDIO_position, SPA_POD_OPT_Pod(&position)); if (position == NULL || !spa_pod_copy_array(position, SPA_TYPE_Id, info->position, SPA_AUDIO_MAX_CHANNELS)) diff --git a/spa/include/spa/param/video/format-utils.h b/spa/include/spa/param/video/format-utils.h index 9abf67021..339e7e523 100644 --- a/spa/include/spa/param/video/format-utils.h +++ b/spa/include/spa/param/video/format-utils.h @@ -44,10 +44,10 @@ spa_format_video_raw_parse(const struct spa_pod *format, { return spa_pod_parse_object(format, SPA_TYPE_OBJECT_Format, NULL, - SPA_FORMAT_VIDEO_format, SPA_POD_Id(&info->format), + SPA_FORMAT_VIDEO_format, SPA_POD_OPT_Id(&info->format), SPA_FORMAT_VIDEO_modifier, SPA_POD_OPT_Long(&info->modifier), - SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle(&info->size), - SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&info->framerate), + SPA_FORMAT_VIDEO_size, SPA_POD_OPT_Rectangle(&info->size), + SPA_FORMAT_VIDEO_framerate, SPA_POD_OPT_Fraction(&info->framerate), SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_OPT_Fraction(&info->max_framerate), SPA_FORMAT_VIDEO_views, SPA_POD_OPT_Int(&info->views), SPA_FORMAT_VIDEO_interlaceMode, SPA_POD_OPT_Id(&info->interlace_mode), @@ -67,7 +67,7 @@ spa_format_video_dsp_parse(const struct spa_pod *format, { return spa_pod_parse_object(format, SPA_TYPE_OBJECT_Format, NULL, - SPA_FORMAT_VIDEO_format, SPA_POD_Id(&info->format), + SPA_FORMAT_VIDEO_format, SPA_POD_OPT_Id(&info->format), SPA_FORMAT_VIDEO_modifier, SPA_POD_OPT_Long(&info->modifier)); } diff --git a/spa/plugins/audioconvert/audioadapter.c b/spa/plugins/audioconvert/audioadapter.c index ea0343598..99ba4c770 100644 --- a/spa/plugins/audioconvert/audioadapter.c +++ b/spa/plugins/audioconvert/audioadapter.c @@ -556,30 +556,6 @@ static int reconfigure_mode(struct impl *this, bool passthrough, return 0; } -static int format_audio_raw_parse_opt(const struct spa_pod *format, struct spa_audio_info_raw *info) -{ - struct spa_pod *position = NULL; - uint32_t media_type, media_subtype; - int res; - if ((res = spa_format_parse(format, &media_type, &media_subtype)) < 0) - return res; - if (media_type != SPA_MEDIA_TYPE_audio || - media_subtype != SPA_MEDIA_SUBTYPE_raw) - return -ENOTSUP; - - spa_zero(*info); - res = spa_pod_parse_object(format, - SPA_TYPE_OBJECT_Format, NULL, - SPA_FORMAT_AUDIO_format, SPA_POD_OPT_Id(&info->format), - SPA_FORMAT_AUDIO_channels, SPA_POD_OPT_Int(&info->channels), - SPA_FORMAT_AUDIO_position, SPA_POD_OPT_Pod(&position)); - if (position == NULL || - !spa_pod_copy_array(position, SPA_TYPE_Id, info->position, SPA_AUDIO_MAX_CHANNELS)) - SPA_FLAG_SET(info->flags, SPA_AUDIO_FLAG_UNPOSITIONED); - - return res; -} - static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { @@ -631,8 +607,18 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, if (format) { struct spa_audio_info info; - if (format_audio_raw_parse_opt(format, &info.info.raw) >= 0) + + spa_zero(info); + if ((res = spa_format_parse(format, &info.media_type, &info.media_subtype)) < 0) + return res; + if (info.media_type != SPA_MEDIA_TYPE_audio || + info.media_subtype != SPA_MEDIA_SUBTYPE_raw) + return -ENOTSUP; + + if (spa_format_audio_raw_parse(format, &info.info.raw) >= 0) { + info.info.raw.rate = 0; this->default_format = info; + } } switch (mode) { diff --git a/spa/plugins/videoconvert/videoadapter.c b/spa/plugins/videoconvert/videoadapter.c index 5b7bae51b..0a2a1422b 100644 --- a/spa/plugins/videoconvert/videoadapter.c +++ b/spa/plugins/videoconvert/videoadapter.c @@ -562,24 +562,6 @@ static int reconfigure_mode(struct impl *this, bool passthrough, return 0; } -static int format_video_raw_parse_opt(const struct spa_pod *format, struct spa_video_info_raw *info) -{ - uint32_t media_type, media_subtype; - int res; - if ((res = spa_format_parse(format, &media_type, &media_subtype)) < 0) - return res; - if (media_type != SPA_MEDIA_TYPE_video || - media_subtype != SPA_MEDIA_SUBTYPE_raw) - return -ENOTSUP; - - spa_zero(*info); - res = spa_pod_parse_object(format, - SPA_TYPE_OBJECT_Format, NULL, - SPA_FORMAT_VIDEO_format, SPA_POD_OPT_Id(&info->format), - SPA_FORMAT_VIDEO_size, SPA_POD_OPT_Int(&info->size)); - return res; -} - static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) { @@ -628,7 +610,15 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, if (format) { struct spa_video_info info; - if (format_video_raw_parse_opt(format, &info.info.raw) >= 0) + + spa_zero(info); + if ((res = spa_format_parse(format, &info.media_type, &info.media_subtype)) < 0) + return res; + if (info.media_type != SPA_MEDIA_TYPE_video || + info.media_subtype != SPA_MEDIA_SUBTYPE_raw) + return -ENOTSUP; + + if (spa_format_video_raw_parse(format, &info.info.raw) >= 0) this->default_format = info; } diff --git a/src/modules/module-protocol-pulse/format.c b/src/modules/module-protocol-pulse/format.c index 2de01054c..a3e7a22fd 100644 --- a/src/modules/module-protocol-pulse/format.c +++ b/src/modules/module-protocol-pulse/format.c @@ -417,25 +417,6 @@ static enum encoding format_encoding_from_id(uint32_t id) return ENCODING_ANY; } -static inline int -audio_raw_parse_opt(const struct spa_pod *format, struct spa_audio_info_raw *info) -{ - struct spa_pod *position = NULL; - int res; - info->flags = 0; - res = spa_pod_parse_object(format, - SPA_TYPE_OBJECT_Format, NULL, - SPA_FORMAT_AUDIO_format, SPA_POD_OPT_Id(&info->format), - SPA_FORMAT_AUDIO_rate, SPA_POD_OPT_Int(&info->rate), - SPA_FORMAT_AUDIO_channels, SPA_POD_OPT_Int(&info->channels), - SPA_FORMAT_AUDIO_position, SPA_POD_OPT_Pod(&position)); - if (position == NULL || - !spa_pod_copy_array(position, SPA_TYPE_Id, info->position, SPA_AUDIO_MAX_CHANNELS)) - SPA_FLAG_SET(info->flags, SPA_AUDIO_FLAG_UNPOSITIONED); - - return res; -} - int format_parse_param(const struct spa_pod *param, bool collect, struct sample_spec *ss, struct channel_map *map, const struct sample_spec *def_ss, const struct channel_map *def_map) @@ -451,14 +432,17 @@ int format_parse_param(const struct spa_pod *param, bool collect, switch (info.media_subtype) { case SPA_MEDIA_SUBTYPE_raw: + if (spa_format_audio_raw_parse(param, &info.info.raw) < 0) + return -ENOTSUP; if (def_ss != NULL) { if (ss != NULL) *ss = *def_ss; - if (audio_raw_parse_opt(param, &info.info.raw) < 0) - return -ENOTSUP; } else { - if (spa_format_audio_raw_parse(param, &info.info.raw) < 0) - return -ENOTSUP; + if (info.info.raw.format == 0 || + info.info.raw.rate == 0 || + info.info.raw.channels == 0 || + info.info.raw.channels > SPA_AUDIO_MAX_CHANNELS) + return -ENOTSUP; } break; case SPA_MEDIA_SUBTYPE_iec958: