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 "media/cast/cast_config.h"
9 #include "media/cast/cast_defines.h"
10 #include "media/cast/logging/logging_defines.h"
11 #include "media/cast/net/rtcp/rtcp_defines.h"
16 // RFC 3550 page 44, including end null.
17 static const size_t kRtcpCnameSize = 256;
19 static const uint32 kCast = ('C' << 24) + ('A' << 16) + ('S' << 8) + 'T';
21 static const uint8 kReceiverLogSubtype = 2;
23 static const size_t kRtcpMaxReceiverLogMessages = 256;
24 static const size_t kRtcpMaxCastLossFields = 100;
26 struct RtcpFieldReceiverReport {
29 uint8 number_of_report_blocks;
32 struct RtcpFieldSenderReport {
35 uint8 number_of_report_blocks;
36 uint32 ntp_most_significant;
37 uint32 ntp_least_significant;
39 uint32 sender_packet_count;
40 uint32 sender_octet_count;
43 struct RtcpFieldReportBlockItem {
47 uint32 cumulative_number_of_packets_lost;
48 uint32 extended_highest_sequence_number;
50 uint32 last_sender_report;
51 uint32 delay_last_sender_report;
59 struct RtcpFieldXrRrtr {
61 uint32 ntp_most_significant;
62 uint32 ntp_least_significant;
65 struct RtcpFieldXrDlrr {
67 uint32 receivers_ssrc;
68 uint32 last_receiver_report;
69 uint32 delay_last_receiver_report;
72 struct RtcpFieldPayloadSpecificApplication {
77 struct RtcpFieldPayloadSpecificCastItem {
79 uint8 number_of_lost_fields;
80 uint16 target_delay_ms;
83 struct RtcpFieldPayloadSpecificCastNackItem {
89 struct RtcpFieldApplicationSpecificCastReceiverLogItem {
92 uint32 event_timestamp_base;
97 } delay_delta_or_packet_id;
98 uint16 event_timestamp_delta;
102 RtcpFieldReceiverReport receiver_report;
103 RtcpFieldSenderReport sender_report;
104 RtcpFieldReportBlockItem report_block_item;
106 RtcpFieldXr extended_report;
107 RtcpFieldXrRrtr rrtr;
108 RtcpFieldXrDlrr dlrr;
110 RtcpFieldPayloadSpecificApplication application_specific;
111 RtcpFieldPayloadSpecificCastItem cast_item;
112 RtcpFieldPayloadSpecificCastNackItem cast_nack_item;
114 RtcpFieldApplicationSpecificCastReceiverLogItem cast_receiver_log;
117 enum RtcpFieldTypes {
123 kRtcpReportBlockItemCode,
129 kRtcpXrUnknownItemCode,
132 kRtcpPayloadSpecificAppCode,
134 // Application specific.
135 kRtcpPayloadSpecificCastCode,
136 kRtcpPayloadSpecificCastNackItemCode,
137 kRtcpApplicationSpecificCastReceiverLogCode,
138 kRtcpApplicationSpecificCastReceiverLogFrameCode,
139 kRtcpApplicationSpecificCastReceiverLogEventCode,
142 struct RtcpCommonHeader {
145 uint8 IC; // Item count / subtype.
146 uint8 PT; // Packet Type.
147 uint16 length_in_octets;
152 RtcpParser(const uint8* rtcp_data, size_t rtcp_length);
155 RtcpFieldTypes FieldType() const;
156 const RtcpField& Field() const;
158 bool IsValid() const;
160 RtcpFieldTypes Begin();
161 RtcpFieldTypes Iterate();
165 kStateTopLevel, // Top level packet
166 kStateReportBlock, // Sender/Receiver report report blocks.
167 kStateApplicationSpecificCastReceiverFrameLog,
168 kStateApplicationSpecificCastReceiverEventLog,
169 kStateExtendedReportBlock,
170 kStateExtendedReportDelaySinceLastReceiverReport,
171 kStatePayloadSpecificApplication,
172 kStatePayloadSpecificCast, // Application specific Cast.
173 kStatePayloadSpecificCastNack, // Application specific Nack for Cast.
176 bool RtcpParseCommonHeader(const uint8* begin,
178 RtcpCommonHeader* parsed_header) const;
180 void IterateTopLevel();
181 void IterateReportBlockItem();
182 void IterateCastReceiverLogFrame();
183 void IterateCastReceiverLogEvent();
184 void IterateExtendedReportItem();
185 void IterateExtendedReportDelaySinceLastReceiverReportItem();
186 void IteratePayloadSpecificAppItem();
187 void IteratePayloadSpecificCastItem();
188 void IteratePayloadSpecificCastNackItem();
191 void EndCurrentBlock();
195 bool ParseReportBlockItem();
197 bool ParseApplicationDefined(uint8 subtype);
198 bool ParseCastReceiverLogFrameItem();
199 bool ParseCastReceiverLogEventItem();
201 bool ParseExtendedReport();
202 bool ParseExtendedReportItem();
203 bool ParseExtendedReportReceiverReferenceTimeReport();
204 bool ParseExtendedReportDelaySinceLastReceiverReport();
206 bool ParseFeedBackCommon(const RtcpCommonHeader& header);
207 bool ParsePayloadSpecificAppItem();
208 bool ParsePayloadSpecificCastItem();
209 bool ParsePayloadSpecificCastNackItem();
212 const uint8* const rtcp_data_begin_;
213 const uint8* const rtcp_data_end_;
216 const uint8* rtcp_data_;
217 const uint8* rtcp_block_end_;
220 uint8 number_of_blocks_;
221 RtcpFieldTypes field_type_;
224 DISALLOW_COPY_AND_ASSIGN(RtcpParser);
227 // Converts a log event type to an integer value.
228 // NOTE: We have only allocated 4 bits to represent the type of event over the
229 // wire. Therefore, this function can only return values from 0 to 15.
230 uint8 ConvertEventTypeToWireFormat(CastLoggingEvent event);
232 // The inverse of |ConvertEventTypeToWireFormat()|.
233 CastLoggingEvent TranslateToLogEventFromWireFormat(uint8 event);
238 #endif // MEDIA_CAST_RTCP_RTCP_UTILITY_H_