Refactor FEC code to use COW buffers

This refactoring helps to reduce unnecessary memcpy calls on the receive
side.

This CL replaces
|uint8 data[IP_PACKET_SIZE]| with |rtc::CopyOnWriteBuffer data| in Packet class,
removes |length| field there, and does necessary changes.

This is a reland of these two CLs with fixes:
https://webrtc-review.googlesource.com/c/src/+/144942
https://webrtc-review.googlesource.com/c/src/+/144881

Bug: webrtc:10750
Change-Id: I76f6dee5a57ade59942ea2822ca4737edfe6438b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/145332
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29035}
This commit is contained in:
Ilya Nikolaevskiy
2019-09-02 13:58:49 +02:00
committed by Commit Bot
parent a66395e72f
commit eec5fff4df
25 changed files with 357 additions and 328 deletions

View File

@ -107,13 +107,12 @@ FlexfecReceiver::AddReceivedPacket(const RtpPacketReceived& packet) {
++packet_counter_.num_fec_packets;
// Insert packet payload into erasure code.
// TODO(brandtr): Remove this memcpy when the FEC packet classes
// are using COW buffers internally.
received_packet->pkt = rtc::scoped_refptr<ForwardErrorCorrection::Packet>(
new ForwardErrorCorrection::Packet());
// TODO(ilnik): after slice capability is added to COW, use it here instead
// of initializing COW buffer with ArrayView.
auto payload = packet.payload();
memcpy(received_packet->pkt->data, payload.data(), payload.size());
received_packet->pkt->length = payload.size();
received_packet->pkt->data.SetData(payload.data(), payload.size());
} else {
// This is a media packet, or a FlexFEC packet belonging to some
// other FlexFEC stream.
@ -123,11 +122,12 @@ FlexfecReceiver::AddReceivedPacket(const RtpPacketReceived& packet) {
received_packet->is_fec = false;
// Insert entire packet into erasure code.
// Create a copy and fill with zeros all mutable extensions.
received_packet->pkt = rtc::scoped_refptr<ForwardErrorCorrection::Packet>(
new ForwardErrorCorrection::Packet());
// Create a copy and fill with zeros all mutable extensions.
packet.CopyAndZeroMutableExtensions(received_packet->pkt->data);
received_packet->pkt->length = packet.size();
RtpPacketReceived packet_copy(packet);
packet_copy.ZeroMutableExtensions();
received_packet->pkt->data = packet_copy.Buffer();
}
++packet_counter_.num_packets;
@ -161,14 +161,15 @@ void FlexfecReceiver::ProcessReceivedPacket(
// Set this flag first, since OnRecoveredPacket may end up here
// again, with the same packet.
recovered_packet->returned = true;
RTC_CHECK(recovered_packet->pkt);
RTC_CHECK_GT(recovered_packet->pkt->data.size(), 0);
recovered_packet_receiver_->OnRecoveredPacket(
recovered_packet->pkt->data, recovered_packet->pkt->length);
recovered_packet->pkt->data.cdata(),
recovered_packet->pkt->data.size());
// Periodically log the incoming packets.
int64_t now_ms = clock_->TimeInMilliseconds();
if (now_ms - last_recovered_packet_ms_ > kPacketLogIntervalMs) {
uint32_t media_ssrc =
ForwardErrorCorrection::ParseSsrc(recovered_packet->pkt->data);
ForwardErrorCorrection::ParseSsrc(recovered_packet->pkt->data.data());
RTC_LOG(LS_VERBOSE) << "Recovered media packet with SSRC: " << media_ssrc
<< " from FlexFEC stream with SSRC: " << ssrc_ << ".";
last_recovered_packet_ms_ = now_ms;