Skip to content

Commit

Permalink
Update webrtc library (#1797)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodoyun authored Feb 15, 2022
1 parent a892fbe commit 7df7628
Show file tree
Hide file tree
Showing 449 changed files with 34,935 additions and 51,447 deletions.
2 changes: 2 additions & 0 deletions erizo/conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
boost/1.76.0
apr/1.7.0
apr-util/1.6.1
abseil/20211102.0

IncludePathsGenerator/0.1@lynckia/includes

[generators]
Expand Down
7 changes: 5 additions & 2 deletions erizo/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ include_directories(${GLIB_INCLUDE_DIRS})
set (BOOST_LIBS thread regex system)
find_package(Boost)
include_directories(${Boost_INCLUDE_DIRS})

set(ERIZO_CMAKE_CXX_FLAGS "${ERIZO_CMAKE_CXX_FLAGS} -DBOOST_THREAD_PROVIDES_FUTURE -DBOOST_THREAD_PROVIDES_FUTURE_CONTINUATION -DBOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY")
# Adding -Wno-error=attributes for libav - an update should fix it
set(ERIZO_CMAKE_CXX_FLAGS "${ERIZO_CMAKE_CXX_FLAGS} -Wno-error=attributes -DBOOST_THREAD_PROVIDES_FUTURE -DBOOST_THREAD_PROVIDES_FUTURE_CONTINUATION -DBOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY")
# GTHREAD
find_library(GTHREAD gthread-2.0 HINTS "${THIRD_PARTY_LIB}")
test_lib(${GTHREAD})
Expand Down Expand Up @@ -128,6 +128,9 @@ set_target_properties(log4cxx PROPERTIES IMPORTED_LOCATION ${LOG4CXX_BUILD}/lib/

include_directories("${LOG4CXX_BUILD}/include")

find_package(absl)
include_directories("${absl_INCLUDE_DIRS}")

# WEBRTC
include("${CMAKE_CURRENT_SOURCE_DIR}/third_party/webrtc.cmake")

Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ if(${ERIZO_BUILD_TYPE} STREQUAL "debug")
set(CMAKE_CXX_FLAGS "-g -Wall -std=c++17 ${ERIZO_CMAKE_CXX_FLAGS}")
elseif(${ERIZO_BUILD_TYPE} STREQUAL "sanitizer")
message("Generating SANITIZER project")
set(CMAKE_CXX_FLAGS "-g -Wall -std=c++17 ${ERIZO_CMAKE_CXX_FLAGS} -O1 -fno-omit-frame-pointer -fsanitize=address -fno-optimize-sibling-calls")
set(CMAKE_CXX_FLAGS "-g -Wall -std=c++17 ${ERIZO_CMAKE_CXX_FLAGS} -Wdeprecated-declarations -O1 -fno-omit-frame-pointer -fsanitize=address -fno-optimize-sibling-calls")
else()
message("Generating RELEASE project")
set(CMAKE_CXX_FLAGS "-g -Wall -O3 -std=c++17 ${ERIZO_CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "-g -Wall -O3 -Wdeprecated-declarations -std=c++17 ${ERIZO_CMAKE_CXX_FLAGS}")
endif()


Expand Down
27 changes: 15 additions & 12 deletions erizo/src/erizo/media/ExternalOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <string>
#include <cstring>

#include "webrtc/api/rtp_parameters.h"

#include "lib/ClockUtils.h"

#include "./WebRtcConnection.h"
Expand Down Expand Up @@ -35,7 +37,6 @@ ExternalOutput::ExternalOutput(std::shared_ptr<Worker> worker, const std::string
av_register_all();
avcodec_register_all();

fec_receiver_.reset(webrtc::UlpfecReceiver::Create(this));
stats_ = std::make_shared<Stats>();
quality_manager_ = std::make_shared<QualityManager>();

Expand Down Expand Up @@ -148,16 +149,10 @@ void ExternalOutput::receiveRawData(const RawDataPacket& /*packet*/) {
return;
}
// This is called by our fec_ object once it recovers a packet.
bool ExternalOutput::OnRecoveredPacket(const uint8_t* rtp_packet, size_t rtp_packet_length) {
void ExternalOutput::OnRecoveredPacket(const uint8_t* rtp_packet, size_t rtp_packet_length) {
video_queue_.pushPacket((const char*)rtp_packet, rtp_packet_length);
return true;
}

int32_t ExternalOutput::OnReceivedPayloadData(const uint8_t* payload_data, size_t payload_size,
const webrtc::WebRtcRTPHeader* rtp_header) {
// Unused by WebRTC's FEC implementation; just something we have to implement.
return 0;
}

void ExternalOutput::writeAudioData(char* buf, int len) {
RtpHeader* head = reinterpret_cast<RtpHeader*>(buf);
Expand Down Expand Up @@ -469,13 +464,21 @@ void ExternalOutput::queueData(char* buffer, int length, packetType type) {
// we would have to pull in from the WebRtc project to fully construct
// a webrtc::RTPHeader object is obscene. So
// let's just do this hacky fix.
if (!fec_receiver_) {
rtc::ArrayView<const webrtc::RtpExtension> empty_extensions;
fec_receiver_ = webrtc::UlpfecReceiver::Create(
h->getSSRC(),
this,
empty_extensions);
}
webrtc::RTPHeader hacky_header;
hacky_header.headerLength = h->getHeaderLength();
hacky_header.sequenceNumber = h->getSeqNumber();
webrtc::RtpPacketReceived hacky_packet;
hacky_packet.Parse((const uint8_t*)buffer, length);
// hacky_header.headerLength = h->getHeaderLength();
// hacky_header.sequenceNumber = h->getSeqNumber();

// AddReceivedRedPacket returns 0 if there's data to process
if (0 == fec_receiver_->AddReceivedRedPacket(hacky_header, (const uint8_t*)buffer,
length, ULP_90000_PT)) {
if (0 == fec_receiver_->AddReceivedRedPacket(hacky_packet, ULP_90000_PT)) {
fec_receiver_->ProcessReceivedFec();
}
} else {
Expand Down
9 changes: 3 additions & 6 deletions erizo/src/erizo/media/ExternalOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern "C" {
#include "thread/Worker.h"
#include "rtp/RtpPacketQueue.h"
#include "rtp/RtpExtensionProcessor.h"
#include "webrtc/modules/rtp_rtcp/source/ulpfec_receiver_impl.h"
#include "webrtc/modules/rtp_rtcp/include/ulpfec_receiver.h"
#include "media/MediaProcessor.h"
#include "media/Depacketizer.h"
#include "./Stats.h"
Expand All @@ -31,7 +31,7 @@ namespace erizo {
static constexpr uint64_t kExternalOutputMaxBitrate = 1000000000;

class ExternalOutput : public MediaSink, public RawDataReceiver, public FeedbackSource,
public webrtc::RtpData, public HandlerManagerListener,
public webrtc::RecoveredPacketReceiver, public HandlerManagerListener,
public std::enable_shared_from_this<ExternalOutput> {
DECLARE_LOGGER();

Expand All @@ -44,10 +44,7 @@ class ExternalOutput : public MediaSink, public RawDataReceiver, public Feedback
void receiveRawData(const RawDataPacket& packet) override;

// webrtc::RtpData callbacks. This is for Forward Error Correction (per rfc5109) handling.
bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
int32_t OnReceivedPayloadData(const uint8_t* payload_data,
size_t payload_size,
const webrtc::WebRtcRTPHeader* rtp_header) override;
void OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;

boost::future<void> close() override;

Expand Down
22 changes: 15 additions & 7 deletions erizo/src/erizo/rtp/BandwidthEstimationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

#include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h"
#include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h"
#include "webrtc/base/logging.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h"
#include "webrtc/rtc_base/logging.h"

namespace erizo {

Expand Down Expand Up @@ -157,9 +158,10 @@ void BandwidthEstimationHandler::read(Context *ctx, std::shared_ptr<DataPacket>
RtcpHeader *chead = reinterpret_cast<RtcpHeader*> (packet->data);
if (!chead->isRtcp() && packet->type == VIDEO_PACKET) {
if (parsePacket(packet)) {
RtpHeader *head = reinterpret_cast<RtpHeader*> (packet->data);
int64_t arrival_time_ms = packet->received_time_ms;
arrival_time_ms = clock_->TimeInMilliseconds() - (ClockUtils::timePointToMs(clock::now()) - arrival_time_ms);
size_t payload_size = packet->length;
size_t payload_size = packet->length - head->getHeaderLength();
pickEstimatorFromHeader();
rbe_->IncomingPacket(arrival_time_ms, payload_size, header_);
} else {
Expand All @@ -172,10 +174,16 @@ void BandwidthEstimationHandler::read(Context *ctx, std::shared_ptr<DataPacket>
bool BandwidthEstimationHandler::parsePacket(std::shared_ptr<DataPacket> packet) {
const uint8_t* buffer = reinterpret_cast<uint8_t*>(packet->data);
size_t length = packet->length;
webrtc::RtpUtility::RtpHeaderParser rtp_parser(buffer, length);
memset(&header_, 0, sizeof(header_));
RtpHeaderExtensionMap map = getHeaderExtensionMap(packet);
return rtp_parser.Parse(&header_, &map);
webrtc::RtpPacket::ExtensionManager extension_manager = getHeaderExtensionMap(packet);
webrtc::RtpPacketReceived emptyPacket(&extension_manager);
header_ = webrtc::RTPHeader();

if (emptyPacket.ParseBuffer(buffer, length)) {
emptyPacket.GetHeader(&header_);
return true;
} else {
return false;
}
}

RtpHeaderExtensionMap BandwidthEstimationHandler::getHeaderExtensionMap(std::shared_ptr<DataPacket> packet) const {
Expand Down Expand Up @@ -258,7 +266,7 @@ void BandwidthEstimationHandler::sendREMBPacket() {

int remb_length = (remb_packet_.getLength() + 1) * 4;
if (active_) {
ELOG_DEBUG("BWE Estimation is %d", last_send_bitrate_);
ELOG_DEBUG("BWE Estimation is %d, using absolute: %u", last_send_bitrate_, using_absolute_send_time_);
getContext()->fireWrite(std::make_shared<DataPacket>(0,
reinterpret_cast<char*>(&remb_packet_), remb_length, OTHER_PACKET));
}
Expand Down
5 changes: 3 additions & 2 deletions erizo/src/erizo/rtp/BandwidthEstimationHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

#include "thread/Worker.h"

#include "webrtc/common_types.h"
#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
#include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
#include "webrtc/modules/rtp_rtcp/include/rtp_header_extension_map.h"

#include "webrtc/system_wrappers/include/clock.h"

namespace erizo {
Expand Down
27 changes: 14 additions & 13 deletions erizo/src/erizo/rtp/FecReceiverHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#include "./MediaDefinitions.h"
#include "./MediaStream.h"

#include "webrtc/api/rtp_parameters.h"

namespace erizo {

DEFINE_LOGGER(FecReceiverHandler, "rtp.FecReceiverHandler");

FecReceiverHandler::FecReceiverHandler() :
enabled_{false} {
fec_receiver_.reset(webrtc::UlpfecReceiver::Create(this));
}

void FecReceiverHandler::setFecReceiver(std::unique_ptr<webrtc::UlpfecReceiver>&& fec_receiver) { // NOLINT
Expand Down Expand Up @@ -45,16 +46,22 @@ void FecReceiverHandler::write(Context *ctx, std::shared_ptr<DataPacket> packet)
if (enabled_ && packet->type == VIDEO_PACKET) {
RtpHeader *rtp_header = reinterpret_cast<RtpHeader*>(packet->data);
if (rtp_header->getPayloadType() == RED_90000_PT) {
if (!fec_receiver_) {
rtc::ArrayView<const webrtc::RtpExtension> empty_extensions;
fec_receiver_ = webrtc::UlpfecReceiver::Create(
rtp_header->getSSRC(),
this,
empty_extensions);
}
// This is a RED/FEC payload, but our remote endpoint doesn't support that
// (most likely because it's firefox :/ )
// Let's go ahead and run this through our fec receiver to convert it to raw VP8
webrtc::RTPHeader hacky_header;
hacky_header.headerLength = rtp_header->getHeaderLength();
hacky_header.sequenceNumber = rtp_header->getSeqNumber();
webrtc::RtpPacketReceived hacky_packet;
hacky_packet.Parse((const uint8_t*)packet->data, packet->length);

// FEC copies memory, manages its own memory, including memory passed in callbacks (in the callback,
// be sure to memcpy out of webrtc's buffers
if (fec_receiver_->AddReceivedRedPacket(hacky_header,
(const uint8_t*) packet->data, packet->length, ULP_90000_PT) == 0) {
if (fec_receiver_->AddReceivedRedPacket(hacky_packet, ULP_90000_PT) == 0) {
fec_receiver_->ProcessReceivedFec();
}
}
Expand All @@ -63,14 +70,8 @@ void FecReceiverHandler::write(Context *ctx, std::shared_ptr<DataPacket> packet)
ctx->fireWrite(std::move(packet));
}

bool FecReceiverHandler::OnRecoveredPacket(const uint8_t* rtp_packet, size_t rtp_packet_length) {
void FecReceiverHandler::OnRecoveredPacket(const uint8_t* rtp_packet, size_t rtp_packet_length) {
getContext()->fireWrite(std::make_shared<DataPacket>(0, (char*)rtp_packet, rtp_packet_length, VIDEO_PACKET)); // NOLINT
return true;
}

int32_t FecReceiverHandler::OnReceivedPayloadData(const uint8_t* /*payload_data*/, size_t /*payload_size*/,
const webrtc::WebRtcRTPHeader* /*rtp_header*/) {
// Unused by WebRTC's FEC implementation; just something we have to implement.
return 0;
}
} // namespace erizo
8 changes: 3 additions & 5 deletions erizo/src/erizo/rtp/FecReceiverHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace erizo {

class MediaStream;

class FecReceiverHandler: public OutboundHandler, public webrtc::RtpData {
class FecReceiverHandler: public OutboundHandler, public webrtc::RecoveredPacketReceiver {
DECLARE_LOGGER();

public:
Expand All @@ -29,10 +29,8 @@ class FecReceiverHandler: public OutboundHandler, public webrtc::RtpData {
void write(Context *ctx, std::shared_ptr<DataPacket> packet) override;
void notifyUpdate() override;

// webrtc::RtpHeader overrides.
int32_t OnReceivedPayloadData(const uint8_t* payloadData, size_t payloadSize,
const webrtc::WebRtcRTPHeader* rtpHeader) override;
bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
// webrtc::RecoveredPacketReceiver overrides.
void OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;

private:
bool enabled_;
Expand Down
37 changes: 24 additions & 13 deletions erizo/src/erizo/rtp/SenderBandwidthEstimantionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include <utility>

#include "webrtc/test/explicit_key_value_config.h"
#include "webrtc/api/units/data_rate.h"
#include "webrtc/api/units/timestamp.h"

#include "./MediaDefinitions.h"
#include "rtp/RtpUtils.h"
#include "./MediaStream.h"
Expand All @@ -15,9 +19,15 @@ constexpr duration SenderBandwidthEstimationHandler::kMinUpdateEstimateInterval;
SenderBandwidthEstimationHandler::SenderBandwidthEstimationHandler(std::shared_ptr<Clock> the_clock) :
connection_{nullptr}, bwe_listener_{nullptr}, clock_{the_clock}, initialized_{false}, enabled_{true},
received_remb_{false}, estimated_bitrate_{0}, estimated_loss_{0},
estimated_rtt_{0}, last_estimate_update_{clock::now()}, sender_bwe_{new SendSideBandwidthEstimation()},
estimated_rtt_{0}, last_estimate_update_{clock::now()},
max_rr_delay_data_size_{0}, max_sr_delay_data_size_{0} {
sender_bwe_->SetBitrates(kStartSendBitrate, kMinSendBitrate, kMaxSendBitrate);
webrtc::test::ExplicitKeyValueConfig key_value_config("");
sender_bwe_.reset(new SendSideBandwidthEstimation(&key_value_config));
sender_bwe_->SetBitrates(
webrtc::DataRate::BitsPerSec(kStartSendBitrate),
webrtc::DataRate::BitsPerSec(kMinSendBitrate),
webrtc::DataRate::BitsPerSec(kMaxSendBitrate),
getNowTimestamp());
}

SenderBandwidthEstimationHandler::SenderBandwidthEstimationHandler(const SenderBandwidthEstimationHandler&& handler) : // NOLINT
Expand Down Expand Up @@ -120,15 +130,14 @@ void SenderBandwidthEstimationHandler::read(Context *ctx, std::shared_ptr<DataPa
char *uniqueId = reinterpret_cast<char*>(&chead->report.rembPacket.uniqueid);
if (!strncmp(uniqueId, "REMB", 4)) {
received_remb_ = true;
int64_t now_ms = ClockUtils::timePointToMs(clock_->now());
uint64_t remb_bitrate = chead->getBrMantis() << chead->getBrExp();
uint64_t bitrate = estimated_bitrate_ != 0 ? estimated_bitrate_ : remb_bitrate;

// We update the REMB with the latest estimation
chead->setREMBBitRate(bitrate);
ELOG_DEBUG("%s message: Updating estimate REMB, bitrate: %lu, estimated_bitrate %lu, remb_bitrate %lu",
connection_->toLog(), bitrate, estimated_bitrate_, remb_bitrate);
sender_bwe_->UpdateReceiverEstimate(now_ms, remb_bitrate);
sender_bwe_->UpdateReceiverEstimate(getNowTimestamp(), webrtc::DataRate::BitsPerSec(remb_bitrate));
updateEstimate();
} else {
ELOG_DEBUG("%s message: Unsupported AFB Packet not REMB", connection_->toLog());
Expand All @@ -147,13 +156,11 @@ void SenderBandwidthEstimationHandler::updateReceiverBlockFromList() {
if (rr_delay_data_.size() < max_rr_delay_data_size_) {
return;
}
// TODO(pedro) Implement alternative when there are no REMBs
if (received_remb_) {
uint32_t total_packets_lost = 0;
uint32_t total_packets_sent = 0;
uint64_t avg_delay = 0;
uint32_t rr_delay_data_size = rr_delay_data_.size();
int64_t now_ms = ClockUtils::timePointToMs(clock_->now());
std::for_each(rr_delay_data_.begin(), rr_delay_data_.end(),
[&avg_delay, &total_packets_lost, rr_delay_data_size, &total_packets_sent, this]
(const std::shared_ptr<RrDelayData> &rr_info) {
Expand All @@ -165,11 +172,11 @@ void SenderBandwidthEstimationHandler::updateReceiverBlockFromList() {
}
});
if (total_packets_sent > 0) {
uint32_t fraction_lost = total_packets_lost * 255 / total_packets_sent;
ELOG_DEBUG("%s message: Updating Estimate with RR, fraction_lost: %u, "
ELOG_DEBUG("%s message: Updating Estimate with RR, packets_lost: %u, "
"delay: %u, period_packets_sent_: %u",
connection_->toLog(), fraction_lost, avg_delay, total_packets_sent);
sender_bwe_->UpdateReceiverBlock(fraction_lost, avg_delay, total_packets_sent, now_ms);
connection_->toLog(), total_packets_lost, avg_delay, total_packets_sent);
sender_bwe_->UpdateRtt(webrtc::TimeDelta::Millis(avg_delay), getNowTimestamp());
sender_bwe_->UpdatePacketsLost(total_packets_lost, total_packets_sent, getNowTimestamp());
updateEstimate();
}
}
Expand All @@ -191,7 +198,7 @@ void SenderBandwidthEstimationHandler::write(Context *ctx, std::shared_ptr<DataP
if (packet->type == VIDEO_PACKET) {
time_point now = clock_->now();
if (received_remb_ && now - last_estimate_update_ > kMinUpdateEstimateInterval) {
sender_bwe_->UpdateEstimate(ClockUtils::timePointToMs(now));
sender_bwe_->UpdateEstimate(getNowTimestamp());
updateEstimate();
last_estimate_update_ = now;
}
Expand All @@ -215,8 +222,7 @@ void SenderBandwidthEstimationHandler::analyzeSr(RtcpHeader* chead) {
}

void SenderBandwidthEstimationHandler::updateEstimate() {
sender_bwe_->CurrentEstimate(&estimated_bitrate_, &estimated_loss_,
&estimated_rtt_);
estimated_bitrate_ = sender_bwe_->target_rate().bps();
if (stats_) {
stats_->getNode()["total"].insertStat("senderBitrateEstimation",
CumulativeStat{static_cast<uint64_t>(estimated_bitrate_)});
Expand All @@ -227,4 +233,9 @@ void SenderBandwidthEstimationHandler::updateEstimate() {
bwe_listener_->onBandwidthEstimate(estimated_bitrate_, estimated_loss_, estimated_rtt_);
}
}

webrtc::Timestamp SenderBandwidthEstimationHandler::getNowTimestamp() {
int64_t now_ms = ClockUtils::timePointToMs(clock_->now());
return webrtc::Timestamp::Millis(now_ms);
}
} // namespace erizo
Loading

0 comments on commit 7df7628

Please sign in to comment.