📄 test_ipipe.c
字号:
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 ));
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;
}
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 yuv16.YUV\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;
}
/* 3 */
int ipipe_yuv2yuv(struct ipipe_params* g_param)
{
//struct ipipe_cropsize crop;
char *inadr, *outadr;
int fd;
int *addr = NULL;
FILE *fp,*fc;
int cy = 0, ccb = 0, ccr = 0,i,j;
struct ipipe_reqbufs reqbufs;
struct ipipe_buffer temp_buff,in_buff, out_buff;
struct buffer buff[2];
struct ipipe_convert convert;
FILE *fccdc ;
int ret = 0;
//s_param = ¶ms;
/*** 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");
fccdc = fopen("in_yuv16.yuv","r+b");
if (fccdc == NULL)
{
printf("error in in_yuv16.yuv\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;
}
ret = ioctl(fd, IPIPE_GET_PARAM,g_param);
if (ret < 0) {
printf("IPIPE_SET_PARAM fail\n");
goto free;
}
g_param->ipipeif_param.source = SDRAM_YUV;
g_param->ipipeif_param.glob_hor_size = 648;
g_param->ipipeif_param.glob_ver_size = 490;
g_param->ipipeif_param.hnum = 640;
g_param->ipipeif_param.vnum = 480;
g_param->ipipeif_param.adofs = 1280;
g_param->ipipe_dpaths_fmt = YUV2YUV;
g_param->ipipe_vsz = 479;
g_param->ipipe_hsz = 639;
g_param->rsz_rsc_param[0].rsz_o_vsz = 479;
g_param->rsz_rsc_param[0].rsz_o_hsz = 639;
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 = 1280;
ret = ioctl(fd, IPIPE_SET_PARAM,g_param);
if (ret < 0) {
printf("IPIPE_SET_PARAM fail\n");
goto free;
}
#endif
/* request for 1 input buffer */
reqbufs.buf_type = IPIPE_BUF_IN;
reqbufs.size = 2* 640 * 480;
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 * 640 * 480;
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 ));
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 */
fread(buff[0].addr,1,640 * 480 * 2, fccdc);
fclose(fccdc);
/*inaddr/SE and outaddr contains the mapped addresses */
inadr = buff[0].addr;
outadr = buff[1].addr;
convert.in_buff.index = convert.out_buff.index = 0;
printf("ipipe_start\n");
if ((ret = ioctl(fd, IPIPE_START, &convert)) < 0){
printf("IPIPE_START fail\n");
goto out;
}
fc = fopen("out_yuv2yuv.YUV", "w");
if (fc == NULL)
{
printf("error in file fc\n");
goto out;
}
fwrite(buff[1].addr,1, 640 * 480 * 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;
}
/* 4 */
int ipipe_16raw2yuv_downscale(struct ipipe_params* g_param)
{
//struct ipipe_cropsize crop;
char *inadr, *outadr;
int fd;
int *addr = NULL;
FILE *fp,*fc;
int cy = 0, ccb = 0, ccr = 0,i,j;
struct ipipe_reqbufs reqbufs;
struct ipipe_buffer temp_buff,in_buff, out_buff;
struct buffer buff[2];
struct ipipe_convert convert;
FILE *fccdc ;
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");
fccdc = fopen("raw16.bin","r+b");
if (fccdc == NULL)
{
printf("error in raw16.bin\n");
goto free;
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_SET_PARAM fail\n");
goto free;
}
g_param->ipipeif_param.ialaw = ALAW_OFF;
g_param->ipipeif_param.pack_mode = SIXTEEN_BIT;
g_param->ipipeif_param.glob_hor_size = 624 + 8;
g_param->ipipeif_param.glob_ver_size = 456 + 10;
g_param->ipipeif_param.hnum = 624;
g_param->ipipeif_param.vnum = 456;
g_param->ipipeif_param.adofs = 624 * 2;
g_param->ipipe_vsz = 456 - 1;
g_param->ipipe_hsz = 624 - 1;
g_param->rsz_rsc_param[0].rsz_o_vsz = 240 - 1;
g_param->rsz_rsc_param[0].rsz_o_hsz = 320 - 1;
g_param->rsz_rsc_param[0].rsz_v_dif = 486;
g_param->rsz_rsc_param[0].rsz_h_dif = 480;
g_param->ext_mem_param[0].rsz_sdr_oft = 320 * 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 = 624* 2 * 456;
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 * 320 * 240;
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 */
fread(buff[0].addr,1,624 * 456 * 2, fccdc);
fclose(fccdc);
/*inaddr/SE and outaddr contains the mapped addresses */
inadr = buff[0].addr;
outadr = buff[1].addr;
convert.in_buff.index = convert.out_buff.index = 0;
printf("ipipe_start\n");
if ((ret = ioctl(fd, IPIPE_START, &convert)) < 0){
printf("IPIPE_START fail\n");
goto out;
}
fc = fopen("yuv16.yuv", "w");
if (fc == NULL)
{
printf("error in file yuv16.yuv\n");
goto out;
}
fwrite(buff[1].addr,1, 320 * 240 * 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;
}
/* 5 */
int yuy_downscale_rsz0(struct ipipe_params* g_param)
{
//struct ipipe_cropsize crop;
char *inadr, *outadr;
int fd;
int *addr = NULL;
FILE *fp,*fc;
int cy = 0, ccb = 0, ccr = 0,i,j;
struct ipipe_reqbufs reqbufs;
struct ipipe_buffer temp_buff,in_buff, out_buff;
struct buffer buff[2];
struct ipipe_convert convert;
FILE *fccdc ;
int ret = 0;
//s_param = ¶ms;
/*** 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");
fccdc = fopen("in_yuv16.yuv","r+b");
if (fccdc == NULL)
{
printf("error in in_yuv16.yuv\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;
}
ret = ioctl(fd, IPIPE_GET_PARAM,g_param);
if (ret < 0) {
printf("IPIPE_SET_PARAM fail\n");
goto free;
}
g_param->ipipeif_param.source = SDRAM_YUV;
g_param->ipipeif_param.glob_hor_size = 648;
g_param->ipipeif_param.glob_ver_size = 490;
g_param->ipipeif_param.hnum = 640;
g_param->ipipeif_param.vnum = 480;
g_param->ipipeif_param.adofs = 1280;
g_param->ipipe_dpaths_fmt = YUV2YUV;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -