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.

Buffer length always zero in ffmpeg application in VPSS with v4l2

I am using DM8148 Processor for Video processing with adv7180 decoder to receive PAL data. The data  converted to YCbCr format. 

I had face problem in Memory map allocation, in "dma_alloc_coherent" function.  It had failed to allocate dma memory. So I moved to User Pointer memory allocation.

Instead of MMAP, I am using USER POINTER to allocate memory for buffer.

But Buffer len size is always zero form the function "vidioc_querybuf" in FFMPEG application.

LOG:

[video4linux2,v4l2 @ 0xd850f0] Buffer len [0] = 0 != 829440
/dev/video0: Operation not permitted


Run time arguments for FFMPEG application :

# ffmpeg -vcodec rawvideo -f video4linux2 -pix_fmt yuv422p12be -s 576x720 -i /dev/video0 out.avi

Above arguments in ffmpeg application are correct?

Please clarify.

  • Please note that in case of user pointer buffer, you will need to allocate the buffers in the user and provide it to the driver. Are you taking care of this?

     

    Regards,

    Brijesh

  • In ffmpeg application,  memory is allocated in mmap_init function.

    static int mmap_init(AVFormatContext *ctx)

    {

         int i, res;
        struct video_data *s = ctx->priv_data;
        struct v4l2_requestbuffers req = {
            .type   = V4L2_BUF_TYPE_VIDEO_CAPTURE,
            .count  = desired_video_buffers,
            .memory = V4L2_MEMORY_USERPTR
        };

        res = v4l2_ioctl(s->fd, VIDIOC_REQBUFS, &req);
        if (res < 0) {
            if (errno == EINVAL) {
                av_log(ctx, AV_LOG_ERROR, "Device does not support mmap\n");
            } else {
                av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n");
            }
            return AVERROR(errno);
        }

        if (req.count < 2) {
            av_log(ctx, AV_LOG_ERROR, "Insufficient buffer memory\n");
            return AVERROR(ENOMEM);
        }
        s->buffers = req.count;
        s->buf_start = av_malloc(sizeof(void *) * s->buffers);
        if (s->buf_start == NULL) {
            av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer pointers\n");
            return AVERROR(ENOMEM);
        }

    s->buf_len = av_malloc(sizeof(unsigned int) * s->buffers);
        if (s->buf_len == NULL) {
            av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer sizes\n");
            av_free(s->buf_start);
            return AVERROR(ENOMEM);
     }

     for (i = 0; i < req.count; i++) {
            struct v4l2_buffer buf = {
                .type   = V4L2_BUF_TYPE_VIDEO_CAPTURE,
                .index  = i,
                .memory = V4L2_MEMORY_MMAP
            };
            res = v4l2_ioctl(s->fd, VIDIOC_QUERYBUF, &buf);
            if (res < 0) {
                av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n");
                return AVERROR(errno);
            }

            s->buf_len[i] = buf.length; //This variable is always zero
            if (s->frame_size > 0 && s->buf_len[i] < s->frame_size) {
                av_log(ctx, AV_LOG_ERROR,
                       "Buffer len [%d] = %d != %d\n",
                       i, s->buf_len[i], s->frame_size);

                return -1;
            }
            s->buf_start[i] = v4l2_mmap(NULL, buf.length,
                                   PROT_READ | PROT_WRITE, MAP_SHARED,
                                   s->fd, buf.m.offset);

            if (s->buf_start[i] == MAP_FAILED) {
                av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", strerror(errno));
                return AVERROR(errno);
            }
        }

        return 0;
    }

    Other than this function in v4lc, any where I need to allocate memory for buffers?

  • Hello,

    Rajeshkumar R said:
    I had face problem in Memory map allocation, in "dma_alloc_coherent" function.  It had failed to allocate dma memory.

    dma_alloc_coherent() returns  pointer to allocated memory on success, NULL on failure

    dma_alloc_coherent() is a Linux kernel API.  It allocates memory suitable for a DMA operation.  The memory would come from somewhere in the physical address space that's granted to the Linux kernel via the u-boot bootargs parameter mem=XX.  .  May be is a  problem with insufficient memory. Check how much MB you are passing, may be is not enough.

    Rajeshkumar R said:
    ffmpeg -vcodec rawvideo -f video4linux2 -pix_fmt yuv422p12be -s 576x720 -i /dev/video0 out.avi

    What is the software release that you are using here?

    Best Regards,

    Margarita

  • What is the software release that you are using here?

    >> I am using the ffmpeg verion 1.1.4.


    DMA Failure Log:

    ti81xxvin ti81xxvin: hdvpss_map_sub_device_to_input
    ti81xxvin ti81xxvin: vidioc_g_std
    ti81xxvin ti81xxvin: vidioc_reqbufs
    ti81xxvin ti81xxvin: ti81xxvin_buffer_setup
    ti81xxvin ti81xxvin: vidioc_querybuf
    ti81xxvin ti81xxvin: ti81xxvin_mmap
    Size 17c000
    Size 17c000
    Mask 1000000 -1
    Dma alocated page
    ti81xxvin ti81xxvin: vidioc_querybuf
    ti81xxvin ti81xxvin: ti81xxvin_mmap
    Size 17c000
    Size 17c000
    Mask 1000000 -1
    Dma alocated page
    ti81xxvin ti81xxvin: vidioc_querybuf
    ti81xxvin ti81xxvin: ti81xxvin_mmap
    Size 17c000
    Size 17c000
    Mask 1000000 -1
    Dma alocated page
    ti81xxvin ti81xxvin: vidioc_querybuf
    ti81xxvin ti81xxvin: ti81xxvin_mmap
    Size 17c000
    Size 17c000
    Mask 1000000 -1
    Dma alocated page
    ti81xxvin ti81xxvin: vidioc_querybuf
    ti81xxvin ti81xxvin: ti81xxvin_mmap
    Size 17c000
    Size 17c000
    Mask 1000000 -1
    Dma alocated page
    ti81xxvin ti81xxvin: vidioc_querybuf
    ti81xxvin ti81xxvin: ti81xxvin_mmap
    Size 17c000
    Size 17c000
    Mask 1000000 -1
    Dma alocated page
    ti81xxvin ti81xxvin: vidioc_querybuf
    ti81xxvin ti81xxvin: ti81xxvin_mmap
    Size 17c000
    Size 17c000
    Mask 1000000 -1
    Dma alocated page
    ti81xxvin ti81xxvin: vidioc_querybuf
    ti81xxvin ti81xxvin: ti81xxvin_mmap
    Size 17c000
    Size 17c000
    Mask 1000000 -1
    Dma alocated page
    VM No Space
    VM return NULL
    (NULL device *): dma_alloc_coherent size 1556480 failed
    ti81xxvin ti81xxvin: ti81xxvin_release

  • how to mention buffer size in user application?

    Regards,

    Rajesh