diff options
author | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2020-07-10 16:44:01 +0100 |
---|---|---|
committer | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2024-05-14 23:56:49 +0100 |
commit | ab62ab959a27fdacb5e12f700c480b4a56e10026 (patch) | |
tree | b3e39799a962ba151bb67b2a5ebd2b3880236f9c | |
parent | 4a143800322dc66c8701489ba8fbf17a2d2b6b4f (diff) |
libcamera: pipeline: vivid: Generate and validate StreamConfigurations
Implement the support for Generating and Validating the streams the
Camera can provide.
Vivid is a simple case with only a single stream.
Test the configurations can be generated and reported with cam -I:
"""
LIBCAMERA_LOG_LEVELS=Pipeline,VIVID:0 ./src/cam/cam -c 1 -I
[232:02:09.633067174] [2882911] INFO IPAManager ipa_manager.cpp:136 libcamera is not installed. Adding '/home//libcamera/build-vivid/src/ipa' to the IPA search path
[232:02:09.633332451] [2882911] WARN IPAManager ipa_manager.cpp:147 No IPA found in '/usr/local/lib/x86_64-linux-gnu/libcamera'
[232:02:09.633373414] [2882911] INFO Camera camera_manager.cpp:283 libcamera v0.0.11+714-d1ebd889-dirty
Using camera vivid
0: 1280x720-BGR888
* Pixelformat: NV21 (320x180)-(3840x2160)/(+0,+0)
- 320x180
- 640x360
- 640x480
- 1280x720
- 1920x1080
- 3840x2160
* Pixelformat: NV12 (320x180)-(3840x2160)/(+0,+0)
- 320x180
- 640x360
- 640x480
- 1280x720
- 1920x1080
- 3840x2160
* Pixelformat: BGRA8888 (320x180)-(3840x2160)/(+0,+0)
- 320x180
- 640x360
- 640x480
- 1280x720
- 1920x1080
- 3840x2160
* Pixelformat: RGBA8888 (320x180)-(3840x2160)/(+0,+0)
- 320x180
- 640x360
- 640x480
- 1280x720
- 1920x1080
- 3840x2160
"""
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
-rw-r--r-- | src/libcamera/pipeline/vivid/vivid.cpp | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/src/libcamera/pipeline/vivid/vivid.cpp b/src/libcamera/pipeline/vivid/vivid.cpp index ec81f2a9..3f697789 100644 --- a/src/libcamera/pipeline/vivid/vivid.cpp +++ b/src/libcamera/pipeline/vivid/vivid.cpp @@ -7,6 +7,8 @@ #include <libcamera/base/log.h> +#include <libcamera/formats.h> + #include "libcamera/internal/camera.h" #include "libcamera/internal/device_enumerator.h" #include "libcamera/internal/media_device.h" @@ -76,8 +78,49 @@ public: int queueRequestDevice(Camera *camera, Request *request) override; bool match(DeviceEnumerator *enumerator) override; + +private: + int processControls(VividCameraData *data, Request *request); + + VividCameraData *cameraData(Camera *camera) + { + return static_cast<VividCameraData *>(camera->_d()); + } }; +VividCameraConfiguration::VividCameraConfiguration() + : CameraConfiguration() +{ +} + +CameraConfiguration::Status VividCameraConfiguration::validate() +{ + Status status = Valid; + + if (config_.empty()) + return Invalid; + + /* Cap the number of entries to the available streams. */ + if (config_.size() > 1) { + config_.resize(1); + status = Adjusted; + } + + StreamConfiguration &cfg = config_[0]; + + /* Adjust the pixel format. */ + const std::vector<libcamera::PixelFormat> formats = cfg.formats().pixelformats(); + if (std::find(formats.begin(), formats.end(), cfg.pixelFormat) == formats.end()) { + cfg.pixelFormat = cfg.formats().pixelformats()[0]; + LOG(VIVID, Debug) << "Adjusting format to " << cfg.pixelFormat.toString(); + status = Adjusted; + } + + cfg.bufferCount = 4; + + return status; +} + PipelineHandlerVivid::PipelineHandlerVivid(CameraManager *manager) : PipelineHandler(manager) { @@ -86,7 +129,37 @@ PipelineHandlerVivid::PipelineHandlerVivid(CameraManager *manager) std::unique_ptr<CameraConfiguration> PipelineHandlerVivid::generateConfiguration(Camera *camera, Span<const StreamRole> roles) { - return std::unique_ptr<CameraConfiguration>(nullptr); + std::unique_ptr<CameraConfiguration> config = + std::make_unique<VividCameraConfiguration>(); + VividCameraData *data = cameraData(camera); + + if (roles.empty()) + return config; + + std::map<V4L2PixelFormat, std::vector<SizeRange>> v4l2Formats = + data->video_->formats(); + std::map<PixelFormat, std::vector<SizeRange>> deviceFormats; + std::transform(v4l2Formats.begin(), v4l2Formats.end(), + std::inserter(deviceFormats, deviceFormats.begin()), + [&](const decltype(v4l2Formats)::value_type &format) { + return decltype(deviceFormats)::value_type{ + format.first.toPixelFormat(), + format.second + }; + }); + + StreamFormats formats(deviceFormats); + StreamConfiguration cfg(formats); + + cfg.pixelFormat = formats::BGR888; + cfg.size = { 1280, 720 }; + cfg.bufferCount = 4; + + config->addConfiguration(cfg); + + config->validate(); + + return config; } int PipelineHandlerVivid::configure(Camera *camera, CameraConfiguration *config) |