Skip to content

Commit 526572a

Browse files
committed
Use chrono in png snapshot streamer
1 parent f87ddd0 commit 526572a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

include/web_video_server/png_streamers.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class PngSnapshotStreamer : public ImageTransportImageStreamer
7878
~PngSnapshotStreamer();
7979

8080
protected:
81-
virtual void sendImage(const cv::Mat &, const rclcpp::Time & time);
81+
virtual void sendImage(const cv::Mat &, const std::chrono::steady_clock::time_point & time);
8282
virtual cv::Mat decodeImage(const sensor_msgs::msg::Image::ConstSharedPtr & msg);
8383

8484
private:

src/png_streamers.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ cv::Mat PngSnapshotStreamer::decodeImage(const sensor_msgs::msg::Image::ConstSha
120120
}
121121
}
122122

123-
void PngSnapshotStreamer::sendImage(const cv::Mat & img, const rclcpp::Time & time)
123+
void PngSnapshotStreamer::sendImage(
124+
const cv::Mat & img,
125+
const std::chrono::steady_clock::time_point & time)
124126
{
125127
std::vector<int> encode_params;
126128
encode_params.push_back(cv::IMWRITE_PNG_COMPRESSION);
@@ -130,7 +132,9 @@ void PngSnapshotStreamer::sendImage(const cv::Mat & img, const rclcpp::Time & ti
130132
cv::imencode(".png", img, encoded_buffer, encode_params);
131133

132134
char stamp[20];
133-
snprintf(stamp, sizeof(stamp), "%.06lf", time.seconds());
135+
snprintf(
136+
stamp, sizeof(stamp), "%.06lf",
137+
std::chrono::duration_cast<std::chrono::duration<double>>(time.time_since_epoch()).count());
134138
async_web_server_cpp::HttpReply::builder(async_web_server_cpp::HttpReply::ok)
135139
.header("Connection", "close")
136140
.header("Server", "web_video_server")

0 commit comments

Comments
 (0)