diff --git a/modules/rtp_rtcp/source/forward_error_correction.cc b/modules/rtp_rtcp/source/forward_error_correction.cc index 9156da629..4cef2eda9 100644 --- a/modules/rtp_rtcp/source/forward_error_correction.cc +++ b/modules/rtp_rtcp/source/forward_error_correction.cc @@ -32,7 +32,7 @@ const WebRtc_UWord8 kUlpHeaderSizeLBitSet = (2 + kMaskSizeLBitSet); // ULP header size in bytes (L bit is cleared). const WebRtc_UWord8 kUlpHeaderSizeLBitClear = (2 + kMaskSizeLBitClear); -//Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. +// Transport header size in bytes. Assume UDP/IPv4 as a reasonable minimum. const WebRtc_UWord8 kTransportOverhead = 28; // @@ -118,13 +118,12 @@ ForwardErrorCorrection::GenerateFEC(const ListWrapper& mediaPacketList, (lBit == 1)? kUlpHeaderSizeLBitSet : kUlpHeaderSizeLBitClear; const WebRtc_UWord16 fecRtpOffset = kFecHeaderSize + ulpHeaderSize - kRtpHeaderSize; - const WebRtc_UWord16 maxMediaPackets = numMaskBytes * 8; - if (numMediaPackets > maxMediaPackets) + if (numMediaPackets > kMaxMediaPackets) { WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, "%s can only protect %d media packets per frame; %d requested", - __FUNCTION__, maxMediaPackets, numMediaPackets); + __FUNCTION__, kMaxMediaPackets, numMediaPackets); return -1; } @@ -174,7 +173,8 @@ ForwardErrorCorrection::GenerateFEC(const ListWrapper& mediaPacketList, } // Result in Q0 with an unsigned round. - WebRtc_UWord32 numFecPackets = (numMediaPackets * protectionFactor + (1 << 7)) >> 8; + WebRtc_UWord32 numFecPackets = (numMediaPackets * protectionFactor + + (1 << 7)) >> 8; if (numFecPackets == 0) { return 0; @@ -283,8 +283,8 @@ ForwardErrorCorrection::GenerateFEC(const ListWrapper& mediaPacketList, { //Note: This shouldn't happen: means packet mask is wrong or poorly designed WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, - "Packet mask has row of zeros %d %d", - numMediaPackets, numFecPackets); + "Packet mask has row of zeros %d %d %d ", + numMediaPackets, numImportantPackets, numFecPackets); delete packetMask; return -1; diff --git a/modules/rtp_rtcp/source/forward_error_correction.h b/modules/rtp_rtcp/source/forward_error_correction.h index 2c9ff3f24..275643b4a 100644 --- a/modules/rtp_rtcp/source/forward_error_correction.h +++ b/modules/rtp_rtcp/source/forward_error_correction.h @@ -23,6 +23,10 @@ namespace webrtc { class ForwardErrorCorrection { public: + + // Maximum number of media packets we can protect + static const int kMaxMediaPackets = 48; + /** * The ListWrapper parameters of #GenerateFEC() should reference structs of this type. */ diff --git a/modules/rtp_rtcp/source/rtp_sender_video.cc b/modules/rtp_rtcp/source/rtp_sender_video.cc index f0d3168de..a02c08e6d 100644 --- a/modules/rtp_rtcp/source/rtp_sender_video.cc +++ b/modules/rtp_rtcp/source/rtp_sender_video.cc @@ -163,7 +163,12 @@ RTPSenderVideo::SendVideoPacket(const FrameType frameType, // Add packet to FEC list _rtpPacketListFec.PushBack(ptrGenericFEC); - _mediaPacketListFec.PushBack(ptrGenericFEC->pkt); + // FEC can only protect up to kMaxMediaPackets packets + if (_mediaPacketListFec.GetSize() < + ForwardErrorCorrection::kMaxMediaPackets) + { + _mediaPacketListFec.PushBack(ptrGenericFEC->pkt); + } // Last packet in frame if (markerBit) @@ -182,6 +187,14 @@ RTPSenderVideo::SendVideoPacket(const FrameType frameType, // Replace payload and clear marker bit. lastMediaRtpHeader.data[1] = _payloadTypeRED; + // Number of first partition packets cannot exceed kMaxMediaPackets + if (_numberFirstPartition > + ForwardErrorCorrection::kMaxMediaPackets) + { + _numberFirstPartition = + ForwardErrorCorrection::kMaxMediaPackets; + } + retVal = _fec.GenerateFEC(_mediaPacketListFec, _fecProtectionFactor, _numberFirstPartition, fecPacketList); while(!_rtpPacketListFec.Empty())