This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: v4l2-info: move flag/type descriptions here
Author:  Hans Verkuil <hans.verk...@cisco.com>
Date:    Sun Feb 4 13:37:50 2018 +0100

Move all the flag and type descriptions to this source.
This makes it easy to reuse these functions by various utilities
and you don't have to change multiple utilities whenever a new
flag or type is added.

Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>

 utils/common/v4l2-info.cpp                  | 564 ++++++++++++++++++++++++++++
 utils/common/v4l2-info.h                    |  94 +++++
 utils/v4l2-compliance/v4l2-compliance.cpp   |  50 ---
 utils/v4l2-compliance/v4l2-compliance.h     |  10 +-
 utils/v4l2-compliance/v4l2-test-buffers.cpp |  51 +--
 utils/v4l2-compliance/v4l2-test-colors.cpp  |   2 +-
 utils/v4l2-ctl/v4l2-ctl-common.cpp          |  19 -
 utils/v4l2-ctl/v4l2-ctl-io.cpp              |  55 +--
 utils/v4l2-ctl/v4l2-ctl-overlay.cpp         |  46 ---
 utils/v4l2-ctl/v4l2-ctl-selection.cpp       |  16 +-
 utils/v4l2-ctl/v4l2-ctl-stds.cpp            |  55 +--
 utils/v4l2-ctl/v4l2-ctl-streaming.cpp       |  29 +-
 utils/v4l2-ctl/v4l2-ctl-subdev.cpp          |   8 +-
 utils/v4l2-ctl/v4l2-ctl.cpp                 | 357 +-----------------
 utils/v4l2-ctl/v4l2-ctl.h                   |  17 +-
 15 files changed, 686 insertions(+), 687 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=f40e8e8579d12f568ab50580d76ae5fd205dc298
diff --git a/utils/common/v4l2-info.cpp b/utils/common/v4l2-info.cpp
index 566ce1a06093..044b67782948 100644
--- a/utils/common/v4l2-info.cpp
+++ b/utils/common/v4l2-info.cpp
@@ -28,6 +28,38 @@
 
 #include <string>
 
+static std::string num2s(unsigned num)
+{
+       char buf[10];
+
+       sprintf(buf, "%08x", num);
+       return buf;
+}
+
+typedef struct {
+       unsigned flag;
+       const char *str;
+} flag_def;
+
+static std::string flags2s(unsigned val, const flag_def *def)
+{
+       std::string s;
+
+       while (def->flag) {
+               if (val & def->flag) {
+                       if (s.length()) s += ", ";
+                       s += def->str;
+                       val &= ~def->flag;
+               }
+               def++;
+       }
+       if (val) {
+               if (s.length()) s += ", ";
+               s += num2s(val);
+       }
+       return s;
+}
+
 static std::string cap2s(unsigned cap)
 {
        std::string s;
@@ -107,3 +139,535 @@ void v4l2_info_capability(const v4l2_capability &vcap)
                printf("%s", cap2s(vcap.device_caps).c_str());
        }
 }
