mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine bandwidth check/test, flash publish test is ok.
This commit is contained in:
parent
b3d3f9ce35
commit
5c4398f4a9
7 changed files with 49 additions and 31 deletions
Binary file not shown.
|
@ -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......");
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -257,6 +257,11 @@ SrsKbpsLimit::~SrsKbpsLimit()
|
|||
{
|
||||
}
|
||||
|
||||
int SrsKbpsLimit::limit_kbps()
|
||||
{
|
||||
return _limit_kbps;
|
||||
}
|
||||
|
||||
void SrsKbpsLimit::recv_limit()
|
||||
{
|
||||
_kbps->sample();
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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,25 +217,13 @@ 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) {
|
||||
if ((ret = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stop_play)) != 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();
|
||||
}
|
||||
}
|
||||
srs_info("BW check recv play stop request.");
|
||||
|
||||
if (true) {
|
||||
|
@ -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.");
|
||||
|
||||
|
|
|
@ -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();
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue