The ioctl VIDIOC_EXPBUF
exports the dma memory as a filedescriptor. I want so transfer these memory over the network using sendfile
(because it is really fast compared to send()
or write()
).
But sendfile()
does not work on these filedescriptor. sendfile() returns with Error -1 and Errno is: Illegal seek.
How to get this working?
int buffer_export(int *vfd, int index, int *dmafd)
{
struct v4l2_exportbuffer expbuf;
memset(&expbuf, 0, sizeof(expbuf));
expbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
expbuf.index = index;
if (ioctl(*vfd, VIDIOC_EXPBUF, &expbuf) == -1) {
perror("VIDIOC_EXPBUF");
return -1;
}
*dmafd = expbuf.fd;
return 0;
}
Here the transfer code.
int *vfd;
//Capture Image
int dmafd, err, bytes_send;
int frame_size = 721920;
off_t offset = 0;
err = buffer_export( vfd, 0, &dmafd);
// returns 0
err = sendfile(socket_fd, dmafd ,&offset, frame_size);
//returns with -1
Update:
Browsing the sendfile source I came across the error occurs while checking the input fd.
retval = -ESPIPE; //=-29
if( !(in.file->f_mode & FMODE_PREAD) )
goto in_fd; //error
f_mode=5;
which is
/* file is open for reading */
#define FMODE_READ ((__force fmode_t)0x1)
/* file is open for writing */
#define FMODE_WRITE ((__force fmode_t)0x2)
/* file is seekable */
#define FMODE_LSEEK ((__force fmode_t)0x4)
/* file can be accessed using pread */
#define FMODE_PREAD ((__force fmode_t)0x8)
/* file can be accessed using pwrite */
fails