mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Detect whether flash enabled for srs-bwt.
This commit is contained in:
parent
c830dc6700
commit
cef7ec79b3
4 changed files with 123 additions and 68 deletions
|
@ -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,
|
# generally, the bandcheck vhost must be: bandcheck.srs.com,
|
||||||
# or need to modify the vhost of client.
|
# or need to modify the vhost of client.
|
||||||
vhost bandcheck.srs.com {
|
vhost bandcheck.srs.com {
|
||||||
|
|
|
@ -35,6 +35,19 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<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_content" class="hide">
|
||||||
<div class="alert alert-info fade in">
|
<div class="alert alert-info fade in">
|
||||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||||
<strong><span>Usage:</span></strong> <span>点击“开始测速”即可测带宽,最大可测试带宽由服务器限制</span>
|
<strong><span>Usage:</span></strong> <span>点击“开始测速”即可测带宽,最大可测试带宽由服务器限制</span>
|
||||||
|
@ -66,8 +79,10 @@
|
||||||
<button class="btn btn-primary" data-dismiss="modal" aria-hidden="true"> 关闭 </button>
|
<button class="btn btn-primary" data-dismiss="modal" aria-hidden="true"> 关闭 </button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
</div>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
|
<p></p>
|
||||||
<p><a href="https://github.com/ossrs/srs">SRS Team © 2013</a></p>
|
<p><a href="https://github.com/ossrs/srs">SRS Team © 2013</a></p>
|
||||||
</footer>
|
</footer>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -86,15 +101,57 @@
|
||||||
<script type="text/javascript" src="js/winlin.utility.js"></script>
|
<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" src="srs_bwt/src/srs.bandwidth.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var bandwidth = null;
|
var __on_flash_ready = null;
|
||||||
|
|
||||||
$(function(){
|
$(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");
|
srs_init_bwt("#txt_url");
|
||||||
|
|
||||||
$("#btn_play").click(on_click_play);
|
$("#btn_play").click(on_click_play);
|
||||||
$("#main_modal").on("show", on_start_bandwidth_test);
|
$("#main_modal").on("show", on_start_bandwidth_test);
|
||||||
$("#main_modal").on("hide", on_stop_bandwidth_test);
|
$("#main_modal").on("hide", on_stop_bandwidth_test);
|
||||||
});
|
};
|
||||||
|
|
||||||
function on_click_play() {
|
function on_click_play() {
|
||||||
$("#check_status").text("");
|
$("#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) {
|
bandwidth.on_srs_info = function(srs_server, srs_primary, srs_authors, srs_id, srs_pid, srs_server_ip) {
|
||||||
$("#check_info").text(
|
$("#check_info").text(
|
||||||
"server:" + srs_server + ", primary:" + srs_primary + ", authors:" + srs_authors +
|
"server:" + srs_server + ", srs_id:" + srs_id + ", srs_pid:" + srs_pid + ", ip:" + srs_server_ip
|
||||||
", srs_id:" + srs_id + ", srs_pid:" + srs_pid + ", ip:" + srs_server_ip
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
bandwidth.on_error = function(code) {
|
bandwidth.on_error = function(code) {
|
||||||
|
|
|
@ -47,24 +47,24 @@ using namespace std;
|
||||||
|
|
||||||
SrsBandwidthSample::SrsBandwidthSample()
|
SrsBandwidthSample::SrsBandwidthSample()
|
||||||
{
|
{
|
||||||
duration_ms = _SRS_BANDWIDTH_SAMPLE_DURATION;
|
duration = _SRS_BANDWIDTH_SAMPLE_DURATION;
|
||||||
kbps = interval_ms = actual_duration_ms = bytes = 0;
|
kbps = interval = actual_duration = bytes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsBandwidthSample::~SrsBandwidthSample()
|
SrsBandwidthSample::~SrsBandwidthSample()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsBandwidthSample::calc_kbps(int _bytes, int _duration)
|
void SrsBandwidthSample::calc_kbps(int _bytes, srs_utime_t _duration)
|
||||||
{
|
{
|
||||||
bytes = _bytes;
|
bytes = _bytes;
|
||||||
actual_duration_ms = _duration;
|
actual_duration = _duration;
|
||||||
|
|
||||||
if (actual_duration_ms <= 0) {
|
if (actual_duration <= 0) {
|
||||||
return;
|
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;
|
SrsBandwidthSample publish_sample;
|
||||||
|
|
||||||
// timeout for a packet.
|
// timeout for a packet.
|
||||||
_rtmp->set_send_timeout(play_sample.duration_ms * 2 * SRS_UTIME_MILLISECONDS);
|
_rtmp->set_send_timeout(play_sample.duration * 2);
|
||||||
_rtmp->set_recv_timeout(publish_sample.duration_ms * 2 * SRS_UTIME_MILLISECONDS);
|
_rtmp->set_recv_timeout(publish_sample.duration * 2);
|
||||||
|
|
||||||
// start test.
|
// start test.
|
||||||
srs_utime_t start_time = srs_update_system_time();
|
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",
|
srs_trace("bandwidth ok. duartion=%dms(%d+%d), play=%dkbps, publish=%dkbps",
|
||||||
srsu2msi(end_time - start_time), play_sample.actual_duration_ms,
|
srsu2msi(end_time - start_time), srsu2msi(play_sample.actual_duration), srsu2msi(publish_sample.actual_duration),
|
||||||
publish_sample.actual_duration_ms, play_sample.kbps,
|
play_sample.kbps, publish_sample.kbps);
|
||||||
publish_sample.kbps);
|
|
||||||
|
|
||||||
srs_usleep(_SRS_BANDWIDTH_FINAL_WAIT);
|
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();
|
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_play();
|
||||||
|
|
||||||
pkt->data->set("limit_kbps", SrsAmf0Any::number(limit->limit_kbps()));
|
pkt->data->set("limit_kbps", SrsAmf0Any::number(limit->limit_kbps()));
|
||||||
pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms));
|
pkt->data->set("duration_ms", SrsAmf0Any::number(srsu2msi(sample->duration)));
|
||||||
pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms));
|
pkt->data->set("interval_ms", SrsAmf0Any::number(srsu2msi(sample->interval)));
|
||||||
|
|
||||||
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
||||||
return srs_error_wrap(err, "send packet");
|
return srs_error_wrap(err, "send packet");
|
||||||
|
@ -260,8 +259,8 @@ srs_error_t SrsBandwidth::play_checking(SrsBandwidthSample* sample, SrsKbpsLimit
|
||||||
|
|
||||||
int data_count = 1;
|
int data_count = 1;
|
||||||
srs_utime_t starttime = srs_update_system_time();
|
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) {
|
||||||
srs_usleep(sample->interval_ms * SRS_UTIME_MILLISECONDS);
|
srs_usleep(sample->interval);
|
||||||
|
|
||||||
// TODO: FIXME: use shared ptr message.
|
// TODO: FIXME: use shared ptr message.
|
||||||
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_playing();
|
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_playing();
|
||||||
|
@ -295,9 +294,9 @@ srs_error_t SrsBandwidth::play_stop(SrsBandwidthSample* sample, SrsKbpsLimit* /*
|
||||||
// notify client to stop play
|
// notify client to stop play
|
||||||
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_stop_play();
|
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_stop_play();
|
||||||
|
|
||||||
pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms));
|
pkt->data->set("duration_ms", SrsAmf0Any::number(srsu2msi(sample->duration)));
|
||||||
pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms));
|
pkt->data->set("interval_ms", SrsAmf0Any::number(srsu2msi(sample->interval)));
|
||||||
pkt->data->set("duration_delta", SrsAmf0Any::number(sample->actual_duration_ms));
|
pkt->data->set("duration_delta", SrsAmf0Any::number(srsu2msi(sample->actual_duration)));
|
||||||
pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes));
|
pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes));
|
||||||
|
|
||||||
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
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();
|
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_publish();
|
||||||
|
|
||||||
pkt->data->set("limit_kbps", SrsAmf0Any::number(limit->limit_kbps()));
|
pkt->data->set("limit_kbps", SrsAmf0Any::number(limit->limit_kbps()));
|
||||||
pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms));
|
pkt->data->set("duration_ms", SrsAmf0Any::number(srsu2msi(sample->duration)));
|
||||||
pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms));
|
pkt->data->set("interval_ms", SrsAmf0Any::number(srsu2msi(sample->interval)));
|
||||||
|
|
||||||
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
||||||
return srs_error_wrap(err, "send packet");
|
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;
|
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();
|
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;
|
SrsCommonMessage* msg = NULL;
|
||||||
SrsBandwidthPacket* pkt = NULL;
|
SrsBandwidthPacket* pkt = NULL;
|
||||||
if ((err = _rtmp->expect_message<SrsBandwidthPacket>(&msg, &pkt)) != srs_success) {
|
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) {
|
if (true) {
|
||||||
// notify client to stop publish
|
// notify client to stop publish
|
||||||
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_stop_publish();
|
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_stop_publish();
|
||||||
pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms));
|
pkt->data->set("duration_ms", SrsAmf0Any::number(srsu2msi(sample->duration)));
|
||||||
pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms));
|
pkt->data->set("interval_ms", SrsAmf0Any::number(srsu2msi(sample->interval)));
|
||||||
pkt->data->set("duration_delta", SrsAmf0Any::number(sample->actual_duration_ms));
|
pkt->data->set("duration_delta", SrsAmf0Any::number(srsu2msi(sample->actual_duration)));
|
||||||
pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes));
|
pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes));
|
||||||
|
|
||||||
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
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("publish_kbps", SrsAmf0Any::number(publish_sample.kbps));
|
||||||
pkt->data->set("play_bytes", SrsAmf0Any::number(play_sample.bytes));
|
pkt->data->set("play_bytes", SrsAmf0Any::number(play_sample.bytes));
|
||||||
pkt->data->set("publish_bytes", SrsAmf0Any::number(publish_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("play_time", SrsAmf0Any::number(srsu2msi(play_sample.actual_duration)));
|
||||||
pkt->data->set("publish_time", SrsAmf0Any::number(publish_sample.actual_duration_ms));
|
pkt->data->set("publish_time", SrsAmf0Any::number(srsu2msi(publish_sample.actual_duration)));
|
||||||
|
|
||||||
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
||||||
return srs_error_wrap(err, "send packet");
|
return srs_error_wrap(err, "send packet");
|
||||||
|
|
|
@ -40,14 +40,14 @@ class ISrsProtocolStatistic;
|
||||||
class SrsBandwidthSample
|
class SrsBandwidthSample
|
||||||
{
|
{
|
||||||
public:
|
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.
|
// if exceed the duration, abort the test.
|
||||||
int duration_ms;
|
srs_utime_t duration;
|
||||||
// The plan, interval for each check/test packet, in ms
|
// The plan, interval for each check/test packet
|
||||||
int interval_ms;
|
srs_utime_t interval;
|
||||||
public:
|
public:
|
||||||
// The actual test duration, in ms.
|
// The actual test duration.
|
||||||
int actual_duration_ms;
|
srs_utime_t actual_duration;
|
||||||
// The actual test bytes
|
// The actual test bytes
|
||||||
int bytes;
|
int bytes;
|
||||||
// The actual test kbps
|
// The actual test kbps
|
||||||
|
@ -58,8 +58,8 @@ public:
|
||||||
public:
|
public:
|
||||||
// Update the bytes and actual duration, then calc the kbps.
|
// Update the bytes and actual duration, then calc the kbps.
|
||||||
// @param _bytes update the sample bytes.
|
// @param _bytes update the sample bytes.
|
||||||
// @param _duration update the actual duration, in ms.
|
// @param _duration update the actual duration.
|
||||||
virtual void calc_kbps(int _bytes, int _duration);
|
virtual void calc_kbps(int _bytes, srs_utime_t _duration);
|
||||||
};
|
};
|
||||||
|
|
||||||
// The bandwidth test agent which provides the interfaces for bandwidth check.
|
// The bandwidth test agent which provides the interfaces for bandwidth check.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue