1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

merge from srs2. for #513.

This commit is contained in:
winlin 2016-12-15 14:54:09 +08:00
parent f30b3073a2
commit 664844b5f5
16 changed files with 25 additions and 553 deletions

View file

@ -963,12 +963,6 @@ vhost with-hls.srs.com {
# @see https://github.com/ossrs/srs/issues/264 # @see https://github.com/ossrs/srs/issues/264
# default: continue # default: continue
hls_on_error continue; hls_on_error continue;
# the hls storage: disk, ram or both.
# disk, to write hls m3u8/ts to disk.
# ram, serve m3u8/ts in memory, which use embedded http server to delivery.
# both, disk and ram.
# default: disk
hls_storage disk;
# the hls output path. # the hls output path.
# the m3u8 file is configured by hls_path/hls_m3u8_file, the default is: # the m3u8 file is configured by hls_path/hls_m3u8_file, the default is:
# ./objs/nginx/html/[app]/[stream].m3u8 # ./objs/nginx/html/[app]/[stream].m3u8
@ -1017,13 +1011,6 @@ vhost with-hls.srs.com {
# ... # ...
# optional, default to empty string. # optional, default to empty string.
hls_entry_prefix http://your-server; hls_entry_prefix http://your-server;
# the hls mount for hls_storage ram,
# which use srs embedded http server to delivery HLS,
# where the mount specifies the HTTP url to mount.
# @see the mount of http_remux.
# @remark the hls_mount must endswith .m3u8.
# default: [vhost]/[app]/[stream].m3u8
hls_mount [vhost]/[app]/[stream].m3u8;
# the default audio codec of hls. # the default audio codec of hls.
# when codec changed, write the PAT/PMT table, but maybe ok util next ts. # when codec changed, write the PAT/PMT table, but maybe ok util next ts.
# so user can set the default codec for mp3. # so user can set the default codec for mp3.

View file

@ -1,20 +0,0 @@
# the config for srs to delivery hls
# @see https://github.com/ossrs/srs/wiki/v1_CN_SampleHLS
# @see full.conf for detail config.
listen 1935;
max_connections 1000;
http_server {
enabled on;
listen 8080;
dir ./objs/nginx/html;
}
vhost __defaultVhost__ {
hls {
enabled on;
hls_fragment 10;
hls_window 60;
hls_storage ram;
hls_mount /[app]/[stream].m3u8;
}
}

View file

@ -319,7 +319,6 @@
3C1EE6C91AB1080900576EE9 /* origin.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = origin.conf; path = ../../../conf/origin.conf; sourceTree = "<group>"; }; 3C1EE6C91AB1080900576EE9 /* origin.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = origin.conf; path = ../../../conf/origin.conf; sourceTree = "<group>"; };
3C1EE6CA1AB1080900576EE9 /* push.mpegts.over.udp.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = push.mpegts.over.udp.conf; path = ../../../conf/push.mpegts.over.udp.conf; sourceTree = "<group>"; }; 3C1EE6CA1AB1080900576EE9 /* push.mpegts.over.udp.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = push.mpegts.over.udp.conf; path = ../../../conf/push.mpegts.over.udp.conf; sourceTree = "<group>"; };
3C1EE6CB1AB1080900576EE9 /* push.rtsp.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = push.rtsp.conf; path = ../../../conf/push.rtsp.conf; sourceTree = "<group>"; }; 3C1EE6CB1AB1080900576EE9 /* push.rtsp.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = push.rtsp.conf; path = ../../../conf/push.rtsp.conf; sourceTree = "<group>"; };
3C1EE6CC1AB1080900576EE9 /* ram.hls.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ram.hls.conf; path = ../../../conf/ram.hls.conf; sourceTree = "<group>"; };
3C1EE6CD1AB1080900576EE9 /* realtime.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = realtime.conf; path = ../../../conf/realtime.conf; sourceTree = "<group>"; }; 3C1EE6CD1AB1080900576EE9 /* realtime.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = realtime.conf; path = ../../../conf/realtime.conf; sourceTree = "<group>"; };
3C1EE6CE1AB1080900576EE9 /* rtmp.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = rtmp.conf; path = ../../../conf/rtmp.conf; sourceTree = "<group>"; }; 3C1EE6CE1AB1080900576EE9 /* rtmp.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = rtmp.conf; path = ../../../conf/rtmp.conf; sourceTree = "<group>"; };
3C1EE6CF1AB1080900576EE9 /* security.deny.publish.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = security.deny.publish.conf; path = ../../../conf/security.deny.publish.conf; sourceTree = "<group>"; }; 3C1EE6CF1AB1080900576EE9 /* security.deny.publish.conf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = security.deny.publish.conf; path = ../../../conf/security.deny.publish.conf; sourceTree = "<group>"; };
@ -755,7 +754,6 @@
3C8280281BAFF896004A1794 /* push.flv.conf */, 3C8280281BAFF896004A1794 /* push.flv.conf */,
3C1EE6CA1AB1080900576EE9 /* push.mpegts.over.udp.conf */, 3C1EE6CA1AB1080900576EE9 /* push.mpegts.over.udp.conf */,
3C1EE6CB1AB1080900576EE9 /* push.rtsp.conf */, 3C1EE6CB1AB1080900576EE9 /* push.rtsp.conf */,
3C1EE6CC1AB1080900576EE9 /* ram.hls.conf */,
3C1EE6CD1AB1080900576EE9 /* realtime.conf */, 3C1EE6CD1AB1080900576EE9 /* realtime.conf */,
3C1EE6CE1AB1080900576EE9 /* rtmp.conf */, 3C1EE6CE1AB1080900576EE9 /* rtmp.conf */,
3C1EE6CF1AB1080900576EE9 /* security.deny.publish.conf */, 3C1EE6CF1AB1080900576EE9 /* security.deny.publish.conf */,

View file

@ -3910,6 +3910,11 @@ int SrsConfig::check_config()
srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret); srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret);
return ret; return ret;
} }
// TODO: FIXME: remove it in future.
if (m == "hls_storage" || m == "hls_mount") {
srs_warn("HLS RAM is removed from SRS2 to SRS3+, please read https://github.com/ossrs/srs/issues/513.");
}
} }
} else if (n == "http_hooks") { } else if (n == "http_hooks") {
for (int j = 0; j < (int)conf->directives.size(); j++) { for (int j = 0; j < (int)conf->directives.size(); j++) {
@ -6075,40 +6080,6 @@ string SrsConfig::get_hls_on_error(string vhost)
return conf->arg0(); return conf->arg0();
} }
string SrsConfig::get_hls_storage(string vhost)
{
static string DEFAULT = "disk";
SrsConfDirective* conf = get_hls(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("hls_storage");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return conf->arg0();
}
string SrsConfig::get_hls_mount(string vhost)
{
static string DEFAULT = "[vhost]/[app]/[stream].m3u8";
SrsConfDirective* conf = get_hls(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("hls_mount");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return conf->arg0();
}
string SrsConfig::get_hls_acodec(string vhost) string SrsConfig::get_hls_acodec(string vhost)
{ {
static string DEFAULT = "aac"; static string DEFAULT = "aac";

View file

@ -1184,14 +1184,6 @@ public:
*/ */
virtual std::string get_hls_on_error(std::string vhost); virtual std::string get_hls_on_error(std::string vhost);
/** /**
* get the HLS storage type.
*/
virtual std::string get_hls_storage(std::string vhost);
/**
* get the HLS mount url for HTTP server.
*/
virtual std::string get_hls_mount(std::string vhost);
/**
* get the HLS default audio codec. * get the HLS default audio codec.
*/ */
virtual std::string get_hls_acodec(std::string vhost); virtual std::string get_hls_acodec(std::string vhost);

View file

@ -61,14 +61,6 @@ using namespace std;
// reset the piece id when deviation overflow this. // reset the piece id when deviation overflow this.
#define SRS_JUMP_WHEN_PIECE_DEVIATION 20 #define SRS_JUMP_WHEN_PIECE_DEVIATION 20
ISrsHlsHandler::ISrsHlsHandler()
{
}
ISrsHlsHandler::~ISrsHlsHandler()
{
}
/** /**
* * the HLS section, only available when HLS enabled. * * the HLS section, only available when HLS enabled.
* */ * */
@ -294,7 +286,6 @@ string SrsDvrAsyncCallOnHlsNotify::to_string()
SrsHlsMuxer::SrsHlsMuxer() SrsHlsMuxer::SrsHlsMuxer()
{ {
req = NULL; req = NULL;
handler = NULL;
hls_fragment = hls_window = 0; hls_fragment = hls_window = 0;
hls_aof_ratio = 1.0; hls_aof_ratio = 1.0;
deviation_ts = 0; deviation_ts = 0;
@ -384,12 +375,10 @@ int SrsHlsMuxer::deviation()
return deviation_ts; return deviation_ts;
} }
int SrsHlsMuxer::initialize(ISrsHlsHandler* h) int SrsHlsMuxer::initialize()
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
handler = h;
if ((ret = async->start()) != ERROR_SUCCESS) { if ((ret = async->start()) != ERROR_SUCCESS) {
return ret; return ret;
} }
@ -426,18 +415,9 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,
// when update config, reset the history target duration. // when update config, reset the history target duration.
max_td = (int)(fragment * _srs_config->get_hls_td_ratio(r->vhost)); max_td = (int)(fragment * _srs_config->get_hls_td_ratio(r->vhost));
std::string storage = _srs_config->get_hls_storage(r->vhost); // TODO: FIXME: refine better for SRS2 only support disk.
if (storage == "ram") {
should_write_cache = true;
should_write_file = false;
} else if (storage == "disk") {
should_write_cache = false; should_write_cache = false;
should_write_file = true; should_write_file = true;
} else {
srs_assert(storage == "both");
should_write_cache = true;
should_write_file = true;
}
// create m3u8 dir once. // create m3u8 dir once.
m3u8_dir = srs_path_dirname(m3u8); m3u8_dir = srs_path_dirname(m3u8);
@ -756,13 +736,6 @@ int SrsHlsMuxer::segment_close(string log_desc)
log_desc.c_str(), current->sequence_no, current->uri.c_str(), current->duration, log_desc.c_str(), current->sequence_no, current->uri.c_str(), current->duration,
current->segment_start_dts); current->segment_start_dts);
// notify handler for update ts.
srs_assert(current->writer);
if (handler && (ret = handler->on_update_ts(req, current->uri, current->writer->cache())) != ERROR_SUCCESS) {
srs_error("notify handler for update ts failed. ret=%d", ret);
return ret;
}
// close the muxer of finished segment. // close the muxer of finished segment.
srs_freep(current->muxer); srs_freep(current->muxer);
std::string full_path = current->full_path; std::string full_path = current->full_path;
@ -829,13 +802,6 @@ int SrsHlsMuxer::segment_close(string log_desc)
} }
} }
if (should_write_cache) {
if ((ret = handler->on_remove_ts(req, segment->uri)) != ERROR_SUCCESS) {
srs_warn("remove the ts from ram hls failed. ret=%d", ret);
return ret;
}
}
srs_freep(segment); srs_freep(segment);
} }
segment_to_remove.clear(); segment_to_remove.clear();
@ -958,12 +924,6 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
} }
srs_info("write m3u8 %s success.", m3u8_file.c_str()); srs_info("write m3u8 %s success.", m3u8_file.c_str());
// notify handler for update m3u8.
if (handler && (ret = handler->on_update_m3u8(req, writer.cache())) != ERROR_SUCCESS) {
srs_error("notify handler for update m3u8 failed. ret=%d", ret);
return ret;
}
return ret; return ret;
} }
@ -1171,7 +1131,6 @@ SrsHls::SrsHls()
{ {
req = NULL; req = NULL;
source = NULL; source = NULL;
handler = NULL;
hls_enabled = false; hls_enabled = false;
hls_can_dispose = false; hls_can_dispose = false;
@ -1243,15 +1202,14 @@ int SrsHls::cycle()
return ret; return ret;
} }
int SrsHls::initialize(SrsSource* s, ISrsHlsHandler* h, SrsRequest* r) int SrsHls::initialize(SrsSource* s, SrsRequest* r)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
source = s; source = s;
handler = h;
req = r; req = r;
if ((ret = muxer->initialize(h)) != ERROR_SUCCESS) { if ((ret = muxer->initialize()) != ERROR_SUCCESS) {
return ret; return ret;
} }

