fix #293, support rtmp remux to http flv live stream.

pull/133/head
winlin 10 years ago
parent 53d9faf395
commit 3b853a6dbd

@ -476,7 +476,10 @@ Supported operating systems and hardware:
[#179](https://github.com/winlinvip/simple-rtmp-server/issues/179) and [#179](https://github.com/winlinvip/simple-rtmp-server/issues/179) and
[274](https://github.com/winlinvip/simple-rtmp-server/issues/274). [274](https://github.com/winlinvip/simple-rtmp-server/issues/274).
1. Support rtmp remux to http flv live stream, read 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 <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 RTMP 302 redirect [#92](https://github.com/winlinvip/simple-rtmp-server/issues/92).
1. [no-plan] Support multiple processes, for both origin and edge 1. [no-plan] Support multiple processes, for both origin and edge

@ -402,6 +402,7 @@ int SrsGoHttpFileServer::copy(ISrsGoHttpResponseWriter* w, SrsFileReader* fs, Sr
SrsGoHttpMuxEntry::SrsGoHttpMuxEntry() SrsGoHttpMuxEntry::SrsGoHttpMuxEntry()
{ {
enabled = true;
explicit_match = false; explicit_match = false;
handler = NULL; handler = NULL;
} }
@ -572,6 +573,10 @@ int SrsGoHttpServeMux::match(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
std::string pattern = it->first; std::string pattern = it->first;
SrsGoHttpMuxEntry* entry = it->second; SrsGoHttpMuxEntry* entry = it->second;
if (!entry->enabled) {
continue;
}
if (!path_match(pattern, path)) { if (!path_match(pattern, path)) {
continue; continue;
} }

@ -230,6 +230,7 @@ public:
bool explicit_match; bool explicit_match;
ISrsGoHttpHandler* handler; ISrsGoHttpHandler* handler;
std::string pattern; std::string pattern;
bool enabled;
public: public:
SrsGoHttpMuxEntry(); SrsGoHttpMuxEntry();
virtual ~SrsGoHttpMuxEntry(); virtual ~SrsGoHttpMuxEntry();

@ -282,12 +282,22 @@ int SrsLiveStream::send_messages(SrsFlvEncoder* enc, SrsSharedPtrMessage** msgs,
return ret; return ret;
} }
SrsLiveEntry::SrsLiveEntry()
{
stream = NULL;
}
SrsHttpServer::SrsHttpServer() SrsHttpServer::SrsHttpServer()
{ {
} }
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(); flvs.clear();
} }
@ -318,7 +328,15 @@ int SrsHttpServer::mount(SrsSource* s, SrsRequest* r)
return ret; return ret;
} }
std::string mount = flvs[r->vhost]; SrsLiveEntry* entry = flvs[r->vhost];
// TODO: FIXME: supports reload.
if (entry->stream) {
entry->stream->entry->enabled = true;
return ret;
}
std::string mount = entry->mount;
// replace the vhost variable // replace the vhost variable
mount = srs_string_replace(mount, "[vhost]", r->vhost); mount = srs_string_replace(mount, "[vhost]", r->vhost);
@ -328,8 +346,10 @@ int SrsHttpServer::mount(SrsSource* s, SrsRequest* r)
// remove the default vhost mount // remove the default vhost mount
mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/"); mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/");
entry->stream = new SrsLiveStream(s, r);
// mount the http flv stream. // 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); srs_error("http: mount flv stream for vhost=%s failed. ret=%d", r->vhost.c_str(), ret);
return ret; return ret;
} }
@ -345,7 +365,8 @@ void SrsHttpServer::unmount(SrsSource* s, SrsRequest* r)
return; return;
} }
// TODO: FIXME: implements it. SrsLiveEntry* entry = flvs[r->vhost];
entry->stream->entry->enabled = false;
} }
int SrsHttpServer::on_reload_vhost_http_updated() int SrsHttpServer::on_reload_vhost_http_updated()
@ -440,10 +461,12 @@ int SrsHttpServer::mount_flv_streaming()
continue; continue;
} }
std::string mount = _srs_config->get_vhost_http_flv_mount(vhost); SrsLiveEntry* entry = new SrsLiveEntry();
flvs[vhost] = mount; 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", 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; return ret;

@ -100,6 +100,18 @@ private:
virtual int send_messages(SrsFlvEncoder* enc, SrsSharedPtrMessage** msgs, int nb_msgs); 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, * the http server instance,
* serve http static file, flv vod stream and flv live stream. * serve http static file, flv vod stream and flv live stream.
@ -109,7 +121,7 @@ class SrsHttpServer : public ISrsReloadHandler
public: public:
SrsGoHttpServeMux mux; SrsGoHttpServeMux mux;
// the flv live streaming template. // the flv live streaming template.
std::map<std::string, std::string> flvs; std::map<std::string, SrsLiveEntry*> flvs;
public: public:
SrsHttpServer(); SrsHttpServer();
virtual ~SrsHttpServer(); virtual ~SrsHttpServer();

Loading…
Cancel
Save