Skip to content

vpu: decoder: Fix video size in buffer pool configuration#331

Open
evanedstrom wants to merge 1 commit into
Freescale:masterfrom
evanedstrom:fix/vpu-buffer-size
Open

vpu: decoder: Fix video size in buffer pool configuration#331
evanedstrom wants to merge 1 commit into
Freescale:masterfrom
evanedstrom:fix/vpu-buffer-size

Conversation

@evanedstrom
Copy link
Copy Markdown

We encountered a visual artifact similar to what is shown in issue #303. I believe the same issue exists in the buffer pool which was fixed in the decoder in 545502e. I implemented this patch for our product, but believe it has upstream utility as others may encounter this same problem.

This sets video_info.size to min_output_framebuffer_size in the buffer pool, matching what 545502e does for individual output buffers.

imx_vpu_dec_buffer_pool->video_info.size should be the actual
framebuffer size. Including the extra reserved space at the end of the
buffer in video_info.size will confuse downstream and make it think
this space is part of the frame data.
* frame size. The buffer pool size can be larger to include reserved
* space on some SoCs, but advertising it will confuse downstream
* interpretation of the buffer contents. */
imx_vpu_dec_buffer_pool->video_info.size = stream_info->min_output_framebuffer_size;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give an example for such a confusion?

Copy link
Copy Markdown
Author

@evanedstrom evanedstrom Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are on i.MX6, decoding H.264 at 800x480 NV12, pipeline excerpt: "queue ! imxvpudec_h264 ! qtvideosink"

I will use the actual sizes of our scenario as an example:

  • min_output_framebuffer_size = 645120 (Y + UV)
  • min_fb_pool_framebuffer_size = 860160 (Y + UV + 215040 bytes of MvCol data used by the VPU)

The decoder sets the output buffer's logical size to 645120 here:

gst_buffer_set_size(out_frame->output_buffer, imx_vpu_dec->current_stream_info.min_output_framebuffer_size);

Prior to this change, video_info.size is set to 860160 in the buffer pool, the full allocated buffer size. This is wrong because the video frame is not this size.

When downstream doesn't support GstVideoMeta, the decoder uses gst_imx_vpu_dec_copy_output_frame_if_needed() which pulls video_info from the dma buffer pool here:

memcpy(&vpu_video_info, gst_imx_vpu_dec_buffer_pool_get_video_info(imx_vpu_dec->dma_buffer_pool), sizeof(GstVideoInfo));

The subsequent call to gst_video_frame_map() then fails because the buffer's logical size (645120) is smaller than video_info.size (860160) so it thinks the buffer is too small for the frame:

    /* do some sanity checks */
    if (frame->map[0].size < info->size)
      goto invalid_size;

Resulting error:

ERROR                default video-frame.c:181:gst_video_frame_map_id: invalid buffer size 645120 < 860160
ERROR              imxvpudec gstimxvpudec.c:1709:gst_imx_vpu_dec_copy_output_frame_if_needed:<imxvpudech264-0> could not map VPU output video frame

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants