mpeg-ts解析丢弃不完整的包 (#1478)

* 丢弃不正确的包

因为网络抖动或者拉流超时导致ts包不全.
这里丢弃掉有问题的包, 避免客户端解码中断

* Update TSDecoder.cpp

* 格式化代码

Co-authored-by: 夏楚 <771730766@qq.com>
This commit is contained in:
alexliyu7352 2022-03-12 09:41:15 +08:00 committed by GitHub
parent 276f763c08
commit 4be3c349be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,6 +55,7 @@ const char *TSSegment::onSearchPacketTail(const char *data, size_t len) {
#if defined(ENABLE_HLS)
#include "mpeg-ts.h"
#include "mpeg-ts-proto.h"
TSDecoder::TSDecoder() : _ts_segment() {
_ts_segment.setOnSegment([this](const char *data, size_t len){
ts_demuxer_input(_demuxer_ctx,(uint8_t*)data,len);
@ -62,8 +63,12 @@ TSDecoder::TSDecoder() : _ts_segment() {
_demuxer_ctx = ts_demuxer_create([](void* param, int program, int stream, int codecid, int flags, int64_t pts, int64_t dts, const void* data, size_t bytes){
TSDecoder *thiz = (TSDecoder*)param;
if (thiz->_on_decode) {
if (flags & MPEG_FLAG_PACKET_CORRUPT) {
WarnL << "ts packet lost, dts:" << dts << " pts:" << pts << " bytes:" << bytes;
} else {
thiz->_on_decode(stream, codecid, flags, pts, dts, data, bytes);
}
}
return 0;
},this);