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
bceff734
Commit
bceff734
authored
May 08, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rtsp服务器支持发送rtcp包
parent
dc676657
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
65 行增加
和
55 行删除
+65
-55
src/Rtsp/Rtsp.h
+1
-0
src/Rtsp/RtspSession.cpp
+61
-54
src/Rtsp/RtspSession.h
+3
-1
没有找到文件。
src/Rtsp/Rtsp.h
查看文件 @
bceff734
...
...
@@ -111,6 +111,7 @@ class RtcpCounter {
public
:
uint32_t
pktCnt
=
0
;
uint32_t
octCount
=
0
;
//网络字节序
uint32_t
timeStamp
=
0
;
};
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
bceff734
...
...
@@ -976,44 +976,6 @@ inline bool RtspSession::findStream() {
}
inline
void
RtspSession
::
sendRtpPacket
(
const
RtpPacket
::
Ptr
&
pkt
)
{
//InfoL<<(int)pkt.Interleaved;
switch
(
_rtpType
)
{
case
Rtsp
:
:
RTP_TCP
:
{
BufferRtp
::
Ptr
buffer
(
new
BufferRtp
(
pkt
));
send
(
buffer
);
#ifdef RTSP_SEND_RTCP
int
iTrackIndex
=
getTrackIndexByTrackId
(
pkt
.
interleaved
/
2
);
RtcpCounter
&
counter
=
_aRtcpCnt
[
iTrackIndex
];
counter
.
pktCnt
+=
1
;
counter
.
octCount
+=
(
pkt
.
length
-
12
);
auto
&
_ticker
=
_aRtcpTicker
[
iTrackIndex
];
if
(
_ticker
.
elapsedTime
()
>
5
*
1000
)
{
//send rtcp every 5 second
_ticker
.
resetTime
();
counter
.
timeStamp
=
pkt
.
timeStamp
;
sendRTCP
();
}
#endif
}
break
;
case
Rtsp
:
:
RTP_UDP
:
{
int
iTrackIndex
=
getTrackIndexByTrackType
(
pkt
->
type
);
auto
&
pSock
=
_apRtpSock
[
iTrackIndex
];
if
(
!
pSock
)
{
shutdown
();
return
;
}
BufferRtp
::
Ptr
buffer
(
new
BufferRtp
(
pkt
,
4
));
_ui64TotalBytes
+=
buffer
->
size
();
pSock
->
send
(
buffer
);
}
break
;
default
:
break
;
}
}
void
RtspSession
::
onRtpSorted
(
const
RtpPacket
::
Ptr
&
rtppt
,
int
trackidx
)
{
_pushSrc
->
onWrite
(
rtppt
,
false
);
}
...
...
@@ -1202,26 +1164,68 @@ bool RtspSession::close() {
return
true
;
}
inline
void
RtspSession
::
sendRtpPacket
(
const
RtpPacket
::
Ptr
&
pkt
)
{
//InfoL<<(int)pkt.Interleaved;
switch
(
_rtpType
)
{
case
Rtsp
:
:
RTP_TCP
:
{
BufferRtp
::
Ptr
buffer
(
new
BufferRtp
(
pkt
));
send
(
buffer
);
}
break
;
case
Rtsp
:
:
RTP_UDP
:
{
int
iTrackIndex
=
getTrackIndexByTrackType
(
pkt
->
type
);
auto
&
pSock
=
_apRtpSock
[
iTrackIndex
];
if
(
!
pSock
)
{
shutdown
();
return
;
}
BufferRtp
::
Ptr
buffer
(
new
BufferRtp
(
pkt
,
4
));
_ui64TotalBytes
+=
buffer
->
size
();
pSock
->
send
(
buffer
);
}
break
;
default
:
break
;
}
#ifdef RTSP_SEND_RTCP
int
iTrackIndex
=
getTrackIndexByInterleaved
(
pkt
->
interleaved
);
if
(
iTrackIndex
==
-
1
){
return
;
}
RtcpCounter
&
counter
=
_aRtcpCnt
[
iTrackIndex
];
counter
.
pktCnt
+=
1
;
counter
.
octCount
+=
(
pkt
->
length
-
pkt
->
offset
);
auto
&
ticker
=
_aRtcpTicker
[
iTrackIndex
];
if
(
ticker
.
elapsedTime
()
>
5
*
1000
)
{
//send rtcp every 5 second
ticker
.
resetTime
();
//直接保存网络字节序
memcpy
(
&
counter
.
timeStamp
,
pkt
->
payload
+
8
,
4
);
sendSenderReport
(
_rtpType
==
Rtsp
::
RTP_TCP
,
iTrackIndex
);
}
#endif
}
#ifdef RTSP_SEND_RTCP
inline
void
RtspSession
::
sendRTCP
()
{
//DebugL;
uint8_t
aui8Rtcp
[
60
]
=
{
0
};
inline
void
RtspSession
::
sendSenderReport
(
bool
overTcp
,
int
iTrackIndex
)
{
uint8_t
aui8Rtcp
[
4
+
28
+
10
+
sizeof
(
SERVER_NAME
)
+
1
]
=
{
0
};
uint8_t
*
pui8Rtcp_SR
=
aui8Rtcp
+
4
,
*
pui8Rtcp_SDES
=
pui8Rtcp_SR
+
28
;
for
(
uint8_t
i
=
0
;
i
<
_uiTrackCnt
;
i
++
)
{
auto
&
track
=
_aTrackInfo
[
i
];
auto
&
counter
=
_aRtcpCnt
[
i
];
auto
&
track
=
_aTrackInfo
[
iTrackIndex
];
auto
&
counter
=
_aRtcpCnt
[
iTrackIndex
];
aui8Rtcp
[
0
]
=
'$'
;
aui8Rtcp
[
1
]
=
track
.
trackId
*
2
+
1
;
aui8Rtcp
[
2
]
=
56
/
256
;
aui8Rtcp
[
3
]
=
56
%
256
;
aui8Rtcp
[
1
]
=
track
->
_interleaved
+
1
;
aui8Rtcp
[
2
]
=
(
sizeof
(
aui8Rtcp
)
-
4
)
/
256
;
aui8Rtcp
[
3
]
=
(
sizeof
(
aui8Rtcp
)
-
4
)
%
256
;
pui8Rtcp_SR
[
0
]
=
0x80
;
pui8Rtcp_SR
[
1
]
=
0xC8
;
pui8Rtcp_SR
[
2
]
=
0x00
;
pui8Rtcp_SR
[
3
]
=
0x06
;
uint32_t
ssrc
=
htonl
(
track
.
ssrc
);
uint32_t
ssrc
=
htonl
(
track
->
_
ssrc
);
memcpy
(
&
pui8Rtcp_SR
[
4
],
&
ssrc
,
4
);
uint64_t
msw
;
...
...
@@ -1236,9 +1240,8 @@ inline void RtspSession::sendRTCP() {
lsw
=
htonl
(
lsw
);
memcpy
(
&
pui8Rtcp_SR
[
12
],
&
lsw
,
4
);
uint32_t
rtpStamp
=
htonl
(
counter
.
timeStamp
);
memcpy
(
&
pui8Rtcp_SR
[
16
],
&
rtpStamp
,
4
);
//直接使用网络字节序
memcpy
(
&
pui8Rtcp_SR
[
16
],
&
counter
.
timeStamp
,
4
);
uint32_t
pktCnt
=
htonl
(
counter
.
pktCnt
);
memcpy
(
&
pui8Rtcp_SR
[
20
],
&
pktCnt
,
4
);
...
...
@@ -1255,9 +1258,13 @@ inline void RtspSession::sendRTCP() {
pui8Rtcp_SDES
[
8
]
=
0x01
;
pui8Rtcp_SDES
[
9
]
=
0x0f
;
memcpy
(
&
pui8Rtcp_SDES
[
10
],
"_ZL_RtspServer_"
,
15
);
pui8Rtcp_SDES
[
25
]
=
0x00
;
send
((
char
*
)
aui8Rtcp
,
60
);
memcpy
(
&
pui8Rtcp_SDES
[
10
],
SERVER_NAME
,
sizeof
(
SERVER_NAME
));
pui8Rtcp_SDES
[
10
+
sizeof
(
SERVER_NAME
)]
=
0x00
;
if
(
overTcp
){
send
(
obtainBuffer
((
char
*
)
aui8Rtcp
,
sizeof
(
aui8Rtcp
)));
}
else
{
_apRtcpSock
[
iTrackIndex
]
->
send
((
char
*
)
aui8Rtcp
+
4
,
sizeof
(
aui8Rtcp
)
-
4
);
}
}
#endif
...
...
src/Rtsp/RtspSession.h
查看文件 @
bceff734
...
...
@@ -46,6 +46,8 @@
using
namespace
std
;
using
namespace
toolkit
;
#define RTSP_SEND_RTCP
namespace
mediakit
{
class
RtspSession
;
...
...
@@ -201,7 +203,7 @@ private:
#ifdef RTSP_SEND_RTCP
RtcpCounter
_aRtcpCnt
[
2
];
//rtcp统计,trackid idx 为数组下标
Ticker
_aRtcpTicker
[
2
];
//rtcp发送时间,trackid idx 为数组下标
inline
void
send
RTCP
(
);
inline
void
send
SenderReport
(
bool
overTcp
,
int
iTrackIndex
);
#endif
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论