c++ - 用 C++ 包装一个 C 插件
问题描述
我正在创建一个gstreamer 插件。因为 gstreamer 是 C 语言,所以它使用自己的类和类似接口的系统来声明插件类型。
如何将这种 C 机制封装在 C++ GstPlugin抽象类中,这样开发人员就无需深入研究这些机制?
这个问题不是 gstreamer 特有的,任何 C 程序加载用 C++ 开发的插件并且必须使用extern "C"来公开静态函数而不进行修改(使模板的使用看似不可能)都是相同的。
使用 gstreamer 编写插件看起来像这样:
#include <gst/gst.h>
/* Definition of structure storing data for this element. */
typedef struct _GstMyFilter {
GstElement element;
GstPad *sinkpad, *srcpad;
gboolean silent;
} GstMyFilter;
/* Standard definition defining a class for this element. */
typedef struct _GstMyFilterClass {
GstElementClass parent_class;
} GstMyFilterClass;
/* Standard function returning type information. */
GType gst_my_filter_get_type (void);
然后这个宏定义原型来调用初始化 gstreamer 类型然后初始化 gstreamer 对象。
#include "filter.h"
G_DEFINE_TYPE (GstMyFilter, gst_my_filter, GST_TYPE_ELEMENT);
现已注册以下内容:
void gst_my_filter_init(GstMyFilter * filter);
void gst_my_filter_class_init(GstMyFilter * klass);
我想隐藏这种机制,以便使用我的代码的开发人员只需继承 GstPlugin 抽象类,而不必声明这些方法或GstMyFilterClass和GstMyFilter类型。
解决方案
推荐阅读
- python - 关闭游标并连接到 SQLite 数据库的最佳实践?
- python - 不确定如何在元组列表中引用元组中的元素
- html - 关于如何将 R 代码集成到网站的指南
- python - Selenium Chrome 更改目录
- amazon-web-services - 从 AWS 服务的现有实例(例如 dynamodb 表)中提取 cloudformation 模板
- node.js - Angular中的swiperjs安装问题
- javascript - JS 将文件上传到 HTML 文件元素,保留常规点击的效果
- javascript - 忽略 API 调用 nodeJS 返回的错误
- html - 如何使图像具有响应性?
- python - Python读取xml