Skip to content

Commit

Permalink
for ossrs#293, mount http flv stream when publish.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jan 18, 2015
1 parent 2698e6d commit faaa918
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
32 changes: 21 additions & 11 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit faaa918

Please # to comment.