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
51e0c710
Commit
51e0c710
authored
Feb 01, 2020
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加更多录制相关方法
parent
e8ba94ba
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
80 行增加
和
76 行删除
+80
-76
src/Record/Recorder.cpp
+58
-76
src/Record/Recorder.h
+22
-0
没有找到文件。
src/Record/Recorder.cpp
查看文件 @
51e0c710
...
...
@@ -34,67 +34,42 @@ using namespace toolkit;
namespace
mediakit
{
MediaSinkInterface
*
createHlsRecorder
(
const
string
&
strVhost_tmp
,
const
string
&
strApp
,
const
string
&
strId
,
const
string
&
customized_path
)
{
#if defined(ENABLE_HLS)
GET_CONFIG
(
bool
,
enableVhost
,
General
::
kEnableVhost
);
GET_CONFIG
(
string
,
hlsPath
,
Hls
::
kFilePath
);
string
strVhost
=
strVhost_tmp
;
if
(
trim
(
strVhost
).
empty
())
{
//如果strVhost为空,则强制为默认虚拟主机
strVhost
=
DEFAULT_VHOST
;
}
string
m3u8FilePath
;
string
params
;
if
(
enableVhost
)
{
m3u8FilePath
=
strVhost
+
"/"
+
strApp
+
"/"
+
strId
+
"/hls.m3u8"
;
params
=
string
(
VHOST_KEY
)
+
"="
+
strVhost
;
}
else
{
m3u8FilePath
=
strApp
+
"/"
+
strId
+
"/hls.m3u8"
;
}
//Here we use the customized file path.
if
(
!
customized_path
.
empty
()){
m3u8FilePath
=
customized_path
+
"/hls.m3u8"
;
}
m3u8FilePath
=
File
::
absolutePath
(
m3u8FilePath
,
hlsPath
);
auto
ret
=
new
HlsRecorder
(
m3u8FilePath
,
params
);
ret
->
setMediaSource
(
strVhost
,
strApp
,
strId
);
return
ret
;
#else
return
nullptr
;
#endif //defined(ENABLE_HLS)
}
MediaSinkInterface
*
createMP4Recorder
(
const
string
&
strVhost_tmp
,
const
string
&
strApp
,
const
string
&
strId
,
const
string
&
customized_path
)
{
#if defined(ENABLE_MP4RECORD)
string
Recorder
::
getRecordPath
(
Recorder
::
type
type
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
,
const
string
&
customized_path
)
{
GET_CONFIG
(
bool
,
enableVhost
,
General
::
kEnableVhost
);
GET_CONFIG
(
string
,
recordPath
,
Record
::
kFilePath
);
GET_CONFIG
(
string
,
recordAppName
,
Record
::
kAppName
);
string
strVhost
=
strVhost_tmp
;
if
(
trim
(
strVhost
).
empty
())
{
//如果strVhost为空,则强制为默认虚拟主机
strVhost
=
DEFAULT_VHOST
;
}
string
mp4FilePath
;
if
(
enableVhost
)
{
mp4FilePath
=
strVhost
+
"/"
+
recordAppName
+
"/"
+
strApp
+
"/"
+
strId
+
"/"
;
}
else
{
mp4FilePath
=
recordAppName
+
"/"
+
strApp
+
"/"
+
strId
+
"/"
;
}
//Here we use the customized file path.
if
(
!
customized_path
.
empty
()){
mp4FilePath
=
customized_path
+
"/"
;
switch
(
type
)
{
case
Recorder
:
:
type_hls
:
{
GET_CONFIG
(
string
,
hlsPath
,
Hls
::
kFilePath
);
string
m3u8FilePath
;
if
(
enableVhost
)
{
m3u8FilePath
=
vhost
+
"/"
+
app
+
"/"
+
stream_id
+
"/hls.m3u8"
;
}
else
{
m3u8FilePath
=
app
+
"/"
+
stream_id
+
"/hls.m3u8"
;
}
//Here we use the customized file path.
if
(
!
customized_path
.
empty
())
{
m3u8FilePath
=
customized_path
+
"/hls.m3u8"
;
}
return
File
::
absolutePath
(
m3u8FilePath
,
hlsPath
);
}
case
Recorder
:
:
type_mp4
:
{
GET_CONFIG
(
string
,
recordPath
,
Record
::
kFilePath
);
GET_CONFIG
(
string
,
recordAppName
,
Record
::
kAppName
);
string
mp4FilePath
;
if
(
enableVhost
)
{
mp4FilePath
=
vhost
+
"/"
+
recordAppName
+
"/"
+
app
+
"/"
+
stream_id
+
"/"
;
}
else
{
mp4FilePath
=
recordAppName
+
"/"
+
app
+
"/"
+
stream_id
+
"/"
;
}
//Here we use the customized file path.
if
(
!
customized_path
.
empty
())
{
mp4FilePath
=
customized_path
+
"/"
;
}
return
File
::
absolutePath
(
mp4FilePath
,
recordPath
);
}
default
:
return
""
;
}
mp4FilePath
=
File
::
absolutePath
(
mp4FilePath
,
recordPath
);
return
new
MP4Recorder
(
mp4FilePath
,
strVhost
,
strApp
,
strId
);
#else
return
nullptr
;
#endif //defined(ENABLE_MP4RECORD)
}
////////////////////////////////////////////////////////////////////////////////////////
class
RecorderHelper
{
...
...
@@ -215,9 +190,10 @@ public:
return
-
1
;
}
auto
recorder
=
MediaSinkInterface
::
Ptr
(
createRecorder
(
vhost
,
app
,
stream_id
,
customized_path
)
);
auto
recorder
=
Recorder
::
createRecorder
(
type
,
vhost
,
app
,
stream_id
,
customized_path
);
if
(
!
recorder
)
{
// 创建录制器失败
WarnL
<<
"不支持该录制类型:"
<<
type
;
return
-
2
;
}
auto
helper
=
std
::
make_shared
<
RecorderHelper
>
(
recorder
,
continueRecord
);
...
...
@@ -334,23 +310,6 @@ private:
return
vhost
+
"/"
+
app
+
"/"
+
stream_id
;
}
MediaSinkInterface
*
createRecorder
(
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
,
const
string
&
customized_path
)
{
MediaSinkInterface
*
ret
=
nullptr
;
switch
(
type
)
{
case
Recorder
:
:
type_hls
:
ret
=
createHlsRecorder
(
vhost
,
app
,
stream_id
,
customized_path
);
break
;
case
Recorder
:
:
type_mp4
:
ret
=
createMP4Recorder
(
vhost
,
app
,
stream_id
,
customized_path
);
break
;
default
:
break
;
}
if
(
!
ret
){
WarnL
<<
"can not create recorder of type: "
<<
type
;
}
return
ret
;
}
/**
* 有些录制类型不需要track就绪即可录制
...
...
@@ -392,6 +351,29 @@ std::shared_ptr<MediaSinkInterface> Recorder::getRecorder(type type, const strin
return
nullptr
;
}
std
::
shared_ptr
<
MediaSinkInterface
>
Recorder
::
createRecorder
(
type
type
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
,
const
string
&
customized_path
){
auto
path
=
Recorder
::
getRecordPath
(
type
,
vhost
,
app
,
stream_id
);
switch
(
type
)
{
case
Recorder
:
:
type_hls
:
{
#if defined(ENABLE_HLS)
auto
ret
=
std
::
make_shared
<
HlsRecorder
>
(
path
,
string
(
VHOST_KEY
)
+
"="
+
vhost
);
ret
->
setMediaSource
(
vhost
,
app
,
stream_id
);
return
ret
;
#endif
return
nullptr
;
}
case
Recorder
:
:
type_mp4
:
{
#if defined(ENABLE_MP4RECORD)
return
std
::
make_shared
<
MP4Recorder
>
(
path
,
vhost
,
app
,
stream_id
);
#endif
return
nullptr
;
}
default
:
return
nullptr
;
}
}
int
Recorder
::
startRecord
(
Recorder
::
type
type
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
,
const
string
&
customized_path
,
bool
waitForRecord
,
bool
continueRecord
)
{
switch
(
type
){
...
...
src/Record/Recorder.h
查看文件 @
51e0c710
...
...
@@ -53,6 +53,17 @@ public:
type_mp4
=
1
}
type
;
/**
* 获取录制文件绝对路径
* @param type hls还是MP4录制
* @param vhost 虚拟主机
* @param app 应用名
* @param stream_id 流id
* @param customized_path 录像文件保存自定义目录,默认为空则自动生成
* @return 录制文件绝对路径
*/
static
string
getRecordPath
(
type
type
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
,
const
string
&
customized_path
=
""
);
/**
* 获取录制状态
* @param type hls还是MP4录制
...
...
@@ -98,6 +109,17 @@ public:
* @param stream_id 流id
*/
static
std
::
shared_ptr
<
MediaSinkInterface
>
getRecorder
(
type
type
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
);
/**
* 创建录制器对象
* @param type hls还是MP4录制
* @param vhost 虚拟主机
* @param app 应用名
* @param stream_id 流id
* @param customized_path 录像文件保存自定义目录,默认为空则自动生成
* @return 对象指针,可能为nullptr
*/
static
std
::
shared_ptr
<
MediaSinkInterface
>
createRecorder
(
type
type
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
,
const
string
&
customized_path
);
private
:
Recorder
()
=
delete
;
~
Recorder
()
=
delete
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论