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
2014-07-13 10:59:26 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
539b595604a0588ec547565d654d5d6ecde54c2e
539b5956
1 parent
e2205966
refine the bandwidth server-side, use kbps limit and sample. 0.9.157
隐藏空白字符变更
内嵌
并排对比
正在显示
5 个修改的文件
包含
34 行增加
和
56 行删除
trunk/src/app/srs_app_bandwidth.cpp
trunk/src/app/srs_app_bandwidth.hpp
trunk/src/app/srs_app_kbps.cpp
trunk/src/app/srs_app_rtmp_conn.cpp
trunk/src/core/srs_core.hpp
trunk/src/app/srs_app_bandwidth.cpp
查看文件 @
539b595
...
...
@@ -51,8 +51,11 @@ SrsBandwidthSample::~SrsBandwidthSample()
{
}
void
SrsBandwidthSample
::
calc_kbps
()
void
SrsBandwidthSample
::
calc_kbps
(
int
_bytes
,
int
_duration
)
{
bytes
=
(
int
)
_bytes
;
actual_duration_ms
=
(
int
)
_duration
;
if
(
actual_duration_ms
<=
0
)
{
return
;
}
...
...
@@ -144,7 +147,6 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit)
return
ret
;
}
play_sample
.
calc_kbps
();
srs_info
(
"stop play test. kbps=%d"
,
play_sample
.
kbps
);
// sample publish
...
...
@@ -155,7 +157,6 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit)
return
ret
;
}
publish_sample
.
calc_kbps
();
srs_info
(
"stop publish test. kbps=%d"
,
publish_sample
.
kbps
);
// stop test.
...
...
@@ -249,15 +250,14 @@ int SrsBandwidth::check_play(SrsBandwidthSample* sample, SrsKbpsLimit* limit)
srs_info
(
"BW check recv play begin response."
);
// send play data to client
int64_t
current_time
=
srs_get_system_time_ms
();
int
size
=
1024
;
// TODO: FIXME: magic number
char
random_data
[
size
];
memset
(
random_data
,
'A'
,
size
);
int
interval
=
0
;
int
data_count
=
1
;
while
((
srs_get_system_time_ms
()
-
current_time
)
<
duration_ms
)
{
st_usleep
(
interval
);
int64_t
starttime
=
srs_get_system_time_ms
();
while
((
srs_get_system_time_ms
()
-
starttime
)
<
sample
->
duration_ms
)
{
st_usleep
(
sample
->
interval_ms
);
// TODO: FIXME: use shared ptr message.
SrsBandwidthPacket
*
pkt
=
SrsBandwidthPacket
::
create_playing
();
...
...
@@ -271,38 +271,24 @@ int SrsBandwidth::check_play(SrsBandwidthSample* sample, SrsKbpsLimit* limit)
}
data_count
+=
2
;
// get length from the rtmp protocol stack.
play_bytes
=
_rtmp
->
get_send_bytes
();
if
((
ret
=
_rtmp
->
send_and_free_packet
(
pkt
,
0
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"send bandwidth check play messages failed. ret=%d"
,
ret
);
return
ret
;
}
// sleep while current kbps <= max_play_kbps
int
kbps
=
0
;
while
(
true
)
{
if
(
srs_get_system_time_ms
()
-
current_time
!=
0
)
kbps
=
play_bytes
*
8
/
(
srs_get_system_time_ms
()
-
current_time
);
if
(
kbps
>
max_play_kbps
)
{
st_usleep
(
500
);
}
else
{
break
;
}
}
limit
->
send_limit
();
}
actual_duration_ms
=
srs_get_system_time_ms
()
-
current_time
;
sample
->
calc_kbps
(
_rtmp
->
get_send_bytes
(),
srs_get_system_time_ms
()
-
starttime
)
;
srs_info
(
"BW check send play bytes over."
);
if
(
true
)
{
// notify client to stop play
SrsBandwidthPacket
*
pkt
=
SrsBandwidthPacket
::
create_stop_play
();
pkt
->
data
->
set
(
"duration_ms"
,
SrsAmf0Any
::
number
(
duration_ms
));
pkt
->
data
->
set
(
"interval_ms"
,
SrsAmf0Any
::
number
(
interval_ms
));
pkt
->
data
->
set
(
"duration_delta"
,
SrsAmf0Any
::
number
(
actual_duration_ms
));
pkt
->
data
->
set
(
"bytes_delta"
,
SrsAmf0Any
::
number
(
play_bytes
));
pkt
->
data
->
set
(
"duration_ms"
,
SrsAmf0Any
::
number
(
sample
->
duration_ms
));
pkt
->
data
->
set
(
"interval_ms"
,
SrsAmf0Any
::
number
(
sample
->
interval_ms
));
pkt
->
data
->
set
(
"duration_delta"
,
SrsAmf0Any
::
number
(
sample
->
actual_duration_ms
));
pkt
->
data
->
set
(
"bytes_delta"
,
SrsAmf0Any
::
number
(
sample
->
bytes
));
if
((
ret
=
_rtmp
->
send_and_free_packet
(
pkt
,
0
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"send bandwidth check stop play message failed. ret=%d"
,
ret
);
...
...
@@ -340,8 +326,8 @@ int SrsBandwidth::check_publish(SrsBandwidthSample* sample, SrsKbpsLimit* limit)
// notify client to start publish
SrsBandwidthPacket
*
pkt
=
SrsBandwidthPacket
::
create_start_publish
();
pkt
->
data
->
set
(
"duration_ms"
,
SrsAmf0Any
::
number
(
duration_ms
));
pkt
->
data
->
set
(
"interval_ms"
,
SrsAmf0Any
::
number
(
interval_ms
));
pkt
->
data
->
set
(
"duration_ms"
,
SrsAmf0Any
::
number
(
sample
->
duration_ms
));
pkt
->
data
->
set
(
"interval_ms"
,
SrsAmf0Any
::
number
(
sample
->
interval_ms
));
if
((
ret
=
_rtmp
->
send_and_free_packet
(
pkt
,
0
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"send bandwidth check start publish message failed. ret=%d"
,
ret
);
...
...
@@ -369,9 +355,9 @@ int SrsBandwidth::check_publish(SrsBandwidthSample* sample, SrsKbpsLimit* limit)
srs_info
(
"BW check recv publish begin response."
);
// recv publish msgs until @duration_ms ms
int64_t
current_time
=
srs_get_system_time_ms
();
while
((
srs_get_system_time_ms
()
-
current_time
)
<
duration_ms
)
{
st_usleep
(
0
);
int64_t
starttime
=
srs_get_system_time_ms
();
while
((
srs_get_system_time_ms
()
-
starttime
)
<
sample
->
duration_ms
)
{
st_usleep
(
sample
->
interval_ms
);
SrsMessage
*
msg
=
NULL
;
if
((
ret
=
_rtmp
->
recv_message
(
&
msg
))
!=
ERROR_SUCCESS
)
{
...
...
@@ -379,31 +365,19 @@ int SrsBandwidth::check_publish(SrsBandwidthSample* sample, SrsKbpsLimit* limit)
return
ret
;
}
SrsAutoFree
(
SrsMessage
,
msg
);
publish_bytes
=
_rtmp
->
get_recv_bytes
();
int
kbps
=
0
;
while
(
true
)
{
if
(
srs_get_system_time_ms
()
-
current_time
!=
0
)
kbps
=
publish_bytes
*
8
/
(
srs_get_system_time_ms
()
-
current_time
);
if
(
kbps
>
max_pub_kbps
)
{
st_usleep
(
500
);
}
else
{
break
;
}
}
limit
->
recv_limit
();
}
actual_duration_ms
=
srs_get_system_time_ms
()
-
current_time
;
sample
->
calc_kbps
(
_rtmp
->
get_recv_bytes
(),
srs_get_system_time_ms
()
-
starttime
)
;
srs_info
(
"BW check recv publish data over."
);
if
(
true
)
{
// notify client to stop publish
SrsBandwidthPacket
*
pkt
=
SrsBandwidthPacket
::
create_stop_publish
();
pkt
->
data
->
set
(
"duration_ms"
,
SrsAmf0Any
::
number
(
duration_ms
));
pkt
->
data
->
set
(
"interval_ms"
,
SrsAmf0Any
::
number
(
interval_ms
));
pkt
->
data
->
set
(
"duration_delta"
,
SrsAmf0Any
::
number
(
actual_duration_ms
));
pkt
->
data
->
set
(
"bytes_delta"
,
SrsAmf0Any
::
number
(
publish_bytes
));
pkt
->
data
->
set
(
"duration_ms"
,
SrsAmf0Any
::
number
(
sample
->
duration_ms
));
pkt
->
data
->
set
(
"interval_ms"
,
SrsAmf0Any
::
number
(
sample
->
interval_ms
));
pkt
->
data
->
set
(
"duration_delta"
,
SrsAmf0Any
::
number
(
sample
->
actual_duration_ms
));
pkt
->
data
->
set
(
"bytes_delta"
,
SrsAmf0Any
::
number
(
sample
->
bytes
));
if
((
ret
=
_rtmp
->
send_and_free_packet
(
pkt
,
0
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"send bandwidth check stop publish message failed. ret=%d"
,
ret
);
...
...
trunk/src/app/srs_app_bandwidth.hpp
查看文件 @
539b595
...
...
@@ -53,6 +53,7 @@ public:
* the plan, interval for each check/test packet, in ms
*/
int
interval_ms
;
public
:
/**
* the actual test duration, in ms.
*/
...
...
@@ -70,9 +71,11 @@ public:
virtual
~
SrsBandwidthSample
();
public
:
/**
* use current sample data to calc the kbps.
* update the bytes and actual duration, then calc the kbps.
* @param _bytes update the sample bytes.
* @param _duration update the actual duration, in ms.
*/
virtual
void
calc_kbps
();
virtual
void
calc_kbps
(
int
_bytes
,
int
_duration
);
};
/**
...
...
trunk/src/app/srs_app_kbps.cpp
查看文件 @
539b595
...
...
@@ -27,6 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_log.hpp>
#include <srs_protocol_io.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_app_st.hpp>
#define _SRS_BANDWIDTH_LIMIT_INTERVAL_MS 100
...
...
trunk/src/app/srs_app_rtmp_conn.cpp
查看文件 @
539b595
...
...
@@ -216,7 +216,7 @@ int SrsRtmpConn::service_cycle()
// do bandwidth test if connect to the vhost which is for bandwidth check.
if
(
_srs_config
->
get_bw_check_enabled
(
req
->
vhost
))
{
return
bandwidth
->
bandwidth_check
(
rtmp
,
io
,
req
,
local_ip
);
return
bandwidth
->
bandwidth_check
(
rtmp
,
skt
,
req
,
local_ip
);
}
if
((
ret
=
rtmp
->
response_connect_app
(
req
,
local_ip
.
c_str
()))
!=
ERROR_SUCCESS
)
{
...
...
trunk/src/core/srs_core.hpp
查看文件 @
539b595
...
...
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR "0"
#define VERSION_MINOR "9"
#define VERSION_REVISION "15
6
"
#define VERSION_REVISION "15
7
"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info.
#define RTMP_SIG_SRS_KEY "SRS"
...
...
请
注册
或
登录
后发表评论