RTC: Reuse UDP socket to receive packet. 4.0.67

pull/2199/head
winlin 4 years ago
parent 9ada516e98
commit b0208029bb

@ -155,6 +155,7 @@ For previous versions, please read:
## V4 changes
* v4.0, 2021-02-04, RTC: Reuse UDP socket to receive packet. 4.0.67
* v4.0, 2021-02-04, At least wait 1ms when <1ms, to avoid epoll_wait spin loop. 4.0.66
* v4.0, 2021-01-31, Enable -std=c++11 by default. 4.0.65
* v4.0, 2021-01-25, Enable --nasm and --srtp-asm by default for performance. 4.0.64

@ -313,7 +313,25 @@ int SrsUdpMuxSocket::recvfrom(srs_utime_t timeout)
return 0;
}
if (nread > 0) {
// Parse address from cache.
bool parsed = false;
if (from.ss_family == AF_INET) {
sockaddr_in* addr = (sockaddr_in*)&from;
// Load from fast cache, previous ip.
std::map<uint32_t, string>::iterator it = cache_.find(addr->sin_addr.s_addr);
if (it == cache_.end()) {
peer_ip = inet_ntoa(addr->sin_addr);
cache_[addr->sin_addr.s_addr] = peer_ip;
} else {
peer_ip = it->second;
}
peer_port = ntohs(addr->sin_port);
parsed = true;
}
if (!parsed && nread > 0) {
// TODO: FIXME: Maybe we should not covert to string for each packet.
char address_string[64];
char port_string[16];
@ -514,6 +532,11 @@ srs_error_t SrsUdpMuxListener::cycle()
SrsAutoFree(SrsErrorPithyPrint, pp_pkt_handler_err);
set_socket_buffer();
// Because we have to decrypt the cipher of received packet payload,
// and the size is not determined, so we think there is at least one copy,
// and we can reuse the plaintext h264/opus with players when got plaintext.
SrsUdpMuxSocket skt(lfd);
while (true) {
if ((err = trd->pull()) != srs_success) {
@ -522,12 +545,6 @@ srs_error_t SrsUdpMuxListener::cycle()
nn_loop++;
// TODO: FIXME: Refactor the memory cache for receiver.
// Because we have to decrypt the cipher of received packet payload,
// and the size is not determined, so we think there is at least one copy,
// and we can reuse the plaintext h264/opus with players when got plaintext.
SrsUdpMuxSocket skt(lfd);
int nread = skt.recvfrom(SRS_UTIME_NO_TIMEOUT);
if (nread <= 0) {
if (nread < 0) {

@ -29,6 +29,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <map>
#include <string>
#include <srs_app_st.hpp>
@ -135,6 +136,8 @@ public:
// TODO: FIXME: Rename it. Refine it for performance issue.
class SrsUdpMuxSocket
{
private:
std::map<uint32_t, std::string> cache_;
private:
char* buf;
int nb_buf;

@ -24,6 +24,6 @@
#ifndef SRS_CORE_VERSION4_HPP
#define SRS_CORE_VERSION4_HPP
#define SRS_VERSION4_REVISION 66
#define SRS_VERSION4_REVISION 67
#endif

Loading…
Cancel
Save