-
Notifications
You must be signed in to change notification settings - Fork 212
feat: Use pluginlib to load streamer plugins at runtime, general refactor #192
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
Open
bjsowa
wants to merge
33
commits into
ros2
Choose a base branch
from
feat/use-pluginlib
base: ros2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
bd73182
Reorganize files
bjsowa bf4af8e
Clean up include directives by including only what's used
bjsowa 26c1322
Clean up package.xml depend tags
bjsowa 17ea6f6
Load streamer plugins using pluginlib
bjsowa e5903e0
Move checking for compressed topics to the plugin itself
bjsowa 1da7991
Add snapshot streamer plugins
bjsowa ec8347c
Add ros_compressed snapshot streamer plugin
bjsowa 72d483e
Detect content type in ros_compressed snapshot streamer
bjsowa 18be8e2
Fix libav streamer factory
bjsowa 90f3ed1
Update listing available topics
bjsowa 3437fee
List snapshot streamers
bjsowa 0e8f668
Add missing includes
bjsowa c4a90b2
Revise class naming conventions
bjsowa 0e12cc8
Move base classes to web_video_server_streamers library
bjsowa bd1489b
Reformat for humble
bjsowa f2467b8
Add some docstrings
bjsowa 1d41e26
Use snake_case for method names
bjsowa db07bd9
boundry -> boundary
bjsowa bf22ec0
decodeImage -> decode_image
bjsowa 55a53cb
Move base streamer classes to streamers namespace
bjsowa 7121805
Reduce duplicated code
bjsowa e9cfad2
Add virtual destructor
bjsowa f0103d0
Include what you use
bjsowa 463b756
Update copyright headers
bjsowa c0177a4
Export project dependencies
bjsowa 54bbd89
Add missing copyright header
bjsowa e2752fb
Pass reference to get_available_topics
bjsowa 7c39972
Remove redundant ImageTransport object
bjsowa 36cbb92
Fix restream frames feature
bjsowa 1c7502c
Pass weak node pointer to streamers to avoid cyclic dependency
bjsowa 79b965f
Fix formatting for humble
bjsowa dd82d45
Add myself to authors
bjsowa 10607cb
Update README, add custom streamer plugin tutorial
bjsowa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| // Copyright (c) 2014, Worcester Polytechnic Institute | ||
| // Copyright (c) 2024, The Robot Web Tools Contributors | ||
| // All rights reserved. | ||
| // | ||
| // 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 HOLDER 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. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <chrono> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "async_web_server_cpp/http_connection.hpp" | ||
| #include "async_web_server_cpp/http_request.hpp" | ||
| #include "rclcpp/node.hpp" | ||
|
|
||
| namespace web_video_server | ||
| { | ||
|
|
||
| /** | ||
| * @brief A common interface for all streaming plugins. | ||
| */ | ||
| class StreamerInterface | ||
| { | ||
| public: | ||
| StreamerInterface( | ||
| const async_web_server_cpp::HttpRequest & request, | ||
| async_web_server_cpp::HttpConnectionPtr connection, | ||
| rclcpp::Node::SharedPtr node); | ||
| virtual ~StreamerInterface(); | ||
|
|
||
| /** | ||
| * @brief Starts the streaming process. | ||
| */ | ||
| virtual void start() = 0; | ||
|
|
||
| /** | ||
| * @brief Returns true if the streamer is inactive and should be deleted. | ||
| * | ||
| * This could be because the connection was closed or snapshot was successfully sent (in case | ||
| * of snapshot streamers). | ||
| */ | ||
| bool is_inactive() | ||
| { | ||
| return inactive_; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Restreams the last received image frame if older than max_age. | ||
| */ | ||
| virtual void restream_frame(std::chrono::duration<double> max_age) = 0; | ||
|
|
||
| /** | ||
| * @brief Returns the topic being streamed. | ||
| */ | ||
| std::string get_topic() | ||
| { | ||
| return topic_; | ||
| } | ||
|
|
||
| protected: | ||
| async_web_server_cpp::HttpConnectionPtr connection_; | ||
| async_web_server_cpp::HttpRequest request_; | ||
| rclcpp::Node::SharedPtr node_; | ||
| bool inactive_; | ||
| std::string topic_; | ||
| }; | ||
|
|
||
| /** | ||
| * @brief A factory interface for creating Streamer instances. | ||
| */ | ||
| class StreamerFactoryInterface | ||
| { | ||
| public: | ||
| virtual ~StreamerFactoryInterface() = default; | ||
|
|
||
| /** | ||
| * @brief Returns the type of streamer created by this factory. | ||
| * | ||
| * This should match the "type" query parameter used to select the streamer. | ||
| */ | ||
| virtual std::string get_type() = 0; | ||
|
|
||
| /** | ||
| * @brief Creates a new Streamer instance. | ||
| * @param request The HTTP request that initiated the streamer. | ||
| * @param connection The HTTP connection to use for streaming. | ||
| * @param node The ROS2 node to use for subscribing to topics. | ||
| * @return A shared pointer to the created Streamer instance. | ||
| */ | ||
| virtual std::shared_ptr<StreamerInterface> create_streamer( | ||
| const async_web_server_cpp::HttpRequest & request, | ||
| async_web_server_cpp::HttpConnectionPtr connection, | ||
| rclcpp::Node::SharedPtr node) = 0; | ||
|
|
||
| /** | ||
| * @brief Creates HTML code for embedding a viewer for this streamer. | ||
| * @param request The HTTP request that initiated the viewer. | ||
| */ | ||
| virtual std::string create_viewer(const async_web_server_cpp::HttpRequest & request); | ||
|
|
||
| /** | ||
| * @brief Returns a list of available topics that can be streamed by this streamer. | ||
| * @param node The ROS2 node to use for discovering topics. | ||
| * @return A vector of topic names. | ||
| */ | ||
| virtual std::vector<std::string> get_available_topics(rclcpp::Node::SharedPtr node); | ||
| }; | ||
|
|
||
| /** | ||
| * @brief A factory interface for creating snapshot Streamer instances. | ||
| */ | ||
| class SnapshotStreamerFactoryInterface : public StreamerFactoryInterface {}; | ||
|
|
||
| } // namespace web_video_server | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it odd that something called "interface" has any non-virtual members, but it's not a huge deal.