16 #if defined(HAVE_VIDEO4LINUX) && !defined(CPPPARSER) 22 #include <sys/ioctl.h> 23 #include <linux/videodev2.h> 26 #ifndef VIDIOC_ENUM_FRAMESIZES 27 enum v4l2_frmsizetypes {
28 V4L2_FRMSIZE_TYPE_DISCRETE = 1,
29 V4L2_FRMSIZE_TYPE_CONTINUOUS = 2,
30 V4L2_FRMSIZE_TYPE_STEPWISE = 3,
33 struct v4l2_frmsize_discrete {
38 struct v4l2_frmsize_stepwise {
47 struct v4l2_frmsizeenum {
52 struct v4l2_frmsize_discrete discrete;
53 struct v4l2_frmsize_stepwise stepwise;
58 #define VIDIOC_ENUM_FRAMESIZES _IOWR('V', 74, struct v4l2_frmsizeenum) 61 #ifndef VIDIOC_ENUM_FRAMEINTERVALS 62 enum v4l2_frmivaltypes {
63 V4L2_FRMIVAL_TYPE_DISCRETE = 1,
64 V4L2_FRMIVAL_TYPE_CONTINUOUS = 2,
65 V4L2_FRMIVAL_TYPE_STEPWISE = 3,
68 struct v4l2_frmival_stepwise {
69 struct v4l2_fract min;
70 struct v4l2_fract max;
71 struct v4l2_fract step;
74 struct v4l2_frmivalenum {
81 struct v4l2_fract discrete;
82 struct v4l2_frmival_stepwise stepwise;
87 #define VIDIOC_ENUM_FRAMEINTERVALS _IOWR('V', 75, struct v4l2_frmivalenum) 97 add_options_for_size(
int fd,
const std::string &dev,
const char *name,
unsigned width,
unsigned height,
unsigned pixelformat) {
98 struct v4l2_frmivalenum frmivalenum;
99 for (
int k = 0;; k++) {
100 memset(&frmivalenum, 0,
sizeof frmivalenum);
101 frmivalenum.index = k;
102 frmivalenum.pixel_format = pixelformat;
103 frmivalenum.width = width;
104 frmivalenum.height = height;
105 if (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmivalenum) == -1) {
109 switch (frmivalenum.type) {
110 case V4L2_FRMIVAL_TYPE_DISCRETE:
111 fps = ((double) frmivalenum.discrete.denominator) / ((double) frmivalenum.discrete.numerator);
114 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
115 case V4L2_FRMIVAL_TYPE_STEPWISE:
118 double max_fps = ((double) frmivalenum.stepwise.max.denominator) / ((double) frmivalenum.stepwise.max.numerator);
128 PT(WebcamVideoV4L) wc =
new WebcamVideoV4L;
132 wc->_size_y = height;
134 wc->_pformat = pixelformat;
135 wc->_pixel_format = std::string((
char*) &pixelformat, 4);
137 WebcamVideoV4L::_all_webcams.push_back(DCAST(
WebcamVideo, wc));
145 void find_all_webcams_v4l() {
146 struct v4l2_capability cap2;
150 pattern.match_files(devs);
151 for (vector_string::iterator it = devs.begin(); it != devs.end(); ++it) {
152 int fd = open(it->c_str(), O_RDWR);
155 if (ioctl(fd, VIDIOC_QUERYCAP, &cap2) != -1) {
156 if ((cap2.capabilities & V4L2_CAP_VIDEO_CAPTURE) &&
157 (cap2.capabilities & V4L2_CAP_STREAMING)) {
158 struct v4l2_fmtdesc fmt;
159 for (
int i = 0;; i++) {
160 memset(&fmt, 0,
sizeof fmt);
162 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
163 if (ioctl(fd, VIDIOC_ENUM_FMT, &fmt) == -1) {
168 switch (fmt.pixelformat) {
170 case V4L2_PIX_FMT_MJPEG:
172 case V4L2_PIX_FMT_YUYV:
173 case V4L2_PIX_FMT_BGR24:
174 case V4L2_PIX_FMT_BGR32:
175 case V4L2_PIX_FMT_RGB24:
176 case V4L2_PIX_FMT_RGB32:
177 case V4L2_PIX_FMT_GREY:
184 struct v4l2_frmsizeenum frmsizeenum;
185 for (
int j = 0;; j++) {
186 memset(&frmsizeenum, 0,
sizeof frmsizeenum);
187 frmsizeenum.index = j;
188 frmsizeenum.pixel_format = fmt.pixelformat;
189 if (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmsizeenum) == -1) {
193 switch (frmsizeenum.type) {
194 case V4L2_FRMSIZE_TYPE_DISCRETE:
197 add_options_for_size(fd, *it, (
const char *)cap2.card,
198 frmsizeenum.discrete.width,
199 frmsizeenum.discrete.height,
203 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
209 for (; width <= frmsizeenum.stepwise.max_width; width *= 2) {
211 for (; height <= frmsizeenum.stepwise.max_height; height *= 2) {
213 add_options_for_size(fd, *it, (
const char *)cap2.card, width, height, fmt.pixelformat);
219 case V4L2_FRMSIZE_TYPE_STEPWISE:
222 for (; width <= frmsizeenum.stepwise.max_width; width *= 2) {
224 for (; height <= frmsizeenum.stepwise.max_height; height *= 2) {
225 if ((width - frmsizeenum.stepwise.min_width) % frmsizeenum.stepwise.step_width == 0 &&
226 (height - frmsizeenum.stepwise.min_height) % frmsizeenum.stepwise.step_height == 0) {
228 add_options_for_size(fd, *it, (
const char *)cap2.card, width, height, fmt.pixelformat);
250 return new WebcamVideoCursorV4L(
this);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Allows you to open a webcam or other video capture device as a video stream.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A MovieVideo is actually any source that provides a sequence of video frames.
static int up_to_power_2(int value)
Returns the smallest power of 2 greater than or equal to value.
TypeHandle is the identifier used to differentiate C++ class types.
This class can be used to test for string matches against standard Unix- shell filename globbing conv...