obs-module.c 21 KB

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