From patchwork Wed Mar 25 22:02:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 3322 Return-Path: Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3F1F760413 for ; Wed, 25 Mar 2020 23:03:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=es-iitr-ac-in.20150623.gappssmtp.com header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b="PHFjIBkI"; dkim-atps=neutral Received: by mail-pf1-x42e.google.com with SMTP id b72so1726421pfb.11 for ; Wed, 25 Mar 2020 15:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=x+wzOSQPHTbsilf0h6r+izYDfTQnprPFenPKccdmsJk=; b=PHFjIBkI9M5BNJJ3X2C/MJ8KMURVp5RbnTDKuPYYUPQJjdoZfIy3SZSFrJcaBYEmz2 Jp5v//jC7X6OMzCDWmiZkyVF7+XLTm3m8ZKXq+XHLkUiE84M/K9aqpe40o3g3mZxYU0p 0FUk1s1z4bk9y9373b3FsbE5yK2JV/OZr19JjG1Z+pB+QWBijg3nGVNm/FC9eMsTUDx8 OU/91SIoqG8sqOyQDOgVz9JzVtu7xfgFZTzTAOqthFKl/eorJYstJ8AZL4M/77u4ZWHA egg6Cr8iigoyAXkFRK0MAu4QQ9PdQZyUYAdARxMXIoPJ4PTavcRt2S1g5wLgZMhzaEjZ HqLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=x+wzOSQPHTbsilf0h6r+izYDfTQnprPFenPKccdmsJk=; b=R4CzwfyjTjHC00kEwlHW4QMh9lFZGqrAHpyW8skAXX519KtsLQzvvYCrqwfMhO6GC6 J7QXE//NLNer8X0ZIsopQuhRDX9RO8NWDBFFqYXLdhbIgajuepy9NUK9h5FyrQq7A1ev pU6UKesEuG0N7hXpii5cs2D9asOX1yWiYCxVbx2JK3EeE61wuZCCSUi1Zh/2PDAdR9sY QX9MQGzk9FJdhTTledtCpVJALM8nRp913q09KaG7WvPKWRHLfTXJaModC9eSNPkQRFk0 9OJ1r1BCLcjX6c7PKtkg9LhjgFGbFBrE0UOs55pq7w+20c1UaDRbVqoH7CqVuZvvkVSE Gf+g== X-Gm-Message-State: ANhLgQ2UnZkZ0v80oZKa1u3MJ3hAKO2cR1D85T4tki0+KY24osrk2X9F MLgAIOsVWt1Alt3ASNbn3aBJ0h+dkylsZw== X-Google-Smtp-Source: ADFU+vu0WD6uL0tDlha43+YlG3Acgo33Bi0v/8s7hVVKuhD0YoID2vAJWOqcbxapBOmB/2mkbfHmmQ== X-Received: by 2002:aa7:8b46:: with SMTP id i6mr5827437pfd.60.1585173779513; Wed, 25 Mar 2020 15:02:59 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.154]) by smtp.gmail.com with ESMTPSA id b189sm95936pfa.209.2020.03.25.15.02.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Mar 2020 15:02:58 -0700 (PDT) Date: Thu, 26 Mar 2020 03:32:52 +0530 From: Kaaira Gupta To: libcamera-devel@lists.libcamera.org, Kieran Bingham , Helen Koike , Vaishali Thakkar Message-ID: <20200325220252.GA14374@kaaira-HP-Pavilion-Notebook> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Subject: [libcamera-devel] [PATCH v2] libcamera: v4l2PixelFormat: Replace hex with fourCC X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Mar 2020 22:03:04 -0000 Print fourCC characters instead of the hex value in toString() as they are more informative. Also, write the tests for this in formats.cpp Signed-off-by: Kaaira Gupta --- Changes since v1: - Add tests for checking this function. - use char[] instead of stringstream. - add checks for default value. - Print '.' for non-printable characters. src/libcamera/v4l2_videodevice.cpp | 19 ++++++++++++++++--- test/v4l2_videodevice/formats.cpp | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index b778181..f5c14aa 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -336,9 +336,22 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const */ std::string V4L2PixelFormat::toString() const { - char str[11]; - snprintf(str, 11, "0x%08x", fourcc_); - return str; + if (fourcc_ == 0) + return "Invalid"; + + char ss[7] = {static_cast(fourcc_ & 0x7f), + static_cast((fourcc_ >> 8) & 0x7f), + static_cast((fourcc_ >> 16) & 0x7f), + static_cast((fourcc_ >> 24) & 0x7f)}; + + for (unsigned int i = 0; i < strlen(ss); i++){ + if (!isprint(ss[i])) + ss[i]= '.'; + } + + if (fourcc_ & (1 << 31)) + strcat(ss, "-BE"); + return ss; } /** diff --git a/test/v4l2_videodevice/formats.cpp b/test/v4l2_videodevice/formats.cpp index d504d17..f129c5c 100644 --- a/test/v4l2_videodevice/formats.cpp +++ b/test/v4l2_videodevice/formats.cpp @@ -47,6 +47,21 @@ protected: return TestFail; } + auto badfourcc = v4l2_fourcc( 1, 2, 3, 4 ); + std::vector> formats{ + {V4L2_PIX_FMT_YUYV,"YUYV"},{0, "Invalid"}, {badfourcc, "...."}, + {V4L2_PIX_FMT_Y16_BE,"Y16 -BE"}}; + + for (const auto &format :formats){ + if (V4L2PixelFormat(format.first).toString()!=format.second){ + return TestFail; + } + } + + if (V4L2PixelFormat().toString() != "Invalid"){ + return TestFail; + } + return TestPass; } };