refine http hooks, donot pass the known variable.

pull/133/head
winlin 10 years ago
parent c49bc0628e
commit 3b4bd194b6

@ -64,6 +64,8 @@ file
../../src/protocol/srs_rtmp_utility.hpp,
../../src/protocol/srs_rtmp_utility.cpp,
app readonly separator,
../../src/app/srs_app_async_call.hpp,
../../src/app/srs_app_async_call.cpp,
../../src/app/srs_app_bandwidth.hpp,
../../src/app/srs_app_bandwidth.cpp,
../../src/app/srs_app_conn.hpp,

@ -520,13 +520,10 @@ int SrsDvrAsyncCallOnDvr::call()
return ret;
}
int connection_id = _srs_context->get_id();
std::string ip = req->ip;
std::string cwd = _srs_config->cwd();
std::string file = 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) {
if ((ret = SrsHttpHooks::on_dvr(url, req, file)) != ERROR_SUCCESS) {
srs_error("hook client on_dvr failed. url=%s, ret=%d", url.c_str(), ret);
return ret;
}

@ -195,13 +195,11 @@ int SrsDvrAsyncCallOnHls::call()
return ret;
}
int connection_id = _srs_context->get_id();
std::string cwd = _srs_config->cwd();
std::string file = path;
int sn = seq_no;
for (int i = 0; i < (int)on_hls->args.size(); i++) {
std::string url = on_hls->args.at(i);
if ((ret = SrsHttpHooks::on_hls(url, connection_id, req, cwd, file, sn)) != ERROR_SUCCESS) {
if ((ret = SrsHttpHooks::on_hls(url, req, file, sn)) != ERROR_SUCCESS) {
srs_error("hook client on_hls failed. url=%s, ret=%d", url.c_str(), ret);
return ret;
}

@ -36,6 +36,7 @@ using namespace std;
#include <srs_app_dvr.hpp>
#include <srs_app_http_client.hpp>
#include <srs_core_autofree.hpp>
#include <srs_app_config.hpp>
#define SRS_HTTP_RESPONSE_OK SRS_XSTR(ERROR_SUCCESS)
@ -50,15 +51,17 @@ SrsHttpHooks::~SrsHttpHooks()
{
}
int SrsHttpHooks::on_connect(string url, int client_id, string ip, SrsRequest* req)
int SrsHttpHooks::on_connect(string url, SrsRequest* req)
{
int ret = ERROR_SUCCESS;
int client_id = _srs_context->get_id();
std::stringstream ss;
ss << SRS_JOBJECT_START
<< SRS_JFIELD_STR("action", "on_connect") << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("client_id", client_id) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("ip", ip) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("ip", req->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("tcUrl", req->tcUrl) << SRS_JFIELD_CONT
@ -82,15 +85,17 @@ int SrsHttpHooks::on_connect(string url, int client_id, string ip, SrsRequest* r
return ret;
}
void SrsHttpHooks::on_close(string url, int client_id, string ip, SrsRequest* req, int64_t send_bytes, int64_t recv_bytes)
void SrsHttpHooks::on_close(string url, SrsRequest* req, int64_t send_bytes, int64_t recv_bytes)
{
int ret = ERROR_SUCCESS;
int client_id = _srs_context->get_id();
std::stringstream ss;
ss << SRS_JOBJECT_START
<< SRS_JFIELD_STR("action", "on_close") << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("client_id", client_id) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("ip", ip) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("ip", req->ip) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("vhost", req->vhost) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("send_bytes", send_bytes) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("recv_bytes", recv_bytes) << SRS_JFIELD_CONT
@ -114,15 +119,17 @@ void SrsHttpHooks::on_close(string url, int client_id, string ip, SrsRequest* re
return;
}
int SrsHttpHooks::on_publish(string url, int client_id, string ip, SrsRequest* req)
int SrsHttpHooks::on_publish(string url, SrsRequest* req)
{
int ret = ERROR_SUCCESS;
int client_id = _srs_context->get_id();
std::stringstream ss;
ss << SRS_JOBJECT_START
<< SRS_JFIELD_STR("action", "on_publish") << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("client_id", client_id) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("ip", ip) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("ip", req->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)
@ -145,15 +152,17 @@ int SrsHttpHooks::on_publish(string url, int client_id, string ip, SrsRequest* r
return ret;
}
void SrsHttpHooks::on_unpublish(string url, int client_id, string ip, SrsRequest* req)
void SrsHttpHooks::on_unpublish(string url, SrsRequest* req)
{
int ret = ERROR_SUCCESS;
int client_id = _srs_context->get_id();
std::stringstream ss;
ss << SRS_JOBJECT_START
<< SRS_JFIELD_STR("action", "on_unpublish") << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("client_id", client_id) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("ip", ip) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("ip", req->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)
@ -176,15 +185,17 @@ void SrsHttpHooks::on_unpublish(string url, int client_id, string ip, SrsRequest
return;
}
int SrsHttpHooks::on_play(string url, int client_id, string ip, SrsRequest* req)
int SrsHttpHooks::on_play(string url, SrsRequest* req)
{
int ret = ERROR_SUCCESS;
int client_id = _srs_context->get_id();
std::stringstream ss;
ss << SRS_JOBJECT_START
<< SRS_JFIELD_STR("action", "on_play") << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("client_id", client_id) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("ip", ip) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("ip", req->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)
@ -207,15 +218,17 @@ int SrsHttpHooks::on_play(string url, int client_id, string ip, SrsRequest* req)
return ret;
}
void SrsHttpHooks::on_stop(string url, int client_id, string ip, SrsRequest* req)
void SrsHttpHooks::on_stop(string url, SrsRequest* req)
{
int ret = ERROR_SUCCESS;
int client_id = _srs_context->get_id();
std::stringstream ss;
ss << SRS_JOBJECT_START
<< SRS_JFIELD_STR("action", "on_stop") << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("client_id", client_id) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("ip", ip) << SRS_JFIELD_CONT
<< SRS_JFIELD_STR("ip", req->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)
@ -238,15 +251,18 @@ void SrsHttpHooks::on_stop(string url, int client_id, string ip, SrsRequest* req
return;
}
int SrsHttpHooks::on_dvr(string url, int client_id, string ip, SrsRequest* req, string cwd, string file)
int SrsHttpHooks::on_dvr(string url, SrsRequest* req, string file)
{
int ret = ERROR_SUCCESS;
int client_id = _srs_context->get_id();
std::string cwd = _srs_config->cwd();
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("ip", req->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
@ -271,10 +287,13 @@ int SrsHttpHooks::on_dvr(string url, int client_id, string ip, SrsRequest* req,
return ret;
}
int SrsHttpHooks::on_hls(string url, int client_id, SrsRequest* req, string cwd, string file, int sn)
int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, int sn)
{
int ret = ERROR_SUCCESS;
int client_id = _srs_context->get_id();
std::string cwd = _srs_config->cwd();
std::stringstream ss;
ss << SRS_JOBJECT_START
<< SRS_JFIELD_STR("action", "on_hls") << SRS_JFIELD_CONT

@ -55,65 +55,55 @@ public:
public:
/**
* on_connect hook, when client connect to srs.
* @param client_id the id of client on server.
* @param url the api server url, to valid the client.
* ignore if empty.
*/
static int on_connect(std::string url, int client_id, std::string ip, SrsRequest* req);
static int on_connect(std::string url, SrsRequest* req);
/**
* on_close hook, when client disconnect to srs, where client is valid by on_connect.
* @param client_id the id of client on server.
* @param url the api server url, to process the event.
* ignore if empty.
*/
static void on_close(std::string url, int client_id, std::string ip, SrsRequest* req, int64_t send_bytes, int64_t recv_bytes);
static void on_close(std::string url, SrsRequest* req, int64_t send_bytes, int64_t recv_bytes);
/**
* on_publish hook, when client(encoder) start to publish stream
* @param client_id the id of client on server.
* @param url the api server url, to valid the client.
* ignore if empty.
*/
static int on_publish(std::string url, int client_id, std::string ip, SrsRequest* req);
static int on_publish(std::string url, SrsRequest* req);
/**
* on_unpublish hook, when client(encoder) stop publish stream.
* @param client_id the id of client on server.
* @param url the api server url, to process the event.
* ignore if empty.
*/
static void on_unpublish(std::string url, int client_id, std::string ip, SrsRequest* req);
static void on_unpublish(std::string url, SrsRequest* req);
/**
* on_play hook, when client start to play stream.
* @param client_id the id of client on server.
* @param url the api server url, to valid the client.
* ignore if empty.
*/
static int on_play(std::string url, int client_id, std::string ip, SrsRequest* req);
static int on_play(std::string url, SrsRequest* req);
/**
* on_stop hook, when client stop to play the stream.
* @param client_id the id of client on server.
* @param url the api server url, to process the event.
* ignore if empty.
*/
static void on_stop(std::string url, int client_id, std::string ip, SrsRequest* req);
static void on_stop(std::string url, 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);
static int on_dvr(std::string url, SrsRequest* req, std::string file);
/**
* when hls reap segment, callback.
* @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 ts file path, can be relative or absolute path.
* @param sn the seq_no, the sequence number of ts in hls/m3u8.
*/
static int on_hls(std::string url, int client_id, SrsRequest* req, std::string cwd, std::string file, int sn);
static int on_hls(std::string url, SrsRequest* req, std::string file, int sn);
private:
static int do_post(std::string url, std::string req, int& code, std::string& res);
};

@ -1265,10 +1265,9 @@ int SrsRtmpConn::http_hooks_on_connect()
return ret;
}
int connection_id = _srs_context->get_id();
for (int i = 0; i < (int)on_connect->args.size(); i++) {
std::string url = on_connect->args.at(i);
if ((ret = SrsHttpHooks::on_connect(url, connection_id, ip, req)) != ERROR_SUCCESS) {
if ((ret = SrsHttpHooks::on_connect(url, req)) != ERROR_SUCCESS) {
srs_error("hook client on_connect failed. url=%s, ret=%d", url.c_str(), ret);
return ret;
}
@ -1291,10 +1290,9 @@ void SrsRtmpConn::http_hooks_on_close()
return;
}
int connection_id = _srs_context->get_id();
for (int i = 0; i < (int)on_close->args.size(); i++) {
std::string url = on_close->args.at(i);
SrsHttpHooks::on_close(url, connection_id, ip, req, kbps->get_send_bytes(), kbps->get_recv_bytes());
SrsHttpHooks::on_close(url, req, kbps->get_send_bytes(), kbps->get_recv_bytes());
}
}
#endif
@ -1313,10 +1311,9 @@ int SrsRtmpConn::http_hooks_on_publish()
return ret;
}
int connection_id = _srs_context->get_id();
for (int i = 0; i < (int)on_publish->args.size(); i++) {
std::string url = on_publish->args.at(i);
if ((ret = SrsHttpHooks::on_publish(url, connection_id, ip, req)) != ERROR_SUCCESS) {
if ((ret = SrsHttpHooks::on_publish(url, req)) != ERROR_SUCCESS) {
srs_error("hook client on_publish failed. url=%s, ret=%d", url.c_str(), ret);
return ret;
}
@ -1339,10 +1336,9 @@ void SrsRtmpConn::http_hooks_on_unpublish()
return;
}
int connection_id = _srs_context->get_id();
for (int i = 0; i < (int)on_unpublish->args.size(); i++) {
std::string url = on_unpublish->args.at(i);
SrsHttpHooks::on_unpublish(url, connection_id, ip, req);
SrsHttpHooks::on_unpublish(url, req);
}
}
#endif
@ -1361,10 +1357,9 @@ int SrsRtmpConn::http_hooks_on_play()
return ret;
}
int connection_id = _srs_context->get_id();
for (int i = 0; i < (int)on_play->args.size(); i++) {
std::string url = on_play->args.at(i);
if ((ret = SrsHttpHooks::on_play(url, connection_id, ip, req)) != ERROR_SUCCESS) {
if ((ret = SrsHttpHooks::on_play(url, req)) != ERROR_SUCCESS) {
srs_error("hook client on_play failed. url=%s, ret=%d", url.c_str(), ret);
return ret;
}
@ -1387,10 +1382,9 @@ void SrsRtmpConn::http_hooks_on_stop()
return;
}
int connection_id = _srs_context->get_id();
for (int i = 0; i < (int)on_stop->args.size(); i++) {
std::string url = on_stop->args.at(i);
SrsHttpHooks::on_stop(url, connection_id, ip, req);
SrsHttpHooks::on_stop(url, req);
}
}
#endif

Loading…
Cancel
Save