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{
|
private function publisher():void{
|
||||||
var data:Array = new Array();
|
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++) {
|
for(var i:int; i < data_size; i++) {
|
||||||
data.push("SrS band check data from client's publishing......");
|
data.push("SrS band check data from client's publishing......");
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,9 @@ using namespace std;
|
||||||
// default sample duration, in ms
|
// default sample duration, in ms
|
||||||
#define _SRS_BANDWIDTH_SAMPLE_DURATION_MS 3000
|
#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()
|
SrsBandwidthSample::SrsBandwidthSample()
|
||||||
{
|
{
|
||||||
duration_ms = _SRS_BANDWIDTH_SAMPLE_DURATION_MS;
|
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) {
|
if ((ret = finial(play_sample, publish_sample, start_time, end_time)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
st_usleep(_SRS_BANDWIDTH_FINAL_WAIT_MS * 1000);
|
||||||
srs_info("BW check finished.");
|
srs_info("BW check finished.");
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -254,6 +259,7 @@ int SrsBandwidth::play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit)
|
||||||
// send start play command to client
|
// send start play command to client
|
||||||
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("duration_ms", SrsAmf0Any::number(sample->duration_ms));
|
pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms));
|
||||||
pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_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
|
// notify client to start publish
|
||||||
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("duration_ms", SrsAmf0Any::number(sample->duration_ms));
|
pkt->data->set("duration_ms", SrsAmf0Any::number(sample->duration_ms));
|
||||||
pkt->data->set("interval_ms", SrsAmf0Any::number(sample->interval_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()
|
void SrsKbpsLimit::recv_limit()
|
||||||
{
|
{
|
||||||
_kbps->sample();
|
_kbps->sample();
|
||||||
|
|
|
@ -210,6 +210,10 @@ public:
|
||||||
SrsKbpsLimit(SrsKbps* kbps, int limit_kbps);
|
SrsKbpsLimit(SrsKbps* kbps, int limit_kbps);
|
||||||
virtual ~SrsKbpsLimit();
|
virtual ~SrsKbpsLimit();
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* get the system limit kbps.
|
||||||
|
*/
|
||||||
|
virtual int limit_kbps();
|
||||||
/**
|
/**
|
||||||
* limit the recv bandwidth.
|
* limit the recv bandwidth.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -130,29 +130,20 @@ int SrsBandwidthClient::bandwidth_check(
|
||||||
*start_time = srs_get_system_time_ms();
|
*start_time = srs_get_system_time_ms();
|
||||||
|
|
||||||
// play
|
// play
|
||||||
int duration_delta = 0;
|
|
||||||
int bytes_delta = 0;
|
|
||||||
if ((ret = play_start()) != ERROR_SUCCESS) {
|
if ((ret = play_start()) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if ((ret = play_checking()) != ERROR_SUCCESS) {
|
if ((ret = play_checking()) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if ((ret = play_stop(duration_delta, bytes_delta)) != ERROR_SUCCESS) {
|
if ((ret = play_stop()) != ERROR_SUCCESS) {
|
||||||
return ret;
|
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
|
// publish
|
||||||
int duration_ms = 0;
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
if ((ret = publish_checking(duration_ms, actual_play_kbps)) != ERROR_SUCCESS) {
|
if ((ret = publish_checking(duration_ms, actual_play_kbps)) != ERROR_SUCCESS) {
|
||||||
|
@ -226,25 +217,13 @@ int SrsBandwidthClient::play_checking()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsBandwidthClient::play_stop(int& duration_delta, int& bytes_delta)
|
int SrsBandwidthClient::play_stop()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (true) {
|
if ((ret = _srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stop_play)) != ERROR_SUCCESS) {
|
||||||
SrsBandwidthPacket* pkt = NULL;
|
|
||||||
if ((ret = _srs_expect_bandwidth_packet2(_rtmp, _bandwidth_is_stop_play, &pkt)) != ERROR_SUCCESS) {
|
|
||||||
return ret;
|
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.");
|
srs_info("BW check recv play stop request.");
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -261,7 +240,7 @@ int SrsBandwidthClient::play_stop(int& duration_delta, int& bytes_delta)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsBandwidthClient::publish_start(int& duration_ms)
|
int SrsBandwidthClient::publish_start(int& duration_ms, int& play_kbps)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
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) {
|
if ((prop = pkt->data->ensure_property_number("duration_ms")) != NULL) {
|
||||||
duration_ms = (int)prop->to_number();
|
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.");
|
srs_info("BW check recv publish begin request.");
|
||||||
|
|
||||||
|
|
|
@ -73,11 +73,11 @@ private:
|
||||||
*/
|
*/
|
||||||
virtual int play_start();
|
virtual int play_start();
|
||||||
virtual int play_checking();
|
virtual int play_checking();
|
||||||
virtual int play_stop(int& duration_delta, int& bytes_delta);
|
virtual int play_stop();
|
||||||
/**
|
/**
|
||||||
* publish check/test, publishing bandwidth kbps.
|
* 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_checking(int duration_ms, int play_kbps);
|
||||||
virtual int publish_stop();
|
virtual int publish_stop();
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue