@@ -53,7 +53,7 @@ LibavStreamer::LibavStreamer(const async_web_server_cpp::HttpRequest &request,
5353 const std::string &format_name, const std::string &codec_name,
5454 const std::string &content_type) :
5555 ImageTransportImageStreamer (request, connection, nh), output_format_(0 ), format_context_(0 ), codec_(0 ), codec_context_(0 ), video_stream_(
56- 0 ), frame_(0 ), sws_context_(0 ), first_image_timestamp_(0 ), format_name_(
56+ 0 ), frame_(0 ), sws_context_(0 ), first_image_timestamp_(std:: nullopt ), format_name_(
5757 format_name), codec_name_(codec_name), content_type_(content_type), opt_(0 ), io_buffer_(0 )
5858{
5959
@@ -256,11 +256,12 @@ void LibavStreamer::initializeEncoder()
256256{
257257}
258258
259- void LibavStreamer::sendImage (const cv::Mat &img, const ros::Time &time)
259+ void LibavStreamer::sendImage (
260+ const cv::Mat & img,
261+ const std::chrono::steady_clock::time_point & time)
260262{
261263 boost::mutex::scoped_lock lock (encode_mutex_);
262- if (first_image_timestamp_.isZero ())
263- {
264+ if (!first_image_timestamp_.has_value ()) {
264265 first_image_timestamp_ = time;
265266 }
266267 std::vector<uint8_t > encoded_frame;
@@ -353,7 +354,8 @@ void LibavStreamer::sendImage(const cv::Mat &img, const ros::Time &time)
353354 std::size_t size;
354355 uint8_t *output_buf;
355356
356- double seconds = (time - first_image_timestamp_).toSec ();
357+ double seconds = std::chrono::duration_cast<std::chrono::duration<double >>(time -
358+ first_image_timestamp_.value ()).count ();
357359 // Encode video at 1/0.95 to minimize delay
358360 pkt.pts = (int64_t )(seconds / av_q2d (video_stream_->time_base ) * 0.95 );
359361 if (pkt.pts <= 0 )
0 commit comments