[libcamera-devel] [PATCH v5 5/7] libcamera: camera: Validate Request befor queueing it

Jacopo Mondi jacopo at jmondi.org
Tue Apr 16 01:18:57 CEST 2019


Validate the Request before proceeding to prepare it at
Camera::queueRequest() time.

For now limit the validation to making sure the Request contains at
least one Stream to capture from.

Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
 src/libcamera/camera.cpp | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index 21caa24b90b5..e93e7b3b8477 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -715,8 +715,9 @@ Request *Camera::createRequest()
  * \param[in] request The request to queue to the camera
  *
  * This method queues a \a request allocated with createRequest() to the camera
- * for capture. Once the request has been queued, the camera will notify its
- * completion through the \ref requestCompleted signal.
+ * for capture and validates it by making sure it contains at least one stream
+ * where to capture from. Once the request has been queued, the camera will
+ * notify its completion through the \ref requestCompleted signal.
  *
  * Ownership of the request is transferred to the camera. It will be deleted
  * automatically after it completes.
@@ -724,6 +725,7 @@ Request *Camera::createRequest()
  * \return 0 on success or a negative error code otherwise
  * \retval -ENODEV The camera has been disconnected from the system
  * \retval -EACCES The camera is not running so requests can't be queued
+ * \retval -EINVAL The request is not valid
  */
 int Camera::queueRequest(Request *request)
 {
@@ -733,6 +735,15 @@ int Camera::queueRequest(Request *request)
 	if (!stateIs(CameraRunning))
 		return -EACCES;
 
+	/*
+	 * \todo: Centralize validation if it gets more complex and update
+	 * the documentation.
+	 */
+	if (request->empty()) {
+		LOG(Camera, Error) << "Invalid request";
+		return -EINVAL;
+	}
+
 	int ret = request->prepare();
 	if (ret) {
 		LOG(Camera, Error) << "Failed to prepare request";
-- 
2.21.0



More information about the libcamera-devel mailing list