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

📄 umc_h264_enc_cpb.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        pCurr = pCurr->future();
    }

}    // countActiveRefs

///////////////////////////////////////////////////////////////////////////////
// removeAllRef
// Marks all frames as not used as reference frames.
///////////////////////////////////////////////////////////////////////////////

template <class PixType>
void H264EncoderFrameList<PixType>::removeAllRef()
{
    H264EncoderFrame<PixType> *pCurr = m_pHead;

    while (pCurr)
    {
        if (pCurr->wasEncoded())
        {
            pCurr->unSetisLongTermRef(0);
            pCurr->unSetisLongTermRef(1);
            pCurr->unSetisShortTermRef(0);
            pCurr->unSetisShortTermRef(1);
        }
        pCurr = pCurr->future();
    }

}    // removeAllRef

template <class PixType>
void H264EncoderFrameList<PixType>::IncreaseRefPicListResetCount(H264EncoderFrame<PixType> *ExcludeFrame)
{
    H264EncoderFrame<PixType> *pCurr = m_pHead;

    while (pCurr)
    {
        if (pCurr!=ExcludeFrame)
        {
            pCurr->IncreaseRefPicListResetCount(0);
            pCurr->IncreaseRefPicListResetCount(1);
        }
        pCurr = pCurr->future();
    }

}    // IncreaseRefPicListResetCount

//////////////////////////////////////////////////////////////////////////////
// freeOldestShortTermRef
// Marks the oldest (having smallest FrameNumWrap) short-term reference frame
// as not used as reference frame.
///////////////////////////////////////////////////////////////////////////////

template <class PixType>
void H264EncoderFrameList<PixType>::freeOldestShortTermRef()
{
    H264EncoderFrame<PixType> *pCurr = m_pHead;
    H264EncoderFrame<PixType> *pOldest = NULL;
    Ipp32s  SmallestFrameNumWrap = 0x0fffffff;    // very large positive

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

    VM_ASSERT(pOldest != NULL);    // Should not have been called if no short-term refs

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

}    // freeOldestShortTermRef

///////////////////////////////////////////////////////////////////////////////
// freeShortTermRef
// Mark the short-term reference frame with specified PicNum as not used
///////////////////////////////////////////////////////////////////////////////

template <class PixType>
void H264EncoderFrameList<PixType>::freeShortTermRef(Ipp32s  PicNum)
{
    H264EncoderFrame<PixType> *pCurr = m_pHead;
    bool found = false;
    while (pCurr)
    {
        if (pCurr->m_PictureStructureForRef>=FRM_STRUCTURE)
        {
            if (pCurr->isShortTermRef() && (pCurr->PicNum(0) == PicNum))
            {
                pCurr->unSetisShortTermRef(0);
                break;
            }
        }
        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) break;

        }

        pCurr = pCurr->future();
    }
    VM_ASSERT(pCurr != NULL);    // No match found, should not happen.

}    // freeShortTermRef

///////////////////////////////////////////////////////////////////////////////
// freeLongTermRef
// Mark the long-term reference frame with specified LongTermPicNum as not used
///////////////////////////////////////////////////////////////////////////////

template <class PixType>
void H264EncoderFrameList<PixType>::freeLongTermRef(Ipp32s  LongTermPicNum)
{
    H264EncoderFrame<PixType> *pCurr = m_pHead;
    bool found = false;

    while (pCurr)
    {
        if (pCurr->m_PictureStructureForRef>=FRM_STRUCTURE)
        {
            if (pCurr->isLongTermRef() && (pCurr->LongTermPicNum(0) == LongTermPicNum))
            {
                pCurr->unSetisLongTermRef(0);
                break;
            }
        }
        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) break;

        }

        pCurr = pCurr->future();
    }
    VM_ASSERT(pCurr != NULL);    // No match found, should not happen.

}    // freeLongTermRef

///////////////////////////////////////////////////////////////////////////////
// freeLongTermRef
// Mark the long-term reference frame with specified LongTermFrameIdx
// as not used
///////////////////////////////////////////////////////////////////////////////

template <class PixType>
void H264EncoderFrameList<PixType>::freeLongTermRefIdx(Ipp32s  LongTermFrameIdx)
{
    H264EncoderFrame<PixType> *pCurr = m_pHead;
    bool found = false;

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

        }

        pCurr = pCurr->future();
    }

    // OK if none found

}    // 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.
///////////////////////////////////////////////////////////////////////////////

template <class PixType>
void H264EncoderFrameList<PixType>::freeOldLongTermRef(Ipp32s  MaxLongTermFrameIdx)
{
    H264EncoderFrame<PixType> *pCurr = m_pHead;

    while (pCurr)
    {
        if (pCurr->isLongTermRef(0) && (pCurr->LongTermFrameIdx() > MaxLongTermFrameIdx))
        {
            pCurr->unSetisLongTermRef(0);
            pCurr->unSetisLongTermRef(1);
        }
        pCurr = pCurr->future();
    }

}    // freeOldLongTermRef

///////////////////////////////////////////////////////////////////////////////
// changeSTtoLTRef
//    Mark the short-term reference frame with specified PicNum as long-term
//  with specified long term idx.
///////////////////////////////////////////////////////////////////////////////

template <class PixType>
void H264EncoderFrameList<PixType>::changeSTtoLTRef(Ipp32s  PicNum, Ipp32s  LongTermFrameIdx)
{
    H264EncoderFrame<PixType> *pCurr = m_pHead;
    bool found=false;
    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);
                break;
            }
        }
        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]);
                found = true;
            }
            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]);
                found = true;
            }
            if (found) break;

        }
        pCurr = pCurr->future();
    }
    VM_ASSERT(pCurr != NULL);    // No match found, should not happen.

}    // changeSTtoLTRef

template <class PixType>
H264EncoderFrame<PixType> *H264EncoderFrameList<PixType>::InsertFrame(VideoData* rFrame,
                                                                      EnumPicCodType ePictureType,
                                                                      Ipp32s        isRef,
                                                                      Ipp32s         num_slices,
                                                                      const IppiSize &padded_size
#if defined ALPHA_BLENDING_H264
                                                                      , Ipp32s alpha
#endif
                                                                      )
{
    Status ps = UMC_OK;
    H264EncoderFrame<PixType> *pFrm;

    pFrm = findNextDisposable();

    //if there are no unused frames allocate new frame
    if (!pFrm){
        pFrm = new H264EncoderFrame<PixType>( rFrame, memAlloc
#if defined ALPHA_BLENDING_H264
            ,alpha
#endif
            ); //Init/allocate from input data
        if( (ps = pFrm->allocate(padded_size, num_slices)) != UMC_OK ) return NULL;
        insertAtCurrent(pFrm);
    }

    rFrame->GetTime( pFrm->pts_start, pFrm->pts_end );

    //Make copy of input data
    VideoProcessing* frame_cnv = new VideoProcessing;
    frame_cnv->GetFrame( rFrame, pFrm );
    delete frame_cnv;

/*    FILE* f = fopen("test.yuv","wb");
    for( int  i = 0; i<pFrm->GetHeight(); i++){
        fwrite((Ipp8u*)pFrm->GetPlanePointer(0)+i*pFrm->GetPlanePitch(0), 1, pFrm->GetWidth()*sizeof(PixType),f);
    }
    for( int  i = 0; i<pFrm->GetHeight()/2; i++){
        fwrite((Ipp8u*)pFrm->GetPlanePointer(1)+i*pFrm->GetPlanePitch(1), 1, pFrm->GetWidth()*sizeof(PixType),f);
    }
    for( int  i = 0; i<pFrm->GetHeight()/2; i++){
        fwrite((Ipp8u*)pFrm->GetPlanePointer(2)+i*pFrm->GetPlanePitch(2), 1, pFrm->GetWidth()*sizeof(PixType),f);
    }
    fclose(f);
*/
    pFrm->m_PicCodType = ePictureType;
    pFrm->m_RefPic = isRef;
    pFrm->unsetWasEncoded();
    return pFrm;
}

/*
#if defined ALPHA_BLENDING_H264
template <class PixType>  inline void H264EncoderFrameList<PixType>::switchToPrimary()
{
    H264EncoderFrame<PixType>* frm = head();
    for(;frm;frm = frm->future()) frm->usePrimary();
}

template <class PixType> inline void H264EncoderFrameList<PixType>::switchToAuxiliary()
{
    H264EncoderFrame<PixType>* frm = head();
    for(;frm;frm = frm->future()) frm->useAux();
}
#endif
*/
/*
template <class PixType> void exchangeFrameYUVPointers( H264EncoderFrame<PixType>* frame1, H264EncoderFrame<PixType>* frame2 )
{
    PixType* tmp1;
    PixType* tmp2;
    PixType* tmp3;
    MemID    id_tmp;
    Ipp8u*   tmp;
    Ipp32s   i;

    tmp1 = frame1->m_pYPlane;
    tmp2 = frame1->m_pUPlane;
    tmp3 = frame1->m_pVPlane;
    frame1->m_pYPlane = frame2->m_pYPlane;
    frame1->m_pUPlane = frame2->m_pUPlane;
    frame1->m_pVPlane = frame2->m_pVPlane;
    frame2->m_pYPlane = tmp1;
    frame2->m_pUPlane = tmp2;
    frame2->m_pVPlane = tmp3;

    id_tmp = frame1->frameDataID;
    frame1->frameDataID = frame2->frameDataID;
    frame2->frameDataID = id_tmp;

    tmp = frame1->frameData;
    frame1->frameData = frame2->frameData;
    frame2->frameData = tmp;

    for( i=0; i < frame1->GetNumPlanes(); i++ ){
        void* tmp = frame1->GetPlanePointer( i );
        frame1->SetPlanePointer( frame2->GetPlanePointer(i), i );
        frame2->SetPlanePointer( tmp, i );
    }

    return;
}
*/

#pragma warning(disable:4661)
template class H264EncoderFrame<Ipp8u>;
template class H264EncoderFrameList<Ipp8u>;
//template void exchangeFrameYUVPointers( H264EncoderFrame<Ipp8u>* frame1, H264EncoderFrame<Ipp8u>* frame2 );
#if defined BITDEPTH_9_12
template class H264EncoderFrame<Ipp16u>;
template class H264EncoderFrameList<Ipp16u>;
//template void exchangeFrameYUVPointers( H264EncoderFrame<Ipp16u>* frame1, H264EncoderFrame<Ipp16u>* frame2 );
#endif

} //namespace UMC_H264_ENCODER

⌨️ 快捷键说明

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