|
|
|
@ -102,7 +102,7 @@ SrsSrtSourceManager::~SrsSrtSourceManager()
|
|
|
|
|
srs_mutex_destroy(lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
srs_error_t SrsSrtSourceManager::fetch_or_create(SrsRequest* r, SrsSrtSource** pps)
|
|
|
|
|
srs_error_t SrsSrtSourceManager::fetch_or_create(SrsRequest* r, SrsSharedPtr<SrsSrtSource>& pps)
|
|
|
|
|
{
|
|
|
|
|
srs_error_t err = srs_success;
|
|
|
|
|
|
|
|
|
@ -110,48 +110,44 @@ srs_error_t SrsSrtSourceManager::fetch_or_create(SrsRequest* r, SrsSrtSource** p
|
|
|
|
|
// @bug https://github.com/ossrs/srs/issues/1230
|
|
|
|
|
SrsLocker(lock);
|
|
|
|
|
|
|
|
|
|
SrsSrtSource* source = NULL;
|
|
|
|
|
if ((source = fetch(r)) != NULL) {
|
|
|
|
|
string stream_url = r->get_stream_url();
|
|
|
|
|
std::map< std::string, SrsSharedPtr<SrsSrtSource> >::iterator it = pool.find(stream_url);
|
|
|
|
|
if (it != pool.end()) {
|
|
|
|
|
SrsSharedPtr<SrsSrtSource> source = it->second;
|
|
|
|
|
|
|
|
|
|
// we always update the request of resource,
|
|
|
|
|
// 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);
|
|
|
|
|
*pps = source;
|
|
|
|
|
pps = source;
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string stream_url = r->get_stream_url();
|
|
|
|
|
string vhost = r->vhost;
|
|
|
|
|
|
|
|
|
|
// should always not exists for create a source.
|
|
|
|
|
srs_assert (pool.find(stream_url) == pool.end());
|
|
|
|
|
|
|
|
|
|
SrsSharedPtr<SrsSrtSource> source(new SrsSrtSource());
|
|
|
|
|
srs_trace("new srt source, stream_url=%s", stream_url.c_str());
|
|
|
|
|
|
|
|
|
|
source = new SrsSrtSource();
|
|
|
|
|
if ((err = source->initialize(r)) != srs_success) {
|
|
|
|
|
return srs_error_wrap(err, "init source %s", r->get_stream_url().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pool[stream_url] = source;
|
|
|
|
|
|
|
|
|
|
*pps = source;
|
|
|
|
|
pps = source;
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsSrtSource* SrsSrtSourceManager::fetch(SrsRequest* r)
|
|
|
|
|
void SrsSrtSourceManager::eliminate(SrsRequest* r)
|
|
|
|
|
{
|
|
|
|
|
SrsSrtSource* source = NULL;
|
|
|
|
|
// Use lock to protect coroutine switch.
|
|
|
|
|
// @bug https://github.com/ossrs/srs/issues/1230
|
|
|
|
|
SrsLocker(lock);
|
|
|
|
|
|
|
|
|
|
string stream_url = r->get_stream_url();
|
|
|
|
|
if (pool.find(stream_url) == pool.end()) {
|
|
|
|
|
return NULL;
|
|
|
|
|
std::map< std::string, SrsSharedPtr<SrsSrtSource> >::iterator it = pool.find(stream_url);
|
|
|
|
|
if (it != pool.end()) {
|
|
|
|
|
pool.erase(it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source = pool[stream_url];
|
|
|
|
|
|
|
|
|
|
return source;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsSrtSourceManager* _srs_srt_sources = NULL;
|
|
|
|
@ -973,6 +969,11 @@ void SrsSrtSource::on_consumer_destroy(SrsSrtConsumer* consumer)
|
|
|
|
|
if (it != consumers.end()) {
|
|
|
|
|
it = consumers.erase(it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Destroy and cleanup source when no publishers and consumers.
|
|
|
|
|
if (can_publish_ && consumers.empty()) {
|
|
|
|
|
_srs_srt_sources->eliminate(req);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SrsSrtSource::can_publish()
|
|
|
|
@ -1026,6 +1027,11 @@ void SrsSrtSource::on_unpublish()
|
|
|
|
|
bridge_->on_unpublish();
|
|
|
|
|
srs_freep(bridge_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Destroy and cleanup source when no publishers and consumers.
|
|
|
|
|
if (can_publish_ && consumers.empty()) {
|
|
|
|
|
_srs_srt_sources->eliminate(req);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
srs_error_t SrsSrtSource::on_packet(SrsSrtPacket* packet)
|
|
|
|
|