common: Add const qualifiers where applicable

This commit is contained in:
Joni Räsänen 2022-05-16 12:02:37 +03:00
parent a6f9afcd28
commit 088fc585ed
14 changed files with 82 additions and 95 deletions

View File

@ -80,7 +80,7 @@ namespace uvgrtp {
private: private:
/* Generate CNAME for participant using host and login names */ /* Generate CNAME for participant using host and login names */
std::string generate_cname(); std::string generate_cname() const;
/* CNAME is the same for all connections */ /* CNAME is the same for all connections */
std::string cname_; std::string cname_;

View File

@ -52,10 +52,10 @@ namespace uvgrtp {
namespace hmac { namespace hmac {
class sha1 { class sha1 {
public: public:
sha1(uint8_t *key, size_t key_size); sha1(const uint8_t *key, size_t key_size);
~sha1(); ~sha1();
void update(uint8_t *data, size_t len); void update(const uint8_t *data, size_t len);
void final(uint8_t *digest); void final(uint8_t *digest);
/* truncate digest to "size" bytes */ /* truncate digest to "size" bytes */
@ -69,10 +69,10 @@ namespace uvgrtp {
class sha256 { class sha256 {
public: public:
sha256(uint8_t *key, size_t key_size); sha256(const uint8_t *key, size_t key_size);
~sha256(); ~sha256();
void update(uint8_t *data, size_t len); void update(const uint8_t *data, size_t len);
void final(uint8_t *digest); void final(uint8_t *digest);
private: private:
@ -87,7 +87,7 @@ namespace uvgrtp {
sha256(); sha256();
~sha256(); ~sha256();
void update(uint8_t *data, size_t len); void update(const uint8_t *data, size_t len);
void final(uint8_t *digest); void final(uint8_t *digest);
private: private:
@ -100,11 +100,11 @@ namespace uvgrtp {
class ecb { class ecb {
public: public:
ecb(uint8_t *key, size_t key_size); ecb(const uint8_t *key, size_t key_size);
~ecb(); ~ecb();
void encrypt(uint8_t *output, uint8_t *input, size_t len); void encrypt(uint8_t *output, const uint8_t *input, size_t len);
void decrypt(uint8_t *output, uint8_t *input, size_t len); void decrypt(uint8_t *output, const uint8_t *input, size_t len);
private: private:
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
@ -115,11 +115,11 @@ namespace uvgrtp {
class cfb { class cfb {
public: public:
cfb(uint8_t *key, size_t key_size, uint8_t *iv); cfb(const uint8_t *key, size_t key_size, const uint8_t *iv);
~cfb(); ~cfb();
void encrypt(uint8_t *output, uint8_t *input, size_t len); void encrypt(uint8_t *output, const uint8_t *input, size_t len);
void decrypt(uint8_t *output, uint8_t *input, size_t len); void decrypt(uint8_t *output, const uint8_t *input, size_t len);
private: private:
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
@ -130,11 +130,11 @@ namespace uvgrtp {
class ctr { class ctr {
public: public:
ctr(uint8_t *key, size_t key_size, uint8_t *iv); ctr(const uint8_t *key, size_t key_size, const uint8_t *iv);
~ctr(); ~ctr();
void encrypt(uint8_t *output, uint8_t *input, size_t len); void encrypt(uint8_t *output, const uint8_t *input, size_t len);
void decrypt(uint8_t *output, uint8_t *input, size_t len); void decrypt(uint8_t *output, const uint8_t *input, size_t len);
private: private:
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
@ -176,7 +176,7 @@ namespace uvgrtp {
b32(); b32();
~b32(); ~b32();
void encode(uint8_t *input, uint8_t *output, size_t len); void encode(const uint8_t *input, uint8_t *output, size_t len);
private: private:
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
@ -189,9 +189,9 @@ namespace uvgrtp {
} }
namespace crc32 { namespace crc32 {
void get_crc32(uint8_t *input, size_t len, uint32_t *output); void get_crc32(const uint8_t *input, size_t len, uint32_t *output);
bool verify_crc32(uint8_t *input, size_t len, uint32_t old_crc); bool verify_crc32(const uint8_t *input, size_t len, uint32_t old_crc);
uint32_t calculate_crc32(uint8_t *input, size_t len); uint32_t calculate_crc32(const uint8_t *input, size_t len);
} }
bool enabled(); bool enabled();

View File

@ -279,7 +279,7 @@ namespace uvgrtp {
/* Get unique key of the media stream /* Get unique key of the media stream
* Used by session to index media streams */ * Used by session to index media streams */
uint32_t get_key(); uint32_t get_key() const;
/// \endcond /// \endcond
/** /**

View File

@ -119,7 +119,7 @@ namespace uvgrtp {
* \retval RTP_MEMORY_ERROR If allocation fails * \retval RTP_MEMORY_ERROR If allocation fails
* \retval RTP_GENERIC_ERROR If sending fails * \retval RTP_GENERIC_ERROR If sending fails
*/ */
rtp_error_t send_sdes_packet(std::vector<uvgrtp::frame::rtcp_sdes_item>& items); rtp_error_t send_sdes_packet(const std::vector<uvgrtp::frame::rtcp_sdes_item>& items);
/** /**
* \brief Send an RTCP APP packet * \brief Send an RTCP APP packet
@ -133,7 +133,7 @@ namespace uvgrtp {
* \retval RTP_MEMORY_ERROR If allocation fails * \retval RTP_MEMORY_ERROR If allocation fails
* \retval RTP_GENERIC_ERROR If sending fails * \retval RTP_GENERIC_ERROR If sending fails
*/ */
rtp_error_t send_app_packet(char *name, uint8_t subtype, size_t payload_len, uint8_t *payload); rtp_error_t send_app_packet(const char *name, uint8_t subtype, size_t payload_len, const uint8_t *payload);
/** /**
* \brief Send an RTCP BYE packet * \brief Send an RTCP BYE packet
@ -175,22 +175,7 @@ namespace uvgrtp {
rtp_error_t add_participant(std::string dst_addr, uint16_t dst_port, uint16_t src_port, uint32_t clock_rate); rtp_error_t add_participant(std::string dst_addr, uint16_t dst_port, uint16_t src_port, uint32_t clock_rate);
/* Functions for updating various RTP sender statistics */ /* Functions for updating various RTP sender statistics */
void sender_inc_seq_cycle_count(); void sender_update_stats(const uvgrtp::frame::rtp_frame *frame);
void sender_inc_sent_pkts(size_t n);
void sender_inc_sent_bytes(size_t n);
void sender_update_stats(uvgrtp::frame::rtp_frame *frame);
void receiver_inc_sent_bytes(uint32_t sender_ssrc, size_t n);
void receiver_inc_overhead_bytes(uint32_t sender_ssrc, size_t n);
void receiver_inc_total_bytes(uint32_t sender_ssrc, size_t n);
void receiver_inc_sent_pkts(uint32_t sender_ssrc, size_t n);
/* Update the RTCP statistics regarding this packet
*
* Return RTP_OK if packet is valid
* Return RTP_INVALID_VALUE if SSRCs of remotes have collided or the packet is invalid in some way
* return RTP_SSRC_COLLISION if our own SSRC has collided and we need to reinitialize it */
rtp_error_t receiver_update_stats(uvgrtp::frame::rtp_frame *frame);
/* If we've detected that our SSRC has collided with someone else's SSRC, we need to /* If we've detected that our SSRC has collided with someone else's SSRC, we need to
* generate new random SSRC and reinitialize our own RTCP state. * generate new random SSRC and reinitialize our own RTCP state.
@ -202,10 +187,10 @@ namespace uvgrtp {
rtp_error_t reset_rtcp_state(uint32_t ssrc); rtp_error_t reset_rtcp_state(uint32_t ssrc);
/* Update various session statistics */ /* Update various session statistics */
void update_session_statistics(uvgrtp::frame::rtp_frame *frame); void update_session_statistics(const uvgrtp::frame::rtp_frame *frame);
/* Return SSRCs of all participants */ /* Return SSRCs of all participants */
std::vector<uint32_t> get_participants(); std::vector<uint32_t> get_participants() const;
/// \endcond /// \endcond
/** /**
@ -318,7 +303,7 @@ namespace uvgrtp {
/* when we start the RTCP instance, we don't know what the SSRC of the remote is /* when we start the RTCP instance, we don't know what the SSRC of the remote is
* when an RTP packet is received, we must check if we've already received a packet * when an RTP packet is received, we must check if we've already received a packet
* from this sender and if not, create new entry to receiver_stats_ map */ * from this sender and if not, create new entry to receiver_stats_ map */
bool is_participant(uint32_t ssrc); bool is_participant(uint32_t ssrc) const;
/* When we receive an RTP or RTCP packet, we need to check the source address and see if it's /* When we receive an RTP or RTCP packet, we need to check the source address and see if it's
* the same address where we've received packets before. * the same address where we've received packets before.
@ -326,14 +311,14 @@ namespace uvgrtp {
* If the address is new, it means we have detected an SSRC collision and the paket should * If the address is new, it means we have detected an SSRC collision and the paket should
* be dropped We also need to check whether this SSRC matches with our own SSRC and if it does * be dropped We also need to check whether this SSRC matches with our own SSRC and if it does
* we need to send RTCP BYE and rejoin to the session */ * we need to send RTCP BYE and rejoin to the session */
bool collision_detected(uint32_t ssrc, sockaddr_in& src_addr); bool collision_detected(uint32_t ssrc, const sockaddr_in& src_addr) const;
/* Move participant from initial_peers_ to participants_ */ /* Move participant from initial_peers_ to participants_ */
rtp_error_t add_participant(uint32_t ssrc); rtp_error_t add_participant(uint32_t ssrc);
/* We've got a message from new source (the SSRC of the frame is not known to us) /* We've got a message from new source (the SSRC of the frame is not known to us)
* Initialize statistics for the peer and move it to participants_ */ * Initialize statistics for the peer and move it to participants_ */
rtp_error_t init_new_participant(uvgrtp::frame::rtp_frame *frame); rtp_error_t init_new_participant(const uvgrtp::frame::rtp_frame *frame);
/* Initialize the RTP Sequence related stuff of peer /* Initialize the RTP Sequence related stuff of peer
* This function assumes that the peer already exists in the participants_ map */ * This function assumes that the peer already exists in the participants_ map */
@ -364,8 +349,8 @@ namespace uvgrtp {
uint16_t secondField, uvgrtp::frame::RTCP_FRAME_TYPE frame_type, bool addLocalSSRC); uint16_t secondField, uvgrtp::frame::RTCP_FRAME_TYPE frame_type, bool addLocalSSRC);
/* read the header values from rtcp packet */ /* read the header values from rtcp packet */
void read_rtcp_header(uint8_t* packet, uvgrtp::frame::rtcp_header& header); void read_rtcp_header(const uint8_t* packet, uvgrtp::frame::rtcp_header& header);
void read_reports(uint8_t* packet, size_t size, uint8_t count, bool has_sender_block, void read_reports(const uint8_t* packet, size_t size, uint8_t count, bool has_sender_block,
std::vector<uvgrtp::frame::rtcp_report_block>& reports); std::vector<uvgrtp::frame::rtcp_report_block>& reports);
/* Takes ownership of the frame */ /* Takes ownership of the frame */
@ -374,20 +359,17 @@ namespace uvgrtp {
void free_participant(rtcp_participant* participant); void free_participant(rtcp_participant* participant);
/* Pointer to RTP context from which clock rate etc. info is collected and which is
* used to change SSRC if a collision is detected */
std::shared_ptr<uvgrtp::rtp> rtp_;
/* Secure RTCP context */ /* Secure RTCP context */
std::shared_ptr<uvgrtp::srtcp> srtcp_; std::shared_ptr<uvgrtp::srtcp> srtcp_;
/* RTP context flags */ /* RTP context flags */
int flags_; int flags_;
/* are we a sender or a receiver */ /* are we a sender (and possible a receiver) or just a receiver */
int our_role_; int our_role_;
/* TODO: time_t?? */ /* TODO: time_t?? */
// TODO: Check these, they don't seem to be used
size_t tp_; /* the last time an RTCP packet was transmitted */ size_t tp_; /* the last time an RTCP packet was transmitted */
size_t tc_; /* the current time */ size_t tc_; /* the current time */
size_t tn_; /* the next scheduled transmission time of an RTCP packet */ size_t tn_; /* the next scheduled transmission time of an RTCP packet */
@ -399,19 +381,23 @@ namespace uvgrtp {
* that will be used for RTCP packets by all members of this session, * that will be used for RTCP packets by all members of this session,
* in octets per second. This will be a specified fraction of the * in octets per second. This will be a specified fraction of the
* "session bandwidth" parameter supplied to the application at startup. */ * "session bandwidth" parameter supplied to the application at startup. */
// TODO: Not used anywhere at the moment
size_t rtcp_bandwidth_; size_t rtcp_bandwidth_;
/* Flag that is true if the application has sent data since /* Flag that is true if the application has sent data since
* the 2nd previous RTCP report was transmitted. */ * the 2nd previous RTCP report was transmitted. */
// TODO: Only set, never read
bool we_sent_; bool we_sent_;
/* The average compound RTCP packet size, in octets, /* The average compound RTCP packet size, in octets,
* over all RTCP packets sent and received by this participant. The * over all RTCP packets sent and received by this participant. The
* size includes lower-layer transport and network protocol headers * size includes lower-layer transport and network protocol headers
* (e.g., UDP and IP) as explained in Section 6.2 */ * (e.g., UDP and IP) as explained in Section 6.2 */
// TODO: Only set, never read
size_t avg_rtcp_pkt_pize_; size_t avg_rtcp_pkt_pize_;
/* Number of RTCP packets and bytes sent and received by this participant */ /* Number of RTCP packets and bytes sent and received by this participant */
// TODO: Only set, never read
size_t rtcp_pkt_count_; size_t rtcp_pkt_count_;
size_t rtcp_byte_count_; size_t rtcp_byte_count_;
@ -419,10 +405,11 @@ namespace uvgrtp {
uint32_t rtcp_pkt_sent_count_; uint32_t rtcp_pkt_sent_count_;
/* Flag that is true if the application has not yet sent an RTCP packet. */ /* Flag that is true if the application has not yet sent an RTCP packet. */
// TODO: Only set, never read
bool initial_; bool initial_;
/* Copy of our own current SSRC */ /* Copy of our own current SSRC */
uint32_t ssrc_; const uint32_t ssrc_;
/* NTP timestamp associated with initial RTP timestamp (aka t = 0) */ /* NTP timestamp associated with initial RTP timestamp (aka t = 0) */
uint64_t clock_start_; uint64_t clock_start_;
@ -434,7 +421,7 @@ namespace uvgrtp {
uint32_t rtp_ts_start_; uint32_t rtp_ts_start_;
std::map<uint32_t, rtcp_participant *> participants_; std::map<uint32_t, rtcp_participant *> participants_;
uint8_t num_receivers_; // maximum is 32 (5 bits) uint8_t num_receivers_; // maximum is 32 at the moment (5 bits)
/* statistics for RTCP Sender and Receiver Reports */ /* statistics for RTCP Sender and Receiver Reports */
struct sender_statistics our_stats; struct sender_statistics our_stats;

View File

@ -64,7 +64,7 @@ rtp_error_t uvgrtp::context::destroy_session(uvgrtp::session *session)
return RTP_OK; return RTP_OK;
} }
std::string uvgrtp::context::generate_cname() std::string uvgrtp::context::generate_cname() const
{ {
std::string host = uvgrtp::hostname::get_hostname(); std::string host = uvgrtp::hostname::get_hostname();
std::string user = uvgrtp::hostname::get_username(); std::string user = uvgrtp::hostname::get_username();

View File

@ -7,7 +7,7 @@
/* ***************** hmac-sha1 ***************** */ /* ***************** hmac-sha1 ***************** */
uvgrtp::crypto::hmac::sha1::sha1(uint8_t *key, size_t key_size) uvgrtp::crypto::hmac::sha1::sha1(const uint8_t *key, size_t key_size)
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
:hmac_(key, key_size) :hmac_(key, key_size)
#endif #endif
@ -21,7 +21,7 @@ uvgrtp::crypto::hmac::sha1::~sha1()
{ {
} }
void uvgrtp::crypto::hmac::sha1::update(uint8_t *data, size_t len) void uvgrtp::crypto::hmac::sha1::update(const uint8_t *data, size_t len)
{ {
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
hmac_.Update(data, len); hmac_.Update(data, len);
@ -62,7 +62,7 @@ void uvgrtp::crypto::hmac::sha1::final(uint8_t *digest, size_t size)
/* ***************** hmac-sha256 ***************** */ /* ***************** hmac-sha256 ***************** */
uvgrtp::crypto::hmac::sha256::sha256(uint8_t *key, size_t key_size) uvgrtp::crypto::hmac::sha256::sha256(const uint8_t *key, size_t key_size)
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
:hmac_(key, key_size) :hmac_(key, key_size)
#endif #endif
@ -76,7 +76,7 @@ uvgrtp::crypto::hmac::sha256::~sha256()
{ {
} }
void uvgrtp::crypto::hmac::sha256::update(uint8_t *data, size_t len) void uvgrtp::crypto::hmac::sha256::update(const uint8_t *data, size_t len)
{ {
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
hmac_.Update(data, len); hmac_.Update(data, len);
@ -113,7 +113,7 @@ uvgrtp::crypto::sha256::~sha256()
{ {
} }
void uvgrtp::crypto::sha256::update(uint8_t *data, size_t len) void uvgrtp::crypto::sha256::update(const uint8_t *data, size_t len)
{ {
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
sha_.Update(data, len); sha_.Update(data, len);
@ -139,7 +139,7 @@ void uvgrtp::crypto::sha256::final(uint8_t *digest)
/* ***************** aes-128 ***************** */ /* ***************** aes-128 ***************** */
uvgrtp::crypto::aes::ctr::ctr(uint8_t *key, size_t key_size, uint8_t *iv) uvgrtp::crypto::aes::ctr::ctr(const uint8_t *key, size_t key_size, const uint8_t *iv)
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
:enc_(key, key_size, iv), :enc_(key, key_size, iv),
dec_(key, key_size, iv) dec_(key, key_size, iv)
@ -154,7 +154,7 @@ uvgrtp::crypto::aes::ctr::~ctr()
{ {
} }
void uvgrtp::crypto::aes::ctr::encrypt(uint8_t *output, uint8_t *input, size_t len) void uvgrtp::crypto::aes::ctr::encrypt(uint8_t *output, const uint8_t *input, size_t len)
{ {
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
enc_.ProcessData(output, input, len); enc_.ProcessData(output, input, len);
@ -166,7 +166,7 @@ void uvgrtp::crypto::aes::ctr::encrypt(uint8_t *output, uint8_t *input, size_t l
#endif #endif
} }
void uvgrtp::crypto::aes::ctr::decrypt(uint8_t *output, uint8_t *input, size_t len) void uvgrtp::crypto::aes::ctr::decrypt(uint8_t *output, const uint8_t *input, size_t len)
{ {
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
dec_.ProcessData(output, input, len); dec_.ProcessData(output, input, len);
@ -178,7 +178,7 @@ void uvgrtp::crypto::aes::ctr::decrypt(uint8_t *output, uint8_t *input, size_t l
#endif #endif
} }
uvgrtp::crypto::aes::cfb::cfb(uint8_t *key, size_t key_size, uint8_t *iv) uvgrtp::crypto::aes::cfb::cfb(const uint8_t *key, size_t key_size, const uint8_t *iv)
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
:enc_(key, key_size, iv), :enc_(key, key_size, iv),
dec_(key, key_size, iv) dec_(key, key_size, iv)
@ -193,7 +193,7 @@ uvgrtp::crypto::aes::cfb::~cfb()
{ {
} }
void uvgrtp::crypto::aes::cfb::encrypt(uint8_t *output, uint8_t *input, size_t len) void uvgrtp::crypto::aes::cfb::encrypt(uint8_t *output, const uint8_t *input, size_t len)
{ {
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
enc_.ProcessData(output, input, len); enc_.ProcessData(output, input, len);
@ -205,7 +205,7 @@ void uvgrtp::crypto::aes::cfb::encrypt(uint8_t *output, uint8_t *input, size_t l
#endif #endif
} }
void uvgrtp::crypto::aes::cfb::decrypt(uint8_t *output, uint8_t *input, size_t len) void uvgrtp::crypto::aes::cfb::decrypt(uint8_t *output, const uint8_t *input, size_t len)
{ {
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
dec_.ProcessData(output, input, len); dec_.ProcessData(output, input, len);
@ -217,7 +217,7 @@ void uvgrtp::crypto::aes::cfb::decrypt(uint8_t *output, uint8_t *input, size_t l
#endif #endif
} }
uvgrtp::crypto::aes::ecb::ecb(uint8_t *key, size_t key_size) uvgrtp::crypto::aes::ecb::ecb(const uint8_t *key, size_t key_size)
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
:enc_(key, key_size), :enc_(key, key_size),
dec_(key, key_size) dec_(key, key_size)
@ -232,7 +232,7 @@ uvgrtp::crypto::aes::ecb::~ecb()
{ {
} }
void uvgrtp::crypto::aes::ecb::encrypt(uint8_t *output, uint8_t *input, size_t len) void uvgrtp::crypto::aes::ecb::encrypt(uint8_t *output, const uint8_t *input, size_t len)
{ {
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
enc_.ProcessData(output, input, len); enc_.ProcessData(output, input, len);
@ -244,7 +244,7 @@ void uvgrtp::crypto::aes::ecb::encrypt(uint8_t *output, uint8_t *input, size_t l
#endif #endif
} }
void uvgrtp::crypto::aes::ecb::decrypt(uint8_t *output, uint8_t *input, size_t len) void uvgrtp::crypto::aes::ecb::decrypt(uint8_t *output, const uint8_t *input, size_t len)
{ {
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
dec_.ProcessData(output, input, len); dec_.ProcessData(output, input, len);
@ -382,7 +382,7 @@ uvgrtp::crypto::b32::~b32()
{ {
} }
void uvgrtp::crypto::b32::encode(uint8_t *input, uint8_t *output, size_t len) void uvgrtp::crypto::b32::encode(const uint8_t *input, uint8_t *output, size_t len)
{ {
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
enc_.Put(input, len); enc_.Put(input, len);
@ -418,7 +418,7 @@ void uvgrtp::crypto::random::generate_random(uint8_t *out, size_t len)
/* ***************** crc32 ***************** */ /* ***************** crc32 ***************** */
void uvgrtp::crypto::crc32::get_crc32(uint8_t *input, size_t len, uint32_t *output) void uvgrtp::crypto::crc32::get_crc32(const uint8_t *input, size_t len, uint32_t *output)
{ {
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
CryptoPP::CRC32 crc32; CryptoPP::CRC32 crc32;
@ -433,7 +433,7 @@ void uvgrtp::crypto::crc32::get_crc32(uint8_t *input, size_t len, uint32_t *outp
#endif #endif
} }
uint32_t uvgrtp::crypto::crc32::calculate_crc32(uint8_t *input, size_t len) uint32_t uvgrtp::crypto::crc32::calculate_crc32(const uint8_t *input, size_t len)
{ {
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
CryptoPP::CRC32 crc32; CryptoPP::CRC32 crc32;
@ -451,7 +451,7 @@ uint32_t uvgrtp::crypto::crc32::calculate_crc32(uint8_t *input, size_t len)
#endif #endif
} }
bool uvgrtp::crypto::crc32::verify_crc32(uint8_t *input, size_t len, uint32_t old_crc) bool uvgrtp::crypto::crc32::verify_crc32(const uint8_t *input, size_t len, uint32_t old_crc)
{ {
#ifdef __RTP_CRYPTO__ #ifdef __RTP_CRYPTO__
CryptoPP::CRC32 crc32; CryptoPP::CRC32 crc32;

View File

@ -574,7 +574,7 @@ rtp_error_t uvgrtp::media_stream::configure_ctx(int flag, ssize_t value)
return ret; return ret;
} }
uint32_t uvgrtp::media_stream::get_key() uint32_t uvgrtp::media_stream::get_key() const
{ {
return key_; return key_;
} }

View File

@ -75,7 +75,7 @@ void uvgrtp::reception_flow::destroy_ring_buffer()
ring_buffer_.clear(); ring_buffer_.clear();
} }
void uvgrtp::reception_flow::set_buffer_size(ssize_t& value) void uvgrtp::reception_flow::set_buffer_size(const ssize_t& value)
{ {
buffer_size_kbytes_ = value; buffer_size_kbytes_ = value;
create_ring_buffer(); create_ring_buffer();

View File

@ -145,7 +145,7 @@ namespace uvgrtp {
uvgrtp::frame::rtp_frame *pull_frame(); uvgrtp::frame::rtp_frame *pull_frame();
uvgrtp::frame::rtp_frame *pull_frame(size_t timeout_ms); uvgrtp::frame::rtp_frame *pull_frame(size_t timeout_ms);
void set_buffer_size(ssize_t& value); void set_buffer_size(const ssize_t& value);
private: private:
/* RTP packet receiver thread */ /* RTP packet receiver thread */

View File

@ -36,11 +36,12 @@ constexpr int ESTIMATED_MAX_RECEPTION_TIME_MS = 10;
const uint32_t MAX_SUPPORTED_PARTICIPANTS = 31; const uint32_t MAX_SUPPORTED_PARTICIPANTS = 31;
uvgrtp::rtcp::rtcp(std::shared_ptr<uvgrtp::rtp> rtp, int flags): uvgrtp::rtcp::rtcp(std::shared_ptr<uvgrtp::rtp> rtp, int flags):
rtp_(rtp), flags_(flags), our_role_(RECEIVER), flags_(flags), our_role_(RECEIVER),
tp_(0), tc_(0), tn_(0), pmembers_(0), tp_(0), tc_(0), tn_(0), pmembers_(0),
members_(0), senders_(0), rtcp_bandwidth_(0), members_(0), senders_(0), rtcp_bandwidth_(0),
we_sent_(0), avg_rtcp_pkt_pize_(0), rtcp_pkt_count_(0), we_sent_(false), avg_rtcp_pkt_pize_(0), rtcp_pkt_count_(0),
rtcp_pkt_sent_count_(0), initial_(true), num_receivers_(0), rtcp_pkt_sent_count_(0), initial_(true), ssrc_(rtp->get_ssrc()),
num_receivers_(0),
sender_hook_(nullptr), sender_hook_(nullptr),
receiver_hook_(nullptr), receiver_hook_(nullptr),
sdes_hook_(nullptr), sdes_hook_(nullptr),
@ -55,7 +56,6 @@ uvgrtp::rtcp::rtcp(std::shared_ptr<uvgrtp::rtp> rtp, int flags):
app_hook_u_(nullptr), app_hook_u_(nullptr),
active_(false) active_(false)
{ {
ssrc_ = rtp->get_ssrc();
clock_rate_ = rtp->get_clock_rate(); clock_rate_ = rtp->get_clock_rate();
clock_start_ = 0; clock_start_ = 0;
@ -595,7 +595,7 @@ std::vector<uvgrtp::socket>& uvgrtp::rtcp::get_sockets()
return sockets_; return sockets_;
} }
std::vector<uint32_t> uvgrtp::rtcp::get_participants() std::vector<uint32_t> uvgrtp::rtcp::get_participants() const
{ {
std::vector<uint32_t> ssrcs; std::vector<uint32_t> ssrcs;
@ -645,7 +645,7 @@ void uvgrtp::rtcp::zero_stats(uvgrtp::receiver_statistics *stats)
stats->cycles = 0; stats->cycles = 0;
} }
bool uvgrtp::rtcp::is_participant(uint32_t ssrc) bool uvgrtp::rtcp::is_participant(uint32_t ssrc) const
{ {
return participants_.find(ssrc) != participants_.end(); return participants_.find(ssrc) != participants_.end();
} }
@ -657,7 +657,7 @@ void uvgrtp::rtcp::set_ts_info(uint64_t clock_start, uint32_t clock_rate, uint32
rtp_ts_start_ = rtp_ts_start; rtp_ts_start_ = rtp_ts_start;
} }
void uvgrtp::rtcp::sender_update_stats(uvgrtp::frame::rtp_frame *frame) void uvgrtp::rtcp::sender_update_stats(const uvgrtp::frame::rtp_frame *frame)
{ {
if (!frame) if (!frame)
{ {
@ -675,7 +675,7 @@ void uvgrtp::rtcp::sender_update_stats(uvgrtp::frame::rtp_frame *frame)
our_stats.sent_rtp_packet = true; our_stats.sent_rtp_packet = true;
} }
rtp_error_t uvgrtp::rtcp::init_new_participant(uvgrtp::frame::rtp_frame *frame) rtp_error_t uvgrtp::rtcp::init_new_participant(const uvgrtp::frame::rtp_frame *frame)
{ {
rtp_error_t ret; rtp_error_t ret;
@ -809,14 +809,14 @@ rtp_error_t uvgrtp::rtcp::reset_rtcp_state(uint32_t ssrc)
return RTP_OK; return RTP_OK;
} }
bool uvgrtp::rtcp::collision_detected(uint32_t ssrc, sockaddr_in& src_addr) bool uvgrtp::rtcp::collision_detected(uint32_t ssrc, const sockaddr_in& src_addr) const
{ {
if (participants_.find(ssrc) == participants_.end()) if (participants_.find(ssrc) == participants_.end())
{ {
return false; return false;
} }
auto sender = participants_[ssrc]; auto sender = participants_.at(ssrc);
if (src_addr.sin_port != sender->address.sin_port && if (src_addr.sin_port != sender->address.sin_port &&
src_addr.sin_addr.s_addr != sender->address.sin_addr.s_addr) src_addr.sin_addr.s_addr != sender->address.sin_addr.s_addr)
@ -827,7 +827,7 @@ bool uvgrtp::rtcp::collision_detected(uint32_t ssrc, sockaddr_in& src_addr)
return false; return false;
} }
void uvgrtp::rtcp::update_session_statistics(uvgrtp::frame::rtp_frame *frame) void uvgrtp::rtcp::update_session_statistics(const uvgrtp::frame::rtp_frame *frame)
{ {
auto p = participants_[frame->header.ssrc]; auto p = participants_[frame->header.ssrc];
@ -1137,7 +1137,7 @@ rtp_error_t uvgrtp::rtcp::handle_app_packet(uint8_t* packet, size_t size,
return RTP_OK; return RTP_OK;
} }
rtp_error_t uvgrtp::rtcp::handle_receiver_report_packet(uint8_t* packet, size_t size, rtp_error_t uvgrtp::rtcp::handle_receiver_report_packet(uint8_t* packet, size_t size,
uvgrtp::frame::rtcp_header& header) uvgrtp::frame::rtcp_header& header)
{ {
if (!packet || !size) if (!packet || !size)
@ -1286,7 +1286,7 @@ rtp_error_t uvgrtp::rtcp::construct_rtcp_header(size_t packet_size,
return RTP_OK; return RTP_OK;
} }
void uvgrtp::rtcp::read_rtcp_header(uint8_t* packet, uvgrtp::frame::rtcp_header& header) void uvgrtp::rtcp::read_rtcp_header(const uint8_t* packet, uvgrtp::frame::rtcp_header& header)
{ {
header.version = (packet[0] >> 6) & 0x3; header.version = (packet[0] >> 6) & 0x3;
header.padding = (packet[0] >> 5) & 0x1; header.padding = (packet[0] >> 5) & 0x1;
@ -1303,7 +1303,7 @@ void uvgrtp::rtcp::read_rtcp_header(uint8_t* packet, uvgrtp::frame::rtcp_header&
header.length = ntohs(*(uint16_t*)&packet[2]); header.length = ntohs(*(uint16_t*)&packet[2]);
} }
void uvgrtp::rtcp::read_reports(uint8_t* packet, size_t size, uint8_t count, bool has_sender_block, void uvgrtp::rtcp::read_reports(const uint8_t* packet, size_t size, uint8_t count, bool has_sender_block,
std::vector<uvgrtp::frame::rtcp_report_block>& reports) std::vector<uvgrtp::frame::rtcp_report_block>& reports)
{ {
uint32_t report_section = RTCP_HEADER_SIZE + SSRC_CSRC_SIZE; uint32_t report_section = RTCP_HEADER_SIZE + SSRC_CSRC_SIZE;
@ -1463,7 +1463,7 @@ rtp_error_t uvgrtp::rtcp::generate_report()
return send_rtcp_packet_to_participants(frame, frame_size); return send_rtcp_packet_to_participants(frame, frame_size);
} }
rtp_error_t uvgrtp::rtcp::send_sdes_packet(std::vector<uvgrtp::frame::rtcp_sdes_item>& items) rtp_error_t uvgrtp::rtcp::send_sdes_packet(const std::vector<uvgrtp::frame::rtcp_sdes_item>& items)
{ {
if (items.empty()) if (items.empty())
{ {
@ -1540,8 +1540,8 @@ rtp_error_t uvgrtp::rtcp::send_bye_packet(std::vector<uint32_t> ssrcs)
return send_rtcp_packet_to_participants(frame, frame_size); return send_rtcp_packet_to_participants(frame, frame_size);
} }
rtp_error_t uvgrtp::rtcp::send_app_packet(char* name, uint8_t subtype, rtp_error_t uvgrtp::rtcp::send_app_packet(const char* name, uint8_t subtype,
size_t payload_len, uint8_t* payload) size_t payload_len, const uint8_t* payload)
{ {
rtp_error_t ret = RTP_OK; rtp_error_t ret = RTP_OK;
uint8_t* frame = nullptr; uint8_t* frame = nullptr;

View File

@ -212,7 +212,7 @@ rtp_error_t uvgrtp::base_srtp::allocate_crypto_ctx(size_t key_size)
return RTP_OK; return RTP_OK;
} }
size_t uvgrtp::base_srtp::get_key_size(int flags) size_t uvgrtp::base_srtp::get_key_size(int flags) const
{ {
size_t key_size = AES128_KEY_SIZE; size_t key_size = AES128_KEY_SIZE;

View File

@ -148,7 +148,7 @@ namespace uvgrtp {
* Returns false if replay protection has not been enabled */ * Returns false if replay protection has not been enabled */
bool is_replayed_packet(uint8_t *digest); bool is_replayed_packet(uint8_t *digest);
size_t get_key_size(int flags); size_t get_key_size(int flags) const;
protected: protected:

View File

@ -151,7 +151,7 @@ authenticate:
return ret; return ret;
} }
bool uvgrtp::srtp::authenticate_rtp() bool uvgrtp::srtp::authenticate_rtp() const
{ {
return authenticate_rtp_; return authenticate_rtp_;
} }

View File

@ -24,7 +24,7 @@ namespace uvgrtp {
rtp_error_t encrypt(uint32_t ssrc, uint16_t seq, uint8_t* buffer, size_t len); rtp_error_t encrypt(uint32_t ssrc, uint16_t seq, uint8_t* buffer, size_t len);
/* Has RTP packet authentication been enabled? */ /* Has RTP packet authentication been enabled? */
bool authenticate_rtp(); bool authenticate_rtp() const;
/* By default RTP packet authentication is disabled but by /* By default RTP packet authentication is disabled but by
* giving RCE_SRTP_AUTHENTICATE_RTP to create_stream() user can enable it. * giving RCE_SRTP_AUTHENTICATE_RTP to create_stream() user can enable it.