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

HTTP-FLV: Crash when multiple viewers. v6.0.148 v7.0.5 #4144

Merged
Merged
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
8 changes: 4 additions & 4 deletions trunk/src/app/srs_app_http_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ SrsLiveStream::SrsLiveStream(SrsRequest* r, SrsBufferCache* c)
cache = c;
req = r->copy()->as_http();
security_ = new SrsSecurity();
alive_ = false;
alive_viewers_ = 0;
}

SrsLiveStream::~SrsLiveStream()
Expand Down Expand Up @@ -634,9 +634,9 @@ srs_error_t SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage
return srs_error_wrap(err, "http hook");
}

alive_ = true;
alive_viewers_++;
err = do_serve_http(w, r);
alive_ = false;
alive_viewers_--;

http_hooks_on_stop(r);

Expand All @@ -645,7 +645,7 @@ srs_error_t SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage

bool SrsLiveStream::alive()
{
return alive_;
return alive_viewers_ > 0;
}

srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
Expand Down
5 changes: 4 additions & 1 deletion trunk/src/app/srs_app_http_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ class SrsLiveStream : public ISrsHttpHandler
SrsRequest* req;
SrsBufferCache* cache;
SrsSecurity* security_;
bool alive_;
// For multiple viewers, which means there will more than one alive viewers for a live stream, so we must
// use an int value to represent if there is any viewer is alive. We should never do cleanup unless all
// viewers closed the connection.
int alive_viewers_;
public:
SrsLiveStream(SrsRequest* r, SrsBufferCache* c);
virtual ~SrsLiveStream();
Expand Down
19 changes: 11 additions & 8 deletions trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,7 @@ SrsLiveSource::SrsLiveSource()
mix_correct = false;
mix_queue = new SrsMixQueue();

_can_publish = true;
can_publish_ = true;
stream_die_at_ = 0;
publisher_idle_at_ = 0;

Expand Down Expand Up @@ -1952,7 +1952,7 @@ srs_error_t SrsLiveSource::cycle()
bool SrsLiveSource::stream_is_dead()
{
// still publishing?
if (!_can_publish || !publish_edge->can_publish()) {
if (!can_publish_ || !publish_edge->can_publish()) {
return false;
}

Expand Down Expand Up @@ -2151,7 +2151,7 @@ SrsContextId SrsLiveSource::pre_source_id()

bool SrsLiveSource::inactive()
{
return _can_publish;
return can_publish_;
}

void SrsLiveSource::update_auth(SrsRequest* r)
Expand All @@ -2167,7 +2167,7 @@ bool SrsLiveSource::can_publish(bool is_edge)
return publish_edge->can_publish();
}

return _can_publish;
return can_publish_;
}

srs_error_t SrsLiveSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata)
Expand Down Expand Up @@ -2566,7 +2566,7 @@ srs_error_t SrsLiveSource::on_publish()
// update the request object.
srs_assert(req);

_can_publish = false;
can_publish_ = false;

// whatever, the publish thread is the source or edge source,
// save its id to srouce id.
Expand Down Expand Up @@ -2614,7 +2614,7 @@ srs_error_t SrsLiveSource::on_publish()
void SrsLiveSource::on_unpublish()
{
// ignore when already unpublished.
if (_can_publish) {
if (can_publish_) {
return;
}

Expand Down Expand Up @@ -2655,7 +2655,10 @@ void SrsLiveSource::on_unpublish()
stream_die_at_ = srs_get_system_time();
}

_can_publish = true;
// Note that we should never set to unpublish before any other handler is done, especially the handler
// which is actually an http stream that unmounts the HTTP path for streaming, because there maybe some
// coroutine switch in these handlers.
can_publish_ = true;
}

srs_error_t SrsLiveSource::create_consumer(SrsLiveConsumer*& consumer)
Expand Down Expand Up @@ -2735,7 +2738,7 @@ void SrsLiveSource::on_consumer_destroy(SrsLiveConsumer* consumer)
play_edge->on_all_client_stop();

// If no publishers, the stream is die.
if (_can_publish) {
if (can_publish_) {
stream_die_at_ = srs_get_system_time();
}

Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ class SrsLiveSource : public ISrsReloadHandler
SrsRtmpFormat* format_;
private:
// Whether source is avaiable for publishing.
bool _can_publish;
bool can_publish_;
// The last die time, while die means neither publishers nor players.
srs_utime_t stream_die_at_;
// The last idle time, while idle means no players.
Expand Down
Loading