00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MPF_RTCP_PACKET_H
00020 #define MPF_RTCP_PACKET_H
00021
00022
00023
00024
00025
00026
00027 #include "mpf_rtp_stat.h"
00028
00029 APT_BEGIN_EXTERN_C
00030
00031
00032
00033 typedef enum {
00034 RTCP_SR = 200,
00035 RTCP_RR = 201,
00036 RTCP_SDES = 202,
00037 RTCP_BYE = 203,
00038 RTCP_APP = 204
00039 } rtcp_type_e;
00040
00041
00042 typedef enum {
00043 RTCP_SDES_END = 0,
00044 RTCP_SDES_CNAME = 1,
00045 RTCP_SDES_NAME = 2,
00046 RTCP_SDES_EMAIL = 3,
00047 RTCP_SDES_PHONE = 4,
00048 RTCP_SDES_LOC = 5,
00049 RTCP_SDES_TOOL = 6,
00050 RTCP_SDES_NOTE = 7,
00051 RTCP_SDES_PRIV = 8
00052 } rtcp_sdes_type_e;
00053
00054
00055 typedef struct rtcp_header_t rtcp_header_t;
00056
00057 typedef struct rtcp_packet_t rtcp_packet_t;
00058
00059 typedef struct rtcp_sdes_item_t rtcp_sdes_item_t;
00060
00061
00062
00063 struct rtcp_header_t {
00064 #if (APR_IS_BIGENDIAN == 1)
00065
00066 unsigned int version: 2;
00067
00068 unsigned int padding: 1;
00069
00070 unsigned int count: 5;
00071
00072 unsigned int pt: 8;
00073 #else
00074
00075 unsigned int count: 5;
00076
00077 unsigned int padding: 1;
00078
00079 unsigned int version: 2;
00080
00081 unsigned int pt: 8;
00082 #endif
00083
00084
00085 unsigned int length: 16;
00086 };
00087
00088
00089 struct rtcp_sdes_item_t {
00090
00091 apr_byte_t type;
00092
00093 apr_byte_t length;
00094
00095 char data[1];
00096 };
00097
00098
00099 struct rtcp_packet_t {
00100
00101 rtcp_header_t header;
00102
00103 union {
00104
00105 struct {
00106
00107 rtcp_sr_stat_t sr_stat;
00108
00109 rtcp_rr_stat_t rr_stat[1];
00110 } sr;
00111
00112
00113 struct {
00114
00115 apr_uint32_t ssrc;
00116
00117 rtcp_rr_stat_t rr_stat[1];
00118 } rr;
00119
00120
00121 struct {
00122
00123 apr_uint32_t ssrc;
00124
00125 rtcp_sdes_item_t item[1];
00126 } sdes;
00127
00128
00129 struct {
00130
00131 apr_uint32_t ssrc[1];
00132
00133 apr_byte_t length;
00134
00135 char data[1];
00136 } bye;
00137 } r;
00138 };
00139
00140
00141 static APR_INLINE void rtcp_header_init(rtcp_header_t *header, rtcp_type_e pt)
00142 {
00143 header->version = RTP_VERSION;
00144 header->padding = 0;
00145 header->count = 0;
00146 header->pt = pt;
00147 header->length = 0;
00148 }
00149
00150 static APR_INLINE void rtcp_header_length_set(rtcp_header_t *header, apr_size_t length)
00151 {
00152 header->length = htons((apr_uint16_t)length / 4 - 1);
00153 }
00154
00155 static APR_INLINE void rtcp_sr_hton(rtcp_sr_stat_t *sr_stat)
00156 {
00157 sr_stat->ssrc = htonl(sr_stat->ssrc);
00158 sr_stat->ntp_sec = htonl(sr_stat->ntp_sec);
00159 sr_stat->ntp_frac = htonl(sr_stat->ntp_frac);
00160 sr_stat->rtp_ts = htonl(sr_stat->rtp_ts);
00161 sr_stat->sent_packets = htonl(sr_stat->sent_packets);
00162 sr_stat->sent_octets = htonl(sr_stat->sent_octets);
00163 }
00164
00165 static APR_INLINE void rtcp_sr_ntoh(rtcp_sr_stat_t *sr_stat)
00166 {
00167 sr_stat->ssrc = ntohl(sr_stat->ssrc);
00168 sr_stat->ntp_sec = ntohl(sr_stat->ntp_sec);
00169 sr_stat->ntp_frac = ntohl(sr_stat->ntp_frac);
00170 sr_stat->rtp_ts = ntohl(sr_stat->rtp_ts);
00171 sr_stat->sent_packets = ntohl(sr_stat->sent_packets);
00172 sr_stat->sent_octets = ntohl(sr_stat->sent_octets);
00173 }
00174
00175 static APR_INLINE void rtcp_rr_hton(rtcp_rr_stat_t *rr_stat)
00176 {
00177 rr_stat->ssrc = htonl(rr_stat->ssrc);
00178 rr_stat->last_seq = htonl(rr_stat->last_seq);
00179 rr_stat->jitter = htonl(rr_stat->jitter);
00180
00181 #if (APR_IS_BIGENDIAN == 0)
00182 rr_stat->lost = ((rr_stat->lost >> 16) & 0x000000ff) |
00183 (rr_stat->lost & 0x0000ff00) |
00184 ((rr_stat->lost << 16) & 0x00ff0000);
00185 #endif
00186 }
00187
00188 static APR_INLINE void rtcp_rr_ntoh(rtcp_rr_stat_t *rr_stat)
00189 {
00190 rr_stat->ssrc = ntohl(rr_stat->ssrc);
00191 rr_stat->last_seq = ntohl(rr_stat->last_seq);
00192 rr_stat->jitter = ntohl(rr_stat->jitter);
00193
00194 #if (APR_IS_BIGENDIAN == 0)
00195 rr_stat->lost = ((rr_stat->lost >> 16) & 0x000000ff) |
00196 (rr_stat->lost & 0x0000ff00) |
00197 ((rr_stat->lost << 16) & 0x00ff0000);
00198 #endif
00199 }
00200
00201 APT_END_EXTERN_C
00202
00203 #endif