From 15f9aeba0eed66443c56925c9c99c3b2df851aac Mon Sep 17 00:00:00 2001 From: Mike Engel Date: Thu, 13 Aug 2020 15:18:46 +0200 Subject: [PATCH] meta-digi-dey: dey-examples: Remove v4l2 examples. This commit removes the v4l2 example because they are superseded by gstreamer examples. Signed-off-by: Mike Engel https://jira.digi.com/browse/DEL-7211 --- .../dey-examples/dey-examples-v4l2.bb | 27 - .../files/v4l2_test/v4l2_common.c | 1129 ----------------- .../dey-examples/files/v4l2_test/v4l2_defs.h | 183 --- .../files/v4l2_test/v4l2_preview_test.c | 505 -------- .../dey-examples/files/v4l2_test/v4l2_still.c | 390 ------ .../packagegroup-dey-examples.bb | 9 - 6 files changed, 2243 deletions(-) delete mode 100644 meta-digi-dey/recipes-digi/dey-examples/dey-examples-v4l2.bb delete mode 100644 meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_common.c delete mode 100644 meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_defs.h delete mode 100644 meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_preview_test.c delete mode 100644 meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_still.c diff --git a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-v4l2.bb b/meta-digi-dey/recipes-digi/dey-examples/dey-examples-v4l2.bb deleted file mode 100644 index d10a2a52d..000000000 --- a/meta-digi-dey/recipes-digi/dey-examples/dey-examples-v4l2.bb +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright (C) 2013-2020 Digi International. - -SUMMARY = "DEY examples: V4L2 test application" -SECTION = "examples" -LICENSE = "GPL-2.0" -LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6" - -inherit use-imx-headers - -SRC_URI = "file://v4l2_test" -INCLUDE_PATH = "-I${STAGING_INCDIR_IMX}" - -S = "${WORKDIR}/v4l2_test" - -do_compile() { - ${CC} -O2 -Wall ${INCLUDE_PATH} ${LDFLAGS} v4l2_still.c -o v4l2_still -lpthread - ${CC} -O2 -Wall ${INCLUDE_PATH} ${LDFLAGS} v4l2_common.c v4l2_preview_test.c -o v4l2_preview_test -lpthread -} - -do_install() { - install -d ${D}${bindir} - install -m 0755 v4l2_still v4l2_preview_test ${D}${bindir} -} - -PACKAGE_ARCH = "${MACHINE_ARCH}" - -COMPATIBLE_MACHINE = "(ccimx6$|ccimx8x|ccimx8m)" diff --git a/meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_common.c b/meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_common.c deleted file mode 100644 index 77c36425a..000000000 --- a/meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_common.c +++ /dev/null @@ -1,1129 +0,0 @@ -/* - * v4l2_common.c - * - * Copyright (C) 2012 by Digi International Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published by - * the Free Software Foundation. - * - * Description: V4L2 common library. - * - * V4L2 API @ http://v4l2spec.bytesex.org/ - * - */ - -#include "v4l2_defs.h" - -#define _MAKE_CHAN(num, v_in, g_in, a_in, out) \ - ((num << 24) | (v_in << 18) | (g_in << 12) | (a_in << 6) | out) -#define IPU_MAX_CH 32 -#define _MAKE_ALT_CHAN(ch) (ch | (IPU_MAX_CH << 24)) -#define NO_DMA 0x3F -/*! - * Enumeration of IPU logical channels. An IPU logical channel is defined as a - * combination of an input (memory to IPU), output (IPU to memory), and/or - * secondary input IDMA channels and in some cases an Image Converter task. - * Some channels consist of only an input or output. - */ -typedef enum { - CHAN_NONE = -1, - MEM_ROT_ENC_MEM = _MAKE_CHAN(1, 45, NO_DMA, NO_DMA, 48), - MEM_ROT_VF_MEM = _MAKE_CHAN(2, 46, NO_DMA, NO_DMA, 49), - MEM_ROT_PP_MEM = _MAKE_CHAN(3, 47, NO_DMA, NO_DMA, 50), - - MEM_PRP_ENC_MEM = _MAKE_CHAN(4, 12, 14, 17, 20), - MEM_PRP_VF_MEM = _MAKE_CHAN(5, 12, 14, 17, 21), - MEM_PP_MEM = _MAKE_CHAN(6, 11, 15, 18, 22), - - MEM_DC_SYNC = _MAKE_CHAN(7, 28, NO_DMA, NO_DMA, NO_DMA), - MEM_DC_ASYNC = _MAKE_CHAN(8, 41, NO_DMA, NO_DMA, NO_DMA), - MEM_BG_SYNC = _MAKE_CHAN(9, 23, NO_DMA, 51, NO_DMA), - MEM_FG_SYNC = _MAKE_CHAN(10, 27, NO_DMA, 31, NO_DMA), - - MEM_BG_ASYNC0 = _MAKE_CHAN(11, 24, NO_DMA, 52, NO_DMA), - MEM_FG_ASYNC0 = _MAKE_CHAN(12, 29, NO_DMA, 33, NO_DMA), - MEM_BG_ASYNC1 = _MAKE_ALT_CHAN(MEM_BG_ASYNC0), - MEM_FG_ASYNC1 = _MAKE_ALT_CHAN(MEM_FG_ASYNC0), - - DIRECT_ASYNC0 = _MAKE_CHAN(13, NO_DMA, NO_DMA, NO_DMA, NO_DMA), - DIRECT_ASYNC1 = _MAKE_CHAN(14, NO_DMA, NO_DMA, NO_DMA, NO_DMA), - - CSI_MEM0 = _MAKE_CHAN(15, NO_DMA, NO_DMA, NO_DMA, 0), - CSI_MEM1 = _MAKE_CHAN(16, NO_DMA, NO_DMA, NO_DMA, 1), - CSI_MEM2 = _MAKE_CHAN(17, NO_DMA, NO_DMA, NO_DMA, 2), - CSI_MEM3 = _MAKE_CHAN(18, NO_DMA, NO_DMA, NO_DMA, 3), - - CSI_MEM = CSI_MEM0, - - CSI_PRP_ENC_MEM = _MAKE_CHAN(19, NO_DMA, NO_DMA, NO_DMA, 20), - CSI_PRP_VF_MEM = _MAKE_CHAN(20, NO_DMA, NO_DMA, NO_DMA, 21), - - /* for vdi mem->vdi->ic->mem , add graphics plane and alpha*/ - MEM_VDI_PRP_VF_MEM_P = _MAKE_CHAN(21, 8, 14, 17, 21), - MEM_VDI_PRP_VF_MEM = _MAKE_CHAN(22, 9, 14, 17, 21), - MEM_VDI_PRP_VF_MEM_N = _MAKE_CHAN(23, 10, 14, 17, 21), - - /* for vdi mem->vdi->mem */ - MEM_VDI_MEM_P = _MAKE_CHAN(24, 8, NO_DMA, NO_DMA, 5), - MEM_VDI_MEM = _MAKE_CHAN(25, 9, NO_DMA, NO_DMA, 5), - MEM_VDI_MEM_N = _MAKE_CHAN(26, 10, NO_DMA, NO_DMA, 5), - - /* fake channel for vdoa to link with IPU */ - MEM_VDOA_MEM = _MAKE_CHAN(27, NO_DMA, NO_DMA, NO_DMA, NO_DMA), - - MEM_PP_ADC = CHAN_NONE, - ADC_SYS2 = CHAN_NONE, - -} ipu_channel_t; - -#define BRIGHTNESS_MAX_VALUE 0xFF -#define BRIGTHNESS_MIN_VALUE 0 -#define SATURATION_MAX_VALUE 0xFF -#define SATURATION_MIN_VALUE 0 -#define GLOBAL_ALPHA_MAX_VALUE 0xFF -/* This is confusing, because they are inverted */ -#define LOCAL_ALPHA_MAX_VALUE 0x0 -#define LOCAL_ALPHA_MIN_VALUE 0xFF - -/* Returns the open file descriptor if the fb is an MXC fb overlay, - * error otherwise. */ -static int v4l2_mxc_is_overlay(char *fb_device) -{ - int fd, ret; - struct fb_fix_screeninfo fb_fix; - - fd = ret = -1; - - if ((fd = open(fb_device, O_RDWR)) < 0) { - log("Unable to open frame buffer 0\n"); - return ret; - } - - if ((ret = ioctl(fd, FBIOGET_FSCREENINFO, &fb_fix)) < 0) { - close(fd); - return ret; - } - - if (!strcmp(fb_fix.id, "DISP3 FG")) - return fd; - - close(fd); - return -1; -} - -/* Return overlay background framebuffer device path, error otherwise */ -int v4l2_get_overlay_bg(char *fb_device) -{ - static const char *fb_path = "/dev/fb"; - int ipu_ch, i; - int fd = -1; - - for (i = 0; i < 2; i++) { - sprintf(fb_device, "%s%d", fb_path, i); - if ((fd = open(fb_device, O_RDWR)) < 0) { - log("Unable to open frame buffer %s\n", fb_device); - goto error; - } - if (ioctl(fd, MXCFB_GET_FB_IPU_CHAN, &ipu_ch) < 0) { - log("ioctl MXCFB_GET_FB_IPU_CHAN error\n"); - close(fd); - goto error; - } - close(fd); - if (ipu_ch == MEM_BG_SYNC) { - log("Overlay background frame buffer device: %s\n", fb_device); - return 0; - } - } - -error: - return -1; -} - -/* Enables or disables the V4L2 previewing */ -int v4l2_overlay_control(int fd_overlay, int start) -{ - /* Start overlay */ - return ioctl(fd_overlay, VIDIOC_OVERLAY, &start); -} - -/* Returns a string representation of some v4L2 pixel formats, or its - * numerical code string otherwise. */ -char *v4l2_fmt_str(int pixelformat) -{ - static char tmp[64] = ""; - - switch (pixelformat) { - case IPU_PIX_FMT_RGB332: - return "RGB332"; - case IPU_PIX_FMT_RGB555: - return "RGB555"; - case IPU_PIX_FMT_RGB565: - return "RGB565"; - case IPU_PIX_FMT_RGB666: - return "RGB666"; - case IPU_PIX_FMT_RGB24: - return "RGB24"; - case IPU_PIX_FMT_BGR32: - return "BGR32"; - case IPU_PIX_FMT_BGRA32: - return "BGRA32"; - case IPU_PIX_FMT_RGB32: - return "RGB32"; - case IPU_PIX_FMT_RGBA32: - return "RGBA32"; - case IPU_PIX_FMT_ABGR32: - return "ABGR32"; - case IPU_PIX_FMT_BGR24: - return "BGR24"; - case IPU_PIX_FMT_YUYV: - return "YUYV"; - case IPU_PIX_FMT_UYVY: - return "UYVY"; - case IPU_PIX_FMT_YVYU: - return "YVYU"; - case IPU_PIX_FMT_VYUY: - return "VYUY"; - case IPU_PIX_FMT_Y41P: - return "Y41P"; - case IPU_PIX_FMT_YUV444: - return "YUV444"; - case IPU_PIX_FMT_VYU444: - return "VYU444"; - case IPU_PIX_FMT_NV12: - return "NV12"; - // Missing formats - default: - sprintf(tmp, "Undecoded format: %x\n", pixelformat); - return tmp; - } -} - -/* Returns true if the specified V4L2 capability is supported by the - * device, false or error otherwise.*/ -int v4l2_is_capability_supported(int fd, int cap) -{ - struct v4l2_capability capability; - int ret = 0; - - /* Check the device capabilities */ - memset(&capability, 0, sizeof(capability)); - ret = ioctl(fd, VIDIOC_QUERYCAP, &capability); - if (ret < 0) { - if (errno == -EINVAL) - log("Not a V4L2 device.\n"); - return ret; - } - - if (capability.capabilities & cap) { - return TRUE; - } - return FALSE; -} - -/* Returns true if the specified V4L2 video standard is supported by the - * device, false or error otherwise.*/ -int v4l2_is_video_std_supported(int fd, int standard) -{ - v4l2_std_id std_id; - int ret = 0; - - /* Check video standard */ - memset(&std_id, 0, sizeof(std_id)); - if ((ret = ioctl(fd, VIDIOC_G_STD, &std_id)) < 0) { - log("VIDIOC_G_STD failed with %d\n", ret); - return ret; - } - - if (std_id & standard) - return TRUE; - return FALSE; -} - -/* Returns true if the specified V4L2 capture pixel format is supported by the - * device, false or error otherwise.*/ -int v4l2_is_format_supported(int fd, int format) -{ - struct v4l2_fmtdesc fmtdesc; - int ret = 0; - - /* Check whether the requested format is supported by the device */ - memset(&fmtdesc, 0, sizeof(fmtdesc)); - fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - do { - ret = ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc); - fmtdesc.index++; - if (fmtdesc.pixelformat == format) - break; - } while (ret >= 0); - - if (ret == 0) - return TRUE; - - if (ret < 0 && errno != EINVAL) - log("VIDIOC_ENUM_FMT failed with %d\n", errno); - return FALSE; -} - -/* Check whether a specified framerate is configured in the device */ -int v4l2_check_frame_rate(int fd, int framerate) -{ - struct v4l2_streamparm streamparm; - - memset(&streamparm, 0, sizeof(streamparm)); - streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - streamparm.parm.capture.timeperframe.numerator = 0; - streamparm.parm.capture.timeperframe.denominator = 0; - if (ioctl(fd, VIDIOC_G_PARM, &streamparm) < 0) { - log("get frame rate failed\n"); - return FALSE; - } - log("Frame rate is %d\n", streamparm.parm.capture.timeperframe.denominator); - - if (streamparm.parm.capture.timeperframe.denominator == framerate) - return TRUE; - return FALSE; -} - -/* Set the specified framerate on the V4L2 device */ -int v4l2_set_frame_rate(int fd, int framerate) -{ - struct v4l2_streamparm streamparm; - - memset(&streamparm, 0, sizeof(streamparm)); - - /* Set stream parameters */ - streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - streamparm.parm.capture.timeperframe.numerator = 1; - streamparm.parm.capture.timeperframe.denominator = framerate; - - return ioctl(fd, VIDIOC_S_PARM, &streamparm); -} - -/* Set the specified capture mode on the V4L2 device */ -int v4l2_set_capture_mode(int fd, int capturemode) -{ - struct v4l2_streamparm streamparm; - - memset(&streamparm, 0, sizeof(streamparm)); - streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (ioctl(fd, VIDIOC_G_PARM, &streamparm) < 0) { - log("get frame rate failed\n"); - return FALSE; - } - - /* Set capture mode */ - streamparm.parm.capture.capturemode = capturemode; - - return ioctl(fd, VIDIOC_S_PARM, &streamparm); -} - -/* Return true if the output specified by name is supported by the device, - * false or error otherwise */ -int v4l2_check_output(int fd, char *name) -{ - struct v4l2_output output; - int ret = 0; - - /* Check what are the available video outputs */ - memset(&output, 0, sizeof(output)); - - do { - ret = ioctl(fd, VIDIOC_ENUMOUTPUT, &output); - output.index++; - if (ret >= 0) - log("Supported output %s\n", output.name); - if (!strcmp((char *)output.name, name)) - return TRUE; - } while (ret >= 0); - - if (ret != 0 && errno != EINVAL) { - log("VIDIOC_ENUMOUTPUT failed with %d\n", errno); - return ret; - } - return FALSE; -} - -/* Set the current video output */ -int v4l2_set_output(int fd, struct fb_fix_screeninfo *fb_fix) -{ - struct v4l2_output output; - int ret = 0; - - memset(&output, 0, sizeof(output)); - while ((ret = ioctl(fd, VIDIOC_ENUMOUTPUT, &output)) >= 0) { - if (!strcmp((char *)output.name, fb_fix->id)) { - if ((ret = ioctl(fd, VIDIOC_S_OUTPUT, &(output.index))) < 0) { - log("Set output failed with %d\n", ret); - } - break; - } - output.index++; - } - - return ret; -} - -/* Sets a specified pixel format and scale to the V4L2 device overlay */ -int v4l2_set_format_capture(int fd, int pixelformat, int height, int width) -{ - struct v4l2_format format; - int ret = 0; - - /* Get the data format */ - if ((ret = ioctl(fd, VIDIOC_G_FMT, &format)) < 0) { - log("Get format failed with %d\n", ret); - return ret; - } - - format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - format.fmt.pix.width = width; - format.fmt.pix.height = height; - format.fmt.pix.pixelformat = pixelformat; - - if ((ret = ioctl(fd, VIDIOC_S_FMT, &format)) < 0) { - log("Set format failed with %d\n", ret); - } - log("Pixel format set to %s\n", v4l2_fmt_str(pixelformat)); - log("Sensor cropping dimensions set to H %d W %d\n", height, width); - return ret; -} - -/* Sets a specified pixel format and scale to the V4L2 device overlay */ -int v4l2_set_format_overlay(int fd, int top, int left, int height, int width) -{ - struct v4l2_format format; - int ret = 0; - - /* Get the data format */ - format.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; - if ((ret = ioctl(fd, VIDIOC_G_FMT, &format)) < 0) { - log("Get format failed with %d\n", ret); - return ret; - } - - format.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; - format.fmt.win.w.top = top; - format.fmt.win.w.left = left; - format.fmt.win.w.width = width; - format.fmt.win.w.height = height; - - if ((ret = ioctl(fd, VIDIOC_S_FMT, &format)) < 0) { - log("Set format failed with %d\n", ret); - } - log("Overlay dimensions set to H %d W %d L %d T %d\n", height, width, left, top); - return ret; -} - -int v4l2_fb_blank(int fd) -{ - return (ioctl(fd, FBIOBLANK, FB_BLANK_NORMAL)); -} - -int v4l2_fb_unblank(int fd) -{ - return (ioctl(fd, FBIOBLANK, FB_BLANK_UNBLANK)); -} - -static int v4l2_fb_put_vinfo(int fd, struct fb_var_screeninfo *fb_var) -{ - return (ioctl(fd, FBIOPUT_VSCREENINFO, fb_var)); -} - -static int v4l2_fb_get_vinfo(int fd, struct fb_var_screeninfo *fb_var) -{ - return (ioctl(fd, FBIOGET_VSCREENINFO, fb_var)); -} - -static int v4l2_fb_get_finfo(int fd, struct fb_fix_screeninfo *fb_fix) -{ - return (ioctl(fd, FBIOGET_FSCREENINFO, fb_fix)); -} - -/* Retrieves fixed and variable framebuffer information */ -int v4l2_fb_get_info(char *fb_device, struct fb_fix_screeninfo *fb_fix, - struct fb_var_screeninfo *fb_var) -{ - int ret = 0; - int fd = 0; - - /* Open framebuffer device */ - if ((fd = open(fb_device, O_RDWR)) < 0) { - log("Unable to open frame buffer %s\n", fb_device); - return -EIO; - } - - log("Opened %s\n", fb_device); - - /* Obtain fixed and variable screen info for framebuffer */ - if ((ret = v4l2_fb_get_vinfo(fd, fb_var)) < 0) - goto out; - - if ((ret = v4l2_fb_get_finfo(fd, fb_fix)) < 0) - goto out; - -out: - return fd; -} - -/* Identifies the available outputs for a framebuffer device. - * - * MXC hardcoded ID strings are: - * DISP3 BG: For background framebuffer. - * DISP3 BG - DI1: For secondary background framebuffer. - * DISP3 FG: For overlay (foreground) framebuffer. - */ -void v4l2_ident_outputs(int fd) -{ - struct v4l2_output output; - int ret = 0; - - /* Identify available outputs */ - memset(&output, 0, sizeof(output)); - do { - ret = ioctl(fd, VIDIOC_ENUMOUTPUT, &output); - output.index++; - log("Supported output %s\n", output.name); - } while (ret >= 0); -} - -/* Returns an opened file descriptor for the MXC overlay framebuffer device. */ -int v4l2_mxc_find_overlay(struct fb_fix_screeninfo *fb_fix, int *fb_fg_fd) -{ - /* Look for overlay (foreground) framebuffer */ - if (!strcmp(fb_fix->id, "DISP3 BG")) { - /* Overlay can be /dev/fb1 or /dev/fb2 */ - if ((*fb_fg_fd = v4l2_mxc_is_overlay("/dev/fb1")) < 0) { - *fb_fg_fd = v4l2_mxc_is_overlay("/dev/fb2"); - log("Overlay framebuffer is /dev/fb2\n"); - } else { - log("Overlay framebuffer is /dev/fb1\n"); - } - - if (*fb_fg_fd < 0) { - log("No overlay framebuffer found.\n"); - return -1; - } - } else if (!strcmp(fb_fix->id, "DISP3 BG - DI1")) { - /* Overlay must be /dev/fb2 */ - if ((*fb_fg_fd = v4l2_mxc_is_overlay("/dev/fb2")) < 0) { - log("No overlay framebuffer found.\n"); - return -1; - } else { - log("Overlay framebuffer is /dev/fb2\n"); - } - } - - return 0; -} - -/* Sets the V4L2 device overlay framebuffer format, dimensions and type */ -int v4l2_overlay_set_framebuffer(int fd, struct fb_fix_screeninfo *fb_fix, - struct fb_var_screeninfo *fb_var, int non_destructive) -{ - struct v4l2_framebuffer framebuffer; - int ret = 0; - - memset(&framebuffer, 0, sizeof(framebuffer)); - - framebuffer.fmt.width = fb_var->xres; - framebuffer.fmt.height = fb_var->yres; - - if (fb_var->bits_per_pixel == 32) { - framebuffer.fmt.pixelformat = IPU_PIX_FMT_BGR32; - framebuffer.fmt.bytesperline = 4 * framebuffer.fmt.width; - log("Framebuffer: BGR32\n"); - } else if (fb_var->bits_per_pixel == 24) { - framebuffer.fmt.pixelformat = IPU_PIX_FMT_BGR24; - framebuffer.fmt.bytesperline = 3 * framebuffer.fmt.width; - log("Framebuffer: BGR24\n"); - } else if (fb_var->bits_per_pixel == 16) { - framebuffer.fmt.pixelformat = IPU_PIX_FMT_RGB565; - framebuffer.fmt.bytesperline = 2 * framebuffer.fmt.width; - log("Framebuffer: RGB565\n"); - } - - /* Draw over the framebuffer, destructive overlay */ - if (!non_destructive) { - framebuffer.flags = V4L2_FBUF_FLAG_PRIMARY; - /* Physical base address of the framebuffer, that is the address of the - * pixel in the top left corner of the framebuffer. Only relevant - * for destructive video overlay. */ - framebuffer.base = (void *)fb_fix->smem_start - + fb_fix->line_length * fb_var->yoffset; - } else { - framebuffer.flags = V4L2_FBUF_FLAG_OVERLAY; - } - - if ((ret = ioctl(fd, VIDIOC_S_FBUF, &framebuffer)) < 0) { - log("set framebuffer failed with %d\n", errno); - return ret; - } - - return ret; -} - -/* Reset V4L2 device cropping rectangle to its default. */ -int v4l2_reset_cropping_rectangle(int fd) -{ - struct v4l2_crop crop; - struct v4l2_cropcap cropcap; - int ret = 0; - - memset(&cropcap, 0, sizeof(cropcap)); - memset(&crop, 0, sizeof(crop)); - - cropcap.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; - if ((ret = ioctl(fd, VIDIOC_CROPCAP, &cropcap)) < 0) { - log("VIDIOC_CROPCAP failed with %d\n", ret); - return ret; - } - - crop.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; - crop.c = cropcap.defrect; - /* Ignore if cropping is not supported (EINVAL). */ - if (((ret = ioctl(fd, VIDIOC_S_CROP, &crop)) < 0) - && errno != EINVAL) { - log("VIDIOC_S_CROP failed with %d\n", ret); - return ret; - } - return ret; -} - -int v4l2_get_cropping_limits(int fd, struct v4l2_rect *limits) -{ - int retval; - struct v4l2_cropcap cropcap; - - cropcap.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; - if ((retval = ioctl(fd, VIDIOC_CROPCAP, &cropcap)) < 0) { - log("VIDIOC_CROPCAP failed: %d", retval); - return retval; - } - - memcpy(limits, &cropcap.bounds, sizeof(cropcap.bounds)); - return 0; -} - -int v4l2_crop_input(int fd, struct v4l2_rect *crop_rectangle) -{ - int retval; - struct v4l2_crop crop; - struct v4l2_rect crop_bounds; - - /* Sanity check */ - retval = v4l2_get_cropping_limits(fd, &crop_bounds); - if (retval < 0) - return retval; - - if (crop_rectangle->left + crop_rectangle->width > crop_bounds.left + crop_bounds.width || - crop_rectangle->top + crop_rectangle->height > crop_bounds.top + crop_bounds.height || - crop_rectangle->width < 8 || crop_rectangle->height < 8) { - log("Invalid input\n"); - return -EINVAL; - } - - crop.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; - memcpy(&crop.c, crop_rectangle, sizeof(crop.c)); - - retval = ioctl(fd, VIDIOC_S_CROP, &crop); - if (retval < 0) { - log("VIDIOC_S_CROP failed: %d", retval); - return retval; - - } - - return 0; -} - -int v4l2_area_zoom(int fd, struct v4l2_rect *crop_rectangle) -{ - int retval; - struct v4l2_rect crop_bounds; - - retval = v4l2_overlay_control(fd, 0); - if (retval < 0) - return retval; - - retval = v4l2_crop_input(fd, crop_rectangle); - if (retval < 0) { - if (retval == -EINVAL) { - v4l2_get_cropping_limits(fd, &crop_bounds); - printf("\nInvalid rectangle!\n"); - printf("Input bounds are:\tTop: %d\tLeft: %d\tWidth: %d\tHeight: %d", - crop_bounds.top, crop_bounds.left, crop_bounds.width, - crop_bounds.height); - printf("\nRequested rectangle: \tTop: %d\tLeft: %d" - "\tWidth: %d\tHeight: %d", - crop_rectangle->top, crop_rectangle->left, - crop_rectangle->width, crop_rectangle->height); - printf("\nValid rectangles are those which:\n" - " Height >= 8\n" - " Width >= 8\n" - " Top + Height < Bound_Top + Bound_Height\n" - " Left + Width < Bound_Left + Bound_Width\n\n"); - } else { - return retval; - } - } - - retval = v4l2_overlay_control(fd, 1); - if (retval < 0) - return retval; - - return 0; -} - -int v4l2_zoom(int fd, int zoom_percentage) -{ - int retval; - float zoom; - struct v4l2_rect crop_rectangle; - struct v4l2_rect crop_bounds; - - /* Get cropping capabilities */ - retval = v4l2_get_cropping_limits(fd, &crop_bounds); - if (retval < 0) - return retval; - - /* Calculate new values */ - zoom = (float)zoom_percentage / 100; - crop_rectangle.height = crop_bounds.height / zoom; - crop_rectangle.width = crop_bounds.width / zoom; - crop_rectangle.left = (crop_bounds.width - crop_rectangle.width) / 2; - crop_rectangle.top = (crop_bounds.height - crop_rectangle.height) / 2; - - return v4l2_area_zoom(fd, &crop_rectangle); -} - -int v4l2_set_control(int fd, int id, int value) -{ - int retval; - struct v4l2_control control; - - control.id = id; - control.value = value; - - retval = ioctl(fd, VIDIOC_S_CTRL, &control); - if (retval < 0) { - log("VIDIOC_S_CTRL failed. Id: %d\tValue: %d\n", id, value); - } - - return retval; -} - -int v4l2_get_control(int fd, int id, int *value) -{ - int retval; - struct v4l2_control control; - - control.id = id; - control.value = 0; - retval = ioctl(fd, VIDIOC_G_CTRL, &control); - if (retval < 0) { - log("VIDIOC_G_CTRL failed. Id: %d\tValue: %d\n", id, *value); - } else { - *value = control.value; - } - - return retval; -} - -int v4l2_set_rotate(int fd, int rotate) -{ - /* This is not supported by V4L2, it's done by the IPUv3 driver */ - return v4l2_set_control(fd, V4L2_CID_MXC_VF_ROT, rotate); -} - -int v4l2_rotate(int fd, int rotate) -{ - int retval; - - /* Stop overlay */ - retval = v4l2_overlay_control(fd, 0); - if (retval < 0) - return retval; - - /* Set new rotation value */ - retval = v4l2_set_rotate(fd, rotate); - if (retval < 0 && errno != EINVAL) - return retval; - - /* Start overlay */ - return v4l2_overlay_control(fd, 1); -} - -int v4l2_set_brightness(int fd, int percentage) -{ - int retval; - int brightness = percentage * BRIGHTNESS_MAX_VALUE / 100; - - retval = v4l2_set_control(fd, V4L2_CID_BRIGHTNESS, brightness); - if (retval < 0) { - log("Set control V4L2_CID_BRIGHTNESS failed. Error: %d\n", retval); - } - - return retval; -} - -int v4l2_get_brightness(int fd, int *percentage) -{ - int retval; - int brightness = 0; - - retval = v4l2_get_control(fd, V4L2_CID_BRIGHTNESS, &brightness); - if (retval < 0) { - log("Get control V4L2_CID_BRIGHTNESS failed. Error: %s\n", strerror(errno)); - } else { - /* (+ 0.5 * BRIGHTNESS_MAX_VALUE) to round integer not using libm */ - *percentage = (brightness * 100 + 0.5 * BRIGHTNESS_MAX_VALUE) / BRIGHTNESS_MAX_VALUE; - } - - return retval; -} - -int v4l2_set_saturation(int fd, int percentage) -{ - int retval; - int saturation = 0; - - /* Valid values are 0, 25, 37, 50, 75, 100 and 150 (hardware limitation) */ - if (percentage < 0 || percentage > 150) { - log("Invalid parameter\n"); - saturation = 50; - } else if (percentage == 0) { - saturation = 0; - } else if (percentage <= 25) { - saturation = 25; - } else if (percentage <= 37) { - saturation = 37; - } else if (percentage <= 50) { - saturation = 50; - } else if (percentage <= 75) { - saturation = 75; - } else if (percentage <= 100) { - saturation = 100; - } else if (percentage <= 150) { - saturation = 150; - } - - retval = v4l2_set_control(fd, V4L2_CID_SATURATION, saturation); - if (retval < 0) { - log("Set control V4L2_CID_SATURATION failed. Error: %s\n", strerror(errno)); - } - - return retval; -} - -int v4l2_get_saturation(int fd, int *percentage) -{ - int retval; - int saturation = 0; - - retval = v4l2_get_control(fd, V4L2_CID_SATURATION, &saturation); - if (retval < 0) { - log("Get control V4L2_CID_SATURATION failed. Error: %s\n", strerror(errno)); - } else { - *percentage = saturation; - } - - return retval; -} - -int v4l2_set_red_balance(int fd, int red) -{ - int retval; - - /* Sanity check */ - if (red > 0xFF) { - log("Invalid parameter\n"); - errno = EINVAL; - return -1; - } - retval = v4l2_set_control(fd, V4L2_CID_RED_BALANCE, red); - if (retval < 0) { - log("Set control V4L2_CID_RED_BALANCE failed. Error: %s\n", strerror(errno)); - } - return retval; -} - -int v4l2_set_blue_balance(int fd, int blue) -{ - int retval; - - /* Sanity check */ - if (blue > 0xFF) { - log("Invalid parameter\n"); - errno = EINVAL; - return -1; - } - - /* Set blue value */ - retval = v4l2_set_control(fd, V4L2_CID_BLUE_BALANCE, blue); - if (retval < 0) { - log("Set control V4L2_CID_BLUE_BALANCE failed. Error: %d\n", retval); - } - - return retval; -} - -int v4l2_set_black_level(int fd, int black) -{ - int retval; - - /* Sanity check */ - if (black > 0xFF) { - log("Invalid parameter\n"); - errno = EINVAL; - return -1; - } - - /* Set black value */ - retval = v4l2_set_control(fd, V4L2_CID_BLACK_LEVEL, black); - if (retval < 0) { - log("Set control V4L2_CID_BLACK_LEVEL failed. Error: %d\n", retval); - } - - return retval; -} - -int v4l2_get_blue_balance(int fd, int *blue) -{ - int retval; - - /* Sanity check */ - if (blue == NULL) { - log("Invalid parameter\n"); - errno = EINVAL; - return -1; - } - - retval = v4l2_get_control(fd, V4L2_CID_BLUE_BALANCE, blue); - if (retval < 0) { - log("Get control V4L2_CID_BLUE_BALANCE failed. Error: %d\n", retval); - } - - return retval; -} - -int v4l2_get_red_balance(int fd, int *red) -{ - int retval; - - /* Sanity check */ - if (red == NULL) { - log("Invalid parameter\n"); - errno = EINVAL; - return -1; - } - - retval = v4l2_get_control(fd, V4L2_CID_RED_BALANCE, red); - if (retval < 0) { - log("Get control V4L2_CID_RED_BALANCE failed. Error: %d\n", retval); - } - - return retval; -} - -int v4l2_get_black_level(int fd, int *black) -{ - int retval; - - /* Sanity check */ - if (black == NULL) { - log("Invalid parameter\n"); - errno = EINVAL; - return -1; - } - - retval = v4l2_get_control(fd, V4L2_CID_BLACK_LEVEL, black); - if (retval < 0) { - log("Get control V4L2_CID_BLACK_LEVEL failed. Error: %d\n", retval); - } - - return retval; -} - -int v4l2_global_alpha_set(int fd, int enable, int percentage) -{ - int retval; - struct mxcfb_gbl_alpha global_alpha; - - global_alpha.enable = enable; - global_alpha.alpha = percentage * GLOBAL_ALPHA_MAX_VALUE / 100; - - retval = ioctl(fd, MXCFB_SET_GBL_ALPHA, &global_alpha); - if (retval < 0) - log("Set global alpha failed MXCFB_SET_GBL_ALPHA. Error: %s\n", - strerror(errno)); - - return retval; -} - -/* Set overlay background framebuffer through sysfs */ -int v4l2_sysfs_set_overlay_bg(char *fb_device) -{ - int ret = 0; - FILE *fp = NULL; - - /* +5 to remove '/dev/' */ - if (!strncmp(fb_device + 5, "fb0", 3)) { - fp = fopen(SYSFS_FSL_DISP_PROPERTY_FB0, "w"); - } else if (!strncmp(fb_device + 5, "fb1", 3)) { - fp = fopen(SYSFS_FSL_DISP_PROPERTY_FB1, "w"); - } - - if (fp) { - fprintf(fp, "%s", "2-layer-fb-bg"); - fclose(fp); - } else { - ret = -1; - } - - return ret; -} - - -void fill_alpha_buffer(char *alpha_buf, int left, int top, int right, - int bottom, char alpha_val, int alpha_fb_w) -{ - char *pPointAlphaValue; - int x, y; - - for (y = top; y < bottom; y++) { - for (x = left; x < right; x++) { - pPointAlphaValue = (char *)(alpha_buf + alpha_fb_w * y + x); - *pPointAlphaValue = alpha_val; - } - } -} - -void fill_alpha_rect(char *alpha_buf, struct v4l2_rect *rect, char alpha_val, int alpha_fb_w) -{ - char *pPointAlphaValue; - int x, y; - - for (y = rect->top; y < rect->height; y++) { - for (x = rect->left; x < rect->width; x++) { - pPointAlphaValue = (char *)(alpha_buf + alpha_fb_w * y + x); - *pPointAlphaValue = alpha_val; - } - } -} - -int v4l2_local_alpha_set(ARGUMENTS * args, int fd_fb_fg, - struct v4l2_rect *alpha_rectangle, int alpha_percentage) -{ - struct fb_var_screeninfo fb_fg_var; - struct mxcfb_loc_alpha l_alpha; - struct v4l2_rect aux_rect; /* Used for setting the default alpha */ - unsigned long loc_alpha_phy_addr0; - unsigned long loc_alpha_phy_addr1; - char *alpha_buf0 = NULL; - char *alpha_buf1 = NULL; - int alpha_buf_size; - int alpha_value = (100 - alpha_percentage) * LOCAL_ALPHA_MIN_VALUE / 100; - - /* Sanity check */ - if (alpha_rectangle->left + alpha_rectangle->width > args->options.width || - alpha_rectangle->top + alpha_rectangle->height > args->options.height) { - log("Invalid alpha_rectangle\n"); - return -1; - } - - /* Switch off overlay */ - v4l2_overlay_control(args->fd_in, 0); - - /* Fetch current fb var info */ - if (v4l2_fb_get_vinfo(fd_fb_fg, &fb_fg_var) < 0) { - log("Failed get varinfo %s\n", strerror(errno)); - close(fd_fb_fg); - return -1; - } - - /* Set dimensions */ - fb_fg_var.xres = args->options.width; - fb_fg_var.yres = args->options.height; - fb_fg_var.xres_virtual = args->options.width; - fb_fg_var.yres_virtual = args->options.height * 2; - - if (v4l2_fb_put_vinfo(fd_fb_fg, &fb_fg_var) < 0) { - log("Failed get varinfo %s\n", strerror(errno)); - close(fd_fb_fg); - return -1; - } - - /* Assure we have the correct var info */ - if (v4l2_fb_get_vinfo(fd_fb_fg, &fb_fg_var) < 0) { - log("Failed get varinfo %s\n", strerror(errno)); - close(fd_fb_fg); - return -1; - } - - /* Enable local alpha */ - memset(&l_alpha, 0, sizeof(struct mxcfb_loc_alpha)); - l_alpha.enable = 1; - l_alpha.alpha_phy_addr0 = 0; - l_alpha.alpha_phy_addr1 = 0; - l_alpha.alpha_in_pixel = 0; - - if (ioctl(fd_fb_fg, MXCFB_SET_LOC_ALPHA, &l_alpha) < 0) { - log("Set local alpha failed: %s\n", strerror(errno)); - close(fd_fb_fg); - return -1; - } - - /* mmap the memory */ - loc_alpha_phy_addr0 = (unsigned long)(l_alpha.alpha_phy_addr0); - loc_alpha_phy_addr1 = (unsigned long)(l_alpha.alpha_phy_addr1); - - alpha_buf_size = fb_fg_var.xres * fb_fg_var.yres; - - alpha_buf0 = (char *)mmap(0, alpha_buf_size, PROT_READ | PROT_WRITE, - MAP_SHARED, fd_fb_fg, loc_alpha_phy_addr0); - if ((int)alpha_buf0 == -1) { - log("\nError: failed to map alpha buffer 0 to memory: %s\n", strerror(errno)); - close(fd_fb_fg); - return -1; - } - - alpha_buf1 = (char *)mmap(0, alpha_buf_size, PROT_READ | PROT_WRITE, - MAP_SHARED, fd_fb_fg, loc_alpha_phy_addr1); - if ((int)alpha_buf1 == -1) { - log("\nError: failed to map alpha buffer 1 to memory: %s\n", strerror(errno)); - munmap((void *)alpha_buf0, alpha_buf_size); - close(fd_fb_fg); - return -1; - } - - /* Switch on overlay */ - v4l2_overlay_control(args->fd_in, 1); - - /* Initialize the rectangle */ - aux_rect.top = 0; - aux_rect.left = 0; - aux_rect.width = args->options.width; - aux_rect.height = args->options.height; - - fill_alpha_rect(alpha_buf0, &aux_rect, 0xFF, args->options.width); - - if (ioctl(fd_fb_fg, MXCFB_SET_LOC_ALP_BUF, &loc_alpha_phy_addr0) < 0) { - printf("Set local alpha buf failed\n"); - close(fd_fb_fg); - return -1; - } - - /* Fill and display the rectangle */ - fill_alpha_rect(alpha_buf0, alpha_rectangle, alpha_value, args->options.width); - - if (ioctl(fd_fb_fg, MXCFB_SET_LOC_ALP_BUF, &loc_alpha_phy_addr0) < 0) { - printf("Set local alpha buf failed\n"); - close(fd_fb_fg); - return -1; - } - - return 0; -} diff --git a/meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_defs.h b/meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_defs.h deleted file mode 100644 index cb0625a6a..000000000 --- a/meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_defs.h +++ /dev/null @@ -1,183 +0,0 @@ -/* - * v4l2_defs.h - * - * Copyright (C) 2012 by Digi International Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published by - * the Free Software Foundation. - * - * Description: V4L2 definitions header file. - * - * From linux/ipu.h - * - */ - -#ifndef V4L2_DEFS_H_ -#define V4L2_DEFS_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,37) -#include -#else -#include -#endif - -#define fourcc(a,b,c,d)\ - (((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24)) - -/*! - * @name IPU Pixel Formats - * - * Pixel formats are defined with ASCII FOURCC code. The pixel format codes are - * the same used by V4L2 API. - */ - -/*! @{ */ -/*! @name Generic or Raw Data Formats */ -/*! @{ */ -#define IPU_PIX_FMT_GENERIC fourcc('I', 'P', 'U', '0') /*!< IPU Generic Data */ -#define IPU_PIX_FMT_GENERIC_32 fourcc('I', 'P', 'U', '1') /*!< IPU Generic Data */ -#define IPU_PIX_FMT_LVDS666 fourcc('L', 'V', 'D', '6') /*!< IPU Generic Data */ -#define IPU_PIX_FMT_LVDS888 fourcc('L', 'V', 'D', '8') /*!< IPU Generic Data */ -/*! @} */ -/*! @name RGB Formats */ -/*! @{ */ -#define IPU_PIX_FMT_RGB332 fourcc('R', 'G', 'B', '1') /*!< 8 RGB-3-3-2 */ -#define IPU_PIX_FMT_RGB555 fourcc('R', 'G', 'B', 'O') /*!< 16 RGB-5-5-5 */ -#define IPU_PIX_FMT_RGB565 fourcc('R', 'G', 'B', 'P') /*!< 1 6 RGB-5-6-5 */ -#define IPU_PIX_FMT_RGB666 fourcc('R', 'G', 'B', '6') /*!< 18 RGB-6-6-6 */ -#define IPU_PIX_FMT_BGR666 fourcc('B', 'G', 'R', '6') /*!< 18 BGR-6-6-6 */ -#define IPU_PIX_FMT_BGR24 fourcc('B', 'G', 'R', '3') /*!< 24 BGR-8-8-8 */ -#define IPU_PIX_FMT_RGB24 fourcc('R', 'G', 'B', '3') /*!< 24 RGB-8-8-8 */ -#define IPU_PIX_FMT_GBR24 fourcc('G', 'B', 'R', '3') /*!< 24 GBR-8-8-8 */ -#define IPU_PIX_FMT_BGR32 fourcc('B', 'G', 'R', '4') /*!< 32 BGR-8-8-8-8 */ -#define IPU_PIX_FMT_BGRA32 fourcc('B', 'G', 'R', 'A') /*!< 32 BGR-8-8-8-8 */ -#define IPU_PIX_FMT_RGB32 fourcc('R', 'G', 'B', '4') /*!< 32 RGB-8-8-8-8 */ -#define IPU_PIX_FMT_RGBA32 fourcc('R', 'G', 'B', 'A') /*!< 32 RGB-8-8-8-8 */ -#define IPU_PIX_FMT_ABGR32 fourcc('A', 'B', 'G', 'R') /*!< 32 ABGR-8-8-8-8 */ -/*! @} */ -/*! @name YUV Interleaved Formats */ -/*! @{ */ -#define IPU_PIX_FMT_YUYV fourcc('Y', 'U', 'Y', 'V') /*!< 16 YUV 4:2:2 */ -#define IPU_PIX_FMT_UYVY fourcc('U', 'Y', 'V', 'Y') /*!< 16 YUV 4:2:2 */ -#define IPU_PIX_FMT_YVYU fourcc('Y', 'V', 'Y', 'U') /*!< 16 YVYU 4:2:2 */ -#define IPU_PIX_FMT_VYUY fourcc('V', 'Y', 'U', 'Y') /*!< 16 VYYU 4:2:2 */ -#define IPU_PIX_FMT_Y41P fourcc('Y', '4', '1', 'P') /*!< 12 YUV 4:1:1 */ -#define IPU_PIX_FMT_YUV444 fourcc('Y', '4', '4', '4') /*!< 24 YUV 4:4:4 */ -#define IPU_PIX_FMT_VYU444 fourcc('V', '4', '4', '4') /*!< 24 VYU 4:4:4 */ -/* two planes -- one Y, one Cb + Cr interleaved */ -#define IPU_PIX_FMT_NV12 fourcc('N', 'V', '1', '2') /* 12 Y/CbCr 4:2:0 */ -/*! @} */ -/*! @name YUV Planar Formats */ -/*! @{ */ -#define IPU_PIX_FMT_GREY fourcc('G', 'R', 'E', 'Y') /*!< 8 Greyscale */ -#define IPU_PIX_FMT_YVU410P fourcc('Y', 'V', 'U', '9') /*!< 9 YVU 4:1:0 */ -#define IPU_PIX_FMT_YUV410P fourcc('Y', 'U', 'V', '9') /*!< 9 YUV 4:1:0 */ -#define IPU_PIX_FMT_YVU420P fourcc('Y', 'V', '1', '2') /*!< 12 YVU 4:2:0 */ -#define IPU_PIX_FMT_YUV420P fourcc('I', '4', '2', '0') /*!< 12 YUV 4:2:0 */ -#define IPU_PIX_FMT_YUV420P2 fourcc('Y', 'U', '1', '2') /*!< 12 YUV 4:2:0 */ -#define IPU_PIX_FMT_YVU422P fourcc('Y', 'V', '1', '6') /*!< 16 YVU 4:2:2 */ -#define IPU_PIX_FMT_YUV422P fourcc('4', '2', '2', 'P') /*!< 16 YUV 4:2:2 */ -/*! @} */ - -#define V4L2_CID_MXC_FLASH (V4L2_CID_PRIVATE_BASE + 1) -#define V4L2_CID_MXC_VF_ROT (V4L2_CID_PRIVATE_BASE + 2) - -extern int verbose; - -#define TRUE 1 -#define FALSE 0 - -#define SYSFS_FSL_DISP_PROPERTY_FB0 "/sys/class/graphics/fb0/fsl_disp_property" -#define SYSFS_FSL_DISP_PROPERTY_FB1 "/sys/class/graphics/fb1/fsl_disp_property" - -#define log( fmt, arg...) \ - do { \ - char msg[256]; \ - if(verbose){ \ - snprintf(msg,sizeof(msg),"[%s:%d]"fmt , __FUNCTION__, \ - __LINE__, ## arg); \ - printf("%s",msg);} \ - } while (0) - -typedef struct { - int format; - int top; - int left; - int height; - int width; - int capturemode; - int non_destructive; - int camera_framerate; -} OPTIONS; - -typedef struct { - int fd_in; - int fd_out; - char v4l2_device[13]; /* /dev/videoNN + '\0' */ - char fb_device[9]; /* /dev/fbN + '\0' */ - OPTIONS options; -} ARGUMENTS; - -int v4l2_get_overlay_bg(char *fb_device); -int v4l2_overlay_control(int fd_overlay, int start); -char *v4l2_fmt_str(int pixelformat); -int v4l2_is_capability_supported(int fd, int capability); -int v4l2_is_video_std_supported(int fd, int standard); -int v4l2_is_format_supported(int fd, int format); -int v4l2_check_frame_rate(int fd, int framerate); -int v4l2_set_stream_parms(int fd, int framerate); -int v4l2_check_output(int fd, char *name); -int v4l2_set_output(int fd, struct fb_fix_screeninfo *fb_fix); -int v4l2_set_frame_rate(int fd, int framerate); -int v4l2_check_frame_rate(int fd, int framerate); -int v4l2_set_format_overlay(int fd, int top, int left, int height, int width); -int v4l2_set_format_capture(int fd, int pixelformat, int height, int width); -int v4l2_fb_get_info(char *fb_device, struct fb_fix_screeninfo *fb_fix, - struct fb_var_screeninfo *fb_var); -void v4l2_ident_outputs(int fd); -int v4l2_mxc_find_overlay(struct fb_fix_screeninfo *fb_fix, int *fb_fg_fd); -int v4l2_overlay_set_framebuffer(int fd, struct fb_fix_screeninfo *fb_fix, - struct fb_var_screeninfo *fb_var, int non_destructive); -int v4l2_reset_cropping_rectangle(int fd); -int v4l2_fb_blank(int fd); -int v4l2_fb_unblank(int fd); -int v4l2_zoom(int fd, int zoom); -int v4l2_set_rotate(int fd, int rotate); -int v4l2_rotate(int fd, int rotate); -int v4l2_crop_input(int fd, struct v4l2_rect *crop_rectangle); -int v4l2_get_cropping_limits(int fd, struct v4l2_rect *limits); -int v4l2_area_zoom(int fd, struct v4l2_rect *crop_rectangle); -int v4l2_set_brightness(int fd, int brightness); -int v4l2_get_brightness(int fd, int *brightness); -int v4l2_set_saturation(int fd, int saturation); -int v4l2_get_saturation(int fd, int *saturation); -int v4l2_set_red_balance(int fd, int red); -int v4l2_set_blue_balance(int fd, int blue); -int v4l2_set_black_level(int fd, int black); -int v4l2_get_red_balance(int fd, int *red); -int v4l2_get_blue_balance(int fd, int *blue); -int v4l2_get_black_level(int fd, int *black); -int v4l2_global_alpha_set(int fd, int enable, int value); -int v4l2_sysfs_set_overlay_bg(char *fb_device); -int v4l2_local_alpha_set(ARGUMENTS * args, int fd_fb_fg, struct v4l2_rect *alpha_rectangle, - int alpha_percentage); - -#endif /* V4L2_DEFS_H_ */ diff --git a/meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_preview_test.c b/meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_preview_test.c deleted file mode 100644 index 64a7ee596..000000000 --- a/meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_preview_test.c +++ /dev/null @@ -1,505 +0,0 @@ -/* - * v4l2_preview_test.c - * - * Copyright (C) 2012 by Digi International Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published by - * the Free Software Foundation. - * - * Description: V4L2 preview test application. - * - * Video overlay, framebuffer overlay or previewing stores images directly into - * the video memory of the graphics card. Video overlays are accessible through - * /dev/video after a VIDIOC_S_FMT to overlay (the default for /dev/video is - * video capture). - * - * V4L2 API @ http://v4l2spec.bytesex.org/ - * - */ -#include -#include - -#include "v4l2_defs.h" - -int verbose = 0; -int fb_fg_fd = -1; -static int should_stop = 0; - -static void signal_handler(int signum, siginfo_t * info, void *myact) -{ - switch (signum) { - case SIGHUP: - case SIGTERM: - case SIGINT: - should_stop = TRUE; - /* FALLTHROUGH */ - default: - log("signal %d caught\n", signum); - break; - } -} - -/** - * Prints online help - * - * @fd file to print on - */ -static void printUsage(FILE * fd) -{ - fprintf(fd, "V4L2 preview test application.\n\n" - "Usage: v4l_preview_test -d -o -h " - "-w -t -l [-r] [-v] [-?]\n\n" - " -d V4L2 capture device, by default /dev/video0\n" - " -o V4L2 output (framebuffer) device, by default /dev/fb0\n" - " -h Video height in pixels\n" - " -w Video width in pixels\n" - " -t Video top offset in pixels\n" - " -l Video left offset in pixels\n" - " -x Non destructive overlay (do not overwrite framebuffer)\n" - " Setting '-x' discards the output device option '-o' and\n" - " uses the overlay background framebuffer.\n" - " -r RGB565 (default is UYVY)\n" - " -u YUYV (default is UYVY)\n" - " -c capture mode (default is 0)\n" - " -v Verbose mode\n" - " -? This help\n\n"); -} - -static void *v4l2_camera_thread(void *pargs) -{ - struct fb_fix_screeninfo fb_fix; - struct fb_var_screeninfo fb_var; - ARGUMENTS *args = pargs; - - /* Check overlay is supported */ - if (!v4l2_is_capability_supported(args->fd_in, V4L2_CAP_VIDEO_OVERLAY)) { - printf("Overlay not supported\n"); - return ((void *)-EINVAL); - } - - /* Check requested image format is supported by capture device */ - if (!v4l2_is_format_supported(args->fd_in, args->options.format)) { - printf("Requested format not supported.\n"); - return ((void *)-EINVAL); - } - - /* Obtain framebuffer parameters */ - if ((args->fd_out = v4l2_fb_get_info(args->fb_device, &fb_fix, &fb_var)) < 0) { - printf("Unable to open %s: %s\n", args->fb_device, strerror(errno)); - exit(-1); - } - - /* Set video output */ - if (v4l2_set_output(args->fd_in, &fb_fix) < 0) { - printf("\nUnable to set current video output.\n"); - exit(-1); - } - - /* Restore default cropping - no zoom */ - v4l2_reset_cropping_rectangle(args->fd_in); - - /* Reset rotation to ROTATE_NONE */ - v4l2_set_rotate(args->fd_in, 0); - - /* Set capture mode */ - v4l2_set_capture_mode(args->fd_in, args->options.capturemode); - - /* Set size in overlay */ - v4l2_set_format_overlay(args->fd_in, - args->options.top, args->options.left, - args->options.height, args->options.width); - - /* Now the overlay functionality is available */ - - /* Obtain overlay framebuffer's fd */ - v4l2_mxc_find_overlay(&fb_fix, &fb_fg_fd); - - /* Draws over the fb (destructive) and sets image format */ - v4l2_overlay_set_framebuffer(args->fd_in, &fb_fix, &fb_var, - args->options.non_destructive); - - v4l2_overlay_control(args->fd_in, 1); - - while (should_stop != TRUE) - sleep(1); - - v4l2_overlay_control(args->fd_in, 0); - - close(args->fd_in); - close(args->fd_out); - if (fb_fg_fd > 0) - close(fb_fg_fd); - - return NULL; -} - -static void v4l2_display_menu(int non_destructive) -{ - printf("\t[h]display the operation Help\n"); - printf("\t[x]eXit\n"); - printf("\t[r]Rotate input\n"); - printf("\t[b]adjust Brightness\n"); - printf("\t[s]adjust Saturation\n"); - printf("\t[c]adjust Color balance\n"); - printf("\t[z]automatic Zoom\n"); - printf("\t[a]zoom Area\n"); - if (non_destructive) { - /* These options are only available in non_destructive overlay */ - printf("\t[g]set Global transparency\n"); - printf("\t[l]set Local transparency\n"); - } - printf("\nChoose option: "); -} - -static int cmd_rotate(int fd) -{ - unsigned int rotate = 0; - - printf("Rotation options:\n"); - printf("\t0 - No rotation\n"); - printf("\t1 - Vertical flip\n"); - printf("\t2 - Horizontal flip\n"); - printf("\t3 - Rotate 180 degree\n"); - printf("\t4 - Rotate 90 degree\n"); - printf("\t5 - Rotate 90 degree right and vertical flip\n"); - printf("\t6 - Rotate 90 degree right and horizontal flip\n"); - printf("\t7 - Rotate 90 degree left\n"); - printf("Choose rotation: "); - scanf("%u", &rotate); - if (rotate > 7) { - printf("Invalid value\n"); - return -1; - } - return v4l2_rotate(fd, rotate); -} - -static int cmd_brightness(int fd) -{ - int brightness = 0; - int ret = -1; - - /* Read current brightness value */ - v4l2_get_brightness(fd, &brightness); - printf("Enter brightness [0-100%%] (current: %u%%): ", brightness); - if ((scanf("%u", &brightness)) != 1 || should_stop) { - return ret; - } - - if (brightness > 100 || brightness < 0) { - printf("Brightness value [%d] out of range.\n", brightness); - } else { - ret = v4l2_set_brightness(fd, brightness); - } - - return ret; -} - -static int cmd_saturation(int fd) -{ - int saturation; - int ret = -1; - - /* Read current saturation value */ - v4l2_get_saturation(fd, &saturation); - printf("Enter saturation (valid values are 0, 25, 37, 50, 75, 100 and 150) [0-150%%] (current: %u%%): ", saturation); - if (scanf("%u", &saturation) != 1 || should_stop) - return ret; - - if (saturation > 150 || saturation < 0) { - printf("Saturation value [%d] out of range.\n", saturation); - } else { - ret = v4l2_set_saturation(fd, saturation); - } - return ret; -} - -static int cmd_zoom(int fd) -{ - int zoom; - int ret = -1; - - printf("Enter zooming percentage [100 - 300]%%: "); - if ((scanf("%i", &zoom)) != 1) - return ret; - - if (zoom < 100 || zoom > 300) { - printf("Zoom value [%d] out of range.\n", zoom); - } else { - ret = v4l2_zoom(fd, zoom); - } - return ret; -} - -static int cmd_area_zoom(int fd) -{ - struct v4l2_rect zoom_rectangle; - int ret = -1; - - printf("Enter rectangle's values (top, left, width [>=8], height [>=8]): "); - if ((scanf("%d,%d,%d,%d", &zoom_rectangle.top, &zoom_rectangle.left, - &zoom_rectangle.width, &zoom_rectangle.height)) != 4 || should_stop) { - printf("Enter four parameters\n"); - return ret; - } else { - ret = v4l2_area_zoom(fd, &zoom_rectangle); - } - return ret; -} - -static int cmd_color_balance(int fd, char cmd) -{ - int ret = -1; - int red, blue, black; - - red = blue = black = 0; - switch (cmd) { - case 'r': - if (v4l2_get_red_balance(fd, &red) < 0) { - printf("\n[ERROR] Unable to get Red balance\n\n"); - } else { - printf("Enter Red balance value (current: %d): ", red); - scanf("%u", &red); - ret = v4l2_set_red_balance(fd, red); - } - break; - case 'b': - if (v4l2_get_blue_balance(fd, &blue) < 0) { - printf("\n[ERROR] Unable to get Blue balance\n\n"); - } else { - printf("Enter Blue balance value (current: %d): ", blue); - scanf("%u", &blue); - ret = v4l2_set_blue_balance(fd, blue); - } - break; - case 'w': - printf("\nNot implemented (yet...)\n\n"); - break; - case 'l': - if (v4l2_get_black_level(fd, &black) < 0) { - printf("\n[ERROR] Unable to get Black level\n\n"); - } else { - printf("Enter Black level value (current: %d): ", black); - scanf("%u", &black); - ret = v4l2_set_black_level(fd, black); - } - break; - default: - break; - } - - return ret; -} - -static int cmd_global_alpha(int fd) -{ - int ret = -1; - int alpha_value; - - printf("Enter alpha_value global transparency [0-100%%]: "); - if (scanf("%d", &alpha_value) != 1 || should_stop) - return ret; - if (alpha_value > 100 || alpha_value < 0) { - printf("Alpha value [%d] out of range.\n", alpha_value); - return ret; - } - ret = v4l2_global_alpha_set(fd, 1, alpha_value); - return ret; -} - -static int cmd_local_alpha(ARGUMENTS * args) -{ - int ret = -1; - struct v4l2_rect alpha_rectangle; - int alpha_value; - - printf("Enter rectangle's values (top, left, width, height): "); - if ((scanf("%d,%d,%d,%d", &alpha_rectangle.top, &alpha_rectangle.left, - &alpha_rectangle.width, &alpha_rectangle.height)) != 4 || should_stop) { - printf("Enter four parameters\n"); - return ret; - } else { - printf("Enter rectangle's transparency [0-100%%]: "); - if (scanf("%d", &alpha_value) != 1 || should_stop) - return ret; - if (alpha_value > 100 || alpha_value < 0) { - printf("Alpha value [%d] out of range.\n", alpha_value); - return ret; - } - ret = v4l2_local_alpha_set(args, fb_fg_fd, &alpha_rectangle, alpha_value); - } - return ret; -} - -static void display_color_balance_menu(void) -{ - printf("Color balance:\n"); - printf("\t[r]adjust Red balance\n"); - printf("\t[b]adjust Blue balance\n"); - printf("\t[w]adjust White balance\n"); - printf("\t[l]adjust bLack level\n"); - printf("Choose option: "); -} - -int main(int argc, char **argv) -{ - int opt; - int retval = 0; - ARGUMENTS args; - pthread_t v4l2_camera_th; - int ret = 0; - char cmd[64] = ""; - struct sigaction act; - char fb_device_flag = 0; /* fb_device set in command line */ - - /* Signal handling */ - memset(&act, 0, sizeof(struct sigaction)); - sigemptyset(&act.sa_mask); - act.sa_flags = SA_SIGINFO; - act.sa_sigaction = signal_handler; - - if ((ret = sigaction(SIGINT, &act, NULL)) < 0) { - log("Signal installation error: %d\n", SIGINT); - return -1; - } - - /* Initialize options */ - memset(&args, 0, sizeof(args)); - args.options.width = 640; - args.options.height = 480; - args.options.format = V4L2_PIX_FMT_UYVY; - args.options.capturemode = 0; - strcpy(args.fb_device, "/dev/fb0"); - strcpy(args.v4l2_device, "/dev/video0"); - - /* Input processing */ - while ((opt = getopt(argc, argv, "w:d:h:l:t:o:xc:vru?")) != -1) { - switch (opt) { - case '?': - printUsage(stderr); - return 1; - case 'd': - strncpy(args.v4l2_device, optarg, sizeof(args.v4l2_device) - 1); - args.v4l2_device[sizeof(args.v4l2_device) - 1] = '\0'; - break; - case 'w': - args.options.width = atoi(optarg); - break; - case 't': - args.options.top = atoi(optarg); - break; - case 'l': - args.options.left = atoi(optarg); - break; - case 'h': - args.options.height = atoi(optarg); - break; - case 'o': - strncpy(args.fb_device, optarg, sizeof(args.fb_device) - 1); - args.fb_device[sizeof(args.fb_device) - 1] = '\0'; - fb_device_flag = 1; - break; - case 'r': - args.options.format = V4L2_PIX_FMT_RGB565; - break; - case 'u': - args.options.format = V4L2_PIX_FMT_YUYV; - break; - case 'x': - args.options.non_destructive = 1; - break; - case 'c': - args.options.capturemode = atoi(optarg); - break; - case 'v': - verbose = 1; - break; - } - } - - /* Input validation */ - if (args.options.height == 0 || args.options.width == 0) { - printf("Invalid input: Display height and width cannot be zero.\n"); - exit(-EINVAL); - } - - if (args.options.non_destructive) { - if (fb_device_flag) { - printf("\n[WARNING] The application will discard '-o' option and use" - " the overlay background framebuffer device.\n"); - } - if (v4l2_get_overlay_bg(args.fb_device) < 0) { - printf("Unable to find overlay background framebuffer device\n"); - exit(-1); - } - } - - printf("\nVideo height %d width %d top %d left %d\n\n", - args.options.height, args.options.width, args.options.top, args.options.left); - - /* Open input device */ - if ((args.fd_in = open(args.v4l2_device, O_RDWR, 0)) < 0) { - printf("Unable to open %s: %s\n", args.v4l2_device, strerror(errno)); - exit(-1); - } - - log("Opened %s\n", args.v4l2_device); - log("V4L2 preview test application started.\n"); - - if (pthread_create(&v4l2_camera_th, NULL, v4l2_camera_thread, (void *)&args)) { - exit(-1); - } - - while (should_stop != TRUE) { - v4l2_display_menu(args.options.non_destructive); - cmd[0] = ' '; - errno = 0; - scanf("%s", cmd); - switch (cmd[0]) { - case 'x': /* Exit */ - should_stop = TRUE; - break; - case 'h': /* Help */ - /* Nothing to do, as the help is shown in each iteration */ - break; - case 'r': - cmd_rotate(args.fd_in); - break; - case 'b': - cmd_brightness(args.fd_in); - break; - case 's': - cmd_saturation(args.fd_in); - break; - case 'z': - cmd_zoom(args.fd_in); - break; - case 'a': - cmd_area_zoom(args.fd_in); - break; - case 'c': - display_color_balance_menu(); - scanf("%s", cmd); - cmd_color_balance(args.fd_in, cmd[0]); - break; - case 'g': - if (args.options.non_destructive) - cmd_global_alpha(args.fd_out); - break; - case 'l': - if (args.options.non_destructive) - cmd_local_alpha(&args); - break; - default: - break; - } - } - - if (pthread_join(v4l2_camera_th, NULL)) { - exit(-1); - } - - log("V4L2 preview test application finished.\n"); - return retval; -} diff --git a/meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_still.c b/meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_still.c deleted file mode 100644 index d33fba0cc..000000000 --- a/meta-digi-dey/recipes-digi/dey-examples/files/v4l2_test/v4l2_still.c +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright 2004-2010 Freescale Semiconductor, Inc. All rights reserved. - * Copyright 2010 Digi International. All rights reserved. - */ - -/* - * The code contained herein is licensed under the GNU General Public - * License. You may obtain a copy of the GNU General Public License - * Version 2 or later at the following locations: - * - * http://www.opensource.org/licenses/gpl-license.html - * http://www.gnu.org/copyleft/gpl.html - */ - -/* - * @file v4l2_still.c - * - * @brief Video For Linux 2 driver test application - * - */ - -#ifdef __cplusplus -extern "C" { -#endif - - /*======================================================================= - INCLUDE FILES - =======================================================================*/ - /* Standard Include Files */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "v4l2_defs.h" - -#define ipu_fourcc(a,b,c,d)\ - (((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24)) - -#define IPU_PIX_FMT_YUYV ipu_fourcc('Y','U','Y','V') /*!< 16 YUV 4:2:2 */ -#define IPU_PIX_FMT_UYVY ipu_fourcc('U','Y','V','Y') /*!< 16 YUV 4:2:2 */ -#define IPU_PIX_FMT_NV12 ipu_fourcc('N','V','1','2') /* 12 Y/CbCr 4:2:0 */ -#define IPU_PIX_FMT_YUV420P ipu_fourcc('I','4','2','0') /*!< 12 YUV 4:2:0 */ -#define IPU_PIX_FMT_YUV420P2 ipu_fourcc('Y','U','1','2') /*!< 12 YUV 4:2:0 */ -#define IPU_PIX_FMT_YUV422P ipu_fourcc('4','2','2','P') /*!< 16 YUV 4:2:2 */ -#define IPU_PIX_FMT_YUV444 ipu_fourcc('Y','4','4','4') /*!< 24 YUV 4:4:4 */ -#define IPU_PIX_FMT_RGB565 ipu_fourcc('R','G','B','P') /*!< 16 RGB-5-6-5 */ -#define IPU_PIX_FMT_BGR24 ipu_fourcc('B','G','R','3') /*!< 24 BGR-8-8-8 */ -#define IPU_PIX_FMT_RGB24 ipu_fourcc('R','G','B','3') /*!< 24 RGB-8-8-8 */ -#define IPU_PIX_FMT_BGR32 ipu_fourcc('B','G','R','4') /*!< 32 BGR-8-8-8-8 */ -#define IPU_PIX_FMT_BGRA32 ipu_fourcc('B','G','R','A') /*!< 32 BGR-8-8-8-8 */ -#define IPU_PIX_FMT_RGB32 ipu_fourcc('R','G','B','4') /*!< 32 RGB-8-8-8-8 */ -#define IPU_PIX_FMT_RGBA32 ipu_fourcc('R','G','B','A') /*!< 32 RGB-8-8-8-8 */ -#define IPU_PIX_FMT_ABGR32 ipu_fourcc('A','B','G','R') /*!< 32 ABGR-8-8-8-8 */ - - static int g_convert = 0; - static int g_width = 640; - static int g_height = 480; - static int g_top = 0; - static int g_left = 0; - static unsigned long g_pixelformat = IPU_PIX_FMT_UYVY; - static int g_bpp = 16; - static int g_camera_framerate = 30; - static int g_capture_mode = 0; - static char g_v4l_device[100] = "/dev/video0"; - - void usage(void) - { - printf("Usage: v4l2_still [-w width] [-h height] [-t top] [-l left] [-f pixformat] [-c] [-m] [-fr]\n" - "-w Image width, 640 by default\n" - "-h Image height, 480 by default\n" - "-t Image top(crop from the source frame), 0 by default\n" - "-l Image left(crop from the source frame), 0 by default\n" - "-f Image pixel format, YUV420, YUV422P, YUYV, UYVY ((default) or YUV444\n" - "-c Convert to YUV420P. This option is valid for interleaved pixel\n" - " formats only - YUYV, UYVY, YUV444\n" - "-m Capture mode, 0-low resolution(default), 1-high resolution \n" - "-d Camera select, /dev/video0, /dev/video1 \n" - "-fr Capture frame rate, 30fps by default\n" - "The output is saved in ./still.uyvy\n" - ); - } - - /* Convert to YUV420 format */ - void fmt_convert(char *dest, char *src, struct v4l2_format *fmt) - { - int row, col, pos = 0; - int bpp, yoff, uoff, voff; - - if (fmt->fmt.pix.pixelformat == IPU_PIX_FMT_YUYV) { - bpp = 2; - yoff = 0; - uoff = 1; - voff = 3; - } - else if (fmt->fmt.pix.pixelformat == IPU_PIX_FMT_UYVY) { - bpp = 2; - yoff = 1; - uoff = 0; - voff = 2; - } - else { /* YUV444 */ - bpp = 4; - yoff = 0; - uoff = 1; - voff = 2; - } - - /* Copy Y */ - for (row = 0; row < fmt->fmt.pix.height; row++) - for (col = 0; col < fmt->fmt.pix.width; col++) - dest[pos++] = src[row * fmt->fmt.pix.bytesperline + col * bpp + yoff]; - - /* Copy U */ - for (row = 0; row < fmt->fmt.pix.height; row += 2) { - for (col = 0; col < fmt->fmt.pix.width; col += 2) - dest[pos++] = src[row * fmt->fmt.pix.bytesperline + col * bpp + uoff]; - } - - /* Copy V */ - for (row = 0; row < fmt->fmt.pix.height; row += 2) { - for (col = 0; col < fmt->fmt.pix.width; col += 2) - dest[pos++] = src[row * fmt->fmt.pix.bytesperline + col * bpp + voff]; - } - } - - int bytes_per_pixel(int fmt) - { - switch (fmt) { - case IPU_PIX_FMT_YUV420P: - case IPU_PIX_FMT_YUV422P: - case IPU_PIX_FMT_NV12: - return 1; - break; - case IPU_PIX_FMT_RGB565: - case IPU_PIX_FMT_YUYV: - case IPU_PIX_FMT_UYVY: - return 2; - break; - case IPU_PIX_FMT_BGR24: - case IPU_PIX_FMT_RGB24: - return 3; - break; - case IPU_PIX_FMT_BGR32: - case IPU_PIX_FMT_BGRA32: - case IPU_PIX_FMT_RGB32: - case IPU_PIX_FMT_RGBA32: - case IPU_PIX_FMT_ABGR32: - return 4; - break; - default: - return 1; - break; - } - return 0; - } - - int v4l_capture_setup(int * fd_v4l) - { - struct v4l2_streamparm parm; - struct v4l2_format fmt; - struct v4l2_crop crop; - int ret = 0; - - if ((*fd_v4l = open(g_v4l_device, O_RDWR, 0)) < 0) - { - printf("Unable to open %s\n", g_v4l_device); - return -1; - } - - parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - parm.parm.capture.timeperframe.numerator = 1; - parm.parm.capture.timeperframe.denominator = g_camera_framerate; - parm.parm.capture.capturemode = g_capture_mode; - - if ((ret = ioctl(*fd_v4l, VIDIOC_S_PARM, &parm)) < 0) - { - printf("VIDIOC_S_PARM failed\n"); - return ret; - } - - crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - crop.c.left = g_left; - crop.c.top = g_top; - crop.c.width = g_width; - crop.c.height = g_height; - if ((ret = ioctl(*fd_v4l, VIDIOC_S_CROP, &crop)) < 0) - { - printf("set cropping failed\n"); - return ret; - } - - memset(&fmt, 0, sizeof(fmt)); - fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - fmt.fmt.pix.pixelformat = g_pixelformat; - fmt.fmt.pix.width = g_width; - fmt.fmt.pix.height = g_height; - fmt.fmt.pix.sizeimage = fmt.fmt.pix.width * fmt.fmt.pix.height * g_bpp / 8; - fmt.fmt.pix.bytesperline = g_width * bytes_per_pixel(g_pixelformat); - - if ((ret = ioctl(*fd_v4l, VIDIOC_S_FMT, &fmt)) < 0) - { - printf("set format failed\n"); - return ret; - } - - return ret; - } - - int v4l_capture_test(int fd_v4l) - { - struct v4l2_format fmt; - int fd_still = 0, ret = 0; - char *buf1, *buf2; - char still_file[100] = "./still.uyvy"; - int bytes = 0; - - if ((fd_still = open(still_file, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) < 0) - { - printf("Unable to create y frame recording file\n"); - return -1; - } - - fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if ((ret = ioctl(fd_v4l, VIDIOC_G_FMT, &fmt)) < 0) { - printf("get format failed\n"); - goto exit1; - } else { - printf("\t Width = %d\n", fmt.fmt.pix.width); - printf("\t Height = %d\n", fmt.fmt.pix.height); - printf("\t Image size = %d\n", fmt.fmt.pix.sizeimage); - printf("\t Pixel format = %c%c%c%c\n", - (char)(fmt.fmt.pix.pixelformat & 0xFF), - (char)((fmt.fmt.pix.pixelformat & 0xFF00) >> 8), - (char)((fmt.fmt.pix.pixelformat & 0xFF0000) >> 16), - (char)((fmt.fmt.pix.pixelformat & 0xFF000000) >> 24)); - } - - buf1 = (char *)malloc(fmt.fmt.pix.sizeimage); - buf2 = (char *)malloc(fmt.fmt.pix.sizeimage); - if (!buf1 || !buf2) - goto exit0; - - memset(buf1, 0, fmt.fmt.pix.sizeimage); - memset(buf2, 0, fmt.fmt.pix.sizeimage); - - if ((bytes = read(fd_v4l, buf1, fmt.fmt.pix.sizeimage)) != fmt.fmt.pix.sizeimage) { - printf("v4l2 read error.\n"); - printf("read %d, expected %d.\n",bytes, fmt.fmt.pix.sizeimage); - goto exit0; - } - - if ((g_convert == 1) && (g_pixelformat != IPU_PIX_FMT_YUV422P) - && (g_pixelformat != IPU_PIX_FMT_YUV420P2)) { - fmt_convert(buf2, buf1, &fmt); - if ((write(fd_still, buf2, fmt.fmt.pix.width * fmt.fmt.pix.height * 3 / 2)) < 0) - goto exit0; - } - else - if ((write(fd_still, buf1, fmt.fmt.pix.sizeimage)) < 0) - goto exit0; - -exit0: - free(buf1); - free(buf2); - close(fd_v4l); -exit1: - close(fd_still); - - return ret; - } - - int main(int argc, char **argv) - { - int fd_v4l; - int i; - int ret; - - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-w") == 0) { - if (argv[++i]) - g_width = atoi(argv[i]); - else { - usage(); - return -1; - } - } - else if (strcmp(argv[i], "-h") == 0) { - if (argv[++i]) - g_height = atoi(argv[i]); - else { - usage(); - return -1; - } - } - else if (strcmp(argv[i], "-t") == 0) { - if (argv[++i]) - g_top = atoi(argv[i]); - else { - usage(); - return -1; - } - } - else if (strcmp(argv[i], "-l") == 0) { - if (argv[++i]) - g_left = atoi(argv[i]); - else { - usage(); - return -1; - } - } - else if (strcmp(argv[i], "-c") == 0) { - g_convert = 1; - } - else if (strcmp(argv[i], "-m") == 0) { - if (argv[++i]) - g_capture_mode = atoi(argv[i]); - else { - usage(); - return -1; - } - } - else if (strcmp(argv[i], "-d") == 0) { - strcpy(g_v4l_device, argv[++i]); - } - else if (strcmp(argv[i], "-fr") == 0) { - if (argv[++i]) - g_camera_framerate = atoi(argv[i]); - else { - usage(); - return -1; - } - } - else if (strcmp(argv[i], "-f") == 0) { - i++; - if (strcmp(argv[i], "NV12") == 0) { - g_pixelformat = IPU_PIX_FMT_NV12; - g_bpp = 12; - } - else if (strcmp(argv[i], "YUV420") == 0) { - g_pixelformat = IPU_PIX_FMT_YUV420P2; - g_bpp = 12; - } - else if (strcmp(argv[i], "YUV422P") == 0) { - g_pixelformat = IPU_PIX_FMT_YUV422P; - g_bpp = 16; - } - else if (strcmp(argv[i], "YUYV") == 0) { - g_pixelformat = IPU_PIX_FMT_YUYV; - g_bpp = 16; - } - else if (strcmp(argv[i], "UYVY") == 0) { - g_pixelformat = IPU_PIX_FMT_UYVY; - g_bpp = 16; - } - else if (strcmp(argv[i], "YUV444") == 0) { - g_pixelformat = IPU_PIX_FMT_YUV444; - g_bpp = 32; - } - else if (strcmp(argv[i], "RGB565") == 0) { - g_pixelformat = IPU_PIX_FMT_RGB565; - g_bpp = 16; - } - else { - printf("Pixel format not supported.\n"); - usage(); - return -1; - } - } - else { - usage(); - return -1; - } - } - - ret = v4l_capture_setup(&fd_v4l); - if (ret) - return ret; - - ret = v4l_capture_test(fd_v4l); - - return ret; - } diff --git a/meta-digi-dey/recipes-digi/packagegroups/packagegroup-dey-examples.bb b/meta-digi-dey/recipes-digi/packagegroups/packagegroup-dey-examples.bb index a4e1d74f5..0293f43d8 100644 --- a/meta-digi-dey/recipes-digi/packagegroups/packagegroup-dey-examples.bb +++ b/meta-digi-dey/recipes-digi/packagegroups/packagegroup-dey-examples.bb @@ -23,18 +23,9 @@ RDEPENDS_${PN} = "\ dey-examples-digiapix \ dey-examples-rtc \ " - RDEPENDS_${PN}_append_ccimx6 = "\ ${@bb.utils.contains("MACHINE_FEATURES", "accel-graphics", "dey-examples-opengles", "", d)} \ dey-examples-v4l2 \ " -RDEPENDS_${PN}_append_ccimx8x = "\ - dey-examples-v4l2 \ -" - -RDEPENDS_${PN}_append_ccimx8m = "\ - dey-examples-v4l2 \ -" - COMPATIBLE_MACHINE = "(ccimx6$|ccimx6ul|ccimx8x|ccimx8m)"