[libcamera-devel] [PATCH v3 20/22] libcamera: uvcvideo: Fill stride and frameSize at config validation
Paul Elder
paul.elder at ideasonboard.com
Sat Jul 4 15:31:38 CEST 2020
Fill the stride and frameSize fields of the StreamConfiguration at
configuration validation time instead of at camera configuration time.
Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
---
New in v3
---
src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 31 ++++++++++++++++----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
index a5feab6..f8d258e 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(V4L2VideoDevice *video);
Status validate() override;
+
+private:
+ V4L2VideoDevice *video_;
};
class PipelineHandlerUVC : public PipelineHandler
@@ -89,8 +92,8 @@ private:
}
};
-UVCCameraConfiguration::UVCCameraConfiguration()
- : CameraConfiguration()
+UVCCameraConfiguration::UVCCameraConfiguration(V4L2VideoDevice *video)
+ : CameraConfiguration(), video_(video)
{
}
@@ -141,6 +144,25 @@ CameraConfiguration::Status UVCCameraConfiguration::validate()
cfg.bufferCount = 4;
+ V4L2DeviceFormat format = {};
+ format.fourcc = video_->toV4L2PixelFormat(cfg.pixelFormat);
+ format.size = cfg.size;
+
+ int ret = video_->tryFormat(&format);
+ if (ret) {
+ LOG(UVC, Warning)
+ << "try_fmt failed, "
+ << "getting stride and frameSize from PixelFormatInfo";
+
+ const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat);
+ cfg.stride = info.stride(cfg.size.width, 0);
+ cfg.frameSize = info.frameSize(cfg.size);
+ return status;
+ }
+
+ cfg.stride = format.planes[0].bpl;
+ cfg.frameSize = format.planes[0].size;
+
return status;
}
@@ -153,7 +175,7 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera,
const StreamRoles &roles)
{
UVCCameraData *data = cameraData(camera);
- CameraConfiguration *config = new UVCCameraConfiguration();
+ CameraConfiguration *config = new UVCCameraConfiguration(data->video_);
if (roles.empty())
return config;
@@ -200,7 +222,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