obs-ffmpeg-mux.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #include <obs-module.h>
  3. #include <obs-hotkey.h>
  4. #include <util/circlebuf.h>
  5. #include <util/darray.h>
  6. #include <util/dstr.h>
  7. #include <util/pipe.h>
  8. #include <util/platform.h>
  9. #include <util/threading.h>
  10. struct ffmpeg_muxer {
  11. obs_output_t *output;
  12. os_process_pipe_t *pipe;
  13. int64_t stop_ts;
  14. uint64_t total_bytes;
  15. bool sent_headers;
  16. volatile bool active;
  17. volatile bool capturing;
  18. volatile bool stopping;
  19. struct dstr path;
  20. struct dstr printable_path;
  21. struct dstr muxer_settings;
  22. struct dstr stream_key;
  23. /* replay buffer and split file */
  24. int64_t cur_size;
  25. int64_t cur_time;
  26. int64_t max_size;
  27. int64_t max_time;
  28. /* replay buffer */
  29. int64_t save_ts;
  30. int keyframes;
  31. obs_hotkey_id hotkey;
  32. volatile bool muxing;
  33. DARRAY(struct encoder_packet) mux_packets;
  34. /* split file */
  35. bool found_video;
  36. bool found_audio[MAX_AUDIO_MIXES];
  37. int64_t video_pts_offset;
  38. int64_t audio_dts_offsets[MAX_AUDIO_MIXES];
  39. bool split_file_ready;
  40. volatile bool manual_split;
  41. /* these are accessed both by replay buffer and by HLS */
  42. pthread_t mux_thread;
  43. bool mux_thread_joinable;
  44. struct circlebuf packets;
  45. /* HLS only */
  46. int keyint_sec;
  47. pthread_mutex_t write_mutex;
  48. os_sem_t *write_sem;
  49. os_event_t *stop_event;
  50. bool is_hls;
  51. int dropped_frames;
  52. int min_priority;
  53. int64_t last_dts_usec;
  54. bool is_network;
  55. bool split_file;
  56. bool allow_overwrite;
  57. };
  58. bool stopping(struct ffmpeg_muxer *stream);
  59. bool active(struct ffmpeg_muxer *stream);
  60. void start_pipe(struct ffmpeg_muxer *stream, const char *path);
  61. bool write_packet(struct ffmpeg_muxer *stream, struct encoder_packet *packet);
  62. bool send_headers(struct ffmpeg_muxer *stream);
  63. int deactivate(struct ffmpeg_muxer *stream, int code);
  64. void ffmpeg_mux_stop(void *data, uint64_t ts);
  65. uint64_t ffmpeg_mux_total_bytes(void *data);