正在显示
3 个修改的文件
包含
34 行增加
和
32 行删除
| @@ -525,8 +525,8 @@ int SrsApiVhosts::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) | @@ -525,8 +525,8 @@ int SrsApiVhosts::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) | ||
| 525 | std::stringstream ss; | 525 | std::stringstream ss; |
| 526 | 526 | ||
| 527 | std::set<std::string> vhost_set; | 527 | std::set<std::string> vhost_set; |
| 528 | - SrsStreamInfoMap* pool = SrsStatistic::instance()->get_pool(); | ||
| 529 | - SrsStreamInfoMap::iterator it; | 528 | + std::map<void*, SrsStreamInfo*>* pool = SrsStatistic::instance()->get_pool(); |
| 529 | + std::map<void*, SrsStreamInfo*>::iterator it; | ||
| 530 | for (it = pool->begin(); it != pool->end(); it++) { | 530 | for (it = pool->begin(); it != pool->end(); it++) { |
| 531 | if (it->second->_req == NULL) | 531 | if (it->second->_req == NULL) |
| 532 | continue; | 532 | continue; |
| @@ -572,8 +572,8 @@ int SrsApiStreams::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) | @@ -572,8 +572,8 @@ int SrsApiStreams::do_process_request(SrsStSocket* skt, SrsHttpMessage* req) | ||
| 572 | if (query_name.size() > 0 || query_vhost.size() > 0) { | 572 | if (query_name.size() > 0 || query_vhost.size() > 0) { |
| 573 | ss << __SRS_JARRAY_START; | 573 | ss << __SRS_JARRAY_START; |
| 574 | bool first = true; | 574 | bool first = true; |
| 575 | - SrsStreamInfoMap* pool = SrsStatistic::instance()->get_pool(); | ||
| 576 | - SrsStreamInfoMap::iterator it; | 575 | + std::map<void*, SrsStreamInfo*>* pool = SrsStatistic::instance()->get_pool(); |
| 576 | + std::map<void*, SrsStreamInfo*>::iterator it; | ||
| 577 | for (it = pool->begin(); it != pool->end(); it++) { | 577 | for (it = pool->begin(); it != pool->end(); it++) { |
| 578 | SrsRequest* reqinfo = it->second->_req; | 578 | SrsRequest* reqinfo = it->second->_req; |
| 579 | if (reqinfo == NULL) | 579 | if (reqinfo == NULL) |
| @@ -32,44 +32,54 @@ SrsStreamInfo::SrsStreamInfo() | @@ -32,44 +32,54 @@ SrsStreamInfo::SrsStreamInfo() | ||
| 32 | 32 | ||
| 33 | SrsStreamInfo::~SrsStreamInfo() | 33 | SrsStreamInfo::~SrsStreamInfo() |
| 34 | { | 34 | { |
| 35 | - if (_req != NULL) | ||
| 36 | - delete _req; | 35 | + srs_freep(_req); |
| 37 | } | 36 | } |
| 38 | 37 | ||
| 39 | -SrsStatistic *SrsStatistic::_instance = NULL; | 38 | +SrsStatistic* SrsStatistic::_instance = NULL; |
| 40 | 39 | ||
| 41 | SrsStatistic::SrsStatistic() | 40 | SrsStatistic::SrsStatistic() |
| 42 | { | 41 | { |
| 43 | - | ||
| 44 | } | 42 | } |
| 45 | 43 | ||
| 46 | SrsStatistic::~SrsStatistic() | 44 | SrsStatistic::~SrsStatistic() |
| 47 | { | 45 | { |
| 48 | - SrsStreamInfoMap::iterator it; | 46 | + std::map<void*, SrsStreamInfo*>::iterator it; |
| 49 | for (it = pool.begin(); it != pool.end(); it++) { | 47 | for (it = pool.begin(); it != pool.end(); it++) { |
| 50 | - delete it->second; | 48 | + SrsStreamInfo* si = it->second; |
| 49 | + srs_freep(si); | ||
| 50 | + } | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +SrsStatistic* SrsStatistic::instance() | ||
| 54 | +{ | ||
| 55 | + if (_instance == NULL) { | ||
| 56 | + _instance = new SrsStatistic(); | ||
| 51 | } | 57 | } |
| 58 | + return _instance; | ||
| 52 | } | 59 | } |
| 53 | 60 | ||
| 54 | -SrsStreamInfoMap* SrsStatistic::get_pool() | 61 | +std::map<void*, SrsStreamInfo*>* SrsStatistic::get_pool() |
| 55 | { | 62 | { |
| 56 | return &pool; | 63 | return &pool; |
| 57 | } | 64 | } |
| 58 | 65 | ||
| 59 | SrsStreamInfo* SrsStatistic::get(void *p) | 66 | SrsStreamInfo* SrsStatistic::get(void *p) |
| 60 | { | 67 | { |
| 61 | - SrsStreamInfoMap::iterator it = pool.find(p); | 68 | + std::map<void*, SrsStreamInfo*>::iterator it = pool.find(p); |
| 62 | if (it == pool.end()) { | 69 | if (it == pool.end()) { |
| 63 | - pool[p] = new SrsStreamInfo(); | ||
| 64 | - return pool[p]; | 70 | + SrsStreamInfo* si = new SrsStreamInfo(); |
| 71 | + pool[p] = si; | ||
| 72 | + return si; | ||
| 65 | } else { | 73 | } else { |
| 66 | - return it->second; | 74 | + SrsStreamInfo* si = it->second; |
| 75 | + return si; | ||
| 67 | } | 76 | } |
| 68 | } | 77 | } |
| 69 | 78 | ||
| 70 | void SrsStatistic::add_request_info(void *p, SrsRequest *req) | 79 | void SrsStatistic::add_request_info(void *p, SrsRequest *req) |
| 71 | { | 80 | { |
| 72 | - SrsStreamInfo *info = get(p); | ||
| 73 | - if (info->_req == NULL) | 81 | + SrsStreamInfo* info = get(p); |
| 82 | + if (info->_req == NULL) { | ||
| 74 | info->_req = req->copy(); | 83 | info->_req = req->copy(); |
| 84 | + } | ||
| 75 | } | 85 | } |
| @@ -39,32 +39,24 @@ class SrsStreamInfo | @@ -39,32 +39,24 @@ class SrsStreamInfo | ||
| 39 | public: | 39 | public: |
| 40 | SrsStreamInfo(); | 40 | SrsStreamInfo(); |
| 41 | virtual ~SrsStreamInfo(); | 41 | virtual ~SrsStreamInfo(); |
| 42 | - | 42 | +public: |
| 43 | SrsRequest *_req; | 43 | SrsRequest *_req; |
| 44 | }; | 44 | }; |
| 45 | 45 | ||
| 46 | -typedef std::map<void*, SrsStreamInfo*> SrsStreamInfoMap; | ||
| 47 | - | ||
| 48 | class SrsStatistic | 46 | class SrsStatistic |
| 49 | { | 47 | { |
| 50 | public: | 48 | public: |
| 51 | - static SrsStatistic *instance() | ||
| 52 | - { | ||
| 53 | - if (_instance == NULL) { | ||
| 54 | - _instance = new SrsStatistic(); | ||
| 55 | - } | ||
| 56 | - return _instance; | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - virtual SrsStreamInfoMap* get_pool(); | ||
| 60 | - | 49 | + static SrsStatistic* instance(); |
| 50 | +public: | ||
| 51 | + virtual std::map<void*, SrsStreamInfo*>* get_pool(); | ||
| 61 | virtual void add_request_info(void *p, SrsRequest *req); | 52 | virtual void add_request_info(void *p, SrsRequest *req); |
| 62 | - | ||
| 63 | private: | 53 | private: |
| 64 | SrsStatistic(); | 54 | SrsStatistic(); |
| 65 | virtual ~SrsStatistic(); | 55 | virtual ~SrsStatistic(); |
| 56 | +private: | ||
| 66 | static SrsStatistic *_instance; | 57 | static SrsStatistic *_instance; |
| 67 | - SrsStreamInfoMap pool; | 58 | + std::map<void*, SrsStreamInfo*> pool; |
| 59 | +private: | ||
| 68 | virtual SrsStreamInfo *get(void *p); | 60 | virtual SrsStreamInfo *get(void *p); |
| 69 | }; | 61 | }; |
| 70 | 62 |
-
请 注册 或 登录 后发表评论