Because of the holidays, TI E2E™ design support forum responses will be delayed from Dec. 25 through Jan. 2. Thank you for your patience.

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/AM5718: Queue Buffer with VIDIOC_QBUF command fail: Invalid argument

Part Number: AM5718

Tool/software: Linux

Dear TI Experts,

My hardware board is AM5718 IDK, and it is run at RT Linux SDK for the latest version.

I have implemented a simple camera application with is similar to dual-camera example.

During my test  the camera passed the commends:

VIDIOC_QUERYCAP

VIDIOC_ENUM_FMT

VIDIOC_G_FMT

VIDIOC_S_FMT

And it also applied the buffer:

VIDIOC_REQBUFS

But it will failed during VIDIOC_QBUF command, it throws a Invalid argument error. The part of example code is as bellow:

int Init_Cameral(int Width , int Hight)
{
    printf("Nemo Init Cameral\n");
    //open device
    fd = open(FILE_VIDEO, O_RDWR);
    if(-1 == fd )
    {
        perror("open video device fail");
        printf("Nemo open video device fail\n");
        return -1 ;
    }
    // Check if the device is capable of streaming
    if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0 )
    {
         perror("Nemo VIDIOC_QUERYCAP");
         return -1;
    }
    else
    {
       printf("Nemo VIDIOC_QUERYCAP ok\n");
       printf("driver:\t\t%s\n",cap.driver);
       printf("card:\t\t%s\n",cap.card);
       printf("bus_info:\t%s\n",cap.bus_info);
       printf("version:\t%d\n",cap.version);
       printf("capabilities:\t%x\n",cap.capabilities);

       if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == V4L2_CAP_VIDEO_CAPTURE)
       {
          printf("Nemo Device %s: supports capture.\n",FILE_VIDEO);
      }

      if ((cap.capabilities & V4L2_CAP_STREAMING) == V4L2_CAP_STREAMING)
      {
          printf("Nemo Device %s: supports streaming.\n",FILE_VIDEO);
      }
    }

    //emu all support fmt
    fmtdesc.index=0;
    fmtdesc.type=V4L2_BUF_TYPE_VIDEO_CAPTURE;
    printf("Support format:\n");
    while(ioctl(fd,VIDIOC_ENUM_FMT,&fmtdesc)!=-1)
    {
       printf("Nemo \t%d.%s\n",fmtdesc.index+1,fmtdesc.description);
       fmtdesc.index++;
    }
    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

    if(ioctl(fd, VIDIOC_G_FMT, &fmt) == -1)
    {
         printf("Unable to get format\n");
         return -1;
    }
    else
    {
        printf("Nemo enable to get format\n");
    }
    fmt.fmt.pix.pixelformat = FOURCC_STR("YUYV");
    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    fmt.fmt.pix.height = IMAGEHEIGHT;
    fmt.fmt.pix.width = IMAGEWIDTH;
    //fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
    if(ioctl(fd, VIDIOC_S_FMT, &fmt) == -1)
    {
         printf("Unable to set format\n");
         return -1;
    }

    {
        printf("fmt.type:\t\t%d\n",fmt.type);
        printf("pix.pixelformat:\t%c%c%c%c\n",fmt.fmt.pix.pixelformat & 0xFF, (fmt.fmt.pix.pixelformat >> 8) & 0xFF,(fmt.fmt.pix.pixelformat >> 16) & 0xFF,     (fmt.fmt.pix.pixelformat >> 24) & 0xFF);
        printf("pix.height:\t\t%d\n",fmt.fmt.pix.height);
        printf("pix.width:\t\t%d\n",fmt.fmt.pix.width);
        printf("pix.field:\t\t%d\n",fmt.fmt.pix.field);
   }
   //set fps
   setfps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
   setfps.parm.capture.timeperframe.numerator = 10;
   setfps.parm.capture.timeperframe.denominator = 10;

   printf("init %s \t[OK]\n",FILE_VIDEO);

   int i ;
   int ret ;

    //apply buffers
    //3
    struct v4l2_requestbuffers  requestbuffer ;
    requestbuffer.count = COUNT ;
    requestbuffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE ;
    requestbuffer.memory = V4L2_MEMORY_DMABUF ;

    ret = ioctl(fd , VIDIOC_REQBUFS , &requestbuffer);
    if(ret != 0)
    {
        perror("request buffer fail ");
        return -3  ;
    }
    else
    {
	printf("Nemo VIDIOC_REQBUFS ok\n ");
    }


    //querybuffer
    struct v4l2_buffer querybuffer ;
    querybuffer.type =  V4L2_BUF_TYPE_VIDEO_CAPTURE ;
    querybuffer.memory = V4L2_MEMORY_DMABUF ;

    struct v4l2_buffer  queuebuffer;
    queuebuffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE ;
    queuebuffer.memory =  V4L2_MEMORY_DMABUF ;
    for(i = 0 ; i < COUNT ; i++)
    {
        querybuffer.index = i ;

        ret = ioctl(fd , VIDIOC_QUERYBUF , &querybuffer);
        if(ret != 0)
        {
            perror("query buffer fail");
            return -4 ;
        }
	else
        {
	     printf("nemo VIDIOC_QUERYBUF ok\n");
	}

        printf("index:%d length:%d  offset:%d \n" ,
             querybuffer.index , querybuffer.length , querybuffer.m.offset);
        length = querybuffer.length ;

        //memory mapping
        yuv[i] = mmap(0,querybuffer.length , PROT_READ | PROT_WRITE , MAP_SHARED , fd , querybuffer.m.offset );


        //queue
        queuebuffer.index = i ;
        ret = ioctl(fd , VIDIOC_QBUF , &queuebuffer);
        if(ret != 0)
        {
            perror("queuebuffer fail");
            return -5 ;
        }
    }
    //init queue
    enqueue.type = V4L2_BUF_TYPE_VIDEO_CAPTURE ;
    dequeue.type = V4L2_BUF_TYPE_VIDEO_CAPTURE ;
    enqueue.memory = V4L2_MEMORY_DMABUF ;
    dequeue.memory = V4L2_MEMORY_DMABUF ;

    return 0 ;
}

 

 

