rtmp-stream.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <obs-module.h>
  2. #include <obs-avc.h>
  3. #include <util/platform.h>
  4. #include <util/circlebuf.h>
  5. #include <util/dstr.h>
  6. #include <util/threading.h>
  7. #include <inttypes.h>
  8. #include "librtmp/rtmp.h"
  9. #include "librtmp/log.h"
  10. #include "flv-mux.h"
  11. #include "net-if.h"
  12. #ifdef _WIN32
  13. #include <Iphlpapi.h>
  14. #else
  15. #include <sys/ioctl.h>
  16. #endif
  17. #define do_log(level, format, ...) \
  18. blog(level, "[rtmp stream: '%s'] " format, \
  19. obs_output_get_name(stream->output), ##__VA_ARGS__)
  20. #define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
  21. #define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
  22. #define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
  23. #define OPT_DROP_THRESHOLD "drop_threshold_ms"
  24. #define OPT_PFRAME_DROP_THRESHOLD "pframe_drop_threshold_ms"
  25. #define OPT_MAX_SHUTDOWN_TIME_SEC "max_shutdown_time_sec"
  26. #define OPT_BIND_IP "bind_ip"
  27. #define OPT_NEWSOCKETLOOP_ENABLED "new_socket_loop_enabled"
  28. #define OPT_LOWLATENCY_ENABLED "low_latency_mode_enabled"
  29. //#define TEST_FRAMEDROPS
  30. #ifdef TEST_FRAMEDROPS
  31. #define DROPTEST_MAX_KBPS 3000
  32. #define DROPTEST_MAX_BYTES (DROPTEST_MAX_KBPS * 1000 / 8)
  33. struct droptest_info {
  34. uint64_t ts;
  35. size_t size;
  36. };
  37. #endif
  38. struct rtmp_stream {
  39. obs_output_t *output;
  40. pthread_mutex_t packets_mutex;
  41. struct circlebuf packets;
  42. bool sent_headers;
  43. volatile bool connecting;
  44. pthread_t connect_thread;
  45. volatile bool active;
  46. volatile bool disconnected;
  47. pthread_t send_thread;
  48. int max_shutdown_time_sec;
  49. os_sem_t *send_sem;
  50. os_event_t *stop_event;
  51. uint64_t stop_ts;
  52. uint64_t shutdown_timeout_ts;
  53. struct dstr path, key;
  54. struct dstr username, password;
  55. struct dstr encoder_name;
  56. struct dstr bind_ip;
  57. /* frame drop variables */
  58. int64_t drop_threshold_usec;
  59. int64_t min_drop_dts_usec;
  60. int64_t pframe_drop_threshold_usec;
  61. int64_t pframe_min_drop_dts_usec;
  62. int min_priority;
  63. float congestion;
  64. int64_t last_dts_usec;
  65. uint64_t total_bytes_sent;
  66. int dropped_frames;
  67. #ifdef TEST_FRAMEDROPS
  68. struct circlebuf droptest_info;
  69. size_t droptest_size;
  70. #endif
  71. RTMP rtmp;
  72. bool new_socket_loop;
  73. bool low_latency_mode;
  74. bool disable_send_window_optimization;
  75. bool socket_thread_active;
  76. pthread_t socket_thread;
  77. uint8_t *write_buf;
  78. size_t write_buf_len;
  79. size_t write_buf_size;
  80. pthread_mutex_t write_buf_mutex;
  81. os_event_t *buffer_space_available_event;
  82. os_event_t *buffer_has_data_event;
  83. os_event_t *socket_available_event;
  84. os_event_t *send_thread_signaled_exit;
  85. };
  86. #ifdef _WIN32
  87. void *socket_thread_windows(void *data);
  88. #endif