ros-drivers / video_stream_opencv

A package to open video streams and publish them in ROS using the opencv videocapture mechanism
224 stars 159 forks source link

thread error if set "reopen_on_read_failure" to be true #78

Open CanboYe opened 3 years ago

CanboYe commented 3 years ago

Because I got Error "Could not capture frame" sometimes, I set "reopen_on_read_failure" to be true.

However, this will result in the thread error as follows and shut down the camera node.

[ERROR] [1603808756.444539510]: Could not capture frame
[ WARN] [1603808756.444615546]: trying to reopen the device
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::thread_resource_error> >'
  what():  boost thread: trying joining itself: Resource deadlock avoided

Btw, I will always get frame dropping and I cannot find the reasons. Is that common? Three kinds of dropping messages are as follows.

[rtsp @ 0x7fbfc802db60] RTP timestamps don't match.
[rtsp @ 0x7fbfc802db60] Received packet without a start chunk; dropping frame.
[rtsp @ 0x7fbfc802db60] Missing packets; dropping frame.

Thanks a lot!

awesomebytes commented 3 years ago

RTP streams do lose data in my experience. I am not happy that video_stream_opencv doesn't deal with that problem gracefully enough, but I don't have a test environment to reproduce the problem.

Did you find a fix?

rolker commented 3 years ago

I'm encountering the same problem and have setup a way to reproduce the failure in a debugging session. Here's what's happening:

In video_stream.cpp's do_capture() method, we get to line 129 where unsubscribe() is called. At line 318 in the unsubscribe() method, capture_thread.join() is called which causes the exception.

It's my first time looking at this code base, so I don't a solution yet, but it seems like we either need to not restart the thread when resubscribing or exit the thread before doing the unsubscribe/resubscribe.

I'll report back if I come up with a solution, but if I don't, I hope the above is useful to someone.