mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-11-24 00:47:21 +08:00
HLS TS 切片下载失败后清除该切片遗留的解复用输入缓存 (#4786)
在 HLS TS 切片下载失败后清除该切片遗留的解复用输入缓存,防止其与下一切片拼接导致错误的包或者损坏的包出现.
This commit is contained in:
@@ -153,6 +153,7 @@ void HlsPlayer::fetchSegment() {
|
||||
return;
|
||||
}
|
||||
if (err) {
|
||||
strong_self->onSegmentDownloadFailed(err);
|
||||
WarnL << "Download ts segment " << url << " failed:" << err;
|
||||
if (err.getErrCode() == Err_timeout) {
|
||||
strong_self->_timeout_multiple = MAX(strong_self->_timeout_multiple + 1, MAX_TIMEOUT_MULTIPLE);
|
||||
@@ -492,6 +493,14 @@ void HlsPlayerImp::onPacket(const char *data, size_t len) {
|
||||
_recvtotalbytes += HlsPlayer::getRecvTotalBytes();
|
||||
}
|
||||
|
||||
void HlsPlayerImp::onSegmentDownloadFailed(const toolkit::SockException &ex) {
|
||||
if (_decoder && ex) {
|
||||
// 失败切片的输入残片不能与下一切片拼接;这里只清输入缓存,不 flush 解码帧。
|
||||
// Input left by a failed segment must not join the next one; clear it without flushing decoded frames.
|
||||
_decoder->clearInputCache();
|
||||
}
|
||||
}
|
||||
|
||||
void HlsPlayerImp::addTrackCompleted() {
|
||||
PlayerImp<HlsPlayer, PlayerBase>::onPlayResult(SockException(Err_success, "play hls success"));
|
||||
}
|
||||
|
||||
@@ -90,6 +90,9 @@ protected:
|
||||
* [AUTO-TRANSLATED:159a6559]
|
||||
*/
|
||||
virtual void onPacket(const char *data, size_t len) = 0;
|
||||
// TS 切片下载失败通知;派生类可清理该切片遗留的输入状态。
|
||||
// Notify derived classes to clear input state left by a failed TS segment.
|
||||
virtual void onSegmentDownloadFailed(const toolkit::SockException &ex) {}
|
||||
|
||||
private:
|
||||
bool onParsed(bool is_m3u8_inner, int64_t sequence, const map<int, ts_segment> &ts_map) override;
|
||||
@@ -149,6 +152,7 @@ public:
|
||||
private:
|
||||
//// HlsPlayer override////
|
||||
void onPacket(const char *data, size_t len) override;
|
||||
void onSegmentDownloadFailed(const toolkit::SockException &ex) override;
|
||||
|
||||
private:
|
||||
//// PlayerBase override////
|
||||
|
||||
Reference in New Issue
Block a user