1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 20:01:56 +00:00

RTC: Reuse UDP socket to receive packet. 4.0.67

This commit is contained in:
winlin 2021-02-04 17:27:32 +08:00
parent cfddc8f266
commit 2b85ad1f60
4 changed files with 29 additions and 8 deletions

View file

@ -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

View file

@ -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];
@ -515,6 +533,11 @@ srs_error_t SrsUdpMuxListener::cycle()
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) {
return srs_error_wrap(err, "udp listener");
@ -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) {

View file

@ -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;

View file

@ -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