reference-modules.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. Module API Reference
  2. ====================
  3. Modules add custom functionality to libobs: typically
  4. :ref:`plugins_sources`, :ref:`plugins_outputs`, :ref:`plugins_encoders`,
  5. and :ref:`plugins_services`.
  6. .. type:: obs_module_t
  7. A module object (not reference counted).
  8. .. code:: cpp
  9. #include <obs-module.h>
  10. Module Macros
  11. -------------
  12. These macros are used within custom plugin modules.
  13. .. macro:: OBS_DECLARE_MODULE()
  14. Declares a libobs module. Exports important core module functions
  15. related to the module itself, OBS version, etc.
  16. ---------------------
  17. .. macro:: OBS_MODULE_USE_DEFAULT_LOCALE(module_name, default_locale)
  18. Helper macro that uses the standard ini file format for localization.
  19. Automatically initializes and destroys localization data, and
  20. automatically provides module externs such as
  21. :c:func:`obs_module_text()` to be able to get a localized string with
  22. little effort.
  23. ---------------------
  24. Module Exports
  25. --------------
  26. These are functions that plugin modules can optionally export in order
  27. to communicate with libobs and front-ends.
  28. .. function:: bool obs_module_load(void)
  29. Required: Called when the module is loaded. Implement this function
  30. to load all the sources/encoders/outputs/services for your module, or
  31. anything else that may need loading.
  32. :return: Return true to continue loading the module, otherwise
  33. false to indicate failure and unload the module
  34. ---------------------
  35. .. function:: void obs_module_unload(void)
  36. Optional: Called when the module is unloaded.
  37. ---------------------
  38. .. function:: void obs_module_post_load(void)
  39. Optional: Called when all modules have finished loading.
  40. ---------------------
  41. .. function:: void obs_module_set_locale(const char *locale)
  42. Called to set the locale language and load the locale data for the
  43. module.
  44. ---------------------
  45. .. function:: void obs_module_free_locale(void)
  46. Called on module destruction to free locale data.
  47. ---------------------
  48. .. function:: const char *obs_module_name(void)
  49. (Optional)
  50. :return: The full name of the module
  51. ---------------------
  52. .. function:: const char *obs_module_description(void)
  53. (Optional)
  54. :return: A description of the module
  55. ---------------------
  56. Module Externs
  57. --------------
  58. These functions are externs that are usable throughout the module.
  59. .. function:: const char *obs_module_text(const char *lookup_string)
  60. :return: A localized string
  61. ---------------------
  62. .. function:: bool obs_module_get_string(const char *lookup_string, const char **translated_string)
  63. Helper function for looking up locale.
  64. :return: *true* if text found, otherwise *false*
  65. ---------------------
  66. .. function:: obs_module_t *obs_current_module(void)
  67. :return: The current module
  68. ---------------------
  69. .. function:: char *obs_module_file(const char *file)
  70. Returns the location to a module data file associated with the
  71. current module. Free with :c:func:`bfree()` when complete.
  72. Equivalent to:
  73. .. code:: cpp
  74. obs_find_module_file(obs_current_module(), file);
  75. ---------------------
  76. .. function:: char *obs_module_config_path(const char *file)
  77. Returns the location to a module config file associated with the
  78. current module. Free with :c:func:`bfree()` when complete. Will
  79. return NULL if configuration directory is not set.
  80. Equivalent to:
  81. .. code:: cpp
  82. obs_module_get_config_path(obs_current_module(), file);
  83. ---------------------
  84. Frontend Module Functions
  85. --------------------------
  86. These are functions used by frontends to load and get information about
  87. plugin modules.
  88. .. function:: int obs_open_module(obs_module_t **module, const char *path, const char *data_path)
  89. Opens a plugin module directly from a specific path.
  90. If the module already exists then the function will return successful, and
  91. the module parameter will be given the pointer to the existing
  92. module.
  93. This does not initialize the module, it only loads the module image. To
  94. initialize the module, call :c:func:`obs_init_module()`.
  95. :param module: The pointer to the created module
  96. :param path: Specifies the path to the module library file. If the
  97. extension is not specified, it will use the extension
  98. appropriate to the operating system
  99. :param data_path: Specifies the path to the directory where the module's
  100. data files are stored (or *NULL* if none)
  101. :returns: | MODULE_SUCCESS - Successful
  102. | MODULE_ERROR - A generic error occurred
  103. | MODULE_FILE_NOT_FOUND - The module was not found
  104. | MODULE_MISSING_EXPORTS - Required exports are missing
  105. | MODULE_INCOMPATIBLE_VER - Incompatible version
  106. | MODULE_HARDCODED_SKIP - Skipped by hardcoded rules
  107. (e.g. obsolete obs-browser macOS plugin)
  108. ---------------------
  109. .. function:: bool obs_init_module(obs_module_t *module)
  110. Initializes the module, which calls its obs_module_load export.
  111. :return: *true* if the module was loaded successfully
  112. ---------------------
  113. .. function:: void obs_log_loaded_modules(void)
  114. Logs loaded modules.
  115. ---------------------
  116. .. function:: const char *obs_get_module_file_name(obs_module_t *module)
  117. :return: The module file name
  118. ---------------------
  119. .. function:: const char *obs_get_module_name(obs_module_t *module)
  120. :return: The module full name (or *NULL* if none)
  121. ---------------------
  122. .. function:: void obs_get_module_author(obs_module_t *module)
  123. :return: The module author(s)
  124. ---------------------
  125. .. function:: const char *obs_get_module_description(obs_module_t *module)
  126. :return: The module description
  127. ---------------------
  128. .. function:: const char *obs_get_module_binary_path(obs_module_t *module)
  129. :return: The module binary path
  130. ---------------------
  131. .. function:: const char *obs_get_module_data_path(obs_module_t *module)
  132. :return: The module data path
  133. ---------------------
  134. .. function:: void obs_add_module_path(const char *bin, const char *data)
  135. Adds a module search path to be used with obs_find_modules. If the search
  136. path strings contain %module%, that text will be replaced with the module
  137. name when used.
  138. :param bin: Specifies the module's binary directory search path
  139. :param data: Specifies the module's data directory search path
  140. ---------------------
  141. .. function:: void obs_load_all_modules(void)
  142. Automatically loads all modules from module paths (convenience function).
  143. ---------------------
  144. .. function:: void obs_load_all_modules2(struct obs_module_failure_info *mfi)
  145. Automatically loads all modules from module paths (convenience function).
  146. Additionally gives you information about modules that fail to load.
  147. :param mfi: Provides module failure information. The *failed_modules*
  148. member is a string list via a pointer to pointers of
  149. strings of modules that failed to load. Can be freed
  150. either with :c:func:`obs_module_failure_info_free()` or
  151. by simply calling :c:func:`bfree()` on the
  152. *failed_modules* member variable.
  153. Relevant data types used with this function:
  154. .. code:: cpp
  155. struct obs_module_failure_info {
  156. char **failed_modules;
  157. size_t count;
  158. };
  159. ---------------------
  160. .. function:: void obs_module_failure_info_free(struct obs_module_failure_info *mfi)
  161. Frees data allocated data used in the *mfi* parameter (calls
  162. :c:func:`bfree()` on the *failed_modules* member variable).
  163. ---------------------
  164. .. function:: void obs_post_load_modules(void)
  165. Notifies modules that all modules have been loaded.
  166. ---------------------
  167. .. function:: void obs_find_modules(obs_find_module_callback_t callback, void *param)
  168. Finds all modules within the search paths added by
  169. :c:func:`obs_add_module_path()`.
  170. Relevant data types used with this function:
  171. .. code:: cpp
  172. struct obs_module_info {
  173. const char *bin_path;
  174. const char *data_path;
  175. };
  176. typedef void (*obs_find_module_callback_t)(void *param,
  177. const struct obs_module_info *info);
  178. ---------------------
  179. .. function:: void obs_find_modules2(obs_find_module_callback_t callback, void *param)
  180. Finds all modules within the search paths added by
  181. :c:func:`obs_add_module_path()`.
  182. Relevant data types used with this function:
  183. .. code:: cpp
  184. struct obs_module_info2 {
  185. const char *bin_path;
  186. const char *data_path;
  187. const char *name;
  188. };
  189. typedef void (*obs_find_module_callback2_t)(void *param,
  190. const struct obs_module_info2 *info);
  191. ---------------------
  192. .. function:: void obs_enum_modules(obs_enum_module_callback_t callback, void *param)
  193. Enumerates all loaded modules.
  194. Relevant data types used with this function:
  195. .. code:: cpp
  196. typedef void (*obs_enum_module_callback_t)(void *param, obs_module_t *module);
  197. ---------------------
  198. .. function:: char *obs_find_module_file(obs_module_t *module, const char *file)
  199. Returns the location of a plugin module data file.
  200. Note: Modules should use obs_module_file function defined in obs-module.h
  201. as a more elegant means of getting their files without having to
  202. specify the module parameter.
  203. :param module: The module associated with the file to locate
  204. :param file: The file to locate
  205. :return: Path string, or NULL if not found. Use bfree to free string
  206. ---------------------
  207. .. function:: char *obs_module_get_config_path(obs_module_t *module, const char *file)
  208. Returns the path of a plugin module config file (whether it exists or not).
  209. Note: Modules should use obs_module_config_path function defined in
  210. obs-module.h as a more elegant means of getting their files without
  211. having to specify the module parameter.
  212. :param module: The module associated with the path
  213. :param file: The file to get a path to
  214. :return: Path string, or NULL if not found. Use bfree to free string
  215. ---------------------
  216. .. function:: void *obs_get_module_lib(obs_module_t *module)
  217. Returns library file of specified module.
  218. :param module: The module where to find library file.
  219. :return: Pointer to module library.