Skip to content

Commit a384cc4

Browse files
committed
for ossrs#250, use udp packet handler.
1 parent 35ab0ea commit a384cc4

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

trunk/src/app/srs_app_mpegts_udp.cpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ using namespace std;
3939

4040
#ifdef SRS_AUTO_STREAM_CASTER
4141

42+
ISrsUdpHandler::ISrsUdpHandler()
43+
{
44+
}
45+
46+
ISrsUdpHandler::~ISrsUdpHandler()
47+
{
48+
}
49+
4250
SrsMpegtsOverUdp::SrsMpegtsOverUdp(SrsConfDirective* c)
4351
{
4452
stream = new SrsStream();
@@ -95,7 +103,7 @@ int SrsMpegtsOverUdp::on_udp_packet(sockaddr_in* from, char* buf, int nb_buf)
95103
}
96104

97105
// process each ts packet
98-
if ((ret = on_ts_packet(stream)) != ERROR_SUCCESS) {
106+
if ((ret = context->decode(stream, this)) != ERROR_SUCCESS) {
99107
srs_warn("mpegts: ignore parse ts packet failed. ret=%d", ret);
100108
continue;
101109
}
@@ -111,18 +119,6 @@ int SrsMpegtsOverUdp::on_udp_packet(sockaddr_in* from, char* buf, int nb_buf)
111119
return ret;
112120
}
113121

114-
int SrsMpegtsOverUdp::on_ts_packet(SrsStream* stream)
115-
{
116-
int ret = ERROR_SUCCESS;
117-
118-
if ((ret = context->decode(stream, this)) != ERROR_SUCCESS) {
119-
srs_error("mpegts: decode ts packet failed. ret=%d", ret);
120-
return ret;
121-
}
122-
123-
return ret;
124-
}
125-
126122
int SrsMpegtsOverUdp::on_ts_message(SrsTsMessage* msg)
127123
{
128124
int ret = ERROR_SUCCESS;

trunk/src/app/srs_app_mpegts_udp.hpp

+24-15
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,43 @@ class SrsSimpleBuffer;
4343
#include <srs_kernel_ts.hpp>
4444

4545
/**
46-
* the mpegts over udp stream caster.
46+
* the udp packet handler.
4747
*/
48-
class SrsMpegtsOverUdp : public ISrsTsHandler
48+
class ISrsUdpHandler
4949
{
50-
private:
51-
SrsStream* stream;
52-
SrsTsContext* context;
53-
SrsSimpleBuffer* buffer;
54-
std::string output;
5550
public:
56-
SrsMpegtsOverUdp(SrsConfDirective* c);
57-
virtual ~SrsMpegtsOverUdp();
51+
ISrsUdpHandler();
52+
virtual ~ISrsUdpHandler();
5853
public:
5954
/**
6055
* when udp listener got a udp packet, notice server to process it.
61-
* @param type, the client type, used to create concrete connection,
56+
* @param type, the client type, used to create concrete connection,
6257
* for instance RTMP connection to serve client.
6358
* @param from, the udp packet from address.
6459
* @param buf, the udp packet bytes, user should copy if need to use.
6560
* @param nb_buf, the size of udp packet bytes.
6661
* @remark user should never use the buf, for it's a shared memory bytes.
6762
*/
68-
virtual int on_udp_packet(sockaddr_in* from, char* buf, int nb_buf);
63+
virtual int on_udp_packet(sockaddr_in* from, char* buf, int nb_buf) = 0;
64+
};
65+
66+
/**
67+
* the mpegts over udp stream caster.
68+
*/
69+
class SrsMpegtsOverUdp : virtual public ISrsTsHandler
70+
, virtual public ISrsUdpHandler
71+
{
6972
private:
70-
/**
71-
* the stream contains the ts packet to parse.
72-
*/
73-
virtual int on_ts_packet(SrsStream* stream);
73+
SrsStream* stream;
74+
SrsTsContext* context;
75+
SrsSimpleBuffer* buffer;
76+
std::string output;
77+
public:
78+
SrsMpegtsOverUdp(SrsConfDirective* c);
79+
virtual ~SrsMpegtsOverUdp();
80+
// interface ISrsUdpHandler
81+
public:
82+
virtual int on_udp_packet(sockaddr_in* from, char* buf, int nb_buf);
7483
// interface ISrsTsHandler
7584
public:
7685
virtual int on_ts_message(SrsTsMessage* msg);

trunk/src/app/srs_app_server.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ class SrsIngester;
4545
class SrsHttpHeartbeat;
4646
class SrsKbps;
4747
class SrsConfDirective;
48-
#ifdef SRS_AUTO_STREAM_CASTER
49-
class SrsMpegtsOverUdp;
50-
#endif
48+
class ISrsUdpHandler;
5149

5250
// listener type for server to identify the connection,
5351
// that is, use different type to process the connection.
@@ -96,7 +94,7 @@ class SrsUdpListener : public SrsListener
9694
private:
9795
char* buf;
9896
int nb_buf;
99-
SrsMpegtsOverUdp* caster;
97+
ISrsUdpHandler* caster;
10098
public:
10199
SrsUdpListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c);
102100
virtual ~SrsUdpListener();

0 commit comments

Comments
 (0)