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

add hls prefix of uri supported

This commit is contained in:
wenjie.zhao 2015-03-13 00:22:55 +08:00
parent efe3050d7a
commit 10da182853
5 changed files with 32 additions and 5 deletions

View file

@ -9,6 +9,7 @@ vhost __defaultVhost__ {
enabled on; enabled on;
hls_fragment 10; hls_fragment 10;
hls_window 60; hls_window 60;
# hls_entry_prefix http://127.0.0.1/;
hls_path ./objs/nginx/html; hls_path ./objs/nginx/html;
} }
} }

View file

@ -1480,7 +1480,7 @@ int SrsConfig::check_config()
} else if (n == "hls") { } else if (n == "hls") {
for (int j = 0; j < (int)conf->directives.size(); j++) { for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str(); string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error" if (m != "enabled" && m != "hls_entry_prefix" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error"
&& m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_acodec" && m != "hls_vcodec" && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_acodec" && m != "hls_vcodec"
) { ) {
ret = ERROR_SYSTEM_CONFIG_INVALID; ret = ERROR_SYSTEM_CONFIG_INVALID;
@ -3138,6 +3138,23 @@ bool SrsConfig::get_hls_enabled(string vhost)
return false; return false;
} }
string SrsConfig::get_hls_entry_prefix(string vhost)
{
SrsConfDirective* hls = get_hls(vhost);
if (!hls) {
return "";
}
SrsConfDirective* conf = hls->get("hls_entry_prefix");
if (!conf) {
return "";
}
return conf->arg0();
}
string SrsConfig::get_hls_path(string vhost) string SrsConfig::get_hls_path(string vhost)
{ {
SrsConfDirective* hls = get_hls(vhost); SrsConfDirective* hls = get_hls(vhost);

View file

@ -866,6 +866,10 @@ public:
*/ */
virtual bool get_hls_enabled(std::string vhost); virtual bool get_hls_enabled(std::string vhost);
/** /**
* get the HLS m3u8 list ts segment entry prefix info.
*/
virtual std::string get_hls_entry_prefix(std::string vhost);
/**
* get the HLS ts/m3u8 file store path. * get the HLS ts/m3u8 file store path.
*/ */
virtual std::string get_hls_path(std::string vhost); virtual std::string get_hls_path(std::string vhost);

View file

@ -203,13 +203,14 @@ int SrsHlsMuxer::sequence_no()
return _sequence_no; return _sequence_no;
} }
int SrsHlsMuxer::update_config(SrsRequest* r, string path, int fragment, int window) int SrsHlsMuxer::update_config(SrsRequest* r, string _entry_prefix, string path, int fragment, int window)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
srs_freep(req); srs_freep(req);
req = r->copy(); req = r->copy();
entry_prefix = _entry_prefix;
hls_path = path; hls_path = path;
hls_fragment = fragment; hls_fragment = fragment;
hls_window = window; hls_window = window;
@ -301,7 +302,8 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)
current->full_path += filename; current->full_path += filename;
// TODO: support base url, and so on. // TODO: support base url, and so on.
current->uri = filename; current->uri += entry_prefix;
current->uri += filename;
std::string tmp_file = current->full_path + ".tmp"; std::string tmp_file = current->full_path + ".tmp";
if ((ret = current->muxer->open(tmp_file.c_str())) != ERROR_SUCCESS) { if ((ret = current->muxer->open(tmp_file.c_str())) != ERROR_SUCCESS) {
@ -668,6 +670,8 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment
int hls_fragment = (int)_srs_config->get_hls_fragment(vhost); int hls_fragment = (int)_srs_config->get_hls_fragment(vhost);
int hls_window = (int)_srs_config->get_hls_window(vhost); int hls_window = (int)_srs_config->get_hls_window(vhost);
// get the hls m3u8 ts list entry prefix config
std::string entry_prefix = _srs_config->get_hls_entry_prefix(vhost);
// get the hls path config // get the hls path config
std::string hls_path = _srs_config->get_hls_path(vhost); std::string hls_path = _srs_config->get_hls_path(vhost);
@ -675,7 +679,7 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment
// for the HLS donot requires the EXT-X-MEDIA-SEQUENCE be monotonically increase. // for the HLS donot requires the EXT-X-MEDIA-SEQUENCE be monotonically increase.
// open muxer // open muxer
if ((ret = muxer->update_config(req, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) { if ((ret = muxer->update_config(req, entry_prefix, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) {
srs_error("m3u8 muxer update config failed. ret=%d", ret); srs_error("m3u8 muxer update config failed. ret=%d", ret);
return ret; return ret;
} }

View file

@ -167,6 +167,7 @@ class SrsHlsMuxer
private: private:
SrsRequest* req; SrsRequest* req;
private: private:
std::string entry_prefix;
std::string hls_path; std::string hls_path;
int hls_fragment; int hls_fragment;
int hls_window; int hls_window;
@ -207,7 +208,7 @@ public:
/** /**
* when publish, update the config for muxer. * when publish, update the config for muxer.
*/ */
virtual int update_config(SrsRequest* r, std::string path, int fragment, int window); virtual int update_config(SrsRequest* r, std::string _entry_prefix, std::string path, int fragment, int window);
/** /**
* open a new segment(a new ts file), * open a new segment(a new ts file),
* @param segment_start_dts use to calc the segment duration, * @param segment_start_dts use to calc the segment duration,