x 265ソース解析:参照フレーム管理

4687 ワード

x 265ソース解析:NAL Unit Type x 265ソース解析:参照フレーム管理x 265ソース解析:符号化構造
//!  rps
void DPB::computeRPS(int curPoc, bool isRAP, RPS * rps, unsigned int maxDecPicBuffer)
{
    unsigned int poci = 0, numNeg = 0, numPos = 0;

    Frame* iterPic = m_picList.first();

    while (iterPic && (poci < maxDecPicBuffer - 1))     ///< iterate decode picture buf
    {
        if ((iterPic->m_poc != curPoc) && iterPic->m_encData->m_bHasReferences)
        {
            if ((m_lastIDR >= curPoc) || (m_lastIDR <= iterPic->m_poc))
            {
                    rps->poc[poci] = iterPic->m_poc;
                    rps->deltaPOC[poci] = rps->poc[poci] - curPoc;          ///< used to construct StBefor StAfter
                    (rps->deltaPOC[poci] < 0) ? numNeg++ : numPos++;
                    rps->bUsed[poci] = !isRAP;                              ///<  :nal unit type
                    poci++;
            }
        }
        iterPic = iterPic->m_next;
    }

    rps->numberOfPictures = poci;
    rps->numberOfPositivePictures = numPos;
    rps->numberOfNegativePictures = numNeg;

    rps->sortDeltaPOC();
}
//!  
void Slice::setRefPicList(PicList& picList)
{
    //! I 
    if (m_sliceType == I_SLICE)
    {
        memset(m_refFrameList, 0, sizeof(m_refFrameList));
        memset(m_refReconPicList, 0, sizeof(m_refReconPicList));
        memset(m_refPOCList, 0, sizeof(m_refPOCList));
        m_numRefIdx[1] = m_numRefIdx[0] = 0;
        return;
    }

    Frame* refPic = NULL;
    Frame* refPicSetStCurr0[MAX_NUM_REF]; 
    Frame* refPicSetStCurr1[MAX_NUM_REF];
    Frame* refPicSetLtCurr[MAX_NUM_REF];
    int numPocStCurr0 = 0;
    int numPocStCurr1 = 0;
    int numPocLtCurr = 0;
    int i;
    
    //!  Ref Short-Term Before
    for (i = 0; i < m_rps.numberOfNegativePictures; i++)
    {
        if (m_rps.bUsed[i])
        {
            refPic = picList.getPOC(m_poc + m_rps.deltaPOC[i]);
            refPicSetStCurr0[numPocStCurr0] = refPic;
            numPocStCurr0++;
        }
    }
    //!  Ref Short-Term After
    for (; i < m_rps.numberOfNegativePictures + m_rps.numberOfPositivePictures; i++)
    {
        if (m_rps.bUsed[i])
        {
            refPic = picList.getPOC(m_poc + m_rps.deltaPOC[i]);
            refPicSetStCurr1[numPocStCurr1] = refPic;
            numPocStCurr1++;
        }
    }

    X265_CHECK(m_rps.numberOfPictures == m_rps.numberOfNegativePictures + m_rps.numberOfPositivePictures,
               "unexpected picture in RPS
"); // ref_pic_list_init Frame* rpsCurrList0[MAX_NUM_REF + 1]; ///< L0 Frame* rpsCurrList1[MAX_NUM_REF + 1]; ///< L1 int numPocTotalCurr = numPocStCurr0 + numPocStCurr1 + numPocLtCurr; //! L0 int cIdx = 0; for (i = 0; i < numPocStCurr0; i++, cIdx++) rpsCurrList0[cIdx] = refPicSetStCurr0[i]; for (i = 0; i < numPocStCurr1; i++, cIdx++) rpsCurrList0[cIdx] = refPicSetStCurr1[i]; for (i = 0; i < numPocLtCurr; i++, cIdx++) rpsCurrList0[cIdx] = refPicSetLtCurr[i]; X265_CHECK(cIdx == numPocTotalCurr, "RPS index check fail
"); //! L1 if (m_sliceType == B_SLICE) { cIdx = 0; for (i = 0; i < numPocStCurr1; i++, cIdx++) rpsCurrList1[cIdx] = refPicSetStCurr1[i]; for (i = 0; i < numPocStCurr0; i++, cIdx++) rpsCurrList1[cIdx] = refPicSetStCurr0[i]; for (i = 0; i < numPocLtCurr; i++, cIdx++) rpsCurrList1[cIdx] = refPicSetLtCurr[i]; X265_CHECK(cIdx == numPocTotalCurr, "RPS index check fail
"); } for (int rIdx = 0; rIdx < m_numRefIdx[0]; rIdx++) { cIdx = rIdx % numPocTotalCurr; X265_CHECK(cIdx >= 0 && cIdx < numPocTotalCurr, "RPS index check fail
"); m_refFrameList[0][rIdx] = rpsCurrList0[cIdx]; } if (m_sliceType != B_SLICE) { m_numRefIdx[1] = 0; memset(m_refFrameList[1], 0, sizeof(m_refFrameList[1])); } else { for (int rIdx = 0; rIdx < m_numRefIdx[1]; rIdx++) { cIdx = rIdx % numPocTotalCurr; X265_CHECK(cIdx >= 0 && cIdx < numPocTotalCurr, "RPS index check fail
"); m_refFrameList[1][rIdx] = rpsCurrList1[cIdx]; } } //! ref POC list for (int dir = 0; dir < 2; dir++) for (int numRefIdx = 0; numRefIdx < m_numRefIdx[dir]; numRefIdx++) m_refPOCList[dir][numRefIdx] = m_refFrameList[dir][numRefIdx]->m_poc; }