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
2022-09-07 12:03:16 +00:00
/* https://stackoverflow.com/questions/1537964/visual-c-equivalent-of-gccs-attribute-packed */
# if defined(__MINGW32__) || defined(__MINGW64__) || defined(__GNUC__) || defined(__linux__)
# define PACK(__Declaration__) __Declaration__ __attribute__((__packed__))
# else
# define PACK(__Declaration__) __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop))
# endif
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 {
2023-07-31 12:02:11 +00:00
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 */
RTCP_FT_RTPFB = 205 , /* Transport layer FB message */
RTCP_FT_PSFB = 206 /* Payload-specific FB message */
2020-01-17 08:18:11 +00:00
} ;
2019-06-17 08:56:21 +00:00
2023-08-01 05:19:49 +00:00
enum RTCP_PSFB_FMT {
RTCP_PSFB_PLI = 1 , /* Picture Loss Indication (PLI), defined in RFC 4585 */
RTCP_PSFB_SLI = 2 , /* Slice Loss Indication (SLI), defined in RFC 4585 */
RTCP_PSFB_RPSI = 3 , /* Reference Picture Selection Indication (RPSI), defined in RFC 4585 */
RTCP_PSFB_FIR = 4 , /* Full Intra Request (FIR), defined in RFC 5154 */
RTCP_PSFB_TSTR = 5 , /* Temporal-Spatial Trade-off Request (TSTR), defined in RFC 5154 */
RTCP_PSFB_AFB = 15 /* Application Layer FB (AFB), defined in RFC 4585 */
} ;
enum RTCP_RTPFB_FMT {
RTCP_RTPFB_NACK = 1 /* Generic NACK, defined in RFC 4585 section 6.2 */
} ;
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
2022-09-15 04:53:59 +00:00
/** \brief See <a href="https://www.rfc-editor.org/rfc/rfc3550#section-5" target="_blank">RFC 3550 section 5</a> */
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 */
2019-05-22 06:24:29 +00:00
2022-09-15 04:53:59 +00:00
/** \brief Length of the packet payload in bytes added by uvgRTP to help process the frame
*
* \ details payload_len = total length - header length - padding length ( if padded )
*/
2022-09-15 04:27:51 +00:00
size_t payload_len = 0 ;
uint8_t * payload = nullptr ;
2020-09-03 05:28:24 +00:00
2022-09-15 04:53:59 +00:00
/// \cond DO_NOT_DOCUMENT
2022-09-15 04:27:51 +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 */
2022-09-15 04:53:59 +00:00
/// \endcond
2019-06-17 08:56:21 +00:00
} ;
2022-09-15 04:53:59 +00:00
/** \brief Header of for all RTCP packets defined in <a href="https://www.rfc-editor.org/rfc/rfc3550#section-6" target="_blank">RFC 3550 section 6</a> */
2020-08-26 12:53:41 +00:00
struct rtcp_header {
2022-09-15 04:53:59 +00:00
/** \brief This field identifies the version of RTP. The version defined by
* RFC 3550 is two ( 2 ) . */
2021-06-03 07:38:49 +00:00
uint8_t version = 0 ;
2022-09-15 04:53:59 +00:00
/** \brief Does this packet contain padding at the end */
2021-06-03 07:38:49 +00:00
uint8_t padding = 0 ;
2020-08-26 12:32:51 +00:00
union {
2022-09-15 04:53:59 +00:00
/** \brief Source count or report count. Alternative to pkt_subtype. */
uint8_t count = 0 ;
/** \brief Subtype in APP packets. Alternative to count */
uint8_t pkt_subtype ;
2023-07-31 12:07:55 +00:00
/** \brief Feedback message type (FMT), specified in RFC 5104 section 4.3. Alternative to count and pkt_subtype */
uint8_t fmt ;
2020-08-26 12:32:51 +00:00
} ;
2022-09-15 04:53:59 +00:00
/** \brief Identifies the RTCP packet type */
2021-06-03 07:38:49 +00:00
uint8_t pkt_type = 0 ;
2022-09-15 04:53:59 +00:00
/** \brief Length of the whole message measured in 32-bit words */
uint16_t length = 0 ;
2019-06-17 08:56:21 +00:00
} ;
2022-09-15 04:53:59 +00:00
/** \brief See <a href="https://www.rfc-editor.org/rfc/rfc3550#section-6.4.1" target="_blank">RFC 3550 section 6.4.1</a> */
2020-08-26 12:53:41 +00:00
struct rtcp_sender_info {
2022-09-15 04:53:59 +00:00
/** \brief NTP timestamp, most significant word */
uint32_t ntp_msw = 0 ;
/** \brief NTP timestamp, least significant word */
uint32_t ntp_lsw = 0 ;
/** \brief RTP timestamp corresponding to this NTP timestamp */
uint32_t rtp_ts = 0 ;
2021-06-03 07:38:49 +00:00
uint32_t pkt_cnt = 0 ;
2022-09-15 04:53:59 +00:00
/** \brief Also known as octet count*/
2021-06-03 07:38:49 +00:00
uint32_t byte_cnt = 0 ;
2019-06-17 08:56:21 +00:00
} ;
2022-09-15 04:53:59 +00:00
/** \brief See <a href="https://www.rfc-editor.org/rfc/rfc3550#section-6.4.1" target="_blank">RFC 3550 section 6.4.1</a> */
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
} ;
2022-09-15 04:53:59 +00:00
/** \brief See <a href="https://www.rfc-editor.org/rfc/rfc3550#section-6.4.2" target="_blank">RFC 3550 section 6.4.2</a> */
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 ;
} ;
2022-09-15 04:53:59 +00:00
/** \brief See <a href="https://www.rfc-editor.org/rfc/rfc3550#section-6.4.1" target="_blank">RFC 3550 section 6.4.1</a> */
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 ;
} ;
2022-09-15 04:53:59 +00:00
/** \brief See <a href="https://www.rfc-editor.org/rfc/rfc3550#section-6.5" target="_blank">RFC 3550 section 6.5</a> */
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-09-15 04:53:59 +00:00
/** \brief See <a href="https://www.rfc-editor.org/rfc/rfc3550#section-6.5" target="_blank">RFC 3550 section 6.5</a> */
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-09-15 04:53:59 +00:00
/** \brief See <a href="https://www.rfc-editor.org/rfc/rfc3550#section-6.5" target="_blank">RFC 3550 section 6.5</a> */
2022-07-09 14:41:54 +00:00
struct rtcp_sdes_packet {
struct rtcp_header header ;
std : : vector < rtcp_sdes_chunk > chunks ;
} ;
2022-09-15 04:53:59 +00:00
/** \brief See <a href="https://www.rfc-editor.org/rfc/rfc3550#section-6.7" target="_blank">RFC 3550 section 6.7</a> */
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-15 04:53:59 +00:00
/** \brief Size of the payload in bytes. Added by uvgRTP to help process the payload. */
size_t payload_len = 0 ;
2020-08-26 12:32:51 +00:00
} ;
2023-08-01 06:20:48 +00:00
/** \brief Full Intra Request, See RFC 5104 section 4.3.1 */
struct rtcp_fir {
uint32_t ssrc = 0 ;
uint8_t seq = 0 ;
} ;
/** \brief Slice Loss Indication, See RFC 4585 section 6.3.2 */
struct rtcp_sli {
uint16_t first = 0 ;
uint16_t num = 0 ;
uint8_t picture_id = 0 ;
} ;
/** \brief Reference Picture Selection Indication, See RFC 4585 section 6.3.3 */
struct rtcp_rpsi {
uint8_t pb = 0 ;
uint8_t pt = 0 ;
uint8_t * str = nullptr ;
} ;
/** \brief RTCP Feedback Control Information, See RFC 4585 section 6.1 */
struct rtcp_fb_fci {
union {
rtcp_fir fir ;
rtcp_sli sli ;
rtcp_rpsi rpsi ;
} ;
} ;
2023-07-31 12:56:06 +00:00
/** \brief Feedback message. See RFC 4585 section 6.1 */
2023-07-31 12:07:55 +00:00
struct rtcp_fb_packet {
struct rtcp_header header ;
uint32_t sender_ssrc = 0 ;
uint32_t media_ssrc = 0 ;
2023-08-01 06:20:48 +00:00
std : : vector < rtcp_fb_fci > items ;
2023-07-31 12:41:46 +00:00
/** \brief Size of the payload in bytes. Added by uvgRTP to help process the payload. */
size_t payload_len = 0 ;
2023-07-31 12:07:55 +00:00
} ;
2020-08-26 12:32:51 +00:00
2023-08-01 05:59:09 +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 ) ;
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 ;