Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clean up source and add publisher status #1568

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,11 @@ SrsSource* SrsSource::fetch(SrsRequest* r)
// and we only need to update the token of request, it's simple.
source->req->update_auth(r);

// all consumers quit and no publisher?
if(source->is_die()) {
source->die_at = srs_get_system_time();
}

return source;
}

Expand Down Expand Up @@ -1719,7 +1724,7 @@ srs_error_t SrsSource::do_cycle_all()
// TODO: FIXME: support source cleanup.
// @see https://github.com/ossrs/srs/issues/713
// @see https://github.com/ossrs/srs/issues/714
#if 0
#if 1
// When source expired, remove it.
if (source->expired()) {
int cid = source->source_id();
Expand Down Expand Up @@ -1763,7 +1768,7 @@ SrsSource::SrsSource()

_can_publish = true;
_pre_source_id = _source_id = -1;
die_at = 0;
die_at = srs_get_system_time(); // all consumers quit and no publisher, update last die time

play_edge = new SrsPlayEdge();
publish_edge = new SrsPublishEdge();
Expand Down Expand Up @@ -1814,13 +1819,8 @@ srs_error_t SrsSource::cycle()
return srs_success;
}

bool SrsSource::expired()
bool SrsSource::is_die()
{
// unknown state?
if (die_at == 0) {
return false;
}

// still publishing?
if (!_can_publish || !publish_edge->can_publish()) {
return false;
Expand All @@ -1830,6 +1830,21 @@ bool SrsSource::expired()
if (!consumers.empty()) {
return false;
}
return true;
}

bool SrsSource::expired()
{
// isn't die?
if(!is_die()) {
return false;
}

// unknown state?
if (die_at == 0) {
// inactive source?
return false;
}

srs_utime_t now = srs_get_system_time();
if (now > die_at + SRS_SOURCE_CLEANUP) {
Expand Down Expand Up @@ -2427,8 +2442,8 @@ void SrsSource::on_unpublish()
stat->on_stream_close(req);
handler->on_unpublish(this, req);

// no consumer, stream is die.
if (consumers.empty()) {
// all consumers quit and no publisher?
if(is_die()) {
die_at = srs_get_system_time();
}
}
Expand Down Expand Up @@ -2494,6 +2509,9 @@ void SrsSource::on_consumer_destroy(SrsConsumer* consumer)

if (consumers.empty()) {
play_edge->on_all_client_stop();
}
// all consumers quit and no publisher?
if(is_die()) {
die_at = srs_get_system_time();
}
}
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/app/srs_app_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ class SrsSource : public ISrsReloadHandler
public:
virtual void dispose();
virtual srs_error_t cycle();
// All consumers quit and no publisher
virtual bool is_die();
// Remove source when expired.
virtual bool expired();
public:
Expand Down