[x265] [PATCH 2 of 2] encoder: proper indentation for the zero-latency loop, no logic changes

Steve Borho steve at borho.org
Wed Jan 21 18:21:35 CET 2015


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1421860883 21600
#      Wed Jan 21 11:21:23 2015 -0600
# Node ID c7edd8f4df131550a80f801a369992dbadd49197
# Parent  7aec6406358de473ffe6ec97fa3916cc95a2307c
encoder: proper indentation for the zero-latency loop, no logic changes

diff -r 7aec6406358d -r c7edd8f4df13 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Wed Jan 21 11:20:10 2015 -0600
+++ b/source/encoder/encoder.cpp	Wed Jan 21 11:21:23 2015 -0600
@@ -499,176 +499,174 @@
     int pass = 0;
     do
     {
+        /* getEncodedPicture() should block until the FrameEncoder has completed
+         * encoding the frame.  This is how back-pressure through the API is
+         * accomplished when the encoder is full */
+        if (!m_bZeroLatency || pass)
+            outFrame = curEncoder->getEncodedPicture(m_nalList);
+        if (outFrame)
+        {
+            Slice *slice = outFrame->m_encData->m_slice;
 
-    /* getEncodedPicture() should block until the FrameEncoder has completed
-     * encoding the frame.  This is how back-pressure through the API is
-     * accomplished when the encoder is full */
-    if (!m_bZeroLatency || pass)
-        outFrame = curEncoder->getEncodedPicture(m_nalList);
-    if (outFrame)
-    {
-        Slice *slice = outFrame->m_encData->m_slice;
+            /* Free up pic_in->analysisData since it has already been used */
+            if (m_param->analysisMode == X265_ANALYSIS_LOAD)
+                freeAnalysis(&outFrame->m_analysisData);
 
-        /* Free up pic_in->analysisData since it has already been used */
-        if (m_param->analysisMode == X265_ANALYSIS_LOAD)
-            freeAnalysis(&outFrame->m_analysisData);
+            if (pic_out)
+            {
+                PicYuv *recpic = outFrame->m_reconPic;
+                pic_out->poc = slice->m_poc;
+                pic_out->bitDepth = X265_DEPTH;
+                pic_out->userData = outFrame->m_userData;
+                pic_out->colorSpace = m_param->internalCsp;
 
-        if (pic_out)
-        {
-            PicYuv *recpic = outFrame->m_reconPic;
-            pic_out->poc = slice->m_poc;
-            pic_out->bitDepth = X265_DEPTH;
-            pic_out->userData = outFrame->m_userData;
-            pic_out->colorSpace = m_param->internalCsp;
+                pic_out->pts = outFrame->m_pts;
+                pic_out->dts = outFrame->m_dts;
 
-            pic_out->pts = outFrame->m_pts;
-            pic_out->dts = outFrame->m_dts;
+                switch (slice->m_sliceType)
+                {
+                case I_SLICE:
+                    pic_out->sliceType = outFrame->m_lowres.bKeyframe ? X265_TYPE_IDR : X265_TYPE_I;
+                    break;
+                case P_SLICE:
+                    pic_out->sliceType = X265_TYPE_P;
+                    break;
+                case B_SLICE:
+                    pic_out->sliceType = X265_TYPE_B;
+                    break;
+                }
 
-            switch (slice->m_sliceType)
+                pic_out->planes[0] = recpic->m_picOrg[0];
+                pic_out->stride[0] = (int)(recpic->m_stride * sizeof(pixel));
+                pic_out->planes[1] = recpic->m_picOrg[1];
+                pic_out->stride[1] = (int)(recpic->m_strideC * sizeof(pixel));
+                pic_out->planes[2] = recpic->m_picOrg[2];
+                pic_out->stride[2] = (int)(recpic->m_strideC * sizeof(pixel));
+
+                /* Dump analysis data from pic_out to file in save mode and free */
+                if (m_param->analysisMode == X265_ANALYSIS_SAVE)
+                {
+                    pic_out->analysisData.poc = pic_out->poc;
+                    pic_out->analysisData.sliceType = pic_out->sliceType;
+                    pic_out->analysisData.numCUsInFrame = outFrame->m_analysisData.numCUsInFrame;
+                    pic_out->analysisData.numPartitions = outFrame->m_analysisData.numPartitions;
+                    pic_out->analysisData.interData = outFrame->m_analysisData.interData;
+                    pic_out->analysisData.intraData = outFrame->m_analysisData.intraData;
+                    writeAnalysisFile(&pic_out->analysisData);
+                    freeAnalysis(&pic_out->analysisData);
+                }
+            }
+            if (slice->m_sliceType == P_SLICE)
             {
-            case I_SLICE:
-                pic_out->sliceType = outFrame->m_lowres.bKeyframe ? X265_TYPE_IDR : X265_TYPE_I;
-                break;
-            case P_SLICE:
-                pic_out->sliceType = X265_TYPE_P;
-                break;
-            case B_SLICE:
-                pic_out->sliceType = X265_TYPE_B;
-                break;
+                if (slice->m_weightPredTable[0][0][0].bPresentFlag)
+                    m_numLumaWPFrames++;
+                if (slice->m_weightPredTable[0][0][1].bPresentFlag ||
+                    slice->m_weightPredTable[0][0][2].bPresentFlag)
+                    m_numChromaWPFrames++;
+            }
+            else if (slice->m_sliceType == B_SLICE)
+            {
+                bool bLuma = false, bChroma = false;
+                for (int l = 0; l < 2; l++)
+                {
+                    if (slice->m_weightPredTable[l][0][0].bPresentFlag)
+                        bLuma = true;
+                    if (slice->m_weightPredTable[l][0][1].bPresentFlag ||
+                        slice->m_weightPredTable[l][0][2].bPresentFlag)
+                        bChroma = true;
+                }
+
+                if (bLuma)
+                    m_numLumaWPBiFrames++;
+                if (bChroma)
+                    m_numChromaWPBiFrames++;
             }
 
-            pic_out->planes[0] = recpic->m_picOrg[0];
-            pic_out->stride[0] = (int)(recpic->m_stride * sizeof(pixel));
-            pic_out->planes[1] = recpic->m_picOrg[1];
-            pic_out->stride[1] = (int)(recpic->m_strideC * sizeof(pixel));
-            pic_out->planes[2] = recpic->m_picOrg[2];
-            pic_out->stride[2] = (int)(recpic->m_strideC * sizeof(pixel));
+            if (m_aborted)
+                return -1;
 
-            /* Dump analysis data from pic_out to file in save mode and free */
+            finishFrameStats(outFrame, curEncoder, curEncoder->m_accessUnitBits);
+
+            /* Allow this frame to be recycled if no frame encoders are using it for reference */
+            if (!pic_out)
+            {
+                ATOMIC_DEC(&outFrame->m_countRefEncoders);
+                m_dpb->recycleUnreferenced();
+            }
+            else
+                m_exportedPic = outFrame;
+
+            m_numDelayedPic--;
+
+            ret = 1;
+        }
+
+        /* pop a single frame from decided list, then provide to frame encoder
+         * curEncoder is guaranteed to be idle at this point */
+        if (!pass)
+            frameEnc = m_lookahead->getDecidedPicture();
+        if (frameEnc && !pass)
+        {
+            /* give this frame a FrameData instance before encoding */
+            if (m_dpb->m_picSymFreeList)
+            {
+                frameEnc->m_encData = m_dpb->m_picSymFreeList;
+                m_dpb->m_picSymFreeList = m_dpb->m_picSymFreeList->m_freeListNext;
+                frameEnc->reinit(m_sps);
+            }
+            else
+            {
+                frameEnc->allocEncodeData(m_param, m_sps);
+                Slice* slice = frameEnc->m_encData->m_slice;
+                slice->m_sps = &m_sps;
+                slice->m_pps = &m_pps;
+                slice->m_maxNumMergeCand = m_param->maxNumMergeCand;
+                slice->m_endCUAddr = slice->realEndAddress(m_sps.numCUsInFrame * NUM_CU_PARTITIONS);
+                frameEnc->m_reconPic->m_cuOffsetC = m_cuOffsetC;
+                frameEnc->m_reconPic->m_cuOffsetY = m_cuOffsetY;
+                frameEnc->m_reconPic->m_buOffsetC = m_buOffsetC;
+                frameEnc->m_reconPic->m_buOffsetY = m_buOffsetY;
+            }
+
+            curEncoder->m_rce.encodeOrder = m_encodedFrameNum++;
+            if (m_bframeDelay)
+            {
+                int64_t *prevReorderedPts = m_prevReorderedPts;
+                frameEnc->m_dts = m_encodedFrameNum > m_bframeDelay
+                    ? prevReorderedPts[(m_encodedFrameNum - m_bframeDelay) % m_bframeDelay]
+                    : frameEnc->m_reorderedPts - m_bframeDelayTime;
+                prevReorderedPts[m_encodedFrameNum % m_bframeDelay] = frameEnc->m_reorderedPts;
+            }
+            else
+                frameEnc->m_dts = frameEnc->m_reorderedPts;
+
+            /* Allocate analysis data before encode in save mode. This is allocated in frameEnc */
             if (m_param->analysisMode == X265_ANALYSIS_SAVE)
             {
-                pic_out->analysisData.poc = pic_out->poc;
-                pic_out->analysisData.sliceType = pic_out->sliceType;
-                pic_out->analysisData.numCUsInFrame = outFrame->m_analysisData.numCUsInFrame;
-                pic_out->analysisData.numPartitions = outFrame->m_analysisData.numPartitions;
-                pic_out->analysisData.interData = outFrame->m_analysisData.interData;
-                pic_out->analysisData.intraData = outFrame->m_analysisData.intraData;
-                writeAnalysisFile(&pic_out->analysisData);
-                freeAnalysis(&pic_out->analysisData);
-            }
-        }
-        if (slice->m_sliceType == P_SLICE)
-        {
-            if (slice->m_weightPredTable[0][0][0].bPresentFlag)
-                m_numLumaWPFrames++;
-            if (slice->m_weightPredTable[0][0][1].bPresentFlag ||
-                slice->m_weightPredTable[0][0][2].bPresentFlag)
-                m_numChromaWPFrames++;
-        }
-        else if (slice->m_sliceType == B_SLICE)
-        {
-            bool bLuma = false, bChroma = false;
-            for (int l = 0; l < 2; l++)
-            {
-                if (slice->m_weightPredTable[l][0][0].bPresentFlag)
-                    bLuma = true;
-                if (slice->m_weightPredTable[l][0][1].bPresentFlag ||
-                    slice->m_weightPredTable[l][0][2].bPresentFlag)
-                    bChroma = true;
+                x265_analysis_data* analysis = &frameEnc->m_analysisData;
+                analysis->poc = frameEnc->m_poc;
+                analysis->sliceType = frameEnc->m_lowres.sliceType;
+                uint32_t widthInCU       = (m_param->sourceWidth  + g_maxCUSize - 1) >> g_maxLog2CUSize;
+                uint32_t heightInCU      = (m_param->sourceHeight + g_maxCUSize - 1) >> g_maxLog2CUSize;
+
+                uint32_t numCUsInFrame   = widthInCU * heightInCU;
+                analysis->numCUsInFrame  = numCUsInFrame;
+                analysis->numPartitions  = NUM_CU_PARTITIONS;
+                allocAnalysis(analysis);
             }
 
-            if (bLuma)
-                m_numLumaWPBiFrames++;
-            if (bChroma)
-                m_numChromaWPBiFrames++;
+            /* determine references, setup RPS, etc */
+            m_dpb->prepareEncode(frameEnc);
+
+            if (m_param->rc.rateControlMode != X265_RC_CQP)
+                m_lookahead->getEstimatedPictureCost(frameEnc);
+
+            /* Allow FrameEncoder::compressFrame() to start in the frame encoder thread */
+            if (!curEncoder->startCompressFrame(frameEnc))
+                m_aborted = true;
         }
-
-        if (m_aborted)
-            return -1;
-
-        finishFrameStats(outFrame, curEncoder, curEncoder->m_accessUnitBits);
-
-        /* Allow this frame to be recycled if no frame encoders are using it for reference */
-        if (!pic_out)
-        {
-            ATOMIC_DEC(&outFrame->m_countRefEncoders);
-            m_dpb->recycleUnreferenced();
-        }
-        else
-            m_exportedPic = outFrame;
-
-        m_numDelayedPic--;
-
-        ret = 1;
-    }
-
-    /* pop a single frame from decided list, then provide to frame encoder
-     * curEncoder is guaranteed to be idle at this point */
-    if (!pass)
-        frameEnc = m_lookahead->getDecidedPicture();
-    if (frameEnc && !pass)
-    {
-        /* give this frame a FrameData instance before encoding */
-        if (m_dpb->m_picSymFreeList)
-        {
-            frameEnc->m_encData = m_dpb->m_picSymFreeList;
-            m_dpb->m_picSymFreeList = m_dpb->m_picSymFreeList->m_freeListNext;
-            frameEnc->reinit(m_sps);
-        }
-        else
-        {
-            frameEnc->allocEncodeData(m_param, m_sps);
-            Slice* slice = frameEnc->m_encData->m_slice;
-            slice->m_sps = &m_sps;
-            slice->m_pps = &m_pps;
-            slice->m_maxNumMergeCand = m_param->maxNumMergeCand;
-            slice->m_endCUAddr = slice->realEndAddress(m_sps.numCUsInFrame * NUM_CU_PARTITIONS);
-            frameEnc->m_reconPic->m_cuOffsetC = m_cuOffsetC;
-            frameEnc->m_reconPic->m_cuOffsetY = m_cuOffsetY;
-            frameEnc->m_reconPic->m_buOffsetC = m_buOffsetC;
-            frameEnc->m_reconPic->m_buOffsetY = m_buOffsetY;
-        }
-
-        curEncoder->m_rce.encodeOrder = m_encodedFrameNum++;
-        if (m_bframeDelay)
-        {
-            int64_t *prevReorderedPts = m_prevReorderedPts;
-            frameEnc->m_dts = m_encodedFrameNum > m_bframeDelay
-                ? prevReorderedPts[(m_encodedFrameNum - m_bframeDelay) % m_bframeDelay]
-                : frameEnc->m_reorderedPts - m_bframeDelayTime;
-            prevReorderedPts[m_encodedFrameNum % m_bframeDelay] = frameEnc->m_reorderedPts;
-        }
-        else
-            frameEnc->m_dts = frameEnc->m_reorderedPts;
-
-        /* Allocate analysis data before encode in save mode. This is allocated in frameEnc */
-        if (m_param->analysisMode == X265_ANALYSIS_SAVE)
-        {
-            x265_analysis_data* analysis = &frameEnc->m_analysisData;
-            analysis->poc = frameEnc->m_poc;
-            analysis->sliceType = frameEnc->m_lowres.sliceType;
-            uint32_t widthInCU       = (m_param->sourceWidth  + g_maxCUSize - 1) >> g_maxLog2CUSize;
-            uint32_t heightInCU      = (m_param->sourceHeight + g_maxCUSize - 1) >> g_maxLog2CUSize;
-
-            uint32_t numCUsInFrame   = widthInCU * heightInCU;
-            analysis->numCUsInFrame  = numCUsInFrame;
-            analysis->numPartitions  = NUM_CU_PARTITIONS;
-            allocAnalysis(analysis);
-        }
-
-        /* determine references, setup RPS, etc */
-        m_dpb->prepareEncode(frameEnc);
-
-        if (m_param->rc.rateControlMode != X265_RC_CQP)
-            m_lookahead->getEstimatedPictureCost(frameEnc);
-
-        /* Allow FrameEncoder::compressFrame() to start in the frame encoder thread */
-        if (!curEncoder->startCompressFrame(frameEnc))
-            m_aborted = true;
-    }
-    else if (m_encodedFrameNum)
-        m_rateControl->setFinalFrameCount(m_encodedFrameNum);
-
+        else if (m_encodedFrameNum)
+            m_rateControl->setFinalFrameCount(m_encodedFrameNum);
     }
     while (m_bZeroLatency && ++pass < 2);
 


More information about the x265-devel mailing list