[{"id":728,"web_url":"https://patchwork.libcamera.org/comment/728/","msgid":"<20190201000614.GC4674@pendragon.ideasonboard.com>","date":"2019-02-01T00:06:14","subject":"Re: [libcamera-devel] [PATCH v6 6/6] libcamera: camera: extend\n\tcamera object to support configuration of streams","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Thu, Jan 31, 2019 at 07:18:53PM +0100, Niklas Söderlund wrote:\n> Extend the camera to support reading and configuring formats for\n> groups of streams. The implementation in the Camera are minimalistic as\n> the heavy lifting are done by the pipeline handler implementations.\n> \n> The most important functionality the camera provides in this context is\n> validation of data structures passed to it from the application and\n> access control to the pipeline handler.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  include/libcamera/camera.h |  6 ++++\n>  src/libcamera/camera.cpp   | 66 ++++++++++++++++++++++++++++++++++++--\n>  2 files changed, 70 insertions(+), 2 deletions(-)\n> \n> diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\n> index d796ce32cc9a6fff..734dbc8e5e7985b5 100644\n> --- a/include/libcamera/camera.h\n> +++ b/include/libcamera/camera.h\n> @@ -7,6 +7,7 @@\n>  #ifndef __LIBCAMERA_CAMERA_H__\n>  #define __LIBCAMERA_CAMERA_H__\n>  \n> +#include <map>\n>  #include <memory>\n>  #include <string>\n>  \n> @@ -16,6 +17,7 @@ namespace libcamera {\n>  \n>  class PipelineHandler;\n>  class Stream;\n> +class StreamConfiguration;\n>  \n>  class Camera final\n>  {\n> @@ -35,6 +37,9 @@ public:\n>  \tvoid release();\n>  \n>  \tconst std::vector<Stream *> &streams() const;\n> +\tstd::map<Stream *, StreamConfiguration>\n> +\tstreamConfiguration(std::vector<Stream *> &streams);\n> +\tint configureStreams(std::map<Stream *, StreamConfiguration> &config);\n>  \n>  private:\n>  \tCamera(PipelineHandler *pipe, const std::string &name);\n> @@ -48,6 +53,7 @@ private:\n>  \tstd::vector<Stream *> streams_;\n>  \n>  \tbool acquired_;\n> +\tbool disconnected_;\n>  };\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 49f49fb71c11e124..b8c6c8b2aa16430a 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -110,7 +110,8 @@ const std::string &Camera::name() const\n>   */\n>  \n>  Camera::Camera(PipelineHandler *pipe, const std::string &name)\n> -\t: pipe_(pipe->shared_from_this()), name_(name), acquired_(false)\n> +\t: pipe_(pipe->shared_from_this()), name_(name), acquired_(false),\n> +\t  disconnected_(false)\n>  {\n>  }\n>  \n> @@ -133,7 +134,7 @@ void Camera::disconnect()\n>  {\n>  \tLOG(Camera, Debug) << \"Disconnecting camera \" << name_;\n>  \n> -\t/** \\todo Block API calls when they will be implemented. */\n> +\tdisconnected_ = true;\n>  \tdisconnected.emit(this);\n>  }\n>  \n> @@ -186,4 +187,65 @@ const std::vector<Stream *> &Camera::streams() const\n>  \treturn streams_;\n>  }\n>  \n> +/**\n> + * \\brief Retrieve a group of stream configurations\n> + * \\param[in] streams A map of stream IDs and configurations to setup\n> + *\n> + * Retrieve the camera's configuration for a specified group of streams. The\n> + * caller can specifies which of the camera's streams to retrieve configuration\n> + * from by populating \\a streams.\n> + *\n> + * The easiest way to populate the array of streams to fetch configuration from\n> + * is to first retrieve the camera's full array of stream with streams() and\n> + * then potentially trim it down to only contain the streams the caller\n> + * are interested in.\n> + *\n> + * \\return A map of successfully retrieved stream IDs and configurations or an\n> + * empty list on error.\n> + */\n> +std::map<Stream *, StreamConfiguration>\n> +Camera::streamConfiguration(std::vector<Stream *> &streams)\n> +{\n> +\tif (disconnected_ || !streams.size())\n> +\t\tstd::map<unsigned int, StreamConfiguration> {};\n> +\n> +\treturn pipe_->streamConfiguration(this, streams);\n> +}\n> +\n> +/**\n> + * \\brief Configure the camera's streams prior to capture\n> + * \\param[in] config A map of stream IDs and configurations to setup\n> + *\n> + * Prior to starting capture, the camera must be configured to select a\n> + * group of streams to be involved in the capture and their configuration.\n> + * The caller specifies which streams are to be involved and their configuration\n> + * by populating \\a config.\n> + *\n> + * The easiest way to populate the array of config is to fetch an initial\n> + * configuration from the camera with streamConfiguration() and then change the\n> + * parameters to fit the caller's need and once all the streams parameters are\n> + * configured hand that over to configureStreams() to actually setup the camera.\n> + *\n> + * Exclusive access to the camera shall be ensured by a call to acquire() prior\n> + * to calling this function, otherwise an -EACCES error will be returned.\n> + *\n> + * \\return 0 on success or a negative error code on error.\n> + * \\retval -ENODEV The camera is not connected to any hardware\n> + * \\retval -EACCES The user has not acquired exclusive access to the camera\n> + * \\retval -EINVAL The configuration is not valid\n> + */\n> +int Camera::configureStreams(std::map<Stream *, StreamConfiguration> &config)\n> +{\n> +\tif (disconnected_)\n> +\t\treturn -ENODEV;\n> +\n> +\tif (!acquired_)\n> +\t\treturn -EACCES;\n> +\n> +\tif (!config.size())\n> +\t\treturn -EINVAL;\n> +\n> +\treturn pipe_->configureStreams(this, config);\n> +}\n> +\n>  } /* namespace libcamera */\n> -- \n> 2.20.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":"<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 03B5160DB4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  1 Feb 2019 01:06:21 +0100 (CET)","from pendragon.ideasonboard.com (85-76-34-136-nat.elisa-mobile.fi\n\t[85.76.34.136])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A272841;\n\tFri,  1 Feb 2019 01:06:20 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1548979581;\n\tbh=PTM1NBkPxMud7sseeOQT8EX9fe9ALIpq5h2+6V1t86s=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=oWQl+H1AsQxT9r9XvrYFYPY3p4Ckl5hvBsG1v6qQ/MniNuvPRbdghWu37f2rH7TZC\n\tQu8Nz3o8yZ/3PkEvsRBN8UE1WHhvFQvGyfdTN/eB9s/lm+i++HOi8blTqQTXTYCgHZ\n\t4BDRQ2Go5BvOti6wxYXrfy0fo4JDdsJootMgjQb4=","Date":"Fri, 1 Feb 2019 02:06:14 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190201000614.GC4674@pendragon.ideasonboard.com>","References":"<20190131181853.23739-1-niklas.soderlund@ragnatech.se>\n\t<20190131181853.23739-7-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190131181853.23739-7-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v6 6/6] libcamera: camera: extend\n\tcamera object to support configuration of streams","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Fri, 01 Feb 2019 00:06:22 -0000"}}]