合并http-ts播放器特性: #1336

This commit is contained in:
xiongziliang 2022-01-09 15:01:23 +08:00
parent a4c69e61cd
commit 7b04385bc8
6 changed files with 254 additions and 246 deletions

View File

@ -1,6 +1,12 @@
// /*
// Created by alex on 2021/4/6. * Copyright (c) 2020 The ZLMediaKit project authors. All Rights Reserved.
// * Created by alex on 2021/4/6.
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
*
* Use of this source code is governed by MIT license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#include "TsPlayer.h" #include "TsPlayer.h"
@ -8,8 +14,6 @@ namespace mediakit {
TsPlayer::TsPlayer(const EventPoller::Ptr &poller) : HttpTSPlayer(poller, true) {} TsPlayer::TsPlayer(const EventPoller::Ptr &poller) : HttpTSPlayer(poller, true) {}
TsPlayer::~TsPlayer() {}
void TsPlayer::play(const string &strUrl) { void TsPlayer::play(const string &strUrl) {
_ts_url.append(strUrl); _ts_url.append(strUrl);
playTs(); playTs();
@ -65,4 +69,5 @@ namespace mediakit {
} }
return ret; return ret;
} }
}//namespace mediakit }//namespace mediakit

View File

@ -1,10 +1,6 @@
//
// Created by alex on 2021/4/6.
//
/* /*
* Copyright (c) 2020 The ZLMediaKit project authors. All Rights Reserved. * Copyright (c) 2020 The ZLMediaKit project authors. All Rights Reserved.
* * Created by alex on 2021/4/6.
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
* *
* Use of this source code is governed by MIT license that can be found in the * Use of this source code is governed by MIT license that can be found in the
@ -24,37 +20,37 @@
#include "Rtp/TSDecoder.h" #include "Rtp/TSDecoder.h"
#include "HttpTSPlayer.h" #include "HttpTSPlayer.h"
using namespace toolkit; using namespace toolkit;
namespace mediakit { namespace mediakit {
class TsPlayer : public HttpTSPlayer, public PlayerBase { class TsPlayer : public HttpTSPlayer, public PlayerBase {
public: public:
TsPlayer(const EventPoller::Ptr &poller); TsPlayer(const EventPoller::Ptr &poller);
~TsPlayer() override; ~TsPlayer() override = default;
/** /**
* *
* @param strUrl
*/ */
void play(const string &strUrl) override; void play(const string &url) override;
/** /**
* *
*/ */
void teardown() override; void teardown() override;
private: private:
void playTs(); void playTs();
void teardown_l(const SockException &ex); void teardown_l(const SockException &ex);
protected: protected:
virtual void onResponseCompleted() override; virtual void onResponseCompleted() override;
virtual void onDisconnect(const SockException &ex) override; virtual void onDisconnect(const SockException &ex) override;
virtual ssize_t onResponseHeader(const string &status, const HttpHeader &header) override; virtual ssize_t onResponseHeader(const string &status, const HttpHeader &header) override;
private: private:
bool _first = true; bool _first = true;
string _ts_url; string _ts_url;
}; };
}//namespace mediakit }//namespace mediakit
#endif //HTTP_TSPLAYER_H #endif //HTTP_TSPLAYER_H

View File

