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 SVTAV1 image transport plugin #161

Draft
wants to merge 6 commits into
base: rolling
Choose a base branch
from
Draft
Changes from 1 commit
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
Next Next commit
Added SVTAV1 image transport plugin
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
ahcorde committed Dec 1, 2023
commit 5fd2db7ccef0b78bda404723a95c8935459b0941
64 changes: 64 additions & 0 deletions svtav1_image_transport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
cmake_minimum_required(VERSION 3.16)

project(svtav1_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)
find_package(cv_bridge REQUIRED)
find_package(OpenCV REQUIRED COMPONENTS imgcodecs imgproc videoio)

include_directories(
include
/usr/include/svt-av1/
)

add_library(
${PROJECT_NAME} SHARED
src/svtav1_publisher.cpp
src/svtav1_subscriber.cpp
src/manifest.cpp
)

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

target_link_libraries(${PROJECT_NAME}
/usr/lib/x86_64-linux-gnu/libSvtAv1Enc.so
/usr/lib/x86_64-linux-gnu/libSvtAv1Dec.so
)

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 svtav1_plugins.xml)

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

ament_package()
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 SVTAV1_IMAGE_TRANSPORT__SVTAV1_COMMON_HPP_
#define SVTAV1_IMAGE_TRANSPORT__SVTAV1_COMMON_HPP_

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

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

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

#endif // SVTAV1_IMAGE_TRANSPORT__SVTAV1_COMMON_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// 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 SVTAV1_IMAGE_TRANSPORT__SVTAV1_PUBLISHER_HPP_
#define SVTAV1_IMAGE_TRANSPORT__SVTAV1_PUBLISHER_HPP_

#include <cstdint>
#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 "svtav1_image_transport/svtav1_common.hpp"

#include "EbSvtAv1Enc.h"
#include "EbSvtAv1Dec.h"

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

class SVTAV1Publisher : public image_transport::SimplePublisherPlugin<CompressedImage>
{
public:
SVTAV1Publisher();
~SVTAV1Publisher() 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;

void Initialize(int width, int height) const;

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

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

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

/* SVT-AV1 Encoder Handle */
mutable EbComponentType * svt_encoder{nullptr};
/* SVT-AV1 configuration */
mutable EbSvtAv1EncConfiguration * svt_config{nullptr};
mutable uint64_t frame_count;
// int dts_offset;
mutable EbBufferHeaderType * input_buf{nullptr};

EbSvtAv1DecConfiguration * svt_decoder_config;
EbComponentType * svt_decoder;

mutable std::mutex mutex;
};

} // namespace svtav1_image_transport

#endif // SVTAV1_IMAGE_TRANSPORT__SVTAV1_PUBLISHER_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// 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 SVTAV1_IMAGE_TRANSPORT__SVTAV1_SUBSCRIBER_HPP_
#define SVTAV1_IMAGE_TRANSPORT__SVTAV1_SUBSCRIBER_HPP_

#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 <EbSvtAv1Dec.h>

#include <opencv2/core.hpp>

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

class SVTAV1Subscriber final
: public image_transport::SimpleSubscriberPlugin<sensor_msgs::msg::CompressedImage>
{
public:
SVTAV1Subscriber();
virtual ~SVTAV1Subscriber() = 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_;

EbSvtAv1DecConfiguration * svt_decoder_config{nullptr};
EbComponentType * svt_decoder{nullptr};
EbBufferHeaderType * output_buf{nullptr};
mutable std::mutex mutex;

mutable bool key_frame_received{false};

mutable EbBufferHeaderType * buffer;
mutable cv::Mat mat_BGR2YUV_I420_decode;

private:
};

} // namespace svtav1_image_transport

#endif // SVTAV1_IMAGE_TRANSPORT__SVTAV1_SUBSCRIBER_HPP_
26 changes: 26 additions & 0 deletions svtav1_image_transport/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<package format="2">
<name>svtav1_image_transport</name>
<version>3.2.0</version>
<description>
svtav1_image_transport provides a plugin to image_transport for transparently sending images
encoded as AVT-AV1
</description>
<maintainer email="ahcorde@gmail.com">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>
<depend>cv_bridge</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>
38 changes: 38 additions & 0 deletions svtav1_image_transport/src/manifest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.

#include <pluginlib/class_list_macros.hpp>
#include "svtav1_image_transport/svtav1_publisher.hpp"
#include "svtav1_image_transport/svtav1_subscriber.hpp"

PLUGINLIB_EXPORT_CLASS(svtav1_image_transport::SVTAV1Publisher, image_transport::PublisherPlugin)
PLUGINLIB_EXPORT_CLASS(svtav1_image_transport::SVTAV1Subscriber, image_transport::SubscriberPlugin)
Loading