View file

@ -53,39 +53,6 @@ class SrsHlsSegment;
class SrsTsCache; class SrsTsCache;
class SrsTsContext; class SrsTsContext;
/**
* the handler for hls event.
* for example, we use memory only hls for
*/
class ISrsHlsHandler
{
public:
ISrsHlsHandler();
virtual ~ISrsHlsHandler();
public:
/**
* when publish stream
*/
virtual int on_hls_publish(SrsRequest* req) = 0;
/**
* when update the m3u8 file.
*/
virtual int on_update_m3u8(SrsRequest* r, std::string m3u8) = 0;
/**
* when reap new ts file.
*/
virtual int on_update_ts(SrsRequest* r, std::string uri, std::string ts) = 0;
/**
* when remove the specified ts file,
* for the hls to remove the expired ts not in hls window.
*/
virtual int on_remove_ts(SrsRequest* r, std::string uri) = 0;
/**
* when unpublish stream
*/
virtual int on_hls_unpublish(SrsRequest* req) = 0;
};
/** /**
* * the HLS section, only available when HLS enabled. * * the HLS section, only available when HLS enabled.
* */ * */
@ -239,8 +206,7 @@ private:
std::string m3u8; std::string m3u8;
std::string m3u8_url; std::string m3u8_url;
private: private:
ISrsHlsHandler* handler; // TODO: FIXME: remove it.
// TODO: FIXME: supports reload.
bool should_write_cache; bool should_write_cache;
bool should_write_file; bool should_write_file;
private: private:
@ -277,7 +243,7 @@ public:
/** /**
* initialize the hls muxer. * initialize the hls muxer.
*/ */
virtual int initialize(ISrsHlsHandler* h); virtual int initialize();
/** /**
* when publish, update the config for muxer. * when publish, update the config for muxer.
*/ */
@ -390,7 +356,6 @@ class SrsHls
private: private:
SrsHlsMuxer* muxer; SrsHlsMuxer* muxer;
SrsHlsCache* hls_cache; SrsHlsCache* hls_cache;
ISrsHlsHandler* handler;
private: private:
SrsRequest* req; SrsRequest* req;
bool hls_enabled; bool hls_enabled;
@ -426,7 +391,7 @@ public:
/** /**
* initialize the hls by handler and source. * initialize the hls by handler and source.
*/ */
virtual int initialize(SrsSource* s, ISrsHlsHandler* h, SrsRequest* r); virtual int initialize(SrsSource* s, SrsRequest* r);
/** /**
* publish stream event, continue to write the m3u8, * publish stream event, continue to write the m3u8,
* for the muxer object not destroyed. * for the muxer object not destroyed.

View file

@ -1297,30 +1297,5 @@ void SrsHttpServer::http_unmount(SrsSource* s, SrsRequest* r)
http_stream->http_unmount(s, r); http_stream->http_unmount(s, r);
} }
int SrsHttpServer::mount_hls(SrsRequest* r)
{
return http_stream->mount_hls(r);
}
int SrsHttpServer::hls_update_m3u8(SrsRequest* r, std::string m3u8)
{
return http_stream->hls_update_m3u8(r, m3u8);
}
int SrsHttpServer::hls_update_ts(SrsRequest* r, std::string uri, std::string ts)
{
return http_stream->hls_update_ts(r, uri, ts);
}
int SrsHttpServer::hls_remove_ts(SrsRequest* r, std::string uri)
{
return http_stream->hls_remove_ts(r, uri);
}
void SrsHttpServer::unmount_hls(SrsRequest* r)
{
http_stream->unmount_hls(r);
}
#endif #endif

View file

@ -417,13 +417,6 @@ public:
public: public:
virtual int http_mount(SrsSource* s, SrsRequest* r); virtual int http_mount(SrsSource* s, SrsRequest* r);
virtual void http_unmount(SrsSource* s, SrsRequest* r); virtual void http_unmount(SrsSource* s, SrsRequest* r);
// hls stream
public:
virtual int mount_hls(SrsRequest* r);
virtual int hls_update_m3u8(SrsRequest* r, std::string m3u8);
virtual int hls_update_ts(SrsRequest* r, std::string uri, std::string ts);
virtual int hls_remove_ts(SrsRequest* r, std::string uri);
virtual void unmount_hls(SrsRequest* r);
}; };
#endif #endif

View file

@ -764,22 +764,6 @@ SrsHttpStreamServer::~SrsHttpStreamServer()
} }
sflvs.clear(); sflvs.clear();
} }
if (true) {
std::map<std::string, SrsHlsEntry*>::iterator it;
for (it = thls.begin(); it != thls.end(); ++it) {
SrsHlsEntry* entry = it->second;
srs_freep(entry);
}
thls.clear();
}
if (true) {
std::map<std::string, SrsHlsEntry*>::iterator it;
for (it = shls.begin(); it != shls.end(); ++it) {
SrsHlsEntry* entry = it->second;
srs_freep(entry);
}
shls.clear();
}
} }
int SrsHttpStreamServer::initialize() int SrsHttpStreamServer::initialize()
@ -791,11 +775,6 @@ int SrsHttpStreamServer::initialize()
return ret; return ret;
} }
// remux rtmp to hls live streaming
if ((ret = initialize_hls_streaming()) != ERROR_SUCCESS) {
return ret;
}
return ret; return ret;
} }
@ -961,190 +940,6 @@ int SrsHttpStreamServer::on_reload_vhost_http_remux_updated(string vhost)
return ret; return ret;
} }
int SrsHttpStreamServer::mount_hls(SrsRequest* r)
{
int ret = ERROR_SUCCESS;
std::string sid = r->get_stream_url();
if (shls.find(sid) == shls.end()) {
srs_info("ignore mount hls stream for disabled");
return ret;
}
SrsHlsEntry* entry = shls[sid];
// TODO: FIXME: supports reload.
std::map<std::string, ISrsHttpHandler*>::iterator it;
for (it = entry->streams.begin(); it != entry->streams.end(); ++it) {
ISrsHttpHandler* stream = it->second;
stream->entry->enabled = true;
}
return ret;
}
int SrsHttpStreamServer::hls_update_m3u8(SrsRequest* r, string m3u8)
{
int ret = ERROR_SUCCESS;
std::string mount;
std::string sid = r->get_stream_url();
SrsHlsEntry* entry = NULL;
// create stream from template when not found.
if (shls.find(sid) == shls.end()) {
if (thls.find(r->vhost) == thls.end()) {
srs_info("ignore mount hls stream for disabled");
return ret;
}
SrsHlsEntry* tmpl = thls[r->vhost];
srs_assert(tmpl);
entry = new SrsHlsEntry();
mount = tmpl->mount;
// 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"/", "/");
entry->tmpl = tmpl;
entry->mount = mount;
shls[sid] = entry;
if (entry->streams.find(mount) == entry->streams.end()) {
ISrsHttpHandler* he = new SrsHlsM3u8Stream();
entry->streams[mount] = he;
if ((ret = mux.handle(mount, he)) != ERROR_SUCCESS) {
srs_error("handle mount=%s failed. ret=%d", mount.c_str(), ret);
return ret;
}
}
} else {
entry = shls[sid];
}
mount = entry->mount;
// update the m3u8 stream.
SrsHlsM3u8Stream* hms = dynamic_cast<SrsHlsM3u8Stream*>(entry->streams[mount]);
if (hms) {
hms->set_m3u8(m3u8);
}
srs_trace("hls update m3u8 ok, mount=%s", mount.c_str());
return ret;
}
int SrsHttpStreamServer::hls_update_ts(SrsRequest* r, string uri, string ts)
{
int ret = ERROR_SUCCESS;
std::string sid = r->get_stream_url();
// when no hls mounted, init with empty m3u8.
if (shls.find(sid) == shls.end()) {
if ((ret = hls_update_m3u8(r, "")) != ERROR_SUCCESS) {
return ret;
}
}
// find again, ignore if not exits.
if (shls.find(sid) == shls.end()) {
return ret;
}
SrsHlsEntry* entry = shls[sid];
srs_assert(entry);
srs_assert(entry->tmpl);
std::string mount = hls_mount_generate(r, uri, entry->tmpl->mount);
if (entry->streams.find(mount) == entry->streams.end()) {
ISrsHttpHandler* he = new SrsHlsTsStream();
entry->streams[mount] = he;
if ((ret = mux.handle(mount, he)) != ERROR_SUCCESS) {
srs_error("handle mount=%s failed. ret=%d", mount.c_str(), ret);
return ret;
}
}
// update the ts stream.
SrsHlsTsStream* hts = dynamic_cast<SrsHlsTsStream*>(entry->streams[mount]);
if (hts) {
hts->set_ts(ts);
}
srs_trace("hls update ts ok, mount=%s", mount.c_str());
return ret;
}
int SrsHttpStreamServer::hls_remove_ts(SrsRequest* r, string uri)
{
int ret = ERROR_SUCCESS;
std::string sid = r->get_stream_url();
// when no hls mounted, ignore.
if (shls.find(sid) == shls.end()) {
return ret;
}
SrsHlsEntry* entry = shls[sid];
srs_assert(entry);
srs_assert(entry->tmpl);
std::string mount = hls_mount_generate(r, uri, entry->tmpl->mount);
// ignore when no ts mounted.
if (entry->streams.find(mount) == entry->streams.end()) {
return ret;
}
// update the ts stream.
SrsHlsTsStream* hts = dynamic_cast<SrsHlsTsStream*>(entry->streams[mount]);
if (hts) {
hts->set_ts("");
// TODO: FIXME: unmount and remove the http handler.
}
srs_trace("hls remove ts ok, mount=%s", mount.c_str());
return ret;
}
void SrsHttpStreamServer::unmount_hls(SrsRequest* r)
{
std::string sid = r->get_stream_url();
if (shls.find(sid) == shls.end()) {
srs_info("ignore unmount hls stream for disabled");
return;
}
SrsHlsEntry* entry = shls[sid];
std::map<std::string, ISrsHttpHandler*>::iterator it;
for (it = entry->streams.begin(); it != entry->streams.end(); ++it) {
ISrsHttpHandler* stream = it->second;
stream->entry->enabled = false;
}
}
int SrsHttpStreamServer::on_reload_vhost_hls(string vhost)
{
int ret = ERROR_SUCCESS;
// TODO: FIXME: implements it.
return ret;
}
int SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph) int SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
@ -1233,7 +1028,7 @@ int SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph)
} }
SrsSource* s = NULL; SrsSource* s = NULL;
if ((ret = SrsSource::fetch_or_create(r, server, server, &s)) != ERROR_SUCCESS) { if ((ret = SrsSource::fetch_or_create(r, server, &s)) != ERROR_SUCCESS) {
return ret; return ret;
} }
srs_assert(s != NULL); srs_assert(s != NULL);
@ -1299,59 +1094,5 @@ int SrsHttpStreamServer::initialize_flv_entry(std::string vhost)
return ret; return ret;
} }
int SrsHttpStreamServer::initialize_hls_streaming()
{
int ret = ERROR_SUCCESS;
// http hls live stream mount for each vhost.
SrsConfDirective* root = _srs_config->get_root();
for (int i = 0; i < (int)root->directives.size(); i++) {
SrsConfDirective* conf = root->at(i);
if (!conf->is_vhost()) {
continue;
}
std::string vhost = conf->arg0();
if (!_srs_config->get_hls_enabled(vhost)) {
continue;
}
std::string storage = _srs_config->get_hls_storage(vhost);
if (storage != "ram" && storage != "both") {
continue;
}
SrsHlsEntry* entry = new SrsHlsEntry();
entry->mount = _srs_config->get_hls_mount(vhost);
thls[vhost] = entry;
srs_trace("http hls live stream, vhost=%s, mount=%s",
vhost.c_str(), entry->mount.c_str());
}
return ret;
}
string SrsHttpStreamServer::hls_mount_generate(SrsRequest* r, string uri, string tmpl)
{
std::string mount = tmpl;
// the ts is relative from the m3u8, the same start dir.
mount = srs_path_dirname(mount);
// replace the vhost variable
mount = srs_string_replace(mount, "[vhost]", r->vhost);
mount = srs_string_replace(mount, "[app]", r->app);
// remove the default vhost mount
mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/");
// mount with ts.
mount += "/";
mount += uri;
return mount;
}
#endif #endif

View file

@ -334,10 +334,6 @@ public:
std::map<std::string, SrsLiveEntry*> tflvs; std::map<std::string, SrsLiveEntry*> tflvs;
// the http live streaming streams, crote by template. // the http live streaming streams, crote by template.
std::map<std::string, SrsLiveEntry*> sflvs; std::map<std::string, SrsLiveEntry*> sflvs;
// the hls live streaming template, to create streams.
std::map<std::string, SrsHlsEntry*> thls;
// the hls live streaming streams, crote by template.
std::map<std::string, SrsHlsEntry*> shls;
public: public:
SrsHttpStreamServer(SrsServer* svr); SrsHttpStreamServer(SrsServer* svr);
virtual ~SrsHttpStreamServer(); virtual ~SrsHttpStreamServer();
@ -347,26 +343,16 @@ public:
public: public:
virtual int http_mount(SrsSource* s, SrsRequest* r); virtual int http_mount(SrsSource* s, SrsRequest* r);
virtual void http_unmount(SrsSource* s, SrsRequest* r); virtual void http_unmount(SrsSource* s, SrsRequest* r);
// hls stream
public:
virtual int mount_hls(SrsRequest* r);
virtual int hls_update_m3u8(SrsRequest* r, std::string m3u8);
virtual int hls_update_ts(SrsRequest* r, std::string uri, std::string ts);
virtual int hls_remove_ts(SrsRequest* r, std::string uri);
virtual void unmount_hls(SrsRequest* r);
// interface ISrsReloadHandler. // interface ISrsReloadHandler.
public: public:
virtual int on_reload_vhost_added(std::string vhost); virtual int on_reload_vhost_added(std::string vhost);
virtual int on_reload_vhost_http_remux_updated(std::string vhost); virtual int on_reload_vhost_http_remux_updated(std::string vhost);
virtual int on_reload_vhost_hls(std::string vhost);
// interface ISrsHttpMatchHijacker // interface ISrsHttpMatchHijacker
public: public:
virtual int hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph); virtual int hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph);
private: private:
virtual int initialize_flv_streaming(); virtual int initialize_flv_streaming();
virtual int initialize_flv_entry(std::string vhost); virtual int initialize_flv_entry(std::string vhost);
virtual int initialize_hls_streaming();
virtual std::string hls_mount_generate(SrsRequest* r, std::string uri, std::string tmpl);
}; };
#endif #endif

View file

@ -710,7 +710,7 @@ int SrsRtmpConn::stream_service_cycle()
// find a source to serve. // find a source to serve.
SrsSource* source = NULL; SrsSource* source = NULL;
if ((ret = SrsSource::fetch_or_create(req, server, server, &source)) != ERROR_SUCCESS) { if ((ret = SrsSource::fetch_or_create(req, server, &source)) != ERROR_SUCCESS) {
return ret; return ret;
} }
srs_assert(source != NULL); srs_assert(source != NULL);

View file

@ -1514,67 +1514,3 @@ void SrsServer::on_unpublish(SrsSource* s, SrsRequest* r)
#endif #endif
} }
int SrsServer::on_hls_publish(SrsRequest* r)
{
int ret = ERROR_SUCCESS;
#ifdef SRS_AUTO_HTTP_SERVER
if ((ret = http_server->mount_hls(r)) != ERROR_SUCCESS) {
return ret;
}
#endif
return ret;
}
int SrsServer::on_update_m3u8(SrsRequest* r, string m3u8)
{
int ret = ERROR_SUCCESS;
#ifdef SRS_AUTO_HTTP_SERVER
if ((ret = http_server->hls_update_m3u8(r, m3u8)) != ERROR_SUCCESS) {
return ret;
}
#endif
return ret;
}
int SrsServer::on_update_ts(SrsRequest* r, string uri, string ts)
{
int ret = ERROR_SUCCESS;
#ifdef SRS_AUTO_HTTP_SERVER
if ((ret = http_server->hls_update_ts(r, uri, ts)) != ERROR_SUCCESS) {
return ret;
}
#endif
return ret;
}
int SrsServer::on_remove_ts(SrsRequest* r, string uri)
{
int ret = ERROR_SUCCESS;
#ifdef SRS_AUTO_HTTP_SERVER
if ((ret = http_server->hls_remove_ts(r, uri)) != ERROR_SUCCESS) {
return ret;
}
#endif
return ret;
}
int SrsServer::on_hls_unpublish(SrsRequest* r)
{
int ret = ERROR_SUCCESS;
#ifdef SRS_AUTO_HTTP_SERVER
http_server->unmount_hls(r);
#endif
return ret;
}

View file

@ -237,7 +237,7 @@ public:
* start connection service thread, destroy client. * start connection service thread, destroy client.
*/ */
class SrsServer : virtual public ISrsReloadHandler class SrsServer : virtual public ISrsReloadHandler
, virtual public ISrsSourceHandler, virtual public ISrsHlsHandler , virtual public ISrsSourceHandler
, virtual public IConnectionManager , virtual public IConnectionManager
{ {
private: private:
@ -391,13 +391,6 @@ public:
public: public:
virtual int on_publish(SrsSource* s, SrsRequest* r); virtual int on_publish(SrsSource* s, SrsRequest* r);
virtual void on_unpublish(SrsSource* s, SrsRequest* r); virtual void on_unpublish(SrsSource* s, SrsRequest* r);
// interface ISrsHlsHandler
public:
virtual int on_hls_publish(SrsRequest* r);
virtual int on_update_m3u8(SrsRequest* r, std::string m3u8);
virtual int on_update_ts(SrsRequest* r, std::string uri, std::string ts);
virtual int on_remove_ts(SrsRequest* r, std::string uri);
virtual int on_hls_unpublish(SrsRequest* r);
}; };
#endif #endif

