mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-21 23:55:07 +03:00
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>
This commit is contained in:
parent
8e716be529
commit
8519df23a9
3 changed files with 43 additions and 41 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue