mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
use system utility for string finds
This commit is contained in:
parent
ca73534d7e
commit
d9f991ed2f
16 changed files with 111 additions and 112 deletions
|
|
@ -268,19 +268,8 @@ int SrsDynamicHttpConn::connect()
|
|||
// parse uri
|
||||
if (!req) {
|
||||
req = new SrsRequest();
|
||||
|
||||
size_t pos = string::npos;
|
||||
string uri = req->tcUrl = output;
|
||||
|
||||
// tcUrl, stream
|
||||
if ((pos = uri.rfind("/")) != string::npos) {
|
||||
req->stream = uri.substr(pos + 1);
|
||||
req->tcUrl = uri = uri.substr(0, pos);
|
||||
}
|
||||
|
||||
srs_discovery_tc_url(req->tcUrl,
|
||||
req->schema, req->host, req->vhost, req->app, req->port,
|
||||
req->param);
|
||||
srs_parse_rtmp_url(output, req->tcUrl, req->stream);
|
||||
srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->port, req->param);
|
||||
}
|
||||
|
||||
// connect host.
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ int SrsFlvSegment::open(bool use_tmp_file)
|
|||
bool fresh_flv_file = !srs_path_exists(path);
|
||||
|
||||
// create dir first.
|
||||
std::string dir = path.substr(0, path.rfind("/"));
|
||||
std::string dir = srs_path_dirname(path);
|
||||
if ((ret = srs_create_dir_recursively(dir)) != ERROR_SUCCESS) {
|
||||
srs_error("create dir=%s failed. ret=%d", dir.c_str(), ret);
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -572,12 +572,7 @@ int SrsHttpMessage::update(string url, bool allow_jsonp, http_parser* header, Sr
|
|||
}
|
||||
|
||||
// parse ext.
|
||||
_ext = _uri->get_path();
|
||||
if ((pos = _ext.rfind(".")) != string::npos) {
|
||||
_ext = _ext.substr(pos);
|
||||
} else {
|
||||
_ext = "";
|
||||
}
|
||||
_ext = srs_path_filext(_uri->get_path());
|
||||
|
||||
// parse jsonp request message.
|
||||
if (allow_jsonp) {
|
||||
|
|
@ -816,23 +811,23 @@ SrsRequest* SrsHttpMessage::to_request(string vhost)
|
|||
{
|
||||
SrsRequest* req = new SrsRequest();
|
||||
|
||||
req->app = _uri->get_path();
|
||||
size_t pos = string::npos;
|
||||
if ((pos = req->app.rfind("/")) != string::npos) {
|
||||
req->stream = req->app.substr(pos + 1);
|
||||
req->app = req->app.substr(0, pos);
|
||||
}
|
||||
if ((pos = req->stream.rfind(".")) != string::npos) {
|
||||
req->stream = req->stream.substr(0, pos);
|
||||
}
|
||||
// http path, for instance, /live/livestream.flv, parse to
|
||||
// app: /live
|
||||
// stream: livestream.flv
|
||||
srs_parse_rtmp_url(_uri->get_path(), req->app, req->stream);
|
||||
|
||||
req->tcUrl = "rtmp://" + vhost + req->app;
|
||||
// trim the start slash, for instance, /live to live
|
||||
req->app = srs_string_trim_start(req->app, "/");
|
||||
|
||||
// remove the extension, for instance, livestream.flv to livestream
|
||||
req->stream = srs_path_filename(req->stream);
|
||||
|
||||
// generate others.
|
||||
req->tcUrl = "rtmp://" + vhost + "/" + req->app;
|
||||
req->pageUrl = get_request_header("Referer");
|
||||
req->objectEncoding = 0;
|
||||
|
||||
srs_discovery_tc_url(req->tcUrl,
|
||||
req->schema, req->host, req->vhost, req->app, req->port,
|
||||
req->param);
|
||||
srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->port, req->param);
|
||||
req->strip();
|
||||
|
||||
return req;
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ int SrsHttpStaticServer::initialize()
|
|||
mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/");
|
||||
|
||||
// the dir mount must always ends with "/"
|
||||
if (mount != "/" && mount.rfind("/") != mount.length() - 1) {
|
||||
if (mount != "/" && !srs_string_ends_with(mount, "/")) {
|
||||
mount += "/";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -611,11 +611,7 @@ SrsLiveEntry::SrsLiveEntry(std::string m, bool h)
|
|||
req = NULL;
|
||||
source = NULL;
|
||||
|
||||
std::string ext;
|
||||
size_t pos = string::npos;
|
||||
if ((pos = m.rfind(".")) != string::npos) {
|
||||
ext = m.substr(pos);
|
||||
}
|
||||
std::string ext = srs_path_filext(m);
|
||||
_is_flv = (ext == ".flv");
|
||||
_is_ts = (ext == ".ts");
|
||||
_is_mp3 = (ext == ".mp3");
|
||||
|
|
@ -1319,10 +1315,7 @@ string SrsHttpStreamServer::hls_mount_generate(SrsRequest* r, string uri, string
|
|||
std::string mount = tmpl;
|
||||
|
||||
// the ts is relative from the m3u8, the same start dir.
|
||||
size_t pos = string::npos;
|
||||
if ((pos = mount.rfind("/")) != string::npos) {
|
||||
mount = mount.substr(0, pos);
|
||||
}
|
||||
mount = srs_path_dirname(mount);
|
||||
|
||||
// replace the vhost variable
|
||||
mount = srs_string_replace(mount, "[vhost]", r->vhost);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ using namespace std;
|
|||
#include <srs_app_pithy_print.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
#include <srs_app_utility.hpp>
|
||||
#include <srs_protocol_utility.hpp>
|
||||
|
||||
// when error, ingester sleep for a while and retry.
|
||||
// ingest never sleep a long time, for we must start the stream ASAP.
|
||||
|
|
@ -354,17 +355,9 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S
|
|||
}
|
||||
|
||||
// find the app and stream in rtmp url
|
||||
std::string url = output;
|
||||
std::string app, stream;
|
||||
size_t pos = std::string::npos;
|
||||
if ((pos = url.rfind("/")) != std::string::npos) {
|
||||
stream = url.substr(pos + 1);
|
||||
url = url.substr(0, pos);
|
||||
}
|
||||
if ((pos = url.rfind("/")) != std::string::npos) {
|
||||
app = url.substr(pos + 1);
|
||||
url = url.substr(0, pos);
|
||||
}
|
||||
srs_parse_rtmp_url(output, app, stream);
|
||||
size_t pos;
|
||||
if ((pos = app.rfind("?")) != std::string::npos) {
|
||||
app = app.substr(0, pos);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -611,19 +611,8 @@ int SrsMpegtsOverUdp::connect()
|
|||
// parse uri
|
||||
if (!req) {
|
||||
req = new SrsRequest();
|
||||
|
||||
size_t pos = string::npos;
|
||||
string uri = req->tcUrl = output;
|
||||
|
||||
// tcUrl, stream
|
||||
if ((pos = uri.rfind("/")) != string::npos) {
|
||||
req->stream = uri.substr(pos + 1);
|
||||
req->tcUrl = uri = uri.substr(0, pos);
|
||||
}
|
||||
|
||||
srs_discovery_tc_url(req->tcUrl,
|
||||
req->schema, req->host, req->vhost, req->app, req->port,
|
||||
req->param);
|
||||
srs_parse_rtmp_url(output, req->tcUrl, req->stream);
|
||||
srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->port, req->param);
|
||||
}
|
||||
|
||||
// connect host.
|
||||
|
|
|
|||
|
|
@ -270,10 +270,7 @@ int SrsRtspConn::do_cycle()
|
|||
if ((pos = rtsp_tcUrl.rfind(".sdp")) != string::npos) {
|
||||
rtsp_tcUrl = rtsp_tcUrl.substr(0, pos);
|
||||
}
|
||||
if ((pos = rtsp_tcUrl.rfind("/")) != string::npos) {
|
||||
rtsp_stream = rtsp_tcUrl.substr(pos + 1);
|
||||
rtsp_tcUrl = rtsp_tcUrl.substr(0, pos);
|
||||
}
|
||||
srs_parse_rtmp_url(rtsp_tcUrl, rtsp_tcUrl, rtsp_stream);
|
||||
|
||||
srs_assert(req->sdp);
|
||||
video_id = ::atoi(req->sdp->video_stream_id.c_str());
|
||||
|
|
@ -651,8 +648,6 @@ int SrsRtspConn::connect()
|
|||
|
||||
// parse uri
|
||||
if (!req) {
|
||||
req = new SrsRequest();
|
||||
|
||||
std::string schema, host, vhost, app, port, param;
|
||||
srs_discovery_tc_url(rtsp_tcUrl, schema, host, vhost, app, port, param);
|
||||
|
||||
|
|
@ -660,19 +655,10 @@ int SrsRtspConn::connect()
|
|||
std::string output = output_template;
|
||||
output = srs_string_replace(output, "[app]", app);
|
||||
output = srs_string_replace(output, "[stream]", rtsp_stream);
|
||||
|
||||
size_t pos = string::npos;
|
||||
string uri = req->tcUrl = output;
|
||||
|
||||
// tcUrl, stream
|
||||
if ((pos = uri.rfind("/")) != string::npos) {
|
||||
req->stream = uri.substr(pos + 1);
|
||||
req->tcUrl = uri = uri.substr(0, pos);
|
||||
}
|
||||
|
||||
srs_discovery_tc_url(req->tcUrl,
|
||||
req->schema, req->host, req->vhost, req->app, req->port,
|
||||
req->param);
|
||||
|
||||
req = new SrsRequest();
|
||||
srs_parse_rtmp_url(output, req->tcUrl, req->stream);
|
||||
srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->port, req->param);
|
||||
}
|
||||
|
||||
// connect host.
|
||||
|
|
|
|||
|
|
@ -202,6 +202,17 @@ public:
|
|||
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
|
||||
};
|
||||
|
||||
/**
|
||||
* the common tcp client, to connect to specified TCP server,
|
||||
* reconnect and close the connection.
|
||||
*/
|
||||
class SrsTcpClient
|
||||
{
|
||||
public:
|
||||
SrsTcpClient();
|
||||
virtual ~SrsTcpClient();
|
||||
};
|
||||
|
||||
// initialize st, requires epoll.
|
||||
extern int srs_st_init();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue