obs-module.c 21 KB

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