blob: 6236d5d43bdc32748deaff49d0c33628f00e86ca [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>
danilchapa4f31bd2016-02-29 05:26:01 -080015#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmb_item.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010016#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
pbos@webrtc.org96edd562013-07-10 15:40:42 +000017#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000018
19namespace webrtc {
danilchapa4f31bd2016-02-29 05:26:01 -080020class TMMBRSet : public std::vector<rtcp::TmmbItem>
niklase@google.com470e71d2011-07-07 08:21:25 +000021{
22public:
pbos@webrtc.org2f446732013-04-08 11:08:41 +000023 void VerifyAndAllocateSet(uint32_t minimumSize);
24 void VerifyAndAllocateSetKeepingData(uint32_t minimumSize);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000025 // Number of valid data items in set.
danilchapa4f31bd2016-02-29 05:26:01 -080026 uint32_t lengthOfSet() const { return size(); }
hta@webrtc.org54536bb2012-05-03 14:07:23 +000027 // Presently allocated max size of set.
danilchapa4f31bd2016-02-29 05:26:01 -080028 uint32_t sizeOfSet() const { return capacity(); }
29 void clearSet() { clear(); }
pbos@webrtc.org2f446732013-04-08 11:08:41 +000030 uint32_t Tmmbr(int i) const {
danilchapa4f31bd2016-02-29 05:26:01 -080031 return (*this)[i].bitrate_bps() / 1000;
hta@webrtc.org54536bb2012-05-03 14:07:23 +000032 }
pbos@webrtc.org2f446732013-04-08 11:08:41 +000033 uint32_t PacketOH(int i) const {
danilchapa4f31bd2016-02-29 05:26:01 -080034 return (*this)[i].packet_overhead();
hta@webrtc.org54536bb2012-05-03 14:07:23 +000035 }
pbos@webrtc.org2f446732013-04-08 11:08:41 +000036 uint32_t Ssrc(int i) const {
danilchapa4f31bd2016-02-29 05:26:01 -080037 return (*this)[i].ssrc();
hta@webrtc.org54536bb2012-05-03 14:07:23 +000038 }
39 void SetEntry(unsigned int i,
pbos@webrtc.org2f446732013-04-08 11:08:41 +000040 uint32_t tmmbrSet,
41 uint32_t packetOHSet,
42 uint32_t ssrcSet);
niklase@google.com470e71d2011-07-07 08:21:25 +000043
pbos@webrtc.org2f446732013-04-08 11:08:41 +000044 void AddEntry(uint32_t tmmbrSet,
45 uint32_t packetOHSet,
46 uint32_t ssrcSet);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000047
48 // Remove one entry from table, and move all others down.
pbos@webrtc.org2f446732013-04-08 11:08:41 +000049 void RemoveEntry(uint32_t sourceIdx);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000050
pbos@webrtc.org2f446732013-04-08 11:08:41 +000051 void SwapEntries(uint32_t firstIdx,
52 uint32_t secondIdx);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000053
54 // Set entry data to zero, but keep it in table.
pbos@webrtc.org2f446732013-04-08 11:08:41 +000055 void ClearEntry(uint32_t idx);
niklase@google.com470e71d2011-07-07 08:21:25 +000056};
57
58class TMMBRHelp
59{
60public:
pwestin@webrtc.orgcac78782012-04-05 08:30:10 +000061 TMMBRHelp();
niklase@google.com470e71d2011-07-07 08:21:25 +000062 virtual ~TMMBRHelp();
63
64 TMMBRSet* BoundingSet(); // used for debuging
65 TMMBRSet* CandidateSet();
66 TMMBRSet* BoundingSetToSend();
67
pbos@webrtc.org2f446732013-04-08 11:08:41 +000068 TMMBRSet* VerifyAndAllocateCandidateSet(const uint32_t minimumSize);
69 int32_t FindTMMBRBoundingSet(TMMBRSet*& boundingSet);
Peter Boström9d0c4322016-02-16 17:59:27 +010070 int32_t SetTMMBRBoundingSetToSend(const TMMBRSet* boundingSetToSend);
niklase@google.com470e71d2011-07-07 08:21:25 +000071
pbos@webrtc.org2f446732013-04-08 11:08:41 +000072 bool IsOwner(const uint32_t ssrc, const uint32_t length) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000073
pbos@webrtc.org2f446732013-04-08 11:08:41 +000074 bool CalcMinBitRate(uint32_t* minBitrateKbit) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000075
76protected:
pbos@webrtc.org2f446732013-04-08 11:08:41 +000077 TMMBRSet* VerifyAndAllocateBoundingSet(uint32_t minimumSize);
78 int32_t VerifyAndAllocateBoundingSetToSend(uint32_t minimumSize);
niklase@google.com470e71d2011-07-07 08:21:25 +000079
pbos@webrtc.org2f446732013-04-08 11:08:41 +000080 int32_t FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet);
niklase@google.com470e71d2011-07-07 08:21:25 +000081
82private:
henrike@webrtc.org65573f22011-12-13 19:17:27 +000083 CriticalSectionWrapper* _criticalSection;
niklase@google.com470e71d2011-07-07 08:21:25 +000084 TMMBRSet _candidateSet;
85 TMMBRSet _boundingSet;
86 TMMBRSet _boundingSetToSend;
87
88 float* _ptrIntersectionBoundingSet;
89 float* _ptrMaxPRBoundingSet;
90};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000091} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000092
93#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_TMMBR_HELP_H_