2019-03-30 09:51:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
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>
|
2019-07-15 06:28:35 +00:00
|
|
|
#include <string>
|
2019-03-30 09:51:30 +00:00
|
|
|
|
2019-06-17 09:01:23 +00:00
|
|
|
|
2019-07-15 08:49:24 +00:00
|
|
|
#if defined(__MINGW32__) || defined(__MINGW64__) || defined(__linux__)
|
2019-06-17 09:01:23 +00:00
|
|
|
#define PACKED_STRUCT(name) \
|
|
|
|
struct __attribute__((packed)) name
|
2019-07-15 08:49:24 +00:00
|
|
|
#else
|
|
|
|
#warning "structures are not packed!"
|
|
|
|
#define PACKED_STRUCT(name) struct name
|
2019-06-17 09:01:23 +00:00
|
|
|
#endif
|
|
|
|
|
2019-05-17 08:08:40 +00:00
|
|
|
const int MAX_PACKET = 65536;
|
2019-09-06 09:47:26 +00:00
|
|
|
const int MAX_PAYLOAD = 1441;
|
2019-05-17 09:49:33 +00:00
|
|
|
|
2019-05-22 06:39:16 +00:00
|
|
|
typedef enum RTP_ERROR {
|
2019-08-14 07:21:33 +00:00
|
|
|
RTP_INTERRUPTED = 2,
|
|
|
|
RTP_NOT_READY = 1,
|
|
|
|
RTP_OK = 0,
|
|
|
|
RTP_GENERIC_ERROR = -1,
|
|
|
|
RTP_SOCKET_ERROR = -2,
|
|
|
|
RTP_BIND_ERROR = -3,
|
|
|
|
RTP_INVALID_VALUE = -4,
|
|
|
|
RTP_SEND_ERROR = -5,
|
|
|
|
RTP_MEMORY_ERROR = -6,
|
|
|
|
RTP_SSRC_COLLISION = -7,
|
2019-05-22 06:39:16 +00:00
|
|
|
} rtp_error_t;
|
2019-03-30 09:51:30 +00:00
|
|
|
|
|
|
|
typedef enum RTP_FORMAT {
|
|
|
|
RTP_FORMAT_GENERIC = 0,
|
|
|
|
RTP_FORMAT_HEVC = 96,
|
|
|
|
RTP_FORMAT_OPUS = 97,
|
|
|
|
} rtp_format_t;
|
2019-06-03 08:53:27 +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
|
|
|
typedef enum RTP_FLAGS {
|
|
|
|
RTP_NO_FLAGS = 0 << 0,
|
|
|
|
|
|
|
|
/* TODO */
|
|
|
|
RTP_SLICE = 1 << 0,
|
|
|
|
|
|
|
|
/* TODO */
|
|
|
|
RTP_MORE = 1 << 1,
|
|
|
|
} rtp_flags_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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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;
|
|
|
|
}
|