{"id":2378,"url":"https://patchwork.libcamera.org/api/patches/2378/?format=json","web_url":"https://patchwork.libcamera.org/patch/2378/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20191126233620.1695316-31-niklas.soderlund@ragnatech.se>","date":"2019-11-26T23:36:20","name":"[libcamera-devel,30/30] libcamera: camera: Remove the prepared state","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"3e5a4278932c041ac7de8ded9c6fdb3e9436a820","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2378/mbox/","series":[{"id":579,"url":"https://patchwork.libcamera.org/api/series/579/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=579","date":"2019-11-26T23:35:50","name":"libcamera: Rework buffer API","version":1,"mbox":"https://patchwork.libcamera.org/series/579/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2378/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2378/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 419DC6136B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Nov 2019 00:39:53 +0100 (CET)","from bismarck.berto.se (p54ac5865.dip0.t-ipconnect.de\n\t[84.172.88.101]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid 0a2f0fc4-10a6-11ea-a0b9-005056917f90;\n\tWed, 27 Nov 2019 00:39:51 +0100 (CET)"],"X-Halon-ID":"0a2f0fc4-10a6-11ea-a0b9-005056917f90","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 27 Nov 2019 00:36:20 +0100","Message-Id":"<20191126233620.1695316-31-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.24.0","In-Reply-To":"<20191126233620.1695316-1-niklas.soderlund@ragnatech.se>","References":"<20191126233620.1695316-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 30/30] libcamera: camera: Remove the\n\tprepared state","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, 26 Nov 2019 23:39:53 -0000"},"content":"With the FrameBuffer rework completed there is no reason to keep the\ncamera prepared state around as buffer allocations are now decoupled\nfrom the camera state. Remove the camera state simplifying the API.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n include/libcamera/camera.h    |   4 --\n src/android/camera_device.cpp |  10 +---\n src/cam/capture.cpp           |   8 ---\n src/libcamera/camera.cpp      | 104 ++++++++--------------------------\n src/qcam/main_window.cpp      |   9 ---\n test/camera/buffer_import.cpp |  10 ----\n test/camera/capture.cpp       |  10 ----\n test/camera/statemachine.cpp  |  83 ---------------------------\n 8 files changed, 26 insertions(+), 212 deletions(-)","diff":"diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\nindex 02d047b9649f53d0..9f542aab213c5d47 100644\n--- a/include/libcamera/camera.h\n+++ b/include/libcamera/camera.h\n@@ -90,9 +90,6 @@ public:\n \tstd::unique_ptr<CameraConfiguration> generateConfiguration(const StreamRoles &roles);\n \tint configure(CameraConfiguration *config);\n \n-\tint allocateBuffers();\n-\tint freeBuffers();\n-\n \tRequest *createRequest(uint64_t cookie = 0);\n \tint queueRequest(Request *request);\n \n@@ -104,7 +101,6 @@ private:\n \t\tCameraAvailable,\n \t\tCameraAcquired,\n \t\tCameraConfigured,\n-\t\tCameraPrepared,\n \t\tCameraRunning,\n \t};\n \ndiff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex a6da658bec277933..34c6119228a9ac0e 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -78,7 +78,6 @@ void CameraDevice::close()\n {\n \tcamera_->stop();\n \n-\tcamera_->freeBuffers();\n \tcamera_->release();\n \n \trunning_ = false;\n@@ -690,16 +689,9 @@ void CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reque\n \n \t/* Start the camera if that's the first request we handle. */\n \tif (!running_) {\n-\t\tint ret = camera_->allocateBuffers();\n-\t\tif (ret) {\n-\t\t\tLOG(HAL, Error) << \"Failed to allocate buffers\";\n-\t\t\treturn;\n-\t\t}\n-\n-\t\tret = camera_->start();\n+\t\tint ret = camera_->start();\n \t\tif (ret) {\n \t\t\tLOG(HAL, Error) << \"Failed to start camera\";\n-\t\t\tcamera_->freeBuffers();\n \t\t\treturn;\n \t\t}\n \ndiff --git a/src/cam/capture.cpp b/src/cam/capture.cpp\nindex 154e6e461ee2b96b..835943a7d2b82e79 100644\n--- a/src/cam/capture.cpp\n+++ b/src/cam/capture.cpp\n@@ -42,12 +42,6 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options)\n \t\treturn ret;\n \t}\n \n-\tret = camera_->allocateBuffers();\n-\tif (ret) {\n-\t\tstd::cerr << \"Failed to allocate buffers\" << std::endl;\n-\t\treturn ret;\n-\t}\n-\n \tcamera_->requestCompleted.connect(this, &Capture::requestComplete);\n \n \tif (options.isSet(OptFile)) {\n@@ -67,8 +61,6 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options)\n \t\twriter_ = nullptr;\n \t}\n \n-\tcamera_->freeBuffers();\n-\n \treturn ret;\n }\n \ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 12878a1c2e6076d3..fca75040ad8b16e7 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -274,15 +274,13 @@ std::size_t CameraConfiguration::size() const\n  * \\section camera_operation Operating the Camera\n  *\n  * An application needs to perform a sequence of operations on a camera before\n- * it is ready to process requests. The camera needs to be acquired, configured\n- * and resources allocated or imported to prepare the camera for capture. Once\n- * started the camera can process requests until it is stopped. When an\n- * application is done with a camera all resources allocated need to be freed\n- * and the camera released.\n+ * it is ready to process requests. The camera needs to be acquired and\n+ * configured to prepare the camera for capture. Once started the camera can\n+ * process requests until it is stopped. When an application is done with a\n+ * camera it needs to be released.\n  *\n  * An application may start and stop a camera multiple times as long as it is\n- * not released. The camera may also be reconfigured provided that all\n- * resources allocated are freed prior to the reconfiguration.\n+ * not released. The camera may also be reconfigured.\n  *\n  * \\subsection Camera States\n  *\n@@ -296,7 +294,6 @@ std::size_t CameraConfiguration::size() const\n  *   node [shape = doublecircle ]; Available;\n  *   node [shape = circle ]; Acquired;\n  *   node [shape = circle ]; Configured;\n- *   node [shape = circle ]; Prepared;\n  *   node [shape = circle ]; Running;\n  *\n  *   Available -> Available [label = \"release()\"];\n@@ -306,14 +303,10 @@ std::size_t CameraConfiguration::size() const\n  *   Acquired -> Configured [label = \"configure()\"];\n  *\n  *   Configured -> Available [label = \"release()\"];\n- *   Configured -> Configured [label = \"configure()\"];\n- *   Configured -> Prepared [label = \"allocateBuffers()\"];\n+ *   Configured -> Configured [label = \"configure(), createRequest()\"];\n+ *   Configured -> Running [label = \"start()\"];\n  *\n- *   Prepared -> Configured [label = \"freeBuffers()\"];\n- *   Prepared -> Prepared [label = \"createRequest()\"];\n- *   Prepared -> Running [label = \"start()\"];\n- *\n- *   Running -> Prepared [label = \"stop()\"];\n+ *   Running -> Configured [label = \"stop()\"];\n  *   Running -> Running [label = \"createRequest(), queueRequest()\"];\n  * }\n  * \\enddot\n@@ -329,19 +322,14 @@ std::size_t CameraConfiguration::size() const\n  * Configured state.\n  *\n  * \\subsubsection Configured\n- * The camera is configured and ready for the application to prepare it with\n- * resources. The camera may be reconfigured multiple times until resources\n- * are provided and the state progresses to Prepared.\n- *\n- * \\subsubsection Prepared\n- * The camera has been configured and provided with resources and is ready to be\n- * started. The application may free the camera's resources to get back to the\n- * Configured state or start() it to progress to the Running state.\n+ * The camera has been configured and is ready to be started. The application\n+ * may release() the camera and to get back to the Available state or start()\n+ * it to progress to the Running state.\n  *\n  * \\subsubsection Running\n  * The camera is running and ready to process requests queued by the\n  * application. The camera remains in this state until it is stopped and moved\n- * to the Prepared state.\n+ * to the Configured state.\n  */\n \n /**\n@@ -419,7 +407,6 @@ static const char *const camera_state_names[] = {\n \t\"Available\",\n \t\"Acquired\",\n \t\"Configured\",\n-\t\"Prepared\",\n \t\"Running\",\n };\n \n@@ -473,11 +460,11 @@ void Camera::disconnect()\n \n \t/*\n \t * If the camera was running when the hardware was removed force the\n-\t * state to Prepared to allow applications to call freeBuffers() and\n-\t * release() before deleting the camera.\n+\t * state to Configured state to allow applications to free resources\n+\t * and release() before deleting the camera.\n \t */\n \tif (state_ == CameraRunning)\n-\t\tstate_ = CameraPrepared;\n+\t\tstate_ = CameraConfigured;\n \n \tdisconnected_ = true;\n \tdisconnected.emit(this);\n@@ -685,53 +672,6 @@ int Camera::configure(CameraConfiguration *config)\n \treturn 0;\n }\n \n-/**\n- * \\brief Allocate buffers for all configured streams\n- *\n- * This function affects the state of the camera, see \\ref camera_operation.\n- *\n- * \\return 0 on success or a negative error code otherwise\n- * \\retval -ENODEV The camera has been disconnected from the system\n- * \\retval -EACCES The camera is not in a state where buffers can be allocated\n- * \\retval -EINVAL The configuration is not valid\n- */\n-int Camera::allocateBuffers()\n-{\n-\tif (disconnected_)\n-\t\treturn -ENODEV;\n-\n-\tif (!stateIs(CameraConfigured))\n-\t\treturn -EACCES;\n-\n-\tif (activeStreams_.empty()) {\n-\t\tLOG(Camera, Error)\n-\t\t\t<< \"Can't allocate buffers without streams\";\n-\t\treturn -EINVAL;\n-\t}\n-\n-\tstate_ = CameraPrepared;\n-\n-\treturn 0;\n-}\n-\n-/**\n- * \\brief Release all buffers from allocated pools in each stream\n- *\n- * This function affects the state of the camera, see \\ref camera_operation.\n- *\n- * \\return 0 on success or a negative error code otherwise\n- * \\retval -EACCES The camera is not in a state where buffers can be freed\n- */\n-int Camera::freeBuffers()\n-{\n-\tif (!stateIs(CameraPrepared))\n-\t\treturn -EACCES;\n-\n-\tstate_ = CameraConfigured;\n-\n-\treturn 0;\n-}\n-\n /**\n  * \\brief Create a request object for the camera\n  * \\param[in] cookie Opaque cookie for application use\n@@ -747,14 +687,14 @@ int Camera::freeBuffers()\n  * The ownership of the returned request is passed to the caller, which is\n  * responsible for either queueing the request or deleting it.\n  *\n- * This function shall only be called when the camera is in the Prepared\n+ * This function shall only be called when the camera is in the Configured\n  * or Running state, see \\ref camera_operation.\n  *\n  * \\return A pointer to the newly created request, or nullptr on error\n  */\n Request *Camera::createRequest(uint64_t cookie)\n {\n-\tif (disconnected_ || !stateBetween(CameraPrepared, CameraRunning))\n+\tif (disconnected_ || !stateBetween(CameraConfigured, CameraRunning))\n \t\treturn nullptr;\n \n \treturn new Request(this, cookie);\n@@ -828,9 +768,15 @@ int Camera::start()\n \tif (disconnected_)\n \t\treturn -ENODEV;\n \n-\tif (!stateIs(CameraPrepared))\n+\tif (!stateIs(CameraConfigured))\n \t\treturn -EACCES;\n \n+\tif (activeStreams_.empty()) {\n+\t\tLOG(Camera, Error)\n+\t\t\t<< \"Can't start camera without streams\";\n+\t\treturn -EINVAL;\n+\t}\n+\n \tfor (Stream *stream : activeStreams_) {\n \t\tret = stream->start();\n \t\tif (ret < 0)\n@@ -870,7 +816,7 @@ int Camera::stop()\n \n \tLOG(Camera, Debug) << \"Stopping capture\";\n \n-\tstate_ = CameraPrepared;\n+\tstate_ = CameraConfigured;\n \n \tpipe_->stop(this);\n \ndiff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 9650bd970f89aa41..38cf79deed37a089 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -172,13 +172,6 @@ int MainWindow::startCapture()\n \n \tadjustSize();\n \n-\tret = camera_->allocateBuffers();\n-\tif (ret) {\n-\t\tstd::cerr << \"Failed to allocate buffers\"\n-\t\t\t  << std::endl;\n-\t\treturn ret;\n-\t}\n-\n \tret = allocator_->allocate(stream, cfg);\n \tif (ret < 0) {\n \t\tstd::cerr << \"Failed to allocate internal buffers\" << std::endl;\n@@ -230,7 +223,6 @@ error:\n \tfor (Request *request : requests)\n \t\tdelete request;\n \n-\tcamera_->freeBuffers();\n \treturn ret;\n }\n \n@@ -243,7 +235,6 @@ void MainWindow::stopCapture()\n \tif (ret)\n \t\tstd::cout << \"Failed to stop capture\" << std::endl;\n \n-\tcamera_->freeBuffers();\n \tisCapturing_ = false;\n \n \tconfig_.reset();\ndiff --git a/test/camera/buffer_import.cpp b/test/camera/buffer_import.cpp\nindex c98afeb9597e21c2..9ae364d44d63b4d5 100644\n--- a/test/camera/buffer_import.cpp\n+++ b/test/camera/buffer_import.cpp\n@@ -174,11 +174,6 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (camera_->allocateBuffers()) {\n-\t\t\tcout << \"Failed to allocate buffers\" << endl;\n-\t\t\treturn TestFail;\n-\t\t}\n-\n \t\tStream *stream = cfg.stream();\n \n \t\tBufferSource source;\n@@ -246,11 +241,6 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (camera_->freeBuffers()) {\n-\t\t\tcout << \"Failed to free buffers\" << endl;\n-\t\t\treturn TestFail;\n-\t\t}\n-\n \t\treturn TestPass;\n \t}\n \ndiff --git a/test/camera/capture.cpp b/test/camera/capture.cpp\nindex ee6d0a1bc1fa839d..545496fe2f7655ea 100644\n--- a/test/camera/capture.cpp\n+++ b/test/camera/capture.cpp\n@@ -80,11 +80,6 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (camera_->allocateBuffers()) {\n-\t\t\tcout << \"Failed to allocate buffers\" << endl;\n-\t\t\treturn TestFail;\n-\t\t}\n-\n \t\tStream *stream = cfg.stream();\n \n \t\tBufferAllocator allocator(camera_);\n@@ -152,11 +147,6 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (camera_->freeBuffers()) {\n-\t\t\tcout << \"Failed to free buffers\" << endl;\n-\t\t\treturn TestFail;\n-\t\t}\n-\n \t\treturn TestPass;\n \t}\n \ndiff --git a/test/camera/statemachine.cpp b/test/camera/statemachine.cpp\nindex e9468d806f977a63..7d409ca20689568b 100644\n--- a/test/camera/statemachine.cpp\n+++ b/test/camera/statemachine.cpp\n@@ -29,12 +29,6 @@ protected:\n \t\tif (camera_->configure(defconf_.get()) != -EACCES)\n \t\t\treturn TestFail;\n \n-\t\tif (camera_->allocateBuffers() != -EACCES)\n-\t\t\treturn TestFail;\n-\n-\t\tif (camera_->freeBuffers() != -EACCES)\n-\t\t\treturn TestFail;\n-\n \t\tif (camera_->createRequest())\n \t\t\treturn TestFail;\n \n@@ -65,12 +59,6 @@ protected:\n \t\tif (camera_->acquire() != -EBUSY)\n \t\t\treturn TestFail;\n \n-\t\tif (camera_->allocateBuffers() != -EACCES)\n-\t\t\treturn TestFail;\n-\n-\t\tif (camera_->freeBuffers() != -EACCES)\n-\t\t\treturn TestFail;\n-\n \t\tif (camera_->createRequest())\n \t\t\treturn TestFail;\n \n@@ -103,57 +91,6 @@ protected:\n \t\tif (camera_->acquire() != -EBUSY)\n \t\t\treturn TestFail;\n \n-\t\tif (camera_->freeBuffers() != -EACCES)\n-\t\t\treturn TestFail;\n-\n-\t\tif (camera_->createRequest())\n-\t\t\treturn TestFail;\n-\n-\t\tRequest request(camera_.get());\n-\t\tif (camera_->queueRequest(&request) != -EACCES)\n-\t\t\treturn TestFail;\n-\n-\t\tif (camera_->start() != -EACCES)\n-\t\t\treturn TestFail;\n-\n-\t\tif (camera_->stop() != -EACCES)\n-\t\t\treturn TestFail;\n-\n-\t\t/* Test operations which should pass. */\n-\t\tif (camera_->configure(defconf_.get()))\n-\t\t\treturn TestFail;\n-\n-\t\t/* Test valid state transitions, end in Prepared state. */\n-\t\tif (camera_->release())\n-\t\t\treturn TestFail;\n-\n-\t\tif (camera_->acquire())\n-\t\t\treturn TestFail;\n-\n-\t\tif (camera_->configure(defconf_.get()))\n-\t\t\treturn TestFail;\n-\n-\t\tif (camera_->allocateBuffers())\n-\t\t\treturn TestFail;\n-\n-\t\treturn TestPass;\n-\t}\n-\n-\tint testPrepared()\n-\t{\n-\t\t/* Test operations which should fail. */\n-\t\tif (camera_->acquire() != -EBUSY)\n-\t\t\treturn TestFail;\n-\n-\t\tif (camera_->release() != -EBUSY)\n-\t\t\treturn TestFail;\n-\n-\t\tif (camera_->configure(defconf_.get()) != -EACCES)\n-\t\t\treturn TestFail;\n-\n-\t\tif (camera_->allocateBuffers() != -EACCES)\n-\t\t\treturn TestFail;\n-\n \t\tRequest request1(camera_.get());\n \t\tif (camera_->queueRequest(&request1) != -EACCES)\n \t\t\treturn TestFail;\n@@ -170,9 +107,6 @@ protected:\n \t\tdelete request2;\n \n \t\t/* Test valid state transitions, end in Running state. */\n-\t\tif (camera_->freeBuffers())\n-\t\t\treturn TestFail;\n-\n \t\tif (camera_->release())\n \t\t\treturn TestFail;\n \n@@ -182,9 +116,6 @@ protected:\n \t\tif (camera_->configure(defconf_.get()))\n \t\t\treturn TestFail;\n \n-\t\tif (camera_->allocateBuffers())\n-\t\t\treturn TestFail;\n-\n \t\t/* Use internally allocated buffers. */\n \t\tallocator_ = new BufferAllocator(camera_);\n \t\tStream *stream = *camera_->streams().begin();\n@@ -209,12 +140,6 @@ protected:\n \t\tif (camera_->configure(defconf_.get()) != -EACCES)\n \t\t\treturn TestFail;\n \n-\t\tif (camera_->allocateBuffers() != -EACCES)\n-\t\t\treturn TestFail;\n-\n-\t\tif (camera_->freeBuffers() != -EACCES)\n-\t\t\treturn TestFail;\n-\n \t\tif (camera_->start() != -EACCES)\n \t\t\treturn TestFail;\n \n@@ -236,9 +161,6 @@ protected:\n \n \t\tdelete allocator_;\n \n-\t\tif (camera_->freeBuffers())\n-\t\t\treturn TestFail;\n-\n \t\tif (camera_->release())\n \t\t\treturn TestFail;\n \n@@ -276,11 +198,6 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (testPrepared() != TestPass) {\n-\t\t\tcout << \"State machine in Prepared state failed\" << endl;\n-\t\t\treturn TestFail;\n-\t\t}\n-\n \t\tif (testRuning() != TestPass) {\n \t\t\tcout << \"State machine in Running state failed\" << endl;\n \t\t\treturn TestFail;\n","prefixes":["libcamera-devel","30/30"]}