blob: 45ce1c47a5d3cd38e1f2ec920ce66b57270b0e8c [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#include "typedefs.h"
16
17#include "critical_section_wrapper.h"
18
19#ifndef NULL
20 #define NULL 0
21#endif
22
23namespace webrtc {
24class TMMBRSet
25{
26public:
27 TMMBRSet();
28 ~TMMBRSet();
29
30 void VerifyAndAllocateSet(WebRtc_UWord32 minimumSize);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000031 void VerifyAndAllocateSetKeepingData(WebRtc_UWord32 minimumSize);
32 // Number of valid data items in set.
33 WebRtc_UWord32 lengthOfSet() const { return _lengthOfSet; }
34 // Presently allocated max size of set.
35 WebRtc_UWord32 sizeOfSet() const { return _sizeOfSet; }
36 void clearSet() {
37 _lengthOfSet = 0;
38 }
39 WebRtc_UWord32 Tmmbr(int i) const {
40 return _data.at(i).tmmbr;
41 }
42 WebRtc_UWord32 PacketOH(int i) const {
43 return _data.at(i).packet_oh;
44 }
45 WebRtc_UWord32 Ssrc(int i) const {
46 return _data.at(i).ssrc;
47 }
48 void SetEntry(unsigned int i,
49 WebRtc_UWord32 tmmbrSet,
50 WebRtc_UWord32 packetOHSet,
51 WebRtc_UWord32 ssrcSet);
niklase@google.com470e71d2011-07-07 08:21:25 +000052
hta@webrtc.org54536bb2012-05-03 14:07:23 +000053 void AddEntry(WebRtc_UWord32 tmmbrSet,
54 WebRtc_UWord32 packetOHSet,
55 WebRtc_UWord32 ssrcSet);
56
57 // Remove one entry from table, and move all others down.
58 void RemoveEntry(WebRtc_UWord32 sourceIdx);
59
60 void SwapEntries(WebRtc_UWord32 firstIdx,
61 WebRtc_UWord32 secondIdx);
62
63 // Set entry data to zero, but keep it in table.
64 void ClearEntry(WebRtc_UWord32 idx);
65
66 private:
67 class SetElement {
68 public:
69 SetElement() : tmmbr(0), packet_oh(0), ssrc(0) {}
70 WebRtc_UWord32 tmmbr;
71 WebRtc_UWord32 packet_oh;
72 WebRtc_UWord32 ssrc;
73 };
74
75 std::vector<SetElement> _data;
76 // Number of places allocated.
77 WebRtc_UWord32 _sizeOfSet;
78 // NUmber of places currently in use.
79 WebRtc_UWord32 _lengthOfSet;
niklase@google.com470e71d2011-07-07 08:21:25 +000080};
81
82class TMMBRHelp
83{
84public:
pwestin@webrtc.orgcac78782012-04-05 08:30:10 +000085 TMMBRHelp();
niklase@google.com470e71d2011-07-07 08:21:25 +000086 virtual ~TMMBRHelp();
87
88 TMMBRSet* BoundingSet(); // used for debuging
89 TMMBRSet* CandidateSet();
90 TMMBRSet* BoundingSetToSend();
91
92 TMMBRSet* VerifyAndAllocateCandidateSet(const WebRtc_UWord32 minimumSize);
93 WebRtc_Word32 FindTMMBRBoundingSet(TMMBRSet*& boundingSet);
pwestin@webrtc.orgcac78782012-04-05 08:30:10 +000094 WebRtc_Word32 SetTMMBRBoundingSetToSend(
95 const TMMBRSet* boundingSetToSend,
96 const WebRtc_UWord32 maxBitrateKbit);
niklase@google.com470e71d2011-07-07 08:21:25 +000097
pwestin@webrtc.orgcac78782012-04-05 08:30:10 +000098 bool IsOwner(const WebRtc_UWord32 ssrc, const WebRtc_UWord32 length) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000099
pwestin@webrtc.orgcac78782012-04-05 08:30:10 +0000100 bool CalcMinBitRate(WebRtc_UWord32* minBitrateKbit) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
102protected:
103 TMMBRSet* VerifyAndAllocateBoundingSet(WebRtc_UWord32 minimumSize);
104 WebRtc_Word32 VerifyAndAllocateBoundingSetToSend(WebRtc_UWord32 minimumSize);
105
106 WebRtc_Word32 FindTMMBRBoundingSet(WebRtc_Word32 numCandidates, TMMBRSet& candidateSet);
107
108private:
henrike@webrtc.org65573f22011-12-13 19:17:27 +0000109 CriticalSectionWrapper* _criticalSection;
niklase@google.com470e71d2011-07-07 08:21:25 +0000110 TMMBRSet _candidateSet;
111 TMMBRSet _boundingSet;
112 TMMBRSet _boundingSetToSend;
113
114 float* _ptrIntersectionBoundingSet;
115 float* _ptrMaxPRBoundingSet;
116};
117} // namespace webrtc
118
119#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_TMMBR_HELP_H_