mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 00:32:57 -04:00
video4linux: don't block on reading camera frames
Add v4l-blocking variable to enable the old behaviour.
This commit is contained in:
parent
2563b65249
commit
e0f8d7885a
@ -26,6 +26,10 @@
|
||||
Configure(config_vision);
|
||||
NotifyCategoryDef(vision, "");
|
||||
|
||||
ConfigVariableBool v4l_blocking
|
||||
("v4l-blocking", false,
|
||||
PRC_DESC("Set this to true if you want to block waiting for webcam frames."));
|
||||
|
||||
ConfigureFn(config_vision) {
|
||||
init_libvision();
|
||||
}
|
||||
|
@ -16,9 +16,12 @@
|
||||
|
||||
#include "pandabase.h"
|
||||
#include "notifyCategoryProxy.h"
|
||||
#include "configVariableBool.h"
|
||||
|
||||
NotifyCategoryDecl(vision, EXPCL_VISION, EXPTP_VISION);
|
||||
|
||||
extern ConfigVariableBool v4l_blocking;
|
||||
|
||||
extern EXPCL_VISION void init_libvision();
|
||||
|
||||
#endif
|
||||
|
@ -209,7 +209,13 @@ WebcamVideoCursorV4L(WebcamVideoV4L *src) : MovieVideoCursor(src) {
|
||||
|
||||
_buffers = NULL;
|
||||
_buflens = NULL;
|
||||
_fd = open(src->_device.c_str(), O_RDWR);
|
||||
|
||||
int mode = O_RDWR;
|
||||
if (!v4l_blocking) {
|
||||
mode = O_NONBLOCK;
|
||||
}
|
||||
|
||||
_fd = open(src->_device.c_str(), mode);
|
||||
if (-1 == _fd) {
|
||||
vision_cat.error() << "Failed to open " << src->_device.c_str() << "\n";
|
||||
return;
|
||||
@ -397,6 +403,10 @@ fetch_buffer() {
|
||||
vbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
vbuf.memory = V4L2_MEMORY_MMAP;
|
||||
if (-1 == ioctl(_fd, VIDIOC_DQBUF, &vbuf) && errno != EIO) {
|
||||
if (errno == EAGAIN) {
|
||||
// Simply nothing is available yet.
|
||||
return NULL;
|
||||
}
|
||||
vision_cat.error() << "Failed to dequeue buffer!\n";
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user