diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index a0c43492e..a9e775db5 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -525,8 +525,8 @@ int SrsApiVhosts::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) std::stringstream ss; std::set vhost_set; - SrsStreamInfoMap* pool = SrsStatistic::instance()->get_pool(); - SrsStreamInfoMap::iterator it; + std::map* pool = SrsStatistic::instance()->get_pool(); + std::map::iterator it; for (it = pool->begin(); it != pool->end(); it++) { if (it->second->_req == NULL) continue; @@ -572,8 +572,8 @@ int SrsApiStreams::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) if (query_name.size() > 0 || query_vhost.size() > 0) { ss << __SRS_JARRAY_START; bool first = true; - SrsStreamInfoMap* pool = SrsStatistic::instance()->get_pool(); - SrsStreamInfoMap::iterator it; + std::map* pool = SrsStatistic::instance()->get_pool(); + std::map::iterator it; for (it = pool->begin(); it != pool->end(); it++) { SrsRequest* reqinfo = it->second->_req; if (reqinfo == NULL) diff --git a/trunk/src/app/srs_app_statistic.cpp b/trunk/src/app/srs_app_statistic.cpp index fea7a9635..331672adb 100644 --- a/trunk/src/app/srs_app_statistic.cpp +++ b/trunk/src/app/srs_app_statistic.cpp @@ -32,44 +32,54 @@ SrsStreamInfo::SrsStreamInfo() SrsStreamInfo::~SrsStreamInfo() { - if (_req != NULL) - delete _req; + srs_freep(_req); } -SrsStatistic *SrsStatistic::_instance = NULL; +SrsStatistic* SrsStatistic::_instance = NULL; SrsStatistic::SrsStatistic() { - } SrsStatistic::~SrsStatistic() { - SrsStreamInfoMap::iterator it; + std::map::iterator it; for (it = pool.begin(); it != pool.end(); it++) { - delete it->second; + SrsStreamInfo* si = it->second; + srs_freep(si); } } -SrsStreamInfoMap* SrsStatistic::get_pool() +SrsStatistic* SrsStatistic::instance() +{ + if (_instance == NULL) { + _instance = new SrsStatistic(); + } + return _instance; +} + +std::map* SrsStatistic::get_pool() { return &pool; } SrsStreamInfo* SrsStatistic::get(void *p) { - SrsStreamInfoMap::iterator it = pool.find(p); + std::map::iterator it = pool.find(p); if (it == pool.end()) { - pool[p] = new SrsStreamInfo(); - return pool[p]; + SrsStreamInfo* si = new SrsStreamInfo(); + pool[p] = si; + return si; } else { - return it->second; + SrsStreamInfo* si = it->second; + return si; } } void SrsStatistic::add_request_info(void *p, SrsRequest *req) { - SrsStreamInfo *info = get(p); - if (info->_req == NULL) + SrsStreamInfo* info = get(p); + if (info->_req == NULL) { info->_req = req->copy(); + } } \ No newline at end of file diff --git a/trunk/src/app/srs_app_statistic.hpp b/trunk/src/app/srs_app_statistic.hpp index 132b78ff4..41cbbeace 100644 --- a/trunk/src/app/srs_app_statistic.hpp +++ b/trunk/src/app/srs_app_statistic.hpp @@ -39,32 +39,24 @@ class SrsStreamInfo public: SrsStreamInfo(); virtual ~SrsStreamInfo(); - +public: SrsRequest *_req; }; -typedef std::map SrsStreamInfoMap; - class SrsStatistic { public: - static SrsStatistic *instance() - { - if (_instance == NULL) { - _instance = new SrsStatistic(); - } - return _instance; - } - - virtual SrsStreamInfoMap* get_pool(); - + static SrsStatistic* instance(); +public: + virtual std::map* get_pool(); virtual void add_request_info(void *p, SrsRequest *req); - private: SrsStatistic(); virtual ~SrsStatistic(); +private: static SrsStatistic *_instance; - SrsStreamInfoMap pool; + std::map pool; +private: virtual SrsStreamInfo *get(void *p); };