Upstream version 5.34.92.0
[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 #include "media/cast/transport/cast_transport_defines.h"
16 #include "media/cast/transport/rtcp/rtcp_builder.h"
17
18 namespace media {
19 namespace cast {
20
21 // TODO(mikhal): Resolve duplication between this and RtcpBuilder.
22 class RtcpSender {
23  public:
24   RtcpSender(scoped_refptr<CastEnvironment> cast_environment,
25              transport::PacedPacketSender* outgoing_transport,
26              uint32 sending_ssrc,
27              const std::string& c_name);
28
29   virtual ~RtcpSender();
30
31   // Returns true if |event| is an interesting receiver event.
32   // Such an event should be sent via RTCP.
33   static bool IsReceiverEvent(const media::cast::CastLoggingEvent& event);
34
35   void SendRtcpFromRtpReceiver(uint32 packet_type_flags,
36                                const transport::RtcpReportBlock* report_block,
37                                const RtcpReceiverReferenceTimeReport* rrtr,
38                                const RtcpCastMessage* cast_message,
39                                RtcpReceiverLogMessage* receiver_log);
40   enum RtcpPacketType {
41     kRtcpSr     = 0x0002,
42     kRtcpRr     = 0x0004,
43     kRtcpBye    = 0x0008,
44     kRtcpPli    = 0x0010,
45     kRtcpNack   = 0x0020,
46     kRtcpFir    = 0x0040,
47     kRtcpSrReq  = 0x0200,
48     kRtcpDlrr   = 0x0400,
49     kRtcpRrtr   = 0x0800,
50     kRtcpRpsi   = 0x8000,
51     kRtcpRemb   = 0x10000,
52     kRtcpCast   = 0x20000,
53     kRtcpSenderLog = 0x40000,
54     kRtcpReceiverLog = 0x80000,
55   };
56  private:
57   void BuildRR(const transport::RtcpReportBlock* report_block,
58                Packet* packet) const;
59
60   void AddReportBlocks(const transport::RtcpReportBlock& report_block,
61                        Packet* packet) const;
62
63   void BuildSdec(Packet* packet) const;
64
65   void BuildPli(uint32 remote_ssrc,
66                 Packet* packet) const;
67
68   void BuildRemb(const RtcpRembMessage* remb,
69                  Packet* packet) const;
70
71   void BuildRpsi(const RtcpRpsiMessage* rpsi,
72                  Packet* packet) const;
73
74   void BuildNack(const RtcpNackMessage* nack,
75                  Packet* packet) const;
76
77   void BuildBye(Packet* packet) const;
78
79   void BuildRrtr(const RtcpReceiverReferenceTimeReport* rrtr,
80                  Packet* packet) const;
81
82   void BuildCast(const RtcpCastMessage* cast_message,
83                  Packet* packet) const;
84
85   void BuildReceiverLog(RtcpReceiverLogMessage* receiver_log_message,
86                         Packet* packet) const;
87
88   inline void BitrateToRembExponentBitrate(uint32 bitrate,
89                                            uint8* exponent,
90                                            uint32* mantissa) const {
91     // 6 bit exponent and a 18 bit mantissa.
92     *exponent = 0;
93     for (int i = 0; i < 64; ++i) {
94       if (bitrate <= (262143u << i)) {
95         *exponent = i;
96         break;
97       }
98     }
99     *mantissa = (bitrate >> *exponent);
100   }
101
102   const uint32 ssrc_;
103   const std::string c_name_;
104
105   // Not owned by this class.
106   transport::PacedPacketSender* const transport_;
107   scoped_refptr<CastEnvironment> cast_environment_;
108
109   DISALLOW_COPY_AND_ASSIGN(RtcpSender);
110 };
111
112 }  // namespace cast
113 }  // namespace media
114 #endif  // MEDIA_CAST_RTCP_RTCP_SENDER_H_