nvidia nx上基于deepstream自定义插件

参考:https://yeping.blog.csdn.net/article/details/116563437?spm=1001.2014.3001.5502
https://blog.csdn.net/quicmous/article/details/116589178?spm=1001.2014.3001.5501
http://ericnode.info/post/gstreamer_intro/

1.下载代码,生成插件模版

git clone https://gitlab.freedesktop.org/gstreamer/gst-template.git
cd gst-template/gst-plugin/src
../tools/make_element MyFilter

2.安装meson build

sudo apt install meson
cd gst-template
meson build

报错

Native dependency gstreamer-1.0 found: NO found '1.14.5' but need: '>=1.19'

修改meson.build文件

#project('gst-template', 'c', version : '1.19.0.1', license : 'LGPL')
project('gst-template', 'c', version : '1.14.5', license : 'LGPL')

plugins_install_dir = join_paths(get_option('libdir'), 'gstreamer-1.0')

cc = meson.get_compiler('c')

gst_version = meson.project_version()
api_version = '1.0'
#gst_dep = dependency('gstreamer-1.0', version : '>=1.19',
gst_dep = dependency('gstreamer-1.0', version : '>=1.14',
    required : true, fallback : ['gstreamer', 'gst_dep'])
#gstbase_dep = dependency('gstreamer-base-1.0', version : '>=1.19',
gstbase_dep = dependency('gstreamer-base-1.0', version : '>=1.14',
  fallback : ['gstreamer', 'gst_base_dep'])
subdir('gst-app')
subdir('gst-plugin')

再编译就正确了。

3.ninja -C build 构建并安装插件

cd gst-template
ninja -C build install

报错:

