void stds_get(int fd) { if (options[OptGetStandard]) { if (doioctl(fd, VIDIOC_G_STD, &standard) == 0) { printf("Video Standard = 0x%08llx\n", (unsigned long long)standard); print_v4lstd((unsigned long long)standard); } } if (options[OptGetDvTimings]) { if (doioctl(fd, VIDIOC_G_DV_TIMINGS, &dv_timings) >= 0) { printf("DV timings:\n"); print_dv_timings(&dv_timings); } } if (options[OptGetDvTimingsCap]) { struct v4l2_dv_timings_cap dv_timings_cap; if (doioctl(fd, VIDIOC_DV_TIMINGS_CAP, &dv_timings_cap) >= 0) { static const flag_def dv_caps_def[] = { { V4L2_DV_BT_CAP_INTERLACED, "Interlaced" }, { V4L2_DV_BT_CAP_PROGRESSIVE, "Progressive" }, { V4L2_DV_BT_CAP_REDUCED_BLANKING, "Reduced Blanking" }, { V4L2_DV_BT_CAP_CUSTOM, "Custom Formats" }, { 0, NULL } }; struct v4l2_bt_timings_cap *bt = &dv_timings_cap.bt; printf("DV timings capabilities:\n"); if (dv_timings_cap.type != V4L2_DV_BT_656_1120) printf("\tUnknown type\n"); else { printf("\tMinimum Width: %u\n", bt->min_width); printf("\tMaximum Width: %u\n", bt->max_width); printf("\tMinimum Height: %u\n", bt->min_height); printf("\tMaximum Height: %u\n", bt->max_height); printf("\tMinimum PClock: %llu\n", bt->min_pixelclock); printf("\tMaximum PClock: %llu\n", bt->max_pixelclock); printf("\tStandards: %s\n", flags2s(bt->standards, dv_standards_def).c_str()); printf("\tCapabilities: %s\n", flags2s(bt->capabilities, dv_caps_def).c_str()); } } } if (options[OptQueryStandard]) { if (doioctl(fd, VIDIOC_QUERYSTD, &standard) == 0) { printf("Video Standard = 0x%08llx\n", (unsigned long long)standard); print_v4lstd((unsigned long long)standard); } } if (options[OptQueryDvTimings]) { doioctl(fd, VIDIOC_QUERY_DV_TIMINGS, &dv_timings); print_dv_timings(&dv_timings); } }
static void print_qctrl(int fd, struct v4l2_queryctrl *queryctrl, struct v4l2_ext_control *ctrl, int show_menus) { struct v4l2_querymenu qmenu = { 0 }; std::string s = name2var(queryctrl->name); int i; qmenu.id = queryctrl->id; switch (queryctrl->type) { case V4L2_CTRL_TYPE_INTEGER: printf("%31s (int) : min=%d max=%d step=%d default=%d value=%d", s.c_str(), queryctrl->minimum, queryctrl->maximum, queryctrl->step, queryctrl->default_value, ctrl->value); break; case V4L2_CTRL_TYPE_INTEGER64: printf("%31s (int64): value=%lld", s.c_str(), ctrl->value64); break; case V4L2_CTRL_TYPE_BOOLEAN: printf("%31s (bool) : default=%d value=%d", s.c_str(), queryctrl->default_value, ctrl->value); break; case V4L2_CTRL_TYPE_MENU: printf("%31s (menu) : min=%d max=%d default=%d value=%d", s.c_str(), queryctrl->minimum, queryctrl->maximum, queryctrl->default_value, ctrl->value); break; case V4L2_CTRL_TYPE_BUTTON: printf("%31s (button)\n", s.c_str()); break; default: break; } if (queryctrl->flags) { const flag_def def[] = { { V4L2_CTRL_FLAG_GRABBED, "grabbed" }, { V4L2_CTRL_FLAG_READ_ONLY, "read-only" }, { V4L2_CTRL_FLAG_UPDATE, "update" }, { V4L2_CTRL_FLAG_INACTIVE, "inactive" }, { V4L2_CTRL_FLAG_SLIDER, "slider" }, { 0, NULL } }; printf(" flags=%s", flags2s(queryctrl->flags, def).c_str()); } printf("\n"); if (queryctrl->type == V4L2_CTRL_TYPE_MENU && show_menus) { for (i = 0; i <= queryctrl->maximum; i++) { qmenu.index = i; if (ioctl(fd, VIDIOC_QUERYMENU, &qmenu)) continue; printf("\t\t\t\t%d: %s\n", i, qmenu.name); } } }
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 std::string ctrlflags2s(__u32 flags) { static const flag_def def[] = { { V4L2_CTRL_FLAG_GRABBED, "grabbed" }, { V4L2_CTRL_FLAG_DISABLED, "disabled" }, { V4L2_CTRL_FLAG_READ_ONLY, "read-only" }, { V4L2_CTRL_FLAG_UPDATE, "update" }, { V4L2_CTRL_FLAG_INACTIVE, "inactive" }, { V4L2_CTRL_FLAG_SLIDER, "slider" }, { V4L2_CTRL_FLAG_WRITE_ONLY, "write-only" }, { V4L2_CTRL_FLAG_VOLATILE, "volatile" }, { 0, NULL } }; return flags2s(flags, def); }
std::string fmtdesc2s(unsigned flags) { return flags2s(flags, fmtdesc_def); }
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; } }
std::string service2s(unsigned service) { return flags2s(service, service_def); }
std::string pixflags2s(unsigned flags) { return flags2s(flags, pixflags_def); }
static void print_dv_timings(const struct v4l2_dv_timings *t) { const struct v4l2_bt_timings *bt; double tot_width, tot_height; switch (t->type) { case V4L2_DV_BT_656_1120: bt = &t->bt; tot_height = bt->height + bt->vfrontporch + bt->vsync + bt->vbackporch + bt->il_vfrontporch + bt->il_vsync + bt->il_vbackporch; tot_width = bt->width + bt->hfrontporch + bt->hsync + bt->hbackporch; if (options[OptConcise]) { printf("\t%dx%d%c%.2f %s\n", bt->width, bt->height, bt->interlaced ? 'i' : 'p', (double)bt->pixelclock / (tot_width * (tot_height / (bt->interlaced ? 2 : 1))), flags2s(bt->flags, dv_flags_def).c_str()); break; } printf("\tActive width: %d\n", bt->width); printf("\tActive height: %d\n", bt->height); printf("\tTotal width: %d\n",bt->width + bt->hfrontporch + bt->hsync + bt->hbackporch); printf("\tTotal height: %d\n", bt->height + bt->vfrontporch + bt->vsync + bt->vbackporch + bt->il_vfrontporch + bt->il_vsync + bt->il_vbackporch); printf("\tFrame format: %s\n", bt->interlaced ? "interlaced" : "progressive"); printf("\tPolarities: %cvsync %chsync\n", (bt->polarities & V4L2_DV_VSYNC_POS_POL) ? '+' : '-', (bt->polarities & V4L2_DV_HSYNC_POS_POL) ? '+' : '-'); printf("\tPixelclock: %lld Hz", bt->pixelclock); if (bt->width && bt->height) { if (bt->interlaced) printf(" (%.2f fields per second)", (double)bt->pixelclock / (tot_width * (tot_height / 2))); else printf(" (%.2f frames per second)", (double)bt->pixelclock / (tot_width * tot_height)); } printf("\n"); printf("\tHorizontal frontporch: %d\n", bt->hfrontporch); printf("\tHorizontal sync: %d\n", bt->hsync); printf("\tHorizontal backporch: %d\n", bt->hbackporch); if (bt->interlaced) printf("\tField 1:\n"); printf("\tVertical frontporch: %d\n", bt->vfrontporch); printf("\tVertical sync: %d\n", bt->vsync); printf("\tVertical backporch: %d\n", bt->vbackporch); if (bt->interlaced) { printf("\tField 2:\n"); printf("\tVertical frontporch: %d\n", bt->il_vfrontporch); printf("\tVertical sync: %d\n", bt->il_vsync); printf("\tVertical backporch: %d\n", bt->il_vbackporch); } printf("\tStandards: %s\n", flags2s(bt->standards, dv_standards_def).c_str()); printf("\tFlags: %s\n", flags2s(bt->flags, dv_flags_def).c_str()); break; default: printf("Timing type not defined\n"); break; } }
static std::string output_cap2s(__u32 capabilities) { return capabilities ? flags2s(capabilities, output_cap_def) : "not defined"; }
static std::string status2s(__u32 status) { return status ? flags2s(status, in_status_def) : "ok"; }