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
c6e9f836
Commit
c6e9f836
authored
Aug 22, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
规范类命名
parent
61d8c526
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
51 行增加
和
51 行删除
+51
-51
src/MediaFile/MP4Recorder.cpp
+8
-8
src/MediaFile/MP4Recorder.h
+4
-4
src/MediaFile/MediaRecorder.cpp
+11
-11
src/MediaFile/MediaRecorder.h
+3
-3
src/Rtsp/RtpMultiCaster.cpp
+12
-12
src/Rtsp/RtpMultiCaster.h
+5
-5
src/Rtsp/RtspSession.cpp
+6
-6
src/Rtsp/RtspSession.h
+2
-2
没有找到文件。
src/MediaFile/M
p4Mak
er.cpp
→
src/MediaFile/M
P4Record
er.cpp
查看文件 @
c6e9f836
...
...
@@ -28,7 +28,7 @@
#include <ctime>
#include <sys/stat.h>
#include "Common/config.h"
#include "M
p4Mak
er.h"
#include "M
P4Record
er.h"
#include "Util/util.h"
#include "Util/NoticeCenter.h"
#include "Thread/WorkThreadPool.h"
...
...
@@ -53,7 +53,7 @@ string timeStr(const char *fmt) {
return
buffer
;
}
M
p4Maker
::
Mp4Mak
er
(
const
string
&
strPath
,
M
P4Recorder
::
MP4Record
er
(
const
string
&
strPath
,
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strStreamId
)
{
...
...
@@ -64,11 +64,11 @@ Mp4Maker::Mp4Maker(const string& strPath,
_info
.
strVhost
=
strVhost
;
_info
.
strFolder
=
strPath
;
}
M
p4Maker
::~
Mp4Mak
er
()
{
M
P4Recorder
::~
MP4Record
er
()
{
closeFile
();
}
void
M
p4Mak
er
::
createFile
()
{
void
M
P4Record
er
::
createFile
()
{
closeFile
();
auto
strDate
=
timeStr
(
"%Y-%m-%d"
);
auto
strTime
=
timeStr
(
"%H-%M-%S"
);
...
...
@@ -100,7 +100,7 @@ void Mp4Maker::createFile() {
}
}
void
M
p4Mak
er
::
asyncClose
()
{
void
M
P4Record
er
::
asyncClose
()
{
auto
muxer
=
_muxer
;
auto
strFileTmp
=
_strFileTmp
;
auto
strFile
=
_strFile
;
...
...
@@ -121,14 +121,14 @@ void Mp4Maker::asyncClose() {
});
}
void
M
p4Mak
er
::
closeFile
()
{
void
M
P4Record
er
::
closeFile
()
{
if
(
_muxer
)
{
asyncClose
();
_muxer
=
nullptr
;
}
}
void
M
p4Mak
er
::
onTrackFrame
(
const
Frame
::
Ptr
&
frame
)
{
void
M
P4Record
er
::
onTrackFrame
(
const
Frame
::
Ptr
&
frame
)
{
GET_CONFIG
(
uint32_t
,
recordSec
,
Record
::
kFileSecond
);
if
(
!
_muxer
||
((
_createFileTicker
.
elapsedTime
()
>
recordSec
*
1000
)
&&
(
!
_haveVideo
||
(
_haveVideo
&&
frame
->
keyFrame
())))
){
...
...
@@ -145,7 +145,7 @@ void Mp4Maker::onTrackFrame(const Frame::Ptr &frame) {
}
}
void
M
p4Mak
er
::
onTrackReady
(
const
Track
::
Ptr
&
track
){
void
M
P4Record
er
::
onTrackReady
(
const
Track
::
Ptr
&
track
){
//保存所有的track,为创建MP4MuxerFile做准备
_tracks
.
emplace_back
(
track
);
if
(
track
->
getTrackType
()
==
TrackVideo
){
...
...
src/MediaFile/M
p4Mak
er.h
→
src/MediaFile/M
P4Record
er.h
查看文件 @
c6e9f836
...
...
@@ -55,14 +55,14 @@ public:
string
strStreamId
;
//流ID
string
strVhost
;
//vhost
};
class
M
p4Mak
er
:
public
MediaSink
{
class
M
P4Record
er
:
public
MediaSink
{
public
:
typedef
std
::
shared_ptr
<
M
p4Mak
er
>
Ptr
;
M
p4Mak
er
(
const
string
&
strPath
,
typedef
std
::
shared_ptr
<
M
P4Record
er
>
Ptr
;
M
P4Record
er
(
const
string
&
strPath
,
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strStreamId
);
virtual
~
M
p4Mak
er
();
virtual
~
M
P4Record
er
();
private
:
/**
* 某Track输出frame,在onAllTrackReady触发后才会调用此方法
...
...
src/MediaFile/MediaRecorder.cpp
查看文件 @
c6e9f836
...
...
@@ -58,10 +58,10 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp,
string
m3u8FilePath
;
if
(
enableVhost
){
m3u8FilePath
=
hlsPath
+
"/"
+
strVhost
+
"/"
+
strApp
+
"/"
+
strId
+
"/hls.m3u8"
;
_hls
Mak
er
.
reset
(
new
HlsRecorder
(
m3u8FilePath
,
string
(
VHOST_KEY
)
+
"="
+
strVhost
,
hlsBufSize
,
hlsDuration
,
hlsNum
));
_hls
Record
er
.
reset
(
new
HlsRecorder
(
m3u8FilePath
,
string
(
VHOST_KEY
)
+
"="
+
strVhost
,
hlsBufSize
,
hlsDuration
,
hlsNum
));
}
else
{
m3u8FilePath
=
hlsPath
+
"/"
+
strApp
+
"/"
+
strId
+
"/hls.m3u8"
;
_hls
Mak
er
.
reset
(
new
HlsRecorder
(
m3u8FilePath
,
""
,
hlsBufSize
,
hlsDuration
,
hlsNum
));
_hls
Record
er
.
reset
(
new
HlsRecorder
(
m3u8FilePath
,
""
,
hlsBufSize
,
hlsDuration
,
hlsNum
));
}
}
#endif //defined(ENABLE_HLS)
...
...
@@ -77,7 +77,7 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp,
}
else
{
mp4FilePath
=
recordPath
+
"/"
+
recordAppName
+
"/"
+
strApp
+
"/"
+
strId
+
"/"
;
}
_mp4
Maker
.
reset
(
new
Mp4Mak
er
(
mp4FilePath
,
strVhost
,
strApp
,
strId
));
_mp4
Recorder
.
reset
(
new
MP4Record
er
(
mp4FilePath
,
strVhost
,
strApp
,
strId
));
}
#endif //defined(ENABLE_MP4V2)
}
...
...
@@ -87,28 +87,28 @@ MediaRecorder::~MediaRecorder() {
void
MediaRecorder
::
inputFrame
(
const
Frame
::
Ptr
&
frame
)
{
#if defined(ENABLE_HLS)
if
(
_hls
Mak
er
)
{
_hls
Mak
er
->
inputFrame
(
frame
);
if
(
_hls
Record
er
)
{
_hls
Record
er
->
inputFrame
(
frame
);
}
#endif //defined(ENABLE_HLS)
#if defined(ENABLE_MP4V2)
if
(
_mp4
Mak
er
)
{
_mp4
Mak
er
->
inputFrame
(
frame
);
if
(
_mp4
Record
er
)
{
_mp4
Record
er
->
inputFrame
(
frame
);
}
#endif //defined(ENABLE_MP4V2)
}
void
MediaRecorder
::
addTrack
(
const
Track
::
Ptr
&
track
)
{
#if defined(ENABLE_HLS)
if
(
_hls
Mak
er
)
{
_hls
Mak
er
->
addTrack
(
track
);
if
(
_hls
Record
er
)
{
_hls
Record
er
->
addTrack
(
track
);
}
#endif //defined(ENABLE_HLS)
#if defined(ENABLE_MP4RECORD)
if
(
_mp4
Mak
er
)
{
_mp4
Mak
er
->
addTrack
(
track
);
if
(
_mp4
Record
er
)
{
_mp4
Record
er
->
addTrack
(
track
);
}
#endif //defined(ENABLE_MP4RECORD)
}
...
...
src/MediaFile/MediaRecorder.h
查看文件 @
c6e9f836
...
...
@@ -30,7 +30,7 @@
#include <memory>
#include "Player/PlayerBase.h"
#include "Common/MediaSink.h"
#include "M
p4Mak
er.h"
#include "M
P4Record
er.h"
#include "HlsRecorder.h"
using
namespace
toolkit
;
...
...
@@ -61,11 +61,11 @@ public:
void
addTrack
(
const
Track
::
Ptr
&
track
)
override
;
private
:
#if defined(ENABLE_HLS)
std
::
shared_ptr
<
HlsRecorder
>
_hls
Mak
er
;
std
::
shared_ptr
<
HlsRecorder
>
_hls
Record
er
;
#endif //defined(ENABLE_HLS)
#if defined(ENABLE_MP4RECORD)
std
::
shared_ptr
<
M
p4Maker
>
_mp4Mak
er
;
std
::
shared_ptr
<
M
P4Recorder
>
_mp4Record
er
;
#endif //defined(ENABLE_MP4RECORD)
};
...
...
src/Rtsp/Rtp
Broad
Caster.cpp
→
src/Rtsp/Rtp
Multi
Caster.cpp
查看文件 @
c6e9f836
...
...
@@ -26,7 +26,7 @@
#include <list>
#include <type_traits>
#include "Rtp
Broad
Caster.h"
#include "Rtp
Multi
Caster.h"
#include "Util/util.h"
#include "Network/sockutil.h"
#include "RtspSession.h"
...
...
@@ -81,10 +81,10 @@ void MultiCastAddressMaker::release(uint32_t iAddr){
}
recursive_mutex
Rtp
Broad
Caster
::
g_mtx
;
unordered_map
<
string
,
weak_ptr
<
Rtp
BroadCaster
>
>
RtpBroad
Caster
::
g_mapBroadCaster
;
recursive_mutex
Rtp
Multi
Caster
::
g_mtx
;
unordered_map
<
string
,
weak_ptr
<
Rtp
MultiCaster
>
>
RtpMulti
Caster
::
g_mapBroadCaster
;
void
Rtp
Broad
Caster
::
setDetachCB
(
void
*
listener
,
const
onDetach
&
cb
)
{
void
Rtp
Multi
Caster
::
setDetachCB
(
void
*
listener
,
const
onDetach
&
cb
)
{
lock_guard
<
recursive_mutex
>
lck
(
_mtx
);
if
(
cb
){
_mapDetach
.
emplace
(
listener
,
cb
);
...
...
@@ -92,12 +92,12 @@ void RtpBroadCaster::setDetachCB(void* listener, const onDetach& cb) {
_mapDetach
.
erase
(
listener
);
}
}
Rtp
BroadCaster
::~
RtpBroad
Caster
()
{
Rtp
MultiCaster
::~
RtpMulti
Caster
()
{
_pReader
->
setReadCB
(
nullptr
);
_pReader
->
setDetachCB
(
nullptr
);
DebugL
;
}
Rtp
BroadCaster
::
RtpBroad
Caster
(
const
EventPoller
::
Ptr
&
poller
,
const
string
&
strLocalIp
,
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strStream
)
{
Rtp
MultiCaster
::
RtpMulti
Caster
(
const
EventPoller
::
Ptr
&
poller
,
const
string
&
strLocalIp
,
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strStream
)
{
auto
src
=
dynamic_pointer_cast
<
RtspMediaSource
>
(
MediaSource
::
find
(
RTSP_SCHEMA
,
strVhost
,
strApp
,
strStream
));
if
(
!
src
){
auto
strErr
=
StrPrinter
<<
"未找到媒体源:"
<<
strVhost
<<
" "
<<
strApp
<<
" "
<<
strStream
<<
endl
;
...
...
@@ -148,22 +148,22 @@ RtpBroadCaster::RtpBroadCaster(const EventPoller::Ptr &poller,const string &strL
<<
strVhost
<<
" "
<<
strApp
<<
" "
<<
strStream
;
}
uint16_t
Rtp
Broad
Caster
::
getPort
(
TrackType
trackType
){
uint16_t
Rtp
Multi
Caster
::
getPort
(
TrackType
trackType
){
return
_apUdpSock
[
trackType
]
->
get_local_port
();
}
string
Rtp
Broad
Caster
::
getIP
(){
string
Rtp
Multi
Caster
::
getIP
(){
return
inet_ntoa
(
_aPeerUdpAddr
[
0
].
sin_addr
);
}
Rtp
BroadCaster
::
Ptr
RtpBroad
Caster
::
make
(
const
EventPoller
::
Ptr
&
poller
,
const
string
&
strLocalIp
,
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strStream
){
Rtp
MultiCaster
::
Ptr
RtpMulti
Caster
::
make
(
const
EventPoller
::
Ptr
&
poller
,
const
string
&
strLocalIp
,
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strStream
){
try
{
auto
ret
=
Ptr
(
new
Rtp
BroadCaster
(
poller
,
strLocalIp
,
strVhost
,
strApp
,
strStream
),[
poller
](
RtpBroad
Caster
*
ptr
){
auto
ret
=
Ptr
(
new
Rtp
MultiCaster
(
poller
,
strLocalIp
,
strVhost
,
strApp
,
strStream
),[
poller
](
RtpMulti
Caster
*
ptr
){
poller
->
async
([
ptr
]()
{
delete
ptr
;
});
});
lock_guard
<
recursive_mutex
>
lck
(
g_mtx
);
string
strKey
=
StrPrinter
<<
strLocalIp
<<
" "
<<
strVhost
<<
" "
<<
strApp
<<
" "
<<
strStream
<<
endl
;
weak_ptr
<
Rtp
Broad
Caster
>
weakPtr
=
ret
;
weak_ptr
<
Rtp
Multi
Caster
>
weakPtr
=
ret
;
g_mapBroadCaster
.
emplace
(
strKey
,
weakPtr
);
return
ret
;
}
catch
(
std
::
exception
&
ex
)
{
...
...
@@ -172,7 +172,7 @@ RtpBroadCaster::Ptr RtpBroadCaster::make(const EventPoller::Ptr &poller,const st
}
}
Rtp
BroadCaster
::
Ptr
RtpBroad
Caster
::
get
(
const
EventPoller
::
Ptr
&
poller
,
const
string
&
strLocalIp
,
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strStream
)
{
Rtp
MultiCaster
::
Ptr
RtpMulti
Caster
::
get
(
const
EventPoller
::
Ptr
&
poller
,
const
string
&
strLocalIp
,
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strStream
)
{
string
strKey
=
StrPrinter
<<
strLocalIp
<<
" "
<<
strVhost
<<
" "
<<
strApp
<<
" "
<<
strStream
<<
endl
;
lock_guard
<
recursive_mutex
>
lck
(
g_mtx
);
auto
it
=
g_mapBroadCaster
.
find
(
strKey
);
...
...
src/Rtsp/Rtp
Broad
Caster.h
→
src/Rtsp/Rtp
Multi
Caster.h
查看文件 @
c6e9f836
...
...
@@ -65,18 +65,18 @@ private:
recursive_mutex
_mtx
;
unordered_set
<
uint32_t
>
_setBadAddr
;
};
class
Rtp
Broad
Caster
{
class
Rtp
Multi
Caster
{
public
:
typedef
std
::
shared_ptr
<
Rtp
Broad
Caster
>
Ptr
;
typedef
std
::
shared_ptr
<
Rtp
Multi
Caster
>
Ptr
;
typedef
function
<
void
()
>
onDetach
;
virtual
~
Rtp
Broad
Caster
();
virtual
~
Rtp
Multi
Caster
();
static
Ptr
get
(
const
EventPoller
::
Ptr
&
poller
,
const
string
&
strLocalIp
,
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strStream
);
void
setDetachCB
(
void
*
listener
,
const
onDetach
&
cb
);
uint16_t
getPort
(
TrackType
trackType
);
string
getIP
();
private
:
static
recursive_mutex
g_mtx
;
static
unordered_map
<
string
,
weak_ptr
<
Rtp
Broad
Caster
>
>
g_mapBroadCaster
;
static
unordered_map
<
string
,
weak_ptr
<
Rtp
Multi
Caster
>
>
g_mapBroadCaster
;
static
Ptr
make
(
const
EventPoller
::
Ptr
&
poller
,
const
string
&
strLocalIp
,
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strStream
);
std
::
shared_ptr
<
uint32_t
>
_multiAddr
;
...
...
@@ -86,7 +86,7 @@ private:
Socket
::
Ptr
_apUdpSock
[
2
];
struct
sockaddr_in
_aPeerUdpAddr
[
2
];
Rtp
Broad
Caster
(
const
EventPoller
::
Ptr
&
poller
,
const
string
&
strLocalIp
,
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strStream
);
Rtp
Multi
Caster
(
const
EventPoller
::
Ptr
&
poller
,
const
string
&
strLocalIp
,
const
string
&
strVhost
,
const
string
&
strApp
,
const
string
&
strStream
);
};
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
c6e9f836
...
...
@@ -673,14 +673,14 @@ void RtspSession::handleReq_Setup(const Parser &parser) {
}
break
;
case
Rtsp
:
:
RTP_MULTICAST
:
{
if
(
!
_
pBrd
caster
){
_
pBrdcaster
=
RtpBroad
Caster
::
get
(
getPoller
(),
get_local_ip
(),
_mediaInfo
.
_vhost
,
_mediaInfo
.
_app
,
_mediaInfo
.
_streamid
);
if
(
!
_
pBrd
caster
)
{
if
(
!
_
multi
caster
){
_
multicaster
=
RtpMulti
Caster
::
get
(
getPoller
(),
get_local_ip
(),
_mediaInfo
.
_vhost
,
_mediaInfo
.
_app
,
_mediaInfo
.
_streamid
);
if
(
!
_
multi
caster
)
{
send_NotAcceptable
();
throw
SockException
(
Err_shutdown
,
"can not get a available udp multicast socket"
);
}
weak_ptr
<
RtspSession
>
weakSelf
=
dynamic_pointer_cast
<
RtspSession
>
(
shared_from_this
());
_
pBrd
caster
->
setDetachCB
(
this
,
[
weakSelf
]()
{
_
multi
caster
->
setDetachCB
(
this
,
[
weakSelf
]()
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
return
;
...
...
@@ -688,7 +688,7 @@ void RtspSession::handleReq_Setup(const Parser &parser) {
strongSelf
->
safeShutdown
(
SockException
(
Err_shutdown
,
"ring buffer detached"
));
});
}
int
iSrvPort
=
_
pBrd
caster
->
getPort
(
trackRef
->
_type
);
int
iSrvPort
=
_
multi
caster
->
getPort
(
trackRef
->
_type
);
//我们用trackIdx区分rtp和rtcp包
//由于组播udp端口是共享的,而rtcp端口为组播udp端口+1,所以rtcp端口需要改成共享端口
auto
pSockRtcp
=
UDPServer
::
Instance
().
getSock
(
getPoller
(),
get_local_ip
().
data
(),
2
*
trackIdx
+
1
,
iSrvPort
+
1
);
...
...
@@ -702,7 +702,7 @@ void RtspSession::handleReq_Setup(const Parser &parser) {
sendRtspResponse
(
"200 OK"
,
{
"Transport"
,
StrPrinter
<<
"RTP/AVP;multicast;"
<<
"destination="
<<
_
pBrd
caster
->
getIP
()
<<
";"
<<
"destination="
<<
_
multi
caster
->
getIP
()
<<
";"
<<
"source="
<<
get_local_ip
()
<<
";"
<<
"port="
<<
iSrvPort
<<
"-"
<<
pSockRtcp
->
get_local_port
()
<<
";"
<<
"ttl="
<<
udpTTL
<<
";"
...
...
src/Rtsp/RtspSession.h
查看文件 @
c6e9f836
...
...
@@ -36,7 +36,7 @@
#include "Common/config.h"
#include "Network/TcpSession.h"
#include "Player/PlayerBase.h"
#include "Rtp
Broad
Caster.h"
#include "Rtp
Multi
Caster.h"
#include "RtspMediaSource.h"
#include "RtspSplitter.h"
#include "RtpReceiver.h"
...
...
@@ -213,7 +213,7 @@ private:
unordered_set
<
int
>
_udpSockConnected
;
////////RTP over udp_multicast////////
//共享的rtp组播对象
Rtp
BroadCaster
::
Ptr
_pBrd
caster
;
Rtp
MultiCaster
::
Ptr
_multi
caster
;
//登录认证
string
_strNonce
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论