srs
srs copied to clipboard
SRT: Support SRTO_PASSPHRASE without streamid.
有些SRT的设备,不支持streamid,但是有密码选项。
具体参考:Access Control
int SrtTestListenCallback(void* opaq, SRTSOCKET ns, int hsversion,
const struct sockaddr* peeraddr, const char* streamid)
{
using namespace std;
// opaq is used to pass some further chained callbacks
// To reject a connection attempt, return -1.
static const map<string, string> passwd {
{"admin", "thelocalmanager"},
{"user", "verylongpassword"}
};
// Try the "standard interpretation" with username at key u
string username;
static const char stdhdr [] = "#!::";
uint32_t* pattern = (uint32_t*)stdhdr;
bool found = -1;
// Extract a username from the StreamID:
if (strlen(streamid) > 4 && *(uint32_t*)streamid == *pattern)
{
vector<string> items;
Split(streamid+4, ',', back_inserter(items));
for (auto& i: items)
{
vector<string> kv;
Split(i, '=', back_inserter(kv));
if (kv.size() == 2 && kv[0] == "u")
{
username = kv[1];
found = true;
}
}
if (!found)
{
cerr << "TEST: USER NOT FOUND, returning false.\n";
return -1;
}
}
else
{
// By default the whole streamid is username
username = streamid;
}
// When the username of the client is known, the passphrase can be set
// on the socket being accepted (SRTSOCKET ns).
// The remaining part of the SRT handshaking process will check the
// passphrase of the client and accept or reject the connection.
// When not found, it will throw an exception
cerr << "TEST: Accessing user '" << username << "', might throw if not found\n";
string exp_pw = passwd.at(username);
cerr << "TEST: Setting password '" << exp_pw << "' as per user '" << username << "'\n";
srt_setsockflag(ns, SRTO_PASSPHRASE, exp_pw.c_str(), exp_pw.size());
return 0;
}
OBS supports passphrase, URL examples:
srt://IP:port?mode=caller&port=17001&latency=2000000&passphrase=vrslcopmdacrpxdq&pbkeylen=16&inputbw=0&oheadbw=10&maxbw=0
-
The
portparameter should be set to the Listener port (= the same port as the first part of the URL) -
The
latencyparameter is best set to (2000000 = 2 seconds) -
passphraseandpbkeylenshould be configured according to the server. -
https://github.com/Haivision/srt/blob/master/docs/API/API-socket-options.md#srto_pbkeylen Possible values: 0 =PBKEYLEN (default value) 16 = AES-128 (effective value) 24 = AES-192 32 = AES-256
-
The
inputbw=0&oheadbw=10&maxbw=0parameters are set to limit the overhead bandwidth. If these are not set, SRT's built-in error correction mechanism may cause the bitrate to suddenly peak, which could increase transmission errors (depending on your available upstream bandwidth).
TRANS_BY_GPT3
Fixed in SRS 5.0