diff --git a/src/uvc/uvc-v4l2.cc b/src/uvc/uvc-v4l2.cc index a064552..afbc7ed 100755 --- a/src/uvc/uvc-v4l2.cc +++ b/src/uvc/uvc-v4l2.cc @@ -41,6 +41,11 @@ namespace uvc { LOG(severity) << str << " error " << errno << ", " << strerror(errno); \ } while (0) +#define NO_DATA_MAX_COUNT 200 +#define LIVING_MAX_COUNT 9000 + +int no_data_count = 0; +int living_count = 0; /* class device_error : public std::exception { public: @@ -385,7 +390,25 @@ struct device { if (xioctl(fd, VIDIOC_QBUF, &buf) < 0) throw_error("VIDIOC_QBUF"); }); + if (living_count < LIVING_MAX_COUNT) { + living_count++; + } else { + living_count = 0; + LOG(INFO) << "UVC pulse detection,Please ignore."; + } } + + no_data_count = 0; + } else { + no_data_count++; + } + + if (no_data_count > NO_DATA_MAX_COUNT) { + no_data_count = 0; + living_count = 0; + LOG(WARNING) << __func__ << "v4l2 get stream time out,Try to reboot!"; + stop_capture(); + start_capture(); } }