+
+std::string fcc2s(__u32 val)
+{
+       std::string s;
+
+       s += val & 0x7f;
+       s += (val >> 8) & 0x7f;
+       s += (val >> 16) & 0x7f;
+       s += (val >> 24) & 0x7f;
+       if (val & (1 << 31))
+               s += "-BE";
+       return s;
+}
+
+std::string buftype2s(int type)
+{
+       switch (type) {
+       case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+               return "Video Capture";
+       case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
+               return "Video Capture Multiplanar";
+       case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+               return "Video Output";
+       case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
+               return "Video Output Multiplanar";
+       case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+               return "Video Overlay";
+       case V4L2_BUF_TYPE_VBI_CAPTURE:
+               return "VBI Capture";
+       case V4L2_BUF_TYPE_VBI_OUTPUT:
+               return "VBI Output";
+       case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
+               return "Sliced VBI Capture";
+       case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
+               return "Sliced VBI Output";
+       case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+               return "Video Output Overlay";
+       case V4L2_BUF_TYPE_SDR_CAPTURE:
+               return "SDR Capture";
+       case V4L2_BUF_TYPE_SDR_OUTPUT:
+               return "SDR Output";
+       case V4L2_BUF_TYPE_META_CAPTURE:
+               return "Metadata Capture";
+       case V4L2_BUF_TYPE_PRIVATE:
+               return "Private";
+       default:
+               return std::string("Unknown (") + num2s(type) + ")";
+       }
+}
+
+std::string field2s(int val)
+{
+       switch (val) {
+       case V4L2_FIELD_ANY:
+               return "Any";
+       case V4L2_FIELD_NONE:
+               return "None";
+       case V4L2_FIELD_TOP:
+               return "Top";
+       case V4L2_FIELD_BOTTOM:
+               return "Bottom";
+       case V4L2_FIELD_INTERLACED:
+               return "Interlaced";
+       case V4L2_FIELD_SEQ_TB:
+               return "Sequential Top-Bottom";
+       case V4L2_FIELD_SEQ_BT:
+               return "Sequential Bottom-Top";
+       case V4L2_FIELD_ALTERNATE:
+               return "Alternating";
+       case V4L2_FIELD_INTERLACED_TB:
+               return "Interlaced Top-Bottom";
+       case V4L2_FIELD_INTERLACED_BT:
+               return "Interlaced Bottom-Top";
+       default:
+               return "Unknown (" + num2s(val) + ")";
+       }
+}
+
+std::string colorspace2s(int val)
+{
+       switch (val) {
+       case V4L2_COLORSPACE_DEFAULT:
+               return "Default";
+       case V4L2_COLORSPACE_SMPTE170M:
+               return "SMPTE 170M";
+       case V4L2_COLORSPACE_SMPTE240M:
+               return "SMPTE 240M";
+       case V4L2_COLORSPACE_REC709:
+               return "Rec. 709";
+       case V4L2_COLORSPACE_BT878:
+               return "Broken Bt878";
+       case V4L2_COLORSPACE_470_SYSTEM_M:
+               return "470 System M";
+       case V4L2_COLORSPACE_470_SYSTEM_BG:
+               return "470 System BG";
+       case V4L2_COLORSPACE_JPEG:
+               return "JPEG";
+       case V4L2_COLORSPACE_SRGB:
+               return "sRGB";
+       case V4L2_COLORSPACE_ADOBERGB:
+               return "AdobeRGB";
+       case V4L2_COLORSPACE_DCI_P3:
+               return "DCI-P3";
+       case V4L2_COLORSPACE_BT2020:
+               return "BT.2020";
+       case V4L2_COLORSPACE_RAW:
+               return "Raw";
+       default:
+               return "Unknown (" + num2s(val) + ")";
+       }
+}
+
+std::string xfer_func2s(int val)
+{
+       switch (val) {
+       case V4L2_XFER_FUNC_DEFAULT:
+               return "Default";
+       case V4L2_XFER_FUNC_709:
+               return "Rec. 709";
+       case V4L2_XFER_FUNC_SRGB:
+               return "sRGB";
+       case V4L2_XFER_FUNC_ADOBERGB:
+               return "AdobeRGB";
+       case V4L2_XFER_FUNC_DCI_P3:
+               return "DCI-P3";
+       case V4L2_XFER_FUNC_SMPTE2084:
+               return "SMPTE 2084";
+       case V4L2_XFER_FUNC_SMPTE240M:
+               return "SMPTE 240M";
+       case V4L2_XFER_FUNC_NONE:
+               return "None";
+       default:
+               return "Unknown (" + num2s(val) + ")";
+       }
+}
+
+std::string ycbcr_enc2s(int val)
+{
+       switch (val) {
+       case V4L2_YCBCR_ENC_DEFAULT:
+               return "Default";
+       case V4L2_YCBCR_ENC_601:
+               return "ITU-R 601";
+       case V4L2_YCBCR_ENC_709:
+               return "Rec. 709";
+       case V4L2_YCBCR_ENC_XV601:
+               return "xvYCC 601";
+       case V4L2_YCBCR_ENC_XV709:
+               return "xvYCC 709";
+       case V4L2_YCBCR_ENC_BT2020:
+               return "BT.2020";
+       case V4L2_YCBCR_ENC_BT2020_CONST_LUM:
+               return "BT.2020 Constant Luminance";
+       case V4L2_YCBCR_ENC_SMPTE240M:
+               return "SMPTE 240M";
+       case V4L2_HSV_ENC_180:
+               return "HSV with Hue 0-179";
+       case V4L2_HSV_ENC_256:
+               return "HSV with Hue 0-255";
+       default:
+               return "Unknown (" + num2s(val) + ")";
+       }
+}
+
+std::string quantization2s(int val)
+{
+       switch (val) {
+       case V4L2_QUANTIZATION_DEFAULT:
+               return "Default";
+       case V4L2_QUANTIZATION_FULL_RANGE:
+               return "Full Range";
+       case V4L2_QUANTIZATION_LIM_RANGE:
+               return "Limited Range";
+       default:
+               return "Unknown (" + num2s(val) + ")";
+       }
+}
+
+static const flag_def pixflags_def[] = {
+       { V4L2_PIX_FMT_FLAG_PREMUL_ALPHA,  "premultiplied-alpha" },
+       { 0, NULL }
+};
+
+std::string pixflags2s(unsigned flags)
+{
+       return flags2s(flags, pixflags_def);
+}
+
+static const flag_def service_def[] = {
+       { V4L2_SLICED_TELETEXT_B,  "teletext" },
+       { V4L2_SLICED_VPS,         "vps" },
+       { V4L2_SLICED_CAPTION_525, "cc" },
+       { V4L2_SLICED_WSS_625,     "wss" },
+       { 0, NULL }
+};
+
+std::string service2s(unsigned service)
+{
+       return flags2s(service, service_def);
+}
+
+static const flag_def fmtdesc_def[] = {
+       { V4L2_FMT_FLAG_COMPRESSED, "compressed" },
+       { V4L2_FMT_FLAG_EMULATED, "emulated" },
+       { 0, NULL }
+};
+
+std::string fmtdesc2s(unsigned flags)
+{
+       return flags2s(flags, fmtdesc_def);
+}
+
+static const flag_def selection_targets_def[] = {
+       { V4L2_SEL_TGT_CROP_ACTIVE, "crop" },
+       { V4L2_SEL_TGT_CROP_DEFAULT, "crop_default" },
+       { V4L2_SEL_TGT_CROP_BOUNDS, "crop_bounds" },
+       { V4L2_SEL_TGT_COMPOSE_ACTIVE, "compose" },
+       { V4L2_SEL_TGT_COMPOSE_DEFAULT, "compose_default" },
+       { V4L2_SEL_TGT_COMPOSE_BOUNDS, "compose_bounds" },
+       { V4L2_SEL_TGT_COMPOSE_PADDED, "compose_padded" },
+       { V4L2_SEL_TGT_NATIVE_SIZE, "native_size" },
+       { 0, NULL }
+};
+
+bool valid_seltarget_at_idx(unsigned i)
+{
+       return i < sizeof(selection_targets_def) / 
sizeof(selection_targets_def[0]) - 1;
+}
+
+unsigned seltarget_at_idx(unsigned i)
+{
+       if (valid_seltarget_at_idx(i))
+               return selection_targets_def[i].flag;
+       return 0;
+}
+
+std::string seltarget2s(__u32 target)
+{
+       int i = 0;
+
+       while (selection_targets_def[i].str != NULL) {
+               if (selection_targets_def[i].flag == target)
+                       return selection_targets_def[i].str;
+               i++;
+       }
+       return std::string("Unknown (") + num2s(target) + ")";
+}
+
+const flag_def selection_flags_def[] = {
+       { V4L2_SEL_FLAG_GE, "ge" },
+       { V4L2_SEL_FLAG_LE, "le" },
+       { V4L2_SEL_FLAG_KEEP_CONFIG, "keep-config" },
+       { 0, NULL }
+};
+
+std::string selflags2s(__u32 flags)
+{
+       return flags2s(flags, selection_flags_def);
+}
+
+static const char *std_pal[] = {
+       "B", "B1", "G", "H", "I", "D", "D1", "K",
+       "M", "N", "Nc", "60",
+       NULL
+};
+static const char *std_ntsc[] = {
+       "M", "M-JP", "443", "M-KR",
+       NULL
+};
+static const char *std_secam[] = {
+       "B", "D", "G", "H", "K", "K1", "L", "Lc",
+       NULL
+};
+static const char *std_atsc[] = {
+       "8-VSB", "16-VSB",
+       NULL
+};
+
+static std::string partstd2s(const char *prefix, const char *stds[], unsigned 
long long std)
+{
+       std::string s = std::string(prefix) + "-";
+       int first = 1;
+
+       while (*stds) {
+               if (std & 1) {
+                       if (!first)
+                               s += "/";
+                       first = 0;
+                       s += *stds;
+               }
+               stds++;
+               std >>= 1;
+       }
+       return s;
+}
+
+std::string std2s(v4l2_std_id std, const char *sep)
+{
+       std::string s;
+
+       if (std & 0xfff) {
+               s += partstd2s("PAL", std_pal, std);
+       }
+       if (std & 0xf000) {
+               if (s.length()) s += sep;
+               s += partstd2s("NTSC", std_ntsc, std >> 12);
+       }
+       if (std & 0xff0000) {
+               if (s.length()) s += sep;
+               s += partstd2s("SECAM", std_secam, std >> 16);
+       }
+       if (std & 0xf000000) {
+               if (s.length()) s += sep;
+               s += partstd2s("ATSC", std_atsc, std >> 24);
+       }
+       return s;
+}
+
+std::string ctrlflags2s(__u32 flags)
+{
+       static const flag_def def[] = {
+               { V4L2_CTRL_FLAG_GRABBED,    "grabbed" },
+               { V4L2_CTRL_FLAG_DISABLED,   "disabled" },
+               { V4L2_CTRL_FLAG_READ_ONLY,  "read-only" },
+               { V4L2_CTRL_FLAG_UPDATE,     "update" },
+               { V4L2_CTRL_FLAG_INACTIVE,   "inactive" },
+               { V4L2_CTRL_FLAG_SLIDER,     "slider" },
+               { V4L2_CTRL_FLAG_WRITE_ONLY, "write-only" },
+               { V4L2_CTRL_FLAG_VOLATILE,   "volatile" },
+               { V4L2_CTRL_FLAG_HAS_PAYLOAD,"has-payload" },
+               { V4L2_CTRL_FLAG_EXECUTE_ON_WRITE, "execute-on-write" },
+               { V4L2_CTRL_FLAG_MODIFY_LAYOUT, "modify-layout" },
+               { 0, NULL }
+       };
+       return flags2s(flags, def);
+}
+
+static const flag_def in_status_def[] = {
+       { V4L2_IN_ST_NO_POWER,    "no power" },
+       { V4L2_IN_ST_NO_SIGNAL,   "no signal" },
+       { V4L2_IN_ST_NO_COLOR,    "no color" },
+       { V4L2_IN_ST_HFLIP,       "hflip" },
+       { V4L2_IN_ST_VFLIP,       "vflip" },
+       { V4L2_IN_ST_NO_H_LOCK,   "no hsync lock" },
+       { V4L2_IN_ST_NO_V_LOCK,   "no vsync lock" },
+       { V4L2_IN_ST_NO_STD_LOCK, "no standard format lock" },
+       { V4L2_IN_ST_COLOR_KILL,  "color kill" },
+       { V4L2_IN_ST_NO_SYNC,     "no sync lock" },
+       { V4L2_IN_ST_NO_EQU,      "no equalizer lock" },
+       { V4L2_IN_ST_NO_CARRIER,  "no carrier" },
+       { V4L2_IN_ST_MACROVISION, "macrovision" },
+       { V4L2_IN_ST_NO_ACCESS,   "no conditional access" },
+       { V4L2_IN_ST_VTR,         "VTR time constant" },
+       { 0, NULL }
+};
+
+std::string in_status2s(__u32 status)
+{
+       return status ? flags2s(status, in_status_def) : "ok";
+}
+
+static const flag_def input_cap_def[] = {
+       { V4L2_IN_CAP_DV_TIMINGS, "DV timings" },
+       { V4L2_IN_CAP_STD, "SDTV standards" },
+       { V4L2_IN_CAP_NATIVE_SIZE, "Native Size" },
+       { 0, NULL }
+};
+
+std::string input_cap2s(__u32 capabilities)
+{
+       return capabilities ? flags2s(capabilities, input_cap_def) : "not 
defined";
+}
+
+static const flag_def output_cap_def[] = {
+       { V4L2_OUT_CAP_DV_TIMINGS, "DV timings" },
+       { V4L2_OUT_CAP_STD, "SDTV standards" },
+       { V4L2_OUT_CAP_NATIVE_SIZE, "Native Size" },
+       { 0, NULL }
+};
+
+std::string output_cap2s(__u32 capabilities)
+{
+       return capabilities ? flags2s(capabilities, output_cap_def) : "not 
defined";
+}
+
+std::string fbufcap2s(unsigned cap)
+{
+       std::string s;
+
+       if (cap & V4L2_FBUF_CAP_EXTERNOVERLAY)
+               s += "\t\t\tExtern Overlay\n";
+       if (cap & V4L2_FBUF_CAP_CHROMAKEY)
+               s += "\t\t\tChromakey\n";
+       if (cap & V4L2_FBUF_CAP_SRC_CHROMAKEY)
+               s += "\t\t\tSource Chromakey\n";
+       if (cap & V4L2_FBUF_CAP_GLOBAL_ALPHA)
+               s += "\t\t\tGlobal Alpha\n";
+       if (cap & V4L2_FBUF_CAP_LOCAL_ALPHA)
+               s += "\t\t\tLocal Alpha\n";
+       if (cap & V4L2_FBUF_CAP_LOCAL_INV_ALPHA)
+               s += "\t\t\tLocal Inverted Alpha\n";
+       if (cap & V4L2_FBUF_CAP_LIST_CLIPPING)
+               s += "\t\t\tClipping List\n";
+       if (cap & V4L2_FBUF_CAP_BITMAP_CLIPPING)
+               s += "\t\t\tClipping Bitmap\n";
+       if (s.empty()) s += "\t\t\t\n";
+       return s;
+}
+
+std::string fbufflags2s(unsigned fl)
+{
+       std::string s;
+
+       if (fl & V4L2_FBUF_FLAG_PRIMARY)
+               s += "\t\t\tPrimary Graphics Surface\n";
+       if (fl & V4L2_FBUF_FLAG_OVERLAY)
+               s += "\t\t\tOverlay Matches Capture/Output Size\n";
+       if (fl & V4L2_FBUF_FLAG_CHROMAKEY)
+               s += "\t\t\tChromakey\n";
+       if (fl & V4L2_FBUF_FLAG_SRC_CHROMAKEY)
+               s += "\t\t\tSource Chromakey\n";
+       if (fl & V4L2_FBUF_FLAG_GLOBAL_ALPHA)
+               s += "\t\t\tGlobal Alpha\n";
+       if (fl & V4L2_FBUF_FLAG_LOCAL_ALPHA)
+               s += "\t\t\tLocal Alpha\n";
+       if (fl & V4L2_FBUF_FLAG_LOCAL_INV_ALPHA)
+               s += "\t\t\tLocal Inverted Alpha\n";
+       if (s.empty()) s += "\t\t\t\n";
+       return s;
+}
+
+static const flag_def dv_standards_def[] = {
+       { V4L2_DV_BT_STD_CEA861, "CTA-861" },
+       { V4L2_DV_BT_STD_DMT, "DMT" },
+       { V4L2_DV_BT_STD_CVT, "CVT" },
+       { V4L2_DV_BT_STD_GTF, "GTF" },
+       { V4L2_DV_BT_STD_SDI, "SDI" },
+       { 0, NULL }
+};
+
+std::string dv_standards2s(__u32 flags)
+{
+       return flags2s(flags, dv_standards_def);
+}
+
+std::string dvflags2s(unsigned vsync, int val)
+{
+       std::string s;
+
+       if (val & V4L2_DV_FL_REDUCED_BLANKING)
+               s += vsync == 8 ?
+                       "reduced blanking v2, " :
+                       "reduced blanking, ";
+       if (val & V4L2_DV_FL_CAN_REDUCE_FPS)
+               s += "framerate can be reduced by 1/1.001, ";
+       if (val & V4L2_DV_FL_REDUCED_FPS)
+               s += "framerate is reduced by 1/1.001, ";
+       if (val & V4L2_DV_FL_HALF_LINE)
+               s += "half-line, ";
+       if (val & V4L2_DV_FL_IS_CE_VIDEO)
+               s += "CE-video, ";
+       if (val & V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE)
+               s += "first field has extra line, ";
+       if (val & V4L2_DV_FL_HAS_PICTURE_ASPECT)
+               s += "has picture aspect, ";
+       if (val & V4L2_DV_FL_HAS_CEA861_VIC)
+               s += "has CTA-861 VIC, ";
+       if (val & V4L2_DV_FL_HAS_HDMI_VIC)
+               s += "has HDMI VIC, ";
+       if (s.length())
+               return s.erase(s.length() - 2, 2);
+       return s;
+}
+
+static const flag_def dv_caps_def[] = {
+       { V4L2_DV_BT_CAP_INTERLACED, "Interlaced" },
+       { V4L2_DV_BT_CAP_PROGRESSIVE, "Progressive" },
+       { V4L2_DV_BT_CAP_REDUCED_BLANKING, "Reduced Blanking" },
+       { V4L2_DV_BT_CAP_CUSTOM, "Custom Formats" },
+       { 0, NULL }
+};
+
+std::string dv_caps2s(__u32 flags)
+{
+       return flags2s(flags, dv_caps_def);
+}
+
+static const flag_def tc_flags_def[] = {
+       { V4L2_TC_FLAG_DROPFRAME, "dropframe" },
+       { V4L2_TC_FLAG_COLORFRAME, "colorframe" },
+       { V4L2_TC_USERBITS_field, "userbits-field" },
+       { V4L2_TC_USERBITS_USERDEFINED, "userbits-userdefined" },
+       { V4L2_TC_USERBITS_8BITCHARS, "userbits-8bitchars" },
+       { 0, NULL }
+};
+
+std::string tc_flags2s(__u32 flags)
+{
+       return flags2s(flags, tc_flags_def);
+}
+
+static const flag_def buffer_flags_def[] = {
+       { V4L2_BUF_FLAG_MAPPED, "mapped" },
+       { V4L2_BUF_FLAG_QUEUED, "queued" },
+       { V4L2_BUF_FLAG_DONE, "done" },
+       { V4L2_BUF_FLAG_KEYFRAME, "keyframe" },
+       { V4L2_BUF_FLAG_PFRAME, "P-frame" },
+       { V4L2_BUF_FLAG_BFRAME, "B-frame" },
+       { V4L2_BUF_FLAG_ERROR, "error" },
+       { V4L2_BUF_FLAG_TIMECODE, "timecode" },
+       { V4L2_BUF_FLAG_PREPARED, "prepared" },
+       { V4L2_BUF_FLAG_NO_CACHE_INVALIDATE, "no-cache-invalidate" },
+       { V4L2_BUF_FLAG_NO_CACHE_CLEAN, "no-cache-clean" },
+       { V4L2_BUF_FLAG_LAST, "last" },
+       { 0, NULL }
+};
+
+std::string bufferflags2s(__u32 flags)
+{
+       return flags2s(flags, buffer_flags_def);
+}
+
+static const flag_def vbi_def[] = {
+       { V4L2_VBI_UNSYNC,     "unsynchronized" },
+       { V4L2_VBI_INTERLACED, "interlaced" },
+       { 0, NULL }
+};
+
+std::string vbiflags2s(__u32 flags)
+{
+       return flags2s(flags, vbi_def);
+}
diff --git a/utils/common/v4l2-info.h b/utils/common/v4l2-info.h
index e33332a3dbe6..ae017473ea77 100644
--- a/utils/common/v4l2-info.h
+++ b/utils/common/v4l2-info.h
@@ -21,4 +21,98 @@
 /* Print capability information */
 void v4l2_info_capability(const v4l2_capability &cap);
 
