Skip to content

Commit

Permalink
fix ossrs#293, support rtmp remux to http flv live stream.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jan 18, 2015
1 parent 53d9faf commit 3b853a6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions trunk/src/app/srs_app_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ int SrsGoHttpFileServer::copy(ISrsGoHttpResponseWriter* w, SrsFileReader* fs, Sr

SrsGoHttpMuxEntry::SrsGoHttpMuxEntry()
{
enabled = true;
explicit_match = false;
handler = NULL;
}
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class SrsGoHttpMuxEntry
bool explicit_match;
ISrsGoHttpHandler* handler;
std::string pattern;
bool enabled;
public:
SrsGoHttpMuxEntry();
virtual ~SrsGoHttpMuxEntry();
Expand Down
37 changes: 30 additions & 7 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,22 @@ int SrsLiveStream::send_messages(SrsFlvEncoder* enc, SrsSharedPtrMessage** msgs,
return ret;
}

SrsLiveEntry::SrsLiveEntry()
{
stream = NULL;
}

SrsHttpServer::SrsHttpServer()
{
}

SrsHttpServer::~SrsHttpServer()
{
std::map<std::string, SrsLiveEntry*>::iterator it;
for (it = flvs.begin(); it != flvs.end(); ++it) {
SrsLiveEntry* entry = it->second;
srs_freep(entry);
}
flvs.clear();
}

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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()
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -109,7 +121,7 @@ class SrsHttpServer : public ISrsReloadHandler
public:
SrsGoHttpServeMux mux;
// the flv live streaming template.
std::map<std::string, std::string> flvs;
std::map<std::string, SrsLiveEntry*> flvs;
public:
SrsHttpServer();
virtual ~SrsHttpServer();
Expand Down

0 comments on commit 3b853a6

Please sign in to comment.