Detect whether flash enabled for srs-bwt.

pull/1568/head
winlin 5 years ago
parent c830dc6700
commit cef7ec79b3

@ -665,7 +665,7 @@ vhost refer.anti_suck.com {
}
}
# vhost for bandwidth check
# vhost for bwt(bandwidth check)
# generally, the bandcheck vhost must be: bandcheck.srs.com,
# or need to modify the vhost of client.
vhost bandcheck.srs.com {

@ -35,39 +35,54 @@
</div>
</div>
<div class="container">
<div class="alert alert-info fade in">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong><span>Usage:</span></strong> <span>点击“开始测速”即可测带宽,最大可测试带宽由服务器限制</span>
</div>
<div class="form-inline">
URL:
<input type="text" id="txt_url" class="input-xxlarge" value=""></input>
<button class="btn btn-primary" id="btn_play">开始测速</button>
<div name="detect_flash">
<div id="main_flash_alert" class="alert alert-danger fade in hide">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong><span>Usage:</span></strong>
<span>
请点击下面的图标启用Flash
</span>
</div>
<div id="main_flash_hdr" class="hide">
</div>
</div>
<div id="main_modal" class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>SRS Bandwidth Check</h3>
</div>
<div class="modal-body">
<div class="row-fluid">
<div class="span1"></div>
<div class="span10">
<div class="progress progress-striped active" id="pb_buffer_bg">
<div class="bar" style="width: 0%;" id="progress_bar"></div>
<div id="main_content" class="hide">
<div class="alert alert-info fade in">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong><span>Usage:</span></strong> <span>点击“开始测速”即可测带宽,最大可测试带宽由服务器限制</span>
</div>
<div class="form-inline">
URL:
<input type="text" id="txt_url" class="input-xxlarge" value=""></input>
<button class="btn btn-primary" id="btn_play">开始测速</button>
</div>
<div id="main_modal" class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>SRS Bandwidth Check</h3>
</div>
<div class="modal-body">
<div class="row-fluid">
<div class="span1"></div>
<div class="span10">
<div class="progress progress-striped active" id="pb_buffer_bg">
<div class="bar" style="width: 0%;" id="progress_bar"></div>
</div>
</div>
<div class="span1"></div>
</div>
<div class="span1"></div>
</div>
<div id="check_status">status</div>
<div id="check_info">info</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" data-dismiss="modal" aria-hidden="true"> 关闭 </button>
<div id="check_status">status</div>
<div id="check_info">info</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" data-dismiss="modal" aria-hidden="true"> 关闭 </button>
</div>
</div>
</div>
<hr>
</div>
<footer>
<p></p>
<p><a href="https://github.com/ossrs/srs">SRS Team &copy; 2013</a></p>
</footer>
<div class="container">
@ -86,15 +101,57 @@
<script type="text/javascript" src="js/winlin.utility.js"></script>
<script type="text/javascript" src="srs_bwt/src/srs.bandwidth.js"></script>
<script type="text/javascript">
var bandwidth = null;
var __on_flash_ready = null;
$(function(){
// 探测Flash是否正常启用。
$('#main_flash_hdr').html(
'\
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100%" height="100%"> \
<param name="movie" value="srs_player/release/srs_player.swf"> \
<param name="quality" value="autohigh"> \
<param name="swliveconnect" value="true"> \
<param name="allowScriptAccess" value="always"> \
<param name="bgcolor" value="#0"> \
<param name="allowFullScreen" value="true"> \
<param name="wmode" value="opaque"> \
<param name="FlashVars" value="log=1"> \
<param name="flashvars" value="id=1&on_player_ready=__on_flash_ready"> \
<embed src="srs_player/release/srs_player.swf" width="100%" height="100%" \
quality="autohigh" bgcolor="#0" align="middle" allowfullscreen="true" allowscriptaccess="always" \
type="application/x-shockwave-flash" swliveconnect="true" wmode="opaque" \
flashvars="id=1&on_player_ready=__on_flash_ready" \
pluginspage="http://www.macromedia.com/go/getflashplayer"> \
</object> \
'
);
$('#main_flash_hdr').show();
var showFlashHdr = setTimeout(function(){
$('#main_flash_alert').show();
}, 300);
__on_flash_ready = function (id) {
clearTimeout(showFlashHdr);
$('#main_flash_alert').hide();
$('#main_flash_hdr').hide();
$('#main_content').show();
autoLoadPage();
};
});
</script>
<script type="text/javascript">
var bandwidth = null;
var autoLoadPage = function() {
srs_init_bwt("#txt_url");
$("#btn_play").click(on_click_play);
$("#main_modal").on("show", on_start_bandwidth_test);
$("#main_modal").on("hide", on_stop_bandwidth_test);
});
};
function on_click_play() {
$("#check_status").text("");
@ -128,8 +185,7 @@
}
bandwidth.on_srs_info = function(srs_server, srs_primary, srs_authors, srs_id, srs_pid, srs_server_ip) {
$("#check_info").text(
"server:" + srs_server + ", primary:" + srs_primary + ", authors:" + srs_authors +
", srs_id:" + srs_id + ", srs_pid:" + srs_pid + ", ip:" + srs_server_ip
"server:" + srs_server + ", srs_id:" + srs_id + ", srs_pid:" + srs_pid + ", ip:" + srs_server_ip
);
}
bandwidth.on_error = function(code) {

@ -47,24 +47,24 @@ using namespace std;
SrsBandwidthSample::SrsBandwidthSample()
{
duration_ms = _SRS_BANDWIDTH_SAMPLE_DURATION;
kbps = interval_ms = actual_duration_ms = bytes = 0;
duration = _SRS_BANDWIDTH_SAMPLE_DURATION;
kbps = interval = actual_duration = bytes = 0;
}
SrsBandwidthSample::~SrsBandwidthSample()
{
}
void SrsBandwidthSample::calc_kbps(int _bytes, int _duration)
void SrsBandwidthSample::calc_kbps(int _bytes, srs_utime_t _duration)
{
bytes = _bytes;
actual_duration_ms = _duration;
actual_duration = _duration;
if (actual_duration_ms <= 0) {
if (actual_duration <= 0) {
return;
}
kbps = bytes * 8 / actual_duration_ms;
kbps = bytes * 8 / srsu2ms(actual_duration);
}
/**
@ -180,8 +180,8 @@ srs_error_t SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit)
SrsBandwidthSample publish_sample;
// timeout for a packet.
_rtmp->set_send_timeout(play_sample.duration_ms * 2 * SRS_UTIME_MILLISECONDS);
_rtmp->set_recv_timeout(publish_sample.duration_ms * 2 * SRS_UTIME_MILLISECONDS);
_rtmp->set_send_timeout(play_sample.duration * 2);
_rtmp->set_recv_timeout(publish_sample.duration * 2);
// start test.
srs_utime_t start_time = srs_update_system_time();
@ -216,9 +216,8 @@ srs_error_t SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit)
}
srs_trace("bandwidth ok. duartion=%dms(%d+%d), play=%dkbps, publish=%dkbps",
srsu2msi(end_time - start_time), play_sample.actual_duration_ms,
publish_sample.actual_duration_ms, play_sample.kbps,
publish_sample.kbps);
srsu2msi(end_time - start_time), srsu2msi(play_sample.actual_duration), srsu2msi(publish_sample.actual_duration),
play_sample.kbps, publish_sample.kbps);
srs_usleep(_SRS_BANDWIDTH_FINAL_WAIT);
@ -234,8 +233,8 @@ srs_error_t SrsBandwidth::play_start(SrsBandwidthSample* sample, SrsKbpsLimit* l
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_play();
pkt->data->set("limit_kbps", SrsAmf0Any::number(limit->limit_kbps()));
pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms));
pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms));
pkt->data->set("duration_ms", SrsAmf0Any::number(srsu2msi(sample->duration)));
pkt->data->set("interval_ms", SrsAmf0Any::number(srsu2msi(sample->interval)));
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
return srs_error_wrap(err, "send packet");
@ -260,8 +259,8 @@ srs_error_t SrsBandwidth::play_checking(SrsBandwidthSample* sample, SrsKbpsLimit
int data_count = 1;
srs_utime_t starttime = srs_update_system_time();
while (int64_t(srsu2ms(srs_get_system_time() - starttime)) < sample->duration_ms) {
srs_usleep(sample->interval_ms * SRS_UTIME_MILLISECONDS);
while (srs_get_system_time() - starttime < sample->duration) {
srs_usleep(sample->interval);
// TODO: FIXME: use shared ptr message.
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_playing();
@ -295,9 +294,9 @@ srs_error_t SrsBandwidth::play_stop(SrsBandwidthSample* sample, SrsKbpsLimit* /*
// notify client to stop play
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_stop_play();
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("duration_ms", SrsAmf0Any::number(srsu2msi(sample->duration)));
pkt->data->set("interval_ms", SrsAmf0Any::number(srsu2msi(sample->interval)));
pkt->data->set("duration_delta", SrsAmf0Any::number(srsu2msi(sample->actual_duration)));
pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes));
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
@ -321,8 +320,8 @@ srs_error_t SrsBandwidth::publish_start(SrsBandwidthSample* sample, SrsKbpsLimit
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_publish();
pkt->data->set("limit_kbps", SrsAmf0Any::number(limit->limit_kbps()));
pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms));
pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms));
pkt->data->set("duration_ms", SrsAmf0Any::number(srsu2msi(sample->duration)));
pkt->data->set("interval_ms", SrsAmf0Any::number(srsu2msi(sample->interval)));
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
return srs_error_wrap(err, "send packet");
@ -340,9 +339,9 @@ srs_error_t SrsBandwidth::publish_checking(SrsBandwidthSample* sample, SrsKbpsLi
{
srs_error_t err = srs_success;
// recv publish msgs until @duration_ms ms
// recv publish msgs until @duration ms
srs_utime_t starttime = srs_update_system_time();
while (int64_t(srsu2ms(srs_get_system_time() - starttime)) < sample->duration_ms) {
while (srs_get_system_time() - starttime < sample->duration) {
SrsCommonMessage* msg = NULL;
SrsBandwidthPacket* pkt = NULL;
if ((err = _rtmp->expect_message<SrsBandwidthPacket>(&msg, &pkt)) != srs_success) {
@ -372,9 +371,9 @@ srs_error_t SrsBandwidth::publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit*
if (true) {
// notify client to stop publish
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_stop_publish();
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("duration_ms", SrsAmf0Any::number(srsu2msi(sample->duration)));
pkt->data->set("interval_ms", SrsAmf0Any::number(srsu2msi(sample->interval)));
pkt->data->set("duration_delta", SrsAmf0Any::number(srsu2msi(sample->actual_duration)));
pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes));
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
@ -411,8 +410,8 @@ srs_error_t SrsBandwidth::do_final(SrsBandwidthSample& play_sample, SrsBandwidth
pkt->data->set("publish_kbps", SrsAmf0Any::number(publish_sample.kbps));
pkt->data->set("play_bytes", SrsAmf0Any::number(play_sample.bytes));
pkt->data->set("publish_bytes", SrsAmf0Any::number(publish_sample.bytes));
pkt->data->set("play_time", SrsAmf0Any::number(play_sample.actual_duration_ms));
pkt->data->set("publish_time", SrsAmf0Any::number(publish_sample.actual_duration_ms));
pkt->data->set("play_time", SrsAmf0Any::number(srsu2msi(play_sample.actual_duration)));
pkt->data->set("publish_time", SrsAmf0Any::number(srsu2msi(publish_sample.actual_duration)));
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
return srs_error_wrap(err, "send packet");

@ -40,14 +40,14 @@ class ISrsProtocolStatistic;
class SrsBandwidthSample
{
public:
// The plan, how long to do the test, in ms,
// The plan, how long to do the test,
// if exceed the duration, abort the test.
int duration_ms;
// The plan, interval for each check/test packet, in ms
int interval_ms;
srs_utime_t duration;
// The plan, interval for each check/test packet
srs_utime_t interval;
public:
// The actual test duration, in ms.
int actual_duration_ms;
// The actual test duration.
srs_utime_t actual_duration;
// The actual test bytes
int bytes;
// The actual test kbps
@ -58,8 +58,8 @@ public:
public:
// 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(int _bytes, int _duration);
// @param _duration update the actual duration.
virtual void calc_kbps(int _bytes, srs_utime_t _duration);
};
// The bandwidth test agent which provides the interfaces for bandwidth check.

Loading…
Cancel
Save