image_publisher.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2023 RealSense, Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include "ros_node_base.h"
  16. #include <sensor_msgs/msg/image.hpp>
  17. #include <image_transport/image_transport.hpp>
  18. namespace realsense2_camera {
  19. class image_publisher
  20. {
  21. public:
  22. virtual void publish( sensor_msgs::msg::Image::UniquePtr image_ptr ) = 0;
  23. virtual size_t get_subscription_count() const = 0;
  24. virtual ~image_publisher() = default;
  25. };
  26. // Native RCL implementation of an image publisher (needed for intra-process communication)
  27. class image_rcl_publisher : public image_publisher
  28. {
  29. public:
  30. image_rcl_publisher( RosNodeBase & node,
  31. const std::string & topic_name,
  32. const rmw_qos_profile_t & qos );
  33. void publish( sensor_msgs::msg::Image::UniquePtr image_ptr ) override;
  34. size_t get_subscription_count() const override;
  35. private:
  36. rclcpp::Publisher< sensor_msgs::msg::Image >::SharedPtr image_publisher_impl;
  37. };
  38. // image_transport implementation of an image publisher (adds a compressed image topic)
  39. class image_transport_publisher : public image_publisher
  40. {
  41. public:
  42. image_transport_publisher( rclcpp::Node & node,
  43. const std::string & topic_name,
  44. const rmw_qos_profile_t & qos );
  45. void publish( sensor_msgs::msg::Image::UniquePtr image_ptr ) override;
  46. size_t get_subscription_count() const override;
  47. private:
  48. std::shared_ptr< image_transport::Publisher > image_publisher_impl;
  49. };
  50. } // namespace realsense2_camera