[{"id":4407,"web_url":"https://patchwork.libcamera.org/comment/4407/","msgid":"<20200407230501.GY1716317@oden.dyn.berto.se>","date":"2020-04-07T23:05:01","subject":"Re: [libcamera-devel] [PATCH v4 4/6] libcamera: camera_sensor:\n\tBreak out properties initialization","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-03-26 15:59:25 +0100, Jacopo Mondi wrote:\n> Refactor the CameraSensor properties initialization to a dedicated virtual\n> function that derived classes could override to register sensor-specific\n> property values.\n> \n> While at it, move documentation of the properties() method to match the\n> declaration order in the class definition and make the properties_ and\n> subdev_ fields protected to allow subclasses access.\n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/libcamera/camera_sensor.cpp       | 115 +++++++++++++++-----------\n>  src/libcamera/include/camera_sensor.h |   7 +-\n>  2 files changed, 73 insertions(+), 49 deletions(-)\n> \n> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> index c1a29e0b3cfc..09771fc40bbb 100644\n> --- a/src/libcamera/camera_sensor.cpp\n> +++ b/src/libcamera/camera_sensor.cpp\n> @@ -51,7 +51,7 @@ LOG_DEFINE_CATEGORY(CameraSensor);\n>   * Once constructed the instance must be initialized with init().\n>   */\n>  CameraSensor::CameraSensor(const MediaEntity *entity)\n> -\t: entity_(entity), properties_(properties::properties)\n> +\t: properties_(properties::properties), entity_(entity)\n>  {\n>  \tsubdev_ = new V4L2Subdevice(entity);\n>  }\n> @@ -93,45 +93,6 @@ int CameraSensor::init()\n>  \tif (ret < 0)\n>  \t\treturn ret;\n>  \n> -\t/* Retrieve and store the camera sensor properties. */\n> -\tconst ControlInfoMap &controls = subdev_->controls();\n> -\tint32_t propertyValue;\n> -\n> -\t/* Camera Location: default is front location. */\n> -\tconst auto &locationControl = controls.find(V4L2_CID_CAMERA_SENSOR_LOCATION);\n> -\tif (locationControl != controls.end()) {\n> -\t\tint32_t v4l2Location =\n> -\t\t\tlocationControl->second.def().get<int32_t>();\n> -\n> -\t\tswitch (v4l2Location) {\n> -\t\tdefault:\n> -\t\t\tLOG(CameraSensor, Warning)\n> -\t\t\t\t<< \"Unsupported camera location \"\n> -\t\t\t\t<< v4l2Location << \", setting to Front\";\n> -\t\t\t/* Fall-through */\n> -\t\tcase V4L2_LOCATION_FRONT:\n> -\t\t\tpropertyValue = properties::CameraLocationFront;\n> -\t\t\tbreak;\n> -\t\tcase V4L2_LOCATION_BACK:\n> -\t\t\tpropertyValue = properties::CameraLocationBack;\n> -\t\t\tbreak;\n> -\t\tcase V4L2_LOCATION_EXTERNAL:\n> -\t\t\tpropertyValue = properties::CameraLocationExternal;\n> -\t\t\tbreak;\n> -\t\t}\n> -\t} else {\n> -\t\tpropertyValue = properties::CameraLocationFront;\n> -\t}\n> -\tproperties_.set(properties::Location, propertyValue);\n> -\n> -\t/* Camera Rotation: default is 0 degrees. */\n> -\tconst auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION);\n> -\tif (rotationControl != controls.end())\n> -\t\tpropertyValue = rotationControl->second.def().get<int32_t>();\n> -\telse\n> -\t\tpropertyValue = 0;\n> -\tproperties_.set(properties::Rotation, propertyValue);\n> -\n>  \t/* Enumerate and cache media bus codes and sizes. */\n>  \tconst ImageFormats formats = subdev_->formats(0);\n>  \tif (formats.isEmpty()) {\n> @@ -162,6 +123,58 @@ int CameraSensor::init()\n>  \tstd::sort(mbusCodes_.begin(), mbusCodes_.end());\n>  \tstd::sort(sizes_.begin(), sizes_.end());\n>  \n> +\treturn initProperties();\n> +}\n> +\n> +/**\n> + * \\brief Initialize the camera sensor standard properties\n> + *\n> + * This method initializes the camera sensor standard properties, by inspecting\n> + * the control information reported by the sensor subdevice.\n> + *\n> + * Derived classes may override this method to register sensor-specific\n> + * properties if needed. If they do so, they shall call the base\n> + * initProperties() method to register standard properties.\n> + *\n> + * \\return 0 on success, a negative error code otherwise\n> + */\n> +int CameraSensor::initProperties()\n> +{\n> +\tconst ControlInfoMap &controlMap = subdev_->controls();\n> +\tint32_t propertyValue;\n> +\n> +\t/* Camera Location: default is front location. */\n> +\tconst auto &locationControl = controlMap.find(V4L2_CID_CAMERA_SENSOR_LOCATION);\n> +\tif (locationControl != controlMap.end()) {\n> +\t\tint32_t v4l2Location =\n> +\t\t\tlocationControl->second.def().get<int32_t>();\n> +\t\tswitch (v4l2Location) {\n> +\t\tcase V4L2_LOCATION_EXTERNAL:\n> +\t\t\tpropertyValue = properties::CameraLocationExternal;\n> +\t\t\tbreak;\n> +\t\tcase V4L2_LOCATION_FRONT:\n> +\t\t\tpropertyValue = properties::CameraLocationFront;\n> +\t\t\tbreak;\n> +\t\tcase V4L2_LOCATION_BACK:\n> +\t\t\tpropertyValue = properties::CameraLocationBack;\n> +\t\t\tbreak;\n> +\t\tdefault:\n> +\t\t\tLOG(CameraSensor, Error)\n> +\t\t\t\t<< \"Unsupported camera location: \" << v4l2Location;\n> +\t\t\treturn -EINVAL;\n> +\t\t}\n> +\t} else {\n> +\t\tpropertyValue = properties::CameraLocationFront;\n> +\t}\n> +\tproperties_.set(properties::Location, propertyValue);\n> +\n> +\t/* Camera Rotation: default is 0 degrees. */\n> +\tpropertyValue = 0;\n> +\tconst auto &rotationControl = controlMap.find(V4L2_CID_CAMERA_SENSOR_ROTATION);\n> +\tif (rotationControl != controlMap.end())\n> +\t\tpropertyValue = rotationControl->second.def().get<int32_t>();\n> +\tproperties_.set(properties::Rotation, propertyValue);\n> +\n>  \treturn 0;\n>  }\n>  \n> @@ -327,12 +340,6 @@ int CameraSensor::getControls(ControlList *ctrls)\n>  \treturn subdev_->getControls(ctrls);\n>  }\n>  \n> -/**\n> - * \\fn CameraSensor::properties()\n> - * \\brief Retrieve the camera sensor properties\n> - * \\return The list of camera sensor properties\n> - */\n> -\n>  /**\n>   * \\brief Write controls to the sensor\n>   * \\param[in] ctrls The list of controls to write\n> @@ -363,11 +370,27 @@ int CameraSensor::setControls(ControlList *ctrls)\n>  \treturn subdev_->setControls(ctrls);\n>  }\n>  \n> +/**\n> + * \\fn CameraSensor::properties()\n> + * \\brief Retrieve the camera sensor properties\n> + * \\return The list of camera sensor properties\n> + */\n> +\n>  std::string CameraSensor::logPrefix() const\n>  {\n>  \treturn \"'\" + subdev_->entity()->name() + \"'\";\n>  }\n>  \n> +/**\n> + * \\var CameraSensor::properties_\n> + * \\brief The list of camera sensor properties\n> + */\n> +\n> +/**\n> + * \\var CameraSensor::subdev_\n> + * \\brief The camera sensor V4L2 subdevice\n> + */\n> +\n>  /**\n>   * \\class CameraSensorFactory\n>   * \\brief Factory of camera sensors\n> diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\n> index 8ffc787e740f..6e4d2b0118bc 100644\n> --- a/src/libcamera/include/camera_sensor.h\n> +++ b/src/libcamera/include/camera_sensor.h\n> @@ -34,6 +34,7 @@ public:\n>  \tCameraSensor &operator=(const CameraSensor &) = delete;\n>  \n>  \tint init();\n> +\tvirtual int initProperties();\n>  \n>  \tconst MediaEntity *entity() const { return entity_; }\n>  \tconst std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }\n> @@ -53,14 +54,14 @@ public:\n>  protected:\n>  \tstd::string logPrefix() const;\n>  \n> +\tControlList properties_;\n> +\tV4L2Subdevice *subdev_;\n> +\n>  private:\n>  \tconst MediaEntity *entity_;\n> -\tV4L2Subdevice *subdev_;\n>  \n>  \tstd::vector<unsigned int> mbusCodes_;\n>  \tstd::vector<Size> sizes_;\n> -\n> -\tControlList properties_;\n>  };\n>  \n>  class CameraSensorFactory\n> -- \n> 2.25.1\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com\n\t[IPv6:2a00:1450:4864:20::12f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D0986600F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Apr 2020 01:05:03 +0200 (CEST)","by mail-lf1-x12f.google.com with SMTP id m19so1666693lfq.13\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 07 Apr 2020 16:05:03 -0700 (PDT)","from localhost (h-200-138.A463.priv.bahnhof.se. [176.10.200.138])\n\tby smtp.gmail.com with ESMTPSA id\n\ti2sm15136602ljj.72.2020.04.07.16.05.02\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 07 Apr 2020 16:05:02 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com header.b=\"eG3zcxpQ\"; \n\tdkim-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=Lyh9J5DG4eRDs7ifd4B4JzZK3BafP6hIQsMZWzjRphQ=;\n\tb=eG3zcxpQTuOspsIpuOw2wT2err3D6PtEqrZ2nXdpNHkIFJ/EMU8Ai5XU0oz+Vf1YpX\n\tBh6M/j655pM4AA/e7V/vn4pG/XjY18jFUM+ZUpn2FLIyDC7ksgkImy/aOq5yKwla8NN8\n\tZvferXg9wiv6XPi1Nts0kKzh65rFg9c04APvaIsJGlXL/Izp6IKNHo88puqwGasViRXu\n\twkgp00VLfsJSyGywXoktbztHxFJKNbfe9hbxMrS9z7nPp2VkWgxuDy/PvBS1fZAgSs6b\n\tnCvdX4GFrY/lfCtzbdLZZSBBGOx1qPteRMGwJ4bbFbrQMAJ2A990PU2WYWG5hkEJSghV\n\tu7OA==","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=Lyh9J5DG4eRDs7ifd4B4JzZK3BafP6hIQsMZWzjRphQ=;\n\tb=diwoU0p4q8EvRZxKxJ8ggC6rR+f4u1ma6/hMJsaW26TZ0Eopu3YOcJt3mP5xy6SzoK\n\thhhWAZVeBh+eazXN2tCyV+Gsfhk8rJsSohSsK9jnziWWUdln3xH58gUbCnSJdWqcPWHA\n\tEmNtxdazUOifTHBdU1Y69JFFxNh7a8Zg3dh0orxu0ekqS9MpZBP8AXuRtiY5lLg96+mf\n\tj4wBA4NVCaDZoBtF0VyQ5wlwfeC7loCm8aFzYCKbovvgBfcvWWdjoYAhBxAHSkQNNET3\n\twg5htbAjUeN2O+SaI0b7BsLtqkHzG6LvypQwbL3slyUak0Sy5gPVQJ7hbZ1G9ixG0SZk\n\ta78Q==","X-Gm-Message-State":"AGi0PuanwxfopHHuyNkLj2XEQJeBBUN38nyAb2m/Iax8Mweb2Obu59LK\n\twME7O3gT3CORfAWMv4WiN7TJMQ==","X-Google-Smtp-Source":"APiQypIiutD7Y+rpaR5bL5A6MSK9i0WEg7Sg6cm6j7Sxa64pW53rJsb4hiOJqaD++JTRi26gLviCNA==","X-Received":"by 2002:a19:ad47:: with SMTP id s7mr2766397lfd.165.1586300703055;\n\tTue, 07 Apr 2020 16:05:03 -0700 (PDT)","Date":"Wed, 8 Apr 2020 01:05:01 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200407230501.GY1716317@oden.dyn.berto.se>","References":"<20200326145927.324919-1-jacopo@jmondi.org>\n\t<20200326145927.324919-5-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200326145927.324919-5-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v4 4/6] libcamera: camera_sensor:\n\tBreak out properties initialization","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":"Tue, 07 Apr 2020 23:05:04 -0000"}}]