1
0
Fork 0
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:
winlin 2015-01-03 15:33:23 +08:00
parent dd2c7e0b4d
commit dc11418c79
12 changed files with 207 additions and 7 deletions

View file

@ -154,7 +154,7 @@ class RESTClients(object):
return code
'''
handle the streams requests: publish/unpublish/dvr stream.
handle the streams requests: publish/unpublish stream.
'''
class RESTStreams(object):
exposed = True
@ -240,6 +240,74 @@ class RESTStreams(object):
return code
'''
handle the dvrs requests: dvr stream.
'''
class RESTDvrs(object):
exposed = True
def GET(self):
enable_crossdomain()
dvrs = {}
return json.dumps(dvrs)
'''
for SRS hook: on_dvr
on_dvr:
when srs reap a dvr file, call the hook,
the request in the POST data string is a object encode by json:
{
"action": "on_dvr",
"client_id": 1985,
"ip": "192.168.1.10", "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
'''
def POST(self):
enable_crossdomain()
# return the error code in str
code = Error.success
req = cherrypy.request.body.read()
trace("post to dvrs, req=%s"%(req))
try:
json_req = json.loads(req)
except Exception, ex:
code = Error.system_parse_json
trace("parse the request to json failed, req=%s, ex=%s, code=%s"%(req, ex, code))
return str(code)
action = json_req["action"]
if action == "on_dvr":
code = self.__on_dvr(json_req)
else:
trace("invalid request action: %s"%(json_req["action"]))
code = Error.request_invalid_action
return str(code)
def OPTIONS(self, *args, **kwargs):
enable_crossdomain()
def __on_dvr(self, req):
code = Error.success
trace("srs %s: client id=%s, ip=%s, vhost=%s, app=%s, stream=%s, cwd=%s, file=%s"%(
req["action"], req["client_id"], req["ip"], 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
'''
@ -1039,6 +1107,7 @@ class V1(object):
self.clients = RESTClients()
self.streams = RESTStreams()
self.sessions = RESTSessions()
self.dvrs = RESTDvrs()
self.chats = RESTChats()
self.servers = RESTServers()
self.nodes = RESTNodes()
@ -1048,6 +1117,7 @@ class V1(object):
"clients": "for srs http callback, to handle the clients requests: connect/disconnect vhost/app.",
"streams": "for srs http callback, to handle the streams requests: publish/unpublish stream.",
"sessions": "for srs http callback, to handle the sessions requests: client play/stop stream",
"dvrs": "for srs http callback, to handle the dvr requests: dvr stream.",
"chats": "for srs demo meeting, the chat streams, public chat room.",
"nodes": {
"summary": "for srs cdn node",