Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AVIF image transport plugin #156

Draft
wants to merge 3 commits into
base: rolling
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions avif_image_transport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
cmake_minimum_required(VERSION 3.5)

project(avif_image_transport)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)
find_package(image_transport REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)

include_directories(include)

add_library(
${PROJECT_NAME} SHARED
src/avif_publisher.cpp
src/avif_subscriber.cpp
src/manifest.cpp
)

target_link_libraries(${PROJECT_NAME} avif)

ament_target_dependencies(${PROJECT_NAME}
"image_transport"
"rclcpp"
"pluginlib"
"sensor_msgs"
)

install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

install(
DIRECTORY "include/"
DESTINATION include
)
pluginlib_export_plugin_description_file(image_transport avif_plugins.xml)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
19 changes: 19 additions & 0 deletions avif_image_transport/avif_plugins.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<library path="avif_image_transport">
<class
name="image_transport/avif_pub"
type="avif_image_transport::AVIFPublisher"
base_class_type="image_transport::PublisherPlugin">
<description>
This plugin publishes a AVIF image
</description>
</class>

<class
name="image_transport/avif_sub"
type="avif_image_transport::AVIFSubscriber"
base_class_type="image_transport::SubscriberPlugin">
<description>
This plugin decompresses a AVIF Image.
</description>
</class>
</library>
51 changes: 51 additions & 0 deletions avif_image_transport/include/avif_image_transport/avif_common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2023, Open Source Robotics Foundation, Inc.
// All rights reserved.
//
// Software License Agreement (BSD License 2.0)
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef AVIF_IMAGE_TRANSPORT__AVIF_COMMON_HPP_
#define AVIF_IMAGE_TRANSPORT__AVIF_COMMON_HPP_

#include <rclcpp/parameter_value.hpp>
#include <rcl_interfaces/msg/parameter_descriptor.hpp>

namespace avif_image_transport
{
using ParameterDescriptor = rcl_interfaces::msg::ParameterDescriptor;
using ParameterValue = rclcpp::ParameterValue;

struct ParameterDefinition
{
const ParameterValue defaultValue;
const ParameterDescriptor descriptor;
};
} // namespace avif_image_transport

#endif // AVIF_IMAGE_TRANSPORT__AVIF_COMMON_HPP_
101 changes: 101 additions & 0 deletions avif_image_transport/include/avif_image_transport/avif_publisher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright (c) 2023, Open Source Robotics Foundation, Inc.
// All rights reserved.
//
// Software License Agreement (BSD License 2.0)
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef AVIF_IMAGE_TRANSPORT__AVIF_PUBLISHER_HPP_
#define AVIF_IMAGE_TRANSPORT__AVIF_PUBLISHER_HPP_

#include <avif/avif.h>

#include <memory>
#include <string>
#include <vector>

#include <sensor_msgs/msg/image.hpp>
#include <sensor_msgs/msg/compressed_image.hpp>
#include <image_transport/simple_publisher_plugin.hpp>

#include <rclcpp/node.hpp>

#include "avif_image_transport/avif_common.hpp"

namespace avif_image_transport
{
using CompressedImage = sensor_msgs::msg::CompressedImage;
using ParameterEvent = rcl_interfaces::msg::ParameterEvent;

struct AvifImageDeleter
{
void operator()(avifImage * image) {avifImageDestroy(image);}
};

using AvifImageUniquePtr = std::unique_ptr<avifImage, AvifImageDeleter>;

class AVIFPublisher : public image_transport::SimplePublisherPlugin<CompressedImage>
{
public:
AVIFPublisher();
~AVIFPublisher() override;
std::string getTransportName() const override;

protected:
// Overridden to set up reconfigure server
void advertiseImpl(
rclcpp::Node * node,
const std::string & base_topic,
rmw_qos_profile_t custom_qos,
rclcpp::PublisherOptions options) override;

void publish(
const sensor_msgs::msg::Image & message,
const PublishFn & publish_fn) const override;

rclcpp::Logger logger_;
rclcpp::Node * node_;

private:
AvifImageUniquePtr ConvertToAvif(
const sensor_msgs::msg::Image & message,
bool lossless,
int bit_depth) const;

std::vector<std::string> parameters_;

avifEncoder * encoder_ = NULL;

void declareParameter(
const std::string & base_name,
const ParameterDefinition & definition);
};

} // namespace avif_image_transport

#endif // AVIF_IMAGE_TRANSPORT__AVIF_PUBLISHER_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright (c) 2023, Open Source Robotics Foundation, Inc.
// All rights reserved.
//
// Software License Agreement (BSD License 2.0)
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.


#ifndef AVIF_IMAGE_TRANSPORT__AVIF_SUBSCRIBER_HPP_
#define AVIF_IMAGE_TRANSPORT__AVIF_SUBSCRIBER_HPP_

#include <avif/avif.h>

#include <memory>
#include <mutex>
#include <string>
#include <vector>

#include <rclcpp/node.hpp>
#include <rclcpp/subscription_options.hpp>

#include <sensor_msgs/msg/image.hpp>
#include <sensor_msgs/msg/compressed_image.hpp>
#include <image_transport/simple_subscriber_plugin.hpp>

#include "avif_image_transport/avif_common.hpp"


namespace avif_image_transport
{
using CompressedImage = sensor_msgs::msg::CompressedImage;
using ParameterEvent = rcl_interfaces::msg::ParameterEvent;

class AVIFSubscriber final
: public image_transport::SimpleSubscriberPlugin<sensor_msgs::msg::CompressedImage>
{
public:
AVIFSubscriber();
virtual ~AVIFSubscriber() = default;

std::string getTransportName() const override;

protected:
void subscribeImpl(
rclcpp::Node *,
const std::string & base_topic,
const Callback & callback,
rmw_qos_profile_t custom_qos,
rclcpp::SubscriptionOptions options) override;

void internalCallback(
const sensor_msgs::msg::CompressedImage::ConstSharedPtr & message,
const Callback & user_cb) override;

rclcpp::Logger logger_;
rclcpp::Node * node_;

private:
avifDecoder * decoder_;
std::mutex mutex;
};

} // namespace avif_image_transport

#endif // AVIF_IMAGE_TRANSPORT__AVIF_SUBSCRIBER_HPP_
25 changes: 25 additions & 0 deletions avif_image_transport/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<package format="2">
<name>avif_image_transport</name>
<version>3.2.0</version>
<description>
avif_image_transport provides a plugin to image_transport for transparently sending images
encoded as avif
</description>
<maintainer email="[email protected]">Alejandro Hernandez Cordero</maintainer>
<license>BSD</license>

<url type="website">http://www.ros.org/wiki/image_transport_plugins</url>
<author>Alejandro Hernandez Cordero</author>

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>image_transport</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
<image_transport plugin="${prefix}/zstd_plugins.xml" />
</export>
</package>
Loading