Skip to content

Commit

Permalink
for #209, support cleanup when srs stop.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed May 30, 2015
1 parent 860d68e commit 4a80a5a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ Compare SRS with other media server.
| RTMP Edge | Stable | X | X | Stable | X |
| RTMP Backup | Stable | X | X | X | X |
| VHOST | Stable | X | X | Stable | Stable |
| Reload | Stable | Stable | X | X | X |
| Reload | Stable | X | X | X | X |
| Forward | Stable | X | X | X | X |
| ATC | Stable | X | X | X | X |

Expand Down Expand Up @@ -312,6 +312,7 @@ Remark:
1. HLS aonly: The HLS audio only streaming delivery.
1. BW check: The bandwidth check.
1. Security: To allow or deny stream publish or play.
1. Reload: Nginx supports reload, but not nginx-rtmp.

## Releases

Expand Down
52 changes: 47 additions & 5 deletions trunk/src/app/srs_app_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ SrsHlsMuxer::SrsHlsMuxer()

SrsHlsMuxer::~SrsHlsMuxer()
{

std::vector<SrsHlsSegment*>::iterator it;
for (it = segments.begin(); it != segments.end(); ++it) {
SrsHlsSegment* segment = *it;
Expand All @@ -305,6 +306,40 @@ SrsHlsMuxer::~SrsHlsMuxer()
srs_freep(context);
}

void SrsHlsMuxer::dispose()
{
if (!should_write_file) {
return;
}

std::vector<SrsHlsSegment*>::iterator it;
for (it = segments.begin(); it != segments.end(); ++it) {
SrsHlsSegment* segment = *it;
if (unlink(segment->full_path.c_str()) < 0) {
srs_warn("dispose unlink path failed, file=%s.", segment->full_path.c_str());
}
}

if (current) {
std::string path = current->full_path + ".tmp";
if (unlink(path.c_str()) < 0) {
srs_warn("dispose unlink path failed, file=%s", path.c_str());
}
}

if (unlink(m3u8.c_str()) < 0) {
srs_warn("dispose unlink path failed. file=%s", m3u8.c_str());
}
srs_trace("gracefully dispose hls %s", req? req->get_stream_url().c_str() : "");
}

int SrsHlsMuxer::cycle()
{
int ret = ERROR_SUCCESS;
// TODO: FIXME: implements it.
return ret;
}

int SrsHlsMuxer::sequence_no()
{
return _sequence_no;
Expand Down Expand Up @@ -720,6 +755,9 @@ int SrsHlsMuxer::segment_close(string log_desc)
std::string tmp_file = current->full_path + ".tmp";
if (should_write_file) {
unlink(tmp_file.c_str());
if (unlink(tmp_file.c_str()) < 0) {
srs_warn("drop unlink path failed, file=%s.", tmp_file.c_str());
}
}

srs_freep(current);
Expand Down Expand Up @@ -754,7 +792,9 @@ int SrsHlsMuxer::segment_close(string log_desc)
SrsHlsSegment* segment = segment_to_remove[i];

if (hls_cleanup) {
unlink(segment->full_path.c_str());
if (unlink(segment->full_path.c_str()) < 0) {
srs_warn("cleanup unlink path failed, file=%s.", segment->full_path.c_str());
}
}

srs_freep(segment);
Expand Down Expand Up @@ -1111,15 +1151,17 @@ SrsHls::~SrsHls()

void SrsHls::dispose()
{
if (hls_enabled) {
on_unpublish();
}

muxer->dispose();
}

int SrsHls::cycle()
{
int ret = ERROR_SUCCESS;

srs_info("hls cycle for source %d", source->source_id());

return ret;
return muxer->cycle();
}

int SrsHls::initialize(SrsSource* s, ISrsHlsHandler* h)
Expand Down
3 changes: 3 additions & 0 deletions trunk/src/app/srs_app_hls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ class SrsHlsMuxer
public:
SrsHlsMuxer();
virtual ~SrsHlsMuxer();
public:
virtual void dispose();
virtual int cycle();
public:
virtual int sequence_no();
virtual std::string ts_url();
Expand Down

0 comments on commit 4a80a5a

Please sign in to comment.