From 526572a47c4f20e6fb0572d609b0e1dd942fbe1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82a=C5=BCej=20Sowa?= Date: Mon, 11 Nov 2024 17:26:21 +0100 Subject: [PATCH] Use chrono in png snapshot streamer --- include/web_video_server/png_streamers.hpp | 2 +- src/png_streamers.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/web_video_server/png_streamers.hpp b/include/web_video_server/png_streamers.hpp index 37a741c..c261fe6 100644 --- a/include/web_video_server/png_streamers.hpp +++ b/include/web_video_server/png_streamers.hpp @@ -78,7 +78,7 @@ class PngSnapshotStreamer : public ImageTransportImageStreamer ~PngSnapshotStreamer(); protected: - virtual void sendImage(const cv::Mat &, const rclcpp::Time & time); + virtual void sendImage(const cv::Mat &, const std::chrono::steady_clock::time_point & time); virtual cv::Mat decodeImage(const sensor_msgs::msg::Image::ConstSharedPtr & msg); private: diff --git a/src/png_streamers.cpp b/src/png_streamers.cpp index 45d0648..c3c9327 100644 --- a/src/png_streamers.cpp +++ b/src/png_streamers.cpp @@ -120,7 +120,9 @@ cv::Mat PngSnapshotStreamer::decodeImage(const sensor_msgs::msg::Image::ConstSha } } -void PngSnapshotStreamer::sendImage(const cv::Mat & img, const rclcpp::Time & time) +void PngSnapshotStreamer::sendImage( + const cv::Mat & img, + const std::chrono::steady_clock::time_point & time) { std::vector encode_params; encode_params.push_back(cv::IMWRITE_PNG_COMPRESSION); @@ -130,7 +132,9 @@ void PngSnapshotStreamer::sendImage(const cv::Mat & img, const rclcpp::Time & ti cv::imencode(".png", img, encoded_buffer, encode_params); char stamp[20]; - snprintf(stamp, sizeof(stamp), "%.06lf", time.seconds()); + snprintf( + stamp, sizeof(stamp), "%.06lf", + std::chrono::duration_cast>(time.time_since_epoch()).count()); async_web_server_cpp::HttpReply::builder(async_web_server_cpp::HttpReply::ok) .header("Connection", "close") .header("Server", "web_video_server")