1
0

obs-module.c 21 KB

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