diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 410d4ec2..f1774fe7 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -415,6 +415,7 @@ const string kWaitTrackReady = "wait_track_ready"; const string kPlayTrack = "play_track"; const string kProxyUrl = "proxy_url"; const string kRtspSpeed = "rtsp_speed"; +const string kSchema = "schema"; const string kLatency = "latency"; const string kPassPhrase = "passPhrase"; const string kCustomHeader = "custom_header"; diff --git a/src/Common/config.h b/src/Common/config.h index 4ee4c76e..d33b71f7 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -638,6 +638,8 @@ extern const std::string kLatency; extern const std::string kPassPhrase; // 自定义rtsp/http头 extern const std::string kCustomHeader; +// 指定采用什么播放协议 +extern const std::string kSchema; } // namespace Client } // namespace mediakit diff --git a/src/Player/MediaPlayer.cpp b/src/Player/MediaPlayer.cpp index 8ed4cc2f..1a36147f 100644 --- a/src/Player/MediaPlayer.cpp +++ b/src/Player/MediaPlayer.cpp @@ -10,6 +10,7 @@ #include #include "MediaPlayer.h" +#include "Common/config.h" using namespace std; using namespace toolkit; @@ -36,7 +37,7 @@ static void setOnCreateSocket_l(const std::shared_ptr &delegate, con } void MediaPlayer::play(const string &url) { - _delegate = PlayerBase::createPlayer(_poller, url); + _delegate = PlayerBase::createPlayer(_poller, url, (*this)[Client::kSchema]); assert(_delegate); setOnCreateSocket_l(_delegate, _on_create_socket); _delegate->setOnShutdown(_on_shutdown); diff --git a/src/Player/PlayerBase.cpp b/src/Player/PlayerBase.cpp index 58a31cfc..b761e61c 100644 --- a/src/Player/PlayerBase.cpp +++ b/src/Player/PlayerBase.cpp @@ -26,7 +26,7 @@ using namespace toolkit; namespace mediakit { -PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &in_poller, const string &url_in) { +PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &in_poller, const string &url_in, const std::string &schema) { auto poller = in_poller ? in_poller : EventPollerPool::Instance().getPoller(); std::weak_ptr weak_poller = poller; auto release_func = [weak_poller](PlayerBase *ptr) { @@ -70,13 +70,13 @@ PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &in_poller, cons return PlayerBase::Ptr(new RtmpPlayerImp(poller), release_func); } if ((strcasecmp("http", prefix.data()) == 0 || strcasecmp("https", prefix.data()) == 0)) { - if (end_with(url, ".m3u8") || end_with(url_in, ".m3u8")) { + if (end_with(url, ".m3u8") || end_with(url_in, ".m3u8") || schema == "hls") { return PlayerBase::Ptr(new HlsPlayerImp(poller), release_func); } - if (end_with(url, ".ts") || end_with(url_in, ".ts")) { + if (end_with(url, ".ts") || end_with(url_in, ".ts") || schema == "ts") { return PlayerBase::Ptr(new TsPlayerImp(poller), release_func); } - if (end_with(url, ".flv") || end_with(url_in, ".flv")) { + if (end_with(url, ".flv") || end_with(url_in, ".flv") || schema == "flv") { return PlayerBase::Ptr(new FlvPlayerImp(poller), release_func); } } diff --git a/src/Player/PlayerBase.h b/src/Player/PlayerBase.h index 59658e46..621aa179 100644 --- a/src/Player/PlayerBase.h +++ b/src/Player/PlayerBase.h @@ -42,7 +42,7 @@ public: using Ptr = std::shared_ptr; using Event = std::function; - static Ptr createPlayer(const toolkit::EventPoller::Ptr &poller, const std::string &strUrl); + static Ptr createPlayer(const toolkit::EventPoller::Ptr &poller, const std::string &strUrl, const std::string &schema = ""); PlayerBase();