obs-internal.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  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. struct obs_source *first_source;
  213. struct obs_source *first_audio_source;
  214. struct obs_display *first_display;
  215. struct obs_output *first_output;
  216. struct obs_encoder *first_encoder;
  217. struct obs_service *first_service;
  218. pthread_mutex_t sources_mutex;
  219. pthread_mutex_t displays_mutex;
  220. pthread_mutex_t outputs_mutex;
  221. pthread_mutex_t encoders_mutex;
  222. pthread_mutex_t services_mutex;
  223. pthread_mutex_t audio_sources_mutex;
  224. struct obs_view main_view;
  225. long long unnamed_index;
  226. volatile bool valid;
  227. };
  228. /* user hotkeys */
  229. struct obs_core_hotkeys {
  230. pthread_mutex_t mutex;
  231. DARRAY(obs_hotkey_t) hotkeys;
  232. obs_hotkey_id next_id;
  233. DARRAY(obs_hotkey_pair_t) hotkey_pairs;
  234. obs_hotkey_pair_id next_pair_id;
  235. pthread_t hotkey_thread;
  236. bool hotkey_thread_initialized;
  237. os_event_t *stop_event;
  238. bool thread_disable_press : 1;
  239. bool strict_modifiers : 1;
  240. bool reroute_hotkeys : 1;
  241. DARRAY(obs_hotkey_binding_t) bindings;
  242. obs_hotkey_callback_router_func router_func;
  243. void *router_func_data;
  244. obs_hotkeys_platform_t *platform_context;
  245. pthread_once_t name_map_init_token;
  246. struct obs_hotkey_name_map *name_map;
  247. signal_handler_t *signals;
  248. char *translations[OBS_KEY_LAST_VALUE];
  249. char *mute;
  250. char *unmute;
  251. char *push_to_mute;
  252. char *push_to_talk;
  253. char *sceneitem_show;
  254. char *sceneitem_hide;
  255. };
  256. struct obs_core {
  257. struct obs_module *first_module;
  258. DARRAY(struct obs_module_path) module_paths;
  259. DARRAY(struct obs_source_info) input_types;
  260. DARRAY(struct obs_source_info) filter_types;
  261. DARRAY(struct obs_source_info) transition_types;
  262. DARRAY(struct obs_output_info) output_types;
  263. DARRAY(struct obs_encoder_info) encoder_types;
  264. DARRAY(struct obs_service_info) service_types;
  265. DARRAY(struct obs_modal_ui) modal_ui_callbacks;
  266. DARRAY(struct obs_modeless_ui) modeless_ui_callbacks;
  267. signal_handler_t *signals;
  268. proc_handler_t *procs;
  269. char *locale;
  270. char *module_config_path;
  271. bool name_store_owned;
  272. profiler_name_store_t *name_store;
  273. /* segmented into multiple sub-structures to keep things a bit more
  274. * clean and organized */
  275. struct obs_core_video video;
  276. struct obs_core_audio audio;
  277. struct obs_core_data data;
  278. struct obs_core_hotkeys hotkeys;
  279. };
  280. extern struct obs_core *obs;
  281. extern void *obs_video_thread(void *param);
  282. /* ------------------------------------------------------------------------- */
  283. /* obs shared context data */
  284. struct obs_context_data {
  285. char *name;
  286. void *data;
  287. obs_data_t *settings;
  288. signal_handler_t *signals;
  289. proc_handler_t *procs;
  290. DARRAY(obs_hotkey_id) hotkeys;
  291. DARRAY(obs_hotkey_pair_id) hotkey_pairs;
  292. obs_data_t *hotkey_data;
  293. DARRAY(char*) rename_cache;
  294. pthread_mutex_t rename_cache_mutex;
  295. pthread_mutex_t *mutex;
  296. struct obs_context_data *next;
  297. struct obs_context_data **prev_next;
  298. };
  299. extern bool obs_context_data_init(
  300. struct obs_context_data *context,
  301. obs_data_t *settings,
  302. const char *name,
  303. obs_data_t *hotkey_data);
  304. extern void obs_context_data_free(struct obs_context_data *context);
  305. extern void obs_context_data_insert(struct obs_context_data *context,
  306. pthread_mutex_t *mutex, void *first);
  307. extern void obs_context_data_remove(struct obs_context_data *context);
  308. extern void obs_context_data_setname(struct obs_context_data *context,
  309. const char *name);
  310. /* ------------------------------------------------------------------------- */
  311. /* ref-counting */
  312. struct obs_weak_ref {
  313. volatile long refs;
  314. volatile long weak_refs;
  315. };
  316. static inline void obs_ref_addref(struct obs_weak_ref *ref)
  317. {
  318. os_atomic_inc_long(&ref->refs);
  319. }
  320. static inline bool obs_ref_release(struct obs_weak_ref *ref)
  321. {
  322. return os_atomic_dec_long(&ref->refs) == -1;
  323. }
  324. static inline void obs_weak_ref_addref(struct obs_weak_ref *ref)
  325. {
  326. os_atomic_inc_long(&ref->weak_refs);
  327. }
  328. static inline bool obs_weak_ref_release(struct obs_weak_ref *ref)
  329. {
  330. return os_atomic_dec_long(&ref->weak_refs) == -1;
  331. }
  332. static inline bool obs_weak_ref_get_ref(struct obs_weak_ref *ref)
  333. {
  334. long owners = ref->refs;
  335. while (owners > -1) {
  336. if (os_atomic_compare_swap_long(&ref->refs, owners, owners + 1))
  337. return true;
  338. owners = ref->refs;
  339. }
  340. return false;
  341. }
  342. /* ------------------------------------------------------------------------- */
  343. /* sources */
  344. struct async_frame {
  345. struct obs_source_frame *frame;
  346. long unused_count;
  347. bool used;
  348. };
  349. struct obs_weak_source {
  350. struct obs_weak_ref ref;
  351. struct obs_source *source;
  352. };
  353. struct obs_source {
  354. struct obs_context_data context;
  355. struct obs_source_info info;
  356. struct obs_weak_source *control;
  357. /* general exposed flags that can be set for the source */
  358. uint32_t flags;
  359. uint32_t default_flags;
  360. /* indicates ownership of the info.id buffer */
  361. bool owns_info_id;
  362. /* signals to call the source update in the video thread */
  363. bool defer_update;
  364. /* ensures show/hide are only called once */
  365. volatile long show_refs;
  366. /* ensures activate/deactivate are only called once */
  367. volatile long activate_refs;
  368. /* used to indicate that the source has been removed and all
  369. * references to it should be released (not exactly how I would prefer
  370. * to handle things but it's the best option) */
  371. bool removed;
  372. bool active;
  373. bool showing;
  374. /* used to temporarily disable sources if needed */
  375. bool enabled;
  376. /* timing (if video is present, is based upon video) */
  377. volatile bool timing_set;
  378. volatile uint64_t timing_adjust;
  379. uint64_t next_audio_ts_min;
  380. uint64_t last_frame_ts;
  381. uint64_t last_sys_timestamp;
  382. bool async_rendered;
  383. /* audio */
  384. bool audio_failed;
  385. bool muted;
  386. struct obs_source *next_audio_source;
  387. struct obs_source **prev_next_audio_source;
  388. struct resample_info sample_info;
  389. audio_resampler_t *resampler;
  390. audio_line_t *audio_line;
  391. pthread_mutex_t audio_mutex;
  392. struct obs_audio_data audio_data;
  393. size_t audio_storage_size;
  394. float base_volume;
  395. float user_volume;
  396. float present_volume;
  397. int64_t sync_offset;
  398. /* async video data */
  399. gs_texture_t *async_texture;
  400. gs_texrender_t *async_convert_texrender;
  401. struct obs_source_frame *cur_async_frame;
  402. bool async_gpu_conversion;
  403. enum video_format async_format;
  404. enum video_format async_cache_format;
  405. enum gs_color_format async_texture_format;
  406. float async_color_matrix[16];
  407. bool async_full_range;
  408. float async_color_range_min[3];
  409. float async_color_range_max[3];
  410. int async_plane_offset[2];
  411. bool async_flip;
  412. bool async_active;
  413. DARRAY(struct async_frame) async_cache;
  414. DARRAY(struct obs_source_frame*)async_frames;
  415. pthread_mutex_t async_mutex;
  416. uint32_t async_width;
  417. uint32_t async_height;
  418. uint32_t async_cache_width;
  419. uint32_t async_cache_height;
  420. uint32_t async_convert_width;
  421. uint32_t async_convert_height;
  422. /* filters */
  423. struct obs_source *filter_parent;
  424. struct obs_source *filter_target;
  425. DARRAY(struct obs_source*) filters;
  426. pthread_mutex_t filter_mutex;
  427. gs_texrender_t *filter_texrender;
  428. enum obs_allow_direct_render allow_direct;
  429. bool rendering_filter;
  430. /* sources specific hotkeys */
  431. obs_hotkey_pair_id mute_unmute_key;
  432. obs_hotkey_id push_to_mute_key;
  433. obs_hotkey_id push_to_talk_key;
  434. bool push_to_mute_enabled : 1;
  435. bool push_to_mute_pressed : 1;
  436. bool push_to_talk_enabled : 1;
  437. bool push_to_talk_pressed : 1;
  438. uint64_t push_to_mute_delay;
  439. uint64_t push_to_mute_stop_time;
  440. uint64_t push_to_talk_delay;
  441. uint64_t push_to_talk_stop_time;
  442. };
  443. extern const struct obs_source_info *find_source(struct darray *list,
  444. const char *id);
  445. extern bool obs_source_init_context(struct obs_source *source,
  446. obs_data_t *settings, const char *name,
  447. obs_data_t *hotkey_data);
  448. extern bool obs_source_init(struct obs_source *source,
  449. const struct obs_source_info *info);
  450. extern void obs_source_destroy(struct obs_source *source);
  451. enum view_type {
  452. MAIN_VIEW,
  453. AUX_VIEW
  454. };
  455. extern void obs_source_activate(obs_source_t *source, enum view_type type);
  456. extern void obs_source_deactivate(obs_source_t *source, enum view_type type);
  457. extern void obs_source_video_tick(obs_source_t *source, float seconds);
  458. extern float obs_source_get_target_volume(obs_source_t *source,
  459. obs_source_t *target);
  460. /* ------------------------------------------------------------------------- */
  461. /* outputs */
  462. enum delay_msg {
  463. DELAY_MSG_PACKET,
  464. DELAY_MSG_START,
  465. DELAY_MSG_STOP,
  466. };
  467. struct delay_data {
  468. enum delay_msg msg;
  469. uint64_t ts;
  470. struct encoder_packet packet;
  471. };
  472. typedef void (*encoded_callback_t)(void *data, struct encoder_packet *packet);
  473. struct obs_weak_output {
  474. struct obs_weak_ref ref;
  475. struct obs_output *output;
  476. };
  477. struct obs_output {
  478. struct obs_context_data context;
  479. struct obs_output_info info;
  480. struct obs_weak_output *control;
  481. /* indicates ownership of the info.id buffer */
  482. bool owns_info_id;
  483. bool received_video;
  484. bool received_audio;
  485. int64_t video_offset;
  486. int64_t audio_offsets[MAX_AUDIO_MIXES];
  487. int64_t highest_audio_ts;
  488. int64_t highest_video_ts;
  489. pthread_mutex_t interleaved_mutex;
  490. DARRAY(struct encoder_packet) interleaved_packets;
  491. int reconnect_retry_sec;
  492. int reconnect_retry_max;
  493. int reconnect_retries;
  494. int reconnect_retry_cur_sec;
  495. bool reconnecting;
  496. pthread_t reconnect_thread;
  497. os_event_t *reconnect_stop_event;
  498. volatile bool reconnect_thread_active;
  499. uint32_t starting_frame_count;
  500. uint32_t starting_skipped_frame_count;
  501. int total_frames;
  502. bool active;
  503. volatile bool stopped;
  504. video_t *video;
  505. audio_t *audio;
  506. obs_encoder_t *video_encoder;
  507. obs_encoder_t *audio_encoders[MAX_AUDIO_MIXES];
  508. obs_service_t *service;
  509. size_t mixer_idx;
  510. uint32_t scaled_width;
  511. uint32_t scaled_height;
  512. bool video_conversion_set;
  513. bool audio_conversion_set;
  514. struct video_scale_info video_conversion;
  515. struct audio_convert_info audio_conversion;
  516. bool valid;
  517. uint64_t active_delay_ns;
  518. encoded_callback_t delay_callback;
  519. struct circlebuf delay_data; /* struct delay_data */
  520. pthread_mutex_t delay_mutex;
  521. uint32_t delay_sec;
  522. uint32_t delay_flags;
  523. uint32_t delay_cur_flags;
  524. volatile long delay_restart_refs;
  525. bool delay_active;
  526. bool delay_capturing;
  527. };
  528. static inline void do_output_signal(struct obs_output *output,
  529. const char *signal)
  530. {
  531. struct calldata params = {0};
  532. calldata_set_ptr(&params, "output", output);
  533. signal_handler_signal(output->context.signals, signal, &params);
  534. calldata_free(&params);
  535. }
  536. extern void process_delay(void *data, struct encoder_packet *packet);
  537. extern void obs_output_cleanup_delay(obs_output_t *output);
  538. extern bool obs_output_delay_start(obs_output_t *output);
  539. extern void obs_output_delay_stop(obs_output_t *output);
  540. extern bool obs_output_actual_start(obs_output_t *output);
  541. extern void obs_output_actual_stop(obs_output_t *output, bool force);
  542. extern const struct obs_output_info *find_output(const char *id);
  543. extern void obs_output_remove_encoder(struct obs_output *output,
  544. struct obs_encoder *encoder);
  545. void obs_output_destroy(obs_output_t *output);
  546. /* ------------------------------------------------------------------------- */
  547. /* encoders */
  548. struct obs_weak_encoder {
  549. struct obs_weak_ref ref;
  550. struct obs_encoder *encoder;
  551. };
  552. struct encoder_callback {
  553. bool sent_first_packet;
  554. void (*new_packet)(void *param, struct encoder_packet *packet);
  555. void *param;
  556. };
  557. struct obs_encoder {
  558. struct obs_context_data context;
  559. struct obs_encoder_info info;
  560. struct obs_weak_encoder *control;
  561. uint32_t samplerate;
  562. size_t planes;
  563. size_t blocksize;
  564. size_t framesize;
  565. size_t framesize_bytes;
  566. size_t mixer_idx;
  567. uint32_t scaled_width;
  568. uint32_t scaled_height;
  569. enum video_format preferred_format;
  570. bool active;
  571. /* indicates ownership of the info.id buffer */
  572. bool owns_info_id;
  573. uint32_t timebase_num;
  574. uint32_t timebase_den;
  575. int64_t cur_pts;
  576. struct circlebuf audio_input_buffer[MAX_AV_PLANES];
  577. uint8_t *audio_output_buffer[MAX_AV_PLANES];
  578. /* if a video encoder is paired with an audio encoder, make it start
  579. * up at the specific timestamp. if this is the audio encoder,
  580. * wait_for_video makes it wait until it's ready to sync up with
  581. * video */
  582. bool wait_for_video;
  583. struct obs_encoder *paired_encoder;
  584. uint64_t start_ts;
  585. pthread_mutex_t outputs_mutex;
  586. DARRAY(obs_output_t*) outputs;
  587. bool destroy_on_stop;
  588. /* stores the video/audio media output pointer. video_t *or audio_t **/
  589. void *media;
  590. pthread_mutex_t callbacks_mutex;
  591. DARRAY(struct encoder_callback) callbacks;
  592. const char *profile_encoder_encode_name;
  593. };
  594. extern struct obs_encoder_info *find_encoder(const char *id);
  595. extern bool obs_encoder_initialize(obs_encoder_t *encoder);
  596. extern void obs_encoder_shutdown(obs_encoder_t *encoder);
  597. extern void obs_encoder_start(obs_encoder_t *encoder,
  598. void (*new_packet)(void *param, struct encoder_packet *packet),
  599. void *param);
  600. extern void obs_encoder_stop(obs_encoder_t *encoder,
  601. void (*new_packet)(void *param, struct encoder_packet *packet),
  602. void *param);
  603. extern void obs_encoder_add_output(struct obs_encoder *encoder,
  604. struct obs_output *output);
  605. extern void obs_encoder_remove_output(struct obs_encoder *encoder,
  606. struct obs_output *output);
  607. void obs_encoder_destroy(obs_encoder_t *encoder);
  608. /* ------------------------------------------------------------------------- */
  609. /* services */
  610. struct obs_weak_service {
  611. struct obs_weak_ref ref;
  612. struct obs_service *service;
  613. };
  614. struct obs_service {
  615. struct obs_context_data context;
  616. struct obs_service_info info;
  617. struct obs_weak_service *control;
  618. /* indicates ownership of the info.id buffer */
  619. bool owns_info_id;
  620. bool active;
  621. bool destroy;
  622. struct obs_output *output;
  623. };
  624. extern const struct obs_service_info *find_service(const char *id);
  625. extern void obs_service_activate(struct obs_service *service);
  626. extern void obs_service_deactivate(struct obs_service *service, bool remove);
  627. extern bool obs_service_initialize(struct obs_service *service,
  628. struct obs_output *output);
  629. void obs_service_destroy(obs_service_t *service);