删除多余ts split代码

This commit is contained in:
xiongziliang 2022-02-13 21:36:04 +08:00
parent 83c1f29253
commit 2e9d77e8e1
7 changed files with 11 additions and 48 deletions

View File

@ -16,7 +16,6 @@ using namespace toolkit;
namespace mediakit {
HlsPlayer::HlsPlayer(const EventPoller::Ptr &poller) {
_segment.setOnSegment([this](const char *data, size_t len) { onPacket(data, len); });
setPoller(poller ? poller : EventPollerPool::Instance().getPoller());
}
@ -68,7 +67,7 @@ void HlsPlayer::fetchSegment() {
}
weak_ptr<HlsPlayer> weak_self = dynamic_pointer_cast<HlsPlayer>(shared_from_this());
if (!_http_ts_player) {
_http_ts_player = std::make_shared<HttpTSPlayer>(getPoller(), false);
_http_ts_player = std::make_shared<HttpTSPlayer>(getPoller());
_http_ts_player->setOnCreateSocket([weak_self](const EventPoller::Ptr &poller) {
auto strong_self = weak_self.lock();
if (strong_self) {
@ -84,7 +83,7 @@ void HlsPlayer::fetchSegment() {
return;
}
//收到ts包
strong_self->onPacket_l(data, len);
strong_self->onPacket(data, len);
});
}
@ -238,16 +237,6 @@ void HlsPlayer::playDelay() {
}, getPoller()));
}
void HlsPlayer::onPacket_l(const char *data, size_t len) {
try {
_segment.input(data, len);
} catch (...) {
//ts解析失败清空缓存数据
_segment.reset();
throw;
}
}
//////////////////////////////////////////////////////////////////////////
void HlsDemuxer::start(const EventPoller::Ptr &poller, TrackListener *listener) {

View File

@ -85,7 +85,6 @@ private:
void fetchSegment();
void teardown_l(const toolkit::SockException &ex);
void fetchIndexFile();
void onPacket_l(const char *data, size_t len);
private:
struct UrlComp {
@ -106,7 +105,6 @@ private:
std::list<std::string> _ts_url_sort;
std::set<std::string, UrlComp> _ts_url_cache;
HttpTSPlayer::Ptr _http_ts_player;
TSSegment _segment;
};
class HlsPlayerImp : public PlayerImp<HlsPlayer, PlayerBase>, private TrackListener {

View File

@ -15,9 +15,7 @@ using namespace toolkit;
namespace mediakit {
HttpTSPlayer::HttpTSPlayer(const EventPoller::Ptr &poller, bool split_ts) {
_split_ts = split_ts;
_segment.setOnSegment([this](const char *data, size_t len) { onPacket(data, len); });
HttpTSPlayer::HttpTSPlayer(const EventPoller::Ptr &poller) {
setPoller(poller ? poller : EventPollerPool::Instance().getPoller());
}
@ -34,17 +32,8 @@ void HttpTSPlayer::onResponseHeader(const string &status, const HttpClient::Http
}
void HttpTSPlayer::onResponseBody(const char *buf, size_t size) {
if (_split_ts) {
try {
_segment.input(buf, size);
} catch (std::exception &ex) {
WarnL << ex.what();
// ts解析失败清空缓存数据
_segment.reset();
throw;
}
} else {
onPacket(buf, size);
if (_on_segment) {
_on_segment(buf, size);
}
}
@ -59,12 +48,6 @@ void HttpTSPlayer::emitOnComplete(const SockException &ex) {
}
}
void HttpTSPlayer::onPacket(const char *data, size_t len) {
if (_on_segment) {
_on_segment(data, len);
}
}
void HttpTSPlayer::setOnComplete(onComplete cb) {
_on_complete = std::move(cb);
}

View File

@ -23,7 +23,7 @@ public:
using Ptr = std::shared_ptr<HttpTSPlayer>;
using onComplete = std::function<void(const toolkit::SockException &)>;
HttpTSPlayer(const toolkit::EventPoller::Ptr &poller = nullptr, bool split_ts = true);
HttpTSPlayer(const toolkit::EventPoller::Ptr &poller = nullptr);
~HttpTSPlayer() override = default;
/**
@ -42,18 +42,10 @@ protected:
void onResponseBody(const char *buf, size_t size) override;
void onResponseCompleted(const toolkit::SockException &ex) override;
protected:
/**
* ts数据
*/
virtual void onPacket(const char *data, size_t len);
private:
void emitOnComplete(const toolkit::SockException &ex);
private:
bool _split_ts;
TSSegment _segment;
onComplete _on_complete;
TSSegment::onSegment _on_segment;
};

View File

@ -15,7 +15,7 @@ using namespace toolkit;
namespace mediakit {
TsPlayer::TsPlayer(const EventPoller::Ptr &poller) : HttpTSPlayer(poller, true) {}
TsPlayer::TsPlayer(const EventPoller::Ptr &poller) : HttpTSPlayer(poller) {}
void TsPlayer::play(const string &url) {
TraceL << "play http-ts: " << url;

View File

@ -24,8 +24,8 @@ public:
~TsPlayerImp() override = default;
private:
//// HlsPlayer override////
void onPacket(const char *data, size_t len) override;
//// TsPlayer override////
void onResponseBody(const char *buf, size_t size) override;
private:
//// PlayerBase override////

View File

@ -18,7 +18,8 @@ namespace mediakit {
TsPlayerImp::TsPlayerImp(const EventPoller::Ptr &poller) : PlayerImp<TsPlayer, PlayerBase>(poller) {}
void TsPlayerImp::onPacket(const char *data, size_t len) {
void TsPlayerImp::onResponseBody(const char *data, size_t len) {
TsPlayer::onResponseBody(data, len);
if (!_decoder && _demuxer) {
_decoder = DecoderImp::createDecoder(DecoderImp::decoder_ts, _demuxer.get());
}