From d80d506360adab30cee64a4e2ec61c96075527bb Mon Sep 17 00:00:00 2001 From: kalman Date: Sat, 1 Sep 2018 20:47:35 +0800 Subject: [PATCH 1/3] 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!"); } } From 54f01eec1a45ec09e61ed890f25b3c25ea8438d2 Mon Sep 17 00:00:00 2001 From: kalman Date: Sat, 1 Sep 2018 20:51:14 +0800 Subject: [PATCH 2/3] Miss blank line --- src/uvc/uvc-v4l2.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/uvc/uvc-v4l2.cc b/src/uvc/uvc-v4l2.cc index b530cb4..06fc8fc 100755 --- a/src/uvc/uvc-v4l2.cc +++ b/src/uvc/uvc-v4l2.cc @@ -44,6 +44,7 @@ namespace uvc { #define NO_DATA_MAX_COUNT 200 int no_data_count = 0; + /* class device_error : public std::exception { public: From 92585a3b8d220373bb570c3f5eec7fb8e31901d4 Mon Sep 17 00:00:00 2001 From: kalman Date: Sat, 1 Sep 2018 21:03:28 +0800 Subject: [PATCH 3/3] Replace LOG(WARNING) with VLOG(2) When get imu params failed or image packet is unaccepted --- src/device/device.cc | 6 +++--- src/internal/streams.cc | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/device/device.cc b/src/device/device.cc index e6a2542..cc4d2b8 100644 --- a/src/device/device.cc +++ b/src/device/device.cc @@ -252,7 +252,7 @@ MotionIntrinsics Device::GetMotionIntrinsics(bool *ok) const { return *motion_intrinsics_; } else { *ok = false; - LOG(WARNING) << "Motion intrinsics not found"; + VLOG(2) << "Motion intrinsics not found"; return {}; } } @@ -263,7 +263,7 @@ Extrinsics Device::GetMotionExtrinsics(const Stream &from, bool *ok) const { return motion_from_extrinsics_.at(from); } catch (const std::out_of_range &e) { *ok = false; - LOG(WARNING) << "Motion extrinsics from " << from << " not found"; + VLOG(2) << "Motion extrinsics from " << from << " not found"; return {}; } } @@ -580,7 +580,7 @@ void Device::ReadAllInfos() { VLOG(2) << "Motion extrinsics left to imu: {" << GetMotionExtrinsics(Stream::LEFT) << "}"; } else { - LOG(WARNING) << "Motion intrinsics & extrinsics not exist"; + VLOG(2) << "Motion intrinsics & extrinsics not exist"; } } diff --git a/src/internal/streams.cc b/src/internal/streams.cc index 4b049e3..97ae970 100644 --- a/src/internal/streams.cc +++ b/src/internal/streams.cc @@ -50,9 +50,9 @@ bool unpack_stereo_img_data( // << ", checksum=0x" << std::hex << static_cast(img_packet.checksum); if (img_packet.header != 0x3B) { - LOG(WARNING) << "Image packet header must be 0x3B, but 0x" << std::hex - << std::uppercase << std::setw(2) << std::setfill('0') - << static_cast(img_packet.header) << " now"; + VLOG(2) << "Image packet header must be 0x3B, but 0x" << std::hex + << std::uppercase << std::setw(2) << std::setfill('0') + << static_cast(img_packet.header) << " now"; return false; } @@ -61,11 +61,11 @@ bool unpack_stereo_img_data( checksum = (checksum ^ packet[i]); } if (img_packet.checksum != checksum) { - LOG(WARNING) << "Image packet checksum should be 0x" << std::hex - << std::uppercase << std::setw(2) << std::setfill('0') - << static_cast(img_packet.checksum) << ", but 0x" - << std::setw(2) << std::setfill('0') - << static_cast(checksum) << " now"; + VLOG(2) << "Image packet checksum should be 0x" << std::hex + << std::uppercase << std::setw(2) << std::setfill('0') + << static_cast(img_packet.checksum) << ", but 0x" + << std::setw(2) << std::setfill('0') << static_cast(checksum) + << " now"; return false; } @@ -160,7 +160,7 @@ bool Streams::PushStream(const Capabilities &capability, const void *data) { } else { // discard left DiscardStreamData(Stream::LEFT); - LOG(WARNING) << "Image packet is unaccepted, frame dropped"; + VLOG(2) << "Image packet is unaccepted, frame dropped"; pushed = false; } } break;