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

for #250, use udp packet handler.

This commit is contained in:
winlin 2015-01-30 00:04:20 +08:00
parent 35ab0ea627
commit a384cc400a
3 changed files with 35 additions and 32 deletions

View file

@ -39,6 +39,14 @@ using namespace std;
#ifdef SRS_AUTO_STREAM_CASTER #ifdef SRS_AUTO_STREAM_CASTER
ISrsUdpHandler::ISrsUdpHandler()
{
}
ISrsUdpHandler::~ISrsUdpHandler()
{
}
SrsMpegtsOverUdp::SrsMpegtsOverUdp(SrsConfDirective* c) SrsMpegtsOverUdp::SrsMpegtsOverUdp(SrsConfDirective* c)
{ {
stream = new SrsStream(); stream = new SrsStream();
@ -95,7 +103,7 @@ int SrsMpegtsOverUdp::on_udp_packet(sockaddr_in* from, char* buf, int nb_buf)
} }
// process each ts packet // process each ts packet
if ((ret = on_ts_packet(stream)) != ERROR_SUCCESS) { if ((ret = context->decode(stream, this)) != ERROR_SUCCESS) {
srs_warn("mpegts: ignore parse ts packet failed. ret=%d", ret); srs_warn("mpegts: ignore parse ts packet failed. ret=%d", ret);
continue; continue;
} }
@ -111,18 +119,6 @@ int SrsMpegtsOverUdp::on_udp_packet(sockaddr_in* from, char* buf, int nb_buf)
return ret; return ret;
} }
int SrsMpegtsOverUdp::on_ts_packet(SrsStream* stream)
{
int ret = ERROR_SUCCESS;
if ((ret = context->decode(stream, this)) != ERROR_SUCCESS) {
srs_error("mpegts: decode ts packet failed. ret=%d", ret);
return ret;
}
return ret;
}
int SrsMpegtsOverUdp::on_ts_message(SrsTsMessage* msg) int SrsMpegtsOverUdp::on_ts_message(SrsTsMessage* msg)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;

View file

@ -43,18 +43,13 @@ class SrsSimpleBuffer;
#include <srs_kernel_ts.hpp> #include <srs_kernel_ts.hpp>
/** /**
* the mpegts over udp stream caster. * the udp packet handler.
*/ */
class SrsMpegtsOverUdp : public ISrsTsHandler class ISrsUdpHandler
{ {
private:
SrsStream* stream;
SrsTsContext* context;
SrsSimpleBuffer* buffer;
std::string output;
public: public:
SrsMpegtsOverUdp(SrsConfDirective* c); ISrsUdpHandler();
virtual ~SrsMpegtsOverUdp(); virtual ~ISrsUdpHandler();
public: public:
/** /**
* when udp listener got a udp packet, notice server to process it. * when udp listener got a udp packet, notice server to process it.
@ -65,12 +60,26 @@ public:
* @param nb_buf, the size of udp packet bytes. * @param nb_buf, the size of udp packet bytes.
* @remark user should never use the buf, for it's a shared memory bytes. * @remark user should never use the buf, for it's a shared memory bytes.
*/ */
virtual int on_udp_packet(sockaddr_in* from, char* buf, int nb_buf); virtual int on_udp_packet(sockaddr_in* from, char* buf, int nb_buf) = 0;
private: };
/** /**
* the stream contains the ts packet to parse. * the mpegts over udp stream caster.
*/ */
virtual int on_ts_packet(SrsStream* stream); class SrsMpegtsOverUdp : virtual public ISrsTsHandler
, virtual public ISrsUdpHandler
{
private:
SrsStream* stream;
SrsTsContext* context;
SrsSimpleBuffer* buffer;
std::string output;
public:
SrsMpegtsOverUdp(SrsConfDirective* c);
virtual ~SrsMpegtsOverUdp();
// interface ISrsUdpHandler
public:
virtual int on_udp_packet(sockaddr_in* from, char* buf, int nb_buf);
// interface ISrsTsHandler // interface ISrsTsHandler
public: public:
virtual int on_ts_message(SrsTsMessage* msg); virtual int on_ts_message(SrsTsMessage* msg);

View file

@ -45,9 +45,7 @@ class SrsIngester;
class SrsHttpHeartbeat; class SrsHttpHeartbeat;
class SrsKbps; class SrsKbps;
class SrsConfDirective; class SrsConfDirective;
#ifdef SRS_AUTO_STREAM_CASTER class ISrsUdpHandler;
class SrsMpegtsOverUdp;
#endif
// listener type for server to identify the connection, // listener type for server to identify the connection,
// that is, use different type to process the connection. // that is, use different type to process the connection.
@ -96,7 +94,7 @@ class SrsUdpListener : public SrsListener
private: private:
char* buf; char* buf;
int nb_buf; int nb_buf;
SrsMpegtsOverUdp* caster; ISrsUdpHandler* caster;
public: public:
SrsUdpListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c); SrsUdpListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c);
virtual ~SrsUdpListener(); virtual ~SrsUdpListener();