winlin

Merge branch 'wenjiegit-develop' into 2.0release

@@ -526,6 +526,13 @@ vhost with-hls.srs.com { @@ -526,6 +526,13 @@ vhost with-hls.srs.com {
526 # in a word, the hls_path is for vhost. 526 # in a word, the hls_path is for vhost.
527 # default: ./objs/nginx/html 527 # default: ./objs/nginx/html
528 hls_path ./objs/nginx/html; 528 hls_path ./objs/nginx/html;
  529 + # the hls entry prefix, which is base url of ts url.
  530 + # if specified, the ts path in m3u8 will be like:
  531 + # http://your-server/live/livestream-0.ts
  532 + # http://your-server/live/livestream-1.ts
  533 + # ...
  534 + # optional, default to empty string.
  535 + hls_entry_prefix http://your-server/;
529 # the hls mount for hls_storage ram, 536 # the hls mount for hls_storage ram,
530 # which use srs embeded http server to delivery HLS, 537 # which use srs embeded http server to delivery HLS,
531 # where the mount specifies the HTTP url to mount. 538 # where the mount specifies the HTTP url to mount.
@@ -1480,7 +1480,7 @@ int SrsConfig::check_config() @@ -1480,7 +1480,7 @@ int SrsConfig::check_config()
1480 } else if (n == "hls") { 1480 } else if (n == "hls") {
1481 for (int j = 0; j < (int)conf->directives.size(); j++) { 1481 for (int j = 0; j < (int)conf->directives.size(); j++) {
1482 string m = conf->at(j)->name.c_str(); 1482 string m = conf->at(j)->name.c_str();
1483 - if (m != "enabled" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error" 1483 + if (m != "enabled" && m != "hls_entry_prefix" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error"
1484 && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_acodec" && m != "hls_vcodec" 1484 && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_acodec" && m != "hls_vcodec"
1485 ) { 1485 ) {
1486 ret = ERROR_SYSTEM_CONFIG_INVALID; 1486 ret = ERROR_SYSTEM_CONFIG_INVALID;
@@ -3138,6 +3138,33 @@ bool SrsConfig::get_hls_enabled(string vhost) @@ -3138,6 +3138,33 @@ bool SrsConfig::get_hls_enabled(string vhost)
3138 return false; 3138 return false;
3139 } 3139 }
3140 3140
  3141 +string SrsConfig::get_hls_entry_prefix(string vhost)
  3142 +{
  3143 + SrsConfDirective* hls = get_hls(vhost);
  3144 +
  3145 + if (!hls) {
  3146 + return "";
  3147 + }
  3148 +
  3149 + SrsConfDirective* conf = hls->get("hls_entry_prefix");
  3150 +
  3151 + if (!conf) {
  3152 + return "";
  3153 + }
  3154 +
  3155 + std::string prefix = conf->arg0();
  3156 + if (prefix.empty()) {
  3157 + return "";
  3158 + }
  3159 +
  3160 + const char last = prefix[prefix.length() - 1];
  3161 + if (last != '/') {
  3162 + return prefix.append("/");
  3163 + }
  3164 +
  3165 + return prefix;
  3166 +}
  3167 +
3141 string SrsConfig::get_hls_path(string vhost) 3168 string SrsConfig::get_hls_path(string vhost)
3142 { 3169 {
3143 SrsConfDirective* hls = get_hls(vhost); 3170 SrsConfDirective* hls = get_hls(vhost);
@@ -866,6 +866,10 @@ public: @@ -866,6 +866,10 @@ public:
866 */ 866 */
867 virtual bool get_hls_enabled(std::string vhost); 867 virtual bool get_hls_enabled(std::string vhost);
868 /** 868 /**
  869 + * get the HLS m3u8 list ts segment entry prefix info.
  870 + */
  871 + virtual std::string get_hls_entry_prefix(std::string vhost);
  872 + /**
869 * get the HLS ts/m3u8 file store path. 873 * get the HLS ts/m3u8 file store path.
870 */ 874 */
871 virtual std::string get_hls_path(std::string vhost); 875 virtual std::string get_hls_path(std::string vhost);
@@ -203,13 +203,14 @@ int SrsHlsMuxer::sequence_no() @@ -203,13 +203,14 @@ int SrsHlsMuxer::sequence_no()
203 return _sequence_no; 203 return _sequence_no;
204 } 204 }
205 205
206 -int SrsHlsMuxer::update_config(SrsRequest* r, string path, int fragment, int window) 206 +int SrsHlsMuxer::update_config(SrsRequest* r, string hls_entry_prefix, string path, int fragment, int window)
207 { 207 {
208 int ret = ERROR_SUCCESS; 208 int ret = ERROR_SUCCESS;
209 209
210 srs_freep(req); 210 srs_freep(req);
211 req = r->copy(); 211 req = r->copy();
212 212
  213 + entry_prefix = hls_entry_prefix;
213 hls_path = path; 214 hls_path = path;
214 hls_fragment = fragment; 215 hls_fragment = fragment;
215 hls_window = window; 216 hls_window = window;
@@ -301,7 +302,8 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) @@ -301,7 +302,8 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)
301 current->full_path += filename; 302 current->full_path += filename;
302 303
303 // TODO: support base url, and so on. 304 // TODO: support base url, and so on.
304 - current->uri = filename; 305 + current->uri += entry_prefix;
  306 + current->uri += filename;
305 307
306 std::string tmp_file = current->full_path + ".tmp"; 308 std::string tmp_file = current->full_path + ".tmp";
307 if ((ret = current->muxer->open(tmp_file.c_str())) != ERROR_SUCCESS) { 309 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 @@ -668,6 +670,8 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment
668 int hls_fragment = (int)_srs_config->get_hls_fragment(vhost); 670 int hls_fragment = (int)_srs_config->get_hls_fragment(vhost);
669 int hls_window = (int)_srs_config->get_hls_window(vhost); 671 int hls_window = (int)_srs_config->get_hls_window(vhost);
670 672
  673 + // get the hls m3u8 ts list entry prefix config
  674 + std::string entry_prefix = _srs_config->get_hls_entry_prefix(vhost);
671 // get the hls path config 675 // get the hls path config
672 std::string hls_path = _srs_config->get_hls_path(vhost); 676 std::string hls_path = _srs_config->get_hls_path(vhost);
673 677
@@ -675,7 +679,7 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment @@ -675,7 +679,7 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment
675 // for the HLS donot requires the EXT-X-MEDIA-SEQUENCE be monotonically increase. 679 // for the HLS donot requires the EXT-X-MEDIA-SEQUENCE be monotonically increase.
676 680
677 // open muxer 681 // open muxer
678 - if ((ret = muxer->update_config(req, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) { 682 + if ((ret = muxer->update_config(req, entry_prefix, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) {
679 srs_error("m3u8 muxer update config failed. ret=%d", ret); 683 srs_error("m3u8 muxer update config failed. ret=%d", ret);
680 return ret; 684 return ret;
681 } 685 }
@@ -167,6 +167,7 @@ class SrsHlsMuxer @@ -167,6 +167,7 @@ class SrsHlsMuxer
167 private: 167 private:
168 SrsRequest* req; 168 SrsRequest* req;
169 private: 169 private:
  170 + std::string entry_prefix;
170 std::string hls_path; 171 std::string hls_path;
171 int hls_fragment; 172 int hls_fragment;
172 int hls_window; 173 int hls_window;
@@ -207,7 +208,7 @@ public: @@ -207,7 +208,7 @@ public:
207 /** 208 /**
208 * when publish, update the config for muxer. 209 * when publish, update the config for muxer.
209 */ 210 */
210 - virtual int update_config(SrsRequest* r, std::string path, int fragment, int window); 211 + virtual int update_config(SrsRequest* r, std::string hls_entry_prefix, std::string path, int fragment, int window);
211 /** 212 /**
212 * open a new segment(a new ts file), 213 * open a new segment(a new ts file),
213 * @param segment_start_dts use to calc the segment duration, 214 * @param segment_start_dts use to calc the segment duration,