⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umc_h264_frame_list.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    }

}    // IncreaseRefPicListResetCount

///////////////////////////////////////////////////////////////////////////////
// removeAllDisplayable
// Marks all frames as not displayable.
///////////////////////////////////////////////////////////////////////////////
void H264DBPList::removeAllDisplayable()
{
    H264DecoderFrame *pCurr = m_pHead;

    while (pCurr)
    {
        pCurr->unSetisDisplayable();
        pCurr = pCurr->future();
    }

}    // removeAllDisplayable

///////////////////////////////////////////////////////////////////////////////
// freeOldestShortTermRef
// Marks the oldest (having smallest FrameNumWrap) short-term reference frame
// as not used as reference frame.
///////////////////////////////////////////////////////////////////////////////
H264DecoderFrame * H264DBPList::freeOldestShortTermRef()
{
    H264DecoderFrame *pOldest = findOldestShortTermRef();
    VM_ASSERT(pOldest != NULL);    // Should not have been called if no short-term refs

    if (pOldest)
    {
        pOldest->unSetisShortTermRef(0);
        pOldest->unSetisShortTermRef(1);
    }

    return pOldest;
}    // freeOldestShortTermRef

H264DecoderFrame * H264DBPList::findOldestShortTermRef()
{
    H264DecoderFrame *pCurr = m_pHead;
    H264DecoderFrame *pOldest = NULL;
    Ipp32s  SmallestFrameNumWrap = 0x0fffffff;    // very large positive

    while (pCurr)
    {
        if (pCurr->isShortTermRef() && (pCurr->FrameNumWrap() < SmallestFrameNumWrap))
        {
            pOldest = pCurr;
            SmallestFrameNumWrap = pCurr->FrameNumWrap();
        }
        pCurr = pCurr->future();
    }

    return pOldest;
}    // findOldestShortTermRef

///////////////////////////////////////////////////////////////////////////////
// freeShortTermRef
// Mark the short-term reference frame with specified picNum as not used
///////////////////////////////////////////////////////////////////////////////
H264DecoderFrame * H264DBPList::freeShortTermRef(Ipp32s  picNum)
{
    H264DecoderFrame *pCurr = m_pHead;
    bool found = false;
    while (pCurr)
    {
        if (pCurr->m_PictureStructureForRef >= FRM_STRUCTURE)
        {
            if (pCurr->isShortTermRef() && (pCurr->PicNum(0) == picNum))
            {
                pCurr->unSetisShortTermRef(0);
                return pCurr;
            }
        }
        else
        {
            if (pCurr->isShortTermRef(0) && (pCurr->PicNum(0) == picNum))
            {
                pCurr->unSetisShortTermRef(0);
                found = true;
            }

            if (pCurr->isShortTermRef(1) && (pCurr->PicNum(1) == picNum))
            {
                pCurr->unSetisShortTermRef(1);
                found = true;
            }

            if (found)
                return pCurr;
        }

        pCurr = pCurr->future();
    }

    VM_ASSERT(false);
    return 0;
}    // freeShortTermRef

///////////////////////////////////////////////////////////////////////////////
// freeLongTermRef
// Mark the long-term reference frame with specified LongTermPicNum as not used
///////////////////////////////////////////////////////////////////////////////
H264DecoderFrame * H264DBPList::freeLongTermRef(Ipp32s  LongTermPicNum)
{
    H264DecoderFrame *pCurr = m_pHead;
    bool found = false;

    while (pCurr)
    {
        if (pCurr->m_PictureStructureForRef>=FRM_STRUCTURE)
        {
            if (pCurr->isLongTermRef() && (pCurr->LongTermPicNum(0) == LongTermPicNum))
            {
                pCurr->unSetisLongTermRef(0);
                return pCurr;
            }
        }
        else
        {
            if (pCurr->isLongTermRef(0) && (pCurr->LongTermPicNum(0) == LongTermPicNum))
            {
                pCurr->unSetisLongTermRef(0);
                found = true;
            }

            if (pCurr->isLongTermRef(1) && (pCurr->LongTermPicNum(1) == LongTermPicNum))
            {
                pCurr->unSetisLongTermRef(1);
                found = true;
            }

            if (found)
                return pCurr;
        }

        pCurr = pCurr->future();
    }


    VM_ASSERT(false);    // No match found, should not happen.
    return 0;
}    // freeLongTermRef

///////////////////////////////////////////////////////////////////////////////
// freeLongTermRef
// Mark the long-term reference frame with specified LongTermFrameIdx
// as not used
///////////////////////////////////////////////////////////////////////////////
H264DecoderFrame * H264DBPList::freeLongTermRefIdx(Ipp32s  LongTermFrameIdx, H264DecoderFrame * pCurrentFrame)
{
    H264DecoderFrame *pCurr = m_pHead;

    while (pCurr)
    {
        if (pCurr->m_PictureStructureForRef >= FRM_STRUCTURE)
        {
            if (pCurr->isLongTermRef() && (pCurr->LongTermFrameIdx() == LongTermFrameIdx ))
            {
                if (pCurrentFrame == pCurr)
                    return 0;
                pCurr->unSetisLongTermRef(0);
                return pCurr;
            }
        }
        else
        {
            if (pCurr->isLongTermRef(0) && (pCurr->LongTermFrameIdx() == LongTermFrameIdx ))
            {
                if (pCurrentFrame == pCurr)
                    return 0;
                pCurr->unSetisLongTermRef(0);
                pCurr->unSetisLongTermRef(1);
                return pCurr;
            }

            if (pCurr->isLongTermRef(1) && (pCurr->LongTermFrameIdx() == LongTermFrameIdx ))
            {
                if (pCurrentFrame == pCurr)
                    return 0;
                pCurr->unSetisLongTermRef(0);
                pCurr->unSetisLongTermRef(1);
                return pCurr;
            }
        }

        pCurr = pCurr->future();
    }

    VM_ASSERT(false);
    return 0;
}    // freeLongTermRefIdx

///////////////////////////////////////////////////////////////////////////////
// freeOldLongTermRef
// Mark any long-term reference frame with LongTermFrameIdx greater
// than MaxLongTermFrameIdx as not used. When MaxLongTermFrameIdx is -1, this
// indicates no long-term frame indices and all long-term reference
// frames should be freed.
///////////////////////////////////////////////////////////////////////////////
H264DecoderFrame * H264DBPList::freeOldLongTermRef(Ipp32s  MaxLongTermFrameIdx, H264DecoderFrame * pFrame)
{
    H264DecoderFrame *pCurr = m_pHead;

    while (pCurr)
    {
        if (pCurr->isLongTermRef(0) && (pCurr->LongTermFrameIdx() > MaxLongTermFrameIdx))
        {
            OnSlideWindow(pCurr, pFrame, 0, true);

            pCurr->unSetisLongTermRef(0);
            pCurr->unSetisLongTermRef(1);
        }

        pCurr = pCurr->future();
    }

    return 0;
    // OK to not find any to free

}    // freeOldLongTermRef

///////////////////////////////////////////////////////////////////////////////
// changeSTtoLTRef
//    Mark the short-term reference frame with specified PicNum as long-term
//  with specified long term idx.
///////////////////////////////////////////////////////////////////////////////
void H264DBPList::changeSTtoLTRef(Ipp32s  picNum, Ipp32s  longTermFrameIdx)
{
    H264DecoderFrame *pCurr = m_pHead;
    while (pCurr)
    {
        if (pCurr->m_PictureStructureForRef >= FRM_STRUCTURE)
        {
            if (pCurr->isShortTermRef() && (pCurr->PicNum(0) == picNum))
            {
                pCurr->unSetisShortTermRef(0);
                pCurr->setLongTermFrameIdx(longTermFrameIdx);
                pCurr->SetisLongTermRef(0);
                pCurr->UpdateLongTermPicNum(2);
                return;
            }
        }
        else
        {
            if (pCurr->isShortTermRef(0) && (pCurr->PicNum(0) == picNum))
            {
                pCurr->unSetisShortTermRef(0);
                pCurr->setLongTermFrameIdx(longTermFrameIdx);
                pCurr->SetisLongTermRef(0);
                pCurr->UpdateLongTermPicNum(pCurr->m_bottom_field_flag[0]);
                return;
            }

            if (pCurr->isShortTermRef(1) && (pCurr->PicNum(1) == picNum))
            {
                pCurr->unSetisShortTermRef(1);
                pCurr->setLongTermFrameIdx(longTermFrameIdx);
                pCurr->SetisLongTermRef(1);
                pCurr->UpdateLongTermPicNum(pCurr->m_bottom_field_flag[1]);
                return;
            }
        }
        pCurr = pCurr->future();
    }

    VM_ASSERT(false);    // No match found, should not happen.
    return;
}    // changeSTtoLTRef

H264DecoderFrame *H264DBPList::findShortTermPic(Ipp32s  picNum, Ipp32s * field)
{
    H264DecoderFrame *pCurr = m_pHead;

    while (pCurr)
    {
        if (pCurr->m_PictureStructureForRef >= FRM_STRUCTURE)
        {
            if ((pCurr->isShortTermRef() == 3) && (pCurr->PicNum(0) == picNum))
            {
                return pCurr;
            }
        }
        else
        {
            if (pCurr->isShortTermRef(0) && (pCurr->PicNum(0) == picNum))
            {
                if (field)
                    *field = 0;
                return pCurr;
            }

            if (pCurr->isShortTermRef(1) && (pCurr->PicNum(1) == picNum))
            {
                if (field)
                    *field = 1;
                return pCurr;
            }
        }

        pCurr = pCurr->future();
    }

    VM_ASSERT(false);    // No match found, should not happen.
    return 0;
}    // findShortTermPic

H264DecoderFrame *H264DBPList::findLongTermPic(Ipp32s  picNum, Ipp32s * field)
{
    H264DecoderFrame *pCurr = m_pHead;

    while (pCurr)
    {
        if (pCurr->m_PictureStructureForRef >= FRM_STRUCTURE)
        {
            if ((pCurr->isLongTermRef() == 3) && (pCurr->LongTermPicNum(0) == picNum))
            {
                return pCurr;
            }
        }
        else
        {
            if (pCurr->isLongTermRef(0) && (pCurr->LongTermPicNum(0) == picNum))
            {
                *field = 0;
                return pCurr;
            }

            if (pCurr->isLongTermRef(1) && (pCurr->LongTermPicNum(1) == picNum))
            {
                *field = 1;
                return pCurr;
            }
        }

        pCurr = pCurr->future();
    }

    VM_ASSERT(false);    // No match found, should not happen.
    return 0;
}    // findLongTermPic

H264DecoderFrame * H264DBPList::FindClosest(H264DecoderFrame * pFrame)
{
    Ipp32s poc = pFrame->PicOrderCnt(0, 3);

    H264DecoderFrame * pOldest = 0;

    Ipp32s  SmallestPicOrderCnt = 0x7fffffff;    // very large positive
    Ipp32s  SmallestRefPicListResetCount = 0;

    for (H264DecoderFrame * pTmp = m_pHead; pTmp; pTmp = pTmp->future())
    {
        if (pTmp->IsSkipped())
            continue;

        if (pTmp != pFrame)
        {
            if (pTmp->m_chroma_format != pFrame->m_chroma_format ||
                pTmp->lumaSize().width != pFrame->lumaSize().width ||
                pTmp->lumaSize().height != pFrame->lumaSize().height)
                continue;

            if (pTmp->RefPicListResetCount(0,3) < SmallestRefPicListResetCount)
            {
                pOldest = pTmp;
                SmallestPicOrderCnt = pTmp->PicOrderCnt(0,3);
                SmallestRefPicListResetCount = pTmp->RefPicListResetCount(0,3);
            }
            else if ((pTmp->PicOrderCnt(0,3) < poc) &&
                     (pTmp->RefPicListResetCount(0,3) == SmallestRefPicListResetCount))
            {
                pOldest = pTmp;
                SmallestPicOrderCnt = pTmp->PicOrderCnt(0,3);
            }
        }
        else
        {
            break;
        }
    }

    return pOldest;
}

void H264DBPList::DebugPrint()
{
    printf("-==========================================\n");
    for (H264DecoderFrame * pTmp = m_pHead; pTmp; pTmp = pTmp->future())
    {
        printf("\n\nUID - %d POC - %d %d  - resetcount - %d\n", pTmp->m_UID, pTmp->m_PicOrderCnt[0], pTmp->m_PicOrderCnt[1], pTmp->RefPicListResetCount(0,3));
        printf("Short - %d %d \n", pTmp->isShortTermRef(0), pTmp->isShortTermRef(1));
        printf("Long - %d %d \n", pTmp->isLongTermRef(0), pTmp->isLongTermRef(1));
        printf("Busy - %d \n", pTmp->GetBusyState());
        printf("Skipping - %d, FrameExist - %d \n", pTmp->IsSkipped(), pTmp->IsFrameExist());
        printf("PicNum - (%d, %d) \n", pTmp->m_PicNum[0], pTmp->m_PicNum[1]);
        printf("LongPicNum - (%d, %d) \n", pTmp->m_LongTermPicNum[0], pTmp->m_LongTermPicNum[1]);
        printf("Disp - %d , wasOutput - %d\n", pTmp->isDisplayable(), pTmp->wasOutputted());

    }
    printf("-==========================================\n");
}


} // end namespace UMC
#endif // UMC_ENABLE_H264_VIDEO_DECODER

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -