From b1168d81753df2e1503495dfecef9d137ac3d5b0 Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Wed, 26 Aug 2020 15:53:41 +0300 Subject: [PATCH] Remove unused code from src/frame.cc Remove all unused (de)allocation code from src/frame.cc and remove the RTCP-related PACKED_STRUCT definitions from include/frame.hh --- include/frame.hh | 46 ++++------------------------- src/frame.cc | 75 ------------------------------------------------ 2 files changed, 5 insertions(+), 116 deletions(-) diff --git a/include/frame.hh b/include/frame.hh index be9c0e4..9230ced 100644 --- a/include/frame.hh +++ b/include/frame.hh @@ -83,7 +83,7 @@ namespace uvg_rtp { sockaddr_in src_addr; }; - PACKED_STRUCT(rtcp_header) { + struct rtcp_header { uint8_t version; uint8_t padding; union { @@ -94,7 +94,7 @@ namespace uvg_rtp { uint16_t length; }; - PACKED_STRUCT(rtcp_sender_info) { + struct rtcp_sender_info { uint32_t ntp_msw; /* NTP timestamp, most significant word */ uint32_t ntp_lsw; /* NTP timestamp, least significant word */ uint32_t rtp_ts; /* RTP timestamp corresponding to same time as NTP */ @@ -102,23 +102,16 @@ namespace uvg_rtp { uint32_t byte_cnt; }; - PACKED_STRUCT(rtcp_report_block) { + struct rtcp_report_block { uint32_t ssrc; uint8_t fraction; - int32_t lost:24; + int32_t lost; uint32_t last_seq; uint32_t jitter; uint32_t lsr; /* last Sender Report */ uint32_t dlsr; /* delay since last Sender Report */ }; - PACKED_STRUCT(rtcp_sender_frame) { - struct rtcp_header header; - uint32_t sender_ssrc; - struct rtcp_sender_info s_info; - struct rtcp_report_block blocks[1]; - }; - struct rtcp_receiver_report { struct rtcp_header header; uint32_t ssrc; @@ -132,13 +125,7 @@ namespace uvg_rtp { std::vector report_blocks; }; - PACKED_STRUCT(rtcp_receiver_frame) { - struct rtcp_header header; - uint32_t sender_ssrc; - struct rtcp_report_block blocks[1]; - }; - - PACKED_STRUCT(rtcp_sdes_item) { + struct rtcp_sdes_item { uint8_t type; uint8_t length; void *data; @@ -157,11 +144,6 @@ namespace uvg_rtp { uint8_t *payload; }; - PACKED_STRUCT(rtcp_bye_frame) { - struct rtcp_header header; - uint32_t ssrc[1]; - }; - PACKED_STRUCT(zrtp_frame) { uint8_t version:4; uint16_t unused:12; @@ -196,16 +178,6 @@ namespace uvg_rtp { * RTP_INVALID_VALUE if "payload_size" is 0 */ zrtp_frame *alloc_zrtp_frame(size_t payload_size); - /* Allocate various types of RTCP frames, see src/rtcp.cc for more details - * - * Return pointer to frame on success - * Return nullptr on error and set rtp_errno to: - * RTP_MEMORY_ERROR if allocation of memory failed - * RTP_INVALID_VALUE if one of the parameters was invalid */ - rtcp_receiver_frame *alloc_rtcp_receiver_frame(size_t nblocks); - rtcp_sender_frame *alloc_rtcp_sender_frame(size_t nblocks); - rtcp_bye_frame *alloc_rtcp_bye_frame(size_t ssrc_count); - /* Deallocate RTP frame * * Return RTP_OK on successs @@ -217,13 +189,5 @@ namespace uvg_rtp { * Return RTP_OK on successs * Return RTP_INVALID_VALUE if "frame" is nullptr */ rtp_error_t dealloc_frame(uvg_rtp::frame::zrtp_frame *frame); - - /* Deallocate various types of RTCP frames - * - * Return RTP_OK on successs - * Return RTP_INVALID_VALUE if "frame" is nullptr */ - rtp_error_t dealloc_frame(rtcp_sender_frame *frame); - rtp_error_t dealloc_frame(rtcp_receiver_frame *frame); - rtp_error_t dealloc_frame(rtcp_bye_frame *frame); }; }; diff --git a/src/frame.cc b/src/frame.cc index 4e78630..8c9f4fa 100644 --- a/src/frame.cc +++ b/src/frame.cc @@ -102,78 +102,3 @@ rtp_error_t uvg_rtp::frame::dealloc_frame(uvg_rtp::frame::zrtp_frame *frame) delete[] frame; return RTP_OK; } - -uvg_rtp::frame::rtcp_sender_frame *uvg_rtp::frame::alloc_rtcp_sender_frame(size_t nblocks) -{ - size_t total_size = - sizeof(rtcp_header) + - sizeof(uint32_t) + - sizeof(rtcp_sender_info) + - sizeof(rtcp_report_block) * nblocks; - - auto *frame = (uvg_rtp::frame::rtcp_sender_frame *)new uint8_t[total_size]; - - if (!frame) { - LOG_ERROR("Failed to allocate memory for RTCP sender report"); - rtp_errno = RTP_MEMORY_ERROR; - return nullptr; - } - - frame->header.version = 2; - frame->header.padding = 0; - frame->header.pkt_type = uvg_rtp::frame::RTCP_FT_SR; - frame->header.length = total_size; - frame->header.count = nblocks; - - /* caller fills these */ - memset(&frame->s_info, 0, sizeof(rtcp_sender_info)); - - if (nblocks == 0) - memset(frame->blocks, 0, sizeof(rtcp_report_block) * nblocks); - - return frame; -} - -uvg_rtp::frame::rtcp_bye_frame *uvg_rtp::frame::alloc_rtcp_bye_frame(size_t ssrc_count) -{ - if (ssrc_count == 0) { - LOG_ERROR("Cannot have 0 SSRC/CSRC!"); - rtp_errno = RTP_INVALID_VALUE; - return nullptr; - } - - size_t total_size = sizeof(rtcp_header) + sizeof(uint32_t) * ssrc_count; - auto *frame = (uvg_rtp::frame::rtcp_bye_frame *)new uint8_t[total_size]; - - if (!frame) { - LOG_ERROR("Failed to allocate memory for RTCP sender report"); - rtp_errno = RTP_MEMORY_ERROR; - return nullptr; - } - - frame->header.version = 2; - frame->header.padding = 0; - frame->header.pkt_type = uvg_rtp::frame::RTCP_FT_BYE; - frame->header.length = total_size; - frame->header.count = ssrc_count; - - return frame; -} - -rtp_error_t uvg_rtp::frame::dealloc_frame(uvg_rtp::frame::rtcp_sender_frame *frame) -{ - if (!frame) - return RTP_INVALID_VALUE; - - delete[] frame; - return RTP_OK; -} - -rtp_error_t uvg_rtp::frame::dealloc_frame(rtcp_bye_frame *frame) -{ - if (!frame) - return RTP_INVALID_VALUE; - - delete[] frame; - return RTP_OK; -}