From 8c21c19fdbf3a397e0bddbe735355b592af3216a Mon Sep 17 00:00:00 2001 From: skufly Date: Mon, 13 Jan 2020 18:59:29 +0800 Subject: [PATCH] refactor(framework): add codec id for packet --- framework/base/media/IAFPacket.h | 3 +++ framework/demuxer/avFormatDemuxer.cpp | 15 ++++++++++++--- framework/demuxer/avFormatDemuxer.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/framework/base/media/IAFPacket.h b/framework/base/media/IAFPacket.h index 3826c248a..157b2cd50 100644 --- a/framework/base/media/IAFPacket.h +++ b/framework/base/media/IAFPacket.h @@ -11,6 +11,7 @@ #include #include #include +#include #include extern "C" { @@ -42,6 +43,8 @@ class CICADA_CPLUS_EXTERN IAFPacket { uint8_t *extra_data; int extra_data_size; + AFCodecID codec_id; + void dump(); ~packetInfo() diff --git a/framework/demuxer/avFormatDemuxer.cpp b/framework/demuxer/avFormatDemuxer.cpp index 84e82e796..761d51489 100644 --- a/framework/demuxer/avFormatDemuxer.cpp +++ b/framework/demuxer/avFormatDemuxer.cpp @@ -282,10 +282,11 @@ namespace Cicada { AV_PKT_DATA_NEW_EXTRADATA, &new_extradata_size); + int streamIndex = pkt->stream_index; + AVCodecParameters *codecpar = mCtx->streams[streamIndex]->codecpar; + if (new_extradata) { AF_LOGI("AV_PKT_DATA_NEW_EXTRADATA"); - int streamIndex = pkt->stream_index; - AVCodecParameters *codecpar = mCtx->streams[streamIndex]->codecpar; av_free(codecpar->extradata); codecpar->extradata = static_cast(av_malloc(new_extradata_size + AV_INPUT_BUFFER_PADDING_SIZE)); memcpy(codecpar->extradata, new_extradata, new_extradata_size); @@ -332,8 +333,16 @@ namespace Cicada { if (needUpdateExtraData) { packet->setExtraData(new_extradata, new_extradata_size); + } else if (!bFillExtraData && (nullptr == packet->getInfo().extra_data) && (nullptr != codecpar->extradata)) { + packet->setExtraData(codecpar->extradata, codecpar->extradata_size); + } + + if (packet->getInfo().extra_data) { + bFillExtraData = true; } + packet->getInfo().codec_id = AVCodec2CicadaCodec(codecpar->codec_id); + if (packet->getInfo().pts != INT64_MIN) { packet->getInfo().timePosition = packet->getInfo().pts - mCtx->start_time; } @@ -526,7 +535,7 @@ namespace Cicada { if (mPthread) { mPthread->stop(); } - + bFillExtraData = false; #endif } diff --git a/framework/demuxer/avFormatDemuxer.h b/framework/demuxer/avFormatDemuxer.h index efdb8a734..1c40428f5 100644 --- a/framework/demuxer/avFormatDemuxer.h +++ b/framework/demuxer/avFormatDemuxer.h @@ -123,6 +123,7 @@ namespace Cicada { std::map> mStreamCtxMap{}; AVIOContext *mPInPutPb = nullptr; bool bOpened{false}; + bool bFillExtraData{false}; int64_t mStartTime = INT64_MIN; std::deque> mPacketQueue{}; bool bEOS{false};