Skip to content

Commit

Permalink
refactor(framework): add codec id for packet
Browse files Browse the repository at this point in the history
  • Loading branch information
skufly authored and pingkai committed Jan 14, 2020
1 parent b9603dc commit 8c21c19
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions framework/base/media/IAFPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vector>
#include <memory>
#include <utils/frame_work_log.h>
#include <utils/AFMediaType.h>
#include <cstring>

extern "C" {
Expand Down Expand Up @@ -42,6 +43,8 @@ class CICADA_CPLUS_EXTERN IAFPacket {
uint8_t *extra_data;
int extra_data_size;

AFCodecID codec_id;

void dump();

~packetInfo()
Expand Down
15 changes: 12 additions & 3 deletions framework/demuxer/avFormatDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t *>(av_malloc(new_extradata_size + AV_INPUT_BUFFER_PADDING_SIZE));
memcpy(codecpar->extradata, new_extradata, new_extradata_size);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -526,7 +535,7 @@ namespace Cicada {
if (mPthread) {
mPthread->stop();
}

bFillExtraData = false;
#endif
}

Expand Down
1 change: 1 addition & 0 deletions framework/demuxer/avFormatDemuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ namespace Cicada {
std::map<int, std::unique_ptr<AVStreamCtx>> mStreamCtxMap{};
AVIOContext *mPInPutPb = nullptr;
bool bOpened{false};
bool bFillExtraData{false};
int64_t mStartTime = INT64_MIN;
std::deque<unique_ptr<IAFPacket>> mPacketQueue{};
bool bEOS{false};
Expand Down

0 comments on commit 8c21c19

Please sign in to comment.