ros-perception / image_common

Common code for working with images in ROS
http://www.ros.org/wiki/image_common
124 stars 219 forks source link

Support zero-copy intra-process publishing (backport #306) #310

Closed mergify[bot] closed 3 months ago

mergify[bot] commented 3 months ago

ROS2 supports intra-process communication when composing multiple nodes in a single process. It additionally can avoid doing any copies of the data when published using std::unique_ptr<MessageT> and subscribed using shared_ptr<const MessageT> or std::unique_ptr<MessageT> (at most 1 subscriber)

This PR is my attempt to add support for publishing using std::unique_ptr without breaking any of the existing APIs.

The idea is that:

  1. Each publisher plugin can decide whether they support publishing using unique ptr (for now I don't see how any other plugin than raw can take advantage of the ownership).
  2. The new Publisher::publish(sensor_msgs::msg::Image::UniquePtr message) method first publishes using the const reference to plugins that don't support std::unique_ptr, then moves the ownership of the message to (at most 1) plugin that supports it.
  3. If there is more than one plugin that supports std::unique_ptr and has subscriptions, we pass the ownership to only one such plugin (the first we find), and for the rest we still use const reference, delegating doing any extra copies to plugin implementations.

Related issues/prs:

212

215

216 (kinda)
This is an automatic backport of pull request #306 done by Mergify.

ahcorde commented 3 months ago

Holding off on this one for Jazzy patch release 1.