void get_supported_settings( CAM_SETTINGS cs, SUPPORTED_SETTINGS *ss ) { struct v4l2_fmtdesc fmt; struct v4l2_frmsizeenum frmsize; struct v4l2_frmivalenum frmival; int res_c = 0; int fps_c = 0; fmt.index = 0; fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; while ( ioctl( fd, VIDIOC_ENUM_FMT, &fmt ) >= 0 ) { strcpy( ss->pix_fmt[fmt.index], fcc2s(fmt.pixelformat).c_str() ); if( strcmp( ss->pix_fmt[fmt.index], cs.pix_fmt ) == 0 ) { frmsize.pixel_format = fmt.pixelformat; frmsize.index = 0; while( ioctl( fd, VIDIOC_ENUM_FRAMESIZES, &frmsize ) >= 0 ) { if ( frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE ) { ss->width[frmsize.index] = frmsize.discrete.width; ss->height[frmsize.index] = frmsize.discrete.height; if( ss->width[frmsize.index] == cs.width && ss->height[frmsize.index] == cs.height ) { frmival.pixel_format = fmt.pixelformat; frmival.width = frmsize.discrete.width; frmival.height = frmsize.discrete.height; frmival.index = 0; while( ioctl( fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival ) >= 0 ) { ss->fps[frmival.index] = frmival.discrete.denominator / frmival.discrete.numerator; frmival.index++; } ss->fps_c = frmival.index; } } else printf("Error. Framesize type is not V4L2_FRMSIZE_TYPE_DISCRETE (unimplemented)\n"); frmsize.index++; } ss->res_c = frmsize.index; } fmt.index++; } ss->fmt_c = fmt.index; }
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++; } }
void get_camera_settings( CAM_SETTINGS *cs ) { struct v4l2_format vfmt; struct v4l2_streamparm parm; vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if( ioctl( fd, VIDIOC_G_FMT, &vfmt ) == 0) { cs->width = vfmt.fmt.pix.width; cs->height = vfmt.fmt.pix.height; strcpy( cs->pix_fmt, fcc2s( vfmt.fmt.pix.pixelformat ).c_str() ); } if( ioctl( fd, VIDIOC_G_PARM, &parm ) == 0 ) { const struct v4l2_fract &tf = parm.parm.capture.timeperframe; cs->fps = tf.denominator / tf.numerator; } }
static void printfbuf(const struct v4l2_framebuffer &fb) { int is_ext = fb.capability & V4L2_FBUF_CAP_EXTERNOVERLAY; printf("Framebuffer Format:\n"); printf("\tCapability : %s", fbufcap2s(fb.capability).c_str() + 3); printf("\tFlags : %s", fbufflags2s(fb.flags).c_str() + 3); if (fb.base) printf("\tBase : 0x%p\n", fb.base); printf("\tWidth : %d\n", fb.fmt.width); printf("\tHeight : %d\n", fb.fmt.height); printf("\tPixel Format : '%s'\n", fcc2s(fb.fmt.pixelformat).c_str()); if (!is_ext) { printf("\tBytes per Line: %d\n", fb.fmt.bytesperline); printf("\tSize image : %d\n", fb.fmt.sizeimage); printf("\tColorspace : %s\n", colorspace2s(fb.fmt.colorspace).c_str()); if (fb.fmt.priv) printf("\tCustom Info : %08x\n", fb.fmt.priv); } }
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; } }