openwrt gstreamer執行個體學習筆記(二.gstreamer 的 Element)

來源:互聯網
上載者:User

標籤:

對程式員來說,GStreamer 中最重要的一個概念就是 GstElement 對象。該對象是構建一個媒體管道的基本塊。所有上層(high-level)組件都源自GstElement對象。任何一個解碼器編碼器、分離器、視頻/音訊輸出組件實際上都是一個 GstElement對象。

對程式員來說,element就像一個黑盒子。你element的一端輸入資料,element對資料進行一些處理,然後資料從element的另一端輸出。拿一個解碼element來說,你輸入一 些有特定編碼的資料,element會輸出相應的解碼資料。

 

Source elements:為管道產生資料,比如從磁碟或者音效卡讀取資料。源元件不接收資料,僅產生資料。

Like Filter elements:同時擁有輸入和輸出pads , 他們對從輸入pads得到的資料進行操作,然後將資料提供給輸出pads。比如過濾器(filters)、轉換器(convertors)、分流器(demuxers)、整流器(muxers)

 

Recv  elements : 接收element是媒體管道的末端,它接收資料但不產生任何資料。寫磁碟、利用音效卡播放聲音以及視頻輸出等都是由接收元件實現的

 

建立一個GstElement對象: 建立一個element的最簡單的方法是通過函數gst_element_factory_make (), 你不再需要一個元件時,你需要使用 gst_object_unref ()來對它進行解引用.

下面的例子顯示了如果通過一個fakesrc工廠對象來建立一個名叫source的元件。程式會檢查元件是否建立成功。檢查完畢後,程式會銷毀元件.

 

#include <gst/gst.h>
int main (int   argc,
      char *argv[])
{
  GstElement *element;

  /* init GStreamer */
  gst_init (&argc, &argv);

  /* create element */
  element = gst_element_factory_make ("fakesrc", "source");
  if (!element) {
    g_print ("Failed to create element of type ‘fakesrc‘\n");
    return -1;
  }
  printf("successful to make element...\n");

  gst_object_unref (GST_OBJECT (element));

  printf("destory the element...\n");

  return 0;

}

 

gst_element_factory_make其實是 gst_element_factory_find () 和 gst_element_factory_create()兩個函數的合體。

gst_element_factory_find ():獲得一個唯一的工廠對象 GstElementFactory對象

gst_element_factory_create() :使用element工廠並根據給定的名字來建立一個element對象。

 

#include <gst/gst.h>

int main (int   argc,

      char *argv[])

{

  GstElementFactory *factory;

  GstElement * element;

  /* init GStreamer */

  gst_init (&argc, &argv);

  /* create element, method #2 */

  factory = gst_element_factory_find ("fakesrc");

  if (!factory) {

    g_print ("Failed to find factory of type ‘fakesrc‘\n");

    return -1;

  }

  element = gst_element_factory_create (factory, "source");

  if (!element) {

    g_print ("Failed to create element, even though its factory exists!\n");

    return -1;

  }

  gst_object_unref (GST_OBJECT (element));

  return 0;

}

 

 

GstElement的屬性大多通過標準的 GObject 對象實現的。使用 GObject 的方法可以對GstElement實行查詢、設定、擷取屬性的值。同樣 GParamSpecs 也被支援。

每個 GstElement 都從其基類 GstObject 繼承了至少一個“名字”屬性。這個名字屬性將在函數gst_element_factory_make ()或者函數gst_element_factory_create ()中使用到。

你可通過函數 gst_object_set_name 設定該屬性,通過 gst_object_get_name 得到一個對象的名字屬性。你也可以通過下面的方法來得到一個對象的名字屬性。

#include <gst/gst.h>

int main (int argc,  char *argv[])
{
  GstElement *element;
  gchar *name;

  /* init GStreamer */
  gst_init (&argc, &argv);

  /* create element */
  element = gst_element_factory_make ("fakesrc", "source");

  /* get name */
  g_object_get (G_OBJECT (element), "name", &name, NULL);
  g_print ("The name of the element is ‘%s‘.\n", name);
  g_free (name);

  gst_object_unref (GST_OBJECT (element));

  return 0;

}

openwrt gstreamer執行個體學習筆記(二.gstreamer 的 Element)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.