diff --git a/README.md b/README.md index b58b7b3fdc..0bef22f658 100755 --- a/README.md +++ b/README.md @@ -476,7 +476,10 @@ Supported operating systems and hardware: [#179](https://github.com/winlinvip/simple-rtmp-server/issues/179) and [274](https://github.com/winlinvip/simple-rtmp-server/issues/274). 1. Support rtmp remux to http flv live stream, read -[#293](https://github.com/winlinvip/simple-rtmp-server/issues/293). +[#293](https://github.com/winlinvip/simple-rtmp-server/issues/293)( +[CN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DeliveryHttpFlvStream), +[EN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DeliveryHttpFlvStream) +). 1. [no-plan] Support <500ms latency, FRSC(Fast RTMP-compatible Stream Channel tech). 1. [no-plan] Support RTMP 302 redirect [#92](https://github.com/winlinvip/simple-rtmp-server/issues/92). 1. [no-plan] Support multiple processes, for both origin and edge diff --git a/trunk/src/app/srs_app_http.cpp b/trunk/src/app/srs_app_http.cpp index 91a48763ca..cc3c5da5d7 100644 --- a/trunk/src/app/srs_app_http.cpp +++ b/trunk/src/app/srs_app_http.cpp @@ -402,6 +402,7 @@ int SrsGoHttpFileServer::copy(ISrsGoHttpResponseWriter* w, SrsFileReader* fs, Sr SrsGoHttpMuxEntry::SrsGoHttpMuxEntry() { + enabled = true; explicit_match = false; handler = NULL; } @@ -572,6 +573,10 @@ int SrsGoHttpServeMux::match(SrsHttpMessage* r, ISrsGoHttpHandler** ph) std::string pattern = it->first; SrsGoHttpMuxEntry* entry = it->second; + if (!entry->enabled) { + continue; + } + if (!path_match(pattern, path)) { continue; } diff --git a/trunk/src/app/srs_app_http.hpp b/trunk/src/app/srs_app_http.hpp index 2a39bec69a..a73a7a9e23 100644 --- a/trunk/src/app/srs_app_http.hpp +++ b/trunk/src/app/srs_app_http.hpp @@ -230,6 +230,7 @@ class SrsGoHttpMuxEntry bool explicit_match; ISrsGoHttpHandler* handler; std::string pattern; + bool enabled; public: SrsGoHttpMuxEntry(); virtual ~SrsGoHttpMuxEntry(); diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index 94fcfd5051..08cbebf70d 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -282,12 +282,22 @@ int SrsLiveStream::send_messages(SrsFlvEncoder* enc, SrsSharedPtrMessage** msgs, return ret; } +SrsLiveEntry::SrsLiveEntry() +{ + stream = NULL; +} + SrsHttpServer::SrsHttpServer() { } SrsHttpServer::~SrsHttpServer() { + std::map::iterator it; + for (it = flvs.begin(); it != flvs.end(); ++it) { + SrsLiveEntry* entry = it->second; + srs_freep(entry); + } flvs.clear(); } @@ -317,8 +327,16 @@ int SrsHttpServer::mount(SrsSource* s, SrsRequest* r) srs_info("ignore mount flv stream for disabled"); return ret; } + + SrsLiveEntry* entry = flvs[r->vhost]; + + // TODO: FIXME: supports reload. + if (entry->stream) { + entry->stream->entry->enabled = true; + return ret; + } - std::string mount = flvs[r->vhost]; + std::string mount = entry->mount; // replace the vhost variable mount = srs_string_replace(mount, "[vhost]", r->vhost); @@ -328,8 +346,10 @@ int SrsHttpServer::mount(SrsSource* s, SrsRequest* r) // remove the default vhost mount mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/"); + entry->stream = new SrsLiveStream(s, r); + // mount the http flv stream. - if ((ret = mux.handle(mount, new SrsLiveStream(s, r))) != ERROR_SUCCESS) { + if ((ret = mux.handle(mount, entry->stream)) != ERROR_SUCCESS) { srs_error("http: mount flv stream for vhost=%s failed. ret=%d", r->vhost.c_str(), ret); return ret; } @@ -344,8 +364,9 @@ void SrsHttpServer::unmount(SrsSource* s, SrsRequest* r) srs_info("ignore unmount flv stream for disabled"); return; } - - // TODO: FIXME: implements it. + + SrsLiveEntry* entry = flvs[r->vhost]; + entry->stream->entry->enabled = false; } int SrsHttpServer::on_reload_vhost_http_updated() @@ -440,10 +461,12 @@ int SrsHttpServer::mount_flv_streaming() continue; } - std::string mount = _srs_config->get_vhost_http_flv_mount(vhost); - flvs[vhost] = mount; + SrsLiveEntry* entry = new SrsLiveEntry(); + entry->vhost = vhost; + entry->mount = _srs_config->get_vhost_http_flv_mount(vhost); + flvs[vhost] = entry; srs_trace("http flv live stream, vhost=%s, mount=%s", - vhost.c_str(), mount.c_str()); + vhost.c_str(), entry->mount.c_str()); } return ret; diff --git a/trunk/src/app/srs_app_http_conn.hpp b/trunk/src/app/srs_app_http_conn.hpp index d26f618989..1d47df01af 100644 --- a/trunk/src/app/srs_app_http_conn.hpp +++ b/trunk/src/app/srs_app_http_conn.hpp @@ -100,6 +100,18 @@ class SrsLiveStream : public ISrsGoHttpHandler virtual int send_messages(SrsFlvEncoder* enc, SrsSharedPtrMessage** msgs, int nb_msgs); }; +/** +* the srs live entry +*/ +struct SrsLiveEntry +{ + std::string vhost; + std::string mount; + SrsLiveStream* stream; + + SrsLiveEntry(); +}; + /** * the http server instance, * serve http static file, flv vod stream and flv live stream. @@ -109,7 +121,7 @@ class SrsHttpServer : public ISrsReloadHandler public: SrsGoHttpServeMux mux; // the flv live streaming template. - std::map flvs; + std::map flvs; public: SrsHttpServer(); virtual ~SrsHttpServer();