1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

support on_hls for http hooks. 2.0.152.

This commit is contained in:
winlin 2015-03-31 17:42:12 +08:00
parent 97442c56b6
commit c49bc0628e
15 changed files with 308 additions and 176 deletions

View file

@ -253,7 +253,7 @@ class RESTDvrs(object):
return json.dumps(dvrs)
'''
for SRS hook: on_dvr,
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:
@ -265,17 +265,6 @@ class RESTDvrs(object):
"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
@ -298,8 +287,6 @@ class RESTDvrs(object):
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
@ -321,18 +308,6 @@ class RESTDvrs(object):
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 hls requests: hls stream.
'''
@ -346,8 +321,8 @@ class RESTHls(object):
return json.dumps(hls)
'''
for SRS hook: on, on_dvr_reap_segment
on_dvr:
for SRS hook: on_hls
on_hls:
when srs reap a dvr file, call the hook,
the request in the POST data string is a object encode by json:
{
@ -356,18 +331,8 @@ class RESTHls(object):
"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"
}
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"
"file": "./objs/nginx/html/live/livestream.1420254068776-100.ts",
"seq_no": 100
}
if valid, the hook must return HTTP code 200(Stauts OK) and response
an int value specifies the error code(0 corresponding to success):
@ -380,7 +345,7 @@ class RESTHls(object):
code = Error.success
req = cherrypy.request.body.read()
trace("post to dvrs, req=%s"%(req))
trace("post to hls, req=%s"%(req))
try:
json_req = json.loads(req)
except Exception, ex:
@ -389,10 +354,8 @@ class RESTHls(object):
return str(code)
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)
if action == "on_hls":
code = self.__on_hls(json_req)
else:
trace("invalid request action: %s"%(json_req["action"]))
code = Error.request_invalid_action
@ -402,27 +365,15 @@ class RESTHls(object):
def OPTIONS(self, *args, **kwargs):
enable_crossdomain()
def __on_dvr(self, req):
def __on_hls(self, req):
code = Error.success
trace("srs %s: client id=%s, ip=%s, vhost=%s, app=%s, stream=%s, cwd=%s, file=%s"%(
trace("srs %s: client id=%s, ip=%s, vhost=%s, app=%s, stream=%s, cwd=%s, file=%s, seq_no=%s"%(
req["action"], req["client_id"], req["ip"], req["vhost"], req["app"], req["stream"],
req["cwd"], req["file"]
req["cwd"], req["file"], req["seq_no"]
))
# TODO: process the on_dvr event
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
# TODO: process the on_hls event
return code