15 #include <unordered_map> 17 #include <dynamic_reconfigure/Config.h> 19 #include <topic_tools/shape_shifter.h> 76 const std::string& topicOrCodec,
const dynamic_reconfigure::Config& config);
89 const std::string& topicOrCodec,
const dynamic_reconfigure::Config& config);
144 const std::string& topicOrCodec);
199 const std::string& topicOrCodec,
const ros::NodeHandle& nh,
const std::string& param);
213 template<
typename Config>
215 const std::string& topicOrCodec,
const Config& config)
217 dynamic_reconfigure::Config configMsg;
218 config.__toMessage__(configMsg);
219 return this->
encode(raw, topicOrCodec, configMsg);
234 template<
typename Config>
236 const std::string& topicOrCodec,
const Config& config)
238 dynamic_reconfigure::Config configMsg;
239 config.__toMessage__(configMsg);
240 return this->
decode(compressed, topicOrCodec, configMsg);
255 inline cras::expected<M, std::string>
encodeTyped(
const sensor_msgs::Image& raw,
const std::string& topicOrCodec,
256 const dynamic_reconfigure::Config& config)
258 const auto shifter = this->
encode(raw, topicOrCodec, config);
260 return cras::make_unexpected(shifter.error());
264 return *shifter->instantiate<M>();
268 return cras::make_unexpected(
cras::format(
"Invalid shapeshifter returned from encoder: %s.", e.what()));
285 const dynamic_reconfigure::Config& config)
289 return this->
decode(shifter, topicOrCodec, config);
303 inline cras::expected<M, std::string>
encodeTyped(
const sensor_msgs::Image& raw,
const std::string& topicOrCodec)
305 return this->encodeTyped<M>(raw, topicOrCodec, dynamic_reconfigure::Config());
321 return this->
decodeTyped(compressed, topicOrCodec, dynamic_reconfigure::Config());
336 inline cras::expected<M, std::string>
encodeTyped(
const sensor_msgs::Image& raw,
const std::string& topicOrCodec,
339 dynamic_reconfigure::Config configMsg;
340 std::list<std::string> errors;
342 return cras::make_unexpected(
"Invalid encoder config: " +
cras::join(errors,
" "));
344 return this->encodeTyped<M>(raw, topicOrCodec, configMsg);
362 dynamic_reconfigure::Config configMsg;
363 std::list<std::string> errors;
365 return cras::make_unexpected(
"Invalid decoder config: " +
cras::join(errors,
" "));
367 return this->
decodeTyped(compressed, topicOrCodec, configMsg);
383 inline cras::expected<M, std::string>
encodeTyped(
const sensor_msgs::Image& raw,
const std::string& topicOrCodec,
422 template<
typename M,
typename Config>
423 inline cras::expected<M, std::string>
encodeTyped(
const sensor_msgs::Image& raw,
const std::string& topicOrCodec,
424 const Config& config)
426 dynamic_reconfigure::Config configMsg;
427 config.__toMessage__(configMsg);
428 return this->encodeTyped<M>(raw, topicOrCodec, configMsg);
444 template<
typename M,
typename Config>
446 const Config& config)
448 dynamic_reconfigure::Config configMsg;
449 config.__toMessage__(configMsg);
450 return this->
decodeTyped(compressed, topicOrCodec, configMsg);
465 std::string
parseTransport(
const std::string& topicOrCodec)
const;
467 std::unique_ptr<pluginlib::ClassLoader<ImageTransportCodecPlugin>>
loader;
468 std::unordered_map<std::string, ImageTransportCodecPlugin::ConstPtr>
codecs;
508 const char* topicOrCodec,
509 sensor_msgs::Image::_height_type rawHeight,
510 sensor_msgs::Image::_width_type rawWidth,
511 const char* rawEncoding,
512 sensor_msgs::Image::_is_bigendian_type rawIsBigEndian,
513 sensor_msgs::Image::_step_type rawStep,
514 size_t rawDataLength,
515 const uint8_t rawData[],
519 size_t serializedConfigLength,
520 const uint8_t serializedConfig[],
556 const char* topicOrCodec,
557 const char* compressedType,
558 const char* compressedMd5sum,
559 size_t compressedDataLength,
560 const uint8_t compressedData[],
561 sensor_msgs::Image::_height_type& rawHeight,
562 sensor_msgs::Image::_width_type& rawWidth,
564 sensor_msgs::Image::_is_bigendian_type& rawIsBigEndian,
565 sensor_msgs::Image::_step_type& rawStep,
567 size_t serializedConfigLength,
568 const uint8_t serializedConfig[],
603 const char* topicOrCodec,
604 const char* compressedType,
605 const char* compressedMd5sum,
606 size_t compressedDataLength,
607 const uint8_t compressedData[],
608 const char* matchFormat,
Plugin-based interface for compressing and decompressing images using codec plugins.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
cras::expected< cras::ShapeShifter, std::string > EncodeResult
Result of image encoding. Either a shapeshifter holding the compressed message, or error message...
ImageTransportCodec::DecodeResult decodeTyped(const M &compressed, const std::string &topicOrCodec, const dynamic_reconfigure::Config &config)
Decode the given compressed image into a raw image.
void loadCodecs()
Load all codecs available via pluginlib. This function can be called multiple times without negative ...
cras::expected< M, std::string > encodeTyped(const sensor_msgs::Image &raw, const std::string &topicOrCodec)
Encode the given raw image into a compressed image using the default compression parameters.
ImageTransportCodec::DecodeResult decodeTyped(const M &compressed, const std::string &topicOrCodec)
Decode the given compressed image into a raw image using the default decompression parameters...
bool imageTransportCodecsDecode(const char *topicOrCodec, const char *compressedType, const char *compressedMd5sum, size_t compressedDataLength, const uint8_t compressedData[], sensor_msgs::Image::_height_type &rawHeight, sensor_msgs::Image::_width_type &rawWidth, cras::allocator_t rawEncodingAllocator, sensor_msgs::Image::_is_bigendian_type &rawIsBigEndian, sensor_msgs::Image::_step_type &rawStep, cras::allocator_t rawDataAllocator, size_t serializedConfigLength, const uint8_t serializedConfig[], cras::allocator_t errorStringAllocator, cras::allocator_t logMessagesAllocator)
Decode the given compressed image using compressed codec with the given config.
std::unique_ptr< pluginlib::ClassLoader< ImageTransportCodecPlugin > > loader
Pluginlib loader of codecs.
Plugin interface to image transport codecs which allows automatic selection of a suitable codec by Im...
virtual ImageTransportCodec::DecodeResult decode(const topic_tools::ShapeShifter &compressed, const std::string &topicOrCodec, const dynamic_reconfigure::Config &config)
Decode the given compressed image shapeshifter into a raw image.
void addCodec(const ImageTransportCodecPlugin::ConstPtr &codec)
Manually add a codec instance. This is usually not needed as the codecs are autodetected using plugin...
std::unordered_map< std::string, ImageTransportCodecPlugin::ConstPtr > codecs
Loaded codecs.
cras::expected< M, std::string > encodeTyped(const sensor_msgs::Image &raw, const std::string &topicOrCodec, const dynamic_reconfigure::Config &config)
Encode the given raw image into a compressed image.
cras::expected< sensor_msgs::Image, std::string > DecodeResult
Result of image decoding. Either a sensor_msgs::Image holding the raw message, or error message...
ImageTransportCodecs(const cras::LogHelperPtr &log=std::make_shared< cras::NodeLogHelper >())
Create the codec interface and load all available codecs.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void msgToShapeShifter(const T &msg, ::topic_tools::ShapeShifter &shifter)
ImageTransportCodec::EncodeResult encode(const sensor_msgs::Image &raw, const std::string &topicOrCodec, const Config &config)
Encode the given raw image into a compressed image shapeshifter.
cras::expected< cras::optional< CompressedImageContent >, std::string > GetCompressedContentResult
Result of getting the actual compressed image data.
Base for all image transport codecs.
bool imageTransportCodecsEncode(const char *topicOrCodec, sensor_msgs::Image::_height_type rawHeight, sensor_msgs::Image::_width_type rawWidth, const char *rawEncoding, sensor_msgs::Image::_is_bigendian_type rawIsBigEndian, sensor_msgs::Image::_step_type rawStep, size_t rawDataLength, const uint8_t rawData[], cras::allocator_t compressedTypeAllocator, cras::allocator_t md5SumAllocator, cras::allocator_t compressedDataAllocator, size_t serializedConfigLength, const uint8_t serializedConfig[], cras::allocator_t errorStringAllocator, cras::allocator_t logMessagesAllocator)
C API ///.
ImageTransportCodec::DecodeResult decodeTyped(const M &compressed, const std::string &topicOrCodec, const Config &config)
Decode the given compressed image into a raw image.
virtual ImageTransportCodec::GetCompressedContentResult getCompressedImageContent(const topic_tools::ShapeShifter &compressed, const std::string &topicOrCodec, const std::string &matchFormat) const
Return the part of the encoded message that represents the actual image data (i.e. the part that can be passed to external decoders or saved to a file). If the codec messages have no such meaning, empty result is returned.
bool convert(const ::XmlRpc::XmlRpcValue &x, ::XmlRpc::XmlRpcValue &v, bool=false, ::std::list<::std::string > *errors=nullptr)
inline ::std::string format(const char *format, ::va_list args)
bool getCompressedImageContents(const char *topicOrCodec, const char *compressedType, const char *compressedMd5sum, size_t compressedDataLength, const uint8_t compressedData[], const char *matchFormat, bool &hasData, cras::allocator_t formatAllocator, cras::allocator_t dataAllocator, cras::allocator_t errorStringAllocator, cras::allocator_t logMessagesAllocator)
Return the part of the encoded message that represents the actual image data (i.e. the part that can be passed to external decoders or saved to a file). If the codec messages have no such meaning, empty result is returned.
virtual ImageTransportCodec::EncodeResult encode(const sensor_msgs::Image &raw, const std::string &topicOrCodec, const dynamic_reconfigure::Config &config)
Encode the given raw image into a compressed image shapeshifter.
void *(* allocator_t)(size_t)
cras::expected< M, std::string > encodeTyped(const sensor_msgs::Image &raw, const std::string &topicOrCodec, const Config &config)
Encode the given raw image into a compressed image.
ImageTransportCodec::DecodeResult decodeTyped(const M &compressed, const std::string &topicOrCodec, const ros::NodeHandle &nh, const std::string ¶m)
Decode the given compressed image into a raw image.
ImageTransportCodec::DecodeResult decodeTyped(const M &compressed, const std::string &topicOrCodec, const XmlRpc::XmlRpcValue &config)
Decode the given compressed image into a raw image.
virtual ~ImageTransportCodecs()
::std::string join(const T &strings, const ::std::string &delimiter)
std::string parseTransport(const std::string &topicOrCodec) const
Parse the name of the codec from a topic.
cras::expected< M, std::string > encodeTyped(const sensor_msgs::Image &raw, const std::string &topicOrCodec, const XmlRpc::XmlRpcValue &config)
Encode the given raw image into a compressed image.
ImageTransportCodec::DecodeResult decode(const topic_tools::ShapeShifter &compressed, const std::string &topicOrCodec, const Config &config)
Decode the given compressed image shapeshifter into a raw image.
::cras::LogHelper::Ptr LogHelperPtr
cras::expected< M, std::string > encodeTyped(const sensor_msgs::Image &raw, const std::string &topicOrCodec, const ros::NodeHandle &nh, const std::string ¶m)
Encode the given raw image into a compressed image.