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