OBS-扩展模块DLL
+ -

OBS扩展模块DLL-模块路径及配置文件路径

2024-06-20 21 0

扩展模块即OBS需要加载的外部dll。这些dll一般位于

  1. C:\Program Files\obs-studio\obs-plugins\64bit

目录下。

模块路径

外部模块的路径添加通过函数obs_add_module_path实现。

  1. void obs_add_module_path(const char *bin, const char *data)
  2. {
  3. struct obs_module_path omp;
  4. if (!obs || !bin || !data)
  5. return;
  6. omp.bin = bstrdup(bin);
  7. omp.data = bstrdup(data);
  8. da_push_back(obs->module_paths, &omp);
  9. }

这其中的两个参数:

  • bin:是模块dll的路
  • data:是配置参数ini的路径

第一个汲到到的obs_add_module_path调用有:

  1. static const char *module_bin[] = {"../../obs-plugins/64bit"};
  2. static const char *module_data[] = {"../../data/obs-plugins/%module%"};
  3. static const int module_patterns_size = sizeof(module_bin) / sizeof(module_bin[0]);
  4. void add_default_module_paths(void)
  5. {
  6. for (int i = 0; i < module_patterns_size; i++)
  7. obs_add_module_path(module_bin[i], module_data[i]);
  8. }

该函数被调用有顺序为:

  • OBSApp::OBSInit()
    • ::StartupOBS
      • ::obs_startup
        • ::obs_init
          • ::add_default_module_paths()
            • ::obs_add_module_path

第二个汲的obs_add_module_path调用有AddExtraModulePaths
调用顺序为:

  • OBSBasic::OBSInit()
    • AddExtraModulePaths()

OBSBasic::OBSInit()中调用代码如下:

  1. /* Safe Mode disables third-party plugins so we don't need to add earch
  2. * paths outside the OBS bundle/installation. */
  3. if (safe_mode || disable_3p_plugins) {
  4. SetSafeModuleNames();
  5. } else {
  6. AddExtraModulePaths();
  7. }

OBSApp是应用程序,而OBSBasic是该应用下的主窗口。

  1. bool OBSApp::OBSInit()
  2. {
  3. //创建主窗口
  4. mainWindow = new OBSBasic();
  5. mainWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  6. connect(mainWindow, &OBSBasic::destroyed, this, &OBSApp::quit);
  7. //初始化主窗口的OBSInit
  8. mainWindow->OBSInit();
  9. }

第一个的最终路径为:

  • C:\Program Files\obs-studio\obs-plugins\64bit
  • C:\Program Files\obs-studio\data\obs-plugins

第二个的最终路径为:

  • C:\Program Files\obs-studio\bin\64bit
  • C:\Program Files\obs-studio\data\obs-studio

路径存储数组obs_core成员module_paths

obs_add_module_path将这些dll的路径及配置信息使用obs_module_path结构体,并存储在obs->module_paths成员中。

模块汲及到的成员包括:

  1. struct obs_core {
  2. struct obs_module *first_module;
  3. DARRAY(struct obs_module_path) module_paths;//模块存储位置
  4. DARRAY(char *) safe_modules; //CMake定义了SAFE_MODULES时才用,通过解析文件获取,如未定义该宏,则为空
  5. ...
  6. }

附录:

这段函数是用来添加额外的模块路径到 OBS Studio 中。函数首先尝试从环境变量中获取两个路径:OBS_PLUGINS_PATHOBS_PLUGINS_DATA_PATH。如果这两个路径都存在,就将 plugins_data_path 拼接成 data_path_with_module_suffix,然后调用 obs_add_module_path 函数,将 plugins_pathdata_path_with_module_suffix 作为参数添加到模块路径中。

接着,如果处于便携模式下 (portable_mode),函数直接返回,不进行后续操作。

然后根据不同的操作系统平台,设置不同的 base_module_dir 路径,并调用相应的路径获取函数。如果路径获取失败 (ret <= 0),函数也直接返回。

最后根据操作系统的不同和架构的不同,设置不同的模块路径。例如,在 macOS 上,根据应用程序支持路径和系统旧版本支持路径添加模块路径;在其它系统上,则根据架构位数添加模块路径。

总体来说,这段函数用于根据环境变量和操作系统平台动态添加 OBS Studio 的模块路径,以支持不同的插件和模块加载需求。

  1. static void AddExtraModulePaths()
  2. {
  3. string plugins_path, plugins_data_path;
  4. char *s;
  5. s = getenv("OBS_PLUGINS_PATH");
  6. if (s)
  7. plugins_path = s;
  8. s = getenv("OBS_PLUGINS_DATA_PATH");
  9. if (s)
  10. plugins_data_path = s;
  11. if (!plugins_path.empty() && !plugins_data_path.empty())
  12. {
  13. string data_path_with_module_suffix;
  14. data_path_with_module_suffix += plugins_data_path;
  15. data_path_with_module_suffix += "/%module%";
  16. obs_add_module_path(plugins_path.c_str(), data_path_with_module_suffix.c_str());
  17. }
  18. if (portable_mode)
  19. return;
  20. char base_module_dir[512];
  21. #if defined(_WIN32)
  22. int ret = GetProgramDataPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
  23. #elif defined(__APPLE__)
  24. int ret = GetConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%.plugin");
  25. #else
  26. int ret = GetConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
  27. #endif
  28. if (ret <= 0)
  29. return;
  30. string path = base_module_dir;
  31. #if defined(__APPLE__)
  32. /* User Application Support Search Path */
  33. obs_add_module_path((path + "/Contents/MacOS").c_str(),(path + "/Contents/Resources").c_str());
  34. #ifndef __aarch64__
  35. /* Legacy System Library Search Path */
  36. char system_legacy_module_dir[PATH_MAX];
  37. GetProgramDataPath(system_legacy_module_dir, sizeof(system_legacy_module_dir), "obs-studio/plugins/%module%");
  38. std::string path_system_legacy = system_legacy_module_dir;
  39. obs_add_module_path((path_system_legacy + "/bin").c_str(), (path_system_legacy + "/data").c_str());
  40. /* Legacy User Application Support Search Path */
  41. char user_legacy_module_dir[PATH_MAX];
  42. GetConfigPath(user_legacy_module_dir, sizeof(user_legacy_module_dir), "obs-studio/plugins/%module%");
  43. std::string path_user_legacy = user_legacy_module_dir;
  44. obs_add_module_path((path_user_legacy + "/bin").c_str(),(path_user_legacy + "/data").c_str());
  45. #endif
  46. #else
  47. #if ARCH_BITS == 64
  48. obs_add_module_path((path + "/bin/64bit").c_str(),
  49. (path + "/data").c_str());
  50. #else
  51. obs_add_module_path((path + "/bin/32bit").c_str(),
  52. (path + "/data").c_str());
  53. #endif
  54. #endif
  55. }

0 篇笔记 写笔记

作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!