winlin

fix #366, config hls to disable cleanup of ts. 2.0.154.

@@ -562,6 +562,7 @@ Supported operating systems and hardware: @@ -562,6 +562,7 @@ Supported operating systems and hardware:
562 562
563 ### SRS 2.0 history 563 ### SRS 2.0 history
564 564
  565 +* v2.0, 2015-03-30, for [#366](https://github.com/winlinvip/simple-rtmp-server/issues/366), config hls to disable cleanup of ts. 2.0.154.
565 * v2.0, 2015-03-31, support server cycle handler. 2.0.153. 566 * v2.0, 2015-03-31, support server cycle handler. 2.0.153.
566 * v2.0, 2015-03-31, support on_hls for http hooks. 2.0.152. 567 * v2.0, 2015-03-31, support on_hls for http hooks. 2.0.152.
567 * v2.0, 2015-03-31, enhanced hls, support deviation for duration. 2.0.151. 568 * v2.0, 2015-03-31, enhanced hls, support deviation for duration. 2.0.151.
@@ -594,7 +594,10 @@ vhost with-hls.srs.com { @@ -594,7 +594,10 @@ vhost with-hls.srs.com {
594 # h264, vn 594 # h264, vn
595 # default: h264 595 # default: h264
596 hls_vcodec h264; 596 hls_vcodec h264;
597 - 597 + # whether cleanup the old ts files.
  598 + # default: on
  599 + hls_cleanup on;
  600 +
598 # on_hls, never config in here, should config in http_hooks. 601 # on_hls, never config in here, should config in http_hooks.
599 # for the hls http callback, @see http_hooks.on_hls of vhost hooks.callback.srs.com 602 # for the hls http callback, @see http_hooks.on_hls of vhost hooks.callback.srs.com
600 # @read https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DeliveryHLS#http-callback 603 # @read https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DeliveryHLS#http-callback
@@ -1482,7 +1482,7 @@ int SrsConfig::check_config() @@ -1482,7 +1482,7 @@ int SrsConfig::check_config()
1482 string m = conf->at(j)->name.c_str(); 1482 string m = conf->at(j)->name.c_str();
1483 if (m != "enabled" && m != "hls_entry_prefix" && 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_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec" 1484 && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec"
1485 - && m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" 1485 + && m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup"
1486 ) { 1486 ) {
1487 ret = ERROR_SYSTEM_CONFIG_INVALID; 1487 ret = ERROR_SYSTEM_CONFIG_INVALID;
1488 srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret); 1488 srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret);
@@ -3388,6 +3388,23 @@ string SrsConfig::get_hls_vcodec(string vhost) @@ -3388,6 +3388,23 @@ string SrsConfig::get_hls_vcodec(string vhost)
3388 return conf->arg0(); 3388 return conf->arg0();
3389 } 3389 }
3390 3390
  3391 +bool SrsConfig::get_hls_cleanup(string vhost)
  3392 +{
  3393 + SrsConfDirective* hls = get_hls(vhost);
  3394 +
  3395 + if (!hls) {
  3396 + return SRS_CONF_DEFAULT_HLS_CLEANUP;
  3397 + }
  3398 +
  3399 + SrsConfDirective* conf = hls->get("hls_cleanup");
  3400 +
  3401 + if (!conf && conf->arg0() != "off") {
  3402 + return SRS_CONF_DEFAULT_HLS_CLEANUP;
  3403 + }
  3404 +
  3405 + return false;
  3406 +}
  3407 +
3391 SrsConfDirective *SrsConfig::get_hds(const string &vhost) 3408 SrsConfDirective *SrsConfig::get_hds(const string &vhost)
3392 { 3409 {
3393 SrsConfDirective* conf = get_vhost(vhost); 3410 SrsConfDirective* conf = get_vhost(vhost);
@@ -61,6 +61,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -61,6 +61,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
61 #define SRS_CONF_DEFAULT_HLS_MOUNT "[vhost]/[app]/[stream].m3u8" 61 #define SRS_CONF_DEFAULT_HLS_MOUNT "[vhost]/[app]/[stream].m3u8"
62 #define SRS_CONF_DEFAULT_HLS_ACODEC "aac" 62 #define SRS_CONF_DEFAULT_HLS_ACODEC "aac"
63 #define SRS_CONF_DEFAULT_HLS_VCODEC "h264" 63 #define SRS_CONF_DEFAULT_HLS_VCODEC "h264"
  64 +#define SRS_CONF_DEFAULT_HLS_CLEANUP true
64 #define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html/[app]/[stream].[timestamp].flv" 65 #define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html/[app]/[stream].[timestamp].flv"
65 #define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session" 66 #define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session"
66 #define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment" 67 #define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment"
@@ -935,6 +936,10 @@ public: @@ -935,6 +936,10 @@ public:
935 * get the HLS default video codec. 936 * get the HLS default video codec.
936 */ 937 */
937 virtual std::string get_hls_vcodec(std::string vhost); 938 virtual std::string get_hls_vcodec(std::string vhost);
  939 + /**
  940 + * whether cleanup the old ts files.
  941 + */
  942 + virtual bool get_hls_cleanup(std::string vhost);
938 943
939 // hds section 944 // hds section
940 private: 945 private:
@@ -224,6 +224,7 @@ SrsHlsMuxer::SrsHlsMuxer() @@ -224,6 +224,7 @@ SrsHlsMuxer::SrsHlsMuxer()
224 hls_fragment = hls_window = 0; 224 hls_fragment = hls_window = 0;
225 hls_aof_ratio = 1.0; 225 hls_aof_ratio = 1.0;
226 hls_fragment_deviation = 0; 226 hls_fragment_deviation = 0;
  227 + hls_cleanup = true;
227 previous_floor_ts = 0; 228 previous_floor_ts = 0;
228 accept_floor_ts = 0; 229 accept_floor_ts = 0;
229 hls_ts_floor = false; 230 hls_ts_floor = false;
@@ -250,19 +251,6 @@ SrsHlsMuxer::~SrsHlsMuxer() @@ -250,19 +251,6 @@ SrsHlsMuxer::~SrsHlsMuxer()
250 srs_freep(async); 251 srs_freep(async);
251 } 252 }
252 253
253 -int SrsHlsMuxer::initialize(ISrsHlsHandler* h)  
254 -{  
255 - int ret = ERROR_SUCCESS;  
256 -  
257 - handler = h;  
258 -  
259 - if ((ret = async->start()) != ERROR_SUCCESS) {  
260 - return ret;  
261 - }  
262 -  
263 - return ret;  
264 -}  
265 -  
266 int SrsHlsMuxer::sequence_no() 254 int SrsHlsMuxer::sequence_no()
267 { 255 {
268 return _sequence_no; 256 return _sequence_no;
@@ -283,9 +271,22 @@ double SrsHlsMuxer::deviation() @@ -283,9 +271,22 @@ double SrsHlsMuxer::deviation()
283 return hls_fragment_deviation; 271 return hls_fragment_deviation;
284 } 272 }
285 273
  274 +int SrsHlsMuxer::initialize(ISrsHlsHandler* h)
  275 +{
  276 + int ret = ERROR_SUCCESS;
  277 +
  278 + handler = h;
  279 +
  280 + if ((ret = async->start()) != ERROR_SUCCESS) {
  281 + return ret;
  282 + }
  283 +
  284 + return ret;
  285 +}
  286 +
286 int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, 287 int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,
287 string path, string m3u8_file, string ts_file, double fragment, double window, 288 string path, string m3u8_file, string ts_file, double fragment, double window,
288 - bool ts_floor, double aof_ratio 289 + bool ts_floor, double aof_ratio, bool cleanup
289 ) { 290 ) {
290 int ret = ERROR_SUCCESS; 291 int ret = ERROR_SUCCESS;
291 292
@@ -298,6 +299,7 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, @@ -298,6 +299,7 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,
298 hls_fragment = fragment; 299 hls_fragment = fragment;
299 hls_aof_ratio = aof_ratio; 300 hls_aof_ratio = aof_ratio;
300 hls_ts_floor = ts_floor; 301 hls_ts_floor = ts_floor;
  302 + hls_cleanup = cleanup;
301 previous_floor_ts = 0; 303 previous_floor_ts = 0;
302 accept_floor_ts = 0; 304 accept_floor_ts = 0;
303 hls_window = window; 305 hls_window = window;
@@ -651,7 +653,11 @@ int SrsHlsMuxer::segment_close(string log_desc) @@ -651,7 +653,11 @@ int SrsHlsMuxer::segment_close(string log_desc)
651 // remove the ts file. 653 // remove the ts file.
652 for (int i = 0; i < (int)segment_to_remove.size(); i++) { 654 for (int i = 0; i < (int)segment_to_remove.size(); i++) {
653 SrsHlsSegment* segment = segment_to_remove[i]; 655 SrsHlsSegment* segment = segment_to_remove[i];
654 - unlink(segment->full_path.c_str()); 656 +
  657 + if (hls_cleanup) {
  658 + unlink(segment->full_path.c_str());
  659 + }
  660 +
655 srs_freep(segment); 661 srs_freep(segment);
656 } 662 }
657 segment_to_remove.clear(); 663 segment_to_remove.clear();
@@ -796,6 +802,7 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment @@ -796,6 +802,7 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment
796 std::string path = _srs_config->get_hls_path(vhost); 802 std::string path = _srs_config->get_hls_path(vhost);
797 std::string m3u8_file = _srs_config->get_hls_m3u8_file(vhost); 803 std::string m3u8_file = _srs_config->get_hls_m3u8_file(vhost);
798 std::string ts_file = _srs_config->get_hls_ts_file(vhost); 804 std::string ts_file = _srs_config->get_hls_ts_file(vhost);
  805 + bool cleanup = _srs_config->get_hls_cleanup(vhost);
799 // the audio overflow, for pure audio to reap segment. 806 // the audio overflow, for pure audio to reap segment.
800 double hls_aof_ratio = _srs_config->get_hls_aof_ratio(vhost); 807 double hls_aof_ratio = _srs_config->get_hls_aof_ratio(vhost);
801 // whether use floor(timestamp/hls_fragment) for variable timestamp 808 // whether use floor(timestamp/hls_fragment) for variable timestamp
@@ -806,7 +813,8 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment @@ -806,7 +813,8 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment
806 813
807 // open muxer 814 // open muxer
808 if ((ret = muxer->update_config(req, entry_prefix, 815 if ((ret = muxer->update_config(req, entry_prefix,
809 - path, m3u8_file, ts_file, hls_fragment, hls_window, ts_floor, hls_aof_ratio)) != ERROR_SUCCESS 816 + path, m3u8_file, ts_file, hls_fragment, hls_window, ts_floor, hls_aof_ratio,
  817 + cleanup)) != ERROR_SUCCESS
810 ) { 818 ) {
811 srs_error("m3u8 muxer update config failed. ret=%d", ret); 819 srs_error("m3u8 muxer update config failed. ret=%d", ret);
812 return ret; 820 return ret;
@@ -188,6 +188,7 @@ private: @@ -188,6 +188,7 @@ private:
188 std::string hls_entry_prefix; 188 std::string hls_entry_prefix;
189 std::string hls_path; 189 std::string hls_path;
190 std::string hls_ts_file; 190 std::string hls_ts_file;
  191 + bool hls_cleanup;
191 std::string m3u8_dir; 192 std::string m3u8_dir;
192 double hls_aof_ratio; 193 double hls_aof_ratio;
193 double hls_fragment; 194 double hls_fragment;
@@ -245,7 +246,8 @@ public: @@ -245,7 +246,8 @@ public:
245 */ 246 */
246 virtual int update_config(SrsRequest* r, std::string entry_prefix, 247 virtual int update_config(SrsRequest* r, std::string entry_prefix,
247 std::string path, std::string m3u8_file, std::string ts_file, 248 std::string path, std::string m3u8_file, std::string ts_file,
248 - double fragment, double window, bool ts_floor, double aof_ratio); 249 + double fragment, double window, bool ts_floor, double aof_ratio,
  250 + bool cleanup);
249 /** 251 /**
250 * open a new segment(a new ts file), 252 * open a new segment(a new ts file),
251 * @param segment_start_dts use to calc the segment duration, 253 * @param segment_start_dts use to calc the segment duration,
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR 2 32 #define VERSION_MAJOR 2
33 #define VERSION_MINOR 0 33 #define VERSION_MINOR 0
34 -#define VERSION_REVISION 153 34 +#define VERSION_REVISION 154
35 35
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"