[libcamera-devel] [PATCH v4 18/21] libcamera: uvcvideo: Fill stride and frameSize at config validation
Paul Elder
paul.elder at ideasonboard.com
Wed Jul 8 15:44:14 CEST 2020
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 at ideasonboard.com>
---
Changes in v4:
- return error if tryFormat fails
- pass UVCCameraData to UVCCameraConfiguration, instead of
V4l2VideoDevice
- mention motivation in commit message
New in v3
---
src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 23 +++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
index 9db69dd..47f383d 100644
--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
@@ -53,9 +53,12 @@ public:
class UVCCameraConfiguration : public CameraConfiguration
{
public:
- UVCCameraConfiguration();
+ UVCCameraConfiguration(UVCCameraData *data);
Status validate() override;
+
+private:
+ UVCCameraData *data_;
};
class PipelineHandlerUVC : public PipelineHandler
@@ -89,8 +92,8 @@ private:
}
};
-UVCCameraConfiguration::UVCCameraConfiguration()
- : CameraConfiguration()
+UVCCameraConfiguration::UVCCameraConfiguration(UVCCameraData *data)
+ : CameraConfiguration(), data_(data)
{
}
@@ -141,6 +144,17 @@ CameraConfiguration::Status UVCCameraConfiguration::validate()
cfg.bufferCount = 4;
+ V4L2DeviceFormat format = {};
+ format.fourcc = data_->video_->toV4L2PixelFormat(cfg.pixelFormat);
+ format.size = cfg.size;
+
+ int ret = data_->video_->tryFormat(&format);
+ if (ret)
+ return Invalid;
+
+ cfg.stride = format.planes[0].bpl;
+ cfg.frameSize = format.planes[0].size;
+
return status;
}
@@ -153,7 +167,7 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera,
const StreamRoles &roles)
{
UVCCameraData *data = cameraData(camera);
- CameraConfiguration *config = new UVCCameraConfiguration();
+ CameraConfiguration *config = new UVCCameraConfiguration(data);
if (roles.empty())
return config;
@@ -200,7 +214,6 @@ int PipelineHandlerUVC::configure(Camera *camera, CameraConfiguration *config)
return -EINVAL;
cfg.setStream(&data->stream_);
- cfg.stride = format.planes[0].bpl;
return 0;
}
--
2.27.0
More information about the libcamera-devel
mailing list