2017-03-25 09:21:39 +00:00
|
|
|
/**
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
2017-03-25 13:29:29 +00:00
|
|
|
* Copyright (c) 2013-2017 OSSRS(winlin)
|
2017-03-25 09:21:39 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2013-11-23 03:36:07 +00:00
|
|
|
|
2014-03-02 13:49:09 +00:00
|
|
|
#ifndef SRS_APP_SERVER_HPP
|
|
|
|
#define SRS_APP_SERVER_HPP
|
2013-11-23 03:36:07 +00:00
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
|
|
|
#include <vector>
|
2015-02-03 08:01:07 +00:00
|
|
|
#include <string>
|
2013-11-23 03:36:07 +00:00
|
|
|
|
2014-03-02 13:49:09 +00:00
|
|
|
#include <srs_app_st.hpp>
|
|
|
|
#include <srs_app_reload.hpp>
|
2015-01-18 10:39:53 +00:00
|
|
|
#include <srs_app_source.hpp>
|
2015-02-03 08:01:07 +00:00
|
|
|
#include <srs_app_hls.hpp>
|
2015-02-17 08:28:28 +00:00
|
|
|
#include <srs_app_listener.hpp>
|
2015-05-03 15:34:59 +00:00
|
|
|
#include <srs_app_conn.hpp>
|
2017-05-30 01:05:02 +00:00
|
|
|
#include <srs_service_st.hpp>
|
2013-11-23 03:36:07 +00:00
|
|
|
|
|
|
|
class SrsServer;
|
|
|
|
class SrsConnection;
|
2015-03-04 05:09:35 +00:00
|
|
|
class SrsHttpServeMux;
|
2015-01-17 15:00:40 +00:00
|
|
|
class SrsHttpServer;
|
2014-04-07 01:27:30 +00:00
|
|
|
class SrsIngester;
|
2014-05-19 09:39:01 +00:00
|
|
|
class SrsHttpHeartbeat;
|
2014-06-19 07:28:05 +00:00
|
|
|
class SrsKbps;
|
2015-01-24 08:27:30 +00:00
|
|
|
class SrsConfDirective;
|
2015-02-17 13:10:06 +00:00
|
|
|
class ISrsTcpHandler;
|
2015-01-29 16:04:20 +00:00
|
|
|
class ISrsUdpHandler;
|
2015-02-17 08:28:28 +00:00
|
|
|
class SrsUdpListener;
|
|
|
|
class SrsTcpListener;
|
2015-05-03 15:34:59 +00:00
|
|
|
#ifdef SRS_AUTO_STREAM_CASTER
|
|
|
|
class SrsAppCasterFlv;
|
|
|
|
#endif
|
2015-09-22 09:46:07 +00:00
|
|
|
#ifdef SRS_AUTO_KAFKA
|
2015-09-22 09:40:05 +00:00
|
|
|
class SrsKafkaProducer;
|
2015-09-22 09:46:07 +00:00
|
|
|
#endif
|
2017-05-29 10:34:41 +00:00
|
|
|
class SrsCoroutineManager;
|
2013-11-23 03:36:07 +00:00
|
|
|
|
2014-03-27 04:27:47 +00:00
|
|
|
// listener type for server to identify the connection,
|
|
|
|
// that is, use different type to process the connection.
|
2017-03-25 09:21:39 +00:00
|
|
|
enum SrsListenerType
|
2013-11-23 03:36:07 +00:00
|
|
|
{
|
2014-03-27 04:27:47 +00:00
|
|
|
// RTMP client,
|
2017-01-16 07:47:26 +00:00
|
|
|
SrsListenerRtmpStream = 0,
|
2014-03-27 04:27:47 +00:00
|
|
|
// HTTP api,
|
2017-01-16 07:47:26 +00:00
|
|
|
SrsListenerHttpApi = 1,
|
2014-03-27 04:27:47 +00:00
|
|
|
// HTTP stream, HDS/HLS/DASH
|
2017-01-16 07:47:26 +00:00
|
|
|
SrsListenerHttpStream = 2,
|
2015-01-24 06:52:52 +00:00
|
|
|
// UDP stream, MPEG-TS over udp.
|
2017-01-16 07:47:26 +00:00
|
|
|
SrsListenerMpegTsOverUdp = 3,
|
2015-02-15 13:28:31 +00:00
|
|
|
// TCP stream, RTSP stream.
|
2017-01-16 07:47:26 +00:00
|
|
|
SrsListenerRtsp = 4,
|
2015-05-03 15:34:59 +00:00
|
|
|
// TCP stream, FLV stream over HTTP.
|
2017-01-16 07:47:26 +00:00
|
|
|
SrsListenerFlv = 5,
|
2013-11-23 03:36:07 +00:00
|
|
|
};
|
|
|
|
|
2015-01-24 06:52:52 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* the common tcp listener, for RTMP/HTTP server.
|
|
|
|
*/
|
2015-02-17 08:28:28 +00:00
|
|
|
class SrsListener
|
2013-11-23 03:36:07 +00:00
|
|
|
{
|
2015-02-17 08:28:28 +00:00
|
|
|
protected:
|
2015-05-19 10:06:20 +00:00
|
|
|
SrsListenerType type;
|
2015-01-24 06:52:52 +00:00
|
|
|
protected:
|
2015-05-19 10:06:20 +00:00
|
|
|
std::string ip;
|
|
|
|
int port;
|
|
|
|
SrsServer* server;
|
2013-11-23 03:36:07 +00:00
|
|
|
public:
|
2015-05-19 10:06:20 +00:00
|
|
|
SrsListener(SrsServer* svr, SrsListenerType t);
|
2014-03-18 03:32:58 +00:00
|
|
|
virtual ~SrsListener();
|
2013-11-23 03:36:07 +00:00
|
|
|
public:
|
2015-05-19 10:06:20 +00:00
|
|
|
virtual SrsListenerType listen_type();
|
|
|
|
virtual int listen(std::string i, int p) = 0;
|
2015-02-17 08:28:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* tcp listener.
|
|
|
|
*/
|
2015-09-22 00:57:31 +00:00
|
|
|
class SrsBufferListener : virtual public SrsListener, virtual public ISrsTcpHandler
|
2015-02-17 08:28:28 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
SrsTcpListener* listener;
|
|
|
|
public:
|
2015-09-22 00:57:31 +00:00
|
|
|
SrsBufferListener(SrsServer* server, SrsListenerType type);
|
|
|
|
virtual ~SrsBufferListener();
|
2015-02-17 08:28:28 +00:00
|
|
|
public:
|
2015-03-23 15:13:57 +00:00
|
|
|
virtual int listen(std::string ip, int port);
|
2017-03-25 09:21:39 +00:00
|
|
|
// ISrsTcpHandler
|
2013-12-14 06:06:32 +00:00
|
|
|
public:
|
2017-05-30 01:05:02 +00:00
|
|
|
virtual int on_tcp_client(srs_netfd_t stfd);
|
2015-01-24 06:52:52 +00:00
|
|
|
};
|
|
|
|
|
2015-01-24 08:27:30 +00:00
|
|
|
#ifdef SRS_AUTO_STREAM_CASTER
|
2015-02-15 13:28:31 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* the tcp listener, for rtsp server.
|
|
|
|
*/
|
2015-02-17 08:28:28 +00:00
|
|
|
class SrsRtspListener : virtual public SrsListener, virtual public ISrsTcpHandler
|
2015-02-15 13:28:31 +00:00
|
|
|
{
|
2015-02-17 08:28:28 +00:00
|
|
|
private:
|
|
|
|
SrsTcpListener* listener;
|
2015-02-17 13:10:06 +00:00
|
|
|
ISrsTcpHandler* caster;
|
2015-02-15 13:28:31 +00:00
|
|
|
public:
|
2015-05-19 10:06:20 +00:00
|
|
|
SrsRtspListener(SrsServer* svr, SrsListenerType t, SrsConfDirective* c);
|
2015-02-15 13:28:31 +00:00
|
|
|
virtual ~SrsRtspListener();
|
|
|
|
public:
|
2015-05-19 10:06:20 +00:00
|
|
|
virtual int listen(std::string i, int p);
|
2017-03-25 09:21:39 +00:00
|
|
|
// ISrsTcpHandler
|
2015-02-17 08:28:28 +00:00
|
|
|
public:
|
2017-05-30 01:05:02 +00:00
|
|
|
virtual int on_tcp_client(srs_netfd_t stfd);
|
2015-02-15 13:28:31 +00:00
|
|
|
};
|
|
|
|
|
2015-05-03 02:56:20 +00:00
|
|
|
/**
|
2015-05-03 15:34:59 +00:00
|
|
|
* the tcp listener, for flv stream server.
|
2015-05-03 02:56:20 +00:00
|
|
|
*/
|
|
|
|
class SrsHttpFlvListener : virtual public SrsListener, virtual public ISrsTcpHandler
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
SrsTcpListener* listener;
|
2015-05-03 15:34:59 +00:00
|
|
|
SrsAppCasterFlv* caster;
|
2015-05-03 02:56:20 +00:00
|
|
|
public:
|
2015-05-19 10:06:20 +00:00
|
|
|
SrsHttpFlvListener(SrsServer* svr, SrsListenerType t, SrsConfDirective* c);
|
2015-05-03 02:56:20 +00:00
|
|
|
virtual ~SrsHttpFlvListener();
|
|
|
|
public:
|
2015-05-19 10:06:20 +00:00
|
|
|
virtual int listen(std::string i, int p);
|
2017-03-25 09:21:39 +00:00
|
|
|
// ISrsTcpHandler
|
2015-05-03 02:56:20 +00:00
|
|
|
public:
|
2017-05-30 01:05:02 +00:00
|
|
|
virtual int on_tcp_client(srs_netfd_t stfd);
|
2015-05-03 02:56:20 +00:00
|
|
|
};
|
2015-05-19 10:06:20 +00:00
|
|
|
#endif
|
2015-05-03 02:56:20 +00:00
|
|
|
|
2015-01-24 06:52:52 +00:00
|
|
|
/**
|
2015-05-19 10:06:20 +00:00
|
|
|
* the udp listener, for udp server.
|
|
|
|
*/
|
|
|
|
class SrsUdpStreamListener : public SrsListener
|
2015-01-24 06:52:52 +00:00
|
|
|
{
|
2015-05-19 10:06:20 +00:00
|
|
|
protected:
|
2015-02-17 08:28:28 +00:00
|
|
|
SrsUdpListener* listener;
|
2015-01-29 16:04:20 +00:00
|
|
|
ISrsUdpHandler* caster;
|
2015-01-24 06:52:52 +00:00
|
|
|
public:
|
2015-05-19 10:06:20 +00:00
|
|
|
SrsUdpStreamListener(SrsServer* svr, SrsListenerType t, ISrsUdpHandler* c);
|
|
|
|
virtual ~SrsUdpStreamListener();
|
2015-01-24 06:52:52 +00:00
|
|
|
public:
|
2015-05-19 10:06:20 +00:00
|
|
|
virtual int listen(std::string i, int p);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the udp listener, for udp stream caster server.
|
|
|
|
*/
|
|
|
|
#ifdef SRS_AUTO_STREAM_CASTER
|
|
|
|
class SrsUdpCasterListener : public SrsUdpStreamListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SrsUdpCasterListener(SrsServer* svr, SrsListenerType t, SrsConfDirective* c);
|
|
|
|
virtual ~SrsUdpCasterListener();
|
2013-11-23 03:36:07 +00:00
|
|
|
};
|
2015-01-24 08:27:30 +00:00
|
|
|
#endif
|
2013-11-23 03:36:07 +00:00
|
|
|
|
2014-04-30 03:26:32 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* convert signal to io,
|
|
|
|
* @see: st-1.9/docs/notes.html
|
|
|
|
*/
|
2017-05-29 09:56:26 +00:00
|
|
|
class SrsSignalManager : public ISrsCoroutineHandler
|
2014-04-30 03:26:32 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
/* Per-process pipe which is used as a signal queue. */
|
|
|
|
/* Up to PIPE_BUF/sizeof(int) signals can be queued up. */
|
|
|
|
int sig_pipe[2];
|
2017-05-30 01:05:02 +00:00
|
|
|
srs_netfd_t signal_read_stfd;
|
2014-04-30 03:26:32 +00:00
|
|
|
private:
|
2017-05-29 09:56:26 +00:00
|
|
|
SrsServer* server;
|
|
|
|
SrsCoroutine* trd;
|
2014-04-30 03:26:32 +00:00
|
|
|
public:
|
2017-05-29 09:56:26 +00:00
|
|
|
SrsSignalManager(SrsServer* s);
|
2014-04-30 03:26:32 +00:00
|
|
|
virtual ~SrsSignalManager();
|
|
|
|
public:
|
2017-06-10 07:20:48 +00:00
|
|
|
virtual srs_error_t initialize();
|
2014-04-30 03:26:32 +00:00
|
|
|
virtual int start();
|
2015-05-23 01:20:16 +00:00
|
|
|
// interface ISrsEndlessThreadHandler.
|
2014-04-30 03:26:32 +00:00
|
|
|
public:
|
|
|
|
virtual int cycle();
|
|
|
|
private:
|
|
|
|
// global singleton instance
|
|
|
|
static SrsSignalManager* instance;
|
|
|
|
/* Signal catching function. */
|
|
|
|
/* Converts signal event to I/O event. */
|
|
|
|
static void sig_catcher(int signo);
|
|
|
|
};
|
|
|
|
|
2015-03-31 10:06:55 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* the handler to the handle cycle in SRS RTMP server.
|
|
|
|
*/
|
2015-03-31 10:06:55 +00:00
|
|
|
class ISrsServerCycle
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ISrsServerCycle();
|
|
|
|
virtual ~ISrsServerCycle();
|
2017-03-25 09:21:39 +00:00
|
|
|
public:
|
2015-03-31 10:06:55 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* initialize the cycle handler.
|
|
|
|
*/
|
2017-06-09 05:29:23 +00:00
|
|
|
virtual srs_error_t initialize() = 0;
|
2015-03-31 10:06:55 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* do on_cycle while server doing cycle.
|
|
|
|
*/
|
2015-12-08 10:32:37 +00:00
|
|
|
virtual int on_cycle() = 0;
|
|
|
|
/**
|
|
|
|
* callback the handler when got client.
|
|
|
|
*/
|
|
|
|
virtual int on_accept_client(int conf_conns, int curr_conns) = 0;
|
2015-03-31 10:06:55 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 07:28:05 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* SRS RTMP server, initialize and listen,
|
|
|
|
* start connection service thread, destroy client.
|
|
|
|
*/
|
2015-01-18 10:39:53 +00:00
|
|
|
class SrsServer : virtual public ISrsReloadHandler
|
2017-05-29 10:34:41 +00:00
|
|
|
, virtual public ISrsSourceHandler
|
|
|
|
, virtual public IConnectionManager
|
2013-11-23 03:36:07 +00:00
|
|
|
{
|
2014-04-02 10:07:34 +00:00
|
|
|
private:
|
2015-06-14 06:06:39 +00:00
|
|
|
// TODO: FIXME: rename to http_api
|
2015-03-04 05:09:35 +00:00
|
|
|
SrsHttpServeMux* http_api_mux;
|
2015-06-14 06:06:39 +00:00
|
|
|
SrsHttpServer* http_server;
|
2014-05-19 09:39:01 +00:00
|
|
|
SrsHttpHeartbeat* http_heartbeat;
|
2014-04-15 06:01:57 +00:00
|
|
|
#ifdef SRS_AUTO_INGEST
|
2014-04-07 01:27:30 +00:00
|
|
|
SrsIngester* ingester;
|
|
|
|
#endif
|
2017-05-29 10:34:41 +00:00
|
|
|
SrsCoroutineManager* conn_manager;
|
2013-11-23 03:36:07 +00:00
|
|
|
private:
|
2014-07-16 03:23:49 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* the pid file fd, lock the file write when server is running.
|
|
|
|
* @remark the init.d script should cleanup the pid file, when stop service,
|
|
|
|
* for the server never delete the file; when system startup, the pid in pid file
|
|
|
|
* maybe valid but the process is not SRS, the init.d script will never start server.
|
|
|
|
*/
|
2014-04-12 12:46:32 +00:00
|
|
|
int pid_fd;
|
2014-07-16 03:23:49 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* all connections, connection manager
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
std::vector<SrsConnection*> conns;
|
2014-07-16 03:23:49 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* all listners, listener manager.
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
std::vector<SrsListener*> listeners;
|
2014-07-16 03:23:49 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* signal manager which convert gignal to io message.
|
|
|
|
*/
|
2014-04-30 03:26:32 +00:00
|
|
|
SrsSignalManager* signal_manager;
|
2014-07-16 03:23:49 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* handle in server cycle.
|
|
|
|
*/
|
2015-03-31 10:06:55 +00:00
|
|
|
ISrsServerCycle* handler;
|
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* user send the signal, convert to variable.
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
bool signal_reload;
|
2015-08-26 13:11:28 +00:00
|
|
|
bool signal_persistence_config;
|
2014-03-18 03:32:58 +00:00
|
|
|
bool signal_gmc_stop;
|
2015-05-30 01:58:17 +00:00
|
|
|
bool signal_gracefully_quit;
|
2016-09-23 07:00:50 +00:00
|
|
|
// parent pid for asprocess.
|
|
|
|
int ppid;
|
2013-11-23 03:36:07 +00:00
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
SrsServer();
|
|
|
|
virtual ~SrsServer();
|
2015-05-30 01:58:17 +00:00
|
|
|
private:
|
2014-07-16 03:23:49 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* the destroy is for gmc to analysis the memory leak,
|
|
|
|
* if not destroy global/static data, the gmc will warning memory leak.
|
|
|
|
* in service, server never destroy, directly exit when restart.
|
|
|
|
*/
|
2014-05-02 06:08:48 +00:00
|
|
|
virtual void destroy();
|
2015-05-30 01:58:17 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* when SIGTERM, SRS should do cleanup, for example,
|
2015-05-30 01:58:17 +00:00
|
|
|
* to stop all ingesters, cleanup HLS and dvr.
|
|
|
|
*/
|
|
|
|
virtual void dispose();
|
2017-03-25 09:21:39 +00:00
|
|
|
// server startup workflow, @see run_master()
|
2013-11-23 03:36:07 +00:00
|
|
|
public:
|
2015-06-09 03:47:04 +00:00
|
|
|
/**
|
|
|
|
* initialize server with callback handler.
|
|
|
|
* @remark user must free the cycle handler.
|
|
|
|
*/
|
2017-06-09 03:50:35 +00:00
|
|
|
virtual srs_error_t initialize(ISrsServerCycle* cycle_handler);
|
2017-06-10 06:29:41 +00:00
|
|
|
virtual srs_error_t initialize_st();
|
2017-06-10 07:20:48 +00:00
|
|
|
virtual srs_error_t initialize_signal();
|
|
|
|
virtual srs_error_t acquire_pid_file();
|
|
|
|
virtual srs_error_t listen();
|
|
|
|
virtual srs_error_t register_signal();
|
|
|
|
virtual srs_error_t http_handle();
|
|
|
|
virtual srs_error_t ingest();
|
|
|
|
virtual srs_error_t cycle();
|
2017-03-25 09:21:39 +00:00
|
|
|
// server utilities.
|
2015-05-03 15:34:59 +00:00
|
|
|
public:
|
2014-07-16 03:23:49 +00:00
|
|
|
/**
|
2015-08-27 10:11:50 +00:00
|
|
|
* callback for signal manager got a signal.
|
|
|
|
* the signal manager convert signal to io message,
|
|
|
|
* whatever, we will got the signo like the orignal signal(int signo) handler.
|
|
|
|
* @param signo the signal number from user, where:
|
|
|
|
* SRS_SIGNAL_GRACEFULLY_QUIT, the SIGTERM, dispose then quit.
|
2016-12-08 10:23:22 +00:00
|
|
|
* SRS_SIGNAL_REOPEN_LOG, the SIGUSR1, reopen the log file.
|
2015-08-27 10:11:50 +00:00
|
|
|
* SRS_SIGNAL_RELOAD, the SIGHUP, reload the config.
|
2016-12-08 10:23:22 +00:00
|
|
|
* SRS_SIGNAL_PERSISTENCE_CONFIG, application level signal, persistence config to file.
|
|
|
|
* @remark, for SIGINT:
|
2015-08-27 10:11:50 +00:00
|
|
|
* no gmc, directly exit.
|
|
|
|
* for gmc, set the variable signal_gmc_stop, the cycle will return and cleanup for gmc.
|
|
|
|
* @remark, maybe the HTTP RAW API will trigger the on_signal() also.
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
virtual void on_signal(int signo);
|
2013-11-23 03:36:07 +00:00
|
|
|
private:
|
2014-07-16 03:23:49 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* the server thread main cycle,
|
|
|
|
* update the global static data, for instance, the current time,
|
|
|
|
* the cpu/mem/network statistic.
|
|
|
|
*/
|
2017-06-10 07:20:48 +00:00
|
|
|
virtual srs_error_t do_cycle();
|
2014-07-16 03:23:49 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* listen at specified protocol.
|
|
|
|
*/
|
2017-06-10 07:20:48 +00:00
|
|
|
virtual srs_error_t listen_rtmp();
|
|
|
|
virtual srs_error_t listen_http_api();
|
|
|
|
virtual srs_error_t listen_http_stream();
|
|
|
|
virtual srs_error_t listen_stream_caster();
|
2014-07-16 03:23:49 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* close the listeners for specified type,
|
|
|
|
* remove the listen object from manager.
|
|
|
|
*/
|
2014-04-12 14:16:39 +00:00
|
|
|
virtual void close_listeners(SrsListenerType type);
|
2014-07-16 03:23:49 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* resample the server kbs.
|
|
|
|
*/
|
2015-03-08 04:55:40 +00:00
|
|
|
virtual void resample_kbps();
|
2017-03-25 09:21:39 +00:00
|
|
|
// internal only
|
2014-04-30 03:26:32 +00:00
|
|
|
public:
|
2014-07-16 03:23:49 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* when listener got a fd, notice server to accept it.
|
|
|
|
* @param type, the client type, used to create concrete connection,
|
|
|
|
* for instance RTMP connection to serve client.
|
|
|
|
* @param stfd, the client fd in st boxed, the underlayer fd.
|
|
|
|
*/
|
2017-05-30 01:05:02 +00:00
|
|
|
virtual int accept_client(SrsListenerType type, srs_netfd_t stfd);
|
2015-12-24 09:25:05 +00:00
|
|
|
private:
|
2017-05-30 01:05:02 +00:00
|
|
|
virtual SrsConnection* fd2conn(SrsListenerType type, srs_netfd_t stfd);
|
2017-03-25 09:21:39 +00:00
|
|
|
// IConnectionManager
|
2015-09-23 09:21:57 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* callback for connection to remove itself.
|
|
|
|
* when connection thread cycle terminated, callback this to delete connection.
|
|
|
|
* @see SrsConnection.on_thread_stop().
|
|
|
|
*/
|
2017-03-26 05:40:39 +00:00
|
|
|
virtual void remove(ISrsConnection* c);
|
2015-05-19 10:06:20 +00:00
|
|
|
// interface ISrsReloadHandler.
|
2013-11-23 03:36:07 +00:00
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
virtual int on_reload_listen();
|
2014-04-12 12:46:32 +00:00
|
|
|
virtual int on_reload_pid();
|
2014-04-13 05:27:51 +00:00
|
|
|
virtual int on_reload_vhost_added(std::string vhost);
|
|
|
|
virtual int on_reload_vhost_removed(std::string vhost);
|
2014-04-13 05:08:10 +00:00
|
|
|
virtual int on_reload_http_api_enabled();
|
|
|
|
virtual int on_reload_http_api_disabled();
|
2014-04-13 05:27:51 +00:00
|
|
|
virtual int on_reload_http_stream_enabled();
|
|
|
|
virtual int on_reload_http_stream_disabled();
|
|
|
|
virtual int on_reload_http_stream_updated();
|
2015-01-18 10:39:53 +00:00
|
|
|
// interface ISrsSourceHandler
|
|
|
|
public:
|
|
|
|
virtual int on_publish(SrsSource* s, SrsRequest* r);
|
|
|
|
virtual void on_unpublish(SrsSource* s, SrsRequest* r);
|
2013-11-23 03:36:07 +00:00
|
|
|
};
|
|
|
|
|
2014-08-02 14:18:39 +00:00
|
|
|
#endif
|
2015-03-10 10:07:43 +00:00
|
|
|
|