yolobs-studio/plugins/obs-outputs/rtmp-stream.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

136 lines
3 KiB
C
Raw Permalink Normal View History

2017-04-19 19:54:15 +00:00
#include <obs-module.h>
#include <obs-avc.h>
#include <util/platform.h>
#include <util/circlebuf.h>
#include <util/dstr.h>
#include <util/threading.h>
#include <inttypes.h>
#include "librtmp/rtmp.h"
#include "librtmp/log.h"
#include "flv-mux.h"
#include "net-if.h"
#ifdef _WIN32
#include <Iphlpapi.h>
#else
#include <sys/ioctl.h>
#endif
2019-09-22 21:19:10 +00:00
#define do_log(level, format, ...) \
2017-04-19 19:54:15 +00:00
blog(level, "[rtmp stream: '%s'] " format, \
2019-09-22 21:19:10 +00:00
obs_output_get_name(stream->output), ##__VA_ARGS__)
2017-04-19 19:54:15 +00:00
2019-09-22 21:19:10 +00:00
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
2017-04-19 19:54:15 +00:00
2019-09-22 21:19:10 +00:00
#define OPT_DYN_BITRATE "dyn_bitrate"
2017-04-19 19:54:15 +00:00
#define OPT_DROP_THRESHOLD "drop_threshold_ms"
#define OPT_PFRAME_DROP_THRESHOLD "pframe_drop_threshold_ms"
#define OPT_MAX_SHUTDOWN_TIME_SEC "max_shutdown_time_sec"
#define OPT_BIND_IP "bind_ip"
#define OPT_NEWSOCKETLOOP_ENABLED "new_socket_loop_enabled"
#define OPT_LOWLATENCY_ENABLED "low_latency_mode_enabled"
2020-10-01 20:15:25 +00:00
#define OPT_METADATA_MULTITRACK "metadata_multitrack"
2017-04-19 19:54:15 +00:00
//#define TEST_FRAMEDROPS
2019-09-22 21:19:10 +00:00
//#define TEST_FRAMEDROPS_WITH_BITRATE_SHORTCUTS
2017-04-19 19:54:15 +00:00
#ifdef TEST_FRAMEDROPS
#define DROPTEST_MAX_KBPS 3000
#define DROPTEST_MAX_BYTES (DROPTEST_MAX_KBPS * 1000 / 8)
struct droptest_info {
uint64_t ts;
size_t size;
};
#endif
2019-09-22 21:19:10 +00:00
struct dbr_frame {
uint64_t send_beg;
uint64_t send_end;
size_t size;
};
2017-04-19 19:54:15 +00:00
struct rtmp_stream {
2019-09-22 21:19:10 +00:00
obs_output_t *output;
2017-04-19 19:54:15 +00:00
2019-09-22 21:19:10 +00:00
pthread_mutex_t packets_mutex;
2017-04-19 19:54:15 +00:00
struct circlebuf packets;
2019-09-22 21:19:10 +00:00
bool sent_headers;
2017-04-19 19:54:15 +00:00
2019-09-22 21:19:10 +00:00
bool got_first_video;
int64_t start_dts_offset;
2018-02-19 19:54:37 +00:00
2019-09-22 21:19:10 +00:00
volatile bool connecting;
pthread_t connect_thread;
2017-04-19 19:54:15 +00:00
2019-09-22 21:19:10 +00:00
volatile bool active;
volatile bool disconnected;
volatile bool encode_error;
pthread_t send_thread;
2017-04-19 19:54:15 +00:00
2019-09-22 21:19:10 +00:00
int max_shutdown_time_sec;
2017-04-19 19:54:15 +00:00
2019-09-22 21:19:10 +00:00
os_sem_t *send_sem;
os_event_t *stop_event;
uint64_t stop_ts;
uint64_t shutdown_timeout_ts;
2017-04-19 19:54:15 +00:00
2019-09-22 21:19:10 +00:00
struct dstr path, key;
struct dstr username, password;
struct dstr encoder_name;
struct dstr bind_ip;
2017-04-19 19:54:15 +00:00
/* frame drop variables */
2019-09-22 21:19:10 +00:00
int64_t drop_threshold_usec;
int64_t pframe_drop_threshold_usec;
int min_priority;
float congestion;
2017-04-19 19:54:15 +00:00
2019-09-22 21:19:10 +00:00
int64_t last_dts_usec;
2017-04-19 19:54:15 +00:00
2019-09-22 21:19:10 +00:00
uint64_t total_bytes_sent;
int dropped_frames;
2017-04-19 19:54:15 +00:00
#ifdef TEST_FRAMEDROPS
struct circlebuf droptest_info;
2019-09-22 21:19:10 +00:00
uint64_t droptest_last_key_check;
size_t droptest_max;
size_t droptest_size;
2017-04-19 19:54:15 +00:00
#endif
2019-09-22 21:19:10 +00:00
pthread_mutex_t dbr_mutex;
struct circlebuf dbr_frames;
size_t dbr_data_size;
uint64_t dbr_inc_timeout;
long audio_bitrate;
long dbr_est_bitrate;
long dbr_orig_bitrate;
long dbr_prev_bitrate;
long dbr_cur_bitrate;
long dbr_inc_bitrate;
bool dbr_enabled;
RTMP rtmp;
bool new_socket_loop;
bool low_latency_mode;
bool disable_send_window_optimization;
bool socket_thread_active;
pthread_t socket_thread;
uint8_t *write_buf;
size_t write_buf_len;
size_t write_buf_size;
pthread_mutex_t write_buf_mutex;
os_event_t *buffer_space_available_event;
os_event_t *buffer_has_data_event;
os_event_t *socket_available_event;
os_event_t *send_thread_signaled_exit;
2017-04-19 19:54:15 +00:00
};
#ifdef _WIN32
void *socket_thread_windows(void *data);
#endif