uvgRTP 2.3.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#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 };
33
34 PACK(struct rtp_header {
35 uint8_t version:2;
36 uint8_t padding:1;
37 uint8_t ext:1;
38 uint8_t cc:4;
39 uint8_t marker:1;
40 uint8_t payload:7;
41 uint16_t seq = 0;
42 uint32_t timestamp = 0;
43 uint32_t ssrc = 0;
44 });
45
46 PACK(struct ext_header {
47 uint16_t type = 0;
48 uint16_t len = 0;
49 uint8_t *data = nullptr;
50 });
51
53 struct rtp_frame {
54 struct rtp_header header;
55 uint32_t *csrc = nullptr;
56 struct ext_header *ext = nullptr;
57
58 size_t padding_len = 0; /* non-zero if frame is padded */
59
64 size_t payload_len = 0;
65 uint8_t* payload = nullptr;
66
68 uint8_t *dgram = nullptr; /* pointer to the UDP datagram (for internal use only) */
69 size_t dgram_size = 0; /* size of the UDP datagram */
71 };
72
74 struct rtcp_header {
77 uint8_t version = 0;
79 uint8_t padding = 0;
80 union {
82 uint8_t count = 0;
84 uint8_t pkt_subtype;
85 };
87 uint8_t pkt_type = 0;
89 uint16_t length = 0;
90 };
91
95 uint32_t ntp_msw = 0;
97 uint32_t ntp_lsw = 0;
99 uint32_t rtp_ts = 0;
100 uint32_t pkt_cnt = 0;
102 uint32_t byte_cnt = 0;
103 };
104
107 uint32_t ssrc = 0;
108 uint8_t fraction = 0;
109 int32_t lost = 0;
110 uint32_t last_seq = 0;
111 uint32_t jitter = 0;
112 uint32_t lsr = 0; /* last Sender Report */
113 uint32_t dlsr = 0; /* delay since last Sender Report */
114 };
115
118 struct rtcp_header header;
119 uint32_t ssrc = 0;
120 std::vector<rtcp_report_block> report_blocks;
121 };
122
125 struct rtcp_header header;
126 uint32_t ssrc = 0;
127 struct rtcp_sender_info sender_info;
128 std::vector<rtcp_report_block> report_blocks;
129 };
130
133 uint8_t type = 0;
134 uint8_t length = 0;
135 uint8_t *data = nullptr;
136 };
137
140 uint32_t ssrc = 0;
141 std::vector<rtcp_sdes_item> items;
142 };
143
146 struct rtcp_header header;
147 std::vector<rtcp_sdes_chunk> chunks;
148 };
149
152 struct rtcp_header header;
153 uint32_t ssrc = 0;
154 uint8_t name[4] = {0};
155 uint8_t *payload = nullptr;
157 size_t payload_len = 0;
158 };
159
160 PACK(struct zrtp_frame {
161 uint8_t version:4;
162 uint16_t unused:12;
163 uint16_t seq = 0;
164 uint32_t magic = 0;
165 uint32_t ssrc = 0;
166 uint8_t payload[1];
167 });
168
169 /* Allocate an RTP frame
170 *
171 * First function allocates an empty RTP frame (no payload)
172 *
173 * Second allocates an RTP frame with payload of size "payload_len",
174 *
175 * Third allocate an RTP frame with payload of size "payload_len"
176 * + probation zone of size "pz_size" * MAX_PAYLOAD
177 *
178 * Return pointer to frame on success
179 * Return nullptr on error and set rtp_errno to:
180 * RTP_MEMORY_ERROR if allocation of memory failed */
181 rtp_frame *alloc_rtp_frame();
182 rtp_frame *alloc_rtp_frame(size_t payload_len);
183
184
185 /* Deallocate RTP frame
186 *
187 * Return RTP_OK on successs
188 * Return RTP_INVALID_VALUE if "frame" is nullptr */
189 rtp_error_t dealloc_frame(uvgrtp::frame::rtp_frame *frame);
190
191
192 /* Allocate ZRTP frame
193 * Parameter "payload_size" defines the length of the frame
194 *
195 * Return pointer to frame on success
196 * Return nullptr on error and set rtp_errno to:
197 * RTP_MEMORY_ERROR if allocation of memory failed
198 * RTP_INVALID_VALUE if "payload_size" is 0 */
199 void* alloc_zrtp_frame(size_t payload_size);
200
201
202 /* Deallocate ZRTP frame
203 *
204 * Return RTP_OK on successs
205 * Return RTP_INVALID_VALUE if "frame" is nullptr */
206 rtp_error_t dealloc_frame(uvgrtp::frame::zrtp_frame* frame);
207 }
208}
209
210namespace uvg_rtp = uvgrtp;
See RFC 3550 section 6.7
Definition: frame.hh:151
size_t payload_len
Size of the payload in bytes. Added by uvgRTP to help process the payload.
Definition: frame.hh:157
Header of for all RTCP packets defined in RFC 3550 section 6
Definition: frame.hh:74
uint8_t pkt_type
Identifies the RTCP packet type.
Definition: frame.hh:87
uint8_t version
This field identifies the version of RTP. The version defined by RFC 3550 is two (2).
Definition: frame.hh:77
uint16_t length
Length of the whole message measured in 32-bit words.
Definition: frame.hh:89
uint8_t padding
Does this packet contain padding at the end.
Definition: frame.hh:79
uint8_t pkt_subtype
Subtype in APP packets. Alternative to count.
Definition: frame.hh:84
uint8_t count
Source count or report count. Alternative to pkt_subtype.
Definition: frame.hh:82
See RFC 3550 section 6.4.2
Definition: frame.hh:117
See RFC 3550 section 6.4.1
Definition: frame.hh:106
See RFC 3550 section 6.5
Definition: frame.hh:139
See RFC 3550 section 6.5
Definition: frame.hh:132
See RFC 3550 section 6.5
Definition: frame.hh:145
See RFC 3550 section 6.4.1
Definition: frame.hh:93
uint32_t rtp_ts
RTP timestamp corresponding to this NTP timestamp.
Definition: frame.hh:99
uint32_t byte_cnt
Also known as octet count.
Definition: frame.hh:102
uint32_t ntp_lsw
NTP timestamp, least significant word.
Definition: frame.hh:97
uint32_t ntp_msw
NTP timestamp, most significant word.
Definition: frame.hh:95
See RFC 3550 section 6.4.1
Definition: frame.hh:124
See RFC 3550 section 5
Definition: frame.hh:53
size_t payload_len
Length of the packet payload in bytes added by uvgRTP to help process the frame.
Definition: frame.hh:64