From 9bf5005bddf71060795f25c3b13d3fcfdccb9d30 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 8 Aug 2021 00:30:08 +0800 Subject: [PATCH 1/2] Squash: Merge SRS4 --- CHANGELOG.md | 1 + README.md | 3 ++- trunk/3rdparty/signaling/README.md | 2 +- trunk/3rdparty/srs-bench/README.md | 2 +- trunk/src/app/srs_app_latest_version.cpp | 11 +++++++++-- trunk/src/core/srs_core_version4.hpp | 2 +- 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f241ba78d..c9bea3681 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ The changelog for SRS. ## SRS 4.0 Changelog +* v4.0, 2021-08-07, Merge [#2514](https://github.com/ossrs/srs/pull/2514), Get original client ip instead of proxy ip, for rtc api #2514. 4.0.150 * v4.0, 2021-08-07, Fix [#2508](https://github.com/ossrs/srs/pull/2508), Support features query by API. 4.0.149 * v4.0, 2021-07-25, Fix build failed. 4.0.146 * v4.0, 2021-07-24, Merge [#2373](https://github.com/ossrs/srs/pull/2373), RTC: Fix NACK negotiation bug for Firefox. 4.0.145 diff --git a/README.md b/README.md index 784941fa1..9c9554ed8 100755 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ please set the CANDIDATE ([CN][v4_CN_WebRTC#config-candidate],[EN][v4_EN_WebRTC# ```bash docker run --rm -it -p 1935:1935 -p 1985:1985 -p 8080:8080 \ --env CANDIDATE=$(ifconfig en0 inet| grep 'inet '|awk '{print $2}') -p 8000:8000/udp \ - ossrs/srs:v4.0.139 ./objs/srs -c conf/srs.conf + ossrs/srs:4 ./objs/srs -c conf/srs.conf ``` @@ -219,6 +219,7 @@ Please read [CHANGELOG](CHANGELOG.md#changelog). ## Releases +* 2020-08-07, Release [v4.0.150](https://github.com/ossrs/srs/releases/tag/v4.0.150), 4.0 dev2, v4.0.150, 145289 lines. * 2020-07-25, Release [v4.0.146](https://github.com/ossrs/srs/releases/tag/v4.0.146), 4.0 dev1, v4.0.146, 144026 lines. * 2020-07-04, Release [v4.0.139](https://github.com/ossrs/srs/releases/tag/v4.0.139), 4.0 dev0, v4.0.139, 143245 lines. * 2020-06-27, [Release v3.0-r0][r3.0r0], 3.0 release0, 3.0.141, 122674 lines. diff --git a/trunk/3rdparty/signaling/README.md b/trunk/3rdparty/signaling/README.md index f20c724f9..b534457f0 100644 --- a/trunk/3rdparty/signaling/README.md +++ b/trunk/3rdparty/signaling/README.md @@ -9,7 +9,7 @@ WebRTC signaling for https://github.com/ossrs/srs ```bash docker run --rm --env CANDIDATE=$(ifconfig en0 inet| grep 'inet '|awk '{print $2}') \ -p 1935:1935 -p 8080:8080 -p 1985:1985 -p 8000:8000/udp \ - registry.cn-hangzhou.aliyuncs.com/ossrs/srs:v4.0.95 \ + registry.cn-hangzhou.aliyuncs.com/ossrs/srs:4 \ objs/srs -c conf/rtc.conf ``` diff --git a/trunk/3rdparty/srs-bench/README.md b/trunk/3rdparty/srs-bench/README.md index d45820cc8..9fb5ff9ca 100644 --- a/trunk/3rdparty/srs-bench/README.md +++ b/trunk/3rdparty/srs-bench/README.md @@ -105,7 +105,7 @@ ffmpeg -re -i doc/source.200kbps.768x320.flv -c copy -f flv -y rtmp://localhost/ if [[ ! -z $(ifconfig en0 inet| grep 'inet '|awk '{print $2}') ]]; then docker run -p 1935:1935 -p 8080:8080 -p 1985:1985 -p 8000:8000/udp \ --rm --env CANDIDATE=$(ifconfig en0 inet| grep 'inet '|awk '{print $2}')\ - registry.cn-hangzhou.aliyuncs.com/ossrs/srs:v4.0.76 objs/srs -c conf/rtc.conf + registry.cn-hangzhou.aliyuncs.com/ossrs/srs:4 objs/srs -c conf/rtc.conf fi ``` diff --git a/trunk/src/app/srs_app_latest_version.cpp b/trunk/src/app/srs_app_latest_version.cpp index 54a08aa8c..53576dfa8 100644 --- a/trunk/src/app/srs_app_latest_version.cpp +++ b/trunk/src/app/srs_app_latest_version.cpp @@ -58,13 +58,15 @@ void srs_build_features(stringstream& ss) SrsConfDirective* conf = root->at(i); if (!rtsp && conf->is_stream_caster() && _srs_config->get_stream_caster_enabled(conf)) { - if (_srs_config->get_stream_caster_engine(conf) == "rtsp") { + string engine = _srs_config->get_stream_caster_engine(conf); + if (engine == "rtsp") { rtsp = true; } } if (conf->is_vhost() && _srs_config->get_vhost_enabled(conf)) { nn_vhosts++; + if (!forward && _srs_config->get_forward_enabled(conf)) { forward = true; } @@ -96,14 +98,19 @@ void srs_build_features(stringstream& ss) security = true; } - for (int j = 0; j < (int)conf->directives.size(); j++) { + for (int j = 0; j < (int)conf->directives.size() && j < 64; j++) { SrsConfDirective* prop = conf->directives.at(j); + if (!ingest && prop->name == "ingest" && _srs_config->get_ingest_enabled(prop)) { ingest = true; } if (!transcode && prop->name == "transcode" && _srs_config->get_transcode_enabled(prop)) { transcode = true; } + + if (ingest && transcode) { + break; + } } } } diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index ecdec4892..e856ee24a 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 0 -#define VERSION_REVISION 149 +#define VERSION_REVISION 150 #endif From 345b691895fcd78bcd4a86b1915ab7b5bf8dd525 Mon Sep 17 00:00:00 2001 From: Haibo Chen Date: Tue, 10 Aug 2021 09:41:20 +0800 Subject: [PATCH 2/2] support http hooks for rtc: on_play/stop/publish/unpublish (#2509) * support http hooks for rtc: on_play/stop/publish/unpublish * Update srs_app_rtc_conn.cpp * Update srs_app_rtc_conn.cpp --- trunk/src/app/srs_app_rtc_api.cpp | 75 ++++++++++++++++++++++++++++++ trunk/src/app/srs_app_rtc_api.hpp | 4 ++ trunk/src/app/srs_app_rtc_conn.cpp | 66 +++++++++++++++++++++++++- trunk/src/app/srs_app_rtc_conn.hpp | 4 ++ 4 files changed, 148 insertions(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_rtc_api.cpp b/trunk/src/app/srs_app_rtc_api.cpp index 16db0416e..c4047c225 100644 --- a/trunk/src/app/srs_app_rtc_api.cpp +++ b/trunk/src/app/srs_app_rtc_api.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -128,6 +129,10 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe ruc.req_->vhost = parsed_vhost->arg0(); } + if ((err = http_hooks_on_play(ruc.req_)) != srs_success) { + return srs_error_wrap(err, "RTC: http_hooks_on_play"); + } + // For client to specifies the candidate(EIP) of server. string eip = r->query_get("eip"); if (eip.empty()) { @@ -242,6 +247,39 @@ srs_error_t SrsGoApiRtcPlay::check_remote_sdp(const SrsSdp& remote_sdp) return err; } +srs_error_t SrsGoApiRtcPlay::http_hooks_on_play(SrsRequest* req) +{ + srs_error_t err = srs_success; + + if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { + return err; + } + + // the http hooks will cause context switch, + // so we must copy all hooks for the on_connect may freed. + // @see https://github.com/ossrs/srs/issues/475 + vector hooks; + + if (true) { + SrsConfDirective* conf = _srs_config->get_vhost_on_play(req->vhost); + + if (!conf) { + return err; + } + + hooks = conf->args; + } + + for (int i = 0; i < (int)hooks.size(); i++) { + std::string url = hooks.at(i); + if ((err = SrsHttpHooks::on_play(url, req)) != srs_success) { + return srs_error_wrap(err, "on_play %s", url.c_str()); + } + } + + return err; +} + SrsGoApiRtcPublish::SrsGoApiRtcPublish(SrsRtcServer* server) { server_ = server; @@ -351,6 +389,10 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter* w, ISrsHtt ruc.req_->vhost = parsed_vhost->arg0(); } + if ((err = http_hooks_on_publish(ruc.req_)) != srs_success) { + return srs_error_wrap(err, "RTC: http_hooks_on_publish"); + } + // For client to specifies the candidate(EIP) of server. string eip = r->query_get("eip"); if (eip.empty()) { @@ -457,6 +499,39 @@ srs_error_t SrsGoApiRtcPublish::check_remote_sdp(const SrsSdp& remote_sdp) return err; } +srs_error_t SrsGoApiRtcPublish::http_hooks_on_publish(SrsRequest* req) +{ + srs_error_t err = srs_success; + + if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { + return err; + } + + // the http hooks will cause context switch, + // so we must copy all hooks for the on_connect may freed. + // @see https://github.com/ossrs/srs/issues/475 + vector hooks; + + if (true) { + SrsConfDirective* conf = _srs_config->get_vhost_on_publish(req->vhost); + + if (!conf) { + return err; + } + + hooks = conf->args; + } + + for (int i = 0; i < (int)hooks.size(); i++) { + std::string url = hooks.at(i); + if ((err = SrsHttpHooks::on_publish(url, req)) != srs_success) { + return srs_error_wrap(err, "rtmp on_publish %s", url.c_str()); + } + } + + return err; +} + SrsGoApiRtcNACK::SrsGoApiRtcNACK(SrsRtcServer* server) { server_ = server; diff --git a/trunk/src/app/srs_app_rtc_api.hpp b/trunk/src/app/srs_app_rtc_api.hpp index 7c849827d..8ee99b40c 100644 --- a/trunk/src/app/srs_app_rtc_api.hpp +++ b/trunk/src/app/srs_app_rtc_api.hpp @@ -27,6 +27,8 @@ public: private: virtual srs_error_t do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, SrsJsonObject* res); srs_error_t check_remote_sdp(const SrsSdp& remote_sdp); +private: + virtual srs_error_t http_hooks_on_play(SrsRequest* req); }; class SrsGoApiRtcPublish : public ISrsHttpHandler @@ -41,6 +43,8 @@ public: private: virtual srs_error_t do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, SrsJsonObject* res); srs_error_t check_remote_sdp(const SrsSdp& remote_sdp); +private: + virtual srs_error_t http_hooks_on_publish(SrsRequest* req); }; class SrsGoApiRtcNACK : public ISrsHttpHandler diff --git a/trunk/src/app/srs_app_rtc_conn.cpp b/trunk/src/app/srs_app_rtc_conn.cpp index a681c0038..a765046f9 100644 --- a/trunk/src/app/srs_app_rtc_conn.cpp +++ b/trunk/src/app/srs_app_rtc_conn.cpp @@ -44,7 +44,7 @@ using namespace std; #include #include #include - +#include #include SrsPps* _srs_pps_sstuns = NULL; @@ -379,6 +379,10 @@ SrsRtcPlayStream::SrsRtcPlayStream(SrsRtcConnection* s, const SrsContextId& cid) SrsRtcPlayStream::~SrsRtcPlayStream() { + if (req_) { + http_hooks_on_stop(); + } + // TODO: FIXME: Should not do callback in de-constructor? if (_srs_rtc_hijacker) { _srs_rtc_hijacker->on_stop_play(session_, this, req_); @@ -866,6 +870,35 @@ srs_error_t SrsRtcPlayStream::do_request_keyframe(uint32_t ssrc, SrsContextId ci return err; } +void SrsRtcPlayStream::http_hooks_on_stop() +{ + if (!_srs_config->get_vhost_http_hooks_enabled(req_->vhost)) { + return; + } + + // the http hooks will cause context switch, + // so we must copy all hooks for the on_connect may freed. + // @see https://github.com/ossrs/srs/issues/475 + vector hooks; + + if (true) { + SrsConfDirective* conf = _srs_config->get_vhost_on_stop(req_->vhost); + + if (!conf) { + return; + } + + hooks = conf->args; + } + + for (int i = 0; i < (int)hooks.size(); i++) { + std::string url = hooks.at(i); + SrsHttpHooks::on_stop(url, req_); + } + + return; +} + SrsRtcPublishRtcpTimer::SrsRtcPublishRtcpTimer(SrsRtcPublishStream* p) : p_(p) { _srs_hybrid->timer1s()->subscribe(this); @@ -975,6 +1008,10 @@ SrsRtcPublishStream::SrsRtcPublishStream(SrsRtcConnection* session, const SrsCon SrsRtcPublishStream::~SrsRtcPublishStream() { + if (req) { + http_hooks_on_unpublish(); + } + srs_freep(timer_rtcp_); srs_freep(timer_twcc_); @@ -1639,6 +1676,33 @@ void SrsRtcPublishStream::update_send_report_time(uint32_t ssrc, const SrsNtp& n } } +void SrsRtcPublishStream::http_hooks_on_unpublish() +{ + if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) { + return; + } + + // the http hooks will cause context switch, + // so we must copy all hooks for the on_connect may freed. + // @see https://github.com/ossrs/srs/issues/475 + vector hooks; + + if (true) { + SrsConfDirective* conf = _srs_config->get_vhost_on_unpublish(req->vhost); + + if (!conf) { + return; + } + + hooks = conf->args; + } + + for (int i = 0; i < (int)hooks.size(); i++) { + std::string url = hooks.at(i); + SrsHttpHooks::on_unpublish(url, req); + } +} + ISrsRtcConnectionHijacker::ISrsRtcConnectionHijacker() { } diff --git a/trunk/src/app/srs_app_rtc_conn.hpp b/trunk/src/app/srs_app_rtc_conn.hpp index da96551a4..934533e2f 100644 --- a/trunk/src/app/srs_app_rtc_conn.hpp +++ b/trunk/src/app/srs_app_rtc_conn.hpp @@ -264,6 +264,8 @@ private: // Interface ISrsRtcPLIWorkerHandler public: virtual srs_error_t do_request_keyframe(uint32_t ssrc, SrsContextId cid); +private: + virtual void http_hooks_on_stop(); }; // A fast timer for publish stream, for RTCP feedback. @@ -375,6 +377,8 @@ private: SrsRtcVideoRecvTrack* get_video_track(uint32_t ssrc); void update_rtt(uint32_t ssrc, int rtt); void update_send_report_time(uint32_t ssrc, const SrsNtp& ntp); +private: + virtual void http_hooks_on_unpublish(); }; // Callback for RTC connection.