winlin

for #209, support cleanup when srs stop.

@@ -250,7 +250,7 @@ Compare SRS with other media server. @@ -250,7 +250,7 @@ Compare SRS with other media server.
250 | RTMP Edge | Stable | X | X | Stable | X | 250 | RTMP Edge | Stable | X | X | Stable | X |
251 | RTMP Backup | Stable | X | X | X | X | 251 | RTMP Backup | Stable | X | X | X | X |
252 | VHOST | Stable | X | X | Stable | Stable | 252 | VHOST | Stable | X | X | Stable | Stable |
253 -| Reload | Stable | Stable | X | X | X | 253 +| Reload | Stable | X | X | X | X |
254 | Forward | Stable | X | X | X | X | 254 | Forward | Stable | X | X | X | X |
255 | ATC | Stable | X | X | X | X | 255 | ATC | Stable | X | X | X | X |
256 256
@@ -312,6 +312,7 @@ Remark: @@ -312,6 +312,7 @@ Remark:
312 1. HLS aonly: The HLS audio only streaming delivery. 312 1. HLS aonly: The HLS audio only streaming delivery.
313 1. BW check: The bandwidth check. 313 1. BW check: The bandwidth check.
314 1. Security: To allow or deny stream publish or play. 314 1. Security: To allow or deny stream publish or play.
  315 +1. Reload: Nginx supports reload, but not nginx-rtmp.
315 316
316 ## Releases 317 ## Releases
317 318
@@ -292,6 +292,7 @@ SrsHlsMuxer::SrsHlsMuxer() @@ -292,6 +292,7 @@ SrsHlsMuxer::SrsHlsMuxer()
292 292
293 SrsHlsMuxer::~SrsHlsMuxer() 293 SrsHlsMuxer::~SrsHlsMuxer()
294 { 294 {
  295 +
295 std::vector<SrsHlsSegment*>::iterator it; 296 std::vector<SrsHlsSegment*>::iterator it;
296 for (it = segments.begin(); it != segments.end(); ++it) { 297 for (it = segments.begin(); it != segments.end(); ++it) {
297 SrsHlsSegment* segment = *it; 298 SrsHlsSegment* segment = *it;
@@ -305,6 +306,40 @@ SrsHlsMuxer::~SrsHlsMuxer() @@ -305,6 +306,40 @@ SrsHlsMuxer::~SrsHlsMuxer()
305 srs_freep(context); 306 srs_freep(context);
306 } 307 }
307 308
  309 +void SrsHlsMuxer::dispose()
  310 +{
  311 + if (!should_write_file) {
  312 + return;
  313 + }
  314 +
  315 + std::vector<SrsHlsSegment*>::iterator it;
  316 + for (it = segments.begin(); it != segments.end(); ++it) {
  317 + SrsHlsSegment* segment = *it;
  318 + if (unlink(segment->full_path.c_str()) < 0) {
  319 + srs_warn("dispose unlink path failed, file=%s.", segment->full_path.c_str());
  320 + }
  321 + }
  322 +
  323 + if (current) {
  324 + std::string path = current->full_path + ".tmp";
  325 + if (unlink(path.c_str()) < 0) {
  326 + srs_warn("dispose unlink path failed, file=%s", path.c_str());
  327 + }
  328 + }
  329 +
  330 + if (unlink(m3u8.c_str()) < 0) {
  331 + srs_warn("dispose unlink path failed. file=%s", m3u8.c_str());
  332 + }
  333 + srs_trace("gracefully dispose hls %s", req? req->get_stream_url().c_str() : "");
  334 +}
  335 +
  336 +int SrsHlsMuxer::cycle()
  337 +{
  338 + int ret = ERROR_SUCCESS;
  339 + // TODO: FIXME: implements it.
  340 + return ret;
  341 +}
  342 +
308 int SrsHlsMuxer::sequence_no() 343 int SrsHlsMuxer::sequence_no()
309 { 344 {
310 return _sequence_no; 345 return _sequence_no;
@@ -720,6 +755,9 @@ int SrsHlsMuxer::segment_close(string log_desc) @@ -720,6 +755,9 @@ int SrsHlsMuxer::segment_close(string log_desc)
720 std::string tmp_file = current->full_path + ".tmp"; 755 std::string tmp_file = current->full_path + ".tmp";
721 if (should_write_file) { 756 if (should_write_file) {
722 unlink(tmp_file.c_str()); 757 unlink(tmp_file.c_str());
  758 + if (unlink(tmp_file.c_str()) < 0) {
  759 + srs_warn("drop unlink path failed, file=%s.", tmp_file.c_str());
  760 + }
723 } 761 }
724 762
725 srs_freep(current); 763 srs_freep(current);
@@ -754,7 +792,9 @@ int SrsHlsMuxer::segment_close(string log_desc) @@ -754,7 +792,9 @@ int SrsHlsMuxer::segment_close(string log_desc)
754 SrsHlsSegment* segment = segment_to_remove[i]; 792 SrsHlsSegment* segment = segment_to_remove[i];
755 793
756 if (hls_cleanup) { 794 if (hls_cleanup) {
757 - unlink(segment->full_path.c_str()); 795 + if (unlink(segment->full_path.c_str()) < 0) {
  796 + srs_warn("cleanup unlink path failed, file=%s.", segment->full_path.c_str());
  797 + }
758 } 798 }
759 799
760 srs_freep(segment); 800 srs_freep(segment);
@@ -1111,15 +1151,17 @@ SrsHls::~SrsHls() @@ -1111,15 +1151,17 @@ SrsHls::~SrsHls()
1111 1151
1112 void SrsHls::dispose() 1152 void SrsHls::dispose()
1113 { 1153 {
  1154 + if (hls_enabled) {
  1155 + on_unpublish();
  1156 + }
  1157 +
  1158 + muxer->dispose();
1114 } 1159 }
1115 1160
1116 int SrsHls::cycle() 1161 int SrsHls::cycle()
1117 { 1162 {
1118 - int ret = ERROR_SUCCESS;  
1119 -  
1120 srs_info("hls cycle for source %d", source->source_id()); 1163 srs_info("hls cycle for source %d", source->source_id());
1121 -  
1122 - return ret; 1164 + return muxer->cycle();
1123 } 1165 }
1124 1166
1125 int SrsHls::initialize(SrsSource* s, ISrsHlsHandler* h) 1167 int SrsHls::initialize(SrsSource* s, ISrsHlsHandler* h)
@@ -260,6 +260,9 @@ public: @@ -260,6 +260,9 @@ public:
260 SrsHlsMuxer(); 260 SrsHlsMuxer();
261 virtual ~SrsHlsMuxer(); 261 virtual ~SrsHlsMuxer();
262 public: 262 public:
  263 + virtual void dispose();
  264 + virtual int cycle();
  265 +public:
263 virtual int sequence_no(); 266 virtual int sequence_no();
264 virtual std::string ts_url(); 267 virtual std::string ts_url();
265 virtual double duration(); 268 virtual double duration();