From d80d506360adab30cee64a4e2ec61c96075527bb Mon Sep 17 00:00:00 2001 From: kalman Date: Sat, 1 Sep 2018 20:47:35 +0800 Subject: [PATCH] Throw error in v4l2 when time out --- src/uvc/uvc-v4l2.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/uvc/uvc-v4l2.cc b/src/uvc/uvc-v4l2.cc index a064552..b530cb4 100755 --- a/src/uvc/uvc-v4l2.cc +++ b/src/uvc/uvc-v4l2.cc @@ -41,6 +41,9 @@ namespace uvc { LOG(severity) << str << " error " << errno << ", " << strerror(errno); \ } while (0) +#define NO_DATA_MAX_COUNT 200 + +int no_data_count = 0; /* class device_error : public std::exception { public: @@ -194,6 +197,7 @@ struct device { ~device() { VLOG(2) << __func__; stop_streaming(); + no_data_count = 0; if (fd != -1 && close(fd) < 0) { LOG_ERROR(WARNING, "close"); } @@ -386,6 +390,14 @@ struct device { throw_error("VIDIOC_QBUF"); }); } + + no_data_count = 0; + } else { + no_data_count++; + } + + if (no_data_count > NO_DATA_MAX_COUNT) { + throw_error("v4l2 get stream time out!"); } }