../gst-plugin/src/gstmyfilter.c:102:41: error: expected ‘)’ before string constant
 GST_ELEMENT_REGISTER_DEFINE (my_filter, "myfilter", GST_RANK_NONE,
                                         ^~~~~~~~~~
../gst-plugin/src/gstmyfilter.c: In function ‘myfilter_init’:
../gst-plugin/src/gstmyfilter.c:266:10: warning: implicit declaration of function ‘GST_ELEMENT_REGISTER’; did you mean ‘GST_ELEMENT_CAST’? [-Wimplicit-function-declaration]
   return GST_ELEMENT_REGISTER (myfilter, myfilter);
          ^~~~~~~~~~~~~~~~~~~~
          GST_ELEMENT_CAST
[2/6] Compiling C object 'gst-plugin/gstaudiofilterexample@sha/src_gstaudiofilter.c.o'.
FAILED: gst-plugin/gstaudiofilterexample@sha/src_gstaudiofilter.c.o 
cc  -Igst-plugin/gstaudiofilterexample@sha -Igst-plugin -I../gst-plugin -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include -I/usr/include/orc-0.4 -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O0 -g -fPIC -pthread -DHAVE_CONFIG_H -MD -MQ 'gst-plugin/gstaudiofilterexample@sha/src_gstaudiofilter.c.o' -MF 'gst-plugin/gstaudiofilterexample@sha/src_gstaudiofilter.c.o.d' -o 'gst-plugin/gstaudiofilterexample@sha/src_gstaudiofilter.c.o' -c ../gst-plugin/src/gstaudiofilter.c
../gst-plugin/src/gstaudiofilter.c:99:51: error: expected ‘)’ before string constant
 GST_ELEMENT_REGISTER_DEFINE (audiofiltertemplate, "audiofiltertemplate",
                                                   ^~~~~~~~~~~~~~~~~~~~~
../gst-plugin/src/gstaudiofilter.c: In function ‘plugin_init’:
../gst-plugin/src/gstaudiofilter.c:311:10: warning: implicit declaration of function ‘GST_ELEMENT_REGISTER’; did you mean ‘GST_ELEMENT_CAST’? [-Wimplicit-function-declaration]
   return GST_ELEMENT_REGISTER (audiofiltertemplate, plugin);
          ^~~~~~~~~~~~~~~~~~~~
          GST_ELEMENT_CAST
../gst-plugin/src/gstaudiofilter.c:311:32: error: ‘audiofiltertemplate’ undeclared (first use in this function); did you mean ‘GstAudioFilterTemplate’?
   return GST_ELEMENT_REGISTER (audiofiltertemplate, plugin);
                                ^~~~~~~~~~~~~~~~~~~
                                GstAudioFilterTemplate
../gst-plugin/src/gstaudiofilter.c:311:32: note: each undeclared identifier is reported only once for each function it appears in
../gst-plugin/src/gstaudiofilter.c:312:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
[3/6] Compiling C object 'gst-plugin/gstplugin@sha/src_gstplugin.c.o'.
FAILED: gst-plugin/gstplugin@sha/src_gstplugin.c.o 
cc  -Igst-plugin/gstplugin@sha -Igst-plugin -I../gst-plugin -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O0 -g -fPIC -pthread -DHAVE_CONFIG_H -MD -MQ 'gst-plugin/gstplugin@sha/src_gstplugin.c.o' -MF 'gst-plugin/gstplugin@sha/src_gstplugin.c.o.d' -o 'gst-plugin/gstplugin@sha/src_gstplugin.c.o' -c ../gst-plugin/src/gstplugin.c
../gst-plugin/src/gstplugin.c:102:47: error: expected ‘)’ before string constant
 GST_ELEMENT_REGISTER_DEFINE (plugin_template, "plugin_template", GST_RANK_NONE,
                                               ^~~~~~~~~~~~~~~~~
../gst-plugin/src/gstplugin.c: In function ‘plugin_init’:
../gst-plugin/src/gstplugin.c:266:10: warning: implicit declaration of function ‘GST_ELEMENT_REGISTER’; did you mean ‘GST_ELEMENT_CAST’? [-Wimplicit-function-declaration]
   return GST_ELEMENT_REGISTER (plugin_template, plugin);
          ^~~~~~~~~~~~~~~~~~~~
          GST_ELEMENT_CAST
../gst-plugin/src/gstplugin.c:266:32: error: ‘plugin_template’ undeclared (first use in this function); did you mean ‘GstPluginTemplate’?
   return GST_ELEMENT_REGISTER (plugin_template, plugin);
                                ^~~~~~~~~~~~~~~
                                GstPluginTemplate
../gst-plugin/src/gstplugin.c:266:32: note: each undeclared identifier is reported only once for each function it appears in
../gst-plugin/src/gstplugin.c:267:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
ninja: build stopped: subcommand failed.

修改:
应该是版本不对应;
注释掉报错的三个GST_ELEMENT_REGISTER_DEFINE();把3个GST_ELEMENT_REGISTER改成:

 return gst_element_register(plugin,"zlfilter",GST_RANK_NONE,GST_TYPE_AUDIO_FILTER_TEMPLATE);
return gst_element_register(plugin, "myplugin", GST_RANK_NONE, GST_TYPE_PLUGIN_TEMPLATE);
return gst_element_register(myfilter, "myfilter", GST_RANK_NONE, GST_TYPE_ELEMENT);

然后编译就成功了

sudo ninja -C build install
ninja: Entering directory `build'
[4/5] Installing files.
Installing gst-plugin/libgstplugin.so to /usr/local/lib/aarch64-linux-gnu/gstreamer-1.0/libgstplugin.so
Installing gst-plugin/libgstaudiofilterexample.so to /usr/local/lib/aarch64-linux-gnu/gstreamer-1.0/libgstaudiofilterexample.so
Installing gst-plugin/libgstmyfilter.so to /usr/local/lib/aarch64-linux-gnu/gstreamer-1.0/libgstmyfilter.so

4.测试

gst-inspect-1.0 build/gst-plugin/libgstplugin.so 
Plugin Details:
  Name                     plugin
  Description              plugin_template
  Filename                 build/gst-plugin/libgstplugin.so
  Version                  1.14.5
  License                  LGPL
  Source module            gst-template-plugin
  Binary package           GStreamer template Plug-ins
  Origin URL               https://gstreamer.freedesktop.org

  myplugin: Plugin

  1 features:
  +-- 1 elements

5.在nx上测试插件
修改一下 etc/profile,定义环境变量 GST_PLUGIN_PATH,在最后加上下面这两行:
GST_PLUGIN_PATH=$GST_PLUGIN_PATH://usr/local/lib/aarch64-linux-gnu/gstreamer-1.0
export GST_PLUGIN_PATH
重启系统后,试一下命令 gst-inspect-1.0 myfilter,查看一下我们写的新元素 myfilter:

gst-inspect-1.0 myfilter
Factory Details:
  Rank                     none (0)
  Long-name                An example plugin
  Klass                    Example/FirstExample
  Description              Shows the basic structure of a plugin
  Author                   your name <your.name@your.isp>

Plugin Details:
  Name                     myfilter
  Description              my_filter
  Filename                 //usr/local/lib/aarch64-linux-gnu/gstreamer-1.0/libgstmyfilter.so
  Version                  1.14.5
  License                  LGPL
  Source module            gst-template-plugin
  Binary package           GStreamer template Plug-ins
  Origin URL               https://gstreamer.freedesktop.org

GObject
 +----GInitiallyUnowned
       +----GstObject
             +----GstElement
                   +----GstMyFilter

Pad Templates:
  SRC template: 'src'
    Availability: Always
    Capabilities:
      ANY
  
  SINK template: 'sink'
    Availability: Always
    Capabilities:
      ANY

Element has no clocking capabilities.
Element has no URI handling capabilities.

Pads:
  SINK: 'sink'
    Pad Template: 'sink'
  SRC: 'src'
    Pad Template: 'src'

Element Properties:
  name                : The name of the object
                        flags: readable, writable
                        String. Default: "myfilter0"
  parent              : The parent of the object
                        flags: readable, writable
                        Object of type "GstObject"
  silent              : Produce verbose output ?
                        flags: readable, writable
                        Boolean. Default: false

再试验一下 gst-launch-1.0 命令:

gst-launch-1.0 fakesrc ! myfilter ! fakesink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
I'm plugged, therefore I'm in.
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
I'm plugged, therefore I'm in.
I'm plugged, therefore I'm in.
I'm plugged, therefore I'm in.
I'm plugged, therefore I'm in.
...

5.nx上deepstream代码中测试该插件
部分代码如下:

int
main (int argc, char *argv[])
{
...
  GstElement *myfilter = NULL;
  myfilter = gst_element_factory_make ("myfilter", "myfilter");
    if (!face_point_detector || !nvvidconv || !nvosd || !sink  || !capfilt
      || !other_four_det || !Vehicle_det || !lpr_sig || !person_class
      || !face_class || !Vehicle_class || !TwoWheeler_class) {
    g_printerr ("One element could not be created. Exiting.\n");
    return -1;
  }
  else if (!myfilter) {
    g_print ("Your self-written filter could not be found. Make sure it "
             "is installed correctly in $(libdir)/gstreamer-1.0/ or "
             "~/.gstreamer-1.0/plugins/ and that gst-inspect-1.0 lists it. "
             "If it doesn't, check with 'GST_DEBUG=*:2 gst-inspect-1.0' for "
             "the reason why it is not being loaded.");
    return -1;
  }
    gst_bin_add_many (GST_BIN (pipeline), face_point_detector, tracker, myfilter,
      queue1, queue2, queue3, queue4, queue5,queue6,queue9, nvvidconv, nvosd, nvtile, sink,
      other_four_det,Vehicle_det,person_class,face_class,Vehicle_class,TwoWheeler_class,NULL);

  if (!gst_element_link_many (streammux, queue1, face_point_detector, queue2,other_four_det,
        queue3,Vehicle_det,person_class,queue4,face_class,Vehicle_class,TwoWheeler_class,
	queue5,nvtile, queue6, nvvidconv, queue9, myfilter,
        nvosd, NULL)) {
    g_printerr ("Inferring and tracking elements link failure.\n");
    return -1;
...
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值