正在显示
2 个修改的文件
包含
104 行增加
和
40 行删除
| @@ -188,8 +188,16 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) | @@ -188,8 +188,16 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) | ||
| 188 | // sample play | 188 | // sample play |
| 189 | srs_info("start play test."); | 189 | srs_info("start play test."); |
| 190 | 190 | ||
| 191 | - if ((ret = check_play(&play_sample, limit)) != ERROR_SUCCESS) { | ||
| 192 | - srs_error("band width play check failed. ret=%d", ret); | 191 | + if ((ret = play_start(&play_sample, limit)) != ERROR_SUCCESS) { |
| 192 | + srs_error("bandwidth play check failed. ret=%d", ret); | ||
| 193 | + return ret; | ||
| 194 | + } | ||
| 195 | + if ((ret = play_checking(&play_sample, limit)) != ERROR_SUCCESS) { | ||
| 196 | + srs_error("bandwidth play check failed. ret=%d", ret); | ||
| 197 | + return ret; | ||
| 198 | + } | ||
| 199 | + if ((ret = play_stop(&play_sample, limit)) != ERROR_SUCCESS) { | ||
| 200 | + srs_error("bandwidth play check failed. ret=%d", ret); | ||
| 193 | return ret; | 201 | return ret; |
| 194 | } | 202 | } |
| 195 | 203 | ||
| @@ -198,8 +206,16 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) | @@ -198,8 +206,16 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) | ||
| 198 | // sample publish | 206 | // sample publish |
| 199 | srs_info("start publish test."); | 207 | srs_info("start publish test."); |
| 200 | 208 | ||
| 201 | - if ((ret = check_publish(&publish_sample, limit)) != ERROR_SUCCESS) { | ||
| 202 | - srs_error("band width publish check failed. ret=%d", ret); | 209 | + if ((ret = publish_start(&publish_sample, limit)) != ERROR_SUCCESS) { |
| 210 | + srs_error("bandwidth publish check failed. ret=%d", ret); | ||
| 211 | + return ret; | ||
| 212 | + } | ||
| 213 | + if ((ret = publish_checking(&publish_sample, limit)) != ERROR_SUCCESS) { | ||
| 214 | + srs_error("bandwidth publish check failed. ret=%d", ret); | ||
| 215 | + return ret; | ||
| 216 | + } | ||
| 217 | + if ((ret = publish_stop(&publish_sample, limit)) != ERROR_SUCCESS) { | ||
| 218 | + srs_error("bandwidth publish check failed. ret=%d", ret); | ||
| 203 | return ret; | 219 | return ret; |
| 204 | } | 220 | } |
| 205 | 221 | ||
| @@ -212,45 +228,19 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) | @@ -212,45 +228,19 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) | ||
| 212 | (int)(end_time - start_time), play_sample.actual_duration_ms, | 228 | (int)(end_time - start_time), play_sample.actual_duration_ms, |
| 213 | publish_sample.actual_duration_ms, play_sample.kbps, | 229 | publish_sample.actual_duration_ms, play_sample.kbps, |
| 214 | publish_sample.kbps); | 230 | publish_sample.kbps); |
| 215 | - | ||
| 216 | - // send finished msg, | ||
| 217 | - // flash client will close connection when got this packet, | ||
| 218 | - // for the publish queue may contains packets. | ||
| 219 | - SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_finish(); | ||
| 220 | - pkt->data->set("code", SrsAmf0Any::number(ERROR_SUCCESS)); | ||
| 221 | - pkt->data->set("start_time", SrsAmf0Any::number(start_time)); | ||
| 222 | - pkt->data->set("end_time", SrsAmf0Any::number(end_time)); | ||
| 223 | - pkt->data->set("play_kbps", SrsAmf0Any::number(play_sample.kbps)); | ||
| 224 | - pkt->data->set("publish_kbps", SrsAmf0Any::number(publish_sample.kbps)); | ||
| 225 | - pkt->data->set("play_bytes", SrsAmf0Any::number(play_sample.bytes)); | ||
| 226 | - pkt->data->set("publish_bytes", SrsAmf0Any::number(publish_sample.bytes)); | ||
| 227 | - pkt->data->set("play_time", SrsAmf0Any::number(play_sample.actual_duration_ms)); | ||
| 228 | - pkt->data->set("publish_time", SrsAmf0Any::number(publish_sample.actual_duration_ms)); | ||
| 229 | - | ||
| 230 | - if ((ret = _rtmp->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { | ||
| 231 | - srs_error("send bandwidth check finish message failed. ret=%d", ret); | ||
| 232 | - return ret; | ||
| 233 | - } | ||
| 234 | - srs_info("send finish packet."); | ||
| 235 | 231 | ||
| 236 | - // we notice the result, and expect a final packet if not flash. | ||
| 237 | - // if flash client, client will disconnect when got finish packet. | ||
| 238 | - bool is_flash = (_req->swfUrl != ""); | ||
| 239 | - if (!is_flash) { | ||
| 240 | - // ignore any error. | ||
| 241 | - _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_flash_final); | ||
| 242 | - srs_info("BW check recv flash final response."); | 232 | + if ((ret = finial(play_sample, publish_sample, start_time, end_time)) != ERROR_SUCCESS) { |
| 233 | + return ret; | ||
| 243 | } | 234 | } |
| 244 | - | ||
| 245 | srs_info("BW check finished."); | 235 | srs_info("BW check finished."); |
| 246 | 236 | ||
| 247 | return ret; | 237 | return ret; |
| 248 | } | 238 | } |
| 249 | 239 | ||
| 250 | -int SrsBandwidth::check_play(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | 240 | +int SrsBandwidth::play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) |
| 251 | { | 241 | { |
| 252 | int ret = ERROR_SUCCESS; | 242 | int ret = ERROR_SUCCESS; |
| 253 | - | 243 | + |
| 254 | if (true) { | 244 | if (true) { |
| 255 | // send start play command to client | 245 | // send start play command to client |
| 256 | SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_play(); | 246 | SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_play(); |
| @@ -269,6 +259,13 @@ int SrsBandwidth::check_play(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | @@ -269,6 +259,13 @@ int SrsBandwidth::check_play(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | ||
| 269 | return ret; | 259 | return ret; |
| 270 | } | 260 | } |
| 271 | srs_info("BW check recv play begin response."); | 261 | srs_info("BW check recv play begin response."); |
| 262 | + | ||
| 263 | + return ret; | ||
| 264 | +} | ||
| 265 | + | ||
| 266 | +int SrsBandwidth::play_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | ||
| 267 | +{ | ||
| 268 | + int ret = ERROR_SUCCESS; | ||
| 272 | 269 | ||
| 273 | // send play data to client | 270 | // send play data to client |
| 274 | int size = 1024; // TODO: FIXME: magic number | 271 | int size = 1024; // TODO: FIXME: magic number |
| @@ -301,6 +298,13 @@ int SrsBandwidth::check_play(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | @@ -301,6 +298,13 @@ int SrsBandwidth::check_play(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | ||
| 301 | } | 298 | } |
| 302 | sample->calc_kbps(_rtmp->get_send_bytes(), srs_get_system_time_ms() - starttime); | 299 | sample->calc_kbps(_rtmp->get_send_bytes(), srs_get_system_time_ms() - starttime); |
| 303 | srs_info("BW check send play bytes over."); | 300 | srs_info("BW check send play bytes over."); |
| 301 | + | ||
| 302 | + return ret; | ||
| 303 | +} | ||
| 304 | + | ||
| 305 | +int SrsBandwidth::play_stop(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | ||
| 306 | +{ | ||
| 307 | + int ret = ERROR_SUCCESS; | ||
| 304 | 308 | ||
| 305 | if (true) { | 309 | if (true) { |
| 306 | // notify client to stop play | 310 | // notify client to stop play |
| @@ -322,11 +326,11 @@ int SrsBandwidth::check_play(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | @@ -322,11 +326,11 @@ int SrsBandwidth::check_play(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | ||
| 322 | return ret; | 326 | return ret; |
| 323 | } | 327 | } |
| 324 | srs_info("BW check recv stop play response."); | 328 | srs_info("BW check recv stop play response."); |
| 325 | - | 329 | + |
| 326 | return ret; | 330 | return ret; |
| 327 | } | 331 | } |
| 328 | 332 | ||
| 329 | -int SrsBandwidth::check_publish(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | 333 | +int SrsBandwidth::publish_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit) |
| 330 | { | 334 | { |
| 331 | int ret = ERROR_SUCCESS; | 335 | int ret = ERROR_SUCCESS; |
| 332 | 336 | ||
| @@ -348,6 +352,13 @@ int SrsBandwidth::check_publish(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | @@ -348,6 +352,13 @@ int SrsBandwidth::check_publish(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | ||
| 348 | return ret; | 352 | return ret; |
| 349 | } | 353 | } |
| 350 | srs_info("BW check recv publish begin response."); | 354 | srs_info("BW check recv publish begin response."); |
| 355 | + | ||
| 356 | + return ret; | ||
| 357 | +} | ||
| 358 | + | ||
| 359 | +int SrsBandwidth::publish_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | ||
| 360 | +{ | ||
| 361 | + int ret = ERROR_SUCCESS; | ||
| 351 | 362 | ||
| 352 | // recv publish msgs until @duration_ms ms | 363 | // recv publish msgs until @duration_ms ms |
| 353 | int64_t starttime = srs_get_system_time_ms(); | 364 | int64_t starttime = srs_get_system_time_ms(); |
| @@ -365,6 +376,13 @@ int SrsBandwidth::check_publish(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | @@ -365,6 +376,13 @@ int SrsBandwidth::check_publish(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | ||
| 365 | } | 376 | } |
| 366 | sample->calc_kbps(_rtmp->get_recv_bytes(), srs_get_system_time_ms() - starttime); | 377 | sample->calc_kbps(_rtmp->get_recv_bytes(), srs_get_system_time_ms() - starttime); |
| 367 | srs_info("BW check recv publish data over."); | 378 | srs_info("BW check recv publish data over."); |
| 379 | + | ||
| 380 | + return ret; | ||
| 381 | +} | ||
| 382 | + | ||
| 383 | +int SrsBandwidth::publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | ||
| 384 | +{ | ||
| 385 | + int ret = ERROR_SUCCESS; | ||
| 368 | 386 | ||
| 369 | if (true) { | 387 | if (true) { |
| 370 | // notify client to stop publish | 388 | // notify client to stop publish |
| @@ -393,6 +411,44 @@ int SrsBandwidth::check_publish(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | @@ -393,6 +411,44 @@ int SrsBandwidth::check_publish(SrsBandwidthSample* sample, SrsKbpsLimit* limit) | ||
| 393 | } | 411 | } |
| 394 | srs_info("BW check recv stop publish response."); | 412 | srs_info("BW check recv stop publish response."); |
| 395 | } | 413 | } |
| 414 | + | ||
| 415 | + return ret; | ||
| 416 | +} | ||
| 417 | + | ||
| 418 | +int SrsBandwidth::finial(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, int64_t start_time, int64_t& end_time) | ||
| 419 | +{ | ||
| 420 | + int ret = ERROR_SUCCESS; | ||
| 421 | + | ||
| 422 | + // send finished msg, | ||
| 423 | + // flash client will close connection when got this packet, | ||
| 424 | + // for the publish queue may contains packets. | ||
| 425 | + SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_finish(); | ||
| 426 | + pkt->data->set("code", SrsAmf0Any::number(ERROR_SUCCESS)); | ||
| 427 | + pkt->data->set("start_time", SrsAmf0Any::number(start_time)); | ||
| 428 | + pkt->data->set("end_time", SrsAmf0Any::number(end_time)); | ||
| 429 | + pkt->data->set("play_kbps", SrsAmf0Any::number(play_sample.kbps)); | ||
| 430 | + pkt->data->set("publish_kbps", SrsAmf0Any::number(publish_sample.kbps)); | ||
| 431 | + pkt->data->set("play_bytes", SrsAmf0Any::number(play_sample.bytes)); | ||
| 432 | + pkt->data->set("publish_bytes", SrsAmf0Any::number(publish_sample.bytes)); | ||
| 433 | + pkt->data->set("play_time", SrsAmf0Any::number(play_sample.actual_duration_ms)); | ||
| 434 | + pkt->data->set("publish_time", SrsAmf0Any::number(publish_sample.actual_duration_ms)); | ||
| 435 | + | ||
| 436 | + if ((ret = _rtmp->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { | ||
| 437 | + srs_error("send bandwidth check finish message failed. ret=%d", ret); | ||
| 438 | + return ret; | ||
| 439 | + } | ||
| 440 | + srs_info("send finish packet."); | ||
| 441 | + | ||
| 442 | + // we notice the result, and expect a final packet if not flash. | ||
| 443 | + // if flash client, client will disconnect when got finish packet. | ||
| 444 | + bool is_flash = (_req->swfUrl != ""); | ||
| 445 | + if (!is_flash) { | ||
| 446 | + // ignore any error. | ||
| 447 | + _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_flash_final); | ||
| 448 | + srs_info("BW check recv flash final response."); | ||
| 449 | + } | ||
| 450 | + | ||
| 451 | + srs_info("BW check finished."); | ||
| 396 | 452 | ||
| 397 | return ret; | 453 | return ret; |
| 398 | } | 454 | } |
| @@ -138,13 +138,21 @@ private: | @@ -138,13 +138,21 @@ private: | ||
| 138 | */ | 138 | */ |
| 139 | virtual int do_bandwidth_check(SrsKbpsLimit* limit); | 139 | virtual int do_bandwidth_check(SrsKbpsLimit* limit); |
| 140 | /** | 140 | /** |
| 141 | - * play sample under specified kbps limit. | 141 | + * play check/test, downloading bandwidth kbps. |
| 142 | */ | 142 | */ |
| 143 | - virtual int check_play(SrsBandwidthSample* sample, SrsKbpsLimit* limit); | 143 | + virtual int play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit); |
| 144 | + virtual int play_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit); | ||
| 145 | + virtual int play_stop(SrsBandwidthSample* sample, SrsKbpsLimit* limit); | ||
| 144 | /** | 146 | /** |
| 145 | - * publish sample under specified kbps limit. | 147 | + * publish check/test, publishing bandwidth kbps. |
| 146 | */ | 148 | */ |
| 147 | - virtual int check_publish(SrsBandwidthSample* sample, SrsKbpsLimit* limit); | 149 | + virtual int publish_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit); |
| 150 | + virtual int publish_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit); | ||
| 151 | + virtual int publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit* limit); | ||
| 152 | + /** | ||
| 153 | + * report and final packet | ||
| 154 | + */ | ||
| 155 | + virtual int finial(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, int64_t start_time, int64_t& end_time); | ||
| 148 | }; | 156 | }; |
| 149 | 157 | ||
| 150 | #endif | 158 | #endif |
-
请 注册 或 登录 后发表评论