Skip to content

Commit

Permalink
image_streamer: don't try/catch in sendImage, but in restreamFrame.
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Soetens <peter@thesourceworks.com>
  • Loading branch information
Peter Soetens committed Feb 6, 2015
1 parent ae10e85 commit 2fb83e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
28 changes: 25 additions & 3 deletions src/image_streamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 1 addition & 8 deletions src/libav_streamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2fb83e0

Please sign in to comment.