1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

refine the statistic arch.

This commit is contained in:
winlin 2015-01-05 12:40:38 +08:00
parent 40ed2249e8
commit cc796a433a
4 changed files with 90 additions and 105 deletions

View file

@ -31,33 +31,62 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core.hpp>
#include <map>
#include <string>
class SrsRequest;
class SrsStreamInfo
struct SrsStatisticVhost
{
public:
SrsStreamInfo();
virtual ~SrsStreamInfo();
std::string vhost;
};
struct SrsStatisticStream
{
public:
SrsRequest *_req;
SrsStatisticVhost* vhost;
std::string app;
std::string stream;
};
struct SrsStatisticClient
{
public:
SrsStatisticStream* stream;
int id;
};
class SrsStatistic
{
public:
static SrsStatistic* instance();
public:
virtual std::map<void*, SrsStreamInfo*>* get_pool();
virtual void add_request_info(void *p, SrsRequest *req);
private:
static SrsStatistic *_instance;
// key: vhost name, value: vhost object.
std::map<std::string, SrsStatisticVhost*> vhosts;
// key: stream name, value: stream object.
std::map<std::string, SrsStatisticStream*> streams;
// key: client id, value: stream object.
std::map<int, SrsStatisticClient*> clients;
private:
SrsStatistic();
virtual ~SrsStatistic();
private:
static SrsStatistic *_instance;
std::map<void*, SrsStreamInfo*> pool;
private:
virtual SrsStreamInfo *get(void *p);
public:
static SrsStatistic* instance();
public:
/**
* when got a client to publish/play stream,
* @param id, the client srs id.
* @param req, the client request object.
*/
virtual int on_client(int id, SrsRequest *req);
public:
/**
* dumps the vhosts to sstream in json.
*/
virtual int dumps_vhosts(std::stringstream& ss);
/**
* dumps the streams to sstream in json.
*/
virtual int dumps_streams(std::stringstream& ss);
};
#endif