复用代码

This commit is contained in:
xiongziliang 2020-09-26 09:39:38 +08:00
parent 2ae97a66ea
commit 4f42f508d5
4 changed files with 4 additions and 22 deletions

@ -1 +1 @@
Subproject commit 8611e88c2eda178973662dcfe180691ff1d8ba35
Subproject commit f564c7ed27f141a3b5f08d239970b24d700a1244

View File

@ -298,12 +298,6 @@ static bool makeFolderMenu(const string &httpPath, const string &strFullPath, st
return true;
}
//字符串是否以xx结尾
static bool end_of(const string &str, const string &substr){
auto pos = str.rfind(substr);
return pos != string::npos && pos == str.size() - substr.size();
};
//拦截hls的播放请求
static bool emitHlsPlayed(const Parser &parser, const MediaInfo &mediaInfo, const HttpSession::HttpAccessPathInvoker &invoker,TcpSession &sender){
//访问的hls.m3u8结尾我们转换成kBroadcastMediaPlayed事件
@ -488,7 +482,7 @@ static string pathCat(const string &a, const string &b){
* @param cb
*/
static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo &mediaInfo, const string &strFile, const HttpFileManager::invoker &cb) {
bool is_hls = end_of(strFile, kHlsSuffix);
bool is_hls = end_with(strFile, kHlsSuffix);
bool file_exist = File::is_file(strFile.data());
if (!is_hls && !file_exist) {
//文件不存在且不是hls,那么直接返回404

View File

@ -17,12 +17,6 @@ using namespace toolkit;
namespace mediakit {
//字符串是否以xx结尾
static bool end_of(const string &str, const string &substr){
auto pos = str.rfind(substr);
return pos != string::npos && pos == str.size() - substr.size();
}
PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &poller,const string &url_in) {
static auto releasePlayer = [](PlayerBase *ptr){
onceToken token(nullptr,[&](){
@ -54,7 +48,7 @@ PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &poller,const st
return PlayerBase::Ptr(new RtmpPlayerImp(poller),releasePlayer);
}
if ((strcasecmp("http",prefix.data()) == 0 || strcasecmp("https",prefix.data()) == 0) && end_of(url, ".m3u8")) {
if ((strcasecmp("http",prefix.data()) == 0 || strcasecmp("https",prefix.data()) == 0) && end_with(url, ".m3u8")) {
return PlayerBase::Ptr(new HlsPlayerImp(poller),releasePlayer);
}

View File

@ -126,12 +126,6 @@ void RtspSession::onRecv(const Buffer::Ptr &buf) {
}
}
//字符串是否以xx结尾
static inline bool end_of(const string &str, const string &substr){
auto pos = str.rfind(substr);
return pos != string::npos && pos == str.size() - substr.size();
}
void RtspSession::onWholeRtspPacket(Parser &parser) {
string method = parser.Method(); //提取出请求命令字
_cseq = atoi(parser["CSeq"].data());
@ -224,7 +218,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
}
auto full_url = parser.FullUrl();
if(end_of(full_url,".sdp")){
if(end_with(full_url,".sdp")){
//去除.sdp后缀防止EasyDarwin推流器强制添加.sdp后缀
full_url = full_url.substr(0,full_url.length() - 4);
_media_info.parse(full_url);