int testFormats(struct node *node) { int type; int ret; for (type = 0; type <= V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; type++) { ret = testFormatsType(node, (enum v4l2_buf_type)type); if (ret > 0) return ret; if (ret && (node->caps & buftype2cap[type])) return fail("%s cap set, but no %s formats defined\n", buftype2s(type).c_str(), buftype2s(type).c_str()); if (!ret && !(node->caps & buftype2cap[type])) return fail("%s cap not set, but %s formats defined\n", buftype2s(type).c_str(), buftype2s(type).c_str()); } ret = testFormatsType(node, V4L2_BUF_TYPE_PRIVATE); if (ret > 0) return ret; if (!ret) warn("Buffer type PRIVATE allowed!\n"); return 0; }
int testEnumFormats(struct node *node) { static const __u32 buftype2cap[] = { 0, V4L2_CAP_VIDEO_CAPTURE, V4L2_CAP_VIDEO_OUTPUT, V4L2_CAP_VIDEO_OVERLAY, V4L2_CAP_VBI_CAPTURE, V4L2_CAP_VBI_OUTPUT, V4L2_CAP_SLICED_VBI_CAPTURE, V4L2_CAP_SLICED_VBI_OUTPUT, V4L2_CAP_VIDEO_OUTPUT_OVERLAY, V4L2_CAP_VIDEO_CAPTURE_MPLANE, V4L2_CAP_VIDEO_OUTPUT_MPLANE, }; int type; int ret; for (type = 0; type <= V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; type++) { ret = testEnumFormatsType(node, (enum v4l2_buf_type)type); if (ret > 0) return ret; switch (type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_OUTPUT: case V4L2_BUF_TYPE_VIDEO_OVERLAY: case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: if (ret < 0 && (node->caps & buftype2cap[type])) return fail("%s cap set, but no %s formats defined\n", buftype2s(type).c_str(), buftype2s(type).c_str()); if (!ret && !(node->caps & buftype2cap[type])) return fail("%s cap not set, but %s formats defined\n", buftype2s(type).c_str(), buftype2s(type).c_str()); break; default: if (!ret) return fail("Buffer type %s not allowed!\n", buftype2s(type).c_str()); break; } } ret = testEnumFormatsType(node, V4L2_BUF_TYPE_PRIVATE); if (ret > 0) return ret; if (!ret) warn("Buffer type PRIVATE allowed!\n"); ret = testEnumFrameSizes(node, 0x20202020); if (ret >= 0) return fail("Accepted framesize for invalid format\n"); ret = testEnumFrameIntervals(node, 0x20202020, 640, 480, false); if (ret >= 0) return fail("Accepted frameinterval for invalid format\n"); return 0; }
void misc_get(int fd) { if (options[OptGetJpegComp]) { struct v4l2_jpegcompression jc; if (doioctl(fd, VIDIOC_G_JPEGCOMP, &jc) == 0) printjpegcomp(jc); } if (options[OptGetParm]) { memset(&parm, 0, sizeof(parm)); parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (doioctl(fd, VIDIOC_G_PARM, &parm) == 0) { const struct v4l2_fract &tf = parm.parm.capture.timeperframe; printf("Streaming Parameters %s:\n", buftype2s(parm.type).c_str()); if (parm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) printf("\tCapabilities : timeperframe\n"); if (parm.parm.capture.capturemode & V4L2_MODE_HIGHQUALITY) printf("\tCapture mode : high quality\n"); if (!tf.denominator || !tf.numerator) printf("\tFrames per second: invalid (%d/%d)\n", tf.denominator, tf.numerator); else printf("\tFrames per second: %.3f (%d/%d)\n", (1.0 * tf.denominator) / tf.numerator, tf.denominator, tf.numerator); printf("\tRead buffers : %d\n", parm.parm.capture.readbuffers); } } if (options[OptGetOutputParm]) { memset(&parm, 0, sizeof(parm)); parm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; if (doioctl(fd, VIDIOC_G_PARM, &parm) == 0) { const struct v4l2_fract &tf = parm.parm.output.timeperframe; printf("Streaming Parameters %s:\n", buftype2s(parm.type).c_str()); if (parm.parm.output.capability & V4L2_CAP_TIMEPERFRAME) printf("\tCapabilities : timeperframe\n"); if (parm.parm.output.outputmode & V4L2_MODE_HIGHQUALITY) printf("\tOutput mode : high quality\n"); if (!tf.denominator || !tf.numerator) printf("\tFrames per second: invalid (%d/%d)\n", tf.denominator, tf.numerator); else printf("\tFrames per second: %.3f (%d/%d)\n", (1.0 * tf.denominator) / tf.numerator, tf.denominator, tf.numerator); printf("\tWrite buffers : %d\n", parm.parm.output.writebuffers); } } }
int testGetFormats(struct node *node) { struct v4l2_format fmt; bool supported = false; int type; int ret; for (type = 0; type <= V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; type++) { memset(&fmt, 0xff, sizeof(fmt)); fmt.type = type; ret = doioctl(node, VIDIOC_G_FMT, &fmt); ret = testFormatsType(node, ret, type, fmt); if (ret && ret != ENOTTY) return ret; if (!ret) { supported = true; node->valid_buftypes |= 1 << type; } if (ret && (node->caps & buftype2cap[type])) return fail("%s cap set, but no %s formats defined\n", buftype2s(type).c_str(), buftype2s(type).c_str()); if (!ret && !(node->caps & buftype2cap[type])) { switch (type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_OUTPUT: case V4L2_BUF_TYPE_VIDEO_OVERLAY: case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: return fail("%s cap not set, but %s formats defined\n", buftype2s(type).c_str(), buftype2s(type).c_str()); default: /* ENUMFMT doesn't support other buftypes */ break; } } } memset(&fmt, 0xff, sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_PRIVATE; ret = doioctl(node, VIDIOC_G_FMT, &fmt); ret = testFormatsType(node, ret, V4L2_BUF_TYPE_PRIVATE, fmt); if (ret && ret != ENOTTY) return ret; if (!ret) { supported = true; warn("Buffer type PRIVATE allowed!\n"); } return supported ? 0 : ENOTTY; }
int testEnumFormats(struct node *node) { bool supported = false; unsigned type; int ret; for (type = 0; type <= V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; type++) { ret = testEnumFormatsType(node, type); if (ret && ret != ENOTTY) return ret; if (!ret) supported = true; switch (type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_OUTPUT: case V4L2_BUF_TYPE_VIDEO_OVERLAY: case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: if (ret && (node->caps & buftype2cap[type])) return fail("%s cap set, but no %s formats defined\n", buftype2s(type).c_str(), buftype2s(type).c_str()); if (!ret && !(node->caps & buftype2cap[type])) return fail("%s cap not set, but %s formats defined\n", buftype2s(type).c_str(), buftype2s(type).c_str()); break; default: if (!ret) return fail("Buffer type %s not allowed!\n", buftype2s(type).c_str()); break; } } ret = testEnumFormatsType(node, V4L2_BUF_TYPE_PRIVATE); if (ret && ret != ENOTTY) return ret; if (!ret) { supported = true; warn("Buffer type PRIVATE allowed!\n"); } ret = testEnumFrameSizes(node, 0x20202020); if (ret != ENOTTY) return fail("Accepted framesize for invalid format\n"); ret = testEnumFrameIntervals(node, 0x20202020, 640, 480, false); if (ret != ENOTTY) return fail("Accepted frameinterval for invalid format\n"); return supported ? 0 : ENOTTY; }
int testParm(struct node *node) { bool supported = false; int type; int ret; for (type = 0; type <= V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; type++) { ret = testParmType(node, type); if (ret && ret != ENOTTY) return ret; if (!ret) { supported = true; if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE && type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && type != V4L2_BUF_TYPE_VIDEO_OUTPUT) return fail("G/S_PARM is only allowed for video capture/output\n"); if (!(node->caps & buftype2cap[type])) return fail("%s cap not set, but G/S_PARM worked\n", buftype2s(type).c_str()); } } ret = testParmType(node, V4L2_BUF_TYPE_PRIVATE); if (ret && ret != ENOTTY) return ret; if (!ret) { supported = true; warn("Buffer type PRIVATE allowed!\n"); } return supported ? 0 : ENOTTY; }
int testTryFormats(struct node *node) { struct v4l2_format fmt, fmt_try; int type; int ret; for (type = 0; type <= V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; type++) { if (!(node->valid_buftypes & (1 << type))) continue; memset(&fmt, 0xff, sizeof(fmt)); fmt.type = type; doioctl(node, VIDIOC_G_FMT, &fmt); fmt_try = fmt; ret = doioctl(node, VIDIOC_TRY_FMT, &fmt_try); if (ret) return fail("%s is valid, but no TRY_FMT was implemented\n", buftype2s(type).c_str()); ret = testFormatsType(node, ret, type, fmt_try); if (ret) return ret; if (memcmp(&fmt, &fmt_try, sizeof(fmt))) return fail("TRY_FMT(G_FMT) != G_FMT\n"); } for (type = 0; type <= V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; type++) { if (!(node->valid_buftypes & (1 << type))) continue; memset(&fmt, 0xff, sizeof(fmt)); fmt.type = type; fmt.fmt.pix.field = V4L2_FIELD_ANY; ret = doioctl(node, VIDIOC_TRY_FMT, &fmt); ret = testFormatsType(node, ret, type, fmt); if (ret) return fail("%s is valid, but TRY_FMT failed to return a format\n", buftype2s(type).c_str()); } memset(&fmt, 0xff, sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_PRIVATE; ret = doioctl(node, VIDIOC_TRY_FMT, &fmt); if (!ret) warn("Buffer type PRIVATE allowed!\n"); return node->valid_buftypes ? 0 : ENOTTY; }
static void print_sliced_vbi_cap(struct v4l2_sliced_vbi_cap &cap) { printf("\tType : %s\n", buftype2s(cap.type).c_str()); printf("\tService Set : %s\n", service2s(cap.service_set).c_str()); for (int i = 0; i < 24; i++) { printf("\tService Line %2d: %8s / %-8s\n", i, service2s(cap.service_lines[0][i]).c_str(), service2s(cap.service_lines[1][i]).c_str()); } }
void print_video_formats(int fd, __u32 type) { struct v4l2_fmtdesc fmt; memset(&fmt, 0, sizeof(fmt)); fmt.type = type; while (test_ioctl(fd, VIDIOC_ENUM_FMT, &fmt) >= 0) { printf("\tIndex : %d\n", fmt.index); printf("\tType : %s\n", buftype2s(type).c_str()); printf("\tPixel Format: '%s'", fcc2s(fmt.pixelformat).c_str()); if (fmt.flags) printf(" (%s)", fmtdesc2s(fmt.flags).c_str()); printf("\n"); printf("\tName : %s\n", fmt.description); printf("\n"); fmt.index++; } }
static void print_buffer(FILE *f, struct v4l2_buffer &buf) { fprintf(f, "\tIndex : %d\n", buf.index); fprintf(f, "\tType : %s\n", buftype2s(buf.type).c_str()); fprintf(f, "\tFlags : %s\n", flags2s(buf.flags, flags_def).c_str()); fprintf(f, "\tField : %s\n", field2s(buf.field).c_str()); fprintf(f, "\tSequence : %u\n", buf.sequence); fprintf(f, "\tLength : %u\n", buf.length); fprintf(f, "\tBytesused: %u\n", buf.bytesused); fprintf(f, "\tTimestamp: %lu.%06lus (%s)\n", buf.timestamp.tv_sec, buf.timestamp.tv_usec, timestamp_type2s(buf.flags).c_str()); if (buf.flags & V4L2_BUF_FLAG_TIMECODE) { static const int fps_types[] = { 0, 24, 25, 30, 50, 60 }; int fps = buf.timecode.type; if (fps > 5) fps = 0; fprintf(f, "\tTimecode : %dfps %s %dh %dm %ds %df (0x%02x 0x%02x 0x%02x 0x%02x)\n", fps_types[fps], flags2s(buf.timecode.flags, tc_flags_def).c_str(), buf.timecode.hours, buf.timecode.minutes, buf.timecode.seconds, buf.timecode.frames, buf.timecode.userbits[0], buf.timecode.userbits[1], buf.timecode.userbits[2], buf.timecode.userbits[3]); } if (buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE || buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { for (unsigned i = 0; i < buf.length; i++) { struct v4l2_plane *p = buf.m.planes + i; fprintf(f, "\tPlane : %d\n", i); fprintf(f, "\t\tLength : %u\n", p->length); fprintf(f, "\t\tBytesused : %u\n", p->bytesused); fprintf(f, "\t\tData Offset: %u\n", p->data_offset); } } fprintf(f, "\n"); }
static void print_video_formats_ext(int fd, __u32 type) { struct v4l2_fmtdesc fmt; struct v4l2_frmsizeenum frmsize; struct v4l2_frmivalenum frmival; fmt.index = 0; fmt.type = type; while (test_ioctl(fd, VIDIOC_ENUM_FMT, &fmt) >= 0) { printf("\tIndex : %d\n", fmt.index); printf("\tType : %s\n", buftype2s(type).c_str()); printf("\tPixel Format: '%s'", fcc2s(fmt.pixelformat).c_str()); if (fmt.flags) printf(" (%s)", fmtdesc2s(fmt.flags).c_str()); printf("\n"); printf("\tName : %s\n", fmt.description); frmsize.pixel_format = fmt.pixelformat; frmsize.index = 0; while (test_ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmsize) >= 0) { print_frmsize(frmsize, "\t"); if (frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE) { frmival.index = 0; frmival.pixel_format = fmt.pixelformat; frmival.width = frmsize.discrete.width; frmival.height = frmsize.discrete.height; while (test_ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival) >= 0) { print_frmival(frmival, "\t\t"); frmival.index++; } } frmsize.index++; } printf("\n"); fmt.index++; } }
void printfmt(const struct v4l2_format &vfmt) { const flag_def vbi_def[] = { { V4L2_VBI_UNSYNC, "unsynchronized" }, { V4L2_VBI_INTERLACED, "interlaced" }, { 0, NULL } }; printf("Format %s:\n", buftype2s(vfmt.type).c_str()); switch (vfmt.type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_OUTPUT: printf("\tWidth/Height : %u/%u\n", vfmt.fmt.pix.width, vfmt.fmt.pix.height); printf("\tPixel Format : '%s'\n", fcc2s(vfmt.fmt.pix.pixelformat).c_str()); printf("\tField : %s\n", field2s(vfmt.fmt.pix.field).c_str()); printf("\tBytes per Line : %u\n", vfmt.fmt.pix.bytesperline); printf("\tSize Image : %u\n", vfmt.fmt.pix.sizeimage); printf("\tColorspace : %s\n", colorspace2s(vfmt.fmt.pix.colorspace).c_str()); printf("\tTransfer Function : %s\n", xfer_func2s(vfmt.fmt.pix.xfer_func).c_str()); printf("\tYCbCr Encoding : %s\n", ycbcr_enc2s(vfmt.fmt.pix.ycbcr_enc).c_str()); printf("\tQuantization : %s\n", quantization2s(vfmt.fmt.pix.quantization).c_str()); if (vfmt.fmt.pix.priv == V4L2_PIX_FMT_PRIV_MAGIC) printf("\tFlags : %s\n", pixflags2s(vfmt.fmt.pix.flags).c_str()); break; case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: printf("\tWidth/Height : %u/%u\n", vfmt.fmt.pix_mp.width, vfmt.fmt.pix_mp.height); printf("\tPixel Format : '%s'\n", fcc2s(vfmt.fmt.pix_mp.pixelformat).c_str()); printf("\tField : %s\n", field2s(vfmt.fmt.pix_mp.field).c_str()); printf("\tNumber of planes : %u\n", vfmt.fmt.pix_mp.num_planes); printf("\tFlags : %s\n", pixflags2s(vfmt.fmt.pix_mp.flags).c_str()); printf("\tColorspace : %s\n", colorspace2s(vfmt.fmt.pix_mp.colorspace).c_str()); printf("\tTransfer Function : %s\n", xfer_func2s(vfmt.fmt.pix_mp.xfer_func).c_str()); printf("\tYCbCr Encoding : %s\n", ycbcr_enc2s(vfmt.fmt.pix_mp.ycbcr_enc).c_str()); printf("\tQuantization : %s\n", quantization2s(vfmt.fmt.pix_mp.quantization).c_str()); for (int i = 0; i < vfmt.fmt.pix_mp.num_planes && i < VIDEO_MAX_PLANES; i++) { printf("\tPlane %d :\n", i); printf("\t Bytes per Line : %u\n", vfmt.fmt.pix_mp.plane_fmt[i].bytesperline); printf("\t Size Image : %u\n", vfmt.fmt.pix_mp.plane_fmt[i].sizeimage); } break; case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: case V4L2_BUF_TYPE_VIDEO_OVERLAY: printf("\tLeft/Top : %d/%d\n", vfmt.fmt.win.w.left, vfmt.fmt.win.w.top); printf("\tWidth/Height: %d/%d\n", vfmt.fmt.win.w.width, vfmt.fmt.win.w.height); printf("\tField : %s\n", field2s(vfmt.fmt.win.field).c_str()); printf("\tChroma Key : 0x%08x\n", vfmt.fmt.win.chromakey); printf("\tGlobal Alpha: 0x%02x\n", vfmt.fmt.win.global_alpha); printf("\tClip Count : %u\n", vfmt.fmt.win.clipcount); if (vfmt.fmt.win.clips) for (unsigned i = 0; i < vfmt.fmt.win.clipcount; i++) { struct v4l2_rect &r = vfmt.fmt.win.clips[i].c; printf("\t\tClip %2d: %ux%u@%ux%u\n", i, r.width, r.height, r.left, r.top); } printf("\tClip Bitmap : %s", vfmt.fmt.win.bitmap ? "Yes, " : "No\n"); if (vfmt.fmt.win.bitmap) { unsigned char *bitmap = (unsigned char *)vfmt.fmt.win.bitmap; unsigned stride = (vfmt.fmt.win.w.width + 7) / 8; unsigned cnt = 0; for (unsigned y = 0; y < vfmt.fmt.win.w.height; y++) for (unsigned x = 0; x < vfmt.fmt.win.w.width; x++) if (bitmap[y * stride + x / 8] & (1 << (x & 7))) cnt++; printf("%u bits of %u are set\n", cnt, vfmt.fmt.win.w.width * vfmt.fmt.win.w.height); } break; case V4L2_BUF_TYPE_VBI_CAPTURE: case V4L2_BUF_TYPE_VBI_OUTPUT: printf("\tSampling Rate : %u Hz\n", vfmt.fmt.vbi.sampling_rate); printf("\tOffset : %u samples (%g secs after leading edge)\n", vfmt.fmt.vbi.offset, (double)vfmt.fmt.vbi.offset / (double)vfmt.fmt.vbi.sampling_rate); printf("\tSamples per Line: %u\n", vfmt.fmt.vbi.samples_per_line); printf("\tSample Format : %s\n", fcc2s(vfmt.fmt.vbi.sample_format).c_str()); printf("\tStart 1st Field : %u\n", vfmt.fmt.vbi.start[0]); printf("\tCount 1st Field : %u\n", vfmt.fmt.vbi.count[0]); printf("\tStart 2nd Field : %u\n", vfmt.fmt.vbi.start[1]); printf("\tCount 2nd Field : %u\n", vfmt.fmt.vbi.count[1]); if (vfmt.fmt.vbi.flags) printf("\tFlags : %s\n", flags2s(vfmt.fmt.vbi.flags, vbi_def).c_str()); break; case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: printf("\tService Set : %s\n", service2s(vfmt.fmt.sliced.service_set).c_str()); for (int i = 0; i < 24; i++) { printf("\tService Line %2d: %8s / %-8s\n", i, service2s(vfmt.fmt.sliced.service_lines[0][i]).c_str(), service2s(vfmt.fmt.sliced.service_lines[1][i]).c_str()); } printf("\tI/O Size : %u\n", vfmt.fmt.sliced.io_size); break; case V4L2_BUF_TYPE_SDR_CAPTURE: case V4L2_BUF_TYPE_SDR_OUTPUT: printf("\tSample Format : %s\n", fcc2s(vfmt.fmt.sdr.pixelformat).c_str()); printf("\tBuffer Size : %u\n", vfmt.fmt.sdr.buffersize); break; } }