obs-internal.h 26 KB

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