Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
b515d37e
提交
b515d37e
authored
2月 15, 2017
作者:
José Luis Millán
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rtcp: calculate RTCP interval internally
上级
0b0ade4c
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
144 行增加
和
66 行删除
+144
-66
Peer.h
worker/include/RTC/Peer.h
+9
-3
Packet.h
worker/include/RTC/RTCP/Packet.h
+4
-0
Room.h
worker/include/RTC/Room.h
+0
-1
RtpReceiver.h
worker/include/RTC/RtpReceiver.h
+5
-1
RtpSender.h
worker/include/RTC/RtpSender.h
+14
-10
Peer.cpp
worker/src/RTC/Peer.cpp
+73
-28
Room.cpp
worker/src/RTC/Room.cpp
+0
-14
RtpReceiver.cpp
worker/src/RTC/RtpReceiver.cpp
+14
-9
RtpSender.cpp
worker/src/RTC/RtpSender.cpp
+25
-0
没有找到文件。
worker/include/RTC/Peer.h
浏览文件 @
b515d37e
...
...
@@ -13,6 +13,7 @@
#include "RTC/RTCP/Sdes.h"
#include "Channel/Request.h"
#include "Channel/Notifier.h"
#include "handles/Timer.h"
#include <string>
#include <unordered_map>
#include <vector>
...
...
@@ -23,7 +24,8 @@ namespace RTC
class
Peer
:
public
RTC
::
Transport
::
Listener
,
public
RTC
::
RtpReceiver
::
Listener
,
public
RTC
::
RtpSender
::
Listener
public
RTC
::
RtpSender
::
Listener
,
public
Timer
::
Listener
{
public
:
class
Listener
...
...
@@ -40,7 +42,6 @@ namespace RTC
virtual
void
onPeerRtcpFeedback
(
RTC
::
Peer
*
peer
,
RTC
::
RtpSender
*
rtpSender
,
RTC
::
RTCP
::
FeedbackRtpPacket
*
packet
)
=
0
;
virtual
void
onPeerRtcpSenderReport
(
RTC
::
Peer
*
peer
,
RTC
::
RtpReceiver
*
rtpReceiver
,
RTC
::
RTCP
::
SenderReport
*
report
)
=
0
;
virtual
void
onPeerRtcpSdesChunk
(
RTC
::
Peer
*
peer
,
RTC
::
RtpReceiver
*
rtpReceiver
,
RTC
::
RTCP
::
SdesChunk
*
chunk
)
=
0
;
virtual
void
onPeerRtcpCompleted
(
RTC
::
Peer
*
peer
)
=
0
;
};
private
:
...
...
@@ -64,7 +65,7 @@ namespace RTC
*/
void
AddRtpSender
(
RTC
::
RtpSender
*
rtpSender
,
std
::
string
&
peerName
,
RTC
::
RtpParameters
*
rtpParameters
);
RTC
::
RtpSender
*
GetRtpSender
(
uint32_t
ssrc
);
void
SendRtcp
();
void
SendRtcp
(
uint64_t
now
);
private
:
RTC
::
Transport
*
GetTransportFromRequest
(
Channel
::
Request
*
request
,
uint32_t
*
transportId
=
nullptr
);
...
...
@@ -87,6 +88,10 @@ namespace RTC
public
:
virtual
void
onRtpSenderClosed
(
RTC
::
RtpSender
*
rtpSender
)
override
;
/* Pure virtual methods inherited from Timer::Listener. */
public
:
virtual
void
onTimer
(
Timer
*
timer
)
override
;
public
:
// Passed by argument.
uint32_t
peerId
;
...
...
@@ -97,6 +102,7 @@ namespace RTC
Listener
*
listener
=
nullptr
;
Channel
::
Notifier
*
notifier
=
nullptr
;
// Others.
Timer
*
timer
=
nullptr
;
bool
hasCapabilities
=
false
;
RTC
::
RtpCapabilities
capabilities
;
std
::
unordered_map
<
uint32_t
,
RTC
::
Transport
*>
transports
;
...
...
worker/include/RTC/RTCP/Packet.h
浏览文件 @
b515d37e
...
...
@@ -9,6 +9,10 @@
namespace
RTC
{
namespace
RTCP
{
// Maximum interval for regular RTCP mode.
constexpr
uint16_t
MAX_VIDEO_INTERVAL_MS
=
1000
;
constexpr
uint16_t
MAX_AUDIO_INTERVAL_MS
=
5000
;
enum
class
Type
:
uint8_t
{
FIR
=
192
,
...
...
worker/include/RTC/Room.h
浏览文件 @
b515d37e
...
...
@@ -63,7 +63,6 @@ namespace RTC
virtual
void
onPeerRtcpFeedback
(
RTC
::
Peer
*
peer
,
RTC
::
RtpSender
*
rtpSender
,
RTC
::
RTCP
::
FeedbackRtpPacket
*
packet
)
override
;
virtual
void
onPeerRtcpSenderReport
(
RTC
::
Peer
*
peer
,
RTC
::
RtpReceiver
*
rtpReceiver
,
RTC
::
RTCP
::
SenderReport
*
report
)
override
;
virtual
void
onPeerRtcpSdesChunk
(
RTC
::
Peer
*
peer
,
RTC
::
RtpReceiver
*
rtpReceiver
,
RTC
::
RTCP
::
SdesChunk
*
chunk
)
override
;
virtual
void
onPeerRtcpCompleted
(
RTC
::
Peer
*
peer
)
override
;
public
:
// Passed by argument.
...
...
worker/include/RTC/RtpReceiver.h
浏览文件 @
b515d37e
...
...
@@ -7,6 +7,7 @@
#include "RTC/RtpStreamRecv.h"
#include "RTC/RTCP/ReceiverReport.h"
#include "RTC/RTCP/Feedback.h"
#include "RTC/RTCP/CompoundPacket.h"
#include "Channel/Request.h"
#include "Channel/Notifier.h"
#include <string>
...
...
@@ -49,7 +50,7 @@ namespace RTC
RTC
::
RtpParameters
*
GetParameters
();
void
ReceiveRtpPacket
(
RTC
::
RtpPacket
*
packet
);
void
ReceiveRtcpSenderReport
(
RTC
::
RTCP
::
SenderReport
*
report
);
RTC
::
RTCP
::
ReceiverReport
*
GetRtcpReceiverReport
(
);
void
GetRtcp
(
RTC
::
RTCP
::
CompoundPacket
*
packet
,
uint64_t
now
);
void
ReceiveRtcpFeedback
(
RTC
::
RTCP
::
FeedbackPsPacket
*
packet
);
void
ReceiveRtcpFeedback
(
RTC
::
RTCP
::
FeedbackRtpPacket
*
packet
);
...
...
@@ -73,6 +74,9 @@ namespace RTC
// Others.
bool
rtpRawEventEnabled
=
false
;
bool
rtpObjectEventEnabled
=
false
;
// Timestamp when last RTCP was sent.
uint64_t
lastRtcpSentTime
=
0
;
uint16_t
maxRtcpInterval
;
};
/* Inline methods. */
...
...
worker/include/RTC/RtpSender.h
浏览文件 @
b515d37e
...
...
@@ -6,9 +6,11 @@
#include "RTC/RtpStreamSend.h"
#include "RTC/RtpDictionaries.h"
#include "RTC/RtpPacket.h"
#include "RTC/RtpDataCounter.h"
#include "RTC/RTCP/SenderReport.h"
#include "RTC/RTCP/Sdes.h"
#include "RTC/RTCP/FeedbackRtpNack.h"
#include "RTC/RTCP/CompoundPacket.h"
#include "Channel/Request.h"
#include "Channel/Notifier.h"
#include <unordered_set>
...
...
@@ -48,10 +50,10 @@ namespace RTC
RTC
::
RtpParameters
*
GetParameters
();
void
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
);
void
ReceiveRtcpSenderReport
(
RTC
::
RTCP
::
SenderReport
*
report
);
RTC
::
RTCP
::
SenderReport
*
GetRtcpSenderReport
();
void
ReceiveRtcpSdesChunk
(
RTC
::
RTCP
::
SdesChunk
*
chunk
);
RTC
::
RTCP
::
SdesChunk
*
GetRtcpSdesChunk
(
);
void
GetRtcp
(
RTC
::
RTCP
::
CompoundPacket
*
packet
,
uint64_t
now
);
void
ReceiveNack
(
RTC
::
RTCP
::
FeedbackRtpNackPacket
*
nackPacket
);
uint32_t
GetTransmissionRate
(
uint64_t
now
);
private
:
void
RetransmitRtpPacket
(
RTC
::
RtpPacket
*
packet
);
...
...
@@ -77,6 +79,14 @@ namespace RTC
// Sender Report holding the RTP stats.
std
::
unique_ptr
<
RTC
::
RTCP
::
SenderReport
>
senderReport
;
std
::
unique_ptr
<
RTC
::
RTCP
::
SdesChunk
>
sdesChunk
;
// RTP counters.
RTC
::
RtpDataCounter
transmitted
;
// Timestamp when last RTCP was sent.
uint64_t
lastRtcpSentTime
=
0
;
uint16_t
maxRtcpInterval
;
// TODO: keep track of retransmitted data too.
//RTC::RtpDataCounter retransmitted;
};
/* Inline methods. */
...
...
@@ -113,12 +123,6 @@ namespace RTC
this
->
senderReport
->
Serialize
();
};
inline
RTC
::
RTCP
::
SenderReport
*
RtpSender
::
GetRtcpSenderReport
()
{
return
this
->
senderReport
.
release
();
};
inline
void
RtpSender
::
ReceiveRtcpSdesChunk
(
RTC
::
RTCP
::
SdesChunk
*
chunk
)
{
...
...
@@ -127,9 +131,9 @@ namespace RTC
};
inline
RTC
::
RTCP
::
SdesChunk
*
RtpSender
::
GetRtcpSdesChunk
(
)
uint32_t
RtpSender
::
GetTransmissionRate
(
uint64_t
now
)
{
return
this
->
sdesChunk
.
release
(
);
return
this
->
transmitted
.
GetRate
(
now
);
};
}
...
...
worker/src/RTC/Peer.cpp
浏览文件 @
b515d37e
...
...
@@ -7,6 +7,7 @@
#include "RTC/RTCP/FeedbackRtpNack.h"
#include "MediaSoupError.h"
#include "Logger.h"
#include "DepLibUV.h"
namespace
RTC
{
...
...
@@ -23,11 +24,19 @@ namespace RTC
notifier
(
notifier
)
{
MS_TRACE
();
this
->
timer
=
new
Timer
(
this
);
// Start the RTCP timer.
this
->
timer
->
Start
(
uint64_t
(
RTC
::
RTCP
::
MAX_VIDEO_INTERVAL_MS
/
2
));
}
Peer
::~
Peer
()
{
MS_TRACE
();
// Close the RTCP timer.
this
->
timer
->
Close
();
}
void
Peer
::
Close
()
...
...
@@ -510,7 +519,7 @@ namespace RTC
return
nullptr
;
}
void
Peer
::
SendRtcp
()
void
Peer
::
SendRtcp
(
uint64_t
now
)
{
MS_TRACE
();
...
...
@@ -521,7 +530,7 @@ namespace RTC
for
(
auto
it
=
this
->
transports
.
begin
();
it
!=
this
->
transports
.
end
();
++
it
)
{
RTC
::
RTCP
::
CompoundPacket
packet
;
std
::
unique_ptr
<
RTC
::
RTCP
::
CompoundPacket
>
packet
(
new
RTC
::
RTCP
::
CompoundPacket
())
;
RTC
::
Transport
*
transport
=
it
->
second
;
for
(
auto
it
=
this
->
rtpSenders
.
begin
();
it
!=
this
->
rtpSenders
.
end
();
++
it
)
...
...
@@ -531,24 +540,26 @@ namespace RTC
if
(
rtpSender
->
GetTransport
()
!=
transport
)
continue
;
RTC
::
RTCP
::
SenderReport
*
report
=
rtpSender
->
GetRtcpSenderReport
(
);
rtpSender
->
GetRtcp
(
packet
.
get
(),
now
);
if
(
report
)
// Send one RTCP compound packet per sender report.
if
(
packet
->
GetSenderReportCount
())
{
packet
.
AddSenderReport
(
report
);
// Ensure that the RTCP packet fits into the RTCP buffer.
if
(
packet
->
GetSize
()
>
MS_RTCP_BUFFER_SIZE
)
{
MS_WARN_TAG
(
rtcp
,
"cannot send RTCP packet, size too big (%zu bytes)"
,
packet
->
GetSize
());
return
;
}
RTC
::
RTCP
::
SdesChunk
*
chunk
=
rtpSender
->
GetRtcpSdesChunk
();
if
(
chunk
)
packet
.
AddSdesChunk
(
chunk
);
packet
->
Serialize
(
Peer
::
rtcpBuffer
);
transport
->
SendRtcpCompoundPacket
(
packet
.
get
());
break
;
// reset the Compound packet.
packet
.
reset
(
new
RTC
::
RTCP
::
CompoundPacket
());
}
}
// TMP: only send RR if SR is also being sent.
// if (packet.GetSenderReportCount() == 0)
// return;
for
(
auto
it
=
this
->
rtpReceivers
.
begin
();
it
!=
this
->
rtpReceivers
.
end
();
++
it
)
{
RTC
::
RtpReceiver
*
rtpReceiver
=
it
->
second
;
...
...
@@ -556,21 +567,22 @@ namespace RTC
if
(
rtpReceiver
->
GetTransport
()
!=
transport
)
continue
;
RTC
::
RTCP
::
ReceiverReport
*
report
=
rtpReceiver
->
GetRtcpReceiverReport
();
if
(
report
)
packet
.
AddReceiverReport
(
report
);
rtpReceiver
->
GetRtcp
(
packet
.
get
(),
now
);
}
//
Ensure that the RTCP packet fits into the RTCP buffer
.
if
(
packet
.
GetSize
()
>
MS_RTCP_BUFFER_SIZE
)
//
Send one RTCP compound with all receiver reports
.
if
(
packet
->
GetReceiverReportCount
()
)
{
MS_WARN_TAG
(
rtcp
,
"cannot send RTCP packet, size too big (%zu bytes)"
,
packet
.
GetSize
());
return
;
}
// Ensure that the RTCP packet fits into the RTCP buffer.
if
(
packet
->
GetSize
()
>
MS_RTCP_BUFFER_SIZE
)
{
MS_WARN_TAG
(
rtcp
,
"cannot send RTCP packet, size too big (%zu bytes)"
,
packet
->
GetSize
());
return
;
}
packet
.
Serialize
(
Peer
::
rtcpBuffer
);
transport
->
SendRtcpCompoundPacket
(
&
packet
);
packet
->
Serialize
(
Peer
::
rtcpBuffer
);
transport
->
SendRtcpCompoundPacket
(
packet
.
get
());
}
}
}
...
...
@@ -904,10 +916,6 @@ namespace RTC
packet
=
packet
->
GetNext
();
}
// TMP: Notify the listener about an incoming RTCP processing termination.
// Used for now as a trigger to relay the processed RTCP data accordingly.
this
->
listener
->
onPeerRtcpCompleted
(
this
);
}
void
Peer
::
onRtpReceiverClosed
(
RTC
::
RtpReceiver
*
rtpReceiver
)
...
...
@@ -939,4 +947,41 @@ namespace RTC
// Notify the listener (Room) so it can remove this RtpSender from its map.
this
->
listener
->
onPeerRtpSenderClosed
(
this
,
rtpSender
);
}
void
Peer
::
onTimer
(
Timer
*
timer
)
{
uint64_t
interval
=
RTC
::
RTCP
::
MAX_VIDEO_INTERVAL_MS
;
uint32_t
now
=
DepLibUV
::
GetTime
();
// Transmission rate in kbps.
uint32_t
rate
=
0
;
this
->
SendRtcp
(
now
);
// Recalculate next RTCP interval.
if
(
this
->
rtpSenders
.
size
())
{
// Get the RTP sending rate.
for
(
auto
&
kv
:
this
->
rtpSenders
)
{
RTC
::
RtpSender
*
rtpSender
=
kv
.
second
;
rate
+=
rtpSender
->
GetTransmissionRate
(
now
)
/
1000
;
}
// Calculate bandwidth: 360 / transmission bandwidth in kbit/s
if
(
rate
)
interval
=
360000
/
rate
;
if
(
interval
>
RTC
::
RTCP
::
MAX_VIDEO_INTERVAL_MS
)
interval
=
RTC
::
RTCP
::
MAX_VIDEO_INTERVAL_MS
;
}
/* The interval between RTCP packets is varied randomly over the range
* [0.5,1.5] times the calculated interval to avoid unintended synchronization
* of all participants.
*/
interval
*=
static_cast
<
float
>
(
Utils
::
Crypto
::
GetRandomUInt
(
5
,
15
))
/
10
;
this
->
timer
->
Start
(
interval
);
}
}
worker/src/RTC/Room.cpp
浏览文件 @
b515d37e
...
...
@@ -685,18 +685,4 @@ namespace RTC
rtpSender
->
ReceiveRtcpSdesChunk
(
chunk
);
}
}
void
Room
::
onPeerRtcpCompleted
(
RTC
::
Peer
*
peer
)
{
MS_TRACE
();
// Tell all the peers but the one in the argument to generate and send their RTCP.
for
(
auto
it
=
this
->
peers
.
begin
();
it
!=
this
->
peers
.
end
();
++
it
)
{
RTC
::
Peer
*
current_peer
=
it
->
second
;
if
(
current_peer
!=
peer
)
current_peer
->
SendRtcp
();
}
}
}
worker/src/RTC/RtpReceiver.cpp
浏览文件 @
b515d37e
...
...
@@ -22,6 +22,11 @@ namespace RTC
notifier
(
notifier
)
{
MS_TRACE
();
if
(
this
->
kind
==
RTC
::
Media
::
Kind
::
AUDIO
)
this
->
maxRtcpInterval
=
RTC
::
RTCP
::
MAX_AUDIO_INTERVAL_MS
;
else
this
->
maxRtcpInterval
=
RTC
::
RTCP
::
MAX_VIDEO_INTERVAL_MS
;
}
RtpReceiver
::~
RtpReceiver
()
...
...
@@ -284,20 +289,20 @@ namespace RTC
// SSRC values in received RTP packets to match the chosen random values.
}
RTC
::
RTCP
::
ReceiverReport
*
RtpReceiver
::
GetRtcpReceiverReport
(
)
void
RtpReceiver
::
GetRtcp
(
RTC
::
RTCP
::
CompoundPacket
*
packet
,
uint64_t
now
)
{
if
(
this
->
rtpStream
)
{
RTC
::
RTCP
::
ReceiverReport
*
report
=
this
->
rtpStream
->
GetRtcpReceiverReport
();
if
(
static_cast
<
float
>
((
now
-
this
->
lastRtcpSentTime
)
*
1.15
)
>=
this
->
maxRtcpInterval
)
{
RTC
::
RTCP
::
ReceiverReport
*
report
=
this
->
rtpStream
->
GetRtcpReceiverReport
();
// TODO: This assumes a single stream for now.
report
->
SetSsrc
(
this
->
rtpParameters
->
encodings
[
0
].
ssrc
);
// TODO: This assumes a single stream for now.
report
->
SetSsrc
(
this
->
rtpParameters
->
encodings
[
0
].
ssrc
);
packet
->
AddReceiverReport
(
report
);
return
report
;
}
else
{
return
nullptr
;
this
->
lastRtcpSentTime
=
now
;
}
}
}
...
...
worker/src/RTC/RtpSender.cpp
浏览文件 @
b515d37e
...
...
@@ -23,6 +23,11 @@ namespace RTC
notifier
(
notifier
)
{
MS_TRACE
();
if
(
this
->
kind
==
RTC
::
Media
::
Kind
::
AUDIO
)
this
->
maxRtcpInterval
=
RTC
::
RTCP
::
MAX_AUDIO_INTERVAL_MS
;
else
this
->
maxRtcpInterval
=
RTC
::
RTCP
::
MAX_VIDEO_INTERVAL_MS
;
}
RtpSender
::~
RtpSender
()
...
...
@@ -260,8 +265,28 @@ namespace RTC
// Send the packet.
this
->
transport
->
SendRtpPacket
(
packet
);
// Save RTP data
transmitted
.
Update
(
packet
);
}
void
RtpSender
::
GetRtcp
(
RTC
::
RTCP
::
CompoundPacket
*
packet
,
uint64_t
now
)
{
// TODO: Until we generate Sender Report.
if
(
this
->
senderReport
)
{
if
(
static_cast
<
float
>
((
now
-
this
->
lastRtcpSentTime
)
*
1.15
)
>=
this
->
maxRtcpInterval
)
{
packet
->
AddSenderReport
(
this
->
senderReport
.
release
());
if
(
this
->
sdesChunk
)
packet
->
AddSdesChunk
(
this
->
sdesChunk
.
release
());
this
->
lastRtcpSentTime
=
now
;
}
}
};
void
RtpSender
::
ReceiveNack
(
RTC
::
RTCP
::
FeedbackRtpNackPacket
*
nackPacket
)
{
MS_TRACE
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论