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
c5cfbce2
Commit
c5cfbce2
authored
Feb 05, 2021
by
xia-chu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化rtp性能
parent
b0e1d5d6
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
45 行增加
和
31 行删除
+45
-31
src/Rtp/GB28181Process.cpp
+1
-1
src/Rtp/GB28181Process.h
+1
-1
src/Rtsp/RtpCodec.cpp
+1
-1
src/Rtsp/RtpCodec.h
+3
-3
src/Rtsp/RtpReceiver.cpp
+2
-6
src/Rtsp/RtpReceiver.h
+1
-4
src/Rtsp/Rtsp.cpp
+15
-0
src/Rtsp/Rtsp.h
+6
-0
src/Rtsp/RtspPlayer.cpp
+2
-2
src/Rtsp/RtspPlayer.h
+3
-3
src/Rtsp/RtspPlayerImp.h
+7
-7
src/Rtsp/RtspSession.cpp
+2
-2
src/Rtsp/RtspSession.h
+1
-1
没有找到文件。
src/Rtp/GB28181Process.cpp
查看文件 @
c5cfbce2
...
...
@@ -34,7 +34,7 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
return
handleOneRtp
(
0
,
TrackVideo
,
90000
,
(
unsigned
char
*
)
data
,
data_len
);
}
void
GB28181Process
::
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
)
{
void
GB28181Process
::
onRtpSorted
(
RtpPacket
::
Ptr
rtp
,
int
)
{
auto
pt
=
rtp
->
getHeader
()
->
pt
;
if
(
!
_rtp_decoder
)
{
switch
(
pt
)
{
...
...
src/Rtp/GB28181Process.h
查看文件 @
c5cfbce2
...
...
@@ -36,7 +36,7 @@ public:
bool
inputRtp
(
bool
,
const
char
*
data
,
size_t
data_len
)
override
;
protected
:
void
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
track_index
)
override
;
void
onRtpSorted
(
RtpPacket
::
Ptr
rtp
,
int
track_index
)
override
;
const
char
*
onSearchPacketTail
(
const
char
*
data
,
size_t
len
)
override
;
ssize_t
onRecvHeader
(
const
char
*
data
,
size_t
len
)
override
{
return
0
;
};
...
...
src/Rtsp/RtpCodec.cpp
查看文件 @
c5cfbce2
...
...
@@ -14,7 +14,7 @@ namespace mediakit{
RtpPacket
::
Ptr
RtpInfo
::
makeRtp
(
TrackType
type
,
const
void
*
data
,
size_t
len
,
bool
mark
,
uint32_t
stamp
)
{
uint16_t
payload_len
=
(
uint16_t
)
(
len
+
RtpPacket
::
kRtpHeaderSize
);
auto
rtp
=
R
esourcePoolHelper
<
RtpPacket
>::
obtainObj
();
auto
rtp
=
R
tpPacket
::
create
();
rtp
->
setCapacity
(
payload_len
+
RtpPacket
::
kRtpTcpHeaderSize
);
rtp
->
setSize
(
payload_len
+
RtpPacket
::
kRtpTcpHeaderSize
);
rtp
->
sample_rate
=
_sample_rate
;
...
...
src/Rtsp/RtpCodec.h
查看文件 @
c5cfbce2
...
...
@@ -58,9 +58,9 @@ protected:
RingType
::
Ptr
_rtpRing
;
};
class
RtpInfo
:
public
ResourcePoolHelper
<
RtpPacket
>
{
class
RtpInfo
{
public
:
typedef
std
::
shared_ptr
<
RtpInfo
>
Ptr
;
using
Ptr
=
std
::
shared_ptr
<
RtpInfo
>
;
RtpInfo
(
uint32_t
ssrc
,
size_t
mtu_size
,
uint32_t
sample_rate
,
uint8_t
pt
,
uint8_t
interleaved
)
{
if
(
ssrc
==
0
)
{
...
...
@@ -73,7 +73,7 @@ public:
_interleaved
=
interleaved
;
}
~
RtpInfo
()
override
{}
virtual
~
RtpInfo
()
{}
//返回rtp负载最大长度
size_t
getMaxSize
()
const
{
...
...
src/Rtsp/RtpReceiver.cpp
查看文件 @
c5cfbce2
...
...
@@ -19,7 +19,7 @@ RtpReceiver::RtpReceiver() {
int
index
=
0
;
for
(
auto
&
sortor
:
_rtp_sortor
)
{
sortor
.
setOnSort
([
this
,
index
](
uint16_t
seq
,
RtpPacket
::
Ptr
&
packet
)
{
onRtpSorted
(
packet
,
index
);
onRtpSorted
(
std
::
move
(
packet
)
,
index
);
});
++
index
;
}
...
...
@@ -61,7 +61,7 @@ bool RtpReceiver::handleOneRtp(int index, TrackType type, int sample_rate, uint8
return
false
;
}
auto
rtp
=
_rtp_pool
.
obtain
();
auto
rtp
=
RtpPacket
::
create
();
//需要添加4个字节的rtp over tcp头
rtp
->
setCapacity
(
RtpPacket
::
kRtpTcpHeaderSize
+
len
);
rtp
->
setSize
(
RtpPacket
::
kRtpTcpHeaderSize
+
len
);
...
...
@@ -90,10 +90,6 @@ void RtpReceiver::clear() {
}
}
void
RtpReceiver
::
setPoolSize
(
size_t
size
)
{
_rtp_pool
.
setSize
(
size
);
}
size_t
RtpReceiver
::
getJitterSize
(
int
index
)
const
{
return
_rtp_sortor
[
index
].
getJitterSize
();
}
...
...
src/Rtsp/RtpReceiver.h
查看文件 @
c5cfbce2
...
...
@@ -182,7 +182,7 @@ protected:
* @param rtp rtp数据包
* @param track_index track索引
*/
virtual
void
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
track_index
)
{}
virtual
void
onRtpSorted
(
RtpPacket
::
Ptr
rtp
,
int
track_index
)
{}
/**
* 解析出rtp但还未排序
...
...
@@ -192,7 +192,6 @@ protected:
virtual
void
onBeforeRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
track_index
)
{}
void
clear
();
void
setPoolSize
(
size_t
size
);
size_t
getJitterSize
(
int
track_index
)
const
;
size_t
getCycleCount
(
int
track_index
)
const
;
uint32_t
getSSRC
(
int
track_index
)
const
;
...
...
@@ -201,8 +200,6 @@ private:
uint32_t
_ssrc
[
2
]
=
{
0
,
0
};
//rtp排序缓存,根据seq排序
PacketSortor
<
RtpPacket
::
Ptr
>
_rtp_sortor
[
2
];
//rtp循环池
RtspMediaSource
::
PoolType
_rtp_pool
;
};
}
//namespace mediakit
...
...
src/Rtsp/Rtsp.cpp
查看文件 @
c5cfbce2
...
...
@@ -531,4 +531,18 @@ size_t RtpPacket::getPayloadSize(){
return
getHeader
()
->
getPayloadSize
(
size
()
-
kRtpTcpHeaderSize
);
}
RtpPacket
::
Ptr
RtpPacket
::
create
(){
#if 0
static ResourcePool<RtpPacket> packet_pool;
static onceToken token([]() {
packet_pool.setSize(1024);
});
auto ret = packet_pool.obtain();
ret->setSize(0);
return ret;
#else
return
Ptr
(
new
RtpPacket
);
#endif
}
}
//
namespace
mediakit
\ No newline at end of file
src/Rtsp/Rtsp.h
查看文件 @
c5cfbce2
...
...
@@ -166,6 +166,12 @@ public:
TrackType
type
;
//音频为采样率,视频一般为90000
uint32_t
sample_rate
;
static
Ptr
create
();
private
:
friend
class
ResourcePool_l
<
RtpPacket
>
;
RtpPacket
()
=
default
;
};
class
RtpPayload
{
...
...
src/Rtsp/RtspPlayer.cpp
查看文件 @
c5cfbce2
...
...
@@ -494,10 +494,10 @@ void RtspPlayer::onRtcpPacket(int track_idx, SdpTrack::Ptr &track, uint8_t *data
}
}
void
RtspPlayer
::
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtppt
,
int
trackidx
){
void
RtspPlayer
::
onRtpSorted
(
RtpPacket
::
Ptr
rtppt
,
int
trackidx
){
_stamp
[
trackidx
]
=
rtppt
->
getStampMS
();
_rtp_recv_ticker
.
resetTime
();
onRecvRTP
(
rtppt
,
_sdp_track
[
trackidx
]);
onRecvRTP
(
std
::
move
(
rtppt
)
,
_sdp_track
[
trackidx
]);
}
float
RtspPlayer
::
getPacketLossRate
(
TrackType
type
)
const
{
...
...
src/Rtsp/RtspPlayer.h
查看文件 @
c5cfbce2
...
...
@@ -33,7 +33,7 @@ using namespace toolkit;
namespace
mediakit
{
//实现了rtsp播放器协议部分的功能,及数据接收功能
class
RtspPlayer
:
public
PlayerBase
,
public
TcpClient
,
public
RtspSplitter
,
public
RtpReceiver
{
class
RtspPlayer
:
public
PlayerBase
,
public
TcpClient
,
public
RtspSplitter
,
public
RtpReceiver
{
public
:
typedef
std
::
shared_ptr
<
RtspPlayer
>
Ptr
;
...
...
@@ -48,7 +48,7 @@ public:
protected
:
//派生类回调函数
virtual
bool
onCheckSDP
(
const
string
&
sdp
)
=
0
;
virtual
void
onRecvRTP
(
const
RtpPacket
::
Ptr
&
rtp
,
const
SdpTrack
::
Ptr
&
track
)
=
0
;
virtual
void
onRecvRTP
(
RtpPacket
::
Ptr
rtp
,
const
SdpTrack
::
Ptr
&
track
)
=
0
;
uint32_t
getProgressMilliSecond
()
const
;
void
seekToMilliSecond
(
uint32_t
ms
);
...
...
@@ -70,7 +70,7 @@ protected:
* @param rtp rtp数据包
* @param track_idx track索引
*/
void
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
track_idx
)
override
;
void
onRtpSorted
(
RtpPacket
::
Ptr
rtp
,
int
track_idx
)
override
;
/**
* 解析出rtp但还未排序
...
...
src/Rtsp/RtspPlayerImp.h
查看文件 @
c5cfbce2
...
...
@@ -59,18 +59,18 @@ private:
return
true
;
}
void
onRecvRTP
(
const
RtpPacket
::
Ptr
&
rtp
,
const
SdpTrack
::
Ptr
&
track
)
override
{
if
(
_rtsp_media_src
)
{
// rtsp直接代理是无法判断该rtp是否是I帧,所以GOP缓存基本是无效的
// 为了减少内存使用,那么我们设置为一直关键帧以便清空GOP缓存
_rtsp_media_src
->
onWrite
(
rtp
,
true
);
}
void
onRecvRTP
(
RtpPacket
::
Ptr
rtp
,
const
SdpTrack
::
Ptr
&
track
)
override
{
_delegate
->
inputRtp
(
rtp
);
if
(
_max_analysis_ms
&&
_delegate
->
isInited
(
_max_analysis_ms
))
{
PlayerImp
<
RtspPlayer
,
RtspDemuxer
>::
onPlayResult
(
SockException
(
Err_success
,
"play rtsp success"
));
_max_analysis_ms
=
0
;
}
if
(
_rtsp_media_src
)
{
// rtsp直接代理是无法判断该rtp是否是I帧,所以GOP缓存基本是无效的
// 为了减少内存使用,那么我们设置为一直关键帧以便清空GOP缓存
_rtsp_media_src
->
onWrite
(
std
::
move
(
rtp
),
true
);
}
}
//在RtspPlayer中触发onPlayResult事件只是代表收到play回复了,
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
c5cfbce2
...
...
@@ -913,8 +913,8 @@ void RtspSession::send_NotAcceptable() {
sendRtspResponse
(
"406 Not Acceptable"
,{
"Connection"
,
"Close"
});
}
void
RtspSession
::
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
track_idx
)
{
_push_src
->
onWrite
(
rtp
,
false
);
void
RtspSession
::
onRtpSorted
(
RtpPacket
::
Ptr
rtp
,
int
track_idx
)
{
_push_src
->
onWrite
(
std
::
move
(
rtp
)
,
false
);
}
void
RtspSession
::
onRcvPeerUdpData
(
int
interleaved
,
const
Buffer
::
Ptr
&
buf
,
const
struct
sockaddr
&
addr
)
{
...
...
src/Rtsp/RtspSession.h
查看文件 @
c5cfbce2
...
...
@@ -79,7 +79,7 @@ protected:
ssize_t
getContentLength
(
Parser
&
parser
)
override
;
////RtpReceiver override////
void
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
track_idx
)
override
;
void
onRtpSorted
(
RtpPacket
::
Ptr
rtp
,
int
track_idx
)
override
;
void
onBeforeRtpSorted
(
const
RtpPacket
::
Ptr
&
rtp
,
int
track_index
)
override
;
///////MediaSourceEvent override///////
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论