Hello!
I wrote programm to capture image from CMOS-matrix, encode JPEG and to send image via RTSP_stream. I have successfully see MJPEG stream via VLC, but I get green image and I think that IPIPE can solve this problem.
I looked sample in dvsdk_2_00_00_22/PSP_02_00_00_140/examples/dm355/ipipe and wrote my function:
short initIPIPE(Buffer_Handle *hBufPtr)
{
struct ipipe_reqbufs reqbufs;
struct ipipe_buffer t_buff;
int ret;
ipipeFd = open(IPIPE_DEVICE, O_RDWR);
if (-1 == ipipeFd) {
cout << "Can't open " << IPIPE_DEVICE << "!" << endl;
return ipipeFd;
}
ret = configureIPIPE(ipipeFd);
if (0 != ret) {
cout << "Can't configure IPIPE!" << endl;
return ret;
}
reqbufs.buf_type = IPIPE_BUF_OUT;
reqbufs.size = imageHeight * (((imageWidth << 1) + 31) & (~31));
reqbufs.count = NUM_BUF;
ret = ioctl(ipipeFd, IPIPE_REQBUF, &reqbufs);
if (-1 == ret ) {
cout << "Can't get IPIPE requested buffer (" << strerror(errno) << "!" << endl;
return ret;
}
t_buff.index = 0;
t_buff.buf_type = IPIPE_BUF_OUT;
ret = ioctl(ipipeFd, IPIPE_QUERYBUF, &t_buff);
if (-1 == ret) {
cout << "Can't get IPIPE out buffer address (" << strerror(errno) << "!" << endl;
return ret;
}
BufferGfx_Attrs gfxAttrs = BufferGfx_Attrs_DEFAULT;
gfxAttrs.dim.width = imageWidth;
gfxAttrs.dim.height = imageHeight;
gfxAttrs.dim.lineLength = imageWidth << 1;
gfxAttrs.colorSpace = ColorSpace_UYVY;
gfxAttrs.bAttrs.reference = TRUE;
Buffer_setNumBytesUsed(*hBufPtr, t_buff.size);
Int8 *virtPtr;
virtPtr = (Int8 *)mmap(NULL, t_buff.size, PROT_READ | PROT_WRITE, MAP_SHARED, ipipeFd, t_buff.offset);
if (virtPtr == MAP_FAILED) {
cout << "Can't mmap IPIPE buffer (" << strerror(errno) << ")!" << endl;
return -1;
}
Buffer_setUseMask(*hBufPtr, gfxAttrs.bAttrs.useMask);
Buffer_setUserPtr(*hBufPtr, virtPtr);
return 0;
}
short processIPIPE(Buffer_Handle hInBuf, Buffer_Handle hOutBuf)
{
struct ipipe_convert convert;
if (-1 == configureIPIPE(ipipeFd)) {
cout << "Can't configure IPIPE!" << endl;
return -1;
}
convert.in_buff.buf_type = IPIPE_BUF_IN;
convert.in_buff.index = -1;
convert.in_buff.offset = (unsigned int)Buffer_getUserPtr(hInBuf);
convert.in_buff.size = Buffer_getNumBytesUsed(hInBuf);
convert.out_buff.index = -1;
convert.out_buff.buf_type = IPIPE_BUF_OUT;
convert.out_buff.offset = (unsigned int)Buffer_getUserPtr(hOutBuf);
convert.out_buff.size = Buffer_getNumBytesUsed(hOutBuf);
if (-1 == ioctl(ipipeFd, IPIPE_START, &convert)) {
cout << "IPIPE don't convert image!" << endl;
return -1;
}
return 0;
}
And programm:
Buffer_Handle hIPIPEBuf;
if (-1 == initIPIPE(&hIPIPEBuf)) {
cout << "Can't init IPIPE!" << endl;
closeIPIPE(hIPIPEBuf);
clear();
}
while (true) {
if (Dmai_EOK != Capture_get(hCapture, &hCapBuf)) {
cout << "Failed to get capture buffer!" << endl;
clear();
}
if (Dmai_EOK != Framecopy_execute(hFramecopy, hCapBuf, hDstBuf)) {
cout << "Failed to execute frame copy job!" << endl;
clear();
}
processIPIPE(hDstBuf, hIPIPEBuf);
..........................
}
Information about hIPIPEBuf:
[1073957228] @ 0x41b94000 (0x84700000 phys) numBytes 614400 (1073862896) useMask 1 (17148) ref yes
Information about hDstBuf:
[0] @ 0x43475000 (0x87300000 phys) numBytes 0 (614400) useMask 0 (1) ref no
Width 640, Height 480, LineLength 1280
[1] @ 0x436f5000 (0x87080000 phys) numBytes 0 (614400) useMask 0 (1) ref no
Width 640, Height 480, LineLength 1280
[2] @ 0x43975000 (0x86e00000 phys) numBytes 0 (614400) useMask 0 (1) ref no
Width 640, Height 480, LineLength 1280
lsmod:
dm355_ipipe_driver 26024 0 - Live 0xbf01d000
dm350mmap 5268 0 - Live 0xbf01a000
cmemk 28044 0 - Live 0xbf012000
davinci_capture 42120 0 - Live 0xbf006000
capture_driver 7768 1 davinci_capture, Live 0xbf003000
tvp5146 6856 1 davinci_capture, Live 0xbf000000
When I start programm I don't get any error and this output:
CPU load 17%
CPU load 1%
CPU load 0%
When I try to get stream via vlc I get Floating point exception.
I have found what problem in the ioctl(ipipeFd, IPIPE_START, &convert), but why?
Where I have error and how can I solve it?
Thank you and excuse me for my bad english.