oRTP 0.16.3
|
00001 /* 00002 The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack. 00003 Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00020 00021 #ifndef RTCP_H 00022 #define RTCP_H 00023 00024 #include <ortp/port.h> 00025 00026 #define RTCP_MAX_RECV_BUFSIZE 1024 00027 00028 #define RTCP_SENDER_INFO_SIZE 20 00029 #define RTCP_REPORT_BLOCK_SIZE 24 00030 #define RTCP_COMMON_HEADER_SIZE 4 00031 #define RTCP_SSRC_FIELD_SIZE 4 00032 00033 #ifdef __cplusplus 00034 extern "C"{ 00035 #endif 00036 00037 /* RTCP common header */ 00038 00039 typedef enum { 00040 RTCP_SR = 200, 00041 RTCP_RR = 201, 00042 RTCP_SDES = 202, 00043 RTCP_BYE = 203, 00044 RTCP_APP = 204 00045 } rtcp_type_t; 00046 00047 00048 typedef struct rtcp_common_header 00049 { 00050 #ifdef ORTP_BIGENDIAN 00051 uint16_t version:2; 00052 uint16_t padbit:1; 00053 uint16_t rc:5; 00054 uint16_t packet_type:8; 00055 #else 00056 uint16_t rc:5; 00057 uint16_t padbit:1; 00058 uint16_t version:2; 00059 uint16_t packet_type:8; 00060 #endif 00061 uint16_t length:16; 00062 } rtcp_common_header_t; 00063 00064 #define rtcp_common_header_set_version(ch,v) (ch)->version=v 00065 #define rtcp_common_header_set_padbit(ch,p) (ch)->padbit=p 00066 #define rtcp_common_header_set_rc(ch,rc) (ch)->rc=rc 00067 #define rtcp_common_header_set_packet_type(ch,pt) (ch)->packet_type=pt 00068 #define rtcp_common_header_set_length(ch,l) (ch)->length=htons(l) 00069 00070 #define rtcp_common_header_get_version(ch) ((ch)->version) 00071 #define rtcp_common_header_get padbit(ch) ((ch)->padbit) 00072 #define rtcp_common_header_get_rc(ch) ((ch)->rc) 00073 #define rtcp_common_header_get_packet_type(ch) ((ch)->packet_type) 00074 #define rtcp_common_header_get_length(ch) ntohs((ch)->length) 00075 00076 00077 /* SR or RR packets */ 00078 00079 typedef struct sender_info 00080 { 00081 uint32_t ntp_timestamp_msw; 00082 uint32_t ntp_timestamp_lsw; 00083 uint32_t rtp_timestamp; 00084 uint32_t senders_packet_count; 00085 uint32_t senders_octet_count; 00086 } sender_info_t; 00087 00088 uint64_t sender_info_get_ntp_timestamp(const sender_info_t *si); 00089 #define sender_info_get_rtp_timestamp(si) ((si)->rtp_timestamp) 00090 #define sender_info_get_packet_count(si) \ 00091 ntohl((si)->senders_packet_count) 00092 #define sender_info_get_octet_count(si) \ 00093 ntohl((si)->senders_octet_count) 00094 00095 00096 typedef struct report_block 00097 { 00098 uint32_t ssrc; 00099 uint32_t fl_cnpl;/*fraction lost + cumulative number of packet lost*/ 00100 uint32_t ext_high_seq_num_rec; /*extended highest sequence number received */ 00101 uint32_t interarrival_jitter; 00102 uint32_t lsr; /*last SR */ 00103 uint32_t delay_snc_last_sr; /*delay since last sr*/ 00104 } report_block_t; 00105 00106 #define report_block_get_ssrc(rb) \ 00107 ntohl((rb)->ssrc) 00108 #define report_block_get_fraction_lost(rb) \ 00109 (((uint32_t)ntohl((rb)->fl_cnpl))>>24) 00110 #define report_block_get_cum_packet_loss(rb) \ 00111 (((uint32_t)ntohl((rb)->fl_cnpl)) & 0xFFFFFF) 00112 #define report_block_get_high_ext_seq(rb) \ 00113 ntohl(((report_block_t*)(rb))->ext_high_seq_num_rec) 00114 #define report_block_get_interarrival_jitter(rb) \ 00115 ntohl(((report_block_t*)(rb))->interarrival_jitter) 00116 #define report_block_get_last_SR_time(rb) \ 00117 ntohl(((report_block_t*)(rb))->lsr) 00118 #define report_block_get_last_SR_delay(rb) \ 00119 ntohl(((report_block_t*)(rb))->delay_snc_last_sr) 00120 00121 #define report_block_set_fraction_lost(rb,fl)\ 00122 ((rb)->fl_cnpl)=htonl( (ntohl((rb)->fl_cnpl) & 0xFFFFFF) | (((fl) & 0xFF)<<24)) 00123 00124 #define report_block_set_cum_packet_lost(rb,cpl)\ 00125 ((rb)->fl_cnpl)=htonl( (ntohl((rb)->fl_cnpl) & 0xFF000000) | (((cpl) & 0xFFFFFF))) 00126 00127 /* SDES packets */ 00128 00129 typedef enum { 00130 RTCP_SDES_END = 0, 00131 RTCP_SDES_CNAME = 1, 00132 RTCP_SDES_NAME = 2, 00133 RTCP_SDES_EMAIL = 3, 00134 RTCP_SDES_PHONE = 4, 00135 RTCP_SDES_LOC = 5, 00136 RTCP_SDES_TOOL = 6, 00137 RTCP_SDES_NOTE = 7, 00138 RTCP_SDES_PRIV = 8, 00139 RTCP_SDES_MAX = 9 00140 } rtcp_sdes_type_t; 00141 00142 typedef struct sdes_chunk 00143 { 00144 uint32_t csrc; 00145 } sdes_chunk_t; 00146 00147 00148 #define sdes_chunk_get_csrc(c) ntohl((c)->csrc) 00149 00150 typedef struct sdes_item 00151 { 00152 uint8_t item_type; 00153 uint8_t len; 00154 char content[1]; 00155 } sdes_item_t; 00156 00157 #define RTCP_SDES_MAX_STRING_SIZE 255 00158 #define RTCP_SDES_ITEM_HEADER_SIZE 2 00159 #define RTCP_SDES_CHUNK_DEFAULT_SIZE 1024 00160 #define RTCP_SDES_CHUNK_HEADER_SIZE (sizeof(sdes_chunk_t)) 00161 00162 /* RTCP bye packet */ 00163 00164 typedef struct rtcp_bye_reason 00165 { 00166 uint8_t len; 00167 char content[1]; 00168 } rtcp_bye_reason_t; 00169 00170 typedef struct rtcp_bye 00171 { 00172 rtcp_common_header_t ch; 00173 uint32_t ssrc[1]; /* the bye may contain several ssrc/csrc */ 00174 } rtcp_bye_t; 00175 #define RTCP_BYE_HEADER_SIZE sizeof(rtcp_bye_t) 00176 #define RTCP_BYE_REASON_MAX_STRING_SIZE 255 00177 00178 00179 00180 typedef struct rtcp_sr{ 00181 rtcp_common_header_t ch; 00182 uint32_t ssrc; 00183 sender_info_t si; 00184 report_block_t rb[1]; 00185 } rtcp_sr_t; 00186 00187 typedef struct rtcp_rr{ 00188 rtcp_common_header_t ch; 00189 uint32_t ssrc; 00190 report_block_t rb[1]; 00191 } rtcp_rr_t; 00192 00193 typedef struct rtcp_app{ 00194 rtcp_common_header_t ch; 00195 uint32_t ssrc; 00196 char name[4]; 00197 } rtcp_app_t; 00198 00199 struct _RtpSession; 00200 void rtp_session_rtcp_process_send(struct _RtpSession *s); 00201 void rtp_session_rtcp_process_recv(struct _RtpSession *s); 00202 00203 #define RTCP_DEFAULT_REPORT_INTERVAL 5 00204 00205 00206 /* packet parsing api */ 00207 00208 /*in case of coumpound packet, set read pointer of m to the beginning of the next RTCP 00209 packet */ 00210 bool_t rtcp_next_packet(mblk_t *m); 00211 /* put the read pointer at the first RTCP packet of the compound packet (as before any previous calls ot rtcp_next_packet() */ 00212 void rtcp_rewind(mblk_t *m); 00213 /* get common header*/ 00214 const rtcp_common_header_t * rtcp_get_common_header(const mblk_t *m); 00215 00216 /*Sender Report accessors */ 00217 /* check if this packet is a SR and if it is correct */ 00218 bool_t rtcp_is_SR(const mblk_t *m); 00219 uint32_t rtcp_SR_get_ssrc(const mblk_t *m); 00220 const sender_info_t * rtcp_SR_get_sender_info(const mblk_t *m); 00221 const report_block_t * rtcp_SR_get_report_block(const mblk_t *m, int idx); 00222 00223 /*Receiver report accessors*/ 00224 bool_t rtcp_is_RR(const mblk_t *m); 00225 uint32_t rtcp_RR_get_ssrc(const mblk_t *m); 00226 const report_block_t * rtcp_RR_get_report_block(const mblk_t *m,int idx); 00227 00228 /*SDES accessors */ 00229 bool_t rtcp_is_SDES(const mblk_t *m); 00230 typedef void (*SdesItemFoundCallback)(void *user_data, uint32_t csrc, rtcp_sdes_type_t t, const char *content, uint8_t content_len); 00231 void rtcp_sdes_parse(const mblk_t *m, SdesItemFoundCallback cb, void *user_data); 00232 00233 /*BYE accessors */ 00234 bool_t rtcp_is_BYE(const mblk_t *m); 00235 bool_t rtcp_BYE_get_ssrc(const mblk_t *m, int idx, uint32_t *ssrc); 00236 bool_t rtcp_BYE_get_reason(const mblk_t *m, const char **reason, int *reason_len); 00237 00238 /*APP accessors */ 00239 bool_t rtcp_is_APP(const mblk_t *m); 00240 int rtcp_APP_get_subtype(const mblk_t *m); 00241 uint32_t rtcp_APP_get_ssrc(const mblk_t *m); 00242 /* name argument is supposed to be at least 4 characters (note: no '\0' written)*/ 00243 void rtcp_APP_get_name(const mblk_t *m, char *name); 00244 /* retrieve the data. when returning, data points directly into the mblk_t */ 00245 void rtcp_APP_get_data(const mblk_t *m, uint8_t **data, int *len); 00246 00247 00248 #ifdef __cplusplus 00249 } 00250 #endif 00251 00252 #endif