+/* Return fourcc pixelformat string */
+std::string fcc2s(__u32 val);
+
+/* Return buffer type description */
+std::string buftype2s(int type);
+
+static inline std::string buftype2s(enum v4l2_buf_type type)
+{
+       return buftype2s((int)type);
+}
+
+/* Return field description */
+std::string field2s(int val);
+
+/* Return colorspace description */
+std::string colorspace2s(int val);
+
+/* Return transfer function description */
+std::string xfer_func2s(int val);
+
+/* Return YCbCr encoding description */
+std::string ycbcr_enc2s(int val);
+
+/* Return quantization description */
+std::string quantization2s(int val);
+
+/* Return v4l2_pix_format flags description */
+std::string pixflags2s(unsigned flags);
+
+/* Return sliced vbi services description */
+std::string service2s(unsigned service);
+
+/* Return v4l2_fmtdesc flags description */
+std::string fmtdesc2s(unsigned flags);
+
+/* Return selection flags description */
+std::string selflags2s(__u32 flags);
+
+/* Return selection target description */
+std::string seltarget2s(__u32 target);
+
+/*
+ * v4l2-info.cpp has a table with valid selection targets,
+ * these functions help navigate that table.
+ */
+
+/* Return true if the table at index i has a valid selection target */
+bool valid_seltarget_at_idx(unsigned i);
+
+/* Return the selection target in the table at index i (or 0 if out of range) 
*/
+unsigned seltarget_at_idx(unsigned i);
+
+/* Return v4l2_std description, separate entries by sep */
+std::string std2s(v4l2_std_id std, const char *sep = " ");
+
+/* Return control flags description */
+std::string ctrlflags2s(__u32 flags);
+
+/* Return input status description */
+std::string in_status2s(__u32 status);
+
+/* Return input capabilities description */
+std::string input_cap2s(__u32 capabilities);
+
+/* Return output capabilities description */
+std::string output_cap2s(__u32 capabilities);
+
+/* Return framebuffer capabilities description */
+std::string fbufcap2s(unsigned cap);
+
+/* Return framebuffer flags description */
+std::string fbufflags2s(unsigned fl);
+
+/* Return DV Timings standards description */
+std::string dv_standards2s(__u32 flags);
+
+/*
+ * Return DV Timings flags description, vsync is the
+ * vertical sync value.
+ */
+std::string dvflags2s(unsigned vsync, int val);
+
+/* Return DV Timings capabilities description */
+std::string dv_caps2s(__u32 flags);
+
+/* Return v4l2_timecode flags description */
+std::string tc_flags2s(__u32 flags);
+
+/* Return v4l2_buffer flags description */
+std::string bufferflags2s(__u32 flags);
+
+/* Return vbi flags description */
+std::string vbiflags2s(__u32 flags);
+
 #endif
