rtcp: deepcopy APP packet data and handle it internally
This commit is contained in:
		
							parent
							
								
									abbf36adf8
								
							
						
					
					
						commit
						7a7a018032
					
				|  | @ -75,6 +75,10 @@ namespace uvgrtp { | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     struct rtcp_app_packet { |     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; |         const char* name; | ||||||
|         uint8_t subtype; |         uint8_t subtype; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										28
									
								
								src/rtcp.cc
								
								
								
								
							
							
						
						
									
										28
									
								
								src/rtcp.cc
								
								
								
								
							|  | @ -101,6 +101,25 @@ uvgrtp::rtcp::~rtcp() | ||||||
|     ourItems_.clear(); |     ourItems_.clear(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | uvgrtp::rtcp_app_packet::rtcp_app_packet(const char* name, uint8_t subtype, size_t payload_len, const uint8_t* payload) | ||||||
|  | { | ||||||
|  |     uint8_t* packet_payload = new uint8_t[payload_len]; | ||||||
|  |     memcpy(packet_payload, payload, payload_len); | ||||||
|  | 
 | ||||||
|  |     char* packet_name = new char[APP_NAME_SIZE]; | ||||||
|  |     memcpy(packet_name, name, APP_NAME_SIZE); | ||||||
|  | 
 | ||||||
|  |     this->name = packet_name; | ||||||
|  |     this->payload = packet_payload; | ||||||
|  |     this->subtype = subtype; | ||||||
|  |     this->payload_len = payload_len; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | uvgrtp::rtcp_app_packet::~rtcp_app_packet() { | ||||||
|  |     delete[] name; | ||||||
|  |     delete[] payload; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void uvgrtp::rtcp::free_participant(rtcp_participant* participant) | void uvgrtp::rtcp::free_participant(rtcp_participant* participant) | ||||||
| { | { | ||||||
|     participant->socket = nullptr; |     participant->socket = nullptr; | ||||||
|  | @ -1676,8 +1695,7 @@ rtp_error_t uvgrtp::rtcp::generate_report() | ||||||
|             if (!app_name.second.empty()) |             if (!app_name.second.empty()) | ||||||
|             { |             { | ||||||
|                 // take the oldest APP packet and send it
 |                 // take the oldest APP packet and send it
 | ||||||
|                 rtcp_app_packet next_packet = app_name.second.front(); |                 rtcp_app_packet& next_packet = app_name.second.front(); | ||||||
|                 app_name.second.pop_front(); |  | ||||||
| 
 | 
 | ||||||
|                 uint16_t secondField = (next_packet.subtype & 0x1f); |                 uint16_t secondField = (next_packet.subtype & 0x1f); | ||||||
| 
 | 
 | ||||||
|  | @ -1690,8 +1708,10 @@ rtp_error_t uvgrtp::rtcp::generate_report() | ||||||
|                 { |                 { | ||||||
|                     LOG_ERROR("Failed to construct APP packet"); |                     LOG_ERROR("Failed to construct APP packet"); | ||||||
|                     delete[] frame; |                     delete[] frame; | ||||||
|  |                     app_name.second.pop_front(); | ||||||
|                     return RTP_GENERIC_ERROR; |                     return RTP_GENERIC_ERROR; | ||||||
|                 } |                 } | ||||||
|  |                 app_name.second.pop_front(); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | @ -1753,15 +1773,13 @@ 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, | rtp_error_t uvgrtp::rtcp::send_app_packet(const char* name, uint8_t subtype, | ||||||
|     size_t payload_len, const uint8_t* payload) |     size_t payload_len, const uint8_t* payload) | ||||||
| { | { | ||||||
|     std::string str(name); |  | ||||||
|     rtcp_app_packet packet = { name, subtype, payload_len, payload }; |  | ||||||
|     packet_mutex_.lock(); |     packet_mutex_.lock(); | ||||||
|     if (!app_packets_[name].empty()) |     if (!app_packets_[name].empty()) | ||||||
|     { |     { | ||||||
|         LOG_WARN("Adding a new APP packet for sending when %llu packets are waiting to be sent", |         LOG_WARN("Adding a new APP packet for sending when %llu packets are waiting to be sent", | ||||||
|             app_packets_[name].size()); |             app_packets_[name].size()); | ||||||
|     } |     } | ||||||
|     app_packets_[name].push_back(packet); |     app_packets_[name].emplace_back(name, subtype, payload_len, payload); | ||||||
|     packet_mutex_.unlock(); |     packet_mutex_.unlock(); | ||||||
| 
 | 
 | ||||||
|     return RTP_OK; |     return RTP_OK; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue