Merge branch 'develop' into merge/develop

pull/2943/head
winlin 4 years ago
commit f41eb05481

@ -14,6 +14,7 @@
#include <srs_protocol_utility.hpp> #include <srs_protocol_utility.hpp>
#include <srs_app_config.hpp> #include <srs_app_config.hpp>
#include <srs_app_statistic.hpp> #include <srs_app_statistic.hpp>
#include <srs_app_http_hooks.hpp>
#include <srs_app_utility.hpp> #include <srs_app_utility.hpp>
#include <unistd.h> #include <unistd.h>
#include <deque> #include <deque>
@ -128,6 +129,10 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
ruc.req_->vhost = parsed_vhost->arg0(); 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. // For client to specifies the candidate(EIP) of server.
string eip = r->query_get("eip"); string eip = r->query_get("eip");
if (eip.empty()) { if (eip.empty()) {
@ -242,6 +247,39 @@ srs_error_t SrsGoApiRtcPlay::check_remote_sdp(const SrsSdp& remote_sdp)
return err; 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<string> 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) SrsGoApiRtcPublish::SrsGoApiRtcPublish(SrsRtcServer* server)
{ {
server_ = server; server_ = server;
@ -351,6 +389,10 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter* w, ISrsHtt
ruc.req_->vhost = parsed_vhost->arg0(); 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. // For client to specifies the candidate(EIP) of server.
string eip = r->query_get("eip"); string eip = r->query_get("eip");
if (eip.empty()) { if (eip.empty()) {
@ -457,6 +499,39 @@ srs_error_t SrsGoApiRtcPublish::check_remote_sdp(const SrsSdp& remote_sdp)
return err; 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<string> 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) SrsGoApiRtcNACK::SrsGoApiRtcNACK(SrsRtcServer* server)
{ {
server_ = server; server_ = server;

@ -27,6 +27,8 @@ public:
private: private:
virtual srs_error_t do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, SrsJsonObject* res); virtual srs_error_t do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, SrsJsonObject* res);
srs_error_t check_remote_sdp(const SrsSdp& remote_sdp); 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 class SrsGoApiRtcPublish : public ISrsHttpHandler
@ -41,6 +43,8 @@ public:
private: private:
virtual srs_error_t do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, SrsJsonObject* res); virtual srs_error_t do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, SrsJsonObject* res);
srs_error_t check_remote_sdp(const SrsSdp& remote_sdp); 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 class SrsGoApiRtcNACK : public ISrsHttpHandler

@ -44,7 +44,7 @@ using namespace std;
#include <srs_app_threads.hpp> #include <srs_app_threads.hpp>
#include <srs_service_log.hpp> #include <srs_service_log.hpp>
#include <srs_app_log.hpp> #include <srs_app_log.hpp>
#include <srs_app_http_hooks.hpp>
#include <srs_protocol_kbps.hpp> #include <srs_protocol_kbps.hpp>
SrsPps* _srs_pps_sstuns = NULL; SrsPps* _srs_pps_sstuns = NULL;
@ -379,6 +379,10 @@ SrsRtcPlayStream::SrsRtcPlayStream(SrsRtcConnection* s, const SrsContextId& cid)
SrsRtcPlayStream::~SrsRtcPlayStream() SrsRtcPlayStream::~SrsRtcPlayStream()
{ {
if (req_) {
http_hooks_on_stop();
}
// TODO: FIXME: Should not do callback in de-constructor? // TODO: FIXME: Should not do callback in de-constructor?
if (_srs_rtc_hijacker) { if (_srs_rtc_hijacker) {
_srs_rtc_hijacker->on_stop_play(session_, this, req_); _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; 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<string> 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) SrsRtcPublishRtcpTimer::SrsRtcPublishRtcpTimer(SrsRtcPublishStream* p) : p_(p)
{ {
_srs_hybrid->timer1s()->subscribe(this); _srs_hybrid->timer1s()->subscribe(this);
@ -975,6 +1008,10 @@ SrsRtcPublishStream::SrsRtcPublishStream(SrsRtcConnection* session, const SrsCon
SrsRtcPublishStream::~SrsRtcPublishStream() SrsRtcPublishStream::~SrsRtcPublishStream()
{ {
if (req) {
http_hooks_on_unpublish();
}
srs_freep(timer_rtcp_); srs_freep(timer_rtcp_);
srs_freep(timer_twcc_); 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<string> 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() ISrsRtcConnectionHijacker::ISrsRtcConnectionHijacker()
{ {
} }

@ -264,6 +264,8 @@ private:
// Interface ISrsRtcPLIWorkerHandler // Interface ISrsRtcPLIWorkerHandler
public: public:
virtual srs_error_t do_request_keyframe(uint32_t ssrc, SrsContextId cid); 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. // A fast timer for publish stream, for RTCP feedback.
@ -375,6 +377,8 @@ private:
SrsRtcVideoRecvTrack* get_video_track(uint32_t ssrc); SrsRtcVideoRecvTrack* get_video_track(uint32_t ssrc);
void update_rtt(uint32_t ssrc, int rtt); void update_rtt(uint32_t ssrc, int rtt);
void update_send_report_time(uint32_t ssrc, const SrsNtp& ntp); void update_send_report_time(uint32_t ssrc, const SrsNtp& ntp);
private:
virtual void http_hooks_on_unpublish();
}; };
// Callback for RTC connection. // Callback for RTC connection.

Loading…
Cancel
Save