refine recv thread, donot set auto response for publish recv thread. 2.0.46
正在显示
3 个修改的文件
包含
47 行增加
和
9 行删除
| @@ -106,25 +106,22 @@ void SrsRecvThread::on_thread_start() | @@ -106,25 +106,22 @@ void SrsRecvThread::on_thread_start() | ||
| 106 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/194 | 106 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/194 |
| 107 | // @see: https://github.com/winlinvip/simple-rtmp-server/issues/217 | 107 | // @see: https://github.com/winlinvip/simple-rtmp-server/issues/217 |
| 108 | rtmp->set_recv_timeout(ST_UTIME_NO_TIMEOUT); | 108 | rtmp->set_recv_timeout(ST_UTIME_NO_TIMEOUT); |
| 109 | - | ||
| 110 | - // disable the protocol auto response, | ||
| 111 | - // for the isolate recv thread should never send any messages. | ||
| 112 | - rtmp->set_auto_response(false); | 109 | + |
| 110 | + handler->on_thread_start(); | ||
| 113 | } | 111 | } |
| 114 | 112 | ||
| 115 | void SrsRecvThread::on_thread_stop() | 113 | void SrsRecvThread::on_thread_stop() |
| 116 | { | 114 | { |
| 117 | - // enable the protocol auto response, | ||
| 118 | - // for the isolate recv thread terminated. | ||
| 119 | - rtmp->set_auto_response(true); | ||
| 120 | - | ||
| 121 | // reset the timeout to pulse mode. | 115 | // reset the timeout to pulse mode. |
| 122 | rtmp->set_recv_timeout(timeout * 1000); | 116 | rtmp->set_recv_timeout(timeout * 1000); |
| 117 | + | ||
| 118 | + handler->on_thread_stop(); | ||
| 123 | } | 119 | } |
| 124 | 120 | ||
| 125 | SrsQueueRecvThread::SrsQueueRecvThread(SrsRtmpServer* rtmp_sdk, int timeout_ms) | 121 | SrsQueueRecvThread::SrsQueueRecvThread(SrsRtmpServer* rtmp_sdk, int timeout_ms) |
| 126 | : trd(this, rtmp_sdk, timeout_ms) | 122 | : trd(this, rtmp_sdk, timeout_ms) |
| 127 | { | 123 | { |
| 124 | + rtmp = rtmp_sdk; | ||
| 128 | recv_error_code = ERROR_SUCCESS; | 125 | recv_error_code = ERROR_SUCCESS; |
| 129 | } | 126 | } |
| 130 | 127 | ||
| @@ -200,11 +197,26 @@ void SrsQueueRecvThread::on_recv_error(int ret) | @@ -200,11 +197,26 @@ void SrsQueueRecvThread::on_recv_error(int ret) | ||
| 200 | recv_error_code = ret; | 197 | recv_error_code = ret; |
| 201 | } | 198 | } |
| 202 | 199 | ||
| 200 | +void SrsQueueRecvThread::on_thread_start() | ||
| 201 | +{ | ||
| 202 | + // disable the protocol auto response, | ||
| 203 | + // for the isolate recv thread should never send any messages. | ||
| 204 | + rtmp->set_auto_response(false); | ||
| 205 | +} | ||
| 206 | + | ||
| 207 | +void SrsQueueRecvThread::on_thread_stop() | ||
| 208 | +{ | ||
| 209 | + // enable the protocol auto response, | ||
| 210 | + // for the isolate recv thread terminated. | ||
| 211 | + rtmp->set_auto_response(true); | ||
| 212 | +} | ||
| 213 | + | ||
| 203 | SrsPublishRecvThread::SrsPublishRecvThread( | 214 | SrsPublishRecvThread::SrsPublishRecvThread( |
| 204 | SrsRtmpServer* rtmp_sdk, int timeout_ms, | 215 | SrsRtmpServer* rtmp_sdk, int timeout_ms, |
| 205 | SrsRtmpConn* conn, SrsSource* source, bool is_fmle, bool is_edge | 216 | SrsRtmpConn* conn, SrsSource* source, bool is_fmle, bool is_edge |
| 206 | ): trd(this, rtmp_sdk, timeout_ms) | 217 | ): trd(this, rtmp_sdk, timeout_ms) |
| 207 | { | 218 | { |
| 219 | + rtmp = rtmp_sdk; | ||
| 208 | _conn = conn; | 220 | _conn = conn; |
| 209 | _source = source; | 221 | _source = source; |
| 210 | _is_fmle = is_fmle; | 222 | _is_fmle = is_fmle; |
| @@ -273,3 +285,15 @@ void SrsPublishRecvThread::on_recv_error(int ret) | @@ -273,3 +285,15 @@ void SrsPublishRecvThread::on_recv_error(int ret) | ||
| 273 | { | 285 | { |
| 274 | recv_error_code = ret; | 286 | recv_error_code = ret; |
| 275 | } | 287 | } |
| 288 | + | ||
| 289 | +void SrsPublishRecvThread::on_thread_start() | ||
| 290 | +{ | ||
| 291 | + // we donot set the auto response to false, | ||
| 292 | + // for the main thread never send message. | ||
| 293 | +} | ||
| 294 | + | ||
| 295 | +void SrsPublishRecvThread::on_thread_stop() | ||
| 296 | +{ | ||
| 297 | + // we donot set the auto response to true, | ||
| 298 | + // for we donot set to false yet. | ||
| 299 | +} |
| @@ -63,6 +63,12 @@ public: | @@ -63,6 +63,12 @@ public: | ||
| 63 | * when recv message error. | 63 | * when recv message error. |
| 64 | */ | 64 | */ |
| 65 | virtual void on_recv_error(int ret) = 0; | 65 | virtual void on_recv_error(int ret) = 0; |
| 66 | + /** | ||
| 67 | + * when thread start or stop, | ||
| 68 | + * for example, the message handler can set whether auto response. | ||
| 69 | + */ | ||
| 70 | + virtual void on_thread_start() = 0; | ||
| 71 | + virtual void on_thread_stop() = 0; | ||
| 66 | }; | 72 | }; |
| 67 | 73 | ||
| 68 | /** | 74 | /** |
| @@ -99,6 +105,7 @@ class SrsQueueRecvThread : public ISrsMessageHandler | @@ -99,6 +105,7 @@ class SrsQueueRecvThread : public ISrsMessageHandler | ||
| 99 | private: | 105 | private: |
| 100 | std::vector<SrsMessage*> queue; | 106 | std::vector<SrsMessage*> queue; |
| 101 | SrsRecvThread trd; | 107 | SrsRecvThread trd; |
| 108 | + SrsRtmpServer* rtmp; | ||
| 102 | // the recv thread error code. | 109 | // the recv thread error code. |
| 103 | int recv_error_code; | 110 | int recv_error_code; |
| 104 | public: | 111 | public: |
| @@ -116,6 +123,9 @@ public: | @@ -116,6 +123,9 @@ public: | ||
| 116 | virtual bool can_handle(); | 123 | virtual bool can_handle(); |
| 117 | virtual int handle(SrsMessage* msg); | 124 | virtual int handle(SrsMessage* msg); |
| 118 | virtual void on_recv_error(int ret); | 125 | virtual void on_recv_error(int ret); |
| 126 | +public: | ||
| 127 | + virtual void on_thread_start(); | ||
| 128 | + virtual void on_thread_stop(); | ||
| 119 | }; | 129 | }; |
| 120 | 130 | ||
| 121 | /** | 131 | /** |
| @@ -126,6 +136,7 @@ class SrsPublishRecvThread : public ISrsMessageHandler | @@ -126,6 +136,7 @@ class SrsPublishRecvThread : public ISrsMessageHandler | ||
| 126 | { | 136 | { |
| 127 | private: | 137 | private: |
| 128 | SrsRecvThread trd; | 138 | SrsRecvThread trd; |
| 139 | + SrsRtmpServer* rtmp; | ||
| 129 | // the msgs already got. | 140 | // the msgs already got. |
| 130 | int64_t _nb_msgs; | 141 | int64_t _nb_msgs; |
| 131 | // the recv thread error code. | 142 | // the recv thread error code. |
| @@ -148,6 +159,9 @@ public: | @@ -148,6 +159,9 @@ public: | ||
| 148 | virtual bool can_handle(); | 159 | virtual bool can_handle(); |
| 149 | virtual int handle(SrsMessage* msg); | 160 | virtual int handle(SrsMessage* msg); |
| 150 | virtual void on_recv_error(int ret); | 161 | virtual void on_recv_error(int ret); |
| 162 | +public: | ||
| 163 | + virtual void on_thread_start(); | ||
| 164 | + virtual void on_thread_stop(); | ||
| 151 | }; | 165 | }; |
| 152 | 166 | ||
| 153 | #endif | 167 | #endif |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR 2 | 32 | #define VERSION_MAJOR 2 |
| 33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
| 34 | -#define VERSION_REVISION 45 | 34 | +#define VERSION_REVISION 46 |
| 35 | // server info. | 35 | // server info. |
| 36 | #define RTMP_SIG_SRS_KEY "SRS" | 36 | #define RTMP_SIG_SRS_KEY "SRS" |
| 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" | 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" |
-
请 注册 或 登录 后发表评论