Statistics
| Branch: | Revision:

janus-gateway / rtcp.h @ 5e9e29e0

History | View | Annotate | Download (7.21 KB)

1
/*! \file    rtcp.h
2
 * \author   Lorenzo Miniero <lorenzo@meetecho.com>
3
 * \copyright GNU Affero General Public License v3
4
 * \brief    RTCP processing (headers)
5
 * \details  Implementation of the RTCP messages. RTCP messages coming
6
 * through the gateway are parsed and, if needed (according to
7
 * http://tools.ietf.org/html/draft-ietf-straw-b2bua-rtcp-00),
8
 * fixed before they are sent to the peers (e.g., to fix SSRCs that may
9
 * have been changed by the gateway). Methods to generate FIR messages
10
 * and generate/cap REMB messages are provided as well.
11
 * 
12
 * \ingroup protocols
13
 * \ref protocols
14
 */
15
 
16
#ifndef _JANUS_RTCP_H
17
#define _JANUS_RTCP_H
18

    
19
#include <arpa/inet.h>
20
#include <endian.h>
21
#include <inttypes.h>
22
#include <string.h>
23

    
24
/*! \brief RTCP Packet Types (http://www.networksorcery.com/enp/protocol/rtcp.htm) */
25
typedef enum {
26
    RTCP_FIR = 192,
27
    RTCP_SR = 200,
28
    RTCP_RR = 201,
29
    RTCP_SDES = 202,
30
    RTCP_BYE = 203,
31
    RTCP_APP = 204,
32
    RTCP_RTPFB = 205,
33
    RTCP_PSFB = 206,
34
} rtcp_type;
35
 
36
 
37
/*! \brief RTCP Header (http://tools.ietf.org/html/rfc3550#section-6.1) */
38
typedef struct rtcp_header
39
{
40
#if __BYTE_ORDER == __BIG_ENDIAN
41
        uint16_t version:2;
42
        uint16_t padding:1;
43
        uint16_t rc:5;
44
        uint16_t type:8;
45
#elif __BYTE_ORDER == __LITTLE_ENDIAN
46
        uint16_t rc:5;
47
        uint16_t padding:1;
48
        uint16_t version:2;
49
        uint16_t type:8;
50
#endif
51
        uint16_t length:16;
52
} rtcp_header;
53

    
54
/*! \brief RTCP Sender Information (http://tools.ietf.org/html/rfc3550#section-6.4.1) */
55
typedef struct sender_info
56
{
57
        uint32_t ntp_ts_msw;
58
        uint32_t ntp_ts_lsw;
59
        uint32_t rtp_ts;
60
        uint32_t s_packets;
61
        uint32_t s_octets;
62
} sender_info;
63

    
64
/*! \brief RTCP Report Block (http://tools.ietf.org/html/rfc3550#section-6.4.1) */
65
typedef struct report_block
66
{
67
        uint32_t ssrc;
68
        uint32_t flcnpl;
69
        uint32_t ehsnr;
70
        uint32_t jitter;
71
        uint32_t lsr;
72
        uint32_t delay;
73
} report_block;
74

    
75
/*! \brief RTCP Sender Report (http://tools.ietf.org/html/rfc3550#section-6.4.1) */
76
typedef struct rtcp_sr
77
{
78
        rtcp_header header;
79
        uint32_t ssrc;
80
        sender_info si;
81
        report_block rb[1];
82
} rtcp_sr;
83

    
84
/*! \brief RTCP Receiver Report (http://tools.ietf.org/html/rfc3550#section-6.4.2) */
85
typedef struct rtcp_rr
86
{
87
        rtcp_header header;
88
        uint32_t ssrc;
89
        report_block rb[1];
90
} rtcp_rr;
91

    
92
/*! \brief RTCP SDES (http://tools.ietf.org/html/rfc3550#section-6.5) */
93
typedef struct rtcp_sdes_chunk
94
{
95
        uint32_t csrc;
96
} rtcp_sdes_chunk;
97

    
98
typedef struct rtcp_sdes_item
99
{
100
        uint8_t type;
101
        uint8_t len;
102
        char content[1];
103
} rtcp_sdes_item;
104

    
105
typedef struct rtcp_sdes
106
{
107
        rtcp_header header;
108
        uint32_t ssrc;
109
        rtcp_sdes_chunk chunk;
110
        rtcp_sdes_item item;
111
} rtcp_sdes;
112

    
113
/*! \brief RTCP BYE (http://tools.ietf.org/html/rfc3550#section-6.6) */
114
typedef struct rtcp_bye
115
{
116
        rtcp_header header;
117
        uint32_t ssrc[1];
118
} rtcp_bye_t;
119

    
120
/*! \brief RTCP APP (http://tools.ietf.org/html/rfc3550#section-6.7) */
121
typedef struct rtcp_app
122
{
123
        rtcp_header header;
124
        uint32_t ssrc;
125
        char name[4];
126
} rtcp_app_t;
127

    
128
/*! \brief RTCP NACK (http://tools.ietf.org/html/rfc4585#section-6.2.1) */
129
typedef struct rtcp_nack
130
{
131
        /*! \brief Packet ID */
132
        uint16_t pid;
133
        /*! \brief bitmask of following lost packets */
134
        uint16_t blp;
135
} rtcp_nack;
136

    
137
/*! \brief Janus representation (linked list) of sequence numbers to send again */
138
typedef struct janus_nack {
139
        /*! \brief Sequence number to send again */
140
        uint16_t seq_no;
141
        /*! \brief Next element in the linked list */
142
        struct janus_nack *next;
143
} janus_nack;
144

    
145

    
146
/*! \brief RTCP REMB (http://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03) */
147
typedef struct rtcp_remb
148
{
149
        /*! \brief Unique identifier ('R' 'E' 'M' 'B') */
150
        char id[4];
151
        /*! \brief Num SSRC, Br Exp, Br Mantissa (bit mask) */
152
        uint32_t bitrate;
153
        /*! \brief SSRC feedback */
154
        uint32_t ssrc[1];
155
} rtcp_remb;
156

    
157

    
158
/*! \brief RTCP FIR (http://tools.ietf.org/search/rfc5104#section-4.3.1.1) */
159
typedef struct rtcp_fir
160
{
161
        /*! \brief SSRC of the media sender that needs to send a key frame */
162
        uint32_t ssrc;
163
        /*! \brief Sequence number (only the first 8 bits are used, the other 24 are reserved) */
164
        uint32_t seqnr;
165
} rtcp_fir;
166

    
167

    
168
/*! \brief RTCP-FB (http://tools.ietf.org/html/rfc4585) */
169
typedef struct rtcp_fb
170
{
171
        /*! \brief Common header */
172
        rtcp_header header;
173
        /*! \brief Sender SSRC */
174
        uint32_t ssrc;
175
        /*! \brief Media source */
176
        uint32_t media;
177
        /*! \brief Feedback Control Information */
178
        char fci[1];
179
} rtcp_fb;
180

    
181

    
182
/*! \brief Method to parse/validate an RTCP message
183
 * @param[in] packet The message data
184
 * @param[in] len The message data length in bytes
185
 * @returns 0 in case of success, -1 on errors */
