Skip to content

Commit

Permalink
[ROS2] port package to ament_cmake / ROS 2 API (#69)
Browse files Browse the repository at this point in the history
* switch from catkin to ament_cmake

* update code to use ROS 2 API

* use ament_cmake_ros

* remove Travis for now

* set CMAKE_CXX_STANDARD

* use API closer to ROS 1

* fix type format match bug in ros2 (#79)

* add node to Executor (#80)

* using shared_ptr to manage the cleanup_timer (#81)

* fix argument mismatch
  • Loading branch information
dirk-thomas authored Sep 19, 2019
1 parent 97ac8e4 commit 84b410b
Show file tree
Hide file tree
Showing 21 changed files with 185 additions and 184 deletions.
40 changes: 0 additions & 40 deletions .travis.yml

This file was deleted.

38 changes: 21 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
cmake_minimum_required(VERSION 2.8.3)
cmake_minimum_required(VERSION 3.5)
project(web_video_server)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS roscpp roslib cv_bridge image_transport async_web_server_cpp sensor_msgs)
find_package(ament_cmake_ros REQUIRED)

find_package(async_web_server_cpp REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(image_transport REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)

find_package(OpenCV REQUIRED)
find_package(Boost REQUIRED COMPONENTS thread)

Expand All @@ -14,22 +18,20 @@ pkg_check_modules(avformat libavformat REQUIRED)
pkg_check_modules(avutil libavutil REQUIRED)
pkg_check_modules(swscale libswscale REQUIRED)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

###################################################
## Declare things to be passed to other projects ##
###################################################

## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package()

###########
## Build ##
###########

## Specify additional locations of header files
include_directories(include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${avcodec_INCLUDE_DIRS}
${avformat_INCLUDE_DIRS}
Expand All @@ -49,9 +51,11 @@ add_executable(${PROJECT_NAME}
src/ros_compressed_streamer.cpp
src/jpeg_streamers.cpp)

ament_target_dependencies(${PROJECT_NAME}
async_web_server_cpp cv_bridge image_transport rclcpp sensor_msgs)

## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
${Boost_LIBRARIES}
${OpenCV_LIBS}
${avcodec_LIBRARIES}
Expand All @@ -60,18 +64,18 @@ target_link_libraries(${PROJECT_NAME}
${swscale_LIBRARIES}
)

ament_package()

#############
## Install ##
#############

## Mark executables and/or libraries for installation
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY include/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION include/${PROJECT_NAME}
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp"
)
4 changes: 2 additions & 2 deletions include/web_video_server/h264_streamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class H264Streamer : public LibavStreamer
{
public:
H264Streamer(const async_web_server_cpp::HttpRequest& request, async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh);
rclcpp::Node::SharedPtr nh);
~H264Streamer();
protected:
virtual void initializeEncoder();
Expand All @@ -26,7 +26,7 @@ class H264StreamerType : public LibavStreamerType
H264StreamerType();
virtual boost::shared_ptr<ImageStreamer> create_streamer(const async_web_server_cpp::HttpRequest& request,
async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh);
rclcpp::Node::SharedPtr nh);
};

}
Expand Down
15 changes: 8 additions & 7 deletions include/web_video_server/image_streamer.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef IMAGE_STREAMER_H_
#define IMAGE_STREAMER_H_

#include <ros/ros.h>
#include <rclcpp/rclcpp.hpp>
#include <image_transport/image_transport.h>
#include <image_transport/transport_hints.h>
#include <opencv2/opencv.hpp>
#include "async_web_server_cpp/http_server.hpp"
#include "async_web_server_cpp/http_request.hpp"
Expand All @@ -15,7 +16,7 @@ class ImageStreamer
public:
ImageStreamer(const async_web_server_cpp::HttpRequest &request,
async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh);
rclcpp::Node::SharedPtr nh);

virtual void start() = 0;

Expand All @@ -33,7 +34,7 @@ class ImageStreamer
protected:
async_web_server_cpp::HttpConnectionPtr connection_;
async_web_server_cpp::HttpRequest request_;
ros::NodeHandle nh_;
rclcpp::Node::SharedPtr nh_;
bool inactive_;
image_transport::Subscriber image_sub_;
std::string topic_;
Expand All @@ -44,12 +45,12 @@ class ImageTransportImageStreamer : public ImageStreamer
{
public:
ImageTransportImageStreamer(const async_web_server_cpp::HttpRequest &request, async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh);
rclcpp::Node::SharedPtr nh);

virtual void start();

protected:
virtual void sendImage(const cv::Mat &, const ros::Time &time) = 0;
virtual void sendImage(const cv::Mat &, const rclcpp::Time &time) = 0;

virtual void initialize(const cv::Mat &);

Expand All @@ -62,15 +63,15 @@ class ImageTransportImageStreamer : public ImageStreamer
image_transport::ImageTransport it_;
bool initialized_;

void imageCallback(const sensor_msgs::ImageConstPtr &msg);
void imageCallback(const sensor_msgs::msg::Image::ConstSharedPtr &msg);
};

class ImageStreamerType
{
public:
virtual boost::shared_ptr<ImageStreamer> create_streamer(const async_web_server_cpp::HttpRequest &request,
async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh) = 0;
rclcpp::Node::SharedPtr nh) = 0;

virtual std::string create_viewer(const async_web_server_cpp::HttpRequest &request) = 0;
};
Expand Down
10 changes: 5 additions & 5 deletions include/web_video_server/jpeg_streamers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class MjpegStreamer : public ImageTransportImageStreamer
{
public:
MjpegStreamer(const async_web_server_cpp::HttpRequest &request, async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh);
rclcpp::Node::SharedPtr nh);

protected:
virtual void sendImage(const cv::Mat &, const ros::Time &time);
virtual void sendImage(const cv::Mat &, const rclcpp::Time &time);

private:
MultipartStream stream_;
Expand All @@ -29,18 +29,18 @@ class MjpegStreamerType : public ImageStreamerType
public:
boost::shared_ptr<ImageStreamer> create_streamer(const async_web_server_cpp::HttpRequest &request,
async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh);
rclcpp::Node::SharedPtr nh);
std::string create_viewer(const async_web_server_cpp::HttpRequest &request);
};

class JpegSnapshotStreamer : public ImageTransportImageStreamer
{
public:
JpegSnapshotStreamer(const async_web_server_cpp::HttpRequest &request,
async_web_server_cpp::HttpConnectionPtr connection, ros::NodeHandle& nh);
async_web_server_cpp::HttpConnectionPtr connection, rclcpp::Node::SharedPtr nh);

protected:
virtual void sendImage(const cv::Mat &, const ros::Time &time);
virtual void sendImage(const cv::Mat &, const rclcpp::Time &time);

private:
int quality_;
Expand Down
8 changes: 4 additions & 4 deletions include/web_video_server/libav_streamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class LibavStreamer : public ImageTransportImageStreamer
{
public:
LibavStreamer(const async_web_server_cpp::HttpRequest &request, async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh, const std::string &format_name, const std::string &codec_name,
rclcpp::Node::SharedPtr nh, const std::string &format_name, const std::string &codec_name,
const std::string &content_type);

~LibavStreamer();

protected:
virtual void initializeEncoder();
virtual void sendImage(const cv::Mat&, const ros::Time& time);
virtual void sendImage(const cv::Mat&, const rclcpp::Time& time);
virtual void initialize(const cv::Mat&);
AVOutputFormat* output_format_;
AVFormatContext* format_context_;
Expand All @@ -45,7 +45,7 @@ class LibavStreamer : public ImageTransportImageStreamer
private:
AVFrame* frame_;
struct SwsContext* sws_context_;
ros::Time first_image_timestamp_;
rclcpp::Time first_image_timestamp_;
boost::mutex encode_mutex_;

std::string format_name_;
Expand All @@ -66,7 +66,7 @@ class LibavStreamerType : public ImageStreamerType

boost::shared_ptr<ImageStreamer> create_streamer(const async_web_server_cpp::HttpRequest &request,
async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh);
rclcpp::Node::SharedPtr nh);

std::string create_viewer(const async_web_server_cpp::HttpRequest &request);

Expand Down
10 changes: 5 additions & 5 deletions include/web_video_server/multipart_stream.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef MULTIPART_STREAM_H_
#define MULTIPART_STREAM_H_

#include <ros/ros.h>
#include <rclcpp/rclcpp.hpp>
#include <async_web_server_cpp/http_connection.hpp>

