blob: ecae946f97d31a9bd3dabd83f40e544f7b99d60a [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 {
danilchap262e4862016-08-05 03:37:38 -070019class 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.com470e71d2011-07-07 08:21:25 +000035
danilchap262e4862016-08-05 03:37:38 -070036 void AddEntry(uint32_t tmmbrSet, uint32_t packetOHSet, uint32_t ssrcSet);
hta@webrtc.org54536bb2012-05-03 14:07:23 +000037
danilchap262e4862016-08-05 03:37:38 -070038 // Remove one entry from table, and move all others down.
39 void RemoveEntry(uint32_t sourceIdx);
niklase@google.com470e71d2011-07-07 08:21:25 +000040};
41
danilchap262e4862016-08-05 03:37:38 -070042class TMMBRHelp {
43 public:
44 TMMBRSet* CandidateSet();
niklase@google.com470e71d2011-07-07 08:21:25 +000045
danilchap262e4862016-08-05 03:37:38 -070046 TMMBRSet* VerifyAndAllocateCandidateSet(const uint32_t minimumSize);
Danil Chapovalovdaa90a72016-08-10 11:29:50 +020047 std::vector<rtcp::TmmbItem> FindTMMBRBoundingSet();
niklase@google.com470e71d2011-07-07 08:21:25 +000048
Danil Chapovalovdaa90a72016-08-10 11:29:50 +020049 static bool IsOwner(const std::vector<rtcp::TmmbItem>& bounding,
50 uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +000051
danilchap262e4862016-08-05 03:37:38 -070052 bool CalcMinBitRate(uint32_t* minBitrateKbit) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000053
danilchap262e4862016-08-05 03:37:38 -070054 static void FindBoundingSet(std::vector<rtcp::TmmbItem> candidates,
55 std::vector<rtcp::TmmbItem>* bounding_set);
niklase@google.com470e71d2011-07-07 08:21:25 +000056
danilchap262e4862016-08-05 03:37:38 -070057 private:
58 TMMBRSet _candidateSet;
niklase@google.com470e71d2011-07-07 08:21:25 +000059};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000060} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000061
danilchap262e4862016-08-05 03:37:38 -070062#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_TMMBR_HELP_H_