thank you for your reply,but my project use v4l2 and dmabuf
///////
if (-1 == ioctl(m_nDevFd, VIDIOC_QUERYCAP, &cap)) {
if (EINVAL == errno) {
plog(m_nDevIndex, “Given device is no V4L2 device”);
}
plog(m_nDevIndex, “Error occurred when querying capabilities”);
return ERR;
}
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
plog(m_nDevIndex, "Given device is no video capture device");
return ERR;
}
//////
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = width;
fmt.fmt.pix.height = height;
fmt.fmt.pix.pixelformat = format;
fmt.fmt.pix.field = V4L2_FIELD_ANY;
if (-1 == ioctl(m_nDevFd, VIDIOC_S_FMT, &fmt))
{
plog(m_nDevIndex, "Error occurred when trying to set format");
return ERR;
}
//////
int VideoCapture::init_dmabuf(void)
{
struct v4l2_requestbuffers req;
int ret = 0;
prepare_dmabufs();
CLEAR(req);
memset(&req, 0, sizeof(req));
req.count = NUM_BUFFS;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_DMABUF;
if (-1 == ioctl(m_nDevFd, VIDIOC_REQBUFS, &req)) {
if (EINVAL == errno) {
plog(m_nDevIndex, "The device does not support dmabuf");
}
return ERR;
}
if (req.count < 1 || req.count != NUM_BUFFS) {
plog(m_nDevIndex, "Insufficient memory to allocate buffers");
return ERR;
}
////
int VideoCapture::prepare_dmabufs()
{
int index;
NvBufferCreateParams input_params = {0};
input_params.payloadType = NvBufferPayload_SurfArray;
input_params.width = m_nWidth;//CAMERA_SRC_WIDTH;
input_params.height = m_nHeight;//CAMERA_SRC_HEIGHT;
input_params.layout = NvBufferLayout_Pitch;
// Create buffer and provide it with camera
for (index = 0; index < NUM_BUFFS; index++)
{
int fd;
NvBufferParams params = {0};
input_params.colorFormat = NvBufferColorFormat_UYVY;
input_params.nvbuf_tag = NvBufferTag_CAMERA;
if (-1 == NvBufferCreateEx(&fd, &input_params))
plog(m_nDevIndex, "Failed to create NvBuffer");
dmabuf_fd[index] = fd;
if (-1 == NvBufferGetParams(fd, ¶ms))
{
plog(m_nDevIndex, "Failed to get NvBuffer parameters");
}
plog(m_nDevIndex, "###VideoCapture[%d] dmabuf_fd[%d-%d]",m_nDevIndex,dmabuf_fd[index],index);
// TODO add multi-planar support
// Currently it supports only YUV422 interlaced single-planar
if (-1 == NvBufferMemMap(fd, 0, NvBufferMem_Read_Write,(void**)&(fd_va[index])))
plog(m_nDevIndex, "Failed to map buffer");
}
plog(m_nDevIndex, "Succeed in preparing stream buffers[%d]",m_nDevIndex);
return true;
}