obs-module.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /******************************************************************************
  2. Copyright (C) 2013-2014 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "util/platform.h"
  15. #include "util/dstr.h"
  16. #include "obs-defs.h"
  17. #include "obs-internal.h"
  18. #include "obs-module.h"
  19. extern const char *get_module_extension(void);
  20. static inline int req_func_not_found(const char *name, const char *path)
  21. {
  22. blog(LOG_DEBUG,
  23. "Required module function '%s' in module '%s' not "
  24. "found, loading of module failed",
  25. name, path);
  26. return MODULE_MISSING_EXPORTS;
  27. }
  28. static int load_module_exports(struct obs_module *mod, const char *path)
  29. {
  30. mod->load = os_dlsym(mod->module, "obs_module_load");
  31. if (!mod->load)
  32. return req_func_not_found("obs_module_load", path);
  33. mod->set_pointer = os_dlsym(mod->module, "obs_module_set_pointer");
  34. if (!mod->set_pointer)
  35. return req_func_not_found("obs_module_set_pointer", path);
  36. mod->ver = os_dlsym(mod->module, "obs_module_ver");
  37. if (!mod->ver)
  38. return req_func_not_found("obs_module_ver", path);
  39. /* optional exports */
  40. mod->unload = os_dlsym(mod->module, "obs_module_unload");
  41. mod->post_load = os_dlsym(mod->module, "obs_module_post_load");
  42. mod->set_locale = os_dlsym(mod->module, "obs_module_set_locale");
  43. mod->free_locale = os_dlsym(mod->module, "obs_module_free_locale");
  44. mod->name = os_dlsym(mod->module, "obs_module_name");
  45. mod->description = os_dlsym(mod->module, "obs_module_description");
  46. mod->author = os_dlsym(mod->module, "obs_module_author");
  47. mod->get_string = os_dlsym(mod->module, "obs_module_get_string");
  48. return MODULE_SUCCESS;
  49. }
  50. bool obs_module_get_locale_string(const obs_module_t *mod,
  51. const char *lookup_string,
  52. const char **translated_string)
  53. {
  54. if (mod->get_string) {
  55. return mod->get_string(lookup_string, translated_string);
  56. }
  57. return false;
  58. }
  59. const char *obs_module_get_locale_text(const obs_module_t *mod,
  60. const char *text)
  61. {
  62. const char *str = text;
  63. obs_module_get_locale_string(mod, text, &str);
  64. return str;
  65. }
  66. static inline char *get_module_name(const char *file)
  67. {
  68. static size_t ext_len = 0;
  69. struct dstr name = {0};
  70. if (ext_len == 0) {
  71. const char *ext = get_module_extension();
  72. ext_len = strlen(ext);
  73. }
  74. dstr_copy(&name, file);
  75. dstr_resize(&name, name.len - ext_len);
  76. return name.array;
  77. }
  78. #ifdef _WIN32
  79. extern void reset_win32_symbol_paths(void);
  80. #endif
  81. int obs_open_module(obs_module_t **module, const char *path,
  82. const char *data_path)
  83. {
  84. struct obs_module mod = {0};
  85. int errorcode;
  86. if (!module || !path || !obs)
  87. return MODULE_ERROR;
  88. #ifdef __APPLE__
  89. /* HACK: Do not load obsolete obs-browser build on macOS; the
  90. * obs-browser plugin used to live in the Application Support
  91. * directory. */
  92. if (astrstri(path, "Library/Application Support") != NULL &&
  93. astrstri(path, "obs-browser") != NULL) {
  94. blog(LOG_WARNING, "Ignoring old obs-browser.so version");
  95. return MODULE_ERROR;
  96. }
  97. #endif
  98. blog(LOG_DEBUG, "---------------------------------");
  99. mod.module = os_dlopen(path);
  100. if (!mod.module) {
  101. blog(LOG_WARNING, "Module '%s' not loaded", path);
  102. return MODULE_FILE_NOT_FOUND;
  103. }
  104. errorcode = load_module_exports(&mod, path);
  105. if (errorcode != MODULE_SUCCESS)
  106. return errorcode;
  107. mod.bin_path = bstrdup(path);
  108. mod.file = strrchr(mod.bin_path, '/');
  109. mod.file = (!mod.file) ? mod.bin_path : (mod.file + 1);
  110. mod.mod_name = get_module_name(mod.file);
  111. mod.data_path = bstrdup(data_path);
  112. mod.next = obs->first_module;
  113. if (mod.file) {
  114. blog(LOG_DEBUG, "Loading module: %s", mod.file);
  115. }
  116. *module = bmemdup(&mod, sizeof(mod));
  117. obs->first_module = (*module);
  118. mod.set_pointer(*module);
  119. if (mod.set_locale)
  120. mod.set_locale(obs->locale);
  121. return MODULE_SUCCESS;
  122. }
  123. bool obs_init_module(obs_module_t *module)
  124. {
  125. if (!module || !obs)
  126. return false;
  127. if (module->loaded)
  128. return true;
  129. const char *profile_name =
  130. profile_store_name(obs_get_profiler_name_store(),
  131. "obs_init_module(%s)", module->file);
  132. profile_start(profile_name);
  133. module->loaded = module->load();
  134. if (!module->loaded)
  135. blog(LOG_WARNING, "Failed to initialize module '%s'",
  136. module->file);
  137. profile_end(profile_name);
  138. return module->loaded;
  139. }
  140. void obs_log_loaded_modules(void)
  141. {
  142. blog(LOG_INFO, " Loaded Modules:");
  143. for (obs_module_t *mod = obs->first_module; !!mod; mod = mod->next)
  144. blog(LOG_INFO, " %s", mod->file);
  145. }
  146. const char *obs_get_module_file_name(obs_module_t *module)
  147. {
  148. return module ? module->file : NULL;
  149. }
  150. const char *obs_get_module_name(obs_module_t *module)
  151. {
  152. return (module && module->name) ? module->name() : NULL;
  153. }
  154. const char *obs_get_module_author(obs_module_t *module)
  155. {
  156. return (module && module->author) ? module->author() : NULL;
  157. }
  158. const char *obs_get_module_description(obs_module_t *module)
  159. {
  160. return (module && module->description) ? module->description() : NULL;
  161. }
  162. const char *obs_get_module_binary_path(obs_module_t *module)
  163. {
  164. return module ? module->bin_path : NULL;
  165. }
  166. const char *obs_get_module_data_path(obs_module_t *module)
  167. {
  168. return module ? module->data_path : NULL;
  169. }
  170. obs_module_t *obs_get_module(const char *name)
  171. {
  172. obs_module_t *module = obs->first_module;
  173. while (module) {
  174. if (strcmp(module->mod_name, name) == 0) {
  175. return module;
  176. }
  177. module = module->next;
  178. }
  179. return NULL;
  180. }
  181. void *obs_get_module_lib(obs_module_t *module)
  182. {
  183. return module ? module->module : NULL;
  184. }
  185. char *obs_find_module_file(obs_module_t *module, const char *file)
  186. {
  187. struct dstr output = {0};
  188. if (!file)
  189. file = "";
  190. if (!module)
  191. return NULL;
  192. dstr_copy(&output, module->data_path);
  193. if (!dstr_is_empty(&output) && dstr_end(&output) != '/' && *file)
  194. dstr_cat_ch(&output, '/');
  195. dstr_cat(&output, file);
  196. if (!os_file_exists(output.array))
  197. dstr_free(&output);
  198. return output.array;
  199. }
  200. char *obs_module_get_config_path(obs_module_t *module, const char *file)
  201. {
  202. struct dstr output = {0};
  203. dstr_copy(&output, obs->module_config_path);
  204. if (!dstr_is_empty(&output) && dstr_end(&output) != '/')
  205. dstr_cat_ch(&output, '/');
  206. dstr_cat(&output, module->mod_name);
  207. dstr_cat_ch(&output, '/');
  208. dstr_cat(&output, file);
  209. return output.array;
  210. }
  211. void obs_add_module_path(const char *bin, const char *data)
  212. {
  213. struct obs_module_path omp;
  214. if (!obs || !bin || !data)
  215. return;
  216. omp.bin = bstrdup(bin);
  217. omp.data = bstrdup(data);
  218. da_push_back(obs->module_paths, &omp);
  219. }
  220. static void load_all_callback(void *param, const struct obs_module_info *info)
  221. {
  222. obs_module_t *module;
  223. if (!os_is_obs_plugin(info->bin_path))
  224. blog(LOG_WARNING, "Skipping module '%s', not an OBS plugin",
  225. info->bin_path);
  226. int code = obs_open_module(&module, info->bin_path, info->data_path);
  227. if (code != MODULE_SUCCESS) {
  228. blog(LOG_DEBUG, "Failed to load module file '%s': %d",
  229. info->bin_path, code);
  230. return;
  231. }
  232. obs_init_module(module);
  233. UNUSED_PARAMETER(param);
  234. }
  235. static const char *obs_load_all_modules_name = "obs_load_all_modules";
  236. #ifdef _WIN32
  237. static const char *reset_win32_symbol_paths_name = "reset_win32_symbol_paths";
  238. #endif
  239. void obs_load_all_modules(void)
  240. {
  241. profile_start(obs_load_all_modules_name);
  242. obs_find_modules(load_all_callback, NULL);
  243. #ifdef _WIN32
  244. profile_start(reset_win32_symbol_paths_name);
  245. reset_win32_symbol_paths();
  246. profile_end(reset_win32_symbol_paths_name);
  247. #endif
  248. profile_end(obs_load_all_modules_name);
  249. }
  250. void obs_post_load_modules(void)
  251. {
  252. for (obs_module_t *mod = obs->first_module; !!mod; mod = mod->next)
  253. if (mod->post_load)
  254. mod->post_load();
  255. }
  256. static inline void make_data_dir(struct dstr *parsed_data_dir,
  257. const char *data_dir, const char *name)
  258. {
  259. dstr_copy(parsed_data_dir, data_dir);
  260. dstr_replace(parsed_data_dir, "%module%", name);
  261. if (dstr_end(parsed_data_dir) == '/')
  262. dstr_resize(parsed_data_dir, parsed_data_dir->len - 1);
  263. }
  264. static char *make_data_directory(const char *module_name, const char *data_dir)
  265. {
  266. struct dstr parsed_data_dir = {0};
  267. bool found = false;
  268. make_data_dir(&parsed_data_dir, data_dir, module_name);
  269. found = os_file_exists(parsed_data_dir.array);
  270. if (!found && astrcmpi_n(module_name, "lib", 3) == 0)
  271. make_data_dir(&parsed_data_dir, data_dir, module_name + 3);
  272. return parsed_data_dir.array;
  273. }
  274. static bool parse_binary_from_directory(struct dstr *parsed_bin_path,
  275. const char *bin_path, const char *file)
  276. {
  277. struct dstr directory = {0};
  278. bool found = true;
  279. dstr_copy(&directory, bin_path);
  280. dstr_replace(&directory, "%module%", file);
  281. if (dstr_end(&directory) != '/')
  282. dstr_cat_ch(&directory, '/');
  283. dstr_copy_dstr(parsed_bin_path, &directory);
  284. dstr_cat(parsed_bin_path, file);
  285. dstr_cat(parsed_bin_path, get_module_extension());
  286. if (!os_file_exists(parsed_bin_path->array)) {
  287. /* if the file doesn't exist, check with 'lib' prefix */
  288. dstr_copy_dstr(parsed_bin_path, &directory);
  289. dstr_cat(parsed_bin_path, "lib");
  290. dstr_cat(parsed_bin_path, file);
  291. dstr_cat(parsed_bin_path, get_module_extension());
  292. /* if neither exist, don't include this as a library */
  293. if (!os_file_exists(parsed_bin_path->array)) {
  294. dstr_free(parsed_bin_path);
  295. found = false;
  296. }
  297. }
  298. dstr_free(&directory);
  299. return found;
  300. }
  301. static void process_found_module(struct obs_module_path *omp, const char *path,
  302. bool directory,
  303. obs_find_module_callback_t callback,
  304. void *param)
  305. {
  306. struct obs_module_info info;
  307. struct dstr name = {0};
  308. struct dstr parsed_bin_path = {0};
  309. const char *file;
  310. char *parsed_data_dir;
  311. bool bin_found = true;
  312. file = strrchr(path, '/');
  313. file = file ? (file + 1) : path;
  314. if (strcmp(file, ".") == 0 || strcmp(file, "..") == 0)
  315. return;
  316. dstr_copy(&name, file);
  317. if (!directory) {
  318. char *ext = strrchr(name.array, '.');
  319. if (ext)
  320. dstr_resize(&name, ext - name.array);
  321. dstr_copy(&parsed_bin_path, path);
  322. } else {
  323. bin_found = parse_binary_from_directory(&parsed_bin_path,
  324. omp->bin, file);
  325. }
  326. parsed_data_dir = make_data_directory(name.array, omp->data);
  327. if (parsed_data_dir && bin_found) {
  328. info.bin_path = parsed_bin_path.array;
  329. info.data_path = parsed_data_dir;
  330. callback(param, &info);
  331. }
  332. bfree(parsed_data_dir);
  333. dstr_free(&name);
  334. dstr_free(&parsed_bin_path);
  335. }
  336. static void find_modules_in_path(struct obs_module_path *omp,
  337. obs_find_module_callback_t callback,
  338. void *param)
  339. {
  340. struct dstr search_path = {0};
  341. char *module_start;
  342. bool search_directories = false;
  343. os_glob_t *gi;
  344. dstr_copy(&search_path, omp->bin);
  345. module_start = strstr(search_path.array, "%module%");
  346. if (module_start) {
  347. dstr_resize(&search_path, module_start - search_path.array);
  348. search_directories = true;
  349. }
  350. if (!dstr_is_empty(&search_path) && dstr_end(&search_path) != '/')
  351. dstr_cat_ch(&search_path, '/');
  352. dstr_cat_ch(&search_path, '*');
  353. if (!search_directories)
  354. dstr_cat(&search_path, get_module_extension());
  355. if (os_glob(search_path.array, 0, &gi) == 0) {
  356. for (size_t i = 0; i < gi->gl_pathc; i++) {
  357. if (search_directories == gi->gl_pathv[i].directory)
  358. process_found_module(omp, gi->gl_pathv[i].path,
  359. search_directories,
  360. callback, param);
  361. }
  362. os_globfree(gi);
  363. }
  364. dstr_free(&search_path);
  365. }
  366. void obs_find_modules(obs_find_module_callback_t callback, void *param)
  367. {
  368. if (!obs)
  369. return;
  370. for (size_t i = 0; i < obs->module_paths.num; i++) {
  371. struct obs_module_path *omp = obs->module_paths.array + i;
  372. find_modules_in_path(omp, callback, param);
  373. }
  374. }
  375. void obs_enum_modules(obs_enum_module_callback_t callback, void *param)
  376. {
  377. struct obs_module *module;
  378. if (!obs)
  379. return;
  380. module = obs->first_module;
  381. while (module) {
  382. callback(param, module);
  383. module = module->next;
  384. }
  385. }
  386. void free_module(struct obs_module *mod)
  387. {
  388. if (!mod)
  389. return;
  390. if (mod->module) {
  391. if (mod->free_locale)
  392. mod->free_locale();
  393. if (mod->loaded && mod->unload)
  394. mod->unload();
  395. /* there is no real reason to close the dynamic libraries,
  396. * and sometimes this can cause issues. */
  397. /* os_dlclose(mod->module); */
  398. }
  399. bfree(mod->mod_name);
  400. bfree(mod->bin_path);
  401. bfree(mod->data_path);
  402. bfree(mod);
  403. }
  404. lookup_t *obs_module_load_locale(obs_module_t *module,
  405. const char *default_locale, const char *locale)
  406. {
  407. struct dstr str = {0};
  408. lookup_t *lookup = NULL;
  409. if (!module || !default_locale || !locale) {
  410. blog(LOG_WARNING, "obs_module_load_locale: Invalid parameters");
  411. return NULL;
  412. }
  413. dstr_copy(&str, "locale/");
  414. dstr_cat(&str, default_locale);
  415. dstr_cat(&str, ".ini");
  416. char *file = obs_find_module_file(module, str.array);
  417. if (file)
  418. lookup = text_lookup_create(file);
  419. bfree(file);
  420. if (!lookup) {
  421. blog(LOG_WARNING, "Failed to load '%s' text for module: '%s'",
  422. default_locale, module->file);
  423. goto cleanup;
  424. }
  425. if (astrcmpi(locale, default_locale) == 0)
  426. goto cleanup;
  427. dstr_copy(&str, "/locale/");
  428. dstr_cat(&str, locale);
  429. dstr_cat(&str, ".ini");
  430. file = obs_find_module_file(module, str.array);
  431. if (!text_lookup_add(lookup, file))
  432. blog(LOG_WARNING, "Failed to load '%s' text for module: '%s'",
  433. locale, module->file);
  434. bfree(file);
  435. cleanup:
  436. dstr_free(&str);
  437. return lookup;
  438. }
  439. #define REGISTER_OBS_DEF(size_var, structure, dest, info) \
  440. do { \
  441. struct structure data = {0}; \
  442. if (!size_var) { \
  443. blog(LOG_ERROR, "Tried to register " #structure \
  444. " outside of obs_module_load"); \
  445. return; \
  446. } \
  447. \
  448. if (size_var > sizeof(data)) { \
  449. blog(LOG_ERROR, \
  450. "Tried to register " #structure \
  451. " with size %llu which is more " \
  452. "than libobs currently supports " \
  453. "(%llu)", \
  454. (long long unsigned)size_var, \
  455. (long long unsigned)sizeof(data)); \
  456. goto error; \
  457. } \
  458. \
  459. memcpy(&data, info, size_var); \
  460. da_push_back(dest, &data); \
  461. } while (false)
  462. #define CHECK_REQUIRED_VAL(type, info, val, func) \
  463. do { \
  464. if ((offsetof(type, val) + sizeof(info->val) > size) || \
  465. !info->val) { \
  466. blog(LOG_ERROR, \
  467. "Required value '" #val "' for " \
  468. "'%s' not found. " #func " failed.", \
  469. info->id); \
  470. goto error; \
  471. } \
  472. } while (false)
  473. #define HANDLE_ERROR(size_var, structure, info) \
  474. do { \
  475. struct structure data = {0}; \
  476. if (!size_var) \
  477. return; \
  478. \
  479. memcpy(&data, info, \
  480. sizeof(data) < size_var ? sizeof(data) : size_var); \
  481. \
  482. if (data.type_data && data.free_type_data) \
  483. data.free_type_data(data.type_data); \
  484. } while (false)
  485. #define source_warn(format, ...) \
  486. blog(LOG_WARNING, "obs_register_source: " format, ##__VA_ARGS__)
  487. #define output_warn(format, ...) \
  488. blog(LOG_WARNING, "obs_register_output: " format, ##__VA_ARGS__)
  489. #define encoder_warn(format, ...) \
  490. blog(LOG_WARNING, "obs_register_encoder: " format, ##__VA_ARGS__)
  491. #define service_warn(format, ...) \
  492. blog(LOG_WARNING, "obs_register_service: " format, ##__VA_ARGS__)
  493. void obs_register_source_s(const struct obs_source_info *info, size_t size)
  494. {
  495. struct obs_source_info data = {0};
  496. struct darray *array = NULL;
  497. if (info->type == OBS_SOURCE_TYPE_INPUT) {
  498. array = &obs->input_types.da;
  499. } else if (info->type == OBS_SOURCE_TYPE_FILTER) {
  500. array = &obs->filter_types.da;
  501. } else if (info->type == OBS_SOURCE_TYPE_TRANSITION) {
  502. array = &obs->transition_types.da;
  503. } else if (info->type != OBS_SOURCE_TYPE_SCENE) {
  504. source_warn("Tried to register unknown source type: %u",
  505. info->type);
  506. goto error;
  507. }
  508. if (get_source_info2(info->id, info->version)) {
  509. source_warn("Source '%s' already exists! "
  510. "Duplicate library?",
  511. info->id);
  512. goto error;
  513. }
  514. if (size > sizeof(data)) {
  515. source_warn("Tried to register obs_source_info with size "
  516. "%llu which is more than libobs currently "
  517. "supports (%llu)",
  518. (long long unsigned)size,
  519. (long long unsigned)sizeof(data));
  520. goto error;
  521. }
  522. memcpy(&data, info, size);
  523. /* mark audio-only filters as an async filter categorically */
  524. if (data.type == OBS_SOURCE_TYPE_FILTER) {
  525. if ((data.output_flags & OBS_SOURCE_VIDEO) == 0)
  526. data.output_flags |= OBS_SOURCE_ASYNC;
  527. }
  528. if (data.type == OBS_SOURCE_TYPE_TRANSITION) {
  529. if (data.get_width)
  530. source_warn("get_width ignored registering "
  531. "transition '%s'",
  532. data.id);
  533. if (data.get_height)
  534. source_warn("get_height ignored registering "
  535. "transition '%s'",
  536. data.id);
  537. data.output_flags |= OBS_SOURCE_COMPOSITE | OBS_SOURCE_VIDEO |
  538. OBS_SOURCE_CUSTOM_DRAW;
  539. }
  540. if ((data.output_flags & OBS_SOURCE_COMPOSITE) != 0) {
  541. if ((data.output_flags & OBS_SOURCE_AUDIO) != 0) {
  542. source_warn("Source '%s': Composite sources "
  543. "cannot be audio sources",
  544. info->id);
  545. goto error;
  546. }
  547. if ((data.output_flags & OBS_SOURCE_ASYNC) != 0) {
  548. source_warn("Source '%s': Composite sources "
  549. "cannot be async sources",
  550. info->id);
  551. goto error;
  552. }
  553. }
  554. #define CHECK_REQUIRED_VAL_(info, val, func) \
  555. CHECK_REQUIRED_VAL(struct obs_source_info, info, val, func)
  556. CHECK_REQUIRED_VAL_(info, get_name, obs_register_source);
  557. if (info->type != OBS_SOURCE_TYPE_FILTER &&
  558. info->type != OBS_SOURCE_TYPE_TRANSITION &&
  559. (info->output_flags & OBS_SOURCE_VIDEO) != 0 &&
  560. (info->output_flags & OBS_SOURCE_ASYNC) == 0) {
  561. CHECK_REQUIRED_VAL_(info, get_width, obs_register_source);
  562. CHECK_REQUIRED_VAL_(info, get_height, obs_register_source);
  563. }
  564. if ((data.output_flags & OBS_SOURCE_COMPOSITE) != 0) {
  565. CHECK_REQUIRED_VAL_(info, audio_render, obs_register_source);
  566. }
  567. #undef CHECK_REQUIRED_VAL_
  568. /* version-related stuff */
  569. data.unversioned_id = data.id;
  570. if (data.version) {
  571. struct dstr versioned_id = {0};
  572. dstr_printf(&versioned_id, "%s_v%d", data.id,
  573. (int)data.version);
  574. data.id = versioned_id.array;
  575. } else {
  576. data.id = bstrdup(data.id);
  577. }
  578. if (array)
  579. darray_push_back(sizeof(struct obs_source_info), array, &data);
  580. da_push_back(obs->source_types, &data);
  581. return;
  582. error:
  583. HANDLE_ERROR(size, obs_source_info, info);
  584. }
  585. void obs_register_output_s(const struct obs_output_info *info, size_t size)
  586. {
  587. if (find_output(info->id)) {
  588. output_warn("Output id '%s' already exists! "
  589. "Duplicate library?",
  590. info->id);
  591. goto error;
  592. }
  593. #define CHECK_REQUIRED_VAL_(info, val, func) \
  594. CHECK_REQUIRED_VAL(struct obs_output_info, info, val, func)
  595. CHECK_REQUIRED_VAL_(info, get_name, obs_register_output);
  596. CHECK_REQUIRED_VAL_(info, create, obs_register_output);
  597. CHECK_REQUIRED_VAL_(info, destroy, obs_register_output);
  598. CHECK_REQUIRED_VAL_(info, start, obs_register_output);
  599. CHECK_REQUIRED_VAL_(info, stop, obs_register_output);
  600. if (info->flags & OBS_OUTPUT_ENCODED) {
  601. CHECK_REQUIRED_VAL_(info, encoded_packet, obs_register_output);
  602. } else {
  603. if (info->flags & OBS_OUTPUT_VIDEO)
  604. CHECK_REQUIRED_VAL_(info, raw_video,
  605. obs_register_output);
  606. if (info->flags & OBS_OUTPUT_AUDIO) {
  607. if (info->flags & OBS_OUTPUT_MULTI_TRACK) {
  608. CHECK_REQUIRED_VAL_(info, raw_audio2,
  609. obs_register_output);
  610. } else {
  611. CHECK_REQUIRED_VAL_(info, raw_audio,
  612. obs_register_output);
  613. }
  614. }
  615. }
  616. #undef CHECK_REQUIRED_VAL_
  617. REGISTER_OBS_DEF(size, obs_output_info, obs->output_types, info);
  618. return;
  619. error:
  620. HANDLE_ERROR(size, obs_output_info, info);
  621. }
  622. void obs_register_encoder_s(const struct obs_encoder_info *info, size_t size)
  623. {
  624. if (find_encoder(info->id)) {
  625. encoder_warn("Encoder id '%s' already exists! "
  626. "Duplicate library?",
  627. info->id);
  628. goto error;
  629. }
  630. #define CHECK_REQUIRED_VAL_(info, val, func) \
  631. CHECK_REQUIRED_VAL(struct obs_encoder_info, info, val, func)
  632. CHECK_REQUIRED_VAL_(info, get_name, obs_register_encoder);
  633. CHECK_REQUIRED_VAL_(info, create, obs_register_encoder);
  634. CHECK_REQUIRED_VAL_(info, destroy, obs_register_encoder);
  635. if ((info->caps & OBS_ENCODER_CAP_PASS_TEXTURE) != 0)
  636. CHECK_REQUIRED_VAL_(info, encode_texture, obs_register_encoder);
  637. else
  638. CHECK_REQUIRED_VAL_(info, encode, obs_register_encoder);
  639. if (info->type == OBS_ENCODER_AUDIO)
  640. CHECK_REQUIRED_VAL_(info, get_frame_size, obs_register_encoder);
  641. #undef CHECK_REQUIRED_VAL_
  642. REGISTER_OBS_DEF(size, obs_encoder_info, obs->encoder_types, info);
  643. return;
  644. error:
  645. HANDLE_ERROR(size, obs_encoder_info, info);
  646. }
  647. void obs_register_service_s(const struct obs_service_info *info, size_t size)
  648. {
  649. if (find_service(info->id)) {
  650. service_warn("Service id '%s' already exists! "
  651. "Duplicate library?",
  652. info->id);
  653. goto error;
  654. }
  655. #define CHECK_REQUIRED_VAL_(info, val, func) \
  656. CHECK_REQUIRED_VAL(struct obs_service_info, info, val, func)
  657. CHECK_REQUIRED_VAL_(info, get_name, obs_register_service);
  658. CHECK_REQUIRED_VAL_(info, create, obs_register_service);
  659. CHECK_REQUIRED_VAL_(info, destroy, obs_register_service);
  660. #undef CHECK_REQUIRED_VAL_
  661. REGISTER_OBS_DEF(size, obs_service_info, obs->service_types, info);
  662. return;
  663. error:
  664. HANDLE_ERROR(size, obs_service_info, info);
  665. }
  666. void obs_register_modal_ui_s(const struct obs_modal_ui *info, size_t size)
  667. {
  668. #define CHECK_REQUIRED_VAL_(info, val, func) \
  669. CHECK_REQUIRED_VAL(struct obs_modal_ui, info, val, func)
  670. CHECK_REQUIRED_VAL_(info, task, obs_register_modal_ui);
  671. CHECK_REQUIRED_VAL_(info, target, obs_register_modal_ui);
  672. CHECK_REQUIRED_VAL_(info, exec, obs_register_modal_ui);
  673. #undef CHECK_REQUIRED_VAL_
  674. REGISTER_OBS_DEF(size, obs_modal_ui, obs->modal_ui_callbacks, info);
  675. return;
  676. error:
  677. HANDLE_ERROR(size, obs_modal_ui, info);
  678. }
  679. void obs_register_modeless_ui_s(const struct obs_modeless_ui *info, size_t size)
  680. {
  681. #define CHECK_REQUIRED_VAL_(info, val, func) \
  682. CHECK_REQUIRED_VAL(struct obs_modeless_ui, info, val, func)
  683. CHECK_REQUIRED_VAL_(info, task, obs_register_modeless_ui);
  684. CHECK_REQUIRED_VAL_(info, target, obs_register_modeless_ui);
  685. CHECK_REQUIRED_VAL_(info, create, obs_register_modeless_ui);
  686. #undef CHECK_REQUIRED_VAL_
  687. REGISTER_OBS_DEF(size, obs_modeless_ui, obs->modeless_ui_callbacks,
  688. info);
  689. return;
  690. error:
  691. HANDLE_ERROR(size, obs_modeless_ui, info);
  692. }