Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Unified Diff: webrtc/modules/rtp_rtcp/source/tmmbr_help.cc

Issue 1989363006: TMMBRHelp::FindBoundingSet function cleaned (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: change function signature and remove now unused functions Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/tmmbr_help.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 43d3a82ab28b3f0570d43873b75e96b8f112c479..022465346ee8c7d15cf60f1f5d8cea0bd4554ba5 100644
--- a/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc
+++ b/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc
@@ -10,10 +10,9 @@
#include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
-#include <assert.h>
-#include <string.h>
-
+#include <algorithm>
#include <limits>
+#include <memory>
#include "webrtc/base/checks.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
@@ -57,53 +56,6 @@ void TMMBRSet::RemoveEntry(uint32_t sourceIdx) {
erase(begin() + sourceIdx);
}
-void TMMBRSet::SwapEntries(uint32_t i, uint32_t j) {
- using std::swap;
- swap((*this)[i], (*this)[j]);
-}
-
-void TMMBRSet::ClearEntry(uint32_t idx) {
- SetEntry(idx, 0, 0, 0);
-}
-
-TMMBRHelp::TMMBRHelp()
- : _candidateSet(),
- _boundingSet(),
- _ptrIntersectionBoundingSet(NULL),
- _ptrMaxPRBoundingSet(NULL) {
-}
-
-TMMBRHelp::~TMMBRHelp() {
- delete [] _ptrIntersectionBoundingSet;
- delete [] _ptrMaxPRBoundingSet;
- _ptrIntersectionBoundingSet = 0;
- _ptrMaxPRBoundingSet = 0;
-}
-
-TMMBRSet*
-TMMBRHelp::VerifyAndAllocateBoundingSet(uint32_t minimumSize)
-{
- rtc::CritScope lock(&_criticalSection);
-
- if(minimumSize > _boundingSet.capacity())
- {
- // make sure that our buffers are big enough
- if(_ptrIntersectionBoundingSet)
- {
- delete [] _ptrIntersectionBoundingSet;
- delete [] _ptrMaxPRBoundingSet;
- }
- _ptrIntersectionBoundingSet = new float[minimumSize];
- _ptrMaxPRBoundingSet = new float[minimumSize];
- }
- _boundingSet.VerifyAndAllocateSet(minimumSize);
- return &_boundingSet;
-}
-
-TMMBRSet* TMMBRHelp::BoundingSet() {
- return &_boundingSet;
-}
-
TMMBRSet*
TMMBRHelp::VerifyAndAllocateCandidateSet(uint32_t minimumSize)
{
@@ -139,7 +91,7 @@ TMMBRHelp::FindTMMBRBoundingSet(TMMBRSet*& boundingSet)
else
{
// make sure this is zero if tmmbr = 0
- assert(_candidateSet.PacketOH(i) == 0);
+ RTC_DCHECK_EQ(_candidateSet.PacketOH(i), 0u);
// Old code:
// _candidateSet.ptrPacketOHSet[i] = 0;
}
@@ -151,7 +103,8 @@ TMMBRHelp::FindTMMBRBoundingSet(TMMBRSet*& boundingSet)
uint32_t numBoundingSet = 0;
if (numSetCandidates > 0)
{
- numBoundingSet = FindTMMBRBoundingSet(numSetCandidates, candidateSet);
+ FindBoundingSet(std::move(candidateSet), &_boundingSet);
+ numBoundingSet = _boundingSet.size();
if(numBoundingSet < 1 || (numBoundingSet > _candidateSet.size()))
{
return -1;
@@ -162,56 +115,46 @@ TMMBRHelp::FindTMMBRBoundingSet(TMMBRSet*& boundingSet)
}
-int32_t
-TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
+void
+TMMBRHelp::FindBoundingSet(std::vector<rtcp::TmmbItem> candidateSet,
+ std::vector<rtcp::TmmbItem>* boundingSet)
{
- rtc::CritScope lock(&_criticalSection);
+ RTC_DCHECK(boundingSet);
+ RTC_DCHECK(!candidateSet.empty());
+ size_t numCandidates = candidateSet.size();
uint32_t numBoundingSet = 0;
- VerifyAndAllocateBoundingSet(candidateSet.capacity());
+ boundingSet->clear();
+ boundingSet->reserve(candidateSet.size());
if (numCandidates == 1)
{
- for (uint32_t i = 0; i < candidateSet.size(); i++)
- {
- if (candidateSet.Tmmbr(i) > 0)
- {
- _boundingSet.AddEntry(candidateSet.Tmmbr(i),
- candidateSet.PacketOH(i),
- candidateSet.Ssrc(i));
- numBoundingSet++;
- }
- }
- return (numBoundingSet == 1) ? 1 : -1;
+ RTC_DCHECK(candidateSet[0].bitrate_bps());
+ *boundingSet = std::move(candidateSet);
+ return;
}
// 1. Sort by increasing packetOH
- for (int i = candidateSet.size() - 1; i >= 0; i--)
- {
- for (int j = 1; j <= i; j++)
- {
- if (candidateSet.PacketOH(j-1) > candidateSet.PacketOH(j))
- {
- candidateSet.SwapEntries(j-1, j);
- }
- }
- }
+ std::sort(candidateSet.begin(), candidateSet.end(),
+ [](const rtcp::TmmbItem& lhs, const rtcp::TmmbItem& rhs) {
+ return lhs.packet_overhead() < rhs.packet_overhead();
+ });
// 2. For tuples with same OH, keep the one w/ the lowest bitrate
for (uint32_t i = 0; i < candidateSet.size(); i++)
{
- if (candidateSet.Tmmbr(i) > 0)
+ if (candidateSet[i].bitrate_bps())
{
// get min bitrate for packets w/ same OH
- uint32_t currentPacketOH = candidateSet.PacketOH(i);
- uint32_t currentMinTMMBR = candidateSet.Tmmbr(i);
+ uint32_t currentPacketOH = candidateSet[i].packet_overhead();
+ uint32_t currentMinTMMBR = candidateSet[i].bitrate_bps();
uint32_t currentMinIndexTMMBR = i;
for (uint32_t j = i+1; j < candidateSet.size(); j++)
{
- if(candidateSet.PacketOH(j) == currentPacketOH)
+ if(candidateSet[j].packet_overhead() == currentPacketOH)
{
- if(candidateSet.Tmmbr(j) < currentMinTMMBR)
+ if(candidateSet[j].bitrate_bps() < currentMinTMMBR)
{
- currentMinTMMBR = candidateSet.Tmmbr(j);
+ currentMinTMMBR = candidateSet[j].bitrate_bps();
currentMinIndexTMMBR = j;
}
}
@@ -219,10 +162,10 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
// keep lowest bitrate
for (uint32_t j = 0; j < candidateSet.size(); j++)
{
- if(candidateSet.PacketOH(j) == currentPacketOH
+ if(candidateSet[j].packet_overhead() == currentPacketOH
&& j != currentMinIndexTMMBR)
{
- candidateSet.ClearEntry(j);
+ candidateSet[j].set_bitrate_bps(0);
numCandidates--;
}
}
@@ -234,9 +177,9 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
uint32_t minIndexTMMBR = 0;
for (uint32_t i = 0; i < candidateSet.size(); i++)
{
- if (candidateSet.Tmmbr(i) > 0)
+ if (candidateSet[i].bitrate_bps())
{
- minTMMBR = candidateSet.Tmmbr(i);
+ minTMMBR = candidateSet[i].bitrate_bps();
minIndexTMMBR = i;
break;
}
@@ -244,44 +187,44 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
for (uint32_t i = 0; i < candidateSet.size(); i++)
{
- if (candidateSet.Tmmbr(i) > 0 && candidateSet.Tmmbr(i) <= minTMMBR)
+ if (candidateSet[i].bitrate_bps() &&
+ candidateSet[i].bitrate_bps() <= minTMMBR)
{
// get min bitrate
- minTMMBR = candidateSet.Tmmbr(i);
+ minTMMBR = candidateSet[i].bitrate_bps();
minIndexTMMBR = i;
}
}
// first member of selected list
- _boundingSet.SetEntry(numBoundingSet,
- candidateSet.Tmmbr(minIndexTMMBR),
- candidateSet.PacketOH(minIndexTMMBR),
- candidateSet.Ssrc(minIndexTMMBR));
+ boundingSet->push_back(candidateSet[minIndexTMMBR]);
+ std::unique_ptr<float[]> _ptrIntersectionBoundingSet(new float[numCandidates]);
+ std::unique_ptr<float[]> _ptrMaxPRBoundingSet(new float[numCandidates]);
// set intersection value
_ptrIntersectionBoundingSet[numBoundingSet] = 0;
// calculate its maximum packet rate (where its line crosses x-axis)
- uint32_t packet_overhead_bits = 8 * _boundingSet.PacketOH(numBoundingSet);
+ uint32_t packet_overhead_bits = 8 * boundingSet->back().packet_overhead();
if (packet_overhead_bits == 0) {
// Avoid division by zero.
_ptrMaxPRBoundingSet[numBoundingSet] = std::numeric_limits<float>::max();
} else {
_ptrMaxPRBoundingSet[numBoundingSet] =
- _boundingSet.Tmmbr(numBoundingSet) * 1000 /
+ boundingSet->back().bitrate_bps() /
static_cast<float>(packet_overhead_bits);
}
numBoundingSet++;
// remove from candidate list
- candidateSet.ClearEntry(minIndexTMMBR);
+ candidateSet[minIndexTMMBR].set_bitrate_bps(0);
numCandidates--;
// 4. Discard from candidate list all tuple w/ lower OH
// (next tuple must be steeper)
for (uint32_t i = 0; i < candidateSet.size(); i++)
{
- if(candidateSet.Tmmbr(i) > 0
- && candidateSet.PacketOH(i) < _boundingSet.PacketOH(0))
+ if(candidateSet[i].bitrate_bps()
+ && candidateSet[i].packet_overhead() < boundingSet->front().packet_overhead())
{
- candidateSet.ClearEntry(i);
+ candidateSet[i].set_bitrate_bps(0);
numCandidates--;
}
}
@@ -289,15 +232,12 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
if (numCandidates == 0)
{
// Should be true already:_boundingSet.lengthOfSet = numBoundingSet;
- assert(_boundingSet.lengthOfSet() == numBoundingSet);
- return numBoundingSet;
+ RTC_DCHECK_EQ(boundingSet->size(), numBoundingSet);
+ return;
}
bool getNewCandidate = true;
- uint32_t curCandidateTMMBR = 0;
- size_t curCandidateIndex = 0;
- uint32_t curCandidatePacketOH = 0;
- uint32_t curCandidateSSRC = 0;
+ rtcp::TmmbItem curCandidate;
do
{
if (getNewCandidate)
@@ -305,13 +245,10 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
// 5. Remove first remaining tuple from candidate list
for (uint32_t i = 0; i < candidateSet.size(); i++)
{
- if (candidateSet.Tmmbr(i) > 0)
+ if (candidateSet[i].bitrate_bps())
{
- curCandidateTMMBR = candidateSet.Tmmbr(i);
- curCandidatePacketOH = candidateSet.PacketOH(i);
- curCandidateSSRC = candidateSet.Ssrc(i);
- curCandidateIndex = i;
- candidateSet.ClearEntry(curCandidateIndex);
+ curCandidate = candidateSet[i];
+ candidateSet[i].set_bitrate_bps(0);
break;
}
}
@@ -319,13 +256,13 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
// 6. Calculate packet rate and intersection of the current
// line with line of last tuple in selected list
- RTC_DCHECK_NE(curCandidatePacketOH,
- _boundingSet.PacketOH(numBoundingSet - 1));
+ RTC_DCHECK_NE(curCandidate.packet_overhead(),
+ boundingSet->back().packet_overhead());
float packetRate
- = float(curCandidateTMMBR
- - _boundingSet.Tmmbr(numBoundingSet-1))*1000
- / (8*(curCandidatePacketOH
- - _boundingSet.PacketOH(numBoundingSet-1)));
+ = float(curCandidate.bitrate_bps()
+ - boundingSet->back().bitrate_bps())
+ / (8*(curCandidate.packet_overhead()
+ - boundingSet->back().packet_overhead()));
// 7. If the packet rate is equal or lower than intersection of
// last tuple in selected list,
@@ -334,9 +271,7 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
{
// remove last tuple and goto step 6
numBoundingSet--;
- _boundingSet.ClearEntry(numBoundingSet);
- _ptrIntersectionBoundingSet[numBoundingSet] = 0;
- _ptrMaxPRBoundingSet[numBoundingSet] = 0;
+ boundingSet->pop_back();
getNewCandidate = false;
} else
{
@@ -345,16 +280,13 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
// list
if (packetRate < _ptrMaxPRBoundingSet[numBoundingSet-1])
{
- _boundingSet.SetEntry(numBoundingSet,
- curCandidateTMMBR,
- curCandidatePacketOH,
- curCandidateSSRC);
+ boundingSet->push_back(curCandidate);
_ptrIntersectionBoundingSet[numBoundingSet] = packetRate;
float packet_overhead_bits =
- 8 * _boundingSet.PacketOH(numBoundingSet);
+ 8 * boundingSet->back().packet_overhead();
RTC_DCHECK_NE(packet_overhead_bits, 0.0f);
_ptrMaxPRBoundingSet[numBoundingSet] =
- _boundingSet.Tmmbr(numBoundingSet) * 1000 /
+ boundingSet->back().bitrate_bps() * 1000 /
danilchap 2016/05/20 13:38:53 overlooked removing *1000 here, removed in patchse
packet_overhead_bits;
numBoundingSet++;
}
@@ -365,7 +297,7 @@ TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet)
// 9. Go back to step 5 if any tuple remains in candidate list
} while (numCandidates > 0);
- return numBoundingSet;
+ RTC_DCHECK_EQ(boundingSet->size(), numBoundingSet);
}
bool TMMBRHelp::IsOwner(const uint32_t ssrc,
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/tmmbr_help.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698