uvgRTP 3.1.3
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#ifdef _WIN32
6#include <winsock2.h>
7#include <windows.h>
8#include <ws2def.h>
9#else
10#include <netinet/in.h>
11#endif
12
13#include <string>
14#include <vector>
15
16/* https://stackoverflow.com/questions/1537964/visual-c-equivalent-of-gccs-attribute-packed */
17#if defined(__MINGW32__) || defined(__MINGW64__) || defined(__GNUC__) || defined(__linux__)
18#define PACK(__Declaration__) __Declaration__ __attribute__((__packed__))
19#else
20#define PACK(__Declaration__) __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop))
21#endif
22
23namespace uvgrtp {
24 namespace frame {
25
26 enum RTCP_FRAME_TYPE {
27 RTCP_FT_SR = 200, /* Sender report */
28 RTCP_FT_RR = 201, /* Receiver report */
29 RTCP_FT_SDES = 202, /* Source description */
30 RTCP_FT_BYE = 203, /* Goodbye */
31 RTCP_FT_APP = 204, /* Application-specific message */
32 RTCP_FT_RTPFB = 205, /* Transport layer FB message */
33 RTCP_FT_PSFB = 206 /* Payload-specific FB message */
34 };
35
36 enum RTCP_PSFB_FMT {
37 RTCP_PSFB_PLI = 1, /* Picture Loss Indication (PLI), defined in RFC 4585 */
38 RTCP_PSFB_SLI = 2, /* Slice Loss Indication (SLI), defined in RFC 4585 */
39 RTCP_PSFB_RPSI = 3, /* Reference Picture Selection Indication (RPSI), defined in RFC 4585 */
40 RTCP_PSFB_FIR = 4, /* Full Intra Request (FIR), defined in RFC 5154 */
41 RTCP_PSFB_TSTR = 5, /* Temporal-Spatial Trade-off Request (TSTR), defined in RFC 5154 */
42 RTCP_PSFB_AFB = 15 /* Application Layer FB (AFB), defined in RFC 4585 */
43 };
44
45 enum RTCP_RTPFB_FMT {
46 RTCP_RTPFB_NACK = 1 /* Generic NACK, defined in RFC 4585 section 6.2 */
47 };
48
49 PACK(struct rtp_header {
50 uint8_t version:2;
51 uint8_t padding:1;
52 uint8_t ext:1;
53 uint8_t cc:4;
54 uint8_t marker:1;
55 uint8_t payload:7;
56 uint16_t seq = 0;
57 uint32_t timestamp = 0;
58 uint32_t ssrc = 0;
59 });
60
61 PACK(struct ext_header {
62 uint16_t type = 0;
63 uint16_t len = 0;
64 uint8_t *data = nullptr;
65 });
66
68 struct rtp_frame {
69 struct rtp_header header;
70 uint32_t *csrc = nullptr;
71 struct ext_header *ext = nullptr;
72
73 size_t padding_len = 0; /* non-zero if frame is padded */
74
79 size_t payload_len = 0;
80 uint8_t* payload = nullptr;
81
83 uint8_t *dgram = nullptr; /* pointer to the UDP datagram (for internal use only) */
84 size_t dgram_size = 0; /* size of the UDP datagram */
86 };
87
89 struct rtcp_header {
92 uint8_t version = 0;
94 uint8_t padding = 0;
95 union {
97 uint8_t count = 0;
99 uint8_t pkt_subtype;
101 uint8_t fmt;
102 };
104 uint8_t pkt_type = 0;
106 uint16_t length = 0;
107 };
108
112 uint32_t ntp_msw = 0;
114 uint32_t ntp_lsw = 0;
116 uint32_t rtp_ts = 0;
117 uint32_t pkt_cnt = 0;
119 uint32_t byte_cnt = 0;
120 };
121
124 uint32_t ssrc = 0;
125 uint8_t fraction = 0;
126 int32_t lost = 0;
127 uint32_t last_seq = 0;
128 uint32_t jitter = 0;
129 uint32_t lsr = 0; /* last Sender Report */
130 uint32_t dlsr = 0; /* delay since last Sender Report */
131 };
132
135 struct rtcp_header header;
136 uint32_t ssrc = 0;
137 std::vector<rtcp_report_block> report_blocks;
138 };
139
142 struct rtcp_header header;
143 uint32_t ssrc = 0;
144 struct rtcp_sender_info sender_info;
145 std::vector<rtcp_report_block> report_blocks;
146 };
147
150 uint8_t type = 0;
151 uint8_t length = 0;
152 uint8_t *data = nullptr;
153 };
154
157 uint32_t ssrc = 0;
158 std::vector<rtcp_sdes_item> items;
159 };
160
163 struct rtcp_header header;
164 std::vector<rtcp_sdes_chunk> chunks;
165 };
166
169 struct rtcp_header header;
170 uint32_t ssrc = 0;
171 uint8_t name[4] = {0};
172 uint8_t *payload = nullptr;
174 size_t payload_len = 0;
175 };
176
178 struct rtcp_fir {
179 uint32_t ssrc = 0;
180 uint8_t seq = 0;
181 };
183 struct rtcp_sli {
184 uint16_t first = 0;
185 uint16_t num = 0;
186 uint8_t picture_id = 0;
187 };
189 struct rtcp_rpsi {
190 uint8_t pb = 0;
191 uint8_t pt = 0;
192 uint8_t* str = nullptr;
193 };
194
196 struct rtcp_fb_fci {
197
198 union {
199 rtcp_fir fir;
200 rtcp_sli sli;
201 rtcp_rpsi rpsi;
202 };
203 };
204
207 struct rtcp_header header;
208 uint32_t sender_ssrc = 0;
209 uint32_t media_ssrc = 0;
210 std::vector<rtcp_fb_fci> items;
212 size_t payload_len = 0;
213 };
214
215
216 PACK(struct zrtp_frame {
217 uint8_t version:4;
218 uint16_t unused:12;
219 uint16_t seq = 0;
220 uint32_t magic = 0;
221 uint32_t ssrc = 0;
222 uint8_t payload[1];
223 });
224
225 /* Allocate an RTP frame
226 *
227 * First function allocates an empty RTP frame (no payload)
228 *
229 * Second allocates an RTP frame with payload of size "payload_len",
230 *
231 * Third allocate an RTP frame with payload of size "payload_len"
232 * + probation zone of size "pz_size" * MAX_PAYLOAD
233 *
234 * Return pointer to frame on success
235 * Return nullptr on error and set rtp_errno to:
236 * RTP_MEMORY_ERROR if allocation of memory failed */
237 rtp_frame *alloc_rtp_frame();
238 rtp_frame *alloc_rtp_frame(size_t payload_len);
239
240
241 /* Deallocate RTP frame
242 *
243 * Return RTP_OK on successs
244 * Return RTP_INVALID_VALUE if "frame" is nullptr */
245 rtp_error_t dealloc_frame(uvgrtp::frame::rtp_frame *frame);
246
247
248 /* Allocate ZRTP frame
249 * Parameter "payload_size" defines the length of the frame
250 *
251 * Return pointer to frame on success
252 * Return nullptr on error and set rtp_errno to:
253 * RTP_MEMORY_ERROR if allocation of memory failed
254 * RTP_INVALID_VALUE if "payload_size" is 0 */
255 void* alloc_zrtp_frame(size_t payload_size);
256
257
258 /* Deallocate ZRTP frame
259 *
260 * Return RTP_OK on successs
261 * Return RTP_INVALID_VALUE if "frame" is nullptr */
262 rtp_error_t dealloc_frame(uvgrtp::frame::zrtp_frame* frame);
263 }
264}
265
266namespace uvg_rtp = uvgrtp;
See RFC 3550 section 6.7
Definition frame.hh:168
size_t payload_len
Size of the payload in bytes. Added by uvgRTP to help process the payload.
Definition frame.hh:174
RTCP Feedback Control Information, See RFC 4585 section 6.1.
Definition frame.hh:196
Feedback message. See RFC 4585 section 6.1.
Definition frame.hh:206
size_t payload_len
Size of the payload in bytes. Added by uvgRTP to help process the payload.
Definition frame.hh:212
Full Intra Request, See RFC 5104 section 4.3.1.
Definition frame.hh:178
Header of for all RTCP packets defined in RFC 3550 section 6
Definition frame.hh:89
uint8_t pkt_type
Identifies the RTCP packet type.
Definition frame.hh:104
uint8_t version
This field identifies the version of RTP. The version defined by RFC 3550 is two (2).
Definition frame.hh:92
uint8_t fmt
Feedback message type (FMT), specified in RFC 5104 section 4.3. Alternative to count and pkt_subtype.
Definition frame.hh:101
uint16_t length
Length of the whole message measured in 32-bit words.
Definition frame.hh:106
uint8_t padding
Does this packet contain padding at the end.
Definition frame.hh:94
uint8_t pkt_subtype
Subtype in APP packets. Alternative to count.
Definition frame.hh:99
uint8_t count
Source count or report count. Alternative to pkt_subtype.
Definition frame.hh:97
See RFC 3550 section 6.4.2
Definition frame.hh:134
See RFC 3550 section 6.4.1
Definition frame.hh:123
Reference Picture Selection Indication, See RFC 4585 section 6.3.3.
Definition frame.hh:189
See RFC 3550 section 6.5
Definition frame.hh:156
See RFC 3550 section 6.5
Definition frame.hh:149
See RFC 3550 section 6.5
Definition frame.hh:162
See RFC 3550 section 6.4.1
Definition frame.hh:110
uint32_t rtp_ts
RTP timestamp corresponding to this NTP timestamp.
Definition frame.hh:116
uint32_t byte_cnt
Also known as octet count.
Definition frame.hh:119
uint32_t ntp_lsw
NTP timestamp, least significant word.
Definition frame.hh:114
uint32_t ntp_msw
NTP timestamp, most significant word.
Definition frame.hh:112
See RFC 3550 section 6.4.1
Definition frame.hh:141
Slice Loss Indication, See RFC 4585 section 6.3.2.
Definition frame.hh:183
See RFC 3550 section 5
Definition frame.hh:68
size_t payload_len
Length of the packet payload in bytes added by uvgRTP to help process the frame.
Definition frame.hh:79