[libcamera-devel,v5,17/19] libcamera: ipu3: Validate the pipe configuration

Message ID 20200731153320.58107-18-jacopo@jmondi.org
State Accepted
Headers show
Series
  • [libcamera-devel,v5,01/19] libcamera: ipu3: Rename mbusCodesToInfo
Related show

Commit Message

Jacopo Mondi July 31, 2020, 3:33 p.m. UTC
Collect the desired ImgU pipe configuration while assigning
streams in the pipeline handler validate() function and ask the
ImgUDevice class to calculate the pipe configuration parameters.

If the requested pipe configuration results in a non-valid
configuration, return an error from the validate() function.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/pipeline/ipu3/ipu3.cpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Patch

diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index a081a81c860c..19c6b1aba2de 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -77,6 +77,7 @@  private:
 	const IPU3CameraData *data_;
 
 	StreamConfiguration cio2Configuration_;
+	ImgUDevice::PipeConfig pipeConfig_;
 };
 
 class PipelineHandlerIPU3 : public PipelineHandler
@@ -189,6 +190,9 @@  CameraConfiguration::Status IPU3CameraConfiguration::validate()
 
 	LOG(IPU3, Debug) << "CIO2 configuration: " << cio2Configuration_.toString();
 
+	ImgUDevice::Pipe pipe{};
+	pipe.input = cio2Configuration_.size;
+
 	/*
 	 * Adjust the configurations if needed and assign streams while
 	 * iterating them.
@@ -263,10 +267,15 @@  CameraConfiguration::Status IPU3CameraConfiguration::validate()
 				cfg->setStream(const_cast<Stream *>(&data_->outStream_));
 				mainOutputAvailable = false;
 
+				pipe.main = cfg->size;
+				if (yuvCount == 1)
+					pipe.viewfinder = pipe.main;
+
 				LOG(IPU3, Debug) << "Assigned " << cfg->toString()
 						 << " to the main output";
 			} else {
 				cfg->setStream(const_cast<Stream *>(&data_->vfStream_));
+				pipe.viewfinder = cfg->size;
 
 				LOG(IPU3, Debug) << "Assigned " << cfg->toString()
 						 << " to the viewfinder output";
@@ -282,6 +291,16 @@  CameraConfiguration::Status IPU3CameraConfiguration::validate()
 		}
 	}
 
+	/* Only compute the ImgU configuration if a YUV stream has been requested. */
+	if (yuvCount) {
+		pipeConfig_ = data_->imgu_->calculatePipeConfig(&pipe);
+		if (pipeConfig_.isNull()) {
+			LOG(IPU3, Error) << "Failed to calculate pipe configuration: "
+					 << "unsupported resolutions.";
+			return Invalid;
+		}
+	}
+
 	return status;
 }