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.
5 #ifndef MEDIA_CAST_RTCP_RTCP_UTILITY_H_
6 #define MEDIA_CAST_RTCP_RTCP_UTILITY_H_
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"
17 // RFC 3550 page 44, including end null.
18 static const size_t kRtcpCnameSize
= 256;
20 static const uint32 kCast
= ('C' << 24) + ('A' << 16) + ('S' << 8) + 'T';
22 static const uint8 kReceiverLogSubtype
= 2;
24 static const size_t kRtcpMaxReceiverLogMessages
= 256;
25 static const size_t kRtcpMaxCastLossFields
= 100;
27 struct RtcpCommonHeader
{
30 uint8 IC
; // Item count / subtype.
31 uint8 PT
; // Packet Type.
32 size_t length_in_octets
;
37 RtcpParser(uint32 local_ssrc
, uint32 remote_ssrc
);
40 bool Parse(base::BigEndianReader
* reader
);
42 bool has_sender_report() const { return has_sender_report_
; }
43 const RtcpSenderInfo
& sender_report() const {
44 return sender_report_
;
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_
; }
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_
; }
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_
; }
59 bool has_receiver_reference_time_report() const {
60 return has_receiver_reference_time_report_
;
62 const RtcpReceiverReferenceTimeReport
&
63 receiver_reference_time_report() const {
64 return receiver_reference_time_report_
;
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
,
85 bool ParseExtendedReportDelaySinceLastReceiverReport(
86 base::BigEndianReader
* reader
);
91 bool has_sender_report_
;
92 RtcpSenderInfo sender_report_
;
95 uint32 delay_since_last_report_
;
96 bool has_last_report_
;
98 // |receiver_log_| is a vector vector, no need for has_*.
99 RtcpReceiverLogMessage receiver_log_
;
101 bool has_cast_message_
;
102 RtcpCastMessage cast_message_
;
104 bool has_receiver_reference_time_report_
;
105 RtcpReceiverReferenceTimeReport receiver_reference_time_report_
;
107 DISALLOW_COPY_AND_ASSIGN(RtcpParser
);
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
);
115 // The inverse of |ConvertEventTypeToWireFormat()|.
116 CastLoggingEvent
TranslateToLogEventFromWireFormat(uint8 event
);
121 #endif // MEDIA_CAST_RTCP_RTCP_UTILITY_H_