use global shared camera manager - #150
Conversation
christianrauch
left a comment
There was a problem hiding this comment.
Your scenario with the two composable nodes makes sense.
Note that the long-term goal is to drop the singleton requirement for the CameraManager. See https://gitlab.freedesktop.org/camera/libcamera/-/issues/246. I am fine with a static camera manager in the node class, but would prefer if this is supported by libcamera as other camera nodes or libraries using libcamera could potentially also be loaded into the container.
| libcamera::CameraManager camera_manager; | ||
| std::shared_ptr<libcamera::CameraManager> camera_manager; |
There was a problem hiding this comment.
Why do we need the static g_camera_manager as well as the camera_manager?
There was a problem hiding this comment.
Yes, we need both.
The static std::weak_ptr<...> g_camera_manager just checks whether a CameraManager already exists. This is the case when another CameraNode was started.
The std::shared_ptr<...> camera_manager is the actual owner of the CameraManager and keeps it alive.
There was a problem hiding this comment.
The
static std::weak_ptr<...> g_camera_managerjust checks whether aCameraManageralready exists. This is the case when anotherCameraNodewas started.
But can this not be determined by the value of the pointer? If camera_manager is nullptr, this is the first time the node runs, and we have to initialise a libcamera::CameraManager. If it is not nullptr, we can just reuse it, using the mutex of course. You can also encapsulate this in something like a get_camera_manager_instance method, that always creates an instance, either by constructing a new CameraManager, or returning the previously constructed.
d31d753 to
5d7ff48
Compare
|
Can you test, if this works with a single static |
|
@AntoBrandi Are you still in this? I did a quick test with |
|
@AntoBrandi The |
I was having the same problem described here: #113 while trying to load multiple camera drivers (as Composable Nodes) into the same ROS 2 Container.
This is especially useful to optimize resources and guarantee zero-copy transmission from the nodes in the same container.

This PR fixes the error
by having a global, shared CameraManager object.
To reproduce the issue:
ros2 run rclcpp_components component_containerros2 component load /ComponentManager camera_ros camera::CameraNode --parameter camera:=1 --parameter frame_id:=right_camera --node-namespace /rightros2 component load /ComponentManager camera_ros camera::CameraNode --parameter camera:=0 --parameter frame_id:=left_camera --node-namespace /left