Skip to content

Commit

Permalink
upipe_avfilter: add mgr helpers for stringification
Browse files Browse the repository at this point in the history
  • Loading branch information
nto authored and cmassiot committed Feb 13, 2025
1 parent 2037b7b commit a0ff584
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
50 changes: 49 additions & 1 deletion include/upipe-av/upipe_avfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
37 changes: 37 additions & 0 deletions lib/upipe-av/upipe_avfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a0ff584

Please sign in to comment.