diff --git a/utils/v4l2-compliance/v4l2-compliance.cpp 
b/utils/v4l2-compliance/v4l2-compliance.cpp
index f5f128a12f99..03139ae9933b 100644
--- a/utils/v4l2-compliance/v4l2-compliance.cpp
+++ b/utils/v4l2-compliance/v4l2-compliance.cpp
@@ -39,7 +39,6 @@
 #include <vector>
 
 #include "v4l2-compliance.h"
-#include <v4l2-info.h>
 #include <media-info.h>
 #ifndef ANDROID
 #include "version.h"
@@ -194,55 +193,6 @@ static void usage(void)
        exit(0);
 }
 
-std::string fcc2s(unsigned int val)
-{
-       std::string s;
-
-       s += val & 0x7f;
-       s += (val >> 8) & 0x7f;
-       s += (val >> 16) & 0x7f;
-       s += (val >> 24) & 0x7f;
-       if (val & (1 << 31))
-               s += "-BE";
-       return s;
-}
-
-std::string buftype2s(int type)
-{
-       switch (type) {
-       case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               return "Video Capture";
-       case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
-               return "Video Capture Multiplanar";
-       case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-               return "Video Output";
-       case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-               return "Video Output Multiplanar";
-       case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-               return "Video Overlay";
-       case V4L2_BUF_TYPE_VBI_CAPTURE:
-               return "VBI Capture";
-       case V4L2_BUF_TYPE_VBI_OUTPUT:
-               return "VBI Output";
-       case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-               return "Sliced VBI Capture";
-       case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-               return "Sliced VBI Output";
-       case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-               return "Video Output Overlay";
-       case V4L2_BUF_TYPE_SDR_CAPTURE:
-               return "SDR Capture";
-       case V4L2_BUF_TYPE_SDR_OUTPUT:
-               return "SDR Output";
-       case V4L2_BUF_TYPE_META_CAPTURE:
-               return "Metadata Capture";
-       case V4L2_BUF_TYPE_PRIVATE:
-               return "Private";
-       default:
-               return std::string("Unknown");
-       }
-}
-
 const char *ok(int res)
 {
        static char buf[100];
diff --git a/utils/v4l2-compliance/v4l2-compliance.h 
b/utils/v4l2-compliance/v4l2-compliance.h
index 2223df5964f8..3263784b0d66 100644
--- a/utils/v4l2-compliance/v4l2-compliance.h
+++ b/utils/v4l2-compliance/v4l2-compliance.h
@@ -42,6 +42,7 @@
 #endif
 
 #include <cv4l-helpers.h>
+#include <v4l2-info.h>
 
 #if !defined(ENODATA) && (defined(__FreeBSD__) || defined(__FreeBSD_kernel__))
 #define ENODATA ENOTSUP
@@ -174,20 +175,11 @@ static inline double fract2f(const struct v4l2_fract *f)
 
 #define doioctl(n, r, p) v4l_named_ioctl((n)->g_v4l_fd(), #r, r, p)
 
-std::string buftype2s(int type);
-std::string fcc2s(unsigned int val);
-
-static inline std::string buftype2s(enum v4l2_buf_type type)
-{
-       return buftype2s((int)type);
-}
-
 const char *ok(int res);
 int check_string(const char *s, size_t len);
 int check_ustring(const __u8 *s, int len);
 int check_0(const void *p, int len);
 int restoreFormat(struct node *node);
-std::string pixfmt2s(unsigned id);
 
 // Media Controller ioctl tests
 int testMediaDeviceInfo(struct node *node);
diff --git a/utils/v4l2-compliance/v4l2-test-buffers.cpp 
b/utils/v4l2-compliance/v4l2-test-buffers.cpp
index 2eeacdad3133..9b0933ef1fea 100644
--- a/utils/v4l2-compliance/v4l2-test-buffers.cpp
+++ b/utils/v4l2-compliance/v4l2-test-buffers.cpp
@@ -67,55 +67,6 @@ enum QueryBufMode {
 typedef std::map<struct timeval, struct v4l2_buffer> buf_info_map;
 static buf_info_map buffer_info;
 
-std::string pixfmt2s(unsigned id)
-{
-       std::string pixfmt;
-
-       pixfmt += (char)(id & 0x7f);
-       pixfmt += (char)((id >> 8) & 0x7f);
-       pixfmt += (char)((id >> 16) & 0x7f);
-       pixfmt += (char)((id >> 24) & 0x7f);
-       if (id & (1 << 31))
-               pixfmt += "-BE";
-       return pixfmt;
-}
-
-static std::string num2s(unsigned num)
-{
-       char buf[10];
-
-       sprintf(buf, "%08x", num);
-       return buf;
-}
-
-static std::string field2s(unsigned val)
-{
-       switch (val) {
-       case V4L2_FIELD_ANY:
-               return "Any";
-       case V4L2_FIELD_NONE:
-               return "None";
-       case V4L2_FIELD_TOP:
-               return "Top";
-       case V4L2_FIELD_BOTTOM:
-               return "Bottom";
-       case V4L2_FIELD_INTERLACED:
-               return "Interlaced";
-       case V4L2_FIELD_SEQ_TB:
-               return "Sequential Top-Bottom";
-       case V4L2_FIELD_SEQ_BT:
-               return "Sequential Bottom-Top";
-       case V4L2_FIELD_ALTERNATE:
-               return "Alternating";
-       case V4L2_FIELD_INTERLACED_TB:
-               return "Interlaced Top-Bottom";
-       case V4L2_FIELD_INTERLACED_BT:
-               return "Interlaced Bottom-Top";
-       default:
-               return "Unknown (" + num2s(val) + ")";
-       }
-}
-
 class buffer : public cv4l_buffer {
 public:
        buffer(unsigned type = 0, unsigned memory = 0, unsigned index = 0) :
@@ -1488,7 +1439,7 @@ static void streamFmt(struct node *node, __u32 
pixelformat, __u32 w, __u32 h, v4
        }
 
        printf("\ttest %s for Format %s, Frame Size %ux%u%s:\n", op,
-                               pixfmt2s(pixelformat).c_str(),
+                               fcc2s(pixelformat).c_str(),
                                fmt.g_width(), fmt.g_frame_height(), hz);
 
        if (has_crop)
diff --git a/utils/v4l2-compliance/v4l2-test-colors.cpp 
b/utils/v4l2-compliance/v4l2-test-colors.cpp
index 3a680dd82b6d..ca7a4ea0c5fa 100644
--- a/utils/v4l2-compliance/v4l2-test-colors.cpp
+++ b/utils/v4l2-compliance/v4l2-test-colors.cpp
@@ -544,7 +544,7 @@ int testColorsAllFormats(struct node *node, unsigned 
component,
                node->s_fmt(fmt);
                printf("\ttest %u%% %s for format %s: %s\n",
                                perc, colors[component],
-                               pixfmt2s(fmt.g_pixelformat()).c_str(),
+                               fcc2s(fmt.g_pixelformat()).c_str(),
                                ok(testColorsFmt(node, component, skip, perc)));
        } while (!node->enum_fmt(fmtdesc));
        printf("\n");
diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp 
b/utils/v4l2-ctl/v4l2-ctl-common.cpp
index d13a59440a33..3466d8ea95b0 100644
--- a/utils/v4l2-ctl/v4l2-ctl-common.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp
@@ -284,25 +284,6 @@ static std::string safename(const char *name)
        return safename((const unsigned char *)name);
 }
 
-static std::string ctrlflags2s(__u32 flags)
-{
-       static const flag_def def[] = {
-               { V4L2_CTRL_FLAG_GRABBED,    "grabbed" },
-               { V4L2_CTRL_FLAG_DISABLED,   "disabled" },
-               { V4L2_CTRL_FLAG_READ_ONLY,  "read-only" },
-               { V4L2_CTRL_FLAG_UPDATE,     "update" },
-               { V4L2_CTRL_FLAG_INACTIVE,   "inactive" },
-               { V4L2_CTRL_FLAG_SLIDER,     "slider" },
-               { V4L2_CTRL_FLAG_WRITE_ONLY, "write-only" },
-               { V4L2_CTRL_FLAG_VOLATILE,   "volatile" },
-               { V4L2_CTRL_FLAG_HAS_PAYLOAD,"has-payload" },
-               { V4L2_CTRL_FLAG_EXECUTE_ON_WRITE, "execute-on-write" },
-               { V4L2_CTRL_FLAG_MODIFY_LAYOUT, "modify-layout" },
-               { 0, NULL }
-       };
-       return flags2s(flags, def);
-}
-
 static void print_qctrl(int fd, struct v4l2_query_ext_ctrl *queryctrl,
                struct v4l2_ext_control *ctrl, int show_menus)
 {
diff --git a/utils/v4l2-ctl/v4l2-ctl-io.cpp b/utils/v4l2-ctl/v4l2-ctl-io.cpp
index f84bdc95fe0c..a3178797ffb3 100644
--- a/utils/v4l2-ctl/v4l2-ctl-io.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-io.cpp
@@ -47,30 +47,6 @@ void io_usage(void)
               );
 }
 
-static const flag_def in_status_def[] = {
-       { V4L2_IN_ST_NO_POWER,    "no power" },
-       { V4L2_IN_ST_NO_SIGNAL,   "no signal" },
-       { V4L2_IN_ST_NO_COLOR,    "no color" },
-       { V4L2_IN_ST_HFLIP,       "hflip" },
-       { V4L2_IN_ST_VFLIP,       "vflip" },
-       { V4L2_IN_ST_NO_H_LOCK,   "no hsync lock" },
-       { V4L2_IN_ST_NO_V_LOCK,   "no vsync lock" },
-       { V4L2_IN_ST_NO_STD_LOCK, "no standard format lock" },
-       { V4L2_IN_ST_COLOR_KILL,  "color kill" },
-       { V4L2_IN_ST_NO_SYNC,     "no sync lock" },
-       { V4L2_IN_ST_NO_EQU,      "no equalizer lock" },
-       { V4L2_IN_ST_NO_CARRIER,  "no carrier" },
-       { V4L2_IN_ST_MACROVISION, "macrovision" },
-       { V4L2_IN_ST_NO_ACCESS,   "no conditional access" },
-       { V4L2_IN_ST_VTR,         "VTR time constant" },
-       { 0, NULL }
-};
-
-static std::string status2s(__u32 status)
-{
-       return status ? flags2s(status, in_status_def) : "ok";
-}
-
 static const char *inputtype2s(__u32 type)
 {
        switch (type) {
@@ -99,31 +75,6 @@ static const char *outputtype2s(__u32 type)
        }
 }
 
-
-static const flag_def input_cap_def[] = {
-       { V4L2_IN_CAP_DV_TIMINGS, "DV timings" },
-       { V4L2_IN_CAP_STD, "SDTV standards" },
-       { V4L2_IN_CAP_NATIVE_SIZE, "Native Size" },
-       { 0, NULL }
-};
-
-static std::string input_cap2s(__u32 capabilities)
-{
-       return capabilities ? flags2s(capabilities, input_cap_def) : "not 
defined";
-}
-
-static const flag_def output_cap_def[] = {
-       { V4L2_OUT_CAP_DV_TIMINGS, "DV timings" },
-       { V4L2_OUT_CAP_STD, "SDTV standards" },
-       { V4L2_OUT_CAP_NATIVE_SIZE, "Native Size" },
-       { 0, NULL }
-};
-
-static std::string output_cap2s(__u32 capabilities)
-{
-       return capabilities ? flags2s(capabilities, output_cap_def) : "not 
defined";
-}
-
 void io_cmd(int ch, char *optarg)
 {
        switch (ch) {
@@ -153,7 +104,7 @@ void io_set(int fd)
                        if (test_ioctl(fd, VIDIOC_ENUMINPUT, &vin) >= 0)
                                printf(" (%s: %s, %s)", vin.name,
                                       inputtype2s(vin.type),
-                                      status2s(vin.status).c_str());
+                                      in_status2s(vin.status).c_str());
                        printf("\n");
                }
        }
