From fc7338449da5789a59337d57d7ca374bbd7a0ad9 Mon Sep 17 00:00:00 2001 From: Domenic Rodriguez Date: Mon, 17 May 2021 08:14:44 -0400 Subject: [PATCH] Fix build for ROS2 Foxy (#111) * Fix build for ROS2 Foxy * Switch incoming CompressedImage msgs to use RCL_ROS_TIME --- CMakeLists.txt | 4 ++-- include/web_video_server/h264_streamer.h | 2 +- include/web_video_server/image_streamer.h | 4 ++-- include/web_video_server/jpeg_streamers.h | 2 +- include/web_video_server/libav_streamer.h | 2 +- include/web_video_server/png_streamers.h | 2 +- include/web_video_server/vp8_streamer.h | 2 +- include/web_video_server/vp9_streamer.h | 2 +- package.xml | 4 ++++ src/jpeg_streamers.cpp | 4 ++-- src/png_streamers.cpp | 4 ++-- src/ros_compressed_streamer.cpp | 4 ++-- src/web_video_server.cpp | 6 +++--- 13 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d756a4..ce84c17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,8 +66,6 @@ target_link_libraries(${PROJECT_NAME} ${swscale_LIBRARIES} ) -ament_package() - ############# ## Install ## ############# @@ -81,3 +79,5 @@ install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION include/${PROJECT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp" ) + +ament_package() diff --git a/include/web_video_server/h264_streamer.h b/include/web_video_server/h264_streamer.h index 1d9fa31..9961389 100644 --- a/include/web_video_server/h264_streamer.h +++ b/include/web_video_server/h264_streamer.h @@ -1,7 +1,7 @@ #ifndef H264_STREAMERS_H_ #define H264_STREAMERS_H_ -#include +#include #include "web_video_server/libav_streamer.h" #include "async_web_server_cpp/http_request.hpp" #include "async_web_server_cpp/http_connection.hpp" diff --git a/include/web_video_server/image_streamer.h b/include/web_video_server/image_streamer.h index c2f5a07..59a1a92 100644 --- a/include/web_video_server/image_streamer.h +++ b/include/web_video_server/image_streamer.h @@ -2,8 +2,8 @@ #define IMAGE_STREAMER_H_ #include -#include -#include +#include +#include #include #include "async_web_server_cpp/http_server.hpp" #include "async_web_server_cpp/http_request.hpp" diff --git a/include/web_video_server/jpeg_streamers.h b/include/web_video_server/jpeg_streamers.h index 30a202b..ad788fa 100644 --- a/include/web_video_server/jpeg_streamers.h +++ b/include/web_video_server/jpeg_streamers.h @@ -1,7 +1,7 @@ #ifndef JPEG_STREAMERS_H_ #define JPEG_STREAMERS_H_ -#include +#include #include "web_video_server/image_streamer.h" #include "async_web_server_cpp/http_request.hpp" #include "async_web_server_cpp/http_connection.hpp" diff --git a/include/web_video_server/libav_streamer.h b/include/web_video_server/libav_streamer.h index 87ef1c7..643e3b3 100644 --- a/include/web_video_server/libav_streamer.h +++ b/include/web_video_server/libav_streamer.h @@ -1,7 +1,7 @@ #ifndef LIBAV_STREAMERS_H_ #define LIBAV_STREAMERS_H_ -#include +#include #include "web_video_server/image_streamer.h" #include "async_web_server_cpp/http_request.hpp" #include "async_web_server_cpp/http_connection.hpp" diff --git a/include/web_video_server/png_streamers.h b/include/web_video_server/png_streamers.h index 197ecc3..a6edabc 100644 --- a/include/web_video_server/png_streamers.h +++ b/include/web_video_server/png_streamers.h @@ -1,7 +1,7 @@ #ifndef PNG_STREAMERS_H_ #define PNG_STREAMERS_H_ -#include +#include #include "web_video_server/image_streamer.h" #include "async_web_server_cpp/http_request.hpp" #include "async_web_server_cpp/http_connection.hpp" diff --git a/include/web_video_server/vp8_streamer.h b/include/web_video_server/vp8_streamer.h index 0f4cd7d..46e8bed 100644 --- a/include/web_video_server/vp8_streamer.h +++ b/include/web_video_server/vp8_streamer.h @@ -37,7 +37,7 @@ #ifndef VP8_STREAMERS_H_ #define VP8_STREAMERS_H_ -#include +#include #include "web_video_server/libav_streamer.h" #include "async_web_server_cpp/http_request.hpp" #include "async_web_server_cpp/http_connection.hpp" diff --git a/include/web_video_server/vp9_streamer.h b/include/web_video_server/vp9_streamer.h index d7f0a2d..06c48f8 100644 --- a/include/web_video_server/vp9_streamer.h +++ b/include/web_video_server/vp9_streamer.h @@ -1,7 +1,7 @@ #ifndef VP9_STREAMERS_H_ #define VP9_STREAMERS_H_ -#include +#include #include "web_video_server/libav_streamer.h" #include "async_web_server_cpp/http_request.hpp" #include "async_web_server_cpp/http_connection.hpp" diff --git a/package.xml b/package.xml index a4989f5..6e3a11c 100644 --- a/package.xml +++ b/package.xml @@ -28,4 +28,8 @@ async_web_server_cpp ffmpeg sensor_msgs + + + ament_cmake + diff --git a/src/jpeg_streamers.cpp b/src/jpeg_streamers.cpp index 029cb96..0c5cf88 100644 --- a/src/jpeg_streamers.cpp +++ b/src/jpeg_streamers.cpp @@ -21,7 +21,7 @@ MjpegStreamer::~MjpegStreamer() void MjpegStreamer::sendImage(const cv::Mat &img, const rclcpp::Time &time) { std::vector encode_params; - encode_params.push_back(CV_IMWRITE_JPEG_QUALITY); + encode_params.push_back(cv::IMWRITE_JPEG_QUALITY); encode_params.push_back(quality_); std::vector encoded_buffer; @@ -63,7 +63,7 @@ JpegSnapshotStreamer::~JpegSnapshotStreamer() void JpegSnapshotStreamer::sendImage(const cv::Mat &img, const rclcpp::Time &time) { std::vector encode_params; - encode_params.push_back(CV_IMWRITE_JPEG_QUALITY); + encode_params.push_back(cv::IMWRITE_JPEG_QUALITY); encode_params.push_back(quality_); std::vector encoded_buffer; diff --git a/src/png_streamers.cpp b/src/png_streamers.cpp index 692e48b..1a9f874 100644 --- a/src/png_streamers.cpp +++ b/src/png_streamers.cpp @@ -21,7 +21,7 @@ PngStreamer::~PngStreamer() void PngStreamer::sendImage(const cv::Mat &img, const rclcpp::Time &time) { std::vector encode_params; - encode_params.push_back(CV_IMWRITE_PNG_COMPRESSION); + encode_params.push_back(cv::IMWRITE_PNG_COMPRESSION); encode_params.push_back(quality_); std::vector encoded_buffer; @@ -63,7 +63,7 @@ PngSnapshotStreamer::~PngSnapshotStreamer() void PngSnapshotStreamer::sendImage(const cv::Mat &img, const rclcpp::Time &time) { std::vector encode_params; - encode_params.push_back(CV_IMWRITE_PNG_COMPRESSION); + encode_params.push_back(cv::IMWRITE_PNG_COMPRESSION); encode_params.push_back(quality_); std::vector encoded_buffer; diff --git a/src/ros_compressed_streamer.cpp b/src/ros_compressed_streamer.cpp index 5ef2031..e64889a 100644 --- a/src/ros_compressed_streamer.cpp +++ b/src/ros_compressed_streamer.cpp @@ -19,7 +19,7 @@ RosCompressedStreamer::~RosCompressedStreamer() void RosCompressedStreamer::start() { std::string compressed_topic = topic_ + "/compressed"; image_sub_ = nh_->create_subscription( - compressed_topic, std::bind(&RosCompressedStreamer::imageCallback, this, std::placeholders::_1), 1); + compressed_topic, 1, std::bind(&RosCompressedStreamer::imageCallback, this, std::placeholders::_1)); } void RosCompressedStreamer::restreamFrame(double max_age) @@ -77,7 +77,7 @@ void RosCompressedStreamer::sendImage(const sensor_msgs::msg::CompressedImage::C void RosCompressedStreamer::imageCallback(const sensor_msgs::msg::CompressedImage::ConstSharedPtr msg) { boost::mutex::scoped_lock lock(send_mutex_); // protects last_msg and last_frame last_msg = msg; - last_frame = rclcpp::Time(msg->header.stamp.sec, msg->header.stamp.nanosec); + last_frame = rclcpp::Time(msg->header.stamp); sendImage(last_msg, last_frame); } diff --git a/src/web_video_server.cpp b/src/web_video_server.cpp index a442165..e0384a1 100644 --- a/src/web_video_server.cpp +++ b/src/web_video_server.cpp @@ -135,7 +135,7 @@ void WebVideoServer::spin() { server_->run(); RCLCPP_INFO(nh_->get_logger(), "Waiting For connections on %s:%d", address_.c_str(), port_); - rclcpp::executors::MultiThreadedExecutor spinner(rclcpp::executor::create_default_executor_arguments(), ros_threads_); + rclcpp::executors::MultiThreadedExecutor spinner(rclcpp::ExecutorOptions(), ros_threads_); spinner.add_node(nh_); if ( publish_rate_ > 0 ) { nh_->create_wall_timer(1s / publish_rate_, [this](){restreamFrames(1.0 / publish_rate_);}); @@ -298,11 +298,11 @@ bool WebVideoServer::handle_list_streams(const async_web_server_cpp::HttpRequest auto & topic_type = topic_and_types.second[0]; // explicitly take the first // TODO debugging fprintf(stderr, "topic_type: %s\n", topic_type.c_str()); - if (topic_type == "sensor_msgs/Image") + if (topic_type == "sensor_msgs/msg/Image") { image_topics.push_back(topic_name); } - else if (topic_type == "sensor_msgs/CameraInfo") + else if (topic_type == "sensor_msgs/msg/CameraInfo") { camera_info_topics.push_back(topic_name); }