summaryrefslogtreecommitdiff
path: root/src/cam/camera_session.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-07-05 19:05:23 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-07-22 17:13:46 +0300
commit8e716be52900389215344577112e88df0d8616df (patch)
treef4f3b12f47f91395ef389ff33c3073b0f9726784 /src/cam/camera_session.cpp
parent34d986d1ec342e84db0302d28b7d8bc98c2cd054 (diff)
cam: Move CameraConfiguration creation to CameraSession class
Creating a configuration for a camera is an operation that logically belongs to the CameraSession class. Move it there. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/cam/camera_session.cpp')
-rw-r--r--src/cam/camera_session.cpp47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp
index 7bb75e86..edc7205d 100644
--- a/src/cam/camera_session.cpp
+++ b/src/cam/camera_session.cpp
@@ -15,14 +15,53 @@
#include "camera_session.h"
#include "event_loop.h"
#include "main.h"
+#include "stream_options.h"
using namespace libcamera;
CameraSession::CameraSession(std::shared_ptr<Camera> camera,
- CameraConfiguration *config)
- : camera_(camera), config_(config), last_(0), queueCount_(0),
- captureCount_(0), captureLimit_(0), printMetadata_(false)
+ const OptionsParser::Options &options)
+ : camera_(camera), last_(0), queueCount_(0), captureCount_(0),
+ captureLimit_(0), printMetadata_(false)
{
+ StreamRoles roles = StreamKeyValueParser::roles(options[OptStream]);
+
+ std::unique_ptr<CameraConfiguration> config =
+ camera_->generateConfiguration(roles);
+ if (!config || config->size() != roles.size()) {
+ std::cerr << "Failed to get default stream configuration"
+ << std::endl;
+ return;
+ }
+
+ /* Apply configuration if explicitly requested. */
+ if (StreamKeyValueParser::updateConfiguration(config.get(),
+ options[OptStream])) {
+ std::cerr << "Failed to update configuration" << std::endl;
+ return;
+ }
+
+ bool strictFormats = options.isSet(OptStrictFormats);
+
+ switch (config->validate()) {
+ case CameraConfiguration::Valid:
+ break;
+
+ case CameraConfiguration::Adjusted:
+ if (strictFormats) {
+ std::cout << "Adjusting camera configuration disallowed by --strict-formats argument"
+ << std::endl;
+ return;
+ }
+ std::cout << "Camera configuration adjusted" << std::endl;
+ break;
+
+ case CameraConfiguration::Invalid:
+ std::cout << "Camera configuration invalid" << std::endl;
+ return;
+ }
+
+ config_ = std::move(config);
}
int CameraSession::start(const OptionsParser::Options &options)
@@ -34,7 +73,7 @@ int CameraSession::start(const OptionsParser::Options &options)
captureLimit_ = options[OptCapture].toInteger();
printMetadata_ = options.isSet(OptMetadata);
- ret = camera_->configure(config_);
+ ret = camera_->configure(config_.get());
if (ret < 0) {
std::cout << "Failed to configure camera" << std::endl;
return ret;