@@ -183,7 +134,7 @@ void io_get(int fd)
                        printf("Video input : %d", input);
                        vin.index = input;
                        if (test_ioctl(fd, VIDIOC_ENUMINPUT, &vin) >= 0)
-                               printf(" (%s: %s)", vin.name, 
status2s(vin.status).c_str());
+                               printf(" (%s: %s)", vin.name, 
in_status2s(vin.status).c_str());
                        printf("\n");
                }
        }
@@ -229,7 +180,7 @@ void io_list(int fd)
                        printf("\tTuner       : 0x%08X\n", vin.tuner);
                        printf("\tStandard    : 0x%016llX (%s)\n", (unsigned 
long long)vin.std,
                                std2s(vin.std).c_str());
-                       printf("\tStatus      : 0x%08X (%s)\n", vin.status, 
status2s(vin.status).c_str());
+                       printf("\tStatus      : 0x%08X (%s)\n", vin.status, 
in_status2s(vin.status).c_str());
                        printf("\tCapabilities: 0x%08X (%s)\n", 
vin.capabilities, input_cap2s(vin.capabilities).c_str());
                         vin.index++;
                 }
diff --git a/utils/v4l2-ctl/v4l2-ctl-overlay.cpp 
b/utils/v4l2-ctl/v4l2-ctl-overlay.cpp
index 3cbbd562cb9e..73710ce53661 100644
--- a/utils/v4l2-ctl/v4l2-ctl-overlay.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-overlay.cpp
@@ -63,52 +63,6 @@ void overlay_usage(void)
               );
 }
 
