1 /*
2  *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
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 
12 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_TMMBR_H_
13 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_TMMBR_H_
14 
15 #include "webrtc/base/basictypes.h"
16 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
17 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
18 
19 namespace webrtc {
20 namespace rtcp {
21 // Temporary Maximum Media Stream Bit Rate Request (TMMBR) (RFC 5104).
22 class Tmmbr : public RtcpPacket {
23  public:
Tmmbr()24   Tmmbr() : RtcpPacket() {
25     memset(&tmmbr_, 0, sizeof(tmmbr_));
26     memset(&tmmbr_item_, 0, sizeof(tmmbr_item_));
27   }
28 
~Tmmbr()29   virtual ~Tmmbr() {}
30 
From(uint32_t ssrc)31   void From(uint32_t ssrc) {
32     tmmbr_.SenderSSRC = ssrc;
33   }
To(uint32_t ssrc)34   void To(uint32_t ssrc) {
35     tmmbr_item_.SSRC = ssrc;
36   }
WithBitrateKbps(uint32_t bitrate_kbps)37   void WithBitrateKbps(uint32_t bitrate_kbps) {
38     tmmbr_item_.MaxTotalMediaBitRate = bitrate_kbps;
39   }
WithOverhead(uint16_t overhead)40   void WithOverhead(uint16_t overhead) {
41     assert(overhead <= 0x1ff);
42     tmmbr_item_.MeasuredOverhead = overhead;
43   }
44 
45  protected:
46   bool Create(uint8_t* packet,
47               size_t* index,
48               size_t max_length,
49               RtcpPacket::PacketReadyCallback* callback) const override;
50 
51  private:
BlockLength()52   size_t BlockLength() const {
53     const size_t kFciLen = 8;
54     return kCommonFbFmtLength + kFciLen;
55   }
56 
57   RTCPUtility::RTCPPacketRTPFBTMMBR tmmbr_;
58   RTCPUtility::RTCPPacketRTPFBTMMBRItem tmmbr_item_;
59 
60   RTC_DISALLOW_COPY_AND_ASSIGN(Tmmbr);
61 };
62 }  // namespace rtcp
63 }  // namespace webrtc
64 #endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_TMMBR_H_
65