gobject base class

本文详细介绍了 GObject 的初始化和析构过程,包括初始化阶段的目标类型构造、接口初始化等关键步骤,以及析构阶段的处置和最终化操作。通过理解这些过程,开发者可以更好地管理 GObject 实例的生命周期。

1. 初始化总结

Invocation time Function Invoked Function's parameters Remark
First call tog_object_newfor target type target type's base_init function On the inheritance tree of classes from fundamental type to target type. base_init is invoked once for each class structure. I have no real idea on how this can be used. If you have a good real-life example of how a class' base_init can be used, please, let me know.
target type's class_init function On target type's class structure Here, you should make sure to initialize or override class methods (that is, assign to each class' method its function pointer) and create the signals and the properties associated to your object.
interface' base_init function On interface' vtable  
interface' interface_init function On interface' vtable  
Each call tog_object_newfor target type target type's class constructor method: GObjectClass->constructor On object's instance If you need to complete the object initialization after all the construction properties are set, override the constructor method and make sure to chain up to the object's parent class before doing your own initialization. In doubt, do not override the constructor method.
type's instance_init function On the inheritance tree of classes from fundamental type to target type. the instance_init provided for each type is invoked once for each instance structure. Provide an instance_init function to initialize your object before its construction properties are set. This is the preferred way to initialize a GObject instance. This function is equivalent to C++ constructors.

2. Readers should feel concerned about one little twist in the order in which functions are invoked: while, technically, the class' constructor method is called before the GType's instance_init function (since g_type_create_instance which calls instance_init is called by g_object_constructor which is the top-level class constructor method and to which users are expected to chain to), the user's code which runs in a user-provided constructor will always run after GType's instance_init function since the user-provided constructor must (you've been warned) chain up before doing anything useful.

3. gobject 析构

Invocation time Function Invoked Function's parameters Remark
Last call tog_object_unreffor an instance of target type target type's dispose class function GObject instance When dispose ends, the object should not hold any reference to any other member object. The object is also expected to be able to answer client method invocations (with possibly an error code but no memory violation) until finalize is executed. dispose can be executed more than once. dispose should chain up to its parent implementation just before returning to the caller.
target type's finalize class function GObject instance Finalize is expected to complete the destruction process initiated by dispose. It should complete the object's destruction. finalize will be executed only once. finalize should chain up to its parent implementation just before returning to the caller. The reason why the destruction process is split is two different phases is explained in the section called “Reference counts and cycles”.
Last call tog_object_unreffor the last instance of target type interface' interface_finalize function On interface' vtable Never used in practice. Unlikely you will need it.
interface' base_finalize function On interface' vtable Never used in practice. Unlikely you will need it.
target type's class_finalize function On target type's class structure Never used in practice. Unlikely you will need it.
type's base_finalize function On the inheritance tree of classes from fundamental type to target type. base_init is invoked once for each class structure. Never used in practice. Unlikely you will need it.


sh-3.2# gst-inspect-1.0 -b (gst-plugin-scanner:5027): GStreamer-WARNING **: 19:43:08.929: Failed to load plugin '/usr/lib64/gstreamer-1.0/libgstffmpeg.so': /usr/lib64/gstreamer-1.0/libgstffmpeg.so: undefined symbol: get_primary_transferfunc size of instance = 1624 size of class = 1848 size of basesrc = 648 size of basesrcclass = 824 (gst-plugin-scanner:5027): GLib-GObject-CRITICAL **: 19:43:09.642: cannot register existing type 'GstTypeSMVideoEnc' (gst-plugin-scanner:5027): GLib-GObject-CRITICAL **: 19:43:09.643: g_param_spec_enum: assertion 'G_TYPE_IS_ENUM (enum_type)' failed (gst-plugin-scanner:5027): GLib-GObject-CRITICAL **: 19:43:09.643: validate_pspec_to_install: assertion 'G_IS_PARAM_SPEC (pspec)' failed (gst-plugin-scanner:5027): GLib-GObject-CRITICAL **: 19:43:09.643: g_param_spec_ref_sink: assertion 'G_IS_PARAM_SPEC (pspec)' failed (gst-plugin-scanner:5027): GLib-GObject-CRITICAL **: 19:43:09.643: g_param_spec_unref: assertion 'G_IS_PARAM_SPEC (pspec)' failed (gst-plugin-scanner:5027): GLib-GObject-CRITICAL **: 19:43:09.643: cannot register existing type 'GstTypeSMVideoEncDRM' (gst-plugin-scanner:5027): GLib-GObject-CRITICAL **: 19:43:09.643: g_param_spec_enum: assertion 'G_TYPE_IS_ENUM (enum_type)' failed (gst-plugin-scanner:5027): GLib-GObject-CRITICAL **: 19:43:09.643: validate_pspec_to_install: assertion 'G_IS_PARAM_SPEC (pspec)' failed (gst-plugin-scanner:5027): GLib-GObject-CRITICAL **: 19:43:09.643: g_param_spec_ref_sink: assertion 'G_IS_PARAM_SPEC (pspec)' failed (gst-plugin-scanner:5027): GLib-GObject-CRITICAL **: 19:43:09.643: g_param_spec_unref: assertion 'G_IS_PARAM_SPEC (pspec)' failed Blacklisted files: libgstffmpeg.so Total count: 1 blacklisted file
04-01
<think>好的,我现在需要帮助用户解决GStreamer插件加载失败的问题,以及处理相关的CRITICAL警告。首先,我需要理清用户的问题描述和已有的引用信息。 用户提到遇到了两个GStreamer的警告,一个是加载libgstchromaprint.so和libgstlibav.so时出现无法在静态TLS块中分配内存的问题,另一个是关于libgstffmpeg.so的未定义符号get_primary_transferfunc,以及GstTypeSMVideoEnc的CRITICAL警告。用户还提供了几个引用,涉及路径设置、插件搜索路径、安装runtime和development安装包的建议。 首先,分析第一个问题:静态TLS块无法分配内存。根据引用[1]中的错误信息,这通常是由于libgomp.so.1库在静态线程本地存储(TLS)中的问题。这可能是因为GStreamer插件需要动态加载的库使用了静态TLS,而系统在加载时无法分配足够的内存。解决方案可能涉及环境变量调整,如设置LD_PRELOAD或修改库的加载方式。 接下来是第二个问题:libgstffmpeg.so的未定义符号get_primary_transferfunc。这通常表明插件编译时使用的库版本与运行时链接的库版本不一致。可能用户安装的FFmpeg相关库版本不兼容,或者插件没有正确链接到所需的依赖项。此外,GstTypeSMVideoEnc的CRITICAL警告可能与此符号缺失有关,导致视频编码器状态机无法正确初始化。 现在结合用户提供的引用,引用[4]提到需要同时安装runtime和development安装包,这可能解决依赖问题。引用[2]和[3]涉及路径设置和插件搜索路径,可能用户的环境变量没有正确配置,导致插件无法找到依赖库。此外,用户可能没有正确安装所有必要的GStreamer插件和依赖项,比如libav或ffmpeg的插件。 可能的解决步骤包括: 1. 确认安装了两个安装包(runtime和development),如引用[4]所述。 2. 检查GStreamer的插件路径是否包含在环境变量中,如引用[3]提到的使用gst-inspect-1.0来验证插件路径。 3. 更新或重新安装FFmpeg相关的库,确保版本兼容。 4. 设置LD_PRELOAD环境变量预加载libgomp,解决静态TLS问题。 5. 检查符号冲突,可能需要重新编译插件或依赖库。 另外,用户提到的undefined symbol问题可能需要检查动态链接的库是否正确,使用ldd或nm工具查看libgstffmpeg.so的依赖项和符号是否存在。如果get_primary_transferfunc是某个新版本FFmpeg中的函数,而用户安装的是旧版本,就会导致符号未找到。此时需要更新FFmpeg或降级GStreamer插件版本以匹配。 关于GstTypeSMVideoEnc的警告,可能需要确认视频编码器的插件是否正确安装,比如x264或其他编码器支持库是否存在。 总结解决方案步骤: 1. 确保完整安装GStreamer和相关开发包。 2. 配置环境变量,正确设置插件路径。 3. 处理静态TLS错误,设置LD_PRELOAD。 4. 解决符号未定义问题,检查FFmpeg版本兼容性。 5. 重新安装或更新相关插件和依赖库。 在生成回答时,需要分步骤说明,确保用户能逐步操作,同时引用提供的参考资料中的正确部分,如引用[4]的安装建议,引用[3]的路径配置等。此外,可能需要指导用户如何验证每个步骤是否成功,例如运行gst-inspect-1.0来检查插件是否加载,或者使用ldd检查库依赖。</think>### GStreamer插件加载失败问题解决方案 #### 1. **静态TLS内存分配问题** **错误特征**: ```bash /lib/aarch64-linux-gnu/libgomp.so.1: cannot allocate memory in static TLS block ``` **原因**:插件依赖的库(如`libgomp`)尝试在静态线程本地存储(TLS)中分配内存,但系统资源不足[^1]。 **解决方案**: - **方法1**:通过环境变量调整动态加载方式 ```bash export LD_PRELOAD=/lib/aarch64-linux-gnu/libgomp.so.1 ``` 强制预加载`libgomp`库,绕过静态TLS限制。 - **方法2**:重新编译依赖库 若问题持续,需重新编译相关库(如GStreamer插件或`libgomp`),启用动态TLS支持。 --- #### 2. **插件未找到或符号未定义问题** **错误特征**: ```bash undefined symbol: get_primary_transferfunc GstTypeSMVideoEnc CRITICAL warning ``` **原因**: - **符号缺失**:`libgstffmpeg.so`依赖的FFmpeg库版本与编译时不一致,导致运行时找不到符号。 - **插件路径错误**:GStreamer未正确识别插件安装路径。 **解决方案**: 1. **确认完整安装GStreamer组件** - 同时安装**Runtime Installer**和**Development Installer**[^4],确保插件和开发文件齐全。 - 默认安装路径应为: ```bash C:\gstreamer\1.0\mingw_x86_64\bin # Windows示例[^2] /usr/lib/aarch64-linux-gnu/gstreamer-1.0 # Linux示例 ``` 2. **配置插件搜索路径** - 添加环境变量`GST_PLUGIN_PATH`指向插件目录: ```bash export GST_PLUGIN_PATH=$GST_PLUGIN_PATH:/usr/lib/aarch64-linux-gnu/gstreamer-1.0 ``` - 验证插件是否可被检测到: ```bash gst-inspect-1.0 libgstffmpeg # 检查FFmpeg插件状态[^3] ``` 3. **解决符号冲突或缺失** - **更新FFmpeg库**:确保安装的FFmpeg版本与GStreamer插件兼容。 ```bash sudo apt-get install ffmpeg libavcodec-dev # Ubuntu示例 ``` - **重新编译插件**:若符号仍缺失,需从源码重新编译GStreamer FFmpeg插件: ```bash git clone https://github.com/GStreamer/gst-plugins-bad cd gst-plugins-bad && meson build && ninja -C build ``` --- #### 3. **验证修复效果** - **检查插件加载**: ```bash gst-launch-1.0 --gst-plugin-path=/your/plugin/path audiotestsrc ! fakesink # 测试基础功能 ``` - **调试符号问题**: 使用`nm`工具检查动态库中的符号是否存在: ```bash nm -D /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstffmpeg.so | grep get_primary_transferfunc ``` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值