Various small fixes to SRT sockets and SRT socket statistics
This commit is contained in:
parent
0af85de22d
commit
cac86fff57
8 changed files with 89 additions and 25 deletions
|
@ -76,6 +76,38 @@ namespace Socket{
|
|||
lastGood = Util::bootMS();
|
||||
}
|
||||
|
||||
// Copy constructor
|
||||
SRTConnection::SRTConnection(const SRTConnection &rhs){
|
||||
initializeEmpty();
|
||||
*this = rhs;
|
||||
}
|
||||
|
||||
// Assignment constructor
|
||||
SRTConnection &SRTConnection::operator=(const SRTConnection &rhs){
|
||||
close();
|
||||
initializeEmpty();
|
||||
if (!rhs){return *this;}
|
||||
memcpy(&remoteaddr, &(rhs.remoteaddr), sizeof(sockaddr_in6));
|
||||
direction = rhs.direction;
|
||||
remotehost = rhs.remotehost;
|
||||
sock = rhs.sock;
|
||||
performanceMonitor = rhs.performanceMonitor;
|
||||
host = rhs.host;
|
||||
outgoing_port = rhs.outgoing_port;
|
||||
prev_pktseq = rhs.prev_pktseq;
|
||||
lastGood = rhs.lastGood;
|
||||
chunkTransmitSize = rhs.chunkTransmitSize;
|
||||
adapter = rhs.adapter;
|
||||
modeName = rhs.modeName;
|
||||
timeout = rhs.timeout;
|
||||
tsbpdMode = rhs.tsbpdMode;
|
||||
params = rhs.params;
|
||||
blocking = rhs.blocking;
|
||||
getBinHost();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
SRTConnection::SRTConnection(const std::string &_host, int _port, const std::string &_direction,
|
||||
const std::map<std::string, std::string> &_params){
|
||||
connect(_host, _port, _direction, _params);
|
||||
|
@ -101,7 +133,7 @@ namespace Socket{
|
|||
memcpy(tmpBuffer + 12, &(reinterpret_cast<const sockaddr_in *>(&remoteaddr)->sin_addr.s_addr), 4);
|
||||
break;
|
||||
case AF_INET6: memcpy(tmpBuffer, &(remoteaddr.sin6_addr.s6_addr), 16); break;
|
||||
default: return ""; break;
|
||||
default: memset(tmpBuffer, 0, 16); break;
|
||||
}
|
||||
return std::string(tmpBuffer, 16);
|
||||
}
|
||||
|
@ -343,6 +375,7 @@ namespace Socket{
|
|||
}
|
||||
|
||||
void SRTConnection::initializeEmpty(){
|
||||
memset(&performanceMonitor, 0, sizeof(performanceMonitor));
|
||||
prev_pktseq = 0;
|
||||
sock = SRT_INVALID_SOCK;
|
||||
outgoing_port = 0;
|
||||
|
@ -494,11 +527,12 @@ namespace Socket{
|
|||
}
|
||||
|
||||
r.direction = direction;
|
||||
r.params = conn.params;
|
||||
r.postConfigureSocket();
|
||||
r.setBlocking(!nonblock);
|
||||
static char addrconv[INET6_ADDRSTRLEN];
|
||||
|
||||
r.remoteaddr = tmpaddr;
|
||||
memcpy(&(r.remoteaddr), &tmpaddr, sizeof(tmpaddr));
|
||||
if (tmpaddr.sin6_family == AF_INET6){
|
||||
r.remotehost = inet_ntop(AF_INET6, &(tmpaddr.sin6_addr), addrconv, INET6_ADDRSTRLEN);
|
||||
HIGH_MSG("IPv6 addr [%s]", r.remotehost.c_str());
|
||||
|
@ -508,6 +542,7 @@ namespace Socket{
|
|||
HIGH_MSG("IPv4 addr [%s]", r.remotehost.c_str());
|
||||
}
|
||||
INFO_MSG("Accepted a socket coming from %s", r.remotehost.c_str());
|
||||
r.getBinHost();
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,16 @@ namespace Socket{
|
|||
}// namespace SockOpt
|
||||
}// namespace SRT
|
||||
|
||||
//Advance declaration so we can make it a friend of SRTConnection
|
||||
class SRTServer;
|
||||
|
||||
class SRTConnection{
|
||||
friend class SRTServer;
|
||||
public:
|
||||
SRTConnection();
|
||||
// copy/assignment constructors
|
||||
SRTConnection(const SRTConnection &rhs);
|
||||
SRTConnection &operator=(const SRTConnection &rhs);
|
||||
SRTConnection(SRTSOCKET alreadyConnected);
|
||||
SRTConnection(const std::string &_host, int _port, const std::string &_direction = "input",
|
||||
const paramList &_params = paramList());
|
||||
|
|
|
@ -15,6 +15,14 @@ tthread::recursive_mutex tMutex;
|
|||
|
||||
namespace TS{
|
||||
|
||||
Assembler::Assembler(){
|
||||
isLive = false;
|
||||
}
|
||||
|
||||
void Assembler::setLive(bool live){
|
||||
isLive = live;
|
||||
}
|
||||
|
||||
bool Assembler::assemble(Stream & TSStrm, const char * ptr, size_t len, bool parse, uint64_t bytePos){
|
||||
bool ret = false;
|
||||
size_t offset = 0;
|
||||
|
@ -30,7 +38,7 @@ namespace TS{
|
|||
tsBuf.FromPointer(leftData);
|
||||
if (!ret && tsBuf.getUnitStart()){ret = true;}
|
||||
if (parse){
|
||||
TSStrm.parse(tsBuf, bytePos);
|
||||
TSStrm.parse(tsBuf, isLive?0:bytePos);
|
||||
}else{
|
||||
TSStrm.add(tsBuf);
|
||||
if (!TSStrm.isDataTrack(tsBuf.getPID())){TSStrm.parse(tsBuf.getPID());}
|
||||
|
@ -59,7 +67,7 @@ namespace TS{
|
|||
tsBuf.FromPointer(ptr + offset);
|
||||
if (!ret && tsBuf.getUnitStart()){ret = true;}
|
||||
if (parse){
|
||||
TSStrm.parse(tsBuf, bytePos);
|
||||
TSStrm.parse(tsBuf, isLive?0:bytePos);
|
||||
}else{
|
||||
TSStrm.add(tsBuf);
|
||||
if (!TSStrm.isDataTrack(tsBuf.getPID())){TSStrm.parse(tsBuf.getPID());}
|
||||
|
|
|
@ -112,9 +112,12 @@ namespace TS{
|
|||
|
||||
class Assembler{
|
||||
public:
|
||||
Assembler();
|
||||
bool assemble(Stream & TSStrm, const char * ptr, size_t len, bool parse = false, uint64_t bytePos = 0);
|
||||
void clear();
|
||||
void setLive(bool live = true);
|
||||
private:
|
||||
bool isLive;
|
||||
Util::ResizeablePointer leftData;
|
||||
TS::Packet tsBuf;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue