Dear All!
I am trying to sort out with DM355 previer. I've wrote a simple program - actually it is mostly the copy of example. I try to make it work on DM355 DVEVM. It compiles successfully and works properly till the PREV_PREVIEW ioctl, where it hangs permanently. I've lost about a week trying to make it working, but had no success. Could you please tell me, what am I doing wrong. Here is the listing:
#include <stdio.h>
#include <media/davinci/dm355_ipipe.h>
#include <media/davinci/imp_previewer.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <media/davinci/imp_common.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "try_ipipe.h"
#include <string.h>
#include <sys/mman.h>
#define WIDTH 1296
#define HEIGHT 972
#define INBUFSNUM 1
#define OUTBUFSNUM 1
#define BYTESPERLINE 2
unsigned int preview_fd, oper_mode, user_mode;
int ret, expected_size, size, i, outwidth, outheight, outsize;
char inbuf[WIDTH*HEIGHT];
char *input_buffer, *output_buffer;
struct prev_channel_config prev_chan_par;
struct prev_single_shot_config prev_ss_config;
struct prev_cap cap;
struct prev_module_param mod_param;
struct imp_reqbufs reqbuf_params;
struct imp_buffer inbuf_params[INBUFSNUM], outbuf_params[OUTBUFSNUM];
struct imp_convert conv_params;
FILE *infile, *outfile;
int main(void)
{
//Opening the Previewer
preview_fd=open("/dev/davinci_previewer", O_RDWR);
//Setting Previewer mode
oper_mode=IMP_MODE_SINGLE_SHOT;
printf("Setting previewer operation mode\n");
ioctl(preview_fd,PREV_S_OPER_MODE,&oper_mode);
// Setting previewer configuration
prev_chan_par.oper_mode=oper_mode;
prev_chan_par.len=0;
prev_chan_par.config=NULL;
ioctl(preview_fd,PREV_S_CONFIG,&prev_chan_par);
prev_chan_par.oper_mode=oper_mode;
prev_chan_par.len=sizeof(struct prev_single_shot_config);
prev_chan_par.config=&prev_ss_config;
ioctl(preview_fd,PREV_G_CONFIG,&prev_chan_par)
prev_ss_config.input.image_width=WIDTH;
prev_ss_config.input.image_height=HEIGHT;
ioctl(preview_fd,PREV_S_CONFIG,&prev_chan_par);
// IPIPE modules cycle initialisation
cap.index=0;
while (1)
{
ret=ioctl(preview_fd, PREV_ENUM_CAP, &cap);
if (ret<0)
{
break;
}
strcpy(mod_param.version,cap.version);
mod_param.module_id=cap.module_id;
mod_param.param = NULL;
ioctl(preview_fd, PREV_S_PARAM, &mod_param)
cap.index++;
}
//Buffers initialisation
expected_size=WIDTH*HEIGHT;
outwidth=WIDTH;
outheight=HEIGHT;
outwidth += 15;
outwidth &= (~15);
outsize = outwidth * outheight * BYTESPERLINE;
infile=fopen("capture_8.raw", "rb");
size=fread(inbuf,1,expected_size,infile);
reqbuf_params.buf_type=IMP_BUF_IN;
reqbuf_params.size=size;
reqbuf_params.count=INBUFSNUM;
ioctl(preview_fd,PREV_REQBUF,&reqbuf_params)
for (i=0;i<INBUFSNUM;i++)
{
inbuf_params[i].index=i;
inbuf_params[i].buf_type=IMP_BUF_IN;
ioctl(preview_fd, PREV_QUERYBUF, &inbuf_params[i])
}
reqbuf_params.buf_type=IMP_BUF_OUT1;
reqbuf_params.size=outsize;
reqbuf_params.count=OUTBUFSNUM;
ioctl(preview_fd,PREV_REQBUF,&reqbuf_params)
for (i=0;i<OUTBUFSNUM;i++)
{
outbuf_params[i].index=i;
outbuf_params[i].buf_type=IMP_BUF_OUT1;
ioctl(preview_fd, PREV_QUERYBUF, &outbuf_params[i]);
}
input_buffer=mmap(NULL,inbuf_params[0].size, PROT_READ|PROT_WRITE,
MAP_SHARED, preview_fd, inbuf_params[0].offset);
output_buffer=mmap(NULL,outbuf_params[0].size,PROT_READ|PROT_WRITE,
MAP_SHARED, preview_fd, inbuf_params[0].offset);
//Begin the operations
memcpy(input_buffer,inbuf,(WIDTH*HEIGHT));
memset(&conv_params,'\0',sizeof(conv_params));
conv_params.in_buff.index=0;
conv_params.in_buff.buf_type=IMP_BUF_IN;
conv_params.in_buff.offset=inbuf_params[0].offset;
conv_params.in_buff.size=inbuf_params[0].size;
conv_params.out_buff1.index=0;
conv_params.out_buff1.buf_type=IMP_BUF_OUT1;
conv_params.out_buff1.offset=outbuf_params[0].offset;
conv_params.out_buff1.size=outbuf_params[0].size;
ioctl(preview_fd, PREV_PREVIEW, &conv_params)
//Finishing preview. Output creation.
outfile=fopen("720p_converted","wb");
fwrite(output_buffer,1,size,outfile)
printf("Output saved.Cleaning memory");
munmap(input_buffer,inbuf_params[0].size);
munmap(output_buffer,outbuf_params[0].size);
fclose(infile);
fclose(outfile);
close(preview_fd);
return 0;
}
What am I doing wrong? Which of the obligatory parameters I have missed?
Thank you in advance.
MS