Skip to content

Correct the issue where the source is consistently emptied prior to configuration. #4276

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
21 changes: 19 additions & 2 deletions trunk/src/app/srs_app_rtc_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ srs_error_t SrsRtcSourceManager::notify(int event, srs_utime_t interval, srs_uti

// When source expired, remove it.
// @see https://github.com/ossrs/srs/issues/713
SrsLocker(lock);
if (source->stream_is_dead()) {
SrsContextId cid = source->source_id();
if (cid.empty()) cid = source->pre_source_id();
Expand Down Expand Up @@ -318,6 +319,7 @@ srs_error_t SrsRtcSourceManager::fetch_or_create(SrsRequest* r, SrsSharedPtr<Srs
// for origin auth is on, the token in request maybe invalid,
// and we only need to update the token of request, it's simple.
source->update_auth(r);
source->update_stream_die_at();
pps = source;

return err;
Expand Down Expand Up @@ -387,7 +389,7 @@ SrsRtcSource::SrsRtcSource()
#endif

pli_for_rtmp_ = pli_elapsed_ = 0;
stream_die_at_ = 0;
stream_die_at_ = srs_get_system_time();
}

SrsRtcSource::~SrsRtcSource()
Expand Down Expand Up @@ -493,6 +495,21 @@ void SrsRtcSource::update_auth(SrsRequest* r)
req->update_auth(r);
}

void SrsRtcSource::update_stream_die_at()
{
// already publishing
if (!is_created_) {
return;
}

// has consumers
if (!consumers.empty()) {
return;
}

stream_die_at_ = srs_get_system_time();
}

srs_error_t SrsRtcSource::on_source_changed()
{
srs_error_t err = srs_success;
Expand Down Expand Up @@ -554,7 +571,7 @@ srs_error_t SrsRtcSource::create_consumer(SrsRtcConsumer*& consumer)
consumer = new SrsRtcConsumer(this);
consumers.push_back(consumer);

stream_die_at_ = 0;
// stream_die_at_ = 0;

// TODO: FIXME: Implements edge cluster.

Expand Down
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_rtc_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class SrsRtcSource : public ISrsFastTimer
public:
// Update the authentication information in request.
virtual void update_auth(SrsRequest* r);
virtual void update_stream_die_at();
private:
// The stream source changed.
virtual srs_error_t on_source_changed();
Expand Down
22 changes: 19 additions & 3 deletions trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,7 @@ srs_error_t SrsLiveSourceManager::fetch_or_create(SrsRequest* r, ISrsLiveSourceH
// for origin auth is on, the token in request maybe invalid,
// and we only need to update the token of request, it's simple.
source->update_auth(r);
source->update_stream_die_at();
pps = source;
return err;
}
Expand Down Expand Up @@ -1861,6 +1862,7 @@ srs_error_t SrsLiveSourceManager::notify(int event, srs_utime_t interval, srs_ut

// When source expired, remove it.
// @see https://github.com/ossrs/srs/issues/713
SrsLocker(lock);
if (source->stream_is_dead()) {
SrsContextId cid = source->source_id();
if (cid.empty()) cid = source->pre_source_id();
Expand All @@ -1887,7 +1889,7 @@ SrsLiveSource::SrsLiveSource()
mix_queue = new SrsMixQueue();

can_publish_ = true;
stream_die_at_ = 0;
stream_die_at_ = srs_get_system_time(); //SrsLiveSource should have a die time.
publisher_idle_at_ = 0;

handler = NULL;
Expand Down Expand Up @@ -2159,6 +2161,21 @@ void SrsLiveSource::update_auth(SrsRequest* r)
req->update_auth(r);
}

void SrsLiveSource::update_stream_die_at()
{
// already publishing
if (!can_publish_ || !publish_edge->can_publish()) {
return;
}

// has consumers
if (!consumers.empty()) {
return;
}

stream_die_at_ = srs_get_system_time();
}

bool SrsLiveSource::can_publish(bool is_edge)
{
// TODO: FIXME: Should check the status of bridge.
Expand Down Expand Up @@ -2676,8 +2693,7 @@ srs_error_t SrsLiveSource::create_consumer(SrsLiveConsumer*& consumer)
consumer = new SrsLiveConsumer(this);
consumers.push_back(consumer);

// There are more than one consumer, so reset the timeout.
stream_die_at_ = 0;
// There are more than one consumer, so reset the publisher idle timeout.
publisher_idle_at_ = 0;

return err;
Expand Down
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ class SrsLiveSource : public ISrsReloadHandler
virtual bool inactive();
// Update the authentication information in request.
virtual void update_auth(SrsRequest* r);
virtual void update_stream_die_at();
public:
virtual bool can_publish(bool is_edge);
virtual srs_error_t on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata);
Expand Down
20 changes: 18 additions & 2 deletions trunk/src/app/srs_app_srt_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ srs_error_t SrsSrtSourceManager::notify(int event, srs_utime_t interval, srs_uti

// When source expired, remove it.
// @see https://github.com/ossrs/srs/issues/713
SrsLocker(lock);
if (source->stream_is_dead()) {
SrsContextId cid = source->source_id();
if (cid.empty()) cid = source->pre_source_id();
Expand Down Expand Up @@ -167,6 +168,7 @@ srs_error_t SrsSrtSourceManager::fetch_or_create(SrsRequest* r, SrsSharedPtr<Srs
// for origin auth is on, the token in request maybe invalid,
// and we only need to update the token of request, it's simple.
source->update_auth(r);
source->update_stream_die_at();
pps = source;

return err;
Expand Down Expand Up @@ -900,7 +902,7 @@ SrsSrtSource::SrsSrtSource()
can_publish_ = true;
frame_builder_ = NULL;
bridge_ = NULL;
stream_die_at_ = 0;
stream_die_at_ = srs_get_system_time();
}

SrsSrtSource::~SrsSrtSource()
Expand Down Expand Up @@ -986,6 +988,20 @@ void SrsSrtSource::update_auth(SrsRequest* r)
req->update_auth(r);
}

void SrsSrtSource::update_stream_die_at()
{
if (!can_publish_) {
return;
}

// has consumers
if (!consumers.empty()) {
return;
}

stream_die_at_ = srs_get_system_time();
}

void SrsSrtSource::set_bridge(ISrsStreamBridge* bridge)
{
srs_freep(bridge_);
Expand All @@ -1002,7 +1018,7 @@ srs_error_t SrsSrtSource::create_consumer(SrsSrtConsumer*& consumer)
consumer = new SrsSrtConsumer(this);
consumers.push_back(consumer);

stream_die_at_ = 0;
// stream_die_at_ = 0;

return err;
}
Expand Down
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_srt_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class SrsSrtSource
virtual SrsContextId pre_source_id();
// Update the authentication information in request.
virtual void update_auth(SrsRequest* r);
virtual void update_stream_die_at();
public:
void set_bridge(ISrsStreamBridge* bridge);
public:
Expand Down