]> granicus.if.org Git - strace/blobdiff - v4l2.c
Remove XLAT_END
[strace] / v4l2.c
diff --git a/v4l2.c b/v4l2.c
index edc06f2fcd2d1709eb275045752493a8ea7dc740..afa5d443412f67cb547ffd09dbcb84ecc47bac72 100644 (file)
--- a/v4l2.c
+++ b/v4l2.c
@@ -2,7 +2,7 @@
  * Copyright (c) 2014 Philippe De Muyter <phdm@macqel.be>
  * Copyright (c) 2014 William Manley <will@williammanley.net>
  * Copyright (c) 2011 Peter Zotov <whitequark@whitequark.org>
- * Copyright (c) 2014-2018 The strace developers.
+ * Copyright (c) 2014-2019 The strace developers.
  * All rights reserved.
  *
  * SPDX-License-Identifier: LGPL-2.1-or-later
@@ -42,11 +42,12 @@ typedef struct v4l2_standard struct_v4l2_standard;
 #include MPERS_DEFS
 
 #include "print_fields.h"
+#include "print_utils.h"
 #include "xstring.h"
 
 /* v4l2_fourcc_be was added by Linux commit v3.18-rc1~101^2^2~127 */
 #ifndef v4l2_fourcc_be
-# define v4l2_fourcc_be(a, b, c, d) (v4l2_fourcc(a, b, c, d) | (1 << 31))
+# define v4l2_fourcc_be(a, b, c, d) (v4l2_fourcc(a, b, c, d) | (1U << 31))
 #endif
 
 #define FMT_FRACT "%u/%u"
@@ -70,6 +71,7 @@ print_pixelformat(uint32_t fourcc, const struct xlat *xlat)
        unsigned int i;
 
        tprints("v4l2_fourcc(");
+       /* Generic char array printing routine.  */
        for (i = 0; i < ARRAY_SIZE(a); ++i) {
                unsigned char c = a[i];
 
@@ -84,7 +86,7 @@ print_pixelformat(uint32_t fourcc, const struct xlat *xlat)
                                '\0'
                        };
                        tprints(sym);
-               } else if (c >= ' ' && c <= 0x7e) {
+               } else if (is_print(c)) {
                        char sym[] = {
                                '\'',
                                c,
@@ -94,12 +96,7 @@ print_pixelformat(uint32_t fourcc, const struct xlat *xlat)
                        tprints(sym);
                } else {
                        char hex[] = {
-                               '\'',
-                               '\\',
-                               'x',
-                               "0123456789abcdef"[c >> 4],
-                               "0123456789abcdef"[c & 0xf],
-                               '\'',
+                               BYTE_HEX_CHARS_PRINTF_QUOTED(c),
                                '\0'
                        };
                        tprints(hex);
@@ -136,7 +133,7 @@ print_v4l2_capability(struct tcb *const tcp, const kernel_ulong_t arg)
                caps.version & 0xFF);
        printflags(v4l2_device_capabilities_flags, caps.capabilities,
                   "V4L2_CAP_???");
-#ifdef V4L2_CAP_DEVICE_CAPS
+#ifdef HAVE_STRUCT_V4L2_CAPABILITY_DEVICE_CAPS
        tprints(", device_caps=");
        printflags(v4l2_device_capabilities_flags, caps.device_caps,
                   "V4L2_CAP_???");
@@ -207,7 +204,7 @@ print_v4l2_format_fmt(struct tcb *const tcp, const char *prefix,
                          "V4L2_COLORSPACE_???");
                tprints("}");
                break;
-#if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
+#if HAVE_STRUCT_V4L2_FORMAT_FMT_PIX_MP
        case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
        case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: {
                unsigned int i, max;
@@ -238,9 +235,7 @@ print_v4l2_format_fmt(struct tcb *const tcp, const char *prefix,
        }
 #endif
        /* OUTPUT_OVERLAY since Linux v2.6.22-rc1~1118^2~179 */
-#if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
        case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-#endif
        case V4L2_BUF_TYPE_VIDEO_OVERLAY: {
                struct_v4l2_clip clip;
                tprints(prefix);
@@ -275,7 +270,7 @@ print_v4l2_format_fmt(struct tcb *const tcp, const char *prefix,
                tprints("}");
                break;
        /* both since Linux v2.6.14-rc2~64 */
-#if HAVE_DECL_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
+#if HAVE_STRUCT_V4L2_FORMAT_FMT_SLICED
        case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
        case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: {
                unsigned int i, j;
@@ -304,12 +299,10 @@ print_v4l2_format_fmt(struct tcb *const tcp, const char *prefix,
                break;
        }
 #endif
+#if HAVE_STRUCT_V4L2_FORMAT_FMT_SDR
        /* since Linux v4.4-rc1~118^2~14 */
-#if HAVE_DECL_V4L2_BUF_TYPE_SDR_OUTPUT
        case V4L2_BUF_TYPE_SDR_OUTPUT:
-#endif
        /* since Linux v3.15-rc1~85^2~213 */
-#if HAVE_DECL_V4L2_BUF_TYPE_SDR_CAPTURE
        case V4L2_BUF_TYPE_SDR_CAPTURE:
                tprints(prefix);
                tprints("fmt.sdr={pixelformat=");
@@ -601,6 +594,34 @@ print_v4l2_input(struct tcb *const tcp, const kernel_ulong_t arg)
 #include "xlat/v4l2_control_id_bases.h"
 #include "xlat/v4l2_control_ids.h"
 
+static void
+print_v4l2_cid(const uint32_t cid)
+{
+       const char *id_name = xlookup(v4l2_control_ids, cid);
+
+       if (id_name) {
+               print_xlat_ex(cid, id_name, XLAT_STYLE_DEFAULT);
+               return;
+       }
+
+       uint64_t class_id = cid;
+       const char *class_str = xlookup_le(v4l2_control_classes, &class_id);
+
+       if (!class_str || (cid - class_id) >= 0x10000) {
+               print_xlat_ex(cid, "V4L2_CID_???", PXF_DEFAULT_STR);
+               return;
+       }
+
+       char *tmp_str;
+
+       if (asprintf(&tmp_str, "%s+%#" PRIx64,
+                    class_str, cid - class_id) < 0)
+               tmp_str = NULL;
+
+       print_xlat_ex(cid, tmp_str, XLAT_STYLE_DEFAULT);
+       free(tmp_str);
+}
+
 static int
 print_v4l2_control(struct tcb *const tcp, const kernel_ulong_t arg,
                   const bool is_get)
@@ -611,8 +632,9 @@ print_v4l2_control(struct tcb *const tcp, const kernel_ulong_t arg,
                tprints(", ");
                if (umove_or_printaddr(tcp, arg, &c))
                        return RVAL_IOCTL_DECODED;
+
                tprints("{id=");
-               printxval(v4l2_control_ids, c.id, "V4L2_CID_???");
+               print_v4l2_cid(c.id);
                if (!is_get)
                        tprintf(", value=%d", c.value);
                return 0;
@@ -787,7 +809,7 @@ print_v4l2_ext_control(struct tcb *tcp, void *elem_buf, size_t elem_size, void *
 
        tprints("{id=");
        printxval(v4l2_control_ids, p->id, "V4L2_CID_???");
-# if HAVE_DECL_V4L2_CTRL_TYPE_STRING
+# if HAVE_STRUCT_V4L2_EXT_CONTROL_STRING
        tprintf(", size=%u", p->size);
        if (p->size > 0) {
                tprints(", string=");