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
2015-05-23 07:57:45 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2f0ef87d6dc94e22f8a11f55488f372bcd00246e
2f0ef87d
1 parent
0bb90145
refine code, rename the sync call to common class.
显示空白字符变更
内嵌
并排对比
正在显示
6 个修改的文件
包含
43 行增加
和
41 行删除
trunk/src/app/srs_app_async_call.cpp
trunk/src/app/srs_app_async_call.hpp
trunk/src/app/srs_app_dvr.cpp
trunk/src/app/srs_app_dvr.hpp
trunk/src/app/srs_app_hls.cpp
trunk/src/app/srs_app_hls.hpp
trunk/src/app/srs_app_async_call.cpp
查看文件 @
2f0ef87
...
...
@@ -31,65 +31,65 @@ using namespace std;
// the sleep interval for http async callback.
#define SRS_AUTO_ASYNC_CALLBACL_SLEEP_US 300000
ISrs
DvrAsyncCall
::
ISrsDvrAsyncCall
()
ISrs
AsyncCallTask
::
ISrsAsyncCallTask
()
{
}
ISrs
DvrAsyncCall
::~
ISrsDvrAsyncCall
()
ISrs
AsyncCallTask
::~
ISrsAsyncCallTask
()
{
}
Srs
DvrAsyncCallThread
::
SrsDvrAsyncCallThread
()
Srs
AsyncCallWorker
::
SrsAsyncCallWorker
()
{
pthread
=
new
SrsThread
(
"async"
,
this
,
SRS_AUTO_ASYNC_CALLBACL_SLEEP_US
,
true
);
}
Srs
DvrAsyncCallThread
::~
SrsDvrAsyncCallThread
()
Srs
AsyncCallWorker
::~
SrsAsyncCallWorker
()
{
stop
();
srs_freep
(
pthread
);
std
::
vector
<
ISrsDvrAsyncCall
*>::
iterator
it
;
for
(
it
=
callbacks
.
begin
();
it
!=
callbacks
.
end
();
++
it
)
{
ISrsDvrAsyncCall
*
call
=
*
it
;
srs_freep
(
call
);
std
::
vector
<
ISrsAsyncCallTask
*>::
iterator
it
;
for
(
it
=
tasks
.
begin
();
it
!=
tasks
.
end
();
++
it
)
{
ISrsAsyncCallTask
*
task
=
*
it
;
srs_freep
(
task
);
}
callbac
ks
.
clear
();
tas
ks
.
clear
();
}
int
Srs
DvrAsyncCallThread
::
call
(
ISrsDvrAsyncCall
*
c
)
int
Srs
AsyncCallWorker
::
execute
(
ISrsAsyncCallTask
*
t
)
{
int
ret
=
ERROR_SUCCESS
;
callbacks
.
push_back
(
c
);
tasks
.
push_back
(
t
);
return
ret
;
}
int
Srs
DvrAsyncCallThread
::
start
()
int
Srs
AsyncCallWorker
::
start
()
{
return
pthread
->
start
();
}
void
Srs
DvrAsyncCallThread
::
stop
()
void
Srs
AsyncCallWorker
::
stop
()
{
pthread
->
stop
();
}
int
Srs
DvrAsyncCallThread
::
cycle
()
int
Srs
AsyncCallWorker
::
cycle
()
{
int
ret
=
ERROR_SUCCESS
;
std
::
vector
<
ISrsDvrAsyncCall
*>
copies
=
callbacks
;
callbacks
.
clear
();
std
::
vector
<
ISrsAsyncCallTask
*>
copies
=
tasks
;
tasks
.
clear
();
std
::
vector
<
ISrs
DvrAsyncCall
*>::
iterator
it
;
std
::
vector
<
ISrs
AsyncCallTask
*>::
iterator
it
;
for
(
it
=
copies
.
begin
();
it
!=
copies
.
end
();
++
it
)
{
ISrsDvrAsyncCall
*
call
=
*
it
;
if
((
ret
=
call
->
call
())
!=
ERROR_SUCCESS
)
{
srs_warn
(
"ignore async callback %s, ret=%d"
,
call
->
to_string
().
c_str
(),
ret
);
ISrsAsyncCallTask
*
task
=
*
it
;
if
((
ret
=
task
->
call
())
!=
ERROR_SUCCESS
)
{
srs_warn
(
"ignore async callback %s, ret=%d"
,
task
->
to_string
().
c_str
(),
ret
);
}
srs_freep
(
call
);
srs_freep
(
task
);
}
return
ret
;
...
...
trunk/src/app/srs_app_async_call.hpp
查看文件 @
2f0ef87
...
...
@@ -42,29 +42,31 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* a video and pass it to the dvr again.
* futhurmore, the aync call never block the main worker thread.
*/
class
ISrs
DvrAsyncCall
class
ISrs
AsyncCallTask
{
public
:
ISrsDvrAsyncCall
();
virtual
~
ISrsDvrAsyncCall
();
ISrsAsyncCallTask
();
virtual
~
ISrsAsyncCallTask
();
public
:
virtual
int
call
()
=
0
;
virtual
std
::
string
to_string
()
=
0
;
};
/**
* the async callback for dvr.
*/
class
SrsDvrAsyncCallThread
:
public
ISrsThreadHandler
* the async callback for dvr.
* when worker call with the task, the worker will do it in isolate thread.
* that is, the task is execute/call in async mode.
*/
class
SrsAsyncCallWorker
:
public
ISrsThreadHandler
{
private
:
SrsThread
*
pthread
;
std
::
vector
<
ISrs
DvrAsyncCall
*>
callbac
ks
;
std
::
vector
<
ISrs
AsyncCallTask
*>
tas
ks
;
public
:
SrsDvrAsyncCallThread
();
virtual
~
SrsDvrAsyncCallThread
();
SrsAsyncCallWorker
();
virtual
~
SrsAsyncCallWorker
();
public
:
virtual
int
call
(
ISrsDvrAsyncCall
*
c
);
virtual
int
execute
(
ISrsAsyncCallTask
*
t
);
public
:
virtual
int
start
();
virtual
void
stop
();
...
...
trunk/src/app/srs_app_dvr.cpp
查看文件 @
2f0ef87
...
...
@@ -548,7 +548,7 @@ SrsDvrPlan::SrsDvrPlan()
dvr_enabled
=
false
;
segment
=
new
SrsFlvSegment
(
this
);
async
=
new
Srs
DvrAsyncCallThread
();
async
=
new
Srs
AsyncCallWorker
();
}
SrsDvrPlan
::~
SrsDvrPlan
()
...
...
@@ -629,7 +629,7 @@ int SrsDvrPlan::on_reap_segment()
{
int
ret
=
ERROR_SUCCESS
;
if
((
ret
=
async
->
call
(
new
SrsDvrAsyncCallOnDvr
(
req
,
segment
->
get_path
())))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
async
->
execute
(
new
SrsDvrAsyncCallOnDvr
(
req
,
segment
->
get_path
())))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
trunk/src/app/srs_app_dvr.hpp
查看文件 @
2f0ef87
...
...
@@ -178,7 +178,7 @@ public:
/**
* the dvr async call.
*/
class
SrsDvrAsyncCallOnDvr
:
public
ISrs
DvrAsyncCall
class
SrsDvrAsyncCallOnDvr
:
public
ISrs
AsyncCallTask
{
private
:
std
::
string
path
;
...
...
@@ -206,7 +206,7 @@ public:
SrsRequest
*
req
;
protected
:
SrsFlvSegment
*
segment
;
Srs
DvrAsyncCallThread
*
async
;
Srs
AsyncCallWorker
*
async
;
bool
dvr_enabled
;
public
:
SrsDvrPlan
();
...
...
trunk/src/app/srs_app_hls.cpp
查看文件 @
2f0ef87
...
...
@@ -286,7 +286,7 @@ SrsHlsMuxer::SrsHlsMuxer()
acodec
=
SrsCodecAudioReserved1
;
should_write_cache
=
false
;
should_write_file
=
true
;
async
=
new
Srs
DvrAsyncCallThread
();
async
=
new
Srs
AsyncCallWorker
();
context
=
new
SrsTsContext
();
}
...
...
@@ -669,7 +669,7 @@ int SrsHlsMuxer::segment_close(string log_desc)
segments
.
push_back
(
current
);
// use async to call the http hooks, for it will cause thread switch.
if
((
ret
=
async
->
call
(
new
SrsDvrAsyncCallOnHls
(
req
,
if
((
ret
=
async
->
execute
(
new
SrsDvrAsyncCallOnHls
(
req
,
current
->
full_path
,
current
->
uri
,
m3u8
,
m3u8_url
,
current
->
sequence_no
,
current
->
duration
)))
!=
ERROR_SUCCESS
)
{
...
...
@@ -677,7 +677,7 @@ int SrsHlsMuxer::segment_close(string log_desc)
}
// use async to call the http hooks, for it will cause thread switch.
if
((
ret
=
async
->
call
(
new
SrsDvrAsyncCallOnHlsNotify
(
req
,
current
->
uri
)))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
async
->
execute
(
new
SrsDvrAsyncCallOnHlsNotify
(
req
,
current
->
uri
)))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
trunk/src/app/srs_app_hls.hpp
查看文件 @
2f0ef87
...
...
@@ -159,7 +159,7 @@ public:
/**
* the hls async call: on_hls
*/
class
SrsDvrAsyncCallOnHls
:
public
ISrs
DvrAsyncCall
class
SrsDvrAsyncCallOnHls
:
public
ISrs
AsyncCallTask
{
private
:
std
::
string
path
;
...
...
@@ -180,7 +180,7 @@ public:
/**
* the hls async call: on_hls_notify
*/
class
SrsDvrAsyncCallOnHlsNotify
:
public
ISrs
DvrAsyncCall
class
SrsDvrAsyncCallOnHlsNotify
:
public
ISrs
AsyncCallTask
{
private
:
std
::
string
ts_url
;
...
...
@@ -215,7 +215,7 @@ private:
double
hls_aof_ratio
;
double
hls_fragment
;
double
hls_window
;
Srs
DvrAsyncCallThread
*
async
;
Srs
AsyncCallWorker
*
async
;
private
:
// whether use floor algorithm for timestamp.
bool
hls_ts_floor
;
...
...
请
注册
或
登录
后发表评论