#include <queue>
Expand All @@ -16,10 +16,10 @@ class MultipartStream {
std::size_t max_queue_size=1);

void sendInitialHeader();
void sendPartHeader(const ros::Time &time, const std::string& type, size_t payload_size);
void sendPartHeader(const rclcpp::Time &time, const std::string& type, size_t payload_size);
void sendPartFooter();
void sendPartAndClear(const ros::Time &time, const std::string& type, std::vector<unsigned char> &data);
void sendPart(const ros::Time &time, const std::string& type, const boost::asio::const_buffer &buffer,
void sendPartAndClear(const rclcpp::Time &time, const std::string& type, std::vector<unsigned char> &data);
void sendPart(const rclcpp::Time &time, const std::string& type, const boost::asio::const_buffer &buffer,
async_web_server_cpp::HttpConnection::ResourcePtr resource);

private:
Expand All @@ -29,7 +29,7 @@ class MultipartStream {
const std::size_t max_queue_size_;
async_web_server_cpp::HttpConnectionPtr connection_;
std::string boundry_;
std::queue<boost::weak_ptr<const void> > pending_footers_;
std::queue<std::weak_ptr<const void> > pending_footers_;
};

}
Expand Down
10 changes: 5 additions & 5 deletions include/web_video_server/ros_compressed_streamer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef ROS_COMPRESSED_STREAMERS_H_
#define ROS_COMPRESSED_STREAMERS_H_

#include <sensor_msgs/CompressedImage.h>
#include <sensor_msgs/msg/compressed_image.hpp>
#include "web_video_server/image_streamer.h"
#include "async_web_server_cpp/http_request.hpp"
#include "async_web_server_cpp/http_connection.hpp"
Expand All @@ -14,22 +14,22 @@ class RosCompressedStreamer : public ImageStreamer
{
public:
RosCompressedStreamer(const async_web_server_cpp::HttpRequest &request, async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh);
rclcpp::Node::SharedPtr nh);
virtual void start();

private:
void imageCallback(const sensor_msgs::CompressedImageConstPtr &msg);
void imageCallback(const sensor_msgs::msg::CompressedImage::ConstSharedPtr msg);

MultipartStream stream_;
ros::Subscriber image_sub_;
rclcpp::Subscription<sensor_msgs::msg::CompressedImage>::SharedPtr image_sub_;
};

class RosCompressedStreamerType : public ImageStreamerType
{
public:
boost::shared_ptr<ImageStreamer> create_streamer(const async_web_server_cpp::HttpRequest &request,
async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh);
rclcpp::Node::SharedPtr nh);
std::string create_viewer(const async_web_server_cpp::HttpRequest &request);
};

Expand Down
4 changes: 2 additions & 2 deletions include/web_video_server/vp8_streamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Vp8Streamer : public LibavStreamer
{
public:
Vp8Streamer(const async_web_server_cpp::HttpRequest& request, async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh);
rclcpp::Node::SharedPtr nh);
~Vp8Streamer();
protected:
virtual void initializeEncoder();
Expand All @@ -63,7 +63,7 @@ class Vp8StreamerType : public LibavStreamerType
Vp8StreamerType();
virtual boost::shared_ptr<ImageStreamer> create_streamer(const async_web_server_cpp::HttpRequest& request,
async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh);
rclcpp::Node::SharedPtr nh);
};

}
Expand Down
4 changes: 2 additions & 2 deletions include/web_video_server/vp9_streamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Vp9Streamer : public LibavStreamer
{
public:
Vp9Streamer(const async_web_server_cpp::HttpRequest& request, async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh);
rclcpp::Node::SharedPtr nh);
~Vp9Streamer();
protected:
virtual void initializeEncoder();
Expand All @@ -25,7 +25,7 @@ class Vp9StreamerType : public LibavStreamerType
Vp9StreamerType();
virtual boost::shared_ptr<ImageStreamer> create_streamer(const async_web_server_cpp::HttpRequest& request,
async_web_server_cpp::HttpConnectionPtr connection,
ros::NodeHandle& nh);
rclcpp::Node::SharedPtr nh);
};

}
Expand Down
Loading

0 comments on commit 84b410b

Please sign in to comment.