From a0ff5846ec3afd3b12df12f609b077afcdbce3d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vasseur?= Date: Thu, 10 Oct 2024 19:18:11 +0200 Subject: [PATCH] upipe_avfilter: add mgr helpers for stringification --- include/upipe-av/upipe_avfilter.h | 50 ++++++++++++++++++++++++++++++- lib/upipe-av/upipe_avfilter.c | 37 +++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/include/upipe-av/upipe_avfilter.h b/include/upipe-av/upipe_avfilter.h index 1e3a92bfd..8cad3fd4b 100644 --- a/include/upipe-av/upipe_avfilter.h +++ b/include/upipe-av/upipe_avfilter.h @@ -106,7 +106,13 @@ enum upipe_avfilt_mgr_command { UPIPE_AVFILT_MGR_SENTINEL = UPIPE_MGR_CONTROL_LOCAL, /** gets the pixel format name from flow def (struct uref *, const char **, bool) */ - UPIPE_AVFILT_MGR_GET_PIXFMT_NAME + UPIPE_AVFILT_MGR_GET_PIXFMT_NAME, + /** gets the color primaries name (int, const char **) */ + UPIPE_AVFILT_MGR_GET_COLOR_PRIMARIES_NAME, + /** gets the color transfer characteristics name (int, const char **) */ + UPIPE_AVFILT_MGR_GET_COLOR_TRANSFER_NAME, + /** gets the color space name (int, const char **) */ + UPIPE_AVFILT_MGR_GET_COLOR_SPACE_NAME, }; /** @This returns the pixel format name for the given flow definition. @@ -125,6 +131,48 @@ static inline int upipe_avfilt_mgr_get_pixfmt_name(struct upipe_mgr *mgr, UPIPE_AVFILT_SIGNATURE, flow_def, name, software); } +/** @This returns the color primaries name for the given value. + * + * @param mgr pointer to manager + * @param color_primaries color primaries value + * @param name color primaries name + * @return an error code + */ +static inline int upipe_avfilt_mgr_get_color_primaries_name( + struct upipe_mgr *mgr, int color_primaries, const char **name) +{ + return upipe_mgr_control(mgr, UPIPE_AVFILT_MGR_GET_COLOR_PRIMARIES_NAME, + UPIPE_AVFILT_SIGNATURE, color_primaries, name); +} + +/** @This returns the color transfer name for the given value. + * + * @param mgr pointer to manager + * @param color_transfer color transfer characteristics value + * @param name color transfer characteristics name + * @return an error code + */ +static inline int upipe_avfilt_mgr_get_color_transfer_name( + struct upipe_mgr *mgr, int color_transfer, const char **name) +{ + return upipe_mgr_control(mgr, UPIPE_AVFILT_MGR_GET_COLOR_TRANSFER_NAME, + UPIPE_AVFILT_SIGNATURE, color_transfer, name); +} + +/** @This returns the color space name for the given value. + * + * @param mgr pointer to manager + * @param color_space color space value + * @param name color space name + * @return an error code + */ +static inline int upipe_avfilt_mgr_get_color_space_name( + struct upipe_mgr *mgr, int color_space, const char **name) +{ + return upipe_mgr_control(mgr, UPIPE_AVFILT_MGR_GET_COLOR_SPACE_NAME, + UPIPE_AVFILT_SIGNATURE, color_space, name); +} + #ifdef __cplusplus } #endif diff --git a/lib/upipe-av/upipe_avfilter.c b/lib/upipe-av/upipe_avfilter.c index 80ec7a64c..af72b9442 100644 --- a/lib/upipe-av/upipe_avfilter.c +++ b/lib/upipe-av/upipe_avfilter.c @@ -2609,6 +2609,43 @@ static int upipe_avfilt_mgr_control(struct upipe_mgr *mgr, bool software = va_arg(args, int); return _upipe_avfilt_mgr_get_pixfmt_name(flow_def, name_p, software); + + case UPIPE_AVFILT_MGR_GET_COLOR_PRIMARIES_NAME: { + UBASE_SIGNATURE_CHECK(args, UPIPE_AVFILT_SIGNATURE) + int color_primaries = va_arg(args, int); + const char **name_p = va_arg(args, const char **); + const char *name = av_color_primaries_name(color_primaries); + if (!name) + return UBASE_ERR_INVALID; + if (name_p) + *name_p = name; + return UBASE_ERR_NONE; + } + + case UPIPE_AVFILT_MGR_GET_COLOR_TRANSFER_NAME: { + UBASE_SIGNATURE_CHECK(args, UPIPE_AVFILT_SIGNATURE) + int color_transfer = va_arg(args, int); + const char **name_p = va_arg(args, const char **); + const char *name = av_color_transfer_name(color_transfer); + if (!name) + return UBASE_ERR_INVALID; + if (name_p) + *name_p = name; + return UBASE_ERR_NONE; + } + + case UPIPE_AVFILT_MGR_GET_COLOR_SPACE_NAME: { + UBASE_SIGNATURE_CHECK(args, UPIPE_AVFILT_SIGNATURE) + int color_space = va_arg(args, int); + const char **name_p = va_arg(args, const char **); + const char *name = av_color_space_name(color_space); + if (!name) + return UBASE_ERR_INVALID; + if (name_p) + *name_p = name; + return UBASE_ERR_NONE; + } + default: return UBASE_ERR_UNHANDLED; }