From d40fc4737bb013eef4e8f9f6587d6fb61c7ef232 Mon Sep 17 00:00:00 2001 From: pingkai Date: Sun, 19 Jan 2020 12:20:16 +0800 Subject: [PATCH] fix(ActiveDecoder): drop the CORRUPT packet Signed-off-by: pingkai --- framework/base/media/AVAFPacket.cpp | 7 ++++++- framework/base/media/IAFPacket.h | 3 ++- framework/codec/ActiveDecoder.cpp | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/framework/base/media/AVAFPacket.cpp b/framework/base/media/AVAFPacket.cpp index b4d7c7b09..ec16e7aab 100644 --- a/framework/base/media/AVAFPacket.cpp +++ b/framework/base/media/AVAFPacket.cpp @@ -15,7 +15,12 @@ void AVAFPacket::copyInfo() mInfo.pts = mpkt->pts; mInfo.dts = mpkt->dts; // TODO: redefine the flags - mInfo.flags = mpkt->flags; + mInfo.flags = 0; + if (mpkt->flags & AV_PKT_FLAG_KEY) + mInfo.flags |= AF_PKT_FLAG_KEY; + if (mpkt->flags & AV_PKT_FLAG_CORRUPT) + mInfo.flags |= AF_PKT_FLAG_CORRUPT; + mInfo.streamIndex = mpkt->stream_index; mInfo.timePosition = INT64_MIN; mInfo.pos = mpkt->pos; diff --git a/framework/base/media/IAFPacket.h b/framework/base/media/IAFPacket.h index 7c5c69a4c..88beb01bd 100644 --- a/framework/base/media/IAFPacket.h +++ b/framework/base/media/IAFPacket.h @@ -27,7 +27,8 @@ struct AFRational { AFRational &operator=(AVRational rational); }; - +#define AF_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe +#define AF_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted class CICADA_CPLUS_EXTERN IAFPacket { public: struct packetInfo { diff --git a/framework/codec/ActiveDecoder.cpp b/framework/codec/ActiveDecoder.cpp index f130d4713..5b5e12750 100644 --- a/framework/codec/ActiveDecoder.cpp +++ b/framework/codec/ActiveDecoder.cpp @@ -137,9 +137,11 @@ bool ActiveDecoder::needDrop(IAFPacket *packet) if (packet == nullptr) { return false; } + if (packet->getInfo().flags & AF_PKT_FLAG_CORRUPT) + return true; if (bNeedKeyFrame) { // need a key frame, when first start or after seek - if (packet->getInfo().flags == 0) { // drop the frame that not a key frame + if ((packet->getInfo().flags & AF_PKT_FLAG_KEY) == 0) { // drop the frame that not a key frame // TODO: return error? AF_LOGW("wait a key frame\n"); return true;