mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix #274: http-callback support on_dvr when reap a dvr file. 2.0.89
This commit is contained in:
parent
dd2c7e0b4d
commit
dc11418c79
12 changed files with 207 additions and 7 deletions
|
@ -1426,6 +1426,7 @@ int SrsConfig::check_config()
|
|||
string m = conf->at(j)->name.c_str();
|
||||
if (m != "enabled" && m != "on_connect" && m != "on_close" && m != "on_publish"
|
||||
&& m != "on_unpublish" && m != "on_play" && m != "on_stop"
|
||||
&& m != "on_dvr"
|
||||
) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("unsupported vhost http_hooks directive %s, ret=%d", m.c_str(), ret);
|
||||
|
@ -2335,6 +2336,17 @@ SrsConfDirective* SrsConfig::get_vhost_on_stop(string vhost)
|
|||
return conf->get("on_stop");
|
||||
}
|
||||
|
||||
SrsConfDirective* SrsConfig::get_vhost_on_dvr(string vhost)
|
||||
{
|
||||
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
|
||||
|
||||
if (!conf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return conf->get("on_dvr");
|
||||
}
|
||||
|
||||
bool SrsConfig::get_bw_check_enabled(string vhost)
|
||||
{
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
|
|
|
@ -610,6 +610,11 @@ public:
|
|||
* @return the on_stop callback directive, the args is the url to callback.
|
||||
*/
|
||||
virtual SrsConfDirective* get_vhost_on_stop(std::string vhost);
|
||||
/**
|
||||
* get the on_dvr callbacks of vhost.
|
||||
* @return the on_dvr callback directive, the args is the url to callback.
|
||||
*/
|
||||
virtual SrsConfDirective* get_vhost_on_dvr(std::string vhost);
|
||||
// bwct(bandwidth check tool) section
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -404,6 +404,30 @@ int SrsDvrPlan::flv_close()
|
|||
return ret;
|
||||
}
|
||||
|
||||
#ifdef SRS_AUTO_HTTP_CALLBACK
|
||||
SrsRequest* req = _req;
|
||||
if (_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
|
||||
// HTTP: on_dvr
|
||||
SrsConfDirective* on_dvr = _srs_config->get_vhost_on_dvr(req->vhost);
|
||||
if (!on_dvr) {
|
||||
srs_info("ignore the empty http callback: on_dvr");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int connection_id = _srs_context->get_id();
|
||||
std::string ip = req->ip;
|
||||
std::string cwd = _srs_config->cwd();
|
||||
std::string file = segment->path;
|
||||
for (int i = 0; i < (int)on_dvr->args.size(); i++) {
|
||||
std::string url = on_dvr->args.at(i);
|
||||
if ((ret = SrsHttpHooks::on_dvr(url, connection_id, ip, req, cwd, file)) != ERROR_SUCCESS) {
|
||||
srs_error("hook client on_dvr failed. url=%s, ret=%d", url.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -379,5 +379,61 @@ void SrsHttpHooks::on_stop(string url, int client_id, string ip, SrsRequest* req
|
|||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
int SrsHttpHooks::on_dvr(string url, int client_id, string ip, SrsRequest* req, string cwd, string file)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
SrsHttpUri uri;
|
||||
if ((ret = uri.initialize(url)) != ERROR_SUCCESS) {
|
||||
srs_error("http uri parse on_dvr url failed, ignored. "
|
||||
"client_id=%d, url=%s, ret=%d", client_id, url.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
ss << __SRS_JOBJECT_START
|
||||
<< __SRS_JFIELD_STR("action", "on_dvr") << __SRS_JFIELD_CONT
|
||||
<< __SRS_JFIELD_ORG("client_id", client_id) << __SRS_JFIELD_CONT
|
||||
<< __SRS_JFIELD_STR("ip", ip) << __SRS_JFIELD_CONT
|
||||
<< __SRS_JFIELD_STR("vhost", req->vhost) << __SRS_JFIELD_CONT
|
||||
<< __SRS_JFIELD_STR("app", req->app) << __SRS_JFIELD_CONT
|
||||
<< __SRS_JFIELD_STR("stream", req->stream) << __SRS_JFIELD_CONT
|
||||
<< __SRS_JFIELD_STR("cwd", cwd) << __SRS_JFIELD_CONT
|
||||
<< __SRS_JFIELD_STR("file", file)
|
||||
<< __SRS_JOBJECT_END;
|
||||
std::string data = ss.str();
|
||||
std::string res;
|
||||
int status_code;
|
||||
|
||||
SrsHttpClient http;
|
||||
if ((ret = http.post(&uri, data, status_code, res)) != ERROR_SUCCESS) {
|
||||
srs_error("http post on_dvr uri failed, ignored. "
|
||||
"client_id=%d, url=%s, request=%s, response=%s, ret=%d",
|
||||
client_id, url.c_str(), data.c_str(), res.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ensure the http status is ok.
|
||||
// https://github.com/winlinvip/simple-rtmp-server/issues/158
|
||||
if (status_code != SRS_CONSTS_HTTP_OK) {
|
||||
ret = ERROR_HTTP_STATUS_INVLIAD;
|
||||
srs_error("http hook on_dvr status failed. "
|
||||
"client_id=%d, code=%d, ret=%d", client_id, status_code, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (res.empty() || res != SRS_HTTP_RESPONSE_OK) {
|
||||
ret = ERROR_HTTP_DATA_INVLIAD;
|
||||
srs_warn("http hook on_dvr validate failed, ignored. "
|
||||
"client_id=%d, res=%s, ret=%d", client_id, res.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
srs_trace("http hook on_dvr success. "
|
||||
"client_id=%d, url=%s, request=%s, response=%s, ret=%d",
|
||||
client_id, url.c_str(), data.c_str(), res.c_str(), ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -58,7 +58,6 @@ public:
|
|||
* @param client_id the id of client on server.
|
||||
* @param url the api server url, to valid the client.
|
||||
* ignore if empty.
|
||||
* @return valid failed or connect to the url failed.
|
||||
*/
|
||||
static int on_connect(std::string url, int client_id, std::string ip, SrsRequest* req);
|
||||
/**
|
||||
|
@ -73,7 +72,6 @@ public:
|
|||
* @param client_id the id of client on server.
|
||||
* @param url the api server url, to valid the client.
|
||||
* ignore if empty.
|
||||
* @return valid failed or connect to the url failed.
|
||||
*/
|
||||
static int on_publish(std::string url, int client_id, std::string ip, SrsRequest* req);
|
||||
/**
|
||||
|
@ -88,7 +86,6 @@ public:
|
|||
* @param client_id the id of client on server.
|
||||
* @param url the api server url, to valid the client.
|
||||
* ignore if empty.
|
||||
* @return valid failed or connect to the url failed.
|
||||
*/
|
||||
static int on_play(std::string url, int client_id, std::string ip, SrsRequest* req);
|
||||
/**
|
||||
|
@ -98,6 +95,15 @@ public:
|
|||
* ignore if empty.
|
||||
*/
|
||||
static void on_stop(std::string url, int client_id, std::string ip, SrsRequest* req);
|
||||
/**
|
||||
* on_dvr hook, when reap a dvr file.
|
||||
* @param client_id the id of client on server.
|
||||
* @param url the api server url, to process the event.
|
||||
* ignore if empty.
|
||||
* @param cwd the current work directory, used to resolve the reltive file path.
|
||||
* @param file the file path, can be relative or absolute path.
|
||||
*/
|
||||
static int on_dvr(std::string url, int client_id, std::string ip, SrsRequest* req, std::string cwd, std::string file);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -135,6 +135,9 @@ int SrsRtmpConn::do_cycle()
|
|||
}
|
||||
srs_verbose("rtmp connect app success");
|
||||
|
||||
// set client ip to request.
|
||||
req->ip = ip;
|
||||
|
||||
// discovery vhost, resolve the vhost from config
|
||||
SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req->vhost);
|
||||
if (parsed_vhost) {
|
||||
|
|
|
@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
// current release version
|
||||
#define VERSION_MAJOR 2
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 88
|
||||
#define VERSION_REVISION 89
|
||||
// server info.
|
||||
#define RTMP_SIG_SRS_KEY "SRS"
|
||||
#define RTMP_SIG_SRS_ROLE "origin/edge server"
|
||||
|
|
|
@ -91,6 +91,7 @@ SrsRequest* SrsRequest::copy()
|
|||
{
|
||||
SrsRequest* cp = new SrsRequest();
|
||||
|
||||
cp->ip = ip;
|
||||
cp->app = app;
|
||||
cp->objectEncoding = objectEncoding;
|
||||
cp->pageUrl = pageUrl;
|
||||
|
|
|
@ -53,6 +53,9 @@ class IMergeReadHandler;
|
|||
*/
|
||||
class SrsRequest
|
||||
{
|
||||
public:
|
||||
// client ip.
|
||||
std::string ip;
|
||||
public:
|
||||
/**
|
||||
* tcUrl: rtmp://request_vhost:port/app/stream
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue