mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
RTC: Reuse UDP socket to receive packet. 4.0.67
This commit is contained in:
parent
cfddc8f266
commit
2b85ad1f60
4 changed files with 29 additions and 8 deletions
|
@ -155,6 +155,7 @@ For previous versions, please read:
|
||||||
|
|
||||||
## V4 changes
|
## 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-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-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
|
* 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;
|
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.
|
// TODO: FIXME: Maybe we should not covert to string for each packet.
|
||||||
char address_string[64];
|
char address_string[64];
|
||||||
char port_string[16];
|
char port_string[16];
|
||||||
|
@ -515,6 +533,11 @@ srs_error_t SrsUdpMuxListener::cycle()
|
||||||
|
|
||||||
set_socket_buffer();
|
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) {
|
while (true) {
|
||||||
if ((err = trd->pull()) != srs_success) {
|
if ((err = trd->pull()) != srs_success) {
|
||||||
return srs_error_wrap(err, "udp listener");
|
return srs_error_wrap(err, "udp listener");
|
||||||
|
@ -522,12 +545,6 @@ srs_error_t SrsUdpMuxListener::cycle()
|
||||||
|
|
||||||
nn_loop++;
|
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);
|
int nread = skt.recvfrom(SRS_UTIME_NO_TIMEOUT);
|
||||||
if (nread <= 0) {
|
if (nread <= 0) {
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <srs_app_st.hpp>
|
#include <srs_app_st.hpp>
|
||||||
|
@ -135,6 +136,8 @@ public:
|
||||||
// TODO: FIXME: Rename it. Refine it for performance issue.
|
// TODO: FIXME: Rename it. Refine it for performance issue.
|
||||||
class SrsUdpMuxSocket
|
class SrsUdpMuxSocket
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
std::map<uint32_t, std::string> cache_;
|
||||||
private:
|
private:
|
||||||
char* buf;
|
char* buf;
|
||||||
int nb_buf;
|
int nb_buf;
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
#ifndef SRS_CORE_VERSION4_HPP
|
#ifndef SRS_CORE_VERSION4_HPP
|
||||||
#define SRS_CORE_VERSION4_HPP
|
#define SRS_CORE_VERSION4_HPP
|
||||||
|
|
||||||
#define SRS_VERSION4_REVISION 66
|
#define SRS_VERSION4_REVISION 67
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue