初探GStreamer

    近日准备把linux手机平台上的各大软件模块都浮光掠影蜻蜓点水的学习一遍,今天看到了多媒体处理模块,不得不去学习一下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]#

  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值