From faaa9187f297c1efad6e575e6409803daa959929 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 18 Jan 2015 18:50:15 +0800 Subject: [PATCH] for #293, mount http flv stream when publish. --- trunk/src/app/srs_app_http_conn.cpp | 32 +++++++++++++++++++---------- trunk/src/app/srs_app_http_conn.hpp | 5 ++++- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index 75ae1eb1d9..426f0cdd4b 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -136,12 +136,15 @@ int SrsVodStream::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* return ret; } -SrsLiveStream::SrsLiveStream() +SrsLiveStream::SrsLiveStream(SrsSource* s, SrsRequest* r) { + source = s; + req = r->copy(); } SrsLiveStream::~SrsLiveStream() { + srs_freep(req); } int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) @@ -182,27 +185,33 @@ int SrsHttpServer::mount(SrsSource* s, SrsRequest* r) { int ret = ERROR_SUCCESS; - if (flvs.empty()) { - srs_info("ignore mount, no flv stream configed."); + if (flvs.find(r->vhost) == flvs.end()) { + srs_info("ignore mount flv stream for disabled"); return ret; } + + std::string mount = flvs[r->vhost]; + + // replace the vhost variable + mount = srs_string_replace(mount, "[vhost]", r->vhost); + mount = srs_string_replace(mount, "[app]", r->app); + mount = srs_string_replace(mount, "[stream]", r->stream); + + // remove the default vhost mount + mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", ""); - if (flvs.find(r->vhost) == flvs.end()) { - srs_info("ignore mount flv stream for disabled"); + // mount the http flv stream. + if ((ret = mux.handle(mount, new SrsLiveStream(s, r))) != ERROR_SUCCESS) { + srs_error("http: mount flv stream for vhost=%s failed. ret=%d", r->vhost.c_str(), ret); return ret; } + srs_trace("http: mount flv stream for vhost=%s, mount=%s", r->vhost.c_str(), mount.c_str()); - // TODO: FIXME: implements it. return ret; } void SrsHttpServer::unmount(SrsSource* s, SrsRequest* r) { - if (flvs.empty()) { - srs_info("ignore unmount, no flv stream configed."); - return; - } - if (flvs.find(r->vhost) == flvs.end()) { srs_info("ignore unmount flv stream for disabled"); return; @@ -269,6 +278,7 @@ int SrsHttpServer::mount_static_file() default_root_exists = true; srs_warn("http: root mount to %s", dir.c_str()); } + srs_trace("http: vhost=%s mount to %s", vhost.c_str(), mount.c_str()); } if (!default_root_exists) { diff --git a/trunk/src/app/srs_app_http_conn.hpp b/trunk/src/app/srs_app_http_conn.hpp index 9f66638cd4..4c9010cfdb 100644 --- a/trunk/src/app/srs_app_http_conn.hpp +++ b/trunk/src/app/srs_app_http_conn.hpp @@ -65,8 +65,11 @@ class SrsVodStream : public SrsGoHttpFileServer */ class SrsLiveStream : public ISrsGoHttpHandler { +private: + SrsRequest* req; + SrsSource* source; public: - SrsLiveStream(); + SrsLiveStream(SrsSource* s, SrsRequest* r); virtual ~SrsLiveStream(); public: virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);