Merge pull request #1612 from xialixin/develop

Fix disconnect RTSP connection has assertion, resulting in program exit
pull/1633/head
winlin 5 years ago committed by GitHub
commit 12a74326e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -240,6 +240,11 @@ srs_error_t SrsRtspConn::serve()
return err; return err;
} }
std::string SrsRtspConn::remote_ip()
{
return "";
}
srs_error_t SrsRtspConn::do_cycle() srs_error_t SrsRtspConn::do_cycle()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -684,6 +689,7 @@ SrsRtspCaster::SrsRtspCaster(SrsConfDirective* c)
output = _srs_config->get_stream_caster_output(c); output = _srs_config->get_stream_caster_output(c);
local_port_min = _srs_config->get_stream_caster_rtp_port_min(c); local_port_min = _srs_config->get_stream_caster_rtp_port_min(c);
local_port_max = _srs_config->get_stream_caster_rtp_port_max(c); local_port_max = _srs_config->get_stream_caster_rtp_port_max(c);
manager = new SrsCoroutineManager();
} }
SrsRtspCaster::~SrsRtspCaster() SrsRtspCaster::~SrsRtspCaster()
@ -691,10 +697,20 @@ SrsRtspCaster::~SrsRtspCaster()
std::vector<SrsRtspConn*>::iterator it; std::vector<SrsRtspConn*>::iterator it;
for (it = clients.begin(); it != clients.end(); ++it) { for (it = clients.begin(); it != clients.end(); ++it) {
SrsRtspConn* conn = *it; SrsRtspConn* conn = *it;
srs_freep(conn); manager->remove(conn);
} }
clients.clear(); clients.clear();
used_ports.clear(); used_ports.clear();
srs_freep(manager);
}
srs_error_t SrsRtspCaster::initialize()
{
srs_error_t err = srs_success;
if ((err = manager->start()) != srs_success) {
return srs_error_wrap(err, "start manager");
}
} }
srs_error_t SrsRtspCaster::alloc_port(int* pport) srs_error_t SrsRtspCaster::alloc_port(int* pport)
@ -747,6 +763,6 @@ void SrsRtspCaster::remove(SrsRtspConn* conn)
} }
srs_info("rtsp: remove connection from caster."); srs_info("rtsp: remove connection from caster.");
srs_freep(conn); manager->remove(conn);
} }

@ -100,7 +100,7 @@ public:
}; };
// The rtsp connection serve the fd. // The rtsp connection serve the fd.
class SrsRtspConn : public ISrsCoroutineHandler class SrsRtspConn : public ISrsCoroutineHandler, public ISrsConnection
{ {
private: private:
std::string output_template; std::string output_template;
@ -143,6 +143,7 @@ public:
virtual ~SrsRtspConn(); virtual ~SrsRtspConn();
public: public:
virtual srs_error_t serve(); virtual srs_error_t serve();
virtual std::string remote_ip();
private: private:
virtual srs_error_t do_cycle(); virtual srs_error_t do_cycle();
// internal methods // internal methods
@ -179,6 +180,7 @@ private:
std::map<int, bool> used_ports; std::map<int, bool> used_ports;
private: private:
std::vector<SrsRtspConn*> clients; std::vector<SrsRtspConn*> clients;
SrsCoroutineManager* manager;
public: public:
SrsRtspCaster(SrsConfDirective* c); SrsRtspCaster(SrsConfDirective* c);
virtual ~SrsRtspCaster(); virtual ~SrsRtspCaster();
@ -188,6 +190,7 @@ public:
virtual srs_error_t alloc_port(int* pport); virtual srs_error_t alloc_port(int* pport);
// Free the alloced rtp port. // Free the alloced rtp port.
virtual void free_port(int lpmin, int lpmax); virtual void free_port(int lpmin, int lpmax);
virtual srs_error_t initialize();
// Interface ISrsTcpHandler // Interface ISrsTcpHandler
public: public:
virtual srs_error_t on_tcp_client(srs_netfd_t stfd); virtual srs_error_t on_tcp_client(srs_netfd_t stfd);

@ -179,6 +179,7 @@ SrsRtspListener::SrsRtspListener(SrsServer* svr, SrsListenerType t, SrsConfDirec
srs_assert(type == SrsListenerRtsp); srs_assert(type == SrsListenerRtsp);
if (type == SrsListenerRtsp) { if (type == SrsListenerRtsp) {
caster = new SrsRtspCaster(c); caster = new SrsRtspCaster(c);
caster->initialize();
} }
} }

@ -50,6 +50,7 @@ class ISrsUdpHandler;
class SrsUdpListener; class SrsUdpListener;
class SrsTcpListener; class SrsTcpListener;
class SrsAppCasterFlv; class SrsAppCasterFlv;
class SrsRtspCaster;
class SrsCoroutineManager; class SrsCoroutineManager;
// The listener type for server to identify the connection, // The listener type for server to identify the connection,
@ -107,7 +108,7 @@ class SrsRtspListener : virtual public SrsListener, virtual public ISrsTcpHandle
{ {
private: private:
SrsTcpListener* listener; SrsTcpListener* listener;
ISrsTcpHandler* caster; SrsRtspCaster* caster;
public: public:
SrsRtspListener(SrsServer* svr, SrsListenerType t, SrsConfDirective* c); SrsRtspListener(SrsServer* svr, SrsListenerType t, SrsConfDirective* c);
virtual ~SrsRtspListener(); virtual ~SrsRtspListener();

Loading…
Cancel
Save