obs-ffmpeg-mux.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 */
  25. int64_t cur_size;
  26. int64_t cur_time;
  27. int64_t max_size;
  28. int64_t max_time;
  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. /* these are accessed both by replay buffer and by HLS */
  35. pthread_t mux_thread;
  36. bool mux_thread_joinable;
  37. struct circlebuf packets;
  38. /* HLS only */
  39. int keyint_sec;
  40. pthread_mutex_t write_mutex;
  41. os_sem_t *write_sem;
  42. os_event_t *stop_event;
  43. bool is_hls;
  44. int dropped_frames;
  45. int min_priority;
  46. int64_t last_dts_usec;
  47. bool is_network;
  48. };
  49. bool stopping(struct ffmpeg_muxer *stream);
  50. bool active(struct ffmpeg_muxer *stream);
  51. void start_pipe(struct ffmpeg_muxer *stream, const char *path);
  52. bool write_packet(struct ffmpeg_muxer *stream, struct encoder_packet *packet);
  53. bool send_headers(struct ffmpeg_muxer *stream);
  54. int deactivate(struct ffmpeg_muxer *stream, int code);
  55. void ffmpeg_mux_stop(void *data, uint64_t ts);
  56. uint64_t ffmpeg_mux_total_bytes(void *data);