1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

SRT: Upgrade libsrt from 1.4.1 to 1.5.1. v6.0.12 (#3362)

Co-authored-by: winlin <winlin@vip.126.com>
This commit is contained in:
john 2023-01-04 19:56:33 +08:00 committed by GitHub
parent 7a56208f2f
commit fe086dfc31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
143 changed files with 38185 additions and 15108 deletions

View file

@ -43,6 +43,8 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#include "platform_sys.h"
#include <cstring>
#include <string>
#include <sstream>
@ -50,32 +52,33 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <algorithm>
#include "udt.h"
#include "api.h"
#include "core.h"
#include "handshake.h"
#include "utilities.h"
using namespace std;
using namespace srt;
CHandShake::CHandShake():
m_iVersion(0),
m_iType(0), // Universal: UDT_UNDEFINED or no flags
m_iISN(0),
m_iMSS(0),
m_iFlightFlagSize(0),
m_iReqType(URQ_WAVEAHAND),
m_iID(0),
m_iCookie(0),
m_extension(false)
srt::CHandShake::CHandShake()
: m_iVersion(0)
, m_iType(0) // Universal: UDT_UNDEFINED or no flags
, m_iISN(0)
, m_iMSS(0)
, m_iFlightFlagSize(0)
, m_iReqType(URQ_WAVEAHAND)
, m_iID(0)
, m_iCookie(0)
, m_extension(false)
{
for (int i = 0; i < 4; ++ i)
m_piPeerIP[i] = 0;
}
int CHandShake::store_to(char* buf, ref_t<size_t> r_size)
int srt::CHandShake::store_to(char* buf, size_t& w_size)
{
size_t& size = *r_size;
if (size < m_iContentSize)
if (w_size < m_iContentSize)
return -1;
int32_t* p = reinterpret_cast<int32_t*>(buf);
@ -90,12 +93,12 @@ int CHandShake::store_to(char* buf, ref_t<size_t> r_size)
for (int i = 0; i < 4; ++ i)
*p++ = m_piPeerIP[i];
size = m_iContentSize;
w_size = m_iContentSize;
return 0;
}
int CHandShake::load_from(const char* buf, size_t size)
int srt::CHandShake::load_from(const char* buf, size_t size)
{
if (size < m_iContentSize)
return -1;
@ -118,6 +121,8 @@ int CHandShake::load_from(const char* buf, size_t size)
#ifdef ENABLE_LOGGING
namespace srt
{
const char* srt_rejectreason_name [] = {
"UNKNOWN",
"SYSTEM",
@ -134,15 +139,31 @@ const char* srt_rejectreason_name [] = {
"MESSAGEAPI",
"CONGESTION",
"FILTER",
"GROUP",
"TIMEOUT"
};
}
std::string RequestTypeStr(UDTRequestType rq)
std::string srt::RequestTypeStr(UDTRequestType rq)
{
if (rq >= URQ_FAILURE_TYPES)
{
SRT_REJECT_REASON rej = RejectReasonForURQ(rq);
int id = rej;
return std::string("ERROR:") + srt_rejectreason_name[id];
std::ostringstream rt;
rt << "ERROR:";
int id = RejectReasonForURQ(rq);
if (id < (int) Size(srt_rejectreason_name))
rt << srt_rejectreason_name[id];
else if (id < SRT_REJC_USERDEFINED)
{
if (id < SRT_REJC_PREDEFINED)
rt << "UNKNOWN:" << id;
else
rt << "PREDEFINED:" << (id - SRT_REJC_PREDEFINED);
}
else
rt << "USERDEFINED:" << (id - SRT_REJC_USERDEFINED);
return rt.str();
}
switch ( rq )
@ -156,7 +177,7 @@ std::string RequestTypeStr(UDTRequestType rq)
}
}
string CHandShake::RdvStateStr(CHandShake::RendezvousState s)
string srt::CHandShake::RdvStateStr(CHandShake::RendezvousState s)
{
switch (s)
{
@ -172,11 +193,22 @@ string CHandShake::RdvStateStr(CHandShake::RendezvousState s)
}
#endif
string CHandShake::show()
bool srt::CHandShake::valid()
{
if (m_iVersion < CUDT::HS_VERSION_UDT4
|| m_iISN < 0 || m_iISN >= CSeqNo::m_iMaxSeqNo
|| m_iMSS < 32
|| m_iFlightFlagSize < 2)
return false;
return true;
}
string srt::CHandShake::show()
{
ostringstream so;
so << "version=" << m_iVersion << " type=" << hex << m_iType << dec
so << "version=" << m_iVersion << " type=0x" << hex << m_iType << dec
<< " ISN=" << m_iISN << " MSS=" << m_iMSS << " FLW=" << m_iFlightFlagSize
<< " reqtype=" << RequestTypeStr(m_iReqType) << " srcID=" << m_iID
<< " cookie=" << hex << m_iCookie << dec
@ -191,9 +223,12 @@ string CHandShake::show()
// CHandShake, not CUDT.
if ( m_iVersion > CUDT::HS_VERSION_UDT4 )
{
so << "EXT: ";
if (m_iType == 0) // no flags at all
so << "none";
const int flags = SrtHSRequest::SRT_HSTYPE_HSFLAGS::unwrap(m_iType);
so << "FLAGS: ";
if (flags == SrtHSRequest::SRT_MAGIC_CODE)
so << "MAGIC";
else if (m_iType == 0)
so << "NONE"; // no flags and no advertised pbkeylen
else
so << ExtensionFlagStr(m_iType);
}
@ -201,7 +236,7 @@ string CHandShake::show()
return so.str();
}
string CHandShake::ExtensionFlagStr(int32_t fl)
string srt::CHandShake::ExtensionFlagStr(int32_t fl)
{
std::ostringstream out;
if ( fl & HS_EXT_HSREQ )
@ -211,7 +246,7 @@ string CHandShake::ExtensionFlagStr(int32_t fl)
if ( fl & HS_EXT_CONFIG )
out << " config";
int kl = SrtHSRequest::SRT_HSTYPE_ENCFLAGS::unwrap(fl) << 6;
const int kl = SrtHSRequest::SRT_HSTYPE_ENCFLAGS::unwrap(fl) << 6;
if (kl != 0)
{
out << " AES-" << kl;
@ -228,7 +263,7 @@ string CHandShake::ExtensionFlagStr(int32_t fl)
// XXX This code isn't currently used. Left here because it can
// be used in future, should any refactoring for the "manual word placement"
// code be done.
bool SrtHSRequest::serialize(char* buf, size_t size) const
bool srt::SrtHSRequest::serialize(char* buf, size_t size) const
{
if (size < SRT_HS_SIZE)
return false;
@ -243,7 +278,7 @@ bool SrtHSRequest::serialize(char* buf, size_t size) const
}
bool SrtHSRequest::deserialize(const char* buf, size_t size)
bool srt::SrtHSRequest::deserialize(const char* buf, size_t size)
{
m_iSrtVersion = 0; // just to let users recognize if it succeeded or not.
@ -258,3 +293,35 @@ bool SrtHSRequest::deserialize(const char* buf, size_t size)
m_iSrtReserved = (*p++);
return true;
}
std::string srt::SrtFlagString(int32_t flags)
{
#define LEN(arr) (sizeof (arr)/(sizeof ((arr)[0])))
std::string output;
static std::string namera[] = { "TSBPD-snd", "TSBPD-rcv", "haicrypt", "TLPktDrop", "NAKReport", "ReXmitFlag", "StreamAPI" };
size_t i = 0;
for (; i < LEN(namera); ++i)
{
if ((flags & 1) == 1)
{
output += "+" + namera[i] + " ";
}
else
{
output += "-" + namera[i] + " ";
}
flags >>= 1;
}
#undef LEN
if (flags != 0)
{
output += "+unknown";
}
return output;
}