mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Remove bandwidth check because falsh is disabled. v5.0.52
This commit is contained in:
parent
1630918b0f
commit
937605b18c
16 changed files with 5 additions and 1490 deletions
|
@ -5,7 +5,7 @@
|
|||
# $SRS_OBJS_DIR the objs directory for Makefile. ie. objs
|
||||
# $SRS_MAKEFILE the makefile name. ie. Makefile
|
||||
#
|
||||
# $MAIN_ENTRANCES array, disable all except the $APP_MAIN itself. ie. ["srs_main_server" "srs_main_bandcheck"]
|
||||
# $MAIN_ENTRANCES array, disable all except the $APP_MAIN itself. ie. ["srs_main_server"]
|
||||
# $APP_MAIN the object file that contains main function. ie. srs_main_server
|
||||
# $BUILD_KEY a string indicates the build key for Makefile. ie. srs
|
||||
# $APP_NAME the app name to output. ie. srs
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
# bandwidth test tool config for srs.
|
||||
# @see full.conf for detail config.
|
||||
|
||||
listen 1935;
|
||||
max_connections 1000;
|
||||
daemon off;
|
||||
srs_log_tank console;
|
||||
vhost __defaultVhost__ {
|
||||
}
|
||||
|
||||
vhost bandcheck.srs.com {
|
||||
enabled on;
|
||||
chunk_size 65000;
|
||||
bandcheck {
|
||||
enabled on;
|
||||
key "35c9b402c12a7246868752e2878f7e0e";
|
||||
interval 30;
|
||||
limit_kbps 4000;
|
||||
}
|
||||
}
|
|
@ -26,17 +26,6 @@ vhost __defaultVhost__ {
|
|||
gop_cache on;
|
||||
}
|
||||
|
||||
vhost bandcheck.srs.com {
|
||||
enabled on;
|
||||
chunk_size 65000;
|
||||
bandcheck {
|
||||
enabled on;
|
||||
key "35c9b402c12a7246868752e2878f7e0e";
|
||||
interval 30;
|
||||
limit_kbps 4000;
|
||||
}
|
||||
}
|
||||
|
||||
vhost demo.srs.com {
|
||||
chunk_size 60000;
|
||||
enabled on;
|
||||
|
@ -46,9 +35,6 @@ vhost demo.srs.com {
|
|||
enabled on;
|
||||
destination 127.0.0.1:19350;
|
||||
}
|
||||
bandcheck {
|
||||
enabled off;
|
||||
}
|
||||
hls {
|
||||
enabled on;
|
||||
hls_path ./objs/nginx/html;
|
||||
|
|
2
trunk/configure
vendored
2
trunk/configure
vendored
|
@ -255,7 +255,7 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then
|
|||
fi
|
||||
MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_source"
|
||||
"srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder" "srs_app_http_stream"
|
||||
"srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config" "srs_app_tencentcloud"
|
||||
"srs_app_st" "srs_app_log" "srs_app_config" "srs_app_tencentcloud"
|
||||
"srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks"
|
||||
"srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_edge"
|
||||
"srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_http_static"
|
||||
|
|
|
@ -7,6 +7,7 @@ The changelog for SRS.
|
|||
|
||||
## SRS 5.0 Changelog
|
||||
|
||||
* v5.0, 2022-08-30, Remove bandwidth check because falsh is disabled. v5.0.52
|
||||
* v5.0, 2022-08-30, Refactor: Use compositor for ISrsKbpsDelta. v5.0.51
|
||||
* v5.0, 2022-08-29, RTC: Stat the WebRTC clients bandwidth. v5.0.50
|
||||
* v5.0, 2022-08-29, HLS: Stat the HLS streaming clients bandwidth. v5.0.49
|
||||
|
|
|
@ -1,451 +0,0 @@
|
|||
//
|
||||
// Copyright (c) 2013-2022 The SRS Authors
|
||||
//
|
||||
// SPDX-License-Identifier: MIT or MulanPSL-2.0
|
||||
//
|
||||
|
||||
#include <srs_app_bandwidth.hpp>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <srs_protocol_rtmp_stack.hpp>
|
||||
#include <srs_protocol_amf0.hpp>
|
||||
#include <srs_app_config.hpp>
|
||||
#include <srs_core_autofree.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
#include <srs_app_utility.hpp>
|
||||
#include <srs_protocol_kbps.hpp>
|
||||
#include <srs_app_st.hpp>
|
||||
|
||||
#define _SRS_BANDWIDTH_LIMIT_INTERVAL 100 * SRS_UTIME_MILLISECONDS
|
||||
|
||||
// default sample duration, in ms
|
||||
#define _SRS_BANDWIDTH_SAMPLE_DURATION 3000 * SRS_UTIME_MILLISECONDS
|
||||
|
||||
// wait for a while for flash to got all packets.
|
||||
#define _SRS_BANDWIDTH_FINAL_WAIT 600 * SRS_UTIME_MILLISECONDS
|
||||
|
||||
SrsBandwidthSample::SrsBandwidthSample()
|
||||
{
|
||||
duration = _SRS_BANDWIDTH_SAMPLE_DURATION;
|
||||
kbps = interval = actual_duration = bytes = 0;
|
||||
}
|
||||
|
||||
SrsBandwidthSample::~SrsBandwidthSample()
|
||||
{
|
||||
}
|
||||
|
||||
void SrsBandwidthSample::calc_kbps(int _bytes, srs_utime_t _duration)
|
||||
{
|
||||
bytes = _bytes;
|
||||
actual_duration = _duration;
|
||||
|
||||
if (actual_duration <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
kbps = bytes * 8 / srsu2ms(actual_duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* recv bandwidth helper.
|
||||
*/
|
||||
typedef bool (*_CheckPacketType)(SrsBandwidthPacket* pkt);
|
||||
bool _bandwidth_is_final(SrsBandwidthPacket* pkt)
|
||||
{
|
||||
return pkt->is_final();
|
||||
}
|
||||
bool _bandwidth_is_starting_play(SrsBandwidthPacket* pkt)
|
||||
{
|
||||
return pkt->is_starting_play();
|
||||
}
|
||||
bool _bandwidth_is_stopped_play(SrsBandwidthPacket* pkt)
|
||||
{
|
||||
return pkt->is_stopped_play();
|
||||
}
|
||||
bool _bandwidth_is_starting_publish(SrsBandwidthPacket* pkt)
|
||||
{
|
||||
return pkt->is_starting_publish();
|
||||
}
|
||||
bool _bandwidth_is_stopped_publish(SrsBandwidthPacket* pkt)
|
||||
{
|
||||
return pkt->is_stopped_publish();
|
||||
}
|
||||
srs_error_t srs_expect_bandwidth_packet(SrsRtmpServer* rtmp, _CheckPacketType pfn)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
while (true) {
|
||||
SrsCommonMessage* msg = NULL;
|
||||
SrsBandwidthPacket* pkt = NULL;
|
||||
if ((err = rtmp->expect_message<SrsBandwidthPacket>(&msg, &pkt)) != srs_success) {
|
||||
return srs_error_wrap(err, "expect message");
|
||||
}
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
SrsAutoFree(SrsBandwidthPacket, pkt);
|
||||
|
||||
if (pfn(pkt)) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
SrsBandwidth::SrsBandwidth()
|
||||
{
|
||||
_req = NULL;
|
||||
_rtmp = NULL;
|
||||
}
|
||||
|
||||
SrsBandwidth::~SrsBandwidth()
|
||||
{
|
||||
}
|
||||
|
||||
srs_error_t SrsBandwidth::bandwidth_check(SrsRtmpServer* rtmp, ISrsProtocolStatistic* io_stat, SrsRequest* req, string local_ip)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
_rtmp = rtmp;
|
||||
_req = req;
|
||||
|
||||
if (!_srs_config->get_bw_check_enabled(_req->vhost)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// validate the bandwidth check key
|
||||
std::string key = "key=" + _srs_config->get_bw_check_key(_req->vhost);
|
||||
if (_req->tcUrl.find(key) == std::string::npos) {
|
||||
return srs_error_new(ERROR_SYSTEM_BANDWIDTH_KEY, "check the vhost=%s %s failed, tcUrl=%s",
|
||||
_req->vhost.c_str(), key.c_str(), _req->tcUrl.c_str());
|
||||
}
|
||||
|
||||
// shared global last check time,
|
||||
// to prevent bandwidth check attack,
|
||||
// if client request check in the window(specifeid by interval),
|
||||
// directly reject the request.
|
||||
static srs_utime_t last_check_time = 0;
|
||||
srs_utime_t interval = _srs_config->get_bw_check_interval(_req->vhost);
|
||||
|
||||
srs_utime_t time_now = srs_update_system_time();
|
||||
// reject the connection in the interval window.
|
||||
if (last_check_time > 0 && time_now - last_check_time < interval) {
|
||||
_rtmp->response_connect_reject(_req, "bandcheck rejected");
|
||||
return srs_error_new(ERROR_SYSTEM_BANDWIDTH_DENIED, "reject, last_check=%" PRId64 ", now=%" PRId64 ", interval=%" PRId64 "", last_check_time, time_now, interval);
|
||||
}
|
||||
|
||||
// accept and do bandwidth check.
|
||||
last_check_time = time_now;
|
||||
|
||||
if ((err = _rtmp->response_connect_app(_req, local_ip.c_str())) != srs_success) {
|
||||
return srs_error_wrap(err, "response connect app");
|
||||
}
|
||||
|
||||
// create a limit object.
|
||||
SrsWallClock clk;
|
||||
SrsKbps kbps(&clk);
|
||||
kbps.set_io(io_stat, io_stat);
|
||||
|
||||
int limit_kbps = _srs_config->get_bw_check_limit_kbps(_req->vhost);
|
||||
SrsKbpsLimit limit(&kbps, limit_kbps);
|
||||
|
||||
return do_bandwidth_check(&limit);
|
||||
}
|
||||
|
||||
srs_error_t SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
SrsBandwidthSample play_sample;
|
||||
SrsBandwidthSample publish_sample;
|
||||
|
||||
// timeout for a packet.
|
||||
_rtmp->set_send_timeout(play_sample.duration * 2);
|
||||
_rtmp->set_recv_timeout(publish_sample.duration * 2);
|
||||
|
||||
// start test.
|
||||
srs_utime_t start_time = srs_update_system_time();
|
||||
|
||||
// sample play
|
||||
if ((err = play_start(&play_sample, limit)) != srs_success) {
|
||||
return srs_error_wrap(err, "play start");
|
||||
}
|
||||
if ((err = play_checking(&play_sample, limit)) != srs_success) {
|
||||
return srs_error_wrap(err, "play check");
|
||||
}
|
||||
if ((err = play_stop(&play_sample, limit)) != srs_success) {
|
||||
return srs_error_wrap(err, "play stop");
|
||||
}
|
||||
|
||||
// sample publish
|
||||
if ((err = publish_start(&publish_sample, limit)) != srs_success) {
|
||||
return srs_error_wrap(err, "publish start");
|
||||
}
|
||||
if ((err = publish_checking(&publish_sample, limit)) != srs_success) {
|
||||
return srs_error_wrap(err, "publish check");
|
||||
}
|
||||
if ((err = publish_stop(&publish_sample, limit)) != srs_success) {
|
||||
return srs_error_wrap(err, "publish stop");
|
||||
}
|
||||
|
||||
// stop test.
|
||||
srs_utime_t end_time = srs_update_system_time();
|
||||
|
||||
if ((err = do_final(play_sample, publish_sample, start_time, end_time)) != srs_success) {
|
||||
return srs_error_wrap(err, "final");
|
||||
}
|
||||
|
||||
srs_trace("bandwidth ok. duartion=%dms(%d+%d), play=%dkbps, publish=%dkbps",
|
||||
srsu2msi(end_time - start_time), srsu2msi(play_sample.actual_duration), srsu2msi(publish_sample.actual_duration),
|
||||
play_sample.kbps, publish_sample.kbps);
|
||||
|
||||
srs_usleep(_SRS_BANDWIDTH_FINAL_WAIT);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsBandwidth::play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
// 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(srsu2msi(sample->duration)));
|
||||
pkt->data->set("interval_ms", SrsAmf0Any::number(srsu2msi(sample->interval)));
|
||||
|
||||
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
||||
return srs_error_wrap(err, "send packet");
|
||||
}
|
||||
}
|
||||
|
||||
if ((err = srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_play)) != srs_success) {
|
||||
return srs_error_wrap(err, "expect bandwidth");
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsBandwidth::play_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// send play data to client
|
||||
int size = 1024; // TODO: FIXME: magic number
|
||||
char random_data[size];
|
||||
memset(random_data, 'A', size);
|
||||
|
||||
int data_count = 1;
|
||||
srs_utime_t starttime = srs_update_system_time();
|
||||
while (srs_get_system_time() - starttime < sample->duration) {
|
||||
srs_usleep(sample->interval);
|
||||
|
||||
// TODO: FIXME: use shared ptr message.
|
||||
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_playing();
|
||||
|
||||
// TODO: FIXME: magic number
|
||||
for (int i = 0; i < data_count; ++i) {
|
||||
std::stringstream seq;
|
||||
seq << i;
|
||||
std::string play_data = "SRS band check data from server's playing......";
|
||||
pkt->data->set(seq.str(), SrsAmf0Any::str(play_data.c_str()));
|
||||
}
|
||||
data_count += 2;
|
||||
|
||||
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
||||
return srs_error_wrap(err, "send packet");
|
||||
}
|
||||
|
||||
limit->send_limit();
|
||||
}
|
||||
srs_update_system_time();
|
||||
sample->calc_kbps((int)_rtmp->get_send_bytes(), srs_get_system_time() - starttime);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsBandwidth::play_stop(SrsBandwidthSample* sample, SrsKbpsLimit* /*limit*/)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
// notify client to stop play
|
||||
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_stop_play();
|
||||
|
||||
pkt->data->set("duration_ms", SrsAmf0Any::number(srsu2msi(sample->duration)));
|
||||
pkt->data->set("interval_ms", SrsAmf0Any::number(srsu2msi(sample->interval)));
|
||||
pkt->data->set("duration_delta", SrsAmf0Any::number(srsu2msi(sample->actual_duration)));
|
||||
pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes));
|
||||
|
||||
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
||||
return srs_error_wrap(err, "send packet");
|
||||
}
|
||||
}
|
||||
|
||||
if ((err = srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_play)) != srs_success) {
|
||||
return srs_error_wrap(err, "expect bandwidth");
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsBandwidth::publish_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
// 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(srsu2msi(sample->duration)));
|
||||
pkt->data->set("interval_ms", SrsAmf0Any::number(srsu2msi(sample->interval)));
|
||||
|
||||
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
||||
return srs_error_wrap(err, "send packet");
|
||||
}
|
||||
}
|
||||
|
||||
if ((err = srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_starting_publish)) != srs_success) {
|
||||
return srs_error_wrap(err, "expect packet");
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsBandwidth::publish_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// recv publish msgs until @duration ms
|
||||
srs_utime_t starttime = srs_update_system_time();
|
||||
while (srs_get_system_time() - starttime < sample->duration) {
|
||||
SrsCommonMessage* msg = NULL;
|
||||
SrsBandwidthPacket* pkt = NULL;
|
||||
if ((err = _rtmp->expect_message<SrsBandwidthPacket>(&msg, &pkt)) != srs_success) {
|
||||
return srs_error_wrap(err, "expect message");
|
||||
}
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
SrsAutoFree(SrsBandwidthPacket, pkt);
|
||||
srs_info("get publish message success.");
|
||||
|
||||
// client requires to stop.
|
||||
if (pkt->is_stop_publish()) {
|
||||
break;
|
||||
}
|
||||
|
||||
limit->recv_limit();
|
||||
}
|
||||
srs_update_system_time();
|
||||
sample->calc_kbps((int)_rtmp->get_recv_bytes(), srs_get_system_time() - starttime);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsBandwidth::publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit* /*limit*/)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
// notify client to stop publish
|
||||
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_stop_publish();
|
||||
pkt->data->set("duration_ms", SrsAmf0Any::number(srsu2msi(sample->duration)));
|
||||
pkt->data->set("interval_ms", SrsAmf0Any::number(srsu2msi(sample->interval)));
|
||||
pkt->data->set("duration_delta", SrsAmf0Any::number(srsu2msi(sample->actual_duration)));
|
||||
pkt->data->set("bytes_delta", SrsAmf0Any::number(sample->bytes));
|
||||
|
||||
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
||||
return srs_error_wrap(err, "send packet");
|
||||
}
|
||||
}
|
||||
|
||||
// expect client to stop publish
|
||||
// if flash client, we never expect the client stop publish bytes,
|
||||
// for the flash send call packet to test publish bandwidth,
|
||||
// there are many many packets in the queue.
|
||||
// we just ignore the packet and send the bandwidth test data.
|
||||
bool is_flash = (_req->swfUrl != "");
|
||||
if (!is_flash) {
|
||||
if ((err = srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_stopped_publish)) != srs_success) {
|
||||
return srs_error_wrap(err, "expect bandwidth");
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsBandwidth::do_final(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, srs_utime_t start_time, srs_utime_t& end_time)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// send finished msg,
|
||||
// flash client will close connection when got this packet,
|
||||
// for the publish queue may contains packets.
|
||||
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_finish();
|
||||
pkt->data->set("start_time", SrsAmf0Any::number(srsu2ms(start_time)));
|
||||
pkt->data->set("end_time", SrsAmf0Any::number(srsu2ms(end_time)));
|
||||
pkt->data->set("play_kbps", SrsAmf0Any::number(play_sample.kbps));
|
||||
pkt->data->set("publish_kbps", SrsAmf0Any::number(publish_sample.kbps));
|
||||
pkt->data->set("play_bytes", SrsAmf0Any::number(play_sample.bytes));
|
||||
pkt->data->set("publish_bytes", SrsAmf0Any::number(publish_sample.bytes));
|
||||
pkt->data->set("play_time", SrsAmf0Any::number(srsu2msi(play_sample.actual_duration)));
|
||||
pkt->data->set("publish_time", SrsAmf0Any::number(srsu2msi(publish_sample.actual_duration)));
|
||||
|
||||
if ((err = _rtmp->send_and_free_packet(pkt, 0)) != srs_success) {
|
||||
return srs_error_wrap(err, "send packet");
|
||||
}
|
||||
|
||||
// we notice the result, and expect a final packet if not flash.
|
||||
// if flash client, client will disconnect when got finish packet.
|
||||
bool is_flash = (_req->swfUrl != "");
|
||||
if (!is_flash) {
|
||||
// ignore any error.
|
||||
err = srs_expect_bandwidth_packet(_rtmp, _bandwidth_is_final);
|
||||
srs_error_reset(err);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
SrsKbpsLimit::SrsKbpsLimit(SrsKbps* kbps, int limit_kbps)
|
||||
{
|
||||
_kbps = kbps;
|
||||
_limit_kbps = limit_kbps;
|
||||
}
|
||||
|
||||
SrsKbpsLimit::~SrsKbpsLimit()
|
||||
{
|
||||
}
|
||||
|
||||
int SrsKbpsLimit::limit_kbps()
|
||||
{
|
||||
return _limit_kbps;
|
||||
}
|
||||
|
||||
void SrsKbpsLimit::recv_limit()
|
||||
{
|
||||
_kbps->sample();
|
||||
|
||||
while (_kbps->get_recv_kbps() > _limit_kbps) {
|
||||
_kbps->sample();
|
||||
|
||||
srs_usleep(_SRS_BANDWIDTH_LIMIT_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
void SrsKbpsLimit::send_limit()
|
||||
{
|
||||
_kbps->sample();
|
||||
|
||||
while (_kbps->get_send_kbps() > _limit_kbps) {
|
||||
_kbps->sample();
|
||||
|
||||
srs_usleep(_SRS_BANDWIDTH_LIMIT_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,166 +0,0 @@
|
|||
//
|
||||
// Copyright (c) 2013-2022 The SRS Authors
|
||||
//
|
||||
// SPDX-License-Identifier: MIT or MulanPSL-2.0
|
||||
//
|
||||
|
||||
#ifndef SRS_APP_BANDWIDTH_HPP
|
||||
#define SRS_APP_BANDWIDTH_HPP
|
||||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <srs_app_st.hpp>
|
||||
|
||||
class SrsKbps;
|
||||
class SrsRequest;
|
||||
class SrsRtmpServer;
|
||||
class SrsKbpsLimit;
|
||||
class ISrsProtocolStatistic;
|
||||
|
||||
// The bandwidth check/test sample.
|
||||
class SrsBandwidthSample
|
||||
{
|
||||
public:
|
||||
// The plan, how long to do the test,
|
||||
// if exceed the duration, abort the test.
|
||||
srs_utime_t duration;
|
||||
// The plan, interval for each check/test packet
|
||||
srs_utime_t interval;
|
||||
public:
|
||||
// The actual test duration.
|
||||
srs_utime_t actual_duration;
|
||||
// The actual test bytes
|
||||
int bytes;
|
||||
// The actual test kbps
|
||||
int kbps;
|
||||
public:
|
||||
SrsBandwidthSample();
|
||||
virtual ~SrsBandwidthSample();
|
||||
public:
|
||||
// Update the bytes and actual duration, then calc the kbps.
|
||||
// @param _bytes update the sample bytes.
|
||||
// @param _duration update the actual duration.
|
||||
virtual void calc_kbps(int _bytes, srs_utime_t _duration);
|
||||
};
|
||||
|
||||
// The bandwidth test agent which provides the interfaces for bandwidth check.
|
||||
// 1. if vhost disabled bandwidth check, ignore.
|
||||
// 2. otherwise, check the key, error if verify failed.
|
||||
// 3. check the interval limit, error if bandwidth in the interval window.
|
||||
// 4. check the bandwidth under the max kbps.
|
||||
// 5. send the bandwidth data to client.
|
||||
// bandwidth workflow:
|
||||
// +------------+ +----------+
|
||||
// | Client | | Server |
|
||||
// +-----+------+ +-----+----+
|
||||
// | |
|
||||
// | connect vhost------> | if vhost enable bandwidth,
|
||||
// | <-----result(success) | do bandwidth check.
|
||||
// | |
|
||||
// | <----call(start play) | onSrsBandCheckStartPlayBytes
|
||||
// | result(playing)-----> | onSrsBandCheckStartingPlayBytes
|
||||
// | <-------data(playing) | onSrsBandCheckStartingPlayBytes
|
||||
// | <-----call(stop play) | onSrsBandCheckStopPlayBytes
|
||||
// | result(stopped)-----> | onSrsBandCheckStoppedPlayBytes
|
||||
// | |
|
||||
// | <-call(start publish) | onSrsBandCheckStartPublishBytes
|
||||
// | result(publishing)--> | onSrsBandCheckStartingPublishBytes
|
||||
// | data(publishing)(3)-> | onSrsBandCheckStartingPublishBytes
|
||||
// | <--call(stop publish) | onSrsBandCheckStopPublishBytes
|
||||
// | result(stopped)(1)--> | onSrsBandCheckStoppedPublishBytes
|
||||
// | |
|
||||
// | <--------------report |
|
||||
// | final(2)------------> | finalClientPacket
|
||||
// | <END> |
|
||||
//
|
||||
// 1. when flash client, server never wait the stop publish response,
|
||||
// for the flash client queue is fullfill with other packets.
|
||||
// 2. when flash client, server never wait the final packet,
|
||||
// for the flash client directly close when got report packet.
|
||||
// 3. for linux client, it will send the publish data then send a stop publish,
|
||||
// for the linux client donot know when to stop the publish.
|
||||
// when server got publishing and stop publish, stop publish.
|
||||
class SrsBandwidth
|
||||
{
|
||||
private:
|
||||
SrsRequest* _req;
|
||||
SrsRtmpServer* _rtmp;
|
||||
public:
|
||||
SrsBandwidth();
|
||||
virtual ~SrsBandwidth();
|
||||
public:
|
||||
// Do the bandwidth check.
|
||||
// @param rtmp, server RTMP protocol object, send/recv RTMP packet to/from client.
|
||||
// @param io_stat, the underlayer io statistic, provides send/recv bytes count.
|
||||
// @param req, client request object, specifies the request info from client.
|
||||
// @param local_ip, the ip of server which client connected at
|
||||
virtual srs_error_t bandwidth_check(SrsRtmpServer* rtmp, ISrsProtocolStatistic* io_stat, SrsRequest* req, std::string local_ip);
|
||||
private:
|
||||
// Used to process band width check from client.
|
||||
// @param limit, the bandwidth limit object, to slowdown if exceed the kbps.
|
||||
virtual srs_error_t do_bandwidth_check(SrsKbpsLimit* limit);
|
||||
// play check/test, downloading bandwidth kbps.
|
||||
private:
|
||||
// Start play/download bandwidth check/test,
|
||||
// send start-play command to client, client must response starting-play
|
||||
// to start the test.
|
||||
virtual srs_error_t play_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit);
|
||||
// Do play/download bandwidth check/test,
|
||||
// server send call messages to client in specified time,
|
||||
// calc the time and bytes sent, then we got the kbps.
|
||||
virtual srs_error_t play_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit);
|
||||
// stop play/download bandwidth check/test,
|
||||
// send stop-play command to client, client must response stopped-play
|
||||
// to stop the test.
|
||||
virtual srs_error_t play_stop(SrsBandwidthSample* sample, SrsKbpsLimit* limit);
|
||||
// publish check/test, publishing bandwidth kbps.
|
||||
private:
|
||||
// Start publish/upload bandwidth check/test,
|
||||
// send start-publish command to client, client must response starting-publish
|
||||
// to start the test.
|
||||
virtual srs_error_t publish_start(SrsBandwidthSample* sample, SrsKbpsLimit* limit);
|
||||
// Do publish/upload bandwidth check/test,
|
||||
// client send call messages to client in specified time,
|
||||
// server calc the time and bytes received, then we got the kbps.
|
||||
// @remark, for linux client, it will send a stop publish client, server will stop publishing.
|
||||
// then enter the publish-stop stage with client.
|
||||
// @remark, for flash client, it will send many many call messages, that is,
|
||||
// the send queue is fullfill with call messages, so we should never expect the
|
||||
// response message in the publish-stop stage.
|
||||
virtual srs_error_t publish_checking(SrsBandwidthSample* sample, SrsKbpsLimit* limit);
|
||||
// Stop publish/upload bandwidth check/test,
|
||||
// send stop-publish command to client,
|
||||
// for linux client, always expect a stopped-publish response from client,
|
||||
// for flash client, the sent queue is fullfill with publishing call messages,
|
||||
// so server never expect the stopped-publish from it.
|
||||
virtual srs_error_t publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit* limit);
|
||||
private:
|
||||
// Report and final packet
|
||||
// report a finish packet, with the bytes/time/kbps bandwidth check/test result,
|
||||
// for linux client, server always expect a final packet from client,
|
||||
// for flash client, the sent queue is fullfill with publishing call messages,
|
||||
// so server never expect the final packet from it.
|
||||
virtual srs_error_t do_final(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, srs_utime_t start_time, srs_utime_t& end_time);
|
||||
};
|
||||
|
||||
// The kbps limit, if exceed the kbps, slow down.
|
||||
class SrsKbpsLimit
|
||||
{
|
||||
private:
|
||||
int _limit_kbps;
|
||||
SrsKbps* _kbps;
|
||||
public:
|
||||
SrsKbpsLimit(SrsKbps* kbps, int limit_kbps);
|
||||
virtual ~SrsKbpsLimit();
|
||||
public:
|
||||
// Get the system limit kbps.
|
||||
virtual int limit_kbps();
|
||||
// Limit the recv bandwidth.
|
||||
virtual void recv_limit();
|
||||
// Limit the send bandwidth.
|
||||
virtual void send_limit();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1505,7 +1505,7 @@ srs_error_t SrsConfig::reload_conf(SrsConfig* conf)
|
|||
//
|
||||
// always support reload without additional code:
|
||||
// chunk_size, ff_log_dir,
|
||||
// bandcheck, http_hooks, heartbeat,
|
||||
// http_hooks, heartbeat,
|
||||
// security
|
||||
|
||||
// merge config: listen
|
||||
|
@ -2593,13 +2593,6 @@ srs_error_t SrsConfig::check_normal_config()
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (n == "bandcheck") {
|
||||
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
||||
string m = conf->at(j)->name;
|
||||
if (m != "enabled" && m != "key" && m != "interval" && m != "limit_kbps") {
|
||||
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.bandcheck.%s of %s", m.c_str(), vhost->arg0().c_str());
|
||||
}
|
||||
}
|
||||
} else if (n == "rtc") {
|
||||
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
||||
string m = conf->at(j)->name;
|
||||
|
@ -4843,94 +4836,6 @@ SrsConfDirective* SrsConfig::get_vhost_on_hls_notify(string vhost)
|
|||
return conf->get("on_hls_notify");
|
||||
}
|
||||
|
||||
bool SrsConfig::get_bw_check_enabled(string vhost)
|
||||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("bandcheck");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("enabled");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
||||
}
|
||||
|
||||
string SrsConfig::get_bw_check_key(string vhost)
|
||||
{
|
||||
static string DEFAULT = "";
|
||||
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("bandcheck");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("key");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return conf->arg0();
|
||||
}
|
||||
|
||||
srs_utime_t SrsConfig::get_bw_check_interval(string vhost)
|
||||
{
|
||||
static int64_t DEFAULT = 30 * SRS_UTIME_SECONDS;
|
||||
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("bandcheck");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("interval");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return (srs_utime_t)(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
||||
}
|
||||
|
||||
int SrsConfig::get_bw_check_limit_kbps(string vhost)
|
||||
{
|
||||
static int DEFAULT = 1000;
|
||||
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("bandcheck");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("limit_kbps");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return ::atoi(conf->arg0().c_str());
|
||||
}
|
||||
|
||||
bool SrsConfig::get_vhost_is_edge(string vhost)
|
||||
{
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
|
|
|
@ -710,23 +710,6 @@ public:
|
|||
// Get the on_hls_notify callbacks of vhost.
|
||||
// @return the on_hls_notify callback directive, the args is the url to callback.
|
||||
virtual SrsConfDirective* get_vhost_on_hls_notify(std::string vhost);
|
||||
// bwct(bandwidth check tool) section
|
||||
public:
|
||||
// Whether bw check enabled for vhost.
|
||||
// If enabled, serve all clients with bandwidth check services.
|
||||
// oterwise, serve all cleints with stream.
|
||||
virtual bool get_bw_check_enabled(std::string vhost);
|
||||
// The key of server, if client key mot match, reject.
|
||||
virtual std::string get_bw_check_key(std::string vhost);
|
||||
// The check interval, in srs_utime_t.
|
||||
// If the client request check in very short time(in the interval),
|
||||
// SRS will reject client.
|
||||
// @remark this is used to prevent the bandwidth check attack.
|
||||
virtual srs_utime_t get_bw_check_interval(std::string vhost);
|
||||
// The max kbps that user can test,
|
||||
// If exceed the kbps, server will slowdown the send-recv.
|
||||
// @remark this is used to protect the service bandwidth.
|
||||
virtual int get_bw_check_limit_kbps(std::string vhost);
|
||||
// vhost cluster section
|
||||
public:
|
||||
// Whether vhost is edge mode.
|
||||
|
|
|
@ -24,7 +24,6 @@ using namespace std;
|
|||
#include <srs_app_config.hpp>
|
||||
#include <srs_app_refer.hpp>
|
||||
#include <srs_app_hls.hpp>
|
||||
#include <srs_app_bandwidth.hpp>
|
||||
#include <srs_app_st.hpp>
|
||||
#include <srs_app_http_hooks.hpp>
|
||||
#include <srs_app_edge.hpp>
|
||||
|
@ -107,7 +106,6 @@ SrsRtmpConn::SrsRtmpConn(SrsServer* svr, srs_netfd_t c, string cip, int cport)
|
|||
|
||||
rtmp = new SrsRtmpServer(skt);
|
||||
refer = new SrsRefer();
|
||||
bandwidth = new SrsBandwidth();
|
||||
security = new SrsSecurity();
|
||||
duration = 0;
|
||||
wakable = NULL;
|
||||
|
@ -142,7 +140,6 @@ SrsRtmpConn::~SrsRtmpConn()
|
|||
srs_freep(info);
|
||||
srs_freep(rtmp);
|
||||
srs_freep(refer);
|
||||
srs_freep(bandwidth);
|
||||
srs_freep(security);
|
||||
}
|
||||
|
||||
|
@ -368,14 +365,6 @@ srs_error_t SrsRtmpConn::service_cycle()
|
|||
// get the ip which client connected.
|
||||
std::string local_ip = srs_get_local_ip(srs_netfd_fileno(stfd));
|
||||
|
||||
// do bandwidth test if connect to the vhost which is for bandwidth check.
|
||||
if (_srs_config->get_bw_check_enabled(req->vhost)) {
|
||||
if ((err = bandwidth->bandwidth_check(rtmp, skt, req, local_ip)) != srs_success) {
|
||||
return srs_error_wrap(err, "rtmp: bandwidth check");
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
// set chunk size to larger.
|
||||
// set the chunk size before any larger response greater than 128,
|
||||
// to make OBS happy, @see https://github.com/ossrs/srs/issues/454
|
||||
|
|
|
@ -9,6 +9,6 @@
|
|||
|
||||
#define VERSION_MAJOR 5
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 51
|
||||
#define VERSION_REVISION 52
|
||||
|
||||
#endif
|
||||
|
|
|
@ -77,37 +77,6 @@ using namespace std;
|
|||
// the same as the timestamp of Type 0 chunk.
|
||||
#define RTMP_FMT_TYPE3 3
|
||||
|
||||
/****************************************************************************
|
||||
*****************************************************************************
|
||||
****************************************************************************/
|
||||
/**
|
||||
* band width check method name, which will be invoked by client.
|
||||
* band width check mothods use SrsBandwidthPacket as its internal packet type,
|
||||
* so ensure you set command name when you use it.
|
||||
*/
|
||||
// server play control
|
||||
#define SRS_BW_CHECK_START_PLAY "onSrsBandCheckStartPlayBytes"
|
||||
#define SRS_BW_CHECK_STARTING_PLAY "onSrsBandCheckStartingPlayBytes"
|
||||
#define SRS_BW_CHECK_STOP_PLAY "onSrsBandCheckStopPlayBytes"
|
||||
#define SRS_BW_CHECK_STOPPED_PLAY "onSrsBandCheckStoppedPlayBytes"
|
||||
|
||||
// server publish control
|
||||
#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"
|
||||
// @remark, flash never send out this packet, for its queue is full.
|
||||
#define SRS_BW_CHECK_FINAL "finalClientPacket"
|
||||
|
||||
// data packets
|
||||
#define SRS_BW_CHECK_PLAYING "onSrsBandCheckPlaying"
|
||||
#define SRS_BW_CHECK_PUBLISHING "onSrsBandCheckPublishing"
|
||||
|
||||
/****************************************************************************
|
||||
*****************************************************************************
|
||||
****************************************************************************/
|
||||
|
@ -714,42 +683,6 @@ srs_error_t SrsProtocol::do_decode_message(SrsMessageHeader& header, SrsBuffer*
|
|||
} else if (command == SRS_CONSTS_RTMP_ON_METADATA) {
|
||||
*ppacket = packet = new SrsOnMetaDataPacket();
|
||||
return packet->decode(stream);
|
||||
} else if (command == SRS_BW_CHECK_FINISHED) {
|
||||
*ppacket = packet = new SrsBandwidthPacket();
|
||||
return packet->decode(stream);
|
||||
} else if (command == SRS_BW_CHECK_PLAYING) {
|
||||
*ppacket = packet = new SrsBandwidthPacket();
|
||||
return packet->decode(stream);
|
||||
} else if (command == SRS_BW_CHECK_PUBLISHING) {
|
||||
*ppacket = packet = new SrsBandwidthPacket();
|
||||
return packet->decode(stream);
|
||||
} else if (command == SRS_BW_CHECK_STARTING_PLAY) {
|
||||
*ppacket = packet = new SrsBandwidthPacket();
|
||||
return packet->decode(stream);
|
||||
} else if (command == SRS_BW_CHECK_STARTING_PUBLISH) {
|
||||
*ppacket = packet = new SrsBandwidthPacket();
|
||||
return packet->decode(stream);
|
||||
} else if (command == SRS_BW_CHECK_START_PLAY) {
|
||||
*ppacket = packet = new SrsBandwidthPacket();
|
||||
return packet->decode(stream);
|
||||
} else if (command == SRS_BW_CHECK_START_PUBLISH) {
|
||||
*ppacket = packet = new SrsBandwidthPacket();
|
||||
return packet->decode(stream);
|
||||
} else if (command == SRS_BW_CHECK_STOPPED_PLAY) {
|
||||
*ppacket = packet = new SrsBandwidthPacket();
|
||||
return packet->decode(stream);
|
||||
} else if (command == SRS_BW_CHECK_STOP_PLAY) {
|
||||
*ppacket = packet = new SrsBandwidthPacket();
|
||||
return packet->decode(stream);
|
||||
} else if (command == SRS_BW_CHECK_STOP_PUBLISH) {
|
||||
*ppacket = packet = new SrsBandwidthPacket();
|
||||
return packet->decode(stream);
|
||||
} else if (command == SRS_BW_CHECK_STOPPED_PUBLISH) {
|
||||
*ppacket = packet = new SrsBandwidthPacket();
|
||||
return packet->decode(stream);
|
||||
} else if (command == SRS_BW_CHECK_FINAL) {
|
||||
*ppacket = packet = new SrsBandwidthPacket();
|
||||
return packet->decode(stream);
|
||||
} else if (command == RTMP_AMF0_COMMAND_CLOSE_STREAM) {
|
||||
*ppacket = packet = new SrsCloseStreamPacket();
|
||||
return packet->decode(stream);
|
||||
|
@ -4166,215 +4099,6 @@ srs_error_t SrsOnStatusCallPacket::encode_packet(SrsBuffer* stream)
|
|||
return err;
|
||||
}
|
||||
|
||||
SrsBandwidthPacket::SrsBandwidthPacket()
|
||||
{
|
||||
command_name = RTMP_AMF0_COMMAND_ON_STATUS;
|
||||
transaction_id = 0;
|
||||
args = SrsAmf0Any::null();
|
||||
data = SrsAmf0Any::object();
|
||||
}
|
||||
|
||||
SrsBandwidthPacket::~SrsBandwidthPacket()
|
||||
{
|
||||
srs_freep(args);
|
||||
srs_freep(data);
|
||||
}
|
||||
|
||||
srs_error_t SrsBandwidthPacket::decode(SrsBuffer *stream)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if ((err = srs_amf0_read_string(stream, command_name)) != srs_success) {
|
||||
return srs_error_wrap(err, "command_name");
|
||||
}
|
||||
|
||||
if ((err = srs_amf0_read_number(stream, transaction_id)) != srs_success) {
|
||||
return srs_error_wrap(err, "transaction_id");
|
||||
}
|
||||
|
||||
if ((err = srs_amf0_read_null(stream)) != srs_success) {
|
||||
return srs_error_wrap(err, "command_object");
|
||||
}
|
||||
|
||||
// @remark, for bandwidth test, ignore the data field.
|
||||
// only decode the stop-play, start-publish and finish packet.
|
||||
if (is_stop_play() || is_start_publish() || is_finish()) {
|
||||
if ((err = data->read(stream)) != srs_success) {
|
||||
return srs_error_wrap(err, "command_object");
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int SrsBandwidthPacket::get_prefer_cid()
|
||||
{
|
||||
return RTMP_CID_OverStream;
|
||||
}
|
||||
|
||||
int SrsBandwidthPacket::get_message_type()
|
||||
{
|
||||
return RTMP_MSG_AMF0CommandMessage;
|
||||
}
|
||||
|
||||
int SrsBandwidthPacket::get_size()
|
||||
{
|
||||
return SrsAmf0Size::str(command_name) + SrsAmf0Size::number()
|
||||
+ SrsAmf0Size::null() + SrsAmf0Size::object(data);
|
||||
}
|
||||
|
||||
srs_error_t SrsBandwidthPacket::encode_packet(SrsBuffer* stream)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if ((err = srs_amf0_write_string(stream, command_name)) != srs_success) {
|
||||
return srs_error_wrap(err, "command_name");
|
||||
}
|
||||
|
||||
if ((err = srs_amf0_write_number(stream, transaction_id)) != srs_success) {
|
||||
return srs_error_wrap(err, "transaction_id");
|
||||
}
|
||||
|
||||
if ((err = srs_amf0_write_null(stream)) != srs_success) {
|
||||
return srs_error_wrap(err, "args");
|
||||
}
|
||||
|
||||
if ((err = data->write(stream)) != srs_success) {
|
||||
return srs_error_wrap(err, "data");
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
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_finish()
|
||||
{
|
||||
return command_name == SRS_BW_CHECK_FINISHED;
|
||||
}
|
||||
|
||||
bool SrsBandwidthPacket::is_final()
|
||||
{
|
||||
return command_name == SRS_BW_CHECK_FINAL;
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::create_start_play()
|
||||
{
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
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();
|
||||
return pkt->set_command(SRS_BW_CHECK_PLAYING);
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::create_stop_play()
|
||||
{
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
return pkt->set_command(SRS_BW_CHECK_STOP_PLAY);
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::create_stopped_play()
|
||||
{
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
return pkt->set_command(SRS_BW_CHECK_STOPPED_PLAY);
|
||||
}
|
||||
|
||||
SrsBandwidthPacket* SrsBandwidthPacket::create_start_publish()
|
||||
{
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
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_stopped_publish()
|
||||
{
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
return pkt->set_command(SRS_BW_CHECK_STOPPED_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;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
SrsOnStatusDataPacket::SrsOnStatusDataPacket()
|
||||
{
|
||||
command_name = RTMP_AMF0_COMMAND_ON_STATUS;
|
||||
|
|
|
@ -1241,65 +1241,6 @@ protected:
|
|||
virtual srs_error_t encode_packet(SrsBuffer* stream);
|
||||
};
|
||||
|
||||
// The special packet for the bandwidth test.
|
||||
// actually, it's a SrsOnStatusCallPacket, but
|
||||
// 1. encode with data field, to send data to client.
|
||||
// 2. decode ignore the data field, donot care.
|
||||
class SrsBandwidthPacket : public SrsPacket
|
||||
{
|
||||
public:
|
||||
// Name of command.
|
||||
std::string command_name;
|
||||
// Transaction ID set to 0.
|
||||
double transaction_id;
|
||||
// Command information does not exist. Set to null type.
|
||||
// @remark, never be NULL, an AMF0 null instance.
|
||||
SrsAmf0Any* args; // null
|
||||
// Name-value pairs that describe the response from the server.
|
||||
// 'code','level', 'description' are names of few among such information.
|
||||
// @remark, never be NULL, an AMF0 object instance.
|
||||
SrsAmf0Object* data;
|
||||
public:
|
||||
SrsBandwidthPacket();
|
||||
virtual ~SrsBandwidthPacket();
|
||||
// Decode functions for concrete packet to override.
|
||||
public:
|
||||
virtual srs_error_t decode(SrsBuffer* stream);
|
||||
// Encode functions for concrete packet to override.
|
||||
public:
|
||||
virtual int get_prefer_cid();
|
||||
virtual int get_message_type();
|
||||
protected:
|
||||
virtual int get_size();
|
||||
virtual srs_error_t encode_packet(SrsBuffer* 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_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_stopped_play();
|
||||
static SrsBandwidthPacket* create_start_publish();
|
||||
static SrsBandwidthPacket* create_starting_publish();
|
||||
static SrsBandwidthPacket* create_publishing();
|
||||
static SrsBandwidthPacket* create_stop_publish();
|
||||
static SrsBandwidthPacket* create_stopped_publish();
|
||||
static SrsBandwidthPacket* create_finish();
|
||||
static SrsBandwidthPacket* create_final();
|
||||
private:
|
||||
virtual SrsBandwidthPacket* set_command(std::string command);
|
||||
};
|
||||
|
||||
// onStatus data, AMF0 Data
|
||||
// @remark, user must set the stream_id by SrsCommonMessage.set_packet().
|
||||
class SrsOnStatusDataPacket : public SrsPacket
|
||||
|
|
|
@ -1843,61 +1843,6 @@ VOID TEST(ConfigMainTest, CheckConf_transcode)
|
|||
}
|
||||
}
|
||||
|
||||
VOID TEST(ConfigMainTest, CheckConf_bandcheck)
|
||||
{
|
||||
srs_error_t err;
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{}}"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{bandchecks{}}"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{enabled on;}}"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{enableds on;}}"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{key \"35c9b402c12a7246868752e2878f7e0e\";}}"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{keys \"35c9b402c12a7246868752e2878f7e0e\";}}"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{interval 30;}}"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{intervals 30;}}"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{limit_kbps 4000;}}"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{limit_kbpss 4000;}}"));
|
||||
}
|
||||
}
|
||||
|
||||
VOID TEST(ConfigMainTest, CheckConf_chunk_size2)
|
||||
{
|
||||
srs_error_t err;
|
||||
|
@ -2019,14 +1964,6 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost)
|
|||
|
||||
MockSrsConfig conf;
|
||||
|
||||
if (true) {
|
||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF));
|
||||
EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_bw_check_interval(""));
|
||||
|
||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{interval 4;}}"));
|
||||
EXPECT_EQ(4 * SRS_UTIME_SECONDS, conf.get_bw_check_interval("v"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF));
|
||||
EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_dash_fragment(""));
|
||||
|
@ -3198,10 +3135,6 @@ VOID TEST(ConfigMainTest, CheckVhostConfig3)
|
|||
EXPECT_TRUE(conf.get_vhost_on_dvr("ossrs.net") == NULL);
|
||||
EXPECT_TRUE(conf.get_vhost_on_hls("ossrs.net") == NULL);
|
||||
EXPECT_TRUE(conf.get_vhost_on_hls_notify("ossrs.net") == NULL);
|
||||
EXPECT_FALSE(conf.get_bw_check_enabled("ossrs.net"));
|
||||
EXPECT_TRUE(conf.get_bw_check_key("ossrs.net").empty());
|
||||
EXPECT_EQ(30000000, conf.get_bw_check_interval("ossrs.net"));
|
||||
EXPECT_EQ(1000, conf.get_bw_check_limit_kbps("ossrs.net"));
|
||||
EXPECT_FALSE(conf.get_vhost_is_edge("ossrs.net"));
|
||||
EXPECT_TRUE(conf.get_vhost_edge_origin("ossrs.net") == NULL);
|
||||
EXPECT_FALSE(conf.get_vhost_edge_token_traverse("ossrs.net"));
|
||||
|
@ -3260,30 +3193,6 @@ VOID TEST(ConfigMainTest, CheckVhostConfig3)
|
|||
EXPECT_TRUE(conf.get_vhost_is_edge("ossrs.net"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{bandcheck{limit_kbps 10;}}"));
|
||||
EXPECT_EQ(10, conf.get_bw_check_limit_kbps("ossrs.net"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{bandcheck{interval 10;}}"));
|
||||
EXPECT_EQ(10000000, conf.get_bw_check_interval("ossrs.net"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{bandcheck{key xxx;}}"));
|
||||
EXPECT_FALSE(conf.get_bw_check_key("ossrs.net").empty());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{bandcheck{enabled on;}}"));
|
||||
EXPECT_TRUE(conf.get_bw_check_enabled("ossrs.net"));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockSrsConfig conf;
|
||||
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{on_hls_notify xxx;}}"));
|
||||
|
|
|
@ -4993,40 +4993,6 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsOnStatusCallPacket)
|
|||
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||
}
|
||||
|
||||
/**
|
||||
* send a SrsBandwidthPacket packet
|
||||
*/
|
||||
VOID TEST(ProtocolStackTest, ProtocolSendSrsBandwidthPacket)
|
||||
{
|
||||
MockBufferIO bio;
|
||||
SrsProtocol proto(&bio);
|
||||
|
||||
SrsAmf0Object* args = SrsAmf0Any::object();
|
||||
|
||||
args->set("stream" , SrsAmf0Any::str("livestream"));
|
||||
args->set("start" , SrsAmf0Any::number(0));
|
||||
|
||||
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||
pkt->command_name = "startPublish";
|
||||
pkt->args = SrsAmf0Any::null();
|
||||
pkt->data = args;
|
||||
|
||||
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||
char buf[] = {
|
||||
0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x14,
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0c, 0x73,
|
||||
0x74, 0x61, 0x72, 0x74, 0x50, 0x75, 0x62, 0x6c,
|
||||
0x69, 0x73, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x05, 0x03, 0x00, 0x06,
|
||||
0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x02, 0x00,
|
||||
0x0a, 0x6c, 0x69, 0x76, 0x65, 0x73, 0x74, 0x72,
|
||||
0x65, 0x61, 0x6d, 0x00, 0x05, 0x73, 0x74, 0x61,
|
||||
0x72, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x09
|
||||
};
|
||||
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||
}
|
||||
|
||||
/**
|
||||
* send a SrsOnStatusDataPacket packet
|
||||
*/
|
||||
|
|
|
@ -841,186 +841,6 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages4)
|
|||
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO io;
|
||||
SrsProtocol p(&io);
|
||||
|
||||
uint8_t bytes[] = {0x02, 0x00, 22, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','F','i','n','i','s','h','e','d', 0x00,0,0,0,0,0,0,0,0};
|
||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
|
||||
SrsPacket* pkt;
|
||||
SrsAutoFree(SrsPacket, pkt);
|
||||
|
||||
// Without enough data, it fail when decoding the request packet.
|
||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO io;
|
||||
SrsProtocol p(&io);
|
||||
|
||||
uint8_t bytes[] = {0x02, 0x00, 21, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','P','l','a','y','i','n','g', 0x00,0,0,0,0,0,0,0,0};
|
||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
|
||||
SrsPacket* pkt;
|
||||
SrsAutoFree(SrsPacket, pkt);
|
||||
|
||||
// Without enough data, it fail when decoding the request packet.
|
||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO io;
|
||||
SrsProtocol p(&io);
|
||||
|
||||
uint8_t bytes[] = {0x02, 0x00, 24, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','P','u','b','l','i','s','h','i','n','g', 0x00,0,0,0,0,0,0,0,0};
|
||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
|
||||
SrsPacket* pkt;
|
||||
SrsAutoFree(SrsPacket, pkt);
|
||||
|
||||
// Without enough data, it fail when decoding the request packet.
|
||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO io;
|
||||
SrsProtocol p(&io);
|
||||
|
||||
uint8_t bytes[] = {0x02, 0x00, 31, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','a','r','t','i','n','g','P','l','a','y','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
|
||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
|
||||
SrsPacket* pkt;
|
||||
SrsAutoFree(SrsPacket, pkt);
|
||||
|
||||
// Without enough data, it fail when decoding the request packet.
|
||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO io;
|
||||
SrsProtocol p(&io);
|
||||
|
||||
uint8_t bytes[] = {0x02, 0x00, 34, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','a','r','t','i','n','g','P','u','b','l','i','s','h','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
|
||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
|
||||
SrsPacket* pkt;
|
||||
SrsAutoFree(SrsPacket, pkt);
|
||||
|
||||
// Without enough data, it fail when decoding the request packet.
|
||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO io;
|
||||
SrsProtocol p(&io);
|
||||
|
||||
uint8_t bytes[] = {0x02, 0x00, 28, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','a','r','t','P','l','a','y','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
|
||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
|
||||
SrsPacket* pkt;
|
||||
SrsAutoFree(SrsPacket, pkt);
|
||||
|
||||
// Without enough data, it fail when decoding the request packet.
|
||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO io;
|
||||
SrsProtocol p(&io);
|
||||
|
||||
uint8_t bytes[] = {0x02, 0x00, 31, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','a','r','t','P','u','b','l','i','s','h','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
|
||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
|
||||
SrsPacket* pkt;
|
||||
SrsAutoFree(SrsPacket, pkt);
|
||||
|
||||
// Without enough data, it fail when decoding the request packet.
|
||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO io;
|
||||
SrsProtocol p(&io);
|
||||
|
||||
uint8_t bytes[] = {0x02, 0x00, 30, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','o','p','p','e','d','P','l','a','y','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
|
||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
|
||||
SrsPacket* pkt;
|
||||
SrsAutoFree(SrsPacket, pkt);
|
||||
|
||||
// Without enough data, it fail when decoding the request packet.
|
||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO io;
|
||||
SrsProtocol p(&io);
|
||||
|
||||
uint8_t bytes[] = {0x02, 0x00, 27, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','o','p','P','l','a','y','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
|
||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
|
||||
SrsPacket* pkt;
|
||||
SrsAutoFree(SrsPacket, pkt);
|
||||
|
||||
// Without enough data, it fail when decoding the request packet.
|
||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO io;
|
||||
SrsProtocol p(&io);
|
||||
|
||||
uint8_t bytes[] = {0x02, 0x00, 30, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','o','p','P','u','b','l','i','s','h','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
|
||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
|
||||
SrsPacket* pkt;
|
||||
SrsAutoFree(SrsPacket, pkt);
|
||||
|
||||
// Without enough data, it fail when decoding the request packet.
|
||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO io;
|
||||
SrsProtocol p(&io);
|
||||
|
||||
uint8_t bytes[] = {0x02, 0x00, 33, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','o','p','p','e','d','P','u','b','l','i','s','h','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
|
||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
|
||||
SrsPacket* pkt;
|
||||
SrsAutoFree(SrsPacket, pkt);
|
||||
|
||||
// Without enough data, it fail when decoding the request packet.
|
||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO io;
|
||||
SrsProtocol p(&io);
|
||||
|
||||
uint8_t bytes[] = {0x02, 0x00, 17, 'f','i','n','a','l','C','l','i','e','n','t','P','a','c','k','e','t', 0x00,0,0,0,0,0,0,0,0};
|
||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||
SrsAutoFree(SrsCommonMessage, msg);
|
||||
|
||||
SrsPacket* pkt;
|
||||
SrsAutoFree(SrsPacket, pkt);
|
||||
|
||||
// Without enough data, it fail when decoding the request packet.
|
||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO io;
|
||||
SrsProtocol p(&io);
|
||||
|
@ -2488,78 +2308,6 @@ VOID TEST(ProtocolRTMPTest, CoverAll)
|
|||
}
|
||||
}
|
||||
|
||||
VOID TEST(ProtocolRTMPTest, CoverBandwidth)
|
||||
{
|
||||
if (true) {
|
||||
SrsBandwidthPacket p;
|
||||
|
||||
p.set_command("onSrsBandCheckStartPlayBytes");
|
||||
EXPECT_TRUE(p.is_start_play());
|
||||
|
||||
p.command_name = "onSrsBandCheckStartPlayBytes";
|
||||
EXPECT_TRUE(p.is_start_play());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
SrsBandwidthPacket* p = SrsBandwidthPacket::create_start_play();
|
||||
EXPECT_TRUE(p->is_start_play());
|
||||
srs_freep(p);
|
||||
}
|
||||
if (true) {
|
||||
SrsBandwidthPacket* p = SrsBandwidthPacket::create_starting_play();
|
||||
EXPECT_TRUE(p->is_starting_play());
|
||||
srs_freep(p);
|
||||
}
|
||||
if (true) {
|
||||
SrsBandwidthPacket* p = SrsBandwidthPacket::create_playing();
|
||||
srs_freep(p);
|
||||
}
|
||||
if (true) {
|
||||
SrsBandwidthPacket* p = SrsBandwidthPacket::create_stop_play();
|
||||
EXPECT_TRUE(p->is_stop_play());
|
||||
srs_freep(p);
|
||||
}
|
||||
if (true) {
|
||||
SrsBandwidthPacket* p = SrsBandwidthPacket::create_stopped_play();
|
||||
EXPECT_TRUE(p->is_stopped_play());
|
||||
srs_freep(p);
|
||||
}
|
||||
if (true) {
|
||||
SrsBandwidthPacket* p = SrsBandwidthPacket::create_start_publish();
|
||||
EXPECT_TRUE(p->is_start_publish());
|
||||
srs_freep(p);
|
||||
}
|
||||
if (true) {
|
||||
SrsBandwidthPacket* p = SrsBandwidthPacket::create_starting_publish();
|
||||
EXPECT_TRUE(p->is_starting_publish());
|
||||
srs_freep(p);
|
||||
}
|
||||
if (true) {
|
||||
SrsBandwidthPacket* p = SrsBandwidthPacket::create_publishing();
|
||||
srs_freep(p);
|
||||
}
|
||||
if (true) {
|
||||
SrsBandwidthPacket* p = SrsBandwidthPacket::create_stop_publish();
|
||||
EXPECT_TRUE(p->is_stop_publish());
|
||||
srs_freep(p);
|
||||
}
|
||||
if (true) {
|
||||
SrsBandwidthPacket* p = SrsBandwidthPacket::create_stopped_publish();
|
||||
EXPECT_TRUE(p->is_stopped_publish());
|
||||
srs_freep(p);
|
||||
}
|
||||
if (true) {
|
||||
SrsBandwidthPacket* p = SrsBandwidthPacket::create_finish();
|
||||
EXPECT_TRUE(p->is_finish());
|
||||
srs_freep(p);
|
||||
}
|
||||
if (true) {
|
||||
SrsBandwidthPacket* p = SrsBandwidthPacket::create_final();
|
||||
EXPECT_TRUE(p->is_final());
|
||||
srs_freep(p);
|
||||
}
|
||||
}
|
||||
|
||||
VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
|
||||
{
|
||||
srs_error_t err;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue