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
28b8e8e0
Commit
28b8e8e0
authored
Jan 30, 2018
by
771730766@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
大幅优化RTSP服务器性能
parent
25551ef3
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
36 行增加
和
9 行删除
+36
-9
src/Rtsp/RtpBroadCaster.cpp
+4
-1
src/Rtsp/RtspPlayer.cpp
+1
-1
src/Rtsp/RtspSession.cpp
+8
-5
src/Rtsp/RtspSession.h
+22
-1
tests/test_server.cpp
+1
-1
没有找到文件。
src/Rtsp/RtpBroadCaster.cpp
查看文件 @
28b8e8e0
...
...
@@ -29,6 +29,8 @@
#include "RtpBroadCaster.h"
#include "Util/util.h"
#include "Network/sockutil.h"
#include "RtspSession.h"
using
namespace
std
;
namespace
ZL
{
...
...
@@ -112,7 +114,8 @@ RtpBroadCaster::RtpBroadCaster(const string &strLocalIp,const string &strApp,con
int
i
=
(
pkt
->
interleaved
/
2
)
%
2
;
auto
&
pSock
=
m_apUdpSock
[
i
];
auto
&
peerAddr
=
m_aPeerUdpAddr
[
i
];
pSock
->
sendTo
((
char
*
)
pkt
->
payload
+
4
,
pkt
->
length
-
4
,(
struct
sockaddr
*
)(
&
peerAddr
));
BufferRtp
::
Ptr
buffer
(
new
BufferRtp
(
pkt
,
4
));
pSock
->
send
(
buffer
,
SOCKET_DEFAULE_FLAGS
,(
struct
sockaddr
*
)(
&
peerAddr
));
});
m_pReader
->
setDetachCB
([
this
](){
unordered_map
<
void
*
,
onDetach
>
m_mapDetach_copy
;
...
...
src/Rtsp/RtspPlayer.cpp
查看文件 @
28b8e8e0
...
...
@@ -346,7 +346,7 @@ void RtspPlayer::HandleResSETUP(const Parser& parser, unsigned int uiTrackIndex)
rtpto
.
sin_port
=
ntohs
(
port
);
rtpto
.
sin_family
=
AF_INET
;
rtpto
.
sin_addr
.
s_addr
=
inet_addr
(
get_peer_ip
().
c_str
());
pUdpSockRef
->
send
To
(
"
\xce\xfa\xed\xfe
"
,
4
,
(
struct
sockaddr
*
)
&
rtpto
);
pUdpSockRef
->
send
(
"
\xce\xfa\xed\xfe
"
,
4
,
SOCKET_DEFAULE_FLAGS
,
(
struct
sockaddr
*
)
&
rtpto
);
}
}
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
28b8e8e0
...
...
@@ -664,7 +664,7 @@ bool RtspSession::handleReq_Play() {
if
(
!
strongSelf
)
{
return
;
}
strongSelf
->
sendRtpPacket
(
*
pack
);
strongSelf
->
sendRtpPacket
(
pack
);
});
});
...
...
@@ -848,11 +848,13 @@ inline bool RtspSession::findStream() {
return
true
;
}
inline
void
RtspSession
::
sendRtpPacket
(
const
RtpPacket
&
pkt
)
{
inline
void
RtspSession
::
sendRtpPacket
(
const
RtpPacket
::
Ptr
&
pkt
)
{
//InfoL<<(int)pkt.Interleaved;
switch
(
m_rtpType
)
{
case
PlayerBase
:
:
RTP_TCP
:
{
send
((
char
*
)
pkt
.
payload
,
pkt
.
length
);
BufferRtp
::
Ptr
buffer
(
new
BufferRtp
(
pkt
));
send
(
buffer
);
#ifdef RTSP_SEND_RTCP
int
iTrackIndex
=
getTrackIndexByTrackId
(
pkt
.
interleaved
/
2
);
RtcpCounter
&
counter
=
m_aRtcpCnt
[
iTrackIndex
];
...
...
@@ -869,7 +871,7 @@ inline void RtspSession::sendRtpPacket(const RtpPacket& pkt) {
}
break
;
case
PlayerBase
:
:
RTP_UDP
:
{
int
iTrackIndex
=
getTrackIndexByTrackId
(
pkt
.
interleaved
/
2
);
int
iTrackIndex
=
getTrackIndexByTrackId
(
pkt
->
interleaved
/
2
);
auto
pSock
=
m_apUdpSock
[
iTrackIndex
].
lock
();
if
(
!
pSock
)
{
shutdown
();
...
...
@@ -879,7 +881,8 @@ inline void RtspSession::sendRtpPacket(const RtpPacket& pkt) {
if
(
!
peerAddr
)
{
return
;
}
pSock
->
sendTo
((
char
*
)
pkt
.
payload
+
4
,
pkt
.
length
-
4
,
peerAddr
.
get
());
BufferRtp
::
Ptr
buffer
(
new
BufferRtp
(
pkt
,
4
));
pSock
->
send
(
buffer
,
SOCKET_DEFAULE_FLAGS
,
peerAddr
.
get
());
}
break
;
default
:
...
...
src/Rtsp/RtspSession.h
查看文件 @
28b8e8e0
...
...
@@ -49,6 +49,24 @@ namespace ZL {
namespace
Rtsp
{
class
RtspSession
;
class
BufferRtp
:
public
Socket
::
Buffer
{
public
:
typedef
std
::
shared_ptr
<
BufferRtp
>
Ptr
;
BufferRtp
(
const
RtpPacket
::
Ptr
&
pkt
,
uint32_t
offset
=
0
)
:
_rtp
(
pkt
),
_offset
(
offset
){}
virtual
~
BufferRtp
(){}
char
*
data
()
override
{
return
(
char
*
)
_rtp
->
payload
+
_offset
;
}
uint32_t
size
()
const
override
{
return
_rtp
->
length
-
_offset
;
}
private
:
RtpPacket
::
Ptr
_rtp
;
uint32_t
_offset
;
};
class
RtspSession
:
public
TcpLimitedSession
<
MAX_TCP_SESSION
>
{
public
:
typedef
std
::
shared_ptr
<
RtspSession
>
Ptr
;
...
...
@@ -73,6 +91,9 @@ private:
int
send
(
const
char
*
pcBuf
,
int
iSize
)
override
{
return
m_pSender
->
send
(
pcBuf
,
iSize
);
}
int
send
(
const
Socket
::
Buffer
::
Ptr
&
pkt
){
return
m_pSender
->
send
(
pkt
);
}
void
shutdown
()
override
;
bool
handleReq_Options
();
//处理options方法
bool
handleReq_Describe
();
//处理describe方法
...
...
@@ -92,7 +113,7 @@ private:
inline
bool
findStream
();
//根据rtsp url查找 MediaSource实例
inline
void
initSender
(
const
std
::
shared_ptr
<
RtspSession
>
&
pSession
);
//处理rtsp over http,quicktime使用的
inline
void
sendRtpPacket
(
const
RtpPacket
&
pkt
);
inline
void
sendRtpPacket
(
const
RtpPacket
::
Ptr
&
pkt
);
inline
string
printSSRC
(
uint32_t
ui32Ssrc
)
{
char
tmp
[
9
]
=
{
0
};
ui32Ssrc
=
htonl
(
ui32Ssrc
);
...
...
tests/test_server.cpp
查看文件 @
28b8e8e0
...
...
@@ -162,7 +162,7 @@ int main(int argc,char *argv[]){
//输入用户名和密码登录(user:test,pwd:123456),输入help命令查看帮助
TcpServer
<
ShellSession
>::
Ptr
shellSrv
(
new
TcpServer
<
ShellSession
>
());
ShellSession
::
addUser
(
"test"
,
"123456"
);
shellSrv
->
start
(
8023
);
shellSrv
->
start
(
mINI
::
Instance
()[
Config
::
Shell
::
kPort
]
);
//开启rtsp/rtmp/http服务器
TcpServer
<
RtspSession
>::
Ptr
rtspSrv
(
new
TcpServer
<
RtspSession
>
());
TcpServer
<
RtmpSession
>::
Ptr
rtmpSrv
(
new
TcpServer
<
RtmpSession
>
());
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论