summaryrefslogtreecommitdiff
path: root/src/cam/camera_session.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-07-06 07:33:10 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-07-22 17:13:47 +0300
commit8519df23a9b8fbc4d845787bc4ad443792736347 (patch)
treed2da6c60f76402e7946ae5bead517bee6b1572b4 /src/cam/camera_session.cpp
parent8e716be52900389215344577112e88df0d8616df (diff)
cam: Move camera acquire to the CameraSession class
Continue moving towards making the CameraSession class the central point to handle a camera by moving the camera acquire operation. A new CameraSession::camera() function is needed to allow access to the camera from CamApp. 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.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp
index edc7205d..10e66446 100644
--- a/src/cam/camera_session.cpp
+++ b/src/cam/camera_session.cpp
@@ -19,11 +19,30 @@
using namespace libcamera;
-CameraSession::CameraSession(std::shared_ptr<Camera> camera,
+CameraSession::CameraSession(CameraManager *cm,
const OptionsParser::Options &options)
- : camera_(camera), last_(0), queueCount_(0), captureCount_(0),
+ : last_(0), queueCount_(0), captureCount_(0),
captureLimit_(0), printMetadata_(false)
{
+ const std::string &cameraId = options[OptCamera];
+ char *endptr;
+ unsigned long index = strtoul(cameraId.c_str(), &endptr, 10);
+ if (*endptr == '\0' && index > 0 && index <= cm->cameras().size())
+ camera_ = cm->cameras()[index - 1];
+ else
+ camera_ = cm->get(cameraId);
+
+ if (!camera_) {
+ std::cerr << "Camera " << cameraId << " not found" << std::endl;
+ return;
+ }
+
+ if (camera_->acquire()) {
+ std::cerr << "Failed to acquire camera " << cameraId
+ << std::endl;
+ return;
+ }
+
StreamRoles roles = StreamKeyValueParser::roles(options[OptStream]);
std::unique_ptr<CameraConfiguration> config =
@@ -64,6 +83,12 @@ CameraSession::CameraSession(std::shared_ptr<Camera> camera,
config_ = std::move(config);
}
+CameraSession::~CameraSession()
+{
+ if (camera_)
+ camera_->release();
+}
+
int CameraSession::start(const OptionsParser::Options &options)
{
int ret;