gstreamer插件知識總結

gstreamer插件知識總結

1.gstreamer插件內部結構及函數總結

(1)定義插件屬性及信號

enum
{
  /* FILL ME */
  SIGNAL_DETECTED,
  LAST_SIGNAL
};

(2)定義襯墊接收和發送的數據類型

static GstStaticPadTemplate sink_factory...

(3)元件屬性及信號初始化

gst_human_detection_class_init()

屬性初始化樣例:

g_object_class_install_property (gobject_class, PROP_PICTUREPATH,
      g_param_spec_string ("picturePath", "picturePath", "output picturePath",
          "NULL", (GParamFlags)(G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS)));

信號初始化樣例:

gst_human_detection_signals[SIGNAL_DETECTED] =
			g_signal_new ("detected", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
            G_STRUCT_OFFSET (GstHumanDetectionClass, detected), NULL, NULL,
            g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);

(4)元件初始化(在加載或使用元件時進行的初始化)

gst_human_detection_init()

在函數中存放如加載網絡等只需加載一次無需在循環中次次加載的事件。

(5)屬性設置函數

gst_human_detection_set_property()

(6)屬性獲取函數

gst_human_detection_get_property()

(7)運行主函數(視頻流中每一幀圖像都會經過此函數處理)

gst_human_detection_chain()

2.插件內部使用知識

(1)鎖的使用

pthread_mutex_t threadMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&threadMutex);
pthread_mutex_unlock(&threadMutex);

(2)初始化信號

static guint gst_human_detection_signals[LAST_SIGNAL] = { 0 };

(3)獲取視頻流分辨率

int width, height;
GstCaps *caps;
caps = gst_pad_get_current_caps (pad);
GstStructure* structure = gst_caps_get_structure(caps, 0);

gst_structure_get_int(structure, "width", &width);
gst_structure_get_int(structure, "height", &height);
...
gst_caps_unref (caps);

(4)獲取視頻中每幀的圖像

GstMapInfo map;
gst_buffer_map(buf, &map, GST_MAP_READ);
v = Mat(Size(width,height),CV_8UC4,(char *)map.data);
...
memcpy(map.data, v.data, map.size);
gst_buffer_unmap (buf, &map);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章