正在显示
7 个修改的文件
包含
48 行增加
和
30 行删除
| @@ -394,7 +394,27 @@ package | @@ -394,7 +394,27 @@ package | ||
| 394 | private function publisher():void{ | 394 | private function publisher():void{ |
| 395 | var data:Array = new Array(); | 395 | var data:Array = new Array(); |
| 396 | 396 | ||
| 397 | - var data_size:int = 100; | 397 | + /** |
| 398 | + * the data size cannot too large, it will increase the test time. | ||
| 399 | + * server need atleast got one packet, then timeout to stop the publish. | ||
| 400 | + * | ||
| 401 | + * cannot too small neither, it will limit the max publish kbps. | ||
| 402 | + * | ||
| 403 | + * the test values: | ||
| 404 | + * test_s test_s | ||
| 405 | + * data_size max_publish_kbps (no limit) (limit upload to 5KBps) | ||
| 406 | + * 100 2116 6.5 7.3 | ||
| 407 | + * 200 4071 6.5 7.7 | ||
| 408 | + * 300 6438 6.5 10.3 | ||
| 409 | + * 400 9328 6.5 10.2 | ||
| 410 | + * 500 10377 6.5 10.0 | ||
| 411 | + * 600 13737 6.5 10.8 | ||
| 412 | + * 700 15635 6.5 12.0 | ||
| 413 | + * 800 18103 6.5 14.0 | ||
| 414 | + * 900 20484 6.5 14.2 | ||
| 415 | + * 1000 21447 6.5 16.8 | ||
| 416 | + */ | ||
| 417 | + var data_size:int = 900; | ||
| 398 | for(var i:int; i < data_size; i++) { | 418 | for(var i:int; i < data_size; i++) { |
| 399 | data.push("SrS band check data from client's publishing......"); | 419 | data.push("SrS band check data from client's publishing......"); |
| 400 | } | 420 | } |
| @@ -42,6 +42,9 @@ using namespace std; | @@ -42,6 +42,9 @@ using namespace std; | ||
| 42 | // default sample duration, in ms | 42 | // default sample duration, in ms |
| 43 | #define _SRS_BANDWIDTH_SAMPLE_DURATION_MS 3000 | 43 | #define _SRS_BANDWIDTH_SAMPLE_DURATION_MS 3000 |
| 44 | 44 | ||
| 45 | +// wait for a while for flash to got all packets. | ||
| 46 | +#define _SRS_BANDWIDTH_FINAL_WAIT_MS 600 | ||
| 47 | + | ||
| 45 | SrsBandwidthSample::SrsBandwidthSample() | 48 | SrsBandwidthSample::SrsBandwidthSample() |
| 46 | { | 49 | { |
| 47 | duration_ms = _SRS_BANDWIDTH_SAMPLE_DURATION_MS; | 50 | duration_ms = _SRS_BANDWIDTH_SAMPLE_DURATION_MS; |
| @@ -241,6 +244,8 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) | @@ -241,6 +244,8 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) | ||
| 241 | if ((ret = finial(play_sample, publish_sample, start_time, end_time)) != ERROR_SUCCESS) { | 244 | if ((ret = finial(play_sample, publish_sample, start_time, end_time)) != ERROR_SUCCESS) { |
| 242 | return ret; | 245 | return ret; |
| 243 | } | 246 | } |
| 247 | + | ||
| 248 | + st_usleep(_SRS_BANDWIDTH_FINAL_WAIT_MS * 1000); | ||
| 244 | srs_info("BW check finished."); | 249 | srs_info("BW check finished."); |
| 245 | 250 | ||
| 246 | return ret; | 251 | return ret; |
| @@ -254,6 +259,7 @@ int SrsBandwidth::play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | @@ -254,6 +259,7 @@ int SrsBandwidth::play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | ||
| 254 | // send start play command to client | 259 | // send start play command to client |
| 255 | SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_play(); | 260 | SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_play(); |
| 256 | 261 | ||
| 262 | + pkt->data->set("limit_kbps", SrsAmf0Any::number(limit->limit_kbps())); | ||
| 257 | pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms)); | 263 | pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms)); |
| 258 | pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms)); | 264 | pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms)); |
| 259 | 265 | ||
| @@ -349,6 +355,7 @@ int SrsBandwidth::publish_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | @@ -349,6 +355,7 @@ int SrsBandwidth::publish_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | ||
| 349 | // notify client to start publish | 355 | // notify client to start publish |
| 350 | SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_publish(); | 356 | SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_publish(); |
| 351 | 357 | ||
| 358 | + pkt->data->set("limit_kbps", SrsAmf0Any::number(limit->limit_kbps())); | ||
| 352 | pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms)); | 359 | pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms)); |
| 353 | pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms)); | 360 | pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_ms)); |
| 354 | 361 |
| @@ -257,6 +257,11 @@ SrsKbpsLimit::~SrsKbpsLimit() | @@ -257,6 +257,11 @@ SrsKbpsLimit::~SrsKbpsLimit() | ||
| 257 | { | 257 | { |
| 258 | } | 258 | } |
| 259 | 259 | ||
| 260 | +int SrsKbpsLimit::limit_kbps() | ||
| 261 | +{ | ||
| 262 | + return _limit_kbps; | ||
| 263 | +} | ||
| 264 | + | ||
| 260 | void SrsKbpsLimit::recv_limit() | 265 | void SrsKbpsLimit::recv_limit() |
| 261 | { | 266 | { |
| 262 | _kbps->sample(); | 267 | _kbps->sample(); |
| @@ -211,6 +211,10 @@ public: | @@ -211,6 +211,10 @@ public: | ||
| 211 | virtual ~SrsKbpsLimit(); | 211 | virtual ~SrsKbpsLimit(); |
| 212 | public: | 212 | public: |
| 213 | /** | 213 | /** |
| 214 | + * get the system limit kbps. | ||
| 215 | + */ | ||
| 216 | + virtual int limit_kbps(); | ||
| 217 | + /** | ||
| 214 | * limit the recv bandwidth. | 218 | * limit the recv bandwidth. |
| 215 | */ | 219 | */ |
| 216 | virtual void recv_limit(); | 220 | virtual void recv_limit(); |
| @@ -130,29 +130,20 @@ int SrsBandwidthClient::bandwidth_check( | @@ -130,29 +130,20 @@ int SrsBandwidthClient::bandwidth_check( | ||
| 130 | *start_time = srs_get_system_time_ms(); | 130 | *start_time = srs_get_system_time_ms(); |
| 131 | 131 | ||
| 132 | // play | 132 | // play |
| 133 | - int duration_delta = 0; | ||
| 134 | - int bytes_delta = 0; | ||
| 135 | if ((ret = play_start()) != ERROR_SUCCESS) { | 133 | if ((ret = play_start()) != ERROR_SUCCESS) { |
| 136 | return ret; | 134 | return ret; |
| 137 | } | 135 | } |
| 138 | if ((ret = play_checking()) != ERROR_SUCCESS) { | 136 | if ((ret = play_checking()) != ERROR_SUCCESS) { |
| 139 | return ret; | 137 | return ret; |
| 140 | } | 138 | } |
| 141 | - if ((ret = play_stop(duration_delta, bytes_delta)) != ERROR_SUCCESS) { | 139 | + if ((ret = play_stop()) != ERROR_SUCCESS) { |
| 142 | return ret; | 140 | return ret; |
| 143 | } | 141 | } |
| 144 | 142 | ||
| 145 | - // play kbps used to refer for publish | ||
| 146 | - int actual_play_kbps = 0; | ||
| 147 | - if (duration_delta > 0) { | ||
| 148 | - actual_play_kbps = bytes_delta * 8 / duration_delta; | ||
| 149 | - } | ||
| 150 | - // max publish kbps, we set to 1.2*play_kbps: | ||
| 151 | - actual_play_kbps = (int)(actual_play_kbps * 1.2); | ||
| 152 | - | ||
| 153 | // publish | 143 | // publish |
| 154 | int duration_ms = 0; | 144 | int duration_ms = 0; |
| 155 | - if ((ret = publish_start(duration_ms)) != ERROR_SUCCESS) { | 145 | + int actual_play_kbps = 0; |
| 146 | + if ((ret = publish_start(duration_ms, actual_play_kbps)) != ERROR_SUCCESS) { | ||
| 156 | return ret; | 147 | return ret; |
| 157 | } | 148 | } |
| 158 | if ((ret = publish_checking(duration_ms, actual_play_kbps)) != ERROR_SUCCESS) { | 149 | if ((ret = publish_checking(duration_ms, actual_play_kbps)) != ERROR_SUCCESS) { |
| @@ -226,25 +217,13 @@ int SrsBandwidthClient::play_checking() | @@ -226,25 +217,13 @@ int SrsBandwidthClient::play_checking() | ||
| 226 | return ret; | 217 | return ret; |
| 227 | } | 218 | } |
| 228 | 219 | ||
| 229 | -int SrsBandwidthClient::play_stop(int& duration_delta, int& bytes_delta) | 220 | +int SrsBandwidthClient::play_stop() |
| 230 | { | 221 | { |
| 231 | int ret = ERROR_SUCCESS; | 222 | int ret = ERROR_SUCCESS; |
| 232 | 223 | ||
| 233 | - if (true) { | ||
| 234 | - SrsBandwidthPacket* pkt = NULL; | ||
| 235 | - if ((ret = _srs_expect_bandwidth_packet2(_rtmp, _bandwidth_is_stop_play, &pkt)) != ERROR_SUCCESS) { | 224 | + if ((ret = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stop_play)) != ERROR_SUCCESS) { |
| 236 | return ret; | 225 | return ret; |
| 237 | } | 226 | } |
| 238 | - SrsAutoFree(SrsBandwidthPacket, pkt); | ||
| 239 | - | ||
| 240 | - SrsAmf0Any* prop = NULL; | ||
| 241 | - if ((prop = pkt->data->ensure_property_number("duration_delta")) != NULL) { | ||
| 242 | - duration_delta = (int)prop->to_number(); | ||
| 243 | - } | ||
| 244 | - if ((prop = pkt->data->ensure_property_number("bytes_delta")) != NULL) { | ||
| 245 | - bytes_delta = (int)prop->to_number(); | ||
| 246 | - } | ||
| 247 | - } | ||
| 248 | srs_info("BW check recv play stop request."); | 227 | srs_info("BW check recv play stop request."); |
| 249 | 228 | ||
| 250 | if (true) { | 229 | if (true) { |
| @@ -261,7 +240,7 @@ int SrsBandwidthClient::play_stop(int& duration_delta, int& bytes_delta) | @@ -261,7 +240,7 @@ int SrsBandwidthClient::play_stop(int& duration_delta, int& bytes_delta) | ||
| 261 | return ret; | 240 | return ret; |
| 262 | } | 241 | } |
| 263 | 242 | ||
| 264 | -int SrsBandwidthClient::publish_start(int& duration_ms) | 243 | +int SrsBandwidthClient::publish_start(int& duration_ms, int& play_kbps) |
| 265 | { | 244 | { |
| 266 | int ret = ERROR_SUCCESS; | 245 | int ret = ERROR_SUCCESS; |
| 267 | 246 | ||
| @@ -276,6 +255,9 @@ int SrsBandwidthClient::publish_start(int& duration_ms) | @@ -276,6 +255,9 @@ int SrsBandwidthClient::publish_start(int& duration_ms) | ||
| 276 | if ((prop = pkt->data->ensure_property_number("duration_ms")) != NULL) { | 255 | if ((prop = pkt->data->ensure_property_number("duration_ms")) != NULL) { |
| 277 | duration_ms = (int)prop->to_number(); | 256 | duration_ms = (int)prop->to_number(); |
| 278 | } | 257 | } |
| 258 | + if ((prop = pkt->data->ensure_property_number("limit_kbps")) != NULL) { | ||
| 259 | + play_kbps = (int)prop->to_number(); | ||
| 260 | + } | ||
| 279 | } | 261 | } |
| 280 | srs_info("BW check recv publish begin request."); | 262 | srs_info("BW check recv publish begin request."); |
| 281 | 263 |
| @@ -73,11 +73,11 @@ private: | @@ -73,11 +73,11 @@ private: | ||
| 73 | */ | 73 | */ |
| 74 | virtual int play_start(); | 74 | virtual int play_start(); |
| 75 | virtual int play_checking(); | 75 | virtual int play_checking(); |
| 76 | - virtual int play_stop(int& duration_delta, int& bytes_delta); | 76 | + virtual int play_stop(); |
| 77 | /** | 77 | /** |
| 78 | * publish check/test, publishing bandwidth kbps. | 78 | * publish check/test, publishing bandwidth kbps. |
| 79 | */ | 79 | */ |
| 80 | - virtual int publish_start(int& duration_ms); | 80 | + virtual int publish_start(int& duration_ms, int& play_kbps); |
| 81 | virtual int publish_checking(int duration_ms, int play_kbps); | 81 | virtual int publish_checking(int duration_ms, int play_kbps); |
| 82 | virtual int publish_stop(); | 82 | virtual int publish_stop(); |
| 83 | /** | 83 | /** |
-
请 注册 或 登录 后发表评论