wenjie.zhao

for #340, refine ts prefix code.

@@ -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.
@@ -9,7 +9,7 @@ vhost __defaultVhost__ { @@ -9,7 +9,7 @@ vhost __defaultVhost__ {
9 enabled on; 9 enabled on;
10 hls_fragment 10; 10 hls_fragment 10;
11 hls_window 60; 11 hls_window 60;
12 -# hls_entry_prefix http://127.0.0.1/; 12 + # hls_entry_prefix http://127.0.0.1/;
13 hls_path ./objs/nginx/html; 13 hls_path ./objs/nginx/html;
14 } 14 }
15 } 15 }
@@ -3152,7 +3152,17 @@ string SrsConfig::get_hls_entry_prefix(string vhost) @@ -3152,7 +3152,17 @@ string SrsConfig::get_hls_entry_prefix(string vhost)
3152 return ""; 3152 return "";
3153 } 3153 }
3154 3154
3155 - return conf->arg0(); 3155 + std::string hls_entry_prefix = conf->arg0();
  3156 + if (hls_entry_prefix.empty()) {
  3157 + return "";
  3158 + }
  3159 +
  3160 + char last_char = hls_entry_prefix[hls_entry_prefix.length() - 1];
  3161 + if (last_char != '/') {
  3162 + hls_entry_prefix.append("/");
  3163 + }
  3164 +
  3165 + return hls_entry_prefix;
3156 } 3166 }
3157 3167
3158 string SrsConfig::get_hls_path(string vhost) 3168 string SrsConfig::get_hls_path(string vhost)
@@ -203,14 +203,14 @@ int SrsHlsMuxer::sequence_no() @@ -203,14 +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 _entry_prefix, 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 = _entry_prefix; 213 + entry_prefix = hls_entry_prefix;
214 hls_path = path; 214 hls_path = path;
215 hls_fragment = fragment; 215 hls_fragment = fragment;
216 hls_window = window; 216 hls_window = window;
@@ -208,7 +208,7 @@ public: @@ -208,7 +208,7 @@ public:
208 /** 208 /**
209 * when publish, update the config for muxer. 209 * when publish, update the config for muxer.
210 */ 210 */
211 - virtual int update_config(SrsRequest* r, std::string _entry_prefix, 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);
212 /** 212 /**
213 * open a new segment(a new ts file), 213 * open a new segment(a new ts file),
214 * @param segment_start_dts use to calc the segment duration, 214 * @param segment_start_dts use to calc the segment duration,