diff --git a/trunk/research/players/srs_bwt/release/srs_bwt.swf b/trunk/research/players/srs_bwt/release/srs_bwt.swf index e0c6cd423..79d45e585 100755 Binary files a/trunk/research/players/srs_bwt/release/srs_bwt.swf and b/trunk/research/players/srs_bwt/release/srs_bwt.swf differ diff --git a/trunk/research/players/srs_bwt/src/SrsBandwidth.as b/trunk/research/players/srs_bwt/src/SrsBandwidth.as index e09e55ffc..2df4420f6 100755 --- a/trunk/research/players/srs_bwt/src/SrsBandwidth.as +++ b/trunk/research/players/srs_bwt/src/SrsBandwidth.as @@ -394,7 +394,27 @@ package private function publisher():void{ var data:Array = new Array(); - var data_size:int = 100; + /** + * the data size cannot too large, it will increase the test time. + * server need atleast got one packet, then timeout to stop the publish. + * + * cannot too small neither, it will limit the max publish kbps. + * + * the test values: + * test_s test_s + * data_size max_publish_kbps (no limit) (limit upload to 5KBps) + * 100 2116 6.5 7.3 + * 200 4071 6.5 7.7 + * 300 6438 6.5 10.3 + * 400 9328 6.5 10.2 + * 500 10377 6.5 10.0 + * 600 13737 6.5 10.8 + * 700 15635 6.5 12.0 + * 800 18103 6.5 14.0 + * 900 20484 6.5 14.2 + * 1000 21447 6.5 16.8 + */ + var data_size:int = 900; for(var i:int; i < data_size; i++) { data.push("SrS band check data from client's publishing......"); } diff --git a/trunk/src/app/srs_app_bandwidth.cpp b/trunk/src/app/srs_app_bandwidth.cpp index c196df835..fe01e1545 100644 --- a/trunk/src/app/srs_app_bandwidth.cpp +++ b/trunk/src/app/srs_app_bandwidth.cpp @@ -42,6 +42,9 @@ using namespace std; // default sample duration, in ms #define _SRS_BANDWIDTH_SAMPLE_DURATION_MS 3000 +// wait for a while for flash to got all packets. +#define _SRS_BANDWIDTH_FINAL_WAIT_MS 600 + SrsBandwidthSample::SrsBandwidthSample() { duration_ms = _SRS_BANDWIDTH_SAMPLE_DURATION_MS; @@ -241,6 +244,8 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) if ((ret = finial(play_sample, publish_sample, start_time, end_time)) != ERROR_SUCCESS) { return ret; } + + st_usleep(_SRS_BANDWIDTH_FINAL_WAIT_MS * 1000); srs_info("BW check finished."); return ret; @@ -254,6 +259,7 @@ int SrsBandwidth::play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) // send start play command to client 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)); @@ -349,6 +355,7 @@ int SrsBandwidth::publish_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) // notify client to start publish 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)); diff --git a/trunk/src/app/srs_app_kbps.cpp b/trunk/src/app/srs_app_kbps.cpp index 9fea51668..028195da9 100644 --- a/trunk/src/app/srs_app_kbps.cpp +++ b/trunk/src/app/srs_app_kbps.cpp @@ -257,6 +257,11 @@ SrsKbpsLimit::~SrsKbpsLimit() { } +int SrsKbpsLimit::limit_kbps() +{ + return _limit_kbps; +} + void SrsKbpsLimit::recv_limit() { _kbps->sample(); diff --git a/trunk/src/app/srs_app_kbps.hpp b/trunk/src/app/srs_app_kbps.hpp index 4156f2f69..8f1587681 100644 --- a/trunk/src/app/srs_app_kbps.hpp +++ b/trunk/src/app/srs_app_kbps.hpp @@ -210,6 +210,10 @@ public: SrsKbpsLimit(SrsKbps* kbps, int limit_kbps); virtual ~SrsKbpsLimit(); public: + /** + * get the system limit kbps. + */ + virtual int limit_kbps(); /** * limit the recv bandwidth. */ diff --git a/trunk/src/libs/srs_lib_bandwidth.cpp b/trunk/src/libs/srs_lib_bandwidth.cpp index b1ae8119a..01b0d75d3 100644 --- a/trunk/src/libs/srs_lib_bandwidth.cpp +++ b/trunk/src/libs/srs_lib_bandwidth.cpp @@ -130,29 +130,20 @@ int SrsBandwidthClient::bandwidth_check( *start_time = srs_get_system_time_ms(); // play - int duration_delta = 0; - int bytes_delta = 0; if ((ret = play_start()) != ERROR_SUCCESS) { return ret; } if ((ret = play_checking()) != ERROR_SUCCESS) { return ret; } - if ((ret = play_stop(duration_delta, bytes_delta)) != ERROR_SUCCESS) { + if ((ret = play_stop()) != ERROR_SUCCESS) { return ret; } - // play kbps used to refer for publish - int actual_play_kbps = 0; - if (duration_delta > 0) { - actual_play_kbps = bytes_delta * 8 / duration_delta; - } - // max publish kbps, we set to 1.2*play_kbps: - actual_play_kbps = (int)(actual_play_kbps * 1.2); - // publish int duration_ms = 0; - if ((ret = publish_start(duration_ms)) != ERROR_SUCCESS) { + int actual_play_kbps = 0; + if ((ret = publish_start(duration_ms, actual_play_kbps)) != ERROR_SUCCESS) { return ret; } if ((ret = publish_checking(duration_ms, actual_play_kbps)) != ERROR_SUCCESS) { @@ -226,24 +217,12 @@ int SrsBandwidthClient::play_checking() return ret; } -int SrsBandwidthClient::play_stop(int& duration_delta, int& bytes_delta) +int SrsBandwidthClient::play_stop() { int ret = ERROR_SUCCESS; - if (true) { - SrsBandwidthPacket* pkt = NULL; - if ((ret = _srs_expect_bandwidth_packet2(_rtmp, _bandwidth_is_stop_play, &pkt)) != ERROR_SUCCESS) { - return ret; - } - SrsAutoFree(SrsBandwidthPacket, pkt); - - SrsAmf0Any* prop = NULL; - if ((prop = pkt->data->ensure_property_number("duration_delta")) != NULL) { - duration_delta = (int)prop->to_number(); - } - if ((prop = pkt->data->ensure_property_number("bytes_delta")) != NULL) { - bytes_delta = (int)prop->to_number(); - } + if ((ret = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stop_play)) != ERROR_SUCCESS) { + return ret; } srs_info("BW check recv play stop request."); @@ -261,7 +240,7 @@ int SrsBandwidthClient::play_stop(int& duration_delta, int& bytes_delta) return ret; } -int SrsBandwidthClient::publish_start(int& duration_ms) +int SrsBandwidthClient::publish_start(int& duration_ms, int& play_kbps) { int ret = ERROR_SUCCESS; @@ -276,6 +255,9 @@ int SrsBandwidthClient::publish_start(int& duration_ms) if ((prop = pkt->data->ensure_property_number("duration_ms")) != NULL) { duration_ms = (int)prop->to_number(); } + if ((prop = pkt->data->ensure_property_number("limit_kbps")) != NULL) { + play_kbps = (int)prop->to_number(); + } } srs_info("BW check recv publish begin request."); diff --git a/trunk/src/libs/srs_lib_bandwidth.hpp b/trunk/src/libs/srs_lib_bandwidth.hpp index 0d86df5a4..82db66d48 100644 --- a/trunk/src/libs/srs_lib_bandwidth.hpp +++ b/trunk/src/libs/srs_lib_bandwidth.hpp @@ -73,11 +73,11 @@ private: */ virtual int play_start(); virtual int play_checking(); - virtual int play_stop(int& duration_delta, int& bytes_delta); + virtual int play_stop(); /** * publish check/test, publishing bandwidth kbps. */ - virtual int publish_start(int& duration_ms); + virtual int publish_start(int& duration_ms, int& play_kbps); virtual int publish_checking(int duration_ms, int play_kbps); virtual int publish_stop(); /**