obs-internal.h 26 KB

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