uvgRTP 4.0.0
An open-source library for RTP/SRTP media delivery
Loading...
Searching...
No Matches
frame.hh
1#pragma once
2
3#include "util.hh"
4
5#include "uvgrtp/export.hh"
6#include "uvgrtp/definitions.hh"
7
8#ifdef _WIN32
9#include <winsock2.h>
10#include <windows.h>
11#include <ws2def.h>
12#else
13#include <netinet/in.h>
14#endif
15
16#include <vector>
17
18/* https://stackoverflow.com/questions/1537964/visual-c-equivalent-of-gccs-attribute-packed */
19#if defined(__MINGW32__) || defined(__MINGW64__) || defined(__GNUC__) || defined(__linux__)
20#define PACK(__Declaration__) __Declaration__ __attribute__((__packed__))
21#else
22#define PACK(__Declaration__) __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop))
23#endif
24
25namespace uvgrtp {
26 namespace frame {
27
28 // enums
29
30 enum RTCP_FRAME_TYPE {
31 RTCP_FT_SR = 200, /* Sender report */
32 RTCP_FT_RR = 201, /* Receiver report */
33 RTCP_FT_SDES = 202, /* Source description */
34 RTCP_FT_BYE = 203, /* Goodbye */
35 RTCP_FT_APP = 204, /* Application-specific message */
36 RTCP_FT_RTPFB = 205, /* Transport layer FB message */
37 RTCP_FT_PSFB = 206 /* Payload-specific FB message */
38 };
39
40 enum RTCP_RTPFB_FMT {
41 RTCP_RTPFB_NACK = 1 /* Generic NACK, defined in RFC 4585 section 6.2 */
42 };
43
44 /*
45 enum RTCP_PSFB_FMT {
46 RTCP_PSFB_PLI = 1, // Picture Loss Indication (PLI), defined in RFC 4585
47 RTCP_PSFB_SLI = 2, // Slice Loss Indication (SLI), defined in RFC 4585
48 RTCP_PSFB_RPSI = 3, // Reference Picture Selection Indication (RPSI), defined in RFC 4585
49 RTCP_PSFB_FIR = 4, // Full Intra Request (FIR), defined in RFC 5154
50 RTCP_PSFB_TSTR = 5, // Temporal-Spatial Trade-off Request (TSTR), defined in RFC 5154
51 RTCP_PSFB_AFB = 15 // Application Layer FB (AFB), defined in RFC 4585
52 };
53 */
54
55
56 // structs
57
65 PACK(struct UVGRTP_EXPORT rtp_header {
66 uint8_t version:2;
67 uint8_t padding:1;
68 uint8_t ext:1;
69 uint8_t cc:4;
70 uint8_t marker:1;
71 uint8_t payload:7;
72 uint16_t seq = 0;
73 uint32_t timestamp = 0;
74 uint32_t ssrc = 0;
75 });
76
84 PACK(struct UVGRTP_EXPORT ext_header {
85 uint16_t type = 0;
86 uint16_t len = 0;
87 uint8_t *data = nullptr;
88 });
89
94 struct UVGRTP_EXPORT rtp_frame {
95 struct rtp_header header;
96 uint32_t *csrc = nullptr;
97 struct ext_header *ext = nullptr;
98
99 size_t padding_len = 0; /* non-zero if frame is padded */
100
105 size_t payload_len = 0;
106 uint8_t* payload = nullptr;
107
109 uint8_t *dgram = nullptr; /* pointer to the UDP datagram (for internal use only) */
110 size_t dgram_size = 0; /* size of the UDP datagram */
112 };
113
118 struct UVGRTP_EXPORT rtcp_header {
121 uint8_t version = 0;
123 uint8_t padding = 0;
124 union {
126 uint8_t count = 0;
128 uint8_t pkt_subtype;
130 uint8_t fmt;
131 };
133 uint8_t pkt_type = 0;
135 uint16_t length = 0;
136 };
137
138
143 struct UVGRTP_EXPORT rtcp_sender_info {
145 uint32_t ntp_msw = 0;
147 uint32_t ntp_lsw = 0;
149 uint32_t rtp_ts = 0;
150 uint32_t pkt_cnt = 0;
152 uint32_t byte_cnt = 0;
153 };
154
159 struct UVGRTP_EXPORT rtcp_report_block {
160 uint32_t ssrc = 0;
161 uint8_t fraction = 0;
162 int32_t lost = 0;
163 uint32_t last_seq = 0;
164 uint32_t jitter = 0;
165 uint32_t lsr = 0; /* last Sender Report */
166 uint32_t dlsr = 0; /* delay since last Sender Report */
167 };
168
173 struct UVGRTP_EXPORT rtcp_sr {
174 struct rtcp_header header;
175 uint32_t ssrc = 0;
176 rtcp_sender_info sender_info;
177 rtcp_report_block* report_blocks;
178 };
179
184 struct UVGRTP_EXPORT rtcp_rr {
185 struct rtcp_header header;
186 uint32_t ssrc = 0;
187 rtcp_report_block* report_blocks;
188 };
189
194 struct UVGRTP_EXPORT rtcp_sdes_item {
195 uint8_t type = 0;
196 uint8_t length = 0;
197 uint8_t* data = nullptr;
198 };
199
204 struct UVGRTP_EXPORT rtcp_sdes_ck {
205 uint32_t ssrc = 0;
206 rtcp_sdes_item* items = nullptr;
207 size_t item_count = 0; // not in rfc, here to make usage easier
208 };
209
210
215 struct UVGRTP_EXPORT rtcp_sdes {
216 struct rtcp_header header;
217 rtcp_sdes_ck* chunks = nullptr;
218 };
223 struct UVGRTP_EXPORT rtcp_app_packet {
224 struct rtcp_header header;
225 uint32_t ssrc = 0;
226 uint8_t name[4] = {0};
227 uint8_t *payload = nullptr;
228 // \brief Size of the payload in bytes. Added by uvgRTP to help process the payload.
229 size_t payload_len = 0;
230 };
231
232 /*
233 * The feedback messages are commented as they were not implemented anywhere. If
234 * someone wants to implement these, please get rid of the union as it breaks rfc by
235 * allowing more than one type of feedback in the same message.
236 *
237 * Please also keep ABI safety in mind by removing std::vector.
238 *
239
240
241 // \brief Full Intra Request, See RFC 5104 section 4.3.1
242 struct rtcp_fir {
243 uint32_t ssrc = 0;
244 uint8_t seq = 0;
245 };
246 // \brief Slice Loss Indication, See RFC 4585 section 6.3.2
247 struct rtcp_sli {
248 uint16_t first = 0;
249 uint16_t num = 0;
250 uint8_t picture_id = 0;
251 };
252 // \brief Reference Picture Selection Indication, See RFC 4585 section 6.3.3
253 struct rtcp_rpsi {
254 uint8_t pb = 0;
255 uint8_t pt = 0;
256 uint8_t* str = nullptr;
257 };
258
259 // \brief RTCP Feedback Control Information, See RFC 4585 section 6.1
260 struct rtcp_fb_fci {
261 union {
262 rtcp_fir fir;
263 rtcp_sli sli;
264 rtcp_rpsi rpsi;
265 };
266 };
267
268 // \brief Feedback message. See RFC 4585 section 6.1
269 struct rtcp_fb_packet {
270 struct rtcp_header header;
271 uint32_t sender_ssrc = 0;
272 uint32_t media_ssrc = 0;
273 std::vector<rtcp_fb_fci> items; // allows illegal stucts, please fix if implementing
274 // \brief Size of the payload in bytes. Added by uvgRTP to help process the payload.
275 size_t payload_len = 0;
276 };
277
278 */
279
280 // dealloc functions, add new functions to the end for abi reasons
292 rtp_error_t UVGRTP_EXPORT dealloc_frame(uvgrtp::frame::rtp_frame* frame);
293
305 rtp_error_t UVGRTP_EXPORT dealloc_sr(uvgrtp::frame::rtcp_sr* sr);
306
318 rtp_error_t UVGRTP_EXPORT dealloc_rr(uvgrtp::frame::rtcp_rr* rr);
319
331 rtp_error_t UVGRTP_EXPORT dealloc_sdes(uvgrtp::frame::rtcp_sdes* sdes);
332
333#if UVGRTP_EXTENDED_API
341 struct rtcp_header header;
342 uint32_t ssrc = 0;
343 std::vector<rtcp_report_block> report_blocks;
344 };
345
353 struct rtcp_header header;
354 uint32_t ssrc = 0;
355 struct rtcp_sender_info sender_info;
356 std::vector<rtcp_report_block> report_blocks;
357 };
358
366 uint32_t ssrc = 0;
367 std::vector<rtcp_sdes_item> items;
368 };
369
377 struct rtcp_header header;
378 std::vector<rtcp_sdes_chunk> chunks;
379 };
380#endif
381 }
382}
383
384namespace uvg_rtp = uvgrtp;
rtp_error_t UVGRTP_EXPORT dealloc_sdes(uvgrtp::frame::rtcp_sdes *sdes)
Deallocates an RTCP Source Description (SDES) frame.
rtp_error_t UVGRTP_EXPORT dealloc_sr(uvgrtp::frame::rtcp_sr *sr)
Deallocates an RTCP Sender Report (SR) frame.
rtp_error_t UVGRTP_EXPORT dealloc_rr(uvgrtp::frame::rtcp_rr *rr)
Deallocates an RTCP Receiver Report (RR) frame.
rtp_error_t UVGRTP_EXPORT dealloc_frame(uvgrtp::frame::rtp_frame *frame)
Deallocates an RTP frame.
See RFC 3550 section 6.7 for details on RTCP Application Packet.
Definition frame.hh:223
Header for all RTCP packets defined in RFC 3550 section 6
Definition frame.hh:118
uint8_t fmt
Feedback message type (FMT), specified in RFC 5104 section 4.3. Alternative to count and pkt_subtype.
Definition frame.hh:130
uint8_t pkt_subtype
Subtype in APP packets. Alternative to count.
Definition frame.hh:128
See RFC 3550 section 6.4.2
Definition frame.hh:340
See RFC 3550 section 6.4.1
Definition frame.hh:159
See RFC 3550 section 6.4.2 for details on the RTCP RR (Receiver Report).
Definition frame.hh:184
See RFC 3550 section 6.5
Definition frame.hh:365
See RFC 3550 section 6.5 for details on RTCP SDES Chunk.
Definition frame.hh:204
See RFC 3550 section 6.5 for details on RTCP SDES Item.
Definition frame.hh:194
See RFC 3550 section 6.5
Definition frame.hh:376
See RFC 3550 section 6.5 for details on RTCP SDES (Source Description).
Definition frame.hh:215
See RFC 3550 section 6.4.1
Definition frame.hh:143
See RFC 3550 section 6.4.1
Definition frame.hh:352
See RFC 3550 section 6.4.1
Definition frame.hh:173
See RFC 3550 section 5
Definition frame.hh:94