25

DeepStream5.0系列之动态增减输入源

 3 years ago
source link: https://blog.csdn.net/zong596568821xp/article/details/111933083
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

点击查看系列文章目录

从 DS4.0 开始就调试了 deepstream 动态增减源的功能,好长时间没接触,又生疏了。好记性不如烂笔头,趁着今天回顾代码,把过程记录一下

1 先跑起来

NVIDIA 官方其实已经发布过 runtime_source_add_delete 模块,见 https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps

我们先把他跑起来,然后我再介绍一下这代码的思路,以及我调试过程中遇到的一些问题

在 /opt/nvidia/deepstream/deepstream-5.0/source/app/samples 路径下克隆工程

make 完生成可执行文件,可以使用以下下边的方式测试

$ ./deepstream-test-rt-src-add-del file:///opt/nvidia/deepstream/deepstream-5.0/samples/streams/sample_1080p_h264.mp4

运行起来后的效果是:每隔 10s 新增一路输入,通过 tiler 模式显示,最多增加到 4 路,然后开始每隔 10s 删除一路,直到删完后,结束整个进程。

2 实现思路

在 deepstream_test_rt_src_add_del.c 中,首先会创建一条 pipeline,顺序如下

uridecodebin -> streammux -> pgie -> tracker -> sgie1 -> sgie2 -> sgie3 -> tiler -> nvvideoconvert -> nvosd -> sink

然后增加一个定时函数, 

g_timeout_add_seconds (10, add_sources, (gpointer) g_source_bin_list);

表示每隔 10s 执行一遍 add_sources 函数,进入该函数

如代码中说明的,当达到设置的最大输入数量时,结束新增,开始删除,也是通过 g_timeout_add_seconds 定时任务,进入 delete_source 函数来完成

delete_source 函数主要是对列表的一些判断,真正执行删除的是 stop_release_source 函数

原理其实很简单,关于动态替换 element 的过程,我在 gstreamer 专栏中有过介绍,可以参考《Gstreamer应用开发手册14:替换管道元件

经过上述的步骤,可以初步实现一个对视频文件源的动态增减,但是我在输入 rtsp 执行删除操作的时候会报错如下

这个问题我曾经在论坛中提问过,可惜没得到好的解决方案

https://forums.developer.nvidia.com/t/error-happend-when-run-runtime-source-add-delete/115285

在论坛中查了一下类似的问题,大概原因是说 rtsp 输入不支持暂停等操作,如下

https://forums.developer.nvidia.com/t/delete-source-dynamically-error/146830/7

这里提供一个“暴力”的方法,就是注释掉 bus_call 里边的 g_main_loop_quit (loop) 函数,也能运行起来,但依然会输出相关的错误信息。

另外一种方法是修改 rtsp source bin 的源码,因为涉及的内容比较细且通用,我会在另外一边博文中介绍,参考《DeepStream5.0系列之修改rtsp source源码》。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK