| Index: webrtc/modules/rtp_rtcp/source/tmmbr_help.cc
|
| diff --git a/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc b/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc
|
| index 5c090504ca07fe5b4f9f0bb4838f3ef55238a7f3..57d003fe16f0f75699cdca8554d3f8ae02573478 100644
|
| --- a/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc
|
| +++ b/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc
|
| @@ -15,84 +15,51 @@
|
|
|
| #include <limits>
|
|
|
| +#include "webrtc/base/checks.h"
|
| #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
|
|
| namespace webrtc {
|
| -TMMBRSet::TMMBRSet() :
|
| - _sizeOfSet(0),
|
| - _lengthOfSet(0)
|
| -{
|
| -}
|
| -
|
| -TMMBRSet::~TMMBRSet()
|
| -{
|
| - _sizeOfSet = 0;
|
| - _lengthOfSet = 0;
|
| -}
|
| -
|
| void
|
| TMMBRSet::VerifyAndAllocateSet(uint32_t minimumSize)
|
| {
|
| - if(minimumSize > _sizeOfSet)
|
| - {
|
| - // make sure that our buffers are big enough
|
| - _data.resize(minimumSize);
|
| - _sizeOfSet = minimumSize;
|
| - }
|
| - // reset memory
|
| - for(uint32_t i = 0; i < _sizeOfSet; i++)
|
| - {
|
| - _data.at(i).tmmbr = 0;
|
| - _data.at(i).packet_oh = 0;
|
| - _data.at(i).ssrc = 0;
|
| - }
|
| - _lengthOfSet = 0;
|
| + clear();
|
| + reserve(minimumSize);
|
| }
|
|
|
| void
|
| TMMBRSet::VerifyAndAllocateSetKeepingData(uint32_t minimumSize)
|
| {
|
| - if(minimumSize > _sizeOfSet)
|
| - {
|
| - {
|
| - _data.resize(minimumSize);
|
| - }
|
| - _sizeOfSet = minimumSize;
|
| - }
|
| + reserve(minimumSize);
|
| }
|
|
|
| void TMMBRSet::SetEntry(unsigned int i,
|
| uint32_t tmmbrSet,
|
| uint32_t packetOHSet,
|
| uint32_t ssrcSet) {
|
| - assert(i < _sizeOfSet);
|
| - _data.at(i).tmmbr = tmmbrSet;
|
| - _data.at(i).packet_oh = packetOHSet;
|
| - _data.at(i).ssrc = ssrcSet;
|
| - if (i >= _lengthOfSet) {
|
| - _lengthOfSet = i + 1;
|
| + RTC_DCHECK_LT(i, capacity());
|
| + if (i >= size()) {
|
| + resize(i+1);
|
| }
|
| + (*this)[i].set_bitrate_bps(tmmbrSet * 1000);
|
| + (*this)[i].set_packet_overhead(packetOHSet);
|
| + (*this)[i].set_ssrc(ssrcSet);
|
| }
|
|
|
| void TMMBRSet::AddEntry(uint32_t tmmbrSet,
|
| uint32_t packetOHSet,
|
| uint32_t ssrcSet) {
|
| - assert(_lengthOfSet < _sizeOfSet);
|
| - SetEntry(_lengthOfSet, tmmbrSet, packetOHSet, ssrcSet);
|
| + RTC_DCHECK_LT(size(), capacity());
|
| + SetEntry(size(), tmmbrSet, packetOHSet, ssrcSet);
|
| }
|
|
|
| void TMMBRSet::RemoveEntry(uint32_t sourceIdx) {
|
| - assert(sourceIdx < _lengthOfSet);
|
| - _data.erase(_data.begin() + sourceIdx);
|
| - _lengthOfSet--;
|
| - _data.resize(_sizeOfSet); // Ensure that size remains the same.
|
| + RTC_DCHECK_LT(sourceIdx, size());
|
| + erase(begin() + sourceIdx);
|
| }
|
|
|
| void TMMBRSet::SwapEntries(uint32_t i, uint32_t j) {
|
| - SetElement temp;
|
| - temp = _data[i];
|
| - _data[i] = _data[j];
|
| - _data[j] = temp;
|
| + using std::swap;
|
| + swap((*this)[i], (*this)[j]);
|
| }
|
|
|
| void TMMBRSet::ClearEntry(uint32_t idx) {
|
| @@ -121,7 +88,7 @@ TMMBRHelp::VerifyAndAllocateBoundingSet(uint32_t minimumSize)
|
| {
|
| CriticalSectionScoped lock(_criticalSection);
|
|
|
| - if(minimumSize > _boundingSet.sizeOfSet())
|
| + if(minimumSize > _boundingSet.capacity())
|
| {
|
| // make sure that our buffers are big enough
|
| if(_ptrIntersectionBoundingSet)
|
| @@ -201,10 +168,9 @@ TMMBRHelp::FindTMMBRBoundingSet(TMMBRSet*& boundingSet)
|
|
|
| // Work on local variable, will be modified
|
| TMMBRSet candidateSet;
|
| - candidateSet.VerifyAndAllocateSet(_candidateSet.sizeOfSet());
|
| + candidateSet.VerifyAndAllocateSet(_candidateSet.capacity());
|
|
|
| - // TODO(hta) Figure out if this should be lengthOfSet instead.
|
| - for (uint32_t i = 0; i < _candidateSet.sizeOfSet(); i++)
|
| + for (uint32_t i = 0; i < _candidateSet.size(); i++)
|
| {
|
| if(_candidateSet.Tmmbr(i))
|
| {
|
| @@ -228,7 +194,7 @@ TMMBRHelp::FindTMMBRBoundingSet(TMMBRSet*& boundingSet)
|
| if (numSetCandidates > 0)
|
| {
|
| numBoundingSet = FindTMMBRBoundingSet(numSetCandidates, candidateSet);
|
| - if(numBoundingSet < 1 || (numBoundingSet > _candidateSet.sizeOfSet()))
|
| + if(numBoundingSet < 1 || (numBoundingSet > _candidateSet.size()))
|
| {
|
| return -1;
|
| }
|
| @@ -244,12 +210,11 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
|
| CriticalSectionScoped lock(_criticalSection);
|
|
|
| uint32_t numBoundingSet = 0;
|
| - VerifyAndAllocateBoundingSet(candidateSet.sizeOfSet());
|
| + VerifyAndAllocateBoundingSet(candidateSet.capacity());
|
|
|
| if (numCandidates == 1)
|
| {
|
| - // TODO(hta): lengthOfSet instead of sizeOfSet?
|
| - for (uint32_t i = 0; i < candidateSet.sizeOfSet(); i++)
|
| + for (uint32_t i = 0; i < candidateSet.size(); i++)
|
| {
|
| if (candidateSet.Tmmbr(i) > 0)
|
| {
|
| @@ -263,7 +228,7 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
|
| }
|
|
|
| // 1. Sort by increasing packetOH
|
| - for (int i = candidateSet.sizeOfSet() - 1; i >= 0; i--)
|
| + for (int i = candidateSet.size() - 1; i >= 0; i--)
|
| {
|
| for (int j = 1; j <= i; j++)
|
| {
|
| @@ -274,7 +239,7 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
|
| }
|
| }
|
| // 2. For tuples with same OH, keep the one w/ the lowest bitrate
|
| - for (uint32_t i = 0; i < candidateSet.sizeOfSet(); i++)
|
| + for (uint32_t i = 0; i < candidateSet.size(); i++)
|
| {
|
| if (candidateSet.Tmmbr(i) > 0)
|
| {
|
| @@ -282,7 +247,7 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
|
| uint32_t currentPacketOH = candidateSet.PacketOH(i);
|
| uint32_t currentMinTMMBR = candidateSet.Tmmbr(i);
|
| uint32_t currentMinIndexTMMBR = i;
|
| - for (uint32_t j = i+1; j < candidateSet.sizeOfSet(); j++)
|
| + for (uint32_t j = i+1; j < candidateSet.size(); j++)
|
| {
|
| if(candidateSet.PacketOH(j) == currentPacketOH)
|
| {
|
| @@ -294,7 +259,7 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
|
| }
|
| }
|
| // keep lowest bitrate
|
| - for (uint32_t j = 0; j < candidateSet.sizeOfSet(); j++)
|
| + for (uint32_t j = 0; j < candidateSet.size(); j++)
|
| {
|
| if(candidateSet.PacketOH(j) == currentPacketOH
|
| && j != currentMinIndexTMMBR)
|
| @@ -308,7 +273,7 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
|
| // (If more than 1, choose the one w/ highest OH).
|
| uint32_t minTMMBR = 0;
|
| uint32_t minIndexTMMBR = 0;
|
| - for (uint32_t i = 0; i < candidateSet.sizeOfSet(); i++)
|
| + for (uint32_t i = 0; i < candidateSet.size(); i++)
|
| {
|
| if (candidateSet.Tmmbr(i) > 0)
|
| {
|
| @@ -318,7 +283,7 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
|
| }
|
| }
|
|
|
| - for (uint32_t i = 0; i < candidateSet.sizeOfSet(); i++)
|
| + for (uint32_t i = 0; i < candidateSet.size(); i++)
|
| {
|
| if (candidateSet.Tmmbr(i) > 0 && candidateSet.Tmmbr(i) <= minTMMBR)
|
| {
|
| @@ -346,7 +311,7 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
|
|
|
| // 4. Discard from candidate list all tuple w/ lower OH
|
| // (next tuple must be steeper)
|
| - for (uint32_t i = 0; i < candidateSet.sizeOfSet(); i++)
|
| + for (uint32_t i = 0; i < candidateSet.size(); i++)
|
| {
|
| if(candidateSet.Tmmbr(i) > 0
|
| && candidateSet.PacketOH(i) < _boundingSet.PacketOH(0))
|
| @@ -373,7 +338,7 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
|
| if (getNewCandidate)
|
| {
|
| // 5. Remove first remaining tuple from candidate list
|
| - for (uint32_t i = 0; i < candidateSet.sizeOfSet(); i++)
|
| + for (uint32_t i = 0; i < candidateSet.size(); i++)
|
| {
|
| if (candidateSet.Tmmbr(i) > 0)
|
| {
|
| @@ -442,7 +407,7 @@ bool TMMBRHelp::IsOwner(const uint32_t ssrc,
|
| return false;
|
| }
|
| for(uint32_t i = 0;
|
| - (i < length) && (i < _boundingSet.sizeOfSet()); ++i) {
|
| + (i < length) && (i < _boundingSet.size()); ++i) {
|
| if(_boundingSet.Ssrc(i) == ssrc) {
|
| return true;
|
| }
|
| @@ -453,7 +418,7 @@ bool TMMBRHelp::IsOwner(const uint32_t ssrc,
|
| bool TMMBRHelp::CalcMinBitRate( uint32_t* minBitrateKbit) const {
|
| CriticalSectionScoped lock(_criticalSection);
|
|
|
| - if (_candidateSet.sizeOfSet() == 0) {
|
| + if (_candidateSet.size() == 0) {
|
| // Empty bounding set.
|
| return false;
|
| }
|
|
|