diff --git a/trunk/conf/srs.conf b/trunk/conf/srs.conf index 793c84134..ad6f26f11 100755 --- a/trunk/conf/srs.conf +++ b/trunk/conf/srs.conf @@ -83,7 +83,7 @@ vhost __defaultVhost__ { vhost dev { enabled on; gop_cache on; - forward 127.0.0.1:19350; + #forward 127.0.0.1:19350; hls { hls off; hls_path ./objs/nginx/html; @@ -100,7 +100,7 @@ vhost dev { on_stop http://127.0.0.1:8085/api/v1/sessions; } transcode { - enabled on; + enabled off; ffmpeg ./objs/ffmpeg/bin/ffmpeg; engine dev { enabled on; diff --git a/trunk/src/core/srs_core_client.cpp b/trunk/src/core/srs_core_client.cpp index 766a2900d..ef2a8328e 100644 --- a/trunk/src/core/srs_core_client.cpp +++ b/trunk/src/core/srs_core_client.cpp @@ -55,6 +55,8 @@ SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd) #ifdef SRS_HTTP http_hooks = new SrsHttpHooks(); #endif + + config->subscribe(this); } SrsClient::~SrsClient() @@ -67,6 +69,8 @@ SrsClient::~SrsClient() #ifdef SRS_HTTP srs_freep(http_hooks); #endif + + config->unsubscribe(this); } // TODO: return detail message when error for client. @@ -113,6 +117,18 @@ int SrsClient::do_cycle() return ret; } + +int SrsClient::on_reload_vhost_removed(SrsConfDirective* vhost) +{ + int ret = ERROR_SUCCESS; + + // if the vhost connected is removed, disconnect the client. + if (req->vhost == vhost->arg0()) { + srs_close_stfd(stfd); + } + + return ret; +} int SrsClient::service_cycle() { diff --git a/trunk/src/core/srs_core_client.hpp b/trunk/src/core/srs_core_client.hpp index 0d84b527d..3273fb93b 100644 --- a/trunk/src/core/srs_core_client.hpp +++ b/trunk/src/core/srs_core_client.hpp @@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +#include class SrsRtmp; class SrsRequest; @@ -46,7 +47,7 @@ class SrsHttpHooks; /** * the client provides the main logic control for RTMP clients. */ -class SrsClient : public SrsConnection +class SrsClient : public SrsConnection, public ISrsReloadHandler { private: char* ip; @@ -62,6 +63,9 @@ public: virtual ~SrsClient(); protected: virtual int do_cycle(); +// interface ISrsReloadHandler +public: + virtual int on_reload_vhost_removed(SrsConfDirective* vhost); private: // when valid and connected to vhost/app, service the client. virtual int service_cycle(); diff --git a/trunk/src/core/srs_core_config.cpp b/trunk/src/core/srs_core_config.cpp index 5338021a5..f5b6922d9 100644 --- a/trunk/src/core/srs_core_config.cpp +++ b/trunk/src/core/srs_core_config.cpp @@ -198,6 +198,19 @@ SrsConfDirective* SrsConfDirective::get(string _name) return NULL; } +SrsConfDirective* SrsConfDirective::get(string _name, string _arg0) +{ + std::vector::iterator it; + for (it = directives.begin(); it != directives.end(); ++it) { + SrsConfDirective* directive = *it; + if (directive->name == _name && directive->arg0() == _arg0) { + return directive; + } + } + + return NULL; +} + int SrsConfDirective::parse(const char* filename) { int ret = ERROR_SUCCESS; @@ -465,6 +478,7 @@ int SrsConfig::reload() } srs_trace("reload listen success."); } + // merge config: pithy_print if (!srs_directive_equals(root->get("pithy_print"), old_root->get("pithy_print"))) { for (it = subscribes.begin(); it != subscribes.end(); ++it) { @@ -476,6 +490,46 @@ int SrsConfig::reload() } srs_trace("reload pithy_print success."); } + + // merge config: vhost added, directly supported. + + // merge config: vhost removed/disabled/modified. + for (int i = 0; i < (int)old_root->directives.size(); i++) { + SrsConfDirective* old_vhost = old_root->at(i); + // only process vhost directives. + if (old_vhost->name != "vhost") { + continue; + } + + SrsConfDirective* new_vhost = root->get("vhost", old_vhost->arg0()); + // ignore if absolutely equal + if (new_vhost && srs_directive_equals(old_vhost, new_vhost)) { + continue; + } + // ignore if enable the new vhost when old vhost is disabled. + if (get_vhost_enabled(new_vhost) && !get_vhost_enabled(old_vhost)) { + continue; + } + // ignore if both old and new vhost are disabled. + if (!get_vhost_enabled(new_vhost) && !get_vhost_enabled(old_vhost)) { + continue; + } + + // merge config: vhost removed/disabled. + if (!get_vhost_enabled(new_vhost) && get_vhost_enabled(old_vhost)) { + srs_trace("vhost %s disabled, reload it.", old_vhost->name.c_str()); + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_vhost_removed(old_vhost)) != ERROR_SUCCESS) { + srs_error("notify subscribes pithy_print remove vhost failed. ret=%d", ret); + return ret; + } + } + srs_trace("reload remove vhost success."); + } + + // merge config: vhost modified. + } // TODO: suppor reload hls/forward/ffmpeg/http @@ -785,12 +839,17 @@ SrsConfDirective* SrsConfig::get_vhost_on_stop(string vhost) bool SrsConfig::get_vhost_enabled(string vhost) { SrsConfDirective* vhost_conf = get_vhost(vhost); + + return get_vhost_enabled(vhost_conf); +} - if (!vhost_conf) { - return true; +bool SrsConfig::get_vhost_enabled(SrsConfDirective* vhost) +{ + if (!vhost) { + return false; } - SrsConfDirective* conf = vhost_conf->get("enabled"); + SrsConfDirective* conf = vhost->get("enabled"); if (!conf) { return true; } diff --git a/trunk/src/core/srs_core_config.hpp b/trunk/src/core/srs_core_config.hpp index 076b5e09c..d173d6ec2 100644 --- a/trunk/src/core/srs_core_config.hpp +++ b/trunk/src/core/srs_core_config.hpp @@ -74,6 +74,7 @@ public: std::string arg2(); SrsConfDirective* at(int index); SrsConfDirective* get(std::string _name); + SrsConfDirective* get(std::string _name, std::string _arg0); public: virtual int parse(const char* filename); public: @@ -113,6 +114,7 @@ private: public: virtual SrsConfDirective* get_vhost(std::string vhost); virtual bool get_vhost_enabled(std::string vhost); + virtual bool get_vhost_enabled(SrsConfDirective* vhost); virtual SrsConfDirective* get_vhost_on_connect(std::string vhost); virtual SrsConfDirective* get_vhost_on_close(std::string vhost); virtual SrsConfDirective* get_vhost_on_publish(std::string vhost); diff --git a/trunk/src/core/srs_core_protocol.cpp b/trunk/src/core/srs_core_protocol.cpp index 940666f09..1b50d18e2 100644 --- a/trunk/src/core/srs_core_protocol.cpp +++ b/trunk/src/core/srs_core_protocol.cpp @@ -307,6 +307,11 @@ void SrsProtocol::set_send_timeout(int64_t timeout_us) return skt->set_send_timeout(timeout_us); } +int64_t SrsProtocol::get_send_timeout() +{ + return skt->get_send_timeout(); +} + int64_t SrsProtocol::get_recv_bytes() { return skt->get_recv_bytes(); diff --git a/trunk/src/core/srs_core_protocol.hpp b/trunk/src/core/srs_core_protocol.hpp index 9cda280ca..f9c5db5fe 100644 --- a/trunk/src/core/srs_core_protocol.hpp +++ b/trunk/src/core/srs_core_protocol.hpp @@ -115,6 +115,7 @@ public: virtual void set_recv_timeout(int64_t timeout_us); virtual int64_t get_recv_timeout(); virtual void set_send_timeout(int64_t timeout_us); + virtual int64_t get_send_timeout(); virtual int64_t get_recv_bytes(); virtual int64_t get_send_bytes(); virtual int get_recv_kbps(); diff --git a/trunk/src/core/srs_core_reload.cpp b/trunk/src/core/srs_core_reload.cpp index a29cdfbe8..54a856309 100644 --- a/trunk/src/core/srs_core_reload.cpp +++ b/trunk/src/core/srs_core_reload.cpp @@ -43,3 +43,8 @@ int ISrsReloadHandler::on_reload_pithy_print() return ERROR_SUCCESS; } +int ISrsReloadHandler::on_reload_vhost_removed(SrsConfDirective* /*vhost*/) +{ + return ERROR_SUCCESS; +} + diff --git a/trunk/src/core/srs_core_reload.hpp b/trunk/src/core/srs_core_reload.hpp index 2b48b7009..b92109797 100644 --- a/trunk/src/core/srs_core_reload.hpp +++ b/trunk/src/core/srs_core_reload.hpp @@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +class SrsConfDirective; + /** * the handler for config reload. */ @@ -40,6 +42,7 @@ public: public: virtual int on_reload_listen(); virtual int on_reload_pithy_print(); + virtual int on_reload_vhost_removed(SrsConfDirective* vhost); }; #endif \ No newline at end of file diff --git a/trunk/src/core/srs_core_rtmp.cpp b/trunk/src/core/srs_core_rtmp.cpp index 0fccf4de3..b48b0795e 100644 --- a/trunk/src/core/srs_core_rtmp.cpp +++ b/trunk/src/core/srs_core_rtmp.cpp @@ -231,6 +231,9 @@ int SrsRtmpClient::handshake() SrsSocket skt(stfd); + skt.set_recv_timeout(protocol->get_recv_timeout()); + skt.set_send_timeout(protocol->get_send_timeout()); + SrsComplexHandshake complex_hs; SrsSimpleHandshake simple_hs; if ((ret = simple_hs.handshake_with_server(skt, complex_hs)) != ERROR_SUCCESS) { @@ -422,6 +425,11 @@ void SrsRtmp::set_send_timeout(int64_t timeout_us) protocol->set_send_timeout(timeout_us); } +int64_t SrsRtmp::get_send_timeout() +{ + return protocol->get_send_timeout(); +} + int64_t SrsRtmp::get_recv_bytes() { return protocol->get_recv_bytes(); @@ -458,6 +466,9 @@ int SrsRtmp::handshake() SrsSocket skt(stfd); + skt.set_recv_timeout(protocol->get_recv_timeout()); + skt.set_send_timeout(protocol->get_send_timeout()); + SrsComplexHandshake complex_hs; SrsSimpleHandshake simple_hs; if ((ret = simple_hs.handshake_with_client(skt, complex_hs)) != ERROR_SUCCESS) { diff --git a/trunk/src/core/srs_core_rtmp.hpp b/trunk/src/core/srs_core_rtmp.hpp index 56fc95112..f6e76d1b7 100644 --- a/trunk/src/core/srs_core_rtmp.hpp +++ b/trunk/src/core/srs_core_rtmp.hpp @@ -144,6 +144,7 @@ public: virtual void set_recv_timeout(int64_t timeout_us); virtual int64_t get_recv_timeout(); virtual void set_send_timeout(int64_t timeout_us); + virtual int64_t get_send_timeout(); virtual int64_t get_recv_bytes(); virtual int64_t get_send_bytes(); virtual int get_recv_kbps(); diff --git a/trunk/src/core/srs_core_socket.cpp b/trunk/src/core/srs_core_socket.cpp index e4c6a0c64..365b3ed77 100644 --- a/trunk/src/core/srs_core_socket.cpp +++ b/trunk/src/core/srs_core_socket.cpp @@ -52,6 +52,11 @@ void SrsSocket::set_send_timeout(int64_t timeout_us) send_timeout = timeout_us; } +int64_t SrsSocket::get_send_timeout() +{ + return send_timeout; +} + int64_t SrsSocket::get_recv_bytes() { return recv_bytes; diff --git a/trunk/src/core/srs_core_socket.hpp b/trunk/src/core/srs_core_socket.hpp index 42e8cf752..f355dbfb1 100644 --- a/trunk/src/core/srs_core_socket.hpp +++ b/trunk/src/core/srs_core_socket.hpp @@ -50,6 +50,7 @@ public: virtual void set_recv_timeout(int64_t timeout_us); virtual int64_t get_recv_timeout(); virtual void set_send_timeout(int64_t timeout_us); + virtual int64_t get_send_timeout(); virtual int64_t get_recv_bytes(); virtual int64_t get_send_bytes(); virtual int get_recv_kbps();