mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTMP: Refine code for gussing stream by app.
This commit is contained in:
parent
96add9be3d
commit
9bd3c51818
4 changed files with 79 additions and 22 deletions
|
@ -459,28 +459,9 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
|
||||||
|
|
||||||
// guess stream name
|
// guess stream name
|
||||||
if (req->stream.empty()) {
|
if (req->stream.empty()) {
|
||||||
srs_trace("client no stream, guess stream from app=%s and param=%s", req->app.c_str(), req->param.c_str());
|
string app = req->app, param = req->param;
|
||||||
|
srs_guess_stream_by_app(req->app, req->param, req->stream);
|
||||||
size_t pos = std::string::npos;
|
srs_trace("Guessing by app=%s, param=%s to app=%s, param=%s, stream=%s", app.c_str(), param.c_str(), req->app.c_str(), req->param.c_str(), req->stream.c_str());
|
||||||
std::string app = req->app;
|
|
||||||
std::string param = req->param;
|
|
||||||
|
|
||||||
// app
|
|
||||||
if ((pos = app.find("/")) != std::string::npos) {
|
|
||||||
req->app = app.substr(0, pos);
|
|
||||||
req->stream = app.substr(pos + 1);
|
|
||||||
if ((pos = req->stream.find("?")) != std::string::npos) {
|
|
||||||
req->stream = req->stream.substr(0, pos);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// param
|
|
||||||
if ((pos = param.find("/")) != std::string::npos) {
|
|
||||||
req->stream = param.substr(pos + 1);
|
|
||||||
if ((pos = req->stream.find("?")) != std::string::npos) {
|
|
||||||
req->stream = req->stream.substr(0, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req->strip();
|
req->strip();
|
||||||
|
|
|
@ -137,6 +137,29 @@ void srs_discovery_tc_url(string tcUrl, string& schema, string& host, string& vh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void srs_guess_stream_by_app(string& app, string& param, string& stream)
|
||||||
|
{
|
||||||
|
size_t pos = std::string::npos;
|
||||||
|
|
||||||
|
// Extract stream from app, if contains slash.
|
||||||
|
if ((pos = app.find("/")) != std::string::npos) {
|
||||||
|
stream = app.substr(pos + 1);
|
||||||
|
app = app.substr(0, pos);
|
||||||
|
|
||||||
|
if ((pos = stream.find("?")) != std::string::npos) {
|
||||||
|
param = stream.substr(pos);
|
||||||
|
stream = stream.substr(0, pos);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract stream from param, if contains slash.
|
||||||
|
if ((pos = param.find("/")) != std::string::npos) {
|
||||||
|
stream = param.substr(pos + 1);
|
||||||
|
param = param.substr(0, pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void srs_parse_query_string(string q, map<string,string>& query)
|
void srs_parse_query_string(string q, map<string,string>& query)
|
||||||
{
|
{
|
||||||
// query string flags.
|
// query string flags.
|
||||||
|
|
|
@ -52,6 +52,12 @@ class ISrsProtocolReadWriter;
|
||||||
extern void srs_discovery_tc_url(std::string tcUrl, std::string& schema, std::string& host, std::string& vhost, std::string& app,
|
extern void srs_discovery_tc_url(std::string tcUrl, std::string& schema, std::string& host, std::string& vhost, std::string& app,
|
||||||
std::string& stream, int& port, std::string& param);
|
std::string& stream, int& port, std::string& param);
|
||||||
|
|
||||||
|
// Guessing stream by app and param, to make OBS happy. For example:
|
||||||
|
// rtmp://ip/live/livestream
|
||||||
|
// rtmp://ip/live/livestream?secret=xxx
|
||||||
|
// rtmp://ip/live?secret=xxx/livestream
|
||||||
|
extern void srs_guess_stream_by_app(std::string& app, std::string& param, std::string& stream);
|
||||||
|
|
||||||
// parse query string to map(k,v).
|
// parse query string to map(k,v).
|
||||||
// must format as key=value&...&keyN=valueN
|
// must format as key=value&...&keyN=valueN
|
||||||
extern void srs_parse_query_string(std::string q, std::map<std::string, std::string>& query);
|
extern void srs_parse_query_string(std::string q, std::map<std::string, std::string>& query);
|
||||||
|
|
|
@ -3574,3 +3574,50 @@ VOID TEST(ProtocolRTMPTest, DiscoveryTcUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VOID TEST(ProtocolRTMPTest, GuessingStream)
|
||||||
|
{
|
||||||
|
// Stream in app without params.
|
||||||
|
if (true) {
|
||||||
|
string app = "live/livestream", param = "", stream = "";
|
||||||
|
srs_guess_stream_by_app(app, param, stream);
|
||||||
|
EXPECT_STREQ("live", app.c_str());
|
||||||
|
EXPECT_STREQ("livestream", stream.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stream in app with params.
|
||||||
|
if (true) {
|
||||||
|
string app = "live/livestream", param = "?secret=xxx", stream = "";
|
||||||
|
srs_guess_stream_by_app(app, param, stream);
|
||||||
|
EXPECT_STREQ("live", app.c_str());
|
||||||
|
EXPECT_STREQ("livestream", stream.c_str());
|
||||||
|
EXPECT_STREQ("?secret=xxx", param.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stream in app with params.
|
||||||
|
if (true) {
|
||||||
|
string app = "live/livestream?secret=xxx", param = "", stream = "";
|
||||||
|
srs_guess_stream_by_app(app, param, stream);
|
||||||
|
EXPECT_STREQ("live", app.c_str());
|
||||||
|
EXPECT_STREQ("livestream", stream.c_str());
|
||||||
|
EXPECT_STREQ("?secret=xxx", param.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stream in param.
|
||||||
|
if (true) {
|
||||||
|
string app = "live", param = "?secret=xxx/livestream", stream = "";
|
||||||
|
srs_guess_stream_by_app(app, param, stream);
|
||||||
|
EXPECT_STREQ("live", app.c_str());
|
||||||
|
EXPECT_STREQ("livestream", stream.c_str());
|
||||||
|
EXPECT_STREQ("?secret=xxx", param.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// No stream.
|
||||||
|
if (true) {
|
||||||
|
string app = "live", param = "?secret=xxx", stream = "";
|
||||||
|
srs_guess_stream_by_app(app, param, stream);
|
||||||
|
EXPECT_STREQ("live", app.c_str());
|
||||||
|
EXPECT_STREQ("", stream.c_str());
|
||||||
|
EXPECT_STREQ("?secret=xxx", param.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue