mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 12:37:09 +08:00
删除多余ts split代码
This commit is contained in:
parent
83c1f29253
commit
2e9d77e8e1
@ -16,7 +16,6 @@ using namespace toolkit;
|
|||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
HlsPlayer::HlsPlayer(const EventPoller::Ptr &poller) {
|
HlsPlayer::HlsPlayer(const EventPoller::Ptr &poller) {
|
||||||
_segment.setOnSegment([this](const char *data, size_t len) { onPacket(data, len); });
|
|
||||||
setPoller(poller ? poller : EventPollerPool::Instance().getPoller());
|
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());
|
weak_ptr<HlsPlayer> weak_self = dynamic_pointer_cast<HlsPlayer>(shared_from_this());
|
||||||
if (!_http_ts_player) {
|
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) {
|
_http_ts_player->setOnCreateSocket([weak_self](const EventPoller::Ptr &poller) {
|
||||||
auto strong_self = weak_self.lock();
|
auto strong_self = weak_self.lock();
|
||||||
if (strong_self) {
|
if (strong_self) {
|
||||||
@ -84,7 +83,7 @@ void HlsPlayer::fetchSegment() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//收到ts包
|
//收到ts包
|
||||||
strong_self->onPacket_l(data, len);
|
strong_self->onPacket(data, len);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,16 +237,6 @@ void HlsPlayer::playDelay() {
|
|||||||
}, getPoller()));
|
}, 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) {
|
void HlsDemuxer::start(const EventPoller::Ptr &poller, TrackListener *listener) {
|
||||||
|
@ -85,7 +85,6 @@ private:
|
|||||||
void fetchSegment();
|
void fetchSegment();
|
||||||
void teardown_l(const toolkit::SockException &ex);
|
void teardown_l(const toolkit::SockException &ex);
|
||||||
void fetchIndexFile();
|
void fetchIndexFile();
|
||||||
void onPacket_l(const char *data, size_t len);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct UrlComp {
|
struct UrlComp {
|
||||||
@ -106,7 +105,6 @@ private:
|
|||||||
std::list<std::string> _ts_url_sort;
|
std::list<std::string> _ts_url_sort;
|
||||||
std::set<std::string, UrlComp> _ts_url_cache;
|
std::set<std::string, UrlComp> _ts_url_cache;
|
||||||
HttpTSPlayer::Ptr _http_ts_player;
|
HttpTSPlayer::Ptr _http_ts_player;
|
||||||
TSSegment _segment;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class HlsPlayerImp : public PlayerImp<HlsPlayer, PlayerBase>, private TrackListener {
|
class HlsPlayerImp : public PlayerImp<HlsPlayer, PlayerBase>, private TrackListener {
|
||||||
|
@ -15,9 +15,7 @@ using namespace toolkit;
|
|||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
HttpTSPlayer::HttpTSPlayer(const EventPoller::Ptr &poller, bool split_ts) {
|
HttpTSPlayer::HttpTSPlayer(const EventPoller::Ptr &poller) {
|
||||||
_split_ts = split_ts;
|
|
||||||
_segment.setOnSegment([this](const char *data, size_t len) { onPacket(data, len); });
|
|
||||||
setPoller(poller ? poller : EventPollerPool::Instance().getPoller());
|
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) {
|
void HttpTSPlayer::onResponseBody(const char *buf, size_t size) {
|
||||||
if (_split_ts) {
|
if (_on_segment) {
|
||||||
try {
|
_on_segment(buf, size);
|
||||||
_segment.input(buf, size);
|
|
||||||
} catch (std::exception &ex) {
|
|
||||||
WarnL << ex.what();
|
|
||||||
// ts解析失败,清空缓存数据
|
|
||||||
_segment.reset();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
onPacket(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) {
|
void HttpTSPlayer::setOnComplete(onComplete cb) {
|
||||||
_on_complete = std::move(cb);
|
_on_complete = std::move(cb);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public:
|
|||||||
using Ptr = std::shared_ptr<HttpTSPlayer>;
|
using Ptr = std::shared_ptr<HttpTSPlayer>;
|
||||||
using onComplete = std::function<void(const toolkit::SockException &)>;
|
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;
|
~HttpTSPlayer() override = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,18 +42,10 @@ protected:
|
|||||||
void onResponseBody(const char *buf, size_t size) override;
|
void onResponseBody(const char *buf, size_t size) override;
|
||||||
void onResponseCompleted(const toolkit::SockException &ex) override;
|
void onResponseCompleted(const toolkit::SockException &ex) override;
|
||||||
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* 收到ts数据
|
|
||||||
*/
|
|
||||||
virtual void onPacket(const char *data, size_t len);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void emitOnComplete(const toolkit::SockException &ex);
|
void emitOnComplete(const toolkit::SockException &ex);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _split_ts;
|
|
||||||
TSSegment _segment;
|
|
||||||
onComplete _on_complete;
|
onComplete _on_complete;
|
||||||
TSSegment::onSegment _on_segment;
|
TSSegment::onSegment _on_segment;
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,7 @@ using namespace toolkit;
|
|||||||
|
|
||||||
namespace mediakit {
|
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) {
|
void TsPlayer::play(const string &url) {
|
||||||
TraceL << "play http-ts: " << url;
|
TraceL << "play http-ts: " << url;
|
||||||
|
@ -24,8 +24,8 @@ public:
|
|||||||
~TsPlayerImp() override = default;
|
~TsPlayerImp() override = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//// HlsPlayer override////
|
//// TsPlayer override////
|
||||||
void onPacket(const char *data, size_t len) override;
|
void onResponseBody(const char *buf, size_t size) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//// PlayerBase override////
|
//// PlayerBase override////
|
||||||
|
@ -18,7 +18,8 @@ namespace mediakit {
|
|||||||
|
|
||||||
TsPlayerImp::TsPlayerImp(const EventPoller::Ptr &poller) : PlayerImp<TsPlayer, PlayerBase>(poller) {}
|
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) {
|
if (!_decoder && _demuxer) {
|
||||||
_decoder = DecoderImp::createDecoder(DecoderImp::decoder_ts, _demuxer.get());
|
_decoder = DecoderImp::createDecoder(DecoderImp::decoder_ts, _demuxer.get());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user