common: Use shared_ptr for managing socket memory
This commit is contained in:
		
							parent
							
								
									de639fe861
								
							
						
					
					
						commit
						32839127f4
					
				|  | @ -315,7 +315,7 @@ namespace uvgrtp { | ||||||
| 
 | 
 | ||||||
|             uvgrtp::srtp   *srtp_; |             uvgrtp::srtp   *srtp_; | ||||||
|             uvgrtp::srtcp  *srtcp_; |             uvgrtp::srtcp  *srtcp_; | ||||||
|             uvgrtp::socket *socket_; |             std::shared_ptr<uvgrtp::socket> socket_; | ||||||
|             std::shared_ptr<uvgrtp::rtp> rtp_; |             std::shared_ptr<uvgrtp::rtp> rtp_; | ||||||
|             uvgrtp::rtcp   *rtcp_; |             uvgrtp::rtcp   *rtcp_; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -57,12 +57,12 @@ namespace uvgrtp { | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     struct rtcp_participant { |     struct rtcp_participant { | ||||||
|         uvgrtp::socket *socket = nullptr; /* socket associated with this 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 */ |         struct receiver_statistics stats;                 /* RTCP session statistics of the participant */ | ||||||
| 
 | 
 | ||||||
|         uint32_t probation = 0;           /* has the participant been fully accepted to the session */ |         uint32_t probation = 0;                           /* has the participant been fully accepted to the session */ | ||||||
|         int role = 0;                /* is the participant a sender or a receiver */ |         int role = 0;                                     /* is the participant a sender or a receiver */ | ||||||
| 
 | 
 | ||||||
|         /* Save the latest RTCP packets received from this participant
 |         /* Save the latest RTCP packets received from this participant
 | ||||||
|          * Users can query these packets using the SSRC of participant */ |          * Users can query these packets using the SSRC of participant */ | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ | ||||||
| #include <sys/socket.h> | #include <sys/socket.h> | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| uvgrtp::formats::h264::h264(uvgrtp::socket* socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags) : | uvgrtp::formats::h264::h264(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags) : | ||||||
|     h26x(socket, rtp, flags) |     h26x(socket, rtp, flags) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -39,7 +39,7 @@ namespace uvgrtp { | ||||||
| 
 | 
 | ||||||
|         class h264 : public h26x { |         class h264 : public h26x { | ||||||
|             public: |             public: | ||||||
|                 h264(uvgrtp::socket *socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags); |                 h264(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags); | ||||||
|                 ~h264(); |                 ~h264(); | ||||||
| 
 | 
 | ||||||
|             protected: |             protected: | ||||||
|  |  | ||||||
|  | @ -20,7 +20,7 @@ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| uvgrtp::formats::h265::h265(uvgrtp::socket* socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags) : | uvgrtp::formats::h265::h265(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags) : | ||||||
|     h26x(socket, rtp, flags) |     h26x(socket, rtp, flags) | ||||||
| {} | {} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -40,7 +40,7 @@ namespace uvgrtp { | ||||||
| 
 | 
 | ||||||
|         class h265 : public h26x { |         class h265 : public h26x { | ||||||
|             public: |             public: | ||||||
|                 h265(uvgrtp::socket *socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags); |                 h265(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags); | ||||||
|                 ~h265(); |                 ~h265(); | ||||||
| 
 | 
 | ||||||
|             protected: |             protected: | ||||||
|  |  | ||||||
|  | @ -21,7 +21,7 @@ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| uvgrtp::formats::h266::h266(uvgrtp::socket* socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags) : | uvgrtp::formats::h266::h266(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags) : | ||||||
|     h26x(socket, rtp, flags) |     h26x(socket, rtp, flags) | ||||||
| {} | {} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -38,7 +38,7 @@ namespace uvgrtp { | ||||||
| 
 | 
 | ||||||
|         class h266 : public h26x { |         class h266 : public h26x { | ||||||
|             public: |             public: | ||||||
|                 h266(uvgrtp::socket *socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags); |                 h266(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags); | ||||||
|                 ~h266(); |                 ~h266(); | ||||||
| 
 | 
 | ||||||
|             protected: |             protected: | ||||||
|  |  | ||||||
|  | @ -80,7 +80,7 @@ static inline unsigned __find_h26x_start(uint32_t value,bool& additional_byte) | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| uvgrtp::formats::h26x::h26x(uvgrtp::socket* socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags) : | uvgrtp::formats::h26x::h26x(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags) : | ||||||
|     media(socket, rtp, flags),  |     media(socket, rtp, flags),  | ||||||
|     queued_(),  |     queued_(),  | ||||||
|     frames_(),  |     frames_(),  | ||||||
|  |  | ||||||
|  | @ -60,7 +60,7 @@ namespace uvgrtp { | ||||||
| 
 | 
 | ||||||
|         class h26x : public media { |         class h26x : public media { | ||||||
|             public: |             public: | ||||||
|                 h26x(uvgrtp::socket *socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags); |                 h26x(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags); | ||||||
|                 virtual ~h26x(); |                 virtual ~h26x(); | ||||||
| 
 | 
 | ||||||
|                 /* Find H26x start code from "data"
 |                 /* Find H26x start code from "data"
 | ||||||
|  |  | ||||||
|  | @ -13,7 +13,7 @@ | ||||||
| 
 | 
 | ||||||
| #define INVALID_SEQ 0xffffffff | #define INVALID_SEQ 0xffffffff | ||||||
| 
 | 
 | ||||||
| uvgrtp::formats::media::media(uvgrtp::socket *socket, std::shared_ptr<uvgrtp::rtp> rtp_ctx, int flags): | uvgrtp::formats::media::media(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> rtp_ctx, int flags): | ||||||
|     socket_(socket), rtp_ctx_(rtp_ctx), flags_(flags), minfo_{} |     socket_(socket), rtp_ctx_(rtp_ctx), flags_(flags), minfo_{} | ||||||
| { | { | ||||||
|     fqueue_ = new uvgrtp::frame_queue(socket, rtp_ctx, flags); |     fqueue_ = new uvgrtp::frame_queue(socket, rtp_ctx, flags); | ||||||
|  |  | ||||||
|  | @ -36,7 +36,7 @@ namespace uvgrtp { | ||||||
| 
 | 
 | ||||||
|         class media { |         class media { | ||||||
|             public: |             public: | ||||||
|                 media(uvgrtp::socket *socket, std::shared_ptr<uvgrtp::rtp> rtp_ctx, int flags); |                 media(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> rtp_ctx, int flags); | ||||||
|                 virtual ~media(); |                 virtual ~media(); | ||||||
| 
 | 
 | ||||||
|                 /* These two functions are called by media_stream which is self is called by the application.
 |                 /* These two functions are called by media_stream which is self is called by the application.
 | ||||||
|  | @ -65,7 +65,7 @@ namespace uvgrtp { | ||||||
|             protected: |             protected: | ||||||
|                 virtual rtp_error_t push_media_frame(uint8_t *data, size_t data_len, int flags); |                 virtual rtp_error_t push_media_frame(uint8_t *data, size_t data_len, int flags); | ||||||
| 
 | 
 | ||||||
|                 uvgrtp::socket *socket_; |                 std::shared_ptr<uvgrtp::socket> socket_; | ||||||
|                 std::shared_ptr<uvgrtp::rtp> rtp_ctx_; |                 std::shared_ptr<uvgrtp::rtp> rtp_ctx_; | ||||||
|                 int flags_; |                 int flags_; | ||||||
|                 uvgrtp::frame_queue *fqueue_; |                 uvgrtp::frame_queue *fqueue_; | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ | ||||||
| 
 | 
 | ||||||
| #define THRESHOLD 2000 | #define THRESHOLD 2000 | ||||||
| 
 | 
 | ||||||
| uvgrtp::holepuncher::holepuncher(uvgrtp::socket *socket): | uvgrtp::holepuncher::holepuncher(std::shared_ptr<uvgrtp::socket> socket): | ||||||
|     socket_(socket), |     socket_(socket), | ||||||
|     last_dgram_sent_(0) |     last_dgram_sent_(0) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ | ||||||
| #include "uvgrtp/util.hh" | #include "uvgrtp/util.hh" | ||||||
| 
 | 
 | ||||||
| #include <atomic> | #include <atomic> | ||||||
|  | #include <memory> | ||||||
| 
 | 
 | ||||||
| namespace uvgrtp { | namespace uvgrtp { | ||||||
| 
 | 
 | ||||||
|  | @ -11,7 +12,7 @@ namespace uvgrtp { | ||||||
| 
 | 
 | ||||||
|     class holepuncher : public runner { |     class holepuncher : public runner { | ||||||
|         public: |         public: | ||||||
|             holepuncher(uvgrtp::socket *socket); |             holepuncher(std::shared_ptr<uvgrtp::socket> socket); | ||||||
|             ~holepuncher(); |             ~holepuncher(); | ||||||
| 
 | 
 | ||||||
|             /* Create new thread object and start the holepuncher
 |             /* Create new thread object and start the holepuncher
 | ||||||
|  | @ -30,7 +31,7 @@ namespace uvgrtp { | ||||||
|         private: |         private: | ||||||
|             void keepalive(); |             void keepalive(); | ||||||
| 
 | 
 | ||||||
|             uvgrtp::socket *socket_; |             std::shared_ptr<uvgrtp::socket> socket_; | ||||||
|             std::atomic<uint64_t> last_dgram_sent_; |             std::atomic<uint64_t> last_dgram_sent_; | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -78,7 +78,7 @@ rtp_error_t uvgrtp::media_stream::init_connection() | ||||||
| { | { | ||||||
|     rtp_error_t ret = RTP_OK; |     rtp_error_t ret = RTP_OK; | ||||||
| 
 | 
 | ||||||
|     socket_ = new uvgrtp::socket(ctx_config_.flags); |     socket_ = std::shared_ptr<uvgrtp::socket> (new uvgrtp::socket(ctx_config_.flags)); | ||||||
| 
 | 
 | ||||||
|     if ((ret = socket_->init(AF_INET, SOCK_DGRAM, 0)) != RTP_OK) |     if ((ret = socket_->init(AF_INET, SOCK_DGRAM, 0)) != RTP_OK) | ||||||
|         return ret; |         return ret; | ||||||
|  | @ -220,7 +220,6 @@ rtp_error_t uvgrtp::media_stream::free_resources(rtp_error_t ret) | ||||||
| 
 | 
 | ||||||
|     if (socket_) |     if (socket_) | ||||||
|     { |     { | ||||||
|         delete socket_; |  | ||||||
|         socket_ = nullptr; |         socket_ = nullptr; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| rtp_error_t uvgrtp::poll::blocked_recv(uvgrtp::socket *socket, uint8_t *buf, size_t buf_len, int timeout, int *bytes_read) | rtp_error_t uvgrtp::poll::blocked_recv(std::shared_ptr<uvgrtp::socket> socket, uint8_t *buf, size_t buf_len, int timeout, int *bytes_read) | ||||||
| { | { | ||||||
|     if (!buf|| !buf_len) |     if (!buf|| !buf_len) | ||||||
|         return RTP_INVALID_VALUE; |         return RTP_INVALID_VALUE; | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ | ||||||
| #include "uvgrtp/util.hh" | #include "uvgrtp/util.hh" | ||||||
| 
 | 
 | ||||||
| #include <vector> | #include <vector> | ||||||
|  | #include <memory> | ||||||
| 
 | 
 | ||||||
| namespace uvgrtp { | namespace uvgrtp { | ||||||
|     class socket; |     class socket; | ||||||
|  | @ -19,7 +20,7 @@ namespace uvgrtp { | ||||||
|         rtp_error_t poll(std::vector<uvgrtp::socket>& sockets, uint8_t *buf, size_t buf_len, int timeout, int *bytes_read); |         rtp_error_t poll(std::vector<uvgrtp::socket>& sockets, uint8_t *buf, size_t buf_len, int timeout, int *bytes_read); | ||||||
| 
 | 
 | ||||||
|         /* TODO:  */ |         /* TODO:  */ | ||||||
|         rtp_error_t blocked_recv(uvgrtp::socket *socket, uint8_t *buf, size_t buf_len, int timeout, int *bytes_read); |         rtp_error_t blocked_recv(std::shared_ptr<uvgrtp::socket> socket, uint8_t *buf, size_t buf_len, int timeout, int *bytes_read); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -22,7 +22,7 @@ | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| uvgrtp::frame_queue::frame_queue(uvgrtp::socket *socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags): | uvgrtp::frame_queue::frame_queue(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags): | ||||||
|     rtp_(rtp), socket_(socket), flags_(flags) |     rtp_(rtp), socket_(socket), flags_(flags) | ||||||
| { | { | ||||||
|     active_     = nullptr; |     active_     = nullptr; | ||||||
|  |  | ||||||
|  | @ -93,7 +93,7 @@ namespace uvgrtp { | ||||||
| 
 | 
 | ||||||
|     class frame_queue { |     class frame_queue { | ||||||
|         public: |         public: | ||||||
|             frame_queue(uvgrtp::socket *socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags); |             frame_queue(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> rtp, int flags); | ||||||
|             ~frame_queue(); |             ~frame_queue(); | ||||||
| 
 | 
 | ||||||
|             rtp_error_t init_transaction(); |             rtp_error_t init_transaction(); | ||||||
|  | @ -196,7 +196,7 @@ namespace uvgrtp { | ||||||
|             ssize_t max_ccount_; /* number of chunks per message */ |             ssize_t max_ccount_; /* number of chunks per message */ | ||||||
| 
 | 
 | ||||||
|             std::shared_ptr<uvgrtp::rtp> rtp_; |             std::shared_ptr<uvgrtp::rtp> rtp_; | ||||||
|             uvgrtp::socket *socket_; |             std::shared_ptr<uvgrtp::socket> socket_; | ||||||
| 
 | 
 | ||||||
|             /* RTP context flags */ |             /* RTP context flags */ | ||||||
|             int flags_; |             int flags_; | ||||||
|  |  | ||||||
|  | @ -70,7 +70,7 @@ void uvgrtp::reception_flow::set_buffer_size(ssize_t& value) | ||||||
|     create_ring_buffer(); |     create_ring_buffer(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| rtp_error_t uvgrtp::reception_flow::start(uvgrtp::socket *socket, int flags) | rtp_error_t uvgrtp::reception_flow::start(std::shared_ptr<uvgrtp::socket> socket, int flags) | ||||||
| { | { | ||||||
|     should_stop_ = false; |     should_stop_ = false; | ||||||
|     processor_ = std::unique_ptr<std::thread>(new std::thread(&uvgrtp::reception_flow::process_packet, this, flags)); |     processor_ = std::unique_ptr<std::thread>(new std::thread(&uvgrtp::reception_flow::process_packet, this, flags)); | ||||||
|  | @ -313,7 +313,7 @@ void uvgrtp::reception_flow::call_aux_handlers(uint32_t key, int flags, uvgrtp:: | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void uvgrtp::reception_flow::receiver(uvgrtp::socket *socket, int flags) | void uvgrtp::reception_flow::receiver(std::shared_ptr<uvgrtp::socket> socket, int flags) | ||||||
| { | { | ||||||
|     LOG_DEBUG("Start reception loop"); |     LOG_DEBUG("Start reception loop"); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -126,7 +126,7 @@ namespace uvgrtp { | ||||||
|              * |              * | ||||||
|              * Return RTP_OK on success |              * Return RTP_OK on success | ||||||
|              * Return RTP_MEMORY_ERROR if allocation of a thread object fails */ |              * Return RTP_MEMORY_ERROR if allocation of a thread object fails */ | ||||||
|             rtp_error_t start(uvgrtp::socket *socket, int flags); |             rtp_error_t start(std::shared_ptr<uvgrtp::socket> socket, int flags); | ||||||
| 
 | 
 | ||||||
|             /* Stop the RTP reception flow and wait until the receive loop is exited
 |             /* Stop the RTP reception flow and wait until the receive loop is exited
 | ||||||
|              * to make sure that destroying the object is safe. |              * to make sure that destroying the object is safe. | ||||||
|  | @ -149,7 +149,7 @@ namespace uvgrtp { | ||||||
| 
 | 
 | ||||||
|         private: |         private: | ||||||
|             /* RTP packet receiver thread */ |             /* RTP packet receiver thread */ | ||||||
|             void receiver(uvgrtp::socket *socket, int flags); |             void receiver(std::shared_ptr<uvgrtp::socket> socket, int flags); | ||||||
| 
 | 
 | ||||||
|             /* RTP packet dispatcher thread */ |             /* RTP packet dispatcher thread */ | ||||||
|             void process_packet(int flags); |             void process_packet(int flags); | ||||||
|  |  | ||||||
							
								
								
									
										14
									
								
								src/rtcp.cc
								
								
								
								
							
							
						
						
									
										14
									
								
								src/rtcp.cc
								
								
								
								
							|  | @ -100,7 +100,7 @@ rtp_error_t uvgrtp::rtcp::stop() | ||||||
|         /* free all receiver statistic structs */ |         /* free all receiver statistic structs */ | ||||||
|         for (auto& participant : participants_) |         for (auto& participant : participants_) | ||||||
|         { |         { | ||||||
|             delete participant.second->socket; |             participant.second->socket = nullptr; | ||||||
|             delete participant.second; |             delete participant.second; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -194,7 +194,7 @@ rtp_error_t uvgrtp::rtcp::add_participant(std::string dst_addr, uint16_t dst_por | ||||||
| 
 | 
 | ||||||
|     zero_stats(&p->stats); |     zero_stats(&p->stats); | ||||||
| 
 | 
 | ||||||
|     p->socket = new uvgrtp::socket(0); |     p->socket = std::shared_ptr<uvgrtp::socket> (new uvgrtp::socket(0)); | ||||||
| 
 | 
 | ||||||
|     if ((ret = p->socket->init(AF_INET, SOCK_DGRAM, 0)) != RTP_OK) |     if ((ret = p->socket->init(AF_INET, SOCK_DGRAM, 0)) != RTP_OK) | ||||||
|     { |     { | ||||||
|  | @ -768,7 +768,7 @@ rtp_error_t uvgrtp::rtcp::handle_incoming_packet(uint8_t *buffer, size_t size) | ||||||
|     uvgrtp::frame::rtcp_header header; |     uvgrtp::frame::rtcp_header header; | ||||||
|     read_rtcp_header(buffer, header); |     read_rtcp_header(buffer, header); | ||||||
| 
 | 
 | ||||||
|     if (size < header.length) |     if (size < header.length) // TODO: This length in header is not supposed to be bytes, but 32-bit words - 1
 | ||||||
|     { |     { | ||||||
|         LOG_ERROR("Received partial rtcp packet. Not supported"); |         LOG_ERROR("Received partial rtcp packet. Not supported"); | ||||||
|         return RTP_NOT_SUPPORTED; |         return RTP_NOT_SUPPORTED; | ||||||
|  | @ -897,7 +897,7 @@ rtp_error_t uvgrtp::rtcp::handle_bye_packet(uint8_t* packet, size_t size) | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         delete participants_[ssrc]->socket; |         participants_[ssrc]->socket = nullptr; | ||||||
|         delete participants_[ssrc]; |         delete participants_[ssrc]; | ||||||
|         participants_.erase(ssrc); |         participants_.erase(ssrc); | ||||||
|     } |     } | ||||||
|  | @ -1198,6 +1198,8 @@ rtp_error_t uvgrtp::rtcp::generate_report() | ||||||
|         frame_size += UVG_SRTCP_INDEX_LENGTH + UVG_AUTH_TAG_LENGTH; |         frame_size += UVG_SRTCP_INDEX_LENGTH + UVG_AUTH_TAG_LENGTH; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     // see https://datatracker.ietf.org/doc/html/rfc3550#section-6.4.1
 | ||||||
|  | 
 | ||||||
|     if (our_role_ == SENDER && our_stats.sent_rtp_packet) |     if (our_role_ == SENDER && our_stats.sent_rtp_packet) | ||||||
|     { |     { | ||||||
|         LOG_DEBUG("Generating RTCP Sender report"); |         LOG_DEBUG("Generating RTCP Sender report"); | ||||||
|  | @ -1240,7 +1242,9 @@ rtp_error_t uvgrtp::rtcp::generate_report() | ||||||
|         if (p.second->stats.received_rtp_packet) |         if (p.second->stats.received_rtp_packet) | ||||||
|         { |         { | ||||||
|             int dropped = p.second->stats.dropped_pkts; |             int dropped = p.second->stats.dropped_pkts; | ||||||
|             uint8_t frac = dropped ? p.second->stats.received_bytes / dropped : 0; |             // TODO: This 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 frac = dropped ? p.second->stats.received_bytes / dropped : 0;  | ||||||
| 
 | 
 | ||||||
|             SET_NEXT_FIELD_32(frame, ptr, htonl(p.first)); /* ssrc */ |             SET_NEXT_FIELD_32(frame, ptr, htonl(p.first)); /* ssrc */ | ||||||
|             SET_NEXT_FIELD_32(frame, ptr, htonl((frac << 24) | p.second->stats.dropped_pkts)); |             SET_NEXT_FIELD_32(frame, ptr, htonl((frac << 24) | p.second->stats.dropped_pkts)); | ||||||
|  |  | ||||||
|  | @ -617,7 +617,7 @@ rtp_error_t uvgrtp::zrtp::initiator_finalize_session() | ||||||
|     return RTP_TIMEOUT; |     return RTP_TIMEOUT; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| rtp_error_t uvgrtp::zrtp::init(uint32_t ssrc, uvgrtp::socket *socket, sockaddr_in& addr) | rtp_error_t uvgrtp::zrtp::init(uint32_t ssrc, std::shared_ptr<uvgrtp::socket> socket, sockaddr_in& addr) | ||||||
| { | { | ||||||
|     std::lock_guard<std::mutex> lock(zrtp_mtx_); |     std::lock_guard<std::mutex> lock(zrtp_mtx_); | ||||||
| 
 | 
 | ||||||
|  | @ -626,7 +626,7 @@ rtp_error_t uvgrtp::zrtp::init(uint32_t ssrc, uvgrtp::socket *socket, sockaddr_i | ||||||
|     return init_msm(ssrc, socket, addr); |     return init_msm(ssrc, socket, addr); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| rtp_error_t uvgrtp::zrtp::init_dhm(uint32_t ssrc, uvgrtp::socket *socket, sockaddr_in& addr) | rtp_error_t uvgrtp::zrtp::init_dhm(uint32_t ssrc, std::shared_ptr<uvgrtp::socket> socket, sockaddr_in& addr) | ||||||
| { | { | ||||||
|     rtp_error_t ret = RTP_OK; |     rtp_error_t ret = RTP_OK; | ||||||
| 
 | 
 | ||||||
|  | @ -723,7 +723,7 @@ rtp_error_t uvgrtp::zrtp::init_dhm(uint32_t ssrc, uvgrtp::socket *socket, sockad | ||||||
|     return RTP_OK; |     return RTP_OK; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| rtp_error_t uvgrtp::zrtp::init_msm(uint32_t ssrc, uvgrtp::socket *socket, sockaddr_in& addr) | rtp_error_t uvgrtp::zrtp::init_msm(uint32_t ssrc, std::shared_ptr<uvgrtp::socket> socket, sockaddr_in& addr) | ||||||
| { | { | ||||||
|     rtp_error_t ret; |     rtp_error_t ret; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/zrtp.hh
								
								
								
								
							
							
						
						
									
										10
									
								
								src/zrtp.hh
								
								
								
								
							|  | @ -14,7 +14,7 @@ | ||||||
| 
 | 
 | ||||||
| #include <mutex> | #include <mutex> | ||||||
| #include <vector> | #include <vector> | ||||||
| 
 | #include <memory> | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| namespace uvgrtp { | namespace uvgrtp { | ||||||
|  | @ -186,7 +186,7 @@ namespace uvgrtp { | ||||||
|              * |              * | ||||||
|              * Return RTP_OK on success |              * Return RTP_OK on success | ||||||
|              * Return RTP_TIMEOUT if remote did not send messages in timely manner */ |              * Return RTP_TIMEOUT if remote did not send messages in timely manner */ | ||||||
|             rtp_error_t init(uint32_t ssrc, uvgrtp::socket *socket, sockaddr_in& addr); |             rtp_error_t init(uint32_t ssrc, std::shared_ptr<uvgrtp::socket> socket, sockaddr_in& addr); | ||||||
| 
 | 
 | ||||||
|             /* Get SRTP keys for the session that was just initialized
 |             /* Get SRTP keys for the session that was just initialized
 | ||||||
|              * |              * | ||||||
|  | @ -219,13 +219,13 @@ namespace uvgrtp { | ||||||
|              * |              * | ||||||
|              * Return RTP_OK on success |              * Return RTP_OK on success | ||||||
|              * Return RTP_TIMEOUT if remote did not send messages in timely manner */ |              * Return RTP_TIMEOUT if remote did not send messages in timely manner */ | ||||||
|             rtp_error_t init_dhm(uint32_t ssrc, uvgrtp::socket *socket, sockaddr_in& addr); |             rtp_error_t init_dhm(uint32_t ssrc, std::shared_ptr<uvgrtp::socket> socket, sockaddr_in& addr); | ||||||
| 
 | 
 | ||||||
|             /* Initialize ZRTP session between us and remote using Multistream mode
 |             /* Initialize ZRTP session between us and remote using Multistream mode
 | ||||||
|              * |              * | ||||||
|              * Return RTP_OK on success |              * Return RTP_OK on success | ||||||
|              * Return RTP_TIMEOUT if remote did not send messages in timely manner */ |              * Return RTP_TIMEOUT if remote did not send messages in timely manner */ | ||||||
|             rtp_error_t init_msm(uint32_t ssrc, uvgrtp::socket *socket, sockaddr_in& addr); |             rtp_error_t init_msm(uint32_t ssrc, std::shared_ptr<uvgrtp::socket> socket, sockaddr_in& addr); | ||||||
| 
 | 
 | ||||||
|             /* Generate zid for this ZRTP instance. ZID is a unique, 96-bit long ID */ |             /* Generate zid for this ZRTP instance. ZID is a unique, 96-bit long ID */ | ||||||
|             void generate_zid(); |             void generate_zid(); | ||||||
|  | @ -300,7 +300,7 @@ namespace uvgrtp { | ||||||
|             rtp_error_t initiator_finalize_session(); |             rtp_error_t initiator_finalize_session(); | ||||||
| 
 | 
 | ||||||
|             uint32_t ssrc_; |             uint32_t ssrc_; | ||||||
|             uvgrtp::socket *socket_; |             std::shared_ptr<uvgrtp::socket> socket_; | ||||||
|             sockaddr_in addr_; |             sockaddr_in addr_; | ||||||
| 
 | 
 | ||||||
|             /* Has the ZRTP connection been initialized using DH */ |             /* Has the ZRTP connection been initialized using DH */ | ||||||
|  |  | ||||||
|  | @ -26,7 +26,7 @@ uvgrtp::zrtp_msg::zrtp_message::~zrtp_message() | ||||||
|     (void)uvgrtp::frame::dealloc_frame(rframe_); |     (void)uvgrtp::frame::dealloc_frame(rframe_); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| rtp_error_t uvgrtp::zrtp_msg::zrtp_message::send_msg(uvgrtp::socket *socket, sockaddr_in& addr) | rtp_error_t uvgrtp::zrtp_msg::zrtp_message::send_msg(std::shared_ptr<uvgrtp::socket> socket, sockaddr_in& addr) | ||||||
| { | { | ||||||
|     rtp_error_t ret; |     rtp_error_t ret; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,6 +6,7 @@ | ||||||
| #include "uvgrtp/frame.hh" | #include "uvgrtp/frame.hh" | ||||||
| #include "uvgrtp/util.hh" | #include "uvgrtp/util.hh" | ||||||
| 
 | 
 | ||||||
|  | #include <memory> | ||||||
| 
 | 
 | ||||||
| namespace uvgrtp { | namespace uvgrtp { | ||||||
| 
 | 
 | ||||||
|  | @ -16,7 +17,7 @@ namespace uvgrtp { | ||||||
|             zrtp_message(); |             zrtp_message(); | ||||||
|             ~zrtp_message(); |             ~zrtp_message(); | ||||||
| 
 | 
 | ||||||
|             rtp_error_t send_msg(uvgrtp::socket* socket, sockaddr_in& addr); |             rtp_error_t send_msg(std::shared_ptr<uvgrtp::socket> socket, sockaddr_in& addr); | ||||||
| 
 | 
 | ||||||
|             /* TODO: description */ |             /* TODO: description */ | ||||||
|             virtual rtp_error_t parse_msg(uvgrtp::zrtp_msg::receiver& receiver, |             virtual rtp_error_t parse_msg(uvgrtp::zrtp_msg::receiver& receiver, | ||||||
|  |  | ||||||
|  | @ -43,7 +43,7 @@ uvgrtp::zrtp_msg::receiver::~receiver() | ||||||
|     delete[] mem_; |     delete[] mem_; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int uvgrtp::zrtp_msg::receiver::recv_msg(uvgrtp::socket *socket, int timeout, int flags) | int uvgrtp::zrtp_msg::receiver::recv_msg(std::shared_ptr<uvgrtp::socket> socket, int timeout, int flags) | ||||||
| { | { | ||||||
|     rtp_error_t ret = RTP_GENERIC_ERROR; |     rtp_error_t ret = RTP_GENERIC_ERROR; | ||||||
|     int nread       = 0; |     int nread       = 0; | ||||||
|  |  | ||||||
|  | @ -6,6 +6,8 @@ | ||||||
| #include <netinet/in.h> | #include <netinet/in.h> | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  | #include <memory> | ||||||
|  | 
 | ||||||
| namespace uvgrtp { | namespace uvgrtp { | ||||||
| 
 | 
 | ||||||
|     class socket; |     class socket; | ||||||
|  | @ -25,7 +27,7 @@ namespace uvgrtp { | ||||||
|                  * Return -EPROTONOSUPPORT if message contains incompatible version number |                  * Return -EPROTONOSUPPORT if message contains incompatible version number | ||||||
|                  * Return -ENOPNOTSUPP if message type is not supported |                  * Return -ENOPNOTSUPP if message type is not supported | ||||||
|                  * Return -errno for any other error */ |                  * Return -errno for any other error */ | ||||||
|                 int recv_msg(uvgrtp::socket *socket, int timeout, int flags); |                 int recv_msg(std::shared_ptr<uvgrtp::socket> socket, int timeout, int flags); | ||||||
| 
 | 
 | ||||||
|                 /* TODO:  */ |                 /* TODO:  */ | ||||||
|                 ssize_t get_msg(void *ptr, size_t len); |                 ssize_t get_msg(void *ptr, size_t len); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue