Skip to content

Commit

Permalink
merge from srs2. for #513.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Dec 15, 2016
1 parent f30b307 commit 664844b
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 553 deletions.
13 changes: 0 additions & 13 deletions trunk/conf/full.conf
Expand Up @@ -963,12 +963,6 @@ vhost with-hls.srs.com {
# @see https://github.com/ossrs/srs/issues/264
# default: 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 m3u8 file is configured by hls_path/hls_m3u8_file, the default is:
# ./objs/nginx/html/[app]/[stream].m3u8
Expand Down Expand Up @@ -1017,13 +1011,6 @@ vhost with-hls.srs.com {
# ...
# optional, default to empty string.
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.
# when codec changed, write the PAT/PMT table, but maybe ok util next ts.
# so user can set the default codec for mp3.
Expand Down
20 changes: 0 additions & 20 deletions trunk/conf/ram.hls.conf

This file was deleted.

2 changes: 0 additions & 2 deletions trunk/ide/srs_xcode/srs_xcode.xcodeproj/project.pbxproj
Expand Up @@ -319,7 +319,6 @@
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>"; };
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>"; };
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>"; };
Expand Down Expand Up @@ -755,7 +754,6 @@
3C8280281BAFF896004A1794 /* push.flv.conf */,
3C1EE6CA1AB1080900576EE9 /* push.mpegts.over.udp.conf */,
3C1EE6CB1AB1080900576EE9 /* push.rtsp.conf */,
3C1EE6CC1AB1080900576EE9 /* ram.hls.conf */,
3C1EE6CD1AB1080900576EE9 /* realtime.conf */,
3C1EE6CE1AB1080900576EE9 /* rtmp.conf */,
3C1EE6CF1AB1080900576EE9 /* security.deny.publish.conf */,
Expand Down
39 changes: 5 additions & 34 deletions trunk/src/app/srs_app_config.cpp
Expand Up @@ -3910,6 +3910,11 @@ int SrsConfig::check_config()
srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), 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") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
Expand Down Expand Up @@ -6075,40 +6080,6 @@ string SrsConfig::get_hls_on_error(string vhost)
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)
{
static string DEFAULT = "aac";
Expand Down
8 changes: 0 additions & 8 deletions trunk/src/app/srs_app_config.hpp
Expand Up @@ -1184,14 +1184,6 @@ class SrsConfig
*/
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.
*/
virtual std::string get_hls_acodec(std::string vhost);
Expand Down
58 changes: 8 additions & 50 deletions trunk/src/app/srs_app_hls.cpp
Expand Up @@ -61,14 +61,6 @@ using namespace std;
// reset the piece id when deviation overflow this.
#define SRS_JUMP_WHEN_PIECE_DEVIATION 20

ISrsHlsHandler::ISrsHlsHandler()
{
}

ISrsHlsHandler::~ISrsHlsHandler()
{
}

/**
* * the HLS section, only available when HLS enabled.
* */
Expand Down Expand Up @@ -294,7 +286,6 @@ string SrsDvrAsyncCallOnHlsNotify::to_string()
SrsHlsMuxer::SrsHlsMuxer()
{
req = NULL;
handler = NULL;
hls_fragment = hls_window = 0;
hls_aof_ratio = 1.0;
deviation_ts = 0;
Expand Down Expand Up @@ -384,11 +375,9 @@ int SrsHlsMuxer::deviation()
return deviation_ts;
}

int SrsHlsMuxer::initialize(ISrsHlsHandler* h)
int SrsHlsMuxer::initialize()
{
int ret = ERROR_SUCCESS;

handler = h;

if ((ret = async->start()) != ERROR_SUCCESS) {
return ret;
Expand Down Expand Up @@ -425,19 +414,10 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,

// when update config, reset the history target duration.
max_td = (int)(fragment * _srs_config->get_hls_td_ratio(r->vhost));

std::string storage = _srs_config->get_hls_storage(r->vhost);
if (storage == "ram") {
should_write_cache = true;
should_write_file = false;
} else if (storage == "disk") {
should_write_cache = false;
should_write_file = true;
} else {
srs_assert(storage == "both");
should_write_cache = true;
should_write_file = true;
}

// TODO: FIXME: refine better for SRS2 only support disk.
should_write_cache = false;
should_write_file = true;

// create m3u8 dir once.
m3u8_dir = srs_path_dirname(m3u8);
Expand Down Expand Up @@ -756,13 +736,6 @@ int SrsHlsMuxer::segment_close(string log_desc)
log_desc.c_str(), current->sequence_no, current->uri.c_str(), current->duration,
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.
srs_freep(current->muxer);
std::string full_path = current->full_path;
Expand Down Expand Up @@ -828,14 +801,7 @@ int SrsHlsMuxer::segment_close(string log_desc)
srs_warn("cleanup unlink path failed, file=%s.", segment->full_path.c_str());
}
}

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);
}
segment_to_remove.clear();
Expand Down Expand Up @@ -957,12 +923,6 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
return ret;
}
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;
}
Expand Down Expand Up @@ -1171,7 +1131,6 @@ SrsHls::SrsHls()
{
req = NULL;
source = NULL;
handler = NULL;

hls_enabled = false;
hls_can_dispose = false;
Expand Down Expand Up @@ -1243,15 +1202,14 @@ int SrsHls::cycle()
return ret;
}

int SrsHls::initialize(SrsSource* s, ISrsHlsHandler* h, SrsRequest* r)
int SrsHls::initialize(SrsSource* s, SrsRequest* r)
{
int ret = ERROR_SUCCESS;

source = s;
handler = h;
req = r;

if ((ret = muxer->initialize(h)) != ERROR_SUCCESS) {
if ((ret = muxer->initialize()) != ERROR_SUCCESS) {
return ret;
}

Expand Down
41 changes: 3 additions & 38 deletions trunk/src/app/srs_app_hls.hpp
Expand Up @@ -53,39 +53,6 @@ class SrsHlsSegment;
class SrsTsCache;
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.
* */
Expand Down Expand Up @@ -239,8 +206,7 @@ class SrsHlsMuxer
std::string m3u8;
std::string m3u8_url;
private:
ISrsHlsHandler* handler;
// TODO: FIXME: supports reload.
// TODO: FIXME: remove it.
bool should_write_cache;
bool should_write_file;
private:
Expand Down Expand Up @@ -277,7 +243,7 @@ class SrsHlsMuxer
/**
* initialize the hls muxer.
*/
virtual int initialize(ISrsHlsHandler* h);
virtual int initialize();
/**
* when publish, update the config for muxer.
*/
Expand Down Expand Up @@ -390,7 +356,6 @@ class SrsHls
private:
SrsHlsMuxer* muxer;
SrsHlsCache* hls_cache;
ISrsHlsHandler* handler;
private:
SrsRequest* req;
bool hls_enabled;
Expand Down Expand Up @@ -426,7 +391,7 @@ class SrsHls
/**
* 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,
* for the muxer object not destroyed.
Expand Down
25 changes: 0 additions & 25 deletions trunk/src/app/srs_app_http_conn.cpp
Expand Up @@ -1297,30 +1297,5 @@ void SrsHttpServer::http_unmount(SrsSource* s, SrsRequest* 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

7 changes: 0 additions & 7 deletions trunk/src/app/srs_app_http_conn.hpp
Expand Up @@ -417,13 +417,6 @@ class SrsHttpServer : public ISrsHttpServeMux
public:
virtual int http_mount(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
Expand Down

0 comments on commit 664844b

Please sign in to comment.