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 | 262e486 | 2016-08-05 03:37:38 -0700 | [diff] [blame] | 19 | class TMMBRSet : public std::vector<rtcp::TmmbItem> { |
| 20 | public: |
| 21 | void VerifyAndAllocateSet(uint32_t minimumSize); |
| 22 | void VerifyAndAllocateSetKeepingData(uint32_t minimumSize); |
| 23 | // Number of valid data items in set. |
| 24 | uint32_t lengthOfSet() const { return size(); } |
| 25 | // Presently allocated max size of set. |
| 26 | uint32_t sizeOfSet() const { return capacity(); } |
| 27 | void clearSet() { clear(); } |
| 28 | uint32_t Tmmbr(int i) const { return (*this)[i].bitrate_bps() / 1000; } |
| 29 | uint32_t PacketOH(int i) const { return (*this)[i].packet_overhead(); } |
| 30 | uint32_t Ssrc(int i) const { return (*this)[i].ssrc(); } |
| 31 | void SetEntry(unsigned int i, |
| 32 | uint32_t tmmbrSet, |
| 33 | uint32_t packetOHSet, |
| 34 | uint32_t ssrcSet); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
danilchap | 262e486 | 2016-08-05 03:37:38 -0700 | [diff] [blame] | 36 | void AddEntry(uint32_t tmmbrSet, uint32_t packetOHSet, uint32_t ssrcSet); |
hta@webrtc.org | 54536bb | 2012-05-03 14:07:23 +0000 | [diff] [blame] | 37 | |
danilchap | 262e486 | 2016-08-05 03:37:38 -0700 | [diff] [blame] | 38 | // Remove one entry from table, and move all others down. |
| 39 | void RemoveEntry(uint32_t sourceIdx); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
danilchap | 262e486 | 2016-08-05 03:37:38 -0700 | [diff] [blame] | 42 | class TMMBRHelp { |
| 43 | public: |
| 44 | TMMBRSet* CandidateSet(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
danilchap | 262e486 | 2016-08-05 03:37:38 -0700 | [diff] [blame] | 46 | TMMBRSet* VerifyAndAllocateCandidateSet(const uint32_t minimumSize); |
Danil Chapovalov | daa90a7 | 2016-08-10 11:29:50 +0200 | [diff] [blame] | 47 | std::vector<rtcp::TmmbItem> FindTMMBRBoundingSet(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
Danil Chapovalov | daa90a7 | 2016-08-10 11:29:50 +0200 | [diff] [blame] | 49 | static bool IsOwner(const std::vector<rtcp::TmmbItem>& bounding, |
| 50 | uint32_t ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
danilchap | 262e486 | 2016-08-05 03:37:38 -0700 | [diff] [blame] | 52 | bool CalcMinBitRate(uint32_t* minBitrateKbit) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
danilchap | 262e486 | 2016-08-05 03:37:38 -0700 | [diff] [blame] | 54 | static void FindBoundingSet(std::vector<rtcp::TmmbItem> candidates, |
| 55 | std::vector<rtcp::TmmbItem>* bounding_set); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | |
danilchap | 262e486 | 2016-08-05 03:37:38 -0700 | [diff] [blame] | 57 | private: |
| 58 | TMMBRSet _candidateSet; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | }; |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 60 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
danilchap | 262e486 | 2016-08-05 03:37:38 -0700 | [diff] [blame] | 62 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_TMMBR_HELP_H_ |