[{"id":4284,"web_url":"https://patchwork.libcamera.org/comment/4284/","msgid":"<20200325123933.GD19171@pendragon.ideasonboard.com>","date":"2020-03-25T12:39:33","subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kaaira,\n\nThank you for the patch.\n\nOn Wed, Mar 25, 2020 at 05:58:25PM +0530, Kaaira Gupta wrote:\n> Print 4CC characters instead of the hex value in toString() as they are\n> more informative.\n> \n> Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>\n> ---\n>  src/libcamera/v4l2_videodevice.cpp | 12 +++++++++---\n>  1 file changed, 9 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index b778181..ea8ee50 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -336,9 +336,15 @@ 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> +\tstd::stringstream ss;\n\nGiven that the string will be at mose 7 characters long, and the first\nfour characters are individually computed, a stringstream seems\noverkill. You can use a plain char[] buffer and write to it directly.\n\n> +\tss << static_cast<char>(fourcc_ & 0x7f)\n\nWhy 7 bits only ?\n\n> +\t   << static_cast<char>((fourcc_ >> 8) & 0x7f)\n> +\t   << static_cast<char>((fourcc_ >> 16) & 0x7f)\n> +\t   << static_cast<char>((fourcc_ >> 24) & 0x7f);\n\nWhat happens if any of these values is non-printable ? What if it's a\nNUL character ? Or a newline ? We shouldn't have such cases normally in\nV4L2 4CCs, but should we protect against that ?\n\nThere's also the case of a default-constructed V4L2PixelFormat, fourcc_\nwill be 0 in that case.\n\nCould you also please add a test case for this function ?\n\n> +\n> +\tif (fourcc_ & (1 << 31))\n> +\t\tss << \"-BE\";\n> +\treturn ss.str();\n>  }\n>  \n>  /**","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C321E60413\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Mar 2020 13:39:36 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D748C80C;\n\tWed, 25 Mar 2020 13:39:35 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"uBB3mKzU\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1585139976;\n\tbh=nUKsenRuiysYWpK9s+oWgE4Eht20E22lyMwEItKIK2U=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=uBB3mKzU9K5F990AFkEVw1sjQQZyAE806HYz/2tcsXpy+ja7NEd8JAmEzcSE33bDE\n\t4KX1rnXJbdAVBbcBNjDVgTcRdESMx1rcTAGmGh6jwR9auGmStu4z5BcLj+KSfjqoiE\n\tL04D6wHh9qCAOEmOlWugEZdmoReC9adSZcoQ5ZHY=","Date":"Wed, 25 Mar 2020 14:39:33 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kaaira Gupta <kgupta@es.iitr.ac.in>","Cc":"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":"<20200325123933.GD19171@pendragon.ideasonboard.com>","References":"<20200325122825.GA16172@kaaira-HP-Pavilion-Notebook>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200325122825.GA16172@kaaira-HP-Pavilion-Notebook>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","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":"Wed, 25 Mar 2020 12:39:37 -0000"}},{"id":4285,"web_url":"https://patchwork.libcamera.org/comment/4285/","msgid":"<91327f2b-dc77-1fd8-2a62-e1201a79dc32@ideasonboard.com>","date":"2020-03-25T13:12:09","subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 25/03/2020 12:39, Laurent Pinchart wrote:\n> Hi Kaaira,\n> \n> Thank you for the patch.\n> \n> On Wed, Mar 25, 2020 at 05:58:25PM +0530, Kaaira Gupta wrote:\n>> Print 4CC characters instead of the hex value in toString() as they are\n>> more informative.\n>>\n>> Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>\n>> ---\n>>  src/libcamera/v4l2_videodevice.cpp | 12 +++++++++---\n>>  1 file changed, 9 insertions(+), 3 deletions(-)\n>>\n>> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n>> index b778181..ea8ee50 100644\n>> --- a/src/libcamera/v4l2_videodevice.cpp\n>> +++ b/src/libcamera/v4l2_videodevice.cpp\n>> @@ -336,9 +336,15 @@ 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>> +\tstd::stringstream ss;\n> \n> Given that the string will be at mose 7 characters long, and the first\n> four characters are individually computed, a stringstream seems\n> overkill. You can use a plain char[] buffer and write to it directly.\n> \n>> +\tss << static_cast<char>(fourcc_ & 0x7f)\n> \n> Why 7 bits only ?\n\n\nThis code follows the patch submitted by Sakari/Hans which was destined\nto go into the V4L2 UAPI header - but seems stalled for no apparent\nreason. It has only positive feedback but didn't progress:\n\nhttps://lore.kernel.org/linux-media/20190916100433.24367-2-hverkuil-cisco@xs4all.nl/\n\n\n\n> \n>> +\t   << static_cast<char>((fourcc_ >> 8) & 0x7f)\n>> +\t   << static_cast<char>((fourcc_ >> 16) & 0x7f)\n>> +\t   << static_cast<char>((fourcc_ >> 24) & 0x7f);\n> \n> What happens if any of these values is non-printable ? What if it's a\n> NUL character ? Or a newline ? We shouldn't have such cases normally in\n> V4L2 4CCs, but should we protect against that ?\n\nI don't think so no. V4L2PixelFormat is *only* an internal thing. It\nshould never be exposed to an application, or to user input.\n\nIf A V4L2 device has a NULL, newline or unprintable character, I suspect\nit's a bug in the kernel.\n\n\n> There's also the case of a default-constructed V4L2PixelFormat, fourcc_\n> will be 0 in that case.\n\nfourcc_ == 0 should indeed be guarded though, and return something like\n<NONE> or <EMPTY>\n\n\n> Could you also please add a test case for this function ?\n>>> +\n>> +\tif (fourcc_ & (1 << 31))\n>> +\t\tss << \"-BE\";\n>> +\treturn ss.str();\n>>  }\n>>  \n>>  /**\n>","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 153B260413\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Mar 2020 14:12:13 +0100 (CET)","from [192.168.0.20]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 47DCB80C;\n\tWed, 25 Mar 2020 14:12:12 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"tnsOpE61\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1585141932;\n\tbh=BEM1jduXa/NYjiVepCq5IMlJxkUeWMTD1bHN8y8+5Fc=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=tnsOpE619cQ1MBFNFqYH3r1QaogM+6mxCzEFtGuaXNqaow6Z5f1KITcxFej6YLiYC\n\tWFlvTTWA1RJMX3kHYDAVEj5a9w7VvknCT1pR4FvIk+BfOmWRFYtZSEw2gGMkbc+AuV\n\tTvebCtJX5xXdEHetC6ryl5BCelD5GyIfejZP3ZBo=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tKaaira Gupta <kgupta@es.iitr.ac.in>","Cc":"libcamera-devel@lists.libcamera.org,\n\tHelen Koike <helen.koike@collabora.com>,\n\tVaishali Thakkar <vthakkar@vaishalithakkar.in>","References":"<20200325122825.GA16172@kaaira-HP-Pavilion-Notebook>\n\t<20200325123933.GD19171@pendragon.ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\t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\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<91327f2b-dc77-1fd8-2a62-e1201a79dc32@ideasonboard.com>","Date":"Wed, 25 Mar 2020 13:12:09 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.9.1","MIME-Version":"1.0","In-Reply-To":"<20200325123933.GD19171@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","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":"Wed, 25 Mar 2020 13:12:13 -0000"}},{"id":4286,"web_url":"https://patchwork.libcamera.org/comment/4286/","msgid":"<20200325131327.GA17937@kaaira-HP-Pavilion-Notebook>","date":"2020-03-25T13:13:27","subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","submitter":{"id":39,"url":"https://patchwork.libcamera.org/api/people/39/","name":"Kaaira Gupta","email":"kgupta@es.iitr.ac.in"},"content":"On Wed, Mar 25, 2020 at 02:39:33PM +0200, Laurent Pinchart wrote:\n> Hi Kaaira,\n> \n> Thank you for the patch.\n> \n> On Wed, Mar 25, 2020 at 05:58:25PM +0530, Kaaira Gupta wrote:\n> > Print 4CC characters instead of the hex value in toString() as they are\n> > more informative.\n> > \n> > Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>\n> > ---\n> >  src/libcamera/v4l2_videodevice.cpp | 12 +++++++++---\n> >  1 file changed, 9 insertions(+), 3 deletions(-)\n> > \n> > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> > index b778181..ea8ee50 100644\n> > --- a/src/libcamera/v4l2_videodevice.cpp\n> > +++ b/src/libcamera/v4l2_videodevice.cpp\n> > @@ -336,9 +336,15 @@ 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> > +\tstd::stringstream ss;\n> \n> Given that the string will be at mose 7 characters long, and the first\n> four characters are individually computed, a stringstream seems\n> overkill. You can use a plain char[] buffer and write to it directly.\n\nYes, I'll do that\n\n> \n> > +\tss << static_cast<char>(fourcc_ & 0x7f)\n> \n> Why 7 bits only ?\n> \n> > +\t   << static_cast<char>((fourcc_ >> 8) & 0x7f)\n> > +\t   << static_cast<char>((fourcc_ >> 16) & 0x7f)\n> > +\t   << static_cast<char>((fourcc_ >> 24) & 0x7f);\n> \n> What happens if any of these values is non-printable ? What if it's a\n> NUL character ? Or a newline ? We shouldn't have such cases normally in\n> V4L2 4CCs, but should we protect against that ?\n\nYes, I'll add these cases too\n\n> \n> There's also the case of a default-constructed V4L2PixelFormat, fourcc_\n> will be 0 in that case.\n> \n> Could you also please add a test case for this function ?\n\nHow should I do that? When I made the changes and wanted to check my\noutputs, I just printed format.fourcc.toString() in \ntest/v4l2_videodevice/v4l2_videodevice_test.cpp...what is the correct\nway to write a test?\n\n> \n> > +\n> > +\tif (fourcc_ & (1 << 31))\n> > +\t\tss << \"-BE\";\n> > +\treturn ss.str();\n> >  }\n> >  \n> >  /**\n> \n> -- \n> Regards,\n> \n> Laurent Pinchart","headers":{"Return-Path":"<kgupta@es.iitr.ac.in>","Received":["from mail-pg1-x541.google.com (mail-pg1-x541.google.com\n\t[IPv6:2607:f8b0:4864:20::541])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 409FD60413\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Mar 2020 14:13:36 +0100 (CET)","by mail-pg1-x541.google.com with SMTP id u12so1120567pgb.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Mar 2020 06:13:36 -0700 (PDT)","from kaaira-HP-Pavilion-Notebook ([103.113.213.154])\n\tby smtp.gmail.com with ESMTPSA id\n\to33sm4463299pje.19.2020.03.25.06.13.31\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tWed, 25 Mar 2020 06:13:34 -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=\"tn73ZqkQ\"; \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=from:date:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:in-reply-to:user-agent;\n\tbh=CbF7lx3jZoiHc19O7n2dbE+rdTYQNEDUcOfixpy9/mg=;\n\tb=tn73ZqkQc/ch1DOa8n3zY6Am9w5/jSPwJAO4+4vJYwiUTpUaqq6nuJNXW0m8c+/Qm5\n\tHrnEDq/ddMXThPtOAp8HvJkXx07Eq3GYbWFVqO6y4kaQo1OJSxo0W4t26s8ZFnCfrOhu\n\tnf+sb/v81QpEyo0GPFpcqu2gHQwyWpKTTbPnZyI8C7ikujJ+s0/FmddBpgYLAdgaqC5z\n\t4xAY5YAgIVVnbX0wfUOW5wuOjsBVnSNx5nyHu65kT5N11V7hZXO/D5K/GrOzTd718HiJ\n\tkUYIUwkGweXXHVARntX4tTVkN2TMtV9elF9LvPkYFPjD+LV91P7f1lnQVJvBCI1g5Gx7\n\tBYag==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:date:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:in-reply-to:user-agent;\n\tbh=CbF7lx3jZoiHc19O7n2dbE+rdTYQNEDUcOfixpy9/mg=;\n\tb=mEbfkKshAip2VrHPielMb1Q1+Wwm5vFmz+Zxcotyf93Hl3qPtmNfwjbLztl0xYkPTE\n\tZTiDdWx47ezrIAvgnWlBz/CVLS49Hhdty7hEq242Evqogv8G/MZ9NgvKam8xhzGEXiHT\n\t0zEOZGj/i4NKaCx8Vt+ELY7KnZvPrDjNMEBcEDoOQ4CkuBV0rcEaNSv1EjLkZvDQ/SPU\n\to5CtR/fESD+gR5Z8ci+kVMfSgA8l/kGkuuMouxscIW3akMQoB8/liYcTSsvldahWpJi5\n\tnLsOW6ZdtRZPYFaHe0VGUtH9MvyJkS0VquMtvGK84G7BxtUEGdhJyftVMiiDxxFswBwU\n\t4nvw==","X-Gm-Message-State":"ANhLgQ0W+er/qHLB28xYH+yEdQVWMO49DhFbfGGgrA2qM2kX1bebyaUq\n\tZ7TOZ8GasWOC1VITlfUxwe5qeQZs0D+6+g==","X-Google-Smtp-Source":"ADFU+vtWfHM3/jxC4qihnKoULPshVDoskXfKzY1FGNxjuKTXDVM/gffR1GeCAIJEV2S93t1/R8YIgw==","X-Received":"by 2002:a63:ec44:: with SMTP id r4mr2964730pgj.425.1585142014748;\n\tWed, 25 Mar 2020 06:13:34 -0700 (PDT)","From":"Kaaira Gupta <kgupta@es.iitr.ac.in>","X-Google-Original-From":"Kaaira Gupta <Kaairakgupta@es.iitr.ac.in>","Date":"Wed, 25 Mar 2020 18:43:27 +0530","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Kaaira Gupta <kgupta@es.iitr.ac.in>, 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":"<20200325131327.GA17937@kaaira-HP-Pavilion-Notebook>","References":"<20200325122825.GA16172@kaaira-HP-Pavilion-Notebook>\n\t<20200325123933.GD19171@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20200325123933.GD19171@pendragon.ideasonboard.com>","User-Agent":"Mutt/1.9.4 (2018-02-28)","Subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","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":"Wed, 25 Mar 2020 13:13:36 -0000"}},{"id":4287,"web_url":"https://patchwork.libcamera.org/comment/4287/","msgid":"<20200325132845.GF19171@pendragon.ideasonboard.com>","date":"2020-03-25T13:28:45","subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nOn Wed, Mar 25, 2020 at 01:12:09PM +0000, Kieran Bingham wrote:\n> On 25/03/2020 12:39, Laurent Pinchart wrote:\n> > On Wed, Mar 25, 2020 at 05:58:25PM +0530, Kaaira Gupta wrote:\n> >> Print 4CC characters instead of the hex value in toString() as they are\n> >> more informative.\n> >>\n> >> Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>\n> >> ---\n> >>  src/libcamera/v4l2_videodevice.cpp | 12 +++++++++---\n> >>  1 file changed, 9 insertions(+), 3 deletions(-)\n> >>\n> >> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> >> index b778181..ea8ee50 100644\n> >> --- a/src/libcamera/v4l2_videodevice.cpp\n> >> +++ b/src/libcamera/v4l2_videodevice.cpp\n> >> @@ -336,9 +336,15 @@ 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> >> +\tstd::stringstream ss;\n> > \n> > Given that the string will be at mose 7 characters long, and the first\n> > four characters are individually computed, a stringstream seems\n> > overkill. You can use a plain char[] buffer and write to it directly.\n> > \n> >> +\tss << static_cast<char>(fourcc_ & 0x7f)\n> > \n> > Why 7 bits only ?\n> \n> This code follows the patch submitted by Sakari/Hans which was destined\n> to go into the V4L2 UAPI header - but seems stalled for no apparent\n> reason. It has only positive feedback but didn't progress:\n> \n> https://lore.kernel.org/linux-media/20190916100433.24367-2-hverkuil-cisco@xs4all.nl/\n> \n> >> +\t   << static_cast<char>((fourcc_ >> 8) & 0x7f)\n> >> +\t   << static_cast<char>((fourcc_ >> 16) & 0x7f)\n> >> +\t   << static_cast<char>((fourcc_ >> 24) & 0x7f);\n> > \n> > What happens if any of these values is non-printable ? What if it's a\n> > NUL character ? Or a newline ? We shouldn't have such cases normally in\n> > V4L2 4CCs, but should we protect against that ?\n> \n> I don't think so no. V4L2PixelFormat is *only* an internal thing. It\n> should never be exposed to an application, or to user input.\n> \n> If A V4L2 device has a NULL, newline or unprintable character, I suspect\n> it's a bug in the kernel.\n\nRight, but what should we then do ? :-) Maybe replacing the\nnon-printable character (as reported by isprint() maybe ?) with a dot ?\n\n> > There's also the case of a default-constructed V4L2PixelFormat, fourcc_\n> > will be 0 in that case.\n> \n> fourcc_ == 0 should indeed be guarded though, and return something like\n> <NONE> or <EMPTY>\n\nIt's documented as invalid ;-)\n\n> > Could you also please add a test case for this function ?\n> >>> +\n> >> +\tif (fourcc_ & (1 << 31))\n> >> +\t\tss << \"-BE\";\n> >> +\treturn ss.str();\n> >>  }\n> >>  \n> >>  /**","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4F1C060413\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Mar 2020 14:28:49 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2CF4680C;\n\tWed, 25 Mar 2020 14:28:48 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"aHDvJGTI\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1585142928;\n\tbh=/jL1F7MLeklDcTv9e4r2jjzn+SOvlE/O1I9FsuljOHM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=aHDvJGTIIYGnJcAqXljoRCNG5fRq6/LVfHoYd0iK8Bxd6Mw6raLFc45pDljVyRfSB\n\tSx/v3I0cMFf4EpXxKtpKOY7tPofCspra5BrS8bRFTodMTu1S7Bo6HbjYW1YclgoeF8\n\tk3Q8UNQB4pZDJJl0zHnXBWtg8UqWy2nwwJfrr6BQ=","Date":"Wed, 25 Mar 2020 15:28:45 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Kaaira Gupta <kgupta@es.iitr.ac.in>, libcamera-devel@lists.libcamera.org,\n\tHelen Koike <helen.koike@collabora.com>,\n\tVaishali Thakkar <vthakkar@vaishalithakkar.in>","Message-ID":"<20200325132845.GF19171@pendragon.ideasonboard.com>","References":"<20200325122825.GA16172@kaaira-HP-Pavilion-Notebook>\n\t<20200325123933.GD19171@pendragon.ideasonboard.com>\n\t<91327f2b-dc77-1fd8-2a62-e1201a79dc32@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<91327f2b-dc77-1fd8-2a62-e1201a79dc32@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","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":"Wed, 25 Mar 2020 13:28:49 -0000"}},{"id":4288,"web_url":"https://patchwork.libcamera.org/comment/4288/","msgid":"<20200325190229.GT19171@pendragon.ideasonboard.com>","date":"2020-03-25T19:02:29","subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kaaira,\n\nOn Wed, Mar 25, 2020 at 06:43:27PM +0530, Kaaira Gupta wrote:\n> On Wed, Mar 25, 2020 at 02:39:33PM +0200, Laurent Pinchart wrote:\n> > On Wed, Mar 25, 2020 at 05:58:25PM +0530, Kaaira Gupta wrote:\n> > > Print 4CC characters instead of the hex value in toString() as they are\n> > > more informative.\n> > > \n> > > Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>\n> > > ---\n> > >  src/libcamera/v4l2_videodevice.cpp | 12 +++++++++---\n> > >  1 file changed, 9 insertions(+), 3 deletions(-)\n> > > \n> > > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> > > index b778181..ea8ee50 100644\n> > > --- a/src/libcamera/v4l2_videodevice.cpp\n> > > +++ b/src/libcamera/v4l2_videodevice.cpp\n> > > @@ -336,9 +336,15 @@ 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> > > +\tstd::stringstream ss;\n> > \n> > Given that the string will be at mose 7 characters long, and the first\n> > four characters are individually computed, a stringstream seems\n> > overkill. You can use a plain char[] buffer and write to it directly.\n> \n> Yes, I'll do that\n> \n> > > +\tss << static_cast<char>(fourcc_ & 0x7f)\n> > \n> > Why 7 bits only ?\n> > \n> > > +\t   << static_cast<char>((fourcc_ >> 8) & 0x7f)\n> > > +\t   << static_cast<char>((fourcc_ >> 16) & 0x7f)\n> > > +\t   << static_cast<char>((fourcc_ >> 24) & 0x7f);\n> > \n> > What happens if any of these values is non-printable ? What if it's a\n> > NUL character ? Or a newline ? We shouldn't have such cases normally in\n> > V4L2 4CCs, but should we protect against that ?\n> \n> Yes, I'll add these cases too\n> \n> > There's also the case of a default-constructed V4L2PixelFormat, fourcc_\n> > will be 0 in that case.\n> > \n> > Could you also please add a test case for this function ?\n> \n> How should I do that? When I made the changes and wanted to check my\n> outputs, I just printed format.fourcc.toString() in \n> test/v4l2_videodevice/v4l2_videodevice_test.cpp...what is the correct\n> way to write a test?\n\nThat's not very nice, as it requires manually looking at the output.\nWhen need automated tests :-)\n\nYou can either add a test case to an existing test, or create a new one.\nFor this specific case we have test/v4l2_videodevice/formats.cpp that\nseems to be a good enough option.\n\nThe test should create V4L2PixelFormat instance, and compare the output\nof their .toString() method with expected output. You could do something\nlike\n\n\tstd::vector<std::pair<uint32_t, const char *>> formats{\n\t\t{ V4L2_PIX_FMT_..., \"...\" },\n\t};\n\nand use a loop for the tests:\n\n\tfor (const auto &format : formats) {\n\t\tif (V4L2PixelFormat(format.first).toString() != format.second) {\n\t\t\t...\n\t\t}\n\t}\n\nYou should include in the vector a few different corner cases (a valid\nformat, 0, a big-endian format, a numerical value that will result in\nnon-printable characters, ...). You should also add one check for the\ndefault constructor with V4L2PixelFormat().toString() != \"....\" outside\nof the loop.\n\n> > > +\n> > > +\tif (fourcc_ & (1 << 31))\n> > > +\t\tss << \"-BE\";\n> > > +\treturn ss.str();\n> > >  }\n> > >  \n> > >  /**","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D8AD860413\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Mar 2020 20:02:33 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DFC1E80C;\n\tWed, 25 Mar 2020 20:02:32 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"snpfGGT4\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1585162953;\n\tbh=DGVvfTro8q1A/UVYpmzIkA8ass3rLlb3y3GZc0RybUY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=snpfGGT4DcLugYRT4I8eijo0L2EcZrg82vCncDKrTVqDCAGTyj3uQgijD2sLc78L0\n\traikkywLAdkvsLlxPaSCiWXJE90YJecoJj9EhvMzgO/z5JEreHlKZirMao7DM1VHMk\n\touaVUeYi1f/j7vr3/dR1dyeQBCyeei+Y+7DGsdt8=","Date":"Wed, 25 Mar 2020 21:02:29 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kaaira Gupta <kgupta@es.iitr.ac.in>","Cc":"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":"<20200325190229.GT19171@pendragon.ideasonboard.com>","References":"<20200325122825.GA16172@kaaira-HP-Pavilion-Notebook>\n\t<20200325123933.GD19171@pendragon.ideasonboard.com>\n\t<20200325131327.GA17937@kaaira-HP-Pavilion-Notebook>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200325131327.GA17937@kaaira-HP-Pavilion-Notebook>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","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":"Wed, 25 Mar 2020 19:02:34 -0000"}},{"id":4291,"web_url":"https://patchwork.libcamera.org/comment/4291/","msgid":"<20200325221125.GA14917@kaaira-HP-Pavilion-Notebook>","date":"2020-03-25T22:11:25","subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","submitter":{"id":39,"url":"https://patchwork.libcamera.org/api/people/39/","name":"Kaaira Gupta","email":"kgupta@es.iitr.ac.in"},"content":"On Wed, Mar 25, 2020 at 09:02:29PM +0200, Laurent Pinchart wrote:\n> Hi Kaaira,\n> \n> On Wed, Mar 25, 2020 at 06:43:27PM +0530, Kaaira Gupta wrote:\n> > On Wed, Mar 25, 2020 at 02:39:33PM +0200, Laurent Pinchart wrote:\n> > > On Wed, Mar 25, 2020 at 05:58:25PM +0530, Kaaira Gupta wrote:\n> > > > Print 4CC characters instead of the hex value in toString() as they are\n> > > > more informative.\n> > > > \n> > > > Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>\n> > > > ---\n> > > >  src/libcamera/v4l2_videodevice.cpp | 12 +++++++++---\n> > > >  1 file changed, 9 insertions(+), 3 deletions(-)\n> > > > \n> > > > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> > > > index b778181..ea8ee50 100644\n> > > > --- a/src/libcamera/v4l2_videodevice.cpp\n> > > > +++ b/src/libcamera/v4l2_videodevice.cpp\n> > > > @@ -336,9 +336,15 @@ 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> > > > +\tstd::stringstream ss;\n> > > \n> > > Given that the string will be at mose 7 characters long, and the first\n> > > four characters are individually computed, a stringstream seems\n> > > overkill. You can use a plain char[] buffer and write to it directly.\n> > \n> > Yes, I'll do that\n> > \n> > > > +\tss << static_cast<char>(fourcc_ & 0x7f)\n> > > \n> > > Why 7 bits only ?\n> > > \n> > > > +\t   << static_cast<char>((fourcc_ >> 8) & 0x7f)\n> > > > +\t   << static_cast<char>((fourcc_ >> 16) & 0x7f)\n> > > > +\t   << static_cast<char>((fourcc_ >> 24) & 0x7f);\n> > > \n> > > What happens if any of these values is non-printable ? What if it's a\n> > > NUL character ? Or a newline ? We shouldn't have such cases normally in\n> > > V4L2 4CCs, but should we protect against that ?\n> > \n> > Yes, I'll add these cases too\n> > \n> > > There's also the case of a default-constructed V4L2PixelFormat, fourcc_\n> > > will be 0 in that case.\n> > > \n> > > Could you also please add a test case for this function ?\n> > \n> > How should I do that? When I made the changes and wanted to check my\n> > outputs, I just printed format.fourcc.toString() in \n> > test/v4l2_videodevice/v4l2_videodevice_test.cpp...what is the correct\n> > way to write a test?\n> \n> That's not very nice, as it requires manually looking at the output.\n> When need automated tests :-)\n> \n> You can either add a test case to an existing test, or create a new one.\n> For this specific case we have test/v4l2_videodevice/formats.cpp that\n> seems to be a good enough option.\n> \n> The test should create V4L2PixelFormat instance, and compare the output\n> of their .toString() method with expected output. You could do something\n> like\n> \n> \tstd::vector<std::pair<uint32_t, const char *>> formats{\n> \t\t{ V4L2_PIX_FMT_..., \"...\" },\n> \t};\n> \n> and use a loop for the tests:\n> \n> \tfor (const auto &format : formats) {\n> \t\tif (V4L2PixelFormat(format.first).toString() != format.second) {\n> \t\t\t...\n> \t\t}\n> \t}\n> \n> You should include in the vector a few different corner cases (a valid\n> format, 0, a big-endian format, a numerical value that will result in\n> non-printable characters, ...). You should also add one check for the\n> default constructor with V4L2PixelFormat().toString() != \"....\" outside\n> of the loop.\n\nYes, done and submitted..but I don't understand why we need to check for\n'0' separately, when we are already checking for the default\nconstructor's value?\n\n> \n> > > > +\n> > > > +\tif (fourcc_ & (1 << 31))\n> > > > +\t\tss << \"-BE\";\n> > > > +\treturn ss.str();\n> > > >  }\n> > > >  \n> > > >  /**\n> \n> -- \n> Regards,\n> \n> Laurent Pinchart","headers":{"Return-Path":"<kgupta@es.iitr.ac.in>","Received":["from mail-pl1-x644.google.com (mail-pl1-x644.google.com\n\t[IPv6:2607:f8b0:4864:20::644])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 496B460413\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Mar 2020 23:11:35 +0100 (CET)","by mail-pl1-x644.google.com with SMTP id t16so1350992plr.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Mar 2020 15:11:35 -0700 (PDT)","from kaaira-HP-Pavilion-Notebook ([103.113.213.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tw15sm125607pfj.28.2020.03.25.15.11.30\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tWed, 25 Mar 2020 15:11:32 -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=\"sxXgF+TK\"; \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=from:date:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:in-reply-to:user-agent;\n\tbh=QqPzVby8u8E2YKB9VgsLa/Q8iKHHgEAP4RcyqMxK78E=;\n\tb=sxXgF+TKs2Kvx2eXCnNvdgamt23HF6VJFJlPnF5gmjtK2d9qb8pSuxGJIOJ+1ZhbBh\n\tTo1T9LqJFucVZoBReL5wtq8I6t9cfaAPNMs12OI7Cb3Bv0fb48CK8od0vIAqd4LVNRph\n\t1RX6OIsxH9osqonr7XOVybIbqKtelZRKyZPvaSl8cnIy86Vx7A+c4ru4YdVb7Kfk4QYs\n\tIP/ZbfJE7NWunAf5WFFP0B/ZiGn/XNIbIb45ACdea5jelDT3N7IyXbE39xDw6Vrt744K\n\tNeo5TiVu3f9S2iDefqlI1mknlpccVhQdmk0PGofUCmvz/Frf9yeLOnStiwnas6VH1ve+\n\tg+Dw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:date:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:in-reply-to:user-agent;\n\tbh=QqPzVby8u8E2YKB9VgsLa/Q8iKHHgEAP4RcyqMxK78E=;\n\tb=RavPCSp5PjpTbi5E6w3LrUaHtUGUx44dG+CCQJEHerDjoB6rJ6Q+tqVHmAvCUSbijX\n\tyyFlu8A9ryVppp7xDIV4CgBj94qySmPeW3lFc/WZbzChQjnN08nze2VrMij7kxKUaSpp\n\tRRf8HBJH1Nc75PRfbt2pAUV2MDVOQfyCF8OqMPW+GZgQJiF8sU0o4Q344c9rGNgEMBk/\n\t4qSgnq72+cS+2EFiiS21LZFR6KcXHLNTi8DJr151kf9Yo3f2AdR4fa701LruzxbFWo98\n\tFHcRa3ijgsiLTVpixYDsyTYiV4KzzxtXUdzlowwIVkx+UgaFWOxyIlvPbjSO0SOpIV3Q\n\t+gWg==","X-Gm-Message-State":"ANhLgQ2dxQ6ZIbj9L73R/Uz2NMY+K4dhRzAqDwc8bbmqOR7eaAwtXLwY\n\tFfB/Y4jX1xtcWW5LrztzIYwQSg==","X-Google-Smtp-Source":"ADFU+vtXGZOMw0+KtWjiuMTRkFIh0qcXmF9i2I5pCfpYmfpWdcNTBgRdoEKnyPXtyMl/ry78gGO/4g==","X-Received":"by 2002:a17:90b:3009:: with SMTP id\n\thg9mr5970417pjb.108.1585174293432; \n\tWed, 25 Mar 2020 15:11:33 -0700 (PDT)","From":"Kaaira Gupta <kgupta@es.iitr.ac.in>","X-Google-Original-From":"Kaaira Gupta <Kaairakgupta@es.iitr.ac.in>","Date":"Thu, 26 Mar 2020 03:41:25 +0530","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Kaaira Gupta <kgupta@es.iitr.ac.in>, 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":"<20200325221125.GA14917@kaaira-HP-Pavilion-Notebook>","References":"<20200325122825.GA16172@kaaira-HP-Pavilion-Notebook>\n\t<20200325123933.GD19171@pendragon.ideasonboard.com>\n\t<20200325131327.GA17937@kaaira-HP-Pavilion-Notebook>\n\t<20200325190229.GT19171@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20200325190229.GT19171@pendragon.ideasonboard.com>","User-Agent":"Mutt/1.9.4 (2018-02-28)","Subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","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":"Wed, 25 Mar 2020 22:11:35 -0000"}},{"id":4293,"web_url":"https://patchwork.libcamera.org/comment/4293/","msgid":"<20200325224146.GY19171@pendragon.ideasonboard.com>","date":"2020-03-25T22:41:46","subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kaaira,\n\nOn Thu, Mar 26, 2020 at 03:41:25AM +0530, Kaaira Gupta wrote:\n> On Wed, Mar 25, 2020 at 09:02:29PM +0200, Laurent Pinchart wrote:\n> > On Wed, Mar 25, 2020 at 06:43:27PM +0530, Kaaira Gupta wrote:\n> >> On Wed, Mar 25, 2020 at 02:39:33PM +0200, Laurent Pinchart wrote:\n> >>> On Wed, Mar 25, 2020 at 05:58:25PM +0530, Kaaira Gupta wrote:\n> >>>> Print 4CC characters instead of the hex value in toString() as they are\n> >>>> more informative.\n> >>>> \n> >>>> Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>\n> >>>> ---\n> >>>>  src/libcamera/v4l2_videodevice.cpp | 12 +++++++++---\n> >>>>  1 file changed, 9 insertions(+), 3 deletions(-)\n> >>>> \n> >>>> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> >>>> index b778181..ea8ee50 100644\n> >>>> --- a/src/libcamera/v4l2_videodevice.cpp\n> >>>> +++ b/src/libcamera/v4l2_videodevice.cpp\n> >>>> @@ -336,9 +336,15 @@ 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> >>>> +\tstd::stringstream ss;\n> >>> \n> >>> Given that the string will be at mose 7 characters long, and the first\n> >>> four characters are individually computed, a stringstream seems\n> >>> overkill. You can use a plain char[] buffer and write to it directly.\n> >> \n> >> Yes, I'll do that\n> >> \n> >>>> +\tss << static_cast<char>(fourcc_ & 0x7f)\n> >>> \n> >>> Why 7 bits only ?\n> >>> \n> >>>> +\t   << static_cast<char>((fourcc_ >> 8) & 0x7f)\n> >>>> +\t   << static_cast<char>((fourcc_ >> 16) & 0x7f)\n> >>>> +\t   << static_cast<char>((fourcc_ >> 24) & 0x7f);\n> >>> \n> >>> What happens if any of these values is non-printable ? What if it's a\n> >>> NUL character ? Or a newline ? We shouldn't have such cases normally in\n> >>> V4L2 4CCs, but should we protect against that ?\n> >> \n> >> Yes, I'll add these cases too\n> >> \n> >>> There's also the case of a default-constructed V4L2PixelFormat, fourcc_\n> >>> will be 0 in that case.\n> >>> \n> >>> Could you also please add a test case for this function ?\n> >> \n> >> How should I do that? When I made the changes and wanted to check my\n> >> outputs, I just printed format.fourcc.toString() in \n> >> test/v4l2_videodevice/v4l2_videodevice_test.cpp...what is the correct\n> >> way to write a test?\n> > \n> > That's not very nice, as it requires manually looking at the output.\n> > When need automated tests :-)\n> > \n> > You can either add a test case to an existing test, or create a new one.\n> > For this specific case we have test/v4l2_videodevice/formats.cpp that\n> > seems to be a good enough option.\n> > \n> > The test should create V4L2PixelFormat instance, and compare the output\n> > of their .toString() method with expected output. You could do something\n> > like\n> > \n> > \tstd::vector<std::pair<uint32_t, const char *>> formats{\n> > \t\t{ V4L2_PIX_FMT_..., \"...\" },\n> > \t};\n> > \n> > and use a loop for the tests:\n> > \n> > \tfor (const auto &format : formats) {\n> > \t\tif (V4L2PixelFormat(format.first).toString() != format.second) {\n> > \t\t\t...\n> > \t\t}\n> > \t}\n> > \n> > You should include in the vector a few different corner cases (a valid\n> > format, 0, a big-endian format, a numerical value that will result in\n> > non-printable characters, ...). You should also add one check for the\n> > default constructor with V4L2PixelFormat().toString() != \"....\" outside\n> > of the loop.\n> \n> Yes, done and submitted..but I don't understand why we need to check for\n> '0' separately, when we are already checking for the default\n> constructor's value?\n\nThere's no current test case to ensure that V4L2PixelFormat() creates an\ninstance with fourcc == 0, that's why I've proposed a separate case.\nIt's hijacking your work a little bit :-)\n\n> >>>> +\n> >>>> +\tif (fourcc_ & (1 << 31))\n> >>>> +\t\tss << \"-BE\";\n> >>>> +\treturn ss.str();\n> >>>>  }\n> >>>>  \n> >>>>  /**","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C25E60413\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Mar 2020 23:41:50 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6AB6E80C;\n\tWed, 25 Mar 2020 23:41:49 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"deK750ek\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1585176109;\n\tbh=Dg0KpgLM8y92J9LnBgylOvQK9PJIkRQ5H63vt5d0seg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=deK750ekqUH1bO28Piw5LJD3YDGnbAXHSeEiQdIf3Jputkb7vF1P5fqm85sfA/VdQ\n\tUicHfbuTNE0N42nBoCZiTGqRlx7Om2VhrD4wkSJ0DiGiMIDjO1G/PqQy3ZaLupm4uC\n\tmqGhBLikfcxfwnhAwMtol5uWoCp5D9qyH0AjYHZg=","Date":"Thu, 26 Mar 2020 00:41:46 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kaaira Gupta <kgupta@es.iitr.ac.in>","Cc":"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":"<20200325224146.GY19171@pendragon.ideasonboard.com>","References":"<20200325122825.GA16172@kaaira-HP-Pavilion-Notebook>\n\t<20200325123933.GD19171@pendragon.ideasonboard.com>\n\t<20200325131327.GA17937@kaaira-HP-Pavilion-Notebook>\n\t<20200325190229.GT19171@pendragon.ideasonboard.com>\n\t<20200325221125.GA14917@kaaira-HP-Pavilion-Notebook>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200325221125.GA14917@kaaira-HP-Pavilion-Notebook>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace\n\thex with 4CC","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":"Wed, 25 Mar 2020 22:41:50 -0000"}}]