From patchwork Fri Apr 5 02:02:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 920 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F3C1B611AA for ; Fri, 5 Apr 2019 04:03:10 +0200 (CEST) X-Halon-ID: f2f279f6-5746-11e9-8144-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id f2f279f6-5746-11e9-8144-0050569116f7; Fri, 05 Apr 2019 04:03:04 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 5 Apr 2019 04:02:54 +0200 Message-Id: <20190405020256.22520-7-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190405020256.22520-1-niklas.soderlund@ragnatech.se> References: <20190405020256.22520-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 6/8] libcamera: camera: Add support for stream usages X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Apr 2019 02:03:11 -0000 Instead of requesting the default configuration for a set of streams where the application has to figure out which streams provided by the camera is best suited for its intended usage, have the library figure this out by using stream usages. The application asks the library for a list of streams and a suggested default configuration for them by supplying a list of stream usages. Once the list is retrieved the application can fine-tune the returned configuration and then try to apply it to the camera. Currently no pipeline handler is prepared to handle stream usages but nor did it make use of the list of Stream IDs which was the previous interface. The main reason for this is that all cameras currently only provide one stream each. This will still be the case but the API will be prepared to expand both pipeline handlers and applications to support streams usages. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- include/libcamera/camera.h | 3 ++- src/cam/main.cpp | 3 +-- src/libcamera/camera.cpp | 30 ++++++++---------------- src/libcamera/include/pipeline_handler.h | 2 +- src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++-- src/libcamera/pipeline/uvcvideo.cpp | 6 ++--- src/libcamera/pipeline/vimc.cpp | 6 ++--- src/libcamera/pipeline_handler.cpp | 10 ++++---- src/qcam/main_window.cpp | 5 ++-- test/camera/capture.cpp | 5 ++-- test/camera/configuration_default.cpp | 17 +++++--------- test/camera/configuration_set.cpp | 3 +-- test/camera/statemachine.cpp | 4 +--- 13 files changed, 37 insertions(+), 61 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 77e4cd1ee14c2c61..0386671c902e55e8 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -22,6 +22,7 @@ class PipelineHandler; class Request; class Stream; class StreamConfiguration; +class StreamUsage; class Camera final { @@ -44,7 +45,7 @@ public: const std::set &streams() const; std::map - streamConfiguration(std::set &streams); + streamConfiguration(const std::vector &usage); int configureStreams(std::map &config); int allocateBuffers(); diff --git a/src/cam/main.cpp b/src/cam/main.cpp index b5895fae85699b26..d45ffd372d932d76 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -80,8 +80,7 @@ static int parseOptions(int argc, char *argv[]) static int prepareCameraConfig(std::map *config) { - std::set streams = camera->streams(); - *config = camera->streamConfiguration(streams); + *config = camera->streamConfiguration({ Stream::VideoRecording() }); Stream *stream = config->begin()->first; if (options.isSet(OptFormat)) { diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 8ee9cc0866167ae1..63fde0ffc3d02d6c 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -345,33 +345,23 @@ const std::set &Camera::streams() const } /** - * \brief Retrieve a group of stream configurations - * \param[in] streams A map of stream IDs and configurations to setup + * \brief Retrieve a group of stream configurations according to stream usages + * \param[in] usages A list of stream usages * - * Retrieve the camera's configuration for a specified group of streams. The - * caller can specifies which of the camera's streams to retrieve configuration - * from by populating \a streams. + * Retrieve configuration for a set of desired usages. The caller specifies a + * list of stream usages and the camera returns a map of suitable streams and + * their suggested default configurations. * - * The easiest way to populate the array of streams to fetch configuration from - * is to first retrieve the camera's full array of stream with streams() and - * then potentially trim it down to only contain the streams the caller - * are interested in. - * - * \return A map of successfully retrieved stream IDs and configurations or an - * empty list on error. + * \return A map of streams to configurations if the requested usages can be + * satisfied, or an empty map otherwise */ std::map -Camera::streamConfiguration(std::set &streams) +Camera::streamConfiguration(const std::vector &usages) { - if (disconnected_ || !streams.size()) + if (disconnected_ || !usages.size() || usages.size() > streams_.size()) return std::map{}; - for (Stream *stream : streams) { - if (streams_.find(stream) == streams_.end()) - return std::map{}; - } - - return pipe_->streamConfiguration(this, streams); + return pipe_->streamConfiguration(this, usages); } /** diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h index acb376e07030ae03..8a1706fad5377bf4 100644 --- a/src/libcamera/include/pipeline_handler.h +++ b/src/libcamera/include/pipeline_handler.h @@ -53,7 +53,7 @@ public: virtual bool match(DeviceEnumerator *enumerator) = 0; virtual std::map - streamConfiguration(Camera *camera, std::set &streams) = 0; + streamConfiguration(Camera *camera, const std::vector &usages) = 0; virtual int configureStreams(Camera *camera, std::map &config) = 0; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index fed04ce50387f1d9..5d01504e24471bcf 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -141,7 +141,7 @@ public: std::map streamConfiguration(Camera *camera, - std::set &streams) override; + const std::vector &usages) override; int configureStreams(Camera *camera, std::map &config) override; @@ -206,7 +206,7 @@ PipelineHandlerIPU3::~PipelineHandlerIPU3() std::map PipelineHandlerIPU3::streamConfiguration(Camera *camera, - std::set &streams) + const std::vector &usages) { std::map configs; IPU3CameraData *data = cameraData(camera); diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index cc3e0cd9afab38b9..dfff7116bc2aa5d3 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -28,7 +28,7 @@ public: std::map streamConfiguration(Camera *camera, - std::set &streams) override; + const std::vector &usages) override; int configureStreams(Camera *camera, std::map &config) override; @@ -84,14 +84,12 @@ PipelineHandlerUVC::~PipelineHandlerUVC() std::map PipelineHandlerUVC::streamConfiguration(Camera *camera, - std::set &streams) + const std::vector &usages) { UVCCameraData *data = cameraData(camera); - std::map configs; StreamConfiguration config{}; - LOG(UVC, Debug) << "Retrieving default format"; config.width = 640; config.height = 480; config.pixelFormat = V4L2_PIX_FMT_YUYV; diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp index 2e8c26fb7c0b2708..4da4ca018d4b942a 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -28,7 +28,7 @@ public: std::map streamConfiguration(Camera *camera, - std::set &streams) override; + const std::vector &usages) override; int configureStreams(Camera *camera, std::map &config) override; @@ -84,14 +84,12 @@ PipelineHandlerVimc::~PipelineHandlerVimc() std::map PipelineHandlerVimc::streamConfiguration(Camera *camera, - std::set &streams) + const std::vector &usages) { VimcCameraData *data = cameraData(camera); std::map configs; - StreamConfiguration config{}; - LOG(VIMC, Debug) << "Retrieving default format"; config.width = 640; config.height = 480; config.pixelFormat = V4L2_PIX_FMT_RGB24; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 1a858f2638ceac5f..0574f9904367605c 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -152,13 +152,13 @@ PipelineHandler::~PipelineHandler() * \fn PipelineHandler::streamConfiguration() * \brief Retrieve a group of stream configurations for a specified camera * \param[in] camera The camera to fetch default configuration from - * \param[in] streams An array of streams to fetch information about + * \param[in] usages A list of stream usages * * Retrieve the species camera's default configuration for a specified group of - * streams. The caller shall populate the \a streams array with the streams it - * wish to fetch the configuration from. The map of streams and configuration - * returned can then be examined by the caller to learn about the defualt - * parameters for the specified streams. + * use-cases. The caller shall populate the \a usages array with the use-cases it + * wishes to fetch the default configuration for. The map of streams and + * configurations returned can then be examined by the caller to learn about + * the default parameters for the specified streams. * * The intended companion to this is \a configureStreams() which can be used to * change the group of streams parameters. diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index fea701422015ce67..faa3bc5739dd8453 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -97,9 +97,8 @@ int MainWindow::startCapture() { int ret; - Stream *stream = *camera_->streams().begin(); - std::set streams{ stream }; - config_ = camera_->streamConfiguration(streams); + config_ = camera_->streamConfiguration({ Stream::VideoRecording() }); + Stream *stream = config_.begin()->first; ret = camera_->configureStreams(config_); if (ret < 0) { std::cout << "Failed to configure camera" << std::endl; diff --git a/test/camera/capture.cpp b/test/camera/capture.cpp index f6932b7505571712..b8dbdb62f9a50a33 100644 --- a/test/camera/capture.cpp +++ b/test/camera/capture.cpp @@ -42,10 +42,9 @@ protected: int run() { - Stream *stream = *camera_->streams().begin(); - std::set streams = { stream }; std::map conf = - camera_->streamConfiguration(streams); + camera_->streamConfiguration({ Stream::VideoRecording() }); + Stream *stream = conf.begin()->first; StreamConfiguration *sconf = &conf.begin()->second; if (!configurationValid(conf)) { diff --git a/test/camera/configuration_default.cpp b/test/camera/configuration_default.cpp index 856cd415f7a6aec1..09861716973d752c 100644 --- a/test/camera/configuration_default.cpp +++ b/test/camera/configuration_default.cpp @@ -20,14 +20,10 @@ protected: { std::map conf; - /* - * Test that asking for default configuration for a valid - * array of streams returns something valid. - */ - std::set streams = { *camera_->streams().begin() }; - conf = camera_->streamConfiguration(streams); + /* Test asking for configuration for a video stream. */ + conf = camera_->streamConfiguration({ Stream::VideoRecording() }); if (conf.empty()) { - cout << "Failed to retrieve configuration for valid streams" + cout << "Failed to retrieve configuration for video streams" << endl; return TestFail; } @@ -39,12 +35,11 @@ protected: /* * Test that asking for configuration for an empty array of - * streams returns an empty list of configurations. + * stream usages returns an empty list of configurations. */ - std::set streams_empty = {}; - conf = camera_->streamConfiguration(streams_empty); + conf = camera_->streamConfiguration({}); if (!conf.empty()) { - cout << "Failed to retrieve configuration for empty streams" + cout << "Failed to retrieve configuration for empty usage list" << endl; return TestFail; } diff --git a/test/camera/configuration_set.cpp b/test/camera/configuration_set.cpp index cac1da959f241bc5..1bc01e66625eedf0 100644 --- a/test/camera/configuration_set.cpp +++ b/test/camera/configuration_set.cpp @@ -18,9 +18,8 @@ class ConfigurationSet : public CameraTest protected: int run() { - std::set streams = { *camera_->streams().begin() }; std::map conf = - camera_->streamConfiguration(streams); + camera_->streamConfiguration({ Stream::VideoRecording() }); StreamConfiguration *sconf = &conf.begin()->second; if (!configurationValid(conf)) { diff --git a/test/camera/statemachine.cpp b/test/camera/statemachine.cpp index f4395f2b1bfed698..ab3c6fb5bea38c36 100644 --- a/test/camera/statemachine.cpp +++ b/test/camera/statemachine.cpp @@ -235,9 +235,7 @@ protected: int run() { - Stream *stream = *camera_->streams().begin(); - std::set streams = { stream }; - defconf_ = camera_->streamConfiguration(streams); + defconf_ = camera_->streamConfiguration({ Stream::VideoRecording() }); if (testAvailable() != TestPass) { cout << "State machine in Available state failed" << endl;