obs.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459
  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 <inttypes.h>
  15. #include "graphics/matrix4.h"
  16. #include "callback/calldata.h"
  17. #include "obs.h"
  18. #include "obs-internal.h"
  19. struct obs_core *obs = NULL;
  20. extern void add_default_module_paths(void);
  21. extern char *find_libobs_data_file(const char *file);
  22. static inline void make_gs_init_data(struct gs_init_data *gid,
  23. const struct obs_video_info *ovi)
  24. {
  25. memcpy(&gid->window, &ovi->window, sizeof(struct gs_window));
  26. gid->cx = ovi->window_width;
  27. gid->cy = ovi->window_height;
  28. gid->num_backbuffers = 2;
  29. gid->format = GS_RGBA;
  30. gid->zsformat = GS_ZS_NONE;
  31. gid->adapter = ovi->adapter;
  32. }
  33. static inline void make_video_info(struct video_output_info *vi,
  34. struct obs_video_info *ovi)
  35. {
  36. vi->name = "video";
  37. vi->format = ovi->output_format;
  38. vi->fps_num = ovi->fps_num;
  39. vi->fps_den = ovi->fps_den;
  40. vi->width = ovi->output_width;
  41. vi->height = ovi->output_height;
  42. vi->range = ovi->range;
  43. vi->colorspace = ovi->colorspace;
  44. vi->cache_size = 6;
  45. }
  46. #define PIXEL_SIZE 4
  47. #define GET_ALIGN(val, align) \
  48. (((val) + (align-1)) & ~(align-1))
  49. static inline void set_420p_sizes(const struct obs_video_info *ovi)
  50. {
  51. struct obs_core_video *video = &obs->video;
  52. uint32_t chroma_pixels;
  53. uint32_t total_bytes;
  54. chroma_pixels = (ovi->output_width * ovi->output_height / 4);
  55. chroma_pixels = GET_ALIGN(chroma_pixels, PIXEL_SIZE);
  56. video->plane_offsets[0] = 0;
  57. video->plane_offsets[1] = ovi->output_width * ovi->output_height;
  58. video->plane_offsets[2] = video->plane_offsets[1] + chroma_pixels;
  59. video->plane_linewidth[0] = ovi->output_width;
  60. video->plane_linewidth[1] = ovi->output_width/2;
  61. video->plane_linewidth[2] = ovi->output_width/2;
  62. video->plane_sizes[0] = video->plane_offsets[1];
  63. video->plane_sizes[1] = video->plane_sizes[0]/4;
  64. video->plane_sizes[2] = video->plane_sizes[1];
  65. total_bytes = video->plane_offsets[2] + chroma_pixels;
  66. video->conversion_height =
  67. (total_bytes/PIXEL_SIZE + ovi->output_width-1) /
  68. ovi->output_width;
  69. video->conversion_height = GET_ALIGN(video->conversion_height, 2);
  70. video->conversion_tech = "Planar420";
  71. }
  72. static inline void set_nv12_sizes(const struct obs_video_info *ovi)
  73. {
  74. struct obs_core_video *video = &obs->video;
  75. uint32_t chroma_pixels;
  76. uint32_t total_bytes;
  77. chroma_pixels = (ovi->output_width * ovi->output_height / 2);
  78. chroma_pixels = GET_ALIGN(chroma_pixels, PIXEL_SIZE);
  79. video->plane_offsets[0] = 0;
  80. video->plane_offsets[1] = ovi->output_width * ovi->output_height;
  81. video->plane_linewidth[0] = ovi->output_width;
  82. video->plane_linewidth[1] = ovi->output_width;
  83. video->plane_sizes[0] = video->plane_offsets[1];
  84. video->plane_sizes[1] = video->plane_sizes[0]/2;
  85. total_bytes = video->plane_offsets[1] + chroma_pixels;
  86. video->conversion_height =
  87. (total_bytes/PIXEL_SIZE + ovi->output_width-1) /
  88. ovi->output_width;
  89. video->conversion_height = GET_ALIGN(video->conversion_height, 2);
  90. video->conversion_tech = "NV12";
  91. }
  92. static inline void calc_gpu_conversion_sizes(const struct obs_video_info *ovi)
  93. {
  94. obs->video.conversion_height = 0;
  95. memset(obs->video.plane_offsets, 0, sizeof(obs->video.plane_offsets));
  96. memset(obs->video.plane_sizes, 0, sizeof(obs->video.plane_sizes));
  97. memset(obs->video.plane_linewidth, 0,
  98. sizeof(obs->video.plane_linewidth));
  99. switch ((uint32_t)ovi->output_format) {
  100. case VIDEO_FORMAT_I420:
  101. set_420p_sizes(ovi);
  102. break;
  103. case VIDEO_FORMAT_NV12:
  104. set_nv12_sizes(ovi);
  105. break;
  106. }
  107. }
  108. static bool obs_init_gpu_conversion(struct obs_video_info *ovi)
  109. {
  110. struct obs_core_video *video = &obs->video;
  111. calc_gpu_conversion_sizes(ovi);
  112. if (!video->conversion_height) {
  113. blog(LOG_INFO, "GPU conversion not available for format: %u",
  114. (unsigned int)ovi->output_format);
  115. video->gpu_conversion = false;
  116. return true;
  117. }
  118. for (size_t i = 0; i < NUM_TEXTURES; i++) {
  119. video->convert_textures[i] = gs_texture_create(
  120. ovi->output_width, video->conversion_height,
  121. GS_RGBA, 1, NULL, GS_RENDER_TARGET);
  122. if (!video->convert_textures[i])
  123. return false;
  124. }
  125. return true;
  126. }
  127. static bool obs_init_textures(struct obs_video_info *ovi)
  128. {
  129. struct obs_core_video *video = &obs->video;
  130. uint32_t output_height = video->gpu_conversion ?
  131. video->conversion_height : ovi->output_height;
  132. size_t i;
  133. for (i = 0; i < NUM_TEXTURES; i++) {
  134. video->copy_surfaces[i] = gs_stagesurface_create(
  135. ovi->output_width, output_height, GS_RGBA);
  136. if (!video->copy_surfaces[i])
  137. return false;
  138. video->render_textures[i] = gs_texture_create(
  139. ovi->base_width, ovi->base_height,
  140. GS_RGBA, 1, NULL, GS_RENDER_TARGET);
  141. if (!video->render_textures[i])
  142. return false;
  143. video->output_textures[i] = gs_texture_create(
  144. ovi->output_width, ovi->output_height,
  145. GS_RGBA, 1, NULL, GS_RENDER_TARGET);
  146. if (!video->output_textures[i])
  147. return false;
  148. }
  149. return true;
  150. }
  151. static int obs_init_graphics(struct obs_video_info *ovi)
  152. {
  153. struct obs_core_video *video = &obs->video;
  154. struct gs_init_data graphics_data;
  155. bool success = true;
  156. int errorcode;
  157. make_gs_init_data(&graphics_data, ovi);
  158. errorcode = gs_create(&video->graphics, ovi->graphics_module,
  159. &graphics_data);
  160. if (errorcode != GS_SUCCESS) {
  161. switch (errorcode) {
  162. case GS_ERROR_MODULE_NOT_FOUND:
  163. return OBS_VIDEO_MODULE_NOT_FOUND;
  164. case GS_ERROR_NOT_SUPPORTED:
  165. return OBS_VIDEO_NOT_SUPPORTED;
  166. default:
  167. return OBS_VIDEO_FAIL;
  168. }
  169. }
  170. gs_enter_context(video->graphics);
  171. char *filename = find_libobs_data_file("default.effect");
  172. video->default_effect = gs_effect_create_from_file(filename,
  173. NULL);
  174. bfree(filename);
  175. if (gs_get_device_type() == GS_DEVICE_OPENGL) {
  176. filename = find_libobs_data_file("default_rect.effect");
  177. video->default_rect_effect = gs_effect_create_from_file(
  178. filename, NULL);
  179. bfree(filename);
  180. }
  181. filename = find_libobs_data_file("solid.effect");
  182. video->solid_effect = gs_effect_create_from_file(filename,
  183. NULL);
  184. bfree(filename);
  185. filename = find_libobs_data_file("format_conversion.effect");
  186. video->conversion_effect = gs_effect_create_from_file(filename,
  187. NULL);
  188. bfree(filename);
  189. filename = find_libobs_data_file("bicubic_scale.effect");
  190. video->bicubic_effect = gs_effect_create_from_file(filename,
  191. NULL);
  192. bfree(filename);
  193. filename = find_libobs_data_file("lanczos_scale.effect");
  194. video->lanczos_effect = gs_effect_create_from_file(filename,
  195. NULL);
  196. bfree(filename);
  197. if (!video->default_effect)
  198. success = false;
  199. if (gs_get_device_type() == GS_DEVICE_OPENGL) {
  200. if (!video->default_rect_effect)
  201. success = false;
  202. }
  203. if (!video->solid_effect)
  204. success = false;
  205. if (!video->conversion_effect)
  206. success = false;
  207. gs_leave_context();
  208. return success ? OBS_VIDEO_SUCCESS : OBS_VIDEO_FAIL;
  209. }
  210. static inline void set_video_matrix(struct obs_core_video *video,
  211. struct obs_video_info *ovi)
  212. {
  213. struct matrix4 mat;
  214. struct vec4 r_row;
  215. if (format_is_yuv(ovi->output_format)) {
  216. video_format_get_parameters(ovi->colorspace, ovi->range,
  217. (float*)&mat, NULL, NULL);
  218. matrix4_inv(&mat, &mat);
  219. /* swap R and G */
  220. r_row = mat.x;
  221. mat.x = mat.y;
  222. mat.y = r_row;
  223. } else {
  224. matrix4_identity(&mat);
  225. }
  226. memcpy(video->color_matrix, &mat, sizeof(float) * 16);
  227. }
  228. static int obs_init_video(struct obs_video_info *ovi)
  229. {
  230. struct obs_core_video *video = &obs->video;
  231. struct video_output_info vi;
  232. int errorcode;
  233. make_video_info(&vi, ovi);
  234. video->base_width = ovi->base_width;
  235. video->base_height = ovi->base_height;
  236. video->output_width = ovi->output_width;
  237. video->output_height = ovi->output_height;
  238. video->gpu_conversion = ovi->gpu_conversion;
  239. video->scale_type = ovi->scale_type;
  240. set_video_matrix(video, ovi);
  241. errorcode = video_output_open(&video->video, &vi);
  242. if (errorcode != VIDEO_OUTPUT_SUCCESS) {
  243. if (errorcode == VIDEO_OUTPUT_INVALIDPARAM) {
  244. blog(LOG_ERROR, "Invalid video parameters specified");
  245. return OBS_VIDEO_INVALID_PARAM;
  246. } else {
  247. blog(LOG_ERROR, "Could not open video output");
  248. }
  249. return OBS_VIDEO_FAIL;
  250. }
  251. if (!obs_display_init(&video->main_display, NULL))
  252. return OBS_VIDEO_FAIL;
  253. video->main_display.cx = ovi->window_width;
  254. video->main_display.cy = ovi->window_height;
  255. gs_enter_context(video->graphics);
  256. if (ovi->gpu_conversion && !obs_init_gpu_conversion(ovi))
  257. return OBS_VIDEO_FAIL;
  258. if (!obs_init_textures(ovi))
  259. return OBS_VIDEO_FAIL;
  260. gs_leave_context();
  261. errorcode = pthread_create(&video->video_thread, NULL,
  262. obs_video_thread, obs);
  263. if (errorcode != 0)
  264. return OBS_VIDEO_FAIL;
  265. video->thread_initialized = true;
  266. return OBS_VIDEO_SUCCESS;
  267. }
  268. static void stop_video(void)
  269. {
  270. struct obs_core_video *video = &obs->video;
  271. void *thread_retval;
  272. if (video->video) {
  273. video_output_stop(video->video);
  274. if (video->thread_initialized) {
  275. pthread_join(video->video_thread, &thread_retval);
  276. video->thread_initialized = false;
  277. }
  278. }
  279. }
  280. static void obs_free_video(void)
  281. {
  282. struct obs_core_video *video = &obs->video;
  283. if (video->video) {
  284. obs_display_free(&video->main_display);
  285. video_output_close(video->video);
  286. video->video = NULL;
  287. if (!video->graphics)
  288. return;
  289. gs_enter_context(video->graphics);
  290. if (video->mapped_surface) {
  291. gs_stagesurface_unmap(video->mapped_surface);
  292. video->mapped_surface = NULL;
  293. }
  294. for (size_t i = 0; i < NUM_TEXTURES; i++) {
  295. gs_stagesurface_destroy(video->copy_surfaces[i]);
  296. gs_texture_destroy(video->render_textures[i]);
  297. gs_texture_destroy(video->convert_textures[i]);
  298. gs_texture_destroy(video->output_textures[i]);
  299. video->copy_surfaces[i] = NULL;
  300. video->render_textures[i] = NULL;
  301. video->convert_textures[i] = NULL;
  302. video->output_textures[i] = NULL;
  303. }
  304. gs_leave_context();
  305. circlebuf_free(&video->vframe_info_buffer);
  306. memset(&video->textures_rendered, 0,
  307. sizeof(video->textures_rendered));
  308. memset(&video->textures_output, 0,
  309. sizeof(video->textures_output));
  310. memset(&video->textures_copied, 0,
  311. sizeof(video->textures_copied));
  312. memset(&video->textures_converted, 0,
  313. sizeof(video->textures_converted));
  314. video->cur_texture = 0;
  315. }
  316. }
  317. static void obs_free_graphics(void)
  318. {
  319. struct obs_core_video *video = &obs->video;
  320. if (video->graphics) {
  321. gs_enter_context(video->graphics);
  322. gs_effect_destroy(video->default_effect);
  323. gs_effect_destroy(video->default_rect_effect);
  324. gs_effect_destroy(video->solid_effect);
  325. gs_effect_destroy(video->conversion_effect);
  326. gs_effect_destroy(video->bicubic_effect);
  327. gs_effect_destroy(video->lanczos_effect);
  328. video->default_effect = NULL;
  329. gs_leave_context();
  330. gs_destroy(video->graphics);
  331. video->graphics = NULL;
  332. }
  333. }
  334. static bool obs_init_audio(struct audio_output_info *ai)
  335. {
  336. struct obs_core_audio *audio = &obs->audio;
  337. int errorcode;
  338. /* TODO: sound subsystem */
  339. audio->user_volume = 1.0f;
  340. audio->present_volume = 1.0f;
  341. errorcode = audio_output_open(&audio->audio, ai);
  342. if (errorcode == AUDIO_OUTPUT_SUCCESS)
  343. return true;
  344. else if (errorcode == AUDIO_OUTPUT_INVALIDPARAM)
  345. blog(LOG_ERROR, "Invalid audio parameters specified");
  346. else
  347. blog(LOG_ERROR, "Could not open audio output");
  348. return false;
  349. }
  350. static void obs_free_audio(void)
  351. {
  352. struct obs_core_audio *audio = &obs->audio;
  353. if (audio->audio)
  354. audio_output_close(audio->audio);
  355. memset(audio, 0, sizeof(struct obs_core_audio));
  356. }
  357. static bool obs_init_data(void)
  358. {
  359. struct obs_core_data *data = &obs->data;
  360. pthread_mutexattr_t attr;
  361. assert(data != NULL);
  362. pthread_mutex_init_value(&obs->data.displays_mutex);
  363. if (pthread_mutexattr_init(&attr) != 0)
  364. return false;
  365. if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
  366. goto fail;
  367. if (pthread_mutex_init(&data->user_sources_mutex, &attr) != 0)
  368. goto fail;
  369. if (pthread_mutex_init(&data->sources_mutex, &attr) != 0)
  370. goto fail;
  371. if (pthread_mutex_init(&data->displays_mutex, &attr) != 0)
  372. goto fail;
  373. if (pthread_mutex_init(&data->outputs_mutex, &attr) != 0)
  374. goto fail;
  375. if (pthread_mutex_init(&data->encoders_mutex, &attr) != 0)
  376. goto fail;
  377. if (pthread_mutex_init(&data->services_mutex, &attr) != 0)
  378. goto fail;
  379. if (!obs_view_init(&data->main_view))
  380. goto fail;
  381. data->valid = true;
  382. fail:
  383. pthread_mutexattr_destroy(&attr);
  384. return data->valid;
  385. }
  386. void obs_main_view_free(struct obs_view *view)
  387. {
  388. if (!view) return;
  389. for (size_t i = 0; i < MAX_CHANNELS; i++)
  390. obs_source_release(view->channels[i]);
  391. memset(view->channels, 0, sizeof(view->channels));
  392. pthread_mutex_destroy(&view->channels_mutex);
  393. }
  394. #define FREE_OBS_LINKED_LIST(type) \
  395. do { \
  396. int unfreed = 0; \
  397. while (data->first_ ## type ) { \
  398. obs_ ## type ## _destroy(data->first_ ## type ); \
  399. unfreed++; \
  400. } \
  401. if (unfreed) \
  402. blog(LOG_INFO, "\t%d " #type "(s) were remaining", \
  403. unfreed); \
  404. } while (false)
  405. static void obs_free_data(void)
  406. {
  407. struct obs_core_data *data = &obs->data;
  408. data->valid = false;
  409. obs_main_view_free(&data->main_view);
  410. blog(LOG_INFO, "Freeing OBS context data");
  411. if (data->user_sources.num)
  412. blog(LOG_INFO, "\t%d user source(s) were remaining",
  413. (int)data->user_sources.num);
  414. while (data->user_sources.num)
  415. obs_source_remove(data->user_sources.array[0]);
  416. da_free(data->user_sources);
  417. FREE_OBS_LINKED_LIST(source);
  418. FREE_OBS_LINKED_LIST(output);
  419. FREE_OBS_LINKED_LIST(encoder);
  420. FREE_OBS_LINKED_LIST(display);
  421. FREE_OBS_LINKED_LIST(service);
  422. pthread_mutex_destroy(&data->user_sources_mutex);
  423. pthread_mutex_destroy(&data->sources_mutex);
  424. pthread_mutex_destroy(&data->displays_mutex);
  425. pthread_mutex_destroy(&data->outputs_mutex);
  426. pthread_mutex_destroy(&data->encoders_mutex);
  427. pthread_mutex_destroy(&data->services_mutex);
  428. }
  429. static const char *obs_signals[] = {
  430. "void source_create(ptr source)",
  431. "void source_destroy(ptr source)",
  432. "void source_add(ptr source)",
  433. "void source_remove(ptr source)",
  434. "void source_activate(ptr source)",
  435. "void source_deactivate(ptr source)",
  436. "void source_show(ptr source)",
  437. "void source_hide(ptr source)",
  438. "void source_rename(ptr source, string new_name, string prev_name)",
  439. "void source_volume(ptr source, in out float volume)",
  440. "void source_volume_level(ptr source, float level, float magnitude, "
  441. "float peak)",
  442. "void channel_change(int channel, in out ptr source, ptr prev_source)",
  443. "void master_volume(in out float volume)",
  444. NULL
  445. };
  446. static inline bool obs_init_handlers(void)
  447. {
  448. obs->signals = signal_handler_create();
  449. if (!obs->signals)
  450. return false;
  451. obs->procs = proc_handler_create();
  452. if (!obs->procs)
  453. return false;
  454. return signal_handler_add_array(obs->signals, obs_signals);
  455. }
  456. extern const struct obs_source_info scene_info;
  457. extern void log_system_info(void);
  458. static bool obs_init(const char *locale)
  459. {
  460. obs = bzalloc(sizeof(struct obs_core));
  461. log_system_info();
  462. if (!obs_init_data())
  463. return false;
  464. if (!obs_init_handlers())
  465. return false;
  466. obs->locale = bstrdup(locale);
  467. obs_register_source(&scene_info);
  468. add_default_module_paths();
  469. return true;
  470. }
  471. #ifdef _WIN32
  472. extern void initialize_crash_handler(void);
  473. #endif
  474. bool obs_startup(const char *locale)
  475. {
  476. bool success;
  477. if (obs) {
  478. blog(LOG_WARNING, "Tried to call obs_startup more than once");
  479. return false;
  480. }
  481. #ifdef _WIN32
  482. initialize_crash_handler();
  483. #endif
  484. success = obs_init(locale);
  485. if (!success)
  486. obs_shutdown();
  487. return success;
  488. }
  489. void obs_shutdown(void)
  490. {
  491. struct obs_module *module;
  492. if (!obs)
  493. return;
  494. da_free(obs->input_types);
  495. da_free(obs->filter_types);
  496. da_free(obs->encoder_types);
  497. da_free(obs->transition_types);
  498. da_free(obs->output_types);
  499. da_free(obs->service_types);
  500. da_free(obs->modal_ui_callbacks);
  501. da_free(obs->modeless_ui_callbacks);
  502. stop_video();
  503. obs_free_data();
  504. obs_free_video();
  505. obs_free_graphics();
  506. obs_free_audio();
  507. proc_handler_destroy(obs->procs);
  508. signal_handler_destroy(obs->signals);
  509. module = obs->first_module;
  510. while (module) {
  511. struct obs_module *next = module->next;
  512. free_module(module);
  513. module = next;
  514. }
  515. obs->first_module = NULL;
  516. for (size_t i = 0; i < obs->module_paths.num; i++)
  517. free_module_path(obs->module_paths.array+i);
  518. da_free(obs->module_paths);
  519. bfree(obs->locale);
  520. bfree(obs);
  521. obs = NULL;
  522. }
  523. bool obs_initialized(void)
  524. {
  525. return obs != NULL;
  526. }
  527. uint32_t obs_get_version(void)
  528. {
  529. return LIBOBS_API_VER;
  530. }
  531. void obs_set_locale(const char *locale)
  532. {
  533. struct obs_module *module;
  534. if (!obs)
  535. return;
  536. if (obs->locale)
  537. bfree(obs->locale);
  538. obs->locale = bstrdup(locale);
  539. module = obs->first_module;
  540. while (module) {
  541. if (module->set_locale)
  542. module->set_locale(locale);
  543. module = module->next;
  544. }
  545. }
  546. const char *obs_get_locale(void)
  547. {
  548. return obs ? obs->locale : NULL;
  549. }
  550. #define OBS_SIZE_MIN 2
  551. #define OBS_SIZE_MAX (32 * 1024)
  552. static inline bool size_valid(uint32_t width, uint32_t height)
  553. {
  554. return (width >= OBS_SIZE_MIN && height >= OBS_SIZE_MIN &&
  555. width <= OBS_SIZE_MAX && height <= OBS_SIZE_MAX);
  556. }
  557. int obs_reset_video(struct obs_video_info *ovi)
  558. {
  559. if (!obs) return OBS_VIDEO_FAIL;
  560. /* don't allow changing of video settings if active. */
  561. if (obs->video.video && video_output_active(obs->video.video))
  562. return OBS_VIDEO_CURRENTLY_ACTIVE;
  563. if (!size_valid(ovi->output_width, ovi->output_height) ||
  564. !size_valid(ovi->base_width, ovi->base_height))
  565. return OBS_VIDEO_INVALID_PARAM;
  566. struct obs_core_video *video = &obs->video;
  567. stop_video();
  568. obs_free_video();
  569. if (!ovi) {
  570. obs_free_graphics();
  571. return OBS_VIDEO_SUCCESS;
  572. }
  573. /* align to multiple-of-two and SSE alignment sizes */
  574. ovi->output_width &= 0xFFFFFFFC;
  575. ovi->output_height &= 0xFFFFFFFE;
  576. if (!video->graphics) {
  577. int errorcode = obs_init_graphics(ovi);
  578. if (errorcode != OBS_VIDEO_SUCCESS) {
  579. obs_free_graphics();
  580. return errorcode;
  581. }
  582. }
  583. blog(LOG_INFO, "video settings reset:\n"
  584. "\tbase resolution: %dx%d\n"
  585. "\toutput resolution: %dx%d\n"
  586. "\tfps: %d/%d",
  587. ovi->base_width, ovi->base_height,
  588. ovi->output_width, ovi->output_height,
  589. ovi->fps_num, ovi->fps_den);
  590. return obs_init_video(ovi);
  591. }
  592. bool obs_reset_audio(struct audio_output_info *ai)
  593. {
  594. if (!obs) return false;
  595. /* don't allow changing of audio settings if active. */
  596. if (obs->audio.audio && audio_output_active(obs->audio.audio))
  597. return false;
  598. obs_free_audio();
  599. if(!ai)
  600. return true;
  601. blog(LOG_INFO, "audio settings reset:\n"
  602. "\tsamples per sec: %d\n"
  603. "\tspeakers: %d\n"
  604. "\tbuffering (ms): %d\n",
  605. (int)ai->samples_per_sec,
  606. (int)ai->speakers,
  607. (int)ai->buffer_ms);
  608. return obs_init_audio(ai);
  609. }
  610. bool obs_get_video_info(struct obs_video_info *ovi)
  611. {
  612. struct obs_core_video *video = &obs->video;
  613. const struct video_output_info *info;
  614. if (!obs || !video->graphics)
  615. return false;
  616. info = video_output_get_info(video->video);
  617. if (!info)
  618. return false;
  619. memset(ovi, 0, sizeof(struct obs_video_info));
  620. ovi->base_width = video->base_width;
  621. ovi->base_height = video->base_height;
  622. ovi->gpu_conversion= video->gpu_conversion;
  623. ovi->scale_type = video->scale_type;
  624. ovi->colorspace = info->colorspace;
  625. ovi->range = info->range;
  626. ovi->output_width = info->width;
  627. ovi->output_height = info->height;
  628. ovi->output_format = info->format;
  629. ovi->fps_num = info->fps_num;
  630. ovi->fps_den = info->fps_den;
  631. return true;
  632. }
  633. bool obs_get_audio_info(struct audio_output_info *aoi)
  634. {
  635. struct obs_core_audio *audio = &obs->audio;
  636. const struct audio_output_info *info;
  637. if (!obs || !audio->audio)
  638. return false;
  639. info = audio_output_get_info(audio->audio);
  640. memcpy(aoi, info, sizeof(struct audio_output_info));
  641. return true;
  642. }
  643. bool obs_enum_input_types(size_t idx, const char **id)
  644. {
  645. if (!obs) return false;
  646. if (idx >= obs->input_types.num)
  647. return false;
  648. *id = obs->input_types.array[idx].id;
  649. return true;
  650. }
  651. bool obs_enum_filter_types(size_t idx, const char **id)
  652. {
  653. if (!obs) return false;
  654. if (idx >= obs->filter_types.num)
  655. return false;
  656. *id = obs->filter_types.array[idx].id;
  657. return true;
  658. }
  659. bool obs_enum_transition_types(size_t idx, const char **id)
  660. {
  661. if (!obs) return false;
  662. if (idx >= obs->transition_types.num)
  663. return false;
  664. *id = obs->transition_types.array[idx].id;
  665. return true;
  666. }
  667. bool obs_enum_output_types(size_t idx, const char **id)
  668. {
  669. if (!obs) return false;
  670. if (idx >= obs->output_types.num)
  671. return false;
  672. *id = obs->output_types.array[idx].id;
  673. return true;
  674. }
  675. bool obs_enum_encoder_types(size_t idx, const char **id)
  676. {
  677. if (!obs) return false;
  678. if (idx >= obs->encoder_types.num)
  679. return false;
  680. *id = obs->encoder_types.array[idx].id;
  681. return true;
  682. }
  683. bool obs_enum_service_types(size_t idx, const char **id)
  684. {
  685. if (!obs) return false;
  686. if (idx >= obs->service_types.num)
  687. return false;
  688. *id = obs->service_types.array[idx].id;
  689. return true;
  690. }
  691. void obs_enter_graphics(void)
  692. {
  693. if (obs && obs->video.graphics)
  694. gs_enter_context(obs->video.graphics);
  695. }
  696. void obs_leave_graphics(void)
  697. {
  698. if (obs && obs->video.graphics)
  699. gs_leave_context();
  700. }
  701. audio_t *obs_get_audio(void)
  702. {
  703. return (obs != NULL) ? obs->audio.audio : NULL;
  704. }
  705. video_t *obs_get_video(void)
  706. {
  707. return (obs != NULL) ? obs->video.video : NULL;
  708. }
  709. /* TODO: optimize this later so it's not just O(N) string lookups */
  710. static inline struct obs_modal_ui *get_modal_ui_callback(const char *id,
  711. const char *task, const char *target)
  712. {
  713. for (size_t i = 0; i < obs->modal_ui_callbacks.num; i++) {
  714. struct obs_modal_ui *callback = obs->modal_ui_callbacks.array+i;
  715. if (strcmp(callback->id, id) == 0 &&
  716. strcmp(callback->task, task) == 0 &&
  717. strcmp(callback->target, target) == 0)
  718. return callback;
  719. }
  720. return NULL;
  721. }
  722. static inline struct obs_modeless_ui *get_modeless_ui_callback(const char *id,
  723. const char *task, const char *target)
  724. {
  725. for (size_t i = 0; i < obs->modeless_ui_callbacks.num; i++) {
  726. struct obs_modeless_ui *callback;
  727. callback = obs->modeless_ui_callbacks.array+i;
  728. if (strcmp(callback->id, id) == 0 &&
  729. strcmp(callback->task, task) == 0 &&
  730. strcmp(callback->target, target) == 0)
  731. return callback;
  732. }
  733. return NULL;
  734. }
  735. int obs_exec_ui(const char *name, const char *task, const char *target,
  736. void *data, void *ui_data)
  737. {
  738. struct obs_modal_ui *callback;
  739. int errorcode = OBS_UI_NOTFOUND;
  740. if (!obs) return errorcode;
  741. callback = get_modal_ui_callback(name, task, target);
  742. if (callback) {
  743. bool success = callback->exec(data, ui_data);
  744. errorcode = success ? OBS_UI_SUCCESS : OBS_UI_CANCEL;
  745. }
  746. return errorcode;
  747. }
  748. void *obs_create_ui(const char *name, const char *task, const char *target,
  749. void *data, void *ui_data)
  750. {
  751. struct obs_modeless_ui *callback;
  752. if (!obs) return NULL;
  753. callback = get_modeless_ui_callback(name, task, target);
  754. return callback ? callback->create(data, ui_data) : NULL;
  755. }
  756. bool obs_add_source(obs_source_t *source)
  757. {
  758. struct calldata params = {0};
  759. if (!obs) return false;
  760. if (!source) return false;
  761. pthread_mutex_lock(&obs->data.sources_mutex);
  762. da_push_back(obs->data.user_sources, &source);
  763. obs_source_addref(source);
  764. pthread_mutex_unlock(&obs->data.sources_mutex);
  765. calldata_set_ptr(&params, "source", source);
  766. signal_handler_signal(obs->signals, "source_add", &params);
  767. calldata_free(&params);
  768. return true;
  769. }
  770. obs_source_t *obs_get_output_source(uint32_t channel)
  771. {
  772. if (!obs) return NULL;
  773. return obs_view_get_source(&obs->data.main_view, channel);
  774. }
  775. void obs_set_output_source(uint32_t channel, obs_source_t *source)
  776. {
  777. assert(channel < MAX_CHANNELS);
  778. if (!obs) return;
  779. if (channel >= MAX_CHANNELS) return;
  780. struct obs_source *prev_source;
  781. struct obs_view *view = &obs->data.main_view;
  782. struct calldata params = {0};
  783. pthread_mutex_lock(&view->channels_mutex);
  784. obs_source_addref(source);
  785. prev_source = view->channels[channel];
  786. calldata_set_int(&params, "channel", channel);
  787. calldata_set_ptr(&params, "prev_source", prev_source);
  788. calldata_set_ptr(&params, "source", source);
  789. signal_handler_signal(obs->signals, "channel_change", &params);
  790. calldata_get_ptr(&params, "source", &source);
  791. calldata_free(&params);
  792. view->channels[channel] = source;
  793. pthread_mutex_unlock(&view->channels_mutex);
  794. if (source)
  795. obs_source_activate(source, MAIN_VIEW);
  796. if (prev_source) {
  797. obs_source_deactivate(prev_source, MAIN_VIEW);
  798. obs_source_release(prev_source);
  799. }
  800. }
  801. void obs_enum_sources(bool (*enum_proc)(void*, obs_source_t*), void *param)
  802. {
  803. if (!obs) return;
  804. pthread_mutex_lock(&obs->data.user_sources_mutex);
  805. for (size_t i = 0; i < obs->data.user_sources.num; i++) {
  806. struct obs_source *source = obs->data.user_sources.array[i];
  807. if (!enum_proc(param, source))
  808. break;
  809. }
  810. pthread_mutex_unlock(&obs->data.user_sources_mutex);
  811. }
  812. static inline void obs_enum(void *pstart, pthread_mutex_t *mutex, void *proc,
  813. void *param)
  814. {
  815. struct obs_context_data **start = pstart, *context;
  816. bool (*enum_proc)(void*, void*) = proc;
  817. assert(start);
  818. assert(mutex);
  819. assert(enum_proc);
  820. pthread_mutex_lock(mutex);
  821. context = *start;
  822. while (context) {
  823. if (!enum_proc(param, context))
  824. break;
  825. context = context->next;
  826. }
  827. pthread_mutex_unlock(mutex);
  828. }
  829. void obs_enum_outputs(bool (*enum_proc)(void*, obs_output_t*), void *param)
  830. {
  831. if (!obs) return;
  832. obs_enum(&obs->data.first_output, &obs->data.outputs_mutex,
  833. enum_proc, param);
  834. }
  835. void obs_enum_encoders(bool (*enum_proc)(void*, obs_encoder_t*), void *param)
  836. {
  837. if (!obs) return;
  838. obs_enum(&obs->data.first_encoder, &obs->data.encoders_mutex,
  839. enum_proc, param);
  840. }
  841. void obs_enum_services(bool (*enum_proc)(void*, obs_service_t*), void *param)
  842. {
  843. if (!obs) return;
  844. obs_enum(&obs->data.first_service, &obs->data.services_mutex,
  845. enum_proc, param);
  846. }
  847. obs_source_t *obs_get_source_by_name(const char *name)
  848. {
  849. struct obs_core_data *data = &obs->data;
  850. struct obs_source *source = NULL;
  851. size_t i;
  852. if (!obs) return NULL;
  853. pthread_mutex_lock(&data->user_sources_mutex);
  854. for (i = 0; i < data->user_sources.num; i++) {
  855. struct obs_source *cur_source = data->user_sources.array[i];
  856. if (strcmp(cur_source->context.name, name) == 0) {
  857. source = cur_source;
  858. obs_source_addref(source);
  859. break;
  860. }
  861. }
  862. pthread_mutex_unlock(&data->user_sources_mutex);
  863. return source;
  864. }
  865. static inline void *get_context_by_name(void *vfirst, const char *name,
  866. pthread_mutex_t *mutex)
  867. {
  868. struct obs_context_data **first = vfirst;
  869. struct obs_context_data *context;
  870. pthread_mutex_lock(mutex);
  871. context = *first;
  872. while (context) {
  873. if (strcmp(context->name, name) == 0)
  874. break;
  875. context = context->next;
  876. }
  877. pthread_mutex_unlock(mutex);
  878. return context;
  879. }
  880. obs_output_t *obs_get_output_by_name(const char *name)
  881. {
  882. if (!obs) return NULL;
  883. return get_context_by_name(&obs->data.first_output, name,
  884. &obs->data.outputs_mutex);
  885. }
  886. obs_encoder_t *obs_get_encoder_by_name(const char *name)
  887. {
  888. if (!obs) return NULL;
  889. return get_context_by_name(&obs->data.first_encoder, name,
  890. &obs->data.encoders_mutex);
  891. }
  892. obs_service_t *obs_get_service_by_name(const char *name)
  893. {
  894. if (!obs) return NULL;
  895. return get_context_by_name(&obs->data.first_service, name,
  896. &obs->data.services_mutex);
  897. }
  898. gs_effect_t *obs_get_default_effect(void)
  899. {
  900. if (!obs) return NULL;
  901. return obs->video.default_effect;
  902. }
  903. gs_effect_t *obs_get_default_rect_effect(void)
  904. {
  905. if (!obs) return NULL;
  906. return obs->video.default_rect_effect;
  907. }
  908. gs_effect_t *obs_get_solid_effect(void)
  909. {
  910. if (!obs) return NULL;
  911. return obs->video.solid_effect;
  912. }
  913. signal_handler_t *obs_get_signal_handler(void)
  914. {
  915. if (!obs) return NULL;
  916. return obs->signals;
  917. }
  918. proc_handler_t *obs_get_proc_handler(void)
  919. {
  920. if (!obs) return NULL;
  921. return obs->procs;
  922. }
  923. void obs_add_draw_callback(
  924. void (*draw)(void *param, uint32_t cx, uint32_t cy),
  925. void *param)
  926. {
  927. if (!obs) return;
  928. obs_display_add_draw_callback(&obs->video.main_display, draw, param);
  929. }
  930. void obs_remove_draw_callback(
  931. void (*draw)(void *param, uint32_t cx, uint32_t cy),
  932. void *param)
  933. {
  934. if (!obs) return;
  935. obs_display_remove_draw_callback(&obs->video.main_display, draw, param);
  936. }
  937. void obs_resize(uint32_t cx, uint32_t cy)
  938. {
  939. if (!obs || !obs->video.video || !obs->video.graphics) return;
  940. obs_display_resize(&obs->video.main_display, cx, cy);
  941. }
  942. void obs_render_main_view(void)
  943. {
  944. if (!obs) return;
  945. obs_view_render(&obs->data.main_view);
  946. }
  947. void obs_set_master_volume(float volume)
  948. {
  949. struct calldata data = {0};
  950. if (!obs) return;
  951. calldata_set_float(&data, "volume", volume);
  952. signal_handler_signal(obs->signals, "master_volume", &data);
  953. volume = (float)calldata_float(&data, "volume");
  954. calldata_free(&data);
  955. obs->audio.user_volume = volume;
  956. }
  957. void obs_set_present_volume(float volume)
  958. {
  959. if (!obs) return;
  960. obs->audio.present_volume = volume;
  961. }
  962. float obs_get_master_volume(void)
  963. {
  964. return obs ? obs->audio.user_volume : 0.0f;
  965. }
  966. float obs_get_present_volume(void)
  967. {
  968. return obs ? obs->audio.present_volume : 0.0f;
  969. }
  970. obs_source_t *obs_load_source(obs_data_t *source_data)
  971. {
  972. obs_source_t *source;
  973. const char *name = obs_data_get_string(source_data, "name");
  974. const char *id = obs_data_get_string(source_data, "id");
  975. obs_data_t *settings = obs_data_get_obj(source_data, "settings");
  976. double volume;
  977. int64_t sync;
  978. uint32_t flags;
  979. uint32_t mixers;
  980. source = obs_source_create(OBS_SOURCE_TYPE_INPUT, id, name, settings);
  981. obs_data_set_default_double(source_data, "volume", 1.0);
  982. volume = obs_data_get_double(source_data, "volume");
  983. obs_source_set_volume(source, (float)volume);
  984. sync = obs_data_get_int(source_data, "sync");
  985. obs_source_set_sync_offset(source, sync);
  986. obs_data_set_default_int(source_data, "mixers", 0xF);
  987. mixers = (uint32_t)obs_data_get_int(source_data, "mixers");
  988. obs_source_set_audio_mixers(source, mixers);
  989. obs_data_set_default_int(source_data, "flags", source->default_flags);
  990. flags = (uint32_t)obs_data_get_int(source_data, "flags");
  991. obs_source_set_flags(source, flags);
  992. obs_data_release(settings);
  993. return source;
  994. }
  995. void obs_load_sources(obs_data_array_t *array)
  996. {
  997. size_t count;
  998. size_t i;
  999. if (!obs) return;
  1000. count = obs_data_array_count(array);
  1001. pthread_mutex_lock(&obs->data.user_sources_mutex);
  1002. for (i = 0; i < count; i++) {
  1003. obs_data_t *source_data = obs_data_array_item(array, i);
  1004. obs_source_t *source = obs_load_source(source_data);
  1005. obs_add_source(source);
  1006. obs_source_release(source);
  1007. obs_data_release(source_data);
  1008. }
  1009. /* tell sources that we want to load */
  1010. for (i = 0; i < obs->data.user_sources.num; i++)
  1011. obs_source_load(obs->data.user_sources.array[i]);
  1012. pthread_mutex_unlock(&obs->data.user_sources_mutex);
  1013. }
  1014. obs_data_t *obs_save_source(obs_source_t *source)
  1015. {
  1016. obs_data_t *source_data = obs_data_create();
  1017. obs_data_t *settings = obs_source_get_settings(source);
  1018. float volume = obs_source_get_volume(source);
  1019. uint32_t mixers = obs_source_get_audio_mixers(source);
  1020. int64_t sync = obs_source_get_sync_offset(source);
  1021. uint32_t flags = obs_source_get_flags(source);
  1022. const char *name = obs_source_get_name(source);
  1023. const char *id = obs_source_get_id(source);
  1024. obs_source_save(source);
  1025. obs_data_set_string(source_data, "name", name);
  1026. obs_data_set_string(source_data, "id", id);
  1027. obs_data_set_obj (source_data, "settings", settings);
  1028. obs_data_set_int (source_data, "mixers", mixers);
  1029. obs_data_set_int (source_data, "sync", sync);
  1030. obs_data_set_int (source_data, "flags", flags);
  1031. obs_data_set_double(source_data, "volume", volume);
  1032. obs_data_release(settings);
  1033. return source_data;
  1034. }
  1035. obs_data_array_t *obs_save_sources(void)
  1036. {
  1037. obs_data_array_t *array;
  1038. size_t i;
  1039. if (!obs) return NULL;
  1040. array = obs_data_array_create();
  1041. pthread_mutex_lock(&obs->data.user_sources_mutex);
  1042. for (i = 0; i < obs->data.user_sources.num; i++) {
  1043. obs_source_t *source = obs->data.user_sources.array[i];
  1044. obs_data_t *source_data = obs_save_source(source);
  1045. obs_data_array_push_back(array, source_data);
  1046. obs_data_release(source_data);
  1047. }
  1048. pthread_mutex_unlock(&obs->data.user_sources_mutex);
  1049. return array;
  1050. }
  1051. /* ensures that names are never blank */
  1052. static inline char *dup_name(const char *name)
  1053. {
  1054. if (!name || !*name) {
  1055. struct dstr unnamed = {0};
  1056. dstr_printf(&unnamed, "__unnamed%004lld",
  1057. obs->data.unnamed_index++);
  1058. return unnamed.array;
  1059. } else {
  1060. return bstrdup(name);
  1061. }
  1062. }
  1063. static inline bool obs_context_data_init_wrap(
  1064. struct obs_context_data *context,
  1065. obs_data_t *settings,
  1066. const char *name)
  1067. {
  1068. assert(context);
  1069. memset(context, 0, sizeof(*context));
  1070. pthread_mutex_init_value(&context->rename_cache_mutex);
  1071. if (pthread_mutex_init(&context->rename_cache_mutex, NULL) < 0)
  1072. return false;
  1073. context->signals = signal_handler_create();
  1074. if (!context->signals)
  1075. return false;
  1076. context->procs = proc_handler_create();
  1077. if (!context->procs)
  1078. return false;
  1079. context->name = dup_name(name);
  1080. context->settings = obs_data_newref(settings);
  1081. return true;
  1082. }
  1083. bool obs_context_data_init(
  1084. struct obs_context_data *context,
  1085. obs_data_t *settings,
  1086. const char *name)
  1087. {
  1088. if (obs_context_data_init_wrap(context, settings, name)) {
  1089. return true;
  1090. } else {
  1091. obs_context_data_free(context);
  1092. return false;
  1093. }
  1094. }
  1095. void obs_context_data_free(struct obs_context_data *context)
  1096. {
  1097. signal_handler_destroy(context->signals);
  1098. proc_handler_destroy(context->procs);
  1099. obs_data_release(context->settings);
  1100. obs_context_data_remove(context);
  1101. pthread_mutex_destroy(&context->rename_cache_mutex);
  1102. bfree(context->name);
  1103. for (size_t i = 0; i < context->rename_cache.num; i++)
  1104. bfree(context->rename_cache.array[i]);
  1105. da_free(context->rename_cache);
  1106. memset(context, 0, sizeof(*context));
  1107. }
  1108. void obs_context_data_insert(struct obs_context_data *context,
  1109. pthread_mutex_t *mutex, void *pfirst)
  1110. {
  1111. struct obs_context_data **first = pfirst;
  1112. assert(context);
  1113. assert(mutex);
  1114. assert(first);
  1115. context->mutex = mutex;
  1116. pthread_mutex_lock(mutex);
  1117. context->prev_next = first;
  1118. context->next = *first;
  1119. *first = context;
  1120. if (context->next)
  1121. context->next->prev_next = &context->next;
  1122. pthread_mutex_unlock(mutex);
  1123. }
  1124. void obs_context_data_remove(struct obs_context_data *context)
  1125. {
  1126. if (context && context->mutex) {
  1127. pthread_mutex_lock(context->mutex);
  1128. if (context->prev_next)
  1129. *context->prev_next = context->next;
  1130. if (context->next)
  1131. context->next->prev_next = context->prev_next;
  1132. pthread_mutex_unlock(context->mutex);
  1133. context->mutex = NULL;
  1134. }
  1135. }
  1136. void obs_context_data_setname(struct obs_context_data *context,
  1137. const char *name)
  1138. {
  1139. pthread_mutex_lock(&context->rename_cache_mutex);
  1140. if (context->name)
  1141. da_push_back(context->rename_cache, &context->name);
  1142. context->name = dup_name(name);
  1143. pthread_mutex_unlock(&context->rename_cache_mutex);
  1144. }