common: Remove unnecessary stuff from util.hh
This commit is contained in:
parent
5d797b0146
commit
e06fc3c46c
|
@ -89,6 +89,7 @@ target_sources(${PROJECT_NAME} PRIVATE
|
|||
src/socket.hh
|
||||
src/zrtp.hh
|
||||
src/frame_queue.hh
|
||||
src/memory.hh
|
||||
|
||||
src/formats/h26x.hh
|
||||
src/formats/h264.hh
|
||||
|
|
|
@ -13,6 +13,13 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/* 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
|
||||
|
||||
namespace uvgrtp {
|
||||
namespace frame {
|
||||
|
||||
|
|
|
@ -9,35 +9,12 @@
|
|||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
typedef SSIZE_T ssize_t;
|
||||
#endif
|
||||
|
||||
/* 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
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef SOCKET socket_t;
|
||||
#else
|
||||
typedef int socket_t;
|
||||
#endif
|
||||
|
||||
const int MAX_PACKET = 65536;
|
||||
const int MAX_PAYLOAD = 1446;
|
||||
const int PKT_MAX_DELAY = 500;
|
||||
|
||||
/* TODO: add ability for user to specify these? */
|
||||
const int PKT_MAX_DELAY_MS = 500;
|
||||
|
||||
// TODO: IPv6 size is 40
|
||||
enum HEADER_SIZES {
|
||||
|
@ -368,54 +345,4 @@ enum RTP_CTX_CONFIGURATION_FLAGS {
|
|||
};
|
||||
|
||||
extern thread_local rtp_error_t rtp_errno;
|
||||
|
||||
#define TIME_DIFF(s, e, u) ((ssize_t)std::chrono::duration_cast<std::chrono::u>(e - s).count())
|
||||
|
||||
#define SET_NEXT_FIELD_32(a, p, v) do { *(uint32_t *)&(a)[p] = (v); p += 4; } while (0)
|
||||
#define SET_FIELD_32(a, i, v) do { *(uint32_t *)&(a)[i] = (v); } while (0)
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
static inline void set_bytes(int *ptr, int nbytes)
|
||||
{
|
||||
if (ptr)
|
||||
*ptr = nbytes;
|
||||
}
|
||||
|
||||
static inline void *memdup(const void *src, size_t len)
|
||||
{
|
||||
uint8_t *dst = new uint8_t[len];
|
||||
std::memcpy(dst, src, len);
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
/// \endcond
|
||||
|
|
|
@ -11,9 +11,27 @@
|
|||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
thread_local rtp_error_t rtp_errno;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
uvgrtp::context::context()
|
||||
{
|
||||
UVG_LOG_INFO("uvgRTP version: %s", uvgrtp::get_version().c_str());
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
static inline void set_bytes(int* ptr, int nbytes)
|
||||
{
|
||||
if (ptr)
|
||||
* ptr = nbytes;
|
||||
}
|
||||
|
||||
static inline void* memdup(const void* src, size_t len)
|
||||
{
|
||||
uint8_t* dst = new uint8_t[len];
|
||||
std::memcpy(dst, src, len);
|
||||
|
||||
return dst;
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "socket.hh"
|
||||
#include "debug.hh"
|
||||
#include "memory.hh"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include "uvgrtp/util.hh"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace uvgrtp {
|
||||
namespace random {
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ const uint32_t MIN_SEQUENTIAL = 2;
|
|||
const uint32_t MAX_DROPOUT = 3000;
|
||||
const uint32_t MAX_MISORDER = 100;
|
||||
const uint32_t DEFAULT_RTCP_INTERVAL_MS = 5000;
|
||||
const int MAX_PACKET = 65536;
|
||||
|
||||
constexpr int ESTIMATED_MAX_RECEPTION_TIME_MS = 10;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "debug.hh"
|
||||
|
||||
#define SET_NEXT_FIELD_32(a, p, v) do { *(uint32_t *)&(a)[p] = (v); p += 4; } while (0)
|
||||
|
||||
uint32_t uvgrtp::get_sr_packet_size(int rce_flags, uint16_t reports)
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "debug.hh"
|
||||
#include "random.hh"
|
||||
#include "memory.hh"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <arpa/inet.h>
|
||||
|
@ -20,7 +21,7 @@ uvgrtp::rtp::rtp(rtp_format_t fmt):
|
|||
wc_start_(),
|
||||
sent_pkts_(0),
|
||||
timestamp_(INVALID_TS),
|
||||
delay_(PKT_MAX_DELAY)
|
||||
delay_(PKT_MAX_DELAY_MS)
|
||||
{
|
||||
seq_ = uvgrtp::random::generate_32() & 0xffff;
|
||||
ts_ = uvgrtp::random::generate_32();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "uvgrtp/util.hh"
|
||||
|
||||
#include "debug.hh"
|
||||
#include "memory.hh"
|
||||
|
||||
#include <thread>
|
||||
|
||||
|
|
|
@ -15,6 +15,11 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef SOCKET socket_t;
|
||||
#else
|
||||
typedef int socket_t;
|
||||
#endif
|
||||
|
||||
namespace uvgrtp {
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#define SET_FIELD_32(a, i, v) do { *(uint32_t *)&(a)[i] = (v); } while (0)
|
||||
|
||||
uvgrtp::srtcp::srtcp()
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "uvgrtp/util.hh"
|
||||
#include "uvgrtp/frame.hh"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
|
Loading…
Reference in New Issue