obs-ffmpeg-mux.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /* these are accessed both by replay buffer and by HLS */
  41. pthread_t mux_thread;
  42. bool mux_thread_joinable;
  43. struct circlebuf packets;
  44. /* HLS only */
  45. int keyint_sec;
  46. pthread_mutex_t write_mutex;
  47. os_sem_t *write_sem;
  48. os_event_t *stop_event;
  49. bool is_hls;
  50. int dropped_frames;
  51. int min_priority;
  52. int64_t last_dts_usec;
  53. bool is_network;
  54. bool split_file;
  55. bool reset_timestamps;
  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);