Skip to content

Commit e0f8d78

Browse files
committed
video4linux: don't block on reading camera frames
Add v4l-blocking variable to enable the old behaviour.
1 parent 2563b65 commit e0f8d78

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

panda/src/vision/config_vision.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
Configure(config_vision);
2727
NotifyCategoryDef(vision, "");
2828

29+
ConfigVariableBool v4l_blocking
30+
("v4l-blocking", false,
31+
PRC_DESC("Set this to true if you want to block waiting for webcam frames."));
32+
2933
ConfigureFn(config_vision) {
3034
init_libvision();
3135
}

panda/src/vision/config_vision.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616

1717
#include "pandabase.h"
1818
#include "notifyCategoryProxy.h"
19+
#include "configVariableBool.h"
1920

2021
NotifyCategoryDecl(vision, EXPCL_VISION, EXPTP_VISION);
2122

23+
extern ConfigVariableBool v4l_blocking;
24+
2225
extern EXPCL_VISION void init_libvision();
2326

2427
#endif

panda/src/vision/webcamVideoCursorV4L.cxx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,13 @@ WebcamVideoCursorV4L(WebcamVideoV4L *src) : MovieVideoCursor(src) {
209209

210210
_buffers = NULL;
211211
_buflens = NULL;
212-
_fd = open(src->_device.c_str(), O_RDWR);
212+
213+
int mode = O_RDWR;
214+
if (!v4l_blocking) {
215+
mode = O_NONBLOCK;
216+
}
217+
218+
_fd = open(src->_device.c_str(), mode);
213219
if (-1 == _fd) {
214220
vision_cat.error() << "Failed to open " << src->_device.c_str() << "\n";
215221
return;
@@ -397,6 +403,10 @@ fetch_buffer() {
397403
vbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
398404
vbuf.memory = V4L2_MEMORY_MMAP;
399405
if (-1 == ioctl(_fd, VIDIOC_DQBUF, &vbuf) && errno != EIO) {
406+
if (errno == EAGAIN) {
407+
// Simply nothing is available yet.
408+
return NULL;
409+
}
400410
vision_cat.error() << "Failed to dequeue buffer!\n";
401411
return NULL;
402412
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy