Skip to content

Commit

Permalink
[Decode]Optimize AV1 DBP logic for repeated frame, fix repeated flag …
Browse files Browse the repository at this point in the history
…and reference counter issue
  • Loading branch information
huangli2018 authored and gfxVPLsdm committed Nov 18, 2024
1 parent 8ea4583 commit 268eb9a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 39 deletions.
8 changes: 5 additions & 3 deletions _studio/mfx_lib/decode/av1/src/mfx_av1_dec_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,8 @@ mfxStatus VideoDECODEAV1::QueryFrame(mfxThreadTask task)

if(info->copyfromframe != UMC::FRAME_MID_INVALID)
{
frame = m_decoder->DecodeFrameID(info->copyfromframe);
frame = m_decoder->FindFrameByMemID(info->copyfromframe);
MFX_CHECK(frame, MFX_ERR_UNDEFINED_BEHAVIOR);
frame->Repeated(false);
}
else
{
Expand All @@ -923,7 +922,10 @@ mfxStatus VideoDECODEAV1::QueryFrame(mfxThreadTask task)
}
mfxStatus sts = DecodeFrame(surface_out, frame);

m_decoder->Flush();
if (info->copyfromframe != UMC::FRAME_MID_INVALID)
{
m_decoder->FlushRepeatFrame(frame);
}

MFX_CHECK_STS(sts);
return MFX_TASK_DONE;
Expand Down
4 changes: 3 additions & 1 deletion _studio/shared/umc/codec/av1_dec/include/umc_av1_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace UMC_AV1_DECODER
m_pCore = pCore;
}

void Flush();
void FlushRepeatFrame(AV1DecoderFrame*);

protected:

Expand Down Expand Up @@ -236,6 +236,8 @@ namespace UMC_AV1_DECODER
mfxF64 in_framerate;
UMC::FrameMemID repeateFrame;//frame to be repeated

FrameHeader last_frame_header;

uint32_t anchor_frames_count;
uint32_t tile_list_idx;
uint32_t frames_to_skip;
Expand Down
6 changes: 0 additions & 6 deletions _studio/shared/umc/codec/av1_dec/include/umc_av1_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@ namespace UMC_AV1_DECODER
void DpbUpdated(bool u)
{ dpb_updated = u; }

bool Repeated() const
{ return repeated; }
void Repeated(bool d)
{ repeated = d; }

bool Outputted() const
{ return outputted; }
void Outputted(bool o)
Expand Down Expand Up @@ -273,7 +268,6 @@ namespace UMC_AV1_DECODER
bool decoded; // set in [application thread] to signal that frame is completed and respective reference counter decremented
// after it frame still may remain in [AV1Decoder::dpb], but only as reference

bool repeated;
bool dpb_updated;
bool decoding_started; // set in [application thread] right after frame submission to the driver started
bool decoding_completed; // set in [scheduler thread] after getting driver status report for the frame
Expand Down
39 changes: 11 additions & 28 deletions _studio/shared/umc/codec/av1_dec/src/umc_av1_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace UMC_AV1_DECODER
{
outputed_frames.clear();
m_prev_frame_header = {};
last_frame_header = {};
}

AV1Decoder::~AV1Decoder()
Expand Down Expand Up @@ -396,25 +397,13 @@ namespace UMC_AV1_DECODER
{
std::unique_lock<std::mutex> l(guard);
pFrame = frameDPB[fh.frame_to_show_map_idx];

if (pFrame->Repeated())
return nullptr;

//Increase referernce here, and will be decreased when
//CompleteDecodedFrames not show_frame case.
pFrame->IncrementReference();
assert(pFrame);
repeateFrame = pFrame->GetMemID();

//Add one more Reference, and add it into outputed frame list
//When QueryFrame finished and update status in outputed frame
//list, then it will be released in CompleteDecodedFrames.
//repeat frame reference counter increase here, and will decrease in queryframe()
pFrame->IncrementReference();
pFrame->Repeated(true);
outputed_frames.push_back(pFrame);

FrameHeader const& refFH = pFrame->GetFrameHeader();

if (!refFH.showable_frame)
throw av1_exception(UMC::UMC_ERR_INVALID_STREAM);

Expand Down Expand Up @@ -1184,10 +1173,10 @@ namespace UMC_AV1_DECODER
void AV1Decoder::CompleteDecodedFrames(FrameHeader const& fh, AV1DecoderFrame* pCurrFrame, AV1DecoderFrame*)
{
std::unique_lock<std::mutex> l(guard);
if (Curr)
if ((Curr) && (!last_frame_header.show_existing_frame)) //if last frame is a repeat frame , do not insert it into output frames, its refcounter will decrease in QueryFrame()
{
FrameHeader const& FH_OutTemp = Curr->GetFrameHeader();
if (Repeat_show || FH_OutTemp.show_frame)
if (FH_OutTemp.show_frame)
{
bool bAdded = false;
for(std::vector<AV1DecoderFrame*>::iterator iter=outputed_frames.begin(); iter!=outputed_frames.end(); iter++)
Expand All @@ -1204,8 +1193,7 @@ namespace UMC_AV1_DECODER
}
else
{
// For no display case, decrease reference here which is increased
// in pFrame->IncrementReference() in show_existing_frame case.
// For no display case, it decrementReference here and frame.completedecoding() in working thread
if(pCurrFrame)
{
if (Curr->UID == -1)
Expand All @@ -1219,7 +1207,7 @@ namespace UMC_AV1_DECODER
for(std::vector<AV1DecoderFrame*>::iterator iter=outputed_frames.begin(); iter!=outputed_frames.end(); )
{
AV1DecoderFrame* temp = *iter;
if(temp->Outputted() && temp->Displayed() && !temp->Decoded() && !temp->Repeated() && temp->DpbUpdated())
if(temp->Outputted() && temp->Displayed() && !temp->Decoded() && temp->DpbUpdated())
{
temp->DecrementReference();
iter = outputed_frames.erase(iter);
Expand All @@ -1232,6 +1220,8 @@ namespace UMC_AV1_DECODER
if(pCurrFrame!= NULL)
Curr = pCurrFrame;

last_frame_header = fh; //store latest frame header

if (fh.show_existing_frame)
{
Repeat_show = 1;
Expand All @@ -1242,19 +1232,12 @@ namespace UMC_AV1_DECODER
}
}

void AV1Decoder::Flush()
void AV1Decoder::FlushRepeatFrame(AV1DecoderFrame* frame)
{
std::unique_lock<std::mutex> l(guard);
for(std::vector<AV1DecoderFrame*>::iterator iter=outputed_frames.begin(); iter!=outputed_frames.end(); )
if (frame->Outputted() && frame->Displayed()) //repeat frame only need these 2 flags, as repeat frame will not call DpbUpdate() function
{
AV1DecoderFrame* temp = *iter;
if(temp->Outputted() && temp->Displayed() && !temp->Decoded() && !temp->Repeated() && temp->DpbUpdated())
{
temp->DecrementReference();
iter = outputed_frames.erase(iter);
}
else
iter++;
frame->DecrementReference(); //repeat frame decrement here
}
}

Expand Down
1 change: 0 additions & 1 deletion _studio/shared/umc/codec/av1_dec/src/umc_av1_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ namespace UMC_AV1_DECODER
error = 0;
displayed = false;
dpb_updated = false;
repeated = false;
outputted = false;
decoded = false;
skipped = false;
Expand Down

0 comments on commit 268eb9a

Please sign in to comment.