播放器新增schema参数支持指定拉流协议

This commit is contained in:
xia-chu 2026-03-11 22:24:21 +08:00
parent bb903fddcd
commit bb49e4dcdc
5 changed files with 10 additions and 6 deletions

View File

@ -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";

View File

@ -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

View File

@ -10,6 +10,7 @@
#include <algorithm>
#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<PlayerBase> &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);

View File

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

View File

@ -42,7 +42,7 @@ public:
using Ptr = std::shared_ptr<PlayerBase>;
using Event = std::function<void(const toolkit::SockException &ex)>;
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();