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
de33d6a8
Commit
de33d6a8
authored
5 years ago
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
整理文件录制
parent
2c2e7262
显示空白字符变更
内嵌
并排
正在显示
25 个修改的文件
包含
150 行增加
和
185 行删除
+150
-185
server/WebHook.cpp
+1
-0
src/Common/MediaSink.h
+2
-0
src/Common/MediaSource.cpp
+2
-2
src/Common/MultiMediaSourceMuxer.h
+28
-8
src/Common/Stamp.cpp
+0
-0
src/Common/Stamp.h
+0
-0
src/Record/HlsMaker.cpp
+0
-0
src/Record/HlsMaker.h
+0
-0
src/Record/HlsMakerImp.cpp
+0
-0
src/Record/HlsMakerImp.h
+0
-0
src/Record/HlsRecorder.h
+13
-5
src/Record/MP4Muxer.cpp
+0
-0
src/Record/MP4Muxer.h
+1
-1
src/Record/MP4Reader.cpp
+20
-19
src/Record/MP4Reader.h
+8
-8
src/Record/MP4Recorder.cpp
+0
-0
src/Record/MP4Recorder.h
+0
-0
src/Record/Recorder.cpp
+58
-96
src/Record/Recorder.h
+12
-42
src/Record/TsMuxer.cpp
+0
-0
src/Record/TsMuxer.h
+1
-1
src/Rtmp/FlvMuxer.h
+1
-1
src/Rtmp/RtmpSession.h
+1
-1
src/Rtsp/RtspPlayer.h
+1
-1
src/Rtsp/RtspSession.h
+1
-0
没有找到文件。
server/WebHook.cpp
查看文件 @
de33d6a8
...
...
@@ -39,6 +39,7 @@
#include "Rtsp/RtspSession.h"
#include "Http/HttpSession.h"
#include "WebHook.h"
#include "Record/MP4Recorder.h"
using
namespace
Json
;
using
namespace
toolkit
;
...
...
This diff is collapsed.
Click to expand it.
src/Common/MediaSink.h
查看文件 @
de33d6a8
...
...
@@ -40,6 +40,8 @@ namespace mediakit{
class
MediaSinkInterface
:
public
FrameWriterInterface
{
public
:
typedef
std
::
shared_ptr
<
MediaSinkInterface
>
Ptr
;
MediaSinkInterface
(){};
virtual
~
MediaSinkInterface
(){};
...
...
This diff is collapsed.
Click to expand it.
src/Common/MediaSource.cpp
查看文件 @
de33d6a8
...
...
@@ -26,7 +26,7 @@
#include "MediaSource.h"
#include "
MediaFile/Media
Reader.h"
#include "
Record/MP4
Reader.h"
#include "Util/util.h"
#include "Network/sockutil.h"
#include "Network/TcpSession.h"
...
...
@@ -278,7 +278,7 @@ MediaSource::Ptr MediaSource::find(
});
if
(
!
ret
&&
bMake
){
//未查找媒体源,则创建一个
ret
=
M
edia
Reader
::
onMakeMediaSource
(
schema
,
vhost
,
app
,
id
);
ret
=
M
P4
Reader
::
onMakeMediaSource
(
schema
,
vhost
,
app
,
id
);
}
return
ret
;
}
...
...
This diff is collapsed.
Click to expand it.
src/Common/MultiMediaSourceMuxer.h
查看文件 @
de33d6a8
...
...
@@ -29,7 +29,7 @@
#include "Rtsp/RtspMediaSourceMuxer.h"
#include "Rtmp/RtmpMediaSourceMuxer.h"
#include "
MediaFile/Media
Recorder.h"
#include "
Record/
Recorder.h"
class
MultiMediaSourceMuxer
:
public
MediaSink
,
public
std
::
enable_shared_from_this
<
MultiMediaSourceMuxer
>
{
public
:
...
...
@@ -42,15 +42,19 @@ public:
bool
bEanbleRtsp
=
true
,
bool
bEanbleRtmp
=
true
,
bool
bEanbleHls
=
true
,
bool
bEnableMp4
=
false
){
bool
bEnableMp4
=
false
){
if
(
bEanbleRtmp
)
{
_rtmp
=
std
::
make_shared
<
RtmpMediaSourceMuxer
>
(
vhost
,
strApp
,
strId
,
std
::
make_shared
<
TitleMeta
>
(
dur_sec
));
}
if
(
bEanbleRtsp
)
{
_rtsp
=
std
::
make_shared
<
RtspMediaSourceMuxer
>
(
vhost
,
strApp
,
strId
,
std
::
make_shared
<
TitleSdp
>
(
dur_sec
));
}
_record
=
std
::
make_shared
<
MediaRecorder
>
(
vhost
,
strApp
,
strId
,
bEanbleHls
,
bEnableMp4
);
if
(
bEanbleHls
){
_hls
.
reset
(
Recorder
::
createHlsRecorder
(
vhost
,
strApp
,
strId
));
}
if
(
bEnableMp4
){
_mp4
.
reset
(
Recorder
::
createMP4Recorder
(
vhost
,
strApp
,
strId
));
}
}
virtual
~
MultiMediaSourceMuxer
(){}
...
...
@@ -64,7 +68,12 @@ public:
if
(
_rtsp
){
_rtsp
->
resetTracks
();
}
_record
->
resetTracks
();
if
(
_hls
){
_hls
->
resetTracks
();
}
if
(
_mp4
){
_mp4
->
resetTracks
();
}
}
/**
...
...
@@ -106,7 +115,12 @@ protected:
if
(
_rtsp
){
_rtsp
->
addTrack
(
track
);
}
_record
->
addTrack
(
track
);
if
(
_hls
){
_hls
->
addTrack
(
track
);
}
if
(
_mp4
){
_mp4
->
addTrack
(
track
);
}
}
/**
...
...
@@ -120,7 +134,12 @@ protected:
if
(
_rtsp
)
{
_rtsp
->
inputFrame
(
frame
);
}
_record
->
inputFrame
(
frame
);
if
(
_hls
){
_hls
->
inputFrame
(
frame
);
}
if
(
_mp4
){
_mp4
->
inputFrame
(
frame
);
}
}
/**
...
...
@@ -139,7 +158,8 @@ protected:
private
:
RtmpMediaSourceMuxer
::
Ptr
_rtmp
;
RtspMediaSourceMuxer
::
Ptr
_rtsp
;
MediaRecorder
::
Ptr
_record
;
MediaSinkInterface
::
Ptr
_hls
;
MediaSinkInterface
::
Ptr
_mp4
;
};
...
...
This diff is collapsed.
Click to expand it.
src/
MediaFile
/Stamp.cpp
→
src/
Common
/Stamp.cpp
查看文件 @
de33d6a8
File moved
This diff is collapsed.
Click to expand it.
src/
MediaFile
/Stamp.h
→
src/
Common
/Stamp.h
查看文件 @
de33d6a8
File moved
This diff is collapsed.
Click to expand it.
src/
MediaFile
/HlsMaker.cpp
→
src/
Record
/HlsMaker.cpp
查看文件 @
de33d6a8
File moved
This diff is collapsed.
Click to expand it.
src/
MediaFile
/HlsMaker.h
→
src/
Record
/HlsMaker.h
查看文件 @
de33d6a8
File moved
This diff is collapsed.
Click to expand it.
src/
MediaFile
/HlsMakerImp.cpp
→
src/
Record
/HlsMakerImp.cpp
查看文件 @
de33d6a8
File moved
This diff is collapsed.
Click to expand it.
src/
MediaFile
/HlsMakerImp.h
→
src/
Record
/HlsMakerImp.h
查看文件 @
de33d6a8
File moved
This diff is collapsed.
Click to expand it.
src/
MediaFile
/HlsRecorder.h
→
src/
Record
/HlsRecorder.h
查看文件 @
de33d6a8
...
...
@@ -32,15 +32,23 @@
namespace
mediakit
{
class
HlsRecorder
:
public
HlsMakerImp
,
public
TsMuxer
{
class
HlsRecorder
:
public
TsMuxer
{
public
:
template
<
typename
...
ArgsType
>
HlsRecorder
(
ArgsType
&&
...
args
)
:
HlsMakerImp
(
std
::
forward
<
ArgsType
>
(
args
)...){}
~
HlsRecorder
(){};
HlsRecorder
(
const
string
&
m3u8_file
,
const
string
&
params
){
GET_CONFIG
(
uint32_t
,
hlsNum
,
Hls
::
kSegmentNum
);
GET_CONFIG
(
uint32_t
,
hlsBufSize
,
Hls
::
kFileBufSize
);
GET_CONFIG
(
uint32_t
,
hlsDuration
,
Hls
::
kSegmentDuration
);
_hls
=
new
HlsMakerImp
(
m3u8_file
,
params
,
hlsBufSize
,
hlsDuration
,
hlsNum
);
}
~
HlsRecorder
(){
delete
_hls
;
}
protected
:
void
onTs
(
const
void
*
packet
,
int
bytes
,
uint32_t
timestamp
,
int
flags
)
override
{
inputData
((
char
*
)
packet
,
bytes
,
timestamp
);
_hls
->
inputData
((
char
*
)
packet
,
bytes
,
timestamp
);
};
private
:
HlsMakerImp
*
_hls
;
};
}
//namespace mediakit
...
...
This diff is collapsed.
Click to expand it.
src/
MediaFile
/MP4Muxer.cpp
→
src/
Record
/MP4Muxer.cpp
查看文件 @
de33d6a8
File moved
This diff is collapsed.
Click to expand it.
src/
MediaFile
/MP4Muxer.h
→
src/
Record
/MP4Muxer.h
查看文件 @
de33d6a8
...
...
@@ -39,7 +39,7 @@
#include "Extension/AAC.h"
#include "Extension/H264.h"
#include "Extension/H265.h"
#include "Stamp.h"
#include "
Common/
Stamp.h"
namespace
mediakit
{
...
...
This diff is collapsed.
Click to expand it.
src/
MediaFile/Media
Reader.cpp
→
src/
Record/MP4
Reader.cpp
查看文件 @
de33d6a8
...
...
@@ -24,9 +24,10 @@
* SOFTWARE.
*/
#include "M
edia
Reader.h"
#include "M
P4
Reader.h"
#include "Common/config.h"
#include "Util/mini.h"
#include "Util/File.h"
#include "Http/HttpSession.h"
#include "Extension/AAC.h"
#include "Extension/H264.h"
...
...
@@ -37,7 +38,7 @@ using namespace toolkit;
namespace
mediakit
{
#ifdef ENABLE_MP4V2
M
ediaReader
::
Media
Reader
(
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strId
,
const
string
&
filePath
)
{
M
P4Reader
::
MP4
Reader
(
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strId
,
const
string
&
filePath
)
{
_poller
=
WorkThreadPool
::
Instance
().
getPoller
();
auto
strFileName
=
filePath
;
if
(
strFileName
.
empty
()){
...
...
@@ -153,7 +154,7 @@ MediaReader::MediaReader(const string &strVhost,const string &strApp, const stri
}
M
ediaReader
::~
Media
Reader
()
{
M
P4Reader
::~
MP4
Reader
()
{
if
(
_hMP4File
!=
MP4_INVALID_FILE_HANDLE
)
{
MP4Close
(
_hMP4File
);
_hMP4File
=
MP4_INVALID_FILE_HANDLE
;
...
...
@@ -161,7 +162,7 @@ MediaReader::~MediaReader() {
}
void
M
edia
Reader
::
startReadMP4
()
{
void
M
P4
Reader
::
startReadMP4
()
{
auto
strongSelf
=
shared_from_this
();
GET_CONFIG
(
uint32_t
,
sampleMS
,
Record
::
kSampleMS
);
...
...
@@ -173,11 +174,11 @@ void MediaReader::startReadMP4() {
readSample
(
sampleMS
,
false
);
_mediaMuxer
->
setListener
(
strongSelf
);
}
bool
M
edia
Reader
::
seekTo
(
MediaSource
&
sender
,
uint32_t
ui32Stamp
){
bool
M
P4
Reader
::
seekTo
(
MediaSource
&
sender
,
uint32_t
ui32Stamp
){
seek
(
ui32Stamp
);
return
true
;
}
bool
M
edia
Reader
::
close
(
MediaSource
&
sender
,
bool
force
){
bool
M
P4
Reader
::
close
(
MediaSource
&
sender
,
bool
force
){
if
(
!
_mediaMuxer
||
(
!
force
&&
_mediaMuxer
->
readerCount
()
!=
0
)){
return
false
;
}
...
...
@@ -186,14 +187,14 @@ bool MediaReader::close(MediaSource &sender,bool force){
return
true
;
}
void
M
edia
Reader
::
onNoneReader
(
MediaSource
&
sender
)
{
void
M
P4
Reader
::
onNoneReader
(
MediaSource
&
sender
)
{
if
(
!
_mediaMuxer
||
_mediaMuxer
->
readerCount
()
!=
0
){
return
;
}
MediaSourceEvent
::
onNoneReader
(
sender
);
}
bool
M
edia
Reader
::
readSample
(
int
iTimeInc
,
bool
justSeekSyncFrame
)
{
bool
M
P4
Reader
::
readSample
(
int
iTimeInc
,
bool
justSeekSyncFrame
)
{
TimeTicker
();
lock_guard
<
recursive_mutex
>
lck
(
_mtx
);
auto
bFlag0
=
readVideoSample
(
iTimeInc
,
justSeekSyncFrame
);
//数据没读完
...
...
@@ -211,7 +212,7 @@ bool MediaReader::readSample(int iTimeInc,bool justSeekSyncFrame) {
//3秒延时关闭
return
_alive
.
elapsedTime
()
<
3
*
1000
;
}
inline
bool
M
edia
Reader
::
readVideoSample
(
int
iTimeInc
,
bool
justSeekSyncFrame
)
{
inline
bool
M
P4
Reader
::
readVideoSample
(
int
iTimeInc
,
bool
justSeekSyncFrame
)
{
if
(
_video_trId
!=
MP4_INVALID_TRACK_ID
)
{
auto
iNextSample
=
getVideoSampleId
(
iTimeInc
);
MP4SampleId
iIdx
=
_video_current
;
...
...
@@ -245,7 +246,7 @@ inline bool MediaReader::readVideoSample(int iTimeInc,bool justSeekSyncFrame) {
return
false
;
}
inline
bool
M
edia
Reader
::
readAudioSample
(
int
iTimeInc
,
bool
justSeekSyncFrame
)
{
inline
bool
M
P4
Reader
::
readAudioSample
(
int
iTimeInc
,
bool
justSeekSyncFrame
)
{
if
(
_audio_trId
!=
MP4_INVALID_TRACK_ID
)
{
auto
iNextSample
=
getAudioSampleId
(
iTimeInc
);
for
(
auto
i
=
_audio_current
;
i
<
iNextSample
;
i
++
)
{
...
...
@@ -267,27 +268,27 @@ inline bool MediaReader::readAudioSample(int iTimeInc,bool justSeekSyncFrame) {
return
false
;
}
inline
void
M
edia
Reader
::
writeH264
(
uint8_t
*
pucData
,
int
iLen
,
uint32_t
dts
,
uint32_t
pts
)
{
inline
void
M
P4
Reader
::
writeH264
(
uint8_t
*
pucData
,
int
iLen
,
uint32_t
dts
,
uint32_t
pts
)
{
_mediaMuxer
->
inputFrame
(
std
::
make_shared
<
H264FrameNoCacheAble
>
((
char
*
)
pucData
,
iLen
,
dts
,
pts
));
}
inline
void
M
edia
Reader
::
writeAAC
(
uint8_t
*
pucData
,
int
iLen
,
uint32_t
uiStamp
)
{
inline
void
M
P4
Reader
::
writeAAC
(
uint8_t
*
pucData
,
int
iLen
,
uint32_t
uiStamp
)
{
_mediaMuxer
->
inputFrame
(
std
::
make_shared
<
AACFrameNoCacheAble
>
((
char
*
)
pucData
,
iLen
,
uiStamp
));
}
inline
MP4SampleId
M
edia
Reader
::
getVideoSampleId
(
int
iTimeInc
)
{
inline
MP4SampleId
M
P4
Reader
::
getVideoSampleId
(
int
iTimeInc
)
{
MP4SampleId
video_current
=
(
double
)
_video_num_samples
*
(
_iSeekTime
+
_ticker
.
elapsedTime
()
+
iTimeInc
)
/
_video_ms
;
video_current
=
MAX
(
0
,
MIN
(
_video_num_samples
,
video_current
));
return
video_current
;
}
inline
MP4SampleId
M
edia
Reader
::
getAudioSampleId
(
int
iTimeInc
)
{
inline
MP4SampleId
M
P4
Reader
::
getAudioSampleId
(
int
iTimeInc
)
{
MP4SampleId
audio_current
=
(
double
)
_audio_num_samples
*
(
_iSeekTime
+
_ticker
.
elapsedTime
()
+
iTimeInc
)
/
_audio_ms
;
audio_current
=
MAX
(
0
,
MIN
(
_audio_num_samples
,
audio_current
));
return
audio_current
;
}
inline
void
M
edia
Reader
::
setSeekTime
(
uint32_t
iSeekTime
){
inline
void
M
P4
Reader
::
setSeekTime
(
uint32_t
iSeekTime
){
_iSeekTime
=
MAX
(
0
,
MIN
(
iSeekTime
,
_iDuration
));
_ticker
.
resetTime
();
if
(
_audio_trId
!=
MP4_INVALID_TRACK_ID
)
{
...
...
@@ -298,10 +299,10 @@ inline void MediaReader::setSeekTime(uint32_t iSeekTime){
}
}
inline
uint32_t
M
edia
Reader
::
getVideoCurrentTime
(){
inline
uint32_t
M
P4
Reader
::
getVideoCurrentTime
(){
return
(
double
)
_video_current
*
_video_ms
/
_video_num_samples
;
}
void
M
edia
Reader
::
seek
(
uint32_t
iSeekTime
,
bool
bReStart
){
void
M
P4
Reader
::
seek
(
uint32_t
iSeekTime
,
bool
bReStart
){
lock_guard
<
recursive_mutex
>
lck
(
_mtx
);
if
(
iSeekTime
==
0
||
_video_trId
==
MP4_INVALID_TRACK_ID
){
setSeekTime
(
iSeekTime
);
...
...
@@ -331,7 +332,7 @@ void MediaReader::seek(uint32_t iSeekTime,bool bReStart){
MediaSource
::
Ptr
M
edia
Reader
::
onMakeMediaSource
(
const
string
&
strSchema
,
MediaSource
::
Ptr
M
P4
Reader
::
onMakeMediaSource
(
const
string
&
strSchema
,
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strId
,
...
...
@@ -343,7 +344,7 @@ MediaSource::Ptr MediaReader::onMakeMediaSource(const string &strSchema,
return
nullptr
;
}
try
{
M
ediaReader
::
Ptr
pReader
(
new
Media
Reader
(
strVhost
,
strApp
,
strId
,
filePath
));
M
P4Reader
::
Ptr
pReader
(
new
MP4
Reader
(
strVhost
,
strApp
,
strId
,
filePath
));
pReader
->
startReadMP4
();
return
MediaSource
::
find
(
strSchema
,
strVhost
,
strApp
,
strId
,
false
);
}
catch
(
std
::
exception
&
ex
)
{
...
...
This diff is collapsed.
Click to expand it.
src/
MediaFile/Media
Reader.h
→
src/
Record/MP4
Reader.h
查看文件 @
de33d6a8
...
...
@@ -37,10 +37,10 @@ using namespace toolkit;
namespace
mediakit
{
class
M
ediaReader
:
public
std
::
enable_shared_from_this
<
Media
Reader
>
,
public
MediaSourceEvent
{
class
M
P4Reader
:
public
std
::
enable_shared_from_this
<
MP4
Reader
>
,
public
MediaSourceEvent
{
public
:
typedef
std
::
shared_ptr
<
M
edia
Reader
>
Ptr
;
virtual
~
M
edia
Reader
();
typedef
std
::
shared_ptr
<
M
P4
Reader
>
Ptr
;
virtual
~
M
P4
Reader
();
/**
* 流化一个mp4文件,使之转换成RtspMediaSource和RtmpMediaSource
...
...
@@ -49,10 +49,10 @@ public:
* @param strId 流id
* @param filePath 文件路径,如果为空则根据配置文件和上面参数自动生成,否则使用指定的文件
*/
M
edia
Reader
(
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strId
,
const
string
&
filePath
=
""
);
M
P4
Reader
(
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strId
,
const
string
&
filePath
=
""
);
/**
* 开始流化MP4文件,需要指出的是,M
edia
Reader对象一经过调用startReadMP4方法,它的强引用会自持有,
* 意思是在文件流化结束之前或中断之前,M
edia
Reader对象是不会被销毁的(不管有没有被外部对象持有)
* 开始流化MP4文件,需要指出的是,M
P4
Reader对象一经过调用startReadMP4方法,它的强引用会自持有,
* 意思是在文件流化结束之前或中断之前,M
P4
Reader对象是不会被销毁的(不管有没有被外部对象持有)
*/
void
startReadMP4
();
...
...
@@ -64,13 +64,13 @@ public:
bool
seekTo
(
MediaSource
&
sender
,
uint32_t
ui32Stamp
)
override
;
/**
* 关闭M
edia
Reader的流化进程,会触发该对象放弃自持有
* 关闭M
P4
Reader的流化进程,会触发该对象放弃自持有
* @return
*/
bool
close
(
MediaSource
&
sender
,
bool
force
)
override
;
/**
* 自动生成M
edia
Reader对象然后查找相关的MediaSource对象
* 自动生成M
P4
Reader对象然后查找相关的MediaSource对象
* @param strSchema 协议名
* @param strVhost 虚拟主机
* @param strApp 应用名
...
...
This diff is collapsed.
Click to expand it.
src/
MediaFile
/MP4Recorder.cpp
→
src/
Record
/MP4Recorder.cpp
查看文件 @
de33d6a8
File moved
This diff is collapsed.
Click to expand it.
src/
MediaFile
/MP4Recorder.h
→
src/
Record
/MP4Recorder.h
查看文件 @
de33d6a8
File moved
This diff is collapsed.
Click to expand it.
src/
MediaFile/Media
Recorder.cpp
→
src/
Record/
Recorder.cpp
查看文件 @
de33d6a8
/*
* MIT License
*
* Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "
Media
Recorder.h"
* MIT License
*
* Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "Recorder.h"
#include "Common/config.h"
#include "Http/HttpSession.h"
#include "Util/util.h"
#include "Util/mini.h"
#include "Network/sockutil.h"
#include "HlsMakerImp.h"
#include "Player/PlayerBase.h"
#include "Common/MediaSink.h"
#include "MP4Recorder.h"
#include "HlsRecorder.h"
using
namespace
toolkit
;
namespace
mediakit
{
MediaRecorder
::
MediaRecorder
(
const
string
&
strVhost_tmp
,
const
string
&
strApp
,
const
string
&
strId
,
bool
enableHls
,
bool
enableMp4
)
{
GET_CONFIG
(
string
,
hlsPath
,
Hls
::
kFilePath
);
GET_CONFIG
(
uint32_t
,
hlsBufSize
,
Hls
::
kFileBufSize
);
GET_CONFIG
(
uint32_t
,
hlsDuration
,
Hls
::
kSegmentDuration
);
GET_CONFIG
(
uint32_t
,
hlsNum
,
Hls
::
kSegmentNum
);
GET_CONFIG
(
bool
,
enableVhost
,
General
::
kEnableVhost
);
MediaSinkInterface
*
Recorder
::
createHlsRecorder
(
const
string
&
strVhost_tmp
,
const
string
&
strApp
,
const
string
&
strId
)
{
#if defined(ENABLE_HLS)
GET_CONFIG
(
bool
,
enableVhost
,
General
::
kEnableVhost
);
GET_CONFIG
(
string
,
hlsPath
,
Hls
::
kFilePath
);
string
strVhost
=
strVhost_tmp
;
if
(
trim
(
strVhost
).
empty
())
{
if
(
trim
(
strVhost
).
empty
())
{
//如果strVhost为空,则强制为默认虚拟主机
strVhost
=
DEFAULT_VHOST
;
}
#if defined(ENABLE_HLS)
if
(
enableHls
)
{
string
m3u8FilePath
;
string
params
;
if
(
enableVhost
)
{
if
(
enableVhost
)
{
m3u8FilePath
=
strVhost
+
"/"
+
strApp
+
"/"
+
strId
+
"/hls.m3u8"
;
params
=
string
(
VHOST_KEY
)
+
"="
+
strVhost
;
}
else
{
}
else
{
m3u8FilePath
=
strApp
+
"/"
+
strId
+
"/hls.m3u8"
;
}
m3u8FilePath
=
File
::
absolutePath
(
m3u8FilePath
,
hlsPath
);
_hlsRecorder
.
reset
(
new
HlsRecorder
(
m3u8FilePath
,
params
,
hlsBufSize
,
hlsDuration
,
hlsNum
));
}
m3u8FilePath
=
File
::
absolutePath
(
m3u8FilePath
,
hlsPath
);
return
new
HlsRecorder
(
m3u8FilePath
,
params
);
#else
return
nullptr
;
#endif //defined(ENABLE_HLS)
}
MediaSinkInterface
*
Recorder
::
createMP4Recorder
(
const
string
&
strVhost_tmp
,
const
string
&
strApp
,
const
string
&
strId
)
{
#if defined(ENABLE_MP4RECORD)
GET_CONFIG
(
string
,
recordPath
,
Record
::
kFilePath
);
GET_CONFIG
(
string
,
recordAppName
,
Record
::
kAppName
);
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
;
}
if
(
enableMp4
){
string
mp4FilePath
;
if
(
enableVhost
)
{
if
(
enableVhost
)
{
mp4FilePath
=
strVhost
+
"/"
+
recordAppName
+
"/"
+
strApp
+
"/"
+
strId
+
"/"
;
}
else
{
mp4FilePath
=
recordAppName
+
"/"
+
strApp
+
"/"
+
strId
+
"/"
;
}
mp4FilePath
=
File
::
absolutePath
(
mp4FilePath
,
recordPath
);
_mp4Recorder
.
reset
(
new
MP4Recorder
(
mp4FilePath
,
strVhost
,
strApp
,
strId
));
}
#endif //defined(ENABLE_MP4RECORD)
}
MediaRecorder
::~
MediaRecorder
()
{
}
void
MediaRecorder
::
inputFrame
(
const
Frame
::
Ptr
&
frame
)
{
#if defined(ENABLE_HLS)
if
(
_hlsRecorder
)
{
_hlsRecorder
->
inputFrame
(
frame
);
}
#endif //defined(ENABLE_HLS)
#if defined(ENABLE_MP4RECORD)
if
(
_mp4Recorder
)
{
_mp4Recorder
->
inputFrame
(
frame
);
}
mp4FilePath
=
File
::
absolutePath
(
mp4FilePath
,
recordPath
);
return
new
MP4Recorder
(
mp4FilePath
,
strVhost
,
strApp
,
strId
);
#else
return
nullptr
;
#endif //defined(ENABLE_MP4RECORD)
}
void
MediaRecorder
::
addTrack
(
const
Track
::
Ptr
&
track
)
{
#if defined(ENABLE_HLS)
if
(
_hlsRecorder
)
{
_hlsRecorder
->
addTrack
(
track
);
}
#endif //defined(ENABLE_HLS)
#if defined(ENABLE_MP4RECORD)
if
(
_mp4Recorder
)
{
_mp4Recorder
->
addTrack
(
track
);
}
#endif //defined(ENABLE_MP4RECORD)
}
void
MediaRecorder
::
resetTracks
()
{
#if defined(ENABLE_HLS)
if
(
_hlsRecorder
)
{
_hlsRecorder
->
resetTracks
();
}
#endif //defined(ENABLE_HLS)
#if defined(ENABLE_MP4RECORD)
if
(
_mp4Recorder
)
{
_mp4Recorder
->
resetTracks
();
}
#endif //defined(ENABLE_MP4RECORD)
}
}
/* namespace mediakit */
This diff is collapsed.
Click to expand it.
src/
MediaFile/Media
Recorder.h
→
src/
Record/
Recorder.h
查看文件 @
de33d6a8
...
...
@@ -24,56 +24,26 @@
* SOFTWARE.
*/
#ifndef SRC_MEDIAFILE_
MEDIA
RECORDER_H_
#define SRC_MEDIAFILE_
MEDIA
RECORDER_H_
#ifndef SRC_MEDIAFILE_RECORDER_H_
#define SRC_MEDIAFILE_RECORDER_H_
#include <memory>
#include "Player/PlayerBase.h"
#include "Common/MediaSink.h"
#include "MP4Recorder.h"
#include "HlsRecorder.h"
using
namespace
toolkit
;
#include <string>
using
namespace
std
;
namespace
mediakit
{
class
MediaRecorder
:
public
MediaSinkInterface
{
public
:
typedef
std
::
shared_ptr
<
MediaRecorder
>
Ptr
;
MediaRecorder
(
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strId
,
bool
enableHls
=
true
,
bool
enableMp4
=
false
);
virtual
~
MediaRecorder
();
class
MediaSinkInterface
;
/**
* 输入frame
* @param frame
*/
void
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
;
/**
* 添加track,内部会调用Track的clone方法
* 只会克隆sps pps这些信息 ,而不会克隆Delegate相关关系
* @param track
*/
void
addTrack
(
const
Track
::
Ptr
&
track
)
override
;
/**
* 重置track
*/
void
resetTracks
()
override
;
class
Recorder
{
public
:
static
MediaSinkInterface
*
createHlsRecorder
(
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strId
);
static
MediaSinkInterface
*
createMP4Recorder
(
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strId
);
private
:
#if defined(ENABLE_HLS)
std
::
shared_ptr
<
HlsRecorder
>
_hlsRecorder
;
#endif //defined(ENABLE_HLS)
#if defined(ENABLE_MP4RECORD)
std
::
shared_ptr
<
MP4Recorder
>
_mp4Recorder
;
#endif //defined(ENABLE_MP4RECORD)
Recorder
()
=
delete
;
~
Recorder
()
=
delete
;
};
}
/* namespace mediakit */
#endif
/* SRC_MEDIAFILE_
MEDIA
RECORDER_H_ */
#endif
/* SRC_MEDIAFILE_RECORDER_H_ */
This diff is collapsed.
Click to expand it.
src/
MediaFile
/TsMuxer.cpp
→
src/
Record
/TsMuxer.cpp
查看文件 @
de33d6a8
File moved
This diff is collapsed.
Click to expand it.
src/
MediaFile
/TsMuxer.h
→
src/
Record
/TsMuxer.h
查看文件 @
de33d6a8
...
...
@@ -32,7 +32,7 @@
#include "Extension/Track.h"
#include "Util/File.h"
#include "Common/MediaSink.h"
#include "Stamp.h"
#include "
Common/
Stamp.h"
using
namespace
toolkit
;
...
...
This diff is collapsed.
Click to expand it.
src/Rtmp/FlvMuxer.h
查看文件 @
de33d6a8
...
...
@@ -30,7 +30,7 @@
#include "Rtmp/Rtmp.h"
#include "Rtmp/RtmpMediaSource.h"
#include "Network/Socket.h"
#include "
MediaFile
/Stamp.h"
#include "
Common
/Stamp.h"
using
namespace
toolkit
;
namespace
mediakit
{
...
...
This diff is collapsed.
Click to expand it.
src/Rtmp/RtmpSession.h
查看文件 @
de33d6a8
...
...
@@ -37,7 +37,7 @@
#include "Util/util.h"
#include "Util/TimeTicker.h"
#include "Network/TcpSession.h"
#include "
MediaFile
/Stamp.h"
#include "
Common
/Stamp.h"
using
namespace
toolkit
;
...
...
This diff is collapsed.
Click to expand it.
src/Rtsp/RtspPlayer.h
查看文件 @
de33d6a8
...
...
@@ -40,7 +40,7 @@
#include "Network/TcpClient.h"
#include "RtspSplitter.h"
#include "RtpReceiver.h"
#include "
MediaFile
/Stamp.h"
#include "
Common
/Stamp.h"
using
namespace
std
;
using
namespace
toolkit
;
...
...
This diff is collapsed.
Click to expand it.
src/Rtsp/RtspSession.h
查看文件 @
de33d6a8
...
...
@@ -41,6 +41,7 @@
#include "RtspSplitter.h"
#include "RtpReceiver.h"
#include "RtspToRtmpMediaSource.h"
#include "Common/Stamp.h"
using
namespace
std
;
using
namespace
toolkit
;
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论