[libcamera-devel,v4,23/31] libcamera: ipu3: Enable media links conditionally

Message ID 20190320163055.22056-24-jacopo@jmondi.org
State Superseded
Headers show
Series
  • libcamera: ipu3: Add ImgU support + multiple streams
Related show

Commit Message

Jacopo Mondi March 20, 2019, 4:30 p.m. UTC
Add a method to the IPU3 pipeline handler class to enable media links on
the ImgU device conditionally to the requested stream configuration.

FIXME: media links for viewfinder and stat node should be enabled
unconditionally.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/pipeline/ipu3/ipu3.cpp | 128 +++++++++++++++------------
 1 file changed, 71 insertions(+), 57 deletions(-)

Patch

diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index ac2b14156d4f..ff1e5329c83d 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -55,7 +55,6 @@  public:
 	int linkSetup(const std::string &source, unsigned int sourcePad,
 		      const std::string &sink, unsigned int sinkPad,
 		      bool enable);
-	int enableLinks(bool enable);
 
 	unsigned int index_;
 	std::string imguName_;
@@ -201,6 +200,8 @@  private:
 
 	int initImgU(ImgUDevice *imgu);
 
+	int enableImgULinks(IPU3CameraData *data, bool enable);
+
 	int setInputFormat(ImgUDevice *imguDevice,
 			   const StreamConfiguration &config,
 			   Rectangle *rect);
@@ -364,11 +365,8 @@  int PipelineHandlerIPU3::configureStreams(Camera *camera,
 			CIO2Config.height = cfg.height;
 	}
 
-	/*
-	 * \todo: Enable links selectively based on the requested streams.
-	 * As of now, enable all links unconditionally.
-	 */
-	ret = data->imgu->enableLinks(true);
+	/* Enable links selectively based on the requested streams. */
+	ret = enableImgULinks(data, true);
 	if (ret)
 		return ret;
 
@@ -873,57 +871,6 @@  int ImgUDevice::linkSetup(const std::string &source, unsigned int sourcePad,
 	return link->setEnabled(enable);
 }
 
-/**
- * \brief Enable or disable all media links in the ImgU instance to prepare
- * for capture operations
- *
- * \todo This method will probably be removed or changed once links will be
- * enabled or disabled selectively.
- *
- * \return 0 on success or a negative error code otherwise
- */
-int ImgUDevice::enableLinks(bool enable)
-{
-	std::string inputName = imguName_ + " input";
-	std::string outputName = imguName_ + " output";
-	std::string viewfinderName = imguName_ + " viewfinder";
-	std::string statName = imguName_ + " 3a stat";
-	int ret;
-
-	/* \todo Establish rules to handle media devices open/close. */
-	ret = mediaDevice_->open();
-	if (ret)
-		return ret;
-
-	ret = linkSetup(inputName, 0, imguName_, PAD_INPUT, enable);
-	if (ret) {
-		mediaDevice_->close();
-		return ret;
-	}
-
-	ret = linkSetup(imguName_, PAD_OUTPUT, outputName, 0, enable);
-	if (ret) {
-		mediaDevice_->close();
-		return ret;
-	}
-
-	ret = linkSetup(imguName_, PAD_VF, viewfinderName, 0, enable);
-	if (ret) {
-		mediaDevice_->close();
-		return ret;
-	}
-
-	ret = linkSetup(imguName_, PAD_STAT, statName, 0, enable);
-	if (ret) {
-		mediaDevice_->close();
-		return ret;
-	}
-
-	mediaDevice_->close();
-
-	return 0;
-}
-
 int PipelineHandlerIPU3::mediaBusToCIO2Format(unsigned int code)
 {
 	switch (code) {
@@ -1152,6 +1099,73 @@  void PipelineHandlerIPU3::deleteCIO2(CIO2Device *cio2)
 	delete cio2->sensor;
 }
 
+/**
+ * \brief Enable links on the ImgU media graph based on the requested
+ * stream configuration
+ *
+ * FIXME: viewfinder and stat should be enabled conditionally on the requested
+ * stream configuration. As of now, the IPU3 driver requires them to be
+ * operated unconditionally not to stall ImgU operations.
+ *
+ * \return 0 on success or a negative error code otherwise
+ */
+int PipelineHandlerIPU3::enableImgULinks(IPU3CameraData *data, bool enable)
+{
+	ImgUDevice *imgu = data->imgu;
+	std::string inputName = imgu->imguName_ + " input";
+	std::string outputName = imgu->imguName_ + " output";
+	std::string viewfinderName = imgu->imguName_ + " viewfinder";
+	std::string statName = imgu->imguName_ + " 3a stat";
+	MediaDevice *media = imgu->mediaDevice_;
+	int ret;
+
+	/* \todo Establish rules to handle media devices open/close. */
+	ret = media->open();
+	if (ret)
+		return ret;
+
+	ret = imgu->linkSetup(inputName, 0, imgu->imguName_,
+			      ImgUDevice::PAD_INPUT, enable);
+	if (ret) {
+		media->close();
+		return ret;
+	}
+
+	/* Output has to be operated unconditionally. */
+	ret = imgu->linkSetup(imgu->imguName_, ImgUDevice::PAD_OUTPUT,
+			      outputName, 0, enable);
+	if (ret) {
+		media->close();
+		return ret;
+	}
+
+	/*
+	 * FIXME: viewfinder should be linked and operated only if required
+	 * but currently the IPU3 driver requires it regardless of the stream
+	 * configuration.
+	 */
+	if (isViewfinderActive(data) || true) {
+		ret = imgu->linkSetup(imgu->imguName_, ImgUDevice::PAD_VF,
+				      viewfinderName, 0, enable);
+		if (ret) {
+			media->close();
+			return ret;
+		}
+	}
+
+	/* FIXME: stat should be conditionally operated as well. */
+	ret = imgu->linkSetup(imgu->imguName_, ImgUDevice::PAD_STAT,
+			      statName, 0, enable);
+	if (ret) {
+		media->close();
+		return ret;
+	}
+
+	media->close();
+
+	return 0;
+}
+
 int PipelineHandlerIPU3::setInputFormat(ImgUDevice *imguDevice,
 					const StreamConfiguration &config,
 					Rectangle *rect)