12 buffers(NULL), n_buffers(0)
54 std::ostringstream oss(
"");
55 oss <<
"/dev/video" << _devId;
65 fprintf(stderr,
"Opening device '%s'\n",
dev_name.c_str());
69 fprintf(stderr,
"Cannot open '%s': %d, %s\n",
70 dev_name.c_str(), errno, strerror(errno));
78 if (close(
fd) == -1) {
94 u = ((
unsigned char *)
buffers[0].start)[
i * 2 + 1] - 128;
95 v = ((
unsigned char *)
buffers[0].start)[
i * 2 + 3] - 128;
98 g = y - 0.71414 * v - 0.34414 * u;
104 y = ((
unsigned char *)
buffers[0].start)[(
i + 1) * 2];
107 g = y - 0.71414 * v - 0.34414 * u;
119 struct v4l2_buffer buf;
121 memset (&(buf), 0,
sizeof (buf));
123 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
124 buf.memory = V4L2_MEMORY_MMAP;
126 if (ioctl(
fd, VIDIOC_DQBUF, &buf) == -1) {
127 perror(
"VIDIOC_DQBUF");
132 if (ioctl(
fd, VIDIOC_QBUF, &buf) == -1) {
133 perror(
"VIDIOC_QBUF");
142 struct v4l2_requestbuffers req;
144 memset (&(req), 0,
sizeof (req));
147 req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
148 req.memory = V4L2_MEMORY_MMAP;
150 if (ioctl(
fd, VIDIOC_REQBUFS, &req) == -1) {
151 perror(
"VIDIOC_REQBUFS");
156 fprintf(stderr,
"Insufficient buffer memory on %s\n",
dev_name.c_str());
163 fprintf(stderr,
"Out of memory\n");
168 struct v4l2_buffer buf;
170 memset (&(buf), 0,
sizeof (buf));
172 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
173 buf.memory = V4L2_MEMORY_MMAP;
176 if (ioctl(
fd, VIDIOC_QUERYBUF, &buf) == -1) {
177 perror(
"VIDIOC_QUERYBUF");
183 buf.length, PROT_READ | PROT_WRITE
211 struct v4l2_capability cap;
212 struct v4l2_format fmt;
214 if (ioctl(
fd, VIDIOC_QUERYCAP, &cap) == -1) {
215 if (EINVAL == errno) {
216 fprintf(stderr,
"%s is no V4L2 device\n",
dev_name.c_str());
218 perror(
"VIDIOC_QUERYCAP");
222 fprintf(stderr,
"video capabilities\n");
223 fprintf(stderr,
"cap.driver = %s\n", cap.driver);
224 fprintf(stderr,
"cap.card = %s\n", cap.card);
225 fprintf(stderr,
"cap.buf_info = %s\n", cap.bus_info);
226 fprintf(stderr,
"cap.version = %d\n", cap.version);
227 fprintf(stderr,
"cap.capabilities = 0x%08x ", cap.capabilities);
228 if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)
229 fprintf(stderr,
" VIDEO_CAPTURE");
230 if (cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)
231 fprintf(stderr,
" VIDEO_OUTPUT");
232 if (cap.capabilities & V4L2_CAP_VIDEO_OVERLAY)
233 fprintf(stderr,
" VIDEO_OVERLAY");
234 if (cap.capabilities & V4L2_CAP_VBI_CAPTURE)
235 fprintf(stderr,
" VBI_CAPTURE");
236 if (cap.capabilities & V4L2_CAP_VBI_OUTPUT)
237 fprintf(stderr,
" VBI_OUTPUT");
238 #ifdef V4L2_CAP_SLICED_VBI_CAPTURE 239 if (cap.capabilities & V4L2_CAP_SLICED_VBI_CAPTURE)
240 fprintf(stderr,
" SLICED_VBI_CAPTURE");
242 #ifdef V4L2_CAP_SLICED_VBI_OUTPUT 243 if (cap.capabilities & V4L2_CAP_SLICED_VBI_OUTPUT)
244 fprintf(stderr,
" VBI_SLICED_OUTPUT");
246 if (cap.capabilities & V4L2_CAP_RDS_CAPTURE)
247 fprintf(stderr,
" RDS_CAPTURE");
248 #if V4L2_CAP_VIDEO_OUTPUT_OVERLAY 249 if (cap.capabilities & V4L2_CAP_VIDEO_OUTPUT_OVERLAY)
250 fprintf(stderr,
" VIDEO_OUTPUT_OVERLAY");
252 if (cap.capabilities & V4L2_CAP_TUNER)
253 fprintf(stderr,
" TUNER");
254 if (cap.capabilities & V4L2_CAP_AUDIO)
255 fprintf(stderr,
" AUDIO");
256 if (cap.capabilities & V4L2_CAP_RADIO)
257 fprintf(stderr,
" RADIO");
258 if (cap.capabilities & V4L2_CAP_READWRITE)
259 fprintf(stderr,
" READWRITE");
260 if (cap.capabilities & V4L2_CAP_ASYNCIO)
261 fprintf(stderr,
" ASYNCIO");
262 if (cap.capabilities & V4L2_CAP_STREAMING)
263 fprintf(stderr,
" STREAMING");
264 fprintf(stderr,
"\n");
266 if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
267 fprintf(stderr,
"%s is no video capture device\n",
dev_name.c_str());
271 memset (&(fmt), 0,
sizeof (fmt));
273 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
274 fmt.fmt.pix.width =
width;
275 fmt.fmt.pix.height =
height;
276 fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
277 fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
279 if (ioctl(
fd, VIDIOC_S_FMT, &fmt) == -1) {
280 perror(
"VIDIOC_S_FMT");
297 enum v4l2_buf_type
type;
300 struct v4l2_buffer buf;
302 memset (&(buf), 0,
sizeof (buf));
304 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
305 buf.memory = V4L2_MEMORY_MMAP;
308 if (ioctl(
fd, VIDIOC_QBUF, &buf) == -1) {
309 perror(
"VIDIOC_QBUF");
314 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
316 if (ioctl(
fd, VIDIOC_STREAMON, &type) == -1) {
317 perror(
"VIDIOC_STREAMON");
325 enum v4l2_buf_type
type;
327 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
329 if (ioctl(
fd, VIDIOC_STREAMOFF, &type) == -1) {
330 perror(
"VIDIOC_STREAMOFF");
png_infop png_charp png_int_32 png_int_32 int * type
png_bytep png_bytep png_size_t length
png_infop png_uint_32 * width
int init(size_t _width, size_t _height, unsigned int devId)
png_infop png_uint_32 png_uint_32 * height
bool write_img(uchar *ret)
bool init_all(size_t _width, size_t _height, unsigned int _devId)