Skip to content

Commit

Permalink
for ossrs#179, refine dvr, support callback when reap dvr segment.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 22, 2015
1 parent 849e59b commit 1246989
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 50 deletions.
5 changes: 4 additions & 1 deletion trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ vhost dvr.srs.com {
# vhost, query all dvr of this vhost.
# response in json, where:
# {code:0, dvrs: [{path_tmpl:"./[15].[04].[05].[999].flv", path_dvr:"./22.7.43.312.flv",
# wait_keyframe:true, vhost:"__defaultVhost", callback:"http://dvr/callback"
# wait_keyframe:true, vhost:"__defaultVhost", callback:"http://127.0.0.1:8085/api/v1/dvrs",
# status:"stop"|"start"
# }]}
# method=POST
# to start dvr of specified vhost.
Expand All @@ -313,6 +314,8 @@ vhost dvr.srs.com {
# vhost, stop all dvr of this vhost.
# response in json, where:
# {code:0}
# when reap segment, the callback POST request in json:
# {action:"on_dvr_reap_segment"}
# default: session
dvr_plan session;
# the dvr output path.
Expand Down
27 changes: 26 additions & 1 deletion trunk/research/api-server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def GET(self):
return json.dumps(dvrs)

'''
for SRS hook: on_dvr
for SRS hook: on_dvr, on_dvr_reap_segment
on_dvr:
when srs reap a dvr file, call the hook,
the request in the POST data string is a object encode by json:
Expand All @@ -265,6 +265,17 @@ def GET(self):
"cwd": "/usr/local/srs",
"file": "./objs/nginx/html/live/livestream.1420254068776.flv"
}
on_dvr_reap_segment:
when api dvr specifes the callback when reap flv segment, call the hook,
the request in the POST data string is a object encode by json:
{
"action": "on_dvr_reap_segment",
"client_id": 1985,
"vhost": "video.test.com", "app": "live",
"stream": "livestream",
"cwd": "/usr/local/srs",
"file": "./objs/nginx/html/live/livestream.1420254068776.flv"
}
if valid, the hook must return HTTP code 200(Stauts OK) and response
an int value specifies the error code(0 corresponding to success):
0
Expand All @@ -287,6 +298,8 @@ def POST(self):
action = json_req["action"]
if action == "on_dvr":
code = self.__on_dvr(json_req)
if action == "on_dvr_reap_segment":
code = self.__on_dvr_reap_segment(json_req)
else:
trace("invalid request action: %s"%(json_req["action"]))
code = Error.request_invalid_action
Expand All @@ -308,6 +321,18 @@ def __on_dvr(self, req):

return code

def __on_dvr_reap_segment(self, req):
code = Error.success

trace("srs %s: client id=%s, vhost=%s, app=%s, stream=%s, cwd=%s, file=%s"%(
req["action"], req["client_id"], req["vhost"], req["app"], req["stream"],
req["cwd"], req["file"]
))

# TODO: process the on_dvr event

return code

'''
handle the sessions requests: client play/stop stream
'''
Expand Down
7 changes: 7 additions & 0 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3342,6 +3342,13 @@ bool SrsConfig::get_dvr_enabled(string vhost)
return false;
}

void SrsConfig::set_dvr_enabled(string vhost, bool enabled)
{
SrsConfDirective* conf = create_directive(vhost, "dvr", "enabled");
conf->args.clear();
conf->args.push_back(enabled? "on":"off");
}

string SrsConfig::get_dvr_path(string vhost)
{
SrsConfDirective* dvr = get_dvr(vhost);
Expand Down
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ class SrsConfig
* whether dvr is enabled.
*/
virtual bool get_dvr_enabled(std::string vhost);
virtual void set_dvr_enabled(std::string vhost, bool enabled);
/**
* get the dvr path, the flv file to save in.
*/
Expand Down
Loading

0 comments on commit 1246989

Please sign in to comment.