obs-internal.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  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. #pragma once
  15. #include "util/c99defs.h"
  16. #include "util/darray.h"
  17. #include "util/circlebuf.h"
  18. #include "util/dstr.h"
  19. #include "util/threading.h"
  20. #include "util/platform.h"
  21. #include "util/profiler.h"
  22. #include "callback/signal.h"
  23. #include "callback/proc.h"
  24. #include "graphics/graphics.h"
  25. #include "media-io/audio-resampler.h"
  26. #include "media-io/video-io.h"
  27. #include "media-io/audio-io.h"
  28. #include "obs.h"
  29. #define NUM_TEXTURES 2
  30. #define MICROSECOND_DEN 1000000
  31. static inline int64_t packet_dts_usec(struct encoder_packet *packet)
  32. {
  33. return packet->dts * MICROSECOND_DEN / packet->timebase_den;
  34. }
  35. struct draw_callback {
  36. void (*draw)(void *param, uint32_t cx, uint32_t cy);
  37. void *param;
  38. };
  39. /* ------------------------------------------------------------------------- */
  40. /* validity checks */
  41. static inline bool obs_object_valid(const void *obj, const char *f,
  42. const char *t)
  43. {
  44. if (!obj) {
  45. blog(LOG_DEBUG, "%s: Null '%s' parameter", f, t);
  46. return false;
  47. }
  48. return true;
  49. }
  50. #define obs_ptr_valid(ptr, func) obs_object_valid(ptr, func, #ptr)
  51. #define obs_source_valid obs_ptr_valid
  52. #define obs_output_valid obs_ptr_valid
  53. #define obs_encoder_valid obs_ptr_valid
  54. #define obs_service_valid obs_ptr_valid
  55. /* ------------------------------------------------------------------------- */
  56. /* modules */
  57. struct obs_module {
  58. char *mod_name;
  59. const char *file;
  60. char *bin_path;
  61. char *data_path;
  62. void *module;
  63. bool loaded;
  64. bool (*load)(void);
  65. void (*unload)(void);
  66. void (*set_locale)(const char *locale);
  67. void (*free_locale)(void);
  68. uint32_t (*ver)(void);
  69. void (*set_pointer)(obs_module_t *module);
  70. const char *(*name)(void);
  71. const char *(*description)(void);
  72. const char *(*author)(void);
  73. struct obs_module *next;
  74. };
  75. extern void free_module(struct obs_module *mod);
  76. struct obs_module_path {
  77. char *bin;
  78. char *data;
  79. };
  80. static inline void free_module_path(struct obs_module_path *omp)
  81. {
  82. if (omp) {
  83. bfree(omp->bin);
  84. bfree(omp->data);
  85. }
  86. }
  87. static inline bool check_path(const char *data, const char *path,
  88. struct dstr *output)
  89. {
  90. dstr_copy(output, path);
  91. dstr_cat(output, data);
  92. return os_file_exists(output->array);
  93. }
  94. /* ------------------------------------------------------------------------- */
  95. /* hotkeys */
  96. struct obs_hotkey {
  97. obs_hotkey_id id;
  98. char *name;
  99. char *description;
  100. obs_hotkey_func func;
  101. void *data;
  102. int pressed;
  103. obs_hotkey_registerer_t registerer_type;
  104. void *registerer;
  105. obs_hotkey_id pair_partner_id;
  106. };
  107. struct obs_hotkey_pair {
  108. obs_hotkey_pair_id pair_id;
  109. obs_hotkey_id id[2];
  110. obs_hotkey_active_func func[2];
  111. bool pressed0 : 1;
  112. bool pressed1 : 1;
  113. void *data[2];
  114. };
  115. typedef struct obs_hotkey_pair obs_hotkey_pair_t;
  116. typedef struct obs_hotkeys_platform obs_hotkeys_platform_t;
  117. void *obs_hotkey_thread(void *param);
  118. struct obs_core_hotkeys;
  119. bool obs_hotkeys_platform_init(struct obs_core_hotkeys *hotkeys);
  120. void obs_hotkeys_platform_free(struct obs_core_hotkeys *hotkeys);
  121. bool obs_hotkeys_platform_is_pressed(obs_hotkeys_platform_t *context,
  122. obs_key_t key);
  123. const char *obs_get_hotkey_translation(obs_key_t key, const char *def);
  124. struct obs_context_data;
  125. void obs_hotkeys_context_release(struct obs_context_data *context);
  126. void obs_hotkeys_free(void);
  127. struct obs_hotkey_binding {
  128. obs_key_combination_t key;
  129. bool pressed : 1;
  130. bool modifiers_match : 1;
  131. obs_hotkey_id hotkey_id;
  132. obs_hotkey_t *hotkey;
  133. };
  134. struct obs_hotkey_name_map;
  135. void obs_hotkey_name_map_free(void);
  136. /* ------------------------------------------------------------------------- */
  137. /* views */
  138. struct obs_view {
  139. pthread_mutex_t channels_mutex;
  140. obs_source_t *channels[MAX_CHANNELS];
  141. };
  142. extern bool obs_view_init(struct obs_view *view);
  143. extern void obs_view_free(struct obs_view *view);
  144. /* ------------------------------------------------------------------------- */
  145. /* displays */
  146. struct obs_display {
  147. bool size_changed;
  148. bool enabled;
  149. uint32_t cx, cy;
  150. uint32_t background_color;
  151. gs_swapchain_t *swap;
  152. pthread_mutex_t draw_callbacks_mutex;
  153. DARRAY(struct draw_callback) draw_callbacks;
  154. struct obs_display *next;
  155. struct obs_display **prev_next;
  156. };
  157. extern bool obs_display_init(struct obs_display *display,
  158. const struct gs_init_data *graphics_data);
  159. extern void obs_display_free(struct obs_display *display);
  160. /* ------------------------------------------------------------------------- */
  161. /* core */
  162. struct obs_vframe_info {
  163. uint64_t timestamp;
  164. int count;
  165. };
  166. struct obs_core_video {
  167. graphics_t *graphics;
  168. gs_stagesurf_t *copy_surfaces[NUM_TEXTURES];
  169. gs_texture_t *render_textures[NUM_TEXTURES];
  170. gs_texture_t *output_textures[NUM_TEXTURES];
  171. gs_texture_t *convert_textures[NUM_TEXTURES];
  172. bool textures_rendered[NUM_TEXTURES];
  173. bool textures_output[NUM_TEXTURES];
  174. bool textures_copied[NUM_TEXTURES];
  175. bool textures_converted[NUM_TEXTURES];
  176. struct circlebuf vframe_info_buffer;
  177. gs_effect_t *default_effect;
  178. gs_effect_t *default_rect_effect;
  179. gs_effect_t *opaque_effect;
  180. gs_effect_t *solid_effect;
  181. gs_effect_t *conversion_effect;
  182. gs_effect_t *bicubic_effect;
  183. gs_effect_t *lanczos_effect;
  184. gs_effect_t *bilinear_lowres_effect;
  185. gs_stagesurf_t *mapped_surface;
  186. int cur_texture;
  187. uint64_t video_time;
  188. video_t *video;
  189. pthread_t video_thread;
  190. bool thread_initialized;
  191. bool gpu_conversion;
  192. const char *conversion_tech;
  193. uint32_t conversion_height;
  194. uint32_t plane_offsets[3];
  195. uint32_t plane_sizes[3];
  196. uint32_t plane_linewidth[3];
  197. uint32_t output_width;
  198. uint32_t output_height;
  199. uint32_t base_width;
  200. uint32_t base_height;
  201. float color_matrix[16];
  202. enum obs_scale_type scale_type;
  203. };
  204. struct obs_core_audio {
  205. /* TODO: sound output subsystem */
  206. audio_t *audio;
  207. float user_volume;
  208. float present_volume;
  209. };
  210. /* user sources, output channels, and displays */
  211. struct obs_core_data {
  212. pthread_mutex_t user_sources_mutex;
  213. DARRAY(struct obs_source*) user_sources;
  214. struct obs_source *first_source;
  215. struct obs_display *first_display;
  216. struct obs_output *first_output;
  217. struct obs_encoder *first_encoder;
  218. struct obs_service *first_service;
  219. pthread_mutex_t sources_mutex;
  220. pthread_mutex_t displays_mutex;
  221. pthread_mutex_t outputs_mutex;
  222. pthread_mutex_t encoders_mutex;
  223. pthread_mutex_t services_mutex;
  224. struct obs_view main_view;
  225. volatile long active_transitions;
  226. long long unnamed_index;
  227. volatile bool valid;
  228. };
  229. /* user hotkeys */
  230. struct obs_core_hotkeys {
  231. pthread_mutex_t mutex;
  232. DARRAY(obs_hotkey_t) hotkeys;
  233. obs_hotkey_id next_id;
  234. DARRAY(obs_hotkey_pair_t) hotkey_pairs;
  235. obs_hotkey_pair_id next_pair_id;
  236. pthread_t hotkey_thread;
  237. bool hotkey_thread_initialized;
  238. os_event_t *stop_event;
  239. bool thread_disable_press : 1;
  240. bool strict_modifiers : 1;
  241. bool reroute_hotkeys : 1;
  242. DARRAY(obs_hotkey_binding_t) bindings;
  243. obs_hotkey_callback_router_func router_func;
  244. void *router_func_data;
  245. obs_hotkeys_platform_t *platform_context;
  246. pthread_once_t name_map_init_token;
  247. struct obs_hotkey_name_map *name_map;
  248. signal_handler_t *signals;
  249. char *translations[OBS_KEY_LAST_VALUE];
  250. char *mute;
  251. char *unmute;
  252. char *push_to_mute;
  253. char *push_to_talk;
  254. char *sceneitem_show;
  255. char *sceneitem_hide;
  256. };
  257. struct obs_core {
  258. struct obs_module *first_module;
  259. DARRAY(struct obs_module_path) module_paths;
  260. DARRAY(struct obs_source_info) input_types;
  261. DARRAY(struct obs_source_info) filter_types;
  262. DARRAY(struct obs_source_info) transition_types;
  263. DARRAY(struct obs_output_info) output_types;
  264. DARRAY(struct obs_encoder_info) encoder_types;
  265. DARRAY(struct obs_service_info) service_types;
  266. DARRAY(struct obs_modal_ui) modal_ui_callbacks;
  267. DARRAY(struct obs_modeless_ui) modeless_ui_callbacks;
  268. signal_handler_t *signals;
  269. proc_handler_t *procs;
  270. char *locale;
  271. char *module_config_path;
  272. bool name_store_owned;
  273. profiler_name_store_t *name_store;
  274. /* segmented into multiple sub-structures to keep things a bit more
  275. * clean and organized */
  276. struct obs_core_video video;
  277. struct obs_core_audio audio;
  278. struct obs_core_data data;
  279. struct obs_core_hotkeys hotkeys;
  280. };
  281. extern struct obs_core *obs;
  282. extern void *obs_video_thread(void *param);
  283. /* ------------------------------------------------------------------------- */
  284. /* obs shared context data */
  285. struct obs_context_data {
  286. char *name;
  287. void *data;
  288. obs_data_t *settings;
  289. signal_handler_t *signals;
  290. proc_handler_t *procs;
  291. DARRAY(obs_hotkey_id) hotkeys;
  292. DARRAY(obs_hotkey_pair_id) hotkey_pairs;
  293. obs_data_t *hotkey_data;
  294. DARRAY(char*) rename_cache;
  295. pthread_mutex_t rename_cache_mutex;
  296. pthread_mutex_t *mutex;
  297. struct obs_context_data *next;
  298. struct obs_context_data **prev_next;
  299. };
  300. extern bool obs_context_data_init(
  301. struct obs_context_data *context,
  302. obs_data_t *settings,
  303. const char *name,
  304. obs_data_t *hotkey_data);
  305. extern void obs_context_data_free(struct obs_context_data *context);
  306. extern void obs_context_data_insert(struct obs_context_data *context,
  307. pthread_mutex_t *mutex, void *first);
  308. extern void obs_context_data_remove(struct obs_context_data *context);
  309. extern void obs_context_data_setname(struct obs_context_data *context,
  310. const char *name);
  311. /* ------------------------------------------------------------------------- */
  312. /* ref-counting */
  313. struct obs_weak_ref {
  314. volatile long refs;
  315. volatile long weak_refs;
  316. };
  317. static inline void obs_ref_addref(struct obs_weak_ref *ref)
  318. {
  319. os_atomic_inc_long(&ref->refs);
  320. }
  321. static inline bool obs_ref_release(struct obs_weak_ref *ref)
  322. {
  323. return os_atomic_dec_long(&ref->refs) == -1;
  324. }
  325. static inline void obs_weak_ref_addref(struct obs_weak_ref *ref)
  326. {
  327. os_atomic_inc_long(&ref->weak_refs);
  328. }
  329. static inline bool obs_weak_ref_release(struct obs_weak_ref *ref)
  330. {
  331. return os_atomic_dec_long(&ref->weak_refs) == -1;
  332. }
  333. static inline bool obs_weak_ref_get_ref(struct obs_weak_ref *ref)
  334. {
  335. long owners = ref->refs;
  336. while (owners > -1) {
  337. if (os_atomic_compare_swap_long(&ref->refs, owners, owners + 1))
  338. return true;
  339. owners = ref->refs;
  340. }
  341. return false;
  342. }
  343. /* ------------------------------------------------------------------------- */
  344. /* sources */
  345. struct async_frame {
  346. struct obs_source_frame *frame;
  347. long unused_count;
  348. bool used;
  349. };
  350. struct obs_weak_source {
  351. struct obs_weak_ref ref;
  352. struct obs_source *source;
  353. };
  354. struct obs_source {
  355. struct obs_context_data context;
  356. struct obs_source_info info;
  357. struct obs_weak_source *control;
  358. /* general exposed flags that can be set for the source */
  359. uint32_t flags;
  360. uint32_t default_flags;
  361. /* indicates ownership of the info.id buffer */
  362. bool owns_info_id;
  363. /* signals to call the source update in the video thread */
  364. bool defer_update;
  365. /* ensures show/hide are only called once */
  366. volatile long show_refs;
  367. /* ensures activate/deactivate are only called once */
  368. volatile long activate_refs;
  369. /* used to indicate that the source has been removed and all
  370. * references to it should be released (not exactly how I would prefer
  371. * to handle things but it's the best option) */
  372. bool removed;
  373. bool active;
  374. bool showing;
  375. /* used to temporarily disable sources if needed */
  376. bool enabled;
  377. /* timing (if video is present, is based upon video) */
  378. volatile bool timing_set;
  379. volatile uint64_t timing_adjust;
  380. uint64_t next_audio_ts_min;
  381. uint64_t last_frame_ts;
  382. uint64_t last_sys_timestamp;
  383. bool async_rendered;
  384. /* audio */
  385. bool audio_failed;
  386. bool muted;
  387. struct resample_info sample_info;
  388. audio_resampler_t *resampler;
  389. audio_line_t *audio_line;
  390. pthread_mutex_t audio_mutex;
  391. struct obs_audio_data audio_data;
  392. size_t audio_storage_size;
  393. float base_volume;
  394. float user_volume;
  395. float present_volume;
  396. int64_t sync_offset;
  397. /* async video data */
  398. gs_texture_t *async_texture;
  399. gs_texrender_t *async_convert_texrender;
  400. struct obs_source_frame *cur_async_frame;
  401. bool async_gpu_conversion;
  402. enum video_format async_format;
  403. enum video_format async_cache_format;
  404. enum gs_color_format async_texture_format;
  405. float async_color_matrix[16];
  406. bool async_full_range;
  407. float async_color_range_min[3];
  408. float async_color_range_max[3];
  409. int async_plane_offset[2];
  410. bool async_flip;
  411. bool async_active;
  412. DARRAY(struct async_frame) async_cache;
  413. DARRAY(struct obs_source_frame*)async_frames;
  414. pthread_mutex_t async_mutex;
  415. uint32_t async_width;
  416. uint32_t async_height;
  417. uint32_t async_cache_width;
  418. uint32_t async_cache_height;
  419. uint32_t async_convert_width;
  420. uint32_t async_convert_height;
  421. /* filters */
  422. struct obs_source *filter_parent;
  423. struct obs_source *filter_target;
  424. DARRAY(struct obs_source*) filters;
  425. pthread_mutex_t filter_mutex;
  426. gs_texrender_t *filter_texrender;
  427. enum obs_allow_direct_render allow_direct;
  428. bool rendering_filter;
  429. /* sources specific hotkeys */
  430. obs_hotkey_pair_id mute_unmute_key;
  431. obs_hotkey_id push_to_mute_key;
  432. obs_hotkey_id push_to_talk_key;
  433. bool push_to_mute_enabled : 1;
  434. bool push_to_mute_pressed : 1;
  435. bool push_to_talk_enabled : 1;
  436. bool push_to_talk_pressed : 1;
  437. uint64_t push_to_mute_delay;
  438. uint64_t push_to_mute_stop_time;
  439. uint64_t push_to_talk_delay;
  440. uint64_t push_to_talk_stop_time;
  441. };
  442. extern const struct obs_source_info *find_source(struct darray *list,
  443. const char *id);
  444. extern bool obs_source_init_context(struct obs_source *source,
  445. obs_data_t *settings, const char *name,
  446. obs_data_t *hotkey_data);
  447. extern bool obs_source_init(struct obs_source *source,
  448. const struct obs_source_info *info);
  449. extern void obs_source_destroy(struct obs_source *source);
  450. enum view_type {
  451. MAIN_VIEW,
  452. AUX_VIEW
  453. };
  454. extern void obs_source_activate(obs_source_t *source, enum view_type type);
  455. extern void obs_source_deactivate(obs_source_t *source, enum view_type type);
  456. extern void obs_source_video_tick(obs_source_t *source, float seconds);
  457. extern float obs_source_get_target_volume(obs_source_t *source,
  458. obs_source_t *target);
  459. /* ------------------------------------------------------------------------- */
  460. /* outputs */
  461. enum delay_msg {
  462. DELAY_MSG_PACKET,
  463. DELAY_MSG_START,
  464. DELAY_MSG_STOP,
  465. };
  466. struct delay_data {
  467. enum delay_msg msg;
  468. uint64_t ts;
  469. struct encoder_packet packet;
  470. };
  471. typedef void (*encoded_callback_t)(void *data, struct encoder_packet *packet);
  472. struct obs_weak_output {
  473. struct obs_weak_ref ref;
  474. struct obs_output *output;
  475. };
  476. struct obs_output {
  477. struct obs_context_data context;
  478. struct obs_output_info info;
  479. struct obs_weak_output *control;
  480. /* indicates ownership of the info.id buffer */
  481. bool owns_info_id;
  482. bool received_video;
  483. bool received_audio;
  484. int64_t video_offset;
  485. int64_t audio_offsets[MAX_AUDIO_MIXES];
  486. int64_t highest_audio_ts;
  487. int64_t highest_video_ts;
  488. pthread_mutex_t interleaved_mutex;
  489. DARRAY(struct encoder_packet) interleaved_packets;
  490. int reconnect_retry_sec;
  491. int reconnect_retry_max;
  492. int reconnect_retries;
  493. int reconnect_retry_cur_sec;
  494. bool reconnecting;
  495. pthread_t reconnect_thread;
  496. os_event_t *reconnect_stop_event;
  497. volatile bool reconnect_thread_active;
  498. uint32_t starting_frame_count;
  499. uint32_t starting_skipped_frame_count;
  500. int total_frames;
  501. bool active;
  502. volatile bool stopped;
  503. video_t *video;
  504. audio_t *audio;
  505. obs_encoder_t *video_encoder;
  506. obs_encoder_t *audio_encoders[MAX_AUDIO_MIXES];
  507. obs_service_t *service;
  508. size_t mixer_idx;
  509. uint32_t scaled_width;
  510. uint32_t scaled_height;
  511. bool video_conversion_set;
  512. bool audio_conversion_set;
  513. struct video_scale_info video_conversion;
  514. struct audio_convert_info audio_conversion;
  515. bool valid;
  516. uint64_t active_delay_ns;
  517. encoded_callback_t delay_callback;
  518. struct circlebuf delay_data; /* struct delay_data */
  519. pthread_mutex_t delay_mutex;
  520. uint32_t delay_sec;
  521. uint32_t delay_flags;
  522. uint32_t delay_cur_flags;
  523. volatile long delay_restart_refs;
  524. bool delay_active;
  525. bool delay_capturing;
  526. };
  527. static inline void do_output_signal(struct obs_output *output,
  528. const char *signal)
  529. {
  530. struct calldata params = {0};
  531. calldata_set_ptr(&params, "output", output);
  532. signal_handler_signal(output->context.signals, signal, &params);
  533. calldata_free(&params);
  534. }
  535. extern void process_delay(void *data, struct encoder_packet *packet);
  536. extern void obs_output_cleanup_delay(obs_output_t *output);
  537. extern bool obs_output_delay_start(obs_output_t *output);
  538. extern void obs_output_delay_stop(obs_output_t *output);
  539. extern bool obs_output_actual_start(obs_output_t *output);
  540. extern void obs_output_actual_stop(obs_output_t *output, bool force);
  541. extern const struct obs_output_info *find_output(const char *id);
  542. extern void obs_output_remove_encoder(struct obs_output *output,
  543. struct obs_encoder *encoder);
  544. void obs_output_destroy(obs_output_t *output);
  545. /* ------------------------------------------------------------------------- */
  546. /* encoders */
  547. struct obs_weak_encoder {
  548. struct obs_weak_ref ref;
  549. struct obs_encoder *encoder;
  550. };
  551. struct encoder_callback {
  552. bool sent_first_packet;
  553. void (*new_packet)(void *param, struct encoder_packet *packet);
  554. void *param;
  555. };
  556. struct obs_encoder {
  557. struct obs_context_data context;
  558. struct obs_encoder_info info;
  559. struct obs_weak_encoder *control;
  560. uint32_t samplerate;
  561. size_t planes;
  562. size_t blocksize;
  563. size_t framesize;
  564. size_t framesize_bytes;
  565. size_t mixer_idx;
  566. uint32_t scaled_width;
  567. uint32_t scaled_height;
  568. enum video_format preferred_format;
  569. bool active;
  570. /* indicates ownership of the info.id buffer */
  571. bool owns_info_id;
  572. uint32_t timebase_num;
  573. uint32_t timebase_den;
  574. int64_t cur_pts;
  575. struct circlebuf audio_input_buffer[MAX_AV_PLANES];
  576. uint8_t *audio_output_buffer[MAX_AV_PLANES];
  577. /* if a video encoder is paired with an audio encoder, make it start
  578. * up at the specific timestamp. if this is the audio encoder,
  579. * wait_for_video makes it wait until it's ready to sync up with
  580. * video */
  581. bool wait_for_video;
  582. struct obs_encoder *paired_encoder;
  583. uint64_t start_ts;
  584. pthread_mutex_t outputs_mutex;
  585. DARRAY(obs_output_t*) outputs;
  586. bool destroy_on_stop;
  587. /* stores the video/audio media output pointer. video_t *or audio_t **/
  588. void *media;
  589. pthread_mutex_t callbacks_mutex;
  590. DARRAY(struct encoder_callback) callbacks;
  591. const char *profile_encoder_encode_name;
  592. };
  593. extern struct obs_encoder_info *find_encoder(const char *id);
  594. extern bool obs_encoder_initialize(obs_encoder_t *encoder);
  595. extern void obs_encoder_shutdown(obs_encoder_t *encoder);
  596. extern void obs_encoder_start(obs_encoder_t *encoder,
  597. void (*new_packet)(void *param, struct encoder_packet *packet),
  598. void *param);
  599. extern void obs_encoder_stop(obs_encoder_t *encoder,
  600. void (*new_packet)(void *param, struct encoder_packet *packet),
  601. void *param);
  602. extern void obs_encoder_add_output(struct obs_encoder *encoder,
  603. struct obs_output *output);
  604. extern void obs_encoder_remove_output(struct obs_encoder *encoder,
  605. struct obs_output *output);
  606. void obs_encoder_destroy(obs_encoder_t *encoder);
  607. /* ------------------------------------------------------------------------- */
  608. /* services */
  609. struct obs_weak_service {
  610. struct obs_weak_ref ref;
  611. struct obs_service *service;
  612. };
  613. struct obs_service {
  614. struct obs_context_data context;
  615. struct obs_service_info info;
  616. struct obs_weak_service *control;
  617. /* indicates ownership of the info.id buffer */
  618. bool owns_info_id;
  619. bool active;
  620. bool destroy;
  621. struct obs_output *output;
  622. };
  623. extern const struct obs_service_info *find_service(const char *id);
  624. extern void obs_service_activate(struct obs_service *service);
  625. extern void obs_service_deactivate(struct obs_service *service, bool remove);
  626. extern bool obs_service_initialize(struct obs_service *service,
  627. struct obs_output *output);
  628. void obs_service_destroy(obs_service_t *service);