Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2015-01-05 13:08:11 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f1efdcd00005a5fe10c3cc05b6853cddbaa1e321
f1efdcd0
1 parent
ae63af6a
refine code, use global virtual id to generate the id of vhost and stream.
隐藏空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
57 行增加
和
2 行删除
trunk/src/app/srs_app_http_api.cpp
trunk/src/app/srs_app_statistic.cpp
trunk/src/app/srs_app_statistic.hpp
trunk/src/app/srs_app_http_api.cpp
查看文件 @
f1efdcd
...
...
@@ -529,6 +529,7 @@ int SrsApiVhosts::do_process_request(SrsStSocket* skt, SrsHttpMessage* req)
ss
<<
__SRS_JOBJECT_START
<<
__SRS_JFIELD_ERROR
(
ret
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_ORG
(
"server"
,
stat
->
server_id
())
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_ORG
(
"vhosts"
,
__SRS_JARRAY_START
)
<<
data
.
str
()
<<
__SRS_JARRAY_END
...
...
@@ -560,6 +561,7 @@ int SrsApiStreams::do_process_request(SrsStSocket* skt, SrsHttpMessage* req)
ss
<<
__SRS_JOBJECT_START
<<
__SRS_JFIELD_ERROR
(
ret
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_ORG
(
"server"
,
stat
->
server_id
())
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_ORG
(
"streams"
,
__SRS_JARRAY_START
)
<<
data
.
str
()
<<
__SRS_JARRAY_END
...
...
trunk/src/app/srs_app_statistic.cpp
查看文件 @
f1efdcd
...
...
@@ -23,16 +23,44 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_app_statistic.hpp>
#include <unistd.h>
#include <sstream>
using
namespace
std
;
#include <srs_protocol_rtmp.hpp>
#include <srs_app_json.hpp>
int64_t
__srs_gvid
=
getpid
();
int64_t
__srs_generate_id
()
{
return
__srs_gvid
++
;
}
SrsStatisticVhost
::
SrsStatisticVhost
()
{
id
=
__srs_generate_id
();
}
SrsStatisticVhost
::~
SrsStatisticVhost
()
{
}
SrsStatisticStream
::
SrsStatisticStream
()
{
id
=
__srs_generate_id
();
vhost
=
NULL
;
}
SrsStatisticStream
::~
SrsStatisticStream
()
{
}
SrsStatistic
*
SrsStatistic
::
_instance
=
new
SrsStatistic
();
SrsStatistic
::
SrsStatistic
()
{
_server_id
=
__srs_generate_id
();
}
SrsStatistic
::~
SrsStatistic
()
...
...
@@ -87,7 +115,8 @@ int SrsStatistic::on_client(int id, SrsRequest* req)
if
(
streams
.
find
(
url
)
==
streams
.
end
())
{
stream
=
new
SrsStatisticStream
();
stream
->
vhost
=
vhost
;
stream
->
stream
=
url
;
stream
->
stream
=
req
->
stream
;
stream
->
url
=
url
;
streams
[
url
]
=
stream
;
}
else
{
stream
=
streams
[
url
];
...
...
@@ -96,6 +125,11 @@ int SrsStatistic::on_client(int id, SrsRequest* req)
return
ret
;
}
int64_t
SrsStatistic
::
server_id
()
{
return
_server_id
;
}
int
SrsStatistic
::
dumps_vhosts
(
stringstream
&
ss
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -104,6 +138,7 @@ int SrsStatistic::dumps_vhosts(stringstream& ss)
for
(
it
=
vhosts
.
begin
();
it
!=
vhosts
.
end
();
it
++
)
{
SrsStatisticVhost
*
vhost
=
it
->
second
;
ss
<<
__SRS_JOBJECT_START
<<
__SRS_JFIELD_ORG
(
"id"
,
vhost
->
id
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_STR
(
"name"
,
vhost
->
vhost
)
<<
__SRS_JOBJECT_END
;
}
...
...
@@ -119,7 +154,9 @@ int SrsStatistic::dumps_streams(stringstream& ss)
for
(
it
=
streams
.
begin
();
it
!=
streams
.
end
();
it
++
)
{
SrsStatisticStream
*
stream
=
it
->
second
;
ss
<<
__SRS_JOBJECT_START
<<
__SRS_JFIELD_STR
(
"url"
,
stream
->
stream
)
<<
__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_JOBJECT_END
;
}
...
...
trunk/src/app/srs_app_statistic.hpp
查看文件 @
f1efdcd
...
...
@@ -38,15 +38,24 @@ class SrsRequest;
struct
SrsStatisticVhost
{
public
:
int64_t
id
;
std
::
string
vhost
;
public
:
SrsStatisticVhost
();
virtual
~
SrsStatisticVhost
();
};
struct
SrsStatisticStream
{
public
:
int64_t
id
;
SrsStatisticVhost
*
vhost
;
std
::
string
app
;
std
::
string
stream
;
std
::
string
url
;
public
:
SrsStatisticStream
();
virtual
~
SrsStatisticStream
();
};
struct
SrsStatisticClient
...
...
@@ -60,6 +69,8 @@ class SrsStatistic
{
private
:
static
SrsStatistic
*
_instance
;
// the id to identify the sever.
int64_t
_server_id
;
// key: vhost name, value: vhost object.
std
::
map
<
std
::
string
,
SrsStatisticVhost
*>
vhosts
;
// key: stream name, value: stream object.
...
...
@@ -80,6 +91,11 @@ public:
virtual
int
on_client
(
int
id
,
SrsRequest
*
req
);
public
:
/**
* get the server id, used to identify the server.
* for example, when restart, the server id must changed.
*/
virtual
int64_t
server_id
();
/**
* dumps the vhosts to sstream in json.
*/
virtual
int
dumps_vhosts
(
std
::
stringstream
&
ss
);
...
...
请
注册
或
登录
后发表评论