@@ -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_received_( false ), first_image_time_( ), format_name_(
5757 format_name), codec_name_(codec_name), content_type_(content_type), opt_(0 ), io_buffer_(0 )
5858{
5959
@@ -256,12 +256,14 @@ 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- first_image_timestamp_ = time;
264+ if (!first_image_received_) {
265+ first_image_received_ = true ;
266+ first_image_time_ = time;
265267 }
266268 std::vector<uint8_t > encoded_frame;
267269#if (LIBAVUTIL_VERSION_MAJOR < 53)
@@ -353,7 +355,8 @@ void LibavStreamer::sendImage(const cv::Mat &img, const ros::Time &time)
353355 std::size_t size;
354356 uint8_t *output_buf;
355357
356- double seconds = (time - first_image_timestamp_).toSec ();
358+ double seconds = std::chrono::duration_cast<std::chrono::duration<double >>(time -
359+ first_image_time_).count ();
357360 // Encode video at 1/0.95 to minimize delay
358361 pkt.pts = (int64_t )(seconds / av_q2d (video_stream_->time_base ) * 0.95 );
359362 if (pkt.pts <= 0 )
0 commit comments