mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
add librtmp bandwidth check/test client.
This commit is contained in:
parent
cf7a48e3da
commit
cc62d254f0
20 changed files with 725 additions and 87 deletions
|
@ -95,6 +95,7 @@ SrsRequest* SrsRequest::copy()
|
|||
cp->pageUrl = pageUrl;
|
||||
cp->host = host;
|
||||
cp->port = port;
|
||||
cp->param = param;
|
||||
cp->schema = schema;
|
||||
cp->stream = stream;
|
||||
cp->swfUrl = swfUrl;
|
||||
|
@ -823,7 +824,9 @@ int SrsRtmpServer::connect_app(SrsRequest* req)
|
|||
|
||||
srs_info("get connect app message params success.");
|
||||
|
||||
srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->port);
|
||||
srs_discovery_tc_url(req->tcUrl,
|
||||
req->schema, req->host, req->vhost, req->app, req->port,
|
||||
req->param);
|
||||
req->strip();
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -67,10 +67,17 @@ public:
|
|||
public:
|
||||
// discovery from tcUrl and play/publish.
|
||||
std::string schema;
|
||||
// the vhost in tcUrl.
|
||||
std::string vhost;
|
||||
// the host in tcUrl.
|
||||
std::string host;
|
||||
// the port in tcUrl.
|
||||
std::string port;
|
||||
// the app in tcUrl, without param.
|
||||
std::string app;
|
||||
// the param in tcUrl(app).
|
||||
std::string param;
|
||||
// the stream in play/publish
|
||||
std::string stream;
|
||||
// for play live stream,
|
||||
// used to specified the stop when exceed the duration.
|
||||
|
|
|
@ -232,17 +232,16 @@ messages.
|
|||
#define SRS_BW_CHECK_START_PUBLISH "onSrsBandCheckStartPublishBytes"
|
||||
#define SRS_BW_CHECK_STARTING_PUBLISH "onSrsBandCheckStartingPublishBytes"
|
||||
#define SRS_BW_CHECK_STOP_PUBLISH "onSrsBandCheckStopPublishBytes"
|
||||
// @remark, flash never send out this packet, for its queue is full.
|
||||
#define SRS_BW_CHECK_STOPPED_PUBLISH "onSrsBandCheckStoppedPublishBytes"
|
||||
|
||||
// EOF control.
|
||||
// the report packet when check finished.
|
||||
#define SRS_BW_CHECK_FINISHED "onSrsBandCheckFinished"
|
||||
// for flash, it will sendout a final call,
|
||||
// used to confirm got the report.
|
||||
// actually, client send out this packet and close the connection,
|
||||
// so server may cannot got this packet, ignore is ok.
|
||||
#define SRS_BW_CHECK_FLASH_FINAL "finalClientPacket"
|
||||
// @remark, flash never send out this packet, for its queue is full.
|
||||
#define SRS_BW_CHECK_FINAL "finalClientPacket"
|
||||
|
||||
// client only
|
||||
// data packets
|
||||
#define SRS_BW_CHECK_PLAYING "onSrsBandCheckPlaying"
|
||||
#define SRS_BW_CHECK_PUBLISHING "onSrsBandCheckPublishing"
|
||||
|
||||
|
@ -688,7 +687,7 @@ int SrsProtocol::do_decode_message(SrsMessageHeader& header, SrsStream* stream,
|
|||
|| command == SRS_BW_CHECK_STOP_PLAY
|
||||
|| command == SRS_BW_CHECK_STOP_PUBLISH
|
||||
|| command == SRS_BW_CHECK_STOPPED_PUBLISH
|
||||
|| command == SRS_BW_CHECK_FLASH_FINAL)
|
||||
|| command == SRS_BW_CHECK_FINAL)
|
||||
{
|
||||
srs_info("decode the AMF0/AMF3 band width check message.");
|
||||
*ppacket = packet = new SrsBandwidthPacket();
|
||||
|
@ -3270,35 +3269,54 @@ int SrsBandwidthPacket::encode_packet(SrsStream* stream)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool SrsBandwidthPacket::is_start_play()
|
||||
{
|
||||
return command_name == SRS_BW_CHECK_START_PLAY;
|
||||
}
|
||||
|
||||
bool SrsBandwidthPacket::is_starting_play()
|
||||
{
|
||||
return command_name == SRS_BW_CHECK_STARTING_PLAY;
|
||||
}
|
||||
|
||||
bool SrsBandwidthPacket::is_stop_play()
|
||||
{
|
||||
return command_name == SRS_BW_CHECK_STOP_PLAY;
|
||||
}
|
||||
|
||||
bool SrsBandwidthPacket::is_stopped_play()
|
||||
{
|
||||
return command_name == SRS_BW_CHECK_STOPPED_PLAY;
|
||||
}
|
||||
|
||||
bool SrsBandwidthPacket::is_start_publish()
|
||||
{
|
||||
return command_name == SRS_BW_CHECK_START_PUBLISH;
|
||||
}
|
||||
|
||||
bool SrsBandwidthPacket::is_starting_publish()
|
||||
{
|
||||
return command_name == SRS_BW_CHECK_STARTING_PUBLISH;
|
||||
}
|
||||
|
||||
bool SrsBandwidthPacket::is_stop_publish()
|
||||
{
|
||||
return command_name == SRS_BW_CHECK_STOP_PUBLISH;
|
||||
}
|
||||
|
||||
bool SrsBandwidthPacket::is_stopped_publish()
|
||||
{
|
||||
return command_name == SRS_BW_CHECK_STOPPED_PUBLISH;
|
||||
}
|
||||
|
||||
bool SrsBandwidthPacket::is_flash_final()
|
||||
bool SrsBandwidthPacket::is_finish()
|
||||
{
|
||||
return command_name == SRS_BW_CHECK_FLASH_FINAL;
|
||||
return command_name == SRS_BW_CHECK_FINISHED;
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::create_finish()
|
||||
bool SrsBandwidthPacket::is_final()
|
||||
{
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
return pkt->set_command(SRS_BW_CHECK_FINISHED);
|
||||
return command_name == SRS_BW_CHECK_FINAL;
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::create_start_play()
|
||||
|
@ -3307,6 +3325,12 @@ SrsBandwidthPacket* SrsBandwidthPacket::create_start_play()
|
|||
return pkt->set_command(SRS_BW_CHECK_START_PLAY);
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::create_starting_play()
|
||||
{
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
return pkt->set_command(SRS_BW_CHECK_STARTING_PLAY);
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::create_playing()
|
||||
{
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
|
@ -3325,12 +3349,36 @@ SrsBandwidthPacket* SrsBandwidthPacket::create_start_publish()
|
|||
return pkt->set_command(SRS_BW_CHECK_START_PUBLISH);
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::create_starting_publish()
|
||||
{
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
return pkt->set_command(SRS_BW_CHECK_STARTING_PUBLISH);
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::create_publishing()
|
||||
{
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
return pkt->set_command(SRS_BW_CHECK_PUBLISHING);
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::create_stop_publish()
|
||||
{
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
return pkt->set_command(SRS_BW_CHECK_STOP_PUBLISH);
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::create_finish()
|
||||
{
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
return pkt->set_command(SRS_BW_CHECK_FINISHED);
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::create_final()
|
||||
{
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
return pkt->set_command(SRS_BW_CHECK_FINAL);
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::set_command(string command)
|
||||
{
|
||||
command_name = command;
|
||||
|
|
|
@ -1230,17 +1230,26 @@ protected:
|
|||
virtual int encode_packet(SrsStream* stream);
|
||||
// help function for bandwidth packet.
|
||||
public:
|
||||
virtual bool is_start_play();
|
||||
virtual bool is_starting_play();
|
||||
virtual bool is_stop_play();
|
||||
virtual bool is_stopped_play();
|
||||
virtual bool is_start_publish();
|
||||
virtual bool is_starting_publish();
|
||||
virtual bool is_stop_publish();
|
||||
virtual bool is_stopped_publish();
|
||||
virtual bool is_flash_final();
|
||||
static SrsBandwidthPacket* create_finish();
|
||||
virtual bool is_finish();
|
||||
virtual bool is_final();
|
||||
static SrsBandwidthPacket* create_start_play();
|
||||
static SrsBandwidthPacket* create_starting_play();
|
||||
static SrsBandwidthPacket* create_playing();
|
||||
static SrsBandwidthPacket* create_stop_play();
|
||||
static SrsBandwidthPacket* create_start_publish();
|
||||
static SrsBandwidthPacket* create_starting_publish();
|
||||
static SrsBandwidthPacket* create_publishing();
|
||||
static SrsBandwidthPacket* create_stop_publish();
|
||||
static SrsBandwidthPacket* create_finish();
|
||||
static SrsBandwidthPacket* create_final();
|
||||
private:
|
||||
virtual SrsBandwidthPacket* set_command(std::string command);
|
||||
};
|
||||
|
|
|
@ -32,7 +32,7 @@ using namespace std;
|
|||
void srs_discovery_tc_url(
|
||||
string tcUrl,
|
||||
string& schema, string& host, string& vhost,
|
||||
string& app, string& port
|
||||
string& app, string& port, std::string& param
|
||||
) {
|
||||
size_t pos = std::string::npos;
|
||||
std::string url = tcUrl;
|
||||
|
@ -58,16 +58,23 @@ void srs_discovery_tc_url(
|
|||
|
||||
app = url;
|
||||
vhost = host;
|
||||
srs_vhost_resolve(vhost, app);
|
||||
srs_vhost_resolve(vhost, app, param);
|
||||
}
|
||||
|
||||
void srs_vhost_resolve(string& vhost, string& app)
|
||||
void srs_vhost_resolve(string& vhost, string& app, string& param)
|
||||
{
|
||||
// get original param
|
||||
size_t pos = 0;
|
||||
if ((pos = app.find("?")) != std::string::npos) {
|
||||
param = app.substr(pos);
|
||||
}
|
||||
|
||||
// filter tcUrl
|
||||
app = srs_string_replace(app, ",", "?");
|
||||
app = srs_string_replace(app, "...", "?");
|
||||
app = srs_string_replace(app, "&&", "?");
|
||||
app = srs_string_replace(app, "=", "?");
|
||||
|
||||
size_t pos = 0;
|
||||
if ((pos = app.find("?")) == std::string::npos) {
|
||||
return;
|
||||
}
|
||||
|
@ -106,7 +113,7 @@ void srs_random_generate(char* bytes, int size)
|
|||
}
|
||||
}
|
||||
|
||||
string srs_generate_tc_url(string ip, string vhost, string app, string port)
|
||||
string srs_generate_tc_url(string ip, string vhost, string app, string port, string param)
|
||||
{
|
||||
string tcUrl = "rtmp://";
|
||||
|
||||
|
@ -123,6 +130,7 @@ string srs_generate_tc_url(string ip, string vhost, string app, string port)
|
|||
|
||||
tcUrl += "/";
|
||||
tcUrl += app;
|
||||
tcUrl += param;
|
||||
|
||||
return tcUrl;
|
||||
}
|
||||
|
|
|
@ -50,20 +50,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
* @param app, for example, live
|
||||
* @param port, for example, 19350
|
||||
* default to 1935 if not specified.
|
||||
* param param, for example, vhost=vhost.ossrs.net
|
||||
*/
|
||||
extern void srs_discovery_tc_url(
|
||||
std::string tcUrl,
|
||||
std::string& schema, std::string& host, std::string& vhost,
|
||||
std::string& app, std::string& port
|
||||
std::string& app, std::string& port, std::string& param
|
||||
);
|
||||
|
||||
/**
|
||||
* resolve the vhost in query string
|
||||
* @pram vhost, update the vhost if query contains the vhost.
|
||||
* @param app, may contains the vhost in query string format:
|
||||
* app?vhost=request_vhost
|
||||
* app...vhost...request_vhost
|
||||
* @param param, the query, for example, ?vhost=xxx
|
||||
*/
|
||||
extern void srs_vhost_resolve(std::string& vhost, std::string& app);
|
||||
extern void srs_vhost_resolve(std::string& vhost, std::string& app, std::string& param);
|
||||
|
||||
/**
|
||||
* generate ramdom data for handshake.
|
||||
|
@ -72,12 +75,14 @@ extern void srs_random_generate(char* bytes, int size);
|
|||
|
||||
/**
|
||||
* generate the tcUrl.
|
||||
* @param param, the app parameters in tcUrl. for example, ?key=xxx,vhost=xxx
|
||||
* @return the tcUrl generated from ip/vhost/app/port.
|
||||
* @remark when vhost equals to __defaultVhost__, use ip as vhost.
|
||||
* @remark ignore port if port equals to default port 1935.
|
||||
*/
|
||||
extern std::string srs_generate_tc_url(
|
||||
std::string ip, std::string vhost, std::string app, std::string port
|
||||
std::string ip, std::string vhost, std::string app, std::string port,
|
||||
std::string param
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue