1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

[1].Add 'stun_strict_check' in conf file

[2].Try to pickup at least H.264 payload type
This commit is contained in:
xiaozhihong 2020-04-08 23:24:59 +08:00
parent 55f264b704
commit 85fcbad778
10 changed files with 73 additions and 13 deletions

View file

@ -438,6 +438,9 @@ vhost rtc.vhost.srs.com {
# Client will send ping(STUN binding request) to server, we use it as heartbeat.
# default: 30
stun_timeout 30;
# The strick check when process stun.
# default: off
stun_strict_check on;
}
# whether enable min delay mode for vhost.
# For RTC, we recommend to set to on.

View file

@ -3876,7 +3876,7 @@ srs_error_t SrsConfig::check_normal_config()
} else if (n == "rtc") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name;
if (m != "enabled" && m != "bframe" && m != "aac" && m != "stun_timeout") {
if (m != "enabled" && m != "bframe" && m != "aac" && m != "stun_timeout" && m != "stun_strict_check") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.rtc.%s of %s", m.c_str(), vhost->arg0().c_str());
}
}
@ -4798,6 +4798,24 @@ srs_utime_t SrsConfig::get_rtc_stun_timeout(string vhost)
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
}
bool SrsConfig::get_rtc_stun_strict_check(string vhost)
{
static bool DEFAULT = false;
SrsConfDirective* conf = get_rtc(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("stun_strict_check");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
SrsConfDirective* SrsConfig::get_vhost(string vhost, bool try_default_vhost)
{
srs_assert(root);

View file

@ -531,6 +531,7 @@ public:
bool get_rtc_bframe_discard(std::string vhost);
bool get_rtc_aac_discard(std::string vhost);
srs_utime_t get_rtc_stun_timeout(std::string vhost);
bool get_rtc_stun_strict_check(std::string vhost);
// vhost specified section
public:

View file

@ -1011,26 +1011,40 @@ srs_error_t SrsGoApiRtcPlay::exchange_sdp(const std::string& app, const std::str
}
if (local_media_desc.payload_types_.empty()) {
return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "no valid found opus payload type");
return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "no found valid opus payload type");
}
} else if (remote_media_desc.is_video()) {
std::deque<SrsMediaPayloadType> backup_payloads;
std::vector<SrsMediaPayloadType> payloads = remote_media_desc.find_media_with_encoding_name("H264");
for (std::vector<SrsMediaPayloadType>::iterator iter = payloads.begin(); iter != payloads.end(); ++iter) {
if (iter->format_specific_param_.empty()) {
backup_payloads.push_front(*iter);
continue;
}
H264SpecificParam h264_param;
if ((err = parse_h264_fmtp(iter->format_specific_param_, h264_param)) != srs_success) {
srs_error_reset(err); continue;
}
if (h264_param.packetization_mode == 1 && h264_param.level_asymmerty_allow == 1) {
// Try to pick the "best match" H.264 payload type.
if (h264_param.packetization_mode == "1" && h264_param.level_asymmerty_allow == "1") {
// Only choose first match H.264 payload type.
local_media_desc.payload_types_.push_back(*iter);
break;
}
backup_payloads.push_back(*iter);
}
// Try my best to pick at least one media payload type.
if (local_media_desc.payload_types_.empty() && ! backup_payloads.empty()) {
srs_warn("choose backup H.264 payload type=%d", backup_payloads.front().payload_type_);
local_media_desc.payload_types_.push_back(backup_payloads.front());
}
if (local_media_desc.payload_types_.empty()) {
return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "no valid found H.264 payload type");
return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "no found valid H.264 payload type");
}
}

View file

@ -110,6 +110,8 @@ SrsPithyPrint::SrsPithyPrint(int _stage_id)
#define SRS_CONSTS_STAGE_HTTP_STREAM_CACHE 10
// for the ng-exec stage.
#define SRS_CONSTS_STAGE_EXEC 11
// for the rtc play
#define SRS_CONSTS_STAGE_RTC_PLAY 12
SrsPithyPrint* SrsPithyPrint::create_rtmp_play()
{
@ -166,6 +168,11 @@ SrsPithyPrint* SrsPithyPrint::create_http_stream_cache()
return new SrsPithyPrint(SRS_CONSTS_STAGE_HTTP_STREAM_CACHE);
}
SrsPithyPrint* SrsPithyPrint::create_rtc_play()
{
return new SrsPithyPrint(SRS_CONSTS_STAGE_RTC_PLAY);
}
SrsPithyPrint::~SrsPithyPrint()
{
leave_stage();

View file

@ -87,6 +87,7 @@ public:
static SrsPithyPrint* create_caster();
static SrsPithyPrint* create_http_stream();
static SrsPithyPrint* create_http_stream_cache();
static SrsPithyPrint* create_rtc_play();
virtual ~SrsPithyPrint();
private:
// Enter the specified stage, return the client id.

View file

@ -53,6 +53,7 @@ using namespace std;
#include <srs_http_stack.hpp>
#include <srs_app_http_api.hpp>
#include <srs_app_statistic.hpp>
#include <srs_app_pithy_print.hpp>
static bool is_stun(const uint8_t* data, const int size)
{
@ -520,11 +521,21 @@ srs_error_t SrsRtcSenderThread::cycle()
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
SrsPithyPrint* pprint = SrsPithyPrint::create_rtc_play();
SrsAutoFree(SrsPithyPrint, pprint);
while (true) {
if ((err = trd->pull()) != srs_success) {
return srs_error_wrap(err, "rtc sender thread");
}
pprint->elapse();
if (pprint->can_print()) {
// TODO: FIXME:
// Print stat like frame/s, packet/s, loss_packets.
}
#ifdef SRS_PERF_QUEUE_COND_WAIT
if (realtime) {
// for realtime, min required msgs is 0, send when got one+ msgs.
@ -709,7 +720,10 @@ srs_error_t SrsRtcSession::on_binding_request(SrsUdpMuxSocket* udp_mux_skt, SrsS
{
srs_error_t err = srs_success;
if (stun_req->get_ice_controlled()) {
bool strict_check = _srs_config->get_rtc_stun_strict_check(request.vhost);
if (strict_check && stun_req->get_ice_controlled()) {
// @see: https://tools.ietf.org/html/draft-ietf-ice-rfc5245bis-00#section-6.1.3.1
// TODO: Send 487 (Role Conflict) error response.
return srs_error_new(ERROR_RTC_STUN, "Peer must not in ice-controlled role in ice-lite mode.");
}
@ -1381,8 +1395,8 @@ srs_error_t SrsRtcServer::cycle()
srs_cond_wait(cond);
}
vector<mmsghdr> mhdrs = mmhdrs;
mmhdrs.clear();
vector<mmsghdr> mhdrs;
mmhdrs.swap(mhdrs);
mmsghdr* p = &mhdrs[0];
for (mmsghdr* end = p + mhdrs.size(); p < end; p += max_sendmmsg) {

View file

@ -76,11 +76,11 @@ srs_error_t parse_h264_fmtp(const std::string& fmtp, H264SpecificParam& h264_par
std::vector<std::string> kv = split_str(vec[i], "=");
if (kv.size() == 2) {
if (kv[0] == "profile-level-id") {
h264_param.profile_level_id = atoi(kv[1].c_str());
h264_param.profile_level_id = kv[1];
} else if (kv[0] == "packetization-mode") {
h264_param.packetization_mode = atoi(kv[1].c_str());
h264_param.packetization_mode = kv[1];
} else if (kv[0] == "level-asymmetry-allowed") {
h264_param.level_asymmerty_allow = atoi(kv[1].c_str());
h264_param.level_asymmerty_allow = kv[1];
} else {
return srs_error_new(ERROR_RTC_SDP_DECODE, "invalid h264 param=%s", kv[0].c_str());
}

View file

@ -73,9 +73,9 @@ class SrsSSRCGroup
struct H264SpecificParam
{
int profile_level_id;
int packetization_mode;
int level_asymmerty_allow;
std::string profile_level_id;
std::string packetization_mode;
std::string level_asymmerty_allow;
};
extern srs_error_t parse_h264_fmtp(const std::string& fmtp, H264SpecificParam& h264_param);

View file

@ -176,6 +176,8 @@
#define SRS_CONSTS_LOG_STREAM_CASTER "SCS"
// The nginx exec log id.
#define SRS_CONSTS_LOG_EXEC "EXE"
// The rtc.
#define SRS_CONSTS_LOG_RTC "RTC"
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////