ffmedia开发库中demo程序实现多窗口(叠加)出现闪烁,请问是什么原因

固件类型:官方提供的固件
固件文件名称:ROC-RK3568-PC-TF-HDMI-MIPI-RK628_Ubuntu20.04-r240_
固件下载地址:百度网盘 请输入提取码
Log日志:log.zip

开发板:ROC-RK3568-PC
操作系统:官方Ubuntu20.04
ffmedia库版本:V2.1.2
ffmedia下载地址:Firefly-Linux / ffmedia_release · GitLab

应用程序:基于ffmedia代码/demo/demo_multi_window.cpp 修改实现两个window显示

关键代码:
rtsp_c = make_shared(“rtsp://192.168.110.140:5544/live/0”);
ret = rtsp_c->init();
if (ret < 0) {
ff_error(“rtsp client init failed\n”);
return ret;
}

// 2. dec module
input_para = rtsp_c->getOutputImagePara();
dec = make_shared<ModuleMppDec>(input_para);
dec->setProductor(rtsp_c);
ret = dec->init();
if (ret < 0) {
    ff_error("Dec init failed\n");
    return ret;
}

// 3. drm display module
input_para = dec->getOutputImagePara();

shared_ptr<DrmDisplayPlane> plane = make_shared<DrmDisplayPlane>(V4L2_PIX_FMT_NV12, 0);
//plane->setRect(100, 100, 1600, 800);
plane->setRect(0, 0, 1920, 1080);
// plane->setWindowLayoutMode(DrmDisplayPlane::RELATIVE_LAYOUT);
plane->setWindowLayoutMode(DrmDisplayPlane::ABSOLUTE_LAYOUT);
//plane->splitPlane(3, 3);

// for (int i = 0; i < 16; i++) {
for (int i = 0; i < 2; i++) {
    windows[i] = make_shared<ModuleDrmDisplay>(input_para, plane);
    windows[i]->setProductor(dec);
    windows[i]->init();
}

windows[0]->setWindowRect(0, 0, 1920, 1080);
windows[0]->setWindowVisibility(true);

windows[1]->setWindowRect(100, 100, 960, 540);
windows[1]->setWindowVisibility(true);

运行效果:

screen -small-original.gif

问题描述:
运行后叠加的画面会出现闪烁,麻烦大佬帮忙分析下原因,非常感谢!

tchip_askquestions
log.zip (643 Bytes)

设置drm模块的z轴值(void setPlanePara(uint32_t fmt, uint32_t plane_zpos);),可参看demo.cpp或demo_multi_drmplane.cpp设置,谁要显示在前面谁的zpos就大,相同的zpos会相互覆盖显示区域,所以看起来就一闪一闪的

dengkx 发表于 2023-9-6 11:08
设置drm模块的z轴值(void setPlanePara(uint32_t fmt, uint32_t plane_zpos);),可参看demo.cpp或demo_multi …

大佬,按照以上方法测试还是存在闪烁问题,麻烦再帮忙看下是什么原因

代码1:可运行,但图像闪烁

   /////程序1

	input_para = dec->getOutputImagePara();

    shared_ptr<DrmDisplayPlane> plane = make_shared<DrmDisplayPlane>();
    shared_ptr<DrmDisplayPlane> plane2 =make_shared<DrmDisplayPlane>();

    windows[0] = make_shared<ModuleDrmDisplay>(input_para, plane);
    windows[0]->setPlanePara(V4L2_PIX_FMT_NV12, 0xff);
    windows[0]->setPlaneRect(0, 0, 1200, 800);
    windows[0]->setProductor(dec);
    windows[0]->init();

    windows[1] = make_shared<ModuleDrmDisplay>(input_para, plane2);
    windows[1]->setPlanePara(V4L2_PIX_FMT_NV12, 0xf0);
    windows[1]->setPlaneRect(0, 0, 1920, 1080);
    windows[1]->setProductor(dec);
    windows[1]->init();

    windows[0]->setWindowRect(0, 0, 960, 540);
    windows[0]->setWindowVisibility(true);

    windows[1]->setWindowRect(0, 0, 1920, 1080);
    windows[1]->setWindowVisibility(true);

	

代码2:运行报错
错误信息:

root@firefly:/home/firefly/code/ffmedia_release/build# ./demo_multi_window
Firefly FFMedia: v2.1.2
INFO: ff_media: connectToServer: connected to server 192.168.110.140:5544
INFO: ff_media: RTPSource: RTPSock current buffer size is(425984)
INFO: 16ModuleRtspClient: init: rtsp para w h: 1920 1080, ws hs: 1920 1080, format: H265
INFO: 15DrmDisplayPlane: setupDisplayDevice: 0 0
INFO: 15DrmDisplayPlane: setupDisplayDevice: conn_id = 149 enc_id = 150 crtc_id = 71
INFO: 15DrmDisplayPlane: setup: plane_id = 101
INFO: 15DrmDisplayPlane: setup: plane_id = -1
ERROR: 15DrmDisplayPlane: setup: drmModeSetPlane failed, ret -2
rga_api version 1.3.0_[0] (RGA is compiling with meson base: $PRODUCT_BASE)
INFO: 16ModuleDrmDisplay: setupWindow: input NV12 0 0 1920 1080 2304 1088
INFO: 16ModuleDrmDisplay: setupWindow: INFO: 16ModuleDrmDisplay: setupWindow: input NV12 0 0 1920 1080 2304 1088
INFO: 16ModuleDrmDisplay: setupWindow: output Unknow V4L2 Format 0 0 1920 1080 1920 1080
output NV12 0 0 960 540 1920 1080
INFO: 10MppDecoder: getTimeoutSample: 0x555e1de040 frame info changed 1 error 0 discard 0
Segmentation fault
/////程序2
	input_para = dec->getOutputImagePara();

    shared_ptr<DrmDisplayPlane> plane = make_shared<DrmDisplayPlane>();

    windows[0] = make_shared<ModuleDrmDisplay>(input_para, plane);
    windows[0]->setPlanePara(V4L2_PIX_FMT_NV12, 0xff);
    windows[0]->setPlaneRect(0, 0, 1200, 800);
    windows[0]->setProductor(dec);
    windows[0]->init();

    windows[1] = make_shared<ModuleDrmDisplay>(input_para, plane);
    windows[1]->setPlanePara(V4L2_PIX_FMT_NV12, 0xf0);
    windows[1]->setPlaneRect(0, 0, 1920, 1080);
    windows[1]->setProductor(dec);
    windows[1]->init();

    windows[0]->setWindowRect(0, 0, 960, 540);
    windows[0]->setWindowVisibility(true);

    windows[1]->setWindowRect(0, 0, 1920, 1080);
    windows[1]->setWindowVisibility(true);

Valerian0 发表于 2023-9-6 22:44
大佬,按照以上方法测试还是存在闪烁问题,麻烦再帮忙看下是什么原因

代码1:可运行,但图像闪烁

z轴好像是有限制的,你设置一个4,另一个设置5 看看

dengkx 发表于 2023-9-7 09:36
z轴好像是有限制的,你设置一个4,另一个设置5 看看

改成4和5程序会报错,只有设置成0xff这种才行,但就是会闪烁,换了一个新版的固件也是报错,是不是哪里没有配置对?

报错信息:

Firefly FFMedia: v2.1.2
INFO: ff_media: connectToServer: connected to server 192.168.110.140:5544
INFO: ff_media: RTPSource: RTPSock current buffer size is(425984)
INFO: 16ModuleRtspClient: init: rtsp para w h: 1920 1080, ws hs: 1920 1080, format: H265
INFO: 15DrmDisplayPlane: setupDisplayDevice: 0 0
INFO: 15DrmDisplayPlane: setupDisplayDevice: conn_id = 149 enc_id = 150 crtc_id = 71
INFO: 15DrmDisplayPlane: setup: plane_id = -1
ERROR: 15DrmDisplayPlane: setup: drmModeSetPlane failed, ret -2
INFO: 15DrmDisplayPlane: setupDisplayDevice: 0 0
INFO: 15DrmDisplayPlane: setupDisplayDevice: conn_id = 149 enc_id = 150 crtc_id = 71
INFO: 15DrmDisplayPlane: setup: plane_id = 101
rga_api version 1.3.0_[0] (RGA is compiling with meson base: $PRODUCT_BASE)
INFO: 16ModuleDrmDisplay: setupWindow: input NV12 0 0 1920 1080 2304 1088
INFO: 16ModuleDrmDisplay: setupWindow: output Unknow V4L2 Format 0 0 960 540 1216 800
INFO: 16ModuleDrmDisplay: setupWindow: input NV12 0 0 1920 1080 2304 1088
INFO: 16ModuleDrmDisplay: setupWindow: output NV12 0 0 1920 1080 1920 1080
INFO: 10MppDecoder: getTimeoutSample: 0x5594e6a040 frame info changed 1 error 0 discard 0
Segmentation fault

Valerian0 发表于 2023-9-7 23:23
改成4和5程序会报错,只有设置成0xff这种才行,但就是会闪烁,换了一个新版的固件也是报错,是不是哪里没 …

用demo 的-z 选项设置看看行不行?

dengkx 发表于 2023-9-8 09:12
用demo 的-z 选项设置看看行不行?

-z 值为255可以运行,跟之前代码一样,但其他值就会报错了
能运行命令:
./demo rtsp://192.168.110.140:5544/live/0 -o 1920x1080 -d 0 -z 255
报错的命令:
./demo rtsp://192.168.110.140:5544/live/0 -o 1920x1080 -d 0 -z 5
报错信息:

root@firefly:/home/firefly/code/ffmedia_release/build# ./demo rtsp://192.168.110.140:5544/live/0 -o 1920x1080 -d 0 -z 5
Firefly FFMedia: v2.1.2
INFO: ff_media: start_instance:

==========================================
INFO: ff_media: start_instance: enable rtsp client
INFO: ff_media: connectToServer: connected to server 192.168.110.140:5544
INFO: ff_media: RTPSource: RTPSock current buffer size is(425984)
INFO: 16ModuleRtspClient: init: rtsp para w h: 1920 1080, ws hs: 1920 1080, format: H265
INFO: 15DrmDisplayPlane: setupDisplayDevice: 0 0
INFO: 15DrmDisplayPlane: setupDisplayDevice: conn_id = 149 enc_id = 150 crtc_id = 71
INFO: 15DrmDisplayPlane: setup: plane_id = -1
ERROR: 15DrmDisplayPlane: setup: drmModeSetPlane failed, ret -2
ERROR: ff_media: start_instance: drm display init failed
==================Summary================
ModuleRtspClient (In Full: 0, Out Empty: 0)
   |--->ModuleMppDec (In Full: 0, Out Empty: 0)
           |--->ModuleDrmDisplay (In Full: 0, Out Empty: 0)

Valerian0 发表于 2023-9-9 17:13
-z 值为255可以运行,跟之前代码一样,但其他值就会报错了
能运行命令:
./demo rtsp://192.168.110.14 …

代码先不设置。直接在外部设置图层的zpos值看看行不行:
modetest -M rockchip -aw 105:zpos:0 // :zpos:

# 图层 id 可以使用下面命令查看
root@firefly:/home/firefly# cat /sys/kernel/debug/dri/0/state | grep plane
plane[54]: Esmart0-win0
plane[71]: Esmart1-win0
plane[88]: Esmart2-win0
plane[105]: Esmart3-win0
plane[122]: Cluster0-win0
plane[136]: Cluster1-win0
plane[150]: Cluster2-win0
plane[164]: Cluster3-win0

本帖最后由 Valerian0 于 2023-9-12 23:52 编辑

dengkx 发表于 2023-9-12 16:27
代码先不设置。直接在外部设置图层的zpos值看看行不行:
modetest -M rockchip -aw 105:zpos:0 // :zpos …

感谢大佬指点,现在可以实现图像叠加了,但有个小问题,需要传不同的plane值才能叠加,没法使用同一个plane_id不同plane_zpos值进行叠加,麻烦再帮忙分析一下,多谢!
可叠加代码(plane_id不同):

不能叠加的代码(plane_id相同):

补充信息:

root@firefly:/sys/kernel/debug/dri/0# cat state | grep plane
plane[57]: Smart0-win0
plane[73]: Smart1-win0
plane[87]: Esmart1-win0
plane[101]: Esmart0-win0
plane[115]: Cluster0-win0
plane[129]: Cluster1-win0
        planes_changed=1
        plane_mask=21
root@firefly:/home/firefly/code/ffmedia_release/build# modetest -M rockchip -aw 87:zpos:0
failed to set PLANE 87 property zpos to 0: Success
root@firefly:/home/firefly/code/ffmedia_release/build# modetest -M rockchip -aw 87:zpos:1
failed to set PLANE 87 property zpos to 1: Success
root@firefly:/home/firefly/code/ffmedia_release/build# modetest -M rockchip -aw 87:zpos:5
failed to set PLANE 87 property zpos to 5: Success

dengkx 发表于 2023-9-12 16:27
代码先不设置。直接在外部设置图层的zpos值看看行不行:
modetest -M rockchip -aw 105:zpos:0 // :zpos …

大佬,麻烦看下上个回复,这个zpos是暂时不支持么?目前我们这边需要实现多个窗口叠加

Valerian0 发表于 2023-9-17 19:35
大佬,麻烦看下上个回复,这个zpos是暂时不支持么?目前我们这边需要实现多个窗口叠加

本来就是不同图层才能叠加,同个图层怎么叠加?

dengkx 发表于 2023-9-18 09:08
本来就是不同图层才能叠加,同个图层怎么叠加?

哦,这下懂了,那个zpos是用来指定不同图层的顺序的,多谢!

dengkx 发表于 2023-9-18 09:08
本来就是不同图层才能叠加,同个图层怎么叠加?

大佬,再请教一下,我现在要实现16个图层的叠加,怎么添加更多的plane ?

Valerian0 发表于 2023-9-22 09:46
大佬,再请教一下,我现在要实现16个图层的叠加,怎么添加更多的plane ?

图层是硬件固定了,需要硬件支持那么多图层才可以,一般也用不到那么多图层相互叠加,都是用一个图层,使用他的不同区域来显示,

dengkx 发表于 2023-9-22 15:34
图层是硬件固定了,需要硬件支持那么多图层才可以,一般也用不到那么多图层相互叠加,都是用一个图层,使 …

使用一个图层的不同区域显示就没法做到两个图像有一部分重合的效果,就会出现闪烁,这边的需求是要实现多个图像叠加,会有部分图像重合的情况,所以有其他方式可以实现么?

Valerian0 发表于 2023-9-22 16:13
使用一个图层的不同区域显示就没法做到两个图像有一部分重合的效果,就会出现闪烁,这边的需求是要实现多 …

cat /sys/kernel/debug/dri/0/state | grep plane 这个就是查看有多少个图层

dengkx 发表于 2023-9-22 16:44
cat /sys/kernel/debug/dri/0/state | grep plane 这个就是查看有多少个图层

目前使用上述命令查到了图层数量,可用的只有两个,我这边实际需要做16个图像的叠加,两个图层是不够用的,如果不能增加图层,请问有其他方式实现图像叠加么,现在要支持最多16路图像的叠加。

另外,我试了下rga 模块的图像混合功能,但那个也只能混合两个图像,并且是图像的混合运算,不能实现像两个图层那样覆盖的效果