加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

AppSrc与Playbin2的结合使用

发布时间:2020-12-13 22:34:32 所属栏目:百科 来源:网络整理
导读:前面关于AppSrc的文章记录了使用AppSrc时,Pipeline的构建过程,这中间需要手动设置一些Element的属性。如果使用Playbin的话,可以省去这些过程。 Playbin支持URI解析,而AppSrc支持的URI格式为appsrc://。因此,只需要将Playbin的uri属性设置为appsrc://,

前面关于AppSrc的文章记录了使用AppSrc时,Pipeline的构建过程,这中间需要手动设置一些Element的属性。如果使用Playbin的话,可以省去这些过程。
Playbin支持URI解析,而AppSrc支持的URI格式为appsrc://。因此,只需要将Playbin的uri属性设置为appsrc://,则playbin就会自动查找到appsrc组件,并将其作为pipeline的source组件。对于AppSrc相关的signal的设置,只要在playbin提供的source-setup事件中处理即可。参考代码如下:

_pipeline   =   gst_element_factory_make( "playbin2","playbin" );
g_signal_connect( _pipeline,"source-setup",G_CALLBACK( setupSrc ),NULL );

AppSrc作为source组件,如果需要支持seek操作,需要设置其stream-type属性。该属性为枚举类型:

(0): stream           - GST_APP_STREAM_TYPE_STREAM
(1): seekable         - GST_APP_STREAM_TYPE_SEEKABLE
(2): random-access    - GST_APP_STREAM_TYPE_RANDOM_ACCESS

该属性的设置可以在source-setup的处理函数中进行:

/*
 * ===  FUNCTION  ======================================================================
 *         Name:  setupSrc
 *  Description:
 * =====================================================================================
 */
static void setupSrc( GstElement * object,GstElement * arg0,gpointer user_data )
{
    gint64 _size;
    g_message( "%s",__func__ );
    fseek( fp,SEEK_END );

    _size   =   ftell( fp );
    g_object_set( arg0,"size",_size,NULL );
    fseek( fp,SEEK_SET );
    g_object_set( arg0,"stream-type",GST_APP_STREAM_TYPE_RANDOM_ACCESS,NULL );

    g_signal_connect ( arg0,"need-data",G_CALLBACK( _needData ),NULL );
    g_signal_connect ( arg0,"enough-data",G_CALLBACK( _enoughData ),"seek-data",G_CALLBACK( _seekData ),NULL );
}       /* -----  end of static function setupSrc  ----- */

附:
支持uri解析的element都会实现GstURIHandler接口,因此,查找gstreamer支持uri解析的element可以按如下方式执行(还不知道是否有更好的方法,用gst-inspect一个一个查太慢且容易出错):

$cd <source_of_gstreamer>
$grep get_protocols ./ -rnw --include=*.c

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读