oRTP  0.23.0
rtcp.h
1 /*
2  The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
3  Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 
21 #ifndef RTCP_H
22 #define RTCP_H
23 
24 #include <ortp/port.h>
25 
26 #define RTCP_MAX_RECV_BUFSIZE 1500
27 
28 #define RTCP_SENDER_INFO_SIZE 20
29 #define RTCP_REPORT_BLOCK_SIZE 24
30 #define RTCP_COMMON_HEADER_SIZE 4
31 #define RTCP_SSRC_FIELD_SIZE 4
32 
33 #ifdef __cplusplus
34 extern "C"{
35 #endif
36 
37 /* RTCP common header */
38 
39 typedef enum {
40  RTCP_SR = 200,
41  RTCP_RR = 201,
42  RTCP_SDES = 202,
43  RTCP_BYE = 203,
44  RTCP_APP = 204
45 } rtcp_type_t;
46 
47 
48 typedef struct rtcp_common_header
49 {
50 #ifdef ORTP_BIGENDIAN
51  uint16_t version:2;
52  uint16_t padbit:1;
53  uint16_t rc:5;
54  uint16_t packet_type:8;
55 #else
56  uint16_t rc:5;
57  uint16_t padbit:1;
58  uint16_t version:2;
59  uint16_t packet_type:8;
60 #endif
61  uint16_t length:16;
63 
64 #define rtcp_common_header_set_version(ch,v) (ch)->version=v
65 #define rtcp_common_header_set_padbit(ch,p) (ch)->padbit=p
66 #define rtcp_common_header_set_rc(ch,rc) (ch)->rc=rc
67 #define rtcp_common_header_set_packet_type(ch,pt) (ch)->packet_type=pt
68 #define rtcp_common_header_set_length(ch,l) (ch)->length=htons(l)
69 
70 #define rtcp_common_header_get_version(ch) ((ch)->version)
71 #define rtcp_common_header_get padbit(ch) ((ch)->padbit)
72 #define rtcp_common_header_get_rc(ch) ((ch)->rc)
73 #define rtcp_common_header_get_packet_type(ch) ((ch)->packet_type)
74 #define rtcp_common_header_get_length(ch) ntohs((ch)->length)
75 
76 
77 /* SR or RR packets */
78 
79 typedef struct sender_info
80 {
81  uint32_t ntp_timestamp_msw;
82  uint32_t ntp_timestamp_lsw;
83  uint32_t rtp_timestamp;
84  uint32_t senders_packet_count;
85  uint32_t senders_octet_count;
87 
88 uint64_t sender_info_get_ntp_timestamp(const sender_info_t *si);
89 #define sender_info_get_rtp_timestamp(si) ((si)->rtp_timestamp)
90 #define sender_info_get_packet_count(si) \
91  ntohl((si)->senders_packet_count)
92 #define sender_info_get_octet_count(si) \
93  ntohl((si)->senders_octet_count)
94 
95 
96 typedef struct report_block
97 {
98  uint32_t ssrc;
99  uint32_t fl_cnpl;/*fraction lost + cumulative number of packet lost*/
100  uint32_t ext_high_seq_num_rec; /*extended highest sequence number received */
101  uint32_t interarrival_jitter;
102  uint32_t lsr; /*last SR */
103  uint32_t delay_snc_last_sr; /*delay since last sr*/
105 
106 #define report_block_get_ssrc(rb) \
107  ntohl((rb)->ssrc)
108 #define report_block_get_fraction_lost(rb) \
109  (((uint32_t)ntohl((rb)->fl_cnpl))>>24)
110 #define report_block_get_cum_packet_loss(rb) \
111  (((uint32_t)ntohl((rb)->fl_cnpl)) & 0xFFFFFF)
112 #define report_block_get_high_ext_seq(rb) \
113  ntohl(((report_block_t*)(rb))->ext_high_seq_num_rec)
114 #define report_block_get_interarrival_jitter(rb) \
115  ntohl(((report_block_t*)(rb))->interarrival_jitter)
116 #define report_block_get_last_SR_time(rb) \
117  ntohl(((report_block_t*)(rb))->lsr)
118 #define report_block_get_last_SR_delay(rb) \
119  ntohl(((report_block_t*)(rb))->delay_snc_last_sr)
120 
121 #define report_block_set_fraction_lost(rb,fl)\
122  ((rb)->fl_cnpl)=htonl( (ntohl((rb)->fl_cnpl) & 0xFFFFFF) | (((fl) & 0xFF)<<24))
123 
124 #define report_block_set_cum_packet_lost(rb,cpl)\
125  ((rb)->fl_cnpl)=htonl( (ntohl((rb)->fl_cnpl) & 0xFF000000) | (((cpl) & 0xFFFFFF)))
126 
127 /* SDES packets */
128 
129 typedef enum {
130  RTCP_SDES_END = 0,
131  RTCP_SDES_CNAME = 1,
132  RTCP_SDES_NAME = 2,
133  RTCP_SDES_EMAIL = 3,
134  RTCP_SDES_PHONE = 4,
135  RTCP_SDES_LOC = 5,
136  RTCP_SDES_TOOL = 6,
137  RTCP_SDES_NOTE = 7,
138  RTCP_SDES_PRIV = 8,
139  RTCP_SDES_MAX = 9
140 } rtcp_sdes_type_t;
141 
142 typedef struct sdes_chunk
143 {
144  uint32_t csrc;
145 } sdes_chunk_t;
146 
147 
148 #define sdes_chunk_get_csrc(c) ntohl((c)->csrc)
149 
150 typedef struct sdes_item
151 {
152  uint8_t item_type;
153  uint8_t len;
154  char content[1];
155 } sdes_item_t;
156 
157 #define RTCP_SDES_MAX_STRING_SIZE 255
158 #define RTCP_SDES_ITEM_HEADER_SIZE 2
159 #define RTCP_SDES_CHUNK_DEFAULT_SIZE 1024
160 #define RTCP_SDES_CHUNK_HEADER_SIZE (sizeof(sdes_chunk_t))
161 
162 /* RTCP bye packet */
163 
164 typedef struct rtcp_bye_reason
165 {
166  uint8_t len;
167  char content[1];
169 
170 typedef struct rtcp_bye
171 {
173  uint32_t ssrc[1]; /* the bye may contain several ssrc/csrc */
174 } rtcp_bye_t;
175 #define RTCP_BYE_HEADER_SIZE sizeof(rtcp_bye_t)
176 #define RTCP_BYE_REASON_MAX_STRING_SIZE 255
177 
178 
179 
180 typedef struct rtcp_sr{
182  uint32_t ssrc;
183  sender_info_t si;
184  report_block_t rb[1];
185 } rtcp_sr_t;
186 
187 typedef struct rtcp_rr{
189  uint32_t ssrc;
190  report_block_t rb[1];
191 } rtcp_rr_t;
192 
193 typedef struct rtcp_app{
195  uint32_t ssrc;
196  char name[4];
197 } rtcp_app_t;
198 
199 struct _RtpSession;
200 ORTP_PUBLIC void rtp_session_rtcp_process_send(struct _RtpSession *s);
201 ORTP_PUBLIC void rtp_session_rtcp_process_recv(struct _RtpSession *s);
202 
203 
204 #define RTCP_DEFAULT_REPORT_INTERVAL 5000 /*ms*/
205 
206 
207 /* packet parsing api */
208 
209 /*in case of coumpound packet, set read pointer of m to the beginning of the next RTCP
210 packet */
211 ORTP_PUBLIC bool_t rtcp_next_packet(mblk_t *m);
212 /* put the read pointer at the first RTCP packet of the compound packet (as before any previous calls ot rtcp_next_packet() */
213 ORTP_PUBLIC void rtcp_rewind(mblk_t *m);
214 /* get common header*/
215 ORTP_PUBLIC const rtcp_common_header_t * rtcp_get_common_header(const mblk_t *m);
216 
217 /*Sender Report accessors */
218 /* check if this packet is a SR and if it is correct */
219 ORTP_PUBLIC bool_t rtcp_is_SR(const mblk_t *m);
220 ORTP_PUBLIC uint32_t rtcp_SR_get_ssrc(const mblk_t *m);
221 ORTP_PUBLIC const sender_info_t * rtcp_SR_get_sender_info(const mblk_t *m);
222 ORTP_PUBLIC const report_block_t * rtcp_SR_get_report_block(const mblk_t *m, int idx);
223 
224 /*Receiver report accessors*/
225 ORTP_PUBLIC bool_t rtcp_is_RR(const mblk_t *m);
226 ORTP_PUBLIC uint32_t rtcp_RR_get_ssrc(const mblk_t *m);
227 ORTP_PUBLIC const report_block_t * rtcp_RR_get_report_block(const mblk_t *m,int idx);
228 
229 /*SDES accessors */
230 ORTP_PUBLIC bool_t rtcp_is_SDES(const mblk_t *m);
231 typedef void (*SdesItemFoundCallback)(void *user_data, uint32_t csrc, rtcp_sdes_type_t t, const char *content, uint8_t content_len);
232 ORTP_PUBLIC void rtcp_sdes_parse(const mblk_t *m, SdesItemFoundCallback cb, void *user_data);
233 
234 /*BYE accessors */
235 ORTP_PUBLIC bool_t rtcp_is_BYE(const mblk_t *m);
236 ORTP_PUBLIC bool_t rtcp_BYE_get_ssrc(const mblk_t *m, int idx, uint32_t *ssrc);
237 ORTP_PUBLIC bool_t rtcp_BYE_get_reason(const mblk_t *m, const char **reason, int *reason_len);
238 
239 /*APP accessors */
240 ORTP_PUBLIC bool_t rtcp_is_APP(const mblk_t *m);
241 ORTP_PUBLIC int rtcp_APP_get_subtype(const mblk_t *m);
242 ORTP_PUBLIC uint32_t rtcp_APP_get_ssrc(const mblk_t *m);
243 /* name argument is supposed to be at least 4 characters (note: no '\0' written)*/
244 ORTP_PUBLIC void rtcp_APP_get_name(const mblk_t *m, char *name);
245 /* retrieve the data. when returning, data points directly into the mblk_t */
246 ORTP_PUBLIC void rtcp_APP_get_data(const mblk_t *m, uint8_t **data, int *len);
247 
248 
249 #ifdef __cplusplus
250 }
251 #endif
252 
253 #endif
Definition: rtcp.h:96
Definition: rtcp.h:170
Definition: rtpsession.h:201
Definition: str_utils.h:49
Definition: rtcp.h:48
Definition: rtcp.h:164
Definition: rtcp.h:193
Definition: rtcp.h:187
Definition: rtcp.h:150
Definition: rtcp.h:142
Definition: rtcp.h:180
Definition: rtcp.h:79