diff --git a/modules/videoio/src/cap_libv4l.cpp b/modules/videoio/src/cap_libv4l.cpp index 46fac95288..6e220a77dc 100644 --- a/modules/videoio/src/cap_libv4l.cpp +++ b/modules/videoio/src/cap_libv4l.cpp @@ -1113,7 +1113,7 @@ static int read_frame_v4l2(CvCaptureCAM_V4L* capture) { default: /* display the error and stop processing */ perror ("VIDIOC_DQBUF"); - return 1; + return -1; } } @@ -1141,7 +1141,7 @@ static int read_frame_v4l2(CvCaptureCAM_V4L* capture) { return 1; } -static void mainloop_v4l2(CvCaptureCAM_V4L* capture) { +static int mainloop_v4l2(CvCaptureCAM_V4L* capture) { unsigned int count; count = 1; @@ -1175,10 +1175,14 @@ static void mainloop_v4l2(CvCaptureCAM_V4L* capture) { break; } - if (read_frame_v4l2 (capture)) - break; + int returnCode=read_frame_v4l2(capture); + if (returnCode == -1) + return -1; + if (returnCode == 1) + return 0; } } + return 0; } static int icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { @@ -1246,7 +1250,7 @@ static int icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { if (capture->is_v4l2_device == 1) { - mainloop_v4l2(capture); + if(mainloop_v4l2(capture) == -1) return 0; } else { diff --git a/modules/videoio/src/cap_v4l.cpp b/modules/videoio/src/cap_v4l.cpp index 9ab85ca8f9..563e7abba8 100644 --- a/modules/videoio/src/cap_v4l.cpp +++ b/modules/videoio/src/cap_v4l.cpp @@ -830,7 +830,7 @@ static int read_frame_v4l2(CvCaptureCAM_V4L* capture) { default: /* display the error and stop processing */ perror ("VIDIOC_DQBUF"); - return 1; + return -1; } } @@ -852,7 +852,7 @@ static int read_frame_v4l2(CvCaptureCAM_V4L* capture) { return 1; } -static void mainloop_v4l2(CvCaptureCAM_V4L* capture) { +static int mainloop_v4l2(CvCaptureCAM_V4L* capture) { unsigned int count; count = 1; @@ -886,10 +886,14 @@ static void mainloop_v4l2(CvCaptureCAM_V4L* capture) { break; } - if (read_frame_v4l2 (capture)) + int returnCode = read_frame_v4l2 (capture); + if(returnCode == -1) + return -1; + if(returnCode == 1) break; } } + return 0; } static bool icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { @@ -931,14 +935,15 @@ static bool icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { #if defined(V4L_ABORT_BADJPEG) // skip first frame. it is often bad -- this is unnotied in traditional apps, // but could be fatal if bad jpeg is enabled - mainloop_v4l2(capture); + if(mainloop_v4l2(capture) == -1) + return false; #endif /* preparation is ok */ capture->FirstCapture = 0; } - mainloop_v4l2(capture); + if(mainloop_v4l2(capture) == -1) return false; return true; }