From 5832de7ed8f53a5dea4e1c52361d3b5aa1a2ea13 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Fri, 24 Dec 2021 14:25:01 +0800 Subject: [PATCH] =?UTF-8?q?HLS:=20ts=E5=88=86=E5=8C=85=E5=99=A8=E4=B8=BB?= =?UTF-8?q?=E5=8A=A8=E4=B8=A2=E5=BC=83=E9=9D=9E=E6=B3=95=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtp/TSDecoder.cpp | 9 +++++++-- src/Rtp/TSDecoder.h | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Rtp/TSDecoder.cpp b/src/Rtp/TSDecoder.cpp index 7a5aee2a..2f347d5d 100644 --- a/src/Rtp/TSDecoder.cpp +++ b/src/Rtp/TSDecoder.cpp @@ -15,8 +15,8 @@ bool TSSegment::isTSPacket(const char *data, size_t len){ return len == TS_PACKET_SIZE && ((uint8_t*)data)[0] == TS_SYNC_BYTE; } -void TSSegment::setOnSegment(const TSSegment::onSegment &cb) { - _onSegment = cb; +void TSSegment::setOnSegment(TSSegment::onSegment cb) { + _onSegment = std::move(cb); } ssize_t TSSegment::onRecvHeader(const char *data, size_t len) { @@ -43,6 +43,11 @@ const char *TSSegment::onSearchPacketTail(const char *data, size_t len) { if (pos) { return (char *) pos; } + if (remainDataSize() > 4 * _size) { + //数据这么多都没ts包,全部清空 + return data + len; + } + //等待更多数据 return nullptr; } diff --git a/src/Rtp/TSDecoder.h b/src/Rtp/TSDecoder.h index a6231ae9..ecaf6b76 100644 --- a/src/Rtp/TSDecoder.h +++ b/src/Rtp/TSDecoder.h @@ -27,7 +27,7 @@ public: typedef std::function onSegment; TSSegment(size_t size = TS_PACKET_SIZE) : _size(size){} ~TSSegment(){} - void setOnSegment(const onSegment &cb); + void setOnSegment(onSegment cb); static bool isTSPacket(const char *data, size_t len); protected: