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
c98e85ca
Commit
c98e85ca
authored
Oct 13, 2021
by
Johnny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加 RtcpContextForSend/RtcpContextForRecv作为RtcpContext子类
parent
290b3f37
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
52 行增加
和
42 行删除
+52
-42
src/Rtcp/RtcpContext.cpp
+25
-21
src/Rtcp/RtcpContext.h
+19
-13
src/Rtp/RtpServer.cpp
+2
-2
src/Rtsp/RtspPlayer.cpp
+1
-1
src/Rtsp/RtspPusher.cpp
+1
-1
src/Rtsp/RtspSession.cpp
+2
-2
webrtc/WebRtcTransport.cpp
+2
-2
没有找到文件。
src/Rtcp/RtcpContext.cpp
查看文件 @
c98e85ca
...
...
@@ -14,12 +14,16 @@ using namespace toolkit;
namespace
mediakit
{
RtcpContext
::
RtcpContext
(
bool
is_receiver
)
{
_is_receiver
=
is_receiver
;
}
void
RtcpContext
::
onRtp
(
uint16_t
seq
,
uint32_t
stamp
,
uint64_t
ntp_stamp_ms
,
uint32_t
sample_rate
,
size_t
bytes
)
{
if
(
_is_receiver
)
{
++
_packets
;
_bytes
+=
bytes
;
_last_rtp_stamp
=
stamp
;
_last_ntp_stamp_ms
=
ntp_stamp_ms
;
}
void
RtcpContextForRecv
::
onRtp
(
uint16_t
seq
,
uint32_t
stamp
,
uint64_t
ntp_stamp_ms
,
uint32_t
sample_rate
,
size_t
bytes
)
{
{
//接收者才做复杂的统计运算
auto
sys_stamp
=
getCurrentMillisecond
();
if
(
_last_rtp_sys_stamp
)
{
...
...
@@ -57,11 +61,7 @@ void RtcpContext::onRtp(uint16_t seq, uint32_t stamp, uint64_t ntp_stamp_ms, uin
_last_rtp_seq
=
seq
;
_last_rtp_sys_stamp
=
sys_stamp
;
}
++
_packets
;
_bytes
+=
bytes
;
_last_rtp_stamp
=
stamp
;
_last_ntp_stamp_ms
=
ntp_stamp_ms
;
RtcpContext
::
onRtp
(
seq
,
stamp
,
ntp_stamp_ms
,
sample_rate
,
bytes
);
}
void
RtcpContext
::
onRtcp
(
RtcpHeader
*
rtcp
)
{
...
...
@@ -115,9 +115,9 @@ uint32_t RtcpContext::getRtt(uint32_t ssrc) const {
}
size_t
RtcpContext
::
getExpectedPackets
()
const
{
if
(
!
_is_receiver
)
{
throw
std
::
runtime_error
(
"rtp发送者无法统计应收包数"
);
}
throw
std
::
runtime_error
(
"没有实现, rtp发送者无法统计应收包数"
);
}
size_t
RtcpContextForRecv
::
getExpectedPackets
()
const
{
return
(
_seq_cycles
<<
16
)
+
_seq_max
-
_seq_base
+
1
;
}
...
...
@@ -129,9 +129,10 @@ size_t RtcpContext::getExpectedPacketsInterval() {
}
size_t
RtcpContext
::
getLost
()
{
if
(
!
_is_receiver
)
{
throw
std
::
runtime_error
(
"rtp发送者无法统计丢包率"
);
}
throw
std
::
runtime_error
(
"没有实现, rtp发送者无法统计丢包率"
);
}
size_t
RtcpContextForRecv
::
getLost
()
{
return
getExpectedPackets
()
-
_packets
;
}
...
...
@@ -143,9 +144,10 @@ size_t RtcpContext::geLostInterval() {
}
Buffer
::
Ptr
RtcpContext
::
createRtcpSR
(
uint32_t
rtcp_ssrc
)
{
if
(
_is_receiver
)
{
throw
std
::
runtime_error
(
"rtp接收者尝试发送sr包"
);
}
throw
std
::
runtime_error
(
"没有实现, rtp接收者尝试发送sr包"
);
}
Buffer
::
Ptr
RtcpContextForSend
::
createRtcpSR
(
uint32_t
rtcp_ssrc
)
{
auto
rtcp
=
RtcpSR
::
create
(
0
);
rtcp
->
setNtpStamp
(
_last_ntp_stamp_ms
);
rtcp
->
rtpts
=
htonl
(
_last_rtp_stamp
);
...
...
@@ -165,9 +167,11 @@ Buffer::Ptr RtcpContext::createRtcpSR(uint32_t rtcp_ssrc) {
}
Buffer
::
Ptr
RtcpContext
::
createRtcpRR
(
uint32_t
rtcp_ssrc
,
uint32_t
rtp_ssrc
)
{
if
(
!
_is_receiver
)
{
throw
std
::
runtime_error
(
"rtp发送者尝试发送rr包"
);
}
throw
std
::
runtime_error
(
"没有实现, rtp发送者尝试发送rr包"
);
}
Buffer
::
Ptr
RtcpContextForRecv
::
createRtcpRR
(
uint32_t
rtcp_ssrc
,
uint32_t
rtp_ssrc
)
{
auto
rtcp
=
RtcpRR
::
create
(
1
);
rtcp
->
ssrc
=
htonl
(
rtcp_ssrc
);
...
...
src/Rtcp/RtcpContext.h
查看文件 @
c98e85ca
...
...
@@ -20,11 +20,7 @@ namespace mediakit {
class
RtcpContext
{
public
:
using
Ptr
=
std
::
shared_ptr
<
RtcpContext
>
;
/**
* 创建rtcp上下文
* @param is_receiver 是否为rtp接收者,接收者更消耗性能
*/
RtcpContext
(
bool
is_receiver
);
virtual
~
RtcpContext
()
=
default
;
/**
* 输出或输入rtp时调用
...
...
@@ -34,7 +30,7 @@ public:
* @param rtp rtp时间戳采样率,视频一般为90000,音频一般为采样率
* @param bytes rtp数据长度
*/
void
onRtp
(
uint16_t
seq
,
uint32_t
stamp
,
uint64_t
ntp_stamp_ms
,
uint32_t
sample_rate
,
size_t
bytes
);
v
irtual
v
oid
onRtp
(
uint16_t
seq
,
uint32_t
stamp
,
uint64_t
ntp_stamp_ms
,
uint32_t
sample_rate
,
size_t
bytes
);
/**
* 输入sr rtcp包
...
...
@@ -45,19 +41,19 @@ public:
/**
* 计算总丢包数
*/
size_t
getLost
();
virtual
size_t
getLost
();
/**
* 返回理应收到的rtp数
*/
size_t
getExpectedPackets
()
const
;
virtual
size_t
getExpectedPackets
()
const
;
/**
* 创建SR rtcp包
* @param rtcp_ssrc rtcp的ssrc
* @return rtcp包
*/
Buffer
::
Ptr
createRtcpSR
(
uint32_t
rtcp_ssrc
);
virtual
Buffer
::
Ptr
createRtcpSR
(
uint32_t
rtcp_ssrc
);
/**
* 创建RR rtcp包
...
...
@@ -65,7 +61,7 @@ public:
* @param rtp_ssrc rtp的ssrc
* @return rtcp包
*/
Buffer
::
Ptr
createRtcpRR
(
uint32_t
rtcp_ssrc
,
uint32_t
rtp_ssrc
);
virtual
Buffer
::
Ptr
createRtcpRR
(
uint32_t
rtcp_ssrc
,
uint32_t
rtp_ssrc
);
/**
* 获取rtt
...
...
@@ -84,9 +80,7 @@ public:
*/
size_t
geLostInterval
();
private
:
//是否为接收者
bool
_is_receiver
;
protected
:
//时间戳抖动值
double
_jitter
=
0
;
//收到或发送的rtp的字节数
...
...
@@ -120,5 +114,17 @@ private:
map
<
uint32_t
/*last_sr_lsr*/
,
uint64_t
/*ntp stamp*/
>
_sender_report_ntp
;
};
class
RtcpContextForSend
:
public
RtcpContext
{
public
:
Buffer
::
Ptr
createRtcpSR
(
uint32_t
rtcp_ssrc
)
override
;
};
class
RtcpContextForRecv
:
public
RtcpContext
{
public
:
void
onRtp
(
uint16_t
seq
,
uint32_t
stamp
,
uint64_t
ntp_stamp_ms
,
uint32_t
sample_rate
,
size_t
bytes
)
override
;
Buffer
::
Ptr
createRtcpRR
(
uint32_t
rtcp_ssrc
,
uint32_t
rtp_ssrc
)
override
;
size_t
getExpectedPackets
()
const
override
;
size_t
getLost
()
override
;
};
}
//namespace mediakit
#endif //ZLMEDIAKIT_RTCPCONTEXT_H
src/Rtp/RtpServer.cpp
查看文件 @
c98e85ca
...
...
@@ -23,11 +23,11 @@ RtpServer::~RtpServer() {
}
}
class
RtcpHelper
:
public
RtcpContext
,
public
std
::
enable_shared_from_this
<
RtcpHelper
>
{
class
RtcpHelper
:
public
RtcpContext
ForRecv
,
public
std
::
enable_shared_from_this
<
RtcpHelper
>
{
public
:
using
Ptr
=
std
::
shared_ptr
<
RtcpHelper
>
;
RtcpHelper
(
Socket
::
Ptr
rtcp_sock
,
uint32_t
sample_rate
)
:
RtcpContext
(
true
)
{
RtcpHelper
(
Socket
::
Ptr
rtcp_sock
,
uint32_t
sample_rate
)
{
_rtcp_sock
=
std
::
move
(
rtcp_sock
);
_sample_rate
=
sample_rate
;
}
...
...
src/Rtsp/RtspPlayer.cpp
查看文件 @
c98e85ca
...
...
@@ -206,7 +206,7 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) {
}
_rtcp_context
.
clear
();
for
(
auto
&
track
:
_sdp_track
)
{
_rtcp_context
.
emplace_back
(
std
::
make_shared
<
RtcpContext
>
(
true
));
_rtcp_context
.
emplace_back
(
std
::
make_shared
<
RtcpContext
ForRecv
>
(
));
}
sendSetup
(
0
);
}
...
...
src/Rtsp/RtspPusher.cpp
查看文件 @
c98e85ca
...
...
@@ -179,7 +179,7 @@ void RtspPusher::sendAnnounce() {
}
_rtcp_context
.
clear
();
for
(
auto
&
track
:
_track_vec
)
{
_rtcp_context
.
emplace_back
(
std
::
make_shared
<
RtcpContext
>
(
false
));
_rtcp_context
.
emplace_back
(
std
::
make_shared
<
RtcpContext
ForSend
>
(
));
}
_on_res_func
=
std
::
bind
(
&
RtspPusher
::
handleResAnnounce
,
this
,
placeholders
::
_1
);
sendRtspRequest
(
"ANNOUNCE"
,
_url
,
{},
src
->
getSdp
());
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
c98e85ca
...
...
@@ -257,7 +257,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
}
_rtcp_context
.
clear
();
for
(
auto
&
track
:
_sdp_track
)
{
_rtcp_context
.
emplace_back
(
std
::
make_shared
<
RtcpContext
>
(
true
));
_rtcp_context
.
emplace_back
(
std
::
make_shared
<
RtcpContext
ForRecv
>
(
));
}
_push_src
=
std
::
make_shared
<
RtspMediaSourceImp
>
(
_media_info
.
_vhost
,
_media_info
.
_app
,
_media_info
.
_streamid
);
_push_src
->
setListener
(
dynamic_pointer_cast
<
MediaSourceEvent
>
(
shared_from_this
()));
...
...
@@ -418,7 +418,7 @@ void RtspSession::onAuthSuccess() {
}
strongSelf
->
_rtcp_context
.
clear
();
for
(
auto
&
track
:
strongSelf
->
_sdp_track
)
{
strongSelf
->
_rtcp_context
.
emplace_back
(
std
::
make_shared
<
RtcpContext
>
(
false
));
strongSelf
->
_rtcp_context
.
emplace_back
(
std
::
make_shared
<
RtcpContext
ForSend
>
(
));
}
strongSelf
->
_sessionid
=
makeRandStr
(
12
);
strongSelf
->
_play_src
=
rtsp_src
;
...
...
webrtc/WebRtcTransport.cpp
查看文件 @
c98e85ca
...
...
@@ -420,7 +420,7 @@ void WebRtcTransportImp::onStartWebRTC() {
track
->
offer_ssrc_rtx
=
m_offer
->
getRtxSSRC
();
track
->
plan_rtp
=
&
m_answer
.
plan
[
0
];;
track
->
plan_rtx
=
m_answer
.
getRelatedRtxPlan
(
track
->
plan_rtp
->
pt
);
track
->
rtcp_context_send
=
std
::
make_shared
<
RtcpContext
>
(
false
);
track
->
rtcp_context_send
=
std
::
make_shared
<
RtcpContext
ForSend
>
(
);
//send ssrc --> MediaTrack
_ssrc_to_track
[
track
->
answer_ssrc_rtp
]
=
track
;
...
...
@@ -656,7 +656,7 @@ private:
private
:
NackContext
_nack_ctx
;
RtcpContext
_rtcp_context
{
true
}
;
RtcpContext
ForRecv
_rtcp_context
;
EventPoller
::
Ptr
_poller
;
DelayTask
::
Ptr
_delay_task
;
function
<
void
(
const
FCI_NACK
&
nack
)
>
_on_nack
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论