SRT edits:

- Increased SRT socket queue from 1 to 100
- Fixed SRT initialization (now clean)
- Made output_ts_base.cpp thread-safe
- Made Output class thread-safe
- SRT TS output can now optionally set open file limit
This commit is contained in:
Ramkoemar 2020-11-19 12:40:21 +01:00 committed by Thulinma
parent 0bd5d742f6
commit 77aa90d48c
8 changed files with 123 additions and 15 deletions

View file

@ -82,6 +82,7 @@ namespace Socket{
}
SRTConnection::SRTConnection(SRTSOCKET alreadyConnected){
initializeEmpty();
sock = alreadyConnected;
}
@ -238,7 +239,7 @@ namespace Socket{
ERROR_MSG("Can't connect SRT Socket: %s", srt_getlasterror_str());
return;
}
if (srt_listen(sock, 1) == SRT_ERROR){
if (srt_listen(sock, 100) == SRT_ERROR){
srt_close(sock);
sock = -1;
ERROR_MSG("Can not listen on Socket");
@ -310,7 +311,7 @@ namespace Socket{
}
return;
}
ERROR_MSG("Unable to send data over socket %" PRId32 ": %s", sock, srt_getlasterror_str());
// ERROR_MSG("Unable to send data over socket %" PRId32 ": %s", sock, srt_getlasterror_str());
if (srt_getsockstate(sock) != SRTS_CONNECTED){close();}
}else{
lastGood = Util::bootMS();
@ -346,6 +347,7 @@ namespace Socket{
outgoing_port = 0;
chunkTransmitSize = 1316;
blocking = false;
timeout = 0;
}
void SRTConnection::setBlocking(bool _blocking){

View file

@ -129,7 +129,7 @@ namespace TS{
bool Packet::FromPointer(const char *data){
memcpy((void *)strBuf, (void *)data, 188);
pos = 188;
return true;
return strBuf[0] == 0x47;
}
/// The deconstructor deletes all space that may be occupied by a Packet.
@ -492,6 +492,39 @@ namespace TS{
tmpBuf += (char)(((time & 0x00000007FLL) << 1) | 0x01);
}
/// Generates a PES Lead-in for a video frame.
/// Prepends the lead-in to variable toSend, assumes toSend's length is all other data.
/// \param len The length of this frame.
/// \param PTS The timestamp of the frame.
void Packet::getPESVideoLeadIn(std::string &outData, unsigned int len, unsigned long long PTS,
unsigned long long offset, bool isAligned, uint64_t bps){
if (len){len += (offset ? 13 : 8);}
if (bps >= 50){
if (len){len += 3;}
}else{
bps = 0;
}
outData.append("\000\000\001\340", 4);
outData += (char)((len >> 8) & 0xFF);
outData += (char)(len & 0xFF);
if (isAligned){
outData.append("\204", 1);
}else{
outData.append("\200", 1);
}
outData += (char)((offset ? 0xC0 : 0x80) | (bps ? 0x10 : 0)); // PTS/DTS + Flags
outData += (char)((offset ? 10 : 5) + (bps ? 3 : 0)); // PESHeaderDataLength
encodePESTimestamp(outData, (offset ? 0x30 : 0x20), PTS + offset);
if (offset){encodePESTimestamp(outData, 0x10, PTS);}
if (bps){
char rate_buf[3];
Bit::htob24(rate_buf, (bps / 50) | 0x800001);
outData.append(rate_buf, 3);
}
}
/// Generates a PES Lead-in for a video frame.
/// Prepends the lead-in to variable toSend, assumes toSend's length is all other data.
/// \param len The length of this frame.
@ -527,6 +560,32 @@ namespace TS{
return tmpStr;
}
/// Generates a PES Lead-in for an audio frame.
/// Prepends the lead-in to variable toSend, assumes toSend's length is all other data.
/// \param len The length of this frame.
/// \param PTS The timestamp of the frame.
void Packet::getPESAudioLeadIn(std::string & outData, unsigned int len, unsigned long long PTS, uint64_t bps){
if (bps >= 50){
len += 3;
}else{
bps = 0;
}
len += 8;
outData.append("\000\000\001\300", 4);
outData += (char)((len & 0xFF00) >> 8); // PES PacketLength
outData += (char)(len & 0x00FF); // PES PacketLength (Cont)
outData += (char)0x84; // isAligned
outData += (char)(0x80 | (bps ? 0x10 : 0)); // PTS/DTS + Flags
outData += (char)(5 + (bps ? 3 : 0)); // PESHeaderDataLength
encodePESTimestamp(outData, 0x20, PTS);
if (bps){
char rate_buf[3];
Bit::htob24(rate_buf, (bps / 50) | 0x800001);
outData.append(rate_buf, 3);
}
}
/// Generates a PES Lead-in for an audio frame.
/// Prepends the lead-in to variable toSend, assumes toSend's length is all other data.
/// \param len The length of this frame.

View file

@ -72,8 +72,11 @@ namespace TS{
void updPos(unsigned int newPos);
// PES helpers
static void getPESVideoLeadIn(std::string & outData, unsigned int len, unsigned long long PTS,
unsigned long long offset, bool isAligned, uint64_t bps = 0);
static std::string &getPESVideoLeadIn(unsigned int len, unsigned long long PTS,
unsigned long long offset, bool isAligned, uint64_t bps = 0);
static void getPESAudioLeadIn(std::string & outData, unsigned int len, unsigned long long PTS, uint64_t bps);
static std::string &getPESAudioLeadIn(unsigned int len, unsigned long long PTS, uint64_t bps = 0);
static std::string &getPESMetaLeadIn(unsigned int len, unsigned long long PTS, uint64_t bps = 0);
static std::string &getPESPS1LeadIn(unsigned int len, unsigned long long PTS, uint64_t bps = 0);