@ -1,6 +1,12 @@
// /*
// Created by alex on 2021/7/5. * Copyright (c) 2020 The ZLMediaKit project authors. All Rights Reserved.
// * Created by alex on 2021/4/6.
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
*
* Use of this source code is governed by MIT license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#ifndef HTTP_TSPLAYERIMP_H #ifndef HTTP_TSPLAYERIMP_H
#define HTTP_TSPLAYERIMP_H #define HTTP_TSPLAYERIMP_H
@ -15,12 +21,12 @@
#include "TsPlayer.h" #include "TsPlayer.h"
using namespace toolkit; using namespace toolkit;
namespace mediakit { namespace mediakit {
class TsDemuxer : public MediaSinkInterface, public TrackSource, public std::enable_shared_from_this<TsDemuxer> { class TsDemuxer : public MediaSinkInterface, public TrackSource, public std::enable_shared_from_this<TsDemuxer> {
public: public:
TsDemuxer() = default; TsDemuxer() = default;
~TsDemuxer() override { _timer = nullptr; } ~TsDemuxer() override { _timer = nullptr; }
void start(const EventPoller::Ptr &poller, TrackListener *listener); void start(const EventPoller::Ptr &poller, TrackListener *listener);
@ -45,11 +51,8 @@ namespace mediakit {
private: private:
void onTick(); void onTick();
int64_t getBufferMS(); int64_t getBufferMS();
int64_t getPlayPosition(); int64_t getPlayPosition();
void setPlayPosition(int64_t pos); void setPlayPosition(int64_t pos);
private: private:
@ -61,13 +64,11 @@ namespace mediakit {
multimap<int64_t, Frame::Ptr> _frame_cache; multimap<int64_t, Frame::Ptr> _frame_cache;
}; };
class TsPlayerImp : public PlayerImp<TsPlayer, PlayerBase>, private TrackListener { class TsPlayerImp : public PlayerImp<TsPlayer, PlayerBase>, private TrackListener {
public: public:
typedef std::shared_ptr<TsPlayerImp> Ptr; using Ptr = std::shared_ptr<TsPlayerImp>;
TsPlayerImp(const EventPoller::Ptr &poller = nullptr); TsPlayerImp(const EventPoller::Ptr &poller = nullptr);
~TsPlayerImp() override = default; ~TsPlayerImp() override = default;
private: private:
@ -77,20 +78,18 @@ namespace mediakit {
private: private:
//// PlayerBase override//// //// PlayerBase override////
void onPlayResult(const SockException &ex) override; void onPlayResult(const SockException &ex) override;
vector<Track::Ptr> getTracks(bool ready = true) const override; vector<Track::Ptr> getTracks(bool ready = true) const override;
void onShutdown(const SockException &ex) override; void onShutdown(const SockException &ex) override;
private: private:
//// TrackListener override//// //// TrackListener override////
bool addTrack(const Track::Ptr &track) override { return true; }; bool addTrack(const Track::Ptr &track) override { return true; };
void addTrackCompleted() override; void addTrackCompleted() override;
private: private:
DecoderImp::Ptr _decoder; DecoderImp::Ptr _decoder;
MediaSinkInterface::Ptr _demuxer; MediaSinkInterface::Ptr _demuxer;
}; };
}//namespace mediakit }//namespace mediakit
#endif //HTTP_TSPLAYERIMP_H #endif //HTTP_TSPLAYERIMP_H

View File

@ -1,6 +1,17 @@
/*
* Copyright (c) 2020 The ZLMediaKit project authors. All Rights Reserved.
* Created by alex on 2021/4/6.
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
*
* Use of this source code is governed by MIT license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#include "TsPlayerImp.h" #include "TsPlayerImp.h"
namespace mediakit { namespace mediakit {
void TsDemuxer::start(const EventPoller::Ptr &poller, TrackListener *listener) { void TsDemuxer::start(const EventPoller::Ptr &poller, TrackListener *listener) {
_frame_cache.clear(); _frame_cache.clear();
_stamp[TrackAudio].setRelativeStamp(0); _stamp[TrackAudio].setRelativeStamp(0);
@ -33,8 +44,6 @@ namespace mediakit {
//根据时间戳缓存frame //根据时间戳缓存frame
_stamp[frame->getTrackType()].revise(frame->dts(), frame->pts(), dts, pts); _stamp[frame->getTrackType()].revise(frame->dts(), frame->pts(), dts, pts);
_frame_cache.emplace(dts, Frame::getCacheAbleFrame(frame)); _frame_cache.emplace(dts, Frame::getCacheAbleFrame(frame));
//根据时间戳缓存frame
// _frame_cache.emplace(dts, Frame::getCacheAbleFrame(frame));
if (getBufferMS() > 30 * 1000) { if (getBufferMS() > 30 * 1000) {
//缓存超过30秒强制消费至15秒(减少延时或内存占用) //缓存超过30秒强制消费至15秒(减少延时或内存占用)

View File

@ -51,8 +51,7 @@ PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &poller, const s
if ((strcasecmp("http", prefix.data()) == 0 || strcasecmp("https", prefix.data()) == 0)) { 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")) {
return PlayerBase::Ptr(new HlsPlayerImp(poller), releasePlayer); return PlayerBase::Ptr(new HlsPlayerImp(poller), releasePlayer);
} } else if (end_with(url, ".ts") || end_with(url_in, ".ts")) {
else if (end_with(url, ".ts") || end_with(url_in, ".ts")) {
return PlayerBase::Ptr(new TsPlayerImp(poller), releasePlayer); return PlayerBase::Ptr(new TsPlayerImp(poller), releasePlayer);
} }
return PlayerBase::Ptr(new TsPlayerImp(poller), releasePlayer); return PlayerBase::Ptr(new TsPlayerImp(poller), releasePlayer);