Tolerate annoying webcams which return undocumented errors
Change-Id: I7797178132103f43af3ff9c4cc20d2de6bd9c908
diff --git a/y2020/vision/v4l2_reader.cc b/y2020/vision/v4l2_reader.cc
index 727f8ba..f43a2ac 100644
--- a/y2020/vision/v4l2_reader.cc
+++ b/y2020/vision/v4l2_reader.cc
@@ -15,10 +15,7 @@
PCHECK(fd_.get() != -1);
// First, clean up after anybody else who left the device streaming.
- {
- int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- PCHECK(Ioctl(VIDIOC_STREAMOFF, &type) == 0);
- }
+ StreamOff();
{
struct v4l2_format format;
@@ -130,5 +127,19 @@
PCHECK(Ioctl(VIDIOC_QBUF, &buffer) == 0);
}
+void V4L2Reader::StreamOff() {
+ int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ const int result = Ioctl(VIDIOC_STREAMOFF, &type);
+ if (result == 0) {
+ return;
+ }
+ // Some devices (like Alex's webcam) return this if streaming isn't currently
+ // on, unlike what the documentations says should happen.
+ if (errno == EBUSY) {
+ return;
+ }
+ PLOG(FATAL) << "VIDIOC_STREAMOFF failed";
+}
+
} // namespace vision
} // namespace frc971