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"
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
{
34 uint8 number_of_report_blocks
;
37 struct RtcpFieldSenderReport
{
40 uint8 number_of_report_blocks
;
41 uint32 ntp_most_significant
;
42 uint32 ntp_least_significant
;
44 uint32 sender_packet_count
;
45 uint32 sender_octet_count
;
48 struct RtcpFieldReportBlockItem
{
52 uint32 cumulative_number_of_packets_lost
;
53 uint32 extended_highest_sequence_number
;
55 uint32 last_sender_report
;
56 uint32 delay_last_sender_report
;
59 struct RtcpFieldSdesCName
{
62 char name
[kRtcpCnameSize
];
70 struct RtcpFieldGenericRtpFeedbackNack
{
76 struct RtcpFieldGenericRtpFeedbackNackItem
{
82 struct RtcpFieldPayloadSpecificFir
{
85 uint32 media_ssrc
; // zero!
88 struct RtcpFieldPayloadSpecificFirItem
{
91 uint8 command_sequence_number
;
94 struct RtcpFieldPayloadSpecificPli
{
100 struct RtcpFieldPayloadSpecificRpsi
{
105 uint16 number_of_valid_bits
;
106 uint8 native_bit_string
[kRtcpRpsiDataSize
];
114 struct RtcpFieldXrRrtr
{
116 uint32 ntp_most_significant
;
117 uint32 ntp_least_significant
;
120 struct RtcpFieldXrDlrr
{
122 uint32 receivers_ssrc
;
123 uint32 last_receiver_report
;
124 uint32 delay_last_receiver_report
;
127 struct RtcpFieldPayloadSpecificApplication
{
132 struct RtcpFieldPayloadSpecificRembItem
{
134 uint8 number_of_ssrcs
;
135 uint32 ssrcs
[kRtcpMaxNumberOfRembFeedbackSsrcs
];
138 struct RtcpFieldPayloadSpecificCastItem
{
140 uint8 number_of_lost_fields
;
143 struct RtcpFieldPayloadSpecificCastNackItem
{
149 struct RtcpFieldApplicationSpecificCastReceiverLogItem
{
151 uint32 rtp_timestamp
;
152 uint32 event_timestamp_base
;
154 uint16 delay_delta_or_packet_id
;
155 uint16 event_timestamp_delta
;
158 struct RtcpFieldApplicationSpecificCastSenderLogItem
{
161 uint32 rtp_timestamp
;
165 RtcpFieldReceiverReport receiver_report
;
166 RtcpFieldSenderReport sender_report
;
167 RtcpFieldReportBlockItem report_block_item
;
168 RtcpFieldSdesCName c_name
;
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
{
197 kRtcpReportBlockItemCode
,
206 kRtcpXrUnknownItemCode
,
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
,
226 kRtcpPayloadSpecificFirCode
,
227 kRtcpPayloadSpecificFirItemCode
,
230 kRtcpGenericRtpFeedbackSrReqCode
,
233 struct RtcpCommonHeader
{
236 uint8 IC
; // Item count / subtype.
237 uint8 PT
; // Packet Type.
238 uint16 length_in_octets
;
243 RtcpParser(const uint8
* rtcp_data
, size_t rtcp_length
);
246 RtcpFieldTypes
FieldType() const;
247 const RtcpField
& Field() const;
249 bool IsValid() const;
251 RtcpFieldTypes
Begin();
252 RtcpFieldTypes
Iterate();
256 kStateTopLevel
, // Top level packet
257 kStateReportBlock
, // Sender/Receiver report report blocks.
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
,
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();
296 void EndCurrentBlock();
300 bool ParseReportBlockItem();
303 bool ParseSdesItem();
304 bool ParseSdesTypes();
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();
321 bool ParsePayloadSpecificAppItem();
322 bool ParsePayloadSpecificRembItem();
323 bool ParsePayloadSpecificCastItem();
324 bool ParsePayloadSpecificCastNackItem();
327 const uint8
* const rtcp_data_begin_
;
328 const uint8
* const rtcp_data_end_
;
331 const uint8
* rtcp_data_
;
332 const uint8
* rtcp_block_end_
;
335 uint8 number_of_blocks_
;
336 RtcpFieldTypes field_type_
;
339 DISALLOW_COPY_AND_ASSIGN(RtcpParser
);
345 #endif // MEDIA_CAST_RTCP_RTCP_UTILITY_H_