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.

V4L2_MEMORY_USERPTR support on DM6446

Hi,

I'm using DM6446 with DVSDK 2.0.0.22. I would like to capture using V4L, but instead of using MMAP (which I also tested, and it works), I'm using V4L2_MEMORY_USERPTR. Unfortunately, when I get to this fragment of code:

      ret = ioctl( captureFd, VIDIOC_QBUF, &buf );
      if( ret  == -1 )
      {
          if(errno == EINVAL)
              printf("EINVAL problem");
         ERR( "VIODIOC_QBUF failed on file descriptor %d\n", captureFd );
          failure_procedure();                              //      macro defined at top of this function
      }

I get an EINVAL error set in errno. My question is: does DM6446n support V4L2_MEMORY_USERPTR?

Another question is: should I use DMAI instead of this approach? Is it worth considering?

 

Thanks

Gab


 

  • Hi,

    What about VIDIOC_REQBUFS? Is it returning successfully? How are you allocating for USER_PTR buffers? Are you using CMEM to allocate USER_PTR buffers?

    Please provide details.

    You can use this application about using USER_PTR(cmem).

     

     

  • Yes, VIDIOC_REQBUFS returns successfully, but I was not using CMEM, I was using memalign() to allocate the USER_PTR buffers. Isn't this correct? Can I only use CMEM?

  • Looks like v4l2 drivers don't support buffers allocated through memalign().

  • I've just modified my code to support CMEM and tried it. Unfortunately, still no success.

    Basically, at startup I create 3 buffers for capturing, in this way:

    int allocate_user_buffers(void)
    {
        void *pool;
        int i;
        unsigned int buf_size = NUM_PIXELS*2; // 16bit  D1 resolution

        CMEM_AllocParams  alloc_params;
        printf("calling cmem utilities for allocating frame buffers\n");
        CMEM_init();

        alloc_params.type = CMEM_POOL;
        alloc_params.flags = CMEM_NONCACHED;
        alloc_params.alignment = 32;
        pool = CMEM_allocPool(0, &alloc_params);

        if (NULL == pool) {
            printf("Failed to allocate cmem pool\n");
            return -1;
        }
        printf("Allocating capture buffers :buf size = %d \n", buf_size);
       
        for (i=0; i < NUM_CAP_BUFS; i++) {
            capture_buffers[i].user_addr = CMEM_alloc(buf_size, &alloc_params);
            if (capture_buffers[i].user_addr) {
                capture_buffers[i].phy_addr = CMEM_getPhys(capture_buffers[i].user_addr);
                if (0 == capture_buffers[i].phy_addr) {
                    printf("Failed to get phy cmem buffer address\n");
                    return -1;
                }
            } else {
                printf("Failed to allocate cmem buffer\n");
                return -1;
            }
            printf("Got %p from CMEM, phy = %p\n", capture_buffers[i].user_addr, (void *)capture_buffers[i].phy_addr);
        }

        return 0;
    }

    This is correctly executed, as reported in the following console output:

    calling cmem utilities for allocating frame buffers
    Allocating capture buffers :buf size = 829440
    Got 0x40f94000 from CMEM, phy = 0x87bc6000
    Got 0x4105f000 from CMEM, phy = 0x87afb000
    Got 0x4112a000 from CMEM, phy = 0x87a30000

    Once again, the app fails when performing VIDIOC_QBUF in the following code fragment:

       for( numBufs = 0; numBufs < req.count; numBufs++ )
       {
            CLEAR( buf );
            
           buf.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
           buf.memory = V4L2_MEMORY_USERPTR;
           buf.index  = numBufs;
          buf.length = 829440;
          buf.m.userptr = (unsigned long)buffersPtr[numBufs].user_addr;

          /*  Enqueue all of the allocated buffers to be available for capture */
          ret = ioctl( captureFd, VIDIOC_QBUF, &buf );
          if( ret  == -1 )
          {
              if(errno == EINVAL)
                  printf("problem with buffer: length %d start %d index %d \n",buf.length,buf.m.userptr,buf.index);
             ERR( "VIODIOC_QBUF failed on file descriptor %d\n", captureFd );
              failure_procedure();                              //      macro defined at top of this function
          }
       }   

    The output reports some info about the buffer involved in the failure, which I report here:

    length 829440 start 1090076672 index 0

    I don't know whether the start address is not valid, or there is a bug somewhere else, or if the DM6446 does not support USER_PTR. Any idea?

  • Looks like problem is different. Are you sure buf.m.userptr is prperly set. Also what is the height and width of the image you are capturing. Whatever you set during set_format should match with buf.length.