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 <Mike.Engel@digi.com> https://jira.digi.com/browse/DEL-7211
This commit is contained in:
parent
6609611d2b
commit
15f9aeba0e
|
|
@ -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)"
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -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 <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <linux/fb.h>
|
|
||||||
#include <linux/mxcfb.h>
|
|
||||||
#include <linux/version.h>
|
|
||||||
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,37)
|
|
||||||
#include <linux/videodev2.h>
|
|
||||||
#else
|
|
||||||
#include <linux/videodev.h>
|
|
||||||
#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_ */
|
|
||||||
|
|
@ -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 <pthread.h>
|
|
||||||
#include <sched.h>
|
|
||||||
|
|
||||||
#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 </dev/video0> -o </dev/fb0> -h <height> "
|
|
||||||
"-w <width> -t <top> -l <left> [-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;
|
|
||||||
}
|
|
||||||
|
|
@ -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 <errno.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <asm/types.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
#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;
|
|
||||||
}
|
|
||||||
|
|
@ -23,18 +23,9 @@ RDEPENDS_${PN} = "\
|
||||||
dey-examples-digiapix \
|
dey-examples-digiapix \
|
||||||
dey-examples-rtc \
|
dey-examples-rtc \
|
||||||
"
|
"
|
||||||
|
|
||||||
RDEPENDS_${PN}_append_ccimx6 = "\
|
RDEPENDS_${PN}_append_ccimx6 = "\
|
||||||
${@bb.utils.contains("MACHINE_FEATURES", "accel-graphics", "dey-examples-opengles", "", d)} \
|
${@bb.utils.contains("MACHINE_FEATURES", "accel-graphics", "dey-examples-opengles", "", d)} \
|
||||||
dey-examples-v4l2 \
|
dey-examples-v4l2 \
|
||||||
"
|
"
|
||||||
|
|
||||||
RDEPENDS_${PN}_append_ccimx8x = "\
|
|
||||||
dey-examples-v4l2 \
|
|
||||||
"
|
|
||||||
|
|
||||||
RDEPENDS_${PN}_append_ccimx8m = "\
|
|
||||||
dey-examples-v4l2 \
|
|
||||||
"
|
|
||||||
|
|
||||||
COMPATIBLE_MACHINE = "(ccimx6$|ccimx6ul|ccimx8x|ccimx8m)"
|
COMPATIBLE_MACHINE = "(ccimx6$|ccimx6ul|ccimx8x|ccimx8m)"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue