当前位置:网站首页>OBS plug-in Foundation
OBS plug-in Foundation
2022-07-23 12:32:00 【Longcheng ne goods 92923】
( One )OBS Basic information of plug-in module ( Use... When loading plug-in modules )
libobsyes obs The core library , Other extensions are based onlibobs( Responsible for managing all plug-ins )
1. Module information structure
// Module information structure obs\obs-studio\libobs\obs-internal.h In the definition of
struct obs_module {
char *mod_name; // Module name
const char *file; // Module filename
char *bin_path; //dll route
char *data_path; // Data path
void *module; //dll After opening handle
bool loaded;
// Some export interfaces of the module
bool (*load)(void); // Call this function pointer first when loading the module , Each module needs to implement this function pointer (obs_moudle_load function )
void (*unload)(void);
void (*post_load)(void);
void (*set_locale)(const char *locale);
bool (*get_string)(const char *lookup_string,
const char **translated_string);
void (*free_locale)(void);
uint32_t (*ver)(void);
void (*set_pointer)(obs_module_t *module);
const char *(*name)(void);
const char *(*description)(void);
const char *(*author)(void);
struct obs_module *next; // Point to the next module
};
2. Module general functions
// obs\obs-studio\libobs\util\platform-windows.c In the definition of
void *os_dlopen(const char *path) // open dll
void *os_dlsym(void *module, const char *func) //dll The export address of the function interface in
// Example :
struct obs_module mod = {0};
mod.module = os_dlopen(path);
load_module_exports(&mod, path);
static int load_module_exports(struct obs_module *mod, const char *path)
{
mod->load = os_dlsym(mod->module, "obs_module_load");
if (!mod->load)
return req_func_not_found("obs_module_load", path);
mod->set_pointer = os_dlsym(mod->module, "obs_module_set_pointer");
if (!mod->set_pointer)
return req_func_not_found("obs_module_set_pointer", path);
mod->ver = os_dlsym(mod->module, "obs_module_ver");
if (!mod->ver)
return req_func_not_found("obs_module_ver", path);
/* optional exports */
mod->unload = os_dlsym(mod->module, "obs_module_unload");
mod->post_load = os_dlsym(mod->module, "obs_module_post_load");
mod->set_locale = os_dlsym(mod->module, "obs_module_set_locale");
mod->free_locale = os_dlsym(mod->module, "obs_module_free_locale");
mod->name = os_dlsym(mod->module, "obs_module_name");
mod->description = os_dlsym(mod->module, "obs_module_description");
mod->author = os_dlsym(mod->module, "obs_module_author");
mod->get_string = os_dlsym(mod->module, "obs_module_get_string");
return MODULE_SUCCESS;
}
( Two )OBS The core content of the plug-in module ( Use... When writing plug-in modules )
Necessary contents for implementing module plug-ins
- Include header file
#include <obs-module.h>obs\obs-studio\libobs\obs-module.h Under the table of contents- contain
OBS_DECLARE_MODULE()macro- Realization
bool obs_module_load(void)( Only in header files obs-module.h In the definition of , Each plug-in module needs to implement this function )Options
- contain
OBS_MODULE_USE_DEFAULT_LOCALE("win-dshow", "en-US")Default language processing related macros ( Though not necessarily , But it usually includes )void obs_module_unload(void)void obs_module_post_load(void);void obs_module_set_locale(const char *locale);void obs_module_free_locale(void);etc.
1. Macro definition OBS_DECLARE_MODULE()
#define OBS_DECLARE_MODULE()
// Static module variables
static obs_module_t *obs_module_pointer;
// Two export interface functions
MODULE_EXPORT void obs_module_set_pointer(obs_module_t *module);
MODULE_EXPORT uint32_t obs_module_ver(void);
// Set variable value
void obs_module_set_pointer(obs_module_t *module)
{
obs_module_pointer = module;
}
// Get the variable value
obs_module_t *obs_current_module(void) { return obs_module_pointer; }
// Module version
uint32_t obs_module_ver(void) { return LIBOBS_API_VER; }
2. bool obs_module_load(void) Function implementation example
//win-dshow plug-in unit obs\obs-studio\plugins\win-dshow\dshow-plugin.cpp In the definition of
bool obs_module_load(void)
{
RegisterDShowSource();
RegisterDShowEncoders();
#ifdef VIRTUALCAM_ENABLED
obs_register_output(&virtualcam_info);
bool installed = vcam_installed(false);
#else
bool installed = false;
#endif
obs_data_t *obs_settings = obs_data_create();
obs_data_set_bool(obs_settings, "vcamEnabled", installed);
obs_apply_private_data(obs_settings);
obs_data_release(obs_settings);
return true;
}
3. Macro definition OBS_MODULE_USE_DEFAULT_LOCALE
/** Optional: Use this macro in a module to use default locale handling. */
#define OBS_MODULE_USE_DEFAULT_LOCALE(module_name, default_locale) \
lookup_t *obs_module_lookup = NULL; \
const char *obs_module_text(const char *val) \
{ \
const char *out = val; \
text_lookup_getstr(obs_module_lookup, val, &out); \
return out; \
} \
bool obs_module_get_string(const char *val, const char **out) \
{ \
return text_lookup_getstr(obs_module_lookup, val, out); \
} \
void obs_module_set_locale(const char *locale) \
{ \
if (obs_module_lookup) \
text_lookup_destroy(obs_module_lookup); \
obs_module_lookup = obs_module_load_locale( \
obs_current_module(), default_locale, locale); \
} \
void obs_module_free_locale(void) \
{ \
text_lookup_destroy(obs_module_lookup); \
obs_module_lookup = NULL; \
}
// Examples of use
OBS_MODULE_USE_DEFAULT_LOCALE("win-dshow", "en-US")
( 3、 ... and ) Use OBS Plug in module
Basic information of plug-ins
- OBS Plug ins are compiled dll library , Put it under the formulated directory , from
libobsload , And then callos_dlopenandos_dlsymGet the external interface of the plug-in- Plug in directory structure
obs\obs-studio\build-vs2019\rundir\Debug\bin-> Executable Directory obs.exeobs\obs-studio\build-vs2019\rundir\Debug\data-> Resource directoryobs\obs-studio\build-vs2019\rundir\Debug\data\obs-plugins-> Various plug-in resource directoriesobs\obs-studio\build-vs2019\rundir\Debug\data\obs-plugins\win-dshow\locale->win-dshow The language pack under the plug-inobs\obs-studio\build-vs2019\rundir\Debug\obs-plugins\32bit-> All plug-ins dll Location
Plug in initialization process
3.1 Set plug-in path (.dll Paths and plug-ins data route )
3.2 Plug in initialization
1. obs_load_all_modules() Function analysis
//obs\obs-studio\libobs\obs-module.c
void obs_load_all_modules(void)
{
profile_start(obs_load_all_modules_name);
obs_find_modules(load_all_callback, NULL); // Find all modules
#ifdef _WIN32
profile_start(reset_win32_symbol_paths_name);
reset_win32_symbol_paths();
profile_end(reset_win32_symbol_paths_name);
#endif
profile_end(obs_load_all_modules_name);
}
void obs_find_modules(obs_find_module_callback_t callback, void *param)
{
if (!obs)
return;
for (size_t i = 0; i < obs->module_paths.num; i++)
{
struct obs_module_path *omp = obs->module_paths.array + i;
find_modules_in_path(omp, callback, param); // Load the found plug-ins
}
}
// Function call
find_modules_in_path() // Add plug-ins
|os_glob()
|process_found_module() // Processing plug-ins
|info.bin_path = parsed_bin_path.array;
|info.data_path = parsed_data_dir;
|callback(param, &info); // Call the callback to send out the plug-in information (info)
|static void load_all_callback(void *param, const struct obs_module_info *info) // Callback function
|obs_open_module() // load dll Get the basic information of the module and export interface
|mod.module = os_dlopen(path);
|load_module_exports(&mod, path); // Get the module export interface pointer Corresponding ## 2. Module general functions
|obs_init_module(module); // Initialization module
|module->loaded // Call the plug-in to implement bool obs_module_load(void)
边栏推荐
- Integrate all lvgl controls into one project (lvgl6.0 version)
- 单片机学习笔记3--单片机结构和最小系统(基于百问网STM32F103系列教程)
- [AUTOSAR CP general 1. how to read AUTOSAR official documents]
- Tencent cloud client command line tool tccli main process analysis
- Practical convolution correlation trick
- 钢结构基本原理全面详细总结
- NLP natural language processing - Introduction to machine learning and natural language processing (2)
- 高分子合成工艺学复习考题
- How to develop the computing power and AI intelligent chips in the data center of "digital computing in the East and digital computing in the west"?
- Interpretation of the paper: iterative feature representation method to improve the prediction performance of N7 methylguanosine (m7G) sites
猜你喜欢

