2021-02-14 07:35:31 +00:00
|
|
|
/// \file util.hh
|
2020-02-13 05:47:51 +00:00
|
|
|
#pragma once
|
2019-03-30 09:51:30 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/// \cond DO_NOT_DOCUMENT
|
2019-07-15 06:28:35 +00:00
|
|
|
#ifdef _WIN32
|
2019-08-15 05:38:49 +00:00
|
|
|
#include <winsock2.h>
|
|
|
|
#include <windows.h>
|
2019-07-15 06:28:35 +00:00
|
|
|
#else
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <algorithm>
|
2019-03-30 09:51:30 +00:00
|
|
|
#include <cstdint>
|
2019-05-17 09:49:33 +00:00
|
|
|
#include <cstddef>
|
2019-06-14 08:34:10 +00:00
|
|
|
#include <cstdio>
|
2020-08-04 07:16:38 +00:00
|
|
|
#include <cstring>
|
2019-07-15 06:28:35 +00:00
|
|
|
#include <string>
|
2019-03-30 09:51:30 +00:00
|
|
|
|
2020-02-14 12:24:42 +00:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
typedef SSIZE_T ssize_t;
|
|
|
|
#endif
|
|
|
|
|
2020-10-01 07:12:01 +00:00
|
|
|
/* https://stackoverflow.com/questions/1537964/visual-c-equivalent-of-gccs-attribute-packed */
|
2021-08-27 08:35:23 +00:00
|
|
|
#if defined(__MINGW32__) || defined(__MINGW64__) || defined(__GNUC__) || defined(__linux__)
|
2020-10-01 07:12:01 +00:00
|
|
|
#define PACK(__Declaration__) __Declaration__ __attribute__((__packed__))
|
2019-07-15 08:49:24 +00:00
|
|
|
#else
|
2020-10-01 07:12:01 +00:00
|
|
|
#define PACK(__Declaration__) __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop))
|
2019-06-17 09:01:23 +00:00
|
|
|
#endif
|
|
|
|
|
2020-01-17 11:41:52 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
typedef SOCKET socket_t;
|
|
|
|
#else
|
|
|
|
typedef int socket_t;
|
|
|
|
#endif
|
|
|
|
|
2021-02-13 02:33:03 +00:00
|
|
|
const int MAX_PACKET = 65536;
|
|
|
|
const int MAX_PAYLOAD = 1446;
|
|
|
|
const int PKT_MAX_DELAY = 100;
|
|
|
|
|
|
|
|
/* TODO: add ability for user to specify these? */
|
|
|
|
enum HEADER_SIZES {
|
|
|
|
ETH_HDR_SIZE = 14,
|
|
|
|
IPV4_HDR_SIZE = 20,
|
|
|
|
UDP_HDR_SIZE = 8,
|
|
|
|
RTP_HDR_SIZE = 12
|
|
|
|
};
|
2021-02-14 07:35:31 +00:00
|
|
|
/// \endcond
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \enum RTP_ERROR
|
|
|
|
*
|
|
|
|
* \brief RTP error codes
|
|
|
|
*
|
|
|
|
* \details These error valus are returned from various uvgRTP functions. Functions that return a pointer set rtp_errno global value that should be checked if a function call failed
|
|
|
|
*/
|
2019-05-22 06:39:16 +00:00
|
|
|
typedef enum RTP_ERROR {
|
2021-02-14 07:35:31 +00:00
|
|
|
RTP_MULTIPLE_PKTS_READY = 6,
|
|
|
|
RTP_PKT_READY = 5,
|
|
|
|
RTP_PKT_MODIFIED = 4,
|
|
|
|
RTP_PKT_NOT_HANDLED = 3,
|
2020-10-07 10:23:08 +00:00
|
|
|
RTP_INTERRUPTED = 2,
|
|
|
|
RTP_NOT_READY = 1,
|
2021-02-14 07:35:31 +00:00
|
|
|
RTP_OK = 0, ///< Success
|
|
|
|
RTP_GENERIC_ERROR = -1, ///< Generic error condition
|
|
|
|
RTP_SOCKET_ERROR = -2, ///< Failed to create socket
|
|
|
|
RTP_BIND_ERROR = -3, ///< Failed to bind to interface
|
|
|
|
RTP_INVALID_VALUE = -4, ///< Invalid value
|
|
|
|
RTP_SEND_ERROR = -5, ///< System call send(2) or one of its derivatives failed
|
|
|
|
RTP_MEMORY_ERROR = -6, ///< Memory allocation failed
|
|
|
|
RTP_SSRC_COLLISION = -7, ///< SSRC collision detected
|
|
|
|
RTP_INITIALIZED = -8, ///< Object already initialized
|
|
|
|
RTP_NOT_INITIALIZED = -9, ///< Object has not been initialized
|
|
|
|
RTP_NOT_SUPPORTED = -10, ///< Method/version/extension not supported
|
|
|
|
RTP_RECV_ERROR = -11, ///< System call recv(2) or one of its derivatives failed
|
|
|
|
RTP_TIMEOUT = -12, ///< Operation timed out
|
|
|
|
RTP_NOT_FOUND = -13, ///< Object not found
|
|
|
|
RTP_AUTH_TAG_MISMATCH = -14, ///< Authentication tag does not match the RTP packet contents
|
2019-05-22 06:39:16 +00:00
|
|
|
} rtp_error_t;
|
2019-03-30 09:51:30 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/**
|
|
|
|
* \enum RTP_FORMAT
|
|
|
|
*
|
2021-02-19 01:13:43 +00:00
|
|
|
* \brief These flags are given to uvgrtp::session::create_stream()
|
2021-02-14 07:35:31 +00:00
|
|
|
*/
|
2019-03-30 09:51:30 +00:00
|
|
|
typedef enum RTP_FORMAT {
|
2021-02-14 07:35:31 +00:00
|
|
|
RTP_FORMAT_GENERIC = 0, ///< Generic format
|
|
|
|
RTP_FORMAT_H264 = 95, ///< H.264/AVC
|
|
|
|
RTP_FORMAT_H265 = 96, ///< H.265/HEVC
|
|
|
|
RTP_FORMAT_H266 = 97, ///< H.266/VVC
|
|
|
|
RTP_FORMAT_OPUS = 98, ///< Opus
|
2019-03-30 09:51:30 +00:00
|
|
|
} rtp_format_t;
|
2019-06-03 08:53:27 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/**
|
|
|
|
* \enum RTP_FLAGS
|
|
|
|
*
|
2021-02-19 01:13:43 +00:00
|
|
|
* \brief These flags are given to uvgrtp::media_stream::push_frame()
|
2021-02-14 07:35:31 +00:00
|
|
|
* and they can be OR'ed together
|
|
|
|
*/
|
Add support for HEVC slices
The API didn't change much, if user wishes to use HEVC slices
(and thus preserve the state between push_frame() calls), he must
call the push_frame() with RTP_SLICE and RTP_MORE flags, like this:
push_frame(conn, data, 123, RTP_SLICE | RTP_MORE);
push_frame(conn, data, 456, RTP_SLICE | RTP_MORE);
push_frame(conn, data, 789, RTP_SLICE | RTP_MORE);
push_frame(conn, data, 100, RTP_SLICE);
RTP_MORE preserves the state between push_frame() calls and when the
last slice is given to kvzRTP, the RTP_MORE flags must be removed.
This flushes the frame queue and deinitializes it.
2019-09-24 05:54:09 +00:00
|
|
|
typedef enum RTP_FLAGS {
|
2021-02-14 07:35:31 +00:00
|
|
|
/** No flags */
|
Add support for HEVC slices
The API didn't change much, if user wishes to use HEVC slices
(and thus preserve the state between push_frame() calls), he must
call the push_frame() with RTP_SLICE and RTP_MORE flags, like this:
push_frame(conn, data, 123, RTP_SLICE | RTP_MORE);
push_frame(conn, data, 456, RTP_SLICE | RTP_MORE);
push_frame(conn, data, 789, RTP_SLICE | RTP_MORE);
push_frame(conn, data, 100, RTP_SLICE);
RTP_MORE preserves the state between push_frame() calls and when the
last slice is given to kvzRTP, the RTP_MORE flags must be removed.
This flushes the frame queue and deinitializes it.
2019-09-24 05:54:09 +00:00
|
|
|
RTP_NO_FLAGS = 0 << 0,
|
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Treat the incoming frame as an H26X slice unit and do not perform start code lookup on it */
|
Add support for HEVC slices
The API didn't change much, if user wishes to use HEVC slices
(and thus preserve the state between push_frame() calls), he must
call the push_frame() with RTP_SLICE and RTP_MORE flags, like this:
push_frame(conn, data, 123, RTP_SLICE | RTP_MORE);
push_frame(conn, data, 456, RTP_SLICE | RTP_MORE);
push_frame(conn, data, 789, RTP_SLICE | RTP_MORE);
push_frame(conn, data, 100, RTP_SLICE);
RTP_MORE preserves the state between push_frame() calls and when the
last slice is given to kvzRTP, the RTP_MORE flags must be removed.
This flushes the frame queue and deinitializes it.
2019-09-24 05:54:09 +00:00
|
|
|
RTP_SLICE = 1 << 0,
|
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Make a copy of the data given to push_frame() and operate on that */
|
|
|
|
RTP_COPY = 1 << 1
|
2019-10-11 07:17:49 +00:00
|
|
|
|
Add support for HEVC slices
The API didn't change much, if user wishes to use HEVC slices
(and thus preserve the state between push_frame() calls), he must
call the push_frame() with RTP_SLICE and RTP_MORE flags, like this:
push_frame(conn, data, 123, RTP_SLICE | RTP_MORE);
push_frame(conn, data, 456, RTP_SLICE | RTP_MORE);
push_frame(conn, data, 789, RTP_SLICE | RTP_MORE);
push_frame(conn, data, 100, RTP_SLICE);
RTP_MORE preserves the state between push_frame() calls and when the
last slice is given to kvzRTP, the RTP_MORE flags must be removed.
This flushes the frame queue and deinitializes it.
2019-09-24 05:54:09 +00:00
|
|
|
} rtp_flags_t;
|
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/**
|
|
|
|
* \enum RTP_CTX_ENABLE_FLAGS
|
|
|
|
*
|
|
|
|
* \brief RTP context enable flags
|
|
|
|
*
|
2021-02-19 01:13:43 +00:00
|
|
|
* \details These flags are passed to uvgrtp::session::create_stream and can be OR'ed together
|
2021-02-14 07:35:31 +00:00
|
|
|
*/
|
2020-01-13 08:00:02 +00:00
|
|
|
enum RTP_CTX_ENABLE_FLAGS {
|
2021-02-14 07:35:31 +00:00
|
|
|
RCE_NO_FLAGS = 0 << 0,
|
2020-01-08 08:55:00 +00:00
|
|
|
|
2022-03-03 06:57:49 +00:00
|
|
|
/* Obsolete */
|
2020-05-28 09:24:18 +00:00
|
|
|
RCE_SYSTEM_CALL_DISPATCHER = 1 << 2,
|
2020-01-08 08:55:00 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Use SRTP for this connection */
|
2020-05-28 09:24:18 +00:00
|
|
|
RCE_SRTP = 1 << 3,
|
2020-01-22 08:57:40 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Use ZRTP for key management
|
2020-01-22 08:57:40 +00:00
|
|
|
*
|
2020-07-30 06:41:01 +00:00
|
|
|
* If this flag is provided, before the session starts,
|
|
|
|
* ZRTP will negotiate keys with the remote participants
|
|
|
|
* and these keys are used as salting/keying material for the session.
|
|
|
|
*
|
|
|
|
* This flag must be coupled with RCE_SRTP and is mutually exclusive
|
|
|
|
* with RCE_SRTP_KMNGMNT_USER. */
|
2020-05-28 09:24:18 +00:00
|
|
|
RCE_SRTP_KMNGMNT_ZRTP = 1 << 4,
|
2020-01-22 08:57:40 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Use user-defined way to manage keys
|
2020-01-22 08:57:40 +00:00
|
|
|
*
|
2020-07-30 06:41:01 +00:00
|
|
|
* If this flag is provided, before the media transportation starts,
|
|
|
|
* user must provide a master key and salt form which SRTP session
|
|
|
|
* keys are derived
|
|
|
|
*
|
|
|
|
* This flag must be coupled with RCE_SRTP and is mutually exclusive
|
|
|
|
* with RCE_SRTP_KMNGMNT_ZRTP */
|
2020-05-28 09:24:18 +00:00
|
|
|
RCE_SRTP_KMNGMNT_USER = 1 << 5,
|
2020-01-22 08:57:40 +00:00
|
|
|
|
2021-02-19 13:18:49 +00:00
|
|
|
/** When uvgRTP is receiving H26X stream, as an attempt to improve
|
2020-04-21 13:10:49 +00:00
|
|
|
* QoS, it will set frame delay for intra frames to be the same
|
|
|
|
* as intra period.
|
|
|
|
*
|
|
|
|
* What this means is that if the regular timer expires for frame
|
2020-04-27 11:07:24 +00:00
|
|
|
* (100 ms) and the frame type is intra, uvgRTP will not drop the
|
2020-04-21 13:10:49 +00:00
|
|
|
* frame but will continue receiving packets in hopes that all the
|
|
|
|
* packets of the intra frame will be received and the frame can be
|
|
|
|
* returned to user. During this period, when the intra frame is deemed
|
2020-04-27 11:07:24 +00:00
|
|
|
* to be late and incomplete, uvgRTP will drop all inter frames until
|
2020-04-21 13:10:49 +00:00
|
|
|
* a) all the packets of late intra frame are received or
|
|
|
|
* b) a new intra frame is received
|
|
|
|
*
|
|
|
|
* This behaviour should reduce the number of gray screens during
|
2021-02-19 13:18:49 +00:00
|
|
|
* video decoding but might cause the video stream to freeze for a while
|
2020-04-21 13:10:49 +00:00
|
|
|
* which is subjectively lesser of two evils
|
|
|
|
*
|
2021-02-19 13:18:49 +00:00
|
|
|
* This behavior can be disabled with RCE_NO_H26X_INTRA_DELAY
|
2020-04-27 11:07:24 +00:00
|
|
|
* If this flag is given, uvgRTP treats all frame types
|
2020-04-21 13:10:49 +00:00
|
|
|
* equally and drops all frames that are late */
|
2021-02-19 13:18:49 +00:00
|
|
|
RCE_NO_H26X_INTRA_DELAY = 1 << 5,
|
2020-04-24 08:31:40 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Fragment generic frames into RTP packets of 1500 bytes.
|
2020-04-24 18:20:27 +00:00
|
|
|
*
|
2020-04-27 11:07:24 +00:00
|
|
|
* If RCE_FRAGMENT_GENERIC is given to create_stream(), uvgRTP will split frames
|
2020-04-24 18:20:27 +00:00
|
|
|
* of type RTP_FORMAT_GENERIC into packets of 1500 bytes automatically and reconstruct
|
|
|
|
* the full frame from the fragments in the receiver
|
|
|
|
*
|
2020-04-27 11:07:24 +00:00
|
|
|
* This behavior is not from any specification and only supported by uvgRTP so it
|
2020-04-24 18:20:27 +00:00
|
|
|
* will break interoperability between libraries if enabled.
|
|
|
|
*
|
2020-04-27 11:07:24 +00:00
|
|
|
* RCE_FRAGMENT_GENERIC can be used, for example, when you're using uvgRTP for
|
2020-04-24 18:20:27 +00:00
|
|
|
* both sender and receiver and the media stream you wish to stream is not supported
|
2020-04-27 11:07:24 +00:00
|
|
|
* by uvgRTP but requires packetization because MEDIA_FRAME_SIZE > MTU */
|
2020-05-28 09:24:18 +00:00
|
|
|
RCE_FRAGMENT_GENERIC = 1 << 6,
|
2020-04-24 18:20:27 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** If SRTP is enabled and RCE_INPLACE_ENCRYPTION flag is *not* given,
|
2020-04-27 11:07:24 +00:00
|
|
|
* uvgRTP will make a copy of the frame given to push_frame().
|
2020-04-27 09:16:53 +00:00
|
|
|
*
|
|
|
|
* If the frame is writable and the application no longer needs the frame,
|
|
|
|
* RCE_INPLACE_ENCRYPTION should be given to create_stream() to prevent
|
|
|
|
* unnecessary copy operations.
|
|
|
|
*
|
|
|
|
* If RCE_INPLACE_ENCRYPTION is given to push_frame(), the input pointer must be writable! */
|
2020-09-02 09:12:28 +00:00
|
|
|
RCE_SRTP_INPLACE_ENCRYPTION = 1 << 7,
|
2020-04-27 09:16:53 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Disable System Call Clustering (SCC) */
|
2020-05-28 09:24:18 +00:00
|
|
|
RCE_NO_SYSTEM_CALL_CLUSTERING = 1 << 8,
|
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Disable RTP payload encryption */
|
2020-10-08 01:02:21 +00:00
|
|
|
RCE_SRTP_NULL_CIPHER = 1 << 9,
|
2020-07-30 08:47:11 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Enable RTP packet authentication
|
2020-07-31 06:56:06 +00:00
|
|
|
*
|
|
|
|
* This flag forces the security layer to add authentication tag
|
|
|
|
* to each outgoing RTP packet for all streams that have SRTP enabled.
|
|
|
|
*
|
|
|
|
* NOTE: this flag must be coupled with at least RCE_SRTP */
|
2020-10-08 01:02:21 +00:00
|
|
|
RCE_SRTP_AUTHENTICATE_RTP = 1 << 10,
|
2020-07-31 06:56:06 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Enable packet replay protection */
|
2020-10-08 01:02:21 +00:00
|
|
|
RCE_SRTP_REPLAY_PROTECTION = 1 << 11,
|
2020-09-04 06:03:28 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Enable RTCP for the media stream.
|
2020-08-06 03:12:34 +00:00
|
|
|
* If SRTP is enabled, SRTCP is used instead */
|
2020-10-08 01:02:21 +00:00
|
|
|
RCE_RTCP = 1 << 12,
|
2020-08-06 03:12:34 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Prepend a 4-byte start code (0x00000001) to HEVC each frame */
|
2021-02-11 08:56:03 +00:00
|
|
|
RCE_H26X_PREPEND_SC = 1 << 13,
|
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** If the Mediastream object is used as a unidirectional stream
|
2021-02-14 01:36:27 +00:00
|
|
|
* but holepunching has been enabled, this flag can be used to make
|
|
|
|
* uvgRTP periodically send a short UDP datagram to keep the hole
|
|
|
|
* in the firewall open */
|
|
|
|
RCE_HOLEPUNCH_KEEPALIVE = 1 << 14,
|
|
|
|
|
2021-04-22 09:39:07 +00:00
|
|
|
/** Use 192-bit keys with SRTP */
|
|
|
|
RCE_SRTP_KEYSIZE_192 = 1 << 15,
|
|
|
|
|
|
|
|
/** Use 256-bit keys with SRTP */
|
|
|
|
RCE_SRTP_KEYSIZE_256 = 1 << 16,
|
|
|
|
|
|
|
|
RCE_LAST = 1 << 17,
|
2020-04-21 13:10:49 +00:00
|
|
|
};
|
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/**
|
|
|
|
* \enum RTP_CTX_CONFIGURATION_FLAGS
|
|
|
|
*
|
|
|
|
* \brief RTP context configuration flags
|
|
|
|
*
|
2021-02-19 01:13:43 +00:00
|
|
|
* \details These flags are given to uvgrtp::media_stream::configure_ctx
|
2021-02-14 07:35:31 +00:00
|
|
|
*/
|
2020-01-13 08:00:02 +00:00
|
|
|
enum RTP_CTX_CONFIGURATION_FLAGS {
|
2020-04-28 05:56:03 +00:00
|
|
|
RCC_NO_FLAGS = 0,
|
2020-01-08 08:55:00 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** How large is the receiver UDP buffer size
|
2020-01-08 08:55:00 +00:00
|
|
|
*
|
|
|
|
* Default value is 4 MB
|
|
|
|
*
|
|
|
|
* For video with high bitrate, it is advisable to set this
|
|
|
|
* to a high number to prevent OS from dropping packets */
|
2020-04-28 05:56:03 +00:00
|
|
|
RCC_UDP_RCV_BUF_SIZE = 1,
|
2021-02-14 07:35:31 +00:00
|
|
|
|
|
|
|
/** How large is the sender UDP buffer size
|
|
|
|
*
|
|
|
|
* Default value is 4 MB
|
|
|
|
*
|
|
|
|
* For video with high bitrate, it is advisable to set this
|
|
|
|
* to a high number to prevent OS from dropping packets */
|
2020-04-28 05:56:03 +00:00
|
|
|
RCC_UDP_SND_BUF_SIZE = 2,
|
2020-01-08 08:55:00 +00:00
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** How many milliseconds is each frame waited until it's dropped
|
2021-02-12 12:05:35 +00:00
|
|
|
*
|
|
|
|
* Default is 100 milliseconds
|
|
|
|
*
|
|
|
|
* This is valid only for fragmented frames,
|
|
|
|
* i.e. RTP_FORMAT_H26X and RTP_FORMAT_GENERIC with RCE_FRAGMENT_GENERIC (TODO) */
|
|
|
|
RCC_PKT_MAX_DELAY = 3,
|
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Overwrite uvgRTP's own payload type in RTP packets and specify your own
|
2021-02-12 12:41:03 +00:00
|
|
|
* dynamic payload type for all packets of an RTP stream */
|
|
|
|
RCC_DYN_PAYLOAD_TYPE = 4,
|
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/** Set a maximum value for the Ethernet frame size assumed by uvgRTP.
|
2021-02-13 02:33:03 +00:00
|
|
|
*
|
|
|
|
* Default is 1500, from this Ethernet, IPv4 and UDP, and RTP headers
|
|
|
|
* are removed from this, giving a payload size of 1446 bytes
|
|
|
|
*
|
|
|
|
* If application wishes to use small UDP datagrams for some reason,
|
|
|
|
* it can set MTU size to, for example, 500 bytes or if it wishes
|
|
|
|
* to use jumbo frames, it can set the MTU size to 9000 bytes */
|
|
|
|
RCC_MTU_SIZE = 5,
|
|
|
|
|
2020-01-13 08:00:02 +00:00
|
|
|
RCC_LAST
|
2020-04-16 08:00:07 +00:00
|
|
|
};
|
|
|
|
|
2021-02-14 07:35:31 +00:00
|
|
|
/// \cond DO_NOT_DOCUMENT
|
2020-04-16 08:00:07 +00:00
|
|
|
enum NOTIFY_REASON {
|
|
|
|
|
|
|
|
/* Timer for the active frame has expired and it has been dropped */
|
|
|
|
NR_FRAME_DROPPED = 0,
|
2020-01-13 08:00:02 +00:00
|
|
|
};
|
2020-01-08 08:55:00 +00:00
|
|
|
|
|
|
|
/* see src/util.hh for more information */
|
|
|
|
typedef struct rtp_ctx_conf {
|
2021-06-03 07:38:49 +00:00
|
|
|
int flags = 0;
|
2020-01-13 08:00:02 +00:00
|
|
|
ssize_t ctx_values[RCC_LAST];
|
2020-01-08 08:55:00 +00:00
|
|
|
} rtp_ctx_conf_t;
|
|
|
|
|
2019-06-17 06:59:32 +00:00
|
|
|
extern thread_local rtp_error_t rtp_errno;
|
2019-06-03 08:53:27 +00:00
|
|
|
|
2020-07-28 07:35:21 +00:00
|
|
|
#define TIME_DIFF(s, e, u) ((ssize_t)std::chrono::duration_cast<std::chrono::u>(e - s).count())
|
|
|
|
|
2020-08-26 09:52:16 +00:00
|
|
|
#define SET_NEXT_FIELD_32(a, p, v) do { *(uint32_t *)&(a)[p] = (v); p += 4; } while (0)
|
2020-09-03 08:35:37 +00:00
|
|
|
#define SET_FIELD_32(a, i, v) do { *(uint32_t *)&(a)[i] = (v); } while (0)
|
2020-08-26 09:52:16 +00:00
|
|
|
|
2019-06-03 08:53:27 +00:00
|
|
|
static inline void hex_dump(uint8_t *buf, size_t len)
|
|
|
|
{
|
|
|
|
if (!buf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < len; i += 10) {
|
|
|
|
fprintf(stderr, "\t");
|
|
|
|
for (size_t k = i; k < i + 10; ++k) {
|
|
|
|
fprintf(stderr, "0x%02x ", buf[k]);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
}
|
2019-06-20 06:25:01 +00:00
|
|
|
|
|
|
|
static inline void set_bytes(int *ptr, int nbytes)
|
|
|
|
{
|
|
|
|
if (ptr)
|
|
|
|
*ptr = nbytes;
|
|
|
|
}
|
2019-06-26 04:52:07 +00:00
|
|
|
|
2020-08-04 07:16:38 +00:00
|
|
|
static inline void *memdup(const void *src, size_t len)
|
|
|
|
{
|
|
|
|
uint8_t *dst = new uint8_t[len];
|
|
|
|
std::memcpy(dst, src, len);
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2019-06-26 04:52:07 +00:00
|
|
|
static inline std::string generate_string(size_t length)
|
|
|
|
{
|
|
|
|
auto randchar = []() -> char
|
|
|
|
{
|
|
|
|
const char charset[] =
|
|
|
|
"0123456789"
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
"abcdefghijklmnopqrstuvwxyz";
|
|
|
|
const size_t max_index = (sizeof(charset) - 1);
|
|
|
|
return charset[ rand() % max_index ];
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string str(length, 0);
|
|
|
|
std::generate_n(str.begin(), length, randchar);
|
|
|
|
return str;
|
|
|
|
}
|
2021-02-14 07:35:31 +00:00
|
|
|
/// \endcond
|