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
188e087f
Commit
188e087f
authored
Sep 13, 2020
by
wxf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 hls ts 切片录制完成通知
parent
a024c515
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
79 行增加
和
0 行删除
+79
-0
server/WebHook.cpp
+22
-0
src/Common/config.cpp
+1
-0
src/Common/config.h
+4
-0
src/Record/HlsMaker.cpp
+5
-0
src/Record/HlsMaker.h
+20
-0
src/Record/HlsMakerImp.cpp
+25
-0
src/Record/HlsMakerImp.h
+2
-0
没有找到文件。
server/WebHook.cpp
查看文件 @
188e087f
...
...
@@ -53,6 +53,7 @@ const string kOnRtspAuth = HOOK_FIELD"on_rtsp_auth";
const
string
kOnStreamChanged
=
HOOK_FIELD
"on_stream_changed"
;
const
string
kOnStreamNotFound
=
HOOK_FIELD
"on_stream_not_found"
;
const
string
kOnRecordMp4
=
HOOK_FIELD
"on_record_mp4"
;
const
string
kOnRecordTs
=
HOOK_FIELD
"on_record_ts"
;
const
string
kOnShellLogin
=
HOOK_FIELD
"on_shell_login"
;
const
string
kOnStreamNoneReader
=
HOOK_FIELD
"on_stream_none_reader"
;
const
string
kOnHttpAccess
=
HOOK_FIELD
"on_http_access"
;
...
...
@@ -70,6 +71,7 @@ onceToken token([](){
mINI
::
Instance
()[
kOnStreamChanged
]
=
"https://127.0.0.1/index/hook/on_stream_changed"
;
mINI
::
Instance
()[
kOnStreamNotFound
]
=
"https://127.0.0.1/index/hook/on_stream_not_found"
;
mINI
::
Instance
()[
kOnRecordMp4
]
=
"https://127.0.0.1/index/hook/on_record_mp4"
;
mINI
::
Instance
()[
kOnRecordTs
]
=
"https://127.0.0.1/index/hook/on_record_ts"
;
mINI
::
Instance
()[
kOnShellLogin
]
=
"https://127.0.0.1/index/hook/on_shell_login"
;
mINI
::
Instance
()[
kOnStreamNoneReader
]
=
"https://127.0.0.1/index/hook/on_stream_none_reader"
;
mINI
::
Instance
()[
kOnHttpAccess
]
=
"https://127.0.0.1/index/hook/on_http_access"
;
...
...
@@ -190,6 +192,7 @@ void installWebHook(){
GET_CONFIG
(
string
,
hook_stream_chaned
,
Hook
::
kOnStreamChanged
);
GET_CONFIG
(
string
,
hook_stream_not_found
,
Hook
::
kOnStreamNotFound
);
GET_CONFIG
(
string
,
hook_record_mp4
,
Hook
::
kOnRecordMp4
);
GET_CONFIG
(
string
,
hook_record_ts
,
Hook
::
kOnRecordTs
);
GET_CONFIG
(
string
,
hook_shell_login
,
Hook
::
kOnShellLogin
);
GET_CONFIG
(
string
,
hook_stream_none_reader
,
Hook
::
kOnStreamNoneReader
);
GET_CONFIG
(
string
,
hook_http_access
,
Hook
::
kOnHttpAccess
);
...
...
@@ -361,6 +364,25 @@ void installWebHook(){
});
#endif //ENABLE_MP4
NoticeCenter
::
Instance
().
addListener
(
nullptr
,
Broadcast
::
kBroadcastRecordTs
,
[](
BroadcastRecordTsArgs
)
{
if
(
!
hook_enable
||
hook_record_ts
.
empty
())
{
return
;
}
ArgsType
body
;
body
[
"start_time"
]
=
(
Json
::
UInt64
)
info
.
ui64StartedTime
;
body
[
"time_len"
]
=
(
Json
::
UInt64
)
info
.
ui64TimeLen
;
body
[
"file_size"
]
=
(
Json
::
UInt64
)
info
.
ui64FileSize
;
body
[
"file_path"
]
=
info
.
strFilePath
;
body
[
"file_name"
]
=
info
.
strFileName
;
body
[
"folder"
]
=
info
.
strFolder
;
body
[
"url"
]
=
info
.
strUrl
;
body
[
"app"
]
=
info
.
strAppName
;
body
[
"stream"
]
=
info
.
strStreamId
;
body
[
"vhost"
]
=
info
.
strVhost
;
// 执行 hook
do_http_hook
(
hook_record_ts
,
body
,
nullptr
);
});
NoticeCenter
::
Instance
().
addListener
(
nullptr
,
Broadcast
::
kBroadcastShellLogin
,[](
BroadcastShellLoginArgs
){
if
(
!
hook_enable
||
hook_shell_login
.
empty
()
||
sender
.
get_peer_ip
()
==
"127.0.0.1"
){
invoker
(
""
);
...
...
src/Common/config.cpp
查看文件 @
188e087f
...
...
@@ -40,6 +40,7 @@ bool loadIniConfig(const char *ini_path){
namespace
Broadcast
{
const
string
kBroadcastMediaChanged
=
"kBroadcastMediaChanged"
;
const
string
kBroadcastRecordMP4
=
"kBroadcastRecordMP4"
;
const
string
kBroadcastRecordTs
=
"kBroadcastRecoredTs"
;
const
string
kBroadcastHttpRequest
=
"kBroadcastHttpRequest"
;
const
string
kBroadcastHttpAccess
=
"kBroadcastHttpAccess"
;
const
string
kBroadcastOnGetRtspRealm
=
"kBroadcastOnGetRtspRealm"
;
...
...
src/Common/config.h
查看文件 @
188e087f
...
...
@@ -60,6 +60,10 @@ extern const string kBroadcastMediaChanged;
extern
const
string
kBroadcastRecordMP4
;
#define BroadcastRecordMP4Args const MP4Info &info
// 录制 ts 文件后广播
extern
const
string
kBroadcastRecordTs
;
#define BroadcastRecordTsArgs const TsInfo &info
//收到http api请求广播
extern
const
string
kBroadcastHttpRequest
;
#define BroadcastHttpRequestArgs const Parser &parser,const HttpSession::HttpResponseInvoker &invoker,bool &consumed,SockInfo &sender
...
...
src/Record/HlsMaker.cpp
查看文件 @
188e087f
...
...
@@ -120,6 +120,11 @@ void HlsMaker::flushLastSegment(uint32_t timestamp, bool eof){
delOldSegment
();
makeIndexFile
(
eof
);
_last_file_name
.
clear
();
onFlushLastSegment
(
seg_dur
);
}
void
HlsMaker
::
onFlushLastSegment
(
uint32_t
)
{
}
bool
HlsMaker
::
isLive
()
{
...
...
src/Record/HlsMaker.h
查看文件 @
188e087f
...
...
@@ -22,6 +22,20 @@ using namespace toolkit;
namespace
mediakit
{
class
TsInfo
{
public
:
time_t
ui64StartedTime
;
// GMT 标准时间,单位秒
time_t
ui64TimeLen
;
// 录像长度,单位毫秒
off_t
ui64FileSize
;
// 文件大小,单位 BYTE
string
strFilePath
;
// 文件路径
string
strFileName
;
// 文件名称
string
strFolder
;
// 文件夹路径
string
strUrl
;
// 播放路径
string
strAppName
;
// 应用名称
string
strStreamId
;
// 流 ID
string
strVhost
;
// vhost
};
class
HlsMaker
{
public
:
/**
...
...
@@ -85,6 +99,12 @@ protected:
*/
void
flushLastSegment
(
uint32_t
timestamp
,
bool
eof
=
false
);
/**
* 上一个 ts 切片写入完成, 可在这里进行通知处理
* @param duration 上一个 ts 切片的时长, 单位为毫秒
*/
virtual
void
onFlushLastSegment
(
uint32_t
duration
);
private
:
/**
* 生成m3u8文件
...
...
src/Record/HlsMakerImp.cpp
查看文件 @
188e087f
...
...
@@ -8,7 +8,10 @@
* may be found in the AUTHORS file in the root of the source tree.
*/
#include <ctime>
#include <sys/stat.h>
#include "HlsMakerImp.h"
#include "Thread/WorkThreadPool.h"
#include "Util/util.h"
#include "Util/uv_errno.h"
...
...
@@ -28,6 +31,8 @@ HlsMakerImp::HlsMakerImp(const string &m3u8_file,
_file_buf
.
reset
(
new
char
[
bufSize
],
[](
char
*
ptr
)
{
delete
[]
ptr
;
});
_info
.
strFolder
=
_path_prefix
;
}
HlsMakerImp
::~
HlsMakerImp
()
{
...
...
@@ -59,6 +64,12 @@ string HlsMakerImp::onOpenSegment(int index) {
}
}
_file
=
makeFile
(
segment_path
,
true
);
_info
.
ui64StartedTime
=
::
time
(
NULL
);
_info
.
strFileName
=
segment_name
;
_info
.
strFilePath
=
segment_path
;
_info
.
strUrl
=
_info
.
strAppName
+
"/"
+
_info
.
strStreamId
+
"/"
+
segment_name
;
if
(
!
_file
)
{
WarnL
<<
"create file failed,"
<<
segment_path
<<
" "
<<
get_uv_errmsg
();
}
...
...
@@ -97,6 +108,17 @@ void HlsMakerImp::onWriteHls(const char *data, int len) {
//DebugL << "\r\n" << string(data,len);
}
void
HlsMakerImp
::
onFlushLastSegment
(
uint32_t
duration
)
{
auto
info
=
_info
;
info
.
ui64TimeLen
=
duration
;
WorkThreadPool
::
Instance
().
getExecutor
()
->
async
([
info
]()
{
struct
stat
fileData
;
stat
(
info
.
strFilePath
.
data
(),
&
fileData
);
const_cast
<
TsInfo
&>
(
info
).
ui64FileSize
=
fileData
.
st_size
;
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastRecordTs
,
info
);
});
}
std
::
shared_ptr
<
FILE
>
HlsMakerImp
::
makeFile
(
const
string
&
file
,
bool
setbuf
)
{
auto
file_buf
=
_file_buf
;
...
...
@@ -113,6 +135,9 @@ std::shared_ptr<FILE> HlsMakerImp::makeFile(const string &file, bool setbuf) {
void
HlsMakerImp
::
setMediaSource
(
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
)
{
_media_src
=
std
::
make_shared
<
HlsMediaSource
>
(
vhost
,
app
,
stream_id
);
_info
.
strAppName
=
app
;
_info
.
strStreamId
=
stream_id
;
_info
.
strVhost
=
vhost
;
}
HlsMediaSource
::
Ptr
HlsMakerImp
::
getMediaSource
()
const
{
...
...
src/Record/HlsMakerImp.h
查看文件 @
188e087f
...
...
@@ -54,6 +54,7 @@ protected:
void
onDelSegment
(
int
index
)
override
;
void
onWriteSegment
(
const
char
*
data
,
int
len
)
override
;
void
onWriteHls
(
const
char
*
data
,
int
len
)
override
;
void
onFlushLastSegment
(
uint32_t
duration
)
override
;
private
:
std
::
shared_ptr
<
FILE
>
makeFile
(
const
string
&
file
,
bool
setbuf
=
false
);
...
...
@@ -66,6 +67,7 @@ private:
std
::
shared_ptr
<
FILE
>
_file
;
std
::
shared_ptr
<
char
>
_file_buf
;
HlsMediaSource
::
Ptr
_media_src
;
TsInfo
_info
;
map
<
int
/*index*/
,
string
/*file_path*/
>
_segment_file_paths
;
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论