Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-04-24 17:38:57 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3ed59f190bc123d5f73eca0729eab9ebaec3deb1
3ed59f19
1 parent
67e1988b
refine srs live flashP2P(integrated by chnvideo)
隐藏空白字符变更
内嵌
并排对比
正在显示
5 个修改的文件
包含
133 行增加
和
2 行删除
trunk/conf/full.conf
trunk/src/app/srs_app_dvr.cpp
trunk/src/app/srs_app_dvr.hpp
trunk/src/app/srs_app_http_hooks.cpp
trunk/src/app/srs_app_http_hooks.hpp
trunk/conf/full.conf
查看文件 @
3ed59f1
...
...
@@ -322,7 +322,20 @@ 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
;
# when dvr got an keyframe, call the hook,
# 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",
# "vhost": "video.test.com", "app": "live",
# "stream": "livestream",
# "segment": {
# "cwd": "/usr/local/srs",
# "path": "./objs/nginx/html/live/livestream.1398315892865.flv",
# "duration": 1001, "offset":0,
# "has_keyframe": true, "pts":1398315895958
# }
# }
# 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",
...
...
trunk/src/app/srs_app_dvr.cpp
查看文件 @
3ed59f1
...
...
@@ -804,9 +804,49 @@ void SrsDvrHssPlan::on_unpublish()
dvr_enabled
=
false
;
}
int
SrsDvrHssPlan
::
on_meta_data
(
SrsOnMetaDataPacket
*
/*metadata*/
)
int
SrsDvrHssPlan
::
on_meta_data
(
SrsOnMetaDataPacket
*
metadata
)
{
int
ret
=
ERROR_SUCCESS
;
SrsRequest
*
req
=
_req
;
// new flv file
std
::
stringstream
path
;
path
<<
_srs_config
->
get_dvr_path
(
req
->
vhost
)
<<
"/"
<<
req
->
app
<<
"/"
<<
req
->
stream
<<
".header.flv"
;
SrsFileStream
fs
;
if
((
ret
=
fs
.
open
(
path
.
str
().
c_str
()))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
SrsFlvEncoder
enc
;
if
((
ret
=
enc
.
initialize
(
&
fs
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
if
((
ret
=
enc
.
write_header
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
int
size
=
0
;
char
*
payload
=
NULL
;
if
((
ret
=
metadata
->
encode
(
size
,
payload
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
SrsAutoFree
(
char
,
payload
,
true
);
if
((
ret
=
enc
.
write_metadata
(
payload
,
size
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
#ifdef SRS_AUTO_HTTP_CALLBACK
if
((
ret
=
on_dvr_reap_flv_header
(
path
.
str
()))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
#endif
return
ret
;
}
...
...
@@ -842,6 +882,27 @@ int64_t SrsDvrHssPlan::filter_timestamp(int64_t timestamp)
return
segment
->
stream_starttime
+
timestamp
;
}
int
SrsDvrHssPlan
::
on_dvr_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"
);
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
);
}
#endif
return
ret
;
}
int
SrsDvrHssPlan
::
update_duration
(
SrsSharedPtrMessage
*
msg
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
trunk/src/app/srs_app_dvr.hpp
查看文件 @
3ed59f1
...
...
@@ -259,6 +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
update_duration
(
SrsSharedPtrMessage
*
msg
);
};
...
...
trunk/src/app/srs_app_http_hooks.cpp
查看文件 @
3ed59f1
...
...
@@ -459,6 +459,55 @@ 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
)
{
int
ret
=
ERROR_SUCCESS
;
srs_verbose
(
"flv header reap, file=%s"
,
header_file
.
c_str
());
SrsHttpUri
uri
;
if
((
ret
=
uri
.
initialize
(
url
))
!=
ERROR_SUCCESS
)
{
srs_warn
(
"http uri parse on_dvr_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
(
"vhost"
,
req
->
vhost
)
<<
JFIELD_CONT
<<
JFIELD_STR
(
"app"
,
req
->
app
)
<<
JFIELD_CONT
<<
JFIELD_STR
(
"stream"
,
req
->
stream
)
<<
JFIELD_CONT
<<
JFIELD_NAME
(
"segment"
)
<<
JOBJECT_START
<<
JFIELD_STR
(
"cwd"
,
_srs_config
->
get_cwd
())
<<
JFIELD_CONT
<<
JFIELD_STR
(
"path"
,
header_file
)
<<
JOBJECT_END
<<
JOBJECT_END
;
std
::
string
data
=
ss
.
str
();
std
::
string
res
;
SrsHttpClient
http
;
if
((
ret
=
http
.
post
(
&
uri
,
data
,
res
))
!=
ERROR_SUCCESS
)
{
srs_warn
(
"http post on_dvr_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
;
}
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. "
"res=%s, ret=%d"
,
res
.
c_str
(),
ret
);
return
;
}
srs_info
(
"http hook on_dvr_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
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
trunk/src/app/srs_app_http_hooks.hpp
查看文件 @
3ed59f1
...
...
@@ -124,6 +124,13 @@ 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.
* @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
);
/**
* on_dvr_reap_flv hook, when dvr close flv file.
* @param url the api server url, to process the event.
* ignore if empty.
...
...
请
注册
或
登录
后发表评论