Skip to content

Commit

Permalink
core: adding method to access CameraManager
Browse files Browse the repository at this point in the history
Added the ability to get at the CameraManager to allow for access to the Camera list.
Also addded instance method to get the Camera list.

Signed-off-by: Anjo Krank <[email protected]>
  • Loading branch information
Anjo Krank authored and naushir committed Jul 10, 2023
1 parent 3d9ac10 commit 69122be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion core/libcamera_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void LibcameraApp::OpenCamera()
if (ret)
throw std::runtime_error("camera manager failed to start, code " + std::to_string(-ret));

std::vector<std::shared_ptr<libcamera::Camera>> cameras = LibcameraApp::GetCameras(camera_manager_);
std::vector<std::shared_ptr<libcamera::Camera>> cameras = GetCameras();
if (cameras.size() == 0)
throw std::runtime_error("no cameras available");
if (options_->camera >= cameras.size())
Expand Down Expand Up @@ -773,6 +773,11 @@ libcamera::Stream *LibcameraApp::GetMainStream() const
return nullptr;
}

const libcamera::CameraManager *LibcameraApp::GetCameraManager() const
{
return camera_manager_.get();
}

std::vector<libcamera::Span<uint8_t>> LibcameraApp::Mmap(FrameBuffer *buffer) const
{
auto item = mapped_buffers_.find(buffer);
Expand Down
8 changes: 7 additions & 1 deletion core/libcamera_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ class LibcameraApp
Stream *LoresStream(StreamInfo *info = nullptr) const;
Stream *GetMainStream() const;

const CameraManager *GetCameraManager() const;
std::vector<std::shared_ptr<libcamera::Camera>> GetCameras()
{
return GetCameras(camera_manager_.get());
}

std::vector<libcamera::Span<uint8_t>> Mmap(FrameBuffer *buffer) const;

void ShowPreview(CompletedRequestPtr &completed_request, Stream *stream);
Expand All @@ -129,7 +135,7 @@ class LibcameraApp
static unsigned int verbosity;
static unsigned int GetVerbosity() { return verbosity; }

static std::vector<std::shared_ptr<libcamera::Camera>> GetCameras(const std::unique_ptr<CameraManager> &cm)
static std::vector<std::shared_ptr<libcamera::Camera>> GetCameras(const CameraManager *cm)
{
std::vector<std::shared_ptr<libcamera::Camera>> cameras = cm->cameras();
// Do not show USB webcams as these are not supported in libcamera-apps!
Expand Down
2 changes: 1 addition & 1 deletion core/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ bool Options::Parse(int argc, char *argv[])
if (ret)
throw std::runtime_error("camera manager failed to start, code " + std::to_string(-ret));

std::vector<std::shared_ptr<libcamera::Camera>> cameras = LibcameraApp::GetCameras(cm);
std::vector<std::shared_ptr<libcamera::Camera>> cameras = LibcameraApp::GetCameras(cm.get());
if (cameras.size() != 0)
{
unsigned int idx = 0;
Expand Down

0 comments on commit 69122be

Please sign in to comment.