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

For 2034, GB28181: Support transport over TCP

This commit is contained in:
yinjiaoyuan 2020-11-15 22:50:59 +08:00 committed by winlin
parent 751dab56d8
commit fe65c7bf84
12 changed files with 807 additions and 46 deletions

View file

@ -95,6 +95,7 @@ class SrsSipRequest;
class SrsGb28181RtmpMuxer;
class SrsGb28181Config;
class SrsGb28181PsRtpProcessor;
class SrsGb28181TcpPsRtpProcessor;
class SrsGb28181SipService;
class SrsGb28181StreamChannel;
class SrsGb28181SipSession;
@ -103,6 +104,8 @@ class SrsServer;
class SrsSource;
class SrsRequest;
class SrsResourceManager;
class SrsGb28181Conn;
class SrsGb28181Caster;
//ps rtp header packet parse
class SrsPsRtpPacket: public SrsRtpPacket
@ -178,6 +181,33 @@ public:
virtual srs_error_t on_rtp_packet(const sockaddr* from, const int fromlen, char* buf, int nb_buf);
};
class SrsGb28181TcpPsRtpProcessor
{
private:
SrsPithyPrint* pprint;
SrsGb28181Config* config;
std::map<std::string, SrsPsRtpPacket*> cache_ps_rtp_packet;
std::map<std::string, SrsPsRtpPacket*> pre_packet;
std::string channel_id;
bool auto_create_channel;
public:
SrsGb28181TcpPsRtpProcessor(SrsGb28181Config* c, std::string sid);
virtual ~SrsGb28181TcpPsRtpProcessor();
private:
bool can_send_ps_av_packet();
void dispose();
void clear_pre_packet();
SrsGb28181RtmpMuxer* create_rtmpmuxer(std::string channel_id, uint32_t ssrc);
srs_error_t rtmpmuxer_enqueue_data(SrsGb28181RtmpMuxer *muxer, uint32_t ssrc,
int peer_port, std::string address_string, SrsPsRtpPacket *pkt);
// Interface ISrsTcpHandler
public:
virtual srs_error_t on_rtp(char* buf, int nb_buf, std::string ip, int port);
public:
virtual srs_error_t on_rtp_packet_jitter(char* buf, int nb_buf, std::string ip, int port);
virtual srs_error_t on_rtp_packet(char* buf, int nb_buf, std::string ip, int port);
};
//ps stream processing parsing interface
class ISrsPsStreamHander
{
@ -385,6 +415,7 @@ public:
int rtp_port_min;
int rtp_port_max;
int rtp_mux_port;
bool rtp_mux_tcp_enable;
bool auto_create_channel;
bool jitterbuffer_enable;
@ -529,5 +560,54 @@ public:
void remove_sip_session(SrsGb28181SipSession* sess);
};
// The gb28181 tcp connection serve the fd.
class SrsGb28181Conn : public ISrsCoroutineHandler, public ISrsConnection
{
private:
char* mbuffer;
srs_netfd_t stfd;
SrsStSocket* skt;
SrsRtspStack* rtsp;
SrsGb28181Caster* caster;
SrsCoroutine* trd;
SrsGb28181TcpPsRtpProcessor *processor;
public:
SrsGb28181Conn(SrsGb28181Caster* c, srs_netfd_t fd, SrsGb28181TcpPsRtpProcessor *rtp_processor);
virtual ~SrsGb28181Conn();
public:
virtual srs_error_t serve();
virtual std::string remote_ip();
private:
virtual srs_error_t do_cycle();
// Interface ISrsOneCycleThreadHandler
public:
virtual srs_error_t cycle();
virtual std::string desc();
virtual const SrsContextId& get_id();
};
// The caster for gb28181.
class SrsGb28181Caster : public ISrsTcpHandler
{
private:
std::string output;
SrsGb28181Config *config;
SrsGb28181TcpPsRtpProcessor *rtp_processor;
private:
std::vector<SrsGb28181Conn*> clients;
SrsResourceManager* manager;
public:
SrsGb28181Caster(SrsConfDirective* c);
virtual ~SrsGb28181Caster();
public:
virtual srs_error_t initialize();
// Interface ISrsTcpHandler
public:
virtual srs_error_t on_tcp_client(srs_netfd_t stfd);
// internal methods.
public:
virtual void remove(SrsGb28181Conn* conn);
};
#endif