1
0
Fork 0
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:
winlin 2015-10-13 16:06:37 +08:00
parent ca73534d7e
commit d9f991ed2f
16 changed files with 111 additions and 112 deletions

View file

@ -464,6 +464,29 @@ string srs_path_basename(string path)
return dirname;
}
string srs_path_filename(string path)
{
std::string filename = path;
size_t pos = string::npos;
if ((pos = filename.rfind(".")) != string::npos) {
return filename.substr(0, pos);
}
return filename;
}
string srs_path_filext(string path)
{
size_t pos = string::npos;
if ((pos = path.rfind(".")) != string::npos) {
return path.substr(pos);
}
return "";
}
bool srs_avc_startswith_annexb(SrsBuffer* stream, int* pnb_start_code)
{
@ -471,7 +494,7 @@ bool srs_avc_startswith_annexb(SrsBuffer* stream, int* pnb_start_code)
char* p = bytes;
for (;;) {
if (!stream->require(p - bytes + 3)) {
if (!stream->require((int)(p - bytes + 3))) {
return false;
}

View file

@ -96,10 +96,14 @@ extern int srs_create_dir_recursively(std::string dir);
// whether path exists.
extern bool srs_path_exists(std::string path);
// get the dirname of path
// get the dirname of path, for instance, filename("/live/livestream")="/live"
extern std::string srs_path_dirname(std::string path);
// get the basename of path
// get the basename of path, for instance, filename("/live/livestream")="livestream"
extern std::string srs_path_basename(std::string path);
// get the filename of path, for instance, filename("livestream.flv")="livestream"
extern std::string srs_path_filename(std::string path);
// get the file extension of path, for instance, filext("live.flv")=".flv"
extern std::string srs_path_filext(std::string path);
/**
* whether stream starts with the avc NALU in "AnnexB"