新增支持http-flv播放器 (#2562)

This commit is contained in:
夏楚
2023-06-17 10:29:27 +08:00
committed by GitHub
parent 03770ff409
commit 7e117b1c7f
13 changed files with 514 additions and 104 deletions

View File

@@ -12,6 +12,7 @@
#include "PlayerBase.h"
#include "Rtsp/RtspPlayerImp.h"
#include "Rtmp/RtmpPlayerImp.h"
#include "Rtmp/FlvPlayer.h"
#include "Http/HlsPlayer.h"
#include "Http/TsPlayerImp.h"
@@ -20,12 +21,13 @@ using namespace toolkit;
namespace mediakit {
PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &poller, const string &url_in) {
static auto releasePlayer = [](PlayerBase *ptr) {
onceToken token(nullptr, [&]() {
delete ptr;
PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &in_poller, const string &url_in) {
auto poller = in_poller ? in_poller : EventPollerPool::Instance().getPoller();
static auto releasePlayer = [poller](PlayerBase *ptr) {
poller->async([ptr]() {
onceToken token(nullptr, [&]() { delete ptr; });
ptr->teardown();
});
ptr->teardown();
};
string url = url_in;
string prefix = findSubString(url.data(), NULL, "://");
@@ -53,9 +55,13 @@ PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &poller, const s
if ((strcasecmp("http", prefix.data()) == 0 || strcasecmp("https", prefix.data()) == 0)) {
if (end_with(url, ".m3u8") || end_with(url_in, ".m3u8")) {
return PlayerBase::Ptr(new HlsPlayerImp(poller), releasePlayer);
} else if (end_with(url, ".ts") || end_with(url_in, ".ts")) {
}
if (end_with(url, ".ts") || end_with(url_in, ".ts")) {
return PlayerBase::Ptr(new TsPlayerImp(poller), releasePlayer);
}
if (end_with(url, ".flv") || end_with(url_in, ".flv")) {
return PlayerBase::Ptr(new FlvPlayerImp(poller), releasePlayer);
}
}
throw std::invalid_argument("not supported play schema:" + url_in);