合并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"
@ -8,8 +14,6 @@ namespace mediakit {
TsPlayer::TsPlayer(const EventPoller::Ptr &poller) : HttpTSPlayer(poller, true) {}
TsPlayer::~TsPlayer() {}
void TsPlayer::play(const string &strUrl) {
_ts_url.append(strUrl);
playTs();
@ -65,4 +69,5 @@ namespace mediakit {
}
return ret;
}
}//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.
*
* 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
@ -24,37 +20,37 @@
#include "Rtp/TSDecoder.h"
#include "HttpTSPlayer.h"
using namespace toolkit;
namespace mediakit {
class TsPlayer : public HttpTSPlayer, public PlayerBase {
public:
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;
private:
void playTs();
void teardown_l(const SockException &ex);
protected:
virtual void onResponseCompleted() override;
virtual void onDisconnect(const SockException &ex) override;
virtual ssize_t onResponseHeader(const string &status, const HttpHeader &header) override;
private:
bool _first = true;
string _ts_url;
};
}//namespace mediakit
#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
#define HTTP_TSPLAYERIMP_H
@ -15,12 +21,12 @@
#include "TsPlayer.h"
using namespace toolkit;
namespace mediakit {
class TsDemuxer : public MediaSinkInterface, public TrackSource, public std::enable_shared_from_this<TsDemuxer> {
public:
TsDemuxer() = default;
~TsDemuxer() override { _timer = nullptr; }
void start(const EventPoller::Ptr &poller, TrackListener *listener);
@ -45,11 +51,8 @@ namespace mediakit {
private:
void onTick();
int64_t getBufferMS();
int64_t getPlayPosition();
void setPlayPosition(int64_t pos);
private:
@ -61,13 +64,11 @@ namespace mediakit {
multimap<int64_t, Frame::Ptr> _frame_cache;
};
class TsPlayerImp : public PlayerImp<TsPlayer, PlayerBase>, private TrackListener {
public:
typedef std::shared_ptr<TsPlayerImp> Ptr;
using Ptr = std::shared_ptr<TsPlayerImp>;
TsPlayerImp(const EventPoller::Ptr &poller = nullptr);
~TsPlayerImp() override = default;
private:
@ -77,20 +78,18 @@ namespace mediakit {
private:
//// PlayerBase override////
void onPlayResult(const SockException &ex) override;
vector<Track::Ptr> getTracks(bool ready = true) const override;
void onShutdown(const SockException &ex) override;
private:
//// TrackListener override////
bool addTrack(const Track::Ptr &track) override { return true; };
void addTrackCompleted() override;
private:
DecoderImp::Ptr _decoder;
MediaSinkInterface::Ptr _demuxer;
};
}//namespace mediakit
#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"
namespace mediakit {
void TsDemuxer::start(const EventPoller::Ptr &poller, TrackListener *listener) {
_frame_cache.clear();
_stamp[TrackAudio].setRelativeStamp(0);
@ -33,8 +44,6 @@ namespace mediakit {
//根据时间戳缓存frame
_stamp[frame->getTrackType()].revise(frame->dts(), frame->pts(), dts, pts);
_frame_cache.emplace(dts, Frame::getCacheAbleFrame(frame));
//根据时间戳缓存frame
// _frame_cache.emplace(dts, Frame::getCacheAbleFrame(frame));
if (getBufferMS() > 30 * 1000) {
//缓存超过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 (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")) {
} 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);