blob: 08b2438f2b83e22a1a4d7748248493e5a6fd3f96 [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"
pbos@webrtc.org96edd562013-07-10 15:40:42 +000016#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
18namespace webrtc {
danilchapa4f31bd2016-02-29 05:26:01 -080019class TMMBRSet : public std::vector<rtcp::TmmbItem>
niklase@google.com470e71d2011-07-07 08:21:25 +000020{
21public:
pbos@webrtc.org2f446732013-04-08 11:08:41 +000022 void VerifyAndAllocateSet(uint32_t minimumSize);
23 void VerifyAndAllocateSetKeepingData(uint32_t minimumSize);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000024 // Number of valid data items in set.
danilchapa4f31bd2016-02-29 05:26:01 -080025 uint32_t lengthOfSet() const { return size(); }
hta@webrtc.org54536bb2012-05-03 14:07:23 +000026 // Presently allocated max size of set.
danilchapa4f31bd2016-02-29 05:26:01 -080027 uint32_t sizeOfSet() const { return capacity(); }
28 void clearSet() { clear(); }
pbos@webrtc.org2f446732013-04-08 11:08:41 +000029 uint32_t Tmmbr(int i) const {
danilchapa4f31bd2016-02-29 05:26:01 -080030 return (*this)[i].bitrate_bps() / 1000;
hta@webrtc.org54536bb2012-05-03 14:07:23 +000031 }
pbos@webrtc.org2f446732013-04-08 11:08:41 +000032 uint32_t PacketOH(int i) const {
danilchapa4f31bd2016-02-29 05:26:01 -080033 return (*this)[i].packet_overhead();
hta@webrtc.org54536bb2012-05-03 14:07:23 +000034 }
pbos@webrtc.org2f446732013-04-08 11:08:41 +000035 uint32_t Ssrc(int i) const {
danilchapa4f31bd2016-02-29 05:26:01 -080036 return (*this)[i].ssrc();
hta@webrtc.org54536bb2012-05-03 14:07:23 +000037 }
38 void SetEntry(unsigned int i,
pbos@webrtc.org2f446732013-04-08 11:08:41 +000039 uint32_t tmmbrSet,
40 uint32_t packetOHSet,
41 uint32_t ssrcSet);
niklase@google.com470e71d2011-07-07 08:21:25 +000042
pbos@webrtc.org2f446732013-04-08 11:08:41 +000043 void AddEntry(uint32_t tmmbrSet,
44 uint32_t packetOHSet,
45 uint32_t ssrcSet);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000046
47 // Remove one entry from table, and move all others down.
pbos@webrtc.org2f446732013-04-08 11:08:41 +000048 void RemoveEntry(uint32_t sourceIdx);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000049
pbos@webrtc.org2f446732013-04-08 11:08:41 +000050 void SwapEntries(uint32_t firstIdx,
51 uint32_t secondIdx);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000052
53 // Set entry data to zero, but keep it in table.
pbos@webrtc.org2f446732013-04-08 11:08:41 +000054 void ClearEntry(uint32_t idx);
niklase@google.com470e71d2011-07-07 08:21:25 +000055};
56
57class TMMBRHelp
58{
59public:
pwestin@webrtc.orgcac78782012-04-05 08:30:10 +000060 TMMBRHelp();
niklase@google.com470e71d2011-07-07 08:21:25 +000061 virtual ~TMMBRHelp();
62
63 TMMBRSet* BoundingSet(); // used for debuging
64 TMMBRSet* CandidateSet();
niklase@google.com470e71d2011-07-07 08:21:25 +000065
pbos@webrtc.org2f446732013-04-08 11:08:41 +000066 TMMBRSet* VerifyAndAllocateCandidateSet(const uint32_t minimumSize);
67 int32_t FindTMMBRBoundingSet(TMMBRSet*& boundingSet);
niklase@google.com470e71d2011-07-07 08:21:25 +000068
pbos@webrtc.org2f446732013-04-08 11:08:41 +000069 bool IsOwner(const uint32_t ssrc, const uint32_t length) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000070
pbos@webrtc.org2f446732013-04-08 11:08:41 +000071 bool CalcMinBitRate(uint32_t* minBitrateKbit) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000072
73protected:
pbos@webrtc.org2f446732013-04-08 11:08:41 +000074 TMMBRSet* VerifyAndAllocateBoundingSet(uint32_t minimumSize);
pbos@webrtc.org2f446732013-04-08 11:08:41 +000075 int32_t FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet);
niklase@google.com470e71d2011-07-07 08:21:25 +000076
77private:
niklase@google.com470e71d2011-07-07 08:21:25 +000078 TMMBRSet _candidateSet;
79 TMMBRSet _boundingSet;
niklase@google.com470e71d2011-07-07 08:21:25 +000080
81 float* _ptrIntersectionBoundingSet;
82 float* _ptrMaxPRBoundingSet;
83};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000084} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000085
86#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_TMMBR_HELP_H_