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
f581f0f2
Commit
f581f0f2
authored
Dec 05, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化精简录制相关代码
parent
6eb4d591
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
47 行增加
和
35 行删除
+47
-35
src/Common/MultiMediaSourceMuxer.h
+1
-17
src/Record/Recorder.cpp
+15
-18
src/Record/Recorder.h
+31
-0
没有找到文件。
src/Common/MultiMediaSourceMuxer.h
查看文件 @
f581f0f2
...
...
@@ -50,31 +50,16 @@ public:
_rtsp
=
std
::
make_shared
<
RtspMediaSourceMuxer
>
(
vhost
,
strApp
,
strId
,
std
::
make_shared
<
TitleSdp
>
(
dur_sec
));
}
_recordFunc
=
[
bEanbleHls
,
bEnableMp4
,
vhost
,
strApp
,
strId
](
bool
start
){
if
(
bEanbleHls
){
if
(
start
){
Recorder
::
startRecord
(
Recorder
::
type_hls
,
vhost
,
strApp
,
strId
,
true
,
false
);
}
else
{
Recorder
::
stopRecord
(
Recorder
::
type_hls
,
vhost
,
strApp
,
strId
);
}
}
if
(
bEnableMp4
){
if
(
start
){
Recorder
::
startRecord
(
Recorder
::
type_mp4
,
vhost
,
strApp
,
strId
,
true
,
false
);
}
else
{
Recorder
::
stopRecord
(
Recorder
::
type_mp4
,
vhost
,
strApp
,
strId
);
}
}
};
_recordFunc
(
true
);
}
virtual
~
MultiMediaSourceMuxer
(){
if
(
_recordFunc
){
_recordFunc
(
false
);
}
}
virtual
~
MultiMediaSourceMuxer
(){}
/**
* 重置音视频媒体
...
...
@@ -158,7 +143,6 @@ protected:
private
:
RtmpMediaSourceMuxer
::
Ptr
_rtmp
;
RtspMediaSourceMuxer
::
Ptr
_rtsp
;
function
<
void
(
bool
)
>
_recordFunc
;
};
...
...
src/Record/Recorder.cpp
查看文件 @
f581f0f2
...
...
@@ -26,6 +26,7 @@
#include "Recorder.h"
#include "Common/config.h"
#include "Common/MediaSource.h"
#include "MP4Recorder.h"
#include "HlsRecorder.h"
...
...
@@ -94,10 +95,9 @@ public:
* 构建函数
* @param bContinueRecord false表明hls录制从头开始录制(意味着hls临时文件在媒体反注册时会被删除)
*/
RecorderHelper
(
const
MediaSinkInterface
::
Ptr
&
recorder
,
vector
<
Track
::
Ptr
>
&&
tracks
,
bool
bContinueRecord
,
const
string
&
schema
)
{
RecorderHelper
(
const
MediaSinkInterface
::
Ptr
&
recorder
,
bool
bContinueRecord
)
{
_recorder
=
recorder
;
_continueRecord
=
bContinueRecord
;
attachTracks
(
std
::
move
(
tracks
),
schema
);
}
~
RecorderHelper
()
{
...
...
@@ -197,7 +197,11 @@ public:
// 创建录制器失败
return
-
2
;
}
_recorder_map
[
key
]
=
std
::
make_shared
<
RecorderHelper
>
(
recorder
,
std
::
move
(
tracks
),
continueRecord
,
schema
);
auto
helper
=
std
::
make_shared
<
RecorderHelper
>
(
recorder
,
continueRecord
);
if
(
tracks
.
size
()){
helper
->
attachTracks
(
std
::
move
(
tracks
),
schema
);
}
_recorder_map
[
key
]
=
std
::
move
(
helper
);
return
0
;
}
...
...
@@ -239,32 +243,24 @@ private:
return
;
}
auto
tracks
=
sender
.
getTracks
(
true
);
if
(
tracks
.
empty
())
{
// 无有效的tracks
return
;
}
if
(
!
it
->
second
->
isRecording
()
||
it
->
second
->
getSchema
()
==
schema
){
// 绑定的协议一致,替换tracks
// 绑定的协议一致或者并未正在录制则替换tracks
auto
tracks
=
sender
.
getTracks
(
true
);
if
(
!
tracks
.
empty
())
{
it
->
second
->
attachTracks
(
std
::
move
(
tracks
),
schema
);
}
}
}
void
onUnRegist
(
const
string
&
schema
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
MediaSource
&
sender
){
auto
key
=
getRecorderKey
(
vhost
,
app
,
stream
);
lock_guard
<
decltype
(
_recorder_mtx
)
>
lck
(
_recorder_mtx
);
auto
it
=
_recorder_map
.
find
(
key
);
if
(
it
==
_recorder_map
.
end
()){
// 录像记录不存在
if
(
it
==
_recorder_map
.
end
()
||
it
->
second
->
getSchema
()
!=
schema
){
// 录像记录不存在
或绑定的协议不一致
return
;
}
if
(
it
->
second
->
getSchema
()
!=
schema
){
// 绑定的协议不一致
return
;
}
if
(
it
->
second
->
continueRecord
()){
// 如果可以继续录制,那么只重置tracks,不删除对象
it
->
second
->
resetTracks
();
...
...
@@ -318,7 +314,7 @@ private:
break
;
}
if
(
!
ret
){
WarnL
<<
"can not
recorder of
: "
<<
type
;
WarnL
<<
"can not
create recorder of type
: "
<<
type
;
}
return
ret
;
}
...
...
@@ -345,6 +341,7 @@ int Recorder::startRecord(Recorder::type type, const string &vhost, const string
case
type_hls
:
return
MediaSourceWatcher
<
type_hls
>::
Instance
().
startRecord
(
vhost
,
app
,
stream_id
,
waitForRecord
,
continueRecord
);
}
WarnL
<<
"unknown record type: "
<<
type
;
return
-
3
;
}
...
...
src/Record/Recorder.h
查看文件 @
f581f0f2
...
...
@@ -53,9 +53,40 @@ public:
type_mp4
=
1
}
type
;
/**
* 获取录制状态
* @param type hls还是MP4录制
* @param vhost 虚拟主机
* @param app 应用名
* @param stream_id 流id
* @return 录制状态
*/
static
status
getRecordStatus
(
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 waitForRecord 是否等待流注册后再录制,未注册时,置false将返回失败
* @param continueRecord 流注销时是否继续等待录制还是立即停止注册
* @return 0代表成功,负数代表失败
*/
static
int
startRecord
(
type
type
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
,
bool
waitForRecord
,
bool
continueRecord
);
/**
* 停止录制
* @param type hls还是MP4录制
* @param vhost 虚拟主机
* @param app 应用名
* @param stream_id 流id
*/
static
void
stopRecord
(
type
type
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
);
/**
* 停止所有录制,一般程序退出时调用
*/
static
void
stopAll
();
private
:
Recorder
()
=
delete
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论