blob: c4541d9fc3b25aabf8df097e851cdb4c17f7eb34 [file] [log] [blame]
Philippe De Muyter0cc96142014-11-03 21:27:40 +01001/*
2 * Copyright (c) 2014 Philippe De Muyter <phdm@macqel.be>
3 * Copyright (c) 2014 William Manley <will@williammanley.net>
4 * Copyright (c) 2011 Peter Zotov <whitequark@whitequark.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include "defs.h"
31
32#include <stdint.h>
33#include <sys/ioctl.h>
34#include <linux/videodev2.h>
35/* some historical constants */
36#ifndef V4L2_CID_HCENTER
37#define V4L2_CID_HCENTER (V4L2_CID_BASE+22)
38#endif
39#ifndef V4L2_CID_VCENTER
40#define V4L2_CID_VCENTER (V4L2_CID_BASE+23)
41#endif
42#ifndef V4L2_CID_BAND_STOP_FILTER
43#define V4L2_CID_BAND_STOP_FILTER (V4L2_CID_BASE+33)
44#endif
45
46#include "xlat/v4l2_device_capabilities_flags.h"
47#include "xlat/v4l2_buf_types.h"
48#include "xlat/v4l2_buf_flags.h"
49#include "xlat/v4l2_framesize_types.h"
50#include "xlat/v4l2_frameinterval_types.h"
51#include "xlat/v4l2_fields.h"
52#include "xlat/v4l2_colorspaces.h"
53#include "xlat/v4l2_format_description_flags.h"
54#include "xlat/v4l2_memories.h"
55#include "xlat/v4l2_control_ids.h"
56#include "xlat/v4l2_control_types.h"
57#include "xlat/v4l2_control_flags.h"
58#include "xlat/v4l2_control_classes.h"
59#include "xlat/v4l2_streaming_capabilities.h"
60#include "xlat/v4l2_capture_modes.h"
61#include "xlat/v4l2_input_types.h"
62
63#define FMT_FRACT "%u/%u"
64#define ARGS_FRACT(x) ((x).numerator), ((x).denominator)
65
66#define FMT_RECT "{left=%i, top=%i, width=%i, height=%i}"
67#define ARGS_RECT(x) (x).left, (x).top, (x).width, (x).height
68
69static void print_pixelformat(uint32_t fourcc)
70{
Dmitry V. Levinf0a5b082015-01-25 00:27:00 +000071 union {
72 uint32_t pixelformat;
73 unsigned char cc[sizeof(uint32_t)];
74 } u = {
75 .pixelformat =
Philippe De Muyter0cc96142014-11-03 21:27:40 +010076#if WORDS_BIGENDIAN
Dmitry V. Levinf0a5b082015-01-25 00:27:00 +000077 htole32(fourcc)
78#else
79 fourcc
Philippe De Muyter0cc96142014-11-03 21:27:40 +010080#endif
Dmitry V. Levinf0a5b082015-01-25 00:27:00 +000081 };
82 unsigned int i;
83
84 tprints("v4l2_fourcc(");
85 for (i = 0; i < sizeof(u.cc); ++i) {
86 unsigned int c = u.cc[i];
87
88 if (i)
89 tprints(", ");
90 if (c == ' ' ||
91 (c >= '0' && c <= '9') ||
92 (c >= 'A' && c <= 'Z') ||
93 (c >= 'a' && c <= 'z')) {
94 char sym[] = {
95 '\'',
96 u.cc[i],
97 '\''
98 };
99 tprints(sym);
100 } else {
101 char hex[] = {
102 '\'',
103 '\\',
104 'x',
105 "0123456789abcdef"[c >> 4],
106 "0123456789abcdef"[c & 0xf],
107 '\'',
108 '\0'
109 };
110 tprints(hex);
111 }
112 }
113 tprints(")");
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100114}
115
116static void print_v4l2_format_fmt(const struct v4l2_format *f)
117{
118 tprints("fmt.");
119 switch (f->type) {
120 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
121 case V4L2_BUF_TYPE_VIDEO_OUTPUT: {
122 const struct v4l2_pix_format *pix = &f->fmt.pix;
123
124 tprintf("pix={width=%u, height=%u, pixelformat=",
125 pix->width, pix->height);
126 print_pixelformat(pix->pixelformat);
127 tprints(", field=");
128 printxval(v4l2_fields, pix->field, "V4L2_FIELD_???");
129 tprintf(", bytesperline=%u, sizeimage=%u, colorspace=",
130 pix->bytesperline, pix->sizeimage);
131 printxval(v4l2_colorspaces, pix->colorspace,
132 "V4L2_COLORSPACE_???");
133 tprints("}");
134 break;
135 }
136#if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
137 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
138 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: {
139 const struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
140 unsigned int i, max;
141
142 tprintf("pix_mp={width=%u, height=%u, pixelformat=",
143 pix_mp->width, pix_mp->height);
144 print_pixelformat(pix_mp->pixelformat);
145 tprints(", field=");
146 printxval(v4l2_fields, pix_mp->field, "V4L2_FIELD_???");
147 tprints(", colorspace=");
148 printxval(v4l2_colorspaces, pix_mp->colorspace,
149 "V4L2_COLORSPACE_???");
150 tprints("plane_fmt=[");
151 max = pix_mp->num_planes;
152 if (max > VIDEO_MAX_PLANES)
153 max = VIDEO_MAX_PLANES;
154 for (i = 0; i < max; i++) {
155 if (i > 0)
156 tprints(", ");
157 tprintf("{sizeimage=%u, bytesperline=%u}",
158 pix_mp->plane_fmt[i].sizeimage,
159 pix_mp->plane_fmt[i].bytesperline);
160 }
161 tprintf("], num_planes=%u}", (unsigned) pix_mp->num_planes);
162 break;
163 }
164#endif
165
166 /* TODO: Complete this switch statement */
167 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Dmitry V. Levin197db572015-01-09 04:53:19 +0000168#if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100169 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Dmitry V. Levin197db572015-01-09 04:53:19 +0000170#endif
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100171 tprints("win={???}");
172 break;
173
174 case V4L2_BUF_TYPE_VBI_CAPTURE:
175 case V4L2_BUF_TYPE_VBI_OUTPUT:
176 tprints("vbi={???}");
177 break;
178
179 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
180 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
181 tprints("sliced={???}");
182 break;
183
184 default:
185 tprints("???");
186 break;
187 }
188}
189
190int
Dmitry V. Levinc7afb482015-01-19 18:44:21 +0000191v4l2_ioctl(struct tcb *tcp, const unsigned int code, long arg)
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100192{
193 if (!verbose(tcp))
194 return 0;
195
196 switch (code) {
197 case VIDIOC_QUERYCAP: /* decode on exit */ {
198 struct v4l2_capability caps;
199
200 if (entering(tcp) || syserror(tcp) || umove(tcp, arg, &caps) < 0)
201 return 0;
Dmitry V. Levin1de59cf2015-01-26 02:45:09 +0000202 tprints(", {driver=");
203 print_quoted_string((const char *) caps.driver,
204 sizeof(caps.driver), QUOTE_0_TERMINATED);
205 tprints(", card=");
206 print_quoted_string((const char *) caps.card,
207 sizeof(caps.card), QUOTE_0_TERMINATED);
208 tprints(", bus_info=");
209 print_quoted_string((const char *) caps.bus_info,
210 sizeof(caps.bus_info), QUOTE_0_TERMINATED);
211 tprintf(", version=%u.%u.%u, capabilities=",
212 (caps.version >> 16) & 0xFF,
213 (caps.version >> 8) & 0xFF,
214 caps.version & 0xFF);
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100215 printflags(v4l2_device_capabilities_flags, caps.capabilities,
216 "V4L2_CAP_???");
217#ifdef V4L2_CAP_DEVICE_CAPS
218 tprints(", device_caps=");
219 printflags(v4l2_device_capabilities_flags, caps.device_caps,
220 "V4L2_CAP_???");
221#endif
222 tprints("}");
223 return 1;
224 }
225
Dmitry V. Levin197db572015-01-09 04:53:19 +0000226#ifdef VIDIOC_ENUM_FRAMESIZES
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100227 case VIDIOC_ENUM_FRAMESIZES: /* decode on exit */ {
228 struct v4l2_frmsizeenum s;
229
230 if (entering(tcp) || umove(tcp, arg, &s) < 0)
231 return 0;
232 tprintf(", {index=%u, pixel_format=", s.index);
233 print_pixelformat(s.pixel_format);
234
235 if (!syserror(tcp)) {
236 tprints(", type=");
237 printxval(v4l2_framesize_types, s.type, "V4L2_FRMSIZE_TYPE_???");
238 switch (s.type) {
239 case V4L2_FRMSIZE_TYPE_DISCRETE:
240 tprintf(", discrete={width=%u, height=%u}",
241 s.discrete.width, s.discrete.height);
242 break;
243 case V4L2_FRMSIZE_TYPE_STEPWISE:
244 tprintf(", stepwise={min_width=%u, max_width=%u, "
245 "step_width=%u, min_height=%u, max_height=%u, "
246 "step_height=%u}",
247 s.stepwise.min_width, s.stepwise.max_width,
248 s.stepwise.step_width, s.stepwise.min_height,
249 s.stepwise.max_height, s.stepwise.step_height);
250 break;
251 }
252 }
253 tprints("}");
254 return 1;
255 }
Dmitry V. Levin197db572015-01-09 04:53:19 +0000256#endif /* VIDIOC_ENUM_FRAMESIZES */
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100257
258 case VIDIOC_G_FMT:
259 case VIDIOC_S_FMT:
260 case VIDIOC_TRY_FMT: {
261 struct v4l2_format f;
262
263 if (umove(tcp, arg, &f) < 0)
264 return 0;
265 if (entering(tcp)) {
266 tprints(", {type=");
267 printxval(v4l2_buf_types, f.type, "V4L2_BUF_TYPE_???");
268 }
269 if ((entering(tcp) && code != VIDIOC_G_FMT)
270 || (exiting(tcp) && !syserror(tcp))) {
271 tprints(exiting(tcp) && code != VIDIOC_G_FMT ? " => " : ", ");
272 print_v4l2_format_fmt(&f);
273 }
274 if (exiting(tcp))
275 tprints("}");
276 return 1;
277 }
278
279 case VIDIOC_ENUM_FMT: {
280 struct v4l2_fmtdesc f;
281
282 if (entering(tcp) || umove(tcp, arg, &f) < 0)
283 return 0;
284
285 tprintf(", {index=%u", f.index);
286 if (!syserror(tcp)) {
287 tprints(", type=");
288 printxval(v4l2_buf_types, f.type, "V4L2_BUF_TYPE_???");
289 tprints(", flags=");
290 printflags(v4l2_format_description_flags, f.flags,
291 "V4L2_FMT_FLAG_???");
Dmitry V. Levin1de59cf2015-01-26 02:45:09 +0000292 tprints(", description=");
293 print_quoted_string((const char *) f.description,
294 sizeof(f.description),
295 QUOTE_0_TERMINATED);
296 tprints(", pixelformat=");
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100297 print_pixelformat(f.pixelformat);
298 }
299 tprints("}");
300 return 1;
301 }
302
303 case VIDIOC_G_PARM:
304 case VIDIOC_S_PARM: {
305 struct v4l2_streamparm s;
306
307 if (entering(tcp) && code == VIDIOC_G_PARM)
308 return 1;
309 if (exiting(tcp) && syserror(tcp))
310 return code == VIDIOC_S_PARM;
311 if (umove(tcp, arg, &s) < 0)
312 return 0;
313 if (entering(tcp)) {
314 tprints(", {type=");
315 printxval(v4l2_buf_types, s.type, "V4L2_BUF_TYPE_???");
316 }
317
318 tprints(exiting(tcp) && code == VIDIOC_S_PARM ? " => {" : ", {");
319 if (s.type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
320 struct v4l2_captureparm *cap = &s.parm.capture;
321
322 tprints("capability=");
323 printflags(v4l2_streaming_capabilities,
324 cap->capability, "V4L2_CAP_???");
325
326 tprints(", capturemode=");
327 printflags(v4l2_capture_modes,
328 cap->capturemode, "V4L2_MODE_???");
329
330 tprintf(", timeperframe=" FMT_FRACT,
331 ARGS_FRACT(cap->timeperframe));
332
333 tprintf(", extendedmode=%u, readbuffers=%u",
334 cap->extendedmode,
335 cap->readbuffers);
336 } else
337 tprints("...");
338 tprints("}");
339 if (exiting(tcp))
340 tprints("}");
341 return 1;
342 }
343
344 case VIDIOC_QUERYCTRL: {
345 struct v4l2_queryctrl c;
346
347 if (umove(tcp, arg, &c) < 0)
348 return 0;
349 /* 'id' field must be printed :
350 * on enter
351 * on exit if !syserror(tcp) && V4L2_CTRL_FLAG_NEXT_CTRL was set
352 */
353 if (entering(tcp)
354 || (exiting(tcp) && tcp->auxstr && !syserror(tcp))) {
355 tprints(exiting(tcp) ? " => " : ", {id=");
356 tcp->auxstr = (c.id & V4L2_CTRL_FLAG_NEXT_CTRL) ? "" : NULL;
357 if (tcp->auxstr) {
358 tprints("V4L2_CTRL_FLAG_NEXT_CTRL|");
359 c.id &= ~V4L2_CTRL_FLAG_NEXT_CTRL;
360 }
361 printxval(v4l2_control_ids, c.id, "V4L2_CID_???");
362 }
363 if (exiting(tcp)) {
364 if (!syserror(tcp)) {
365 tprints(", type=");
366 printxval(v4l2_control_types, c.type,
367 "V4L2_CTRL_TYPE_???");
Dmitry V. Levin1de59cf2015-01-26 02:45:09 +0000368 tprints(", name=");
369 print_quoted_string((const char *) c.name,
370 sizeof(c.name),
371 QUOTE_0_TERMINATED);
372 tprintf(", minimum=%i, maximum=%i, step=%i, "
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100373 "default_value=%i, flags=",
Dmitry V. Levin1de59cf2015-01-26 02:45:09 +0000374 c.minimum, c.maximum,
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100375 c.step, c.default_value);
376 printflags(v4l2_control_flags, c.flags,
377 "V4L2_CTRL_FLAG_???");
378 }
379 tprints("}");
380 }
381 return 1;
382 }
383
384 case VIDIOC_G_CTRL:
385 case VIDIOC_S_CTRL: {
386 struct v4l2_control c;
387
388 if (entering(tcp) || umove(tcp, arg, &c) < 0)
389 return 0;
390 tprints(", {id=");
391 printxval(v4l2_control_ids, c.id, "V4L2_CID_???");
392 if (!syserror(tcp) || code != VIDIOC_G_CTRL)
393 tprintf(", value=%i", c.value);
394 tprints("}");
395 return 1;
396 }
397
398 case VIDIOC_S_EXT_CTRLS:
399 case VIDIOC_TRY_EXT_CTRLS:
400 case VIDIOC_G_EXT_CTRLS: {
401 struct v4l2_ext_controls c;
402 unsigned int n;
403 bool must_print_values;
404
405 if (entering(tcp) && code == VIDIOC_G_EXT_CTRLS)
406 return 0;
407 if (exiting(tcp) && syserror(tcp) && code != VIDIOC_G_EXT_CTRLS)
408 return 0;
409 must_print_values = ((entering(tcp) && code != VIDIOC_G_EXT_CTRLS)
410 || (exiting(tcp) && !syserror(tcp)));
411 if (umove(tcp, arg, &c) < 0)
412 return 0;
413 tprints(code != VIDIOC_G_EXT_CTRLS && exiting(tcp) ? " => " : ", ");
414 tprints("{ctrl_class=");
415 printxval(v4l2_control_classes, c.ctrl_class,
416 "V4L2_CTRL_CLASS_???");
417 tprintf(", count=%u", c.count);
418 if (exiting(tcp) && syserror(tcp))
419 tprintf(", error_idx=%u", c.error_idx);
420 tprints(", controls=[");
421 for (n = 0; n < c.count; ++n) {
422 struct v4l2_ext_control ctrl;
423
424 if (n > 0)
425 tprints(", ");
426 if (umove(tcp, (long) (c.controls + n), &ctrl) < 0)
427 break;
428 if (abbrev(tcp) && n == 2) {
429 tprints("...");
430 break;
431 }
432 tprints("{id=");
433 printxval(v4l2_control_ids, ctrl.id, "V4L2_CID_???");
434#if HAVE_DECL_V4L2_CTRL_TYPE_STRING
435 tprintf(", size=%u", ctrl.size);
436 if (ctrl.size > 0) {
437 if (must_print_values) {
438 tprints(", string=");
439 printstr(tcp, (long) ctrl.string, ctrl.size);
440 }
441 } else
442#endif
443 {
444 if (must_print_values) {
445 tprintf(", value=%i, value64=%lli", ctrl.value,
446 ctrl.value64);
447 }
448 }
449 tprints("}");
450 }
451 tprints("]}");
452 return 1;
453 }
454
455 case VIDIOC_ENUMSTD: {
456 struct v4l2_standard s;
457
458 if (umove(tcp, arg, &s) < 0)
459 return 0;
460 if (entering(tcp))
461 tprintf(", {index=%i", s.index);
462 else {
463 if (!syserror(tcp)) {
Dmitry V. Levin1de59cf2015-01-26 02:45:09 +0000464 tprints(", name=");
465 print_quoted_string((const char *) s.name,
466 sizeof(s.name),
467 QUOTE_0_TERMINATED);
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100468 tprintf(", frameperiod=" FMT_FRACT, ARGS_FRACT(s.frameperiod));
469 tprintf(", framelines=%i", s.framelines);
470 }
471 tprints("}");
472 }
473 return 1;
474 }
475
476 case VIDIOC_G_STD:
477 case VIDIOC_S_STD: {
478 v4l2_std_id s;
479
480 if (code == VIDIOC_G_STD && exiting(tcp) && syserror(tcp))
481 return 0;
482 if (umove(tcp, arg, &s) < 0)
483 return 0;
484 if ((code == VIDIOC_S_STD) == entering(tcp))
485 tprintf(", std=%#llx", s);
486 return 1;
487 }
488
489 case VIDIOC_ENUMINPUT: {
490 struct v4l2_input i;
491
492 if (entering(tcp) || umove(tcp, arg, &i) < 0)
493 return 0;
494 tprintf(", {index=%i", i.index);
495 if (!syserror(tcp)) {
Dmitry V. Levin1de59cf2015-01-26 02:45:09 +0000496 tprints(", name=");
497 print_quoted_string((const char *) i.name,
498 sizeof(i.name), QUOTE_0_TERMINATED);
499 tprints(", type=");
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100500 printxval(v4l2_input_types, i.type,
501 "V4L2_INPUT_TYPE_???");
502 }
503 tprints("}");
504 return 1;
505 }
506
507 case VIDIOC_G_INPUT:
508 case VIDIOC_S_INPUT: {
509 int index;
510
511 if (entering(tcp) || syserror(tcp) || umove(tcp, arg, &index) < 0)
512 return 0;
513
514 tprintf(", index=%i", index);
515 return 1;
516 }
517
Dmitry V. Levin197db572015-01-09 04:53:19 +0000518#ifdef VIDIOC_ENUM_FRAMEINTERVALS
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100519 case VIDIOC_ENUM_FRAMEINTERVALS: {
520 struct v4l2_frmivalenum f;
521
522 if (entering(tcp) || umove(tcp, arg, &f) < 0)
523 return 0;
524 tprintf(", {index=%i, pixel_format=", f.index);
525 print_pixelformat(f.pixel_format);
526 tprintf(", width=%u, height=%u", f.width, f.height);
527 if (!syserror(tcp)) {
528 tprints(", type=");
529 printxval(v4l2_frameinterval_types, f.type,
530 "V4L2_FRMIVAL_TYPE_???");
531 switch (f.type) {
532 case V4L2_FRMIVAL_TYPE_DISCRETE:
533 tprintf(", discrete=" FMT_FRACT,
534 ARGS_FRACT(f.discrete));
535 break;
536 case V4L2_FRMIVAL_TYPE_STEPWISE:
537 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
538 tprintf(", stepwise={min=" FMT_FRACT ", max="
539 FMT_FRACT ", step=" FMT_FRACT "}",
540 ARGS_FRACT(f.stepwise.min),
541 ARGS_FRACT(f.stepwise.max),
542 ARGS_FRACT(f.stepwise.step));
543 break;
544 }
545 }
546 tprints("}");
547 return 1;
548 }
Dmitry V. Levin197db572015-01-09 04:53:19 +0000549#endif /* VIDIOC_ENUM_FRAMEINTERVALS */
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100550
551 case VIDIOC_CROPCAP: {
552 struct v4l2_cropcap c;
553
554 if (entering(tcp) || umove(tcp, arg, &c) < 0)
555 return 0;
556 tprints(", type=");
557 printxval(v4l2_buf_types, c.type, "V4L2_BUF_TYPE_???");
558 if (syserror(tcp))
559 return 1;
560 tprintf(", bounds=" FMT_RECT ", defrect=" FMT_RECT ", "
561 "pixelaspect=" FMT_FRACT, ARGS_RECT(c.bounds),
562 ARGS_RECT(c.defrect), ARGS_FRACT(c.pixelaspect));
563 return 1;
564 }
565
566 case VIDIOC_G_FBUF:
567 case VIDIOC_S_FBUF: {
568 struct v4l2_framebuffer b;
569
570 if (syserror(tcp) && code == VIDIOC_G_FBUF)
571 return 0;
572 if (entering(tcp) || umove(tcp, arg, &b) < 0)
573 return 0;
574 tprintf(", {capability=%x, flags=%x, base=%p}",
575 b.capability, b.flags, b.base);
576 return 1;
577 }
578
579 case VIDIOC_REQBUFS: {
580 struct v4l2_requestbuffers reqbufs;
581
582 if (umove(tcp, arg, &reqbufs) < 0)
583 return 0;
584 if (entering(tcp)) {
585 tprintf(", {count=%u, type=", reqbufs.count);
586 printxval(v4l2_buf_types, reqbufs.type, "V4L2_BUF_TYPE_???");
587 tprints(", memory=");
588 printxval(v4l2_memories, reqbufs.memory, "V4L2_MEMORY_???");
589 tprints("}");
590 return 1;
591 } else if (syserror(tcp))
592 return 1;
593 else {
594 static char outstr[sizeof("{count=}") + sizeof(int) * 3];
595
596 sprintf(outstr, "{count=%u}", reqbufs.count);
597 tcp->auxstr = outstr;
598 return 1 + RVAL_STR;
599 }
600 }
601
602 case VIDIOC_QUERYBUF:
603 case VIDIOC_QBUF:
604 case VIDIOC_DQBUF: {
605 struct v4l2_buffer b;
606
607 if (umove(tcp, arg, &b) < 0)
608 return 0;
609 if (entering(tcp)) {
610 tprints(", {type=");
611 printxval(v4l2_buf_types, b.type, "V4L2_BUF_TYPE_???");
612 if (code != VIDIOC_DQBUF)
613 tprintf(", index=%u", b.index);
614 } else {
615 if (!syserror(tcp)) {
616 if (code == VIDIOC_DQBUF)
617 tprintf(", index=%u", b.index);
618 tprints(", memory=");
619 printxval(v4l2_memories, b.memory, "V4L2_MEMORY_???");
620
621 if (b.memory == V4L2_MEMORY_MMAP) {
622 tprintf(", m.offset=%#x", b.m.offset);
623 } else if (b.memory == V4L2_MEMORY_USERPTR) {
624 tprintf(", m.userptr=%#lx", b.m.userptr);
625 }
626
627 tprintf(", length=%u, bytesused=%u, flags=",
628 b.length, b.bytesused);
629 printflags(v4l2_buf_flags, b.flags, "V4L2_BUF_FLAG_???");
630 if (code == VIDIOC_DQBUF)
631 tprintf(", timestamp = {%lu.%06lu}",
632 b.timestamp.tv_sec,
633 b.timestamp.tv_usec);
634 tprints(", ...");
635 }
636 tprints("}");
637 }
638 return 1;
639 }
640
641 case VIDIOC_STREAMON:
642 case VIDIOC_STREAMOFF: {
643 int type;
644
645 if (umove(tcp, arg, &type) < 0)
646 return 0;
647 if (entering(tcp)) {
648 tprints(", ");
649 printxval(v4l2_buf_types, type, "V4L2_BUF_TYPE_???");
650 }
651 return 1;
652 }
653
654 default: /* decode on exit */
655 return 0;
656 }
657}