Skip to content

Commit 7cefb52

Browse files
committed
V4L: do not return frame if it can not be retrieved
1 parent 0448260 commit 7cefb52

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

modules/videoio/src/cap_libv4l.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ typedef struct CvCaptureCAM_V4L
312312
int deviceHandle;
313313
int bufferIndex;
314314
int FirstCapture;
315+
bool returnFrame;
315316

316317
int width; int height;
317318
int mode;
@@ -1094,6 +1095,8 @@ static CvCaptureCAM_V4L * icvCaptureFromCAM_V4L (const char* deviceName)
10941095
capture->is_v4l2_device = 1;
10951096
}
10961097

1098+
capture->returnFrame = true;
1099+
10971100
return capture;
10981101
}; /* End icvOpenCAM_V4L */
10991102

@@ -1119,6 +1122,7 @@ static int read_frame_v4l2(CvCaptureCAM_V4L* capture) {
11191122

11201123
default:
11211124
/* display the error and stop processing */
1125+
capture->returnFrame = false;
11221126
perror ("VIDIOC_DQBUF");
11231127
return -1;
11241128
}
@@ -1360,7 +1364,10 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) {
13601364

13611365
}
13621366

1363-
return(&capture->frame);
1367+
if (capture->returnFrame)
1368+
return(&capture->frame);
1369+
else
1370+
return 0;
13641371
}
13651372

13661373
static int zeroPropertyQuietly(CvCaptureCAM_V4L* capture, int property_id, int value)

modules/videoio/src/cap_v4l.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ struct CvCaptureCAM_V4L : public CvCapture
280280
__u32 fps;
281281
bool convert_rgb;
282282
bool frame_allocated;
283+
bool returnFrame;
283284

284285
/* V4L2 variables */
285286
buffer buffers[MAX_V4L_BUFFERS + 1];
@@ -820,6 +821,7 @@ bool CvCaptureCAM_V4L::open(const char* _deviceName)
820821
fps = DEFAULT_V4L_FPS;
821822
convert_rgb = true;
822823
deviceName = _deviceName;
824+
returnFrame = true;
823825

824826
return _capture_V4L2(this) == 1;
825827
}
@@ -847,6 +849,7 @@ static int read_frame_v4l2(CvCaptureCAM_V4L* capture) {
847849

848850
default:
849851
/* display the error and stop processing */
852+
capture->returnFrame = false;
850853
perror ("VIDIOC_DQBUF");
851854
return -1;
852855
}
@@ -1581,7 +1584,10 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) {
15811584
break;
15821585
}
15831586

1584-
return(&capture->frame);
1587+
if (capture->returnFrame)
1588+
return(&capture->frame);
1589+
else
1590+
return 0;
15851591
}
15861592

15871593
static inline __u32 capPropertyToV4L2(int prop) {

0 commit comments

Comments
 (0)