Index: webrtc/modules/rtp_rtcp/source/flexfec_receiver.cc |
diff --git a/webrtc/modules/rtp_rtcp/source/flexfec_receiver.cc b/webrtc/modules/rtp_rtcp/source/flexfec_receiver.cc |
index 2c974754915cad4a28188b823bb9f1f949e96d95..9eae01cd93b07fff27ca17bc99d9725bff482056 100644 |
--- a/webrtc/modules/rtp_rtcp/source/flexfec_receiver.cc |
+++ b/webrtc/modules/rtp_rtcp/source/flexfec_receiver.cc |
@@ -14,7 +14,8 @@ |
#include "webrtc/base/logging.h" |
#include "webrtc/base/scoped_ref_ptr.h" |
-#include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
+#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
namespace webrtc { |
@@ -29,15 +30,24 @@ constexpr size_t kMinFlexfecHeaderSize = 20; |
// How often to log the recovered packets to the text log. |
constexpr int kPacketLogIntervalMs = 10000; |
+bool HasBweExtension(const RtpPacketReceived& packet) { |
+ return packet.HasExtension<TransportSequenceNumber>() || |
+ packet.HasExtension<AbsoluteSendTime>() || |
+ packet.HasExtension<TransmissionOffset>(); |
+} |
+ |
} // namespace |
-FlexfecReceiver::FlexfecReceiver(uint32_t ssrc, |
- uint32_t protected_media_ssrc, |
- RecoveredPacketReceiver* callback) |
+FlexfecReceiver::FlexfecReceiver( |
+ uint32_t ssrc, |
+ uint32_t protected_media_ssrc, |
+ RecoveredPacketReceiver* recovered_packet_receiver, |
+ RemoteBitrateEstimator* remote_bitrate_estimator) |
: ssrc_(ssrc), |
protected_media_ssrc_(protected_media_ssrc), |
erasure_code_(ForwardErrorCorrection::CreateFlexfec()), |
- callback_(callback), |
+ recovered_packet_receiver_(recovered_packet_receiver), |
+ remote_bitrate_estimator_(remote_bitrate_estimator), |
clock_(Clock::GetRealTimeClock()), |
last_recovered_packet_ms_(-1) { |
// It's OK to create this object on a different thread/task queue than |
@@ -47,11 +57,10 @@ FlexfecReceiver::FlexfecReceiver(uint32_t ssrc, |
FlexfecReceiver::~FlexfecReceiver() = default; |
-bool FlexfecReceiver::AddAndProcessReceivedPacket(const uint8_t* packet, |
- size_t packet_length) { |
+bool FlexfecReceiver::AddAndProcessReceivedPacket(RtpPacketReceived packet) { |
RTC_DCHECK(sequence_checker_.CalledSequentially()); |
- if (!AddReceivedPacket(packet, packet_length)) { |
+ if (!AddReceivedPacket(std::move(packet))) { |
return false; |
} |
return ProcessReceivedPackets(); |
@@ -62,42 +71,40 @@ FecPacketCounter FlexfecReceiver::GetPacketCounter() const { |
return packet_counter_; |
} |
-bool FlexfecReceiver::AddReceivedPacket(const uint8_t* packet, |
- size_t packet_length) { |
+bool FlexfecReceiver::AddReceivedPacket(RtpPacketReceived packet) { |
RTC_DCHECK(sequence_checker_.CalledSequentially()); |
// RTP packets with a full base header (12 bytes), but without payload, |
// could conceivably be useful in the decoding. Therefore we check |
- // with a strict inequality here. |
- if (packet_length < kRtpHeaderSize) { |
- LOG(LS_WARNING) << "Truncated packet, discarding."; |
- return false; |
- } |
- |
- // TODO(brandtr): Consider how to handle received FlexFEC packets and |
- // the bandwidth estimator. |
- RtpPacketReceived parsed_packet; |
- if (!parsed_packet.Parse(packet, packet_length)) { |
- return false; |
- } |
+ // with a non-strict inequality here. |
+ RTC_DCHECK_GE(packet.size(), kRtpHeaderSize); |
// Demultiplex based on SSRC, and insert into erasure code decoder. |
std::unique_ptr<ReceivedPacket> received_packet(new ReceivedPacket()); |
- received_packet->seq_num = parsed_packet.SequenceNumber(); |
- received_packet->ssrc = parsed_packet.Ssrc(); |
+ received_packet->seq_num = packet.SequenceNumber(); |
+ received_packet->ssrc = packet.Ssrc(); |
if (received_packet->ssrc == ssrc_) { |
- // This is a FEC packet belonging to this FlexFEC stream. |
- if (parsed_packet.payload_size() < kMinFlexfecHeaderSize) { |
+ // This is a FlexFEC packet. |
+ if (packet.payload_size() < kMinFlexfecHeaderSize) { |
LOG(LS_WARNING) << "Truncated FlexFEC packet, discarding."; |
return false; |
} |
received_packet->is_fec = true; |
++packet_counter_.num_fec_packets; |
+ |
+ // Notify BWE. |
danilchap
2016/12/13 14:11:24
why is it done all the way down here rather than i
brandtr
2016/12/14 12:55:49
I forgot that Call demuxes based on SSRC, so we co
|
+ if (HasBweExtension(packet)) { |
+ RTPHeader header; |
+ packet.GetHeader(&header); |
+ remote_bitrate_estimator_->IncomingPacket(packet.arrival_time_ms(), |
+ packet.payload_size(), header); |
+ } |
+ |
// 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<Packet>(new Packet()); |
- auto payload = parsed_packet.payload(); |
+ auto payload = packet.payload(); |
memcpy(received_packet->pkt->data, payload.data(), payload.size()); |
received_packet->pkt->length = payload.size(); |
} else { |
@@ -107,13 +114,14 @@ bool FlexfecReceiver::AddReceivedPacket(const uint8_t* packet, |
return false; |
} |
received_packet->is_fec = false; |
+ |
// Insert entire packet into erasure code. |
// TODO(brandtr): Remove this memcpy too. |
received_packet->pkt = rtc::scoped_refptr<Packet>(new Packet()); |
- memcpy(received_packet->pkt->data, parsed_packet.data(), |
- parsed_packet.size()); |
- received_packet->pkt->length = parsed_packet.size(); |
+ memcpy(received_packet->pkt->data, packet.data(), packet.size()); |
+ received_packet->pkt->length = packet.size(); |
} |
+ |
received_packets_.push_back(std::move(received_packet)); |
++packet_counter_.num_packets; |
@@ -145,8 +153,8 @@ bool FlexfecReceiver::ProcessReceivedPackets() { |
continue; |
} |
++packet_counter_.num_recovered_packets; |
- if (!callback_->OnRecoveredPacket(recovered_packet->pkt->data, |
- recovered_packet->pkt->length)) { |
+ if (!recovered_packet_receiver_->OnRecoveredPacket( |
+ recovered_packet->pkt->data, recovered_packet->pkt->length)) { |
return false; |
} |
recovered_packet->returned = true; |