从零开始成为GStreamer专家——基于Windows的GStreamer从源码下载、编译到开发 基于Windows的GStreamer从源码下载、编译到开发 本文介绍了在GStreamer下载方法,使用过程中的部分依赖,以及在Windows上编译配置GStreamer过程,为学习GStreamer 创建条件。GStreamer代码下载到Sign up · GitLabfreedesktop.org GitLab loginhttps://gitlab.freedesktop.org/users/sign_up上注册一个用户。在PC机上用ssh-keygen -t rsa -C "yourname@yourhost.com"生成id_rsa.pub值,把这个值贴到下面Key框里,如果这一步不会,请搜索参考ssh-keygen的用法。git clone git@gitlab.freedesktop.org:gstreamer/gstreamer.git或 git clonehttps://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 optionshttps://mesonbuild.com/Builtin-options.htmlopenssl.def是描述需要导出符号的文件:LIBRARY cryptoEXPORTS 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)