{"id":3343,"url":"https://patchwork.libcamera.org/api/1.1/patches/3343/?format=json","web_url":"https://patchwork.libcamera.org/patch/3343/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200326201400.GA29067@kaaira-HP-Pavilion-Notebook>","date":"2020-03-26T20:14:00","name":"[libcamera-devel,v4] libcamera: v4l2PixelFormat: Replace hex with fourCC","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"0dc0dc61e565b4dbfd353752886e26c797778906","submitter":{"id":39,"url":"https://patchwork.libcamera.org/api/1.1/people/39/?format=json","name":"Kaaira Gupta","email":"kgupta@es.iitr.ac.in"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3343/mbox/","series":[{"id":784,"url":"https://patchwork.libcamera.org/api/1.1/series/784/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=784","date":"2020-03-26T20:14:00","name":"[libcamera-devel,v4] libcamera: v4l2PixelFormat: Replace hex with fourCC","version":4,"mbox":"https://patchwork.libcamera.org/series/784/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3343/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3343/checks/","tags":{},"headers":{"Return-Path":"<kgupta@es.iitr.ac.in>","Received":["from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com\n\t[IPv6:2607:f8b0:4864:20::52b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 14D9960412\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Mar 2020 21:14:10 +0100 (CET)","by mail-pg1-x52b.google.com with SMTP id a32so3458932pga.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Mar 2020 13:14:09 -0700 (PDT)","from kaaira-HP-Pavilion-Notebook ([103.113.213.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tj38sm2231342pgi.51.2020.03.26.13.14.05\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tThu, 26 Mar 2020 13:14:07 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=es-iitr-ac-in.20150623.gappssmtp.com\n\theader.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b=\"YE76cruy\"; \n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:subject:message-id:mime-version:content-disposition\n\t:user-agent; bh=+WwGuhGPhcludT0HCtl5ArqUofjOoNPxiNxH8uvRPE8=;\n\tb=YE76cruyAzRVPF7slyMCSAk5SoY3Cf+gsgQ/bqlc6ykVfsGZXqkI9brvwapuBgSqJZ\n\tHXwN5ZQ7b9qVqRPKO/kz/V7eS1keEXxiXKpET7fWGURyct+mT83t0ljRREWqYWn/4gG5\n\tVBzXcAkpvWZVTns+QPU9mBvqCz6Z/UC1ANUo6heEqnYta1tn5QltoLLSm1xOMgV27zQJ\n\tgmBNecEe/cVNz8TmnImO6wslbJZi5wxBeZD8/ae9nXsSZGxFmGBMqqituj9ty3jpgFsZ\n\teFLvLG0tVu3SPSXD4XWaYl6CGSObvCBP0z8rtJKpr2LV0f03hjHx0QIoxsjRVePVMG5X\n\tpvuw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:subject:message-id:mime-version\n\t:content-disposition:user-agent;\n\tbh=+WwGuhGPhcludT0HCtl5ArqUofjOoNPxiNxH8uvRPE8=;\n\tb=E1PLNE3ShtxsbS4x1PbaEptVK0UXmaz3UpqWHyBGbRw38xTlEwprYZoIkj0CVGzDwW\n\t0OmnMSNQ0ECkR0u31axU8WIxDtQStBLFnRgWnhHgZk2w7U/+yO4clzUtRnAhsf/lT9bf\n\tl1zIjl2xZ1FEQfQlFKOVGvxeGiKSaxJhTo2YmBidWSBQv9TKJjjqPVp7N/upZjDXt3lG\n\twZ0OPqeH8pcHGwG5gRqMo5MQM+icZAX6GcPnfZJ0mTu4fPAykLBTWw1JXfFuv7DiZLUT\n\tCdiJHY2QFfoQN80kLFsYVJ4jJKl9P9Tzi7BOLkJVkukor9xN3ek7/znQBDMBeHig7jTJ\n\tNxVw==","X-Gm-Message-State":"ANhLgQ2TbBNKA27f2Ha9TEFkDJdyKpAwVL7XGEpoWSzyn5KQu+OoR1O/\n\tW18+YgJY1i3018dcvuglslsmvmuw7hgiwQ==","X-Google-Smtp-Source":"ADFU+vv3VXOZCAeyopcZ3v3+OG/oONCtYHo2gnvAA2OrwEpL6rKQyKyuSZKJE5Xa++lVFUdj+kq2HQ==","X-Received":"by 2002:a63:b557:: with SMTP id\n\tu23mr10301653pgo.160.1585253647875; \n\tThu, 26 Mar 2020 13:14:07 -0700 (PDT)","Date":"Fri, 27 Mar 2020 01:44:00 +0530","From":"Kaaira Gupta <kgupta@es.iitr.ac.in>","To":"libcamera-devel@lists.libcamera.org,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tHelen Koike <helen.koike@collabora.com>,\n\tVaishali Thakkar <vthakkar@vaishalithakkar.in>","Message-ID":"<20200326201400.GA29067@kaaira-HP-Pavilion-Notebook>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","User-Agent":"Mutt/1.9.4 (2018-02-28)","Subject":"[libcamera-devel] [PATCH v4] libcamera: v4l2PixelFormat: Replace\n\thex with fourCC","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Thu, 26 Mar 2020 20:14:10 -0000"},"content":"Print fourCC characters instead of the hex value in toString() as they are\nmore informative. Also, write the tests for this in formats.cpp\n\nSigned-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>\n---\n\nChanges since v3:\n\t- Reformatted the code\n\t- Changed 'invalid' to \"<INVALID>\"\n\t- Changed cerr message.\n\nChanges since v2:\n        - reformatted the code\n        - added cerr messages before TestFail\n        - Changed test case to accomodate edge case\n        - Increased buffer size of char array\n        - Changed the maximum length of for loop.\n\nChanges since v1:\n        - Add tests for checking this function.\n        - use char[] instead of stringstream.\n        - add checks for default value.\n        - Print '.' for non-printable characters.\n\n src/libcamera/v4l2_videodevice.cpp | 20 +++++++++++++++++---\n test/v4l2_videodevice/formats.cpp  | 22 ++++++++++++++++++++++\n 2 files changed, 39 insertions(+), 3 deletions(-)","diff":"diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex b778181..eb33a68 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -336,9 +336,23 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n  */\n std::string V4L2PixelFormat::toString() const\n {\n-\tchar str[11];\n-\tsnprintf(str, 11, \"0x%08x\", fourcc_);\n-\treturn str;\n+\tif (fourcc_ == 0)\n+\t\treturn \"<INVALID>\";\n+\n+\tchar ss[8] = { static_cast<char>(fourcc_ & 0x7f),\n+\t\t       static_cast<char>((fourcc_ >> 8) & 0x7f),\n+\t\t       static_cast<char>((fourcc_ >> 16) & 0x7f),\n+\t\t       static_cast<char>((fourcc_ >> 24) & 0x7f) };\n+\n+\tfor (unsigned int i = 0; i < 4; i++) {\n+\t\tif (!isprint(ss[i]))\n+\t\t\tss[i] = '.';\n+\t}\n+\n+\tif (fourcc_ & (1 << 31))\n+\t\tstrcat(ss, \"-BE\");\n+\n+\treturn ss;\n }\n \n /**\ndiff --git a/test/v4l2_videodevice/formats.cpp b/test/v4l2_videodevice/formats.cpp\nindex d504d17..d01eccd 100644\n--- a/test/v4l2_videodevice/formats.cpp\n+++ b/test/v4l2_videodevice/formats.cpp\n@@ -47,6 +47,28 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\tstd::vector<std::pair<uint32_t, const char*>> formats{\n+\t\t\t{ V4L2_PIX_FMT_YUYV, \"YUYV\" },\n+\t\t\t{ 0, \"<INVALID>\" },\n+\t\t\t{ v4l2_fourcc(0, 1, 2, 3), \"....\" },\n+\t\t\t{ V4L2_PIX_FMT_Y16_BE, \"Y16 -BE\" }\n+\t\t};\n+\n+\t\tfor (const auto &format : formats) {\n+\t\t\tif (V4L2PixelFormat(format.first).toString() != format.second) {\n+\t\t\t\tcerr << \"Failed to convert V4L2PixelFormat\"\n+\t\t\t\t     << utils::hex(format.first) << \"to string\"\n+\t\t\t\t     << endl;\n+\t\t\t\treturn TestFail;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (V4L2PixelFormat().toString() != \"<INVALID>\") {\n+\t\t\tcerr << \"Failed to convert default V4L2PixelFormat to string\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\treturn TestPass;\n \t}\n };\n","prefixes":["libcamera-devel","v4"]}