-static std::string fbufcap2s(unsigned cap)
-{
-       std::string s;
-
-       if (cap & V4L2_FBUF_CAP_EXTERNOVERLAY)
-               s += "\t\t\tExtern Overlay\n";
-       if (cap & V4L2_FBUF_CAP_CHROMAKEY)
-               s += "\t\t\tChromakey\n";
-       if (cap & V4L2_FBUF_CAP_SRC_CHROMAKEY)
-               s += "\t\t\tSource Chromakey\n";
-       if (cap & V4L2_FBUF_CAP_GLOBAL_ALPHA)
-               s += "\t\t\tGlobal Alpha\n";
-       if (cap & V4L2_FBUF_CAP_LOCAL_ALPHA)
-               s += "\t\t\tLocal Alpha\n";
-       if (cap & V4L2_FBUF_CAP_LOCAL_INV_ALPHA)
-               s += "\t\t\tLocal Inverted Alpha\n";
-       if (cap & V4L2_FBUF_CAP_LIST_CLIPPING)
-               s += "\t\t\tClipping List\n";
-       if (cap & V4L2_FBUF_CAP_BITMAP_CLIPPING)
-               s += "\t\t\tClipping Bitmap\n";
-       if (s.empty()) s += "\t\t\t\n";
-       return s;
-}
-
-static std::string fbufflags2s(unsigned fl)
-{
-       std::string s;
-
-       if (fl & V4L2_FBUF_FLAG_PRIMARY)
-               s += "\t\t\tPrimary Graphics Surface\n";
-       if (fl & V4L2_FBUF_FLAG_OVERLAY)
-               s += "\t\t\tOverlay Matches Capture/Output Size\n";
-       if (fl & V4L2_FBUF_FLAG_CHROMAKEY)
-               s += "\t\t\tChromakey\n";
-       if (fl & V4L2_FBUF_FLAG_SRC_CHROMAKEY)
-               s += "\t\t\tSource Chromakey\n";
-       if (fl & V4L2_FBUF_FLAG_GLOBAL_ALPHA)
-               s += "\t\t\tGlobal Alpha\n";
-       if (fl & V4L2_FBUF_FLAG_LOCAL_ALPHA)
-               s += "\t\t\tLocal Alpha\n";
-       if (fl & V4L2_FBUF_FLAG_LOCAL_INV_ALPHA)
-               s += "\t\t\tLocal Inverted Alpha\n";
-       if (s.empty()) s += "\t\t\t\n";
-       return s;
-}
-
 static void printfbuf(const struct v4l2_framebuffer &fb)
 {
        int is_ext = fb.capability & V4L2_FBUF_CAP_EXTERNOVERLAY;
diff --git a/utils/v4l2-ctl/v4l2-ctl-selection.cpp 
b/utils/v4l2-ctl/v4l2-ctl-selection.cpp
index 22dab74d2c70..ad64273ca769 100644
--- a/utils/v4l2-ctl/v4l2-ctl-selection.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-selection.cpp
@@ -365,17 +365,17 @@ void selection_get(int fd)
 
        if (options[OptGetSelection]) {
                struct v4l2_selection sel;
-               int t = 0;
+               unsigned idx = 0;
 
                memset(&sel, 0, sizeof(sel));
                sel.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 
                if (options[OptAll] || get_sel_target == -1) {
-                       while (selection_targets_def[t].str != NULL) {
-                               sel.target = selection_targets_def[t].flag;
+                       while (valid_seltarget_at_idx(idx)) {
+                               sel.target = seltarget_at_idx(idx);
                                if (doioctl(fd, VIDIOC_G_SELECTION, &sel) == 0)
                                        print_selection(sel);
-                               t++;
+                               idx++;
                        }
                } else {
                        sel.target = get_sel_target;
@@ -386,17 +386,17 @@ void selection_get(int fd)
 
        if (options[OptGetOutputSelection]) {
                struct v4l2_selection sel;
-               int t = 0;
+               unsigned idx = 0;
 
                memset(&sel, 0, sizeof(sel));
                sel.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
 
                if (options[OptAll] || get_sel_target == -1) {
-                       while (selection_targets_def[t].str != NULL) {
-                               sel.target = selection_targets_def[t].flag;
+                       while (valid_seltarget_at_idx(idx)) {
+                               sel.target = seltarget_at_idx(idx);
                                if (doioctl(fd, VIDIOC_G_SELECTION, &sel) == 0)
                                        print_selection(sel);
-                               t++;
+                               idx++;
                        }
                } else {
                        sel.target = get_sel_target;
diff --git a/utils/v4l2-ctl/v4l2-ctl-stds.cpp b/utils/v4l2-ctl/v4l2-ctl-stds.cpp
index 4c305a00f3e8..aa0bfea57908 100644
--- a/utils/v4l2-ctl/v4l2-ctl-stds.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-stds.cpp
@@ -362,44 +362,6 @@ static void parse_dv_bt_timings(char *optarg, struct 
v4l2_dv_timings *dv_timings
        }
 }
 
-static const flag_def dv_standards_def[] = {
-       { V4L2_DV_BT_STD_CEA861, "CTA-861" },
-       { V4L2_DV_BT_STD_DMT, "DMT" },
-       { V4L2_DV_BT_STD_CVT, "CVT" },
-       { V4L2_DV_BT_STD_GTF, "GTF" },
-       { V4L2_DV_BT_STD_SDI, "SDI" },
-       { 0, NULL }
-};
-
-static std::string dvflags2s(unsigned vsync, int val)
-{
-       std::string s;
-
-       if (val & V4L2_DV_FL_REDUCED_BLANKING)
-               s += vsync == 8 ?
-                       "reduced blanking v2, " :
-                       "reduced blanking, ";
-       if (val & V4L2_DV_FL_CAN_REDUCE_FPS)
-               s += "framerate can be reduced by 1/1.001, ";
-       if (val & V4L2_DV_FL_REDUCED_FPS)
-               s += "framerate is reduced by 1/1.001, ";
-       if (val & V4L2_DV_FL_HALF_LINE)
-               s += "half-line, ";
-       if (val & V4L2_DV_FL_IS_CE_VIDEO)
-               s += "CE-video, ";
-       if (val & V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE)
-               s += "first field has extra line, ";
-       if (val & V4L2_DV_FL_HAS_PICTURE_ASPECT)
-               s += "has picture aspect, ";
-       if (val & V4L2_DV_FL_HAS_CEA861_VIC)
-               s += "has CTA-861 VIC, ";
-       if (val & V4L2_DV_FL_HAS_HDMI_VIC)
-               s += "has HDMI VIC, ";
-       if (s.length())
-               return s.erase(s.length() - 2, 2);
-       return s;
-}
-
 static void print_dv_timings(const struct v4l2_dv_timings *t)
 {
        const struct v4l2_bt_timings *bt;
@@ -458,7 +420,7 @@ static void print_dv_timings(const struct v4l2_dv_timings 
*t)
                        printf("\tVertical sync: %d\n", bt->il_vsync);
                        printf("\tVertical backporch: %d\n", bt->il_vbackporch);
                }
-               printf("\tStandards: %s\n", flags2s(bt->standards, 
dv_standards_def).c_str());
+               printf("\tStandards: %s\n", 
dv_standards2s(bt->standards).c_str());
                if (bt->flags & V4L2_DV_FL_HAS_PICTURE_ASPECT)
                        printf("\tPicture aspect: %u:%u\n",
                               bt->picture_aspect.numerator,
@@ -620,7 +582,7 @@ void stds_get(int fd)
        if (options[OptGetStandard]) {
                if (doioctl(fd, VIDIOC_G_STD, &standard) == 0) {
                        printf("Video Standard = 0x%08llx\n", (unsigned long 
long)standard);
-                       print_v4lstd((unsigned long long)standard);
+                       printf("\t%s\n", std2s(standard, "\n\t").c_str());
                }
        }
 
@@ -636,13 +598,6 @@ void stds_get(int fd)
 
                dv_timings_cap.pad = dv_timings_cap_pad;
                if (doioctl(fd, VIDIOC_DV_TIMINGS_CAP, &dv_timings_cap) >= 0) {
-                       static const flag_def dv_caps_def[] = {
-                               { V4L2_DV_BT_CAP_INTERLACED, "Interlaced" },
-                               { V4L2_DV_BT_CAP_PROGRESSIVE, "Progressive" },
-                               { V4L2_DV_BT_CAP_REDUCED_BLANKING, "Reduced 
Blanking" },
-                               { V4L2_DV_BT_CAP_CUSTOM, "Custom Formats" },
-                               { 0, NULL }
-                       };
                        struct v4l2_bt_timings_cap *bt = &dv_timings_cap.bt;
 
                        printf("DV timings capabilities:\n");
@@ -656,9 +611,9 @@ void stds_get(int fd)
                                printf("\tMinimum PClock: %llu\n", 
bt->min_pixelclock);
                                printf("\tMaximum PClock: %llu\n", 
bt->max_pixelclock);
                                printf("\tStandards: %s\n",
-                                       flags2s(bt->standards, 
dv_standards_def).c_str());
+                                       dv_standards2s(bt->standards).c_str());
                                printf("\tCapabilities: %s\n",
-                                       flags2s(bt->capabilities, 
dv_caps_def).c_str());
+                                       dv_caps2s(bt->capabilities).c_str());
                        }
                }
        }
@@ -666,7 +621,7 @@ void stds_get(int fd)
         if (options[OptQueryStandard]) {
                if (doioctl(fd, VIDIOC_QUERYSTD, &standard) == 0) {
                        printf("Video Standard = 0x%08llx\n", (unsigned long 
long)standard);
-                       print_v4lstd((unsigned long long)standard);
+                       printf("\t%s\n", std2s(standard, "\n\t").c_str());
                }
        }
 
diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp 
b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
index 89ff2ad3027f..2da684befc88 100644
--- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp
@@ -194,22 +194,6 @@ static void write_u32(FILE *f, __u32 v)
        fwrite(&v, 1, sizeof(v), f);
 }
 
-static const flag_def flags_def[] = {
-       { V4L2_BUF_FLAG_MAPPED, "mapped" },
-       { V4L2_BUF_FLAG_QUEUED, "queued" },
-       { V4L2_BUF_FLAG_DONE, "done" },
-       { V4L2_BUF_FLAG_KEYFRAME, "keyframe" },
-       { V4L2_BUF_FLAG_PFRAME, "P-frame" },
-       { V4L2_BUF_FLAG_BFRAME, "B-frame" },
-       { V4L2_BUF_FLAG_ERROR, "error" },
-       { V4L2_BUF_FLAG_TIMECODE, "timecode" },
-       { V4L2_BUF_FLAG_PREPARED, "prepared" },
-       { V4L2_BUF_FLAG_NO_CACHE_INVALIDATE, "no-cache-invalidate" },
-       { V4L2_BUF_FLAG_NO_CACHE_CLEAN, "no-cache-clean" },
-       { V4L2_BUF_FLAG_LAST, "last" },
-       { 0, NULL }
-};
-
 static std::string timestamp_type2s(__u32 flags)
 {
        char buf[20];
@@ -242,22 +226,13 @@ static std::string timestamp_src2s(__u32 flags)
        }
 }
 
-static const flag_def tc_flags_def[] = {
-       { V4L2_TC_FLAG_DROPFRAME, "dropframe" },
-       { V4L2_TC_FLAG_COLORFRAME, "colorframe" },
-       { V4L2_TC_USERBITS_field, "userbits-field" },
-       { V4L2_TC_USERBITS_USERDEFINED, "userbits-userdefined" },
-       { V4L2_TC_USERBITS_8BITCHARS, "userbits-8bitchars" },
-       { 0, NULL }
-};
-
 static void print_buffer(FILE *f, struct v4l2_buffer &buf)
 {
        const unsigned ts_flags = V4L2_BUF_FLAG_TIMESTAMP_MASK | 
V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
 
        fprintf(f, "\tIndex    : %d\n", buf.index);
        fprintf(f, "\tType     : %s\n", buftype2s(buf.type).c_str());
-       fprintf(f, "\tFlags    : %s\n", flags2s(buf.flags & ~ts_flags, 
flags_def).c_str());
+       fprintf(f, "\tFlags    : %s\n", bufferflags2s(buf.flags & 
~ts_flags).c_str());
        fprintf(f, "\tField    : %s\n", field2s(buf.field).c_str());
        fprintf(f, "\tSequence : %u\n", buf.sequence);
        fprintf(f, "\tLength   : %u\n", buf.length);
@@ -272,7 +247,7 @@ static void print_buffer(FILE *f, struct v4l2_buffer &buf)
                        fps = 0;
                fprintf(f, "\tTimecode : %dfps %s %dh %dm %ds %df (0x%02x 
0x%02x 0x%02x 0x%02x)\n",
                        fps_types[fps],
-                       flags2s(buf.timecode.flags, tc_flags_def).c_str(),
+                       tc_flags2s(buf.timecode.flags).c_str(),
                        buf.timecode.hours, buf.timecode.minutes,
                        buf.timecode.seconds, buf.timecode.frames,
                        buf.timecode.userbits[0], buf.timecode.userbits[1],
diff --git a/utils/v4l2-ctl/v4l2-ctl-subdev.cpp 
b/utils/v4l2-ctl/v4l2-ctl-subdev.cpp
index 717e4c843a03..b6c223da8f14 100644
--- a/utils/v4l2-ctl/v4l2-ctl-subdev.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-subdev.cpp
@@ -510,7 +510,7 @@ void subdev_get(int fd)
 
        if (options[OptGetSubDevSelection]) {
                struct v4l2_subdev_selection sel;
-               int t = 0;
+               unsigned idx = 0;
 
                memset(&sel, 0, sizeof(sel));
                sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
@@ -518,11 +518,11 @@ void subdev_get(int fd)
 
                printf("ioctl: VIDIOC_SUBDEV_G_SELECTION (pad=%u)\n", sel.pad);
                if (options[OptAll] || get_sel_target == -1) {
-                       while (selection_targets_def[t].str != NULL) {
-                               sel.target = selection_targets_def[t].flag;
+                       while (valid_seltarget_at_idx(idx)) {
+                               sel.target = seltarget_at_idx(idx);
                                if (test_ioctl(fd, VIDIOC_SUBDEV_G_SELECTION, 
&sel) == 0)
                                        print_subdev_selection(sel);
-                               t++;
+                               idx++;
                        }
                } else {
                        sel.target = get_sel_target;
diff --git a/utils/v4l2-ctl/v4l2-ctl.cpp b/utils/v4l2-ctl/v4l2-ctl.cpp
index a269297986b9..03a82a946761 100644
--- a/utils/v4l2-ctl/v4l2-ctl.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl.cpp
@@ -41,7 +41,6 @@
 
 #include "v4l2-ctl.h"
 
-#include <v4l2-info.h>
 #include <media-info.h>
 
 #ifdef HAVE_SYS_KLOG_H
@@ -321,234 +320,6 @@ int doioctl_name(int fd, unsigned long int request, void 
*parm, const char *name
        return retval;
 }
 
-static std::string num2s(unsigned num)
-{
-       char buf[10];
-
-       sprintf(buf, "%08x", num);
-       return buf;
-}
-
-std::string buftype2s(int type)
-{
-       switch (type) {
-       case 0:
-               return "Invalid";
-       case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               return "Video Capture";
-       case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
-               return "Video Capture Multiplanar";
-       case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-               return "Video Output";
-       case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-               return "Video Output Multiplanar";
-       case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-               return "Video Overlay";
-       case V4L2_BUF_TYPE_VBI_CAPTURE:
-               return "VBI Capture";
-       case V4L2_BUF_TYPE_VBI_OUTPUT:
-               return "VBI Output";
-       case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-               return "Sliced VBI Capture";
-       case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-               return "Sliced VBI Output";
-       case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-               return "Video Output Overlay";
-       case V4L2_BUF_TYPE_SDR_CAPTURE:
-               return "SDR Capture";
-       case V4L2_BUF_TYPE_SDR_OUTPUT:
-               return "SDR Output";
-       case V4L2_BUF_TYPE_META_CAPTURE:
-               return "Metadata Capture";
-       default:
-               return "Unknown (" + num2s(type) + ")";
-       }
-}
-
-std::string fcc2s(unsigned int val)
-{
-       std::string s;
-
-       s += val & 0x7f;
-       s += (val >> 8) & 0x7f;
-       s += (val >> 16) & 0x7f;
-       s += (val >> 24) & 0x7f;
-       if (val & (1 << 31))
-               s += "-BE";
-       return s;
-}
-
-std::string field2s(int val)
-{
-       switch (val) {
-       case V4L2_FIELD_ANY:
-               return "Any";
-       case V4L2_FIELD_NONE:
-               return "None";
-       case V4L2_FIELD_TOP:
-               return "Top";
-       case V4L2_FIELD_BOTTOM:
-               return "Bottom";
-       case V4L2_FIELD_INTERLACED:
-               return "Interlaced";
-       case V4L2_FIELD_SEQ_TB:
-               return "Sequential Top-Bottom";
-       case V4L2_FIELD_SEQ_BT:
-               return "Sequential Bottom-Top";
-       case V4L2_FIELD_ALTERNATE:
-               return "Alternating";
-       case V4L2_FIELD_INTERLACED_TB:
-               return "Interlaced Top-Bottom";
-       case V4L2_FIELD_INTERLACED_BT:
-               return "Interlaced Bottom-Top";
-       default:
-               return "Unknown (" + num2s(val) + ")";
-       }
-}
-
-std::string colorspace2s(int val)
-{
-       switch (val) {
-       case V4L2_COLORSPACE_DEFAULT:
-               return "Default";
-       case V4L2_COLORSPACE_SMPTE170M:
-               return "SMPTE 170M";
-       case V4L2_COLORSPACE_SMPTE240M:
-               return "SMPTE 240M";
-       case V4L2_COLORSPACE_REC709:
-               return "Rec. 709";
-       case V4L2_COLORSPACE_BT878:
-               return "Broken Bt878";
-       case V4L2_COLORSPACE_470_SYSTEM_M:
-               return "470 System M";
-       case V4L2_COLORSPACE_470_SYSTEM_BG:
-               return "470 System BG";
-       case V4L2_COLORSPACE_JPEG:
-               return "JPEG";
-       case V4L2_COLORSPACE_SRGB:
-               return "sRGB";
-       case V4L2_COLORSPACE_ADOBERGB:
-               return "AdobeRGB";
-       case V4L2_COLORSPACE_DCI_P3:
-               return "DCI-P3";
-       case V4L2_COLORSPACE_BT2020:
-               return "BT.2020";
-       case V4L2_COLORSPACE_RAW:
-               return "Raw";
-       default:
-               return "Unknown (" + num2s(val) + ")";
-       }
-}
-
-std::string xfer_func2s(int val)
-{
-       switch (val) {
-       case V4L2_XFER_FUNC_DEFAULT:
-               return "Default";
-       case V4L2_XFER_FUNC_709:
-               return "Rec. 709";
-       case V4L2_XFER_FUNC_SRGB:
-               return "sRGB";
-       case V4L2_XFER_FUNC_ADOBERGB:
-               return "AdobeRGB";
-       case V4L2_XFER_FUNC_DCI_P3:
-               return "DCI-P3";
-       case V4L2_XFER_FUNC_SMPTE2084:
-               return "SMPTE 2084";
-       case V4L2_XFER_FUNC_SMPTE240M:
-               return "SMPTE 240M";
-       case V4L2_XFER_FUNC_NONE:
-               return "None";
-       default:
-               return "Unknown (" + num2s(val) + ")";
-       }
-}
-
-std::string ycbcr_enc2s(int val)
-{
-       switch (val) {
-       case V4L2_YCBCR_ENC_DEFAULT:
-               return "Default";
-       case V4L2_YCBCR_ENC_601:
-               return "ITU-R 601";
-       case V4L2_YCBCR_ENC_709:
-               return "Rec. 709";
-       case V4L2_YCBCR_ENC_XV601:
-               return "xvYCC 601";
-       case V4L2_YCBCR_ENC_XV709:
-               return "xvYCC 709";
-       case V4L2_YCBCR_ENC_BT2020:
-               return "BT.2020";
-       case V4L2_YCBCR_ENC_BT2020_CONST_LUM:
-               return "BT.2020 Constant Luminance";
-       case V4L2_YCBCR_ENC_SMPTE240M:
-               return "SMPTE 240M";
-       case V4L2_HSV_ENC_180:
-               return "HSV with Hue 0-179";
-       case V4L2_HSV_ENC_256:
-               return "HSV with Hue 0-255";
-       default:
-               return "Unknown (" + num2s(val) + ")";
-       }
-}
-
-std::string quantization2s(int val)
-{
-       switch (val) {
-       case V4L2_QUANTIZATION_DEFAULT:
-               return "Default";
-       case V4L2_QUANTIZATION_FULL_RANGE:
-               return "Full Range";
-       case V4L2_QUANTIZATION_LIM_RANGE:
-               return "Limited Range";
-       default:
-               return "Unknown (" + num2s(val) + ")";
-       }
-}
-
-std::string flags2s(unsigned val, const flag_def *def)
-{
-       std::string s;
-
-       while (def->flag) {
-               if (val & def->flag) {
-                       if (s.length()) s += ", ";
-                       s += def->str;
-                       val &= ~def->flag;
-               }
-               def++;
-       }
-       if (val) {
-               if (s.length()) s += ", ";
-               s += num2s(val);
-       }
-       return s;
-}
-
-
-static const flag_def pixflags_def[] = {
-       { V4L2_PIX_FMT_FLAG_PREMUL_ALPHA,  "premultiplied-alpha" },
-       { 0, NULL }
-};
-
-std::string pixflags2s(unsigned flags)
-{
-       return flags2s(flags, pixflags_def);
-}
-
-static const flag_def service_def[] = {
-       { V4L2_SLICED_TELETEXT_B,  "teletext" },
-       { V4L2_SLICED_VPS,         "vps" },
-       { V4L2_SLICED_CAPTION_525, "cc" },
-       { V4L2_SLICED_WSS_625,     "wss" },
-       { 0, NULL }
-};
-
-std::string service2s(unsigned service)
-{
-       return flags2s(service, service_def);
-}
-
 /*
  * Any pixelformat that is not a YUV format is assumed to be
  * RGB or HSV.
@@ -608,11 +379,6 @@ static bool is_rgb_or_hsv(__u32 pixelformat)
 
 void printfmt(const struct v4l2_format &vfmt)
 {
-       const flag_def vbi_def[] = {
-               { V4L2_VBI_UNSYNC,     "unsynchronized" },
-               { V4L2_VBI_INTERLACED, "interlaced" },
-               { 0, NULL }
-       };
        __u32 colsp = vfmt.fmt.pix.colorspace;
        __u32 ycbcr_enc = vfmt.fmt.pix.ycbcr_enc;
 
@@ -708,7 +474,7 @@ void printfmt(const struct v4l2_format &vfmt)
                printf("\tStart 2nd Field : %u\n", vfmt.fmt.vbi.start[1]);
                printf("\tCount 2nd Field : %u\n", vfmt.fmt.vbi.count[1]);
                if (vfmt.fmt.vbi.flags)
-                       printf("\tFlags           : %s\n", 
flags2s(vfmt.fmt.vbi.flags, vbi_def).c_str());
+                       printf("\tFlags           : %s\n", 
vbiflags2s(vfmt.fmt.vbi.flags).c_str());
                break;
        case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
        case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
@@ -733,17 +499,6 @@ void printfmt(const struct v4l2_format &vfmt)
        }
 }
 
-static const flag_def fmtdesc_def[] = {
-       { V4L2_FMT_FLAG_COMPRESSED, "compressed" },
-       { V4L2_FMT_FLAG_EMULATED, "emulated" },
-       { 0, NULL }
-};
-
-std::string fmtdesc2s(unsigned flags)
-{
-       return flags2s(flags, fmtdesc_def);
-}
-
 void print_video_formats(int fd, __u32 type)
 {
        struct v4l2_fmtdesc fmt;
@@ -779,80 +534,6 @@ int parse_subopt(char **subs, const char * const *subopts, 
char **value)
        return opt;
 }
 
-static std::string partstd2s(const char *prefix, const char *stds[], unsigned 
long long std)
-{
-       std::string s = std::string(prefix) + "-";
-       int first = 1;
-
-       while (*stds) {
-               if (std & 1) {
-                       if (!first)
-                               s += "/";
-                       first = 0;
-                       s += *stds;
-               }
-               stds++;
-               std >>= 1;
-       }
-       return s;
-}
-
-static const char *std_pal[] = {
-       "B", "B1", "G", "H", "I", "D", "D1", "K",
-       "M", "N", "Nc", "60",
-       NULL
-};
-static const char *std_ntsc[] = {
-       "M", "M-JP", "443", "M-KR",
-       NULL
-};
-static const char *std_secam[] = {
-       "B", "D", "G", "H", "K", "K1", "L", "Lc",
-       NULL
-};
-static const char *std_atsc[] = {
-       "8-VSB", "16-VSB",
-       NULL
-};
-
-std::string std2s(v4l2_std_id std)
-{
-       std::string s;
-
-       if (std & 0xfff) {
-               s += partstd2s("PAL", std_pal, std);
-       }
-       if (std & 0xf000) {
-               if (s.length()) s += " ";
-               s += partstd2s("NTSC", std_ntsc, std >> 12);
-       }
-       if (std & 0xff0000) {
-               if (s.length()) s += " ";
-               s += partstd2s("SECAM", std_secam, std >> 16);
-       }
-       if (std & 0xf000000) {
-               if (s.length()) s += " ";
-               s += partstd2s("ATSC", std_atsc, std >> 24);
-       }
-       return s;
-}
-
-void print_v4lstd(v4l2_std_id std)
-{
-       if (std & 0xfff) {
-               printf("\t%s\n", partstd2s("PAL", std_pal, std).c_str());
-       }
-       if (std & 0xf000) {
-               printf("\t%s\n", partstd2s("NTSC", std_ntsc, std >> 
12).c_str());
-       }
-       if (std & 0xff0000) {
-               printf("\t%s\n", partstd2s("SECAM", std_secam, std >> 
16).c_str());
-       }
-       if (std & 0xf000000) {
-               printf("\t%s\n", partstd2s("ATSC", std_atsc, std >> 
24).c_str());
-       }
-}
-
 __u32 parse_field(const char *s)
 {
        if (!strcmp(s, "any")) return V4L2_FIELD_ANY;
@@ -1011,42 +692,6 @@ int parse_fmt(char *optarg, __u32 &width, __u32 &height, 
__u32 &pixelformat,
        return fmts;
 }
 
-const flag_def selection_targets_def[] = {
-       { V4L2_SEL_TGT_CROP_ACTIVE, "crop" },
-       { V4L2_SEL_TGT_CROP_DEFAULT, "crop_default" },
-       { V4L2_SEL_TGT_CROP_BOUNDS, "crop_bounds" },
-       { V4L2_SEL_TGT_COMPOSE_ACTIVE, "compose" },
-       { V4L2_SEL_TGT_COMPOSE_DEFAULT, "compose_default" },
-       { V4L2_SEL_TGT_COMPOSE_BOUNDS, "compose_bounds" },
-       { V4L2_SEL_TGT_COMPOSE_PADDED, "compose_padded" },
-       { V4L2_SEL_TGT_NATIVE_SIZE, "native_size" },
-       { 0, NULL }
-};
-
-std::string seltarget2s(__u32 target)
-{
-       int i = 0;
-
-       while (selection_targets_def[i].str != NULL) {
-               if (selection_targets_def[i].flag == target)
-                       return selection_targets_def[i].str;
-               i++;
-       }
-       return "Unknown";
-}
-
-const flag_def selection_flags_def[] = {
-       { V4L2_SEL_FLAG_GE, "ge" },
-       { V4L2_SEL_FLAG_LE, "le" },
-       { V4L2_SEL_FLAG_KEEP_CONFIG, "keep-config" },
-       { 0, NULL }
-};
-
-std::string selflags2s(__u32 flags)
-{
-       return flags2s(flags, selection_flags_def);
-}
-
 int parse_selection_flags(const char *s)
 {
        if (!strcmp(s, "le")) return V4L2_SEL_FLAG_LE;
diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h
index 06de460fe16e..c50c03071eb6 100644
--- a/utils/v4l2-ctl/v4l2-ctl.h
+++ b/utils/v4l2-ctl/v4l2-ctl.h
@@ -12,6 +12,8 @@
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
 
+#include <v4l2-info.h>
+
 #ifndef NO_LIBV4L2
 #include <libv4l2.h>
 #else
@@ -266,19 +268,7 @@ typedef struct {
 // v4l2-ctl.cpp
 int doioctl_name(int fd, unsigned long int request, void *parm, const char 
*name);
 int test_ioctl(int fd, int cmd, void *arg);
-std::string flags2s(unsigned val, const flag_def *def);
 int parse_subopt(char **subs, const char * const *subopts, char **value);
-std::string std2s(v4l2_std_id std);
-std::string buftype2s(int type);
-std::string fcc2s(unsigned int val);
-std::string fmtdesc2s(unsigned flags);
-std::string colorspace2s(int val);
-std::string xfer_func2s(int val);
-std::string ycbcr_enc2s(int val);
-std::string quantization2s(int val);
-std::string service2s(unsigned service);
-std::string field2s(int val);
-void print_v4lstd(v4l2_std_id std);
 __u32 parse_field(const char *s);
 __u32 parse_colorspace(const char *s);
 __u32 parse_xfer_func(const char *s);
@@ -288,9 +278,6 @@ int parse_fmt(char *optarg, __u32 &width, __u32 &height, 
__u32 &pixelformat,
              __u32 &field, __u32 &colorspace, __u32 &xfer, __u32 &ycbcr,
              __u32 &quantization, __u32 &flags, __u32 *bytesperline);
 int parse_selection_target(const char *s, unsigned int &target);
-extern const flag_def selection_targets_def[];
-std::string seltarget2s(__u32 target);
-std::string selflags2s(__u32 flags);
 int parse_selection_flags(const char *s);
 void print_selection(const struct v4l2_selection &sel);
 __u32 find_pixel_format(int fd, unsigned index, bool output, bool mplane);

_______________________________________________
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

Reply via email to