2015-01-04 14:47:12 +00:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
2015-04-29 09:38:23 +00:00
|
|
|
Copyright (c) 2013-2015 SRS(simple-rtmp-server)
|
2015-01-04 14:47:12 +00:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <srs_app_statistic.hpp>
|
|
|
|
|
2015-01-05 05:08:11 +00:00
|
|
|
#include <unistd.h>
|
2015-01-05 04:57:48 +00:00
|
|
|
#include <sstream>
|
|
|
|
using namespace std;
|
|
|
|
|
2015-06-13 08:04:59 +00:00
|
|
|
#include <srs_rtmp_stack.hpp>
|
2015-01-05 04:57:48 +00:00
|
|
|
#include <srs_app_json.hpp>
|
2015-05-23 01:58:00 +00:00
|
|
|
#include <srs_protocol_kbps.hpp>
|
2015-03-08 11:59:10 +00:00
|
|
|
#include <srs_app_conn.hpp>
|
2015-04-02 07:05:09 +00:00
|
|
|
#include <srs_app_config.hpp>
|
|
|
|
#include <srs_kernel_utility.hpp>
|
2015-01-04 14:47:12 +00:00
|
|
|
|
2015-03-21 03:55:28 +00:00
|
|
|
int64_t srs_gvid = getpid();
|
2015-01-05 05:08:11 +00:00
|
|
|
|
2015-03-21 03:55:28 +00:00
|
|
|
int64_t srs_generate_id()
|
2015-01-05 05:08:11 +00:00
|
|
|
{
|
2015-03-21 03:55:28 +00:00
|
|
|
return srs_gvid++;
|
2015-01-05 05:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SrsStatisticVhost::SrsStatisticVhost()
|
|
|
|
{
|
2015-03-21 03:55:28 +00:00
|
|
|
id = srs_generate_id();
|
2015-03-08 11:59:10 +00:00
|
|
|
|
|
|
|
kbps = new SrsKbps();
|
|
|
|
kbps->set_io(NULL, NULL);
|
2015-01-05 05:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SrsStatisticVhost::~SrsStatisticVhost()
|
|
|
|
{
|
2015-03-08 11:59:10 +00:00
|
|
|
srs_freep(kbps);
|
2015-01-05 05:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SrsStatisticStream::SrsStatisticStream()
|
|
|
|
{
|
2015-03-21 03:55:28 +00:00
|
|
|
id = srs_generate_id();
|
2015-01-05 05:08:11 +00:00
|
|
|
vhost = NULL;
|
2015-05-08 08:45:25 +00:00
|
|
|
status = STATISTIC_STREAM_STATUS_IDLING;
|
2015-03-08 07:33:08 +00:00
|
|
|
|
|
|
|
has_video = false;
|
|
|
|
vcodec = SrsCodecVideoReserved;
|
2015-03-08 10:33:35 +00:00
|
|
|
avc_profile = SrsAvcProfileReserved;
|
|
|
|
avc_level = SrsAvcLevelReserved;
|
2015-03-08 07:33:08 +00:00
|
|
|
|
|
|
|
has_audio = false;
|
|
|
|
acodec = SrsCodecAudioReserved1;
|
|
|
|
asample_rate = SrsCodecAudioSampleRateReserved;
|
|
|
|
asound_type = SrsCodecAudioSoundTypeReserved;
|
2015-03-08 09:56:49 +00:00
|
|
|
aac_object = SrsAacObjectTypeReserved;
|
2015-03-08 11:59:10 +00:00
|
|
|
|
|
|
|
kbps = new SrsKbps();
|
|
|
|
kbps->set_io(NULL, NULL);
|
2015-01-05 05:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SrsStatisticStream::~SrsStatisticStream()
|
|
|
|
{
|
2015-03-08 11:59:10 +00:00
|
|
|
srs_freep(kbps);
|
2015-01-05 05:08:11 +00:00
|
|
|
}
|
|
|
|
|
2015-05-08 08:45:25 +00:00
|
|
|
void SrsStatisticStream::publish()
|
|
|
|
{
|
|
|
|
status = STATISTIC_STREAM_STATUS_PUBLISHING;
|
|
|
|
}
|
|
|
|
|
2015-03-08 07:33:08 +00:00
|
|
|
void SrsStatisticStream::close()
|
|
|
|
{
|
|
|
|
has_video = false;
|
|
|
|
has_audio = false;
|
2015-05-08 08:45:25 +00:00
|
|
|
status = STATISTIC_STREAM_STATUS_IDLING;
|
2015-03-08 07:33:08 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 04:40:38 +00:00
|
|
|
SrsStatistic* SrsStatistic::_instance = new SrsStatistic();
|
2015-01-04 14:47:12 +00:00
|
|
|
|
|
|
|
SrsStatistic::SrsStatistic()
|
|
|
|
{
|
2015-03-21 03:55:28 +00:00
|
|
|
_server_id = srs_generate_id();
|
2015-03-08 11:59:10 +00:00
|
|
|
|
|
|
|
kbps = new SrsKbps();
|
|
|
|
kbps->set_io(NULL, NULL);
|
2015-01-04 14:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SrsStatistic::~SrsStatistic()
|
|
|
|
{
|
2015-03-08 11:59:10 +00:00
|
|
|
srs_freep(kbps);
|
|
|
|
|
2015-01-05 04:40:38 +00:00
|
|
|
if (true) {
|
|
|
|
std::map<std::string, SrsStatisticVhost*>::iterator it;
|
|
|
|
for (it = vhosts.begin(); it != vhosts.end(); it++) {
|
|
|
|
SrsStatisticVhost* vhost = it->second;
|
|
|
|
srs_freep(vhost);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (true) {
|
|
|
|
std::map<std::string, SrsStatisticStream*>::iterator it;
|
|
|
|
for (it = streams.begin(); it != streams.end(); it++) {
|
|
|
|
SrsStatisticStream* stream = it->second;
|
|
|
|
srs_freep(stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (true) {
|
|
|
|
std::map<int, SrsStatisticClient*>::iterator it;
|
|
|
|
for (it = clients.begin(); it != clients.end(); it++) {
|
|
|
|
SrsStatisticClient* client = it->second;
|
|
|
|
srs_freep(client);
|
|
|
|
}
|
2015-01-05 04:20:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsStatistic* SrsStatistic::instance()
|
|
|
|
{
|
|
|
|
return _instance;
|
2015-01-04 14:47:12 +00:00
|
|
|
}
|
|
|
|
|
2015-08-11 07:23:46 +00:00
|
|
|
SrsStatisticStream* SrsStatistic::find_stream(int stream_id)
|
|
|
|
{
|
|
|
|
std::map<int, SrsStatisticClient*>::iterator it;
|
|
|
|
for (it = clients.begin(); it != clients.end(); it++) {
|
|
|
|
SrsStatisticClient* client = it->second;
|
|
|
|
SrsStatisticStream* stream = client->stream;
|
|
|
|
|
|
|
|
if (stream_id == stream->id) {
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-03-08 07:33:08 +00:00
|
|
|
int SrsStatistic::on_video_info(SrsRequest* req,
|
2015-03-08 10:33:35 +00:00
|
|
|
SrsCodecVideo vcodec, SrsAvcProfile avc_profile, SrsAvcLevel avc_level
|
2015-03-08 07:33:08 +00:00
|
|
|
) {
|
2015-01-05 04:40:38 +00:00
|
|
|
int ret = ERROR_SUCCESS;
|
2015-01-05 04:57:48 +00:00
|
|
|
|
2015-03-08 07:33:08 +00:00
|
|
|
SrsStatisticVhost* vhost = create_vhost(req);
|
|
|
|
SrsStatisticStream* stream = create_stream(vhost, req);
|
|
|
|
|
|
|
|
stream->has_video = true;
|
|
|
|
stream->vcodec = vcodec;
|
|
|
|
stream->avc_profile = avc_profile;
|
|
|
|
stream->avc_level = avc_level;
|
2015-01-05 04:57:48 +00:00
|
|
|
|
2015-03-08 07:33:08 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SrsStatistic::on_audio_info(SrsRequest* req,
|
|
|
|
SrsCodecAudio acodec, SrsCodecAudioSampleRate asample_rate, SrsCodecAudioSoundType asound_type,
|
2015-03-08 09:56:49 +00:00
|
|
|
SrsAacObjectType aac_object
|
2015-03-08 07:33:08 +00:00
|
|
|
) {
|
|
|
|
int ret = ERROR_SUCCESS;
|
2015-01-05 04:57:48 +00:00
|
|
|
|
2015-03-08 07:33:08 +00:00
|
|
|
SrsStatisticVhost* vhost = create_vhost(req);
|
|
|
|
SrsStatisticStream* stream = create_stream(vhost, req);
|
|
|
|
|
|
|
|
stream->has_audio = true;
|
|
|
|
stream->acodec = acodec;
|
|
|
|
stream->asample_rate = asample_rate;
|
|
|
|
stream->asound_type = asound_type;
|
2015-03-08 09:56:49 +00:00
|
|
|
stream->aac_object = aac_object;
|
2015-03-08 07:33:08 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-05-08 08:45:25 +00:00
|
|
|
void SrsStatistic::on_stream_publish(SrsRequest* req)
|
|
|
|
{
|
|
|
|
SrsStatisticVhost* vhost = create_vhost(req);
|
|
|
|
SrsStatisticStream* stream = create_stream(vhost, req);
|
|
|
|
|
|
|
|
stream->publish();
|
|
|
|
}
|
|
|
|
|
2015-03-08 07:33:08 +00:00
|
|
|
void SrsStatistic::on_stream_close(SrsRequest* req)
|
|
|
|
{
|
|
|
|
SrsStatisticVhost* vhost = create_vhost(req);
|
|
|
|
SrsStatisticStream* stream = create_stream(vhost, req);
|
|
|
|
|
|
|
|
stream->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
int SrsStatistic::on_client(int id, SrsRequest* req)
|
|
|
|
{
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
SrsStatisticVhost* vhost = create_vhost(req);
|
|
|
|
SrsStatisticStream* stream = create_stream(vhost, req);
|
2015-01-06 14:20:31 +00:00
|
|
|
|
|
|
|
// create client if not exists
|
|
|
|
SrsStatisticClient* client = NULL;
|
|
|
|
if (clients.find(id) == clients.end()) {
|
|
|
|
client = new SrsStatisticClient();
|
2015-05-22 03:20:25 +00:00
|
|
|
client->id = id;
|
2015-01-06 14:20:31 +00:00
|
|
|
client->stream = stream;
|
|
|
|
clients[id] = client;
|
|
|
|
} else {
|
|
|
|
client = clients[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-08 07:33:08 +00:00
|
|
|
void SrsStatistic::on_disconnect(int id)
|
2015-01-06 14:20:31 +00:00
|
|
|
{
|
|
|
|
std::map<int, SrsStatisticClient*>::iterator it;
|
|
|
|
it = clients.find(id);
|
|
|
|
if (it != clients.end()) {
|
2015-01-07 15:27:24 +00:00
|
|
|
SrsStatisticClient* client = it->second;
|
|
|
|
srs_freep(client);
|
|
|
|
clients.erase(it);
|
2015-01-06 14:20:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-08 11:59:10 +00:00
|
|
|
void SrsStatistic::kbps_add_delta(SrsConnection* conn)
|
|
|
|
{
|
|
|
|
int id = conn->srs_id();
|
|
|
|
if (clients.find(id) == clients.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsStatisticClient* client = clients[id];
|
|
|
|
|
|
|
|
// resample the kbps to collect the delta.
|
|
|
|
conn->resample();
|
|
|
|
|
|
|
|
// add delta of connection to kbps.
|
|
|
|
// for next sample() of server kbps can get the stat.
|
|
|
|
kbps->add_delta(conn);
|
|
|
|
client->stream->kbps->add_delta(conn);
|
|
|
|
client->stream->vhost->kbps->add_delta(conn);
|
|
|
|
|
|
|
|
// cleanup the delta.
|
|
|
|
conn->cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsKbps* SrsStatistic::kbps_sample()
|
|
|
|
{
|
|
|
|
kbps->sample();
|
|
|
|
if (true) {
|
|
|
|
std::map<std::string, SrsStatisticVhost*>::iterator it;
|
|
|
|
for (it = vhosts.begin(); it != vhosts.end(); it++) {
|
|
|
|
SrsStatisticVhost* vhost = it->second;
|
|
|
|
vhost->kbps->sample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (true) {
|
|
|
|
std::map<std::string, SrsStatisticStream*>::iterator it;
|
|
|
|
for (it = streams.begin(); it != streams.end(); it++) {
|
|
|
|
SrsStatisticStream* stream = it->second;
|
|
|
|
stream->kbps->sample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return kbps;
|
|
|
|
}
|
|
|
|
|
2015-01-05 05:08:11 +00:00
|
|
|
int64_t SrsStatistic::server_id()
|
|
|
|
{
|
|
|
|
return _server_id;
|
|
|
|
}
|
|
|
|
|
2015-01-05 04:57:48 +00:00
|
|
|
int SrsStatistic::dumps_vhosts(stringstream& ss)
|
2015-01-04 14:47:12 +00:00
|
|
|
{
|
2015-01-05 04:40:38 +00:00
|
|
|
int ret = ERROR_SUCCESS;
|
2015-01-05 04:57:48 +00:00
|
|
|
|
2015-03-21 02:25:03 +00:00
|
|
|
ss << SRS_JARRAY_START;
|
2015-01-05 04:57:48 +00:00
|
|
|
std::map<std::string, SrsStatisticVhost*>::iterator it;
|
|
|
|
for (it = vhosts.begin(); it != vhosts.end(); it++) {
|
|
|
|
SrsStatisticVhost* vhost = it->second;
|
2015-01-07 15:27:24 +00:00
|
|
|
if (it != vhosts.begin()) {
|
2015-03-21 02:25:03 +00:00
|
|
|
ss << SRS_JFIELD_CONT;
|
2015-01-06 14:20:31 +00:00
|
|
|
}
|
2015-04-02 07:05:09 +00:00
|
|
|
|
|
|
|
// dumps the config of vhost.
|
|
|
|
bool hls_enabled = _srs_config->get_hls_enabled(vhost->vhost);
|
2015-01-06 14:20:31 +00:00
|
|
|
|
2015-03-21 02:25:03 +00:00
|
|
|
ss << SRS_JOBJECT_START
|
|
|
|
<< SRS_JFIELD_ORG("id", vhost->id) << SRS_JFIELD_CONT
|
|
|
|
<< SRS_JFIELD_STR("name", vhost->vhost) << SRS_JFIELD_CONT
|
|
|
|
<< SRS_JFIELD_ORG("send_bytes", vhost->kbps->get_send_bytes()) << SRS_JFIELD_CONT
|
2015-04-02 07:05:09 +00:00
|
|
|
<< SRS_JFIELD_ORG("recv_bytes", vhost->kbps->get_recv_bytes()) << SRS_JFIELD_CONT
|
|
|
|
<< SRS_JFIELD_NAME("hls") << SRS_JOBJECT_START
|
|
|
|
<< SRS_JFIELD_BOOL("enabled", hls_enabled) << SRS_JFIELD_CONT
|
|
|
|
<< SRS_JFIELD_ORG("fragment", _srs_config->get_hls_fragment(vhost->vhost))
|
|
|
|
<< SRS_JOBJECT_END
|
2015-03-21 02:25:03 +00:00
|
|
|
<< SRS_JOBJECT_END;
|
2015-01-05 04:57:48 +00:00
|
|
|
}
|
2015-03-21 02:25:03 +00:00
|
|
|
ss << SRS_JARRAY_END;
|
2015-01-06 14:20:31 +00:00
|
|
|
|
2015-01-05 04:40:38 +00:00
|
|
|
return ret;
|
2015-01-04 14:47:12 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 04:57:48 +00:00
|
|
|
int SrsStatistic::dumps_streams(stringstream& ss)
|
2015-01-04 14:47:12 +00:00
|
|
|
{
|
2015-01-05 04:40:38 +00:00
|
|
|
int ret = ERROR_SUCCESS;
|
2015-01-05 04:57:48 +00:00
|
|
|
|
2015-03-21 02:25:03 +00:00
|
|
|
ss << SRS_JARRAY_START;
|
2015-01-05 04:57:48 +00:00
|
|
|
std::map<std::string, SrsStatisticStream*>::iterator it;
|
|
|
|
for (it = streams.begin(); it != streams.end(); it++) {
|
|
|
|
SrsStatisticStream* stream = it->second;
|
2015-01-07 15:27:24 +00:00
|
|
|
if (it != streams.begin()) {
|
2015-03-21 02:25:03 +00:00
|
|
|
ss << SRS_JFIELD_CONT;
|
2015-01-06 14:20:31 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 13:58:10 +00:00
|
|
|
int client_num = 0;
|
|
|
|
std::map<int, SrsStatisticClient*>::iterator it_client;
|
|
|
|
for (it_client = clients.begin(); it_client != clients.end(); it_client++) {
|
|
|
|
SrsStatisticClient* client = it_client->second;
|
|
|
|
if (client->stream == stream) {
|
|
|
|
client_num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-21 02:25:03 +00:00
|
|
|
ss << SRS_JOBJECT_START
|
|
|
|
<< SRS_JFIELD_ORG("id", stream->id) << SRS_JFIELD_CONT
|
|
|
|
<< SRS_JFIELD_STR("name", stream->stream) << SRS_JFIELD_CONT
|
|
|
|
<< SRS_JFIELD_ORG("vhost", stream->vhost->id) << SRS_JFIELD_CONT
|
2015-04-02 07:05:09 +00:00
|
|
|
<< SRS_JFIELD_STR("app", stream->app) << SRS_JFIELD_CONT
|
2015-03-21 02:25:03 +00:00
|
|
|
<< SRS_JFIELD_ORG("clients", client_num) << SRS_JFIELD_CONT
|
|
|
|
<< SRS_JFIELD_ORG("send_bytes", stream->kbps->get_send_bytes()) << SRS_JFIELD_CONT
|
2015-04-02 07:05:09 +00:00
|
|
|
<< SRS_JFIELD_ORG("recv_bytes", stream->kbps->get_recv_bytes()) << SRS_JFIELD_CONT
|
2015-05-08 08:45:25 +00:00
|
|
|
<< SRS_JFIELD_ORG("live_ms", srs_get_system_time_ms()) << SRS_JFIELD_CONT
|
|
|
|
<< SRS_JFIELD_STR("status", stream->status) << SRS_JFIELD_CONT;
|
2015-04-02 07:05:09 +00:00
|
|
|
|
2015-03-08 07:33:08 +00:00
|
|
|
if (!stream->has_video) {
|
2015-03-21 02:25:03 +00:00
|
|
|
ss << SRS_JFIELD_NULL("video") << SRS_JFIELD_CONT;
|
2015-03-08 07:33:08 +00:00
|
|
|
} else {
|
2015-03-21 02:25:03 +00:00
|
|
|
ss << SRS_JFIELD_NAME("video")
|
|
|
|
<< SRS_JOBJECT_START
|
|
|
|
<< SRS_JFIELD_STR("codec", srs_codec_video2str(stream->vcodec)) << SRS_JFIELD_CONT
|
|
|
|
<< SRS_JFIELD_STR("profile", srs_codec_avc_profile2str(stream->avc_profile)) << SRS_JFIELD_CONT
|
|
|
|
<< SRS_JFIELD_ORG("level", srs_codec_avc_level2str(stream->avc_level))
|
|
|
|
<< SRS_JOBJECT_END
|
|
|
|
<< SRS_JFIELD_CONT;
|
2015-03-08 07:33:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!stream->has_audio) {
|
2015-03-21 02:25:03 +00:00
|
|
|
ss << SRS_JFIELD_NULL("audio");
|
2015-03-08 07:33:08 +00:00
|
|
|
} else {
|
2015-03-21 02:25:03 +00:00
|
|
|
ss << SRS_JFIELD_NAME("audio")
|
|
|
|
<< SRS_JOBJECT_START
|
|
|
|
<< SRS_JFIELD_STR("codec", srs_codec_audio2str(stream->acodec)) << SRS_JFIELD_CONT
|
|
|
|
<< SRS_JFIELD_ORG("sample_rate", (int)flv_sample_rates[stream->asample_rate]) << SRS_JFIELD_CONT
|
|
|
|
<< SRS_JFIELD_ORG("channel", (int)stream->asound_type + 1) << SRS_JFIELD_CONT
|
|
|
|
<< SRS_JFIELD_STR("profile", srs_codec_aac_object2str(stream->aac_object))
|
|
|
|
<< SRS_JOBJECT_END;
|
2015-03-08 07:33:08 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 02:25:03 +00:00
|
|
|
ss << SRS_JOBJECT_END;
|
2015-01-05 04:57:48 +00:00
|
|
|
}
|
2015-03-21 02:25:03 +00:00
|
|
|
ss << SRS_JARRAY_END;
|
2015-01-05 04:57:48 +00:00
|
|
|
|
2015-01-05 04:40:38 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2015-03-08 07:33:08 +00:00
|
|
|
|
|
|
|
SrsStatisticVhost* SrsStatistic::create_vhost(SrsRequest* req)
|
|
|
|
{
|
|
|
|
SrsStatisticVhost* vhost = NULL;
|
|
|
|
|
|
|
|
// create vhost if not exists.
|
|
|
|
if (vhosts.find(req->vhost) == vhosts.end()) {
|
|
|
|
vhost = new SrsStatisticVhost();
|
|
|
|
vhost->vhost = req->vhost;
|
|
|
|
vhosts[req->vhost] = vhost;
|
|
|
|
return vhost;
|
|
|
|
}
|
|
|
|
|
|
|
|
vhost = vhosts[req->vhost];
|
|
|
|
|
|
|
|
return vhost;
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsStatisticStream* SrsStatistic::create_stream(SrsStatisticVhost* vhost, SrsRequest* req)
|
|
|
|
{
|
|
|
|
std::string url = req->get_stream_url();
|
|
|
|
|
|
|
|
SrsStatisticStream* stream = NULL;
|
|
|
|
|
|
|
|
// create stream if not exists.
|
|
|
|
if (streams.find(url) == streams.end()) {
|
|
|
|
stream = new SrsStatisticStream();
|
|
|
|
stream->vhost = vhost;
|
|
|
|
stream->stream = req->stream;
|
2015-04-02 07:05:09 +00:00
|
|
|
stream->app = req->app;
|
2015-03-08 07:33:08 +00:00
|
|
|
stream->url = url;
|
|
|
|
streams[url] = stream;
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = streams[url];
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|