186
int janus_rtcp_parse(char *packet, int len);
187

    
188
/*! \brief Method to fix an RTCP message (http://tools.ietf.org/html/draft-ietf-straw-b2bua-rtcp-00)
189
 * @param[in] packet The message data
190
 * @param[in] len The message data length in bytes
191
 * @param[in] fixssrc Whether the method needs to fix the message or just parse it
192
 * @param[in] newssrcl The SSRC of the sender to put in the message
193
 * @param[in] newssrcr The SSRC of the receiver to put in the message
194
 * @returns 0 in case of success, -1 on errors */
195
int janus_rtcp_fix_ssrc(char *packet, int len, int fixssrc, uint32_t newssrcl, uint32_t newssrcr);
196

    
197
/*! \brief Method to parse an RTCP NACK message
198
 * @param[in] packet The message data
199
 * @param[in] len The message data length in bytes
200
 * @returns A list of janus_nack elements containing the sequence numbers to send again */
201
GSList *janus_rtcp_get_nacks(char *packet, int len);
202

    
203
/*! \brief Method to modify an existing RTCP REMB message to cap the reported bitrate
204
 * @param[in] packet The message data
205
 * @param[in] len The message data length in bytes
206
 * @param[in] bitrate The new bitrate to report (e.g., 128000)
207
 * @returns 0 in case of success, -1 on errors */
208
int janus_rtcp_cap_remb(char *packet, int len, uint64_t bitrate);
209

    
210
/*! \brief Method to generate a new RTCP REMB message to cap the reported bitrate
211
 * @param[in] packet The buffer data (MUST be at least 24 chars)
212
 * @param[in] len The message data length in bytes (MUST be 24)
213
 * @param[in] bitrate The bitrate to report (e.g., 128000)
214
 * @returns 0 in case of success, -1 on errors */
215
int janus_rtcp_remb(char *packet, int len, uint64_t bitrate);
216

    
217
/*! \brief Method to generate a new RTCP FIR message to request a key frame
218
 * @param[in] packet The buffer data (MUST be at least 20 chars)
219
 * @param[in] len The message data length in bytes (MUST be 20)
220
 * @param[in,out] seqnr The current FIR sequence number (will be incremented by the method)
221
 * @returns 0 in case of success, -1 on errors */
222
int janus_rtcp_fir(char *packet, int len, int *seqnr);
223

    
224
/*! \brief Method to generate a new legacy RTCP FIR (RFC2032) message to request a key frame
225
 * \note This is actually identical to janus_rtcp_fir(), with the difference that we set 192 as packet type
226
 * @param[in] packet The buffer data (MUST be at least 20 chars)
227
 * @param[in] len The message data length in bytes (MUST be 20)
228
 * @param[in,out] seqnr The current FIR sequence number (will be incremented by the method)
229
 * @returns 0 in case of success, -1 on errors */
230
int janus_rtcp_fir_legacy(char *packet, int len, int *seqnr);
231

    
232
/*! \brief Method to generate a new RTCP PLI message to request a key frame
233
 * @param[in] packet The buffer data (MUST be at least 20 chars)
234
 * @param[in] len The message data length in bytes (MUST be 8)
235
 * @returns 0 in case of success, -1 on errors */
236
int janus_rtcp_pli(char *packet, int len);
237

    
238
#endif