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
845b2ea8
Unverified
Commit
845b2ea8
authored
May 11, 2022
by
夏楚
Committed by
Gitee
May 11, 2022
Browse files
Options
Browse Files
Download
Plain Diff
!16 增加长期保存hls切片的功能
增加长期保存hls切片的功能,segKeep=0为不长期保存,segKeep=1为长期保存。此功能部分等效于segNum=0的情况,不同的是这个保留不会在m3u8文件中体现。
parents
4c1f0c9b
5bc313ba
显示空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
34 行增加
和
7 行删除
+34
-7
conf/config.ini
+5
-0
src/Common/config.cpp
+2
-0
src/Common/config.h
+2
-0
src/Record/HlsMaker.cpp
+10
-2
src/Record/HlsMaker.h
+8
-1
src/Record/HlsMakerImp.cpp
+3
-2
src/Record/HlsMakerImp.h
+2
-1
src/Record/HlsRecorder.h
+2
-1
没有找到文件。
conf/config.ini
查看文件 @
845b2ea8
...
...
@@ -111,6 +111,11 @@ segRetain=5
broadcastRecordTs
=
0
#直播hls文件删除延时,单位秒,issue: #913
deleteDelaySec
=
0
#是否保留hls文件,此功能部分等效于segNum=0的情况
#不同的是这个保留不会在m3u8文件中体现
#0为不保留,不起作用
#1为保留,则不删除hls文件,如果开启此功能,注意磁盘大小,或者定期手动清理hls文件
segKeep
=
0
[hook]
#在推流时,如果url参数匹对admin_params,那么可以不经过hook鉴权直接推流成功,播放时亦然
...
...
src/Common/config.cpp
查看文件 @
845b2ea8
...
...
@@ -252,6 +252,7 @@ namespace Hls {
#define HLS_FIELD "hls."
const
string
kSegmentDuration
=
HLS_FIELD
"segDur"
;
const
string
kSegmentNum
=
HLS_FIELD
"segNum"
;
const
string
kSegmentKeep
=
HLS_FIELD
"segKeep"
;
const
string
kSegmentRetain
=
HLS_FIELD
"segRetain"
;
const
string
kFileBufSize
=
HLS_FIELD
"fileBufSize"
;
const
string
kFilePath
=
HLS_FIELD
"filePath"
;
...
...
@@ -261,6 +262,7 @@ const string kDeleteDelaySec = HLS_FIELD"deleteDelaySec";
static
onceToken
token
([](){
mINI
::
Instance
()[
kSegmentDuration
]
=
2
;
mINI
::
Instance
()[
kSegmentNum
]
=
3
;
mINI
::
Instance
()[
kSegmentKeep
]
=
false
;
mINI
::
Instance
()[
kSegmentRetain
]
=
5
;
mINI
::
Instance
()[
kFileBufSize
]
=
64
*
1024
;
mINI
::
Instance
()[
kFilePath
]
=
"./www"
;
...
...
src/Common/config.h
查看文件 @
845b2ea8
...
...
@@ -295,6 +295,8 @@ namespace Hls {
extern
const
std
::
string
kSegmentDuration
;
//m3u8文件中HLS切片个数,如果设置为0,则不删除切片,而是保存为点播
extern
const
std
::
string
kSegmentNum
;
//如果设置为0,则不保留切片,设置为1则一直保留切片
extern
const
std
::
string
kSegmentKeep
;
//HLS切片从m3u8文件中移除后,继续保留在磁盘上的个数
extern
const
std
::
string
kSegmentRetain
;
//HLS文件写缓存大小
...
...
src/Record/HlsMaker.cpp
查看文件 @
845b2ea8
...
...
@@ -14,10 +14,11 @@ using namespace std;
namespace
mediakit
{
HlsMaker
::
HlsMaker
(
float
seg_duration
,
uint32_t
seg_number
)
{
HlsMaker
::
HlsMaker
(
float
seg_duration
,
uint32_t
seg_number
,
bool
seg_keep
)
{
//最小允许设置为0,0个切片代表点播
_seg_number
=
seg_number
;
_seg_duration
=
seg_duration
;
_seg_keep
=
seg_keep
;
}
HlsMaker
::~
HlsMaker
()
{
...
...
@@ -105,7 +106,10 @@ void HlsMaker::delOldSegment() {
if
(
_file_index
>
_seg_number
)
{
_seg_dur_list
.
pop_front
();
}
//如果设置为一直保存,就不删除
if
(
_seg_keep
)
{
return
;
}
GET_CONFIG
(
uint32_t
,
segRetain
,
Hls
::
kSegmentRetain
);
//但是实际保存的切片个数比m3u8所述多若干个,这样做的目的是防止播放器在切片删除前能下载完毕
if
(
_file_index
>
_seg_number
+
segRetain
)
{
...
...
@@ -149,6 +153,10 @@ bool HlsMaker::isLive() {
return
_seg_number
!=
0
;
}
bool
HlsMaker
::
isKeep
()
{
return
_seg_keep
;
}
void
HlsMaker
::
clear
()
{
_file_index
=
0
;
_last_timestamp
=
0
;
...
...
src/Record/HlsMaker.h
查看文件 @
845b2ea8
...
...
@@ -26,8 +26,9 @@ public:
/**
* @param seg_duration 切片文件长度
* @param seg_number 切片个数
* @param seg_keep 是否保留切片文件
*/
HlsMaker
(
float
seg_duration
=
5
,
uint32_t
seg_number
=
3
);
HlsMaker
(
float
seg_duration
=
5
,
uint32_t
seg_number
=
3
,
bool
seg_keep
=
false
);
virtual
~
HlsMaker
();
/**
...
...
@@ -45,6 +46,11 @@ public:
bool
isLive
();
/**
* 是否保留切片文件
*/
bool
isKeep
();
/**
* 清空记录
*/
void
clear
();
...
...
@@ -108,6 +114,7 @@ private:
private
:
float
_seg_duration
=
0
;
uint32_t
_seg_number
=
0
;
bool
_seg_keep
=
false
;
uint32_t
_last_timestamp
=
0
;
uint32_t
_last_seg_timestamp
=
0
;
uint64_t
_file_index
=
0
;
...
...
src/Record/HlsMakerImp.cpp
查看文件 @
845b2ea8
...
...
@@ -23,7 +23,8 @@ HlsMakerImp::HlsMakerImp(const string &m3u8_file,
const
string
&
params
,
uint32_t
bufSize
,
float
seg_duration
,
uint32_t
seg_number
)
:
HlsMaker
(
seg_duration
,
seg_number
)
{
uint32_t
seg_number
,
bool
seg_keep
)
:
HlsMaker
(
seg_duration
,
seg_number
,
seg_keep
)
{
_poller
=
EventPollerPool
::
Instance
().
getPoller
();
_path_prefix
=
m3u8_file
.
substr
(
0
,
m3u8_file
.
rfind
(
'/'
));
_path_hls
=
m3u8_file
;
...
...
@@ -47,7 +48,7 @@ void HlsMakerImp::clearCache() {
void
HlsMakerImp
::
clearCache
(
bool
immediately
,
bool
eof
)
{
//录制完了
flushLastSegment
(
eof
);
if
(
!
isLive
())
{
if
(
!
isLive
()
||
isKeep
()
)
{
return
;
}
...
...
src/Record/HlsMakerImp.h
查看文件 @
845b2ea8
...
...
@@ -25,7 +25,8 @@ public:
const
std
::
string
&
params
,
uint32_t
bufSize
=
64
*
1024
,
float
seg_duration
=
5
,
uint32_t
seg_number
=
3
);
uint32_t
seg_number
=
3
,
bool
seg_keep
=
false
);
~
HlsMakerImp
()
override
;
...
...
src/Record/HlsRecorder.h
查看文件 @
845b2ea8
...
...
@@ -22,9 +22,10 @@ public:
HlsRecorder
(
const
std
::
string
&
m3u8_file
,
const
std
::
string
&
params
)
:
MpegMuxer
(
false
)
{
GET_CONFIG
(
uint32_t
,
hlsNum
,
Hls
::
kSegmentNum
);
GET_CONFIG
(
bool
,
hlsKeep
,
Hls
::
kSegmentKeep
);
GET_CONFIG
(
uint32_t
,
hlsBufSize
,
Hls
::
kFileBufSize
);
GET_CONFIG
(
float
,
hlsDuration
,
Hls
::
kSegmentDuration
);
_hls
=
std
::
make_shared
<
HlsMakerImp
>
(
m3u8_file
,
params
,
hlsBufSize
,
hlsDuration
,
hlsNum
);
_hls
=
std
::
make_shared
<
HlsMakerImp
>
(
m3u8_file
,
params
,
hlsBufSize
,
hlsDuration
,
hlsNum
,
hlsKeep
);
//清空上次的残余文件
_hls
->
clearCache
();
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论