hls播放器兼容带参数的url

This commit is contained in:
xiongziliang 2020-05-21 14:10:27 +08:00
parent c6064406eb
commit c02438f9c8

View File

@ -23,14 +23,20 @@ static bool end_of(const string &str, const string &substr){
return pos != string::npos && pos == str.size() - substr.size(); return pos != string::npos && pos == str.size() - substr.size();
} }
PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &poller,const string &strUrl) { PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &poller,const string &url_in) {
static auto releasePlayer = [](PlayerBase *ptr){ static auto releasePlayer = [](PlayerBase *ptr){
onceToken token(nullptr,[&](){ onceToken token(nullptr,[&](){
delete ptr; delete ptr;
}); });
ptr->teardown(); ptr->teardown();
}; };
string prefix = FindField(strUrl.data(), NULL, "://"); string url = url_in;
string prefix = FindField(url.data(), NULL, "://");
auto pos = url.find('?');
if (pos != string::npos) {
//去除?后面的字符串
url = url.substr(0, pos);
}
if (strcasecmp("rtsps",prefix.data()) == 0) { if (strcasecmp("rtsps",prefix.data()) == 0) {
return PlayerBase::Ptr(new TcpClientWithSSL<RtspPlayerImp>(poller),releasePlayer); return PlayerBase::Ptr(new TcpClientWithSSL<RtspPlayerImp>(poller),releasePlayer);
@ -48,7 +54,7 @@ PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &poller,const st
return PlayerBase::Ptr(new RtmpPlayerImp(poller),releasePlayer); return PlayerBase::Ptr(new RtmpPlayerImp(poller),releasePlayer);
} }
if ((strcasecmp("http",prefix.data()) == 0 || strcasecmp("https",prefix.data()) == 0) && end_of(strUrl, ".m3u8")) { if ((strcasecmp("http",prefix.data()) == 0 || strcasecmp("https",prefix.data()) == 0) && end_of(url, ".m3u8")) {
return PlayerBase::Ptr(new HlsPlayerImp(poller),releasePlayer); return PlayerBase::Ptr(new HlsPlayerImp(poller),releasePlayer);
} }