From: StevenPuttemans Date: Fri, 30 Aug 2013 11:16:18 +0000 (+0200) Subject: Added changes suggested by bug #3186 : fixing the unplugging of webcam X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~1314^2~1016^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e7921c3fe765a1d230abdd6aaa291d4a0c1bac65;p=platform%2Fupstream%2Fopencv.git Added changes suggested by bug #3186 : fixing the unplugging of webcam --- diff --git a/modules/highgui/src/cap_v4l.cpp b/modules/highgui/src/cap_v4l.cpp index 045c6f8..49432c9 100644 --- a/modules/highgui/src/cap_v4l.cpp +++ b/modules/highgui/src/cap_v4l.cpp @@ -1236,10 +1236,10 @@ static int read_frame_v4l2(CvCaptureCAM_V4L* capture) { //set timestamp in capture struct to be timestamp of most recent frame capture->timestamp = buf.timestamp; - return 1; + return 2; } -static void mainloop_v4l2(CvCaptureCAM_V4L* capture) { +static int mainloop_v4l2(CvCaptureCAM_V4L* capture) { unsigned int count; count = 1; @@ -1273,8 +1273,13 @@ static void mainloop_v4l2(CvCaptureCAM_V4L* capture) { break; } - if (read_frame_v4l2 (capture)) - break; + int readresult = read_frame_v412(capture); + if (readresult == 2){ + return 0; + } + if (readresult){ + return 1; + } } } } @@ -1354,7 +1359,10 @@ static int icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { { // 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)){ + fprintf( stderr, "HIGHGUI ERROR: V4L: Could not capture image.\n"); + return 0; + } } #endif @@ -1366,9 +1374,10 @@ static int icvGrabFrameCAM_V4L(CvCaptureCAM_V4L* capture) { if (V4L2_SUPPORT == 1) { - - mainloop_v4l2(capture); - + if(!mainloop_v4l2(capture)){ + fprintf( stderr, "HIGHGUI ERROR: V4L: Could not capture image.\n"); + return 0; + } } #endif /* HAVE_CAMV4L2 */ #if defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2)