从零开始成为GStreamer专家——基于Windows的GStreamer从源码下载、编译到开发

基于Windows的GStreamer从源码下载、编译到开发

        本文介绍了在GStreamer下载方法, 使用过程中的部分依赖,以及在Windows上编译配置GStreamer 过程,为学习GStreamer 创建条件。

 GStreamer 代码下载

  1. Sign up · GitLabfreedesktop.org GitLab loginicon-default.png?t=N7T8https://gitlab.freedesktop.org/users/sign_up上注册一个用户。
  2. 在PC机上用ssh-keygen -t rsa -C "yourname@yourhost.com"生成id_rsa.pub值,把这个值贴到下面Key框里,如果这一步不会,请搜索参考 ssh-keygen的用法。
  3. git clone git@gitlab.freedesktop.org:gstreamer/gstreamer.git  或 git clone https://gitlab.freedesktop.org/gstreamer/gstreamer.git 下载源码。下载下来的代码是整个工程,目录结构如下:​

相关基础知识

一、glib路径:https://www.linuxfromscratch.org/blfs/view/svn/general/glib2.htmlhttps://www.linuxfromscratch.org/blfs/view/svn/general/glib2.html

二、准备GObject相关知识,代码在glib中

        GObject又称为GLib对象系统,和glibc,libc没有关系,glibc是linux下的GNU C函数库,libc是linux下的ANSI C函数库。面向对像的方法常常用私有来隐藏信息,而用C语言实现的系统中,私有却没有那么简单。一种方法是将私有成员分离到独立的结构体中;另外一种方法是将私有结构体存放到源码文件,对外结构体中仅仅保存一个指针,指向这个结构。

        GObject相关URL:GObject – 2.0https://docs.gtk.org/gobject/

三、下载gst-template:git clone git://anongit.freedesktop.org/gstreamer/gst-template.git 可以利用其中的工具来产生plugin,方法是:../tools/make_element plugin_name

四、第三方依赖库下载
        Gstreamer的功能有时候依赖第三方库,这些库在Gstreamer的subprojects下面没有对应的工程。如果自己下载编译,修改meson.build其实是个挺费时的工程,这个时候,可以到https://mesonbuild.com/Wrapdb-projects.html#meson-wrapdb-packages 这个网站上下载Meson WrapDB packages,然后将对应的.warp文件放到subprojects/目录下即可。如编译openssl就可以下载openssl.wrap。

五、编译三方库过程中,只生成*.dll文件,未生成*.lib的故障解决:故障原因由未导出任何API导致,可以由以下方式解决,如在.c文件中增加一个API,并且export。

#if defined(_WIN32)
__declspec(dllexport) int OPENSSL_generate_lib_func() 
{
    return 1;
}
#endif

        但这种方式治标不治本,编译产生的函数声明等等都没有导出来,导致链接的时候符号查找不到,可以在链接时,加入/DEF:openssl.def选项,

openssl_cflags = ['/DEF:openssl.def',]
libssl_dep = declare_dependency(
  include_directories: include_directories,
  dependencies: dependencies + [libcrypto_dep],
  link_with: libssl_lib,
  link_args:openssl_cflags,
)

官方指导链接:Built-in optionsicon-default.png?t=N7T8https://mesonbuild.com/Builtin-options.htmlopenssl.def是描述需要导出符号的文件:
LIBRARY   crypto
EXPORTS
    a2i_IPADDRESS
    ASN1_ANY_it
    ASN1_item_d2i
    ASN1_item_free
    ASN1_item_i2d
    ASN1_item_new

        详情参见官方指导文档:/DEF (Specify Module-Definition File) | Microsoft Docs

        可以在Gstreamer的顶层meson_options.txt中加入option('openssl', type : 'feature', value : 'auto'),在meson.build的subprojects中加入  ['openssl', { 'option': get_option('openssl'), 'match_gst_version': false}],就可以编译openssl了。

        事实上.def文件要配置全是很难的,这里给出一种方式:

1. 首先,您可以创建静态库。修改meson.build,加入
libcrypto_lib = static_library(
  'crypto',
  dependencies: dependencies,
  sources: libcrypto_sources,
  include_directories: include_directories,
  c_args: c_args,
  install: true,
  link_args:openssl_cflags,
)

libssl_lib = static_library(
  'ssl',
  dependencies: dependencies + [libcrypto_dep],
  sources: libssl_sources,
  include_directories: include_directories,
  c_args: c_args,
  link_args:openssl_cflags,
  install: true,
)
2. 然后使用“dumpbin/linkermember”从静态库中导出所有符号。
    dumpbin /LINKERMEMBER libcrypto.a > libcrypto.txt
    dumpbin /LINKERMEMBER libssl.a > libssl.txt
3. 将所有符号放入.def文件。
4. 使用.def文件创建dll。

Gstreamer libogg中使用.def的方式:
sources = ['bitwise.c', 'framing.c']

libogg = library('ogg',
  sources,
  include_directories : incdir,
  vs_module_defs: '../win32/ogg.def',
  install: true,
)

bw_test = executable('bitwise', 'bitwise.c',
  include_directories : incdir,
  c_args : '-D_V_SELFTEST'
)
framing_test = executable('framing', 'framing.c',
  include_directories : incdir,
  c_args : '-D_V_SELFTEST'
)

test('bitwise', bw_test)
test('framing', framing_test)

libogg_dep = declare_dependency(link_with : libogg,
  include_directories : incdir)

不过,使用.def创建的dll,在使用时,涉及到具体的函数时,仍然需要import,用__declspec(dllimport),详见:

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值