线性规划之Google OR-Tools 简介与实战

ARM架构与编程7--异常与中断(基于百问网ARM架构与编程教程视频)

利用or-tools来求解路径规划问题(VRP)

利用google or-tools 求解逻辑难题:斑马问题

Interpretation of the paper: develop and verify the deep learning system to classify the etiology of macular hole and predict the anatomical results

Check the sandbox file in the real app

【AUTOSAR CanTP 1.学习UDS诊断的网络层协议】

【基于UDS服务的BootLoader架构和刷写流程】

单片机学习笔记1--资料下载、环境搭建(基于百问网STM32F103系列教程)

博客搭建五:图床选择
随机推荐
钢结构基本原理复习
NLP natural language processing - Introduction to machine learning and natural language processing (2)
In depth interpretation of Google or tools' complex scheduling program
Using pycaret: low code, automated machine learning framework to solve classification problems
Build "green computing" and interpret "Intelligent Computing Center"
【AUTOSAR CanDrive 1.学习CanDrive的功能和结构】
switch实现表达式计算
Examen des principes fondamentaux de la structure en acier
【分清楚常量指针与指针常量 Const int *与Int * Const的含义与用法】
【Autosar 存储Stack NVM】
高分子物理名词解释
对字符串函数的使用和理解(1)
Interpretation of the paper: develop a prediction model based on multi-layer deep learning to identify DNA N4 methylcytosine modification
【学习总结】
单片机学习笔记7--SysTick定时器(基于百问网STM32F103系列教程)
单片机学习笔记6--中断系统(基于百问网STM32F103系列教程)
ARM架构与编程6--重定位(基于百问网ARM架构与编程教程视频)
利用or-tools来求解路径规划问题(TSP)
钢结构复习题
[AUTOSAR candrive 2. understand the mapping relationship between communication HOH, canid and pduid]