Home | History | Annotate | Download | only in rtcp
      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(scoped_refptr<CastEnvironment> cast_environment,
     22              PacedPacketSender* const paced_packet_sender,
     23              uint32 sending_ssrc,
     24              const std::string& c_name);
     25 
     26   virtual ~RtcpSender();
     27 
     28   void SendRtcpFromRtpSender(uint32 packet_type_flags,
     29                              const RtcpSenderInfo* sender_info,
     30                              const RtcpDlrrReportBlock* dlrr,
     31                              RtcpSenderLogMessage* sender_log);
     32 
     33   void SendRtcpFromRtpReceiver(uint32 packet_type_flags,
     34                                const RtcpReportBlock* report_block,
     35                                const RtcpReceiverReferenceTimeReport* rrtr,
     36                                const RtcpCastMessage* cast_message,
     37                                RtcpReceiverLogMessage* receiver_log);
     38 
     39   enum RtcpPacketType {
     40     kRtcpSr     = 0x0002,
     41     kRtcpRr     = 0x0004,
     42     kRtcpBye    = 0x0008,
     43     kRtcpPli    = 0x0010,
     44     kRtcpNack   = 0x0020,
     45     kRtcpFir    = 0x0040,
     46     kRtcpSrReq  = 0x0200,
     47     kRtcpDlrr   = 0x0400,
     48     kRtcpRrtr   = 0x0800,
     49     kRtcpRpsi   = 0x8000,
     50     kRtcpRemb   = 0x10000,
     51     kRtcpCast   = 0x20000,
     52     kRtcpSenderLog = 0x40000,
     53     kRtcpReceiverLog = 0x80000,
     54   };
     55 
     56  private:
     57   void BuildSR(const RtcpSenderInfo& sender_info,
     58                const RtcpReportBlock* report_block,
     59                std::vector<uint8>* packet) const;
     60 
     61   void BuildRR(const RtcpReportBlock* report_block,
     62                std::vector<uint8>* packet) const;
     63 
     64   void AddReportBlocks(const RtcpReportBlock& report_block,
     65                        std::vector<uint8>* packet) const;
     66 
     67   void BuildSdec(std::vector<uint8>* packet) const;
     68 
     69   void BuildPli(uint32 remote_ssrc,
     70                 std::vector<uint8>* packet) const;
     71 
     72   void BuildRemb(const RtcpRembMessage* remb,
     73                  std::vector<uint8>* packet) const;
     74 
     75   void BuildRpsi(const RtcpRpsiMessage* rpsi,
     76                  std::vector<uint8>* packet) const;
     77 
     78   void BuildNack(const RtcpNackMessage* nack,
     79                  std::vector<uint8>* packet) const;
     80 
     81   void BuildBye(std::vector<uint8>* packet) const;
     82 
     83   void BuildDlrrRb(const RtcpDlrrReportBlock* dlrr,
     84                    std::vector<uint8>* packet) const;
     85 
     86   void BuildRrtr(const RtcpReceiverReferenceTimeReport* rrtr,
     87                  std::vector<uint8>* packet) const;
     88 
     89   void BuildCast(const RtcpCastMessage* cast_message,
     90                  std::vector<uint8>* packet) const;
     91 
     92   void BuildSenderLog(RtcpSenderLogMessage* sender_log_message,
     93                       std::vector<uint8>* packet) const;
     94 
     95   void BuildReceiverLog(RtcpReceiverLogMessage* receiver_log_message,
     96                         std::vector<uint8>* packet) const;
     97 
     98   inline void BitrateToRembExponentBitrate(uint32 bitrate,
     99                                            uint8* exponent,
    100                                            uint32* mantissa) const {
    101     // 6 bit exponent and a 18 bit mantissa.
    102     *exponent = 0;
    103     for (int i = 0; i < 64; ++i) {
    104       if (bitrate <= (262143u << i)) {
    105         *exponent = i;
    106         break;
    107       }
    108     }
    109     *mantissa = (bitrate >> *exponent);
    110   }
    111 
    112   const uint32 ssrc_;
    113   const std::string c_name_;
    114 
    115   // Not owned by this class.
    116   PacedPacketSender* transport_;
    117   scoped_refptr<CastEnvironment> cast_environment_;
    118 
    119   DISALLOW_COPY_AND_ASSIGN(RtcpSender);
    120 };
    121 
    122 }  // namespace cast
    123 }  // namespace media
    124 #endif  // MEDIA_CAST_RTCP_RTCP_SENDER_H_
    125