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 12:40:38 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cc796a433a7c6bfb5a00a1a28c13fac1848283a6
cc796a43
1 parent
40ed2249
refine the statistic arch.
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
90 行增加
和
105 行删除
trunk/src/app/srs_app_http_api.cpp
trunk/src/app/srs_app_rtmp_conn.cpp
trunk/src/app/srs_app_statistic.cpp
trunk/src/app/srs_app_statistic.hpp
trunk/src/app/srs_app_http_api.cpp
查看文件 @
cc796a4
...
...
@@ -26,7 +26,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifdef SRS_AUTO_HTTP_API
#include <sstream>
#include <set>
using
namespace
std
;
#include <srs_kernel_log.hpp>
...
...
@@ -522,30 +521,14 @@ bool SrsApiVhosts::can_handle(const char* path, int length, const char** /*pchil
int
SrsApiVhosts
::
do_process_request
(
SrsStSocket
*
skt
,
SrsHttpMessage
*
req
)
{
int
ret
=
ERROR_SUCCESS
;
std
::
stringstream
ss
;
std
::
set
<
std
::
string
>
vhost_set
;
std
::
map
<
void
*
,
SrsStreamInfo
*>*
pool
=
SrsStatistic
::
instance
()
->
get_pool
();
std
::
map
<
void
*
,
SrsStreamInfo
*>::
iterator
it
;
for
(
it
=
pool
->
begin
();
it
!=
pool
->
end
();
it
++
)
{
if
(
it
->
second
->
_req
==
NULL
)
continue
;
vhost_set
.
insert
(
it
->
second
->
_req
->
vhost
);
}
ss
<<
__SRS_JARRAY_START
;
bool
first
=
true
;
std
::
set
<
std
::
string
>::
iterator
it_set
;
for
(
it_set
=
vhost_set
.
begin
();
it_set
!=
vhost_set
.
end
();
it_set
++
)
{
if
(
first
)
{
first
=
false
;
}
else
{
ss
<<
__SRS_JFIELD_CONT
;
}
ss
<<
"
\"
"
<<
(
*
it_set
)
<<
"
\"
"
;
SrsStatistic
*
stat
=
SrsStatistic
::
instance
();
if
((
ret
=
stat
->
dumps_vhosts
(
ss
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
ss
<<
__SRS_JARRAY_END
;
return
res_json
(
skt
,
req
,
ss
.
str
());
}
...
...
@@ -565,40 +548,13 @@ bool SrsApiStreams::can_handle(const char* path, int length, const char** /*pchi
int
SrsApiStreams
::
do_process_request
(
SrsStSocket
*
skt
,
SrsHttpMessage
*
req
)
{
int
ret
=
ERROR_SUCCESS
;
std
::
stringstream
ss
;
std
::
string
query_name
=
req
->
query_get
(
"name"
);
std
::
string
query_vhost
=
req
->
query_get
(
"vhost"
);
if
(
query_name
.
size
()
>
0
||
query_vhost
.
size
()
>
0
)
{
ss
<<
__SRS_JARRAY_START
;
bool
first
=
true
;
std
::
map
<
void
*
,
SrsStreamInfo
*>*
pool
=
SrsStatistic
::
instance
()
->
get_pool
();
std
::
map
<
void
*
,
SrsStreamInfo
*>::
iterator
it
;
for
(
it
=
pool
->
begin
();
it
!=
pool
->
end
();
it
++
)
{
SrsRequest
*
reqinfo
=
it
->
second
->
_req
;
if
(
reqinfo
==
NULL
)
continue
;
if
(
reqinfo
->
stream
==
query_name
||
reqinfo
->
vhost
==
query_vhost
)
{
if
(
first
)
{
first
=
false
;
}
else
{
ss
<<
__SRS_JFIELD_CONT
;
}
ss
<<
__SRS_JOBJECT_START
<<
__SRS_JFIELD_STR
(
"name"
,
reqinfo
->
stream
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_STR
(
"url"
,
reqinfo
->
tcUrl
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_ORG
(
"clients"
,
0
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_STR
(
"status"
,
"idle"
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_STR
(
"type"
,
""
)
<<
__SRS_JFIELD_CONT
<<
__SRS_JFIELD_STR
(
"codec"
,
""
)
<<
__SRS_JOBJECT_END
;
}
}
ss
<<
__SRS_JARRAY_END
;
}
else
{
return
res_error
(
skt
,
req
,
400
,
"Bad Request"
,
"unknown query"
);
SrsStatistic
*
stat
=
SrsStatistic
::
instance
();
if
((
ret
=
stat
->
dumps_streams
(
ss
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
return
res_json
(
skt
,
req
,
ss
.
str
());
...
...
trunk/src/app/srs_app_rtmp_conn.cpp
查看文件 @
cc796a4
...
...
@@ -396,7 +396,12 @@ int SrsRtmpConn::stream_service_cycle()
}
srs_assert
(
source
!=
NULL
);
SrsStatistic
::
instance
()
->
add_request_info
(
source
,
req
);
// update the statistic when source disconveried.
SrsStatistic
*
stat
=
SrsStatistic
::
instance
();
if
((
ret
=
stat
->
on_client
(
_srs_context
->
get_id
(),
req
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"stat client failed. ret=%d"
,
ret
);
return
ret
;
}
// check ASAP, to fail it faster if invalid.
if
(
type
!=
SrsRtmpConnPlay
&&
!
vhost_is_edge
)
{
...
...
trunk/src/app/srs_app_statistic.cpp
查看文件 @
cc796a4
...
...
@@ -25,17 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_protocol_rtmp.hpp>
SrsStreamInfo
::
SrsStreamInfo
()
{
_req
=
NULL
;
}
SrsStreamInfo
::~
SrsStreamInfo
()
{
srs_freep
(
_req
);
}
SrsStatistic
*
SrsStatistic
::
_instance
=
NULL
;
SrsStatistic
*
SrsStatistic
::
_instance
=
new
SrsStatistic
();
SrsStatistic
::
SrsStatistic
()
{
...
...
@@ -43,43 +33,48 @@ SrsStatistic::SrsStatistic()
SrsStatistic
::~
SrsStatistic
()
{
std
::
map
<
void
*
,
SrsStreamInfo
*>::
iterator
it
;
for
(
it
=
pool
.
begin
();
it
!=
pool
.
end
();
it
++
)
{
SrsStreamInfo
*
si
=
it
->
second
;
srs_freep
(
si
);
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
);
}
}
}
SrsStatistic
*
SrsStatistic
::
instance
()
{
if
(
_instance
==
NULL
)
{
_instance
=
new
SrsStatistic
();
}
return
_instance
;
}
std
::
map
<
void
*
,
SrsStreamInfo
*>*
SrsStatistic
::
get_pool
(
)
int
SrsStatistic
::
on_client
(
int
id
,
SrsRequest
*
req
)
{
return
&
pool
;
int
ret
=
ERROR_SUCCESS
;
return
ret
;
}
SrsStreamInfo
*
SrsStatistic
::
get
(
void
*
p
)
int
SrsStatistic
::
dumps_vhosts
(
std
::
stringstream
&
ss
)
{
std
::
map
<
void
*
,
SrsStreamInfo
*>::
iterator
it
=
pool
.
find
(
p
);
if
(
it
==
pool
.
end
())
{
SrsStreamInfo
*
si
=
new
SrsStreamInfo
();
pool
[
p
]
=
si
;
return
si
;
}
else
{
SrsStreamInfo
*
si
=
it
->
second
;
return
si
;
}
int
ret
=
ERROR_SUCCESS
;
return
ret
;
}
void
SrsStatistic
::
add_request_info
(
void
*
p
,
SrsRequest
*
req
)
int
SrsStatistic
::
dumps_streams
(
std
::
stringstream
&
ss
)
{
SrsStreamInfo
*
info
=
get
(
p
);
if
(
info
->
_req
==
NULL
)
{
info
->
_req
=
req
->
copy
();
}
}
\ No newline at end of file
int
ret
=
ERROR_SUCCESS
;
return
ret
;
}
...
...
trunk/src/app/srs_app_statistic.hpp
查看文件 @
cc796a4
...
...
@@ -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
();
public
:
SrsRequest
*
_req
;
std
::
string
vhost
;
};
class
SrsStatistic
struct
SrsStatisticStream
{
public
:
static
SrsStatistic
*
instance
();
SrsStatisticVhost
*
vhost
;
std
::
string
app
;
std
::
string
stream
;
};
struct
SrsStatisticClient
{
public
:
virtual
std
::
map
<
void
*
,
SrsStreamInfo
*>*
get_pool
();
virtual
void
add_request_info
(
void
*
p
,
SrsRequest
*
req
);
private
:
SrsStatistic
();
virtual
~
SrsStatistic
();
SrsStatisticStream
*
stream
;
int
id
;
};
class
SrsStatistic
{
private
:
static
SrsStatistic
*
_instance
;
std
::
map
<
void
*
,
SrsStreamInfo
*>
pool
;
// 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
:
virtual
SrsStreamInfo
*
get
(
void
*
p
);
SrsStatistic
();
virtual
~
SrsStatistic
();
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
...
...
请
注册
或
登录
后发表评论