blob: 29bc70c0cd3bcb9a105eea74d177b2149de423e7 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.orgcac78782012-04-05 08:30:10 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_TMMBR_HELP_H_
12#define WEBRTC_MODULES_RTP_RTCP_SOURCE_TMMBR_HELP_H_
13
hta@webrtc.org54536bb2012-05-03 14:07:23 +000014#include <vector>
niklase@google.com470e71d2011-07-07 08:21:25 +000015
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000016#include "webrtc/typedefs.h"
17#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000018
19namespace webrtc {
20class TMMBRSet
21{
22public:
23 TMMBRSet();
24 ~TMMBRSet();
25
pbos@webrtc.org2f446732013-04-08 11:08:41 +000026 void VerifyAndAllocateSet(uint32_t minimumSize);
27 void VerifyAndAllocateSetKeepingData(uint32_t minimumSize);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000028 // Number of valid data items in set.
pbos@webrtc.org2f446732013-04-08 11:08:41 +000029 uint32_t lengthOfSet() const { return _lengthOfSet; }
hta@webrtc.org54536bb2012-05-03 14:07:23 +000030 // Presently allocated max size of set.
pbos@webrtc.org2f446732013-04-08 11:08:41 +000031 uint32_t sizeOfSet() const { return _sizeOfSet; }
hta@webrtc.org54536bb2012-05-03 14:07:23 +000032 void clearSet() {
33 _lengthOfSet = 0;
34 }
pbos@webrtc.org2f446732013-04-08 11:08:41 +000035 uint32_t Tmmbr(int i) const {
hta@webrtc.org54536bb2012-05-03 14:07:23 +000036 return _data.at(i).tmmbr;
37 }
pbos@webrtc.org2f446732013-04-08 11:08:41 +000038 uint32_t PacketOH(int i) const {
hta@webrtc.org54536bb2012-05-03 14:07:23 +000039 return _data.at(i).packet_oh;
40 }
pbos@webrtc.org2f446732013-04-08 11:08:41 +000041 uint32_t Ssrc(int i) const {
hta@webrtc.org54536bb2012-05-03 14:07:23 +000042 return _data.at(i).ssrc;
43 }
44 void SetEntry(unsigned int i,
pbos@webrtc.org2f446732013-04-08 11:08:41 +000045 uint32_t tmmbrSet,
46 uint32_t packetOHSet,
47 uint32_t ssrcSet);
niklase@google.com470e71d2011-07-07 08:21:25 +000048
pbos@webrtc.org2f446732013-04-08 11:08:41 +000049 void AddEntry(uint32_t tmmbrSet,
50 uint32_t packetOHSet,
51 uint32_t ssrcSet);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000052
53 // Remove one entry from table, and move all others down.
pbos@webrtc.org2f446732013-04-08 11:08:41 +000054 void RemoveEntry(uint32_t sourceIdx);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000055
pbos@webrtc.org2f446732013-04-08 11:08:41 +000056 void SwapEntries(uint32_t firstIdx,
57 uint32_t secondIdx);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000058
59 // Set entry data to zero, but keep it in table.
pbos@webrtc.org2f446732013-04-08 11:08:41 +000060 void ClearEntry(uint32_t idx);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000061
62 private:
63 class SetElement {
64 public:
65 SetElement() : tmmbr(0), packet_oh(0), ssrc(0) {}
pbos@webrtc.org2f446732013-04-08 11:08:41 +000066 uint32_t tmmbr;
67 uint32_t packet_oh;
68 uint32_t ssrc;
hta@webrtc.org54536bb2012-05-03 14:07:23 +000069 };
70
71 std::vector<SetElement> _data;
72 // Number of places allocated.
pbos@webrtc.org2f446732013-04-08 11:08:41 +000073 uint32_t _sizeOfSet;
hta@webrtc.org54536bb2012-05-03 14:07:23 +000074 // NUmber of places currently in use.
pbos@webrtc.org2f446732013-04-08 11:08:41 +000075 uint32_t _lengthOfSet;
niklase@google.com470e71d2011-07-07 08:21:25 +000076};
77
78class TMMBRHelp
79{
80public:
pwestin@webrtc.orgcac78782012-04-05 08:30:10 +000081 TMMBRHelp();
niklase@google.com470e71d2011-07-07 08:21:25 +000082 virtual ~TMMBRHelp();
83
84 TMMBRSet* BoundingSet(); // used for debuging
85 TMMBRSet* CandidateSet();
86 TMMBRSet* BoundingSetToSend();
87
pbos@webrtc.org2f446732013-04-08 11:08:41 +000088 TMMBRSet* VerifyAndAllocateCandidateSet(const uint32_t minimumSize);
89 int32_t FindTMMBRBoundingSet(TMMBRSet*& boundingSet);
90 int32_t SetTMMBRBoundingSetToSend(
pwestin@webrtc.orgcac78782012-04-05 08:30:10 +000091 const TMMBRSet* boundingSetToSend,
pbos@webrtc.org2f446732013-04-08 11:08:41 +000092 const uint32_t maxBitrateKbit);
niklase@google.com470e71d2011-07-07 08:21:25 +000093
pbos@webrtc.org2f446732013-04-08 11:08:41 +000094 bool IsOwner(const uint32_t ssrc, const uint32_t length) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000095
pbos@webrtc.org2f446732013-04-08 11:08:41 +000096 bool CalcMinBitRate(uint32_t* minBitrateKbit) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000097
98protected:
pbos@webrtc.org2f446732013-04-08 11:08:41 +000099 TMMBRSet* VerifyAndAllocateBoundingSet(uint32_t minimumSize);
100 int32_t VerifyAndAllocateBoundingSetToSend(uint32_t minimumSize);
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000102 int32_t FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet);
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
104private:
henrike@webrtc.org65573f22011-12-13 19:17:27 +0000105 CriticalSectionWrapper* _criticalSection;
niklase@google.com470e71d2011-07-07 08:21:25 +0000106 TMMBRSet _candidateSet;
107 TMMBRSet _boundingSet;
108 TMMBRSet _boundingSetToSend;
109
110 float* _ptrIntersectionBoundingSet;
111 float* _ptrMaxPRBoundingSet;
112};
113} // namespace webrtc
114
115#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_TMMBR_HELP_H_