[libcamera-devel,v5,12/23] libcamera: ipu3: Fill stride and frameSize at config validation

Message ID 20200709132835.112593-13-paul.elder@ideasonboard.com
State Accepted
Headers show
Series
  • Clean up formats in v4l2-compat and pipeline handlers
Related show

Commit Message

Paul Elder July 9, 2020, 1:28 p.m. UTC
Fill the stride and frameSize fields of the StreamConfiguration at
configuration validation time instead of at camera configuration time.
This allows applications to get the stride when trying a configuration
without modifying the active configuration of the camera.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

---
Changes in v5:
- simplify code

Changes in v4:
- fix stride and frameSize calculation
- mention motivation in commit message

New in v3
---
 src/libcamera/pipeline/ipu3/ipu3.cpp | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Patch

diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index af51fb2..eb00eec 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -278,6 +278,12 @@  CameraConfiguration::Status IPU3CameraConfiguration::validate()
 				<< cfg.toString();
 			status = Adjusted;
 		}
+
+		const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat);
+		bool packedRaw = info.colourEncoding == PixelFormatInfo::ColourEncodingRAW;
+
+		cfg.stride = info.stride(cfg.size.width, 0, packedRaw ? 64 : 1);
+		cfg.frameSize = info.frameSize(cfg.size, packedRaw ? 64 : 1);
 	}
 
 	return status;
@@ -495,21 +501,13 @@  int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c)
 			if (ret)
 				return ret;
 
-			cfg.stride = outputFormat.planes[0].bpl;
 			outActive = true;
 		} else if (stream == vfStream) {
 			ret = imgu->configureViewfinder(cfg, &outputFormat);
 			if (ret)
 				return ret;
 
-			cfg.stride = outputFormat.planes[0].bpl;
 			vfActive = true;
-		} else {
-			/*
-			 * The RAW stream is configured as part of the CIO2 and
-			 * no configuration is needed for the ImgU.
-			 */
-			cfg.stride = cio2Format.planes[0].bpl;
 		}
 	}