mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Squash: Fix bugs. v5.0.20
This commit is contained in:
parent
d2fe83b032
commit
4110fb14cb
36 changed files with 433 additions and 98 deletions
|
@ -2471,7 +2471,7 @@ srs_error_t SrsConfig::check_normal_config()
|
|||
&& n != "grace_start_wait" && n != "empty_ip_ok" && n != "disable_daemon_for_docker"
|
||||
&& n != "inotify_auto_reload" && n != "auto_reload_for_docker" && n != "tcmalloc_release_rate"
|
||||
&& n != "query_latest_version"
|
||||
&& n != "circuit_breaker" && n != "is_full"
|
||||
&& n != "circuit_breaker" && n != "is_full" && n != "in_docker"
|
||||
) {
|
||||
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str());
|
||||
}
|
||||
|
@ -2542,7 +2542,7 @@ srs_error_t SrsConfig::check_normal_config()
|
|||
string n = conf->at(i)->name;
|
||||
if (n != "enabled" && n != "listen" && n != "dir" && n != "candidate" && n != "ecdsa"
|
||||
&& n != "encrypt" && n != "reuseport" && n != "merge_nalus" && n != "black_hole"
|
||||
&& n != "ip_family") {
|
||||
&& n != "ip_family" && n != "api_as_candidates") {
|
||||
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal rtc_server.%s", n.c_str());
|
||||
}
|
||||
}
|
||||
|
@ -2999,6 +2999,18 @@ bool SrsConfig::get_daemon()
|
|||
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
||||
}
|
||||
|
||||
bool SrsConfig::get_in_docker()
|
||||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = root->get("in_docker");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
||||
}
|
||||
|
||||
bool SrsConfig::is_full_config()
|
||||
{
|
||||
static bool DEFAULT = false;
|
||||
|
@ -3532,6 +3544,23 @@ std::string SrsConfig::get_rtc_server_candidates()
|
|||
return conf->arg0();
|
||||
}
|
||||
|
||||
bool SrsConfig::get_api_as_candidates()
|
||||
{
|
||||
static bool DEFAULT = true;
|
||||
|
||||
SrsConfDirective* conf = root->get("rtc_server");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("api_as_candidates");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
||||
}
|
||||
|
||||
std::string SrsConfig::get_rtc_server_ip_family()
|
||||
{
|
||||
static string DEFAULT = "ipv4";
|
||||
|
|
|
@ -382,6 +382,8 @@ public:
|
|||
// If true, SRS will run in daemon mode, fork and fork to reap the
|
||||
// grand-child process to init process.
|
||||
virtual bool get_daemon();
|
||||
// Whether srs in docker.
|
||||
virtual bool get_in_docker();
|
||||
private:
|
||||
// Whether user use full.conf
|
||||
virtual bool is_full_config();
|
||||
|
@ -467,6 +469,7 @@ public:
|
|||
virtual bool get_rtc_server_enabled(SrsConfDirective* conf);
|
||||
virtual int get_rtc_server_listen();
|
||||
virtual std::string get_rtc_server_candidates();
|
||||
virtual bool get_api_as_candidates();
|
||||
virtual std::string get_rtc_server_ip_family();
|
||||
virtual bool get_rtc_server_ecdsa();
|
||||
virtual bool get_rtc_server_encrypt();
|
||||
|
|
|
@ -745,6 +745,7 @@ SrsDvrSegmentPlan::SrsDvrSegmentPlan()
|
|||
{
|
||||
cduration = 0;
|
||||
wait_keyframe = false;
|
||||
reopening_segment_ = false;
|
||||
}
|
||||
|
||||
SrsDvrSegmentPlan::~SrsDvrSegmentPlan()
|
||||
|
@ -845,6 +846,12 @@ srs_error_t SrsDvrSegmentPlan::on_video(SrsSharedPtrMessage* shared_video, SrsFo
|
|||
srs_error_t SrsDvrSegmentPlan::update_duration(SrsSharedPtrMessage* msg)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// When reopening the segment, never update the duration, because there is actually no media data.
|
||||
// @see https://github.com/ossrs/srs/issues/2717
|
||||
if (reopening_segment_) {
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_assert(segment);
|
||||
|
||||
|
@ -879,8 +886,11 @@ srs_error_t SrsDvrSegmentPlan::update_duration(SrsSharedPtrMessage* msg)
|
|||
return srs_error_wrap(err, "segment open");
|
||||
}
|
||||
|
||||
// update sequence header
|
||||
if ((err = hub->on_dvr_request_sh()) != srs_success) {
|
||||
// When update sequence header, set the reopening state to prevent infinitely recursive call.
|
||||
reopening_segment_ = true;
|
||||
err = hub->on_dvr_request_sh();
|
||||
reopening_segment_ = false;
|
||||
if (err != srs_success) {
|
||||
return srs_error_wrap(err, "request sh");
|
||||
}
|
||||
|
||||
|
|
|
@ -198,6 +198,8 @@ private:
|
|||
// in config, in srs_utime_t
|
||||
srs_utime_t cduration;
|
||||
bool wait_keyframe;
|
||||
// Whether reopening the DVR file.
|
||||
bool reopening_segment_;
|
||||
public:
|
||||
SrsDvrSegmentPlan();
|
||||
virtual ~SrsDvrSegmentPlan();
|
||||
|
|
|
@ -207,7 +207,7 @@ srs_error_t SrsLatestVersion::cycle()
|
|||
string url;
|
||||
srs_utime_t starttime = srs_update_system_time();
|
||||
if ((err = query_latest_version(url)) != srs_success) {
|
||||
srs_warn("query err %s", srs_error_desc(err).c_str());
|
||||
srs_trace("query release err %s", srs_error_summary(err).c_str());
|
||||
srs_freep(err); // Ignore any error.
|
||||
}
|
||||
|
||||
|
|
|
@ -652,7 +652,7 @@ srs_error_t SrsUdpMuxListener::cycle()
|
|||
if (pps_last > 10000 || pps_average > 10000) {
|
||||
pps_unit = "(w)"; pps_last /= 10000; pps_average /= 10000;
|
||||
} else if (pps_last > 1000 || pps_average > 1000) {
|
||||
pps_unit = "(k)"; pps_last /= 10000; pps_average /= 10000;
|
||||
pps_unit = "(k)"; pps_last /= 1000; pps_average /= 1000;
|
||||
}
|
||||
|
||||
srs_trace("<- RTC RECV #%d, udp %" PRId64 ", pps %d/%d%s, schedule %" PRId64,
|
||||
|
|
|
@ -117,6 +117,7 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
|
|||
// The RTC user config object.
|
||||
SrsRtcUserConfig ruc;
|
||||
ruc.req_->ip = clientip;
|
||||
ruc.api_ = api;
|
||||
|
||||
srs_parse_rtmp_url(streamurl, ruc.req_->tcUrl, ruc.req_->stream);
|
||||
|
||||
|
@ -185,6 +186,14 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
|
|||
server_enabled, rtc_enabled, ruc.req_->vhost.c_str());
|
||||
}
|
||||
|
||||
// For RTMP to RTC, fail if disabled and RTMP is active, see https://github.com/ossrs/srs/issues/2728
|
||||
if (!_srs_config->get_rtc_from_rtmp(ruc.req_->vhost)) {
|
||||
SrsLiveSource* rtmp = _srs_sources->fetch(ruc.req_);
|
||||
if (rtmp && !rtmp->inactive()) {
|
||||
return srs_error_new(ERROR_RTC_DISABLED, "Disabled rtmp_to_rtc of %s, see #2728", ruc.req_->vhost.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: FIXME: When server enabled, but vhost disabled, should report error.
|
||||
SrsRtcConnection* session = NULL;
|
||||
if ((err = server_->create_session(&ruc, local_sdp, &session)) != srs_success) {
|
||||
|
@ -375,6 +384,7 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter* w, ISrsHtt
|
|||
// The RTC user config object.
|
||||
SrsRtcUserConfig ruc;
|
||||
ruc.req_->ip = clientip;
|
||||
ruc.api_ = api;
|
||||
|
||||
srs_parse_rtmp_url(streamurl, ruc.req_->tcUrl, ruc.req_->stream);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <srs_app_rtc_server.hpp>
|
||||
|
||||
#include <set>
|
||||
using namespace std;
|
||||
|
||||
#include <srs_app_config.hpp>
|
||||
|
@ -149,18 +150,65 @@ bool srs_is_rtcp(const uint8_t* data, size_t len)
|
|||
return (len >= 12) && (data[0] & 0x80) && (data[1] >= 192 && data[1] <= 223);
|
||||
}
|
||||
|
||||
static std::vector<std::string> get_candidate_ips()
|
||||
srs_error_t api_server_as_candidates(string api, set<string>& candidate_ips)
|
||||
{
|
||||
std::vector<std::string> candidate_ips;
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (api.empty() || !_srs_config->get_api_as_candidates()) {
|
||||
return err;
|
||||
}
|
||||
|
||||
SrsHttpUri uri;
|
||||
if ((err = uri.initialize(api)) != srs_success) {
|
||||
return srs_error_wrap(err, "parse %s", api.c_str());
|
||||
}
|
||||
|
||||
string hostname = uri.get_host();
|
||||
if (hostname.empty() || hostname == SRS_CONSTS_LOCALHOST_NAME) {
|
||||
return err;
|
||||
}
|
||||
if (hostname == SRS_CONSTS_LOCALHOST || hostname == SRS_CONSTS_LOOPBACK || hostname == SRS_CONSTS_LOOPBACK6) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// Try to parse the domain name if not IP.
|
||||
int family = 0;
|
||||
string ip = srs_dns_resolve(hostname, family);
|
||||
if (ip.empty() || ip == SRS_CONSTS_LOCALHOST || ip == SRS_CONSTS_LOOPBACK || ip == SRS_CONSTS_LOOPBACK6) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// Try to add the API server ip as candidates.
|
||||
candidate_ips.insert(ip);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static set<string> discover_candidates(SrsRtcUserConfig* ruc)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// Try to discover the eip as candidate, specified by user.
|
||||
set<string> candidate_ips;
|
||||
if (!ruc->eip_.empty()) {
|
||||
candidate_ips.insert(ruc->eip_);
|
||||
}
|
||||
|
||||
// Try to discover from api of request, if api_as_candidates enabled.
|
||||
if ((err = api_server_as_candidates(ruc->api_, candidate_ips)) != srs_success) {
|
||||
srs_warn("ignore discovering ip from api %s, err %s", ruc->api_.c_str(), srs_error_summary(err).c_str());
|
||||
srs_freep(err);
|
||||
}
|
||||
|
||||
// If not * or 0.0.0.0, use the candidate as exposed IP.
|
||||
string candidate = _srs_config->get_rtc_server_candidates();
|
||||
if (candidate != "*" && candidate != "0.0.0.0") {
|
||||
candidate_ips.push_back(candidate);
|
||||
candidate_ips.insert(candidate);
|
||||
return candidate_ips;
|
||||
}
|
||||
|
||||
// For * or 0.0.0.0, auto discovery expose ip addresses.
|
||||
std::vector<SrsIPAddress*>& ips = srs_get_local_ips();
|
||||
// Discover from local network interface addresses.
|
||||
vector<SrsIPAddress*>& ips = srs_get_local_ips();
|
||||
if (ips.empty()) {
|
||||
return candidate_ips;
|
||||
}
|
||||
|
@ -180,7 +228,7 @@ static std::vector<std::string> get_candidate_ips()
|
|||
continue;
|
||||
}
|
||||
|
||||
candidate_ips.push_back(ip->ip);
|
||||
candidate_ips.insert(ip->ip);
|
||||
srs_trace("Best matched ip=%s, ifname=%s", ip->ip.c_str(), ip->ifname.c_str());
|
||||
}
|
||||
|
||||
|
@ -195,7 +243,7 @@ static std::vector<std::string> get_candidate_ips()
|
|||
continue;
|
||||
}
|
||||
|
||||
candidate_ips.push_back(ip->ip);
|
||||
candidate_ips.insert(ip->ip);
|
||||
srs_trace("No best matched, use first ip=%s, ifname=%s", ip->ip.c_str(), ip->ifname.c_str());
|
||||
return candidate_ips;
|
||||
}
|
||||
|
@ -203,7 +251,7 @@ static std::vector<std::string> get_candidate_ips()
|
|||
// We use the first one.
|
||||
if (candidate_ips.empty()) {
|
||||
SrsIPAddress* ip = ips[0];
|
||||
candidate_ips.push_back(ip->ip);
|
||||
candidate_ips.insert(ip->ip);
|
||||
srs_warn("No best matched, use first ip=%s, ifname=%s", ip->ip.c_str(), ip->ifname.c_str());
|
||||
return candidate_ips;
|
||||
}
|
||||
|
@ -524,19 +572,17 @@ srs_error_t SrsRtcServer::do_create_session(SrsRtcUserConfig* ruc, SrsSdp& local
|
|||
local_sdp.set_fingerprint(_srs_rtc_dtls_certificate->get_fingerprint());
|
||||
|
||||
// We allows to mock the eip of server.
|
||||
if (!ruc->eip_.empty()) {
|
||||
string host;
|
||||
int port = _srs_config->get_rtc_server_listen();
|
||||
srs_parse_hostport(ruc->eip_, host, port);
|
||||
|
||||
local_sdp.add_candidate(host, port, "host");
|
||||
srs_trace("RTC: Use candidate mock_eip %s as %s:%d", ruc->eip_.c_str(), host.c_str(), port);
|
||||
} else {
|
||||
std::vector<string> candidate_ips = get_candidate_ips();
|
||||
for (int i = 0; i < (int)candidate_ips.size(); ++i) {
|
||||
local_sdp.add_candidate(candidate_ips[i], _srs_config->get_rtc_server_listen(), "host");
|
||||
if (true) {
|
||||
int listen_port = _srs_config->get_rtc_server_listen();
|
||||
set<string> candidates = discover_candidates(ruc);
|
||||
for (set<string>::iterator it = candidates.begin(); it != candidates.end(); ++it) {
|
||||
string hostname; int port = listen_port;
|
||||
srs_parse_hostport(*it, hostname,port);
|
||||
local_sdp.add_candidate(hostname, port, "host");
|
||||
}
|
||||
srs_trace("RTC: Use candidates %s", srs_join_vector_string(candidate_ips, ", ").c_str());
|
||||
|
||||
vector<string> v = vector<string>(candidates.begin(), candidates.end());
|
||||
srs_trace("RTC: Use candidates %s", srs_join_vector_string(v, ", ").c_str());
|
||||
}
|
||||
|
||||
// Setup the negotiate DTLS by config.
|
||||
|
|
|
@ -78,6 +78,7 @@ public:
|
|||
SrsSdp remote_sdp_;
|
||||
std::string eip_;
|
||||
std::string codec_;
|
||||
std::string api_;
|
||||
|
||||
// Generated data.
|
||||
SrsRequest* req_;
|
||||
|
|
|
@ -49,7 +49,7 @@ std::string srs_listener_type2string(SrsListenerType type)
|
|||
case SrsListenerHttpStream:
|
||||
return "HTTP-Server";
|
||||
case SrsListenerHttpsStream:
|
||||
return "HTTP-Server";
|
||||
return "HTTPS-Server";
|
||||
case SrsListenerMpegTsOverUdp:
|
||||
return "MPEG-TS over UDP";
|
||||
case SrsListenerFlv:
|
||||
|
|
|
@ -448,7 +448,7 @@ public:
|
|||
// @param h the event handler for source.
|
||||
// @param pps the matched source, if success never be NULL.
|
||||
virtual srs_error_t fetch_or_create(SrsRequest* r, ISrsLiveSourceHandler* h, SrsLiveSource** pps);
|
||||
private:
|
||||
public:
|
||||
// Get the exists source, NULL when not exists.
|
||||
// update the request and return the exists source.
|
||||
virtual SrsLiveSource* fetch(SrsRequest* r);
|
||||
|
|
|
@ -68,7 +68,7 @@ typedef SrsCplxError* srs_error_t;
|
|||
|
||||
#include <string>
|
||||
// The context ID, it default to a string object, we can also use other objects.
|
||||
// @remark User can directly user string as SrsContextId, we user struct to ensure the context is an object.
|
||||
// @remark User can directly use string as SrsContextId, we use struct to ensure the context is an object.
|
||||
#if 1
|
||||
class _SrsContextId
|
||||
{
|
||||
|
|
|
@ -9,6 +9,6 @@
|
|||
|
||||
#define VERSION_MAJOR 4
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 212
|
||||
#define VERSION_REVISION 220
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,6 +9,6 @@
|
|||
|
||||
#define VERSION_MAJOR 5
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 19
|
||||
#define VERSION_REVISION 20
|
||||
|
||||
#endif
|
||||
|
|
|
@ -107,6 +107,7 @@
|
|||
///////////////////////////////////////////////////////////
|
||||
#define SRS_CONSTS_NULL_FILE "/dev/null"
|
||||
#define SRS_CONSTS_LOCALHOST "127.0.0.1"
|
||||
#define SRS_CONSTS_LOCALHOST_NAME "localhost"
|
||||
#define SRS_CONSTS_LOOPBACK "0.0.0.0"
|
||||
#define SRS_CONSTS_LOOPBACK6 "::"
|
||||
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
#include <iomanip>
|
||||
using namespace std;
|
||||
|
||||
// For CentOS 6 or C++98, @see https://github.com/ossrs/srs/issues/2815
|
||||
#ifndef UINT32_MAX
|
||||
#define UINT32_MAX (4294967295U)
|
||||
#endif
|
||||
|
||||
#define SRS_MP4_EOF_SIZE 0
|
||||
#define SRS_MP4_USE_LARGE_SIZE 1
|
||||
|
||||
|
|
|
@ -384,6 +384,14 @@ srs_error_t run_directly_or_daemon()
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// Try to load the config if docker detect failed.
|
||||
if (!_srs_in_docker) {
|
||||
_srs_in_docker = _srs_config->get_in_docker();
|
||||
if (_srs_in_docker) {
|
||||
srs_trace("enable in_docker by config");
|
||||
}
|
||||
}
|
||||
|
||||
// Load daemon from config, disable it for docker.
|
||||
// @see https://github.com/ossrs/srs/issues/1594
|
||||
bool run_as_daemon = _srs_config->get_daemon();
|
||||
|
|
|
@ -260,7 +260,7 @@ rtmp_client::rtmp_client(std::string key_path):_key_path(key_path)
|
|||
_streamname = ret_vec[1];
|
||||
}
|
||||
std::stringstream url_ss;
|
||||
|
||||
|
||||
std::vector<std::string> ip_ports = _srs_config->get_listens();
|
||||
int port = 0;
|
||||
std::string ip;
|
||||
|
@ -271,24 +271,19 @@ rtmp_client::rtmp_client(std::string key_path):_key_path(key_path)
|
|||
break;
|
||||
}
|
||||
}
|
||||
port = (port == 0) ? 1935 : port;
|
||||
if (_vhost == DEF_VHOST) {
|
||||
url_ss << "rtmp://127.0.0.1:" << port
|
||||
<< "/" << _appname
|
||||
<< "/" << _streamname;
|
||||
} else {
|
||||
if (_appname.find("?") == std::string::npos) {
|
||||
url_ss << "rtmp://127.0.0.1:" << port
|
||||
<< "/" << _appname << "?vhost=" << _vhost
|
||||
<< "/" << _streamname;
|
||||
} else {
|
||||
url_ss << "rtmp://127.0.0.1:" << port
|
||||
<< "/" << _appname << "&vhost=" << _vhost
|
||||
<< "/" << _streamname;
|
||||
}
|
||||
}
|
||||
|
||||
_url = url_ss.str();
|
||||
port = (port == 0) ? SRS_CONSTS_RTMP_DEFAULT_PORT : port;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "rtmp://" << SRS_CONSTS_LOCALHOST;
|
||||
ss << ":" << port;
|
||||
ss << "/" << _appname;
|
||||
if (_vhost != DEF_VHOST) {
|
||||
ss << "?vhost=" << _vhost;
|
||||
}
|
||||
ss << "/" << _streamname;
|
||||
|
||||
_url = ss.str();
|
||||
|
||||
_h264_sps_changed = false;
|
||||
_h264_pps_changed = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue