Skip to content

Commit 0bd80de

Browse files
author
fengyifan
committed
clean up source and add publisher status
1 parent 6c1067d commit 0bd80de

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

trunk/src/app/srs_app_source.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,8 @@ SrsSource* SrsSource::fetch(SrsRequest* r)
16811681
// and we only need to update the token of request, it's simple.
16821682
source->req->update_auth(r);
16831683

1684+
source->die_at = 0;
1685+
source->active_at = srs_get_system_time();
16841686
return source;
16851687
}
16861688

@@ -1719,7 +1721,7 @@ srs_error_t SrsSource::do_cycle_all()
17191721
// TODO: FIXME: support source cleanup.
17201722
// @see https://github.com/ossrs/srs/issues/713
17211723
// @see https://github.com/ossrs/srs/issues/714
1722-
#if 0
1724+
#if 1
17231725
// When source expired, remove it.
17241726
if (source->expired()) {
17251727
int cid = source->source_id();
@@ -1764,6 +1766,7 @@ SrsSource::SrsSource()
17641766
_can_publish = true;
17651767
_pre_source_id = _source_id = -1;
17661768
die_at = 0;
1769+
active_at = srs_get_system_time();
17671770

17681771
play_edge = new SrsPlayEdge();
17691772
publish_edge = new SrsPublishEdge();
@@ -1816,11 +1819,6 @@ srs_error_t SrsSource::cycle()
18161819

18171820
bool SrsSource::expired()
18181821
{
1819-
// unknown state?
1820-
if (die_at == 0) {
1821-
return false;
1822-
}
1823-
18241822
// still publishing?
18251823
if (!_can_publish || !publish_edge->can_publish()) {
18261824
return false;
@@ -1830,6 +1828,16 @@ bool SrsSource::expired()
18301828
if (!consumers.empty()) {
18311829
return false;
18321830
}
1831+
1832+
// unknown state?
1833+
if (die_at == 0) {
1834+
// inactive source?
1835+
int64_t now = srs_get_system_time();
1836+
if (now > active_at + SRS_SOURCE_CLEANUP * 1.5) { // use SRS_CONSTS_RTMP_RECV_TIMEOUT_US ?
1837+
return true;
1838+
}
1839+
return false;
1840+
}
18331841

18341842
srs_utime_t now = srs_get_system_time();
18351843
if (now > die_at + SRS_SOURCE_CLEANUP) {
@@ -2005,6 +2013,8 @@ bool SrsSource::can_publish(bool is_edge)
20052013

20062014
srs_error_t SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata)
20072015
{
2016+
active_at = srs_get_system_time();
2017+
20082018
srs_error_t err = srs_success;
20092019

20102020
// if allow atc_auto and bravo-atc detected, open atc for vhost.
@@ -2051,6 +2061,8 @@ srs_error_t SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket*
20512061

20522062
srs_error_t SrsSource::on_audio(SrsCommonMessage* shared_audio)
20532063
{
2064+
active_at = srs_get_system_time();
2065+
20542066
srs_error_t err = srs_success;
20552067

20562068
// monotically increase detect.
@@ -2159,6 +2171,8 @@ srs_error_t SrsSource::on_audio_imp(SrsSharedPtrMessage* msg)
21592171

21602172
srs_error_t SrsSource::on_video(SrsCommonMessage* shared_video)
21612173
{
2174+
active_at = srs_get_system_time();
2175+
21622176
srs_error_t err = srs_success;
21632177

21642178
// monotically increase detect.

trunk/src/app/srs_app_source.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ class SrsSource : public ISrsReloadHandler
508508
// The last die time, when all consumers quit and no publisher,
509509
// We will remove the source when source die.
510510
srs_utime_t die_at;
511+
// last active time
512+
int64_t active_at;
511513
public:
512514
SrsSource();
513515
virtual ~SrsSource();

0 commit comments

Comments
 (0)