Home | History | Annotate | Download | only in rtcp
      1 // Copyright 2014 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_UTILITY_H_
      6 #define MEDIA_CAST_RTCP_RTCP_UTILITY_H_
      7 
      8 #include "base/big_endian.h"
      9 #include "media/cast/cast_config.h"
     10 #include "media/cast/cast_defines.h"
     11 #include "media/cast/logging/logging_defines.h"
     12 #include "media/cast/net/rtcp/rtcp_defines.h"
     13 
     14 namespace media {
     15 namespace cast {
     16 
     17 // RFC 3550 page 44, including end null.
     18 static const size_t kRtcpCnameSize = 256;
     19 
     20 static const uint32 kCast = ('C' << 24) + ('A' << 16) + ('S' << 8) + 'T';
     21 
     22 static const uint8 kReceiverLogSubtype = 2;
     23 
     24 static const size_t kRtcpMaxReceiverLogMessages = 256;
     25 static const size_t kRtcpMaxCastLossFields = 100;
     26 
     27 struct RtcpCommonHeader {
     28   uint8 V;   // Version.
     29   bool P;    // Padding.
     30   uint8 IC;  // Item count / subtype.
     31   uint8 PT;  // Packet Type.
     32   size_t length_in_octets;
     33 };
     34 
     35 class RtcpParser {
     36  public:
     37   RtcpParser(uint32 local_ssrc, uint32 remote_ssrc);
     38   ~RtcpParser();
     39 
     40   bool Parse(base::BigEndianReader* reader);
     41 
     42   bool has_sender_report() const { return has_sender_report_; }
     43   const RtcpSenderInfo& sender_report() const {
     44     return sender_report_;
     45   }
     46 
     47   bool has_last_report() const { return has_last_report_; }
     48   uint32 last_report() const { return last_report_; }
     49   uint32 delay_since_last_report() const { return delay_since_last_report_; }
     50 
     51   bool has_receiver_log() const { return !receiver_log_.empty(); }
     52   const RtcpReceiverLogMessage& receiver_log() const { return receiver_log_; }
     53   RtcpReceiverLogMessage* mutable_receiver_log() { return & receiver_log_; }
     54 
     55   bool has_cast_message() const { return has_cast_message_; }
     56   const RtcpCastMessage& cast_message() const { return cast_message_; }
     57   RtcpCastMessage* mutable_cast_message() { return &cast_message_; }
     58 
     59   bool has_receiver_reference_time_report() const {
     60     return has_receiver_reference_time_report_;
     61   }
     62   const RtcpReceiverReferenceTimeReport&
     63   receiver_reference_time_report() const {
     64     return receiver_reference_time_report_;
     65   }
     66 
     67  private:
     68   bool ParseCommonHeader(base::BigEndianReader* reader,
     69                          RtcpCommonHeader* parsed_header);
     70   bool ParseSR(base::BigEndianReader* reader,
     71                const RtcpCommonHeader& header);
     72   bool ParseRR(base::BigEndianReader* reader,
     73                const RtcpCommonHeader& header);
     74   bool ParseReportBlock(base::BigEndianReader* reader);
     75   bool ParseApplicationDefined(base::BigEndianReader* reader,
     76                                const RtcpCommonHeader& header);
     77   bool ParseCastReceiverLogFrameItem(base::BigEndianReader* reader);
     78   bool ParseFeedbackCommon(base::BigEndianReader* reader,
     79                            const RtcpCommonHeader& header);
     80   bool ParseExtendedReport(base::BigEndianReader* reader,
     81                            const RtcpCommonHeader& header);
     82   bool ParseExtendedReportReceiverReferenceTimeReport(
     83       base::BigEndianReader* reader,
     84       uint32 remote_ssrc);
     85   bool ParseExtendedReportDelaySinceLastReceiverReport(
     86       base::BigEndianReader* reader);
     87 
     88   uint32 local_ssrc_;
     89   uint32 remote_ssrc_;
     90 
     91   bool has_sender_report_;
     92   RtcpSenderInfo sender_report_;
     93 
     94   uint32 last_report_;
     95   uint32 delay_since_last_report_;
     96   bool has_last_report_;
     97 
     98   // |receiver_log_| is a vector vector, no need for has_*.
     99   RtcpReceiverLogMessage receiver_log_;
    100 
    101   bool has_cast_message_;
    102   RtcpCastMessage cast_message_;
    103 
    104   bool has_receiver_reference_time_report_;
    105   RtcpReceiverReferenceTimeReport receiver_reference_time_report_;
    106 
    107   DISALLOW_COPY_AND_ASSIGN(RtcpParser);
    108 };
    109 
    110 // Converts a log event type to an integer value.
    111 // NOTE: We have only allocated 4 bits to represent the type of event over the
    112 // wire. Therefore, this function can only return values from 0 to 15.
    113 uint8 ConvertEventTypeToWireFormat(CastLoggingEvent event);
    114 
    115 // The inverse of |ConvertEventTypeToWireFormat()|.
    116 CastLoggingEvent TranslateToLogEventFromWireFormat(uint8 event);
    117 
    118 }  // namespace cast
    119 }  // namespace media
    120 
    121 #endif  // MEDIA_CAST_RTCP_RTCP_UTILITY_H_
    122