winlin

add dvr_plan hss to full.conf

... ... @@ -122,7 +122,7 @@ vhost dvr.srs.com {
# start to record to file when encoder publish,
# reap flv according by specified dvr_plan.
# http callbacks:
# @see http callback on_dvr_reap_flv on http_hooks section.
# @see http callback on_dvr_hss_reap_flv on http_hooks section.
dvr {
# whether enabled dvr features
# default: off
... ... @@ -142,6 +142,7 @@ vhost dvr.srs.com {
# the dvr plan. canbe:
# session reap flv when session end(unpublish).
# segment reap flv when flv duration exceed the specified dvr_duration.
# hss reap flv required by bravo(chnvideo.com) p2p system.
# default: session
dvr_plan session;
# the param for plan(segment), in seconds.
... ... @@ -347,10 +348,12 @@ vhost hooks.callback.srs.com {
# support multiple api hooks, format:
# on_stop http://xxx/api0 http://xxx/api1 http://xxx/apiN
on_stop http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;
#
# for dvr(dvr_plan is hss).
# when dvr got flv header, call the hook,
# the request in the POST data string is a object encode by json:
# {
# "action": "on_dvr_reap_flv_header",
# "action": "on_dvr_hss_reap_flv_header",
# "vhost": "video.test.com", "app": "live",
# "stream": "livestream",
# "segment": {
... ... @@ -361,7 +364,7 @@ vhost hooks.callback.srs.com {
# when dvr reap flv file, call the hook,
# the request in the POST data string is a object encode by json:
# {
# "action": "on_dvr_reap_flv",
# "action": "on_dvr_hss_reap_flv",
# "vhost": "video.test.com", "app": "live",
# "stream": "livestream",
# "segment": {
... ... @@ -376,7 +379,7 @@ vhost hooks.callback.srs.com {
# 0
# support multiple api hooks, format:
# on_stop http://xxx/api0 http://xxx/api1 http://xxx/apiN
on_dvr_reap_flv http://127.0.0.1:8085/api/v1/dvrs http://localhost:8085/api/v1/dvrs;
on_dvr_hss_reap_flv http://127.0.0.1:8085/api/v1/dvrs http://localhost:8085/api/v1/dvrs;
}
}
... ...
... ... @@ -113,14 +113,14 @@ int proxy(srs_rtmp_t irtmp, srs_rtmp_t ortmp)
trace("irtmp get packet failed. ret=%d", ret);
return ret;
}
verbose("irtmp got packet: type=%s, time=%d, size=%d",
trace("irtmp got packet: type=%s, time=%d, size=%d",
srs_type2string(type), timestamp, size);
if ((ret = srs_write_packet(ortmp, type, timestamp, data, size)) != 0) {
trace("irtmp get packet failed. ret=%d", ret);
return ret;
}
verbose("ortmp sent packet: type=%s, time=%d, size=%d",
trace("ortmp sent packet: type=%s, time=%d, size=%d",
srs_type2string(type), timestamp, size);
}
... ...
... ... @@ -1587,7 +1587,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_stop(string vhost)
return conf->get("on_stop");
}
SrsConfDirective* SrsConfig::get_vhost_on_dvr_reap_flv(string vhost)
SrsConfDirective* SrsConfig::get_vhost_on_dvr_hss_reap_flv(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
... ... @@ -1605,7 +1605,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_dvr_reap_flv(string vhost)
return NULL;
}
return conf->get("on_dvr_reap_flv");
return conf->get("on_dvr_hss_reap_flv");
}
bool SrsConfig::get_vhost_enabled(string vhost)
... ...
... ... @@ -177,7 +177,7 @@ public:
virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost);
virtual SrsConfDirective* get_vhost_on_play(std::string vhost);
virtual SrsConfDirective* get_vhost_on_stop(std::string vhost);
virtual SrsConfDirective* get_vhost_on_dvr_reap_flv(std::string vhost);
virtual SrsConfDirective* get_vhost_on_dvr_hss_reap_flv(std::string vhost);
virtual bool get_gop_cache(std::string vhost);
virtual bool get_atc(std::string vhost);
virtual double get_queue_length(std::string vhost);
... ...
... ... @@ -565,7 +565,7 @@ int SrsDvrPlan::flv_close()
}
#ifdef SRS_AUTO_HTTP_CALLBACK
if ((ret = on_dvr_reap_flv()) != ERROR_SUCCESS) {
if ((ret = on_dvr_hss_reap_flv()) != ERROR_SUCCESS) {
return ret;
}
#endif
... ... @@ -612,21 +612,21 @@ int SrsDvrPlan::write_flv_header()
return ret;
}
int SrsDvrPlan::on_dvr_reap_flv()
int SrsDvrPlan::on_dvr_hss_reap_flv()
{
int ret = ERROR_SUCCESS;
#ifdef SRS_AUTO_HTTP_CALLBACK
// HTTP: on_dvr_reap_flv
SrsConfDirective* on_dvr_reap_flv = _srs_config->get_vhost_on_dvr_reap_flv(_req->vhost);
if (!on_dvr_reap_flv) {
srs_info("ignore the empty http callback: on_dvr_reap_flv");
// HTTP: on_dvr_hss_reap_flv
SrsConfDirective* on_dvr_hss_reap_flv = _srs_config->get_vhost_on_dvr_hss_reap_flv(_req->vhost);
if (!on_dvr_hss_reap_flv) {
srs_info("ignore the empty http callback: on_dvr_hss_reap_flv");
return ret;
}
for (int i = 0; i < (int)on_dvr_reap_flv->args.size(); i++) {
std::string url = on_dvr_reap_flv->args.at(i);
SrsHttpHooks::on_dvr_reap_flv(url, _req, segment);
for (int i = 0; i < (int)on_dvr_hss_reap_flv->args.size(); i++) {
std::string url = on_dvr_hss_reap_flv->args.at(i);
SrsHttpHooks::on_dvr_hss_reap_flv(url, _req, segment);
}
#endif
... ... @@ -842,7 +842,7 @@ int SrsDvrHssPlan::on_meta_data(SrsOnMetaDataPacket* metadata)
}
#ifdef SRS_AUTO_HTTP_CALLBACK
if ((ret = on_dvr_reap_flv_header(path.str())) != ERROR_SUCCESS) {
if ((ret = on_dvr_hss_reap_flv_header(path.str())) != ERROR_SUCCESS) {
return ret;
}
#endif
... ... @@ -882,21 +882,21 @@ int64_t SrsDvrHssPlan::filter_timestamp(int64_t timestamp)
return segment->stream_starttime + timestamp;
}
int SrsDvrHssPlan::on_dvr_reap_flv_header(string path)
int SrsDvrHssPlan::on_dvr_hss_reap_flv_header(string path)
{
int ret = ERROR_SUCCESS;
#ifdef SRS_AUTO_HTTP_CALLBACK
// HTTP: on_dvr_reap_flv_header
SrsConfDirective* on_dvr_reap_flv = _srs_config->get_vhost_on_dvr_reap_flv(_req->vhost);
if (!on_dvr_reap_flv) {
srs_info("ignore the empty http callback: on_dvr_reap_flv");
// HTTP: on_dvr_hss_reap_flv_header
SrsConfDirective* on_dvr_hss_reap_flv = _srs_config->get_vhost_on_dvr_hss_reap_flv(_req->vhost);
if (!on_dvr_hss_reap_flv) {
srs_info("ignore the empty http callback: on_dvr_hss_reap_flv");
return ret;
}
for (int i = 0; i < (int)on_dvr_reap_flv->args.size(); i++) {
std::string url = on_dvr_reap_flv->args.at(i);
SrsHttpHooks::on_dvr_reap_flv_header(url, _req, path);
for (int i = 0; i < (int)on_dvr_hss_reap_flv->args.size(); i++) {
std::string url = on_dvr_hss_reap_flv->args.at(i);
SrsHttpHooks::on_dvr_hss_reap_flv_header(url, _req, path);
}
#endif
... ...
... ... @@ -200,7 +200,7 @@ private:
/**
* when srs reap the flv(close the segment), notice the api.
*/
virtual int on_dvr_reap_flv();
virtual int on_dvr_hss_reap_flv();
public:
static SrsDvrPlan* create_plan(std::string vhost);
};
... ... @@ -259,7 +259,7 @@ protected:
virtual int on_video_keyframe();
virtual int64_t filter_timestamp(int64_t timestamp);
private:
virtual int on_dvr_reap_flv_header(std::string path);
virtual int on_dvr_hss_reap_flv_header(std::string path);
virtual int update_duration(SrsSharedPtrMessage* msg);
};
... ...
... ... @@ -459,7 +459,7 @@ void SrsHttpHooks::on_stop(string url, int client_id, string ip, SrsRequest* req
return;
}
void SrsHttpHooks::on_dvr_reap_flv_header(std::string url, SrsRequest* req, std::string header_file)
void SrsHttpHooks::on_dvr_hss_reap_flv_header(std::string url, SrsRequest* req, std::string header_file)
{
int ret = ERROR_SUCCESS;
... ... @@ -467,14 +467,14 @@ void SrsHttpHooks::on_dvr_reap_flv_header(std::string url, SrsRequest* req, std:
SrsHttpUri uri;
if ((ret = uri.initialize(url)) != ERROR_SUCCESS) {
srs_warn("http uri parse on_dvr_reap_flv_header url failed, ignored. "
srs_warn("http uri parse on_dvr_hss_reap_flv_header url failed, ignored. "
"url=%s, ret=%d", url.c_str(), ret);
return;
}
std::stringstream ss;
ss << JOBJECT_START
<< JFIELD_STR("action", "on_dvr_reap_flv_header") << JFIELD_CONT
<< JFIELD_STR("action", "on_dvr_hss_reap_flv_header") << JFIELD_CONT
<< JFIELD_STR("vhost", req->vhost) << JFIELD_CONT
<< JFIELD_STR("app", req->app) << JFIELD_CONT
<< JFIELD_STR("stream", req->stream) << JFIELD_CONT
... ... @@ -488,7 +488,7 @@ void SrsHttpHooks::on_dvr_reap_flv_header(std::string url, SrsRequest* req, std:
SrsHttpClient http;
if ((ret = http.post(&uri, data, res)) != ERROR_SUCCESS) {
srs_warn("http post on_dvr_reap_flv_header uri failed, ignored. "
srs_warn("http post on_dvr_hss_reap_flv_header uri failed, ignored. "
"url=%s, request=%s, response=%s, ret=%d",
url.c_str(), data.c_str(), res.c_str(), ret);
return;
... ... @@ -496,19 +496,19 @@ void SrsHttpHooks::on_dvr_reap_flv_header(std::string url, SrsRequest* req, std:
if (res.empty() || res != SRS_HTTP_RESPONSE_OK) {
ret = ERROR_HTTP_DATA_INVLIAD;
srs_warn("http hook on_dvr_reap_flv_header validate failed, ignored. "
srs_warn("http hook on_dvr_hss_reap_flv_header validate failed, ignored. "
"res=%s, ret=%d", res.c_str(), ret);
return;
}
srs_info("http hook on_dvr_reap_flv_header success. "
srs_info("http hook on_dvr_hss_reap_flv_header success. "
"url=%s, request=%s, response=%s, ret=%d",
url.c_str(), data.c_str(), res.c_str(), ret);
return;
}
void SrsHttpHooks::on_dvr_reap_flv(string url, SrsRequest* req, SrsFlvSegment* segment)
void SrsHttpHooks::on_dvr_hss_reap_flv(string url, SrsRequest* req, SrsFlvSegment* segment)
{
int ret = ERROR_SUCCESS;
... ... @@ -520,14 +520,14 @@ void SrsHttpHooks::on_dvr_reap_flv(string url, SrsRequest* req, SrsFlvSegment* s
SrsHttpUri uri;
if ((ret = uri.initialize(url)) != ERROR_SUCCESS) {
srs_warn("http uri parse on_dvr_reap_flv url failed, ignored. "
srs_warn("http uri parse on_dvr_hss_reap_flv url failed, ignored. "
"url=%s, ret=%d", url.c_str(), ret);
return;
}
std::stringstream ss;
ss << JOBJECT_START
<< JFIELD_STR("action", "on_dvr_reap_flv") << JFIELD_CONT
<< JFIELD_STR("action", "on_dvr_hss_reap_flv") << JFIELD_CONT
<< JFIELD_STR("vhost", req->vhost) << JFIELD_CONT
<< JFIELD_STR("app", req->app) << JFIELD_CONT
<< JFIELD_STR("stream", req->stream) << JFIELD_CONT
... ... @@ -545,7 +545,7 @@ void SrsHttpHooks::on_dvr_reap_flv(string url, SrsRequest* req, SrsFlvSegment* s
SrsHttpClient http;
if ((ret = http.post(&uri, data, res)) != ERROR_SUCCESS) {
srs_warn("http post on_dvr_reap_flv uri failed, ignored. "
srs_warn("http post on_dvr_hss_reap_flv uri failed, ignored. "
"url=%s, request=%s, response=%s, ret=%d",
url.c_str(), data.c_str(), res.c_str(), ret);
return;
... ... @@ -553,12 +553,12 @@ void SrsHttpHooks::on_dvr_reap_flv(string url, SrsRequest* req, SrsFlvSegment* s
if (res.empty() || res != SRS_HTTP_RESPONSE_OK) {
ret = ERROR_HTTP_DATA_INVLIAD;
srs_warn("http hook on_dvr_reap_flv validate failed, ignored. "
srs_warn("http hook on_dvr_hss_reap_flv validate failed, ignored. "
"res=%s, ret=%d", res.c_str(), ret);
return;
}
srs_info("http hook on_dvr_reap_flv success. "
srs_info("http hook on_dvr_hss_reap_flv success. "
"url=%s, request=%s, response=%s, ret=%d",
url.c_str(), data.c_str(), res.c_str(), ret);
... ...
... ... @@ -124,19 +124,19 @@ public:
static void on_stop(std::string url, int client_id, std::string ip, SrsRequest* req);
public:
/**
* on_dvr_reap_flv_header hook, when dvr write flv file header.
* on_dvr_hss_reap_flv_header hook, when dvr write flv file header.
* @param url the api server url, to process the event.
* ignore if empty.
* @param header_file the flv header file.
*/
static void on_dvr_reap_flv_header(std::string url, SrsRequest* req, std::string header_file);
static void on_dvr_hss_reap_flv_header(std::string url, SrsRequest* req, std::string header_file);
/**
* on_dvr_reap_flv hook, when dvr close flv file.
* on_dvr_hss_reap_flv hook, when dvr close flv file.
* @param url the api server url, to process the event.
* ignore if empty.
* @param segment the current flv segment.
*/
static void on_dvr_reap_flv(std::string url, SrsRequest* req, SrsFlvSegment* segment);
static void on_dvr_hss_reap_flv(std::string url, SrsRequest* req, SrsFlvSegment* segment);
};
#endif
... ...