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

for bug #237, use isolate thread to recv message. 2.0.41

This commit is contained in:
winlin 2014-12-01 23:38:51 +08:00
parent 0e7836868c
commit 472b1742a2
5 changed files with 209 additions and 122 deletions

View file

@ -25,6 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_protocol_rtmp.hpp>
#include <srs_protocol_stack.hpp>
#include <srs_app_rtmp_conn.hpp>
ISrsMessageHandler::ISrsMessageHandler()
{
@ -89,6 +90,11 @@ int SrsRecvThread::cycle()
return ret;
}
void SrsRecvThread::stop_loop()
{
trd->stop_loop();
}
void SrsRecvThread::on_thread_start()
{
// the multiple messages writev improve performance large,
@ -179,3 +185,72 @@ int SrsQueueRecvThread::handle(SrsMessage* msg)
return ERROR_SUCCESS;
}
SrsPublishRecvThread::SrsPublishRecvThread(
SrsRtmpServer* rtmp_sdk, int timeout_ms,
SrsRtmpConn* conn, SrsSource* source, bool is_fmle, bool is_edge
): trd(this, rtmp_sdk, timeout_ms)
{
_conn = conn;
_source = source;
_is_fmle = is_fmle;
_is_edge = is_edge;
recv_error_code = ERROR_SUCCESS;
_nb_msgs = 0;
}
SrsPublishRecvThread::~SrsPublishRecvThread()
{
trd.stop();
}
int64_t SrsPublishRecvThread::nb_msgs()
{
return _nb_msgs;
}
int SrsPublishRecvThread::error_code()
{
return recv_error_code;
}
int SrsPublishRecvThread::start()
{
return trd.start();
}
void SrsPublishRecvThread::stop()
{
trd.stop();
}
bool SrsPublishRecvThread::can_handle()
{
// publish thread always can handle message.
return true;
}
int SrsPublishRecvThread::handle(SrsMessage* msg)
{
int ret = ERROR_SUCCESS;
_nb_msgs++;
// the rtmp connection will handle this message,
// quit the thread loop when error.
recv_error_code = ret = _conn->handle_publish_message(_source, msg, _is_fmle, _is_edge);
// when error, use stop loop to terminate the thread normally,
// for we are in the thread loop now, and should never use stop() to terminate it.
if (ret != ERROR_SUCCESS) {
trd.stop_loop();
}
// must always free it,
// the source will copy it if need to use.
srs_freep(msg);
// TODO: FIXME: implements it.
return ret;
}