复用代码

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

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);
}