niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 14 | #include <vector> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 16 | #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
pbos@webrtc.org | 96edd56 | 2013-07-10 15:40:42 +0000 | [diff] [blame] | 17 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | class TMMBRSet |
| 21 | { |
| 22 | public: |
| 23 | TMMBRSet(); |
| 24 | ~TMMBRSet(); |
| 25 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 26 | void VerifyAndAllocateSet(uint32_t minimumSize); |
| 27 | void VerifyAndAllocateSetKeepingData(uint32_t minimumSize); |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 28 | // Number of valid data items in set. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 29 | uint32_t lengthOfSet() const { return _lengthOfSet; } |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 30 | // Presently allocated max size of set. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 31 | uint32_t sizeOfSet() const { return _sizeOfSet; } |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 32 | void clearSet() { |
| 33 | _lengthOfSet = 0; |
| 34 | } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 35 | uint32_t Tmmbr(int i) const { |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 36 | return _data.at(i).tmmbr; |
| 37 | } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 38 | uint32_t PacketOH(int i) const { |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 39 | return _data.at(i).packet_oh; |
| 40 | } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 41 | uint32_t Ssrc(int i) const { |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 42 | return _data.at(i).ssrc; |
| 43 | } |
| 44 | void SetEntry(unsigned int i, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 45 | uint32_t tmmbrSet, |
| 46 | uint32_t packetOHSet, |
| 47 | uint32_t ssrcSet); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 49 | void AddEntry(uint32_t tmmbrSet, |
| 50 | uint32_t packetOHSet, |
| 51 | uint32_t ssrcSet); |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 52 | |
| 53 | // Remove one entry from table, and move all others down. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 54 | void RemoveEntry(uint32_t sourceIdx); |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 55 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 56 | void SwapEntries(uint32_t firstIdx, |
| 57 | uint32_t secondIdx); |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 58 | |
| 59 | // Set entry data to zero, but keep it in table. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 60 | void ClearEntry(uint32_t idx); |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 61 | |
| 62 | private: |
| 63 | class SetElement { |
| 64 | public: |
| 65 | SetElement() : tmmbr(0), packet_oh(0), ssrc(0) {} |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 66 | uint32_t tmmbr; |
| 67 | uint32_t packet_oh; |
| 68 | uint32_t ssrc; |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | std::vector<SetElement> _data; |
| 72 | // Number of places allocated. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 73 | uint32_t _sizeOfSet; |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 74 | // NUmber of places currently in use. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 75 | uint32_t _lengthOfSet; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | class TMMBRHelp |
| 79 | { |
| 80 | public: |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 81 | TMMBRHelp(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | virtual ~TMMBRHelp(); |
| 83 | |
| 84 | TMMBRSet* BoundingSet(); // used for debuging |
| 85 | TMMBRSet* CandidateSet(); |
| 86 | TMMBRSet* BoundingSetToSend(); |
| 87 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 88 | TMMBRSet* VerifyAndAllocateCandidateSet(const uint32_t minimumSize); |
| 89 | int32_t FindTMMBRBoundingSet(TMMBRSet*& boundingSet); |
Peter Boström | 9d0c432 | 2016-02-16 17:59:27 +0100 | [diff] [blame] | 90 | int32_t SetTMMBRBoundingSetToSend(const TMMBRSet* boundingSetToSend); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 92 | bool IsOwner(const uint32_t ssrc, const uint32_t length) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 94 | bool CalcMinBitRate(uint32_t* minBitrateKbit) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | |
| 96 | protected: |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 97 | TMMBRSet* VerifyAndAllocateBoundingSet(uint32_t minimumSize); |
| 98 | int32_t VerifyAndAllocateBoundingSetToSend(uint32_t minimumSize); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 100 | int32_t FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | |
| 102 | private: |
henrike@webrtc.org | 65573f2 | 2011-12-13 19:17:27 +0000 | [diff] [blame] | 103 | CriticalSectionWrapper* _criticalSection; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | TMMBRSet _candidateSet; |
| 105 | TMMBRSet _boundingSet; |
| 106 | TMMBRSet _boundingSetToSend; |
| 107 | |
| 108 | float* _ptrIntersectionBoundingSet; |
| 109 | float* _ptrMaxPRBoundingSet; |
| 110 | }; |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 111 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 112 | |
| 113 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_TMMBR_HELP_H_ |