正在显示
3 个修改的文件
包含
35 行增加
和
32 行删除
@@ -39,6 +39,14 @@ using namespace std; | @@ -39,6 +39,14 @@ using namespace std; | ||
39 | 39 | ||
40 | #ifdef SRS_AUTO_STREAM_CASTER | 40 | #ifdef SRS_AUTO_STREAM_CASTER |
41 | 41 | ||
42 | +ISrsUdpHandler::ISrsUdpHandler() | ||
43 | +{ | ||
44 | +} | ||
45 | + | ||
46 | +ISrsUdpHandler::~ISrsUdpHandler() | ||
47 | +{ | ||
48 | +} | ||
49 | + | ||
42 | SrsMpegtsOverUdp::SrsMpegtsOverUdp(SrsConfDirective* c) | 50 | SrsMpegtsOverUdp::SrsMpegtsOverUdp(SrsConfDirective* c) |
43 | { | 51 | { |
44 | stream = new SrsStream(); | 52 | stream = new SrsStream(); |
@@ -95,7 +103,7 @@ int SrsMpegtsOverUdp::on_udp_packet(sockaddr_in* from, char* buf, int nb_buf) | @@ -95,7 +103,7 @@ int SrsMpegtsOverUdp::on_udp_packet(sockaddr_in* from, char* buf, int nb_buf) | ||
95 | } | 103 | } |
96 | 104 | ||
97 | // process each ts packet | 105 | // process each ts packet |
98 | - if ((ret = on_ts_packet(stream)) != ERROR_SUCCESS) { | 106 | + if ((ret = context->decode(stream, this)) != ERROR_SUCCESS) { |
99 | srs_warn("mpegts: ignore parse ts packet failed. ret=%d", ret); | 107 | srs_warn("mpegts: ignore parse ts packet failed. ret=%d", ret); |
100 | continue; | 108 | continue; |
101 | } | 109 | } |
@@ -111,18 +119,6 @@ int SrsMpegtsOverUdp::on_udp_packet(sockaddr_in* from, char* buf, int nb_buf) | @@ -111,18 +119,6 @@ int SrsMpegtsOverUdp::on_udp_packet(sockaddr_in* from, char* buf, int nb_buf) | ||
111 | return ret; | 119 | return ret; |
112 | } | 120 | } |
113 | 121 | ||
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 | - | ||
126 | int SrsMpegtsOverUdp::on_ts_message(SrsTsMessage* msg) | 122 | int SrsMpegtsOverUdp::on_ts_message(SrsTsMessage* msg) |
127 | { | 123 | { |
128 | int ret = ERROR_SUCCESS; | 124 | int ret = ERROR_SUCCESS; |
@@ -43,34 +43,43 @@ class SrsSimpleBuffer; | @@ -43,34 +43,43 @@ class SrsSimpleBuffer; | ||
43 | #include <srs_kernel_ts.hpp> | 43 | #include <srs_kernel_ts.hpp> |
44 | 44 | ||
45 | /** | 45 | /** |
46 | -* the mpegts over udp stream caster. | 46 | +* the udp packet handler. |
47 | */ | 47 | */ |
48 | -class SrsMpegtsOverUdp : public ISrsTsHandler | 48 | +class ISrsUdpHandler |
49 | { | 49 | { |
50 | -private: | ||
51 | - SrsStream* stream; | ||
52 | - SrsTsContext* context; | ||
53 | - SrsSimpleBuffer* buffer; | ||
54 | - std::string output; | ||
55 | public: | 50 | public: |
56 | - SrsMpegtsOverUdp(SrsConfDirective* c); | ||
57 | - virtual ~SrsMpegtsOverUdp(); | 51 | + ISrsUdpHandler(); |
52 | + virtual ~ISrsUdpHandler(); | ||
58 | public: | 53 | public: |
59 | /** | 54 | /** |
60 | * when udp listener got a udp packet, notice server to process it. | 55 | * 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, |
62 | * for instance RTMP connection to serve client. | 57 | * for instance RTMP connection to serve client. |
63 | * @param from, the udp packet from address. | 58 | * @param from, the udp packet from address. |
64 | * @param buf, the udp packet bytes, user should copy if need to use. | 59 | * @param buf, the udp packet bytes, user should copy if need to use. |
65 | * @param nb_buf, the size of udp packet bytes. | 60 | * @param nb_buf, the size of udp packet bytes. |
66 | * @remark user should never use the buf, for it's a shared memory bytes. | 61 | * @remark user should never use the buf, for it's a shared memory bytes. |
67 | */ | 62 | */ |
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 | +{ | ||
69 | private: | 72 | 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); | ||
74 | // interface ISrsTsHandler | 83 | // interface ISrsTsHandler |
75 | public: | 84 | public: |
76 | virtual int on_ts_message(SrsTsMessage* msg); | 85 | virtual int on_ts_message(SrsTsMessage* msg); |
@@ -45,9 +45,7 @@ class SrsIngester; | @@ -45,9 +45,7 @@ class SrsIngester; | ||
45 | class SrsHttpHeartbeat; | 45 | class SrsHttpHeartbeat; |
46 | class SrsKbps; | 46 | class SrsKbps; |
47 | class SrsConfDirective; | 47 | class SrsConfDirective; |
48 | -#ifdef SRS_AUTO_STREAM_CASTER | ||
49 | -class SrsMpegtsOverUdp; | ||
50 | -#endif | 48 | +class ISrsUdpHandler; |
51 | 49 | ||
52 | // listener type for server to identify the connection, | 50 | // listener type for server to identify the connection, |
53 | // that is, use different type to process the connection. | 51 | // that is, use different type to process the connection. |
@@ -96,7 +94,7 @@ class SrsUdpListener : public SrsListener | @@ -96,7 +94,7 @@ class SrsUdpListener : public SrsListener | ||
96 | private: | 94 | private: |
97 | char* buf; | 95 | char* buf; |
98 | int nb_buf; | 96 | int nb_buf; |
99 | - SrsMpegtsOverUdp* caster; | 97 | + ISrsUdpHandler* caster; |
100 | public: | 98 | public: |
101 | SrsUdpListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c); | 99 | SrsUdpListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c); |
102 | virtual ~SrsUdpListener(); | 100 | virtual ~SrsUdpListener(); |
-
请 注册 或 登录 后发表评论