⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_ipipe.c

📁 德州仪器新推出的达芬奇技术dm355的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/////* previewer_test_application.c */
/* Header files */
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
#include <asm-arm/arch/dm355_ipipe.h>
#include <asm-arm/arch/dm355_ipipe_hw.h>
//#include "ipipe_param_header.h"
//#include "ipipe_para.h"
#include <getopt.h>
#include <sys/time.h>
#include <stdlib.h>
#include "bayerimage.h"
//#include "bayer_book.h"
#define DR_NAME     "/dev/dm355_ipipe"

#define DEBUG
#define I_WIDTH 624 
#define I_HEIGHT 456
#define O_WIDTH 640
#define O_HEIGHT 480
#define I_8RAW_WIDTH 640
#define I_8RAW_HEIGHT 480
//#define I_RAW_HEIGHT 640
//#define I_8RAW_HEIGHT 640

#define HELP                    "-h"
#define INCREMENT(argnum,argmax)  do{ argnum++; if(argnum > argmax){ usage(argv[0]); }  }while(0)
#ifdef DEBUG
#define IPIPE_DBGENTER printf("%s : E", __FUNCTION__);
#define IPIPE_DBGEXIT  printf("%s : L", __FUNCTION__);
#define IPIPE_DEBUG(x) printf("DEBUG:%s:%s:%s",__FUNCTION__,__LINE__,x);
#else
#define IPIPE_DBGENTER
#define IPIPE_DBGEXIT
#define IPIPE_DEBUG(x)
#endif
#define TEST_NO                 "-n"

#define INCREMENT(argnum,argmax)  do{ argnum++; if(argnum > argmax){ usage(argv[0]); }  }while(0)
struct buffer {
        void *addr;
	int length;
};
struct ipipe_params *s_param;
/* IPIPE_REQBUF:positive test */
int main(int argc, char* argv[])
{
	int ret = 0;
	if(argc == 1)
        {
             usage(argv[0]);
        }
	struct ipipe_params *g_param = malloc(sizeof(struct ipipe_params));
	switch(atoi(argv[1]))
	{
		case 0:
			ioctl_test(g_param);
			break;	
		case 1:
			ipipe_8raw2yuv(g_param);
			break;
		
		case 2:
	                ipipe_16raw2yuv(g_param);
	        	break;
	
		case 3:
	                ipipe_yuv2yuv(g_param);
	        	break;
	
		case 4:
			ipipe_16raw2yuv_downscale(g_param);
			break;
		 case 5:
			yuy_downscale_rsz0(g_param);
			break;
		
		 case 6:
                        yuy_upscale_rsz0(g_param);
                        break;
		 case 7:
			yuy_downscale_rsz1(g_param);
			break;
		 
		 case 8:
                        yuy_upscale_rsz1(g_param);
                        break;
		case 9:
			ipipe_8raw2yuv_downscale(g_param);
			break;
		case 10:
	                ipipe_16raw2yuv_up_rsz1(g_param);
	        	break;
		case 12:
	                ipipe_16raw2yuv_down_rsz1(g_param);
	        	break;
	}

	return 0;
	
}

/* 0 */
int ioctl_test(struct ipipe_params* g_param)
{
	int fd,i,j;
	 char *inadr, *outadr;
	int *addr = NULL;
	FILE *fp,*fc;
	struct ipipe_reqbufs reqbufs;
	struct ipipe_buffer temp_buff,in_buff, out_buff;
	struct buffer buff[2];
	struct ipipe_convert convert;
	FILE *ioctl_fd ;
	int ret = 0;

	/*** Output Device name ***/
	if ((fd = open(DR_NAME, O_RDWR)) < 0)
	{
		printf("\nError opening ipipe device;");
		free(g_param);
		return -1;
	}
	printf("device opened\n");
	ioctl_fd = fopen("raw16.bin","r+b");
	if (ioctl_fd == NULL)
	{
		printf("error in raw16.bin\n");
		goto free;
		return -1;
	}	
#if 1
	printf("fd = %d\n",fd);
	ret = ioctl(fd, IPIPE_SET_PARAM,NULL);
        if (ret < 0) {
	        printf("IPIPE_SET_PARAM fail\n");
	        goto free;
	}
	printf("IPIPE_SET_PARAM PASS\n");
#endif
	ret = ioctl(fd, IPIPE_GET_PARAM,g_param);
        if (ret < 0) {
                printf("IPIPE_GET_PARAM fail\n");
                goto free;
        }
	printf("IPIPE_GET_PARAM PASS\n");	
	ret = ioctl(fd, IPIPE_SET_PARAM,g_param);
        if (ret < 0) {
	        printf("IPIPE_SET_PARAM fail\n");
	        goto free;
	}
	printf("IPIPE_SET_PARAM PASS\n");

	/* request for 1 input buffer */
	reqbufs.buf_type = IPIPE_BUF_IN;
	reqbufs.size = 2* I_WIDTH * I_HEIGHT;
	reqbufs.count = 1;
	if ((ret = ioctl(fd, IPIPE_REQBUF, &reqbufs)) < 0){
		printf("IPIPE_REQBUF fail\n");
		goto free;
		
	}
	printf("IPIPE_REQBUF PASS\n");
	 /* request for 1 output buffer */
	reqbufs.buf_type = IPIPE_BUF_OUT;
	/*resize ratio will be 1*/
	reqbufs.size =  2 * O_HEIGHT * O_WIDTH;
	reqbufs.count = 1;
	
	if ((ret = ioctl(fd, IPIPE_REQBUF, &reqbufs)) < 0){
		printf("IPIPE_REQBUF fail\n");
		goto free;
	}	
//	printf("req_buf_out\n");

	temp_buff.index = 0;
	temp_buff.buf_type = IPIPE_BUF_IN;
	/*query buffer for input buffer*/	
	if ((ret = ioctl(fd,IPIPE_QUERYBUF,&temp_buff)) < 0){
		printf("IPIPE_QUERYBUF fail\n");
		goto free;
		 
	}
	in_buff.index = 0;
	in_buff.offset = temp_buff.offset;
	
	buff[0].length = temp_buff.size;
	
	//buff[0].addr = mmap(NULL, temp_buff.size, PROT_READ | PROT_WRITE, MAP_SHARED,
	//			fd,(temp_buff.offset >> 12));
	
	buff[0].addr = mmap(NULL, temp_buff.size, PROT_READ | PROT_WRITE, MAP_SHARED,
				fd,(temp_buff.offset));
	if (buff[0].addr == MAP_FAILED) {
		printf("\ncannot mmap buffer\n");
		goto free;
	}

	temp_buff.index = 0;
	temp_buff.buf_type = IPIPE_BUF_OUT;
	/*query buffer for output buffer*/	
	
	if ((ret = ioctl(fd,IPIPE_QUERYBUF,&temp_buff)) < 0){
		printf("IPIPE_QUERYBUF fail\n");
	}
	printf("add_app = %x\n",temp_buff.offset);
			
	out_buff.index = 0;
	out_buff.offset = temp_buff.offset;

	buff[1].length = temp_buff.size;
	//buff[1].addr = mmap(NULL, temp_buff.size, PROT_READ | PROT_WRITE, MAP_SHARED,
	//                                fd, temp_buff.offset >> 12);

	buff[1].addr = mmap(NULL, temp_buff.size, PROT_READ | PROT_WRITE, MAP_SHARED,
	                                fd, temp_buff.offset);

	 if (buff[1].addr == MAP_FAILED) {
	 	printf("\ncannot mmap buffer\n");
		munmap(buff[0].addr, buff[0].length);
		goto free;
	}
	printf("MMAP PASS\n");
	/*copy the image to mapped virtual address */
	
	fread(buff[0].addr,1,I_HEIGHT * I_WIDTH * 2, ioctl_fd);
	fclose(ioctl_fd);
	inadr = buff[0].addr;
        outadr = buff[1].addr;
	
	convert.in_buff.index = convert.out_buff.index = 0;
		
	if ((ret = ioctl(fd, IPIPE_START, &convert)) < 0){
		
		printf("IPIPE_START fail\n");
		goto out;
	}

	printf("IPIPE_START PASS\n");
	fc = fopen("yuv16.YUV", "w");
	
	if (fc == NULL)
	{	
		printf("error in file fc\n");
		goto out;
	}
	fwrite(buff[1].addr,1, O_WIDTH * O_HEIGHT * 2,fc);
	fclose(fc);
	
out:
	munmap(buff[0].addr, buff[0].length);
	munmap(buff[1].addr, buff[1].length);
free:
	close(fd);
	free(g_param);
	printf("file closed");	
	return ret;

}
/* 1 */
int ipipe_8raw2yuv(struct ipipe_params* g_param)
{
	int fd,i,j;
	char *inadr, *outadr;
	int *addr = NULL;
	FILE *fp,*fc;
	struct ipipe_reqbufs reqbufs;
	struct ipipe_buffer temp_buff,in_buff, out_buff;
	struct buffer buff[2];
	struct ipipe_convert convert;
	int ret = 0;

	/*** Output Device name ***/
	if ((fd = open(DR_NAME, O_RDWR)) < 0)
	{
		printf("\nError opening ipipe device;");
		free(g_param);
		return -1;
	}
	ret = ioctl(fd, IPIPE_SET_PARAM,NULL);
        if (ret < 0) {
	        printf("IPIPE_SET_PARAM fail\n");
	        goto free;
	}
	ret = ioctl(fd, IPIPE_GET_PARAM,g_param);
        if (ret < 0) {
                printf("IPIPE_GET_PARAM fail\n");
                goto free;
        }
	g_param->ipipeif_param.ialaw = ALAW_ON;
	g_param->ipipeif_param.pack_mode = EIGHT_BIT;
	g_param->ipipeif_param.glob_ver_size = I_8RAW_HEIGHT + 10;
	g_param->ipipeif_param.glob_hor_size = I_8RAW_WIDTH + 8;
	g_param->ipipeif_param.hnum = I_8RAW_WIDTH;
	g_param->ipipeif_param.vnum = I_8RAW_HEIGHT;
	g_param->ipipeif_param.adofs = I_8RAW_WIDTH;
	g_param->ipipe_vsz = I_8RAW_HEIGHT - 1;
	g_param->ipipe_hsz = I_8RAW_WIDTH - 1;
	g_param->rsz_rsc_param[0].rsz_o_vsz = O_HEIGHT - 1;
	g_param->rsz_rsc_param[0].rsz_o_hsz = O_WIDTH - 1;
	g_param->rsz_rsc_param[0].rsz_v_dif = 256;
	g_param->rsz_rsc_param[0].rsz_h_dif = 256;
	g_param->ext_mem_param[0].rsz_sdr_oft = O_WIDTH * 2;
	
	ret = ioctl(fd, IPIPE_SET_PARAM,g_param);
        if (ret < 0) {
	        printf("IPIPE_SET_PARAM fail\n");
	        goto free;
	}

	/* request for 1 input buffer */
	reqbufs.buf_type = IPIPE_BUF_IN;
	reqbufs.size = I_8RAW_WIDTH * I_8RAW_HEIGHT;
	reqbufs.count = 1;
	if ((ret = ioctl(fd, IPIPE_REQBUF, &reqbufs)) < 0){
		printf("IPIPE_REQBUF fail\n");
		goto free;
		
	}
	 /* request for 1 output buffer */
	reqbufs.buf_type = IPIPE_BUF_OUT;
	/*resize ratio will be 1*/
	reqbufs.size =  2 * O_HEIGHT * O_WIDTH;
	reqbufs.count = 1;
	
	if ((ret = ioctl(fd, IPIPE_REQBUF, &reqbufs)) < 0){
		printf("IPIPE_REQBUF fail\n");
		goto free;
	}	

	temp_buff.index = 0;
	temp_buff.buf_type = IPIPE_BUF_IN;
	/*query buffer for input buffer*/	
	if ((ret = ioctl(fd,IPIPE_QUERYBUF,&temp_buff)) < 0){
		printf("IPIPE_QUERYBUF fail\n");
		goto free;
		 
	}
	in_buff.index = 0;
	in_buff.offset = temp_buff.offset;
	
	buff[0].length = temp_buff.size;
	
	buff[0].addr = mmap(NULL, temp_buff.size, PROT_READ | PROT_WRITE, MAP_SHARED,
				fd,(temp_buff.offset ));

	if (buff[0].addr == MAP_FAILED) {
		printf("\ncannot mmap buffer\n");
		goto free;
	}

	temp_buff.index = 0;
	temp_buff.buf_type = IPIPE_BUF_OUT;
	/*query buffer for output buffer*/	
	
	if ((ret = ioctl(fd,IPIPE_QUERYBUF,&temp_buff)) < 0){
		printf("IPIPE_QUERYBUF fail\n");
	}
	printf("add_app = %x\n",temp_buff.offset);
			
	out_buff.index = 0;
	out_buff.offset = temp_buff.offset;

	buff[1].length = temp_buff.size;
	buff[1].addr = mmap(NULL, temp_buff.size, PROT_READ | PROT_WRITE, MAP_SHARED,
	                                fd, temp_buff.offset);
	 if (buff[1].addr == MAP_FAILED) {
	 	printf("\ncannot mmap buffer\n");
		munmap(buff[0].addr, buff[0].length);
		goto free;
	}
	/*copy the image to mapped virtual address */
	memcpy(buff[0].addr,bayerimage,I_8RAW_WIDTH * I_8RAW_HEIGHT);
	inadr = buff[0].addr;
        outadr = buff[1].addr;
	
	convert.in_buff.index = convert.out_buff.index = 0;
		
	if ((ret = ioctl(fd, IPIPE_START, &convert)) < 0){
		
		printf("IPIPE_START fail\n");
		goto out;
	}
	printf("reached 1\n");	

	fc = fopen("yuv16.YUV", "w");
	
	if (fc == NULL)
	{	
		printf("error in file fc\n");
		goto out;
	}
	printf("reached 2\n");	
	fwrite(buff[1].addr,1, O_WIDTH * O_HEIGHT * 2,fc);
	fclose(fc);
	printf("reached 3\n");	
	
out:
	munmap(buff[0].addr, buff[0].length);
	munmap(buff[1].addr, buff[1].length);
free:
	close(fd);
	free(g_param);
	printf("file closed");	
	return ret;
}
/* 2 */
int ipipe_16raw2yuv(struct ipipe_params* g_param)
{
	int fd,i,j;
	char *inadr, *outadr;
	int *addr = NULL;
	FILE *fp,*fc;
	struct ipipe_reqbufs reqbufs;
	struct ipipe_buffer temp_buff,in_buff, out_buff;
	struct buffer buff[2];
	struct ipipe_convert convert;
	FILE *ioctl_fd ;
	int ret = 0;

	/*** Output Device name ***/
	if ((fd = open(DR_NAME, O_RDWR)) < 0)
	{
		printf("\nError opening ipipe device;");
		free(g_param);
		return -1;
	}
	printf("device opened\n");
	ioctl_fd = fopen("raw16.bin","r+b");
	if (ioctl_fd == NULL)
	{
		printf("error in raw16.bin\n");
		goto free;
		return -1;
	}	
#if 1
	printf("fd = %d\n",fd);
	ret = ioctl(fd, IPIPE_SET_PARAM,NULL);
        if (ret < 0) {
	        printf("IPIPE_SET_PARAM fail\n");
	        goto free;
	}
	printf("IPIPE_SET_PARAM PASS\n");
#endif
	ret = ioctl(fd, IPIPE_GET_PARAM,g_param);
        if (ret < 0) {
                printf("IPIPE_GET_PARAM fail\n");
                goto free;
        }
	printf("IPIPE_GET_PARAM PASS\n");	
	
#if 1
	g_param->ipipeif_param.ialaw = ALAW_OFF;
        g_param->ipipeif_param.pack_mode = SIXTEEN_BIT;
        g_param->ipipeif_param.hnum = I_WIDTH;
        g_param->ipipeif_param.vnum = I_HEIGHT;
        g_param->ipipeif_param.adofs = I_WIDTH * 2; 
        g_param->ipipe_vsz = I_HEIGHT - 1;
        g_param->ipipe_hsz = I_WIDTH - 1;
        g_param->rsz_rsc_param[0].rsz_o_vsz = O_HEIGHT - 1;
        g_param->rsz_rsc_param[0].rsz_o_hsz = O_WIDTH - 1;
        g_param->rsz_rsc_param[0].rsz_v_dif = 243;
        g_param->rsz_rsc_param[0].rsz_h_dif = 243;
        g_param->ext_mem_param[0].rsz_sdr_oft = O_WIDTH * 2;	
#endif
	
	ret = ioctl(fd, IPIPE_SET_PARAM,g_param);
        if (ret < 0) {
	        printf("IPIPE_SET_PARAM fail\n");
	        goto free;
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -