Fork me on GitHub
rtcp.h
Go to the documentation of this file.
1 
16 #ifndef _JANUS_RTCP_H
17 #define _JANUS_RTCP_H
18 
19 #include <arpa/inet.h>
20 #ifdef __MACH__
21 #include <machine/endian.h>
22 #else
23 #include <endian.h>
24 #endif
25 #include <inttypes.h>
26 #include <string.h>
27 
29 typedef enum {
30  RTCP_FIR = 192,
31  RTCP_SR = 200,
32  RTCP_RR = 201,
33  RTCP_SDES = 202,
34  RTCP_BYE = 203,
35  RTCP_APP = 204,
36  RTCP_RTPFB = 205,
37  RTCP_PSFB = 206,
38  RTCP_XR = 207,
39 } rtcp_type;
40 
41 
43 typedef struct rtcp_header
44 {
45 #if __BYTE_ORDER == __BIG_ENDIAN
46  uint16_t version:2;
47  uint16_t padding:1;
48  uint16_t rc:5;
49  uint16_t type:8;
50 #elif __BYTE_ORDER == __LITTLE_ENDIAN
51  uint16_t rc:5;
52  uint16_t padding:1;
53  uint16_t version:2;
54  uint16_t type:8;
55 #endif
56  uint16_t length:16;
57 } rtcp_header;
58 
60 typedef struct sender_info
61 {
62  uint32_t ntp_ts_msw;
63  uint32_t ntp_ts_lsw;
64  uint32_t rtp_ts;
65  uint32_t s_packets;
66  uint32_t s_octets;
67 } sender_info;
68 
70 typedef struct report_block
71 {
72  uint32_t ssrc;
73  uint32_t flcnpl;
74  uint32_t ehsnr;
75  uint32_t jitter;
76  uint32_t lsr;
77  uint32_t delay;
78 } report_block;
79 
81 typedef struct rtcp_sr
82 {
84  uint32_t ssrc;
86  report_block rb[1];
87 } rtcp_sr;
88 
90 typedef struct rtcp_rr
91 {
93  uint32_t ssrc;
94  report_block rb[1];
95 } rtcp_rr;
96 
98 typedef struct rtcp_sdes_chunk
99 {
100  uint32_t ssrc;
102 
103 typedef struct rtcp_sdes_item
104 {
105  uint8_t type;
106  uint8_t len;
107  char content[1];
109 
110 typedef struct rtcp_sdes
111 {
115 } rtcp_sdes;
116 
118 typedef struct rtcp_bye
119 {
121  uint32_t ssrc[1];
122 } rtcp_bye_t;
123 
125 typedef struct rtcp_app
126 {
128  uint32_t ssrc;
129  char name[4];
130 } rtcp_app_t;
131 
133 typedef struct rtcp_nack
134 {
136  uint16_t pid;
138  uint16_t blp;
139 } rtcp_nack;
140 
142 typedef struct janus_nack {
144  uint16_t seq_no;
146  struct janus_nack *next;
147 } janus_nack;
148 
149 
151 typedef struct rtcp_remb
152 {
154  char id[4];
156  uint32_t bitrate;
158  uint32_t ssrc[1];
159 } rtcp_remb;
160 
161 
163 typedef struct rtcp_fir
164 {
166  uint32_t ssrc;
168  uint32_t seqnr;
169 } rtcp_fir;
170 
171 
173 typedef struct rtcp_fb
174 {
178  uint32_t ssrc;
180  uint32_t media;
182  char fci[1];
183 } rtcp_fb;
184 
186 typedef struct extended_report_block
187 {
189  uint8_t blocktype;
191  uint8_t typesp;
193  uint16_t length;
195  char content[1];
196 
198 
200 typedef struct rtcp_xr
201 {
203  uint32_t ssrc;
205 } rtcp_xr;
206 
207 
209 typedef struct rtcp_context
210 {
211  /* Whether we received any RTP packet at all (don't send RR otherwise) */
212  uint8_t rtp_recvd:1;
213 
214  uint16_t last_seq_nr;
215  uint16_t seq_cycle;
216  uint16_t base_seq;
217  /* Payload type */
218  uint16_t pt;
219 
220  /* RFC 3550 A.8 Interarrival Jitter */
221  uint64_t transit;
222  double jitter, jitter_remote;
223  /* Timestamp base (e.g., 48000 for opus audio, or 90000 for video) */
224  uint32_t tb;
225 
226  /* Last SR received */
227  uint32_t lsr;
228  /* Monotonic time of last SR received */
229  int64_t lsr_ts;
230 
231  /* Last RR/SR we sent */
232  int64_t last_sent;
233 
234  /* RFC 3550 A.3 */
235  uint32_t received;
236  uint32_t received_prior;
237  uint32_t expected;
238  uint32_t expected_prior;
239  uint32_t lost, lost_remote;
240 } rtcp_context;
249 uint32_t janus_rtcp_context_get_lost_all(rtcp_context *ctx, gboolean remote);
254 uint32_t janus_rtcp_context_get_jitter(rtcp_context *ctx, gboolean remote);
255 
256 
261 guint32 janus_rtcp_get_sender_ssrc(char *packet, int len);
266 guint32 janus_rtcp_get_receiver_ssrc(char *packet, int len);
267 
273 int janus_rtcp_parse(rtcp_context *ctx, char *packet, int len);
274 
284 int janus_rtcp_fix_ssrc(rtcp_context *ctx, char *packet, int len, int fixssrc, uint32_t newssrcl, uint32_t newssrcr);
285 
291 char *janus_rtcp_filter(char *packet, int len, int *newlen);
292 
298 int janus_rtcp_process_incoming_rtp(rtcp_context *ctx, char *packet, int len);
299 
305 
310 gboolean janus_rtcp_has_bye(char *packet, int len);
311 
316 gboolean janus_rtcp_has_fir(char *packet, int len);
317 
322 gboolean janus_rtcp_has_pli(char *packet, int len);
323 
328 GSList *janus_rtcp_get_nacks(char *packet, int len);
329 
338 int janus_rtcp_remove_nacks(char *packet, int len);
339 
344 uint32_t janus_rtcp_get_remb(char *packet, int len);
345 
351 int janus_rtcp_cap_remb(char *packet, int len, uint32_t bitrate);
352 
359 int janus_rtcp_sdes(char *packet, int len, const char *cname, int cnamelen);
360 
366 int janus_rtcp_remb(char *packet, int len, uint32_t bitrate);
367 
373 int janus_rtcp_fir(char *packet, int len, int *seqnr);
374 
381 int janus_rtcp_fir_legacy(char *packet, int len, int *seqnr);
382 
387 int janus_rtcp_pli(char *packet, int len);
388 
394 int janus_rtcp_nacks(char *packet, int len, GSList *nacks);
395 
396 #endif
RTCP Report Block (http://tools.ietf.org/html/rfc3550#section-6.4.1)
Definition: rtcp.h:70
uint8_t blocktype
Block type (BT)
Definition: rtcp.h:189
uint16_t padding
Definition: rtcp.h:47
uint32_t seqnr
Sequence number (only the first 8 bits are used, the other 24 are reserved)
Definition: rtcp.h:168
uint32_t tb
Definition: rtcp.h:224
Definition: rtcp.h:110
uint32_t ehsnr
Definition: rtcp.h:74
rtcp_header header
Definition: rtcp.h:83
uint8_t len
Definition: rtcp.h:106
RTCP SDES (http://tools.ietf.org/html/rfc3550#section-6.5)
Definition: rtcp.h:98
RTCP BYE (http://tools.ietf.org/html/rfc3550#section-6.6)
Definition: rtcp.h:118
uint32_t ssrc
Definition: rtcp.h:93
rtcp_sdes_chunk chunk
Definition: rtcp.h:113
uint32_t janus_rtcp_context_get_lost_all(rtcp_context *ctx, gboolean remote)
Method to retrieve the total number of lost packets from an existing RTCP context.
Definition: rtcp.c:493
struct sender_info sender_info
RTCP Sender Information (http://tools.ietf.org/html/rfc3550#section-6.4.1)
uint16_t last_seq_nr
Definition: rtcp.h:214
RTCP Extended Report Block (https://tools.ietf.org/html/rfc3611#section-3)
Definition: rtcp.h:186
RTCP-FB (http://tools.ietf.org/html/rfc4585)
Definition: rtcp.h:173
uint32_t lost_remote
Definition: rtcp.h:239
uint16_t pid
Packet ID.
Definition: rtcp.h:136
rtcp_header header
Definition: rtcp.h:112
struct rtcp_fir rtcp_fir
RTCP FIR (http://tools.ietf.org/search/rfc5104#section-4.3.1.1)
guint32 janus_rtcp_get_receiver_ssrc(char *packet, int len)
Method to quickly retrieve the received SSRC (needed for demuxing RTCP in BUNDLE) ...
Definition: rtcp.c:80
uint32_t rtp_ts
Definition: rtcp.h:64
uint16_t blp
bitmask of following lost packets
Definition: rtcp.h:138
int64_t lsr_ts
Definition: rtcp.h:229
uint32_t janus_rtcp_get_remb(char *packet, int len)
Inspect an existing RTCP REMB message to retrieve the reported bitrate.
Definition: rtcp.c:741
int janus_rtcp_remb(char *packet, int len, uint32_t bitrate)
Method to generate a new RTCP REMB message to cap the reported bitrate.
Definition: rtcp.c:875
uint32_t ssrc
Sender SSRC.
Definition: rtcp.h:178
RTCP Header (http://tools.ietf.org/html/rfc3550#section-6.1)
Definition: rtcp.h:43
uint64_t transit
Definition: rtcp.h:221
uint16_t seq_cycle
Definition: rtcp.h:215
struct rtcp_sdes_chunk rtcp_sdes_chunk
RTCP SDES (http://tools.ietf.org/html/rfc3550#section-6.5)
struct report_block report_block
RTCP Report Block (http://tools.ietf.org/html/rfc3550#section-6.4.1)
struct rtcp_sdes rtcp_sdes
gboolean janus_rtcp_has_pli(char *packet, int len)
Method to check whether an RTCP message contains a PLI request.
Definition: rtcp.c:610
uint32_t bitrate
Num SSRC, Br Exp, Br Mantissa (bit mask)
Definition: rtcp.h:156
int janus_rtcp_fix_ssrc(rtcp_context *ctx, char *packet, int len, int fixssrc, uint32_t newssrcl, uint32_t newssrcr)
Method to fix an RTCP message (http://tools.ietf.org/html/draft-ietf-straw-b2bua-rtcp-00) ...
Definition: rtcp.c:150
struct rtcp_nack rtcp_nack
RTCP NACK (http://tools.ietf.org/html/rfc4585#section-6.2.1)
rtcp_sdes_item item
Definition: rtcp.h:114
gboolean janus_rtcp_has_fir(char *packet, int len)
Method to check whether an RTCP message contains a FIR request.
Definition: rtcp.c:582
uint32_t lsr
Definition: rtcp.h:76
uint8_t type
Definition: rtcp.h:105
int janus_rtcp_process_incoming_rtp(rtcp_context *ctx, char *packet, int len)
Method to quickly process the header of an incoming RTP packet to update the associated RTCP context...
Definition: rtcp.c:444
RTCP APP (http://tools.ietf.org/html/rfc3550#section-6.7)
Definition: rtcp.h:125
rtcp_header header
Common header.
Definition: rtcp.h:176
rtcp_header header
Definition: rtcp.h:120
uint16_t seq_no
Sequence number to send again.
Definition: rtcp.h:144
Definition: rtcp.h:36
uint16_t length
Block length.
Definition: rtcp.h:193
uint32_t janus_rtcp_context_get_jitter(rtcp_context *ctx, gboolean remote)
Method to retrieve the jitter from an existing RTCP context.
Definition: rtcp.c:525
struct rtcp_app rtcp_app_t
RTCP APP (http://tools.ietf.org/html/rfc3550#section-6.7)
int janus_rtcp_parse(rtcp_context *ctx, char *packet, int len)
Method to parse/validate an RTCP message.
Definition: rtcp.c:24
Definition: rtcp.h:31
RTCP Receiver Report (http://tools.ietf.org/html/rfc3550#section-6.4.2)
Definition: rtcp.h:90
uint32_t ssrc
Definition: rtcp.h:100
int janus_rtcp_nacks(char *packet, int len, GSList *nacks)
Method to generate a new RTCP NACK message to report lost packets.
Definition: rtcp.c:976
struct rtcp_fb rtcp_fb
RTCP-FB (http://tools.ietf.org/html/rfc4585)
RTCP NACK (http://tools.ietf.org/html/rfc4585#section-6.2.1)
Definition: rtcp.h:133
uint32_t received
Definition: rtcp.h:235
Definition: rtcp.h:33
uint16_t pt
Definition: rtcp.h:218
uint32_t media
Media source.
Definition: rtcp.h:180
Definition: rtcp.h:32
uint8_t typesp
Type-specific.
Definition: rtcp.h:191
char * janus_rtcp_filter(char *packet, int len, int *newlen)
Method to filter an outgoing RTCP message (http://tools.ietf.org/html/draft-ietf-straw-b2bua-rtcp-00)...
Definition: rtcp.c:382
struct rtcp_bye rtcp_bye_t
RTCP BYE (http://tools.ietf.org/html/rfc3550#section-6.6)
RTCP Extended Report (https://tools.ietf.org/html/rfc3611#section-2)
Definition: rtcp.h:200
int janus_rtcp_cap_remb(char *packet, int len, uint32_t bitrate)
Method to modify an existing RTCP REMB message to cap the reported bitrate.
Definition: rtcp.c:783
uint16_t length
Definition: rtcp.h:56
struct rtcp_remb rtcp_remb
RTCP REMB (http://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03)
uint32_t ssrc
Definition: rtcp.h:128
struct rtcp_header rtcp_header
RTCP Header (http://tools.ietf.org/html/rfc3550#section-6.1)
Janus representation (linked list) of sequence numbers to send again.
Definition: rtcp.h:142
uint16_t version
Definition: rtcp.h:46
rtcp_type
RTCP Packet Types (http://www.networksorcery.com/enp/protocol/rtcp.htm)
Definition: rtcp.h:29
int janus_rtcp_fir_legacy(char *packet, int len, int *seqnr)
Method to generate a new legacy RTCP FIR (RFC2032) message to request a key frame.
Definition: rtcp.c:939
int janus_rtcp_pli(char *packet, int len)
Method to generate a new RTCP PLI message to request a key frame.
Definition: rtcp.c:962
uint32_t s_octets
Definition: rtcp.h:66
uint16_t base_seq
Definition: rtcp.h:216
uint32_t expected
Definition: rtcp.h:237
sender_info si
Definition: rtcp.h:85
RTCP REMB (http://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03)
Definition: rtcp.h:151
uint32_t s_packets
Definition: rtcp.h:65
struct rtcp_sdes_item rtcp_sdes_item
int janus_rtcp_fir(char *packet, int len, int *seqnr)
Method to generate a new RTCP FIR message to request a key frame.
Definition: rtcp.c:917
GSList * janus_rtcp_get_nacks(char *packet, int len)
Method to parse an RTCP NACK message.
Definition: rtcp.c:641
uint32_t jitter
Definition: rtcp.h:75
Definition: rtcp.h:38
uint32_t ntp_ts_msw
Definition: rtcp.h:62
Definition: rtcp.h:37
struct extended_report_block extended_report_block
RTCP Extended Report Block (https://tools.ietf.org/html/rfc3611#section-3)
uint32_t ssrc
SSRC of the media sender that needs to send a key frame.
Definition: rtcp.h:166
uint32_t ntp_ts_lsw
Definition: rtcp.h:63
Internal RTCP state context (for RR/SR)
Definition: rtcp.h:209
rtcp_header header
Definition: rtcp.h:92
gboolean janus_rtcp_has_bye(char *packet, int len)
Method to check whether an RTCP message contains a BYE message.
Definition: rtcp.c:554
uint16_t type
Definition: rtcp.h:49
Definition: rtcp.h:34
struct janus_nack * next
Next element in the linked list.
Definition: rtcp.h:146
uint32_t ssrc
Definition: rtcp.h:84
uint32_t ssrc
Definition: rtcp.h:203
uint32_t delay
Definition: rtcp.h:77
struct rtcp_xr rtcp_xr
RTCP Extended Report (https://tools.ietf.org/html/rfc3611#section-2)
struct rtcp_sr rtcp_sr
RTCP Sender Report (http://tools.ietf.org/html/rfc3550#section-6.4.1)
struct janus_nack janus_nack
Janus representation (linked list) of sequence numbers to send again.
int janus_rtcp_remove_nacks(char *packet, int len)
Method to remove an RTCP NACK message.
Definition: rtcp.c:692
uint8_t rtp_recvd
Definition: rtcp.h:212
int janus_rtcp_report_block(rtcp_context *ctx, report_block *rb)
Method to fill in a Report Block in a Receiver Report.
Definition: rtcp.c:531
int64_t last_sent
Definition: rtcp.h:232
double jitter_remote
Definition: rtcp.h:222
uint16_t rc
Definition: rtcp.h:48
rtcp_header header
Definition: rtcp.h:202
guint32 janus_rtcp_get_sender_ssrc(char *packet, int len)
Method to quickly retrieve the sender SSRC (needed for demuxing RTCP in BUNDLE)
Definition: rtcp.c:28
uint32_t flcnpl
Definition: rtcp.h:73
struct rtcp_context rtcp_context
Internal RTCP state context (for RR/SR)
Definition: rtcp.h:30
RTCP Sender Report (http://tools.ietf.org/html/rfc3550#section-6.4.1)
Definition: rtcp.h:81
Definition: rtcp.h:35
uint32_t expected_prior
Definition: rtcp.h:238
struct rtcp_rr rtcp_rr
RTCP Receiver Report (http://tools.ietf.org/html/rfc3550#section-6.4.2)
uint32_t ssrc
Definition: rtcp.h:72
uint32_t janus_rtcp_context_get_lsr(rtcp_context *ctx)
Method to retrieve the LSR from an existing RTCP context.
Definition: rtcp.c:489
Definition: rtcp.h:103
uint32_t received_prior
Definition: rtcp.h:236
rtcp_header header
Definition: rtcp.h:127
uint32_t lsr
Definition: rtcp.h:227
int janus_rtcp_sdes(char *packet, int len, const char *cname, int cnamelen)
Method to generate a new RTCP SDES message.
Definition: rtcp.c:848
RTCP FIR (http://tools.ietf.org/search/rfc5104#section-4.3.1.1)
Definition: rtcp.h:163
RTCP Sender Information (http://tools.ietf.org/html/rfc3550#section-6.4.1)
Definition: rtcp.h:60