Implement RCC_PKT_MAX_DELAY
This commit is contained in:
parent
755fe99d88
commit
ca66f6f8dc
|
@ -62,6 +62,7 @@ namespace uvg_rtp {
|
|||
std::deque<uvg_rtp::frame::rtp_frame *> queued;
|
||||
std::unordered_map<uint32_t, h265_info_t> frames;
|
||||
std::unordered_set<uint32_t> dropped;
|
||||
uvg_rtp::rtp *rtp_ctx;
|
||||
} h265_frame_info_t;
|
||||
|
||||
class h265 : public h26x {
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace uvg_rtp {
|
|||
uint16_t get_sequence();
|
||||
uint32_t get_clock_rate();
|
||||
size_t get_payload_size();
|
||||
size_t get_pkt_max_delay();
|
||||
rtp_format_t get_payload();
|
||||
|
||||
void inc_sent_pkts();
|
||||
|
@ -26,6 +27,7 @@ namespace uvg_rtp {
|
|||
void set_dynamic_payload(uint8_t payload);
|
||||
void set_timestamp(uint64_t timestamp);
|
||||
void set_payload_size(size_t payload_size);
|
||||
void set_pkt_max_delay(size_t delay);
|
||||
|
||||
void fill_header(uint8_t *buffer);
|
||||
void update_sequence(uint8_t *buffer);
|
||||
|
@ -55,6 +57,13 @@ namespace uvg_rtp {
|
|||
* By default, the value is set to 1443
|
||||
* (maximum amount of payload bytes when MTU is 1500) */
|
||||
size_t payload_size_;
|
||||
|
||||
/* What is the maximum delay allowed for each frame
|
||||
* i.e. how long does the packet receiver wait for
|
||||
* all fragments of a frame until it's considered late and dropped
|
||||
*
|
||||
* Default value is 100ms */
|
||||
size_t delay_;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ typedef SSIZE_T ssize_t;
|
|||
|
||||
const int MAX_PACKET = 65536;
|
||||
const int MAX_PAYLOAD = 1443;
|
||||
const int PKT_MAX_DELAY = 100;
|
||||
|
||||
typedef enum RTP_ERROR {
|
||||
RTP_MULTIPLE_PKTS_READY = 6, /* multiple packets can be queried from the layer */
|
||||
|
@ -208,6 +209,14 @@ enum RTP_CTX_CONFIGURATION_FLAGS {
|
|||
RCC_UDP_RCV_BUF_SIZE = 1,
|
||||
RCC_UDP_SND_BUF_SIZE = 2,
|
||||
|
||||
/* How many milliseconds is each frame waited until it's dropped
|
||||
*
|
||||
* Default is 100 milliseconds
|
||||
*
|
||||
* This is valid only for fragmented frames,
|
||||
* i.e. RTP_FORMAT_H26X and RTP_FORMAT_GENERIC with RCE_FRAGMENT_GENERIC (TODO) */
|
||||
RCC_PKT_MAX_DELAY = 3,
|
||||
|
||||
RCC_LAST
|
||||
};
|
||||
|
||||
|
|
|
@ -182,6 +182,7 @@ rtp_error_t uvg_rtp::formats::h265::push_nal_unit(uint8_t *data, size_t data_len
|
|||
uvg_rtp::formats::h265::h265(uvg_rtp::socket *socket, uvg_rtp::rtp *rtp, int flags):
|
||||
h26x(socket, rtp, flags), finfo_{}
|
||||
{
|
||||
finfo_.rtp_ctx = rtp;
|
||||
}
|
||||
|
||||
uvg_rtp::formats::h265::~h265()
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
#include "formats/h265.hh"
|
||||
|
||||
#define RTP_FRAME_MAX_DELAY 100
|
||||
#define INVALID_SEQ 0x13371338
|
||||
#define INVALID_TS 0xffffffff
|
||||
|
||||
|
@ -65,9 +64,9 @@ static inline uint8_t __get_nal(uvg_rtp::frame::rtp_frame *frame)
|
|||
return NT_OTHER;
|
||||
}
|
||||
|
||||
static inline bool __frame_late(uvg_rtp::formats::h265_info_t& hinfo)
|
||||
static inline bool __frame_late(uvg_rtp::formats::h265_info_t& hinfo, size_t max_delay)
|
||||
{
|
||||
return (uvg_rtp::clock::hrc::diff_now(hinfo.sframe_time) >= RTP_FRAME_MAX_DELAY);
|
||||
return (uvg_rtp::clock::hrc::diff_now(hinfo.sframe_time) >= max_delay);
|
||||
}
|
||||
|
||||
static void __drop_frame(uvg_rtp::formats::h265_frame_info_t *finfo, uint32_t ts)
|
||||
|
@ -326,7 +325,7 @@ rtp_error_t uvg_rtp::formats::h265::packet_handler(void *arg, int flags, uvg_rtp
|
|||
}
|
||||
}
|
||||
|
||||
if (__frame_late(finfo->frames.at(c_ts))) {
|
||||
if (__frame_late(finfo->frames.at(c_ts), finfo->rtp_ctx->get_pkt_max_delay())) {
|
||||
if (nal_type != NT_INTRA || (nal_type == NT_INTRA && !enable_idelay)) {
|
||||
__drop_frame(finfo, c_ts);
|
||||
finfo->dropped.insert(c_ts);
|
||||
|
|
|
@ -609,6 +609,14 @@ rtp_error_t uvg_rtp::media_stream::configure_ctx(int flag, ssize_t value)
|
|||
}
|
||||
break;
|
||||
|
||||
case RCC_PKT_MAX_DELAY: {
|
||||
if (value <= 0)
|
||||
return RTP_INVALID_VALUE;
|
||||
|
||||
rtp_->set_pkt_max_delay(value);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return RTP_INVALID_VALUE;
|
||||
}
|
||||
|
|
13
src/rtp.cc
13
src/rtp.cc
|
@ -16,7 +16,8 @@ uvg_rtp::rtp::rtp(rtp_format_t fmt):
|
|||
wc_start_(0),
|
||||
sent_pkts_(0),
|
||||
timestamp_(INVALID_TS),
|
||||
payload_size_(MAX_PAYLOAD)
|
||||
payload_size_(MAX_PAYLOAD),
|
||||
delay_(PKT_MAX_DELAY)
|
||||
{
|
||||
seq_ = uvg_rtp::random::generate_32() & 0xffff;
|
||||
ts_ = uvg_rtp::random::generate_32();
|
||||
|
@ -140,6 +141,16 @@ rtp_format_t uvg_rtp::rtp::get_payload()
|
|||
return (rtp_format_t)fmt_;
|
||||
}
|
||||
|
||||
void uvg_rtp::rtp::set_pkt_max_delay(size_t delay)
|
||||
{
|
||||
delay_ = delay;
|
||||
}
|
||||
|
||||
size_t uvg_rtp::rtp::get_pkt_max_delay()
|
||||
{
|
||||
return delay_;
|
||||
}
|
||||
|
||||
rtp_error_t uvg_rtp::rtp::packet_handler(ssize_t size, void *packet, int flags, uvg_rtp::frame::rtp_frame **out)
|
||||
{
|
||||
(void)flags;
|
||||
|
|
Loading…
Reference in New Issue