1
0

obs-module.c 22 KB

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