a-oRTP  5.2.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 #ifndef RTCP_H
21 #define RTCP_H
22 
23 #include <ortp/port.h>
24 
25 #define RTCP_MAX_RECV_BUFSIZE 1500
26 
27 #define RTCP_SENDER_INFO_SIZE 20
28 #define RTCP_REPORT_BLOCK_SIZE 24
29 #define RTCP_XREPORT_BLOCK_SIZE 4
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_RTPFB = 205,
46  RTCP_PSFB = 206,
47  RTCP_XR = 207,
48 } rtcp_type_t;
49 
50 typedef struct rtcp_common_header {
51 #ifdef ORTP_BIGENDIAN
52  uint16_t version : 2;
53  uint16_t padbit : 1;
54  uint16_t rc : 5;
55  uint16_t packet_type : 8;
56 #else
57  uint16_t rc : 5;
58  uint16_t padbit : 1;
59  uint16_t version : 2;
60  uint16_t packet_type : 8;
61 #endif
62  uint16_t length : 16;
64 
65 #define rtcp_common_header_set_version(ch, v) (ch)->version = v
66 #define rtcp_common_header_set_padbit(ch, p) (ch)->padbit = p
67 #define rtcp_common_header_set_rc(ch, rc) (ch)->rc = rc
68 #define rtcp_common_header_set_packet_type(ch, pt) (ch)->packet_type = pt
69 #define rtcp_common_header_set_length(ch, l) (ch)->length = htons(l)
70 
71 #define rtcp_common_header_get_version(ch) ((ch)->version)
72 #define rtcp_common_header_get padbit(ch)((ch)->padbit)
73 #define rtcp_common_header_get_rc(ch) ((ch)->rc)
74 #define rtcp_common_header_get_packet_type(ch) ((ch)->packet_type)
75 #define rtcp_common_header_get_length(ch) ntohs((ch)->length)
76 
77 /* SR or RR packets */
78 
79 typedef struct sender_info {
80  uint32_t ntp_timestamp_msw;
81  uint32_t ntp_timestamp_lsw;
82  uint32_t rtp_timestamp;
83  uint32_t senders_packet_count;
84  uint32_t senders_octet_count;
86 
87 uint64_t sender_info_get_ntp_timestamp(const sender_info_t *si);
88 #define sender_info_get_rtp_timestamp(si) ((si)->rtp_timestamp)
89 #define sender_info_get_packet_count(si) ntohl((si)->senders_packet_count)
90 #define sender_info_get_octet_count(si) ntohl((si)->senders_octet_count)
91 
92 typedef struct report_block {
93  uint32_t ssrc;
94  uint32_t fl_cnpl; /*fraction lost + cumulative number of packet lost*/
95  uint32_t ext_high_seq_num_rec; /*extended highest sequence number received */
96  uint32_t interarrival_jitter;
97  uint32_t lsr; /*last SR */
98  uint32_t delay_snc_last_sr; /*delay since last sr*/
100 
101 #define report_block_get_ssrc(rb) ntohl((rb)->ssrc)
102 #define report_block_get_fraction_lost(rb) (((uint32_t) ntohl((rb)->fl_cnpl)) >> 24)
103 #define report_block_get_cum_packet_loss(rb) (((uint32_t) ntohl((rb)->fl_cnpl)) & 0xFFFFFF)
104 #define report_block_get_high_ext_seq(rb) ntohl(((report_block_t *) (rb))->ext_high_seq_num_rec)
105 #define report_block_get_interarrival_jitter(rb) ntohl(((report_block_t *) (rb))->interarrival_jitter)
106 #define report_block_get_last_SR_time(rb) ntohl(((report_block_t *) (rb))->lsr)
107 #define report_block_get_last_SR_delay(rb) ntohl(((report_block_t *) (rb))->delay_snc_last_sr)
108 
109 #define report_block_set_fraction_lost(rb, fl) ((rb)->fl_cnpl) = htonl((ntohl((rb)->fl_cnpl) & 0xFFFFFF) | (((fl) &0xFF) << 24))
110 
111 #define report_block_set_cum_packet_lost(rb, cpl) ((rb)->fl_cnpl) = htonl((ntohl((rb)->fl_cnpl) & 0xFF000000) | (((cpl) &0xFFFFFF)))
112 
113 /* SDES packets */
114 
115 typedef enum { RTCP_SDES_END = 0, RTCP_SDES_CNAME = 1, RTCP_SDES_NAME = 2, RTCP_SDES_EMAIL = 3, RTCP_SDES_PHONE = 4, RTCP_SDES_LOC = 5, RTCP_SDES_TOOL = 6, RTCP_SDES_NOTE = 7, RTCP_SDES_PRIV = 8, RTCP_SDES_MAX = 9 } rtcp_sdes_type_t;
116 
117 typedef struct sdes_chunk {
118  uint32_t csrc;
119 } sdes_chunk_t;
120 
121 #define sdes_chunk_get_csrc(c) ntohl((c)->csrc)
122 
123 typedef struct sdes_item {
124  uint8_t item_type;
125  uint8_t len;
126  char content[1];
127 } sdes_item_t;
128 
129 #define RTCP_SDES_MAX_STRING_SIZE 255
130 #define RTCP_SDES_ITEM_HEADER_SIZE 2
131 #define RTCP_SDES_CHUNK_DEFAULT_SIZE 1024
132 #define RTCP_SDES_CHUNK_HEADER_SIZE (sizeof(sdes_chunk_t))
133 
134 /* RTCP bye packet */
135 
136 typedef struct rtcp_bye_reason {
137  uint8_t len;
138  char content[1];
140 
141 typedef struct rtcp_bye {
143  uint32_t ssrc[1]; /* the bye may contain several ssrc/csrc */
144 } rtcp_bye_t;
145 #define RTCP_BYE_HEADER_SIZE sizeof(rtcp_bye_t)
146 #define RTCP_BYE_REASON_MAX_STRING_SIZE 255
147 
148 typedef struct rtcp_sr {
150  uint32_t ssrc;
151  sender_info_t si;
152  report_block_t rb[1];
153 } rtcp_sr_t;
154 
155 typedef struct rtcp_rr {
157  uint32_t ssrc;
158  report_block_t rb[1];
159 } rtcp_rr_t;
160 
161 typedef struct rtcp_app {
163  uint32_t ssrc;
164  char name[4];
165 } rtcp_app_t;
166 
167 /* rfc3611 */
168 #define RTCP_XR_LRLE 1
169 #define RTCP_XR_DRLE 2
170 #define RTCP_XR_PRT 3
171 #define RTCP_XR_RR 4
172 #define RTCP_XR_DLRR 5
173 #define RTCP_XR_SS 6
174 #define RTCP_XR_VM 7
175 #define RTCP_XR_DM 16 /* Delay metrics block */
176 
177 /* rfc7005 */
178 #define RTCP_XR_DJB 23 /* De-Jitter Buffer Metrics block */
179 
180 typedef struct rtcp_xr_rrt {
181  uint32_t ntp_timestamp_msw;
182  uint32_t ntp_timestamp_lsw;
183 } rtcp_xr_rrt_t;
184 
185 typedef struct rtcp_xr_dlrr {
186  uint32_t ssrc;
187  uint32_t last_rr;
188  uint32_t delaysince_last_rr;
190 
191 typedef struct rtcp_xr_ss /* flags in type-specific: L|D|J|ToH|rsvd.*/
192 {
193  uint32_t ssrc;
194  uint16_t begin_seq;
195  uint16_t end_seq;
196  uint32_t lost_packets;
197  uint32_t dup_packets;
198  uint32_t min_jitter;
199  uint32_t max_jitter;
200  uint32_t mean_jitter;
201  uint32_t dev_jitter;
202  uint8_t min_ttl_or_hl;
203  uint8_t max_ttl_or_hl;
204  uint8_t mean_ttl_or_hl;
205  uint8_t dev_ttl_or_hl;
206 } rtcp_xr_ss_t;
207 
208 typedef struct rtcp_xr_vm {
209  uint32_t ssrc;
210  uint8_t loss_rate;
211  uint8_t discard_rate;
212  uint8_t burst_density;
213  uint8_t gap_density;
214  uint16_t burst_duration;
215  uint16_t gap_duration;
216  uint16_t round_trip_delay;
217  uint16_t end_system_delay;
218  uint8_t signal_level;
219  uint8_t noise_level;
220  uint8_t RERL;
221  uint8_t Gmin;
222  uint8_t R_factor;
223  uint8_t ext_R_factor;
224  uint8_t MOS_LQ;
225  uint8_t MOS_CQ;
226  uint8_t RX_config;
227  uint8_t reserved;
228  uint16_t JB_nominal;
229  uint16_t JB_maximum;
230  uint16_t JB_abs_max;
231 } rtcp_xr_vm_t;
232 
233 typedef struct rtcp_xr_djb {
234  uint32_t ssrc;
235  uint16_t djb_nominal;
236  uint16_t djb_maximum;
237  uint16_t djb_highwater_mark;
238  uint16_t djb_lowwater_mark;
239 } rtcp_xr_djb_t;
240 
241 typedef struct xreport_block {
242  uint8_t BT : 8;
243  uint8_t type_specific : 8;
244  uint16_t block_len : 16;
246 
247 typedef struct rtcp_xr {
249  uint32_t ssrc;
250  xreport_block_t rb[1];
251 } rtcp_xr_t;
252 
253 typedef struct rtcp_fb {
255  uint32_t ssrc_sender;
256  uint32_t ssrc_local;
257 } rtcp_fb_t;
258 
259 struct _RtpSession;
260 void rtp_session_rtcp_process_send(struct _RtpSession *s);
261 void rtp_session_rtcp_process_recv(struct _RtpSession *s);
262 
263 #define RTCP_DEFAULT_REPORT_INTERVAL 5
264 #define RTCP_DEFAULT_REPORT_INTERVAL_VIDEO 1
265 
266 /* packet parsing api */
267 
268 /*in case of coumpound packet, set read pointer of m to the beginning of the next RTCP
269 packet */
270 bool_t rtcp_next_packet(mblk_t *m);
271 /* put the read pointer at the first RTCP packet of the compound packet (as before any previous calls ot rtcp_next_packet() */
272 void rtcp_rewind(mblk_t *m);
273 /* get common header*/
274 const rtcp_common_header_t *rtcp_get_common_header(const mblk_t *m);
275 
276 /*Sender Report accessors */
277 /* check if this packet is a SR and if it is correct */
278 bool_t rtcp_is_SR(const mblk_t *m);
279 uint32_t rtcp_SR_get_ssrc(const mblk_t *m);
280 const sender_info_t *rtcp_SR_get_sender_info(const mblk_t *m);
281 const report_block_t *rtcp_SR_get_report_block(const mblk_t *m, int idx);
282 
283 /*Receiver report accessors*/
284 bool_t rtcp_is_RR(const mblk_t *m);
285 uint32_t rtcp_RR_get_ssrc(const mblk_t *m);
286 const report_block_t *rtcp_RR_get_report_block(const mblk_t *m, int idx);
287 
288 /*SDES accessors */
289 bool_t rtcp_is_SDES(const mblk_t *m);
290 typedef void (*SdesItemFoundCallback)(void *user_data, uint32_t csrc, rtcp_sdes_type_t t, const char *content, uint8_t content_len);
291 void rtcp_sdes_parse(const mblk_t *m, SdesItemFoundCallback cb, void *user_data);
292 
293 /*BYE accessors */
294 bool_t rtcp_is_BYE(const mblk_t *m);
295 bool_t rtcp_BYE_get_ssrc(const mblk_t *m, int idx, uint32_t *ssrc);
296 bool_t rtcp_BYE_get_reason(const mblk_t *m, const char **reason, int *reason_len);
297 
298 /*APP accessors */
299 bool_t rtcp_is_APP(const mblk_t *m);
300 int rtcp_APP_get_subtype(const mblk_t *m);
301 uint32_t rtcp_APP_get_ssrc(const mblk_t *m);
302 /* name argument is supposed to be at least 4 characters (note: no '\0' written)*/
303 void rtcp_APP_get_name(const mblk_t *m, char *name);
304 /* retrieve the data. when returning, data points directly into the mblk_t */
305 void rtcp_APP_get_data(const mblk_t *m, uint8_t **data, int *len);
306 
307 bool_t rtcp_is_RTPFB(const mblk_t *m);
308 bool_t rtcp_is_PSFB(const mblk_t *m);
309 
310 #ifdef __cplusplus
311 }
312 #endif
313 
314 #endif
Definition: rtpsession.h:261
Definition: str_utils.h:25
Definition: rtcp.h:92
Definition: rtcp.h:161
Definition: rtcp.h:136
Definition: rtcp.h:141
Definition: rtcp.h:50
Definition: rtcp.h:253
Definition: rtcp.h:155
Definition: rtcp.h:148
Definition: rtcp.h:233
Definition: rtcp.h:185
Definition: rtcp.h:180
Definition: rtcp.h:192
Definition: rtcp.h:208
Definition: rtcp.h:247
Definition: rtcp.h:117
Definition: rtcp.h:123
Definition: rtcp.h:79
Definition: rtcp.h:241