Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: adding method to access CameraManager #528

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the GetCameras() override is needed right? Instead you need to change (below):

static std::vector<std::shared_ptr<libcamera::Camera>> GetCameras(const std::unique_ptr<CameraManager> &cm)

to

static std::vector<std::shared_ptr<libcamera::Camera>> GetCameras(const CameraManager> *cm)

Copy link
Author

@anjok anjok Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right.

But I already have a LibCameraApp, so I might as well just use a new app->GetCameras() off of it and not deal with the camera manager at all? After all, I was only doing that because that's what the multiple other code pieces in LibCameraApp did and you didn't have a singular means to get at the list.

Also, you'd need to change "public", if interim, API.. I don't care one way or another, but given there's no way to get at the manager without an app in the first place, and there's not way to get a unique_ptr without having one first, I would recommend (again without knowing a lot about what all of this does or should do) to remove the static method and just have an instance method....

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so the options use that method... why? I guess this is where our problems came from, as we're using the options when the app has already been created. So now you have two cam managers... at least I think so.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another place that uses GetCameras() with the camera manager already opened. This is why passing in an external camera manager must still be supported.

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