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-23 16:25:18 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7ff8df4d973e6dbc0496d7c2c3e0740429128fea
7ff8df4d
1 parent
09901d31
refine code, notice api when segment close
显示空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
48 行增加
和
57 行删除
trunk/src/app/srs_app_dvr.cpp
trunk/src/app/srs_app_dvr.hpp
trunk/src/app/srs_app_dvr.cpp
查看文件 @
7ff8df4
...
...
@@ -305,6 +305,9 @@ SrsDvrPlan::SrsDvrPlan()
dvr_enabled
=
false
;
fs
=
new
SrsFileStream
();
enc
=
new
SrsFlvEncoder
();
segment_has_keyframe
=
true
;
starttime
=
-
1
;
duration
=
0
;
}
SrsDvrPlan
::~
SrsDvrPlan
()
...
...
@@ -407,7 +410,7 @@ int SrsDvrPlan::on_audio(SrsSharedPtrMessage* audio)
return
ret
;
}
if
((
ret
=
on_audio_msg
(
audio
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
update_duration
(
audio
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
@@ -435,15 +438,13 @@ int SrsDvrPlan::on_video(SrsSharedPtrMessage* video)
#ifdef SRS_AUTO_HTTP_CALLBACK
bool
is_key_frame
=
SrsCodec
::
video_is_keyframe
((
int8_t
*
)
payload
,
size
);
srs_verbose
(
"dvr video is key: %d"
,
is_key_frame
);
if
(
is_key_frame
)
{
if
((
ret
=
on_dvr_keyframe
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
segment_has_keyframe
=
true
;
}
srs_verbose
(
"dvr video is key: %d"
,
is_key_frame
);
#endif
if
((
ret
=
on_video_msg
(
video
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
update_duration
(
video
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
@@ -471,19 +472,9 @@ int SrsDvrPlan::flv_open(string stream, string path)
return
ret
;
}
srs_trace
(
"dvr stream %s to file %s"
,
stream
.
c_str
(),
path
.
c_str
());
return
ret
;
}
int
SrsDvrPlan
::
on_audio_msg
(
SrsSharedPtrMessage
*
/*audio*/
)
{
int
ret
=
ERROR_SUCCESS
;
return
ret
;
}
segment_has_keyframe
=
false
;
int
SrsDvrPlan
::
on_video_msg
(
SrsSharedPtrMessage
*
/*video*/
)
{
int
ret
=
ERROR_SUCCESS
;
srs_trace
(
"dvr stream %s to file %s"
,
stream
.
c_str
(),
path
.
c_str
());
return
ret
;
}
...
...
@@ -503,6 +494,28 @@ int SrsDvrPlan::flv_close()
return
ret
;
}
#ifdef SRS_AUTO_HTTP_CALLBACK
if
(
segment_has_keyframe
)
{
if
((
ret
=
on_dvr_keyframe
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
}
#endif
return
ret
;
}
int
SrsDvrPlan
::
update_duration
(
SrsSharedPtrMessage
*
msg
)
{
int
ret
=
ERROR_SUCCESS
;
// foreach msg, collect the duration.
if
(
starttime
<
0
||
starttime
>
msg
->
header
.
timestamp
)
{
starttime
=
msg
->
header
.
timestamp
;
}
duration
+=
msg
->
header
.
timestamp
-
starttime
;
starttime
=
msg
->
header
.
timestamp
;
return
ret
;
}
...
...
@@ -565,8 +578,6 @@ void SrsDvrSessionPlan::on_unpublish()
SrsDvrSegmentPlan
::
SrsDvrSegmentPlan
()
{
starttime
=
-
1
;
duration
=
0
;
segment_duration
=
-
1
;
}
...
...
@@ -611,38 +622,13 @@ void SrsDvrSegmentPlan::on_unpublish()
dvr_enabled
=
false
;
}
int
SrsDvrSegmentPlan
::
on_audio_msg
(
SrsSharedPtrMessage
*
audio
)
{
int
ret
=
ERROR_SUCCESS
;
if
((
ret
=
update_duration
(
audio
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
return
ret
;
}
int
SrsDvrSegmentPlan
::
on_video_msg
(
SrsSharedPtrMessage
*
video
)
{
int
ret
=
ERROR_SUCCESS
;
if
((
ret
=
update_duration
(
video
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
return
ret
;
}
int
SrsDvrSegmentPlan
::
update_duration
(
SrsSharedPtrMessage
*
msg
)
{
int
ret
=
ERROR_SUCCESS
;
// foreach msg, collect the duration.
if
(
starttime
<
0
||
starttime
>
msg
->
header
.
timestamp
)
{
starttime
=
msg
->
header
.
timestamp
;
if
((
ret
=
SrsDvrPlan
::
update_duration
(
msg
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
duration
+=
msg
->
header
.
timestamp
-
starttime
;
starttime
=
msg
->
header
.
timestamp
;
// reap if exceed duration.
if
(
duration
>
0
&&
segment_duration
>
0
&&
duration
>
segment_duration
)
{
...
...
trunk/src/app/srs_app_dvr.hpp
查看文件 @
7ff8df4
...
...
@@ -127,10 +127,20 @@ protected:
SrsSource
*
_source
;
SrsRequest
*
_req
;
SrsRtmpJitter
*
jitter
;
protected
:
/**
* current flv file path.
*/
std
::
string
current_flv_path
;
/**
* whether current segment has keyframe.
*/
bool
segment_has_keyframe
;
/**
* current segment duration and starttime.
*/
int64_t
duration
;
int64_t
starttime
;
public
:
SrsDvrPlan
();
virtual
~
SrsDvrPlan
();
...
...
@@ -143,14 +153,13 @@ public:
virtual
int
on_video
(
SrsSharedPtrMessage
*
video
);
protected
:
virtual
int
flv_open
(
std
::
string
stream
,
std
::
string
path
);
/**
* user should override this method.
* for the audio/video is corrected by jitter.
*/
virtual
int
on_audio_msg
(
SrsSharedPtrMessage
*
audio
);
virtual
int
on_video_msg
(
SrsSharedPtrMessage
*
video
);
virtual
int
flv_close
();
virtual
int
update_duration
(
SrsSharedPtrMessage
*
msg
);
private
:
/**
* when srs reap the flv(close the segment),
* if has keyframe, notice the api.
*/
virtual
int
on_dvr_keyframe
();
public
:
static
SrsDvrPlan
*
create_plan
(
std
::
string
vhost
);
...
...
@@ -174,8 +183,6 @@ public:
class
SrsDvrSegmentPlan
:
public
SrsDvrPlan
{
private
:
int64_t
duration
;
int64_t
starttime
;
// in config, in ms
int
segment_duration
;
public
:
...
...
@@ -185,8 +192,6 @@ public:
virtual
int
initialize
(
SrsSource
*
source
,
SrsRequest
*
req
);
virtual
int
on_publish
();
virtual
void
on_unpublish
();
virtual
int
on_audio_msg
(
SrsSharedPtrMessage
*
audio
);
virtual
int
on_video_msg
(
SrsSharedPtrMessage
*
video
);
private
:
virtual
int
update_duration
(
SrsSharedPtrMessage
*
msg
);
};
...
...
请
注册
或
登录
后发表评论