Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 2eba346

Browse files
starwarfanlzhai
authored andcommitted
Use REMB for RID streams (#361)
1 parent e8b7a77 commit 2eba346

File tree

7 files changed

+214
-11
lines changed

7 files changed

+214
-11
lines changed
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
From 15553a66a08795ab3bbbcfdc9ad3547911ac763e Mon Sep 17 00:00:00 2001
2+
From: Chen Li1 <[email protected]>
3+
Date: Thu, 31 Oct 2019 15:39:42 +0800
4+
Subject: [PATCH] Enable REMB for RID streams
5+
6+
---
7+
erizo/src/erizo/MediaStream.cpp | 16 +++++++++++++---
8+
erizo/src/erizo/SdpInfo.cpp | 1 +
9+
erizo/src/erizo/rtp/BandwidthEstimationHandler.cpp | 20 ++++++++++++++------
10+
erizo/src/erizo/rtp/BandwidthEstimationHandler.h | 4 ++--
11+
erizo/src/erizo/rtp/RtpExtensionProcessor.cpp | 2 +-
12+
5 files changed, 31 insertions(+), 12 deletions(-)
13+
14+
diff --git a/erizo/src/erizo/MediaStream.cpp b/erizo/src/erizo/MediaStream.cpp
15+
index a78b057..4327c6f 100644
16+
--- a/erizo/src/erizo/MediaStream.cpp
17+
+++ b/erizo/src/erizo/MediaStream.cpp
18+
@@ -21,7 +21,7 @@
19+
#include "rtp/RtcpForwarder.h"
20+
// #include "rtp/RtpSlideShowHandler.h"
21+
// #include "rtp/RtpTrackMuteHandler.h"
22+
-// #include "rtp/BandwidthEstimationHandler.h"
23+
+#include "rtp/BandwidthEstimationHandler.h"
24+
// #include "rtp/FecReceiverHandler.h"
25+
#include "rtp/RtcpProcessorHandler.h"
26+
// #include "rtp/RtpRetransmissionHandler.h"
27+
@@ -151,6 +151,10 @@ bool MediaStream::setRemoteSdp(std::shared_ptr<SdpInfo> sdp) {
28+
if (!sending_) {
29+
return true;
30+
}
31+
+ if (!sdp) {
32+
+ ELOG_WARN("%s message: setting remote SDP nullptr", toLog());
33+
+ return true;
34+
+ }
35+
remote_sdp_ = std::make_shared<SdpInfo>(*sdp.get());
36+
if (remote_sdp_->videoBandwidth != 0) {
37+
ELOG_DEBUG("%s message: Setting remote BW, maxVideoBW: %u", toLog(), remote_sdp_->videoBandwidth);
38+
@@ -193,6 +197,10 @@ bool MediaStream::setRemoteSdp(std::shared_ptr<SdpInfo> sdp) {
39+
rtcp_processor_->addSourceSsrc(new_ssrc);
40+
});
41+
42+
+ if (remote_sdp_->rids().size() > 1) {
43+
+ simulcast_ = true;
44+
+ }
45+
+
46+
initializePipeline();
47+
48+
initializeStats();
49+
@@ -348,7 +356,7 @@ void MediaStream::initializePipeline() {
50+
pipeline_->addFront(std::make_shared<PacketReader>(this));
51+
pipeline_->addFront(WoogeenHandler(this));
52+
53+
- pipeline_->addFront(std::make_shared<RtcpProcessorHandler>());
54+
+ // pipeline_->addFront(std::make_shared<RtcpProcessorHandler>());
55+
// pipeline_->addFront(std::make_shared<FecReceiverHandler>());
56+
// pipeline_->addFront(std::make_shared<LayerBitrateCalculationHandler>());
57+
// pipeline_->addFront(std::make_shared<QualityFilterHandler>());
58+
@@ -357,7 +365,9 @@ void MediaStream::initializePipeline() {
59+
// pipeline_->addFront(std::make_shared<RtpSlideShowHandler>());
60+
// pipeline_->addFront(std::make_shared<RtpPaddingGeneratorHandler>());
61+
// pipeline_->addFront(std::make_shared<PliPacerHandler>());
62+
- // pipeline_->addFront(std::make_shared<BandwidthEstimationHandler>());
63+
+ if (simulcast_ && is_publisher_) {
64+
+ pipeline_->addFront(std::make_shared<BandwidthEstimationHandler>());
65+
+ }
66+
// pipeline_->addFront(std::make_shared<RtpPaddingRemovalHandler>());
67+
// pipeline_->addFront(std::make_shared<RtcpFeedbackGenerationHandler>());
68+
// pipeline_->addFront(std::make_shared<RtpRetransmissionHandler>());
69+
diff --git a/erizo/src/erizo/SdpInfo.cpp b/erizo/src/erizo/SdpInfo.cpp
70+
index c4d9ea7..4e13951 100644
71+
--- a/erizo/src/erizo/SdpInfo.cpp
72+
+++ b/erizo/src/erizo/SdpInfo.cpp
73+
@@ -69,6 +69,7 @@ namespace erizo {
74+
}
75+
76+
bool SdpInfo::initWithSdp(const std::string& sdp, const std::string& media) {
77+
+ rids_.clear();
78+
return processSdp(sdp, media);
79+
}
80+
std::string SdpInfo::addCandidate(const CandidateInfo& info) {
81+
diff --git a/erizo/src/erizo/rtp/BandwidthEstimationHandler.cpp b/erizo/src/erizo/rtp/BandwidthEstimationHandler.cpp
82+
index a5a9366..d283ca5 100644
83+
--- a/erizo/src/erizo/rtp/BandwidthEstimationHandler.cpp
84+
+++ b/erizo/src/erizo/rtp/BandwidthEstimationHandler.cpp
85+
@@ -97,15 +97,15 @@ void BandwidthEstimationHandler::process() {
86+
}, std::chrono::milliseconds(rbe_->TimeUntilNextProcess()));
87+
}
88+
89+
-void BandwidthEstimationHandler::updateExtensionMaps(std::array<RTPExtensions, 10> video_map,
90+
- std::array<RTPExtensions, 10> audio_map) {
91+
+void BandwidthEstimationHandler::updateExtensionMaps(std::array<RTPExtensions, 20> video_map,
92+
+ std::array<RTPExtensions, 20> audio_map) {
93+
updateExtensionMap(true, video_map);
94+
updateExtensionMap(false, audio_map);
95+
}
96+
97+
-void BandwidthEstimationHandler::updateExtensionMap(bool is_video, std::array<RTPExtensions, 10> map) {
98+
+void BandwidthEstimationHandler::updateExtensionMap(bool is_video, std::array<RTPExtensions, 20> map) {
99+
webrtc::RTPExtensionType type = webrtc::kRtpExtensionNone;
100+
- for (uint8_t id = 0; id < 10; id++) {
101+
+ for (uint8_t id = 0; id < 20; id++) {
102+
RTPExtensions extension = map[id];
103+
switch (extension) {
104+
case RTP_ID:
105+
@@ -130,6 +130,9 @@ void BandwidthEstimationHandler::updateExtensionMap(bool is_video, std::array<RT
106+
case PLAYBACK_TIME:
107+
type = webrtc::kRtpExtensionPlayoutDelay;
108+
break;
109+
+ default:
110+
+ continue;
111+
+ break;
112+
}
113+
if (type == webrtc::kRtpExtensionNone) {
114+
continue;
115+
@@ -219,6 +222,11 @@ void BandwidthEstimationHandler::pickEstimator() {
116+
}
117+
118+
void BandwidthEstimationHandler::sendREMBPacket() {
119+
+ uint32_t mul = 1;
120+
+ auto remoteSdp = stream_->getRemoteSdpInfo();
121+
+ if (remoteSdp && !remoteSdp->rids().empty()) {
122+
+ mul = (1 << remoteSdp->rids().size()) - 1;
123+
+ }
124+
remb_packet_.setPacketType(RTCP_PS_Feedback_PT);
125+
remb_packet_.setBlockCount(RTCP_AFB);
126+
memcpy(&remb_packet_.report.rembPacket.uniqueid, "REMB", 4);
127+
@@ -229,12 +237,12 @@ void BandwidthEstimationHandler::sendREMBPacket() {
128+
remb_packet_.setLength(5);
129+
uint32_t capped_bitrate = max_video_bw_ > 0 ? std::min(max_video_bw_, bitrate_) : bitrate_;
130+
ELOG_DEBUG("Bitrates min(%u,%u) = %u", bitrate_, max_video_bw_, capped_bitrate);
131+
- remb_packet_.setREMBBitRate(capped_bitrate);
132+
+ remb_packet_.setREMBBitRate(bitrate_ * mul);
133+
remb_packet_.setREMBNumSSRC(1);
134+
remb_packet_.setREMBFeedSSRC(0, stream_->getVideoSourceSSRC());
135+
int remb_length = (remb_packet_.getLength() + 1) * 4;
136+
if (active_) {
137+
- ELOG_DEBUG("BWE Estimation is %d", last_send_bitrate_);
138+
+ ELOG_DEBUG("BWE Estimation is %d", bitrate_ * mul);
139+
getContext()->fireWrite(std::make_shared<DataPacket>(0,
140+
reinterpret_cast<char*>(&remb_packet_), remb_length, OTHER_PACKET));
141+
}
142+
diff --git a/erizo/src/erizo/rtp/BandwidthEstimationHandler.h b/erizo/src/erizo/rtp/BandwidthEstimationHandler.h
143+
index c851ab1..166d799 100644
144+
--- a/erizo/src/erizo/rtp/BandwidthEstimationHandler.h
145+
+++ b/erizo/src/erizo/rtp/BandwidthEstimationHandler.h
146+
@@ -55,7 +55,7 @@ class BandwidthEstimationHandler: public Handler, public RemoteBitrateObserver,
147+
void write(Context *ctx, std::shared_ptr<DataPacket> packet) override;
148+
void notifyUpdate() override;
149+
150+
- void updateExtensionMaps(std::array<RTPExtensions, 10> video_map, std::array<RTPExtensions, 10> audio_map);
151+
+ void updateExtensionMaps(std::array<RTPExtensions, 20> video_map, std::array<RTPExtensions, 20> audio_map);
152+
153+
private:
154+
void process();
155+
@@ -65,7 +65,7 @@ class BandwidthEstimationHandler: public Handler, public RemoteBitrateObserver,
156+
void pickEstimatorFromHeader();
157+
void pickEstimator();
158+
159+
- void updateExtensionMap(bool video, std::array<RTPExtensions, 10> map);
160+
+ void updateExtensionMap(bool video, std::array<RTPExtensions, 20> map);
161+
162+
MediaStream *stream_;
163+
std::shared_ptr<Worker> worker_;
164+
diff --git a/erizo/src/erizo/rtp/RtpExtensionProcessor.cpp b/erizo/src/erizo/rtp/RtpExtensionProcessor.cpp
165+
index 5ee860e..6ea37e8 100644
166+
--- a/erizo/src/erizo/rtp/RtpExtensionProcessor.cpp
167+
+++ b/erizo/src/erizo/rtp/RtpExtensionProcessor.cpp
168+
@@ -153,7 +153,7 @@ uint32_t RtpExtensionProcessor::processRtpExtensions(std::shared_ptr<DataPacket>
169+
if (extId != 0 && extMap[extId] != 0) {
170+
switch (extMap[extId]) {
171+
case ABS_SEND_TIME:
172+
- processAbsSendTime(extBuffer);
173+
+ // processAbsSendTime(extBuffer);
174+
break;
175+
case VIDEO_ORIENTATION:
176+
processVideoOrientation(extBuffer);
177+
--
178+
2.7.4
179+

source/agent/webrtc/log4cxx.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ log4j.logger.rtp.StatsCalculator=WARN
6363
log4j.logger.rtp.LayerDetectorHandler=WARN
6464
log4j.logger.rtp.PliPacerHandler=WARN
6565
log4j.logger.rtp.RtpPaddingGeneratorHandler=WARN
66+
log4j.logger.rtp.BandwidthEstimationHandler=WARN

source/agent/webrtc/sdp.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,20 @@ exports.getExtId = function (sdp, extUri) {
422422
}
423423
}
424424
}
425-
return -1;
425+
return 0;
426+
};
427+
428+
exports.filterExt = function (sdp, uri) {
429+
const sdpObj = transform.parse(sdp);
430+
for (const media of sdpObj.media) {
431+
if (Array.isArray(media.ext)) {
432+
media.ext = media.ext.filter(ext => ext.uri !== uri);
433+
}
434+
if (Array.isArray(media.rtcpFb)) {
435+
media.rtcpFb = media.rtcpFb.filter(fb => fb.type !== 'transport-cc');
436+
}
437+
}
438+
return transform.write(sdpObj);
426439
};
427440

428441
exports.processOffer = function (sdp, preference = {}, direction) {

source/agent/webrtc/webrtcLib/binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'erizo/src/erizo/rtp/RtpUtils.cpp',
3434
'erizo/src/erizo/rtp/QualityManager.cpp',
3535
'erizo/src/erizo/rtp/RtpExtensionProcessor.cpp',
36+
'erizo/src/erizo/rtp/BandwidthEstimationHandler.cpp',
3637
'<!@(find erizo/src/erizo/dtls -name "*.cpp")',
3738
'<!@(find erizo/src/erizo/dtls -name "*.c")',
3839
'<!@(find erizo/src/erizo/pipeline -name "*.cpp")',

source/agent/webrtc/wrtcConnection.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const {
2424
getLegacySimulcastInfo,
2525
hasCodec,
2626
getExtId,
27+
filterExt,
2728
addAudioSSRC,
2829
addVideoSSRC,
2930
} = require('./sdp');
@@ -184,6 +185,10 @@ module.exports = function (spec, on_status, on_mediaUpdate) {
184185
const vSsrc = videoFramePacketizer.ssrc();
185186
message = addVideoSSRC(message, vSsrc);
186187
}
188+
if (isSimulcast) {
189+
// TODO: enable transport-cc for simulcast if bandwidth works
190+
message = filterExt(message, TransportSeqNumUri);
191+
}
187192
log.debug('Answer SDP', message);
188193
on_status({type: 'answer', sdp: message});
189194

@@ -292,10 +297,9 @@ module.exports = function (spec, on_status, on_mediaUpdate) {
292297

293298
var processLegacySimulcast = function (sdp) {
294299
// Process legacy simulcast info for Safari
295-
log.debug('Process legacy simulcast');
296300
const simInfo = getLegacySimulcastInfo(sdp);
297301
if (simInfo.length > 1 && video) {
298-
isSimulcast = true;
302+
log.debug('Process legacy simulcast');
299303
stream = new WrtcStream({
300304
audioFrameConstructor,
301305
videoFrameConstructor,
@@ -337,12 +341,19 @@ module.exports = function (spec, on_status, on_mediaUpdate) {
337341

338342
var setupTransport = function (sdp) {
339343
if (direction === 'in') {
344+
const simulcastInfo = getSimulcastInfo(sdp);
345+
const legacySimInfo = getLegacySimulcastInfo(sdp);
346+
transportSeqNumExt = getExtId(sdp, TransportSeqNumUri);
347+
if (simulcastInfo.length > 0 || legacySimInfo.length > 1) {
348+
isSimulcast = true;
349+
transportSeqNumExt = 0;
350+
}
351+
340352
if (audio) {
341353
audioFrameConstructor = new AudioFrameConstructor();
342354
audioFrameConstructor.bindTransport(wrtc.getMediaStream(wrtcId));
343355
}
344356
if (video) {
345-
transportSeqNumExt = getExtId(sdp, TransportSeqNumUri);
346357
videoFrameConstructor = new VideoFrameConstructor(on_mediaUpdate, transportSeqNumExt);
347358
videoFrameConstructor.bindTransport(wrtc.getMediaStream(wrtcId));
348359
}
@@ -352,10 +363,6 @@ module.exports = function (spec, on_status, on_mediaUpdate) {
352363
}
353364
const aSsrc = getAudioSsrc(sdp);
354365
const vSsrc = getVideoSsrcList(sdp);
355-
const simulcastInfo = getSimulcastInfo(sdp);
356-
if (simulcastInfo.length > 0) {
357-
isSimulcast = true;
358-
}
359366
log.debug('SDP ssrc:', aSsrc, vSsrc);
360367
wrtc.setRemoteSsrc(aSsrc, vSsrc, '');
361368
wrtc.setSimulcastInfo(simulcastInfo);

source/core/owt_base/VideoFrameConstructor.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ bool VideoFrameConstructor::init(uint32_t transportccExtId)
6262
m_remoteBitrateObserver.reset(new VieRemb(Clock::GetRealTimeClock()));
6363
m_remoteBitrateEstimator.reset(new RemoteEstimatorProxy(Clock::GetRealTimeClock(), m_packetRouter.get()));
6464
m_videoReceiver.reset(new ViEReceiver(m_video_receiver.get(), m_remoteBitrateEstimator.get(), this));
65-
m_videoReceiver->SetReceiveTransportSequenceNumberStatus(true, transportccExtId);
6665

6766
RtpRtcp::Configuration configuration;
6867
configuration.audio = false; // Video.
@@ -73,7 +72,10 @@ bool VideoFrameConstructor::init(uint32_t transportccExtId)
7372
m_rtpRtcp->SetRTCPStatus(webrtc::RtcpMode::kCompound);
7473
// Since currently our MCU only claims FIR support in SDP, we choose FirRtcp for now.
7574
m_rtpRtcp->SetKeyFrameRequestMethod(kKeyFrameReqFirRtcp);
76-
m_rtpRtcp->RegisterSendRtpHeaderExtension(RTPExtensionType::kRtpExtensionTransportSequenceNumber, transportccExtId);
75+
if (transportccExtId > 0) {
76+
m_videoReceiver->SetReceiveTransportSequenceNumberStatus(true, transportccExtId);
77+
m_rtpRtcp->RegisterSendRtpHeaderExtension(RTPExtensionType::kRtpExtensionTransportSequenceNumber, transportccExtId);
78+
}
7779
m_rtpRtcp->SetREMBStatus(false);
7880
m_videoReceiver->SetRtpRtcpModule(m_rtpRtcp.get());
7981
m_remoteBitrateObserver->AddRembSender(m_rtpRtcp.get());

source/core/owt_base/VideoFrameConstructor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class VideoFrameConstructor : public erizo::MediaSink,
5252
DECLARE_LOGGER();
5353

5454
public:
55-
VideoFrameConstructor(VideoInfoListener*, uint32_t transportccExtId = 2);
55+
VideoFrameConstructor(VideoInfoListener*, uint32_t transportccExtId = 0);
5656
virtual ~VideoFrameConstructor();
5757

5858
void bindTransport(erizo::MediaSource* source, erizo::FeedbackSink* fbSink);

0 commit comments

Comments
 (0)