And the log is as bellow:

root@am57xx-evm:~# ./camera                                                                            
Nemo Init Cameral                                                                                      
Nemo VIDIOC_QUERYCAP ok                                                                                
driver:         vip                                                                                    
card:           vip                                                                                    
bus_info:       platform:vip                                                                           
version:        263200                                                                                 
capabilities:   85200001                                                                               
Nemo Device /dev/video1: supports capture.                                                             
Nemo Device /dev/video1: supports streaming.                                                           
Support format:                                                                                        
Nemo    1.Y/CbCr 4:2:0                                                                                 
Nemo    2.UYVY 4:2:2                                                                                   
Nemo    3.YUYV 4:2:2                                                                                   
Nemo    4.VYUY 4:2:2                                                                                   
Nemo    5.YVYU 4:2:2                                                                                   
Nemo    6.24-bit RGB 8-8-8                                                                             
Nemo    7.32-bit A/XRGB 8-8-8-8                                                                        
Nemo    8.24-bit BGR 8-8-8                                                                             
Nemo    9.32-bit BGRA/X 8-8-8-8                                                                        
Nemo    10.8-bit Bayer BGBG/GRGR                                                                       
Nemo enable to get format                                                                              
fmt.type:               1                                                                              
pix.pixelformat:        YUYV                                                                           
pix.height:             240                                                                            
pix.width:              320                                                                            
pix.field:              1                                                                              
init /dev/video1        [OK]                                                                           
Nemo VIDIOC_REQBUFS ok                                                                                 
 nemo VIDIOC_QUERYBUF ok                                                                               
index:0 length:153600  offset:0                                                                        
queuebuffer fail: Invalid argument                                                                     
root@am57xx-evm:~# ./camera                                                                            
Nemo Init Cameral                                                                                      
Nemo VIDIOC_QUERYCAP ok                                                                                
driver:         vip                                                                                    
card:           vip                                                                                    
bus_info:       platform:vip                                                                           
version:        263200                                                                                 
capabilities:   85200001                                                                               
Nemo Device /dev/video1: supports capture.                                                             
Nemo Device /dev/video1: supports streaming.                                                           
Support format:                                                                                        
Nemo    1.Y/CbCr 4:2:0                                                                                 
Nemo    2.UYVY 4:2:2                                                                                   
Nemo    3.YUYV 4:2:2                                                                                   
Nemo    4.VYUY 4:2:2                                                                                   
Nemo    5.YVYU 4:2:2                                                                                   
Nemo    6.24-bit RGB 8-8-8                                                                             
Nemo    7.32-bit A/XRGB 8-8-8-8                                                                        
Nemo    8.24-bit BGR 8-8-8                                                                             
Nemo    9.32-bit BGRA/X 8-8-8-8                                                                        
Nemo    10.8-bit Bayer BGBG/GRGR                                                                       
Nemo enable to get format                                                                              
fmt.type:               1                                                                              
pix.pixelformat:        YUYV                                                                           
pix.height:             240                                                                            
pix.width:              320                                                                            
pix.field:              1                                                                              
init /dev/video1        [OK]                                                                           
Nemo VIDIOC_REQBUFS ok                                                                                 
 nemo VIDIOC_QUERYBUF ok                                                                               
index:0 length:153600  offset:0                                                                        
queuebuffer fail: Invalid argument                

 

What is the problem in here? Thanks a lot!

Best Regards,

Nemo