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> |
danilchap | a4f31bd | 2016-02-29 05:26:01 -0800 | [diff] [blame^] | 15 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmb_item.h" |
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 { |
danilchap | a4f31bd | 2016-02-29 05:26:01 -0800 | [diff] [blame^] | 20 | class TMMBRSet : public std::vector<rtcp::TmmbItem> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | { |
| 22 | public: |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 23 | void VerifyAndAllocateSet(uint32_t minimumSize); |
| 24 | void VerifyAndAllocateSetKeepingData(uint32_t minimumSize); |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 25 | // Number of valid data items in set. |
danilchap | a4f31bd | 2016-02-29 05:26:01 -0800 | [diff] [blame^] | 26 | uint32_t lengthOfSet() const { return size(); } |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 27 | // Presently allocated max size of set. |
danilchap | a4f31bd | 2016-02-29 05:26:01 -0800 | [diff] [blame^] | 28 | uint32_t sizeOfSet() const { return capacity(); } |
| 29 | void clearSet() { clear(); } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 30 | uint32_t Tmmbr(int i) const { |
danilchap | a4f31bd | 2016-02-29 05:26:01 -0800 | [diff] [blame^] | 31 | return (*this)[i].bitrate_bps() / 1000; |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 32 | } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 33 | uint32_t PacketOH(int i) const { |
danilchap | a4f31bd | 2016-02-29 05:26:01 -0800 | [diff] [blame^] | 34 | return (*this)[i].packet_overhead(); |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 35 | } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 36 | uint32_t Ssrc(int i) const { |
danilchap | a4f31bd | 2016-02-29 05:26:01 -0800 | [diff] [blame^] | 37 | return (*this)[i].ssrc(); |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 38 | } |
| 39 | void SetEntry(unsigned int i, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 40 | uint32_t tmmbrSet, |
| 41 | uint32_t packetOHSet, |
| 42 | uint32_t ssrcSet); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 44 | void AddEntry(uint32_t tmmbrSet, |
| 45 | uint32_t packetOHSet, |
| 46 | uint32_t ssrcSet); |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 47 | |
| 48 | // Remove one entry from table, and move all others down. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 49 | void RemoveEntry(uint32_t sourceIdx); |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 50 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 51 | void SwapEntries(uint32_t firstIdx, |
| 52 | uint32_t secondIdx); |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 53 | |
| 54 | // Set entry data to zero, but keep it in table. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 55 | void ClearEntry(uint32_t idx); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | class TMMBRHelp |
| 59 | { |
| 60 | public: |
pwestin@webrtc.org | cac7878 | 2012-04-05 08:30:10 +0000 | [diff] [blame] | 61 | TMMBRHelp(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | virtual ~TMMBRHelp(); |
| 63 | |
| 64 | TMMBRSet* BoundingSet(); // used for debuging |
| 65 | TMMBRSet* CandidateSet(); |
| 66 | TMMBRSet* BoundingSetToSend(); |
| 67 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 68 | TMMBRSet* VerifyAndAllocateCandidateSet(const uint32_t minimumSize); |
| 69 | int32_t FindTMMBRBoundingSet(TMMBRSet*& boundingSet); |
Peter Boström | 9d0c432 | 2016-02-16 17:59:27 +0100 | [diff] [blame] | 70 | int32_t SetTMMBRBoundingSetToSend(const TMMBRSet* boundingSetToSend); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 72 | bool IsOwner(const uint32_t ssrc, const uint32_t length) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 74 | bool CalcMinBitRate(uint32_t* minBitrateKbit) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | |
| 76 | protected: |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 77 | TMMBRSet* VerifyAndAllocateBoundingSet(uint32_t minimumSize); |
| 78 | int32_t VerifyAndAllocateBoundingSetToSend(uint32_t minimumSize); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 80 | int32_t FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
| 82 | private: |
henrike@webrtc.org | 65573f2 | 2011-12-13 19:17:27 +0000 | [diff] [blame] | 83 | CriticalSectionWrapper* _criticalSection; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | TMMBRSet _candidateSet; |
| 85 | TMMBRSet _boundingSet; |
| 86 | TMMBRSet _boundingSetToSend; |
| 87 | |
| 88 | float* _ptrIntersectionBoundingSet; |
| 89 | float* _ptrMaxPRBoundingSet; |
| 90 | }; |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 91 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 92 | |
| 93 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_TMMBR_HELP_H_ |