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;
41 
42 
44 typedef struct rtcp_header
45 {
46 #if __BYTE_ORDER == __BIG_ENDIAN
47  uint16_t version:2;
48  uint16_t padding:1;
49  uint16_t rc:5;
50  uint16_t type:8;
51 #elif __BYTE_ORDER == __LITTLE_ENDIAN
52  uint16_t rc:5;
53  uint16_t padding:1;
54  uint16_t version:2;
55  uint16_t type:8;
56 #endif
57  uint16_t length:16;
58 } rtcp_header;
60 
62 typedef struct sender_info
63 {
64  uint32_t ntp_ts_msw;
65  uint32_t ntp_ts_lsw;
66  uint32_t rtp_ts;
67  uint32_t s_packets;
68  uint32_t s_octets;
69 } sender_info;
71 
73 typedef struct report_block
74 {
75  uint32_t ssrc;
76  uint32_t flcnpl;
77  uint32_t ehsnr;
78  uint32_t jitter;
79  uint32_t lsr;
80  uint32_t delay;
81 } report_block;
83 
85 typedef struct rtcp_sr
86 {
88  uint32_t ssrc;
90  report_block rb[1];
91 } rtcp_sr;
93 
95 typedef struct rtcp_rr
96 {
98  uint32_t ssrc;
99  report_block rb[1];
100 } rtcp_rr;
102 
104 typedef struct rtcp_sdes_chunk
105 {
106  uint32_t ssrc;
109 
110 typedef struct rtcp_sdes_item
111 {
112  uint8_t type;
113  uint8_t len;
114  char content[1];
117 
118 typedef struct rtcp_sdes
119 {
123 } rtcp_sdes;
125 
127 typedef struct rtcp_bye
128 {
130  uint32_t ssrc[1];
131 } rtcp_bye;
133 
135 typedef struct rtcp_app
136 {
138  uint32_t ssrc;
139  char name[4];
140 } rtcp_app;
142 
144 typedef struct rtcp_nack
145 {
147  uint16_t pid;
149  uint16_t blp;
150 } rtcp_nack;
152 
154 typedef struct janus_nack {
156  uint16_t seq_no;
158  struct janus_nack *next;
159 } janus_nack;
160 
161 
163 typedef struct rtcp_remb
164 {
166  char id[4];
168  uint32_t bitrate;
170  uint32_t ssrc[3];
171 } rtcp_remb;
173 
174 
176 typedef struct rtcp_fir
177 {
179  uint32_t ssrc;
181  uint32_t seqnr;
182 } rtcp_fir;
184 
185 
187 typedef struct rtcp_fb
188 {
192  uint32_t ssrc;
194  uint32_t media;
196  char fci[1];
197 } rtcp_fb;
199 
201 typedef struct extended_report_block
202 {
204  uint8_t blocktype;
206  uint8_t typesp;
208  uint16_t length;
210  char content[1];
211 
214 
216 typedef struct rtcp_xr
217 {
219  uint32_t ssrc;
221 } rtcp_xr;
223 
224 
226 typedef struct rtcp_context
227 {
228  /* Whether we received any RTP packet at all (don't send RR otherwise) */
229  uint8_t rtp_recvd:1;
230 
231  uint16_t max_seq_nr;
232  uint16_t seq_cycle;
233  uint16_t base_seq;
234  /* Payload type */
235  uint16_t pt;
236 
237  /* RFC 3550 A.8 Interarrival Jitter */
238  uint64_t transit;
239  double jitter, jitter_remote;
240  /* Timestamp base (e.g., 48000 for opus audio, or 90000 for video) */
241  uint32_t tb;
242 
243  /* Last SR received */
244  uint32_t lsr;
245  /* Monotonic time of last SR received */
246  int64_t lsr_ts;
247 
248  /* Last RR/SR we sent */
249  int64_t last_sent;
250 
251  /* Estimated round-trip time */
252  uint32_t rtt;
253 
254  /* RFC 3550 A.3 */
255  uint32_t received;
256  uint32_t received_prior;
257  uint32_t expected;
258  uint32_t expected_prior;
259  uint32_t lost, lost_remote;
260 
261  uint32_t retransmitted;
263 
264  /* Inbound RR process */
265  int64_t rr_last_ts;
266  uint32_t rr_last_ehsnr;
267  uint32_t rr_last_lost;
271 
272  /* Outbound RR process */
273  int64_t out_rr_last_ts;
274 
275  /* Link quality estimations */
280 } rtcp_context;
282 
285 {
289  guint64 timestamp;
292 
301 uint32_t janus_rtcp_context_get_lost_all(janus_rtcp_context *ctx, gboolean remote);
306 uint32_t janus_rtcp_context_get_jitter(janus_rtcp_context *ctx, gboolean remote);
327 guint32 janus_rtcp_get_sender_ssrc(char *packet, int len);
332 guint32 janus_rtcp_get_receiver_ssrc(char *packet, int len);
333 
339 int janus_rtcp_parse(janus_rtcp_context *ctx, char *packet, int len);
340 
350 int janus_rtcp_fix_ssrc(janus_rtcp_context *ctx, char *packet, int len, int fixssrc, uint32_t newssrcl, uint32_t newssrcr);
351 
357 char *janus_rtcp_filter(char *packet, int len, int *newlen);
358 
364 int janus_rtcp_process_incoming_rtp(janus_rtcp_context *ctx, char *packet, int len);
365 
371 
380 gboolean janus_rtcp_parse_lost_info(char *packet, int len, uint32_t *lost, int *fraction);
381 
386 gboolean janus_rtcp_has_bye(char *packet, int len);
387 
392 gboolean janus_rtcp_has_fir(char *packet, int len);
393 
398 gboolean janus_rtcp_has_pli(char *packet, int len);
399 
404 GSList *janus_rtcp_get_nacks(char *packet, int len);
405 
414 int janus_rtcp_remove_nacks(char *packet, int len);
415 
420 uint32_t janus_rtcp_get_remb(char *packet, int len);
421 
427 int janus_rtcp_cap_remb(char *packet, int len, uint32_t bitrate);
428 
435 int janus_rtcp_sdes_cname(char *packet, int len, const char *cname, int cnamelen);
436 
442 int janus_rtcp_remb(char *packet, int len, uint32_t bitrate);
443 
450 int janus_rtcp_remb_ssrcs(char *packet, int len, uint32_t bitrate, uint8_t numssrc);
451 
457 int janus_rtcp_fir(char *packet, int len, int *seqnr);
458 
465 int janus_rtcp_fir_legacy(char *packet, int len, int *seqnr);
466 
471 int janus_rtcp_pli(char *packet, int len);
472 
478 int janus_rtcp_nacks(char *packet, int len, GSList *nacks);
479 
488 int janus_rtcp_transport_wide_cc_feedback(char *packet, size_t len, guint32 ssrc, guint32 media, guint8 feedback_packet_count, GQueue *transport_wide_cc_stats);
489 
490 #endif
int janus_rtcp_sdes_cname(char *packet, int len, const char *cname, int cnamelen)
Method to generate a new RTCP SDES message.
Definition: rtcp.c:984
RTCP Report Block (http://tools.ietf.org/html/rfc3550#section-6.4.1)
Definition: rtcp.h:73
uint8_t blocktype
Block type (BT)
Definition: rtcp.h:204
uint16_t padding
Definition: rtcp.h:48
uint32_t seqnr
Sequence number (only the first 8 bits are used, the other 24 are reserved)
Definition: rtcp.h:181
uint32_t tb
Definition: rtcp.h:241
struct rtcp_bye rtcp_bye
RTCP BYE (http://tools.ietf.org/html/rfc3550#section-6.6)
Definition: rtcp.h:118
uint32_t ehsnr
Definition: rtcp.h:77
rtcp_header header
Definition: rtcp.h:87
rtcp_fb janus_rtcp_fb
Definition: rtcp.h:198
uint8_t len
Definition: rtcp.h:113
RTCP SDES (http://tools.ietf.org/html/rfc3550#section-6.5)
Definition: rtcp.h:104
RTCP BYE (http://tools.ietf.org/html/rfc3550#section-6.6)
Definition: rtcp.h:127
uint32_t ssrc
Definition: rtcp.h:98
rtcp_sdes_chunk chunk
Definition: rtcp.h:121
rtcp_fir janus_rtcp_fb_fir
Definition: rtcp.h:183
struct sender_info sender_info
RTCP Sender Information (http://tools.ietf.org/html/rfc3550#section-6.4.1)
RTCP Extended Report Block (https://tools.ietf.org/html/rfc3611#section-3)
Definition: rtcp.h:201
RTCP-FB (http://tools.ietf.org/html/rfc4585)
Definition: rtcp.h:187
uint32_t lost_remote
Definition: rtcp.h:259
uint32_t retransmitted_prior
Definition: rtcp.h:262
uint16_t pid
Packet ID.
Definition: rtcp.h:147
rtcp_transport_wide_cc_stats janus_rtcp_transport_wide_cc_stats
Definition: rtcp.h:291
rtcp_sdes janus_rtcp_sdes
Definition: rtcp.h:124
rtcp_header header
Definition: rtcp.h:120
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:81
int64_t rr_last_ts
Definition: rtcp.h:265
uint32_t rtp_ts
Definition: rtcp.h:66
uint16_t blp
bitmask of following lost packets
Definition: rtcp.h:149
uint32_t rr_last_ehsnr
Definition: rtcp.h:266
int64_t lsr_ts
Definition: rtcp.h:246
uint32_t janus_rtcp_context_get_rtt(janus_rtcp_context *ctx)
Method to retrieve the estimated round-trip time from an existing RTCP context.
Definition: rtcp.c:550
uint32_t janus_rtcp_get_remb(char *packet, int len)
Inspect an existing RTCP REMB message to retrieve the reported bitrate.
Definition: rtcp.c:877
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:1011
uint32_t ssrc
Sender SSRC.
Definition: rtcp.h:192
RTCP Header (http://tools.ietf.org/html/rfc3550#section-6.1)
Definition: rtcp.h:44
uint64_t transit
Definition: rtcp.h:238
uint16_t seq_cycle
Definition: rtcp.h:232
extended_report_block janus_extended_report_block
Definition: rtcp.h:213
rtcp_rr janus_rtcp_rr
Definition: rtcp.h:101
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:746
rtcp_sr janus_rtcp_sr
Definition: rtcp.h:92
int janus_rtcp_report_block(janus_rtcp_context *ctx, janus_report_block *rb)
Method to fill in a Report Block in a Receiver Report.
Definition: rtcp.c:634
uint32_t bitrate
Num SSRC, Br Exp, Br Mantissa (bit mask)
Definition: rtcp.h:168
guint32 transport_seq_num
Transwport wide sequence number.
Definition: rtcp.h:287
struct rtcp_nack rtcp_nack
RTCP NACK (http://tools.ietf.org/html/rfc4585#section-6.2.1)
rtcp_sdes_item item
Definition: rtcp.h:122
gboolean janus_rtcp_has_fir(char *packet, int len)
Method to check whether an RTCP message contains a FIR request.
Definition: rtcp.c:720
uint32_t lsr
Definition: rtcp.h:79
uint8_t type
Definition: rtcp.h:112
int64_t out_rr_last_ts
Definition: rtcp.h:273
rtcp_app janus_rtcp_app
Definition: rtcp.h:141
uint32_t retransmitted
Definition: rtcp.h:261
double out_link_quality
Definition: rtcp.h:278
RTCP APP (http://tools.ietf.org/html/rfc3550#section-6.7)
Definition: rtcp.h:135
rtcp_header header
Common header.
Definition: rtcp.h:190
rtcp_header header
Definition: rtcp.h:129
uint16_t seq_no
Sequence number to send again.
Definition: rtcp.h:156
Definition: rtcp.h:36
rtcp_type janus_rtcp_type
Definition: rtcp.h:40
uint16_t length
Block length.
Definition: rtcp.h:208
Definition: rtcp.h:31
double in_media_link_quality
Definition: rtcp.h:277
RTCP Receiver Report (http://tools.ietf.org/html/rfc3550#section-6.4.2)
Definition: rtcp.h:95
uint32_t ssrc
Definition: rtcp.h:106
guint64 timestamp
Reception time.
Definition: rtcp.h:289
struct rtcp_transport_wide_cc_stats rtcp_transport_wide_cc_stats
Stores transport wide packet reception statistics.
rtcp_context janus_rtcp_context
Definition: rtcp.h:281
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:1120
struct rtcp_fb rtcp_fb
RTCP-FB (http://tools.ietf.org/html/rfc4585)
uint32_t janus_rtcp_context_get_lost_all(janus_rtcp_context *ctx, gboolean remote)
Method to retrieve the total number of lost packets from an existing RTCP context.
Definition: rtcp.c:570
RTCP NACK (http://tools.ietf.org/html/rfc4585#section-6.2.1)
Definition: rtcp.h:144
uint32_t received
Definition: rtcp.h:255
Definition: rtcp.h:33
uint16_t pt
Definition: rtcp.h:235
uint32_t media
Media source.
Definition: rtcp.h:194
uint32_t janus_rtcp_context_get_in_link_quality(janus_rtcp_context *ctx)
Method to retrieve inbound link quality from an existing RTCP context.
Definition: rtcp.c:554
Definition: rtcp.h:32
uint8_t typesp
Type-specific.
Definition: rtcp.h:206
struct rtcp_app rtcp_app
RTCP APP (http://tools.ietf.org/html/rfc3550#section-6.7)
double out_media_link_quality
Definition: rtcp.h:279
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:443
RTCP Extended Report (https://tools.ietf.org/html/rfc3611#section-2)
Definition: rtcp.h:216
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:919
uint16_t length
Definition: rtcp.h:57
struct rtcp_remb rtcp_remb
RTCP REMB (http://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03)
uint32_t ssrc
Definition: rtcp.h:138
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:154
int janus_rtcp_fix_ssrc(janus_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:213
uint16_t version
Definition: rtcp.h:47
rtcp_type
RTCP Packet Types (http://www.networksorcery.com/enp/protocol/rtcp.htm)
Definition: rtcp.h:29
rtcp_bye janus_rtcp_bye
Definition: rtcp.h:132
uint16_t max_seq_nr
Definition: rtcp.h:231
uint32_t janus_rtcp_context_get_in_media_link_quality(janus_rtcp_context *ctx)
Method to retrieve inbound media link quality from an existing RTCP context.
Definition: rtcp.c:558
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:1083
int janus_rtcp_pli(char *packet, int len)
Method to generate a new RTCP PLI message to request a key frame.
Definition: rtcp.c:1106
rtcp_sdes_chunk janus_rtcp_sdes_chunk
Definition: rtcp.h:108
int janus_rtcp_process_incoming_rtp(janus_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:505
uint32_t s_octets
Definition: rtcp.h:68
uint16_t base_seq
Definition: rtcp.h:233
uint32_t expected
Definition: rtcp.h:257
gint nack_count
Definition: rtcp.h:270
sender_info si
Definition: rtcp.h:89
RTCP REMB (http://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03)
Definition: rtcp.h:163
uint32_t janus_rtcp_context_get_out_link_quality(janus_rtcp_context *ctx)
Method to retrieve outbound link quality from an existing RTCP context.
Definition: rtcp.c:562
uint32_t s_packets
Definition: rtcp.h:67
struct rtcp_sdes_item rtcp_sdes_item
rtcp_remb janus_rtcp_fb_remb
Definition: rtcp.h:172
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:1061
GSList * janus_rtcp_get_nacks(char *packet, int len)
Method to parse an RTCP NACK message.
Definition: rtcp.c:776
uint32_t jitter
Definition: rtcp.h:78
Definition: rtcp.h:38
uint32_t ntp_ts_msw
Definition: rtcp.h:64
uint32_t rr_last_nack_count
Definition: rtcp.h:268
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:179
uint32_t janus_rtcp_context_get_jitter(janus_rtcp_context *ctx, gboolean remote)
Method to retrieve the jitter from an existing RTCP context.
Definition: rtcp.c:602
uint32_t ntp_ts_lsw
Definition: rtcp.h:65
Stores transport wide packet reception statistics.
Definition: rtcp.h:284
Internal RTCP state context (for RR/SR)
Definition: rtcp.h:226
rtcp_header header
Definition: rtcp.h:97
gboolean janus_rtcp_has_bye(char *packet, int len)
Method to check whether an RTCP message contains a BYE message.
Definition: rtcp.c:694
uint16_t type
Definition: rtcp.h:50
uint32_t rtt
Definition: rtcp.h:252
Definition: rtcp.h:34
int janus_rtcp_parse(janus_rtcp_context *ctx, char *packet, int len)
Method to parse/validate an RTCP message.
Definition: rtcp.c:25
struct janus_nack * next
Next element in the linked list.
Definition: rtcp.h:158
uint32_t ssrc
Definition: rtcp.h:88
uint32_t ssrc
Definition: rtcp.h:219
uint32_t delay
Definition: rtcp.h:80
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)
int janus_rtcp_remb_ssrcs(char *packet, int len, uint32_t bitrate, uint8_t numssrc)
Method to generate a new RTCP REMB message to cap the reported bitrate, but for more SSRCs...
Definition: rtcp.c:1016
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:828
sender_info janus_sender_info
Definition: rtcp.h:70
rtcp_xr janus_rtcp_xr
Definition: rtcp.h:222
int64_t last_sent
Definition: rtcp.h:249
gint sent_packets_since_last_rr
Definition: rtcp.h:269
double jitter_remote
Definition: rtcp.h:239
report_block janus_report_block
Definition: rtcp.h:82
rtcp_nack janus_rtcp_nack
Definition: rtcp.h:151
uint16_t rc
Definition: rtcp.h:49
gboolean janus_rtcp_parse_lost_info(char *packet, int len, uint32_t *lost, int *fraction)
Method to quickly fetch the lost packets info from an RR packet, if present.
Definition: rtcp.c:659
rtcp_header header
Definition: rtcp.h:218
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:29
uint32_t flcnpl
Definition: rtcp.h:76
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:85
Definition: rtcp.h:35
uint32_t expected_prior
Definition: rtcp.h:258
struct rtcp_rr rtcp_rr
RTCP Receiver Report (http://tools.ietf.org/html/rfc3550#section-6.4.2)
uint32_t ssrc
Definition: rtcp.h:75
uint32_t janus_rtcp_context_get_out_media_link_quality(janus_rtcp_context *ctx)
Method to retrieve outbound media link quality from an existing RTCP context.
Definition: rtcp.c:566
rtcp_sdes_item janus_rtcp_sdes_item
Definition: rtcp.h:116
double in_link_quality
Definition: rtcp.h:276
Definition: rtcp.h:110
uint32_t rr_last_lost
Definition: rtcp.h:267
rtcp_header janus_rtcp_header
Definition: rtcp.h:59
uint32_t received_prior
Definition: rtcp.h:256
rtcp_header header
Definition: rtcp.h:137
uint32_t lsr
Definition: rtcp.h:244
int janus_rtcp_transport_wide_cc_feedback(char *packet, size_t len, guint32 ssrc, guint32 media, guint8 feedback_packet_count, GQueue *transport_wide_cc_stats)
Method to generate a new RTCP transport wide message to report reception stats.
Definition: rtcp.c:1171
RTCP FIR (http://tools.ietf.org/search/rfc5104#section-4.3.1.1)
Definition: rtcp.h:176
RTCP Sender Information (http://tools.ietf.org/html/rfc3550#section-6.4.1)
Definition: rtcp.h:62