Debian Codegraph @

src/proto/rtp.h

raw symbols SCIP
1 #ifndef RIST_PROTO_RTP_H
2 #define RIST_PROTO_RTP_H
3
4 #include "common/attributes.h"
5 #include <stdint.h>
6
7 /*
8
9 RTP header format (RFC 3550)
10 The RTP header is always present on data packets
11
12 0 1 2 3
13 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
14 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
15 |V=2|P|X| CC |M| PT | sequence number |
16 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
17 | timestamp |
18 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
19 | synchronization source (SSRC) identifier |
20 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
21 | contributing source (CSRC) identifiers |
22 | .... |
23 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24
25 */
26 /*
27 0 1 2 3
28 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
29 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 |V=2|0| Subtype | PT=APP=204 | Length |
31 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 | SSRC of media source |
33 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 | name (ASCII) |
35 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 | Timestamp, most significant word |
37 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 | Timestamp, least significant word |
39 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 | Processing Delay (microseconds) |
41 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 | Padding bytes |
43 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 ...
45 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 | Padding bytes |
47 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 */
49 /*
50 RTP header extension format (RFC 3550)
51
52 0 1 2 3
53 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
54 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55 | defined by profile | length |
56 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 | header extension |
58 | .... |
59
60 RIST implementation of header extension format used for null packet
61 deletion and sequence number extension (VSF TR-06-02, 8.3)
62
63 0 1 2 3
64 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
65 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 | 0x52 (R) | 0x49 (I) | Length=1 |
67 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 |N|E|Size |0 0 0|T| NPD bits | Sequence Number Extension |
69 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 */
71
72 /*
73 RTCP Control Channel:
74
75 [ GRE header ]
76 [ Reduced overhead header. ]
77 [ RTCP payload .]
78
79 */
80
81
82 // RTCP constants
83 #define RTCP_FB_HEADER_SIZE 12
84
85 #define PTYPE_RTCP_CUSTOM1 72
86 #define PTYPE_RTCP_CUSTOM2 73
87 #define PTYPE_RTCP_CUSTOM3 74
88 #define PTYPE_RTCP_CUSTOM4 75
89 #define PTYPE_RTCP_CUSTOM5 76
90 #define PTYPE_XR 77
91
92 #define PTYPE_SR 200
93 #define PTYPE_RR 201
94 #define PTYPE_SDES 202
95 #define PTYPE_NACK_CUSTOM 204
96 #define PTYPE_NACK_BITMASK 205
97 // To be deprecated in the future
98 #define PTYPE_XR_LEGACY 207
99
100 #define NACK_FMT_BITMASK 1
101 #define NACK_FMT_RANGE 0
102 #define ECHO_REQUEST 2
103 #define ECHO_RESPONSE 3
104
105 #define RTCP_SDES_SIZE 10
106 #define RTP_MPEGTS_FLAGS 0x80
107 #define RTCP_SR_FLAGS 0x80
108 #define RTCP_RR_FULL_FLAGS 0x81
109 #define RTCP_SDES_FLAGS 0x81
110 #define RTCP_NACK_RANGE_FLAGS 0x80
111 #define RTCP_NACK_BITMASK_FLAGS 0x81
112 #define RTCP_ECHOEXT_REQ_FLAGS 0x82
113 #define RTCP_ECHOEXT_RESP_FLAGS 0x83
114
115 // RTP Payload types and clocks
116 // March 1995 (page 9): https://tools.ietf.org/html/draft-ietf-avt-profile-04
117 // Nov 2019 (page 2): https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml
118 #define RTP_PTYPE_MPEGTS (0x21)
119 #define RTP_PTYPE_MPEGTS_CLOCKHZ (90000)
120 #define RTP_PTYPE_RIST (21)
121 #define RTP_PTYPE_RIST_CLOCKHZ (UINT16_MAX + 1)
122
123 RIST_PACKED_STRUCT(rist_rtp_hdr,{
124 uint8_t flags;
125 uint8_t payload_type;
126 uint16_t seq;
127 uint32_t ts;
128 uint32_t ssrc;
129 })
130
131 RIST_PACKED_STRUCT(rist_rtp_hdr_ext, {
132 uint16_t identifier; /* set to 0x5249 */
133 uint16_t length; /*shall be set to 1 */
134 uint8_t flags;
135 uint8_t npd_bits;
136 uint16_t seq_ext;
137 })
138
139 RIST_PACKED_STRUCT(rist_protocol_hdr,{
140 uint16_t src_port;
141 uint16_t dst_port;
142 struct rist_rtp_hdr rtp;
143 })
144
145 RIST_PACKED_STRUCT(rist_rtp_nack_record,{
146 uint16_t start;
147 uint16_t extra;
148 })
149
150 RIST_PACKED_STRUCT(rist_rtcp_hdr,{
151 uint8_t flags;
152 uint8_t ptype;
153 uint16_t len;
154 uint32_t ssrc;
155 })
156
157 RIST_PACKED_STRUCT(rist_rtcp_nack_range,{
158 uint8_t flags;
159 uint8_t ptype;
160 uint16_t len;
161 uint32_t ssrc_source;
162 uint8_t name[4];
163 })
164
165 RIST_PACKED_STRUCT(rist_rtcp_nack_bitmask,{
166 uint8_t flags;
167 uint8_t ptype;
168 uint16_t len;
169 uint32_t ssrc_source;
170 uint32_t ssrc;
171 })
172
173 RIST_PACKED_STRUCT(rist_rtcp_echoext, {
174 uint8_t flags;
175 uint8_t ptype;
176 uint16_t len;
177 uint32_t ssrc;
178 uint8_t name[4];
179 uint32_t ntp_msw;
180 uint32_t ntp_lsw;
181 uint32_t delay;
182 })
183
184 RIST_PACKED_STRUCT(rist_rtcp_sr_pkt,{
185 struct rist_rtcp_hdr rtcp;
186 uint32_t ntp_msw;
187 uint32_t ntp_lsw;
188 uint32_t rtp_ts;
189 uint32_t sender_pkts;
190 uint32_t sender_bytes;
191 })
192
193 RIST_PACKED_STRUCT(rist_rtcp_rr_pkt,{
194 struct rist_rtcp_hdr rtcp;
195 uint32_t recv_ssrc;
196 uint8_t fraction_lost;
197 uint8_t cumulative_pkt_loss_msb;
198 uint16_t cumulative_pkt_loss_lshw;
199 uint32_t highest_seq;
200 uint32_t jitter;
201 uint32_t lsr;
202 uint32_t dlsr;
203 })
204
205 RIST_PACKED_STRUCT(rist_rtcp_rr_empty_pkt,{
206 struct rist_rtcp_hdr rtcp;
207 })
208
209 RIST_PACKED_STRUCT(rist_rtcp_sdes_pkt,{
210 struct rist_rtcp_hdr rtcp;
211 uint8_t cname;
212 uint8_t name_len;
213 char udn[1];
214 })
215
216 RIST_PACKED_STRUCT(rist_rtcp_xr_block_hdr, {
217 uint8_t type;
218 uint8_t reserved;
219 uint16_t length;
220 })
221 //Receiver reference time report block
222 RIST_PACKED_STRUCT(rist_rtcp_xr_rrtrb, {
223 uint8_t block_type;
224 uint8_t reserved;
225 uint16_t length;
226 uint32_t ntp_msw;
227 uint32_t ntp_lsw;
228 })
229
230 RIST_PACKED_STRUCT(rist_rtcp_xr_dlrr, {
231 uint8_t block_type;
232 uint8_t reserved;
233 uint16_t length;
234 uint32_t ssrc;
235 uint32_t lrr;
236 uint32_t delay;
237 })
238
239 static inline uint32_t get_rtp_ts_clock(uint8_t ptype) {
240 uint32_t clock = 0;
241 switch(ptype) {
242 case RTP_PTYPE_MPEGTS:
243 case 14: // MPA
244 case 25: // CelB
245 case 26: // JPEG
246 case 28: // nv
247 case 31: // H261
248 case 32: // MPV
249 case 34: // H263
250 clock = RTP_PTYPE_MPEGTS_CLOCKHZ;
251 break;
252 case 0: // PCMU
253 case 3: // GSM
254 case 4: // G723
255 case 5: // DVI4
256 case 7: // LPC
257 case 8: // PCMA
258 case 9: // G722
259 case 12: // QCELP
260 case 13: // CN
261 case 15: // G728
262 case 18: // G729
263 clock = 8000;
264 break;
265 case 16: // DVI4
266 clock = 11025;
267 break;
268 case 6: // DVI4
269 clock = 16000;
270 break;
271 case 17: // DVI4
272 clock = 22050;
273 break;
274 case 10: // L16
275 case 11: // L16
276 clock = 44100;
277 break;
278 default:
279 clock = 0;
280 break;
281 }
282 return clock;
283 }
284
285 #endif /* RIST_PROTO_RTP_H */