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!"); } }