From f9257b89e74b1d372b1978db53e891d4e675565d Mon Sep 17 00:00:00 2001 From: zhengfl Date: Wed, 8 Jul 2015 15:43:09 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#438=20=20=20=20=20=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=9Aedge=E6=A8=A1=E5=BC=8F=EF=BC=8C=E6=8E=A8=E6=B5=81?= =?UTF-8?q?=E6=97=B6=E5=BC=82=E5=B8=B8=E6=96=AD=E5=BC=80=E3=80=82=20=20=20?= =?UTF-8?q?=20=20=E8=A7=A3=E5=86=B3=E6=96=B9=E6=B3=95=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0edge=E6=A8=A1=E5=BC=8F=E6=8E=A8=E6=B5=81=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trunk/src/app/srs_app_edge.cpp | 5 +++ trunk/src/app/srs_app_edge.hpp | 1 + trunk/src/app/srs_app_rtmp_conn.cpp | 48 ++++++++++++++++++++--------- trunk/src/app/srs_app_rtmp_conn.hpp | 1 + trunk/src/app/srs_app_source.cpp | 5 +++ trunk/src/app/srs_app_source.hpp | 1 + 6 files changed, 46 insertions(+), 15 deletions(-) mode change 100644 => 100755 trunk/src/app/srs_app_edge.hpp mode change 100644 => 100755 trunk/src/app/srs_app_rtmp_conn.hpp mode change 100644 => 100755 trunk/src/app/srs_app_source.hpp diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp index 8014e75bd..4bd4950dd 100755 --- a/trunk/src/app/srs_app_edge.cpp +++ b/trunk/src/app/srs_app_edge.cpp @@ -806,6 +806,11 @@ int SrsPublishEdge::initialize(SrsSource* source, SrsRequest* req) return ret; } +bool SrsPublishEdge::can_publish() +{ + return state != SrsEdgeStatePublish; +} + int SrsPublishEdge::on_client_publish() { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_edge.hpp b/trunk/src/app/srs_app_edge.hpp old mode 100644 new mode 100755 index aa0cfc82d..ef3046512 --- a/trunk/src/app/srs_app_edge.hpp +++ b/trunk/src/app/srs_app_edge.hpp @@ -207,6 +207,7 @@ public: virtual void set_queue_size(double queue_size); public: virtual int initialize(SrsSource* source, SrsRequest* req); + virtual bool can_publish(); /** * when client publish stream on edge. */ diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 6239a8872..c4dd9bb96 100755 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -423,27 +423,20 @@ int SrsRtmpConn::stream_service_cycle() } } srs_assert(source != NULL); - + + // check ASAP, to fail it faster if invalid. + if (type != SrsRtmpConnPlay) { + if ((ret = prepare_publish(source, vhost_is_edge)) != ERROR_SUCCESS) { + return ret; + } + } + // update the statistic when source disconveried. SrsStatistic* stat = SrsStatistic::instance(); if ((ret = stat->on_client(_srs_context->get_id(), req)) != ERROR_SUCCESS) { srs_error("stat client failed. ret=%d", ret); return ret; } - - // check ASAP, to fail it faster if invalid. - if (type != SrsRtmpConnPlay && !vhost_is_edge) { - // check publish available - // for edge, never check it, for edge use proxy mode. - if (!source->can_publish()) { - ret = ERROR_SYSTEM_STREAM_BUSY; - srs_warn("stream %s is already publishing. ret=%d", - req->get_stream_url().c_str(), ret); - // to delay request - st_usleep(SRS_STREAM_BUSY_SLEEP_US); - return ret; - } - } bool enabled_cache = _srs_config->get_gop_cache(req->vhost); srs_trace("source url=%s, ip=%s, cache=%d, is_edge=%d, source_id=%d[%d]", @@ -1260,6 +1253,31 @@ int SrsRtmpConn::do_token_traverse_auth(SrsRtmpClient* client) return ret; } +int SrsRtmpConn::prepare_publish(SrsSource* source, bool vhost_is_edge) +{ + int ret = ERROR_SUCCESS; + srs_assert(source); + + // check publish available + bool can_publish = false; + if (vhost_is_edge) { + can_publish = source->proxy_can_publish(); + } else { + can_publish = source->can_publish(); + } + + if (!can_publish) { + ret = ERROR_SYSTEM_STREAM_BUSY; + srs_warn("stream %s is already publishing. ret=%d", + req->get_stream_url().c_str(), ret); + // to delay request + st_usleep(SRS_STREAM_BUSY_SLEEP_US); + return ret; + } + + return ret; +} + int SrsRtmpConn::http_hooks_on_connect() { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_rtmp_conn.hpp b/trunk/src/app/srs_app_rtmp_conn.hpp old mode 100644 new mode 100755 index 96db60ac7..14eb1f64c --- a/trunk/src/app/srs_app_rtmp_conn.hpp +++ b/trunk/src/app/srs_app_rtmp_conn.hpp @@ -123,6 +123,7 @@ private: virtual int check_edge_token_traverse_auth(); virtual int connect_server(int origin_index, st_netfd_t* pstsock); virtual int do_token_traverse_auth(SrsRtmpClient* client); + virtual int prepare_publish(SrsSource* source, bool vhost_is_edge); private: virtual int http_hooks_on_connect(); virtual void http_hooks_on_close(); diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index a9dbe8609..2e268c3bd 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -1355,6 +1355,11 @@ bool SrsSource::can_publish() return _can_publish; } +bool SrsSource::proxy_can_publish() +{ + return publish_edge->can_publish(); +} + int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata) { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp old mode 100644 new mode 100755 index b654668d5..7e9bb5262 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -538,6 +538,7 @@ public: // logic data methods public: virtual bool can_publish(); + virtual bool proxy_can_publish(); virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata); public: virtual int on_audio(SrsCommonMessage* audio);