reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
rtcp.c
Go to the documentation of this file.
1
6#include <string.h>
7#include <re_types.h>
8#include <re_fmt.h>
9#include <re_mem.h>
10#include <re_mbuf.h>
11#include <re_list.h>
12#include <re_sa.h>
13#include <re_rtp.h>
14#include "rtcp.h"
15
16
17static int rtcp_quick_send(struct rtp_sock *rs, enum rtcp_type type,
18 uint32_t count, ...)
19{
20 struct mbuf *mb;
21 va_list ap;
22 int err;
23
24 mb = mbuf_alloc(32);
25 if (!mb)
26 return ENOMEM;
27
28 mb->pos = RTCP_HEADROOM;
29
30 va_start(ap, count);
31 err = rtcp_vencode(mb, type, count, ap);
32 va_end(ap);
33
34 mb->pos = RTCP_HEADROOM;
35
36 if (!err)
37 err = rtcp_send(rs, mb);
38
40
41 return err;
42}
43
44
55int rtcp_send_app(struct rtp_sock *rs, const char name[4],
56 const uint8_t *data, size_t len)
57{
59 name, data, len);
60}
61
62
72{
73 return rtcp_quick_send(rs, RTCP_FIR, 0, ssrc);
74}
75
76
90
91
105
106
107const char *rtcp_type_name(enum rtcp_type type)
108{
109 switch (type) {
110
111 case RTCP_FIR: return "FIR";
112 case RTCP_NACK: return "NACK";
113 case RTCP_SR: return "SR";
114 case RTCP_RR: return "RR";
115 case RTCP_SDES: return "SDES";
116 case RTCP_BYE: return "BYE";
117 case RTCP_APP: return "APP";
118 case RTCP_RTPFB: return "RTPFB";
119 case RTCP_PSFB: return "PSFB";
120 case RTCP_XR: return "XR";
121 case RTCP_AVB: return "AVB";
122 default: return "?";
123 }
124}
125
126
128{
129 switch (sdes) {
130
131 case RTCP_SDES_END: return "END";
132 case RTCP_SDES_CNAME: return "CNAME";
133 case RTCP_SDES_NAME: return "NAME";
134 case RTCP_SDES_EMAIL: return "EMAIL";
135 case RTCP_SDES_PHONE: return "PHONE";
136 case RTCP_SDES_LOC: return "LOC";
137 case RTCP_SDES_TOOL: return "TOOL";
138 case RTCP_SDES_NOTE: return "NOTE";
139 case RTCP_SDES_PRIV: return "PRIV";
140 default: return "?";
141 }
142}
143
144
153int rtcp_msg_print(struct re_printf *pf, const struct rtcp_msg *msg)
154{
155 size_t i, j;
156 int err;
157
158 if (!msg)
159 return 0;
160
161 err = re_hprintf(pf, "%8s pad=%d count=%-2d pt=%-3d len=%u ",
162 rtcp_type_name((enum rtcp_type)msg->hdr.pt),
163 msg->hdr.p,
164 msg->hdr.count, msg->hdr.pt, msg->hdr.length);
165 if (err)
166 return err;
167
168 switch (msg->hdr.pt) {
169
170 case RTCP_SR:
171 err = re_hprintf(pf, "%08x %u %u %u %u %u",
172 msg->r.sr.ssrc,
173 msg->r.sr.ntp_sec,
174 msg->r.sr.ntp_frac,
175 msg->r.sr.rtp_ts,
176 msg->r.sr.psent,
177 msg->r.sr.osent);
178 for (i=0; i<msg->hdr.count && !err; i++) {
179 const struct rtcp_rr *rr = &msg->r.sr.rrv[i];
180 err = re_hprintf(pf, " {%08x %u %d %u %u %u %u}",
181 rr->ssrc, rr->fraction, rr->lost,
182 rr->last_seq, rr->jitter,
183 rr->lsr, rr->dlsr);
184 }
185 break;
186
187 case RTCP_RR:
188 err = re_hprintf(pf, "%08x", msg->r.rr.ssrc);
189 for (i=0; i<msg->hdr.count && !err; i++) {
190 const struct rtcp_rr *rr = &msg->r.rr.rrv[i];
191 err = re_hprintf(pf, " {0x%08x %u %d %u %u %u %u}",
192 rr->ssrc, rr->fraction, rr->lost,
193 rr->last_seq, rr->jitter,
194 rr->lsr, rr->dlsr);
195 }
196 break;
197
198 case RTCP_SDES:
199 for (i=0; i<msg->hdr.count; i++) {
200 const struct rtcp_sdes *sdes = &msg->r.sdesv[i];
201
202 err = re_hprintf(pf, " {0x%08x n=%u",
203 sdes->src, sdes->n);
204 for (j=0; j<sdes->n && !err; j++) {
205 const struct rtcp_sdes_item *item;
206 item = &sdes->itemv[j];
207 err = re_hprintf(pf, " <%s:%b>",
208 rtcp_sdes_name(item->type),
209 item->data,
210 (size_t)item->length);
211 }
212 err |= re_hprintf(pf, "}");
213 }
214 break;
215
216 case RTCP_BYE:
217 err = re_hprintf(pf, "%u srcs:", msg->hdr.count);
218 for (i=0; i<msg->hdr.count && !err; i++) {
219 err = re_hprintf(pf, " %08x",
220 msg->r.bye.srcv[i]);
221 }
222 err |= re_hprintf(pf, " '%s'", msg->r.bye.reason);
223 break;
224
225 case RTCP_APP:
226 err = re_hprintf(pf, "src=%08x '%b' data=%zu",
227 msg->r.app.src,
228 msg->r.app.name, sizeof(msg->r.app.name),
229 msg->r.app.data_len);
230 break;
231
232 case RTCP_FIR:
233 err = re_hprintf(pf, "ssrc=%08x", msg->r.fir.ssrc);
234 break;
235
236 case RTCP_NACK:
237 err = re_hprintf(pf, "ssrc=%08x fsn=%04x blp=%04x",
238 msg->r.nack.ssrc, msg->r.nack.fsn,
239 msg->r.nack.blp);
240 break;
241
242 case RTCP_RTPFB:
243 err = re_hprintf(pf, "pkt=%08x med=%08x n=%u",
244 msg->r.fb.ssrc_packet,
245 msg->r.fb.ssrc_media,
246 msg->r.fb.n);
247 if (msg->hdr.count == RTCP_RTPFB_GNACK) {
248 err |= re_hprintf(pf, " GNACK");
249 for (i=0; i<msg->r.fb.n; i++) {
250 err |= re_hprintf(pf, " {%04x %04x}",
251 msg->r.fb.fci.gnackv[i].pid,
252 msg->r.fb.fci.gnackv[i].blp);
253 }
254 }
255 break;
256
257 case RTCP_PSFB:
258 err = re_hprintf(pf, "pkt=%08x med=%08x n=%u",
259 msg->r.fb.ssrc_packet,
260 msg->r.fb.ssrc_media,
261 msg->r.fb.n);
262 if (msg->hdr.count == RTCP_PSFB_SLI) {
263 err |= re_hprintf(pf, " SLI");
264 for (i=0; i<msg->r.fb.n; i++) {
265 err |= re_hprintf(pf, " {%04x %04x %02x}",
266 msg->r.fb.fci.sliv[i].first,
267 msg->r.fb.fci.sliv[i].number,
268 msg->r.fb.fci.sliv[i].picid);
269 }
270 }
271 else if (msg->hdr.count == RTCP_PSFB_AFB) {
272 err |= re_hprintf(pf, " AFB %u bytes",
273 msg->r.fb.n * 4);
274 }
275 break;
276
277 default:
278 err = re_hprintf(pf, "<len=%u>", msg->hdr.length);
279 break;
280 }
281
282 err |= re_hprintf(pf, "\n");
283
284 return err;
285}
Interface to Real-time Transport Protocol and RTCP.
@ RTCP_RTPFB_GNACK
Generic NACK.
Definition re_rtp.h:65
rtcp_sdes_type
SDES Types.
Definition re_rtp.h:51
@ RTCP_SDES_NOTE
Notice about the source
Definition re_rtp.h:59
@ RTCP_SDES_CNAME
Canonical name
Definition re_rtp.h:53
@ RTCP_SDES_PHONE
User's phone number
Definition re_rtp.h:56
@ RTCP_SDES_TOOL
Name of application or tool
Definition re_rtp.h:58
@ RTCP_SDES_LOC
Geographic user location
Definition re_rtp.h:57
@ RTCP_SDES_EMAIL
User's electronic mail address.
Definition re_rtp.h:55
@ RTCP_SDES_END
End of SDES list
Definition re_rtp.h:52
@ RTCP_SDES_NAME
User name
Definition re_rtp.h:54
@ RTCP_SDES_PRIV
Private extension
Definition re_rtp.h:60
rtcp_type
RTCP Packet Types.
Definition re_rtp.h:36
@ RTCP_APP
Application-defined
Definition re_rtp.h:43
@ RTCP_RTPFB
Transport layer FB message (RFC 4585)
Definition re_rtp.h:44
@ RTCP_RR
Receiver Report
Definition re_rtp.h:40
@ RTCP_SR
Sender Report
Definition re_rtp.h:39
@ RTCP_XR
Extended Report (RFC 3611)
Definition re_rtp.h:46
@ RTCP_PSFB
Payload-specific FB message (RFC 4585)
Definition re_rtp.h:45
@ RTCP_SDES
Source Description
Definition re_rtp.h:41
@ RTCP_FIR
Full INTRA-frame Request (RFC 2032)
Definition re_rtp.h:37
@ RTCP_NACK
Negative Acknowledgement (RFC 2032)
Definition re_rtp.h:38
@ RTCP_AVB
AVB RTCP Packet (IEEE1733)
Definition re_rtp.h:47
@ RTCP_BYE
Goodbye
Definition re_rtp.h:42
void * rtp_sock(const struct rtp_sock *rs)
@ RTCP_PSFB_AFB
Application layer Feedback Messages.
Definition re_rtp.h:72
@ RTCP_PSFB_PLI
Picture Loss Indication (PLI)
Definition re_rtp.h:70
@ RTCP_PSFB_SLI
Slice Loss Indication (SLI)
Definition re_rtp.h:71
uint32_t rtp_sess_ssrc(const struct rtp_sock *rs)
int rtcp_send_app(struct rtp_sock *rs, const char name[4], const uint8_t *data, size_t len)
Send an RTCP Application-Defined (APP) packet.
Definition rtcp.c:55
int rtcp_send_pli(struct rtp_sock *rs, uint32_t fb_ssrc)
Send an RTCP Picture Loss Indication (PLI) packet.
Definition rtcp.c:100
static int rtcp_quick_send(struct rtp_sock *rs, enum rtcp_type type, uint32_t count,...)
Definition rtcp.c:17
int rtcp_msg_print(struct re_printf *pf, const struct rtcp_msg *msg)
Print an RTCP Message.
Definition rtcp.c:153
int rtcp_send_nack(struct rtp_sock *rs, uint16_t fsn, uint16_t blp)
Send an RTCP NACK packet.
Definition rtcp.c:86
const char * rtcp_type_name(enum rtcp_type type)
Definition rtcp.c:107
int rtcp_send_fir(struct rtp_sock *rs, uint32_t ssrc)
Send a Full INTRA-frame Request (FIR) packet.
Definition rtcp.c:71
const char * rtcp_sdes_name(enum rtcp_sdes_type sdes)
Definition rtcp.c:127
unsigned short uint16_t
Definition stdint.h:84
unsigned int uint32_t
Definition stdint.h:85
unsigned char uint8_t
Definition stdint.h:83
unsigned int p
Padding flag
Definition re_rtp.h:99
unsigned int pt
RTCP packet type
Definition re_rtp.h:101
unsigned int count
Varies by packet type
Definition re_rtp.h:100
uint16_t length
Packet length in words.
Definition re_rtp.h:102
One RTCP Message.
Definition re_rtp.h:95
union rtcp_msg::@11 r
uint32_t ntp_sec
NTP timestamp - seconds
Definition re_rtp.h:108
uint32_t osent
RTP octets sent
Definition re_rtp.h:112
struct rtcp_msg::rtcp_hdr hdr
struct rtcp_msg::@11::@12 sr
Sender report (SR)
uint32_t ssrc
Sender generating report
Definition re_rtp.h:107
struct rtcp_msg::@11::@13 rr
Reception report (RR)
uint32_t ntp_frac
NTP timestamp - fractions.
Definition re_rtp.h:109
struct rtcp_rr rrv[1]
Reception report blocks
Definition re_rtp.h:113
uint32_t psent
RTP packets sent
Definition re_rtp.h:111
uint32_t rtp_ts
RTP timestamp
Definition re_rtp.h:110
Reception report block.
Definition re_rtp.h:76
uint32_t lsr
Last SR packet from this source.
Definition re_rtp.h:83
uint32_t dlsr
Delay since last SR packet
Definition re_rtp.h:84
uint32_t jitter
Interarrival jitter
Definition re_rtp.h:82
uint32_t ssrc
Data source being reported
Definition re_rtp.h:77
uint32_t last_seq
Extended last seq.
Definition re_rtp.h:81
SDES item.
Definition re_rtp.h:88
void list()
Definition userAdmin.cxx:66