[{"id":11288,"web_url":"https://patchwork.libcamera.org/comment/11288/","msgid":"<20200709134910.GP3875643@oden.dyn.berto.se>","date":"2020-07-09T13:49:10","subject":"Re: [libcamera-devel] [PATCH v2 13/20] libcamera: ipu3: Store\n\tCameraData as mutable in CameraConfiguration","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Jacopo,\n\nThanks for your work.\n\nOn 2020-07-09 10:41:21 +0200, Jacopo Mondi wrote:\n> A reference to the CameraData sub-class is stored in the\n> IPU3CameraConfiguration as a const pointer, as the now removed comment\n> reports \"to allow the compiler catch un-wanted modifications during\n> validate()\".\n> \n> As the CameraData contains pointers to the available streams, which are\n> actually assigned during validate, the comment and the rationale behind\n> that choice seems now moot.\n> \n> Store CameraData as a mutable pointer and remove the comment and the\n> const_cast<> required to assign streams.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n\nI see now the comment gets removed in the end, which I think is nice :-)\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 16 ++++------------\n>  1 file changed, 4 insertions(+), 12 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index feabffe641e1..9fed6c1e5aa7 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -75,7 +75,7 @@ private:\n>  \t * reference to the camera data, store a new reference to the camera.\n>  \t */\n>  \tstd::shared_ptr<Camera> camera_;\n> -\tconst IPU3CameraData *data_;\n> +\tIPU3CameraData *data_;\n>  \n>  \tStreamConfiguration cio2Configuration_;\n>  \tstd::vector<const Stream *> streams_;\n> @@ -207,7 +207,7 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()\n>  \t\t\tcfg.size = cio2Configuration_.size;\n>  \t\t\tcfg.pixelFormat = cio2Configuration_.pixelFormat;\n>  \t\t\tcfg.bufferCount = cio2Configuration_.bufferCount;\n> -\t\t\tcfg.setStream(const_cast<Stream *>(&data_->rawStream_));\n> +\t\t\tcfg.setStream(&data_->rawStream_);\n>  \n>  \t\t\tLOG(IPU3, Debug) << \"Assigned \" << cfg.toString()\n>  \t\t\t\t\t << \" to the raw stream\";\n> @@ -256,27 +256,19 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()\n>  \t\tcfg.bufferCount = IPU3_BUFFER_COUNT;\n>  \t\tcfg.pixelFormat = formats::NV12;\n>  \n> -\t\t/*\n> -\t\t * Use a const_cast<> here instead of storing a mutable stream\n> -\t\t * pointer in the configuration to let the compiler catch\n> -\t\t * unwanted modifications of camera data in the configuration\n> -\t\t * validate() implementation.\n> -\t\t */\n> -\t\tStream *stream;\n>  \t\tif (mainOutputAvailable &&\n>  \t\t    (oldCfg.size == yuvSize || outCount == 1)) {\n> -\t\t\tstream = const_cast<Stream *>(&data_->outStream_);\n> +\t\t\tcfg.setStream(&data_->outStream_);\n>  \t\t\tmainOutputAvailable = false;\n>  \n>  \t\t\tLOG(IPU3, Debug) << \"Assigned \" << cfg.toString()\n>  \t\t\t\t\t << \" to the main output\";\n>  \t\t} else {\n> -\t\t\tstream = const_cast<Stream *>(&data_->vfStream_);\n> +\t\t\tcfg.setStream(&data_->vfStream_);\n>  \n>  \t\t\tLOG(IPU3, Debug) << \"Assigned \" << cfg.toString()\n>  \t\t\t\t\t << \" to the viewfinder output\";\n>  \t\t}\n> -\t\tcfg.setStream(stream);\n>  \n>  \t\tif (cfg.pixelFormat != oldCfg.pixelFormat ||\n>  \t\t    cfg.size != oldCfg.size) {\n> -- \n> 2.27.0\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 73D28BD792\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  9 Jul 2020 13:49:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 09C026123A;\n\tThu,  9 Jul 2020 15:49:15 +0200 (CEST)","from mail-lf1-x143.google.com (mail-lf1-x143.google.com\n\t[IPv6:2a00:1450:4864:20::143])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DFE23611B2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  9 Jul 2020 15:49:12 +0200 (CEST)","by mail-lf1-x143.google.com with SMTP id y13so1172102lfe.9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 09 Jul 2020 06:49:12 -0700 (PDT)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\t11sm818756lju.102.2020.07.09.06.49.11\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 09 Jul 2020 06:49:11 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com\n\theader.b=\"jMX/XGsl\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=KpW2+gIDx113uEikQjf9Vxm4SMount/IzVA2Ergh8R4=;\n\tb=jMX/XGslhdgKow7CXUDarc01YBb3ezBJa1GnszEMMEjlOZn62exzi4ZqYlNry7iQDw\n\tPjy6NaKuFHm2C97L/FgFde3G6Suv0BtyAxM5Dc4mfqd1U7a317/+QQ2apFmOPB9yXDAg\n\tBnax8i/SSMwxLZJ9m5ngddCnGCSlAC+DTk6BmtJsK/jn5S/8KQ96qPWJeM7yib6S+c4h\n\tGuBthWq/D/BcvywjAgu+O5G/+jr2GoBUqyGeTK+v3M9lAEY069oiDbVxe7ybtwAbmpoJ\n\tacQQWj9Mc4FfiqFsaTXaO9SteiAx7wMM0i6dkGIHKMf0ZX/HDu5cFUZN7BD4tFUS2jCe\n\tNfgQ==","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:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=KpW2+gIDx113uEikQjf9Vxm4SMount/IzVA2Ergh8R4=;\n\tb=tzAY19PoG78+UZF0O9kNVH2MOygqf7VEs1wqeKDFxr9w/drvBEQ/7y9BJA8kiHqna3\n\tnD6WcprFtrGJ12wY98QpXJkX3/6oiPztk5pFPmWSaPETomY5Jn3NOEuTa0v33rYj0cKJ\n\t3kEqxlFln9QjLuAeNxOBm5aQCWY6fn1gKLG03fhfBPcPPH8WpTFth3LYdU+uoT8+7KZc\n\tsRvbnU+rHLgVpJPg0y3Yp0I87m6pn8x6dfTCGBtsWaORSmugBV/57RZAqxzmt1CickyQ\n\tejg5XIFSwKLQ++arpthHa4/xz5DfoDsy62UByrX9Zqa0NHdKEL4W/1YtwRfqPqVfsCuh\n\tZKLg==","X-Gm-Message-State":"AOAM5333MD3qZN4d+A349pbkAg+/QWRi2dyWM+nnBQ2KtyVoD4mOGc1H\n\t1WUDBJAiJUGNbFSv8BA42/hrCNAaRD4=","X-Google-Smtp-Source":"ABdhPJxQPYfdWN1dDpJK3bG2cKXLj4shTV7nXnYcxJ3zER+GNa7VH33BBUrAKumCXeOw6nEJQPuPjw==","X-Received":"by 2002:ac2:5325:: with SMTP id f5mr39642539lfh.6.1594302552188; \n\tThu, 09 Jul 2020 06:49:12 -0700 (PDT)","Date":"Thu, 9 Jul 2020 15:49:10 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<20200709134910.GP3875643@oden.dyn.berto.se>","References":"<20200709084128.5316-1-jacopo@jmondi.org>\n\t<20200709084128.5316-14-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200709084128.5316-14-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v2 13/20] libcamera: ipu3: Store\n\tCameraData as mutable in CameraConfiguration","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"iso-8859-1\"","Content-Transfer-Encoding":"quoted-printable","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":11323,"web_url":"https://patchwork.libcamera.org/comment/11323/","msgid":"<20200710121029.GO5964@pendragon.ideasonboard.com>","date":"2020-07-10T12:10:29","subject":"Re: [libcamera-devel] [PATCH v2 13/20] libcamera: ipu3: Store\n\tCameraData as mutable in CameraConfiguration","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Thu, Jul 09, 2020 at 10:41:21AM +0200, Jacopo Mondi wrote:\n> A reference to the CameraData sub-class is stored in the\n> IPU3CameraConfiguration as a const pointer, as the now removed comment\n> reports \"to allow the compiler catch un-wanted modifications during\n> validate()\".\n> \n> As the CameraData contains pointers to the available streams, which are\n> actually assigned during validate, the comment and the rationale behind\n> that choice seems now moot.\n\nThe idea is that IPU3CameraData models the active state of the camera,\nwhile IPU3CameraConfiguration models a configuration. The latter may\nneed to access the former to query information, but should not modify\nit. That's why it's stored as a const pointer. I'd rather explore the\noption of storing a const Stream * in CameraConfiguration.\n\n> Store CameraData as a mutable pointer and remove the comment and the\n> const_cast<> required to assign streams.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 16 ++++------------\n>  1 file changed, 4 insertions(+), 12 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index feabffe641e1..9fed6c1e5aa7 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -75,7 +75,7 @@ private:\n>  \t * reference to the camera data, store a new reference to the camera.\n>  \t */\n>  \tstd::shared_ptr<Camera> camera_;\n> -\tconst IPU3CameraData *data_;\n> +\tIPU3CameraData *data_;\n>  \n>  \tStreamConfiguration cio2Configuration_;\n>  \tstd::vector<const Stream *> streams_;\n> @@ -207,7 +207,7 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()\n>  \t\t\tcfg.size = cio2Configuration_.size;\n>  \t\t\tcfg.pixelFormat = cio2Configuration_.pixelFormat;\n>  \t\t\tcfg.bufferCount = cio2Configuration_.bufferCount;\n> -\t\t\tcfg.setStream(const_cast<Stream *>(&data_->rawStream_));\n> +\t\t\tcfg.setStream(&data_->rawStream_);\n>  \n>  \t\t\tLOG(IPU3, Debug) << \"Assigned \" << cfg.toString()\n>  \t\t\t\t\t << \" to the raw stream\";\n> @@ -256,27 +256,19 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()\n>  \t\tcfg.bufferCount = IPU3_BUFFER_COUNT;\n>  \t\tcfg.pixelFormat = formats::NV12;\n>  \n> -\t\t/*\n> -\t\t * Use a const_cast<> here instead of storing a mutable stream\n> -\t\t * pointer in the configuration to let the compiler catch\n> -\t\t * unwanted modifications of camera data in the configuration\n> -\t\t * validate() implementation.\n> -\t\t */\n> -\t\tStream *stream;\n>  \t\tif (mainOutputAvailable &&\n>  \t\t    (oldCfg.size == yuvSize || outCount == 1)) {\n> -\t\t\tstream = const_cast<Stream *>(&data_->outStream_);\n> +\t\t\tcfg.setStream(&data_->outStream_);\n>  \t\t\tmainOutputAvailable = false;\n>  \n>  \t\t\tLOG(IPU3, Debug) << \"Assigned \" << cfg.toString()\n>  \t\t\t\t\t << \" to the main output\";\n>  \t\t} else {\n> -\t\t\tstream = const_cast<Stream *>(&data_->vfStream_);\n> +\t\t\tcfg.setStream(&data_->vfStream_);\n>  \n>  \t\t\tLOG(IPU3, Debug) << \"Assigned \" << cfg.toString()\n>  \t\t\t\t\t << \" to the viewfinder output\";\n>  \t\t}\n> -\t\tcfg.setStream(stream);\n>  \n>  \t\tif (cfg.pixelFormat != oldCfg.pixelFormat ||\n>  \t\t    cfg.size != oldCfg.size) {","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id E0DC3BD792\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 10 Jul 2020 12:10:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6C90C613C3;\n\tFri, 10 Jul 2020 14:10:37 +0200 (CEST)","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 BD8646118A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Jul 2020 14:10:36 +0200 (CEST)","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 3A69A2C0;\n\tFri, 10 Jul 2020 14:10:36 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"NDT+gKeG\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1594383036;\n\tbh=t8DKxO5cwILbrHhBtGgUwDuDygqrzKf/cag++EIz/Ts=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=NDT+gKeG/18SCjIwYkrFpqa3UbfRL6y9bInyMv7KqDe8D+oq7xHau/rt3ze7j5dU8\n\tW6DNa67NPOR2BQbtkiM85rvZ9fjA0pIWPosrsM2wFgDx7qq7rAN5Qx2Jw8QhPyLTdA\n\tutUo3Wdcf77EL1khic5+4RtHpuKmoZjL3rdZUJ5k=","Date":"Fri, 10 Jul 2020 15:10:29 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<20200710121029.GO5964@pendragon.ideasonboard.com>","References":"<20200709084128.5316-1-jacopo@jmondi.org>\n\t<20200709084128.5316-14-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200709084128.5316-14-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v2 13/20] libcamera: ipu3: Store\n\tCameraData as mutable in CameraConfiguration","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]