2019-05-17 09:47:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-06-01 07:54:23 +00:00
|
|
|
#include "util.hh"
|
|
|
|
|
2019-08-14 07:21:33 +00:00
|
|
|
#ifdef _WIN32
|
2020-02-18 05:42:28 +00:00
|
|
|
#include <winsock2.h>
|
|
|
|
#include <windows.h>
|
2019-08-14 07:21:33 +00:00
|
|
|
#include <ws2def.h>
|
|
|
|
#else
|
|
|
|
#include <netinet/in.h>
|
2019-09-30 05:58:01 +00:00
|
|
|
#endif
|
2019-08-14 07:21:33 +00:00
|
|
|
|
2019-06-18 06:55:23 +00:00
|
|
|
#include <string>
|
2020-08-26 08:02:15 +00:00
|
|
|
#include <vector>
|
2019-06-18 06:55:23 +00:00
|
|
|
|
2021-02-19 01:13:43 +00:00
|
|
|
namespace uvgrtp {
|
2019-05-22 09:43:35 +00:00
|
|
|
namespace frame {
|
2019-05-22 06:24:29 +00:00
|
|
|
|
2020-01-17 08:18:11 +00:00
|
|
|
enum RTCP_FRAME_TYPE {
|
|
|
|
RTCP_FT_SR = 200, /* Sender report */
|
|
|
|
RTCP_FT_RR = 201, /* Receiver report */
|
|
|
|
RTCP_FT_SDES = 202, /* Source description */
|
|
|
|
RTCP_FT_BYE = 203, /* Goodbye */
|
|
|
|
RTCP_FT_APP = 204 /* Application-specific message */
|
|
|
|
};
|
2019-06-17 08:56:21 +00:00
|
|
|
|
2020-10-01 07:12:01 +00:00
|
|
|
PACK(struct rtp_header {
|
2019-07-24 06:50:27 +00:00
|
|
|
uint8_t version:2;
|
|
|
|
uint8_t padding:1;
|
|
|
|
uint8_t ext:1;
|
|
|
|
uint8_t cc:4;
|
|
|
|
uint8_t marker:1;
|
|
|
|
uint8_t payload:7;
|
2021-06-03 07:38:49 +00:00
|
|
|
uint16_t seq = 0;
|
|
|
|
uint32_t timestamp = 0;
|
|
|
|
uint32_t ssrc = 0;
|
2020-10-01 07:12:01 +00:00
|
|
|
});
|
2019-07-24 06:50:27 +00:00
|
|
|
|
2020-10-01 07:12:01 +00:00
|
|
|
PACK(struct ext_header {
|
2021-06-03 07:38:49 +00:00
|
|
|
uint16_t type = 0;
|
|
|
|
uint16_t len = 0;
|
|
|
|
uint8_t *data = nullptr;
|
2020-10-01 07:12:01 +00:00
|
|
|
});
|
2019-08-14 05:38:21 +00:00
|
|
|
|
2019-07-24 06:50:27 +00:00
|
|
|
struct rtp_frame {
|
|
|
|
struct rtp_header header;
|
2021-06-03 07:38:49 +00:00
|
|
|
uint32_t *csrc = nullptr;
|
2022-08-25 09:11:12 +00:00
|
|
|
struct ext_header *ext = nullptr;
|
2019-05-17 09:47:38 +00:00
|
|
|
|
2021-06-03 07:38:49 +00:00
|
|
|
size_t padding_len = 0; /* non-zero if frame is padded */
|
|
|
|
size_t payload_len = 0; /* payload_len: total_len - header_len - padding length (if padded) */
|
2019-05-17 09:47:38 +00:00
|
|
|
|
2019-08-30 07:14:35 +00:00
|
|
|
/* Probation zone is a small area of free-to-use memory for the frame receiver
|
|
|
|
* when handling fragments. For example HEVC fragments that belong to future frames
|
|
|
|
* but cannot be relocated there (start sequence missing) are copied to probation
|
|
|
|
* zone and when the frame becomes active, all fragments in the probation are relocated
|
|
|
|
*
|
|
|
|
* NOTE 1: Probation zone will increase the memory usage and will increase
|
|
|
|
* the internal fragmentation as this memory is not usable for anything else
|
|
|
|
*
|
2019-09-11 08:34:12 +00:00
|
|
|
* NOTE 2: This is a Linux-only optimization */
|
2021-06-03 07:38:49 +00:00
|
|
|
size_t probation_len = 0;
|
|
|
|
size_t probation_off = 0;
|
|
|
|
uint8_t *probation = nullptr;
|
|
|
|
uint8_t *payload = nullptr;
|
2019-05-22 06:24:29 +00:00
|
|
|
|
2021-06-03 07:38:49 +00:00
|
|
|
uint8_t *dgram = nullptr; /* pointer to the UDP datagram (for internal use only) */
|
|
|
|
size_t dgram_size = 0; /* size of the UDP datagram */
|
2020-09-03 05:28:24 +00:00
|
|
|
|
2021-06-03 07:38:49 +00:00
|
|
|
rtp_format_t format = RTP_FORMAT_GENERIC;
|
|
|
|
int type = 0;
|
2022-08-25 09:11:12 +00:00
|
|
|
sockaddr_in src_addr = {};
|
2019-06-17 08:56:21 +00:00
|
|
|
};
|
|
|
|
|
2020-08-26 12:53:41 +00:00
|
|
|
struct rtcp_header {
|
2021-06-03 07:38:49 +00:00
|
|
|
uint8_t version = 0;
|
|
|
|
uint8_t padding = 0;
|
2020-08-26 12:32:51 +00:00
|
|
|
union {
|
2022-08-25 09:11:12 +00:00
|
|
|
uint8_t count = 0;
|
2020-08-26 12:32:51 +00:00
|
|
|
uint8_t pkt_subtype; /* for app packets */
|
|
|
|
};
|
2021-06-03 07:38:49 +00:00
|
|
|
uint8_t pkt_type = 0;
|
2022-09-05 04:37:10 +00:00
|
|
|
uint16_t length = 0; // whole message measured in 32-bit words
|
2019-06-17 08:56:21 +00:00
|
|
|
};
|
|
|
|
|
2020-08-26 12:53:41 +00:00
|
|
|
struct rtcp_sender_info {
|
2021-06-03 07:38:49 +00:00
|
|
|
uint32_t ntp_msw = 0; /* NTP timestamp, most significant word */
|
|
|
|
uint32_t ntp_lsw = 0; /* NTP timestamp, least significant word */
|
|
|
|
uint32_t rtp_ts = 0; /* RTP timestamp corresponding to same time as NTP */
|
|
|
|
uint32_t pkt_cnt = 0;
|
|
|
|
uint32_t byte_cnt = 0;
|
2019-06-17 08:56:21 +00:00
|
|
|
};
|
|
|
|
|
2020-08-26 12:53:41 +00:00
|
|
|
struct rtcp_report_block {
|
2021-06-03 07:38:49 +00:00
|
|
|
uint32_t ssrc = 0;
|
|
|
|
uint8_t fraction = 0;
|
|
|
|
int32_t lost = 0;
|
|
|
|
uint32_t last_seq = 0;
|
|
|
|
uint32_t jitter = 0;
|
|
|
|
uint32_t lsr = 0; /* last Sender Report */
|
|
|
|
uint32_t dlsr = 0; /* delay since last Sender Report */
|
2019-06-17 08:56:21 +00:00
|
|
|
};
|
|
|
|
|
2020-08-26 08:02:15 +00:00
|
|
|
struct rtcp_receiver_report {
|
|
|
|
struct rtcp_header header;
|
2021-06-03 07:38:49 +00:00
|
|
|
uint32_t ssrc = 0;
|
2020-08-26 08:02:15 +00:00
|
|
|
std::vector<rtcp_report_block> report_blocks;
|
|
|
|
};
|
|
|
|
|
2020-08-26 10:19:37 +00:00
|
|
|
struct rtcp_sender_report {
|
|
|
|
struct rtcp_header header;
|
2021-06-03 07:38:49 +00:00
|
|
|
uint32_t ssrc = 0;
|
2020-08-26 10:19:37 +00:00
|
|
|
struct rtcp_sender_info sender_info;
|
|
|
|
std::vector<rtcp_report_block> report_blocks;
|
|
|
|
};
|
|
|
|
|
2020-08-26 12:53:41 +00:00
|
|
|
struct rtcp_sdes_item {
|
2021-06-03 07:38:49 +00:00
|
|
|
uint8_t type = 0;
|
|
|
|
uint8_t length = 0;
|
2022-08-31 07:06:37 +00:00
|
|
|
uint8_t *data = nullptr;
|
2019-06-17 08:56:21 +00:00
|
|
|
};
|
|
|
|
|
2022-07-09 14:41:54 +00:00
|
|
|
struct rtcp_sdes_chunk {
|
2021-06-03 07:38:49 +00:00
|
|
|
uint32_t ssrc = 0;
|
2020-08-26 11:58:20 +00:00
|
|
|
std::vector<rtcp_sdes_item> items;
|
2019-06-17 08:56:21 +00:00
|
|
|
};
|
|
|
|
|
2022-07-09 14:41:54 +00:00
|
|
|
struct rtcp_sdes_packet {
|
|
|
|
struct rtcp_header header;
|
|
|
|
std::vector<rtcp_sdes_chunk> chunks;
|
|
|
|
};
|
|
|
|
|
2020-08-26 12:32:51 +00:00
|
|
|
struct rtcp_app_packet {
|
2019-06-18 06:55:23 +00:00
|
|
|
struct rtcp_header header;
|
2021-06-03 07:38:49 +00:00
|
|
|
uint32_t ssrc = 0;
|
2022-08-25 09:11:12 +00:00
|
|
|
uint8_t name[4] = {0};
|
2021-06-03 07:38:49 +00:00
|
|
|
uint8_t *payload = nullptr;
|
2022-09-05 04:37:10 +00:00
|
|
|
size_t payload_len = 0; // in bytes
|
2020-08-26 12:32:51 +00:00
|
|
|
};
|
|
|
|
|
2020-10-01 07:12:01 +00:00
|
|
|
PACK(struct zrtp_frame {
|
2020-01-22 08:57:40 +00:00
|
|
|
uint8_t version:4;
|
|
|
|
uint16_t unused:12;
|
2021-06-03 07:38:49 +00:00
|
|
|
uint16_t seq = 0;
|
|
|
|
uint32_t magic = 0;
|
|
|
|
uint32_t ssrc = 0;
|
2020-02-14 12:24:42 +00:00
|
|
|
uint8_t payload[1];
|
2020-10-01 07:12:01 +00:00
|
|
|
});
|
2020-01-22 08:57:40 +00:00
|
|
|
|
2020-01-17 08:33:28 +00:00
|
|
|
/* Allocate an RTP frame
|
|
|
|
*
|
|
|
|
* First function allocates an empty RTP frame (no payload)
|
|
|
|
*
|
|
|
|
* Second allocates an RTP frame with payload of size "payload_len",
|
|
|
|
*
|
|
|
|
* Third allocate an RTP frame with payload of size "payload_len"
|
|
|
|
* + probation zone of size "pz_size" * MAX_PAYLOAD
|
|
|
|
*
|
|
|
|
* Return pointer to frame on success
|
|
|
|
* Return nullptr on error and set rtp_errno to:
|
|
|
|
* RTP_MEMORY_ERROR if allocation of memory failed */
|
|
|
|
rtp_frame *alloc_rtp_frame();
|
|
|
|
rtp_frame *alloc_rtp_frame(size_t payload_len);
|
|
|
|
rtp_frame *alloc_rtp_frame(size_t payload_len, size_t pz_size);
|
|
|
|
|
2022-08-25 15:02:51 +00:00
|
|
|
|
|
|
|
/* Deallocate RTP frame
|
|
|
|
*
|
|
|
|
* Return RTP_OK on successs
|
|
|
|
* Return RTP_INVALID_VALUE if "frame" is nullptr */
|
|
|
|
rtp_error_t dealloc_frame(uvgrtp::frame::rtp_frame *frame);
|
|
|
|
|
|
|
|
|
2020-01-22 08:57:40 +00:00
|
|
|
/* Allocate ZRTP frame
|
2022-08-25 15:02:51 +00:00
|
|
|
* Parameter "payload_size" defines the length of the frame
|
2020-01-22 08:57:40 +00:00
|
|
|
*
|
|
|
|
* Return pointer to frame on success
|
|
|
|
* Return nullptr on error and set rtp_errno to:
|
|
|
|
* RTP_MEMORY_ERROR if allocation of memory failed
|
|
|
|
* RTP_INVALID_VALUE if "payload_size" is 0 */
|
2022-08-25 15:02:51 +00:00
|
|
|
void* alloc_zrtp_frame(size_t payload_size);
|
2020-01-22 08:57:40 +00:00
|
|
|
|
2019-06-18 06:55:23 +00:00
|
|
|
|
2020-01-22 08:57:40 +00:00
|
|
|
/* Deallocate ZRTP frame
|
|
|
|
*
|
|
|
|
* Return RTP_OK on successs
|
|
|
|
* Return RTP_INVALID_VALUE if "frame" is nullptr */
|
2022-08-25 15:02:51 +00:00
|
|
|
rtp_error_t dealloc_frame(uvgrtp::frame::zrtp_frame* frame);
|
2022-02-28 06:46:04 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-19 01:13:43 +00:00
|
|
|
|
|
|
|
namespace uvg_rtp = uvgrtp;
|