diff --git a/src/image_streamer.cpp b/src/image_streamer.cpp index 0650ab5..1a4981a 100644 --- a/src/image_streamer.cpp +++ b/src/image_streamer.cpp @@ -27,10 +27,32 @@ void ImageStreamer::restreamFrame(double max_age) { if (inactive_ || !initialized_ ) return; - if ( last_frame + ros::WallDuration(max_age) < ros::WallTime::now() ) { - boost::mutex::scoped_lock lock(send_mutex_); - sendImage(output_size_image, ros::WallTime::now() ); // don't update last_frame, it may remain an old value. + try { + if ( last_frame + ros::WallDuration(max_age) < ros::WallTime::now() ) { + boost::mutex::scoped_lock lock(send_mutex_); + sendImage(output_size_image, ros::WallTime::now() ); // don't update last_frame, it may remain an old value. + } + } + catch (boost::system::system_error &e) + { + // happens when client disconnects + ROS_DEBUG("system_error exception: %s", e.what()); + inactive_ = true; + return; + } + catch (std::exception &e) + { + ROS_ERROR_THROTTLE(30, "exception: %s", e.what()); + inactive_ = true; + return; } + catch (...) + { + ROS_ERROR_THROTTLE(30, "exception"); + inactive_ = true; + return; + } + } void ImageStreamer::imageCallback(const sensor_msgs::ImageConstPtr &msg) diff --git a/src/libav_streamer.cpp b/src/libav_streamer.cpp index cd395f1..91868fc 100644 --- a/src/libav_streamer.cpp +++ b/src/libav_streamer.cpp @@ -320,14 +320,7 @@ void LibavStreamer::sendImage(const cv::Mat &img, const ros::WallTime &time) av_free_packet(&pkt); - try { - connection_->write_and_clear(encoded_frame); - } catch (boost::system::system_error& e) { - // probably a broken pipe. Bail out. - ROS_DEBUG("system_error exception: %s", e.what()); - inactive_ = true; - return; - } + connection_->write_and_clear(encoded_frame); } LibavStreamerType::LibavStreamerType(const std::string &format_name, const std::string &codec_name,