Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
98750831
Commit
98750831
authored
Dec 30, 2021
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hls/mp4录制放置在后台线程
parent
84f3aa07
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
61 行增加
和
4 行删除
+61
-4
server/WebApi.cpp
+7
-1
src/Record/HlsRecorder.cpp
+34
-0
src/Record/HlsRecorder.h
+3
-1
src/Record/MP4Recorder.cpp
+17
-2
没有找到文件。
server/WebApi.cpp
查看文件 @
98750831
...
...
@@ -219,6 +219,10 @@ extern std::vector<size_t> getBlockTypeSize();
extern
uint64_t
getTotalMemBlockByType
(
int
type
);
extern
uint64_t
getThisThreadMemBlockByType
(
int
type
)
;
namespace
mediakit
{
extern
ThreadPool
&
getMP4Thread
();
extern
ThreadPool
&
getHlsThread
();
}
static
inline
void
addHttpListener
(){
GET_CONFIG
(
bool
,
api_debug
,
API
::
kApiDebug
);
//注册监听kBroadcastHttpRequest事件
...
...
@@ -403,7 +407,7 @@ void getStatisticJson(const function<void(Value &val)> &cb) {
val
[
"totalMemBlockTypeCount"
]
=
str
;
}
auto
thread_size
=
EventPollerPool
::
Instance
().
getExecutorSize
()
+
WorkThreadPool
::
Instance
().
getExecutorSize
();
auto
thread_size
=
2
+
EventPollerPool
::
Instance
().
getExecutorSize
()
+
WorkThreadPool
::
Instance
().
getExecutorSize
();
std
::
shared_ptr
<
vector
<
Value
>
>
thread_mem_info
=
std
::
make_shared
<
vector
<
Value
>
>
(
thread_size
);
shared_ptr
<
void
>
finished
(
nullptr
,
[
thread_mem_info
,
cb
,
obj
](
void
*
)
{
...
...
@@ -441,6 +445,8 @@ void getStatisticJson(const function<void(Value &val)> &cb) {
};
EventPollerPool
::
Instance
().
for_each
(
lam1
);
WorkThreadPool
::
Instance
().
for_each
(
lam1
);
lam0
(
getMP4Thread
());
lam0
(
getHlsThread
());
#else
cb
(
*
obj
);
#endif
...
...
src/Record/HlsRecorder.cpp
0 → 100644
查看文件 @
98750831
/*
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
*
* Use of this source code is governed by MIT license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#include "HlsRecorder.h"
namespace
mediakit
{
ThreadPool
&
getHlsThread
()
{
static
ThreadPool
ret
(
1
,
ThreadPool
::
PRIORITY_LOWEST
,
true
);
static
onceToken
s_token
([]()
{
ret
.
async
([]()
{
setThreadName
(
"hls thread"
);
});
});
return
ret
;
}
bool
HlsRecorder
::
inputFrame
(
const
Frame
::
Ptr
&
frame
)
{
auto
ptr
=
shared_from_this
();
auto
cached_frame
=
Frame
::
getCacheAbleFrame
(
frame
);
getHlsThread
().
async
([
ptr
,
cached_frame
]()
{
ptr
->
inputFrame_l
(
cached_frame
);
});
return
true
;
}
}
//namespace mediakit
src/Record/HlsRecorder.h
查看文件 @
98750831
...
...
@@ -63,7 +63,9 @@ public:
return
hls_demand
?
(
_clear_cache
?
true
:
_enabled
)
:
true
;
}
bool
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
{
bool
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
;
bool
inputFrame_l
(
const
Frame
::
Ptr
&
frame
)
{
GET_CONFIG
(
bool
,
hls_demand
,
General
::
kHlsDemand
);
if
(
_clear_cache
&&
hls_demand
)
{
_clear_cache
=
false
;
...
...
src/Record/MP4Recorder.cpp
查看文件 @
98750831
...
...
@@ -20,6 +20,16 @@ using namespace toolkit;
namespace
mediakit
{
ThreadPool
&
getMP4Thread
()
{
static
ThreadPool
ret
(
1
,
ThreadPool
::
PRIORITY_LOWEST
,
true
);
static
onceToken
s_token
([]()
{
ret
.
async
([]()
{
setThreadName
(
"mp4 thread"
);
});
});
return
ret
;
}
MP4Recorder
::
MP4Recorder
(
const
string
&
path
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
,
size_t
max_second
)
{
_folder_path
=
path
;
/////record 业务逻辑//////
...
...
@@ -67,7 +77,7 @@ void MP4Recorder::asyncClose() {
auto
full_path_tmp
=
_full_path_tmp
;
auto
full_path
=
_full_path
;
auto
info
=
_info
;
WorkThreadPool
::
Instance
().
getExecutor
()
->
async
([
muxer
,
full_path_tmp
,
full_path
,
info
]()
mutable
{
getMP4Thread
().
async
([
muxer
,
full_path_tmp
,
full_path
,
info
]()
mutable
{
//获取文件录制时间,放在关闭mp4之前是为了忽略关闭mp4执行时间
info
.
time_len
=
(
float
)
(
::
time
(
NULL
)
-
info
.
start_time
);
//关闭mp4非常耗时,所以要放在后台线程执行
...
...
@@ -112,7 +122,12 @@ bool MP4Recorder::inputFrame(const Frame::Ptr &frame) {
if
(
_muxer
)
{
//生成mp4文件
return
_muxer
->
inputFrame
(
frame
);
auto
muxer
=
_muxer
;
auto
cached_frame
=
Frame
::
getCacheAbleFrame
(
frame
);
getMP4Thread
().
async
([
muxer
,
cached_frame
]()
{
return
muxer
->
inputFrame
(
cached_frame
);
});
return
true
;
}
return
false
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论