obs-ffmpeg-mux.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. #include <obs-avc.h>
  3. #include <obs-module.h>
  4. #include <obs-hotkey.h>
  5. #include <util/circlebuf.h>
  6. #include <util/darray.h>
  7. #include <util/dstr.h>
  8. #include <util/pipe.h>
  9. #include <util/platform.h>
  10. #include <util/threading.h>
  11. struct ffmpeg_muxer {
  12. obs_output_t *output;
  13. os_process_pipe_t *pipe;
  14. int64_t stop_ts;
  15. uint64_t total_bytes;
  16. bool sent_headers;
  17. volatile bool active;
  18. volatile bool capturing;
  19. volatile bool stopping;
  20. struct dstr path;
  21. struct dstr printable_path;
  22. struct dstr muxer_settings;
  23. struct dstr stream_key;
  24. /* replay buffer and split file */
  25. int64_t cur_size;
  26. int64_t cur_time;
  27. int64_t max_size;
  28. int64_t max_time;
  29. /* replay buffer */
  30. int64_t save_ts;
  31. int keyframes;
  32. obs_hotkey_id hotkey;
  33. volatile bool muxing;
  34. DARRAY(struct encoder_packet) mux_packets;
  35. /* split file */
  36. bool found_video;
  37. bool found_audio[MAX_AUDIO_MIXES];
  38. int64_t video_pts_offset;
  39. int64_t audio_dts_offsets[MAX_AUDIO_MIXES];
  40. bool split_file_ready;
  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 reset_timestamps;
  57. bool allow_overwrite;
  58. };
  59. bool stopping(struct ffmpeg_muxer *stream);
  60. bool active(struct ffmpeg_muxer *stream);
  61. void start_pipe(struct ffmpeg_muxer *stream, const char *path);
  62. bool write_packet(struct ffmpeg_muxer *stream, struct encoder_packet *packet);
  63. bool send_headers(struct ffmpeg_muxer *stream);
  64. int deactivate(struct ffmpeg_muxer *stream, int code);
  65. void ffmpeg_mux_stop(void *data, uint64_t ts);
  66. uint64_t ffmpeg_mux_total_bytes(void *data);