rockchip-linux / mpp

Media Process Platform (MPP) module
602 stars 171 forks source link

Issue: Unable to Achieve maximum FPS with Distorted Image Output on gst-launch-1.0 Pipeline #700

Open smzahraee opened 4 weeks ago

smzahraee commented 4 weeks ago

using rk3528

Issue: Unable to Achieve 60 FPS with Distorted Image Output on gst-launch-1.0 Pipeline

Pipeline Command:

gst-launch-1.0 videotestsrc ! video/x-raw,width=1280,height=720,framerate=60/1 ! mpph264enc ! h264parse ! rtph264pay config-interval=1 pt=96 ! udpsink host=10.42.0.1 port=8554 sync=false

Problem: I am attempting to stream video at 1280x720 resolution with a frame rate of 120 fps using the above gst-launch-1.0 pipeline. However, I'm facing two issues:

  1. Frame rate issue: The output does not reach the expected 60 fps.
  2. Image quality issue: The streamed image appears distorted or incorrect.

Could you please help identify possible causes or suggest configurations that might resolve these issues?

image

HermanChen commented 3 weeks ago

it seems a cache issue for using cpu copy pixel data

smzahraee commented 3 weeks ago

I also checked /proc/meminfo, mpp doesn't use the cma area. I enabled kernel CMA but I face the following problem:

0.000000] Hardware name: Rockchip (Device Tree)
[    0.000000] [<b000f50d>] (unwind_backtrace) from [<b000e027>] (show_stack+0xb/0xc)
[    0.000000] [<b000e027>] (show_stack) from [<b0646449>] (memblock_alloc_range_nid+0x29/0x98)
[    0.000000] [<b0646449>] (memblock_alloc_range_nid) from [<b06471ef>] (cma_declare_contiguous_nid+0x123/0x17c)
[    0.000000] [<b06471ef>] (cma_declare_contiguous_nid) from [<b0643e47>] (dma_contiguous_reserve_area+0x27/0x4c)
[    0.000000] [<b0643e47>] (dma_contiguous_reserve_area) from [<b0643e9d>] (dma_contiguous_reserve+0x31/0x40)
[    0.000000] [<b0643e9d>] (dma_contiguous_reserve) from [<b0640609>] (arm_memblock_init+0x7d/0xe0)
[    0.000000] [<b0640609>] (arm_memblock_init) from [<b063fbd1>] (setup_arch+0xe1/0x324)
[    0.000000] [<b063fbd1>] (setup_arch) from [<b063d889>] (start_kernel+0x35/0x350)
[    0.000000] [<b063d889>] (start_kernel) from [<00000000>] (0x0)
[    0.000000] cma: Failed to reserve 0 KiB
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x000000000fffffff]
[    0.000000] Movable zone start for each node"
smzahraee commented 3 weeks ago

is there a way to enable rk-dma-heap-cma for mpp? it seems that it does not use it.

HermanChen commented 3 weeks ago

Check .config for CONFIG_DMABUF_HEAPS_ROCKCHIP ? system-heap is more commonly used.

smzahraee commented 3 weeks ago

I'm not sure why, but enabling only CONFIG_DMABUF_HEAPS_ROCKCHIP doesn’t make the encoder work.

 ./mpi_enc_test -t 7 -w 480 -h 272 -i ./ds_480x272.yuv -o t1.h264
mpp[239]: mpi_enc_utils: cmd parse result:
mpp[239]: mpi_enc_utils: input  file name: ./ds_480x272.yuv
mpp[239]: mpi_enc_utils: output file name: t1.h264
mpp[239]: mpi_enc_utils: width      : 480
mpp[239]: mpi_enc_utils: height     : 272
mpp[239]: mpi_enc_utils: format     : 0
mpp[239]: mpi_enc_utils: type       : 7
mpp[239]: mpi_enc_test: ./mpi_enc_test start
mpp[239]: mpp_rt: can NOT found any allocator
mpp[239]: mpp_log: allocator_std_open Warning: std allocator should be used on simulation mode only
mpp[239]: mpp_buffer: mpp_buffer_group_init leave
mpp[239]: mpp_buffer: mpp_buffer_get_unused enter
mpp[239]: mpp_buffer: mpp_buffer_get_unused leave
mpp[239]: mpp_buffer: mpp_buffer_create enter
mpp[239]: mpp_log: allocator_std_alloc Warning: std allocator should be used on simulation mode only
mpp[239]: mpp_buffer: mpp_buffer_create failed to create buffer with size 245760
mpp[239]: mpp_buffer: mpp_buffer_create leave
mpp[239]: mpi_enc_test: enc_test failed to get buffer for input frame ret -1
mpp[239]: mpp_buffer: mpp_buffer_group_deinit enter
mpp[239]: mpp_buffer: mpp_buffer_group_deinit leave
mpp[239]: mpi_enc_test: chn 0 encode 0 frames time 0 ms delay   0 ms fps 0.00 bps 0
mpp[239]: mpi_enc_test: ./mpi_enc_test average frame rate 0.00

it seems that it creates /dev/rk_dma_heap/ but mpp needs/dev/dma_heap

The following configurations are also needed to get it working, but with these settings, I end up with a distorted image. extra configuration that I set:

CONFIG_DMABUF_HEAPS=y
CONFIG_DMABUF_SYSFS_STATS=y
CONFIG_DMABUF_HEAPS_DEFERRED_FREE=y
CONFIG_DMABUF_HEAPS_PAGE_POOL=y
CONFIG_DMABUF_HEAPS_SYSTEM=y
CONFIG_DMABUF_HEAPS_CMA=y
HermanChen commented 3 weeks ago

Try remove -i option and mpi_enc_test will draw a color bar for test.

smzahraee commented 3 weeks ago

here is the default pattern image

smzahraee commented 3 weeks ago

I checked the /proc/meminfo it seems that it does not use the cma

HermanChen commented 3 weeks ago

The luma part is correct and the chroma part has error. Is the buffer size enough for w h 3 / 2?

HermanChen commented 3 weeks ago

Or there is something corrupt the chroma part memory

smzahraee commented 3 weeks ago

Where can I check the image buffer size in mpp? is there any env variable for that?

HermanChen commented 2 weeks ago

For encoder the image buffer is not provided by mpp. The image buffer is from outside the mpp encoder.

smzahraee commented 2 weeks ago

As I tested, the board can not start encoding without heap DMA, which will be enabled by those kernel configs that I mentioned earlier configs. if you look at the MppRuntimeService, it tries to allocate memory from one of the followings:

my CPU doesn't have DRI(GPU) and ion(Android-specific), so I have to allocate buffers from DMA or CMA.

As I tested mpp tries to get buffers from /dev/dma_heap which is a generic Linux kernel driver. and it doesn't care about rk-dma-heap-cma that already exists in rockchip kernel driver!