【GStreamer开发】GStreamer播放教程07——自定义playbin2的sink
目标
通过手动选择音频和视频的sink,playbin2可以进一步定制。这允许使用playbin2的应用在解码后可以自行做最终的渲染和显示。本教程展示了:
如何替换playbin2选择的sink
如何使用一个复杂的pipeline来作为sink
介绍
playbin2有两个属性:audio-sink和video-sink。应用只需要实例化合适的element然后通过这两个属性传给playbin2就行了。
这个方法只能使用一个简单地element来做sink。如果遇到的情况不是简单地element而是一个复杂的pipeline呢(比如均衡器加一个音频sink),就需要用Bin来包装一下,让playbin2感觉还是一个element。
一个Bin就是一个容器,可以容纳一部分的pipeline,但操作的时候作为一个element。例如,我们在所有教程里面用得GstPipeline就是一个不会和外面的element做交互的GstBin。在Bin里面的element通过虚拟Pad(Ghost Pads)来和外面的element交互。这也就是说,Bin上得一个pad仅仅实现把外面的element上的pad的数据传到内部的element的pad上。
GstBin也是element的一类,所以element可以用的地方,Bin也都能用,特别是,可以作为playbin2的sink。
一个均衡的播放器
- #include <gst/gst.h>
- int main(int argc, charchar *argv[]) {
- GstElement *pipeline, *bin, *equalizer, *convert, *sink;
- GstPad *pad, *ghost_pad;
- GstBus *bus;
- GstMessage *msg;
- /* Initialize GStreamer */
- gst_init (&argc, &argv);
- /* Build the pipeline */
- pipeline = gst_parse_launch ("playbin2 uri=http://docs.gstreamer.com/media/sintel_trailer-480p.webm", NULL);
- /* Create the elements inside the sink bin */
- equalizer = gst_element_factory_make ("equalizer-3bands", "equalizer");
- convert = gst_element_factory_make ("audioconvert", "convert");
- sink = gst_element_factory_make ("autoaudiosink", "audio_sink");
- if (!equalizer || !convert || !sink) {
- g_printerr ("Not all elements could be created.\n");
- ;
- }
- /* Create the sink bin, add the elements and link them */
- bin = gst_bin_new ("audio_sink_bin");
- gst_bin_add_many (GST_BIN (bin), equalizer, convert, sink, NULL);
- gst_element_link_many (equalizer, convert, sink, NULL);
- pad = gst_element_get_static_pad (equalizer, "sink");
- ghost_pad = gst_ghost_pad_new ("sink", pad);
- gst_pad_set_active (ghost_pad, TRUE);
- gst_element_add_pad (bin, ghost_pad);
- gst_object_unref (pad);
- /* Configure the equalizer */
- 4.0, NULL);
- 4.0, NULL);
- /* Set playbin2's audio sink to be our sink bin */
- g_object_set (GST_OBJECT (pipeline), "audio-sink", bin, NULL);
- /* Start playing */
- gst_element_set_state (pipeline, GST_STATE_PLAYING);
- /* Wait until error or EOS */
- bus = gst_element_get_bus (pipeline);
- msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
- /* Free resources */
- if (msg != NULL)
- gst_message_unref (msg);
- gst_object_unref (bus);
- gst_element_set_state (pipeline, GST_STATE_NULL);
- gst_object_unref (pipeline);
- ;
- }
工作流程
- /* Create the elements inside the sink bin */
- equalizer = gst_element_factory_make ("equalizer-3bands", "equalizer");
- convert = gst_element_factory_make ("audioconvert", "convert");
- sink = gst_element_factory_make ("autoaudiosink", "audio_sink");
- if (!equalizer || !convert || !sink) {
- g_printerr ("Not all elements could be created.\n");
- ;
- }
生成所有的sink bin所需要的element。我们使用了一个equalizer-3bands和一个autoaudiosink,中间还用audioconvert连接起来。
- /* Create the sink bin, add the elements and link them */
- bin = gst_bin_new ("audio_sink_bin");
- gst_bin_add_many (GST_BIN (bin), equalizer, convert, sink, NULL);
- gst_element_link_many (equalizer, convert, sink, NULL);
这几句把新的element加到Bin里面然后连接起来,就和在pipeline中一样。
- pad = gst_element_get_static_pad (equalizer, "sink");
- ghost_pad = gst_ghost_pad_new ("sink", pad);
- gst_pad_set_active (ghost_pad, TRUE);
- gst_element_add_pad (bin, ghost_pad);
- gst_object_unref (pad);
现在我们需要生成虚拟Pad,这也一部分在Bin里面的pipeline可以连接到外面。这个虚拟Pad会和内部的一个element的Pad连接起来,我们会用gst_element_get_static_pad()来获得这个Pad。如果是一个RequestPad而不是Always
Pad的话,那么我们就用get_element_request_pad()方法,具体请参考《GStreamer基础教程07——多线程和Pad的有效性》
虚拟Pad用gst_ghost_pad_new()来创建,用gst_pad_set_active()来激活。然后用gst_element_add_pad()来加入Bin。
最后,我们用gst_object_unref()来释放获得的均衡器的sink pad。
在这点上,我们有一个有sink功能的Bin,可以在playbin2里面用作音频sink,我们只需要设置一下playbin2的相关属性就行了。
- /* Set playbin2's audio sink to be our sink bin */
- g_object_set (GST_OBJECT (pipeline), "audio-sink", bin, NULL);
这和用一个sink element设置playbin2的audio-sink属性是完全一样的。
- /* Configure the equalizer */
- 4.0, NULL);
- 4.0, NULL);
剩下的就是均衡器的配置了。在这个例子中,两个高频波段设置了最大的衰减,这样就增强了低音修改不同的值来实际看看效果。
【GStreamer开发】GStreamer播放教程07——自定义playbin2的sink的更多相关文章
- 新手编译开发OpenWrt入门教程(自定义固件、ubuntu学习)
转自: http://www.znck007.com/forum.php?mod=viewthread&tid=21571 由于openwrt编译教程资料很多,不同的cpu芯片只需要选择对 ...
- 【GStreamer开发】GStreamer基础教程13——播放速度
目标 快进,倒放和慢放是trick模式的共同技巧,它们有一个共同点就是它们都修改了播放的速度.本教程会展示如何来获得这些效果和如何进行逐帧的跳跃.主要内容是: 如何来变换播放的速度,变快或者变慢,前进 ...
- 【GStreamer开发】GStreamer基础教程14——常用的element
目标 本教程给出了一系列开发中常用的element.它们包括大杂烩般的eleemnt(比如playbin2)以及一些调试时很有用的element. 简单来说,下面用gst-launch这个工具给出一个 ...
- 【GStreamer开发】GStreamer基础教程10——GStreamer工具
目标 GStreamer提供了一系列方便使用的工具.这篇教程里不牵涉任何代码,但还是会讲一些有用的内容: 如何在命令行下建立一个pipeline--完全不使用C 如何找出一个element的Capab ...
- 【GStreamer开发】GStreamer基础教程15——继承Clutter
目标 Clutter是一个开源的库,用来创建快速.可移植和动态的GUI.GStreamer可以通过cluttersink这个element把clutter集成进来,允许视频像纹理一样使用.本教程会展示 ...
- 【GStreamer开发】GStreamer基础教程12——流
目标 直接播放Internet上的文件而不在本地保存就被称为流播放.我们在前面教程里已经这样做过了,使用了http://的URL.本教程展示的是在播放流的时候需要记住的几个点,特别是: 如何设置缓冲 ...
- 【GStreamer开发】GStreamer基础教程05——集成GUI工具
目标 本教程展示了如何在GStreamer集成一个GUI(比如:GTK+).最基本的原则是GStreamer处理多媒体的播放而GUI处理和用户的交互. 在这个教程里面,我们可以学到: 如何告诉GStr ...
- 【GStreamer开发】GStreamer基础教程08——pipeline的快捷访问
目标 GStreamer建立的pipeline不需要完全关闭.有多种方法可以让数据在任何时候送到pipeline中或者从pipeline中取出.本教程会展示: 如何把外部数据送到pipeline中 如 ...
- gstreamer应用开发(播放器)之旅
GStreamer开发,主要分为两块:应用开发.插件开发. 插件开发人员,通常是编解码库的作者(做出了编解码库后,希望gstreamer能用起来这个库,因此增加这个适配层).芯片原厂人员(将自家的hw ...
随机推荐
- shell命令的原理
https://blog.csdn.net/m0_37925202/article/details/80258974 https://blog.csdn.net/a15929748502/articl ...
- (19)打鸡儿教你Vue.js
了解vue2.x的核心技术 建立前端组件化的思想 常用的vue语法 vue-router,vuex,vue-cli 使用vue-cli工具 Vue框架常用知识点 vue核心技术 集成Vue 重点看,重 ...
- Three.js中的div标签跟随(模型弹框)
目录 Three.js中的div标签跟随(模型弹框) 参考官方案例 核心渲染器 用法 注意事项 Three.js中的div标签跟随(模型弹框) 参考官方案例 核心渲染器 three.js-master ...
- for循环实战性能优化之使用Map集合优化
笔者在<for循环实战性能优化>中提出了五种提升for循环性能的优化策略,这次我们在其中嵌套循环优化小循环驱动大循环的基础上,借助Map集合高效的查询性能来优化嵌套for循环 ...
- 简要介绍 X Window System (又称为X11 or X)
X11是一个应用程序,而不是一个操作系统,主要功能是提供图形界面,实现架构和网络架构相同,有X Client和X Server组件,另外还有Window Manager和Display Manager ...
- etcd,flannel,docker relationship---and k8s
journalctl -xe voidcn.com/article/p-qufvdmpq-bqn.html etcd more etcd.confETCD_NAME=default ETCD_DATA ...
- 10分钟彻底理解Redis持久化和主从复制
在这篇文章,我们一起了解 Redis 使用中非常重要的两个机制:Reids 持久化和主从复制. 什么是 Redis 持久化? Redis 作为一个键值对内存数据库(NoSQL),数据都存储在内存当中, ...
- Spring源码解析--IOC根容器Beanfactory详解
BeanFactory和FactoryBean的联系和区别 BeanFactory是整个Spring容器的根容器,里面描述了在所有的子类或子接口当中对容器的处理原则和职责,包括生命周期的一些约定. F ...
- CMU Database Systems - Timestamp Ordering Concurrency Control
2PL是悲观锁,Pessimistic,这章讲乐观锁,Optimistic,单机的,非分布式的 Timestamp Ordering,以时间为序,这个是非常自然的想法,按每个transaction的时 ...
- pip 安装,更新模块
moudle_name:是对应的模块名:请自行更换为自己需要更新的模块名 查看所有可更新的模块: pip list --outdated 更新某一个模块: pip install --upgrade ...
