o The payload type field of the first RTCP packet in a compound
packet must be equal to SR or RR.
o The padding bit (P) should be zero for the first packet of a
compound RTCP packet because only the last should possibly need
padding.
o The length fields of the individual RTCP packets must total to
the overall length of the compound RTCP packet as received.
This is a fairly strong check.
The code fragment below performs all of these checks. The packet type
is not checked for subsequent packets since unknown packet types may
be present and should be ignored.
u_int32 len; /* length of compound RTCP packet in words */
rtcp_t *r; /* RTCP header */
rtcp_t *end; /* end of compound RTCP packet */
if ((*(u_int16 *)r & RTCP_VALID_MASK) != RTCP_VALID_VALUE) {
/* something wrong with packet format */
}
end = (rtcp_t *)((u_int32 *)r + len);
do r = (rtcp_t *)((u_int32 *)r + r->common.length + 1);
while (r < end && r->common.version == 2);
if (r != end) {
/* something wrong with packet format */
}
A.3 Determining the Number of RTP Packets Expected and Lost
In order to compute packet loss rates, the number of packets expected
and actually received from each source needs to be known, using per-
source state information defined in struct source referenced via
pointer s in the code below. The number of packets received is simply
the count of packets as they arrive, including any late or duplicate
Schulzrinne, et al Standards Track [Page 63]
RFC 1889 RTP January 1996
packets. The number of packets expected can be computed by the
receiver as the difference between the highest sequence number
received ( s->max_seq ) and the first sequence number received ( s-
>base_seq ). Since the sequence number is only 16 bits and will wrap
around, it is necessary to extend the highest sequence number with
the (shifted) count of sequence number wraparounds ( s->cycles ).
Both the received packet count and the count of cycles are maintained
the RTP header validity check routine in Appendix A.1.
extended_max = s->cycles + s->max_seq;
expected = extended_max - s->base_seq + 1;
The number of packets lost is defined to be the number of packets
expected less the number of packets actually received:
lost = expected - s->received;
Since this number is carried in 24 bits, it should be clamped at
0xffffff rather than wrap around to zero.
The fraction of packets lost during the last reporting interval
(since the previous SR or RR packet was sent) is calculated from
differences in the expected and received packet counts across the
interval, where expected_prior and received_prior are the values
saved when the previous reception report was generated: