Remove Unused AsTextButtonBorder RTTI helper.
[chromium-blink-merge.git] / media / cast / rtcp / rtcp_utility.h
blob5760135b8a191d69ceccd1171a338496e90aeb25
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.
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/rtcp/rtcp_defines.h"
12 namespace media {
13 namespace cast {
15 static const int kRtcpRpsiDataSize = 30;
17 // RFC 3550 page 44, including end null.
18 static const size_t kRtcpCnameSize = 256;
19 static const int kRtcpMaxNumberOfRembFeedbackSsrcs = 255;
21 static const uint32 kRemb = ('R' << 24) + ('E' << 16) + ('M' << 8) + 'B';
22 static const uint32 kCast = ('C' << 24) + ('A' << 16) + ('S' << 8) + 'T';
24 static const uint8 kSenderLogSubtype = 1;
25 static const uint8 kReceiverLogSubtype = 2;
27 static const size_t kRtcpMaxReceiverLogMessages = 256;
28 static const size_t kRtcpMaxNackFields = 253;
29 static const size_t kRtcpMaxCastLossFields = 100;
31 struct RtcpFieldReceiverReport {
32 // RFC 3550.
33 uint32 sender_ssrc;
34 uint8 number_of_report_blocks;
37 struct RtcpFieldSenderReport {
38 // RFC 3550.
39 uint32 sender_ssrc;
40 uint8 number_of_report_blocks;
41 uint32 ntp_most_significant;
42 uint32 ntp_least_significant;
43 uint32 rtp_timestamp;
44 uint32 sender_packet_count;
45 uint32 sender_octet_count;
48 struct RtcpFieldReportBlockItem {
49 // RFC 3550.
50 uint32 ssrc;
51 uint8 fraction_lost;
52 uint32 cumulative_number_of_packets_lost;
53 uint32 extended_highest_sequence_number;
54 uint32 jitter;
55 uint32 last_sender_report;
56 uint32 delay_last_sender_report;
59 struct RtcpFieldSdesCName {
60 // RFC 3550
61 uint32 sender_ssrc;
62 char name[kRtcpCnameSize];
65 struct RtcpFieldBye {
66 // RFC 3550.
67 uint32 sender_ssrc;
70 struct RtcpFieldGenericRtpFeedbackNack {
71 // RFC 4585.
72 uint32 sender_ssrc;
73 uint32 media_ssrc;
76 struct RtcpFieldGenericRtpFeedbackNackItem {
77 // RFC 4585.
78 uint16 packet_id;
79 uint16 bitmask;
82 struct RtcpFieldPayloadSpecificFir {
83 // RFC 5104.
84 uint32 sender_ssrc;
85 uint32 media_ssrc; // zero!
88 struct RtcpFieldPayloadSpecificFirItem {
89 // RFC 5104.
90 uint32 ssrc;
91 uint8 command_sequence_number;
94 struct RtcpFieldPayloadSpecificPli {
95 // RFC 4585.
96 uint32 sender_ssrc;
97 uint32 media_ssrc;
100 struct RtcpFieldPayloadSpecificRpsi {
101 // RFC 4585.
102 uint32 sender_ssrc;
103 uint32 media_ssrc;
104 uint8 payload_type;
105 uint16 number_of_valid_bits;
106 uint8 native_bit_string[kRtcpRpsiDataSize];
109 struct RtcpFieldXr {
110 // RFC 3611.
111 uint32 sender_ssrc;
114 struct RtcpFieldXrRrtr {
115 // RFC 3611.
116 uint32 ntp_most_significant;
117 uint32 ntp_least_significant;
120 struct RtcpFieldXrDlrr {
121 // RFC 3611.
122 uint32 receivers_ssrc;
123 uint32 last_receiver_report;
124 uint32 delay_last_receiver_report;
127 struct RtcpFieldPayloadSpecificApplication {
128 uint32 sender_ssrc;
129 uint32 media_ssrc;
132 struct RtcpFieldPayloadSpecificRembItem {
133 uint32 bitrate;
134 uint8 number_of_ssrcs;
135 uint32 ssrcs[kRtcpMaxNumberOfRembFeedbackSsrcs];
138 struct RtcpFieldPayloadSpecificCastItem {
139 uint8 last_frame_id;
140 uint8 number_of_lost_fields;
143 struct RtcpFieldPayloadSpecificCastNackItem {
144 uint8 frame_id;
145 uint16 packet_id;
146 uint8 bitmask;
149 struct RtcpFieldApplicationSpecificCastReceiverLogItem {
150 uint32 sender_ssrc;
151 uint32 rtp_timestamp;
152 uint32 event_timestamp_base;
153 uint8 event;
154 uint16 delay_delta_or_packet_id;
155 uint16 event_timestamp_delta;
158 struct RtcpFieldApplicationSpecificCastSenderLogItem {
159 uint32 sender_ssrc;
160 uint8 status;
161 uint32 rtp_timestamp;
164 union RtcpField {
165 RtcpFieldReceiverReport receiver_report;
166 RtcpFieldSenderReport sender_report;
167 RtcpFieldReportBlockItem report_block_item;
168 RtcpFieldSdesCName c_name;
169 RtcpFieldBye bye;
171 RtcpFieldXr extended_report;
172 RtcpFieldXrRrtr rrtr;
173 RtcpFieldXrDlrr dlrr;
175 RtcpFieldGenericRtpFeedbackNack nack;
176 RtcpFieldGenericRtpFeedbackNackItem nack_item;
178 RtcpFieldPayloadSpecificPli pli;
179 RtcpFieldPayloadSpecificRpsi rpsi;
180 RtcpFieldPayloadSpecificFir fir;
181 RtcpFieldPayloadSpecificFirItem fir_item;
182 RtcpFieldPayloadSpecificApplication application_specific;
183 RtcpFieldPayloadSpecificRembItem remb_item;
184 RtcpFieldPayloadSpecificCastItem cast_item;
185 RtcpFieldPayloadSpecificCastNackItem cast_nack_item;
187 RtcpFieldApplicationSpecificCastReceiverLogItem cast_receiver_log;
188 RtcpFieldApplicationSpecificCastSenderLogItem cast_sender_log;
191 enum RtcpFieldTypes {
192 kRtcpNotValidCode,
194 // RFC 3550.
195 kRtcpRrCode,
196 kRtcpSrCode,
197 kRtcpReportBlockItemCode,
198 kRtcpSdesCode,
199 kRtcpSdesChunkCode,
200 kRtcpByeCode,
202 // RFC 3611.
203 kRtcpXrCode,
204 kRtcpXrRrtrCode,
205 kRtcpXrDlrrCode,
206 kRtcpXrUnknownItemCode,
208 // RFC 4585.
209 kRtcpGenericRtpFeedbackNackCode,
210 kRtcpGenericRtpFeedbackNackItemCode,
211 kRtcpPayloadSpecificPliCode,
212 kRtcpPayloadSpecificRpsiCode,
213 kRtcpPayloadSpecificAppCode,
215 // Application specific.
216 kRtcpPayloadSpecificRembCode,
217 kRtcpPayloadSpecificRembItemCode,
218 kRtcpPayloadSpecificCastCode,
219 kRtcpPayloadSpecificCastNackItemCode,
220 kRtcpApplicationSpecificCastReceiverLogCode,
221 kRtcpApplicationSpecificCastReceiverLogFrameCode,
222 kRtcpApplicationSpecificCastReceiverLogEventCode,
223 kRtcpApplicationSpecificCastSenderLogCode,
225 // RFC 5104.
226 kRtcpPayloadSpecificFirCode,
227 kRtcpPayloadSpecificFirItemCode,
229 // RFC 6051.
230 kRtcpGenericRtpFeedbackSrReqCode,
233 struct RtcpCommonHeader {
234 uint8 V; // Version.
235 bool P; // Padding.
236 uint8 IC; // Item count / subtype.
237 uint8 PT; // Packet Type.
238 uint16 length_in_octets;
241 class RtcpParser {
242 public:
243 RtcpParser(const uint8* rtcp_data, size_t rtcp_length);
244 ~RtcpParser();
246 RtcpFieldTypes FieldType() const;
247 const RtcpField& Field() const;
249 bool IsValid() const;
251 RtcpFieldTypes Begin();
252 RtcpFieldTypes Iterate();
254 private:
255 enum ParseState {
256 kStateTopLevel, // Top level packet
257 kStateReportBlock, // Sender/Receiver report report blocks.
258 kStateSdes,
259 kStateBye,
260 kStateApplicationSpecificCastReceiverFrameLog,
261 kStateApplicationSpecificCastReceiverEventLog,
262 kStateApplicationSpecificCastSenderLog,
263 kStateExtendedReportBlock,
264 kStateExtendedReportDelaySinceLastReceiverReport,
265 kStateGenericRtpFeedbackNack,
266 kStatePayloadSpecificRpsi,
267 kStatePayloadSpecificFir,
268 kStatePayloadSpecificApplication,
269 kStatePayloadSpecificRemb, // Application specific Remb.
270 kStatePayloadSpecificCast, // Application specific Cast.
271 kStatePayloadSpecificCastNack, // Application specific Nack for Cast.
274 bool RtcpParseCommonHeader(const uint8* begin,
275 const uint8* end,
276 RtcpCommonHeader* parsed_header) const;
278 void IterateTopLevel();
279 void IterateReportBlockItem();
280 void IterateSdesItem();
281 void IterateByeItem();
282 void IterateCastReceiverLogFrame();
283 void IterateCastReceiverLogEvent();
284 void IterateCastSenderLog();
285 void IterateExtendedReportItem();
286 void IterateExtendedReportDelaySinceLastReceiverReportItem();
287 void IterateNackItem();
288 void IterateRpsiItem();
289 void IterateFirItem();
290 void IteratePayloadSpecificAppItem();
291 void IteratePayloadSpecificRembItem();
292 void IteratePayloadSpecificCastItem();
293 void IteratePayloadSpecificCastNackItem();
295 void Validate();
296 void EndCurrentBlock();
298 bool ParseRR();
299 bool ParseSR();
300 bool ParseReportBlockItem();
302 bool ParseSdes();
303 bool ParseSdesItem();
304 bool ParseSdesTypes();
305 bool ParseBye();
306 bool ParseByeItem();
307 bool ParseApplicationDefined(uint8 subtype);
308 bool ParseCastReceiverLogFrameItem();
309 bool ParseCastReceiverLogEventItem();
310 bool ParseCastSenderLogItem();
312 bool ParseExtendedReport();
313 bool ParseExtendedReportItem();
314 bool ParseExtendedReportReceiverReferenceTimeReport();
315 bool ParseExtendedReportDelaySinceLastReceiverReport();
317 bool ParseFeedBackCommon(const RtcpCommonHeader& header);
318 bool ParseNackItem();
319 bool ParseRpsiItem();
320 bool ParseFirItem();
321 bool ParsePayloadSpecificAppItem();
322 bool ParsePayloadSpecificRembItem();
323 bool ParsePayloadSpecificCastItem();
324 bool ParsePayloadSpecificCastNackItem();
326 private:
327 const uint8* const rtcp_data_begin_;
328 const uint8* const rtcp_data_end_;
330 bool valid_packet_;
331 const uint8* rtcp_data_;
332 const uint8* rtcp_block_end_;
334 ParseState state_;
335 uint8 number_of_blocks_;
336 RtcpFieldTypes field_type_;
337 RtcpField field_;
339 DISALLOW_COPY_AND_ASSIGN(RtcpParser);
342 } // namespace cast
343 } // namespace media
345 #endif // MEDIA_CAST_RTCP_RTCP_UTILITY_H_