summaryrefslogtreecommitdiff
path: root/media/cast/rtcp/rtcp_sender.h
blob: 7dbbc0f95b514bfce8d875669c2a5be0333dba92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_CAST_RTCP_RTCP_SENDER_H_
#define MEDIA_CAST_RTCP_RTCP_SENDER_H_

#include <list>
#include <string>

#include "media/cast/cast_config.h"
#include "media/cast/cast_defines.h"
#include "media/cast/rtcp/rtcp.h"
#include "media/cast/rtcp/rtcp_defines.h"

namespace media {
namespace cast {

class RtcpSender {
 public:
  RtcpSender(PacedPacketSender* const paced_packet_sender,
             uint32 sending_ssrc,
             const std::string& c_name);

  virtual ~RtcpSender();

  void SendRtcp(uint32 packet_type_flags,
                const RtcpSenderInfo* sender_info,
                const RtcpReportBlock* report_block,
                uint32 pli_remote_ssrc,
                const RtcpDlrrReportBlock* dlrr,
                const RtcpReceiverReferenceTimeReport* rrtr,
                const RtcpCastMessage* cast_message);

  enum RtcpPacketType {
    kRtcpSr     = 0x0002,
    kRtcpRr     = 0x0004,
    kRtcpBye    = 0x0008,
    kRtcpPli    = 0x0010,
    kRtcpNack   = 0x0020,
    kRtcpFir    = 0x0040,
    kRtcpSrReq  = 0x0200,
    kRtcpDlrr   = 0x0400,
    kRtcpRrtr   = 0x0800,
    kRtcpRpsi   = 0x8000,
    kRtcpRemb   = 0x10000,
    kRtcpCast   = 0x20000,
  };

 private:
  void BuildSR(const RtcpSenderInfo& sender_info,
               const RtcpReportBlock* report_block,
               std::vector<uint8>* packet) const;

  void BuildRR(const RtcpReportBlock* report_block,
               std::vector<uint8>* packet) const;

  void AddReportBlocks(const RtcpReportBlock& report_block,
                       std::vector<uint8>* packet) const;

  void BuildSdec(std::vector<uint8>* packet) const;

  void BuildPli(uint32 remote_ssrc,
                std::vector<uint8>* packet) const;

  void BuildRemb(const RtcpRembMessage* remb,
                 std::vector<uint8>* packet) const;

  void BuildRpsi(const RtcpRpsiMessage* rpsi,
                 std::vector<uint8>* packet) const;

  void BuildNack(const RtcpNackMessage* nack,
                 std::vector<uint8>* packet) const;

  void BuildBye(std::vector<uint8>* packet) const;

  void BuildDlrrRb(const RtcpDlrrReportBlock* dlrr,
                   std::vector<uint8>* packet) const;

  void BuildRrtr(const RtcpReceiverReferenceTimeReport* rrtr,
                 std::vector<uint8>* packet) const;

  void BuildCast(const RtcpCastMessage* cast_message,
                 std::vector<uint8>* packet) const;

  inline void BitrateToRembExponentBitrate(uint32 bitrate,
                                           uint8* exponent,
                                           uint32* mantissa) const {
    // 6 bit exponent and a 18 bit mantissa.
    *exponent = 0;
    for (int i = 0; i < 64; ++i) {
      if (bitrate <= (262143u << i)) {
        *exponent = i;
        break;
      }
    }
    *mantissa = (bitrate >> *exponent);
  }

  const uint32 ssrc_;
  const std::string c_name_;

  // Not owned by this class.
  PacedPacketSender* transport_;

  DISALLOW_COPY_AND_ASSIGN(RtcpSender);
};

}  // namespace cast
}  // namespace media
#endif  // MEDIA_CAST_RTCP_RTCP_SENDER_H_