iT邦幫忙

2026 iThome 鐵人賽

DAY 24
0

每個插件打開時都會顯示漂漂亮亮的資訊欄,而我們生成的模板已經有資訊欄了,只是模板也不知道你要顯示什麼內容,所以會填入一些預設值或是FIXME,今天的任務就是修改這些資訊欄

插件資訊

首先我們打開 gstironmancolormagic.c並滑到最下方

static gboolean
plugin_init (GstPlugin * plugin)
{

  /* FIXME Remember to set the rank if it's an element that is meant
     to be autoplugged by decodebin. */
  return gst_element_register (plugin, "ironmancolormagic", GST_RANK_NONE,
      GST_TYPE_IRONMAN_COLOR_MAGIC);
}

/* FIXME: these are normally defined by the GStreamer build system.
   If you are creating an element to be included in gst-plugins-*,
   remove these, as they're always defined.  Otherwise, edit as
   appropriate for your external plugin package. */
#ifndef VERSION
#define VERSION "0.0.FIXME"
#endif
#ifndef PACKAGE
#define PACKAGE "FIXME_package"
#endif
#ifndef PACKAGE_NAME
#define PACKAGE_NAME "FIXME_package_name"
#endif
#ifndef GST_PACKAGE_ORIGIN
#define GST_PACKAGE_ORIGIN "http://FIXME.org/"
#endif

GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
    GST_VERSION_MINOR,
    ironmancolormagic,
    "FIXME plugin description",
    plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)

讓我們再複習一次,GStreamer運作的基底是元件(Element),而一個插件(Plugin)可以包含數個元件,插件的目標會比較大,而元件則是在這個大目標下拆分出更細的任務。這邊要修改的是「插件」的資訊

欄位說明

  • VERSION 插件的版本號
  • PACKAGE 程式庫的簡易名稱。例如gst-plugins-good
  • PACKAGE_NAME 程式庫的詳細名稱。例如GStreamer Good Plugins
  • GST_PACKAGE_ORIGIN 最初的設計是原始碼的倉庫位置,但隨便寫都行

GST_PLUGIN_DEFINE

定義你的插件,此處會使用上述Macro填入我們所看見的插件資訊欄位,記得要修改這邊的插件描述,內容就是你這個插件可以完成什麼事情。

這邊的plugin_init代表插件的進入點,當GStreamer搜尋插件的時候會執行這個進入點,plugin_init內可以註冊多個元件,所以有時候會看見某些插件的原始碼把GST_PLUGIN_DEFINE分離到一個plugin.c,在該檔案註冊多個元件

修改後

static gboolean
plugin_init (GstPlugin * plugin)
{
  return gst_element_register (plugin, "ironmancolormagic", GST_RANK_NONE,
      GST_TYPE_IRONMAN_COLOR_MAGIC);
}

#ifndef VERSION
#define VERSION "0.0.1"
#endif
#ifndef PACKAGE
#define PACKAGE "ironman-color-plugins"
#endif
#ifndef PACKAGE_NAME
#define PACKAGE_NAME "Ironman Color Plugins"
#endif
#ifndef GST_PACKAGE_ORIGIN
#define GST_PACKAGE_ORIGIN "https://ithelp.ithome.com.tw/users/20183527/ironman/9495"
#endif

GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
    GST_VERSION_MINOR,
    ironmancolormagic,
    "Change the color displayed inside bounding boxes",
    plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)
Plugin Details:
  Name                     ironmancolormagic
  Description              Change the color displayed inside bounding boxes
  Filename                 ./libgstironmancolormagic.so
  Version                  0.0.1
  License                  LGPL
  Source module            ironman-color-plugins
  Binary package           Ironman Color Plugins
  Origin URL               https://ithelp.ithome.com.tw/users/20183527/ironman/9495

  ironmancolormagic: FIXME Long name

  1 features:
  +-- 1 elements

元件資訊

我們可以看到元件旁邊的說明還是FIXME Long name,接下來就是修改這個欄位。先用gst-inspect-1.0看一下元件目前的資訊欄位,讓GST_PLUGIN_PATH加上當前目錄,這樣就可以讓GStreamer從當前目錄尋找元件,當然你也可以安裝到官方定義的搜尋目錄底下/usr/lib/x86_64-linux-gnu/gstreamer-1.0

GST_PLUGIN_PATH=$(pwd) gst-inspect-1.0 ironmancolormagic
Factory Details:
  Rank                     none (0)
  Long-name                FIXME Long name
  Klass                    Generic
  Description              FIXME Description
  Author                   FIXME <fixme@example.com>

Plugin Details:
  Name                     ironmancolormagic
  Description              Change the color displayed inside bounding boxes
  Filename                 /ironman/sources/gst/colormagic/libgstironmancolormagic.so
  Version                  0.0.1
  License                  LGPL
  Source module            ironman-color-plugins
  Binary package           Ironman Color Plugins
  Origin URL               https://ithelp.ithome.com.tw/users/20183527/ironman/9495

GObject
 +----GInitiallyUnowned
       +----GstObject
             +----GstElement
                   +----GstBaseTransform
                         +----GstIronmanColorMagic

在Factory Details這一段還是有FIXME,我們要找到gst_ironman_color_magic_class_init裡面有一行gst_element_class_set_static_metadata,把這邊的欄位修改成你的資訊就可以囉

gst_element_class_set_static_metadata (GST_ELEMENT_CLASS(klass),
      "Ironman Color Magic", "Video/Effect", "Change displayed color inside specific bounding boxes",
      "Justin Yu");
Factory Details:
  Rank                     none (0)
  Long-name                Ironman Color Magic
  Klass                    Video/Effect
  Description              Change displayed color inside specific bounding boxes
  Author                   Justin Yu

Plugin Details:
  Name                     ironmancolormagic
  Description              Change the color displayed inside bounding boxes
  Filename                 /ironman/sources/gst/colormagic/libgstironmancolormagic.so
  Version                  0.0.1
  License                  LGPL
  Source module            ironman-color-plugins
  Binary package           Ironman Color Plugins
  Origin URL               https://ithelp.ithome.com.tw/users/20183527/ironman/9495

GObject
 +----GInitiallyUnowned
       +----GstObject
             +----GstElement
                   +----GstBaseTransform
                         +----GstIronmanColorMagic

結語

透過這篇文章,我相信大家可以很清楚地對照每個欄位該填入什麼資訊,避免初次開發時踩坑,我也是比對了好多元件的資訊欄才能整理出這篇文章的內容,相信修改這些欄位能讓你的插件看起來更專業


上一篇
[Day 23] 產生GStreamer插件的模板
下一篇
[Day 25] 替你的元件新增屬性
系列文
深入認識DeepStream,不只是停在執行範例 共 29 篇
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言