From 0c4468dc185fa8b9e7d6add914595c5e928b24fd Mon Sep 17 00:00:00 2001 From: Vittorio Giovara Date: Thu, 21 Apr 2016 17:24:07 -0400 Subject: stereo3d: Add API to get name from value or value from name Use it in av_dump_format() instead of a huge switch case. --- libavutil/stereo3d.c | 33 +++++++++++++++++++++++++++++++++ libavutil/stereo3d.h | 18 ++++++++++++++++++ libavutil/version.h | 2 +- 3 files changed, 52 insertions(+), 1 deletion(-) (limited to 'libavutil') diff --git a/libavutil/stereo3d.c b/libavutil/stereo3d.c index 2dcfddf14b..0d72609cd0 100644 --- a/libavutil/stereo3d.c +++ b/libavutil/stereo3d.c @@ -21,6 +21,7 @@ #include #include +#include "common.h" #include "mem.h" #include "stereo3d.h" @@ -41,3 +42,35 @@ AVStereo3D *av_stereo3d_create_side_data(AVFrame *frame) return (AVStereo3D *)side_data->data; } + +static const char *stereo3d_type_names[] = { + [AV_STEREO3D_2D] = "2D", + [AV_STEREO3D_SIDEBYSIDE] = "side by side", + [AV_STEREO3D_TOPBOTTOM] = "top and bottom", + [AV_STEREO3D_FRAMESEQUENCE] = "frame alternate", + [AV_STEREO3D_CHECKERBOARD] = "checkerboard", + [AV_STEREO3D_SIDEBYSIDE_QUINCUNX] = "side by side (quincunx subsampling)", + [AV_STEREO3D_LINES] = "interleaved lines", + [AV_STEREO3D_COLUMNS] = "interleaved columns", +}; + +const char *av_stereo3d_type_name(unsigned int type) +{ + if (type >= FF_ARRAY_ELEMS(stereo3d_type_names)) + return "unknown"; + + return stereo3d_type_names[type]; +} + +int av_stereo3d_from_name(const char *name) +{ + int i; + + for (i = 0; i < FF_ARRAY_ELEMS(stereo3d_type_names); i++) { + size_t len = strlen(stereo3d_type_names[i]); + if (!strncmp(stereo3d_type_names[i], name, len)) + return i; + } + + return -1; +} diff --git a/libavutil/stereo3d.h b/libavutil/stereo3d.h index b1910b1f87..aea1b7052b 100644 --- a/libavutil/stereo3d.h +++ b/libavutil/stereo3d.h @@ -149,4 +149,22 @@ AVStereo3D *av_stereo3d_alloc(void); */ AVStereo3D *av_stereo3d_create_side_data(AVFrame *frame); +/** + * Provide a human-readable name of a given stereo3d type. + * + * @param type The input stereo3d type value. + * + * @return The name of the stereo3d value, or "unknown". + */ +const char *av_stereo3d_type_name(unsigned int type); + +/** + * Get the AVStereo3DType form a human-readable name. + * + * @param type The input string. + * + * @return The AVStereo3DType value, or -1 if not found. + */ +int av_stereo3d_from_name(const char *name); + #endif /* AVUTIL_STEREO3D_H */ diff --git a/libavutil/version.h b/libavutil/version.h index 7bbac410b7..4cee2b0ba1 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -54,7 +54,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 55 -#define LIBAVUTIL_VERSION_MINOR 11 +#define LIBAVUTIL_VERSION_MINOR 12 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ -- cgit v1.2.3