TMMBRSet become vector<rtcp::TmmbItem>
this is a slice of https://codereview.webrtc.org/1474693002/ All TMMBRSet functions intentionally left unchanged. Goal to make them obsolete, not to clear. BUG=webrtc:5565 Review URL: https://codereview.webrtc.org/1669323002 Cr-Commit-Position: refs/heads/master@{#11813}
This commit is contained in:
parent
dffb894a4c
commit
a4f31bd03a
@ -19,81 +19,47 @@
|
||||
#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) {
|
||||
@ -122,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)
|
||||
@ -202,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))
|
||||
{
|
||||
@ -229,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;
|
||||
}
|
||||
@ -245,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)
|
||||
{
|
||||
@ -264,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++)
|
||||
{
|
||||
@ -275,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)
|
||||
{
|
||||
@ -283,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)
|
||||
{
|
||||
@ -295,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)
|
||||
@ -310,7 +274,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)
|
||||
{
|
||||
@ -320,7 +284,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)
|
||||
{
|
||||
@ -354,7 +318,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))
|
||||
@ -381,7 +345,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)
|
||||
{
|
||||
@ -455,7 +419,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;
|
||||
}
|
||||
@ -466,7 +430,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;
|
||||
}
|
||||
|
||||
@ -12,34 +12,29 @@
|
||||
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_TMMBR_HELP_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmb_item.h"
|
||||
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
class TMMBRSet
|
||||
class TMMBRSet : public std::vector<rtcp::TmmbItem>
|
||||
{
|
||||
public:
|
||||
TMMBRSet();
|
||||
~TMMBRSet();
|
||||
|
||||
void VerifyAndAllocateSet(uint32_t minimumSize);
|
||||
void VerifyAndAllocateSetKeepingData(uint32_t minimumSize);
|
||||
// Number of valid data items in set.
|
||||
uint32_t lengthOfSet() const { return _lengthOfSet; }
|
||||
uint32_t lengthOfSet() const { return size(); }
|
||||
// Presently allocated max size of set.
|
||||
uint32_t sizeOfSet() const { return _sizeOfSet; }
|
||||
void clearSet() {
|
||||
_lengthOfSet = 0;
|
||||
}
|
||||
uint32_t sizeOfSet() const { return capacity(); }
|
||||
void clearSet() { clear(); }
|
||||
uint32_t Tmmbr(int i) const {
|
||||
return _data.at(i).tmmbr;
|
||||
return (*this)[i].bitrate_bps() / 1000;
|
||||
}
|
||||
uint32_t PacketOH(int i) const {
|
||||
return _data.at(i).packet_oh;
|
||||
return (*this)[i].packet_overhead();
|
||||
}
|
||||
uint32_t Ssrc(int i) const {
|
||||
return _data.at(i).ssrc;
|
||||
return (*this)[i].ssrc();
|
||||
}
|
||||
void SetEntry(unsigned int i,
|
||||
uint32_t tmmbrSet,
|
||||
@ -58,21 +53,6 @@ public:
|
||||
|
||||
// Set entry data to zero, but keep it in table.
|
||||
void ClearEntry(uint32_t idx);
|
||||
|
||||
private:
|
||||
class SetElement {
|
||||
public:
|
||||
SetElement() : tmmbr(0), packet_oh(0), ssrc(0) {}
|
||||
uint32_t tmmbr;
|
||||
uint32_t packet_oh;
|
||||
uint32_t ssrc;
|
||||
};
|
||||
|
||||
std::vector<SetElement> _data;
|
||||
// Number of places allocated.
|
||||
uint32_t _sizeOfSet;
|
||||
// NUmber of places currently in use.
|
||||
uint32_t _lengthOfSet;
|
||||
};
|
||||
|
||||
class TMMBRHelp
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user