Skip to content

Commit 25e753d

Browse files
authored
fix: Use new image_transport API when applicable (#203)
* fix: Remove usage of deprecated rclcpp API * Make the fix compatible with older distributions * Fix again * Keep forcing QoS depth of 1 in ros_compressed streamer * Update get_qos_profile_from_name API * Remove unused transport hints
1 parent 4b5f4e3 commit 25e753d

5 files changed

Lines changed: 24 additions & 15 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ if(${cv_bridge_VERSION} VERSION_LESS "3.3.0")
4141
add_compile_definitions(CV_BRIDGE_USES_OLD_HEADERS)
4242
endif()
4343

44+
if(${image_transport_VERSION} VERSION_LESS "6.4.0")
45+
add_compile_definitions(IMAGE_TRANSPORT_USES_OLD_API)
46+
endif()
47+
4448
## Declare a cpp library
4549
add_library(${PROJECT_NAME} SHARED
4650
src/web_video_server.cpp

include/web_video_server/utils.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@
3232
#include <string>
3333
#include <optional>
3434

35-
#include "rmw/types.h"
35+
#include "rclcpp/qos.hpp"
3636

3737
namespace web_video_server
3838
{
3939

4040
/**
4141
* @brief Gets a QoS profile given an input name, if valid.
42-
* @param name The name of the QoS profile name.
42+
* @param name The name of the QoS profile.
4343
* @return An optional containing the matching QoS profile.
4444
*/
45-
std::optional<rmw_qos_profile_t> get_qos_profile_from_name(std::string name);
45+
std::optional<rclcpp::QoS> get_qos_profile_from_name(const std::string & name);
4646

4747
} // namespace web_video_server

src/streamers/image_transport_streamer.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#include "async_web_server_cpp/http_connection.hpp"
5353
#include "async_web_server_cpp/http_request.hpp"
5454
#include "image_transport/image_transport.hpp"
55-
#include "image_transport/transport_hints.hpp"
5655
#include "rclcpp/node.hpp"
5756
#include "rclcpp/logging.hpp"
5857
#include "rmw/qos_profiles.h"
@@ -118,7 +117,6 @@ void ImageTransportStreamerBase::start()
118117
return;
119118
}
120119

121-
const image_transport::TransportHints hints(node.get(), default_transport_);
122120
auto tnat = node->get_topic_names_and_types();
123121
inactive_ = true;
124122
for (auto topic_and_types : tnat) {
@@ -139,18 +137,25 @@ void ImageTransportStreamerBase::start()
139137
qos_profile_name_.c_str());
140138
auto qos_profile = get_qos_profile_from_name(qos_profile_name_);
141139
if (!qos_profile) {
142-
qos_profile = rmw_qos_profile_default;
140+
qos_profile = rclcpp::QoS(rclcpp::QoSInitialization::from_rmw(rmw_qos_profile_default));
143141
RCLCPP_ERROR(
144142
logger_,
145143
"Invalid QoS profile %s specified. Using default profile.",
146144
qos_profile_name_.c_str());
147145
}
148146

149147
// Create subscriber
148+
#ifdef IMAGE_TRANSPORT_USES_OLD_API
150149
image_sub_ = image_transport::create_subscription(
151150
node.get(), topic_,
152151
std::bind(&ImageTransportStreamerBase::image_callback, this, std::placeholders::_1),
152+
default_transport_, qos_profile.value().get_rmw_qos_profile());
153+
#else
154+
image_sub_ = image_transport::create_subscription(
155+
*node.get(), topic_,
156+
std::bind(&ImageTransportStreamerBase::image_callback, this, std::placeholders::_1),
153157
default_transport_, qos_profile.value());
158+
#endif
154159
}
155160

156161
#pragma GCC diagnostic pop

src/streamers/ros_compressed_streamer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ rclcpp::QoS make_compressed_qos(
8484
logger,
8585
"Invalid QoS profile %s specified. Using default profile.",
8686
qos_profile_name.c_str());
87-
qos_profile = rmw_qos_profile_default;
87+
qos_profile = rclcpp::QoS(rclcpp::QoSInitialization::from_rmw(rmw_qos_profile_default));
8888
}
8989

90-
return rclcpp::QoS(
91-
rclcpp::QoSInitialization(qos_profile.value().history, 1),
92-
qos_profile.value());
90+
auto qos = qos_profile.value();
91+
qos.keep_last(1);
92+
return qos;
9393
}
9494

9595
std::optional<std::string> resolve_content_type(

src/utils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@
3232
#include <optional>
3333
#include <string>
3434

35+
#include "rclcpp/qos.hpp"
3536
#include "rmw/qos_profiles.h"
36-
#include "rmw/types.h"
3737

3838
namespace web_video_server
3939
{
4040

41-
std::optional<rmw_qos_profile_t> get_qos_profile_from_name(const std::string name)
41+
std::optional<rclcpp::QoS> get_qos_profile_from_name(const std::string & name)
4242
{
4343
if (name == "default") {
44-
return rmw_qos_profile_default;
44+
return rclcpp::QoS(rclcpp::QoSInitialization::from_rmw(rmw_qos_profile_default));
4545
}
4646
if (name == "system_default") {
47-
return rmw_qos_profile_system_default;
47+
return rclcpp::SystemDefaultsQoS();
4848
}
4949
if (name == "sensor_data") {
50-
return rmw_qos_profile_sensor_data;
50+
return rclcpp::SensorDataQoS();
5151
}
5252
return std::nullopt;
5353
}

0 commit comments

Comments
 (0)