From c3ed0deac1bca54f31e1f014a3ea94ba04054019 Mon Sep 17 00:00:00 2001 From: Bernd Pfrommer Date: Thu, 7 Aug 2025 17:09:49 -0400 Subject: [PATCH 1/2] better error message when filtering decoder --- src/utils.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/utils.cpp b/src/utils.cpp index 4c5515d..a07ed20 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -213,7 +213,8 @@ enum AVPixelFormat ros_to_av_pix_format(const std::string & ros_pix_fmt) const auto it = ros_to_av_pix_map.find(ros_pix_fmt); if (it == ros_to_av_pix_map.end()) { RCLCPP_ERROR_STREAM( - rclcpp::get_logger("encoder"), "no AV pixel format known for ros format " << ros_pix_fmt); + rclcpp::get_logger("encoder/decoder"), + "no AV pixel format known for ros format " << ros_pix_fmt); throw(std::runtime_error("no matching pixel format found for: " + ros_pix_fmt)); } return (it->second); @@ -314,11 +315,19 @@ std::string filter_decoders(const std::string & codec, const std::string & decod std::string filtered; const auto valid_decoders = split_by_char(find_decoders(codec), ','); for (const auto & dec : split_by_char(decoders, ',')) { + bool found = false; for (const auto & valid : valid_decoders) { if (dec == valid) { filtered += (filtered.empty() ? "" : ",") + dec; + found = true; + break; } } + if (!found) { + RCLCPP_WARN_STREAM( + rclcpp::get_logger("encoder/decoder"), + "ignoring invalid decoder " << dec << " for codec " << codec); + } } return (filtered); } From eb14dcc1eb45d1917f13d324989685a07b3a2df4 Mon Sep 17 00:00:00 2001 From: Bernd Pfrommer Date: Thu, 7 Aug 2025 20:57:25 -0400 Subject: [PATCH 2/2] added utility functions for splitting --- include/ffmpeg_encoder_decoder/utils.hpp | 15 +++++++++++++++ src/decoder.cpp | 7 +------ src/utils.cpp | 14 ++++++++++++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/include/ffmpeg_encoder_decoder/utils.hpp b/include/ffmpeg_encoder_decoder/utils.hpp index 9dce509..5b498a8 100644 --- a/include/ffmpeg_encoder_decoder/utils.hpp +++ b/include/ffmpeg_encoder_decoder/utils.hpp @@ -175,6 +175,21 @@ std::vector split_by_char(const std::string & str_list, const char * \return true if ROS encoding is single channel and color format is like NV12/yuv420p */ bool encode_single_channel_as_color(const std::string & encoding, enum AVPixelFormat fmt); + +/** + * \brief splits a string with a list of decoders + * \param decoder_list comma-separated list of decoders + * \return vector of separated strings + */ +std::vector split_decoders(const std::string & decoder_list); + +/** + * \brief splits a string with an encoding ("codec;fmt;fmt;fmt") + * \param encoding string with encoding information + * \return vector of separated strings + */ +std::vector split_encoding(const std::string & encoding); + } // namespace utils } // namespace ffmpeg_encoder_decoder #endif // FFMPEG_ENCODER_DECODER__UTILS_HPP_ diff --git a/src/decoder.cpp b/src/decoder.cpp index 667ec44..5dbb2f7 100644 --- a/src/decoder.cpp +++ b/src/decoder.cpp @@ -66,15 +66,10 @@ void Decoder::setOutputMessageEncoding(const std::string & output_encoding) outputMsgEncoding_ = output_encoding; } -static std::vector splitEncoding(const std::string & encoding) -{ - return (utils::split_by_char(encoding, ';')); -} - void Decoder::setEncoding(const std::string & encoding) { packetEncoding_ = encoding; - const auto split = splitEncoding(encoding); + const auto split = ffmpeg_encoder_decoder::utils::split_encoding(encoding); if (outputMsgEncoding_.empty()) { // assume orig was bgr8 outputMsgEncoding_ = split.size() == 4 ? split[3] : "bgr8"; diff --git a/src/utils.cpp b/src/utils.cpp index a07ed20..e22bd89 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -266,6 +266,16 @@ std::vector split_by_char(const std::string & str_list, const char return (split); } +std::vector split_decoders(const std::string & decoder_list) +{ + return (split_by_char(decoder_list, ',')); +} + +std::vector split_encoding(const std::string & encoding) +{ + return (split_by_char(encoding, ';')); +} + // This function finds the encoding that is the target of a given encoder. static AVCodecID find_id_for_encoder_or_encoding(const std::string & encoder) @@ -313,8 +323,8 @@ std::string find_decoders(const std::string & codec) std::string filter_decoders(const std::string & codec, const std::string & decoders) { std::string filtered; - const auto valid_decoders = split_by_char(find_decoders(codec), ','); - for (const auto & dec : split_by_char(decoders, ',')) { + const auto valid_decoders = split_decoders(find_decoders(codec)); + for (const auto & dec : split_decoders(decoders)) { bool found = false; for (const auto & valid : valid_decoders) { if (dec == valid) {