初探GStreamer .

GStreamer,江湖上人稱“PIPELINE式的多媒體處理框架”,在該媒體處理框架將多媒體數據流處理劃分成各種能夠自由組合重用的節點,然後將 節點組合成串行處理的媒體處理鏈。看看下面的命令:


    gst-launch-0.10 filesrc location="concept.mp3" ! decodebin ! alsasink

    UNIX的粉絲們是不是異常眼熟呢?沒錯,就是類似於“ps -ef | grep xxx”那種東西。gst-launch是GStreamer的命令處理瑞士軍刀,用來調試各種plug-ins組成的多媒體處理鏈。而上述短短一行命令,就能實現PC linux上的MP3播放功能,可見GStreamer的設計的簡潔和優美。

    下邊看看GStreamer的基本概念。

    Element :簡單說就是節點。Element的input和output稱爲Pads source pads是指Element的輸出(output), sink pads指Element的輸入(input)。BIN:用以將一組Element以鏈接組成一個邏輯單元,Element的容器,同時也是 Element的子類。PipeLine是一種特定的Top-Level的BIN,PipeLine啓動後,在單獨的線程中運行。下邊是一個典型的 PIPELLINE示例:

    GStreamer的PipeLine示例

    GStreamer定義了幾類Element,Source Element是指只有source pad沒有sink pad的Element,是起始的Element,例如:從文件/網絡讀入多媒體數據。Filter Element有一個sink pad 和src pad同時存在的節點,是中間處理的Element,例如完成convertors, demuxers, muxers and codecs的工作。sink Elemen和source Element相反,只有sink pad,沒有source pad,一個終結的Element,完成像寫入到磁盤、播放到聲卡等工作。

    Bus:Bus負責PipeLine線程和宿主的程序之間的通信,每個PipeLine缺省創建一個Bus。宿主程序有兩種方法是用Bus,第一種是使用 GLib/Gtk+ main loop及gst_bus_add_watch () or gst_bus_add_signal_watch ()事件回調函數機制。第二種是程序通過gst_bus_peek () /gst_bus_poll ()主動檢查Bus中的消息.

    GStreamer的發佈包中分成幾種Plug-ins:GStreamer Core Plugins、GStreamer Base Plugins、GStreamer Good Plugins、GStreamer Ugly Plugins、GStreamer Bad Plugins、GStreamer Non-Linear Multimedia Editing Plugins。其文檔中有詳細描述每種plugins包含哪些Elements,對某種版本的Linux,很可能只包含 Core Plugins、Base Plugins、Good Plugins,其他的plugins基於版權或者架構的理由並不包含在內。

    下面是某種linux上GStreamer的Plug-ins的測試(只作爲技術學習使用的探索):

 

1、播放MP3:不通過,也許需要另外安裝mp3的plug-ins。

[root@localhost shallon]# gst-launch filesrc location="bb.mp3" ! decodebin ! alsasink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
ERROR: from element /GstPipeline:pipeline0/GstFileSrc:filesrc0: Internal data flow error.
Additional debug info:
gstbasesrc.c(2330): gst_base_src_loop (): /GstPipeline:pipeline0/GstFileSrc:filesrc0:
streaming task paused, reason not-linked (-1)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
FREEING pipeline ...


---------------------------------------------------------------------------------------

2、測試語音播放

[root@localhost disk]# gst-launch audiotestsrc ! alsasink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstAudioSinkClock

^CCaught interrupt -- handling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 21179521433 ns.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
FREEING pipeline ...

----------------------------------------------------------------------
3、測試視頻播放

[root@localhost disk]# gst-launch videotestsrc ! xvimagesink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
^CCaught interrupt -- handling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 118018425281 ns.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
FREEING pipeline ...
[root@localhost disk]#

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章