Socket library and Config library restructuring, improvement to UDP socket reliability
This commit is contained in:
parent
97752f2c2d
commit
3d26741148
37 changed files with 151 additions and 110 deletions
|
@ -1,5 +1,7 @@
|
||||||
#include "certificate.h"
|
#include "certificate.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
Certificate::Certificate() : rsa_ctx(NULL){
|
Certificate::Certificate() : rsa_ctx(NULL){
|
||||||
memset((void *)&cert, 0x00, sizeof(cert));
|
memset((void *)&cert, 0x00, sizeof(cert));
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include "encode.h"
|
#include "encode.h"
|
||||||
#include "procs.h"
|
#include "procs.h"
|
||||||
#include "timing.h"
|
#include "timing.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
namespace Comms{
|
namespace Comms{
|
||||||
Comms::Comms(){
|
Comms::Comms(){
|
||||||
|
|
|
@ -38,8 +38,8 @@
|
||||||
bool Util::Config::is_active = false;
|
bool Util::Config::is_active = false;
|
||||||
bool Util::Config::is_restarting = false;
|
bool Util::Config::is_restarting = false;
|
||||||
static Socket::Server *serv_sock_pointer = 0;
|
static Socket::Server *serv_sock_pointer = 0;
|
||||||
uint32_t Util::Config::printDebugLevel = DEBUG; //
|
uint32_t Util::printDebugLevel = DEBUG;
|
||||||
std::string Util::Config::streamName;
|
std::string Util::streamName;
|
||||||
char Util::exitReason[256] = {0};
|
char Util::exitReason[256] = {0};
|
||||||
|
|
||||||
void Util::logExitReason(const char *format, ...){
|
void Util::logExitReason(const char *format, ...){
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
/// Contains utility code, not directly related to streaming media
|
/// Contains utility code, not directly related to streaming media
|
||||||
namespace Util{
|
namespace Util{
|
||||||
|
extern uint32_t printDebugLevel;
|
||||||
|
extern std::string streamName; ///< Used by debug messages to identify the stream name
|
||||||
extern char exitReason[256];
|
extern char exitReason[256];
|
||||||
void logExitReason(const char * format, ...);
|
void logExitReason(const char * format, ...);
|
||||||
|
|
||||||
|
@ -27,8 +29,6 @@ namespace Util{
|
||||||
// variables
|
// variables
|
||||||
static bool is_active; ///< Set to true by activate(), set to false by the signal handler.
|
static bool is_active; ///< Set to true by activate(), set to false by the signal handler.
|
||||||
static bool is_restarting; ///< Set to true when restarting, set to false on boot.
|
static bool is_restarting; ///< Set to true when restarting, set to false on boot.
|
||||||
static uint32_t printDebugLevel;
|
|
||||||
static std::string streamName; ///< Used by debug messages to identify the stream name
|
|
||||||
// functions
|
// functions
|
||||||
Config();
|
Config();
|
||||||
Config(std::string cmd);
|
Config(std::string cmd);
|
||||||
|
|
|
@ -23,11 +23,18 @@
|
||||||
|
|
||||||
#define APPIDENT APPNAME "/" PACKAGE_VERSION
|
#define APPIDENT APPNAME "/" PACKAGE_VERSION
|
||||||
#define __STDC_FORMAT_MACROS 1
|
#define __STDC_FORMAT_MACROS 1
|
||||||
#include "config.h"
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
//Declare as extern so we don't have to include the whole config.h header
|
||||||
|
namespace Util{
|
||||||
|
extern uint32_t printDebugLevel;
|
||||||
|
extern std::string streamName;
|
||||||
|
}
|
||||||
|
|
||||||
static const char *DBG_LVL_LIST[] ={"NONE", "FAIL", "ERROR", "WARN", "INFO", "MEDIUM",
|
static const char *DBG_LVL_LIST[] ={"NONE", "FAIL", "ERROR", "WARN", "INFO", "MEDIUM",
|
||||||
"HIGH", "VERYHIGH", "EXTREME", "INSANE", "DONTEVEN"};
|
"HIGH", "VERYHIGH", "EXTREME", "INSANE", "DONTEVEN"};
|
||||||
|
|
||||||
|
@ -44,29 +51,29 @@ static const char *DBG_LVL_LIST[] ={"NONE", "FAIL", "ERROR", "WARN", "IN
|
||||||
|
|
||||||
#if DEBUG >= DLVL_DEVEL
|
#if DEBUG >= DLVL_DEVEL
|
||||||
#define DEBUG_MSG(lvl, msg, ...) \
|
#define DEBUG_MSG(lvl, msg, ...) \
|
||||||
if (Util::Config::printDebugLevel >= lvl){\
|
if (Util::printDebugLevel >= lvl){\
|
||||||
fprintf(stderr, "%s|%s|%d|%s:%d|%s|" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, \
|
fprintf(stderr, "%s|%s|%d|%s:%d|%s|" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, \
|
||||||
getpid(), __FILE__, __LINE__, Util::Config::streamName.c_str(), ##__VA_ARGS__); \
|
getpid(), __FILE__, __LINE__, Util::streamName.c_str(), ##__VA_ARGS__); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define DEBUG_MSG(lvl, msg, ...) \
|
#define DEBUG_MSG(lvl, msg, ...) \
|
||||||
if (Util::Config::printDebugLevel >= lvl){\
|
if (Util::printDebugLevel >= lvl){\
|
||||||
fprintf(stderr, "%s|%s|%d||%s|" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, \
|
fprintf(stderr, "%s|%s|%d||%s|" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, \
|
||||||
getpid(), Util::Config::streamName.c_str(), ##__VA_ARGS__); \
|
getpid(), Util::streamName.c_str(), ##__VA_ARGS__); \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#if DEBUG >= DLVL_DEVEL
|
#if DEBUG >= DLVL_DEVEL
|
||||||
#define DEBUG_MSG(lvl, msg, ...) \
|
#define DEBUG_MSG(lvl, msg, ...) \
|
||||||
if (Util::Config::printDebugLevel >= lvl){\
|
if (Util::printDebugLevel >= lvl){\
|
||||||
fprintf(stderr, "%s|MistProcess|%d|%s:%d|%s|" msg "\n", DBG_LVL_LIST[lvl], getpid(), __FILE__, \
|
fprintf(stderr, "%s|MistProcess|%d|%s:%d|%s|" msg "\n", DBG_LVL_LIST[lvl], getpid(), __FILE__, \
|
||||||
__LINE__, Util::Config::streamName.c_str(), ##__VA_ARGS__); \
|
__LINE__, Util::streamName.c_str(), ##__VA_ARGS__); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define DEBUG_MSG(lvl, msg, ...) \
|
#define DEBUG_MSG(lvl, msg, ...) \
|
||||||
if (Util::Config::printDebugLevel >= lvl){\
|
if (Util::printDebugLevel >= lvl){\
|
||||||
fprintf(stderr, "%s|MistProcess|%d||%s|" msg "\n", DBG_LVL_LIST[lvl], getpid(), \
|
fprintf(stderr, "%s|MistProcess|%d||%s|" msg "\n", DBG_LVL_LIST[lvl], getpid(), \
|
||||||
Util::Config::streamName.c_str(), ##__VA_ARGS__); \
|
Util::streamName.c_str(), ##__VA_ARGS__); \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "dtls_srtp_handshake.h"
|
#include "dtls_srtp_handshake.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/* Write mbedtls into a log file. */
|
/* Write mbedtls into a log file. */
|
||||||
#define LOG_TO_FILE 0
|
#define LOG_TO_FILE 0
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "timing.h"
|
#include "timing.h"
|
||||||
#include "url.h"
|
#include "url.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "json.h"
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <wait.h>
|
#include <wait.h>
|
||||||
#endif
|
#endif
|
||||||
#include "timing.h"
|
#include "timing.h"
|
||||||
|
#include "json.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "riff.h"
|
#include "riff.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
namespace RIFF{
|
namespace RIFF{
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "bitfields.h"
|
#include "bitfields.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
namespace RIFF{
|
namespace RIFF{
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/sem.h>
|
#include <sys/sem.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#if defined(__CYGWIN__) || defined(_WIN32)
|
#if defined(__CYGWIN__) || defined(_WIN32)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "timing.h"
|
#include "timing.h"
|
||||||
|
|
102
lib/socket.cpp
102
lib/socket.cpp
|
@ -5,6 +5,7 @@
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "timing.h"
|
#include "timing.h"
|
||||||
|
#include "json.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
@ -114,7 +115,7 @@ bool Socket::isLocal(const std::string &remotehost){
|
||||||
/// Helper function that matches two binary-format IPv6 addresses with prefix bits of prefix.
|
/// Helper function that matches two binary-format IPv6 addresses with prefix bits of prefix.
|
||||||
bool Socket::matchIPv6Addr(const std::string &A, const std::string &B, uint8_t prefix){
|
bool Socket::matchIPv6Addr(const std::string &A, const std::string &B, uint8_t prefix){
|
||||||
if (!prefix){prefix = 128;}
|
if (!prefix){prefix = 128;}
|
||||||
if (Util::Config::printDebugLevel >= DLVL_MEDIUM){
|
if (Util::printDebugLevel >= DLVL_MEDIUM){
|
||||||
std::string Astr, Bstr;
|
std::string Astr, Bstr;
|
||||||
Socket::hostBytesToStr(A.data(), 16, Astr);
|
Socket::hostBytesToStr(A.data(), 16, Astr);
|
||||||
Socket::hostBytesToStr(B.data(), 16, Bstr);
|
Socket::hostBytesToStr(B.data(), 16, Bstr);
|
||||||
|
@ -1572,17 +1573,56 @@ Socket::UDPConnection::UDPConnection(bool nonblock){
|
||||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
family = AF_INET;
|
family = AF_INET;
|
||||||
}
|
}
|
||||||
if (sock == -1){FAIL_MSG("Could not create UDP socket: %s", strerror(errno));}
|
if (sock == -1){
|
||||||
|
FAIL_MSG("Could not create UDP socket: %s", strerror(errno));
|
||||||
|
}else{
|
||||||
|
if (nonblock){setBlocking(!nonblock);}
|
||||||
|
checkRecvBuf();
|
||||||
|
}
|
||||||
up = 0;
|
up = 0;
|
||||||
down = 0;
|
down = 0;
|
||||||
destAddr = 0;
|
destAddr = 0;
|
||||||
destAddr_size = 0;
|
destAddr_size = 0;
|
||||||
data = 0;
|
data.allocate(2048);
|
||||||
data_size = 0;
|
|
||||||
data_len = 0;
|
|
||||||
if (nonblock){setBlocking(!nonblock);}
|
|
||||||
}// Socket::UDPConnection UDP Contructor
|
}// Socket::UDPConnection UDP Contructor
|
||||||
|
|
||||||
|
///Checks if the UDP receive buffer is at least 1 mbyte, attempts to increase and warns user through log message on failure.
|
||||||
|
void Socket::UDPConnection::checkRecvBuf(){
|
||||||
|
if (sock == -1){return;}
|
||||||
|
int recvbuf = 0;
|
||||||
|
int origbuf = 0;
|
||||||
|
socklen_t slen = sizeof(recvbuf);
|
||||||
|
getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (void*)&recvbuf, &slen);
|
||||||
|
origbuf = recvbuf;
|
||||||
|
if (recvbuf < 1024*1024){
|
||||||
|
recvbuf = 1024*1024;
|
||||||
|
setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (void*)&recvbuf, sizeof(recvbuf));
|
||||||
|
slen = sizeof(recvbuf);
|
||||||
|
getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (void*)&recvbuf, &slen);
|
||||||
|
if (recvbuf < 1024*1024){
|
||||||
|
recvbuf = 1024*1024;
|
||||||
|
setsockopt(sock, SOL_SOCKET, SO_RCVBUFFORCE, (void*)&recvbuf, sizeof(recvbuf));
|
||||||
|
slen = sizeof(recvbuf);
|
||||||
|
getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (void*)&recvbuf, &slen);
|
||||||
|
}
|
||||||
|
if (recvbuf < 200*1024){
|
||||||
|
recvbuf = 200*1024;
|
||||||
|
setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (void*)&recvbuf, sizeof(recvbuf));
|
||||||
|
slen = sizeof(recvbuf);
|
||||||
|
getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (void*)&recvbuf, &slen);
|
||||||
|
if (recvbuf < 200*1024){
|
||||||
|
recvbuf = 200*1024;
|
||||||
|
setsockopt(sock, SOL_SOCKET, SO_RCVBUFFORCE, (void*)&recvbuf, sizeof(recvbuf));
|
||||||
|
slen = sizeof(recvbuf);
|
||||||
|
getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (void*)&recvbuf, &slen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (recvbuf < 200*1024){
|
||||||
|
WARN_MSG("Your UDP receive buffer is set < 200 kbyte (%db) and the kernel denied our request for an increase. It's recommended to set your net.core.rmem_max setting to at least 200 kbyte for best results.", origbuf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Copies a UDP socket, re-allocating local copies of any needed structures.
|
/// Copies a UDP socket, re-allocating local copies of any needed structures.
|
||||||
/// The data/data_size/data_len variables are *not* copied over.
|
/// The data/data_size/data_len variables are *not* copied over.
|
||||||
Socket::UDPConnection::UDPConnection(const UDPConnection &o){
|
Socket::UDPConnection::UDPConnection(const UDPConnection &o){
|
||||||
|
@ -1594,6 +1634,7 @@ Socket::UDPConnection::UDPConnection(const UDPConnection &o){
|
||||||
family = AF_INET;
|
family = AF_INET;
|
||||||
}
|
}
|
||||||
if (sock == -1){FAIL_MSG("Could not create UDP socket: %s", strerror(errno));}
|
if (sock == -1){FAIL_MSG("Could not create UDP socket: %s", strerror(errno));}
|
||||||
|
checkRecvBuf();
|
||||||
up = 0;
|
up = 0;
|
||||||
down = 0;
|
down = 0;
|
||||||
if (o.destAddr && o.destAddr_size){
|
if (o.destAddr && o.destAddr_size){
|
||||||
|
@ -1604,13 +1645,7 @@ Socket::UDPConnection::UDPConnection(const UDPConnection &o){
|
||||||
destAddr = 0;
|
destAddr = 0;
|
||||||
destAddr_size = 0;
|
destAddr_size = 0;
|
||||||
}
|
}
|
||||||
data = (char *)malloc(1024);
|
data.allocate(2048);
|
||||||
if (data){
|
|
||||||
data_size = 1024;
|
|
||||||
}else{
|
|
||||||
data_size = 0;
|
|
||||||
}
|
|
||||||
data_len = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Close the UDP socket
|
/// Close the UDP socket
|
||||||
|
@ -1629,10 +1664,6 @@ Socket::UDPConnection::~UDPConnection(){
|
||||||
free(destAddr);
|
free(destAddr);
|
||||||
destAddr = 0;
|
destAddr = 0;
|
||||||
}
|
}
|
||||||
if (data){
|
|
||||||
free(data);
|
|
||||||
data = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores the properties of the receiving end of this UDP socket.
|
/// Stores the properties of the receiving end of this UDP socket.
|
||||||
|
@ -1674,6 +1705,7 @@ void Socket::UDPConnection::SetDestination(std::string destIp, uint32_t port){
|
||||||
close();
|
close();
|
||||||
family = rp->ai_family;
|
family = rp->ai_family;
|
||||||
sock = socket(family, SOCK_DGRAM, 0);
|
sock = socket(family, SOCK_DGRAM, 0);
|
||||||
|
checkRecvBuf();
|
||||||
if (boundPort){
|
if (boundPort){
|
||||||
INFO_MSG("Rebinding to %s:%d %s", boundAddr.c_str(), boundPort, boundMulti.c_str());
|
INFO_MSG("Rebinding to %s:%d %s", boundAddr.c_str(), boundPort, boundMulti.c_str());
|
||||||
bind(boundPort, boundAddr, boundMulti);
|
bind(boundPort, boundAddr, boundMulti);
|
||||||
|
@ -1815,6 +1847,7 @@ uint16_t Socket::UDPConnection::bind(int port, std::string iface, const std::str
|
||||||
for (rp = addr_result; rp != NULL; rp = rp->ai_next){
|
for (rp = addr_result; rp != NULL; rp = rp->ai_next){
|
||||||
sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
||||||
if (sock == -1){continue;}
|
if (sock == -1){continue;}
|
||||||
|
checkRecvBuf();
|
||||||
char human_addr[INET6_ADDRSTRLEN];
|
char human_addr[INET6_ADDRSTRLEN];
|
||||||
char human_port[16];
|
char human_port[16];
|
||||||
getnameinfo(rp->ai_addr, rp->ai_addrlen, human_addr, INET6_ADDRSTRLEN, human_port, 16,
|
getnameinfo(rp->ai_addr, rp->ai_addrlen, human_addr, INET6_ADDRSTRLEN, human_port, 16,
|
||||||
|
@ -1964,36 +1997,23 @@ uint16_t Socket::UDPConnection::bind(int port, std::string iface, const std::str
|
||||||
bool Socket::UDPConnection::Receive(){
|
bool Socket::UDPConnection::Receive(){
|
||||||
if (sock == -1){return false;}
|
if (sock == -1){return false;}
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
if (data_size != SOCKETSIZE){
|
data.allocate((SOCKETSIZE);
|
||||||
data = (char *)realloc(data, SOCKETSIZE);
|
|
||||||
data_size = SOCKETSIZE;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
int r = recvfrom(sock, data, data_size, MSG_PEEK | MSG_TRUNC | MSG_DONTWAIT, 0, 0);
|
data.truncate(0);
|
||||||
|
socklen_t destsize = destAddr_size;
|
||||||
|
int r = recvfrom(sock, data, data.rsize(), MSG_TRUNC | MSG_DONTWAIT, (sockaddr *)destAddr, &destsize);
|
||||||
if (r == -1){
|
if (r == -1){
|
||||||
if (errno != EAGAIN){INFO_MSG("UDP receive: %d (%s)", errno, strerror(errno));}
|
if (errno != EAGAIN){INFO_MSG("UDP receive: %d (%s)", errno, strerror(errno));}
|
||||||
data_len = 0;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (data_size < (unsigned int)r){
|
data.append(0, r);
|
||||||
char *tmp = (char *)realloc(data, r);
|
down += r;
|
||||||
if (tmp){
|
//Handle UDP packets that are too large
|
||||||
data = tmp;
|
if (data.rsize() < (unsigned int)r){
|
||||||
data_size = r;
|
INFO_MSG("Doubling UDP socket buffer from %" PRIu32 " to %" PRIu32, data.rsize(), data.rsize()*2);
|
||||||
}else{
|
data.allocate(data.rsize()*2);
|
||||||
FAIL_MSG("Could not resize socket buffer to %d bytes!", r);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
socklen_t destsize = destAddr_size;
|
return (r > 0);
|
||||||
r = recvfrom(sock, data, data_size, 0, (sockaddr *)destAddr, &destsize);
|
|
||||||
if (r > 0){
|
|
||||||
down += r;
|
|
||||||
data_len = r;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
data_len = 0;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Socket::UDPConnection::getSock(){
|
int Socket::UDPConnection::getSock(){
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#ifdef SSL
|
#ifdef SSL
|
||||||
#include "mbedtls/ctr_drbg.h"
|
#include "mbedtls/ctr_drbg.h"
|
||||||
|
@ -195,14 +196,13 @@ namespace Socket{
|
||||||
unsigned int destAddr_size; ///< Size of the destination address pointer.
|
unsigned int destAddr_size; ///< Size of the destination address pointer.
|
||||||
unsigned int up; ///< Amount of bytes transferred up.
|
unsigned int up; ///< Amount of bytes transferred up.
|
||||||
unsigned int down; ///< Amount of bytes transferred down.
|
unsigned int down; ///< Amount of bytes transferred down.
|
||||||
unsigned int data_size; ///< The size in bytes of the allocated space in the data pointer.
|
|
||||||
int family; ///< Current socket address family
|
int family; ///< Current socket address family
|
||||||
std::string boundAddr, boundMulti;
|
std::string boundAddr, boundMulti;
|
||||||
int boundPort;
|
int boundPort;
|
||||||
|
void checkRecvBuf();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
char *data; ///< Holds the last received packet.
|
Util::ResizeablePointer data;
|
||||||
unsigned int data_len; ///< The size in bytes of the last received packet.
|
|
||||||
UDPConnection(const UDPConnection &o);
|
UDPConnection(const UDPConnection &o);
|
||||||
UDPConnection(bool nonblock = false);
|
UDPConnection(bool nonblock = false);
|
||||||
~UDPConnection();
|
~UDPConnection();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "srtp.h"
|
#include "srtp.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/* --------------------------------------- */
|
/* --------------------------------------- */
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <srtp2/srtp.h>
|
#include <srtp2/srtp.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#define SRTP_PARSER_MASTER_KEY_LEN 16
|
#define SRTP_PARSER_MASTER_KEY_LEN 16
|
||||||
#define SRTP_PARSER_MASTER_SALT_LEN 14
|
#define SRTP_PARSER_MASTER_SALT_LEN 14
|
||||||
|
|
|
@ -407,8 +407,8 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir
|
||||||
(char *)filename.c_str()};
|
(char *)filename.c_str()};
|
||||||
int argNum = 3;
|
int argNum = 3;
|
||||||
std::string debugLvl;
|
std::string debugLvl;
|
||||||
if (Util::Config::printDebugLevel != DEBUG && !str_args.count("--debug")){
|
if (Util::printDebugLevel != DEBUG && !str_args.count("--debug")){
|
||||||
debugLvl = JSON::Value(Util::Config::printDebugLevel).asString();
|
debugLvl = JSON::Value(Util::printDebugLevel).asString();
|
||||||
argv[++argNum] = (char *)"--debug";
|
argv[++argNum] = (char *)"--debug";
|
||||||
argv[++argNum] = (char *)debugLvl.c_str();
|
argv[++argNum] = (char *)debugLvl.c_str();
|
||||||
}
|
}
|
||||||
|
@ -563,7 +563,7 @@ pid_t Util::startPush(const std::string &streamname, std::string &target, int de
|
||||||
// Set original target string in environment
|
// Set original target string in environment
|
||||||
setenv("MST_ORIG_TARGET", target.c_str(), 1);
|
setenv("MST_ORIG_TARGET", target.c_str(), 1);
|
||||||
//If no debug level set, default to level of starting process
|
//If no debug level set, default to level of starting process
|
||||||
if (debugLvl < 0){debugLvl = Util::Config::printDebugLevel;}
|
if (debugLvl < 0){debugLvl = Util::printDebugLevel;}
|
||||||
|
|
||||||
// The target can hold variables like current time etc
|
// The target can hold variables like current time etc
|
||||||
streamVariables(target, streamname);
|
streamVariables(target, streamname);
|
||||||
|
@ -1285,7 +1285,7 @@ std::set<size_t> Util::wouldSelect(const DTSC::Meta &M, const std::map<std::stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Util::Config::printDebugLevel >= DLVL_MEDIUM){
|
if (Util::printDebugLevel >= DLVL_MEDIUM){
|
||||||
// print the selected tracks
|
// print the selected tracks
|
||||||
std::stringstream selected;
|
std::stringstream selected;
|
||||||
for (std::set<size_t>::iterator it = result.begin(); it != result.end(); it++){
|
for (std::set<size_t>::iterator it = result.begin(); it != result.end(); it++){
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "checksum.h" // for crc32
|
#include "checksum.h" // for crc32
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "stun.h"
|
#include "stun.h"
|
||||||
|
#include "socket.h"
|
||||||
|
|
||||||
/* --------------------------------------- */
|
/* --------------------------------------- */
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "timing.h"
|
#include "timing.h"
|
||||||
#include "triggers.h"
|
#include "triggers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "json.h"
|
||||||
#include <string.h> //for strncmp
|
#include <string.h> //for strncmp
|
||||||
|
|
||||||
namespace Triggers{
|
namespace Triggers{
|
||||||
|
|
|
@ -265,7 +265,7 @@ int main_loop(int argc, char **argv){
|
||||||
}
|
}
|
||||||
if (Controller::Storage.isMember("config") && Controller::Storage["config"].isMember("debug") &&
|
if (Controller::Storage.isMember("config") && Controller::Storage["config"].isMember("debug") &&
|
||||||
Controller::Storage["config"]["debug"].isInt()){
|
Controller::Storage["config"]["debug"].isInt()){
|
||||||
Util::Config::printDebugLevel = Controller::Storage["config"]["debug"].asInt();
|
Util::printDebugLevel = Controller::Storage["config"]["debug"].asInt();
|
||||||
}
|
}
|
||||||
// check for port, interface and username in arguments
|
// check for port, interface and username in arguments
|
||||||
// if they are not there, take them from config file, if there
|
// if they are not there, take them from config file, if there
|
||||||
|
|
|
@ -443,8 +443,8 @@ void Controller::handleUDPAPI(void *np){
|
||||||
uSock.SetDestination(UDP_API_HOST, UDP_API_PORT);
|
uSock.SetDestination(UDP_API_HOST, UDP_API_PORT);
|
||||||
while (Controller::conf.is_active){
|
while (Controller::conf.is_active){
|
||||||
if (uSock.Receive()){
|
if (uSock.Receive()){
|
||||||
MEDIUM_MSG("UDP API: %s", uSock.data);
|
MEDIUM_MSG("UDP API: %s", (const char*)uSock.data);
|
||||||
JSON::Value Request = JSON::fromString(uSock.data, uSock.data_len);
|
JSON::Value Request = JSON::fromString(uSock.data, uSock.data.size());
|
||||||
Request["minimal"] = true;
|
Request["minimal"] = true;
|
||||||
JSON::Value Response;
|
JSON::Value Response;
|
||||||
if (Request.isObject()){
|
if (Request.isObject()){
|
||||||
|
@ -454,7 +454,7 @@ void Controller::handleUDPAPI(void *np){
|
||||||
Response.removeMember("authorize");
|
Response.removeMember("authorize");
|
||||||
uSock.SendNow(Response.toString());
|
uSock.SendNow(Response.toString());
|
||||||
}else{
|
}else{
|
||||||
WARN_MSG("Invalid API command received over UDP: %s", uSock.data);
|
WARN_MSG("Invalid API command received over UDP: %s", (const char*)uSock.data);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
Util::sleep(500);
|
Util::sleep(500);
|
||||||
|
@ -515,9 +515,9 @@ void Controller::handleAPICommands(JSON::Value &Request, JSON::Value &Response){
|
||||||
JSON::Value &out = Controller::Storage["config"];
|
JSON::Value &out = Controller::Storage["config"];
|
||||||
if (in.isMember("debug")){
|
if (in.isMember("debug")){
|
||||||
out["debug"] = in["debug"];
|
out["debug"] = in["debug"];
|
||||||
if (Util::Config::printDebugLevel != (out["debug"].isInt() ? out["debug"].asInt() : DEBUG)){
|
if (Util::printDebugLevel != (out["debug"].isInt() ? out["debug"].asInt() : DEBUG)){
|
||||||
Util::Config::printDebugLevel = (out["debug"].isInt() ? out["debug"].asInt() : DEBUG);
|
Util::printDebugLevel = (out["debug"].isInt() ? out["debug"].asInt() : DEBUG);
|
||||||
INFO_MSG("Debug level set to %u", Util::Config::printDebugLevel);
|
INFO_MSG("Debug level set to %u", Util::printDebugLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (in.isMember("protocols")){
|
if (in.isMember("protocols")){
|
||||||
|
|
|
@ -116,9 +116,9 @@ namespace Controller{
|
||||||
argarr[argnum++] = (char *)(p[it.key()].c_str());
|
argarr[argnum++] = (char *)(p[it.key()].c_str());
|
||||||
}else{
|
}else{
|
||||||
if (it.key() == "debug"){
|
if (it.key() == "debug"){
|
||||||
if (Util::Config::printDebugLevel != DEBUG){
|
if (Util::printDebugLevel != DEBUG){
|
||||||
static std::string debugLvlStr;
|
static std::string debugLvlStr;
|
||||||
debugLvlStr = JSON::Value(Util::Config::printDebugLevel).asString();
|
debugLvlStr = JSON::Value(Util::printDebugLevel).asString();
|
||||||
argarr[argnum++] = (char *)((*it)["option"].asStringRef().c_str());
|
argarr[argnum++] = (char *)((*it)["option"].asStringRef().c_str());
|
||||||
argarr[argnum++] = (char *)debugLvlStr.c_str();
|
argarr[argnum++] = (char *)debugLvlStr.c_str();
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,7 +306,7 @@ namespace Mist{
|
||||||
int Input::boot(int argc, char *argv[]){
|
int Input::boot(int argc, char *argv[]){
|
||||||
if (!(config->parseArgs(argc, argv))){return 1;}
|
if (!(config->parseArgs(argc, argv))){return 1;}
|
||||||
streamName = config->getString("streamname");
|
streamName = config->getString("streamname");
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
|
|
||||||
if (config->getBool("json")){
|
if (config->getBool("json")){
|
||||||
capa["version"] = PACKAGE_VERSION;
|
capa["version"] = PACKAGE_VERSION;
|
||||||
|
|
|
@ -373,8 +373,8 @@ namespace Mist{
|
||||||
// // wrong sending port, ignore packet
|
// // wrong sending port, ignore packet
|
||||||
// continue;
|
// continue;
|
||||||
//}
|
//}
|
||||||
tcpCon.addDown(s.data_len);
|
tcpCon.addDown(s.data.size());
|
||||||
RTP::Packet pack(s.data, s.data_len);
|
RTP::Packet pack(s.data, s.data.size());
|
||||||
if (!it->second.theirSSRC){it->second.theirSSRC = pack.getSSRC();}
|
if (!it->second.theirSSRC){it->second.theirSSRC = pack.getSSRC();}
|
||||||
it->second.sorter.addPacket(pack);
|
it->second.sorter.addPacket(pack);
|
||||||
}
|
}
|
||||||
|
|
|
@ -512,7 +512,7 @@ namespace Mist{
|
||||||
std::string leftData;
|
std::string leftData;
|
||||||
bool received = false;
|
bool received = false;
|
||||||
while (udpCon.Receive()){
|
while (udpCon.Receive()){
|
||||||
downCounter += udpCon.data_len;
|
downCounter += udpCon.data.size();
|
||||||
received = true;
|
received = true;
|
||||||
if (!gettingData){
|
if (!gettingData){
|
||||||
gettingData = true;
|
gettingData = true;
|
||||||
|
@ -521,20 +521,20 @@ namespace Mist{
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
// Try to read full TS Packets
|
// Try to read full TS Packets
|
||||||
// Watch out! We push here to a global, in order for threads to be able to access it.
|
// Watch out! We push here to a global, in order for threads to be able to access it.
|
||||||
while (offset < udpCon.data_len){
|
while (offset < udpCon.data.size()){
|
||||||
if (udpCon.data[offset] == 0x47){// check for sync byte
|
if (udpCon.data[offset] == 0x47){// check for sync byte
|
||||||
if (offset + 188 <= udpCon.data_len){
|
if (offset + 188 <= udpCon.data.size()){
|
||||||
tsBuf.FromPointer(udpCon.data + offset);
|
tsBuf.FromPointer(udpCon.data + offset);
|
||||||
liveStream.add(tsBuf);
|
liveStream.add(tsBuf);
|
||||||
if (!liveStream.isDataTrack(tsBuf.getPID())){liveStream.parse(tsBuf.getPID());}
|
if (!liveStream.isDataTrack(tsBuf.getPID())){liveStream.parse(tsBuf.getPID());}
|
||||||
leftData.clear();
|
leftData.clear();
|
||||||
}else{
|
}else{
|
||||||
leftData.append(udpCon.data + offset, udpCon.data_len - offset);
|
leftData.append(udpCon.data + offset, udpCon.data.size() - offset);
|
||||||
}
|
}
|
||||||
offset += 188;
|
offset += 188;
|
||||||
}else{
|
}else{
|
||||||
uint32_t maxBytes =
|
uint32_t maxBytes =
|
||||||
std::min((uint32_t)(188 - leftData.size()), (uint32_t)(udpCon.data_len - offset));
|
std::min((uint32_t)(188 - leftData.size()), (uint32_t)(udpCon.data.size() - offset));
|
||||||
uint32_t numBytes = maxBytes;
|
uint32_t numBytes = maxBytes;
|
||||||
VERYHIGH_MSG("%" PRIu32 " bytes of non-sync-byte data received", numBytes);
|
VERYHIGH_MSG("%" PRIu32 " bytes of non-sync-byte data received", numBytes);
|
||||||
if (leftData.size()){
|
if (leftData.size()){
|
||||||
|
|
|
@ -80,7 +80,7 @@ namespace Mist{
|
||||||
// If we have a streamname option, set internal streamname to that option
|
// If we have a streamname option, set internal streamname to that option
|
||||||
if (!streamName.size() && config->hasOption("streamname")){
|
if (!streamName.size() && config->hasOption("streamname")){
|
||||||
streamName = config->getString("streamname");
|
streamName = config->getString("streamname");
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*LTS-START*/
|
/*LTS-START*/
|
||||||
|
@ -321,7 +321,7 @@ namespace Mist{
|
||||||
JSON::Value strCnf = Util::getStreamConfig(streamName);
|
JSON::Value strCnf = Util::getStreamConfig(streamName);
|
||||||
if (strCnf && strCnf["fallback_stream"].asStringRef().size()){
|
if (strCnf && strCnf["fallback_stream"].asStringRef().size()){
|
||||||
streamName = strCnf["fallback_stream"].asStringRef();
|
streamName = strCnf["fallback_stream"].asStringRef();
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
INFO_MSG("Switching to configured fallback stream '%s'", streamName.c_str());
|
INFO_MSG("Switching to configured fallback stream '%s'", streamName.c_str());
|
||||||
reconnect();
|
reconnect();
|
||||||
return;
|
return;
|
||||||
|
@ -352,7 +352,7 @@ namespace Mist{
|
||||||
newStrm.c_str());
|
newStrm.c_str());
|
||||||
std::string origStream = streamName;
|
std::string origStream = streamName;
|
||||||
streamName = newStrm;
|
streamName = newStrm;
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
if (!Util::startInput(streamName, "", true, isPushing())){
|
if (!Util::startInput(streamName, "", true, isPushing())){
|
||||||
onFail("Stream open failed (fallback stream for '" + origStream + "')", true);
|
onFail("Stream open failed (fallback stream for '" + origStream + "')", true);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -223,7 +223,7 @@ namespace Mist{
|
||||||
void OutDTSC::handlePlay(DTSC::Scan &dScan){
|
void OutDTSC::handlePlay(DTSC::Scan &dScan){
|
||||||
streamName = dScan.getMember("stream").asString();
|
streamName = dScan.getMember("stream").asString();
|
||||||
Util::sanitizeName(streamName);
|
Util::sanitizeName(streamName);
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
parseData = true;
|
parseData = true;
|
||||||
INFO_MSG("Handled play for stream %s", streamName.c_str());
|
INFO_MSG("Handled play for stream %s", streamName.c_str());
|
||||||
setBlocking(false);
|
setBlocking(false);
|
||||||
|
@ -233,7 +233,7 @@ namespace Mist{
|
||||||
streamName = dScan.getMember("stream").asString();
|
streamName = dScan.getMember("stream").asString();
|
||||||
std::string passString = dScan.getMember("password").asString();
|
std::string passString = dScan.getMember("password").asString();
|
||||||
Util::sanitizeName(streamName);
|
Util::sanitizeName(streamName);
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
if (!allowPush(passString)){
|
if (!allowPush(passString)){
|
||||||
onFail("Push not allowed - stream and/or password incorrect", true);
|
onFail("Push not allowed - stream and/or password incorrect", true);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -397,7 +397,7 @@ namespace Mist{
|
||||||
int argnum = 0;
|
int argnum = 0;
|
||||||
argarr[argnum++] = (char *)tmparg.c_str();
|
argarr[argnum++] = (char *)tmparg.c_str();
|
||||||
std::string temphost = getConnectedHost();
|
std::string temphost = getConnectedHost();
|
||||||
std::string debuglevel = JSON::Value(Util::Config::printDebugLevel).asString();
|
std::string debuglevel = JSON::Value(Util::printDebugLevel).asString();
|
||||||
argarr[argnum++] = (char *)"--ip";
|
argarr[argnum++] = (char *)"--ip";
|
||||||
argarr[argnum++] = (char *)(temphost.c_str());
|
argarr[argnum++] = (char *)(temphost.c_str());
|
||||||
argarr[argnum++] = (char *)"--stream";
|
argarr[argnum++] = (char *)"--stream";
|
||||||
|
@ -405,7 +405,7 @@ namespace Mist{
|
||||||
argarr[argnum++] = (char *)"--prequest";
|
argarr[argnum++] = (char *)"--prequest";
|
||||||
argarr[argnum++] = (char *)(tmpPrequest.c_str());
|
argarr[argnum++] = (char *)(tmpPrequest.c_str());
|
||||||
// set the debug level if non-default
|
// set the debug level if non-default
|
||||||
if (Util::Config::printDebugLevel != DEBUG){
|
if (Util::printDebugLevel != DEBUG){
|
||||||
argarr[argnum++] = (char *)"--debug";
|
argarr[argnum++] = (char *)"--debug";
|
||||||
argarr[argnum++] = (char *)(debuglevel.c_str());
|
argarr[argnum++] = (char *)(debuglevel.c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -441,7 +441,7 @@ namespace Mist{
|
||||||
INFO_MSG("Falling back to default stream '%s' -> '%s'", defStrm.c_str(), newStrm.c_str());
|
INFO_MSG("Falling back to default stream '%s' -> '%s'", defStrm.c_str(), newStrm.c_str());
|
||||||
origStreamName = streamName;
|
origStreamName = streamName;
|
||||||
streamName = newStrm;
|
streamName = newStrm;
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
reconnect();
|
reconnect();
|
||||||
return getStatusJSON(reqHost, useragent);
|
return getStatusJSON(reqHost, useragent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,7 +216,7 @@ namespace Mist{
|
||||||
char ffcmd[256];
|
char ffcmd[256];
|
||||||
ffcmd[255] = 0; // ensure there is an ending null byte
|
ffcmd[255] = 0; // ensure there is an ending null byte
|
||||||
snprintf(ffcmd, 255, "ffmpeg %s -f h264 -i - %s -vframes 1 -f mjpeg -",
|
snprintf(ffcmd, 255, "ffmpeg %s -f h264 -i - %s -vframes 1 -f mjpeg -",
|
||||||
(Util::Config::printDebugLevel >= DLVL_MEDIUM ? "" : "-v quiet"),
|
(Util::printDebugLevel >= DLVL_MEDIUM ? "" : "-v quiet"),
|
||||||
config->getString("ffopts").c_str());
|
config->getString("ffopts").c_str());
|
||||||
|
|
||||||
HIGH_MSG("Starting JPG command: %s", ffcmd);
|
HIGH_MSG("Starting JPG command: %s", ffcmd);
|
||||||
|
|
|
@ -828,11 +828,11 @@ namespace Mist{
|
||||||
if (streamName.find('?') != std::string::npos){
|
if (streamName.find('?') != std::string::npos){
|
||||||
std::string tmpVars = streamName.substr(streamName.find('?') + 1);
|
std::string tmpVars = streamName.substr(streamName.find('?') + 1);
|
||||||
streamName = streamName.substr(0, streamName.find('?'));
|
streamName = streamName.substr(0, streamName.find('?'));
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
HTTP::parseVars(tmpVars, targetParams);
|
HTTP::parseVars(tmpVars, targetParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
reqUrl += "/" + streamName; // LTS
|
reqUrl += "/" + streamName; // LTS
|
||||||
|
|
||||||
/*LTS-START*/
|
/*LTS-START*/
|
||||||
|
@ -850,17 +850,17 @@ namespace Mist{
|
||||||
size_t lSlash = newUrl.rfind('/');
|
size_t lSlash = newUrl.rfind('/');
|
||||||
if (lSlash != std::string::npos){
|
if (lSlash != std::string::npos){
|
||||||
streamName = newUrl.substr(lSlash + 1);
|
streamName = newUrl.substr(lSlash + 1);
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
}else{
|
}else{
|
||||||
streamName = newUrl;
|
streamName = newUrl;
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*LTS-END*/
|
/*LTS-END*/
|
||||||
|
|
||||||
if (streamName.find('/')){
|
if (streamName.find('/')){
|
||||||
streamName = streamName.substr(0, streamName.find('/'));
|
streamName = streamName.substr(0, streamName.find('/'));
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t colonPos = streamName.find(':');
|
size_t colonPos = streamName.find(':');
|
||||||
|
@ -871,7 +871,7 @@ namespace Mist{
|
||||||
}else{
|
}else{
|
||||||
streamName = oldName.substr(colonPos + 1) + std::string(".") + oldName.substr(0, colonPos);
|
streamName = oldName.substr(colonPos + 1) + std::string(".") + oldName.substr(0, colonPos);
|
||||||
}
|
}
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
}
|
}
|
||||||
|
|
||||||
Util::sanitizeName(streamName);
|
Util::sanitizeName(streamName);
|
||||||
|
@ -922,14 +922,14 @@ namespace Mist{
|
||||||
int8_t playMessageType = messageType;
|
int8_t playMessageType = messageType;
|
||||||
int32_t playStreamId = streamId;
|
int32_t playStreamId = streamId;
|
||||||
streamName = Encodings::URL::decode(amfData.getContentP(3)->StrValue());
|
streamName = Encodings::URL::decode(amfData.getContentP(3)->StrValue());
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
reqUrl += "/" + streamName; // LTS
|
reqUrl += "/" + streamName; // LTS
|
||||||
|
|
||||||
// handle variables
|
// handle variables
|
||||||
if (streamName.find('?') != std::string::npos){
|
if (streamName.find('?') != std::string::npos){
|
||||||
std::string tmpVars = streamName.substr(streamName.find('?') + 1);
|
std::string tmpVars = streamName.substr(streamName.find('?') + 1);
|
||||||
streamName = streamName.substr(0, streamName.find('?'));
|
streamName = streamName.substr(0, streamName.find('?'));
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
HTTP::parseVars(tmpVars, targetParams);
|
HTTP::parseVars(tmpVars, targetParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -941,7 +941,7 @@ namespace Mist{
|
||||||
}else{
|
}else{
|
||||||
streamName = oldName.substr(colonPos + 1) + std::string(".") + oldName.substr(0, colonPos);
|
streamName = oldName.substr(colonPos + 1) + std::string(".") + oldName.substr(0, colonPos);
|
||||||
}
|
}
|
||||||
Util::Config::streamName = streamName;
|
Util::streamName = streamName;
|
||||||
}
|
}
|
||||||
Util::sanitizeName(streamName);
|
Util::sanitizeName(streamName);
|
||||||
|
|
||||||
|
|
|
@ -485,8 +485,8 @@ namespace Mist{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
lastRecv = Util::bootSecs(); // prevent disconnect of idle TCP connection when using UDP
|
lastRecv = Util::bootSecs(); // prevent disconnect of idle TCP connection when using UDP
|
||||||
myConn.addDown(s.data_len);
|
myConn.addDown(s.data.size());
|
||||||
RTP::Packet pack(s.data, s.data_len);
|
RTP::Packet pack(s.data, s.data.size());
|
||||||
if (!it->second.theirSSRC){it->second.theirSSRC = pack.getSSRC();}
|
if (!it->second.theirSSRC){it->second.theirSSRC = pack.getSSRC();}
|
||||||
it->second.sorter.addPacket(pack);
|
it->second.sorter.addPacket(pack);
|
||||||
}
|
}
|
||||||
|
|
|
@ -910,7 +910,7 @@ namespace Mist{
|
||||||
bool hadPack = false;
|
bool hadPack = false;
|
||||||
while (udp.Receive()){
|
while (udp.Receive()){
|
||||||
hadPack = true;
|
hadPack = true;
|
||||||
myConn.addDown(udp.data_len);
|
myConn.addDown(udp.data.size());
|
||||||
|
|
||||||
uint8_t fb = (uint8_t)udp.data[0];
|
uint8_t fb = (uint8_t)udp.data[0];
|
||||||
|
|
||||||
|
@ -936,7 +936,7 @@ namespace Mist{
|
||||||
|
|
||||||
size_t nparsed = 0;
|
size_t nparsed = 0;
|
||||||
StunMessage stun_msg;
|
StunMessage stun_msg;
|
||||||
if (stunReader.parse((uint8_t *)udp.data, udp.data_len, nparsed, stun_msg) != 0){
|
if (stunReader.parse((uint8_t *)(char*)udp.data, udp.data.size(), nparsed, stun_msg) != 0){
|
||||||
FAIL_MSG("Failed to parse a stun message.");
|
FAIL_MSG("Failed to parse a stun message.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1006,7 +1006,7 @@ namespace Mist{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dtlsHandshake.parse((const uint8_t *)udp.data, udp.data_len) != 0){
|
if (dtlsHandshake.parse((const uint8_t *)(const char*)udp.data, udp.data.size()) != 0){
|
||||||
FAIL_MSG("Failed to parse a DTLS packet.");
|
FAIL_MSG("Failed to parse a DTLS packet.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1049,7 +1049,7 @@ namespace Mist{
|
||||||
|
|
||||||
if ((pt < 64) || (pt >= 96)){
|
if ((pt < 64) || (pt >= 96)){
|
||||||
|
|
||||||
RTP::Packet rtp_pkt((const char *)udp.data, (unsigned int)udp.data_len);
|
RTP::Packet rtp_pkt((const char *)udp.data, (unsigned int)udp.data.size());
|
||||||
uint16_t currSeqNum = rtp_pkt.getSequence();
|
uint16_t currSeqNum = rtp_pkt.getSequence();
|
||||||
|
|
||||||
size_t idx = M.trackIDToIndex(rtp_pkt.getPayloadType(), getpid());
|
size_t idx = M.trackIDToIndex(rtp_pkt.getPayloadType(), getpid());
|
||||||
|
@ -1071,8 +1071,8 @@ namespace Mist{
|
||||||
WebRTCTrack &rtcTrack = webrtcTracks[idx];
|
WebRTCTrack &rtcTrack = webrtcTracks[idx];
|
||||||
|
|
||||||
// Decrypt the SRTP to RTP
|
// Decrypt the SRTP to RTP
|
||||||
int len = (int)udp.data_len;
|
int len = udp.data.size();
|
||||||
if (srtpReader.unprotectRtp((uint8_t *)udp.data, &len) != 0){
|
if (srtpReader.unprotectRtp((uint8_t *)(char*)udp.data, &len) != 0){
|
||||||
if (packetLog.is_open()){packetLog << "[" << Util::bootMS() << "]" << "RTP decrypt failure" << std::endl;}
|
if (packetLog.is_open()){packetLog << "[" << Util::bootMS() << "]" << "RTP decrypt failure" << std::endl;}
|
||||||
FAIL_MSG("Failed to unprotect a RTP packet.");
|
FAIL_MSG("Failed to unprotect a RTP packet.");
|
||||||
return;
|
return;
|
||||||
|
@ -1102,8 +1102,8 @@ namespace Mist{
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
//Decrypt feedback packet
|
//Decrypt feedback packet
|
||||||
int len = udp.data_len;
|
int len = udp.data.size();
|
||||||
if (srtpReader.unprotectRtcp((uint8_t *)udp.data, &len) != 0){
|
if (srtpReader.unprotectRtcp((uint8_t *)(char*)udp.data, &len) != 0){
|
||||||
if (packetLog.is_open()){packetLog << "[" << Util::bootMS() << "]" << "RTCP decrypt failure" << std::endl;}
|
if (packetLog.is_open()){packetLog << "[" << Util::bootMS() << "]" << "RTCP decrypt failure" << std::endl;}
|
||||||
FAIL_MSG("Failed to unprotect RTCP.");
|
FAIL_MSG("Failed to unprotect RTCP.");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace Mist{
|
||||||
streamName = opt["sink"].asString();
|
streamName = opt["sink"].asString();
|
||||||
if (!streamName.size()){streamName = opt["source"].asString();}
|
if (!streamName.size()){streamName = opt["source"].asString();}
|
||||||
Util::streamVariables(streamName, opt["source"].asString());
|
Util::streamVariables(streamName, opt["source"].asString());
|
||||||
Util::Config::streamName = opt["source"].asString() + "→" + streamName;
|
Util::streamName = opt["source"].asString() + "→" + streamName;
|
||||||
}
|
}
|
||||||
bool needsLock(){return false;}
|
bool needsLock(){return false;}
|
||||||
bool isSingular(){return false;}
|
bool isSingular(){return false;}
|
||||||
|
|
|
@ -389,7 +389,7 @@ namespace Mist{
|
||||||
streamName = opt["sink"].asString();
|
streamName = opt["sink"].asString();
|
||||||
if (!streamName.size()){streamName = opt["source"].asString();}
|
if (!streamName.size()){streamName = opt["source"].asString();}
|
||||||
Util::streamVariables(streamName, opt["source"].asString());
|
Util::streamVariables(streamName, opt["source"].asString());
|
||||||
Util::Config::streamName = opt["source"].asString() + "→" + streamName;
|
Util::streamName = opt["source"].asString() + "→" + streamName;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string EncodeOutputEBML::getTrackType(int tid){return M.getType(tid);}
|
std::string EncodeOutputEBML::getTrackType(int tid){return M.getType(tid);}
|
||||||
|
|
|
@ -227,7 +227,7 @@ namespace Mist{
|
||||||
streamName = opt["sink"].asString();
|
streamName = opt["sink"].asString();
|
||||||
if (!streamName.size()){streamName = opt["source"].asString();}
|
if (!streamName.size()){streamName = opt["source"].asString();}
|
||||||
Util::streamVariables(streamName, opt["source"].asString());
|
Util::streamVariables(streamName, opt["source"].asString());
|
||||||
Util::Config::streamName = opt["source"].asString() + "→" + streamName;
|
Util::streamName = opt["source"].asString() + "→" + streamName;
|
||||||
preRun();
|
preRun();
|
||||||
};
|
};
|
||||||
virtual bool needsLock(){return false;}
|
virtual bool needsLock(){return false;}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "../lib/urireader.cpp"
|
#include "../lib/urireader.cpp"
|
||||||
|
#include "../lib/config.cpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class URITest : public Util::DataCallback{
|
class URITest : public Util::DataCallback{
|
||||||
|
|
Loading…
Add table
Reference in a new issue