obs-internal.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain 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. #pragma once
  15. #include "util/c99defs.h"
  16. #include "util/darray.h"
  17. #include "util/deque.h"
  18. #include "util/dstr.h"
  19. #include "util/threading.h"
  20. #include "util/platform.h"
  21. #include "util/profiler.h"
  22. #include "util/task.h"
  23. #include "util/uthash.h"
  24. #include "callback/signal.h"
  25. #include "callback/proc.h"
  26. #include "graphics/graphics.h"
  27. #include "graphics/matrix4.h"
  28. #include "media-io/audio-resampler.h"
  29. #include "media-io/video-io.h"
  30. #include "media-io/audio-io.h"
  31. #include "obs.h"
  32. #include <obsversion.h>
  33. #include <caption/caption.h>
  34. /* Custom helpers for the UUID hash table */
  35. #define HASH_FIND_UUID(head, uuid, out) \
  36. HASH_FIND(hh_uuid, head, uuid, UUID_STR_LENGTH, out)
  37. #define HASH_ADD_UUID(head, uuid_field, add) \
  38. HASH_ADD(hh_uuid, head, uuid_field[0], UUID_STR_LENGTH, add)
  39. #define NUM_TEXTURES 2
  40. #define NUM_CHANNELS 3
  41. #define MICROSECOND_DEN 1000000
  42. #define NUM_ENCODE_TEXTURES 10
  43. #define NUM_ENCODE_TEXTURE_FRAMES_TO_WAIT 1
  44. static inline int64_t packet_dts_usec(struct encoder_packet *packet)
  45. {
  46. return packet->dts * MICROSECOND_DEN / packet->timebase_den;
  47. }
  48. struct tick_callback {
  49. void (*tick)(void *param, float seconds);
  50. void *param;
  51. };
  52. struct draw_callback {
  53. void (*draw)(void *param, uint32_t cx, uint32_t cy);
  54. void *param;
  55. };
  56. struct rendered_callback {
  57. void (*rendered)(void *param);
  58. void *param;
  59. };
  60. /* ------------------------------------------------------------------------- */
  61. /* validity checks */
  62. static inline bool obs_object_valid(const void *obj, const char *f,
  63. const char *t)
  64. {
  65. if (!obj) {
  66. blog(LOG_DEBUG, "%s: Null '%s' parameter", f, t);
  67. return false;
  68. }
  69. return true;
  70. }
  71. #define obs_ptr_valid(ptr, func) obs_object_valid(ptr, func, #ptr)
  72. #define obs_source_valid obs_ptr_valid
  73. #define obs_output_valid obs_ptr_valid
  74. #define obs_encoder_valid obs_ptr_valid
  75. #define obs_service_valid obs_ptr_valid
  76. /* ------------------------------------------------------------------------- */
  77. /* modules */
  78. struct obs_module {
  79. char *mod_name;
  80. const char *file;
  81. char *bin_path;
  82. char *data_path;
  83. void *module;
  84. bool loaded;
  85. bool (*load)(void);
  86. void (*unload)(void);
  87. void (*post_load)(void);
  88. void (*set_locale)(const char *locale);
  89. bool (*get_string)(const char *lookup_string,
  90. const char **translated_string);
  91. void (*free_locale)(void);
  92. uint32_t (*ver)(void);
  93. void (*set_pointer)(obs_module_t *module);
  94. const char *(*name)(void);
  95. const char *(*description)(void);
  96. const char *(*author)(void);
  97. struct obs_module *next;
  98. };
  99. extern void free_module(struct obs_module *mod);
  100. struct obs_module_path {
  101. char *bin;
  102. char *data;
  103. };
  104. static inline void free_module_path(struct obs_module_path *omp)
  105. {
  106. if (omp) {
  107. bfree(omp->bin);
  108. bfree(omp->data);
  109. }
  110. }
  111. static inline bool check_path(const char *data, const char *path,
  112. struct dstr *output)
  113. {
  114. dstr_copy(output, path);
  115. dstr_cat(output, data);
  116. return os_file_exists(output->array);
  117. }
  118. /* ------------------------------------------------------------------------- */
  119. /* hotkeys */
  120. struct obs_hotkey {
  121. obs_hotkey_id id;
  122. char *name;
  123. char *description;
  124. obs_hotkey_func func;
  125. void *data;
  126. int pressed;
  127. obs_hotkey_registerer_t registerer_type;
  128. void *registerer;
  129. obs_hotkey_id pair_partner_id;
  130. UT_hash_handle hh;
  131. };
  132. struct obs_hotkey_pair {
  133. obs_hotkey_pair_id pair_id;
  134. obs_hotkey_id id[2];
  135. obs_hotkey_active_func func[2];
  136. bool pressed0;
  137. bool pressed1;
  138. void *data[2];
  139. UT_hash_handle hh;
  140. };
  141. typedef struct obs_hotkey_pair obs_hotkey_pair_t;
  142. typedef struct obs_hotkeys_platform obs_hotkeys_platform_t;
  143. void *obs_hotkey_thread(void *param);
  144. struct obs_core_hotkeys;
  145. bool obs_hotkeys_platform_init(struct obs_core_hotkeys *hotkeys);
  146. void obs_hotkeys_platform_free(struct obs_core_hotkeys *hotkeys);
  147. bool obs_hotkeys_platform_is_pressed(obs_hotkeys_platform_t *context,
  148. obs_key_t key);
  149. const char *obs_get_hotkey_translation(obs_key_t key, const char *def);
  150. struct obs_context_data;
  151. void obs_hotkeys_context_release(struct obs_context_data *context);
  152. void obs_hotkeys_free(void);
  153. struct obs_hotkey_binding {
  154. obs_key_combination_t key;
  155. bool pressed;
  156. bool modifiers_match;
  157. obs_hotkey_id hotkey_id;
  158. obs_hotkey_t *hotkey;
  159. };
  160. struct obs_hotkey_name_map_item;
  161. void obs_hotkey_name_map_free(void);
  162. /* ------------------------------------------------------------------------- */
  163. /* views */
  164. struct obs_view {
  165. pthread_mutex_t channels_mutex;
  166. obs_source_t *channels[MAX_CHANNELS];
  167. };
  168. extern bool obs_view_init(struct obs_view *view);
  169. extern void obs_view_free(struct obs_view *view);
  170. /* ------------------------------------------------------------------------- */
  171. /* displays */
  172. struct obs_display {
  173. bool update_color_space;
  174. bool enabled;
  175. uint32_t cx, cy;
  176. uint32_t next_cx, next_cy;
  177. uint32_t background_color;
  178. gs_swapchain_t *swap;
  179. pthread_mutex_t draw_callbacks_mutex;
  180. pthread_mutex_t draw_info_mutex;
  181. DARRAY(struct draw_callback) draw_callbacks;
  182. bool use_clear_workaround;
  183. struct obs_display *next;
  184. struct obs_display **prev_next;
  185. };
  186. extern bool obs_display_init(struct obs_display *display,
  187. const struct gs_init_data *graphics_data);
  188. extern void obs_display_free(struct obs_display *display);
  189. /* ------------------------------------------------------------------------- */
  190. /* core */
  191. struct obs_vframe_info {
  192. uint64_t timestamp;
  193. int count;
  194. };
  195. struct obs_tex_frame {
  196. gs_texture_t *tex;
  197. gs_texture_t *tex_uv;
  198. uint32_t handle;
  199. uint64_t timestamp;
  200. uint64_t lock_key;
  201. int count;
  202. bool released;
  203. };
  204. struct obs_task_info {
  205. obs_task_t task;
  206. void *param;
  207. };
  208. struct obs_core_video_mix {
  209. struct obs_view *view;
  210. gs_stagesurf_t *active_copy_surfaces[NUM_TEXTURES][NUM_CHANNELS];
  211. gs_stagesurf_t *copy_surfaces[NUM_TEXTURES][NUM_CHANNELS];
  212. gs_texture_t *convert_textures[NUM_CHANNELS];
  213. gs_texture_t *convert_textures_encode[NUM_CHANNELS];
  214. #ifdef _WIN32
  215. gs_stagesurf_t *copy_surfaces_encode[NUM_TEXTURES];
  216. #endif
  217. gs_texture_t *render_texture;
  218. gs_texture_t *output_texture;
  219. enum gs_color_space render_space;
  220. bool texture_rendered;
  221. bool textures_copied[NUM_TEXTURES];
  222. bool texture_converted;
  223. bool using_nv12_tex;
  224. bool using_p010_tex;
  225. struct deque vframe_info_buffer;
  226. struct deque vframe_info_buffer_gpu;
  227. gs_stagesurf_t *mapped_surfaces[NUM_CHANNELS];
  228. int cur_texture;
  229. volatile long raw_active;
  230. volatile long gpu_encoder_active;
  231. bool gpu_was_active;
  232. bool raw_was_active;
  233. bool was_active;
  234. pthread_mutex_t gpu_encoder_mutex;
  235. struct deque gpu_encoder_queue;
  236. struct deque gpu_encoder_avail_queue;
  237. DARRAY(obs_encoder_t *) gpu_encoders;
  238. os_sem_t *gpu_encode_semaphore;
  239. os_event_t *gpu_encode_inactive;
  240. pthread_t gpu_encode_thread;
  241. bool gpu_encode_thread_initialized;
  242. volatile bool gpu_encode_stop;
  243. video_t *video;
  244. struct obs_video_info ovi;
  245. bool gpu_conversion;
  246. const char *conversion_techs[NUM_CHANNELS];
  247. bool conversion_needed;
  248. float conversion_width_i;
  249. float conversion_height_i;
  250. float color_matrix[16];
  251. bool encoder_only_mix;
  252. long encoder_refs;
  253. };
  254. extern struct obs_core_video_mix *
  255. obs_create_video_mix(struct obs_video_info *ovi);
  256. extern void obs_free_video_mix(struct obs_core_video_mix *video);
  257. struct obs_core_video {
  258. graphics_t *graphics;
  259. gs_effect_t *default_effect;
  260. gs_effect_t *default_rect_effect;
  261. gs_effect_t *opaque_effect;
  262. gs_effect_t *solid_effect;
  263. gs_effect_t *repeat_effect;
  264. gs_effect_t *conversion_effect;
  265. gs_effect_t *bicubic_effect;
  266. gs_effect_t *lanczos_effect;
  267. gs_effect_t *area_effect;
  268. gs_effect_t *bilinear_lowres_effect;
  269. gs_effect_t *premultiplied_alpha_effect;
  270. gs_samplerstate_t *point_sampler;
  271. uint64_t video_time;
  272. uint64_t video_frame_interval_ns;
  273. uint64_t video_half_frame_interval_ns;
  274. uint64_t video_avg_frame_time_ns;
  275. double video_fps;
  276. pthread_t video_thread;
  277. uint32_t total_frames;
  278. uint32_t lagged_frames;
  279. bool thread_initialized;
  280. gs_texture_t *transparent_texture;
  281. gs_effect_t *deinterlace_discard_effect;
  282. gs_effect_t *deinterlace_discard_2x_effect;
  283. gs_effect_t *deinterlace_linear_effect;
  284. gs_effect_t *deinterlace_linear_2x_effect;
  285. gs_effect_t *deinterlace_blend_effect;
  286. gs_effect_t *deinterlace_blend_2x_effect;
  287. gs_effect_t *deinterlace_yadif_effect;
  288. gs_effect_t *deinterlace_yadif_2x_effect;
  289. float sdr_white_level;
  290. float hdr_nominal_peak_level;
  291. pthread_mutex_t task_mutex;
  292. struct deque tasks;
  293. pthread_mutex_t mixes_mutex;
  294. DARRAY(struct obs_core_video_mix *) mixes;
  295. struct obs_core_video_mix *main_mix;
  296. };
  297. struct audio_monitor;
  298. struct obs_core_audio {
  299. audio_t *audio;
  300. DARRAY(struct obs_source *) render_order;
  301. DARRAY(struct obs_source *) root_nodes;
  302. uint64_t buffered_ts;
  303. struct deque buffered_timestamps;
  304. uint64_t buffering_wait_ticks;
  305. int total_buffering_ticks;
  306. int max_buffering_ticks;
  307. bool fixed_buffer;
  308. pthread_mutex_t monitoring_mutex;
  309. DARRAY(struct audio_monitor *) monitors;
  310. char *monitoring_device_name;
  311. char *monitoring_device_id;
  312. pthread_mutex_t task_mutex;
  313. struct deque tasks;
  314. };
  315. /* user sources, output channels, and displays */
  316. struct obs_core_data {
  317. /* Hash tables (uthash) */
  318. struct obs_source *sources; /* Lookup by UUID (hh_uuid) */
  319. struct obs_source *public_sources; /* Lookup by name (hh) */
  320. /* Linked lists */
  321. struct obs_source *first_audio_source;
  322. struct obs_display *first_display;
  323. struct obs_output *first_output;
  324. struct obs_encoder *first_encoder;
  325. struct obs_service *first_service;
  326. pthread_mutex_t sources_mutex;
  327. pthread_mutex_t displays_mutex;
  328. pthread_mutex_t outputs_mutex;
  329. pthread_mutex_t encoders_mutex;
  330. pthread_mutex_t services_mutex;
  331. pthread_mutex_t audio_sources_mutex;
  332. pthread_mutex_t draw_callbacks_mutex;
  333. DARRAY(struct draw_callback) draw_callbacks;
  334. DARRAY(struct rendered_callback) rendered_callbacks;
  335. DARRAY(struct tick_callback) tick_callbacks;
  336. struct obs_view main_view;
  337. long long unnamed_index;
  338. obs_data_t *private_data;
  339. volatile bool valid;
  340. DARRAY(char *) protocols;
  341. DARRAY(obs_source_t *) sources_to_tick;
  342. };
  343. /* user hotkeys */
  344. struct obs_core_hotkeys {
  345. pthread_mutex_t mutex;
  346. obs_hotkey_t *hotkeys;
  347. obs_hotkey_id next_id;
  348. obs_hotkey_pair_t *hotkey_pairs;
  349. obs_hotkey_pair_id next_pair_id;
  350. pthread_t hotkey_thread;
  351. bool hotkey_thread_initialized;
  352. os_event_t *stop_event;
  353. bool thread_disable_press;
  354. bool strict_modifiers;
  355. bool reroute_hotkeys;
  356. DARRAY(obs_hotkey_binding_t) bindings;
  357. obs_hotkey_callback_router_func router_func;
  358. void *router_func_data;
  359. obs_hotkeys_platform_t *platform_context;
  360. pthread_once_t name_map_init_token;
  361. struct obs_hotkey_name_map_item *name_map;
  362. signal_handler_t *signals;
  363. char *translations[OBS_KEY_LAST_VALUE];
  364. char *mute;
  365. char *unmute;
  366. char *push_to_mute;
  367. char *push_to_talk;
  368. char *sceneitem_show;
  369. char *sceneitem_hide;
  370. };
  371. typedef DARRAY(struct obs_source_info) obs_source_info_array_t;
  372. struct obs_core {
  373. struct obs_module *first_module;
  374. DARRAY(struct obs_module_path) module_paths;
  375. DARRAY(char *) safe_modules;
  376. obs_source_info_array_t source_types;
  377. obs_source_info_array_t input_types;
  378. obs_source_info_array_t filter_types;
  379. obs_source_info_array_t transition_types;
  380. DARRAY(struct obs_output_info) output_types;
  381. DARRAY(struct obs_encoder_info) encoder_types;
  382. DARRAY(struct obs_service_info) service_types;
  383. signal_handler_t *signals;
  384. proc_handler_t *procs;
  385. char *locale;
  386. char *module_config_path;
  387. bool name_store_owned;
  388. profiler_name_store_t *name_store;
  389. /* segmented into multiple sub-structures to keep things a bit more
  390. * clean and organized */
  391. struct obs_core_video video;
  392. struct obs_core_audio audio;
  393. struct obs_core_data data;
  394. struct obs_core_hotkeys hotkeys;
  395. os_task_queue_t *destruction_task_thread;
  396. obs_task_handler_t ui_task_handler;
  397. };
  398. extern struct obs_core *obs;
  399. struct obs_graphics_context {
  400. uint64_t last_time;
  401. uint64_t interval;
  402. uint64_t frame_time_total_ns;
  403. uint64_t fps_total_ns;
  404. uint32_t fps_total_frames;
  405. const char *video_thread_name;
  406. };
  407. extern void *obs_graphics_thread(void *param);
  408. extern bool obs_graphics_thread_loop(struct obs_graphics_context *context);
  409. #ifdef __APPLE__
  410. extern void *obs_graphics_thread_autorelease(void *param);
  411. extern bool
  412. obs_graphics_thread_loop_autorelease(struct obs_graphics_context *context);
  413. #endif
  414. extern gs_effect_t *obs_load_effect(gs_effect_t **effect, const char *file);
  415. extern bool audio_callback(void *param, uint64_t start_ts_in,
  416. uint64_t end_ts_in, uint64_t *out_ts,
  417. uint32_t mixers, struct audio_output_data *mixes);
  418. extern struct obs_core_video_mix *get_mix_for_video(video_t *video);
  419. extern void
  420. start_raw_video(video_t *video, const struct video_scale_info *conversion,
  421. uint32_t frame_rate_divisor,
  422. void (*callback)(void *param, struct video_data *frame),
  423. void *param);
  424. extern void stop_raw_video(video_t *video,
  425. void (*callback)(void *param,
  426. struct video_data *frame),
  427. void *param);
  428. /* ------------------------------------------------------------------------- */
  429. /* obs shared context data */
  430. struct obs_weak_ref {
  431. volatile long refs;
  432. volatile long weak_refs;
  433. };
  434. struct obs_weak_object {
  435. struct obs_weak_ref ref;
  436. struct obs_context_data *object;
  437. };
  438. typedef void (*obs_destroy_cb)(void *obj);
  439. struct obs_context_data {
  440. char *name;
  441. const char *uuid;
  442. void *data;
  443. obs_data_t *settings;
  444. signal_handler_t *signals;
  445. proc_handler_t *procs;
  446. enum obs_obj_type type;
  447. struct obs_weak_object *control;
  448. obs_destroy_cb destroy;
  449. DARRAY(obs_hotkey_id) hotkeys;
  450. DARRAY(obs_hotkey_pair_id) hotkey_pairs;
  451. obs_data_t *hotkey_data;
  452. DARRAY(char *) rename_cache;
  453. pthread_mutex_t rename_cache_mutex;
  454. pthread_mutex_t *mutex;
  455. struct obs_context_data *next;
  456. struct obs_context_data **prev_next;
  457. UT_hash_handle hh;
  458. UT_hash_handle hh_uuid;
  459. bool private;
  460. };
  461. extern bool obs_context_data_init(struct obs_context_data *context,
  462. enum obs_obj_type type, obs_data_t *settings,
  463. const char *name, const char *uuid,
  464. obs_data_t *hotkey_data, bool private);
  465. extern void obs_context_init_control(struct obs_context_data *context,
  466. void *object, obs_destroy_cb destroy);
  467. extern void obs_context_data_free(struct obs_context_data *context);
  468. extern void obs_context_data_insert(struct obs_context_data *context,
  469. pthread_mutex_t *mutex, void *first);
  470. extern void obs_context_data_insert_name(struct obs_context_data *context,
  471. pthread_mutex_t *mutex, void *first);
  472. extern void obs_context_data_insert_uuid(struct obs_context_data *context,
  473. pthread_mutex_t *mutex,
  474. void *first_uuid);
  475. extern void obs_context_data_remove(struct obs_context_data *context);
  476. extern void obs_context_data_remove_name(struct obs_context_data *context,
  477. void *phead);
  478. extern void obs_context_data_remove_uuid(struct obs_context_data *context,
  479. void *puuid_head);
  480. extern void obs_context_wait(struct obs_context_data *context);
  481. extern void obs_context_data_setname(struct obs_context_data *context,
  482. const char *name);
  483. extern void obs_context_data_setname_ht(struct obs_context_data *context,
  484. const char *name, void *phead);
  485. /* ------------------------------------------------------------------------- */
  486. /* ref-counting */
  487. static inline void obs_ref_addref(struct obs_weak_ref *ref)
  488. {
  489. os_atomic_inc_long(&ref->refs);
  490. }
  491. static inline bool obs_ref_release(struct obs_weak_ref *ref)
  492. {
  493. return os_atomic_dec_long(&ref->refs) == -1;
  494. }
  495. static inline void obs_weak_ref_addref(struct obs_weak_ref *ref)
  496. {
  497. os_atomic_inc_long(&ref->weak_refs);
  498. }
  499. static inline bool obs_weak_ref_release(struct obs_weak_ref *ref)
  500. {
  501. return os_atomic_dec_long(&ref->weak_refs) == -1;
  502. }
  503. static inline bool obs_weak_ref_get_ref(struct obs_weak_ref *ref)
  504. {
  505. long owners = os_atomic_load_long(&ref->refs);
  506. while (owners > -1) {
  507. if (os_atomic_compare_exchange_long(&ref->refs, &owners,
  508. owners + 1)) {
  509. return true;
  510. }
  511. }
  512. return false;
  513. }
  514. static inline bool obs_weak_ref_expired(struct obs_weak_ref *ref)
  515. {
  516. long owners = os_atomic_load_long(&ref->refs);
  517. return owners < 0;
  518. }
  519. /* ------------------------------------------------------------------------- */
  520. /* sources */
  521. struct async_frame {
  522. struct obs_source_frame *frame;
  523. long unused_count;
  524. bool used;
  525. };
  526. enum audio_action_type {
  527. AUDIO_ACTION_VOL,
  528. AUDIO_ACTION_MUTE,
  529. AUDIO_ACTION_PTT,
  530. AUDIO_ACTION_PTM,
  531. };
  532. struct audio_action {
  533. uint64_t timestamp;
  534. enum audio_action_type type;
  535. union {
  536. float vol;
  537. bool set;
  538. };
  539. };
  540. struct obs_weak_source {
  541. struct obs_weak_ref ref;
  542. struct obs_source *source;
  543. };
  544. struct audio_cb_info {
  545. obs_source_audio_capture_t callback;
  546. void *param;
  547. };
  548. struct caption_cb_info {
  549. obs_source_caption_t callback;
  550. void *param;
  551. };
  552. enum media_action_type {
  553. MEDIA_ACTION_NONE,
  554. MEDIA_ACTION_PLAY_PAUSE,
  555. MEDIA_ACTION_RESTART,
  556. MEDIA_ACTION_STOP,
  557. MEDIA_ACTION_NEXT,
  558. MEDIA_ACTION_PREVIOUS,
  559. MEDIA_ACTION_SET_TIME,
  560. };
  561. struct media_action {
  562. enum media_action_type type;
  563. union {
  564. bool pause;
  565. int64_t ms;
  566. };
  567. };
  568. struct obs_source {
  569. struct obs_context_data context;
  570. struct obs_source_info info;
  571. /* general exposed flags that can be set for the source */
  572. uint32_t flags;
  573. uint32_t default_flags;
  574. uint32_t last_obs_ver;
  575. /* indicates ownership of the info.id buffer */
  576. bool owns_info_id;
  577. /* signals to call the source update in the video thread */
  578. long defer_update_count;
  579. /* ensures show/hide are only called once */
  580. volatile long show_refs;
  581. /* ensures activate/deactivate are only called once */
  582. volatile long activate_refs;
  583. /* source is in the process of being destroyed */
  584. volatile long destroying;
  585. /* used to indicate that the source has been removed and all
  586. * references to it should be released (not exactly how I would prefer
  587. * to handle things but it's the best option) */
  588. bool removed;
  589. /* used to indicate if the source should show up when queried for user ui */
  590. bool temp_removed;
  591. bool active;
  592. bool showing;
  593. /* used to temporarily disable sources if needed */
  594. bool enabled;
  595. /* hint to allow sources to render more quickly */
  596. bool texcoords_centered;
  597. /* timing (if video is present, is based upon video) */
  598. volatile bool timing_set;
  599. volatile uint64_t timing_adjust;
  600. uint64_t resample_offset;
  601. uint64_t last_audio_ts;
  602. uint64_t next_audio_ts_min;
  603. uint64_t next_audio_sys_ts_min;
  604. uint64_t last_frame_ts;
  605. uint64_t last_sys_timestamp;
  606. bool async_rendered;
  607. /* audio */
  608. bool audio_failed;
  609. bool audio_pending;
  610. bool pending_stop;
  611. bool audio_active;
  612. bool user_muted;
  613. bool muted;
  614. struct obs_source *next_audio_source;
  615. struct obs_source **prev_next_audio_source;
  616. uint64_t audio_ts;
  617. struct deque audio_input_buf[MAX_AUDIO_CHANNELS];
  618. size_t last_audio_input_buf_size;
  619. DARRAY(struct audio_action) audio_actions;
  620. float *audio_output_buf[MAX_AUDIO_MIXES][MAX_AUDIO_CHANNELS];
  621. float *audio_mix_buf[MAX_AUDIO_CHANNELS];
  622. struct resample_info sample_info;
  623. audio_resampler_t *resampler;
  624. pthread_mutex_t audio_actions_mutex;
  625. pthread_mutex_t audio_buf_mutex;
  626. pthread_mutex_t audio_mutex;
  627. pthread_mutex_t audio_cb_mutex;
  628. DARRAY(struct audio_cb_info) audio_cb_list;
  629. struct obs_audio_data audio_data;
  630. size_t audio_storage_size;
  631. uint32_t audio_mixers;
  632. float user_volume;
  633. float volume;
  634. int64_t sync_offset;
  635. int64_t last_sync_offset;
  636. float balance;
  637. /* async video data */
  638. gs_texture_t *async_textures[MAX_AV_PLANES];
  639. gs_texrender_t *async_texrender;
  640. struct obs_source_frame *cur_async_frame;
  641. bool async_gpu_conversion;
  642. enum video_format async_format;
  643. bool async_full_range;
  644. uint8_t async_trc;
  645. enum video_format async_cache_format;
  646. bool async_cache_full_range;
  647. uint8_t async_cache_trc;
  648. enum gs_color_format async_texture_formats[MAX_AV_PLANES];
  649. int async_channel_count;
  650. long async_rotation;
  651. bool async_flip;
  652. bool async_linear_alpha;
  653. bool async_active;
  654. bool async_update_texture;
  655. bool async_unbuffered;
  656. bool async_decoupled;
  657. struct obs_source_frame *async_preload_frame;
  658. DARRAY(struct async_frame) async_cache;
  659. DARRAY(struct obs_source_frame *) async_frames;
  660. pthread_mutex_t async_mutex;
  661. uint32_t async_width;
  662. uint32_t async_height;
  663. uint32_t async_cache_width;
  664. uint32_t async_cache_height;
  665. uint32_t async_convert_width[MAX_AV_PLANES];
  666. uint32_t async_convert_height[MAX_AV_PLANES];
  667. pthread_mutex_t caption_cb_mutex;
  668. DARRAY(struct caption_cb_info) caption_cb_list;
  669. /* async video deinterlacing */
  670. uint64_t deinterlace_offset;
  671. uint64_t deinterlace_frame_ts;
  672. gs_effect_t *deinterlace_effect;
  673. struct obs_source_frame *prev_async_frame;
  674. gs_texture_t *async_prev_textures[MAX_AV_PLANES];
  675. gs_texrender_t *async_prev_texrender;
  676. uint32_t deinterlace_half_duration;
  677. enum obs_deinterlace_mode deinterlace_mode;
  678. bool deinterlace_top_first;
  679. bool deinterlace_rendered;
  680. /* filters */
  681. struct obs_source *filter_parent;
  682. struct obs_source *filter_target;
  683. DARRAY(struct obs_source *) filters;
  684. pthread_mutex_t filter_mutex;
  685. gs_texrender_t *filter_texrender;
  686. enum obs_allow_direct_render allow_direct;
  687. bool rendering_filter;
  688. bool filter_bypass_active;
  689. /* sources specific hotkeys */
  690. obs_hotkey_pair_id mute_unmute_key;
  691. obs_hotkey_id push_to_mute_key;
  692. obs_hotkey_id push_to_talk_key;
  693. bool push_to_mute_enabled;
  694. bool push_to_mute_pressed;
  695. bool user_push_to_mute_pressed;
  696. bool push_to_talk_enabled;
  697. bool push_to_talk_pressed;
  698. bool user_push_to_talk_pressed;
  699. uint64_t push_to_mute_delay;
  700. uint64_t push_to_mute_stop_time;
  701. uint64_t push_to_talk_delay;
  702. uint64_t push_to_talk_stop_time;
  703. /* transitions */
  704. uint64_t transition_start_time;
  705. uint64_t transition_duration;
  706. pthread_mutex_t transition_tex_mutex;
  707. gs_texrender_t *transition_texrender[2];
  708. pthread_mutex_t transition_mutex;
  709. obs_source_t *transition_sources[2];
  710. float transition_manual_clamp;
  711. float transition_manual_torque;
  712. float transition_manual_target;
  713. float transition_manual_val;
  714. bool transitioning_video;
  715. bool transitioning_audio;
  716. bool transition_source_active[2];
  717. uint32_t transition_alignment;
  718. uint32_t transition_actual_cx;
  719. uint32_t transition_actual_cy;
  720. uint32_t transition_cx;
  721. uint32_t transition_cy;
  722. uint32_t transition_fixed_duration;
  723. bool transition_use_fixed_duration;
  724. enum obs_transition_mode transition_mode;
  725. enum obs_transition_scale_type transition_scale_type;
  726. struct matrix4 transition_matrices[2];
  727. /* color space */
  728. gs_texrender_t *color_space_texrender;
  729. /* audio monitoring */
  730. struct audio_monitor *monitor;
  731. enum obs_monitoring_type monitoring_type;
  732. /* media action queue */
  733. DARRAY(struct media_action) media_actions;
  734. pthread_mutex_t media_actions_mutex;
  735. /* private data */
  736. obs_data_t *private_settings;
  737. };
  738. extern struct obs_source_info *get_source_info(const char *id);
  739. extern struct obs_source_info *get_source_info2(const char *unversioned_id,
  740. uint32_t ver);
  741. extern bool obs_source_init_context(struct obs_source *source,
  742. obs_data_t *settings, const char *name,
  743. const char *uuid, obs_data_t *hotkey_data,
  744. bool private);
  745. extern bool obs_transition_init(obs_source_t *transition);
  746. extern void obs_transition_free(obs_source_t *transition);
  747. extern void obs_transition_tick(obs_source_t *transition, float t);
  748. extern void obs_transition_enum_sources(obs_source_t *transition,
  749. obs_source_enum_proc_t enum_callback,
  750. void *param);
  751. extern void obs_transition_save(obs_source_t *source, obs_data_t *data);
  752. extern void obs_transition_load(obs_source_t *source, obs_data_t *data);
  753. struct audio_monitor *audio_monitor_create(obs_source_t *source);
  754. void audio_monitor_reset(struct audio_monitor *monitor);
  755. extern void audio_monitor_destroy(struct audio_monitor *monitor);
  756. extern obs_source_t *
  757. obs_source_create_set_last_ver(const char *id, const char *name,
  758. const char *uuid, obs_data_t *settings,
  759. obs_data_t *hotkey_data, uint32_t last_obs_ver,
  760. bool is_private);
  761. extern void obs_source_destroy(struct obs_source *source);
  762. enum view_type {
  763. MAIN_VIEW,
  764. AUX_VIEW,
  765. };
  766. static inline void obs_source_dosignal(struct obs_source *source,
  767. const char *signal_obs,
  768. const char *signal_source)
  769. {
  770. struct calldata data;
  771. uint8_t stack[128];
  772. calldata_init_fixed(&data, stack, sizeof(stack));
  773. calldata_set_ptr(&data, "source", source);
  774. if (signal_obs && !source->context.private)
  775. signal_handler_signal(obs->signals, signal_obs, &data);
  776. if (signal_source)
  777. signal_handler_signal(source->context.signals, signal_source,
  778. &data);
  779. }
  780. /* maximum timestamp variance in nanoseconds */
  781. #define MAX_TS_VAR 2000000000ULL
  782. static inline bool frame_out_of_bounds(const obs_source_t *source, uint64_t ts)
  783. {
  784. if (ts < source->last_frame_ts)
  785. return ((source->last_frame_ts - ts) > MAX_TS_VAR);
  786. else
  787. return ((ts - source->last_frame_ts) > MAX_TS_VAR);
  788. }
  789. static inline enum gs_color_format
  790. convert_video_format(enum video_format format, enum video_trc trc)
  791. {
  792. switch (trc) {
  793. case VIDEO_TRC_PQ:
  794. case VIDEO_TRC_HLG:
  795. return GS_RGBA16F;
  796. default:
  797. switch (format) {
  798. case VIDEO_FORMAT_RGBA:
  799. return GS_RGBA;
  800. case VIDEO_FORMAT_BGRA:
  801. case VIDEO_FORMAT_I40A:
  802. case VIDEO_FORMAT_I42A:
  803. case VIDEO_FORMAT_YUVA:
  804. case VIDEO_FORMAT_AYUV:
  805. return GS_BGRA;
  806. case VIDEO_FORMAT_I010:
  807. case VIDEO_FORMAT_P010:
  808. case VIDEO_FORMAT_I210:
  809. case VIDEO_FORMAT_I412:
  810. case VIDEO_FORMAT_YA2L:
  811. case VIDEO_FORMAT_P216:
  812. case VIDEO_FORMAT_P416:
  813. case VIDEO_FORMAT_V210:
  814. case VIDEO_FORMAT_R10L:
  815. return GS_RGBA16F;
  816. default:
  817. return GS_BGRX;
  818. }
  819. }
  820. }
  821. static inline enum gs_color_space convert_video_space(enum video_format format,
  822. enum video_trc trc)
  823. {
  824. enum gs_color_space space = GS_CS_SRGB;
  825. if (convert_video_format(format, trc) == GS_RGBA16F) {
  826. switch (trc) {
  827. case VIDEO_TRC_DEFAULT:
  828. case VIDEO_TRC_SRGB:
  829. space = GS_CS_SRGB_16F;
  830. break;
  831. case VIDEO_TRC_PQ:
  832. case VIDEO_TRC_HLG:
  833. space = GS_CS_709_EXTENDED;
  834. }
  835. }
  836. return space;
  837. }
  838. extern void obs_source_set_texcoords_centered(obs_source_t *source,
  839. bool centered);
  840. extern void obs_source_activate(obs_source_t *source, enum view_type type);
  841. extern void obs_source_deactivate(obs_source_t *source, enum view_type type);
  842. extern void obs_source_video_tick(obs_source_t *source, float seconds);
  843. extern float obs_source_get_target_volume(obs_source_t *source,
  844. obs_source_t *target);
  845. extern void obs_source_audio_render(obs_source_t *source, uint32_t mixers,
  846. size_t channels, size_t sample_rate,
  847. size_t size);
  848. extern void add_alignment(struct vec2 *v, uint32_t align, int cx, int cy);
  849. extern struct obs_source_frame *filter_async_video(obs_source_t *source,
  850. struct obs_source_frame *in);
  851. extern bool update_async_texture(struct obs_source *source,
  852. const struct obs_source_frame *frame,
  853. gs_texture_t *tex, gs_texrender_t *texrender);
  854. extern bool update_async_textures(struct obs_source *source,
  855. const struct obs_source_frame *frame,
  856. gs_texture_t *tex[MAX_AV_PLANES],
  857. gs_texrender_t *texrender);
  858. extern bool set_async_texture_size(struct obs_source *source,
  859. const struct obs_source_frame *frame);
  860. extern void remove_async_frame(obs_source_t *source,
  861. struct obs_source_frame *frame);
  862. extern void set_deinterlace_texture_size(obs_source_t *source);
  863. extern void deinterlace_process_last_frame(obs_source_t *source,
  864. uint64_t sys_time);
  865. extern void deinterlace_update_async_video(obs_source_t *source);
  866. extern void deinterlace_render(obs_source_t *s);
  867. /* ------------------------------------------------------------------------- */
  868. /* outputs */
  869. enum delay_msg {
  870. DELAY_MSG_PACKET,
  871. DELAY_MSG_START,
  872. DELAY_MSG_STOP,
  873. };
  874. struct delay_data {
  875. enum delay_msg msg;
  876. uint64_t ts;
  877. struct encoder_packet packet;
  878. };
  879. typedef void (*encoded_callback_t)(void *data, struct encoder_packet *packet);
  880. struct obs_weak_output {
  881. struct obs_weak_ref ref;
  882. struct obs_output *output;
  883. };
  884. #define CAPTION_LINE_CHARS (32)
  885. #define CAPTION_LINE_BYTES (4 * CAPTION_LINE_CHARS)
  886. struct caption_text {
  887. char text[CAPTION_LINE_BYTES + 1];
  888. double display_duration;
  889. struct caption_text *next;
  890. };
  891. struct pause_data {
  892. pthread_mutex_t mutex;
  893. uint64_t last_video_ts;
  894. uint64_t ts_start;
  895. uint64_t ts_end;
  896. uint64_t ts_offset;
  897. };
  898. extern bool video_pause_check(struct pause_data *pause, uint64_t timestamp);
  899. extern bool audio_pause_check(struct pause_data *pause, struct audio_data *data,
  900. size_t sample_rate);
  901. extern void pause_reset(struct pause_data *pause);
  902. struct obs_output {
  903. struct obs_context_data context;
  904. struct obs_output_info info;
  905. /* indicates ownership of the info.id buffer */
  906. bool owns_info_id;
  907. bool received_video[MAX_OUTPUT_VIDEO_ENCODERS];
  908. bool received_audio;
  909. volatile bool data_active;
  910. volatile bool end_data_capture_thread_active;
  911. int64_t video_offsets[MAX_OUTPUT_VIDEO_ENCODERS];
  912. int64_t audio_offsets[MAX_OUTPUT_AUDIO_ENCODERS];
  913. int64_t highest_audio_ts;
  914. int64_t highest_video_ts[MAX_OUTPUT_VIDEO_ENCODERS];
  915. pthread_t end_data_capture_thread;
  916. os_event_t *stopping_event;
  917. pthread_mutex_t interleaved_mutex;
  918. DARRAY(struct encoder_packet) interleaved_packets;
  919. int stop_code;
  920. int reconnect_retry_sec;
  921. int reconnect_retry_max;
  922. int reconnect_retries;
  923. uint32_t reconnect_retry_cur_msec;
  924. float reconnect_retry_exp;
  925. pthread_t reconnect_thread;
  926. os_event_t *reconnect_stop_event;
  927. volatile bool reconnecting;
  928. volatile bool reconnect_thread_active;
  929. uint32_t starting_drawn_count;
  930. uint32_t starting_lagged_count;
  931. int total_frames;
  932. volatile bool active;
  933. volatile bool paused;
  934. video_t *video;
  935. audio_t *audio;
  936. obs_encoder_t *video_encoders[MAX_OUTPUT_VIDEO_ENCODERS];
  937. obs_encoder_t *audio_encoders[MAX_OUTPUT_AUDIO_ENCODERS];
  938. obs_service_t *service;
  939. size_t mixer_mask;
  940. struct pause_data pause;
  941. struct deque audio_buffer[MAX_AUDIO_MIXES][MAX_AV_PLANES];
  942. uint64_t audio_start_ts;
  943. uint64_t video_start_ts;
  944. size_t audio_size;
  945. size_t planes;
  946. size_t sample_rate;
  947. size_t total_audio_frames;
  948. uint32_t scaled_width;
  949. uint32_t scaled_height;
  950. bool video_conversion_set;
  951. bool audio_conversion_set;
  952. struct video_scale_info video_conversion;
  953. struct audio_convert_info audio_conversion;
  954. pthread_mutex_t caption_mutex;
  955. double caption_timestamp;
  956. struct caption_text *caption_head;
  957. struct caption_text *caption_tail;
  958. struct deque caption_data;
  959. bool valid;
  960. uint64_t active_delay_ns;
  961. encoded_callback_t delay_callback;
  962. struct deque delay_data; /* struct delay_data */
  963. pthread_mutex_t delay_mutex;
  964. uint32_t delay_sec;
  965. uint32_t delay_flags;
  966. uint32_t delay_cur_flags;
  967. volatile long delay_restart_refs;
  968. volatile bool delay_active;
  969. volatile bool delay_capturing;
  970. char *last_error_message;
  971. float audio_data[MAX_AUDIO_CHANNELS][AUDIO_OUTPUT_FRAMES];
  972. };
  973. static inline void do_output_signal(struct obs_output *output,
  974. const char *signal)
  975. {
  976. struct calldata params = {0};
  977. calldata_set_ptr(&params, "output", output);
  978. signal_handler_signal(output->context.signals, signal, &params);
  979. calldata_free(&params);
  980. }
  981. extern void process_delay(void *data, struct encoder_packet *packet);
  982. extern void obs_output_cleanup_delay(obs_output_t *output);
  983. extern bool obs_output_delay_start(obs_output_t *output);
  984. extern void obs_output_delay_stop(obs_output_t *output);
  985. extern bool obs_output_actual_start(obs_output_t *output);
  986. extern void obs_output_actual_stop(obs_output_t *output, bool force,
  987. uint64_t ts);
  988. extern const struct obs_output_info *find_output(const char *id);
  989. extern void obs_output_remove_encoder(struct obs_output *output,
  990. struct obs_encoder *encoder);
  991. extern void
  992. obs_encoder_packet_create_instance(struct encoder_packet *dst,
  993. const struct encoder_packet *src);
  994. void obs_output_destroy(obs_output_t *output);
  995. /* ------------------------------------------------------------------------- */
  996. /* encoders */
  997. struct obs_weak_encoder {
  998. struct obs_weak_ref ref;
  999. struct obs_encoder *encoder;
  1000. };
  1001. struct encoder_callback {
  1002. bool sent_first_packet;
  1003. void (*new_packet)(void *param, struct encoder_packet *packet);
  1004. void *param;
  1005. };
  1006. struct obs_encoder {
  1007. struct obs_context_data context;
  1008. struct obs_encoder_info info;
  1009. /* allows re-routing to another encoder */
  1010. struct obs_encoder_info orig_info;
  1011. pthread_mutex_t init_mutex;
  1012. uint32_t samplerate;
  1013. size_t planes;
  1014. size_t blocksize;
  1015. size_t framesize;
  1016. size_t framesize_bytes;
  1017. size_t mixer_idx;
  1018. /* OBS_SCALE_DISABLE indicates GPU scaling is disabled */
  1019. enum obs_scale_type gpu_scale_type;
  1020. uint32_t scaled_width;
  1021. uint32_t scaled_height;
  1022. enum video_format preferred_format;
  1023. volatile bool active;
  1024. volatile bool paused;
  1025. bool initialized;
  1026. /* indicates ownership of the info.id buffer */
  1027. bool owns_info_id;
  1028. uint32_t timebase_num;
  1029. uint32_t timebase_den;
  1030. // allow outputting at fractions of main composition FPS,
  1031. // e.g. 60 FPS with frame_rate_divisor = 1 turns into 30 FPS
  1032. //
  1033. // a separate counter is used in favor of using remainder calculations
  1034. // to allow "inputs" started at the same time to start on the same frame
  1035. // whereas with remainder calculation the frame alignment would depend on
  1036. // the total frame count at the time the encoder was started
  1037. uint32_t frame_rate_divisor;
  1038. uint32_t frame_rate_divisor_counter; // only used for GPU encoders
  1039. video_t *fps_override;
  1040. /* Regions of interest to prioritize during encoding */
  1041. pthread_mutex_t roi_mutex;
  1042. DARRAY(struct obs_encoder_roi) roi;
  1043. uint32_t roi_increment;
  1044. int64_t cur_pts;
  1045. struct deque audio_input_buffer[MAX_AV_PLANES];
  1046. uint8_t *audio_output_buffer[MAX_AV_PLANES];
  1047. /* if a video encoder is paired with an audio encoder, make it start
  1048. * up at the specific timestamp. if this is the audio encoder,
  1049. * it waits until it's ready to sync up with video */
  1050. bool first_received;
  1051. DARRAY(struct obs_encoder *) paired_encoders;
  1052. int64_t offset_usec;
  1053. uint64_t first_raw_ts;
  1054. uint64_t start_ts;
  1055. pthread_mutex_t outputs_mutex;
  1056. DARRAY(obs_output_t *) outputs;
  1057. bool destroy_on_stop;
  1058. /* stores the video/audio media output pointer. video_t *or audio_t **/
  1059. void *media;
  1060. pthread_mutex_t callbacks_mutex;
  1061. DARRAY(struct encoder_callback) callbacks;
  1062. struct pause_data pause;
  1063. const char *profile_encoder_encode_name;
  1064. char *last_error_message;
  1065. /* reconfigure encoder at next possible opportunity */
  1066. bool reconfigure_requested;
  1067. };
  1068. extern struct obs_encoder_info *find_encoder(const char *id);
  1069. extern bool obs_encoder_initialize(obs_encoder_t *encoder);
  1070. extern void obs_encoder_shutdown(obs_encoder_t *encoder);
  1071. extern void obs_encoder_start(obs_encoder_t *encoder,
  1072. void (*new_packet)(void *param,
  1073. struct encoder_packet *packet),
  1074. void *param);
  1075. extern void obs_encoder_stop(obs_encoder_t *encoder,
  1076. void (*new_packet)(void *param,
  1077. struct encoder_packet *packet),
  1078. void *param);
  1079. extern void obs_encoder_add_output(struct obs_encoder *encoder,
  1080. struct obs_output *output);
  1081. extern void obs_encoder_remove_output(struct obs_encoder *encoder,
  1082. struct obs_output *output);
  1083. extern bool start_gpu_encode(obs_encoder_t *encoder);
  1084. extern void stop_gpu_encode(obs_encoder_t *encoder);
  1085. extern bool do_encode(struct obs_encoder *encoder, struct encoder_frame *frame);
  1086. extern void send_off_encoder_packet(obs_encoder_t *encoder, bool success,
  1087. bool received, struct encoder_packet *pkt);
  1088. void obs_encoder_destroy(obs_encoder_t *encoder);
  1089. /* ------------------------------------------------------------------------- */
  1090. /* services */
  1091. struct obs_weak_service {
  1092. struct obs_weak_ref ref;
  1093. struct obs_service *service;
  1094. };
  1095. struct obs_service {
  1096. struct obs_context_data context;
  1097. struct obs_service_info info;
  1098. /* indicates ownership of the info.id buffer */
  1099. bool owns_info_id;
  1100. bool active;
  1101. bool destroy;
  1102. struct obs_output *output;
  1103. };
  1104. extern const struct obs_service_info *find_service(const char *id);
  1105. extern void obs_service_activate(struct obs_service *service);
  1106. extern void obs_service_deactivate(struct obs_service *service, bool remove);
  1107. extern bool obs_service_initialize(struct obs_service *service,
  1108. struct obs_output *output);
  1109. void obs_service_destroy(obs_service_t *service);
  1110. void obs_output_remove_encoder_internal(struct obs_output *output,
  1111. struct obs_encoder *encoder);