mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix #713, refine source to avoid critical fetch and create. 2.0.222
This commit is contained in:
parent
ec4d1b3b4f
commit
cb1d47bfef
5 changed files with 19 additions and 32 deletions
|
@ -344,6 +344,7 @@ Remark:
|
||||||
|
|
||||||
## History
|
## History
|
||||||
|
|
||||||
|
* v2.0, 2016-12-13, fix #713, refine source to avoid critical fetch and create. 2.0.222
|
||||||
* <strong>v2.0, 2016-11-09, [2.0 beta2(2.0.221)][r2.0b2] released. 86691 lines.</strong>
|
* <strong>v2.0, 2016-11-09, [2.0 beta2(2.0.221)][r2.0b2] released. 86691 lines.</strong>
|
||||||
* v2.0, 2016-11-05, fix #654, crash when source cleanup for edge. 2.0.221
|
* v2.0, 2016-11-05, fix #654, crash when source cleanup for edge. 2.0.221
|
||||||
* v2.0, 2016-10-26, fix #666, crash when source cleanup for http-flv. 2.0.220
|
* v2.0, 2016-10-26, fix #666, crash when source cleanup for http-flv. 2.0.220
|
||||||
|
|
|
@ -1228,12 +1228,10 @@ int SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSource* s = SrsSource::fetch(r);
|
SrsSource* s = NULL;
|
||||||
if (!s) {
|
if ((ret = SrsSource::fetch_or_create(r, server, server, &s)) != ERROR_SUCCESS) {
|
||||||
if ((ret = SrsSource::create(r, server, server, &s)) != ERROR_SUCCESS) {
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
srs_assert(s != NULL);
|
srs_assert(s != NULL);
|
||||||
|
|
||||||
// create http streaming handler.
|
// create http streaming handler.
|
||||||
|
|
|
@ -486,12 +486,10 @@ int SrsRtmpConn::stream_service_cycle()
|
||||||
rtmp->set_send_timeout(SRS_CONSTS_RTMP_SEND_TIMEOUT_US);
|
rtmp->set_send_timeout(SRS_CONSTS_RTMP_SEND_TIMEOUT_US);
|
||||||
|
|
||||||
// find a source to serve.
|
// find a source to serve.
|
||||||
SrsSource* source = SrsSource::fetch(req);
|
SrsSource* source = NULL;
|
||||||
if (!source) {
|
if ((ret = SrsSource::fetch_or_create(req, server, server, &source)) != ERROR_SUCCESS) {
|
||||||
if ((ret = SrsSource::create(req, server, server, &source)) != ERROR_SUCCESS) {
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
srs_assert(source != NULL);
|
srs_assert(source != NULL);
|
||||||
|
|
||||||
// update the statistic when source disconveried.
|
// update the statistic when source disconveried.
|
||||||
|
|
|
@ -731,17 +731,23 @@ ISrsSourceHandler::~ISrsSourceHandler()
|
||||||
|
|
||||||
std::map<std::string, SrsSource*> SrsSource::pool;
|
std::map<std::string, SrsSource*> SrsSource::pool;
|
||||||
|
|
||||||
int SrsSource::create(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* hh, SrsSource** pps)
|
int SrsSource::fetch_or_create(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* hh, SrsSource** pps)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
SrsSource* source = NULL;
|
||||||
|
if ((source = fetch(r)) != NULL) {
|
||||||
|
*pps = source;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
string stream_url = r->get_stream_url();
|
string stream_url = r->get_stream_url();
|
||||||
string vhost = r->vhost;
|
string vhost = r->vhost;
|
||||||
|
|
||||||
// should always not exists for create a source.
|
// should always not exists for create a source.
|
||||||
srs_assert (pool.find(stream_url) == pool.end());
|
srs_assert (pool.find(stream_url) == pool.end());
|
||||||
|
|
||||||
SrsSource* source = new SrsSource();
|
source = new SrsSource();
|
||||||
if ((ret = source->initialize(r, h, hh)) != ERROR_SUCCESS) {
|
if ((ret = source->initialize(r, h, hh)) != ERROR_SUCCESS) {
|
||||||
srs_freep(source);
|
srs_freep(source);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -774,20 +780,6 @@ SrsSource* SrsSource::fetch(SrsRequest* r)
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSource* SrsSource::fetch(std::string vhost, std::string app, std::string stream)
|
|
||||||
{
|
|
||||||
SrsSource* source = NULL;
|
|
||||||
string stream_url = srs_generate_stream_url(vhost, app, stream);
|
|
||||||
|
|
||||||
if (pool.find(stream_url) == pool.end()) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
source = pool[stream_url];
|
|
||||||
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SrsSource::dispose_all()
|
void SrsSource::dispose_all()
|
||||||
{
|
{
|
||||||
std::map<std::string, SrsSource*>::iterator it;
|
std::map<std::string, SrsSource*>::iterator it;
|
||||||
|
|
|
@ -418,22 +418,20 @@ private:
|
||||||
static std::map<std::string, SrsSource*> pool;
|
static std::map<std::string, SrsSource*> pool;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* find stream by vhost/app/stream.
|
* create source when fetch from cache failed.
|
||||||
* @param r the client request.
|
* @param r the client request.
|
||||||
* @param h the event handler for source.
|
* @param h the event handler for source.
|
||||||
* @param hh the event handler for hls.
|
* @param hh the event handler for hls.
|
||||||
* @param pps the matched source, if success never be NULL.
|
* @param pps the matched source, if success never be NULL.
|
||||||
*/
|
*/
|
||||||
static int create(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* hh, SrsSource** pps);
|
static int fetch_or_create(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* hh, SrsSource** pps);
|
||||||
|
private:
|
||||||
/**
|
/**
|
||||||
* get the exists source, NULL when not exists.
|
* get the exists source, NULL when not exists.
|
||||||
* update the request and return the exists source.
|
* update the request and return the exists source.
|
||||||
*/
|
*/
|
||||||
static SrsSource* fetch(SrsRequest* r);
|
static SrsSource* fetch(SrsRequest* r);
|
||||||
/**
|
public:
|
||||||
* get the exists source by stream info(vhost, app, stream), NULL when not exists.
|
|
||||||
*/
|
|
||||||
static SrsSource* fetch(std::string vhost, std::string app, std::string stream);
|
|
||||||
/**
|
/**
|
||||||
* dispose and cycle all sources.
|
* dispose and cycle all sources.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue