/*
* \file cameratester.c
* \brief
*
* \version 1.0.0
* \date 2012年06月26日
* \author James Deng <csjamesdeng@allwinnertech.com>
*
* Copyright (c) 2012 Allwinner Technology. All Rights Reserved.
*
*/
#include <linux/videodev2.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include "drv_display_sun4i.h"
#include "dragonboard_inc.h"
struct buffer
{
void *start;
size_t length;
};
struct size
{
int width;
int height;
};
typedef enum
{
TVD_UV_SWAP,
TVD_COLOR_SET,
}tvd_param_t;
static int fd;
static int csi_format;
static int fps;
static int req_frame_num;
static struct buffer *buffers = NULL;
static int nbuffers = 0;
static struct size input_size;
static struct size disp_size;
static int disp;
static int layer;
static __disp_layer_info_t layer_para;
static int screen_width;
static int screen_height;
static __disp_pixel_fmt_t disp_format;
static __disp_pixel_mod_t disp_seq;
static __disp_pixel_seq_t disp_mode;
#define DISPLAY
#define LCD_WIDTH 800
#define LCD_HEIGHT 480
int sel = 0;//which screen 0/1
//__disp_video_fb_t video_fb;
#if 0
int disp_init(int w,int h)
{
/*display start*/
//unsigned int h,w;
unsigned int arg[4];
__u32 id = 0;
#if 0
//h= 480;
//w= 640;
if((disp = open("/dev/disp",O_RDWR)) == -1)
{
printf("open file /dev/disp fail. \n");
return 0;
}
arg[0] = 0;
ioctl(disp, DISP_CMD_LCD_ON, (void*)arg);
//layer0
arg[0] = 0;
arg[1] = DISP_LAYER_WORK_MODE_SCALER;
layer = ioctl(disp, DISP_CMD_LAYER_REQUEST, (void*)arg);
if(layer == 0)
{
printf("request layer0 fail\n");
return 0;
}
printf("video layer hdl:%d\n", layer);
layer_para.mode = DISP_LAYER_WORK_MODE_SCALER;
layer_para.pipe = 0;
layer_para.fb.addr[0] = 0;//your Y address,modify this
layer_para.fb.addr[1] = 0; //your C address,modify this
layer_para.fb.addr[2] = 0;
layer_para.fb.size.width = w;
layer_para.fb.size.height = h;
layer_para.fb.mode = disp_mode;///DISP_MOD_INTERLEAVED;//DISP_MOD_NON_MB_PLANAR;//DISP_MOD_NON_MB_PLANAR;//DISP_MOD_NON_MB_UV_COMBINED;
layer_para.fb.format = disp_format;//DISP_FORMAT_YUV420;//DISP_FORMAT_YUV422;//DISP_FORMAT_YUV420;
layer_para.fb.br_swap = 0;
layer_para.fb.seq = disp_seq;//DISP_SEQ_UVUV;//DISP_SEQ_YUYV;//DISP_SEQ_YVYU;//DISP_SEQ_UYVY;//DISP_SEQ_VYUY//DISP_SEQ_UVUV
layer_para.ck_enable = 0;
layer_para.alpha_en = 1;
layer_para.alpha_val = 0xff;
layer_para.src_win.x = 0;
layer_para.src_win.y = 0;
layer_para.src_win.width = w;
layer_para.src_win.height = h;
layer_para.scn_win.x = 0;
layer_para.scn_win.y = 0;
layer_para.scn_win.width = LCD_WIDTH;//800;
layer_para.scn_win.height = LCD_HEIGHT;//480;
arg[0] = sel;
arg[1] = layer;
arg[2] = (__u32)&layer_para;
ioctl(disp,DISP_CMD_LAYER_SET_PARA,(void*)arg);
arg[0] = sel;
arg[1] = layer;
ioctl(disp,DISP_CMD_LAYER_TOP,(void*)arg);
#endif
arg[0] = sel;
arg[1] = layer;
ioctl(disp,DISP_CMD_LAYER_OPEN,(void*)arg);
#if 1
int fb_fd;
unsigned long fb_layer;
void *addr = NULL;
fb_fd = open("/dev/fb0", O_RDWR);
if (ioctl(fb_fd, FBIOGET_LAYER_HDL_0, &fb_layer) == -1) {
printf("get fb layer handel\n");
}
addr = malloc(LCD_WIDTH*LCD_HEIGHT*3);
memset(addr, 0xff, LCD_WIDTH*LCD_HEIGHT*3);
write(fb_fd, addr, LCD_WIDTH*LCD_HEIGHT*3);
//memset(addr, 0x12, 800*480*3);
printf("fb_layer hdl: %ld\n", fb_layer);
close(fb_fd);
arg[0] = 0;
arg[1] = fb_layer;
ioctl(disp, DISP_CMD_LAYER_BOTTOM, (void *)arg);
#endif
}
#endif
int ii=234;
#if 1
static int disp_init(int width, int height)
{
unsigned int args[4];
if ((disp = open("/dev/disp", O_RDWR)) == -1) {
db_error("can't open /dev/disp(%s)\n", strerror(errno));
return -1;
}
args[0] = 0;
screen_width = ioctl(disp, DISP_CMD_SCN_GET_WIDTH, args);
screen_height = ioctl(disp, DISP_CMD_SCN_GET_HEIGHT, args);
args[0] = 0;
args[1] = DISP_LAYER_WORK_MODE_SCALER;
layer = ioctl(disp, DISP_CMD_LAYER_REQUEST, args);
if (layer == 0) {
db_error("request layer failed\n");
return -1;
}
memset(&layer_para, 0, sizeof(__disp_layer_info_t));
layer_para.mode = DISP_LAYER_WORK_MODE_SCALER;
layer_para.pipe = 0;
layer_para.prio = 0;
layer_para.alpha_en = 1;
layer_para.alpha_val = 0xff;
layer_para.ck_enable = 0;
layer_para.src_win.x = 0;
layer_para.src_win.y = 0;
layer_para.src_win.width = width;
layer_para.src_win.height = height;
layer_para.scn_win.x = screen_width >> 1;
layer_para.scn_win.y = 0;
layer_para.scn_win.width = screen_width >> 1;
layer_para.scn_win.height = screen_height >> 1;
layer_para.fb.addr[0] = 324;
layer_para.fb.addr[1] = 875;
layer_para.fb.addr[2] = 456;
layer_para.fb.size.width = width;
layer_para.fb.size.height = height;
layer_para.fb.format = disp_format;
layer_para.fb.seq = disp_seq;
layer_para.fb.mode = disp_mode;
layer_para.fb.br_swap = 0;
args[0] = 0;
args[1] = layer;
args[2] = (__u32)&layer_para;
ioctl(disp, DISP_CMD_LAYER_SET_PARA, args);
args[0] = 0;
args[1] = layer;
ioctl(disp, DISP_CMD_LAYER_TOP, args);
args[0] = 0;
args[1] = layer;
ioctl(disp, DISP_CMD_LAYER_OPEN, args);
return 0;
}
#endif
static int disp_start(void)
{
unsigned int args[4];
args[0] = 0;
args[1] = layer;
return ioctl(disp, DISP_CMD_VIDEO_START, args);
}
static int disp_stop(void)
{
unsigned int args[4];
args[0] = 0;
args[1] = layer;
return ioctl(disp, DISP_CMD_VIDEO_STOP, args);
}
static int disp_quit(void)
{
unsigned int args[4];
args[0] = 0;
args[0] = layer;
ioctl(disp, DISP_CMD_LAYER_CLOSE, args);
ioctl(disp, DISP_CMD_LAYER_RELEASE, args);
return 0;
}
static int disp_set_addr(int width, int height, unsigned int *addr)
{
__disp_video_fb_t fb;
unsigned int args[4];
memset(&fb, 0, sizeof(__disp_video_fb_t));
fb.interlace = 0;
fb.top_field_first = 0;
fb.frame_rate = 25;
fb.addr[0] = *addr;
fb.id = 0;
switch (csi_format) {
case V4L2_PIX_FMT_YUV422P:
case V4L2_PIX_FMT_YUYV:
case V4L2_PIX_FMT_YVYU:
case V4L2_PIX_FMT_UYVY:
case V4L2_PIX_FMT_VYUY:
fb.addr[1] = *addr + width * height;
fb.addr[2] = *addr + width * height * 3 / 2;
break;
case V4L2_PIX_FMT_YUV420:
fb.addr[1] = *addr + width * height;
fb.addr[2] = *addr + width * height * 5 / 4;
break;
case V4L2_PIX_FMT_NV16:
case V4L2_PIX_FMT_NV12:
case V4L2_PIX_FMT_HM12:
fb.addr[1] = *addr + width * height;
fb.addr[2] = layer_para.fb.addr[1];
break;
default:
break;
}
args[0] = 0;
args[1] = layer;
args[2] = (__u32)&fb;
return ioctl(disp, DISP_CMD_VIDEO_SET_FB, args);
}
static int read_frame(void)
{
struct v4l2_buffer buf;
memset(&buf, 0, sizeof(struct v4l2_buffer));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
ioctl(fd, VIDIOC_DQBUF, &buf);
disp_set_addr(disp_size.width, disp_size.height, &buf.m.offset);
ioctl(fd, VIDIOC_QBUF, &buf);
return 1;
}
static int g_aiSupportedFormats[] = {V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_MJPEG, V4L2_PIX_FMT_RGB565, V4L2_PIX_FMT_NV12};
static int isSupportThisFormat(int iPixelFormat)
{
int i;
for (i = 0; i < sizeof(g_aiSupportedFormats)/sizeof(g_aiSupport
kuangdoushi
- 粉丝: 55
- 资源: 14
最新资源
- 汇编语言安装文件:nasm-2.16.03
- Java 插件框架 (PF4J).zip
- image-svnadmin-2.5.3.tgz 正在使用ing,方便简单使用,运维好工具
- 地平线ros2文件.zip
- Java 多线程课程的代码及少量注释.zip
- 数据库课程设计-基于的个性化购物平台的建表语句.sql
- 数据库课程设计-基于的图书智能一体化管理系统的建表语句.sql
- Java 代码覆盖率库.zip
- Java 代码和算法的存储库 也为该存储库加注星标 .zip
- 免安装Windows10/Windows11系统截图工具,无需安装第三方截图工具 双击直接使用截图即可 是一款免费可靠的截图小工具哦~
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