Fix division by zero in FindTMMBRBoundingSet

BUG=webrtc:5490

Review URL: https://codereview.webrtc.org/1727273003

Cr-Commit-Position: refs/heads/master@{#11749}
This commit is contained in:
danilchap 2016-02-24 09:23:37 -08:00 committed by Commit bot
parent 07fb9be37f
commit f6ff9714c0

View File

@ -15,6 +15,7 @@
#include <limits> #include <limits>
#include "webrtc/base/checks.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
namespace webrtc { namespace webrtc {
@ -300,6 +301,7 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
&& j != currentMinIndexTMMBR) && j != currentMinIndexTMMBR)
{ {
candidateSet.ClearEntry(j); candidateSet.ClearEntry(j);
numCandidates--;
} }
} }
} }
@ -336,9 +338,15 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
// set intersection value // set intersection value
_ptrIntersectionBoundingSet[numBoundingSet] = 0; _ptrIntersectionBoundingSet[numBoundingSet] = 0;
// calculate its maximum packet rate (where its line crosses x-axis) // calculate its maximum packet rate (where its line crosses x-axis)
_ptrMaxPRBoundingSet[numBoundingSet] uint32_t packet_overhead_bits = 8 * _boundingSet.PacketOH(numBoundingSet);
= _boundingSet.Tmmbr(numBoundingSet) * 1000 if (packet_overhead_bits == 0) {
/ float(8 * _boundingSet.PacketOH(numBoundingSet)); // Avoid division by zero.
_ptrMaxPRBoundingSet[numBoundingSet] = std::numeric_limits<float>::max();
} else {
_ptrMaxPRBoundingSet[numBoundingSet] =
_boundingSet.Tmmbr(numBoundingSet) * 1000 /
static_cast<float>(packet_overhead_bits);
}
numBoundingSet++; numBoundingSet++;
// remove from candidate list // remove from candidate list
candidateSet.ClearEntry(minIndexTMMBR); candidateSet.ClearEntry(minIndexTMMBR);
@ -364,10 +372,10 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
} }
bool getNewCandidate = true; bool getNewCandidate = true;
int curCandidateTMMBR = 0; uint32_t curCandidateTMMBR = 0;
int curCandidateIndex = 0; size_t curCandidateIndex = 0;
int curCandidatePacketOH = 0; uint32_t curCandidatePacketOH = 0;
int curCandidateSSRC = 0; uint32_t curCandidateSSRC = 0;
do do
{ {
if (getNewCandidate) if (getNewCandidate)
@ -389,6 +397,8 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
// 6. Calculate packet rate and intersection of the current // 6. Calculate packet rate and intersection of the current
// line with line of last tuple in selected list // line with line of last tuple in selected list
RTC_DCHECK_NE(curCandidatePacketOH,
_boundingSet.PacketOH(numBoundingSet - 1));
float packetRate float packetRate
= float(curCandidateTMMBR = float(curCandidateTMMBR
- _boundingSet.Tmmbr(numBoundingSet-1))*1000 - _boundingSet.Tmmbr(numBoundingSet-1))*1000
@ -418,9 +428,12 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
curCandidatePacketOH, curCandidatePacketOH,
curCandidateSSRC); curCandidateSSRC);
_ptrIntersectionBoundingSet[numBoundingSet] = packetRate; _ptrIntersectionBoundingSet[numBoundingSet] = packetRate;
_ptrMaxPRBoundingSet[numBoundingSet] float packet_overhead_bits =
= _boundingSet.Tmmbr(numBoundingSet)*1000 8 * _boundingSet.PacketOH(numBoundingSet);
/ float(8*_boundingSet.PacketOH(numBoundingSet)); RTC_DCHECK_NE(packet_overhead_bits, 0.0f);
_ptrMaxPRBoundingSet[numBoundingSet] =
_boundingSet.Tmmbr(numBoundingSet) * 1000 /
packet_overhead_bits;
numBoundingSet++; numBoundingSet++;
} }
numCandidates--; numCandidates--;