1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

RTC: Use isolate cid for UDP mux listener

This commit is contained in:
winlin 2020-07-22 12:00:23 +08:00
parent d2984ea49c
commit 03105c96c2
2 changed files with 15 additions and 8 deletions

View file

@ -416,6 +416,7 @@ SrsUdpMuxListener::SrsUdpMuxListener(ISrsUdpMuxHandler* h, std::string i, int p)
buf = new char[nb_buf]; buf = new char[nb_buf];
trd = new SrsDummyCoroutine(); trd = new SrsDummyCoroutine();
cid = _srs_context->generate_id();
} }
SrsUdpMuxListener::~SrsUdpMuxListener() SrsUdpMuxListener::~SrsUdpMuxListener()
@ -442,11 +443,9 @@ srs_error_t SrsUdpMuxListener::listen()
if ((err = srs_udp_listen(ip, port, &lfd)) != srs_success) { if ((err = srs_udp_listen(ip, port, &lfd)) != srs_success) {
return srs_error_wrap(err, "listen %s:%d", ip.c_str(), port); return srs_error_wrap(err, "listen %s:%d", ip.c_str(), port);
} }
set_socket_buffer();
srs_freep(trd); srs_freep(trd);
trd = new SrsSTCoroutine("udp", this); trd = new SrsSTCoroutine("udp", this, cid);
if ((err = trd->start()) != srs_success) { if ((err = trd->start()) != srs_success) {
return srs_error_wrap(err, "start thread"); return srs_error_wrap(err, "start thread");
} }
@ -506,6 +505,8 @@ srs_error_t SrsUdpMuxListener::cycle()
uint64_t nn_msgs_last = 0; uint64_t nn_msgs_last = 0;
uint64_t nn_loop = 0; uint64_t nn_loop = 0;
srs_utime_t time_last = srs_get_system_time(); srs_utime_t time_last = srs_get_system_time();
set_socket_buffer();
while (true) { while (true) {
if ((err = trd->pull()) != srs_success) { if ((err = trd->pull()) != srs_success) {
@ -531,8 +532,13 @@ srs_error_t SrsUdpMuxListener::cycle()
nn_msgs++; nn_msgs++;
nn_msgs_stage++; nn_msgs_stage++;
if ((err = handler->on_udp_packet(&skt)) != srs_success) { // Restore context when packets processed.
if (true) {
SrsContextRestore(cid);
err = handler->on_udp_packet(&skt);
}
if (err != srs_success) {
// remux udp never return // remux udp never return
srs_warn("udp packet handler error:%s", srs_error_desc(err).c_str()); srs_warn("udp packet handler error:%s", srs_error_desc(err).c_str());
srs_error_reset(err); srs_error_reset(err);

View file

@ -163,13 +163,14 @@ public:
class SrsUdpMuxListener : public ISrsCoroutineHandler class SrsUdpMuxListener : public ISrsCoroutineHandler
{ {
protected: private:
srs_netfd_t lfd; srs_netfd_t lfd;
SrsCoroutine* trd; SrsCoroutine* trd;
protected: SrsContextId cid;
private:
char* buf; char* buf;
int nb_buf; int nb_buf;
protected: private:
ISrsUdpMuxHandler* handler; ISrsUdpMuxHandler* handler;
std::string ip; std::string ip;
int port; int port;