- add sources.
[platform/framework/web/crosswalk.git] / src / media / cast / rtcp / rtcp_sender.h
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_CAST_RTCP_RTCP_SENDER_H_
6 #define MEDIA_CAST_RTCP_RTCP_SENDER_H_
7
8 #include <list>
9 #include <string>
10
11 #include "media/cast/cast_config.h"
12 #include "media/cast/cast_defines.h"
13 #include "media/cast/rtcp/rtcp.h"
14 #include "media/cast/rtcp/rtcp_defines.h"
15
16 namespace media {
17 namespace cast {
18
19 class RtcpSender {
20  public:
21   RtcpSender(PacedPacketSender* const paced_packet_sender,
22              uint32 sending_ssrc,
23              const std::string& c_name);
24
25   virtual ~RtcpSender();
26
27   void SendRtcp(uint32 packet_type_flags,
28                 const RtcpSenderInfo* sender_info,
29                 const RtcpReportBlock* report_block,
30                 uint32 pli_remote_ssrc,
31                 const RtcpDlrrReportBlock* dlrr,
32                 const RtcpReceiverReferenceTimeReport* rrtr,
33                 const RtcpCastMessage* cast_message);
34
35   enum RtcpPacketType {
36     kRtcpSr     = 0x0002,
37     kRtcpRr     = 0x0004,
38     kRtcpBye    = 0x0008,
39     kRtcpPli    = 0x0010,
40     kRtcpNack   = 0x0020,
41     kRtcpFir    = 0x0040,
42     kRtcpSrReq  = 0x0200,
43     kRtcpDlrr   = 0x0400,
44     kRtcpRrtr   = 0x0800,
45     kRtcpRpsi   = 0x8000,
46     kRtcpRemb   = 0x10000,
47     kRtcpCast   = 0x20000,
48   };
49
50  private:
51   void BuildSR(const RtcpSenderInfo& sender_info,
52                const RtcpReportBlock* report_block,
53                std::vector<uint8>* packet) const;
54
55   void BuildRR(const RtcpReportBlock* report_block,
56                std::vector<uint8>* packet) const;
57
58   void AddReportBlocks(const RtcpReportBlock& report_block,
59                        std::vector<uint8>* packet) const;
60
61   void BuildSdec(std::vector<uint8>* packet) const;
62
63   void BuildPli(uint32 remote_ssrc,
64                 std::vector<uint8>* packet) const;
65
66   void BuildRemb(const RtcpRembMessage* remb,
67                  std::vector<uint8>* packet) const;
68
69   void BuildRpsi(const RtcpRpsiMessage* rpsi,
70                  std::vector<uint8>* packet) const;
71
72   void BuildNack(const RtcpNackMessage* nack,
73                  std::vector<uint8>* packet) const;
74
75   void BuildBye(std::vector<uint8>* packet) const;
76
77   void BuildDlrrRb(const RtcpDlrrReportBlock* dlrr,
78                    std::vector<uint8>* packet) const;
79
80   void BuildRrtr(const RtcpReceiverReferenceTimeReport* rrtr,
81                  std::vector<uint8>* packet) const;
82
83   void BuildCast(const RtcpCastMessage* cast_message,
84                  std::vector<uint8>* packet) const;
85
86   inline void BitrateToRembExponentBitrate(uint32 bitrate,
87                                            uint8* exponent,
88                                            uint32* mantissa) const {
89     // 6 bit exponent and a 18 bit mantissa.
90     *exponent = 0;
91     for (int i = 0; i < 64; ++i) {
92       if (bitrate <= (262143u << i)) {
93         *exponent = i;
94         break;
95       }
96     }
97     *mantissa = (bitrate >> *exponent);
98   }
99
100   const uint32 ssrc_;
101   const std::string c_name_;
102
103   // Not owned by this class.
104   PacedPacketSender* transport_;
105
106   DISALLOW_COPY_AND_ASSIGN(RtcpSender);
107 };
108
109 }  // namespace cast
110 }  // namespace media
111 #endif  // MEDIA_CAST_RTCP_RTCP_SENDER_H_