[libcamera-devel,v2,2/9] ipu3: Allow only one camera being started
diff mbox series

Message ID 20220526082737.1081262-3-chenghaoyang@google.com
State Superseded
Headers show
Series
  • Use two imgus in ipu3 pipeline handler
Related show

Commit Message

Harvey Yang May 26, 2022, 8:27 a.m. UTC
From: Harvey Yang <chenghaoyang@chromium.org>

As we hardly have use cases/applications that need both cameras at the
same time, this patch adds a rule that only one camera can be started
one time. This also allows the following patches that use both imgus to
process frames from one single camera.

Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>
---
 src/libcamera/pipeline/ipu3/ipu3.cpp | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index fd989e61..c943ee6a 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -166,6 +166,8 @@  private:
 	MediaDevice *cio2MediaDev_;
 	MediaDevice *imguMediaDev_;
 
+	Camera *inUseCamera_ = nullptr;
+
 	std::vector<IPABuffer> ipaBuffers_;
 };
 
@@ -765,6 +767,14 @@  int PipelineHandlerIPU3::freeBuffers(Camera *camera)
 
 int PipelineHandlerIPU3::start(Camera *camera, [[maybe_unused]] const ControlList *controls)
 {
+	/*
+	 * Enforce that only a single camera can be used at a time to use both
+	 * ImgUs on the camera, so that StillCapture stream can adopt another
+	 * set of configuration.
+	 */
+	if (inUseCamera_ && inUseCamera_ != camera)
+		return -EBUSY;
+
 	IPU3CameraData *data = cameraData(camera);
 	CIO2Device *cio2 = &data->cio2_;
 	ImgUDevice *imgu = data->imgu_;
@@ -781,6 +791,8 @@  int PipelineHandlerIPU3::start(Camera *camera, [[maybe_unused]] const ControlLis
 	if (ret)
 		return ret;
 
+	inUseCamera_ = camera;
+
 	ret = data->ipa_->start();
 	if (ret)
 		goto error;
@@ -808,6 +820,8 @@  error:
 	freeBuffers(camera);
 	LOG(IPU3, Error) << "Failed to start camera " << camera->id();
 
+	inUseCamera_ = nullptr;
+
 	return ret;
 }
 
@@ -826,6 +840,8 @@  void PipelineHandlerIPU3::stopDevice(Camera *camera)
 		LOG(IPU3, Warning) << "Failed to stop camera " << camera->id();
 
 	freeBuffers(camera);
+
+	inUseCamera_ = nullptr;
 }
 
 void IPU3CameraData::cancelPendingRequests()