common: Remove most MSVC compiler warnings
This commit is contained in:
parent
c4f89cf7b5
commit
f915b2aa17
|
@ -15,26 +15,6 @@
|
|||
|
||||
namespace uvgrtp {
|
||||
namespace frame {
|
||||
enum HEADER_SIZES {
|
||||
HEADER_SIZE_RTP = 12,
|
||||
HEADER_SIZE_OPUS = 1,
|
||||
HEADER_SIZE_H264_INDICATOR = 1,
|
||||
HEADER_SIZE_H264_NAL = 1,
|
||||
HEADER_SIZE_H264_FU = 1,
|
||||
HEADER_SIZE_H265_PAYLOAD = 2,
|
||||
HEADER_SIZE_H265_NAL = 2,
|
||||
HEADER_SIZE_H265_FU = 1,
|
||||
HEADER_SIZE_H266_PAYLOAD = 2,
|
||||
HEADER_SIZE_H266_NAL = 2,
|
||||
HEADER_SIZE_H266_FU = 1,
|
||||
};
|
||||
|
||||
enum RTP_FRAME_TYPE {
|
||||
RTP_FT_GENERIC = 0, /* payload length + RTP Header size (N + 12) */
|
||||
RTP_FT_OPUS = 1, /* payload length + RTP Header size + Opus header (N + 12 + 0 [for now]) */
|
||||
RTP_FT_H265_FU = 2, /* payload length + RTP Header size + HEVC NAL Header + FU Header (N + 12 + 2 + 1) */
|
||||
RTP_FT_H266_FU = 2, /* payload length + RTP Header size + HEVC NAL Header + FU Header (N + 12 + 2 + 1) */
|
||||
};
|
||||
|
||||
enum RTCP_FRAME_TYPE {
|
||||
RTCP_FT_SR = 200, /* Sender report */
|
||||
|
@ -65,7 +45,7 @@ namespace uvgrtp {
|
|||
struct rtp_frame {
|
||||
struct rtp_header header;
|
||||
uint32_t *csrc = nullptr;
|
||||
struct ext_header *ext;
|
||||
struct ext_header *ext = nullptr;
|
||||
|
||||
size_t padding_len = 0; /* non-zero if frame is padded */
|
||||
size_t payload_len = 0; /* payload_len: total_len - header_len - padding length (if padded) */
|
||||
|
@ -89,14 +69,14 @@ namespace uvgrtp {
|
|||
|
||||
rtp_format_t format = RTP_FORMAT_GENERIC;
|
||||
int type = 0;
|
||||
sockaddr_in src_addr;
|
||||
sockaddr_in src_addr = {};
|
||||
};
|
||||
|
||||
struct rtcp_header {
|
||||
uint8_t version = 0;
|
||||
uint8_t padding = 0;
|
||||
union {
|
||||
uint8_t count;
|
||||
uint8_t count = 0;
|
||||
uint8_t pkt_subtype; /* for app packets */
|
||||
};
|
||||
uint8_t pkt_type = 0;
|
||||
|
@ -153,7 +133,7 @@ namespace uvgrtp {
|
|||
struct rtcp_app_packet {
|
||||
struct rtcp_header header;
|
||||
uint32_t ssrc = 0;
|
||||
uint8_t name[4];
|
||||
uint8_t name[4] = {0};
|
||||
uint8_t *payload = nullptr;
|
||||
};
|
||||
|
||||
|
|
|
@ -40,8 +40,8 @@ namespace uvgrtp {
|
|||
class media_stream {
|
||||
public:
|
||||
/// \cond DO_NOT_DOCUMENT
|
||||
media_stream(std::string cname, std::string addr, int src_port, int dst_port, rtp_format_t fmt, int rce_flags);
|
||||
media_stream(std::string cname, std::string remote_addr, std::string local_addr, int src_port, int dst_port,
|
||||
media_stream(std::string cname, std::string addr, uint16_t src_port, uint16_t dst_port, rtp_format_t fmt, int rce_flags);
|
||||
media_stream(std::string cname, std::string remote_addr, std::string local_addr, uint16_t src_port, uint16_t dst_port,
|
||||
rtp_format_t fmt, int rce_flags);
|
||||
~media_stream();
|
||||
|
||||
|
@ -331,13 +331,12 @@ namespace uvgrtp {
|
|||
sockaddr_in remote_sockaddr_;
|
||||
std::string remote_address_;
|
||||
std::string local_address_;
|
||||
int src_port_;
|
||||
int dst_port_;
|
||||
uint16_t src_port_;
|
||||
uint16_t dst_port_;
|
||||
rtp_format_t fmt_;
|
||||
int rce_flags_;
|
||||
|
||||
/* Media context config */
|
||||
rtp_ctx_conf_t ctx_config_;
|
||||
int rce_flags_ = 0;
|
||||
|
||||
/* Media config f.ex. for Opus */
|
||||
void *media_config_;
|
||||
|
@ -360,8 +359,8 @@ namespace uvgrtp {
|
|||
|
||||
std::string cname_;
|
||||
|
||||
int fps_enumerator_ = 30;
|
||||
int fps_denominator_ = 1;
|
||||
ssize_t fps_enumerator_ = 30;
|
||||
ssize_t fps_denominator_ = 1;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace uvgrtp {
|
|||
|
||||
struct rtcp_participant {
|
||||
std::shared_ptr<uvgrtp::socket> socket = nullptr; /* socket associated with this participant */
|
||||
sockaddr_in address; /* address of the participant */
|
||||
sockaddr_in address = {}; /* address of the participant */
|
||||
struct receiver_statistics stats; /* RTCP session statistics of the participant */
|
||||
|
||||
uint32_t probation = 0; /* has the participant been fully accepted to the session */
|
||||
|
@ -76,13 +76,13 @@ namespace uvgrtp {
|
|||
|
||||
struct rtcp_app_packet {
|
||||
rtcp_app_packet(const rtcp_app_packet& orig_packet) = delete;
|
||||
rtcp_app_packet(const char* name, uint8_t subtype, size_t payload_len, const uint8_t* payload);
|
||||
rtcp_app_packet(const char* name, uint8_t subtype, uint32_t payload_len, const uint8_t* payload);
|
||||
~rtcp_app_packet();
|
||||
|
||||
const char* name;
|
||||
uint8_t subtype;
|
||||
|
||||
size_t payload_len;
|
||||
uint32_t payload_len;
|
||||
const uint8_t* payload;
|
||||
};
|
||||
|
||||
|
@ -147,7 +147,7 @@ namespace uvgrtp {
|
|||
* \retval RTP_MEMORY_ERROR If allocation fails
|
||||
* \retval RTP_GENERIC_ERROR If sending fails
|
||||
*/
|
||||
rtp_error_t send_app_packet(const char *name, uint8_t subtype, size_t payload_len, const uint8_t *payload);
|
||||
rtp_error_t send_app_packet(const char *name, uint8_t subtype, uint32_t payload_len, const uint8_t *payload);
|
||||
|
||||
/**
|
||||
* \brief Send an RTCP BYE packet
|
||||
|
@ -312,10 +312,10 @@ namespace uvgrtp {
|
|||
|
||||
rtp_error_t set_sdes_items(const std::vector<uvgrtp::frame::rtcp_sdes_item>& items);
|
||||
|
||||
size_t size_of_ready_app_packets() const;
|
||||
uint32_t size_of_ready_app_packets() const;
|
||||
|
||||
size_t size_of_compound_packet(uint16_t reports,
|
||||
bool sr_packet, bool rr_packet, bool sdes_packet, size_t app_size, bool bye_packet) const;
|
||||
uint32_t size_of_compound_packet(uint16_t reports,
|
||||
bool sr_packet, bool rr_packet, bool sdes_packet, uint32_t app_size, bool bye_packet) const;
|
||||
|
||||
/* read the header values from rtcp packet */
|
||||
void read_rtcp_header(const uint8_t* buffer, size_t& read_ptr,
|
||||
|
@ -386,7 +386,7 @@ namespace uvgrtp {
|
|||
void zero_stats(uvgrtp::receiver_statistics *stats);
|
||||
|
||||
/* Takes ownership of the frame */
|
||||
rtp_error_t send_rtcp_packet_to_participants(uint8_t* frame, size_t frame_size, bool encrypt);
|
||||
rtp_error_t send_rtcp_packet_to_participants(uint8_t* frame, uint32_t frame_size, bool encrypt);
|
||||
|
||||
void free_participant(rtcp_participant* participant);
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace uvgrtp {
|
|||
* \retval nullptr If RCE_SRTP is given but RCE_SRTP_KMNGMNT_* flag is not given
|
||||
* \retval nullptr If memory allocation failed
|
||||
*/
|
||||
uvgrtp::media_stream *create_stream(int src_port, int dst_port, rtp_format_t fmt, int rce_flags);
|
||||
uvgrtp::media_stream *create_stream(uint16_t src_port, uint16_t dst_port, rtp_format_t fmt, int rce_flags);
|
||||
|
||||
/**
|
||||
* \brief Destroy a media stream
|
||||
|
|
|
@ -38,6 +38,8 @@ const int MAX_PAYLOAD = 1446;
|
|||
const int PKT_MAX_DELAY = 500;
|
||||
|
||||
/* TODO: add ability for user to specify these? */
|
||||
|
||||
// TODO: IPv6 size is 40
|
||||
enum HEADER_SIZES {
|
||||
ETH_HDR_SIZE = 14,
|
||||
IPV4_HDR_SIZE = 20,
|
||||
|
@ -299,13 +301,6 @@ enum RTP_CTX_CONFIGURATION_FLAGS {
|
|||
RCC_LAST
|
||||
};
|
||||
|
||||
|
||||
/* see src/util.hh for more information */
|
||||
typedef struct rtp_ctx_conf {
|
||||
int rce_flags = 0;
|
||||
ssize_t ctx_values[RCC_LAST];
|
||||
} rtp_ctx_conf_t;
|
||||
|
||||
extern thread_local rtp_error_t rtp_errno;
|
||||
|
||||
#define TIME_DIFF(s, e, u) ((ssize_t)std::chrono::duration_cast<std::chrono::u>(e - s).count())
|
||||
|
|
19
src/clock.cc
19
src/clock.cc
|
@ -9,6 +9,11 @@ static const uint64_t NTP_SCALE_FRAC = 4294967296ULL;
|
|||
|
||||
static inline uint32_t ntp_diff_ms(uint64_t older, uint64_t newer)
|
||||
{
|
||||
if (older > newer)
|
||||
{
|
||||
UVG_LOG_ERROR("Older timestamp is actually newer");
|
||||
}
|
||||
|
||||
uint32_t s1 = (older >> 32) & 0xffffffff;
|
||||
uint32_t s2 = (newer >> 32) & 0xffffffff;
|
||||
uint64_t us1 = ((older & 0xffffffff) * 1000000UL) / NTP_SCALE_FRAC;
|
||||
|
@ -93,10 +98,20 @@ uint64_t uvgrtp::clock::jiffies_to_ms(uint64_t jiffies)
|
|||
#ifdef _WIN32
|
||||
int uvgrtp::clock::gettimeofday(struct timeval * tp, struct timezone * tzp)
|
||||
{
|
||||
if (tzp != nullptr)
|
||||
{
|
||||
UVG_LOG_ERROR("Timezone not supported");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/10905892/equivalent-of-gettimeday-for-windows
|
||||
|
||||
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
|
||||
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
|
||||
// until 00:00:00 January 1, 1970
|
||||
static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
|
||||
static const uint64_t epoch = ((uint64_t) 116444736000000000ULL);
|
||||
|
||||
// TODO: Why do we have two epochs defined?
|
||||
|
||||
SYSTEMTIME system_time;
|
||||
FILETIME file_time;
|
||||
|
@ -107,7 +122,7 @@ int uvgrtp::clock::gettimeofday(struct timeval * tp, struct timezone * tzp)
|
|||
time = ((uint64_t)file_time.dwLowDateTime ) ;
|
||||
time += ((uint64_t)file_time.dwHighDateTime) << 32;
|
||||
|
||||
tp->tv_sec = (long) ((time - EPOCH) / 10000000L);
|
||||
tp->tv_sec = (long) ((time - epoch) / 10000000L);
|
||||
tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -150,16 +150,9 @@ namespace uvgrtp {
|
|||
dh();
|
||||
~dh();
|
||||
|
||||
/* TODO: */
|
||||
void generate_keys();
|
||||
|
||||
/* TODO: */
|
||||
void get_pk(uint8_t *pk, size_t len);
|
||||
|
||||
/* TODO: */
|
||||
void set_remote_pk(uint8_t *pk, size_t len);
|
||||
|
||||
/* TODO: */
|
||||
void get_shared_secret(uint8_t *ss, size_t len);
|
||||
|
||||
private:
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
// TODO constexpr??
|
||||
|
||||
inline const std::string className(const std::string& prettyFunction)
|
||||
{
|
||||
size_t colons = prettyFunction.find("::");
|
||||
|
|
|
@ -27,17 +27,17 @@ uvgrtp::formats::h264::~h264()
|
|||
|
||||
uint8_t uvgrtp::formats::h264::get_payload_header_size() const
|
||||
{
|
||||
return uvgrtp::frame::HEADER_SIZE_H264_INDICATOR;
|
||||
return HEADER_SIZE_H264_INDICATOR;
|
||||
}
|
||||
|
||||
uint8_t uvgrtp::formats::h264::get_nal_header_size() const
|
||||
{
|
||||
return uvgrtp::frame::HEADER_SIZE_H264_NAL;
|
||||
return HEADER_SIZE_H264_NAL;
|
||||
}
|
||||
|
||||
uint8_t uvgrtp::formats::h264::get_fu_header_size() const
|
||||
{
|
||||
return uvgrtp::frame::HEADER_SIZE_H264_FU;
|
||||
return HEADER_SIZE_H264_FU;
|
||||
}
|
||||
|
||||
uint8_t uvgrtp::formats::h264::get_start_code_range() const
|
||||
|
@ -113,10 +113,7 @@ rtp_error_t uvgrtp::formats::h264::finalize_aggregation_pkt()
|
|||
aggr_pkt_info_.fu_indicator[0] = (0 << 7) | ((nri & 0x3) << 5) | H264_PKT_AGGR;
|
||||
|
||||
aggr_pkt_info_.aggr_pkt.push_back(
|
||||
std::make_pair(
|
||||
uvgrtp::frame::HEADER_SIZE_H264_FU,
|
||||
aggr_pkt_info_.fu_indicator
|
||||
)
|
||||
std::make_pair(HEADER_SIZE_H264_FU, aggr_pkt_info_.fu_indicator)
|
||||
);
|
||||
|
||||
for (auto& nalu: aggr_pkt_info_.nalus) {
|
||||
|
@ -176,7 +173,7 @@ uvgrtp::frame::rtp_frame* uvgrtp::formats::h264::allocate_rtp_frame_with_startco
|
|||
|
||||
complete->payload = new uint8_t[complete->payload_len];
|
||||
|
||||
if (add_start_code) {
|
||||
if (add_start_code && complete->payload_len >= 3) {
|
||||
complete->payload[0] = 0;
|
||||
complete->payload[1] = 0;
|
||||
complete->payload[2] = 1;
|
||||
|
|
|
@ -16,6 +16,10 @@ namespace uvgrtp {
|
|||
|
||||
namespace formats {
|
||||
|
||||
constexpr uint8_t HEADER_SIZE_H264_INDICATOR = 1;
|
||||
constexpr uint8_t HEADER_SIZE_H264_NAL = 1;
|
||||
constexpr uint8_t HEADER_SIZE_H264_FU = 1;
|
||||
|
||||
enum H264_NAL_TYPES {
|
||||
H264_NON_IDR = 1,
|
||||
H264_IDR = 5,
|
||||
|
@ -24,19 +28,19 @@ namespace uvgrtp {
|
|||
};
|
||||
|
||||
struct h264_aggregation_packet {
|
||||
uint8_t fu_indicator[uvgrtp::frame::HEADER_SIZE_H264_INDICATOR];
|
||||
uint8_t fu_indicator[HEADER_SIZE_H264_INDICATOR] = {0};
|
||||
uvgrtp::buf_vec nalus; /* discrete NAL units */
|
||||
uvgrtp::buf_vec aggr_pkt; /* crafted aggregation packet */
|
||||
};
|
||||
|
||||
struct h264_headers {
|
||||
uint8_t fu_indicator[uvgrtp::frame::HEADER_SIZE_H264_INDICATOR];
|
||||
uint8_t fu_indicator[HEADER_SIZE_H264_INDICATOR];
|
||||
|
||||
/* there are three types of Fragmentation Unit headers:
|
||||
* - header for the first fragment
|
||||
* - header for all middle fragments
|
||||
* - header for the last fragment */
|
||||
uint8_t fu_headers[3 * uvgrtp::frame::HEADER_SIZE_H264_FU];
|
||||
uint8_t fu_headers[3 * HEADER_SIZE_H264_FU];
|
||||
};
|
||||
|
||||
class h264 : public h26x {
|
||||
|
|
|
@ -30,17 +30,17 @@ uvgrtp::formats::h265::~h265()
|
|||
|
||||
uint8_t uvgrtp::formats::h265::get_payload_header_size() const
|
||||
{
|
||||
return uvgrtp::frame::HEADER_SIZE_H265_PAYLOAD;
|
||||
return HEADER_SIZE_H265_PAYLOAD;
|
||||
}
|
||||
|
||||
uint8_t uvgrtp::formats::h265::get_nal_header_size() const
|
||||
{
|
||||
return uvgrtp::frame::HEADER_SIZE_H265_NAL;
|
||||
return HEADER_SIZE_H265_NAL;
|
||||
}
|
||||
|
||||
uint8_t uvgrtp::formats::h265::get_fu_header_size() const
|
||||
{
|
||||
return uvgrtp::frame::HEADER_SIZE_H265_FU;
|
||||
return HEADER_SIZE_H265_FU;
|
||||
}
|
||||
|
||||
uint8_t uvgrtp::formats::h265::get_start_code_range() const
|
||||
|
@ -118,10 +118,7 @@ rtp_error_t uvgrtp::formats::h265::finalize_aggregation_pkt()
|
|||
aggr_pkt_info_.payload_header[1] = 1;
|
||||
|
||||
aggr_pkt_info_.aggr_pkt.push_back(
|
||||
std::make_pair(
|
||||
uvgrtp::frame::HEADER_SIZE_H265_PAYLOAD,
|
||||
aggr_pkt_info_.payload_header
|
||||
)
|
||||
std::make_pair(HEADER_SIZE_H265_PAYLOAD, aggr_pkt_info_.payload_header)
|
||||
);
|
||||
|
||||
for (size_t i = 0; i < aggr_pkt_info_.nalus.size(); ++i) {
|
||||
|
|
|
@ -17,6 +17,10 @@ namespace uvgrtp {
|
|||
|
||||
namespace formats {
|
||||
|
||||
constexpr uint8_t HEADER_SIZE_H265_PAYLOAD = 2;
|
||||
constexpr uint8_t HEADER_SIZE_H265_NAL = 2;
|
||||
constexpr uint8_t HEADER_SIZE_H265_FU = 1;
|
||||
|
||||
enum H265_NAL_TYPES {
|
||||
H265_TRAIL_R = 1,
|
||||
H265_IDR_W_RADL = 19,
|
||||
|
@ -25,19 +29,19 @@ namespace uvgrtp {
|
|||
};
|
||||
|
||||
struct h265_aggregation_packet {
|
||||
uint8_t payload_header[uvgrtp::frame::HEADER_SIZE_H265_PAYLOAD];
|
||||
uint8_t payload_header[HEADER_SIZE_H265_PAYLOAD] = {0};
|
||||
uvgrtp::buf_vec nalus; /* discrete NAL units */
|
||||
uvgrtp::buf_vec aggr_pkt; /* crafted aggregation packet */
|
||||
};
|
||||
|
||||
struct h265_headers {
|
||||
uint8_t payload_header[uvgrtp::frame::HEADER_SIZE_H265_PAYLOAD];
|
||||
uint8_t payload_header[HEADER_SIZE_H265_PAYLOAD];
|
||||
|
||||
/* there are three types of Fragmentation Unit headers:
|
||||
* - header for the first fragment
|
||||
* - header for all middle fragments
|
||||
* - header for the last fragment */
|
||||
uint8_t fu_headers[3 * uvgrtp::frame::HEADER_SIZE_H265_FU];
|
||||
uint8_t fu_headers[3 * HEADER_SIZE_H265_FU];
|
||||
};
|
||||
|
||||
class h265 : public h26x {
|
||||
|
|
|
@ -31,17 +31,17 @@ uvgrtp::formats::h266::~h266()
|
|||
|
||||
uint8_t uvgrtp::formats::h266::get_payload_header_size() const
|
||||
{
|
||||
return uvgrtp::frame::HEADER_SIZE_H266_PAYLOAD;
|
||||
return HEADER_SIZE_H266_PAYLOAD;
|
||||
}
|
||||
|
||||
uint8_t uvgrtp::formats::h266::get_nal_header_size() const
|
||||
{
|
||||
return uvgrtp::frame::HEADER_SIZE_H266_NAL;
|
||||
return HEADER_SIZE_H266_NAL;
|
||||
}
|
||||
|
||||
uint8_t uvgrtp::formats::h266::get_fu_header_size() const
|
||||
{
|
||||
return uvgrtp::frame::HEADER_SIZE_H266_FU;
|
||||
return HEADER_SIZE_H266_FU;
|
||||
}
|
||||
|
||||
uint8_t uvgrtp::formats::h266::get_start_code_range() const
|
||||
|
|
|
@ -16,6 +16,10 @@ namespace uvgrtp {
|
|||
|
||||
namespace formats {
|
||||
|
||||
constexpr uint8_t HEADER_SIZE_H266_PAYLOAD = 2;
|
||||
constexpr uint8_t HEADER_SIZE_H266_NAL = 2;
|
||||
constexpr uint8_t HEADER_SIZE_H266_FU = 1;
|
||||
|
||||
enum H266_NAL_TYPES {
|
||||
H266_TRAIL_NUT = 0,
|
||||
H266_IDR_W_RADL = 7,
|
||||
|
@ -24,19 +28,19 @@ namespace uvgrtp {
|
|||
};
|
||||
|
||||
struct h266_aggregation_packet {
|
||||
uint8_t payload_header[uvgrtp::frame::HEADER_SIZE_H266_PAYLOAD];
|
||||
uint8_t payload_header[HEADER_SIZE_H266_PAYLOAD];
|
||||
uvgrtp::buf_vec nalus; /* discrete NAL units */
|
||||
uvgrtp::buf_vec aggr_pkt; /* crafted aggregation packet */
|
||||
};
|
||||
|
||||
struct h266_headers {
|
||||
uint8_t payload_header[uvgrtp::frame::HEADER_SIZE_H266_PAYLOAD];
|
||||
uint8_t payload_header[HEADER_SIZE_H266_PAYLOAD];
|
||||
|
||||
/* there are three types of Fragmentation Unit headers:
|
||||
* - header for the first fragment
|
||||
* - header for all middle fragments
|
||||
* - header for the last fragment */
|
||||
uint8_t fu_headers[3 * uvgrtp::frame::HEADER_SIZE_H266_FU];
|
||||
uint8_t fu_headers[3 * HEADER_SIZE_H266_FU];
|
||||
};
|
||||
|
||||
class h266 : public h26x {
|
||||
|
|
|
@ -40,7 +40,7 @@ constexpr int GARBAGE_COLLECTION_INTERVAL_MS = 100;
|
|||
// any value less than 30 minutes is ok here, since that is how long it takes to go through all timestamps
|
||||
constexpr int TIME_TO_KEEP_TRACK_OF_PREVIOUS_FRAMES_MS = 5000;
|
||||
|
||||
static inline unsigned __find_h26x_start(uint32_t value,bool& additional_byte)
|
||||
static inline uint8_t __find_h26x_start(uint32_t value,bool& additional_byte)
|
||||
{
|
||||
additional_byte = false;
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
|
@ -124,7 +124,6 @@ ssize_t uvgrtp::formats::h26x::find_h26x_start_code(
|
|||
|
||||
uint64_t prefetch = UINT64_MAX;
|
||||
uint32_t value = UINT32_MAX;
|
||||
unsigned ret = 0;
|
||||
|
||||
/* We can get rid of the bounds check when looping through
|
||||
* non-zero 8 byte chunks by setting the last byte to zero.
|
||||
|
@ -137,32 +136,37 @@ ssize_t uvgrtp::formats::h26x::find_h26x_start_code(
|
|||
while (pos + 8 < len) {
|
||||
prefetch = *(uint64_t *)ptr;
|
||||
|
||||
if (!prev_z)
|
||||
{
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
if (!prev_z && !(cur_z = haszero64_le(prefetch))) {
|
||||
cur_z = haszero64_le(prefetch);
|
||||
#else
|
||||
if (!prev_z && !(cur_z = haszero64_be(prefetch))) {
|
||||
cur_z = haszero64_be(prefetch)
|
||||
#endif
|
||||
/* pos is not used in the following loop so it makes little sense to
|
||||
* update it on every iteration. Faster way to do the loop is to save
|
||||
* ptr's current value before loop, update only ptr in the loop and when
|
||||
* the loop is exited, calculate the difference between tmp and ptr to get
|
||||
* the number of iterations done * 8 */
|
||||
tmp = ptr;
|
||||
if (!cur_z) {
|
||||
/* pos is not used in the following loop so it makes little sense to
|
||||
* update it on every iteration. Faster way to do the loop is to save
|
||||
* ptr's current value before loop, update only ptr in the loop and when
|
||||
* the loop is exited, calculate the difference between tmp and ptr to get
|
||||
* the number of iterations done * 8 */
|
||||
tmp = ptr;
|
||||
|
||||
do {
|
||||
ptr += 8;
|
||||
prefetch = *(uint64_t *)ptr;
|
||||
do {
|
||||
ptr += 8;
|
||||
prefetch = *(uint64_t*)ptr;
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
cur_z = haszero64_le(prefetch);
|
||||
cur_z = haszero64_le(prefetch);
|
||||
#else
|
||||
cur_z = haszero64_be(prefetch);
|
||||
cur_z = haszero64_be(prefetch);
|
||||
#endif
|
||||
} while (!cur_z);
|
||||
} while (!cur_z);
|
||||
|
||||
pos += PTR_DIFF(ptr, tmp);
|
||||
pos += PTR_DIFF(ptr, tmp);
|
||||
|
||||
if (pos + 8 >= len)
|
||||
break;
|
||||
if (pos + 8 >= len)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
value = *(uint32_t *)ptr;
|
||||
|
@ -193,10 +197,11 @@ ssize_t uvgrtp::formats::h26x::find_h26x_start_code(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
bool additional_byte = false;
|
||||
if ((ret = start_len = __find_h26x_start(value,additional_byte)) > 0) {
|
||||
uint8_t ret = __find_h26x_start(value, additional_byte);
|
||||
start_len = ret;
|
||||
if (ret > 0) {
|
||||
if (ret == 5) {
|
||||
ret = 3;
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
|
@ -465,7 +470,7 @@ uvgrtp::frame::rtp_frame* uvgrtp::formats::h26x::allocate_rtp_frame_with_startco
|
|||
|
||||
complete->payload = new uint8_t[complete->payload_len];
|
||||
|
||||
if (add_start_code) {
|
||||
if (add_start_code && complete->payload_len >= 4) {
|
||||
complete->payload[0] = 0;
|
||||
complete->payload[1] = 0;
|
||||
complete->payload[2] = 0;
|
||||
|
@ -501,9 +506,9 @@ bool uvgrtp::formats::h26x::is_frame_late(uvgrtp::formats::h26x_info_t& hinfo, s
|
|||
return (uvgrtp::clock::hrc::diff_now(hinfo.sframe_time) >= max_delay);
|
||||
}
|
||||
|
||||
uint32_t uvgrtp::formats::h26x::drop_frame(uint32_t ts)
|
||||
size_t uvgrtp::formats::h26x::drop_frame(uint32_t ts)
|
||||
{
|
||||
uint32_t total_cleaned = 0;
|
||||
size_t total_cleaned = 0;
|
||||
if (frames_.find(ts) == frames_.end())
|
||||
{
|
||||
UVG_LOG_ERROR("Tried to drop a non-existing frame");
|
||||
|
@ -713,7 +718,7 @@ rtp_error_t uvgrtp::formats::h26x::packet_handler(int rce_flags, uvgrtp::frame::
|
|||
void uvgrtp::formats::h26x::garbage_collect_lost_frames(size_t timout)
|
||||
{
|
||||
if (uvgrtp::clock::hrc::diff_now(last_garbage_collection_) >= GARBAGE_COLLECTION_INTERVAL_MS) {
|
||||
uint32_t total_cleaned = 0;
|
||||
size_t total_cleaned = 0;
|
||||
std::vector<uint32_t> to_remove;
|
||||
|
||||
// first find all frames that have been waiting for too long
|
||||
|
|
|
@ -17,8 +17,6 @@ namespace uvgrtp {
|
|||
|
||||
namespace formats {
|
||||
|
||||
#define RTP_HDR_SIZE 12
|
||||
|
||||
enum class FRAG_TYPE {
|
||||
FT_INVALID = -2, /* invalid combination of S and E bits */
|
||||
FT_NOT_FRAG = -1, /* frame doesn't contain fragment */
|
||||
|
@ -38,7 +36,7 @@ namespace uvgrtp {
|
|||
/* clock reading when the first fragment is received */
|
||||
uvgrtp::clock::hrc::hrc_t sframe_time;
|
||||
|
||||
uvgrtp::formats::NAL_TYPE nal_type;
|
||||
uvgrtp::formats::NAL_TYPE nal_type = uvgrtp::formats::NAL_TYPE::NT_OTHER;
|
||||
|
||||
bool start_received = false;
|
||||
bool end_received = false;
|
||||
|
@ -153,7 +151,7 @@ namespace uvgrtp {
|
|||
private:
|
||||
|
||||
bool is_frame_late(uvgrtp::formats::h26x_info_t& hinfo, size_t max_delay);
|
||||
uint32_t drop_frame(uint32_t ts);
|
||||
size_t drop_frame(uint32_t ts);
|
||||
|
||||
inline size_t calculate_expected_fus(uint32_t ts);
|
||||
inline void initialize_new_fragmented_frame(uint32_t ts, NAL_TYPE nal_type);
|
||||
|
|
|
@ -100,7 +100,7 @@ rtp_error_t uvgrtp::formats::media::packet_handler(void *arg, int rce_flags, uvg
|
|||
auto frame = *out;
|
||||
uint32_t ts = frame->header.timestamp;
|
||||
uint32_t seq = frame->header.seq;
|
||||
size_t recv = 0;
|
||||
uint32_t recv = 0;
|
||||
|
||||
/* If fragmentation of generic frame has not been enabled, we can just return the frame
|
||||
* in "out" because RTP packet handler has done all the necessasry stuff for small RTP packets */
|
||||
|
@ -123,9 +123,13 @@ rtp_error_t uvgrtp::formats::media::packet_handler(void *arg, int rce_flags, uvg
|
|||
|
||||
if (minfo->frames[ts].e_seq != INVALID_SEQ && minfo->frames[ts].s_seq != INVALID_SEQ) {
|
||||
if (minfo->frames[ts].s_seq > minfo->frames[ts].e_seq)
|
||||
recv = 0xffff - minfo->frames[ts].s_seq + minfo->frames[ts].e_seq + 2;
|
||||
{
|
||||
recv = UINT16_MAX - minfo->frames[ts].s_seq + minfo->frames[ts].e_seq + (uint32_t)2;
|
||||
}
|
||||
else
|
||||
recv = minfo->frames[ts].e_seq - minfo->frames[ts].s_seq + 1;
|
||||
{
|
||||
recv = minfo->frames[ts].e_seq - minfo->frames[ts].s_seq + (uint32_t)1;
|
||||
}
|
||||
|
||||
if (recv == minfo->frames[ts].npkts) {
|
||||
auto retframe = uvgrtp::frame::alloc_rtp_frame(minfo->frames[ts].size);
|
||||
|
@ -165,7 +169,7 @@ rtp_error_t uvgrtp::formats::media::packet_handler(void *arg, int rce_flags, uvg
|
|||
return RTP_OK;
|
||||
}
|
||||
|
||||
void uvgrtp::formats::media::set_fps(int enumerator, int denominator)
|
||||
void uvgrtp::formats::media::set_fps(ssize_t enumerator, ssize_t denominator)
|
||||
{
|
||||
fqueue_->set_fps(enumerator, denominator);
|
||||
}
|
|
@ -21,6 +21,9 @@ namespace uvgrtp {
|
|||
|
||||
#define INVALID_TS 0xffffffff
|
||||
|
||||
/* TODO: This functionality has much in common with h26x fragmentation and
|
||||
* they could use same structures */
|
||||
|
||||
typedef struct media_info {
|
||||
uint32_t s_seq = 0;
|
||||
uint32_t e_seq = 0;
|
||||
|
@ -62,7 +65,7 @@ namespace uvgrtp {
|
|||
/* Return pointer to the internal frame info structure which is relayed to packet handler */
|
||||
media_frame_info_t *get_media_frame_info();
|
||||
|
||||
void set_fps(int enumarator, int denominator);
|
||||
void set_fps(ssize_t enumarator, ssize_t denominator);
|
||||
|
||||
protected:
|
||||
virtual rtp_error_t push_media_frame(uint8_t *data, size_t data_len, int rtp_flags);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
uvgrtp::frame_queue::frame_queue(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> rtp, int rce_flags):
|
||||
active_(nullptr),
|
||||
dealloc_hook_(nullptr),
|
||||
max_mcount_(MAX_MSG_COUNT),
|
||||
max_ccount_(MAX_CHUNK_COUNT* max_mcount_),
|
||||
rtp_(rtp),
|
||||
|
@ -312,7 +313,7 @@ rtp_error_t uvgrtp::frame_queue::flush_queue()
|
|||
|
||||
// send pkt vects
|
||||
if (socket_->sendto(active_->packets[i], 0) != RTP_OK) {
|
||||
UVG_LOG_ERROR("Failed to send packet: %s", strerror(errno));
|
||||
UVG_LOG_ERROR("Failed to send packet: %li", errno);
|
||||
(void)deinit_transaction();
|
||||
return RTP_SEND_ERROR;
|
||||
}
|
||||
|
@ -320,7 +321,7 @@ rtp_error_t uvgrtp::frame_queue::flush_queue()
|
|||
|
||||
}
|
||||
else if (socket_->sendto(active_->packets, 0) != RTP_OK) {
|
||||
UVG_LOG_ERROR("Failed to flush the message queue: %s", strerror(errno));
|
||||
UVG_LOG_ERROR("Failed to flush the message queue: %li", errno);
|
||||
(void)deinit_transaction();
|
||||
return RTP_SEND_ERROR;
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace uvgrtp {
|
|||
|
||||
/* If the application code provided us a deallocation hook, this points to it.
|
||||
* When SCD finishes processing a transaction, it will call this hook with "data_raw" pointer */
|
||||
void (*dealloc_hook)(void *);
|
||||
void (*dealloc_hook)(void *) = nullptr;
|
||||
|
||||
} transaction_t;
|
||||
|
||||
|
@ -149,7 +149,7 @@ namespace uvgrtp {
|
|||
* significant memory leaks */
|
||||
void install_dealloc_hook(void (*dealloc_hook)(void *));
|
||||
|
||||
void set_fps(int enumerator, int denominator)
|
||||
void set_fps(ssize_t enumerator, ssize_t denominator)
|
||||
{
|
||||
fps = enumerator > 0 && denominator > 0;
|
||||
if (denominator > 0)
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
|
||||
uvgrtp::holepuncher::holepuncher(std::shared_ptr<uvgrtp::socket> socket):
|
||||
socket_(socket),
|
||||
last_dgram_sent_(0)
|
||||
{
|
||||
}
|
||||
last_dgram_sent_(0),
|
||||
active_(false)
|
||||
{}
|
||||
|
||||
uvgrtp::holepuncher::~holepuncher()
|
||||
{
|
||||
|
|
|
@ -21,13 +21,13 @@
|
|||
#include <errno.h>
|
||||
|
||||
uvgrtp::media_stream::media_stream(std::string cname, std::string addr,
|
||||
int src_port, int dst_port, rtp_format_t fmt, int rce_flags):
|
||||
uint16_t src_port, uint16_t dst_port, rtp_format_t fmt, int rce_flags):
|
||||
srtp_(nullptr),
|
||||
srtcp_(nullptr),
|
||||
socket_(nullptr),
|
||||
rtp_(nullptr),
|
||||
rtcp_(nullptr),
|
||||
ctx_config_(),
|
||||
rce_flags_(),
|
||||
media_config_(nullptr),
|
||||
initialized_(false),
|
||||
rtp_handler_key_(0),
|
||||
|
@ -45,13 +45,11 @@ uvgrtp::media_stream::media_stream(std::string cname, std::string addr,
|
|||
src_port_ = src_port;
|
||||
dst_port_ = dst_port;
|
||||
key_ = uvgrtp::random::generate_32();
|
||||
|
||||
ctx_config_.rce_flags = rce_flags;
|
||||
}
|
||||
|
||||
uvgrtp::media_stream::media_stream(std::string cname,
|
||||
std::string remote_addr, std::string local_addr,
|
||||
int src_port, int dst_port,
|
||||
uint16_t src_port, uint16_t dst_port,
|
||||
rtp_format_t fmt, int rce_flags
|
||||
):
|
||||
media_stream(cname, remote_addr, src_port, dst_port, fmt, rce_flags)
|
||||
|
@ -70,12 +68,12 @@ uvgrtp::media_stream::~media_stream()
|
|||
// and media stream is destroyed. Note that this is the only way to stop pull
|
||||
// frame without waiting
|
||||
|
||||
if ((ctx_config_.rce_flags & RCE_RTCP) && rtcp_)
|
||||
if ((rce_flags_ & RCE_RTCP) && rtcp_)
|
||||
{
|
||||
rtcp_->stop();
|
||||
}
|
||||
|
||||
if ((ctx_config_.rce_flags & RCE_HOLEPUNCH_KEEPALIVE) && holepuncher_)
|
||||
if ((rce_flags_ & RCE_HOLEPUNCH_KEEPALIVE) && holepuncher_)
|
||||
{
|
||||
holepuncher_->stop();
|
||||
}
|
||||
|
@ -87,7 +85,7 @@ rtp_error_t uvgrtp::media_stream::init_connection()
|
|||
{
|
||||
rtp_error_t ret = RTP_OK;
|
||||
|
||||
socket_ = std::shared_ptr<uvgrtp::socket> (new uvgrtp::socket(ctx_config_.rce_flags));
|
||||
socket_ = std::shared_ptr<uvgrtp::socket> (new uvgrtp::socket(rce_flags_));
|
||||
|
||||
if ((ret = socket_->init(AF_INET, SOCK_DGRAM, 0)) != RTP_OK)
|
||||
return ret;
|
||||
|
@ -100,12 +98,14 @@ rtp_error_t uvgrtp::media_stream::init_connection()
|
|||
UVG_LOG_ERROR("Failed to make the socket non-blocking!");
|
||||
#endif
|
||||
|
||||
short int family = AF_INET;
|
||||
|
||||
// no reason to fail sending even if binding fails so we set remote address first
|
||||
remote_sockaddr_ = socket_->create_sockaddr(AF_INET, remote_address_, dst_port_);
|
||||
remote_sockaddr_ = socket_->create_sockaddr(family, remote_address_, dst_port_);
|
||||
socket_->set_sockaddr(remote_sockaddr_);
|
||||
|
||||
if (local_address_ != "") {
|
||||
sockaddr_in bind_addr = socket_->create_sockaddr(AF_INET, local_address_, src_port_);
|
||||
sockaddr_in bind_addr = socket_->create_sockaddr(family, local_address_, src_port_);
|
||||
|
||||
if ((ret = socket_->bind(bind_addr)) != RTP_OK)
|
||||
{
|
||||
|
@ -115,7 +115,7 @@ rtp_error_t uvgrtp::media_stream::init_connection()
|
|||
}
|
||||
else
|
||||
{
|
||||
if ((ret = socket_->bind(AF_INET, INADDR_ANY, src_port_)) != RTP_OK)
|
||||
if ((ret = socket_->bind(family, INADDR_ANY, src_port_)) != RTP_OK)
|
||||
{
|
||||
log_platform_error("bind(2) to any failed");
|
||||
return ret;
|
||||
|
@ -141,10 +141,10 @@ rtp_error_t uvgrtp::media_stream::init_connection()
|
|||
|
||||
rtp_error_t uvgrtp::media_stream::create_media(rtp_format_t fmt)
|
||||
{
|
||||
switch (fmt_) {
|
||||
switch (fmt) {
|
||||
case RTP_FORMAT_H264:
|
||||
{
|
||||
uvgrtp::formats::h264* format_264 = new uvgrtp::formats::h264(socket_, rtp_, ctx_config_.rce_flags);
|
||||
uvgrtp::formats::h264* format_264 = new uvgrtp::formats::h264(socket_, rtp_, rce_flags_);
|
||||
|
||||
reception_flow_->install_aux_handler_cpp(
|
||||
rtp_handler_key_,
|
||||
|
@ -157,7 +157,7 @@ rtp_error_t uvgrtp::media_stream::create_media(rtp_format_t fmt)
|
|||
}
|
||||
case RTP_FORMAT_H265:
|
||||
{
|
||||
uvgrtp::formats::h265* format_265 = new uvgrtp::formats::h265(socket_, rtp_, ctx_config_.rce_flags);
|
||||
uvgrtp::formats::h265* format_265 = new uvgrtp::formats::h265(socket_, rtp_, rce_flags_);
|
||||
|
||||
reception_flow_->install_aux_handler_cpp(
|
||||
rtp_handler_key_,
|
||||
|
@ -170,7 +170,7 @@ rtp_error_t uvgrtp::media_stream::create_media(rtp_format_t fmt)
|
|||
}
|
||||
case RTP_FORMAT_H266:
|
||||
{
|
||||
uvgrtp::formats::h266* format_266 = new uvgrtp::formats::h266(socket_, rtp_, ctx_config_.rce_flags);
|
||||
uvgrtp::formats::h266* format_266 = new uvgrtp::formats::h266(socket_, rtp_, rce_flags_);
|
||||
|
||||
reception_flow_->install_aux_handler_cpp(
|
||||
rtp_handler_key_,
|
||||
|
@ -183,7 +183,7 @@ rtp_error_t uvgrtp::media_stream::create_media(rtp_format_t fmt)
|
|||
}
|
||||
case RTP_FORMAT_OPUS:
|
||||
case RTP_FORMAT_GENERIC:
|
||||
media_ = std::unique_ptr<uvgrtp::formats::media> (new uvgrtp::formats::media(socket_, rtp_, ctx_config_.rce_flags));
|
||||
media_ = std::unique_ptr<uvgrtp::formats::media> (new uvgrtp::formats::media(socket_, rtp_, rce_flags_));
|
||||
|
||||
reception_flow_->install_aux_handler(
|
||||
rtp_handler_key_,
|
||||
|
@ -248,7 +248,7 @@ rtp_error_t uvgrtp::media_stream::init()
|
|||
reception_flow_ = std::unique_ptr<uvgrtp::reception_flow> (new uvgrtp::reception_flow());
|
||||
|
||||
rtp_ = std::shared_ptr<uvgrtp::rtp> (new uvgrtp::rtp(fmt_));
|
||||
rtcp_ = std::shared_ptr<uvgrtp::rtcp> (new uvgrtp::rtcp(rtp_, cname_, ctx_config_.rce_flags));
|
||||
rtcp_ = std::shared_ptr<uvgrtp::rtcp> (new uvgrtp::rtcp(rtp_, cname_, rce_flags_));
|
||||
|
||||
socket_->install_handler(rtcp_.get(), rtcp_->send_packet_handler_vec);
|
||||
|
||||
|
@ -278,15 +278,15 @@ rtp_error_t uvgrtp::media_stream::init(std::shared_ptr<uvgrtp::zrtp> zrtp)
|
|||
return free_resources(ret);
|
||||
}
|
||||
|
||||
srtp_ = std::shared_ptr<uvgrtp::srtp>(new uvgrtp::srtp(ctx_config_.rce_flags));
|
||||
if ((ret = init_srtp_with_zrtp(ctx_config_.rce_flags, SRTP, srtp_, zrtp)) != RTP_OK)
|
||||
srtp_ = std::shared_ptr<uvgrtp::srtp>(new uvgrtp::srtp(rce_flags_));
|
||||
if ((ret = init_srtp_with_zrtp(rce_flags_, SRTP, srtp_, zrtp)) != RTP_OK)
|
||||
return free_resources(ret);
|
||||
|
||||
srtcp_ = std::shared_ptr<uvgrtp::srtcp> (new uvgrtp::srtcp());
|
||||
if ((ret = init_srtp_with_zrtp(ctx_config_.rce_flags, SRTCP, srtcp_, zrtp)) != RTP_OK)
|
||||
if ((ret = init_srtp_with_zrtp(rce_flags_, SRTCP, srtcp_, zrtp)) != RTP_OK)
|
||||
return free_resources(ret);
|
||||
|
||||
rtcp_ = std::shared_ptr<uvgrtp::rtcp> (new uvgrtp::rtcp(rtp_, cname_, srtcp_, ctx_config_.rce_flags));
|
||||
rtcp_ = std::shared_ptr<uvgrtp::rtcp> (new uvgrtp::rtcp(rtp_, cname_, srtcp_, rce_flags_));
|
||||
|
||||
socket_->install_handler(rtcp_.get(), rtcp_->send_packet_handler_vec);
|
||||
socket_->install_handler(srtp_.get(), srtp_->send_packet_handler);
|
||||
|
@ -320,22 +320,22 @@ rtp_error_t uvgrtp::media_stream::add_srtp_ctx(uint8_t *key, uint8_t *salt)
|
|||
|
||||
rtp_ = std::shared_ptr<uvgrtp::rtp> (new uvgrtp::rtp(fmt_));
|
||||
|
||||
srtp_ = std::shared_ptr<uvgrtp::srtp> (new uvgrtp::srtp(ctx_config_.rce_flags));
|
||||
srtp_ = std::shared_ptr<uvgrtp::srtp> (new uvgrtp::srtp(rce_flags_));
|
||||
|
||||
// why are they local and remote key/salt the same?
|
||||
if ((ret = srtp_->init(SRTP, ctx_config_.rce_flags, key, key, salt, salt)) != RTP_OK) {
|
||||
if ((ret = srtp_->init(SRTP, rce_flags_, key, key, salt, salt)) != RTP_OK) {
|
||||
UVG_LOG_WARN("Failed to initialize SRTP for media stream!");
|
||||
return free_resources(ret);
|
||||
}
|
||||
|
||||
srtcp_ = std::shared_ptr<uvgrtp::srtcp> (new uvgrtp::srtcp());
|
||||
|
||||
if ((ret = srtcp_->init(SRTCP, ctx_config_.rce_flags, key, key, salt, salt)) != RTP_OK) {
|
||||
if ((ret = srtcp_->init(SRTCP, rce_flags_, key, key, salt, salt)) != RTP_OK) {
|
||||
UVG_LOG_WARN("Failed to initialize SRTCP for media stream!");
|
||||
return free_resources(ret);
|
||||
}
|
||||
|
||||
rtcp_ = std::shared_ptr<uvgrtp::rtcp> (new uvgrtp::rtcp(rtp_, cname_, srtcp_, ctx_config_.rce_flags));
|
||||
rtcp_ = std::shared_ptr<uvgrtp::rtcp> (new uvgrtp::rtcp(rtp_, cname_, srtcp_, rce_flags_));
|
||||
|
||||
socket_->install_handler(rtcp_.get(), rtcp_->send_packet_handler_vec);
|
||||
socket_->install_handler(srtp_.get(), srtp_->send_packet_handler);
|
||||
|
@ -353,22 +353,22 @@ rtp_error_t uvgrtp::media_stream::start_components()
|
|||
if (create_media(fmt_) != RTP_OK)
|
||||
return free_resources(RTP_MEMORY_ERROR);
|
||||
|
||||
if (ctx_config_.rce_flags & RCE_HOLEPUNCH_KEEPALIVE) {
|
||||
if (rce_flags_ & RCE_HOLEPUNCH_KEEPALIVE) {
|
||||
holepuncher_ = std::unique_ptr<uvgrtp::holepuncher> (new uvgrtp::holepuncher(socket_));
|
||||
holepuncher_->start();
|
||||
}
|
||||
|
||||
if (ctx_config_.rce_flags & RCE_RTCP) {
|
||||
if (rce_flags_ & RCE_RTCP) {
|
||||
rtcp_->add_participant(remote_address_, src_port_ + 1, dst_port_ + 1, rtp_->get_clock_rate());
|
||||
rtcp_->set_session_bandwidth(get_default_bandwidth_kbps(fmt_));
|
||||
rtcp_->start();
|
||||
}
|
||||
|
||||
if (ctx_config_.rce_flags & RCE_SRTP_AUTHENTICATE_RTP)
|
||||
if (rce_flags_ & RCE_SRTP_AUTHENTICATE_RTP)
|
||||
rtp_->set_payload_size(MAX_PAYLOAD - UVG_AUTH_TAG_LENGTH);
|
||||
|
||||
initialized_ = true;
|
||||
return reception_flow_->start(socket_, ctx_config_.rce_flags);
|
||||
return reception_flow_->start(socket_, rce_flags_);
|
||||
}
|
||||
|
||||
rtp_error_t uvgrtp::media_stream::push_frame(uint8_t *data, size_t data_len, int rtp_flags)
|
||||
|
@ -378,7 +378,7 @@ rtp_error_t uvgrtp::media_stream::push_frame(uint8_t *data, size_t data_len, int
|
|||
return RTP_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
if (ctx_config_.rce_flags & RCE_HOLEPUNCH_KEEPALIVE && holepuncher_)
|
||||
if (rce_flags_ & RCE_HOLEPUNCH_KEEPALIVE && holepuncher_)
|
||||
holepuncher_->notify();
|
||||
|
||||
return media_->push_frame(data, data_len, rtp_flags);
|
||||
|
@ -391,7 +391,7 @@ rtp_error_t uvgrtp::media_stream::push_frame(std::unique_ptr<uint8_t[]> data, si
|
|||
return RTP_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
if (ctx_config_.rce_flags & RCE_HOLEPUNCH_KEEPALIVE && holepuncher_)
|
||||
if (rce_flags_ & RCE_HOLEPUNCH_KEEPALIVE && holepuncher_)
|
||||
holepuncher_->notify();
|
||||
|
||||
return media_->push_frame(std::move(data), data_len, rtp_flags);
|
||||
|
@ -406,7 +406,7 @@ rtp_error_t uvgrtp::media_stream::push_frame(uint8_t *data, size_t data_len, uin
|
|||
return RTP_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
if (ctx_config_.rce_flags & RCE_HOLEPUNCH_KEEPALIVE)
|
||||
if (rce_flags_ & RCE_HOLEPUNCH_KEEPALIVE)
|
||||
holepuncher_->notify();
|
||||
|
||||
rtp_->set_timestamp(ts);
|
||||
|
@ -425,7 +425,7 @@ rtp_error_t uvgrtp::media_stream::push_frame(std::unique_ptr<uint8_t[]> data, si
|
|||
return RTP_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
if (ctx_config_.rce_flags & RCE_HOLEPUNCH_KEEPALIVE)
|
||||
if (rce_flags_ & RCE_HOLEPUNCH_KEEPALIVE)
|
||||
holepuncher_->notify();
|
||||
|
||||
rtp_->set_timestamp(ts);
|
||||
|
@ -566,7 +566,7 @@ rtp_error_t uvgrtp::media_stream::configure_ctx(int rcc_flag, ssize_t value)
|
|||
ssize_t hdr = ETH_HDR_SIZE + IPV4_HDR_SIZE + UDP_HDR_SIZE + RTP_HDR_SIZE;
|
||||
ssize_t max_size = 0xffff - IPV4_HDR_SIZE - UDP_HDR_SIZE;
|
||||
|
||||
if (ctx_config_.rce_flags & RCE_SRTP_AUTHENTICATE_RTP)
|
||||
if (rce_flags_ & RCE_SRTP_AUTHENTICATE_RTP)
|
||||
hdr += UVG_AUTH_TAG_LENGTH;
|
||||
|
||||
if (value <= hdr)
|
||||
|
@ -621,7 +621,7 @@ uint32_t uvgrtp::media_stream::get_ssrc() const
|
|||
{
|
||||
if (!initialized_ || rtp_ == nullptr) {
|
||||
UVG_LOG_ERROR("RTP context has not been initialized, please call init before asking ssrc!");
|
||||
return RTP_NOT_INITIALIZED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return rtp_->get_ssrc();
|
||||
|
@ -630,7 +630,7 @@ uint32_t uvgrtp::media_stream::get_ssrc() const
|
|||
rtp_error_t uvgrtp::media_stream::init_srtp_with_zrtp(int rce_flags, int type, std::shared_ptr<uvgrtp::base_srtp> srtp,
|
||||
std::shared_ptr<uvgrtp::zrtp> zrtp)
|
||||
{
|
||||
size_t key_size = srtp->get_key_size(rce_flags);
|
||||
uint32_t key_size = srtp->get_key_size(rce_flags);
|
||||
|
||||
uint8_t* local_key = new uint8_t[key_size];
|
||||
uint8_t* remote_key = new uint8_t[key_size];
|
||||
|
@ -679,7 +679,7 @@ int uvgrtp::media_stream::get_default_bandwidth_kbps(rtp_format_t fmt)
|
|||
break;
|
||||
default:
|
||||
UVG_LOG_WARN("Unknown RTP format, setting session bandwidth to 64 kbps");
|
||||
int bandwidth = 64;
|
||||
bandwidth = 64;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,9 @@
|
|||
rtp_error_t uvgrtp::random::init()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
srand(GetTickCount());
|
||||
|
||||
uint32_t ticks = (uint32_t)GetTickCount64();
|
||||
srand(ticks);
|
||||
#else
|
||||
srand(time(NULL));
|
||||
#endif
|
||||
|
@ -71,14 +73,14 @@ int uvgrtp::random::generate(void *buf, size_t n)
|
|||
|
||||
return res ? 0 : -1;
|
||||
}
|
||||
return -1;
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
int status = SecRandomCopyBytes(kSecRandomDefault, n, buf);
|
||||
if (status == errSecSuccess)
|
||||
{
|
||||
return n;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ rtp_error_t uvgrtp::reception_flow::start(std::shared_ptr<uvgrtp::socket> socket
|
|||
|
||||
UVG_LOG_DEBUG("Creating receiving threads and setting priorities");
|
||||
processor_ = std::unique_ptr<std::thread>(new std::thread(&uvgrtp::reception_flow::process_packet, this, rce_flags));
|
||||
receiver_ = std::unique_ptr<std::thread>(new std::thread(&uvgrtp::reception_flow::receiver, this, socket, rce_flags));
|
||||
receiver_ = std::unique_ptr<std::thread>(new std::thread(&uvgrtp::reception_flow::receiver, this, socket));
|
||||
|
||||
// set receiver thread priority to maximum
|
||||
#ifndef WIN32
|
||||
|
@ -158,7 +158,7 @@ uvgrtp::frame::rtp_frame *uvgrtp::reception_flow::pull_frame()
|
|||
return frame;
|
||||
}
|
||||
|
||||
uvgrtp::frame::rtp_frame *uvgrtp::reception_flow::pull_frame(size_t timeout_ms)
|
||||
uvgrtp::frame::rtp_frame *uvgrtp::reception_flow::pull_frame(ssize_t timeout_ms)
|
||||
{
|
||||
auto start_time = std::chrono::high_resolution_clock::now();
|
||||
|
||||
|
@ -328,7 +328,7 @@ void uvgrtp::reception_flow::call_aux_handlers(uint32_t key, int rce_flags, uvgr
|
|||
}
|
||||
}
|
||||
|
||||
void uvgrtp::reception_flow::receiver(std::shared_ptr<uvgrtp::socket> socket, int rce_flags)
|
||||
void uvgrtp::reception_flow::receiver(std::shared_ptr<uvgrtp::socket> socket)
|
||||
{
|
||||
int read_packets = 0;
|
||||
|
||||
|
@ -342,7 +342,7 @@ void uvgrtp::reception_flow::receiver(std::shared_ptr<uvgrtp::socket> socket, in
|
|||
pollfd* pfds = new pollfd();
|
||||
#endif
|
||||
|
||||
int read_fds = socket->get_raw_socket();
|
||||
size_t read_fds = socket->get_raw_socket();
|
||||
pfds->fd = read_fds;
|
||||
pfds->events = POLLIN;
|
||||
|
||||
|
|
|
@ -143,13 +143,13 @@ namespace uvgrtp {
|
|||
* Return pointer to RTP frame on success
|
||||
* Return nullptr if operation timed out or an error occurred */
|
||||
uvgrtp::frame::rtp_frame *pull_frame();
|
||||
uvgrtp::frame::rtp_frame *pull_frame(size_t timeout_ms);
|
||||
uvgrtp::frame::rtp_frame *pull_frame(ssize_t timeout_ms);
|
||||
|
||||
void set_buffer_size(const ssize_t& value);
|
||||
|
||||
private:
|
||||
/* RTP packet receiver thread */
|
||||
void receiver(std::shared_ptr<uvgrtp::socket> socket, int rce_flags);
|
||||
void receiver(std::shared_ptr<uvgrtp::socket> socket);
|
||||
|
||||
/* RTP packet dispatcher thread */
|
||||
void process_packet(int rce_flags);
|
||||
|
|
77
src/rtcp.cc
77
src/rtcp.cc
|
@ -79,7 +79,7 @@ uvgrtp::rtcp::rtcp(std::shared_ptr<uvgrtp::rtp> rtp, std::string cname, int rce_
|
|||
// items should not have null termination
|
||||
const char* c = cname.c_str();
|
||||
memcpy(cname_, c, cname.length());
|
||||
uint8_t length = cname.length();
|
||||
uint8_t length = (uint8_t)cname.length();
|
||||
|
||||
cnameItem_ = { 1, length, (void*)cname_ };
|
||||
ourItems_.push_back(cnameItem_);
|
||||
|
@ -103,7 +103,7 @@ uvgrtp::rtcp::~rtcp()
|
|||
ourItems_.clear();
|
||||
}
|
||||
|
||||
uvgrtp::rtcp_app_packet::rtcp_app_packet(const char* name, uint8_t subtype, size_t payload_len, const uint8_t* payload)
|
||||
uvgrtp::rtcp_app_packet::rtcp_app_packet(const char* name, uint8_t subtype, uint32_t payload_len, const uint8_t* payload)
|
||||
{
|
||||
uint8_t* packet_payload = new uint8_t[payload_len];
|
||||
memcpy(packet_payload, payload, payload_len);
|
||||
|
@ -216,7 +216,7 @@ void uvgrtp::rtcp::rtcp_runner(rtcp* rtcp, int interval)
|
|||
UVG_LOG_DEBUG("Sleeping for %i ms before sending first RTCP report", initial_sleep_ms);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(initial_sleep_ms));
|
||||
|
||||
uint8_t buffer[MAX_PACKET];
|
||||
std::unique_ptr<uint8_t[]> buffer = std::unique_ptr<uint8_t[]>(new uint8_t[MAX_PACKET]);
|
||||
|
||||
uvgrtp::clock::hrc::hrc_t start = uvgrtp::clock::hrc::now();
|
||||
|
||||
|
@ -224,7 +224,7 @@ void uvgrtp::rtcp::rtcp_runner(rtcp* rtcp, int interval)
|
|||
while (rtcp->is_active())
|
||||
{
|
||||
long int next_sendslot = i * interval;
|
||||
long int run_time = uvgrtp::clock::hrc::diff_now(start);
|
||||
uint32_t run_time = (uint32_t)uvgrtp::clock::hrc::diff_now(start);
|
||||
long int diff_ms = next_sendslot - run_time;
|
||||
|
||||
rtp_error_t ret = RTP_OK;
|
||||
|
@ -251,11 +251,11 @@ void uvgrtp::rtcp::rtcp_runner(rtcp* rtcp, int interval)
|
|||
poll_timout = max_poll_timeout_ms;
|
||||
}
|
||||
|
||||
ret = uvgrtp::poll::poll(rtcp->get_sockets(), buffer, MAX_PACKET, poll_timout, &nread);
|
||||
ret = uvgrtp::poll::poll(rtcp->get_sockets(), buffer.get(), MAX_PACKET, poll_timout, &nread);
|
||||
|
||||
if (ret == RTP_OK && nread > 0)
|
||||
{
|
||||
(void)rtcp->handle_incoming_packet(buffer, (size_t)nread);
|
||||
(void)rtcp->handle_incoming_packet(buffer.get(), (size_t)nread);
|
||||
} else if (ret == RTP_INTERRUPTED) {
|
||||
/* do nothing */
|
||||
} else {
|
||||
|
@ -945,9 +945,8 @@ void uvgrtp::rtcp::update_session_statistics(const uvgrtp::frame::rtp_frame *fra
|
|||
p->stats.dropped_pkts = dropped >= 0 ? dropped : 0;
|
||||
|
||||
// the arrival time expressed as an RTP timestamp
|
||||
uint32_t arrival =
|
||||
p->stats.initial_rtp +
|
||||
+ (uint32_t)uvgrtp::clock::ntp::diff_now(p->stats.initial_ntp)*(p->stats.clock_rate / 1000);
|
||||
uint32_t arrival = p->stats.initial_rtp +
|
||||
(uint32_t)uvgrtp::clock::ntp::diff_now(p->stats.initial_ntp)*(p->stats.clock_rate / 1000);
|
||||
|
||||
// calculate interarrival jitter. See RFC 3550 A.8
|
||||
uint32_t transit = arrival - frame->header.timestamp; // A.8: int transit = arrival - r->ts
|
||||
|
@ -1009,7 +1008,7 @@ rtp_error_t uvgrtp::rtcp::recv_packet_handler(void *arg, int rce_flags, frame::r
|
|||
|
||||
rtp_error_t uvgrtp::rtcp::send_packet_handler_vec(void *arg, uvgrtp::buf_vec& buffers)
|
||||
{
|
||||
ssize_t pkt_size = -uvgrtp::frame::HEADER_SIZE_RTP;
|
||||
ssize_t pkt_size = -HEADER_SIZES::RTP_HDR_SIZE;
|
||||
|
||||
for (auto& buffer : buffers)
|
||||
{
|
||||
|
@ -1026,8 +1025,10 @@ rtp_error_t uvgrtp::rtcp::send_packet_handler_vec(void *arg, uvgrtp::buf_vec& bu
|
|||
|
||||
size_t uvgrtp::rtcp::rtcp_length_in_bytes(uint16_t length)
|
||||
{
|
||||
size_t expanded_length = length;
|
||||
|
||||
// the length field is the rtcp packet size measured in 32-bit words - 1
|
||||
return uint32_t(length + 1) * sizeof(uint32_t);
|
||||
return (expanded_length + 1)* sizeof(uint32_t);
|
||||
}
|
||||
|
||||
rtp_error_t uvgrtp::rtcp::handle_incoming_packet(uint8_t *buffer, size_t size)
|
||||
|
@ -1076,7 +1077,7 @@ rtp_error_t uvgrtp::rtcp::handle_incoming_packet(uint8_t *buffer, size_t size)
|
|||
uvgrtp::frame::rtcp_header header;
|
||||
read_rtcp_header(buffer, read_ptr, header);
|
||||
|
||||
uint32_t size_of_rtcp_packet = rtcp_length_in_bytes(header.length);
|
||||
size_t size_of_rtcp_packet = rtcp_length_in_bytes(header.length);
|
||||
|
||||
/* Possible packet padding means header.length is only reliable way to find next packet.
|
||||
* We have to substract the size of header, since it was added when reading the header. */
|
||||
|
@ -1111,7 +1112,7 @@ rtp_error_t uvgrtp::rtcp::handle_incoming_packet(uint8_t *buffer, size_t size)
|
|||
return RTP_INVALID_VALUE;
|
||||
}
|
||||
|
||||
rtp_error_t ret = RTP_INVALID_VALUE;
|
||||
ret = RTP_INVALID_VALUE;
|
||||
|
||||
switch (header.pkt_type)
|
||||
{
|
||||
|
@ -1400,6 +1401,8 @@ rtp_error_t uvgrtp::rtcp::handle_sdes_packet(uint8_t* packet, size_t& read_ptr,
|
|||
rtp_error_t uvgrtp::rtcp::handle_bye_packet(uint8_t* packet, size_t& read_ptr,
|
||||
size_t packet_end, uvgrtp::frame::rtcp_header& header)
|
||||
{
|
||||
(void)header; // TODO: Process BYE packet better
|
||||
|
||||
for (size_t i = 0; i < packet_end; i += sizeof(uint32_t))
|
||||
{
|
||||
uint32_t ssrc = 0;
|
||||
|
@ -1440,7 +1443,7 @@ rtp_error_t uvgrtp::rtcp::handle_app_packet(uint8_t* packet, size_t& read_ptr,
|
|||
memcpy(frame->name, &packet[read_ptr], APP_NAME_SIZE);
|
||||
read_ptr += APP_NAME_SIZE;
|
||||
|
||||
uint32_t application_data_size = packet_end - read_ptr;
|
||||
size_t application_data_size = packet_end - read_ptr;
|
||||
|
||||
// application data is saved to payload
|
||||
frame->payload = new uint8_t[application_data_size];
|
||||
|
@ -1468,7 +1471,7 @@ rtp_error_t uvgrtp::rtcp::handle_app_packet(uint8_t* packet, size_t& read_ptr,
|
|||
return RTP_OK;
|
||||
}
|
||||
|
||||
rtp_error_t uvgrtp::rtcp::send_rtcp_packet_to_participants(uint8_t* frame, size_t frame_size, bool encrypt)
|
||||
rtp_error_t uvgrtp::rtcp::send_rtcp_packet_to_participants(uint8_t* frame, uint32_t frame_size, bool encrypt)
|
||||
{
|
||||
if (!frame)
|
||||
{
|
||||
|
@ -1508,9 +1511,9 @@ rtp_error_t uvgrtp::rtcp::send_rtcp_packet_to_participants(uint8_t* frame, size_
|
|||
return ret;
|
||||
}
|
||||
|
||||
size_t uvgrtp::rtcp::size_of_ready_app_packets() const
|
||||
uint32_t uvgrtp::rtcp::size_of_ready_app_packets() const
|
||||
{
|
||||
size_t app_size = 0;
|
||||
uint32_t app_size = 0;
|
||||
for (auto& app_name : app_packets_)
|
||||
{
|
||||
// TODO: Should we also send one per subtype?
|
||||
|
@ -1523,10 +1526,10 @@ size_t uvgrtp::rtcp::size_of_ready_app_packets() const
|
|||
return app_size;
|
||||
}
|
||||
|
||||
size_t uvgrtp::rtcp::size_of_compound_packet(uint16_t reports,
|
||||
bool sr_packet, bool rr_packet, bool sdes_packet, size_t app_size, bool bye_packet) const
|
||||
uint32_t uvgrtp::rtcp::size_of_compound_packet(uint16_t reports,
|
||||
bool sr_packet, bool rr_packet, bool sdes_packet, uint32_t app_size, bool bye_packet) const
|
||||
{
|
||||
size_t compound_packet_size = 0;
|
||||
uint32_t compound_packet_size = 0;
|
||||
|
||||
if (sr_packet)
|
||||
{
|
||||
|
@ -1570,7 +1573,7 @@ rtp_error_t uvgrtp::rtcp::generate_report()
|
|||
std::lock_guard<std::mutex> lock(packet_mutex_);
|
||||
rtcp_pkt_sent_count_++;
|
||||
|
||||
uint16_t reports = 0;
|
||||
uint8_t reports = 0;
|
||||
for (auto& p : participants_)
|
||||
{
|
||||
if (p.second->stats.received_rtp_packet)
|
||||
|
@ -1582,10 +1585,10 @@ rtp_error_t uvgrtp::rtcp::generate_report()
|
|||
bool sr_packet = our_role_ == SENDER && our_stats.sent_rtp_packet;
|
||||
bool rr_packet = our_role_ == RECEIVER || our_stats.sent_rtp_packet == 0;
|
||||
bool sdes_packet = true;
|
||||
size_t app_packets_size = size_of_ready_app_packets();
|
||||
uint32_t app_packets_size = size_of_ready_app_packets();
|
||||
bool bye_packet = !bye_ssrcs_.empty();
|
||||
|
||||
size_t compound_packet_size = size_of_compound_packet(reports, sr_packet, rr_packet, sdes_packet, app_packets_size, bye_packet);
|
||||
uint32_t compound_packet_size = size_of_compound_packet(reports, sr_packet, rr_packet, sdes_packet, app_packets_size, bye_packet);
|
||||
|
||||
if (compound_packet_size == 0)
|
||||
{
|
||||
|
@ -1603,7 +1606,7 @@ rtp_error_t uvgrtp::rtcp::generate_report()
|
|||
|
||||
// see https://datatracker.ietf.org/doc/html/rfc3550#section-6.4.1
|
||||
|
||||
int write_ptr = 0;
|
||||
size_t write_ptr = 0;
|
||||
if (sr_packet)
|
||||
{
|
||||
// sender reports have sender information in addition compared to receiver reports
|
||||
|
@ -1619,8 +1622,11 @@ rtp_error_t uvgrtp::rtcp::generate_report()
|
|||
/* TODO: The RTP timestamp should be from an actual RTP packet and NTP timestamp should be the one
|
||||
corresponding to it. */
|
||||
uint64_t ntp_ts = uvgrtp::clock::ntp::now();
|
||||
uint64_t rtp_ts = rtp_ts_start_ + (uvgrtp::clock::ntp::diff(clock_start_, ntp_ts))
|
||||
* float(clock_rate_ / 1000);
|
||||
|
||||
uint64_t expanded_ts_start = rtp_ts_start_;
|
||||
uint64_t ts_since_start = (uint64_t)(uvgrtp::clock::ntp::diff(clock_start_, ntp_ts) * double(clock_rate_ / 1000));
|
||||
|
||||
uint64_t rtp_ts = expanded_ts_start + ts_since_start;
|
||||
|
||||
if (!construct_rtcp_header(frame, write_ptr, sender_report_size, reports, uvgrtp::frame::RTCP_FT_SR) ||
|
||||
!construct_ssrc(frame, write_ptr, ssrc_) ||
|
||||
|
@ -1655,12 +1661,15 @@ rtp_error_t uvgrtp::rtcp::generate_report()
|
|||
if (p.second->stats.received_rtp_packet)
|
||||
{
|
||||
uint32_t dropped_packets = p.second->stats.dropped_pkts;
|
||||
// TODO: This should be the number of packets lost compared to number of packets expected (see fraction lost in RFC 3550)
|
||||
|
||||
// TODO: Fraction should be the number of packets lost compared to number of packets expected (see fraction lost in RFC 3550)
|
||||
// see https://datatracker.ietf.org/doc/html/rfc3550#appendix-A.3
|
||||
uint8_t fraction = dropped_packets ? p.second->stats.received_bytes / dropped_packets : 0;
|
||||
|
||||
//uint8_t fraction = dropped_packets ? p.second->stats.received_bytes / dropped_packets : 0;
|
||||
uint8_t fraction = 0; // disabled, because it was incorrect
|
||||
|
||||
uint64_t diff = (u_long)uvgrtp::clock::hrc::diff_now(p.second->stats.sr_ts);
|
||||
uint32_t dlrs = uvgrtp::clock::ms_to_jiffies(diff);
|
||||
uint32_t dlrs = (uint32_t)uvgrtp::clock::ms_to_jiffies(diff);
|
||||
|
||||
/* calculate delay of last SR only if SR has been received at least once */
|
||||
if (p.second->stats.lsr == 0)
|
||||
|
@ -1669,7 +1678,7 @@ rtp_error_t uvgrtp::rtcp::generate_report()
|
|||
}
|
||||
|
||||
construct_report_block(frame, write_ptr, p.first, fraction, dropped_packets,
|
||||
p.second->stats.cycles, p.second->stats.max_seq, p.second->stats.jitter,
|
||||
p.second->stats.cycles, p.second->stats.max_seq, (uint32_t)p.second->stats.jitter,
|
||||
p.second->stats.lsr, dlrs);
|
||||
|
||||
// we only send reports if there is something to report since last report
|
||||
|
@ -1702,9 +1711,9 @@ rtp_error_t uvgrtp::rtcp::generate_report()
|
|||
// take the oldest APP packet and send it
|
||||
rtcp_app_packet& next_packet = app_name.second.front();
|
||||
|
||||
uint16_t secondField = (next_packet.subtype & 0x1f);
|
||||
uint8_t secondField = (next_packet.subtype & 0x1f);
|
||||
|
||||
size_t packet_size = get_app_packet_size(next_packet.payload_len);
|
||||
uint32_t packet_size = get_app_packet_size(next_packet.payload_len);
|
||||
|
||||
if (!construct_rtcp_header(frame, write_ptr, packet_size, secondField,
|
||||
uvgrtp::frame::RTCP_FT_APP) ||
|
||||
|
@ -1725,7 +1734,7 @@ rtp_error_t uvgrtp::rtcp::generate_report()
|
|||
if (bye_packet)
|
||||
{
|
||||
// header construction does not add our ssrc for BYE
|
||||
uint16_t secondField = (bye_ssrcs_.size() & 0x1f);
|
||||
uint8_t secondField = (bye_ssrcs_.size() & 0x1f);
|
||||
if (!construct_rtcp_header(frame, write_ptr, get_bye_packet_size(bye_ssrcs_), secondField,
|
||||
uvgrtp::frame::RTCP_FT_BYE) ||
|
||||
!construct_bye_packet(frame, write_ptr, bye_ssrcs_))
|
||||
|
@ -1776,7 +1785,7 @@ rtp_error_t uvgrtp::rtcp::send_bye_packet(std::vector<uint32_t> ssrcs)
|
|||
}
|
||||
|
||||
rtp_error_t uvgrtp::rtcp::send_app_packet(const char* name, uint8_t subtype,
|
||||
size_t payload_len, const uint8_t* payload)
|
||||
uint32_t payload_len, const uint8_t* payload)
|
||||
{
|
||||
packet_mutex_.lock();
|
||||
if (!app_packets_[name].empty())
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
#include "debug.hh"
|
||||
|
||||
|
||||
size_t uvgrtp::get_sr_packet_size(int rce_flags, uint16_t reports)
|
||||
uint32_t uvgrtp::get_sr_packet_size(int rce_flags, uint16_t reports)
|
||||
{
|
||||
/* Sender report is otherwise identical with receiver report,
|
||||
* but it also includes sender info */
|
||||
return get_rr_packet_size(rce_flags, reports) + SENDER_INFO_SIZE;
|
||||
}
|
||||
|
||||
size_t uvgrtp::get_rr_packet_size(int rce_flags, uint16_t reports)
|
||||
uint32_t uvgrtp::get_rr_packet_size(int rce_flags, uint16_t reports)
|
||||
{
|
||||
size_t size = (size_t)RTCP_HEADER_SIZE + SSRC_CSRC_SIZE
|
||||
uint32_t size = (size_t)RTCP_HEADER_SIZE + SSRC_CSRC_SIZE
|
||||
+ (size_t)REPORT_BLOCK_SIZE * reports;
|
||||
if (rce_flags & RCE_SRTP)
|
||||
{
|
||||
|
@ -24,17 +24,17 @@ size_t uvgrtp::get_rr_packet_size(int rce_flags, uint16_t reports)
|
|||
return size;
|
||||
}
|
||||
|
||||
size_t uvgrtp::get_app_packet_size(size_t payload_len)
|
||||
uint32_t uvgrtp::get_app_packet_size(uint32_t payload_len)
|
||||
{
|
||||
return RTCP_HEADER_SIZE + SSRC_CSRC_SIZE + APP_NAME_SIZE + payload_len;
|
||||
}
|
||||
|
||||
size_t uvgrtp::get_sdes_packet_size(const std::vector<uvgrtp::frame::rtcp_sdes_item>& items) {
|
||||
uint32_t uvgrtp::get_sdes_packet_size(const std::vector<uvgrtp::frame::rtcp_sdes_item>& items) {
|
||||
/* We currently only support having one source. If uvgRTP is used in a mixer, multiple sources
|
||||
* should be supported in SDES packet. */
|
||||
|
||||
size_t frame_size = RTCP_HEADER_SIZE + SSRC_CSRC_SIZE; // our ssrc
|
||||
frame_size += items.size() * 2; /* sdes item type + length, both take one byte */
|
||||
uint32_t frame_size = RTCP_HEADER_SIZE + SSRC_CSRC_SIZE; // our ssrc
|
||||
frame_size += (uint32_t)items.size() * 2; /* sdes item type + length, both take one byte */
|
||||
for (auto& item : items)
|
||||
{
|
||||
if (item.length <= 255)
|
||||
|
@ -54,14 +54,13 @@ size_t uvgrtp::get_sdes_packet_size(const std::vector<uvgrtp::frame::rtcp_sdes_i
|
|||
return frame_size;
|
||||
}
|
||||
|
||||
size_t uvgrtp::get_bye_packet_size(const std::vector<uint32_t>& ssrcs)
|
||||
uint32_t uvgrtp::get_bye_packet_size(const std::vector<uint32_t>& ssrcs)
|
||||
{
|
||||
return RTCP_HEADER_SIZE + ssrcs.size() * SSRC_CSRC_SIZE;
|
||||
return RTCP_HEADER_SIZE + (uint32_t)ssrcs.size() * SSRC_CSRC_SIZE;
|
||||
}
|
||||
|
||||
bool uvgrtp::construct_rtcp_header(uint8_t* frame, int& ptr, size_t packet_size,
|
||||
uint16_t secondField,
|
||||
uvgrtp::frame::RTCP_FRAME_TYPE frame_type)
|
||||
bool uvgrtp::construct_rtcp_header(uint8_t* frame, size_t& ptr, size_t packet_size,
|
||||
uint8_t secondField, uvgrtp::frame::RTCP_FRAME_TYPE frame_type)
|
||||
{
|
||||
if (packet_size > UINT16_MAX)
|
||||
{
|
||||
|
@ -75,9 +74,12 @@ bool uvgrtp::construct_rtcp_header(uint8_t* frame, int& ptr, size_t packet_size,
|
|||
return false;
|
||||
}
|
||||
|
||||
uint8_t v = 2;
|
||||
uint8_t p = 0;
|
||||
|
||||
// header |V=2|P| SC | PT | length |
|
||||
frame[ptr] = (2 << 6) | (0 << 5) | secondField;
|
||||
frame[ptr + 1] = frame_type;
|
||||
frame[ptr] = (v << 6) | (p << 5) | secondField;
|
||||
frame[ptr + 1] = (uint8_t)frame_type;
|
||||
|
||||
// The RTCP header length field is measured in 32-bit words - 1
|
||||
*(uint16_t*)&frame[ptr + 2] = htons((uint16_t)packet_size / sizeof(uint32_t) - 1);
|
||||
|
@ -86,13 +88,13 @@ bool uvgrtp::construct_rtcp_header(uint8_t* frame, int& ptr, size_t packet_size,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool uvgrtp::construct_ssrc(uint8_t* frame, int& ptr, uint32_t ssrc)
|
||||
bool uvgrtp::construct_ssrc(uint8_t* frame, size_t& ptr, uint32_t ssrc)
|
||||
{
|
||||
SET_NEXT_FIELD_32(frame, ptr, htonl(ssrc));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool uvgrtp::construct_sender_info(uint8_t* frame, int& ptr, uint64_t ntp_ts, uint64_t rtp_ts,
|
||||
bool uvgrtp::construct_sender_info(uint8_t* frame, size_t& ptr, uint64_t ntp_ts, uint64_t rtp_ts,
|
||||
uint32_t sent_packets, uint32_t sent_bytes)
|
||||
{
|
||||
SET_NEXT_FIELD_32(frame, ptr, htonl(ntp_ts >> 32)); // NTP ts msw
|
||||
|
@ -104,7 +106,7 @@ bool uvgrtp::construct_sender_info(uint8_t* frame, int& ptr, uint64_t ntp_ts, ui
|
|||
return true;
|
||||
}
|
||||
|
||||
bool uvgrtp::construct_report_block(uint8_t* frame, int& ptr, uint32_t ssrc, uint8_t fraction,
|
||||
bool uvgrtp::construct_report_block(uint8_t* frame, size_t& ptr, uint32_t ssrc, uint8_t fraction,
|
||||
uint32_t dropped_packets, uint16_t seq_cycles, uint16_t max_seq, uint32_t jitter,
|
||||
uint32_t lsr, uint32_t dlsr)
|
||||
{
|
||||
|
@ -118,7 +120,7 @@ bool uvgrtp::construct_report_block(uint8_t* frame, int& ptr, uint32_t ssrc, uin
|
|||
return true;
|
||||
}
|
||||
|
||||
bool uvgrtp::construct_app_packet(uint8_t* frame, int& ptr,
|
||||
bool uvgrtp::construct_app_packet(uint8_t* frame, size_t& ptr,
|
||||
const char* name, const uint8_t* payload, size_t payload_len)
|
||||
{
|
||||
memcpy(&frame[ptr], name, APP_NAME_SIZE);
|
||||
|
@ -128,7 +130,7 @@ bool uvgrtp::construct_app_packet(uint8_t* frame, int& ptr,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool uvgrtp::construct_sdes_chunk(uint8_t* frame, int& ptr,
|
||||
bool uvgrtp::construct_sdes_chunk(uint8_t* frame, size_t& ptr,
|
||||
uvgrtp::frame::rtcp_sdes_chunk chunk) {
|
||||
|
||||
bool have_cname = false;
|
||||
|
@ -161,7 +163,7 @@ bool uvgrtp::construct_sdes_chunk(uint8_t* frame, int& ptr,
|
|||
return have_cname;
|
||||
}
|
||||
|
||||
bool uvgrtp::construct_bye_packet(uint8_t* frame, int& ptr, const std::vector<uint32_t>& ssrcs)
|
||||
bool uvgrtp::construct_bye_packet(uint8_t* frame, size_t& ptr, const std::vector<uint32_t>& ssrcs)
|
||||
{
|
||||
for (auto& ssrc : ssrcs)
|
||||
{
|
||||
|
|
|
@ -13,35 +13,35 @@ namespace uvgrtp
|
|||
const uint16_t REPORT_BLOCK_SIZE = 24;
|
||||
const uint16_t APP_NAME_SIZE = 4;
|
||||
|
||||
size_t get_sr_packet_size(int rce_flags, uint16_t reports);
|
||||
size_t get_rr_packet_size(int rce_flags, uint16_t reports);
|
||||
size_t get_sdes_packet_size(const std::vector<uvgrtp::frame::rtcp_sdes_item>& items);
|
||||
size_t get_app_packet_size(size_t payload_len);
|
||||
size_t get_bye_packet_size(const std::vector<uint32_t>& ssrcs);
|
||||
uint32_t get_sr_packet_size(int rce_flags, uint16_t reports);
|
||||
uint32_t get_rr_packet_size(int rce_flags, uint16_t reports);
|
||||
uint32_t get_sdes_packet_size(const std::vector<uvgrtp::frame::rtcp_sdes_item>& items);
|
||||
uint32_t get_app_packet_size(uint32_t payload_len);
|
||||
uint32_t get_bye_packet_size(const std::vector<uint32_t>& ssrcs);
|
||||
|
||||
// Add the RTCP header
|
||||
bool construct_rtcp_header(uint8_t* frame, int& ptr, size_t packet_size,
|
||||
uint16_t secondField, uvgrtp::frame::RTCP_FRAME_TYPE frame_type);
|
||||
bool construct_rtcp_header(uint8_t* frame, size_t& ptr, size_t packet_size,
|
||||
uint8_t secondField, uvgrtp::frame::RTCP_FRAME_TYPE frame_type);
|
||||
|
||||
// Add an ssrc to packet, not present in all packets
|
||||
bool construct_ssrc(uint8_t* frame, int& ptr, uint32_t ssrc);
|
||||
bool construct_ssrc(uint8_t* frame, size_t& ptr, uint32_t ssrc);
|
||||
|
||||
// Add sender info for sender report
|
||||
bool construct_sender_info(uint8_t* frame, int& ptr,
|
||||
bool construct_sender_info(uint8_t* frame, size_t& ptr,
|
||||
uint64_t ntp_ts, uint64_t rtp_ts, uint32_t sent_packets, uint32_t sent_bytes);
|
||||
|
||||
// Add one report block for sender or receiver report
|
||||
bool construct_report_block(uint8_t* frame, int& ptr, uint32_t ssrc, uint8_t fraction,
|
||||
bool construct_report_block(uint8_t* frame, size_t& ptr, uint32_t ssrc, uint8_t fraction,
|
||||
uint32_t dropped_packets, uint16_t seq_cycles, uint16_t max_seq, uint32_t jitter,
|
||||
uint32_t lsr, uint32_t dlsr);
|
||||
|
||||
// Add the items to the frame
|
||||
bool construct_sdes_chunk(uint8_t* frame, int& ptr, uvgrtp::frame::rtcp_sdes_chunk chunk);
|
||||
bool construct_sdes_chunk(uint8_t* frame, size_t& ptr, uvgrtp::frame::rtcp_sdes_chunk chunk);
|
||||
|
||||
// Add the name and payload to APP packet, remember to also add SSRC separately
|
||||
bool construct_app_packet(uint8_t* frame, int& ptr,
|
||||
bool construct_app_packet(uint8_t* frame, size_t& ptr,
|
||||
const char* name, const uint8_t* payload, size_t payload_len);
|
||||
|
||||
// Add BYE ssrcs, should probably be removed
|
||||
bool construct_bye_packet(uint8_t* frame, int& ptr, const std::vector<uint32_t>& ssrcs);
|
||||
bool construct_bye_packet(uint8_t* frame, size_t& ptr, const std::vector<uint32_t>& ssrcs);
|
||||
}
|
13
src/rtp.cc
13
src/rtp.cc
|
@ -46,7 +46,8 @@ uint16_t uvgrtp::rtp::get_sequence() const
|
|||
|
||||
void uvgrtp::rtp::set_payload(rtp_format_t fmt)
|
||||
{
|
||||
payload_ = fmt_ = fmt;
|
||||
fmt_ = fmt;
|
||||
payload_ = (uint8_t)fmt;
|
||||
|
||||
switch (fmt_) {
|
||||
case RTP_FORMAT_H264:
|
||||
|
@ -117,7 +118,9 @@ void uvgrtp::rtp::fill_header(uint8_t *buffer)
|
|||
std::chrono::microseconds time_since_start =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(t1 - wc_start_);
|
||||
|
||||
uint32_t rtp_timestamp = ts_ + time_since_start.count() * clock_rate_ / 1000000;
|
||||
uint64_t u_seconds = time_since_start.count() * clock_rate_;
|
||||
|
||||
uint32_t rtp_timestamp = ts_ + uint32_t(u_seconds / 1000000);
|
||||
|
||||
*(uint32_t *)&buffer[4] = htonl((u_long)rtp_timestamp);
|
||||
|
||||
|
@ -181,8 +184,12 @@ rtp_error_t uvgrtp::rtp::packet_handler(ssize_t size, void *packet, int rce_flag
|
|||
return RTP_PKT_NOT_HANDLED;
|
||||
}
|
||||
|
||||
if (!(*out = uvgrtp::frame::alloc_rtp_frame()))
|
||||
*out = uvgrtp::frame::alloc_rtp_frame();
|
||||
|
||||
if (*out == nullptr)
|
||||
{
|
||||
return RTP_GENERIC_ERROR;
|
||||
}
|
||||
|
||||
(*out)->header.version = (ptr[0] >> 6) & 0x03;
|
||||
(*out)->header.padding = (ptr[0] >> 5) & 0x01;
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace uvgrtp {
|
|||
uint32_t ssrc_;
|
||||
uint32_t ts_;
|
||||
uint16_t seq_;
|
||||
uint8_t fmt_;
|
||||
rtp_format_t fmt_;
|
||||
uint8_t payload_;
|
||||
|
||||
uint32_t clock_rate_;
|
||||
|
|
|
@ -31,7 +31,7 @@ uvgrtp::session::~session()
|
|||
streams_.clear();
|
||||
}
|
||||
|
||||
uvgrtp::media_stream *uvgrtp::session::create_stream(int r_port, int s_port, rtp_format_t fmt, int rce_flags)
|
||||
uvgrtp::media_stream *uvgrtp::session::create_stream(uint16_t r_port, uint16_t s_port, rtp_format_t fmt, int rce_flags)
|
||||
{
|
||||
std::lock_guard<std::mutex> m(session_mtx_);
|
||||
|
||||
|
|
|
@ -29,9 +29,16 @@ using namespace mingw;
|
|||
#define WSABUF_SIZE 256
|
||||
|
||||
uvgrtp::socket::socket(int rce_flags):
|
||||
socket_(-1),
|
||||
socket_(0),
|
||||
remote_address_(),
|
||||
local_address_(),
|
||||
rce_flags_(rce_flags),
|
||||
local_address_()
|
||||
#ifdef _WIN32
|
||||
buffers_()
|
||||
#else
|
||||
header_(),
|
||||
chunks_()
|
||||
#endif
|
||||
{}
|
||||
|
||||
uvgrtp::socket::~socket()
|
||||
|
@ -72,7 +79,9 @@ rtp_error_t uvgrtp::socket::init(short family, int type, int protocol)
|
|||
rtp_error_t uvgrtp::socket::setsockopt(int level, int optname, const void *optval, socklen_t optlen)
|
||||
{
|
||||
if (::setsockopt(socket_, level, optname, (const char *)optval, optlen) < 0) {
|
||||
UVG_LOG_ERROR("Failed to set socket options: %s", strerror(errno));
|
||||
|
||||
//strerror(errno), depricated
|
||||
UVG_LOG_ERROR("Failed to set socket options");
|
||||
return RTP_GENERIC_ERROR;
|
||||
}
|
||||
|
||||
|
@ -570,7 +579,8 @@ rtp_error_t uvgrtp::socket::__recv(uint8_t *buf, size_t buf_len, int recv_flags,
|
|||
|
||||
set_bytes(bytes_read, ret);
|
||||
#else
|
||||
|
||||
(void)recv_flags;
|
||||
|
||||
WSABUF DataBuf;
|
||||
DataBuf.len = (u_long)buf_len;
|
||||
DataBuf.buf = (char *)buf;
|
||||
|
@ -634,6 +644,9 @@ rtp_error_t uvgrtp::socket::__recvfrom(uint8_t *buf, size_t buf_len, int recv_fl
|
|||
|
||||
set_bytes(bytes_read, ret);
|
||||
#else
|
||||
|
||||
(void)recv_flags;
|
||||
|
||||
WSABUF DataBuf;
|
||||
DataBuf.len = (u_long)buf_len;
|
||||
DataBuf.buf = (char *)buf;
|
||||
|
|
|
@ -104,9 +104,9 @@ rtp_error_t uvgrtp::base_srtp::init(int type, int rce_flags, uint8_t* local_key,
|
|||
return RTP_OK;
|
||||
}
|
||||
|
||||
size_t uvgrtp::base_srtp::get_key_size(int rce_flags) const
|
||||
uint32_t uvgrtp::base_srtp::get_key_size(int rce_flags) const
|
||||
{
|
||||
size_t key_size = AES128_KEY_SIZE;
|
||||
uint32_t key_size = AES128_KEY_SIZE;
|
||||
|
||||
if (!(rce_flags & RCE_SRTP_KMNGMNT_ZRTP))
|
||||
{
|
||||
|
|
|
@ -65,12 +65,12 @@ namespace uvgrtp {
|
|||
|
||||
// Master key and salt used to derive session keys
|
||||
uint8_t* master_key = nullptr;
|
||||
uint8_t master_salt[UVG_SALT_LENGTH];
|
||||
uint8_t master_salt[UVG_SALT_LENGTH] = {};
|
||||
|
||||
// Session keys are used to encrypt/authenticate packets
|
||||
uint8_t* enc_key = nullptr;
|
||||
uint8_t auth_key[UVG_AUTH_LENGTH];
|
||||
uint8_t salt_key[UVG_SALT_LENGTH];
|
||||
uint8_t auth_key[UVG_AUTH_LENGTH] = {};
|
||||
uint8_t salt_key[UVG_SALT_LENGTH] = {};
|
||||
|
||||
int type = 0; /* srtp or srtcp */
|
||||
uint32_t roc = 0; /* rollover counter */
|
||||
|
@ -122,7 +122,7 @@ namespace uvgrtp {
|
|||
* Returns false if replay protection has not been enabled */
|
||||
bool is_replayed_packet(uint8_t *digest);
|
||||
|
||||
size_t get_key_size(int rce_flags) const;
|
||||
uint32_t get_key_size(int rce_flags) const;
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -15,15 +15,15 @@ uvgrtp::srtcp::~srtcp()
|
|||
{
|
||||
}
|
||||
|
||||
rtp_error_t uvgrtp::srtcp::handle_rtcp_encryption(int rce_flags, uint64_t packet_number,
|
||||
uint32_t ssrc, uint8_t* frame, size_t frame_size)
|
||||
rtp_error_t uvgrtp::srtcp::handle_rtcp_encryption(int rce_flags, uint32_t packet_number,
|
||||
uint32_t ssrc, uint8_t* frame, uint32_t frame_size)
|
||||
{
|
||||
auto ret = RTP_OK;
|
||||
|
||||
/* Encrypt the packet if NULL cipher has not been enabled,
|
||||
* calculate authentication tag for the packet and add SRTCP index at the end */
|
||||
if (rce_flags & RCE_SRTP) {
|
||||
if (!(RCE_SRTP & RCE_SRTP_NULL_CIPHER)) {
|
||||
if (!(rce_flags & RCE_SRTP_NULL_CIPHER)) {
|
||||
ret = encrypt(ssrc, packet_number, &frame[8],
|
||||
frame_size - 8 - UVG_SRTCP_INDEX_LENGTH - UVG_AUTH_TAG_LENGTH);
|
||||
SET_FIELD_32(frame, frame_size - UVG_SRTCP_INDEX_LENGTH - UVG_AUTH_TAG_LENGTH,
|
||||
|
|
|
@ -12,8 +12,8 @@ namespace uvgrtp {
|
|||
*
|
||||
* Report RTP_OK on succes
|
||||
* Return RTP_INVALID_VALUE if IV creation fails */
|
||||
rtp_error_t handle_rtcp_encryption(int rce_flags, uint64_t packet_number,
|
||||
uint32_t ssrc, uint8_t* frame, size_t frame_size);
|
||||
rtp_error_t handle_rtcp_encryption(int rce_flags, uint32_t packet_number,
|
||||
uint32_t ssrc, uint8_t* frame, uint32_t frame_size);
|
||||
|
||||
/* Decrypt and verify the authenticity of the RTCP packet
|
||||
*
|
||||
|
|
|
@ -26,6 +26,8 @@ using namespace uvgrtp::zrtp_msg;
|
|||
#define ZRTP_VERSION 110
|
||||
|
||||
uvgrtp::zrtp::zrtp():
|
||||
ssrc_(0),
|
||||
remote_addr_(),
|
||||
initialized_(false),
|
||||
receiver_()
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "uvgrtp/socket.hh"
|
||||
|
||||
#include "../debug.hh"
|
||||
#include "../crypto.hh""
|
||||
#include "../crypto.hh"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
|
|
@ -30,6 +30,10 @@ uvgrtp::zrtp_msg::confack::~confack()
|
|||
rtp_error_t uvgrtp::zrtp_msg::confack::parse_msg(uvgrtp::zrtp_msg::receiver& receiver,
|
||||
zrtp_session_t& session)
|
||||
{
|
||||
(void)session;
|
||||
|
||||
// TODO
|
||||
|
||||
ssize_t len = 0;
|
||||
allocate_rframe(sizeof(zrtp_confack));
|
||||
|
||||
|
|
|
@ -174,16 +174,16 @@ namespace uvgrtp {
|
|||
typedef struct zrtp_secrets {
|
||||
/* Retained (for uvgRTP, preshared mode is not supported so we're
|
||||
* going to generate just some random values for these) */
|
||||
uint8_t rs1[32];
|
||||
uint8_t rs2[32];
|
||||
uint8_t raux[32];
|
||||
uint8_t rpbx[32];
|
||||
uint8_t rs1[32] = {};
|
||||
uint8_t rs2[32] = {};
|
||||
uint8_t raux[32] = {};
|
||||
uint8_t rpbx[32] = {};
|
||||
|
||||
/* Shared secrets
|
||||
*
|
||||
* Because uvgRTP supports only DH mode,
|
||||
* other shared secrets (s1 - s3) are null */
|
||||
uint8_t s0[32];
|
||||
uint8_t s0[32] = {};
|
||||
uint8_t* s1 = nullptr;
|
||||
uint8_t* s2 = nullptr;
|
||||
uint8_t* s3 = nullptr;
|
||||
|
@ -250,27 +250,27 @@ namespace uvgrtp {
|
|||
uint32_t sas_type = 0;
|
||||
|
||||
/* Session capabilities */
|
||||
zrtp_capab_t capabilities;
|
||||
zrtp_capab_t capabilities = {};
|
||||
|
||||
/* Various hash values of the ZRTP session */
|
||||
zrtp_hash_ctx_t hash_ctx;
|
||||
zrtp_hash_ctx_t hash_ctx = {};
|
||||
|
||||
/* DH-related variables */
|
||||
zrtp_dh_ctx_t dh_ctx;
|
||||
zrtp_dh_ctx_t dh_ctx = {};
|
||||
|
||||
/* ZRTP keying material (for HMAC/AES etc) */
|
||||
zrtp_key_ctx_t key_ctx;
|
||||
zrtp_key_ctx_t key_ctx = {};
|
||||
|
||||
/* Retained and shared secrets of the ZRTP session */
|
||||
zrtp_secrets_t secrets;
|
||||
zrtp_secrets_t secrets = {};
|
||||
|
||||
uint8_t o_zid[12]; /* our ZID */
|
||||
uint8_t r_zid[12]; /* remote ZID */
|
||||
|
||||
/* Pointers to messages sent by us and messages received from remote.
|
||||
* These are used to calculate various hash values */
|
||||
zrtp_messages_t l_msg;
|
||||
zrtp_messages_t r_msg;
|
||||
zrtp_messages_t l_msg = {};
|
||||
zrtp_messages_t r_msg = {};
|
||||
} zrtp_session_t;
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ rtp_error_t uvgrtp::zrtp_msg::error::parse_msg(uvgrtp::zrtp_msg::receiver& recei
|
|||
zrtp_session_t& session)
|
||||
{
|
||||
(void)receiver;
|
||||
(void)session;
|
||||
|
||||
/* TODO: */
|
||||
|
||||
|
|
|
@ -27,6 +27,9 @@ rtp_error_t uvgrtp::zrtp_msg::hello_ack::parse_msg(uvgrtp::zrtp_msg::receiver& r
|
|||
zrtp_session_t& session)
|
||||
{
|
||||
(void)receiver;
|
||||
(void)session;
|
||||
|
||||
// TODO?
|
||||
|
||||
return RTP_OK;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ namespace uvgrtp {
|
|||
|
||||
rtp_error_t send_msg(std::shared_ptr<uvgrtp::socket> socket, sockaddr_in& addr);
|
||||
|
||||
/* TODO: description */
|
||||
virtual rtp_error_t parse_msg(uvgrtp::zrtp_msg::receiver& receiver,
|
||||
zrtp_session_t& session) = 0;
|
||||
|
||||
|
|
|
@ -30,11 +30,11 @@
|
|||
|
||||
using namespace uvgrtp::zrtp_msg;
|
||||
|
||||
uvgrtp::zrtp_msg::receiver::receiver()
|
||||
{
|
||||
mem_ = new uint8_t[1024];
|
||||
len_ = 1024;
|
||||
}
|
||||
uvgrtp::zrtp_msg::receiver::receiver():
|
||||
mem_(new uint8_t[1024]),
|
||||
len_(1024),
|
||||
rlen_(0)
|
||||
{}
|
||||
|
||||
uvgrtp::zrtp_msg::receiver::~receiver()
|
||||
{
|
||||
|
@ -59,6 +59,9 @@ rtp_error_t uvgrtp::zrtp_msg::receiver::recv_msg(std::shared_ptr<uvgrtp::socket>
|
|||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
(void)recv_flags;
|
||||
|
||||
if ((ret = uvgrtp::poll::blocked_recv(socket, mem_, len_, timeout, &nread)) != RTP_OK) {
|
||||
if (ret == RTP_INTERRUPTED)
|
||||
return ret;
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace uvgrtp {
|
|||
rtp_error_t recv_msg(std::shared_ptr<uvgrtp::socket> socket, int timeout, int recv_flags,
|
||||
int& out_type);
|
||||
|
||||
/* TODO: */
|
||||
// get received message to ptr. Len is the size of buffer in ptr.
|
||||
ssize_t get_msg(void *ptr, size_t len);
|
||||
|
||||
/* ZRTP packet handler is used after ZRTP state initialization has finished
|
||||
|
|
Loading…
Reference in New Issue