diff --git a/include/media_stream.hh b/include/media_stream.hh index 9242479..09b83a7 100644 --- a/include/media_stream.hh +++ b/include/media_stream.hh @@ -107,15 +107,12 @@ namespace uvg_rtp { rtp_error_t install_notify_hook(void *arg, void (*hook)(void *, int)); /* Configure the media stream in various ways - * The first version takes a configuration flag and value for that configuration (f.ex. UDP buffer size) - * The second version only takes a flag that enables some functionality (f.ex. SCD) * * See utils.hh for more details * * Return RTP_OK on success * Return RTP_INVALID_VALUE if "flag" is not recognized or "value" is invalid */ rtp_error_t configure_ctx(int flag, ssize_t value); - rtp_error_t configure_ctx(int flag); /* Setter and getter for media-specific config that can be used f.ex with Opus */ void set_media_config(void *config); diff --git a/include/queue.hh b/include/queue.hh index 8510d85..8c4a749 100644 --- a/include/queue.hh +++ b/include/queue.hh @@ -96,8 +96,8 @@ namespace uvg_rtp { class frame_queue { public: - frame_queue(rtp_format_t fmt, rtp_ctx_conf_t& conf); - frame_queue(rtp_format_t fmt, rtp_ctx_conf_t& conf, uvg_rtp::dispatcher *dispatcher); + frame_queue(rtp_format_t fmt); + frame_queue(rtp_format_t fmt, uvg_rtp::dispatcher *dispatcher); ~frame_queue(); rtp_error_t init_transaction(uvg_rtp::sender *sender); diff --git a/include/util.hh b/include/util.hh index 4b09588..4bd90ca 100644 --- a/include/util.hh +++ b/include/util.hh @@ -160,39 +160,7 @@ enum RTP_CTX_ENABLE_FLAGS { /* These options are given to configuration() */ enum RTP_CTX_CONFIGURATION_FLAGS { /* No configuration flags */ - RCC_NO_FLAGS = 0, - - /* How many packets can be fit into - * probation zone until they overflow to separate frames. - * - * By default, probation zone is disabled - * - * NOTE: how many **packets**, not bytes */ - RCC_PROBATION_ZONE_SIZE = 1, - - /* How many transactions can be cached for later use - * Caching transactions improves performance by reducing - * the number of (de)allocations but increases the memory - * footprint of the program - * - * By default, 10 transactions are cached */ - RCC_MAX_TRANSACTIONS = 2, - - /* How many UDP packets does one transaction object hold. - * - * uvgRTP splits one input frame [argument of push_frame()] into - * multiple UDP packets, each of size 1500 bytes. This UDP packets - * are stored into a transaction object. - * - * Video with high bitrate may require large value for "RCC_MAX_MESSAGES" - * - * By default, it is set to 500 (ie. one frame can take up to 500 * 1500 bytes) */ - RCC_MAX_MESSAGES = 3, - - /* How many chunks each UDP packet can at most contain - * - * By default, this is set to 4 */ - RCC_MAX_CHUNKS_PER_MSG = 4, + RCC_NO_FLAGS = 0, /* How large is the receiver/sender UDP buffer size * @@ -200,7 +168,8 @@ enum RTP_CTX_CONFIGURATION_FLAGS { * * For video with high bitrate, it is advisable to set this * to a high number to prevent OS from dropping packets */ - RCC_UDP_BUF_SIZE = 5, + RCC_UDP_RCV_BUF_SIZE = 1, + RCC_UDP_SND_BUF_SIZE = 2, RCC_LAST }; diff --git a/src/media_stream.cc b/src/media_stream.cc index ba7ad52..430420f 100644 --- a/src/media_stream.cc +++ b/src/media_stream.cc @@ -199,22 +199,34 @@ void *uvg_rtp::media_stream::get_media_config() rtp_error_t uvg_rtp::media_stream::configure_ctx(int flag, ssize_t value) { - if (flag < 0 || flag >= RCC_LAST || value < 0) - return RTP_INVALID_VALUE; + rtp_error_t ret = RTP_OK; - ctx_config_.ctx_values[flag] = value; + switch (flag) { + case RCC_UDP_SND_BUF_SIZE: { + if (value <= 0) + return RTP_INVALID_VALUE; - return RTP_OK; -} + int buf_size = value; + if ((ret = socket_.setsockopt(SOL_SOCKET, SO_SNDBUF, (const char *)&buf_size, sizeof(int))) != RTP_OK) + return ret; + } + break; -rtp_error_t uvg_rtp::media_stream::configure_ctx(int flag) -{ - if (flag < 0 || flag >= RCE_LAST) - return RTP_INVALID_VALUE; + case RCC_UDP_RCV_BUF_SIZE: { + if (value <= 0) + return RTP_INVALID_VALUE; - ctx_config_.flags |= flag; + int buf_size = value; + if ((ret = socket_.setsockopt(SOL_SOCKET, SO_RCVBUF, (const char *)&buf_size, sizeof(int))) != RTP_OK) + return ret; + } + break; - return RTP_OK; + default: + return RTP_INVALID_VALUE; + } + + return ret; } uint32_t uvg_rtp::media_stream::get_key() diff --git a/src/queue.cc b/src/queue.cc index cc50e37..3f30d4e 100644 --- a/src/queue.cc +++ b/src/queue.cc @@ -15,30 +15,19 @@ #include "formats/hevc.hh" -uvg_rtp::frame_queue::frame_queue(rtp_format_t fmt, rtp_ctx_conf_t& conf): +uvg_rtp::frame_queue::frame_queue(rtp_format_t fmt): active_(nullptr), fmt_(fmt), dealloc_hook_(nullptr) { active_ = nullptr; dispatcher_ = nullptr; - max_queued_ = conf.ctx_values[RCC_MAX_TRANSACTIONS]; - max_mcount_ = conf.ctx_values[RCC_MAX_MESSAGES]; - max_ccount_ = conf.ctx_values[RCC_MAX_CHUNKS_PER_MSG] * max_mcount_; - - if (max_queued_ <= 0) - max_queued_ = MAX_QUEUED_MSGS; - - if (max_mcount_ <= 0) - max_mcount_ = MAX_MSG_COUNT; - - if (max_ccount_ <= 0) - max_ccount_ = MAX_CHUNK_COUNT * max_mcount_; - - free_.reserve(max_queued_); + max_queued_ = MAX_QUEUED_MSGS; + max_mcount_ = MAX_MSG_COUNT; + max_ccount_ = MAX_CHUNK_COUNT * max_mcount_; } -uvg_rtp::frame_queue::frame_queue(rtp_format_t fmt, rtp_ctx_conf_t& conf, uvg_rtp::dispatcher *dispatcher): - frame_queue(fmt, conf) +uvg_rtp::frame_queue::frame_queue(rtp_format_t fmt, uvg_rtp::dispatcher *dispatcher): + frame_queue(fmt) { dispatcher_ = dispatcher; } diff --git a/src/receiver.cc b/src/receiver.cc index 298b65c..8031921 100644 --- a/src/receiver.cc +++ b/src/receiver.cc @@ -39,10 +39,7 @@ rtp_error_t uvg_rtp::receiver::stop() rtp_error_t uvg_rtp::receiver::start() { rtp_error_t ret = RTP_OK; - ssize_t buf_size = conf_.ctx_values[RCC_UDP_BUF_SIZE]; - - if (buf_size <= 0) - buf_size = 4 * 1000 * 1000; + ssize_t buf_size = 4 * 1000 * 1000; if ((ret = socket_.setsockopt(SOL_SOCKET, SO_RCVBUF, (const char *)&buf_size, sizeof(int))) != RTP_OK) return ret; diff --git a/src/sender.cc b/src/sender.cc index dfa1d2e..5459f61 100644 --- a/src/sender.cc +++ b/src/sender.cc @@ -50,10 +50,7 @@ rtp_error_t uvg_rtp::sender::destroy() rtp_error_t uvg_rtp::sender::init() { rtp_error_t ret = RTP_OK; - ssize_t buf_size = conf_.ctx_values[RCC_UDP_BUF_SIZE]; - - if (buf_size <= 0) - buf_size = 4 * 1000 * 1000; + ssize_t buf_size = 4 * 1000 * 1000; if ((ret = socket_.setsockopt(SOL_SOCKET, SO_SNDBUF, (const char *)&buf_size, sizeof(int))) != RTP_OK) return ret; @@ -61,13 +58,13 @@ rtp_error_t uvg_rtp::sender::init() #ifndef _WIN32 if (fmt_ == RTP_FORMAT_HEVC && conf_.flags & RCE_SYSTEM_CALL_DISPATCHER) { dispatcher_ = new uvg_rtp::dispatcher(&socket_); - fqueue_ = new uvg_rtp::frame_queue(fmt_, conf_, dispatcher_); + fqueue_ = new uvg_rtp::frame_queue(fmt_, dispatcher_); if (dispatcher_) dispatcher_->start(); } else { #endif - fqueue_ = new uvg_rtp::frame_queue(fmt_, conf_); + fqueue_ = new uvg_rtp::frame_queue(fmt_); dispatcher_ = nullptr; #ifndef _WIN32 }