View file

@ -737,7 +737,7 @@ ISrsSourceHandler::~ISrsSourceHandler()
std::map<std::string, SrsSource*> SrsSource::pool; std::map<std::string, SrsSource*> SrsSource::pool;
int SrsSource::fetch_or_create(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* hh, SrsSource** pps) int SrsSource::fetch_or_create(SrsRequest* r, ISrsSourceHandler* h, SrsSource** pps)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
@ -754,7 +754,7 @@ int SrsSource::fetch_or_create(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandl
srs_assert (pool.find(stream_url) == pool.end()); srs_assert (pool.find(stream_url) == pool.end());
source = new SrsSource(); source = new SrsSource();
if ((ret = source->initialize(r, h, hh)) != ERROR_SUCCESS) { if ((ret = source->initialize(r, h)) != ERROR_SUCCESS) {
srs_freep(source); srs_freep(source);
return ret; return ret;
} }
@ -1058,12 +1058,11 @@ bool SrsSource::expired()
return false; return false;
} }
int SrsSource::initialize(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* hh) int SrsSource::initialize(SrsRequest* r, ISrsSourceHandler* h)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
srs_assert(h); srs_assert(h);
srs_assert(hh);
srs_assert(!req); srs_assert(!req);
handler = h; handler = h;
@ -1071,7 +1070,7 @@ int SrsSource::initialize(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* h
atc = _srs_config->get_atc(req->vhost); atc = _srs_config->get_atc(req->vhost);
#ifdef SRS_AUTO_HLS #ifdef SRS_AUTO_HLS
if ((ret = hls->initialize(this, hh, req)) != ERROR_SUCCESS) { if ((ret = hls->initialize(this, req)) != ERROR_SUCCESS) {
return ret; return ret;
} }
#endif #endif

View file

@ -63,7 +63,6 @@ class SrsDvr;
class SrsEncoder; class SrsEncoder;
#endif #endif
class SrsBuffer; class SrsBuffer;
class ISrsHlsHandler;
#ifdef SRS_AUTO_HDS #ifdef SRS_AUTO_HDS
class SrsHds; class SrsHds;
#endif #endif
@ -423,10 +422,9 @@ public:
* create source when fetch from cache failed. * create source when fetch from cache failed.
* @param r the client request. * @param r the client request.
* @param h the event handler for source. * @param h the event handler for source.
* @param hh the event handler for hls.
* @param pps the matched source, if success never be NULL. * @param pps the matched source, if success never be NULL.
*/ */
static int fetch_or_create(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* hh, SrsSource** pps); static int fetch_or_create(SrsRequest* r, ISrsSourceHandler* h, SrsSource** pps);
private: private:
/** /**
* get the exists source, NULL when not exists. * get the exists source, NULL when not exists.
@ -533,7 +531,7 @@ public:
/** /**
* initialize the hls with handlers. * initialize the hls with handlers.
*/ */
virtual int initialize(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* hh); virtual int initialize(SrsRequest* r, ISrsSourceHandler* h);
// interface ISrsReloadHandler // interface ISrsReloadHandler
public: public:
virtual int on_reload_vhost_play(std::string vhost); virtual int on_reload_vhost_play(std::string vhost);