[x265] [PATCH] Replaced Encoder* with x265_param* as member of

dtyx265 at gmail.com dtyx265 at gmail.com
Sat Mar 8 01:48:23 CET 2014


# HG changeset patch
# User David T Yuen <dtyx265 at gmail.com>
# Date 1394239618 28800
# Node ID 8584ba886cb036301b6424b6fe1a83c423597405
# Parent  9f3515756d0fc0a5496f722ae208341ee2e8d61c
Replaced Encoder* with x265_param* as member of
TEncCu, framefilter, ratecontrol, CostEstimate and Lookahead
Added m_CUTransquantBypassFlagValue to TEncCu since it's part of Encoder and not x265_param
framefilter's processRow and processRowPost needed Encoder* to run Encoder::signalReconRowCompleted

diff -r 9f3515756d0f -r 8584ba886cb0 source/Lib/TLibEncoder/TEncCu.cpp
--- a/source/Lib/TLibEncoder/TEncCu.cpp	Fri Mar 07 14:49:07 2014 -0800
+++ b/source/Lib/TLibEncoder/TEncCu.cpp	Fri Mar 07 16:46:58 2014 -0800
@@ -100,7 +100,7 @@
 
     m_origYuv = new TComYuv*[m_totalDepth - 1];
 
-    int csp = m_cfg->param->internalCsp;
+    int csp = m_param->internalCsp;
 
     bool ok = true;
     for (int i = 0; i < m_totalDepth - 1; i++)
@@ -330,7 +330,8 @@
  */
 void TEncCu::init(Encoder* top)
 {
-    m_cfg = top;
+    m_param = top->param;
+    m_CUTransquantBypassFlagValue = top->m_CUTransquantBypassFlagValue;
 }
 
 // ====================================================================================================================
@@ -380,7 +381,7 @@
     }
     else
     {
-        if (m_cfg->param->rdLevel < 5)
+        if (m_param->rdLevel < 5)
         {
             TComDataCU* outBestCU = NULL;
 
@@ -731,7 +732,7 @@
         if (outBestCU->getSlice()->getSliceType() != I_SLICE)
         {
             // 2Nx2N
-            if (m_cfg->param->bEnableEarlySkip)
+            if (m_param->bEnableEarlySkip)
             {
                 xCheckRDCostInter(outBestCU, outTempCU, SIZE_2Nx2N);
                 outTempCU->initEstData(depth, qp); // by competition for inter_2Nx2N
@@ -741,12 +742,12 @@
 
             outTempCU->initEstData(depth, qp);
 
-            if (!m_cfg->param->bEnableEarlySkip)
+            if (!m_param->bEnableEarlySkip)
             {
                 // 2Nx2N, NxN
                 xCheckRDCostInter(outBestCU, outTempCU, SIZE_2Nx2N);
                 outTempCU->initEstData(depth, qp);
-                if (m_cfg->param->bEnableCbfFastMode)
+                if (m_param->bEnableCbfFastMode)
                 {
                     doNotBlockPu = outBestCU->getQtRootCbf(0) != 0;
                 }
@@ -770,14 +771,14 @@
                     }
                 }
 
-                if (m_cfg->param->bEnableRectInter)
+                if (m_param->bEnableRectInter)
                 {
                     // 2NxN, Nx2N
                     if (doNotBlockPu)
                     {
                         xCheckRDCostInter(outBestCU, outTempCU, SIZE_Nx2N);
                         outTempCU->initEstData(depth, qp);
-                        if (m_cfg->param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_Nx2N)
+                        if (m_param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_Nx2N)
                         {
                             doNotBlockPu = outBestCU->getQtRootCbf(0) != 0;
                         }
@@ -786,7 +787,7 @@
                     {
                         xCheckRDCostInter(outBestCU, outTempCU, SIZE_2NxN);
                         outTempCU->initEstData(depth, qp);
-                        if (m_cfg->param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_2NxN)
+                        if (m_param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_2NxN)
                         {
                             doNotBlockPu = outBestCU->getQtRootCbf(0) != 0;
                         }
@@ -808,7 +809,7 @@
                         {
                             xCheckRDCostInter(outBestCU, outTempCU, SIZE_2NxnU);
                             outTempCU->initEstData(depth, qp);
-                            if (m_cfg->param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_2NxnU)
+                            if (m_param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_2NxnU)
                             {
                                 doNotBlockPu = outBestCU->getQtRootCbf(0) != 0;
                             }
@@ -817,7 +818,7 @@
                         {
                             xCheckRDCostInter(outBestCU, outTempCU, SIZE_2NxnD);
                             outTempCU->initEstData(depth, qp);
-                            if (m_cfg->param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_2NxnD)
+                            if (m_param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_2NxnD)
                             {
                                 doNotBlockPu = outBestCU->getQtRootCbf(0) != 0;
                             }
@@ -829,7 +830,7 @@
                         {
                             xCheckRDCostInter(outBestCU, outTempCU, SIZE_2NxnU, true);
                             outTempCU->initEstData(depth, qp);
-                            if (m_cfg->param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_2NxnU)
+                            if (m_param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_2NxnU)
                             {
                                 doNotBlockPu = outBestCU->getQtRootCbf(0) != 0;
                             }
@@ -838,7 +839,7 @@
                         {
                             xCheckRDCostInter(outBestCU, outTempCU, SIZE_2NxnD, true);
                             outTempCU->initEstData(depth, qp);
-                            if (m_cfg->param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_2NxnD)
+                            if (m_param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_2NxnD)
                             {
                                 doNotBlockPu = outBestCU->getQtRootCbf(0) != 0;
                             }
@@ -852,7 +853,7 @@
                         {
                             xCheckRDCostInter(outBestCU, outTempCU, SIZE_nLx2N);
                             outTempCU->initEstData(depth, qp);
-                            if (m_cfg->param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_nLx2N)
+                            if (m_param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_nLx2N)
                             {
                                 doNotBlockPu = outBestCU->getQtRootCbf(0) != 0;
                             }
@@ -869,7 +870,7 @@
                         {
                             xCheckRDCostInter(outBestCU, outTempCU, SIZE_nLx2N, true);
                             outTempCU->initEstData(depth, qp);
-                            if (m_cfg->param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_nLx2N)
+                            if (m_param->bEnableCbfFastMode && outBestCU->getPartitionSize(0) == SIZE_nLx2N)
                             {
                                 doNotBlockPu = outBestCU->getQtRootCbf(0) != 0;
                             }
@@ -1228,7 +1229,7 @@
 
     UChar depth = outTempCU->getDepth(0);
     outTempCU->setPartSizeSubParts(SIZE_2Nx2N, 0, depth); // interprets depth relative to LCU level
-    outTempCU->setCUTransquantBypassSubParts(m_cfg->m_CUTransquantBypassFlagValue, 0, depth);
+    outTempCU->setCUTransquantBypassSubParts(m_CUTransquantBypassFlagValue, 0, depth);
     outTempCU->getInterMergeCandidates(0, 0, mvFieldNeighbours, interDirNeighbours, numValidMergeCand);
 
     int mergeCandBuffer[MRG_MAX_NUM_CANDS];
@@ -1254,8 +1255,8 @@
         for (uint32_t mergeCand = 0; mergeCand < numValidMergeCand; ++mergeCand)
         {
             /* TODO: check only necessary when -F>1, and ref pixels available is in units of LCU rows */
-            if (mvFieldNeighbours[0 + 2 * mergeCand].mv.y >= (m_cfg->param->searchRange + 1) * 4
-                || mvFieldNeighbours[1 + 2 * mergeCand].mv.y >= (m_cfg->param->searchRange + 1) * 4)
+            if (mvFieldNeighbours[0 + 2 * mergeCand].mv.y >= (m_param->searchRange + 1) * 4
+                || mvFieldNeighbours[1 + 2 * mergeCand].mv.y >= (m_param->searchRange + 1) * 4)
             {
                 continue;
             }
@@ -1265,7 +1266,7 @@
                 {
                     // set MC parameters
                     outTempCU->setPredModeSubParts(MODE_INTER, 0, depth); // interprets depth relative to LCU level
-                    outTempCU->setCUTransquantBypassSubParts(m_cfg->m_CUTransquantBypassFlagValue,     0, depth);
+                    outTempCU->setCUTransquantBypassSubParts(m_CUTransquantBypassFlagValue,     0, depth);
                     outTempCU->setPartSizeSubParts(SIZE_2Nx2N, 0, depth); // interprets depth relative to LCU level
                     outTempCU->setMergeFlag(0, true);
                     outTempCU->setMergeIndex(0, mergeCand);
@@ -1321,7 +1322,7 @@
             }
         }
 
-        if (noResidual == 0 && m_cfg->param->bEnableEarlySkip)
+        if (noResidual == 0 && m_param->bEnableEarlySkip)
         {
             if (outBestCU->getQtRootCbf(0) == 0)
             {
@@ -1361,7 +1362,7 @@
     outTempCU->setSkipFlagSubParts(false, 0, depth);
     outTempCU->setPartSizeSubParts(partSize, 0, depth);
     outTempCU->setPredModeSubParts(MODE_INTER, 0, depth);
-    outTempCU->setCUTransquantBypassSubParts(m_cfg->m_CUTransquantBypassFlagValue, 0, depth);
+    outTempCU->setCUTransquantBypassSubParts(m_CUTransquantBypassFlagValue, 0, depth);
 
     m_tmpRecoYuv[depth]->clear();
     m_tmpResiYuv[depth]->clear();
@@ -1382,7 +1383,7 @@
     outTempCU->setSkipFlagSubParts(false, 0, depth);
     outTempCU->setPartSizeSubParts(partSize, 0, depth);
     outTempCU->setPredModeSubParts(MODE_INTRA, 0, depth);
-    outTempCU->setCUTransquantBypassSubParts(m_cfg->m_CUTransquantBypassFlagValue, 0, depth);
+    outTempCU->setCUTransquantBypassSubParts(m_CUTransquantBypassFlagValue, 0, depth);
 
     m_search->estIntraPredQT(outTempCU, m_origYuv[depth], m_tmpPredYuv[depth], m_tmpResiYuv[depth], m_tmpRecoYuv[depth], preCalcDistC, true);
 
@@ -1422,7 +1423,7 @@
     outTempCU->setSkipFlagSubParts(false, 0, depth);
     outTempCU->setPartSizeSubParts(partSize, 0, depth);
     outTempCU->setPredModeSubParts(MODE_INTRA, 0, depth);
-    outTempCU->setCUTransquantBypassSubParts(m_cfg->m_CUTransquantBypassFlagValue, 0, depth);
+    outTempCU->setCUTransquantBypassSubParts(m_CUTransquantBypassFlagValue, 0, depth);
 
     bool bSeparateLumaChroma = true; // choose estimation mode
     uint32_t preCalcDistC = 0;
@@ -1479,7 +1480,7 @@
     outTempCU->setPartSizeSubParts(SIZE_2Nx2N, 0, depth);
     outTempCU->setPredModeSubParts(MODE_INTRA, 0, depth);
     outTempCU->setTrIdxSubParts(0, 0, depth);
-    outTempCU->setCUTransquantBypassSubParts(m_cfg->m_CUTransquantBypassFlagValue, 0, depth);
+    outTempCU->setCUTransquantBypassSubParts(m_CUTransquantBypassFlagValue, 0, depth);
 
     m_search->IPCMSearch(outTempCU, m_origYuv[depth], m_tmpPredYuv[depth], m_tmpResiYuv[depth], m_tmpRecoYuv[depth]);
 
diff -r 9f3515756d0f -r 8584ba886cb0 source/Lib/TLibEncoder/TEncCu.h
--- a/source/Lib/TLibEncoder/TEncCu.h	Fri Mar 07 14:49:07 2014 -0800
+++ b/source/Lib/TLibEncoder/TEncCu.h	Fri Mar 07 16:46:58 2014 -0800
@@ -111,7 +111,7 @@
     TComYuv**    m_bestMergeRecoYuv;
     TComYuv**    m_origYuv;     ///< Original Yuv at each depth
 
-    Encoder*     m_cfg;
+    x265_param*  m_param;
     TEncSearch*  m_search;
     TComTrQuant* m_trQuant;
     TComRdCost*  m_rdCost;
@@ -125,6 +125,7 @@
     UChar        m_totalDepth;
 
     bool         m_bEncodeDQP;
+    bool         m_CUTransquantBypassFlagValue;
 
 public:
 
diff -r 9f3515756d0f -r 8584ba886cb0 source/encoder/compress.cpp
--- a/source/encoder/compress.cpp	Fri Mar 07 14:49:07 2014 -0800
+++ b/source/encoder/compress.cpp	Fri Mar 07 16:46:58 2014 -0800
@@ -81,7 +81,7 @@
 
     cu->setPartSizeSubParts(partSize, 0, depth);
     cu->setPredModeSubParts(MODE_INTRA, 0, depth);
-    cu->setCUTransquantBypassSubParts(m_cfg->m_CUTransquantBypassFlagValue, 0, depth);
+    cu->setCUTransquantBypassSubParts(m_CUTransquantBypassFlagValue, 0, depth);
 
     uint32_t initTrDepth = cu->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1;
     uint32_t width       = cu->getCUSize(0) >> initTrDepth;
@@ -199,7 +199,7 @@
 
     outTempCU->setPartSizeSubParts(partSize, 0, depth);
     outTempCU->setPredModeSubParts(MODE_INTER, 0, depth);
-    outTempCU->setCUTransquantBypassSubParts(m_cfg->m_CUTransquantBypassFlagValue, 0, depth);
+    outTempCU->setCUTransquantBypassSubParts(m_CUTransquantBypassFlagValue, 0, depth);
 
     //do motion compensation only for Luma since luma cost alone is calculated
     outTempCU->m_totalBits = 0;
@@ -225,13 +225,13 @@
 
     UChar depth = outTempCU->getDepth(0);
     outTempCU->setPartSizeSubParts(SIZE_2Nx2N, 0, depth); // interprets depth relative to LCU level
-    outTempCU->setCUTransquantBypassSubParts(m_cfg->m_CUTransquantBypassFlagValue, 0, depth);
+    outTempCU->setCUTransquantBypassSubParts(m_CUTransquantBypassFlagValue, 0, depth);
     outTempCU->getInterMergeCandidates(0, 0, mvFieldNeighbours, interDirNeighbours, numValidMergeCand);
     outTempCU->setPredModeSubParts(MODE_INTER, 0, depth);
     outTempCU->setMergeFlag(0, true);
 
     outBestCU->setPartSizeSubParts(SIZE_2Nx2N, 0, depth); // interprets depth relative to LCU level
-    outBestCU->setCUTransquantBypassSubParts(m_cfg->m_CUTransquantBypassFlagValue, 0, depth);
+    outBestCU->setCUTransquantBypassSubParts(m_CUTransquantBypassFlagValue, 0, depth);
     outBestCU->setPredModeSubParts(MODE_INTER, 0, depth);
     outBestCU->setMergeFlag(0, true);
 
@@ -242,8 +242,8 @@
     for (int mergeCand = 0; mergeCand < numValidMergeCand; ++mergeCand)
     {
         /* TODO: check only necessary when -F>1, and ref pixels available is in units of LCU rows */
-        if (mvFieldNeighbours[0 + 2 * mergeCand].mv.y < (m_cfg->param->searchRange + 1) * 4
-            && mvFieldNeighbours[1 + 2 * mergeCand].mv.y < (m_cfg->param->searchRange + 1) * 4)
+        if (mvFieldNeighbours[0 + 2 * mergeCand].mv.y < (m_param->searchRange + 1) * 4
+            && mvFieldNeighbours[1 + 2 * mergeCand].mv.y < (m_param->searchRange + 1) * 4)
         {
             // set MC parameters, interprets depth relative to LCU level
             outTempCU->setMergeIndex(0, mergeCand);
@@ -254,7 +254,7 @@
             // do MC only for Luma part
             m_search->motionCompensation(outTempCU, m_tmpPredYuv[depth], REF_PIC_LIST_X, 0, true, false);
             bitsCand = mergeCand + 1;
-            if (mergeCand == (int)m_cfg->param->maxNumMergeCand - 1)
+            if (mergeCand == (int)m_param->maxNumMergeCand - 1)
             {
                 bitsCand--;
             }
@@ -294,7 +294,7 @@
         outTempCU->m_totalCost = m_rdCost->calcRdSADCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
         outTempCU->m_sa8dCost = outTempCU->m_totalCost;
         outBestCU->m_sa8dCost = outTempCU->m_sa8dCost;
-        if (m_cfg->param->rdLevel >= 1)
+        if (m_param->rdLevel >= 1)
         {
             //calculate the motion compensation for chroma for the best mode selected
             int numPart = outBestCU->getNumPartInter();
@@ -360,7 +360,7 @@
     bool bInsidePicture = (rpelx < outTempCU->getSlice()->getSPS()->getPicWidthInLumaSamples()) &&
         (bpely < outTempCU->getSlice()->getSPS()->getPicHeightInLumaSamples());
 
-    if (depth == 0 && m_cfg->param->rdLevel == 0)
+    if (depth == 0 && m_param->rdLevel == 0)
     {
         m_origYuv[depth]->copyToPicYuv(cu->getPic()->getPicYuvRec(), cu->getAddr(), 0, 0, 0);
     }
@@ -427,8 +427,8 @@
             /* Compute  Merge Cost */
             xComputeCostMerge2Nx2N(m_bestMergeCU[depth], m_mergeCU[depth], m_modePredYuv[3][depth], m_bestMergeRecoYuv[depth]);
             bool earlyskip = false;
-            if (m_cfg->param->rdLevel >= 1)
-                earlyskip = (m_cfg->param->bEnableEarlySkip && m_bestMergeCU[depth]->isSkipped(0));
+            if (m_param->rdLevel >= 1)
+                earlyskip = (m_param->bEnableEarlySkip && m_bestMergeCU[depth]->isSkipped(0));
 
             if (!earlyskip)
             {
@@ -443,7 +443,7 @@
                 }
 
                 /*Compute Rect costs*/
-                if (m_cfg->param->bEnableRectInter)
+                if (m_param->bEnableRectInter)
                 {
                     xComputeCostInter(m_interCU_Nx2N[depth], m_modePredYuv[1][depth], SIZE_Nx2N);
                     xComputeCostInter(m_interCU_2NxN[depth], m_modePredYuv[2][depth], SIZE_2NxN);
@@ -465,7 +465,7 @@
                     m_modePredYuv[2][depth] = m_bestPredYuv[depth];
                     m_bestPredYuv[depth] = tempYuv;
                 }
-                if (m_cfg->param->rdLevel > 2)
+                if (m_param->rdLevel > 2)
                 {
                     //calculate the motion compensation for chroma for the best mode selected
                     int numPart = outBestCU->getNumPartInter();
@@ -494,7 +494,7 @@
                 {
                     /*compute intra cost */
                     bool bdoIntra = true;
-                    if (m_cfg->param->rdLevel > 2)
+                    if (m_param->rdLevel > 2)
                     {
                         bdoIntra = (outBestCU->getCbf(0, TEXT_LUMA) ||  outBestCU->getCbf(0, TEXT_CHROMA_U) ||
                                     outBestCU->getCbf(0, TEXT_CHROMA_V));
@@ -502,7 +502,7 @@
                     if (bdoIntra)
                     {
                         xComputeCostIntraInInter(m_intraInInterCU[depth], SIZE_2Nx2N);
-                        if (m_cfg->param->rdLevel > 2)
+                        if (m_param->rdLevel > 2)
                         {
                             xEncodeIntraInInter(m_intraInInterCU[depth], m_origYuv[depth], m_modePredYuv[5][depth],
                                                 m_tmpResiYuv[depth],  m_tmpRecoYuv[depth]);
@@ -520,7 +520,7 @@
                         }
                     }
                 }
-                if (m_cfg->param->rdLevel == 2)
+                if (m_param->rdLevel == 2)
                 {
                     if (m_bestMergeCU[depth]->m_sa8dCost < outBestCU->m_totalCost)
                     {
@@ -549,7 +549,7 @@
                         xEncodeIntraInInter(outBestCU, m_origYuv[depth], m_bestPredYuv[depth], m_tmpResiYuv[depth],  m_bestRecoYuv[depth]);
                     }
                 }
-                if (m_cfg->param->rdLevel == 1)
+                if (m_param->rdLevel == 1)
                 {
                     if (m_bestMergeCU[depth]->m_sa8dCost < outBestCU->m_totalCost)
                     {
@@ -578,7 +578,7 @@
                         m_search->generateCoeffRecon(outBestCU, m_origYuv[depth], m_bestPredYuv[depth], m_tmpResiYuv[depth], m_bestRecoYuv[depth], false);
                     }
                 }
-                if (m_cfg->param->rdLevel == 0)
+                if (m_param->rdLevel == 0)
                 {
                     if (outBestCU->getPredictionMode(0) == MODE_INTER)
                     {
@@ -602,7 +602,7 @@
                 m_bestMergeRecoYuv[depth] = tempYuv;
             }
 
-            if (m_cfg->param->rdLevel > 0) //checkDQP can be done only after residual encoding is done
+            if (m_param->rdLevel > 0) //checkDQP can be done only after residual encoding is done
                 xCheckDQP(outBestCU);
             /* Disable recursive analysis for whole CUs temporarily */
             if ((outBestCU != 0) && (outBestCU->isSkipped(0)))
@@ -610,7 +610,7 @@
             else
                 bSubBranch = true;
 
-            if (m_cfg->param->rdLevel > 1)
+            if (m_param->rdLevel > 1)
             {
                 m_entropyCoder->resetBits();
                 m_entropyCoder->encodeSplitFlag(outBestCU, 0, depth, true);
@@ -679,7 +679,7 @@
                 outBestCU->copyToPic((UChar)depth);
 
                 /* Copy Yuv data to picture Yuv */
-                if (m_cfg->param->rdLevel != 0)
+                if (m_param->rdLevel != 0)
                     xCopyYuv2Pic(outBestCU->getPic(), outBestCU->getAddr(), outBestCU->getZorderIdxInCU(), depth, depth, outBestCU, lpelx, tpely);
                 return;
             }
@@ -718,9 +718,9 @@
 #endif // if EARLY_EXIT
                 /* Adding costs from best SUbCUs */
                 outTempCU->copyPartFrom(subBestPartCU, nextDepth_partIndex, nextDepth, true); // Keep best part data to current temporary data.
-                if (m_cfg->param->rdLevel != 0)
+                if (m_param->rdLevel != 0)
                     xCopyYuv2Tmp(subBestPartCU->getTotalNumPart() * nextDepth_partIndex, nextDepth);
-                if (m_cfg->param->rdLevel == 0)
+                if (m_param->rdLevel == 0)
                     m_bestPredYuv[nextDepth]->copyToPartYuv(m_tmpPredYuv[depth], subBestPartCU->getTotalNumPart() * nextDepth_partIndex);
             }
             else if (bInSlice)
@@ -732,14 +732,14 @@
 
         if (!bBoundary)
         {
-            if (m_cfg->param->rdLevel > 1)
+            if (m_param->rdLevel > 1)
             {
                 m_entropyCoder->resetBits();
                 m_entropyCoder->encodeSplitFlag(outTempCU, 0, depth, true);
                 outTempCU->m_totalBits += m_entropyCoder->getNumberOfWrittenBits(); // split bits
             }
         }
-        if (m_cfg->param->rdLevel > 1)
+        if (m_param->rdLevel > 1)
             outTempCU->m_totalCost = m_rdCost->calcRdCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
         else
             outTempCU->m_totalCost = m_rdCost->calcRdSADCost(outTempCU->m_totalDistortion, outTempCU->m_totalBits);
@@ -812,11 +812,11 @@
     /* Copy Best data to Picture for next partition prediction. */
     outBestCU->copyToPic((UChar)depth);
 
-    if (m_cfg->param->rdLevel == 0 && depth == 0)
+    if (m_param->rdLevel == 0 && depth == 0)
     {
         encodeResidue(outBestCU, outBestCU, 0, 0);
     }
-    else if (m_cfg->param->rdLevel != 0)
+    else if (m_param->rdLevel != 0)
     {
         /* Copy Yuv data to picture Yuv */
         xCopyYuv2Pic(outBestCU->getPic(), outBestCU->getAddr(), outBestCU->getZorderIdxInCU(), depth, depth, outBestCU, lpelx, tpely);
@@ -875,13 +875,13 @@
             src2stride = m_bestPredYuv[0]->getCStride();
             src1stride = m_origYuv[0]->getCStride();
             dststride = m_tmpResiYuv[depth]->m_cwidth;
-            primitives.chroma[m_cfg->param->internalCsp].sub_ps[part](dst, dststride, src1, src2, src1stride, src2stride);
+            primitives.chroma[m_param->internalCsp].sub_ps[part](dst, dststride, src1, src2, src1stride, src2stride);
 
             src2 = m_bestPredYuv[0]->getCrAddr(absPartIdx);
             src1 = m_origYuv[0]->getCrAddr(absPartIdx);
             dst = m_tmpResiYuv[depth]->getCrAddr(0);
             dststride = m_tmpResiYuv[depth]->m_cwidth;
-            primitives.chroma[m_cfg->param->internalCsp].sub_ps[part](dst, dststride, src1, src2, src1stride, src2stride);
+            primitives.chroma[m_param->internalCsp].sub_ps[part](dst, dststride, src1, src2, src1stride, src2stride);
 
             //Residual encoding
             m_search->residualTransformQuantInter(cu, 0, 0, m_tmpResiYuv[depth], cu->getDepth(0), true);
@@ -911,12 +911,12 @@
                 dststride = m_bestRecoYuv[depth]->getCStride();
                 src1stride = m_bestPredYuv[0]->getCStride();
                 src2stride = m_tmpResiYuv[depth]->m_cwidth;
-                primitives.chroma[m_cfg->param->internalCsp].add_ps[part](reco, dststride, pred, res, src1stride, src2stride);
+                primitives.chroma[m_param->internalCsp].add_ps[part](reco, dststride, pred, res, src1stride, src2stride);
 
                 pred = m_bestPredYuv[0]->getCrAddr(absPartIdx);
                 res = m_tmpResiYuv[depth]->getCrAddr(0);
                 reco = m_bestRecoYuv[depth]->getCrAddr(0);
-                primitives.chroma[m_cfg->param->internalCsp].add_ps[part](reco, dststride, pred, res, src1stride, src2stride);
+                primitives.chroma[m_param->internalCsp].add_ps[part](reco, dststride, pred, res, src1stride, src2stride);
                 m_bestRecoYuv[depth]->copyToPicYuv(lcu->getPic()->getPicYuvRec(), lcu->getAddr(), absPartIdx, 0, 0);
                 return;
             }
@@ -935,11 +935,11 @@
         dst = rec->getCbAddr(cu->getAddr(), absPartIdx);
         srcstride = m_bestPredYuv[0]->getCStride();
         dststride = rec->getCStride();
-        primitives.chroma[m_cfg->param->internalCsp].copy_pp[part](dst, dststride, src, srcstride);
+        primitives.chroma[m_param->internalCsp].copy_pp[part](dst, dststride, src, srcstride);
 
         src = m_bestPredYuv[0]->getCrAddr(absPartIdx);
         dst = rec->getCrAddr(cu->getAddr(), absPartIdx);
-        primitives.chroma[m_cfg->param->internalCsp].copy_pp[part](dst, dststride, src, srcstride);
+        primitives.chroma[m_param->internalCsp].copy_pp[part](dst, dststride, src, srcstride);
     }
     else
     {
diff -r 9f3515756d0f -r 8584ba886cb0 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Fri Mar 07 14:49:07 2014 -0800
+++ b/source/encoder/frameencoder.cpp	Fri Mar 07 16:46:58 2014 -0800
@@ -536,7 +536,7 @@
             // Extend border after whole-frame SAO is finished
             for (int row = 0; row < m_numRows; row++)
             {
-                m_frameFilter.processRowPost(row);
+                m_frameFilter.processRowPost(row, m_cfg);
             }
         }
 
diff -r 9f3515756d0f -r 8584ba886cb0 source/encoder/frameencoder.h
--- a/source/encoder/frameencoder.h	Fri Mar 07 14:49:07 2014 -0800
+++ b/source/encoder/frameencoder.h	Fri Mar 07 16:46:58 2014 -0800
@@ -67,7 +67,7 @@
 
     void processRowFilter(int row)
     {
-        m_frameFilter.processRow(row);
+        m_frameFilter.processRow(row, m_cfg);
     }
 
     void enqueueRowEncoder(int row)
diff -r 9f3515756d0f -r 8584ba886cb0 source/encoder/framefilter.cpp
--- a/source/encoder/framefilter.cpp	Fri Mar 07 14:49:07 2014 -0800
+++ b/source/encoder/framefilter.cpp	Fri Mar 07 16:46:58 2014 -0800
@@ -36,8 +36,7 @@
 // * LoopFilter
 // **************************************************************************
 FrameFilter::FrameFilter()
-    : m_cfg(NULL)
-    , m_pic(NULL)
+    : m_param(NULL)
     , m_rdGoOnBinCodersCABAC(true)
     , m_ssimBuf(NULL)
 {
@@ -45,12 +44,12 @@
 
 void FrameFilter::destroy()
 {
-    if (m_cfg->param->bEnableLoopFilter)
+    if (m_param->bEnableLoopFilter)
     {
         m_loopFilter.destroy();
     }
 
-    if (m_cfg->param->bEnableSAO)
+    if (m_param->bEnableSAO)
     {
         // NOTE: I don't check sao flag since loopfilter and sao have same control status
         m_sao.destroy();
@@ -61,11 +60,10 @@
 
 void FrameFilter::init(Encoder *top, int numRows, TEncSbac* rdGoOnSbacCoder)
 {
-    m_top = top;
-    m_cfg = top;
+    m_param = top->param;
     m_numRows = numRows;
-    m_hChromaShift = CHROMA_H_SHIFT(m_cfg->param->internalCsp);
-    m_vChromaShift = CHROMA_V_SHIFT(m_cfg->param->internalCsp);
+    m_hChromaShift = CHROMA_H_SHIFT(m_param->internalCsp);
+    m_vChromaShift = CHROMA_V_SHIFT(m_param->internalCsp);
 
     // NOTE: for sao only, I write this code because I want to exact match with HM's bug bitstream
     m_rdGoOnSbacCoderRow0 = rdGoOnSbacCoder;
@@ -80,26 +78,26 @@
         m_sao.setSaoLcuBoundary(top->param->saoLcuBoundary);
         m_sao.setSaoLcuBasedOptimization(top->param->saoLcuBasedOptimization);
         m_sao.setMaxNumOffsetsPerPic(top->m_maxNumOffsetsPerPic);
-        m_sao.create(top->param->sourceWidth, top->param->sourceHeight, g_maxCUSize, g_maxCUSize, m_cfg->param->internalCsp);
+        m_sao.create(top->param->sourceWidth, top->param->sourceHeight, g_maxCUSize, g_maxCUSize, m_param->internalCsp);
         m_sao.createEncBuffer();
     }
 
-    if (m_cfg->param->bEnableSsim)
-        m_ssimBuf = (int*)x265_malloc(sizeof(int) * 8 * (m_cfg->param->sourceWidth / 4 + 3));
+    if (m_param->bEnableSsim)
+        m_ssimBuf = (int*)x265_malloc(sizeof(int) * 8 * (m_param->sourceWidth / 4 + 3));
 }
 
 void FrameFilter::start(TComPic *pic)
 {
     m_pic = pic;
 
-    m_saoRowDelay = m_cfg->param->bEnableLoopFilter ? 1 : 0;
+    m_saoRowDelay = m_param->bEnableLoopFilter ? 1 : 0;
     m_loopFilter.setCfg(pic->getSlice()->getPPS()->getLoopFilterAcrossTilesEnabledFlag());
     m_rdGoOnSbacCoder.init(&m_rdGoOnBinCodersCABAC);
     m_entropyCoder.setEntropyCoder(&m_rdGoOnSbacCoder, pic->getSlice());
     m_entropyCoder.setBitstream(&m_bitCounter);
     m_rdGoOnBinCodersCABAC.m_fracBits = 0;
 
-    if (m_cfg->param->bEnableSAO)
+    if (m_param->bEnableSAO)
     {
         m_sao.resetStats();
         m_sao.createPicSaoInfo(pic);
@@ -110,7 +108,7 @@
 
         // NOTE: Disable SAO automatic turn-off when frame parallelism is
         // enabled for output exact independent of frame thread count
-        if (m_cfg->param->frameNumThreads > 1)
+        if (m_param->frameNumThreads > 1)
         {
             saoParam->bSaoFlag[0] = true;
             saoParam->bSaoFlag[1] = true;
@@ -122,18 +120,18 @@
 {
 }
 
-void FrameFilter::processRow(int row)
+void FrameFilter::processRow(int row, Encoder* cfg)
 {
     PPAScopeEvent(Thread_filterCU);
 
-    if (!m_cfg->param->bEnableLoopFilter && !m_cfg->param->bEnableSAO)
+    if (!m_param->bEnableLoopFilter && !m_param->bEnableSAO)
     {
-        processRowPost(row);
+        processRowPost(row, cfg);
         return;
     }
 
     // NOTE: We are here only active both of loopfilter and sao, the row 0 always finished, so we can safe to copy row[0]'s data
-    if (row == 0 && m_cfg->param->bEnableSAO)
+    if (row == 0 && m_param->bEnableSAO)
     {
         // NOTE: not need, seems HM's bug, I want to keep output exact matched.
         m_rdGoOnBinCodersCABAC.m_fracBits = ((TEncBinCABAC*)((TEncSbac*)m_rdGoOnSbacCoderRow0->m_binIf))->m_fracBits;
@@ -144,12 +142,12 @@
     const uint32_t lineStartCUAddr = row * numCols;
 
     // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas
-    if (m_cfg->param->bEnableSAO && m_cfg->param->saoLcuBasedOptimization && m_cfg->param->saoLcuBoundary)
+    if (m_param->bEnableSAO && m_param->saoLcuBasedOptimization && m_param->saoLcuBoundary)
     {
         m_sao.calcSaoStatsRowCus_BeforeDblk(m_pic, row);
     }
 
-    if (m_cfg->param->bEnableLoopFilter)
+    if (m_param->bEnableLoopFilter)
     {
         for (uint32_t col = 0; col < numCols; col++)
         {
@@ -173,7 +171,7 @@
 
     // SAO
     SAOParam* saoParam = m_pic->getPicSym()->getSaoParam();
-    if (m_cfg->param->bEnableSAO && m_sao.getSaoLcuBasedOptimization())
+    if (m_param->bEnableSAO && m_sao.getSaoLcuBasedOptimization())
     {
         m_sao.rdoSaoUnitRow(saoParam, row);
 
@@ -187,17 +185,17 @@
     // this row of CTUs has been encoded
 
     // NOTE: in --sao-lcu-opt=0 mode, we do it later
-    if (m_cfg->param->bEnableSAO && !m_sao.getSaoLcuBasedOptimization())
+    if (m_param->bEnableSAO && !m_sao.getSaoLcuBasedOptimization())
         return;
 
     if (row > 0)
     {
-        processRowPost(row - 1);
+        processRowPost(row - 1, cfg);
     }
 
     if (row == m_numRows - 1)
     {
-        if (m_cfg->param->bEnableSAO && m_sao.getSaoLcuBasedOptimization())
+        if (m_param->bEnableSAO && m_sao.getSaoLcuBasedOptimization())
         {
             m_sao.rdoSaoUnitRowEnd(saoParam, m_pic->getNumCUsInFrame());
 
@@ -207,11 +205,11 @@
             }
         }
 
-        processRowPost(row);
+        processRowPost(row, cfg);
     }
 }
 
-void FrameFilter::processRowPost(int row)
+void FrameFilter::processRowPost(int row, Encoder* cfg)
 {
     const uint32_t numCols = m_pic->getPicSym()->getFrameWidthInCU();
     const uint32_t lineStartCUAddr = row * numCols;
@@ -267,15 +265,15 @@
     // Notify other FrameEncoders that this row of reconstructed pixels is available
     m_pic->m_reconRowCount++;
     if (m_pic->m_countRefEncoders)
-        m_top->signalReconRowCompleted(m_pic->getPOC());
+        cfg->signalReconRowCompleted(m_pic->getPOC());
 
     int cuAddr = lineStartCUAddr;
-    if (m_cfg->param->bEnablePsnr)
+    if (m_param->bEnablePsnr)
     {
         TComPicYuv* orig  = m_pic->getPicYuvOrg();
 
         int stride = recon->getStride();
-        int width  = recon->getWidth() - m_cfg->m_pad[0];
+        int width  = recon->getWidth() - cfg->m_pad[0];
         int height;
 
         if (row == m_numRows - 1)
@@ -295,7 +293,7 @@
         m_pic->m_SSDU += ssdU;
         m_pic->m_SSDV += ssdV;
     }
-    if (m_cfg->param->bEnableSsim && m_ssimBuf)
+    if (m_param->bEnableSsim && m_ssimBuf)
     {
         pixel *rec = (pixel*)m_pic->getPicYuvRec()->getLumaAddr();
         pixel *org = (pixel*)m_pic->getPicYuvOrg()->getLumaAddr();
@@ -312,10 +310,10 @@
         * to avoid alignment of ssim blocks with DCT blocks. */
         minPixY += bStart ? 2 : -6;
         m_pic->m_ssim += calculateSSIM(rec + 2 + minPixY * stride1, stride1, org + 2 + minPixY * stride2, stride2,
-                                       m_cfg->param->sourceWidth - 2, maxPixY - minPixY, m_ssimBuf, &ssim_cnt);
+                                       m_param->sourceWidth - 2, maxPixY - minPixY, m_ssimBuf, &ssim_cnt);
         m_pic->m_ssimCnt += ssim_cnt;
     }
-    if (m_cfg->param->decodedPictureHashSEI == 1)
+    if (m_param->decodedPictureHashSEI == 1)
     {
         uint32_t width = recon->getWidth();
         uint32_t height = recon->getCUHeight(row);
@@ -338,7 +336,7 @@
 
         updateMD5Plane(m_pic->m_state[2], recon->getCrAddr(cuAddr), width, height, stride);
     }
-    else if (m_cfg->param->decodedPictureHashSEI == 2)
+    else if (m_param->decodedPictureHashSEI == 2)
     {
         uint32_t width = recon->getWidth();
         uint32_t height = recon->getCUHeight(row);
@@ -355,7 +353,7 @@
         updateCRC(recon->getCbAddr(cuAddr), m_pic->m_crc[1], height, width, stride);
         updateCRC(recon->getCrAddr(cuAddr), m_pic->m_crc[2], height, width, stride);
     }
-    else if (m_cfg->param->decodedPictureHashSEI == 3)
+    else if (m_param->decodedPictureHashSEI == 3)
     {
         uint32_t width = recon->getWidth();
         uint32_t height = recon->getCUHeight(row);
diff -r 9f3515756d0f -r 8584ba886cb0 source/encoder/framefilter.h
--- a/source/encoder/framefilter.h	Fri Mar 07 14:49:07 2014 -0800
+++ b/source/encoder/framefilter.h	Fri Mar 07 16:46:58 2014 -0800
@@ -50,14 +50,13 @@
     void start(TComPic *pic);
     void end();
 
-    void processRow(int row);
-    void processRowPost(int row);
+    void processRow(int row, Encoder* cfg);
+    void processRowPost(int row, Encoder* cfg);
     void processSao(int row);
 
 protected:
 
-    Encoder*                    m_top;
-    Encoder*                    m_cfg;
+    x265_param*                 m_param;
     TComPic*                    m_pic;
     int                         m_hChromaShift;
     int                         m_vChromaShift;
diff -r 9f3515756d0f -r 8584ba886cb0 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Fri Mar 07 14:49:07 2014 -0800
+++ b/source/encoder/ratecontrol.cpp	Fri Mar 07 16:46:58 2014 -0800
@@ -73,7 +73,7 @@
     int stride = pic->getPicYuvOrg()->getStride();
     int cStride = pic->getPicYuvOrg()->getCStride();
     uint32_t blockOffsetLuma = block_x + (block_y * stride);
-    int colorFormat = cfg->param->internalCsp;
+    int colorFormat = param->internalCsp;
     int hShift = CHROMA_H_SHIFT(colorFormat);
     int vShift = CHROMA_V_SHIFT(colorFormat);
     uint32_t blockOffsetChroma = (block_x >> hShift) + ((block_y >> vShift) * cStride);
@@ -103,14 +103,14 @@
     int block_xy = 0;
     int block_x = 0, block_y = 0;
     double strength = 0.f;
-    if (cfg->param->rc.aqMode == X265_AQ_NONE || cfg->param->rc.aqStrength == 0)
+    if (param->rc.aqMode == X265_AQ_NONE || param->rc.aqStrength == 0)
     {
         /* Need to init it anyways for CU tree */
         int cuWidth = ((maxCol / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
         int cuHeight = ((maxRow / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
         int cuCount = cuWidth * cuHeight;
 
-        if (cfg->param->rc.aqMode && cfg->param->rc.aqStrength == 0)
+        if (param->rc.aqMode && param->rc.aqStrength == 0)
         {
             memset(pic->m_lowres.qpOffset, 0, cuCount * sizeof(double));
             memset(pic->m_lowres.qpAqOffset, 0, cuCount * sizeof(double));
@@ -121,7 +121,7 @@
         }
 
         /* Need variance data for weighted prediction */
-        if (cfg->param->bEnableWeightedPred)
+        if (param->bEnableWeightedPred)
         {
             for (block_y = 0; block_y < maxRow; block_y += 16)
             {
@@ -136,7 +136,7 @@
     {
         block_xy = 0;
         double avg_adj_pow2 = 0, avg_adj = 0, qp_adj = 0;
-        if (cfg->param->rc.aqMode == X265_AQ_AUTO_VARIANCE)
+        if (param->rc.aqMode == X265_AQ_AUTO_VARIANCE)
         {
             double bit_depth_correction = pow(1 << (X265_DEPTH - 8), 0.5);
             for (block_y = 0; block_y < maxRow; block_y += 16)
@@ -154,18 +154,18 @@
 
             avg_adj /= ncu;
             avg_adj_pow2 /= ncu;
-            strength = cfg->param->rc.aqStrength * avg_adj / bit_depth_correction;
+            strength = param->rc.aqStrength * avg_adj / bit_depth_correction;
             avg_adj = avg_adj - 0.5f * (avg_adj_pow2 - (14.f * bit_depth_correction)) / avg_adj;
         }
         else
-            strength = cfg->param->rc.aqStrength * 1.0397f;
+            strength = param->rc.aqStrength * 1.0397f;
 
         block_xy = 0;
         for (block_y = 0; block_y < maxRow; block_y += 16)
         {
             for (block_x = 0; block_x < maxCol; block_x += 16)
             {
-                if (cfg->param->rc.aqMode == X265_AQ_AUTO_VARIANCE)
+                if (param->rc.aqMode == X265_AQ_AUTO_VARIANCE)
                 {
                     qp_adj = pic->m_lowres.qpOffset[block_xy];
                     qp_adj = strength * (qp_adj - avg_adj);
@@ -183,10 +183,10 @@
         }
     }
 
-    if (cfg->param->bEnableWeightedPred)
+    if (param->bEnableWeightedPred)
     {
-        int hShift = CHROMA_H_SHIFT(cfg->param->internalCsp);
-        int vShift = CHROMA_V_SHIFT(cfg->param->internalCsp);
+        int hShift = CHROMA_H_SHIFT(param->internalCsp);
+        int vShift = CHROMA_V_SHIFT(param->internalCsp);
         maxCol = ((maxCol + 8) >> 4) << 4;
         maxRow = ((maxRow + 8) >> 4) << 4;
         int width[3]  = { maxCol, maxCol >> hShift, maxCol >> hShift };
@@ -204,48 +204,48 @@
 
 RateControl::RateControl(Encoder * _cfg)
 {
-    this->cfg = _cfg;
-    int lowresCuWidth = ((cfg->param->sourceWidth / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
-    int lowresCuHeight = ((cfg->param->sourceHeight / 2)  + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
+    param = _cfg->param;
+    int lowresCuWidth = ((param->sourceWidth / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
+    int lowresCuHeight = ((param->sourceHeight / 2)  + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
     ncu = lowresCuWidth * lowresCuHeight;
-    if (cfg->param->rc.cuTree)
+    if (param->rc.cuTree)
     {
         qCompress = 1;
-        cfg->param->rc.pbFactor = 1;
+        param->rc.pbFactor = 1;
     }
     else
-        qCompress = cfg->param->rc.qCompress;
+        qCompress = param->rc.qCompress;
 
-    // validate for cfg->param->rc, maybe it is need to add a function like x265_parameters_valiate()
-    cfg->param->rc.rfConstant = Clip3((double)-QP_BD_OFFSET, (double)51, cfg->param->rc.rfConstant);
-    cfg->param->rc.rfConstantMax = Clip3((double)-QP_BD_OFFSET, (double)51, cfg->param->rc.rfConstantMax);
+    // validate for param->rc, maybe it is need to add a function like x265_parameters_valiate()
+    param->rc.rfConstant = Clip3((double)-QP_BD_OFFSET, (double)51, param->rc.rfConstant);
+    param->rc.rfConstantMax = Clip3((double)-QP_BD_OFFSET, (double)51, param->rc.rfConstantMax);
     rateFactorMaxIncrement = 0;
     vbvMinRate = 0;
 
-    if (cfg->param->rc.rateControlMode == X265_RC_CRF)
+    if (param->rc.rateControlMode == X265_RC_CRF)
     {
-        cfg->param->rc.qp = (int)cfg->param->rc.rfConstant + QP_BD_OFFSET;
-        cfg->param->rc.bitrate = 0;
+        param->rc.qp = (int)param->rc.rfConstant + QP_BD_OFFSET;
+        param->rc.bitrate = 0;
 
-        double baseCplx = ncu * (cfg->param->bframes ? 120 : 80);
-        double mbtree_offset = cfg->param->rc.cuTree ? (1.0 - cfg->param->rc.qCompress) * 13.5 : 0;
+        double baseCplx = ncu * (param->bframes ? 120 : 80);
+        double mbtree_offset = param->rc.cuTree ? (1.0 - param->rc.qCompress) * 13.5 : 0;
         rateFactorConstant = pow(baseCplx, 1 - qCompress) /
-            qp2qScale(cfg->param->rc.rfConstant + mbtree_offset);
-        if (cfg->param->rc.rfConstantMax)
+            qp2qScale(param->rc.rfConstant + mbtree_offset);
+        if (param->rc.rfConstantMax)
         {
-            rateFactorMaxIncrement = cfg->param->rc.rfConstantMax - cfg->param->rc.rfConstant;
+            rateFactorMaxIncrement = param->rc.rfConstantMax - param->rc.rfConstant;
             if (rateFactorMaxIncrement <= 0)
             {
-                x265_log(cfg->param, X265_LOG_WARNING, "CRF max must be greater than CRF\n");
+                x265_log(param, X265_LOG_WARNING, "CRF max must be greater than CRF\n");
                 rateFactorMaxIncrement = 0;
             }
         }
     }
 
-    isAbr = cfg->param->rc.rateControlMode != X265_RC_CQP; // later add 2pass option
-    bitrate = cfg->param->rc.bitrate * 1000;
-    frameDuration = (double)cfg->param->fpsDenom / cfg->param->fpsNum;
-    qp = cfg->param->rc.qp;
+    isAbr = param->rc.rateControlMode != X265_RC_CQP; // later add 2pass option
+    bitrate = param->rc.bitrate * 1000;
+    frameDuration = (double)param->fpsDenom / param->fpsNum;
+    qp = param->rc.qp;
     lastRceq = 1; /* handles the cmplxrsum when the previous frame cost is zero */
     shortTermCplxSum = 0;
     shortTermCplxCount = 0;
@@ -254,97 +254,97 @@
     lastAbrResetPoc = -1;
     frameSizeEstimated = 0;
     // vbv initialization
-    cfg->param->rc.vbvBufferSize = Clip3(0, 2000000, cfg->param->rc.vbvBufferSize);
-    cfg->param->rc.vbvMaxBitrate = Clip3(0, 2000000, cfg->param->rc.vbvMaxBitrate);
-    cfg->param->rc.vbvBufferInit = Clip3(0.0, 2000000.0, cfg->param->rc.vbvBufferInit);
+    param->rc.vbvBufferSize = Clip3(0, 2000000, param->rc.vbvBufferSize);
+    param->rc.vbvMaxBitrate = Clip3(0, 2000000, param->rc.vbvMaxBitrate);
+    param->rc.vbvBufferInit = Clip3(0.0, 2000000.0, param->rc.vbvBufferInit);
     vbvMinRate = 0;
-    if (cfg->param->rc.vbvBufferSize)
+    if (param->rc.vbvBufferSize)
     {
-        if (cfg->param->rc.rateControlMode == X265_RC_CQP)
+        if (param->rc.rateControlMode == X265_RC_CQP)
         {
-            x265_log(cfg->param, X265_LOG_WARNING, "VBV is incompatible with constant QP, ignored.\n");
-            cfg->param->rc.vbvBufferSize = 0;
-            cfg->param->rc.vbvMaxBitrate = 0;
+            x265_log(param, X265_LOG_WARNING, "VBV is incompatible with constant QP, ignored.\n");
+            param->rc.vbvBufferSize = 0;
+            param->rc.vbvMaxBitrate = 0;
         }
-        else if (cfg->param->rc.vbvMaxBitrate == 0)
+        else if (param->rc.vbvMaxBitrate == 0)
         {
-            if (cfg->param->rc.rateControlMode == X265_RC_ABR)
+            if (param->rc.rateControlMode == X265_RC_ABR)
             {
-                x265_log(cfg->param, X265_LOG_WARNING, "VBV maxrate unspecified, assuming CBR\n");
-                cfg->param->rc.vbvMaxBitrate = cfg->param->rc.bitrate;
+                x265_log(param, X265_LOG_WARNING, "VBV maxrate unspecified, assuming CBR\n");
+                param->rc.vbvMaxBitrate = param->rc.bitrate;
             }
             else
             {
-                x265_log(cfg->param, X265_LOG_WARNING, "VBV bufsize set but maxrate unspecified, ignored\n");
-                cfg->param->rc.vbvBufferSize = 0;
+                x265_log(param, X265_LOG_WARNING, "VBV bufsize set but maxrate unspecified, ignored\n");
+                param->rc.vbvBufferSize = 0;
             }
         }
-        else if (cfg->param->rc.vbvMaxBitrate < cfg->param->rc.bitrate &&
-                 cfg->param->rc.rateControlMode == X265_RC_ABR)
+        else if (param->rc.vbvMaxBitrate < param->rc.bitrate &&
+                 param->rc.rateControlMode == X265_RC_ABR)
         {
-            x265_log(cfg->param, X265_LOG_WARNING, "max bitrate less than average bitrate, assuming CBR\n");
-            cfg->param->rc.bitrate = cfg->param->rc.vbvMaxBitrate;
+            x265_log(param, X265_LOG_WARNING, "max bitrate less than average bitrate, assuming CBR\n");
+            param->rc.bitrate = param->rc.vbvMaxBitrate;
         }
     }
-    else if (cfg->param->rc.vbvMaxBitrate)
+    else if (param->rc.vbvMaxBitrate)
     {
-        x265_log(cfg->param, X265_LOG_WARNING, "VBV maxrate specified, but no bufsize, ignored\n");
-        cfg->param->rc.vbvMaxBitrate = 0;
+        x265_log(param, X265_LOG_WARNING, "VBV maxrate specified, but no bufsize, ignored\n");
+        param->rc.vbvMaxBitrate = 0;
     }
 
-    isVbv = cfg->param->rc.vbvMaxBitrate > 0 && cfg->param->rc.vbvBufferSize > 0;
-    double fps = (double)cfg->param->fpsNum / cfg->param->fpsDenom;
+    isVbv = param->rc.vbvMaxBitrate > 0 && param->rc.vbvBufferSize > 0;
+    double fps = (double)param->fpsNum / param->fpsDenom;
     if (isVbv)
     {
         /* We don't support changing the ABR bitrate right now,
            so if the stream starts as CBR, keep it CBR. */
-        if (cfg->param->rc.vbvBufferSize < (int)(cfg->param->rc.vbvMaxBitrate / fps))
+        if (param->rc.vbvBufferSize < (int)(param->rc.vbvMaxBitrate / fps))
         {
-            cfg->param->rc.vbvBufferSize = (int)(cfg->param->rc.vbvMaxBitrate / fps);
-            x265_log(cfg->param, X265_LOG_WARNING, "VBV buffer size cannot be smaller than one frame, using %d kbit\n",
-                     cfg->param->rc.vbvBufferSize);
+            param->rc.vbvBufferSize = (int)(param->rc.vbvMaxBitrate / fps);
+            x265_log(param, X265_LOG_WARNING, "VBV buffer size cannot be smaller than one frame, using %d kbit\n",
+                     param->rc.vbvBufferSize);
         }
-        int vbvBufferSize = cfg->param->rc.vbvBufferSize * 1000;
-        int vbvMaxBitrate = cfg->param->rc.vbvMaxBitrate * 1000;
+        int vbvBufferSize = param->rc.vbvBufferSize * 1000;
+        int vbvMaxBitrate = param->rc.vbvMaxBitrate * 1000;
 
         bufferRate = vbvMaxBitrate / fps;
         vbvMaxRate = vbvMaxBitrate;
         bufferSize = vbvBufferSize;
         singleFrameVbv = bufferRate * 1.1 > bufferSize;
 
-        if (cfg->param->rc.vbvBufferInit > 1.)
-            cfg->param->rc.vbvBufferInit = Clip3(0.0, 1.0, cfg->param->rc.vbvBufferInit / cfg->param->rc.vbvBufferSize);
-        cfg->param->rc.vbvBufferInit = Clip3(0.0, 1.0, X265_MAX(cfg->param->rc.vbvBufferInit, bufferRate / bufferSize));
-        bufferFillFinal = bufferSize * cfg->param->rc.vbvBufferInit;
-        vbvMinRate = /*!rc->b_2pass && */ cfg->param->rc.rateControlMode == X265_RC_ABR
-            && cfg->param->rc.vbvMaxBitrate <= cfg->param->rc.bitrate;
+        if (param->rc.vbvBufferInit > 1.)
+            param->rc.vbvBufferInit = Clip3(0.0, 1.0, param->rc.vbvBufferInit / param->rc.vbvBufferSize);
+        param->rc.vbvBufferInit = Clip3(0.0, 1.0, X265_MAX(param->rc.vbvBufferInit, bufferRate / bufferSize));
+        bufferFillFinal = bufferSize * param->rc.vbvBufferInit;
+        vbvMinRate = /*!rc->b_2pass && */ param->rc.rateControlMode == X265_RC_ABR
+            && param->rc.vbvMaxBitrate <= param->rc.bitrate;
     }
 
-    bframes = cfg->param->bframes;
+    bframes = param->bframes;
     bframeBits = 0;
     leadingNoBSatd = 0;
-    if (cfg->param->rc.rateControlMode == X265_RC_ABR)
+    if (param->rc.rateControlMode == X265_RC_ABR)
     {
         /* Adjust the first frame in order to stabilize the quality level compared to the rest */
 #define ABR_INIT_QP_MIN (24 + QP_BD_OFFSET)
 #define ABR_INIT_QP_MAX (34 + QP_BD_OFFSET)
     }
-    else if (cfg->param->rc.rateControlMode == X265_RC_CRF)
+    else if (param->rc.rateControlMode == X265_RC_CRF)
     {
-#define ABR_INIT_QP ((int)cfg->param->rc.rfConstant)
+#define ABR_INIT_QP ((int)param->rc.rfConstant)
     }
     reInit();
 
-    ipOffset = 6.0 * X265_LOG2(cfg->param->rc.ipFactor);
-    pbOffset = 6.0 * X265_LOG2(cfg->param->rc.pbFactor);
+    ipOffset = 6.0 * X265_LOG2(param->rc.ipFactor);
+    pbOffset = 6.0 * X265_LOG2(param->rc.pbFactor);
     for (int i = 0; i < 3; i++)
     {
-        lastQScaleFor[i] = qp2qScale(cfg->param->rc.rateControlMode == X265_RC_CRF ? ABR_INIT_QP : ABR_INIT_QP_MIN);
+        lastQScaleFor[i] = qp2qScale(param->rc.rateControlMode == X265_RC_CRF ? ABR_INIT_QP : ABR_INIT_QP_MIN);
         lmin[i] = qp2qScale(MIN_QP);
         lmax[i] = qp2qScale(MAX_MAX_QP);
     }
 
-    if (cfg->param->rc.rateControlMode == X265_RC_CQP)
+    if (param->rc.rateControlMode == X265_RC_CQP)
     {
         qpConstant[P_SLICE] = qp;
         qpConstant[I_SLICE] = Clip3(0, MAX_MAX_QP, (int)(qp - ipOffset + 0.5));
@@ -352,7 +352,7 @@
     }
 
     /* qstep - value set as encoder specific */
-    lstep = pow(2, cfg->param->rc.qpStep / 6.0);
+    lstep = pow(2, param->rc.qpStep / 6.0);
 }
 
 void RateControl::reInit()
@@ -364,7 +364,7 @@
     cplxrSum = .01 * pow(7.0e5, qCompress) * pow(ncu, 0.5);
     wantedBitsWindow = bitrate * frameDuration;
     accumPNorm = .01;
-    accumPQp = (cfg->param->rc.rateControlMode == X265_RC_CRF ? ABR_INIT_QP : ABR_INIT_QP_MIN) * accumPNorm;
+    accumPQp = (param->rc.rateControlMode == X265_RC_CRF ? ABR_INIT_QP : ABR_INIT_QP_MIN) * accumPNorm;
 
     /* Frame Predictors and Row predictors used in vbv */
     for (int i = 0; i < 5; i++)
@@ -502,7 +502,7 @@
     }
     else
     {
-        double abrBuffer = 2 * cfg->param->rc.rateTolerance * bitrate;
+        double abrBuffer = 2 * param->rc.rateTolerance * bitrate;
 
         /* 1pass ABR */
 
@@ -528,7 +528,7 @@
         rce->mvBits = 0;
         rce->sliceType = sliceType;
 
-        if (cfg->param->rc.rateControlMode == X265_RC_CRF)
+        if (param->rc.rateControlMode == X265_RC_CRF)
         {
             q = getQScale(rce, rateFactorConstant);
         }
@@ -544,7 +544,7 @@
             if (!vbvMinRate && currentSatd)
             {
                 /* use framesDone instead of POC as poc count is not serial with bframes enabled */
-                double timeDone = (double)(framesDone - cfg->param->frameNumThreads + 1) * frameDuration;
+                double timeDone = (double)(framesDone - param->frameNumThreads + 1) * frameDuration;
                 wantedBits = timeDone * bitrate;
                 if (wantedBits > 0 && totalBits > 0)
                 {
@@ -555,14 +555,14 @@
             }
         }
 
-        if (sliceType == I_SLICE && cfg->param->keyframeMax > 1
+        if (sliceType == I_SLICE && param->keyframeMax > 1
             && lastNonBPictType != I_SLICE && !isAbrReset)
         {
             q = qp2qScale(accumPQp / accumPNorm);
-            q /= fabs(cfg->param->rc.ipFactor);
+            q /= fabs(param->rc.ipFactor);
         }
 
-        if (cfg->param->rc.rateControlMode != X265_RC_CRF)
+        if (param->rc.rateControlMode != X265_RC_CRF)
         {
             double lqmin = 0, lqmax = 0;
             if (totalBits == 0 && !isVbv)
@@ -585,7 +585,7 @@
         else
         {
             if (qCompress != 1 && framesDone == 0)
-                q = qp2qScale(ABR_INIT_QP) / fabs(cfg->param->rc.ipFactor);
+                q = qp2qScale(ABR_INIT_QP) / fabs(param->rc.ipFactor);
         }
         double lmin1 = lmin[sliceType];
         double lmax1 = lmax[sliceType];
@@ -597,7 +597,7 @@
         lastQScaleFor[sliceType] = q;
 
         if (curSlice->getPOC() == 0 || (isAbrReset && sliceType == I_SLICE))
-            lastQScaleFor[P_SLICE] = q * fabs(cfg->param->rc.ipFactor);
+            lastQScaleFor[P_SLICE] = q * fabs(param->rc.ipFactor);
 
         rce->frameSizePlanned = predictSize(&pred[sliceType], q, (double)currentSatd);
 
@@ -607,7 +607,7 @@
 
 void RateControl::checkAndResetABR(RateControlEntry* rce, bool isFrameDone)
 {
-    double abrBuffer = 2 * cfg->param->rc.rateTolerance * bitrate;
+    double abrBuffer = 2 * param->rc.rateTolerance * bitrate;
 
     // Check if current Slice is a scene cut that follows low detailed/blank frames
     if (rce->lastSatd > 4 * rce->movingAvgSum)
@@ -654,7 +654,7 @@
     // since they are controlled by the P-frames' QPs.
     if (isVbv && currentSatd > 0)
     {
-        if (cfg->param->lookaheadDepth)
+        if (param->lookaheadDepth)
         {
             int terminate = 0;
 
@@ -666,9 +666,9 @@
                 double bufferFillCur = bufferFill - curBits;
                 double targetFill;
                 double totalDuration = 0;
-                frameQ[P_SLICE] = sliceType == I_SLICE ? q * cfg->param->rc.ipFactor : q;
-                frameQ[B_SLICE] = frameQ[P_SLICE] * cfg->param->rc.pbFactor;
-                frameQ[I_SLICE] = frameQ[P_SLICE] / cfg->param->rc.ipFactor;
+                frameQ[P_SLICE] = sliceType == I_SLICE ? q * param->rc.ipFactor : q;
+                frameQ[B_SLICE] = frameQ[P_SLICE] * param->rc.pbFactor;
+                frameQ[I_SLICE] = frameQ[P_SLICE] / param->rc.ipFactor;
                 /* Loop over the planned future frames. */
                 for (int j = 0; bufferFillCur >= 0 && bufferFillCur <= bufferSize; j++)
                 {
@@ -742,7 +742,7 @@
         {
             int nb = bframes;
             double bits = predictSize(&pred[sliceType], q, (double)currentSatd);
-            double bbits = predictSize(&predBfromP, q * cfg->param->rc.pbFactor, (double)currentSatd);
+            double bbits = predictSize(&predBfromP, q * param->rc.pbFactor, (double)currentSatd);
             double space;
             if (bbits > bufferRate)
                 nb = 0;
@@ -859,8 +859,8 @@
     double qpAbsoluteMax = MAX_MAX_QP;
     if (rateFactorMaxIncrement)
         qpAbsoluteMax = X265_MIN(qpAbsoluteMax, rce->qpNoVbv + rateFactorMaxIncrement);
-    double qpMax = X265_MIN(prevRowQp + cfg->param->rc.qpStep, qpAbsoluteMax);
-    double qpMin = X265_MAX(prevRowQp - cfg->param->rc.qpStep, MIN_QP);
+    double qpMax = X265_MIN(prevRowQp + param->rc.qpStep, qpAbsoluteMax);
+    double qpMin = X265_MAX(prevRowQp - param->rc.qpStep, MIN_QP);
     double stepSize = 0.5;
     double bufferLeftPlanned = rce->bufferFill - rce->frameSizePlanned;
 
@@ -877,7 +877,7 @@
             qpVbv = X265_MAX(qpVbv, qpMin);
         }
         /* More threads means we have to be more cautious in letting ratecontrol use up extra bits. */
-        double rcTol = bufferLeftPlanned / cfg->param->frameNumThreads * cfg->param->rc.rateTolerance;
+        double rcTol = bufferLeftPlanned / param->frameNumThreads * param->rc.rateTolerance;
         int32_t encodedBitsSoFar = 0;
         double accFrameBits = predictRowsSizeSum(pic, qpVbv, encodedBitsSoFar);
 
@@ -951,14 +951,14 @@
 {
     double q;
 
-    if (cfg->param->rc.cuTree)
+    if (param->rc.cuTree)
     {
         // Scale and units are obtained from rateNum and rateDenom for videos with fixed frame rates.
-        double timescale = (double)cfg->param->fpsDenom / (2 * cfg->param->fpsNum);
-        q = pow(BASE_FRAME_DURATION / CLIP_DURATION(2 * timescale), 1 - cfg->param->rc.qCompress);
+        double timescale = (double)param->fpsDenom / (2 * param->fpsNum);
+        q = pow(BASE_FRAME_DURATION / CLIP_DURATION(2 * timescale), 1 - param->rc.qCompress);
     }
     else
-        q = pow(rce->blurredComplexity, 1 - cfg->param->rc.qCompress);
+        q = pow(rce->blurredComplexity, 1 - param->rc.qCompress);
 
     // avoid NaN's in the rc_eq
     if (rce->texBits + rce->mvBits == 0)
@@ -1002,7 +1002,7 @@
     bufferFillFinal -= bits;
 
     if (bufferFillFinal < 0)
-        x265_log(cfg->param, X265_LOG_WARNING, "poc:%d, VBV underflow (%.0f bits)\n", rce->poc, bufferFillFinal);
+        x265_log(param, X265_LOG_WARNING, "poc:%d, VBV underflow (%.0f bits)\n", rce->poc, bufferFillFinal);
 
     bufferFillFinal = X265_MAX(bufferFillFinal, 0);
     bufferFillFinal += bufferRate;
@@ -1014,13 +1014,13 @@
 {
     if (isAbr)
     {
-        if (cfg->param->rc.rateControlMode == X265_RC_ABR)
+        if (param->rc.rateControlMode == X265_RC_ABR)
         {
             checkAndResetABR(rce, true);
         }
         if (!isAbrReset)
         {
-            if (cfg->param->rc.aqMode || isVbv)
+            if (param->rc.aqMode || isVbv)
             {
                 if (pic->m_qpaRc)
                 {
@@ -1048,7 +1048,7 @@
             {
                 /* Depends on the fact that B-frame's QP is an offset from the following P-frame's.
                  * Not perfectly accurate with B-refs, but good enough. */
-                cplxrSum += bits * qp2qScale(rce->qpaRc) / (rce->qRceq * fabs(cfg->param->rc.pbFactor));
+                cplxrSum += bits * qp2qScale(rce->qpaRc) / (rce->qRceq * fabs(param->rc.pbFactor));
             }
             wantedBitsWindow += frameDuration * bitrate;
             totalBits += bits;
diff -r 9f3515756d0f -r 8584ba886cb0 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h	Fri Mar 07 14:49:07 2014 -0800
+++ b/source/encoder/ratecontrol.h	Fri Mar 07 16:46:58 2014 -0800
@@ -75,7 +75,7 @@
 struct RateControl
 {
     TComSlice *curSlice;      /* all info about the current frame */
-    Encoder *cfg;
+    x265_param* param;
     SliceType sliceType;      /* Current frame type */
     int ncu;                  /* number of CUs in a frame */
     int keyFrameInterval;     /* TODO: need to initialize in init */
diff -r 9f3515756d0f -r 8584ba886cb0 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Fri Mar 07 14:49:07 2014 -0800
+++ b/source/encoder/slicetype.cpp	Fri Mar 07 16:46:58 2014 -0800
@@ -59,11 +59,11 @@
 Lookahead::Lookahead(Encoder *_cfg, ThreadPool* pool)
     : est(pool)
 {
-    this->cfg = _cfg;
-    lastKeyframe = -cfg->param->keyframeMax;
+    param = _cfg->param;
+    lastKeyframe = -param->keyframeMax;
     lastNonB = NULL;
-    widthInCU = ((cfg->param->sourceWidth / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
-    heightInCU = ((cfg->param->sourceHeight / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
+    widthInCU = ((param->sourceWidth / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
+    heightInCU = ((param->sourceHeight / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
     scratch = (int*)x265_malloc(widthInCU * sizeof(int));
     memset(histogram, 0, sizeof(histogram));
 }
@@ -99,7 +99,7 @@
     pic->m_lowres.init(orig, pic->getSlice()->getPOC(), sliceType);
     inputQueue.pushBack(*pic);
 
-    if (inputQueue.size() >= cfg->param->lookaheadDepth)
+    if (inputQueue.size() >= param->lookaheadDepth)
         slicetypeDecide();
 }
 
@@ -168,27 +168,27 @@
     if (pic->m_lowres.costEst[b - p0][p1 - b] < 0)
     {
         CostEstimate cost(ThreadPool::getThreadPool());
-        cost.init(cfg, pic);
+        cost.init(param, pic);
         cost.estimateFrameCost(frames, p0, p1, b, false);
         cost.flush();
     }
-    if (cfg->param->rc.cuTree)
+    if (param->rc.cuTree)
     {
         pic->m_lowres.satdCost = frameCostRecalculate(frames, p0, p1, b);
-        if (b && cfg->param->rc.vbvBufferSize)
+        if (b && param->rc.vbvBufferSize)
             frameCostRecalculate(frames, b, b, b);
     }
 
-    else if (cfg->param->rc.aqMode)
+    else if (param->rc.aqMode)
         pic->m_lowres.satdCost = pic->m_lowres.costEstAq[b - p0][p1 - b];
     else
         pic->m_lowres.satdCost = pic->m_lowres.costEst[b - p0][p1 - b];
 
-    if (cfg->param->rc.vbvBufferSize > 0 && cfg->param->rc.vbvMaxBitrate > 0)
+    if (param->rc.vbvBufferSize > 0 && param->rc.vbvMaxBitrate > 0)
     {
         pic->m_lowres.lowresCostForRc = pic->m_lowres.lowresCosts[b - p0][p1 - b];
         uint32_t lowresRow = 0, lowresCol = 0, lowresCuIdx = 0, sum = 0;
-        uint32_t scale = cfg->param->maxCUSize / (2 * X265_LOWRES_CU_SIZE);
+        uint32_t scale = param->maxCUSize / (2 * X265_LOWRES_CU_SIZE);
         uint32_t widthInLowresCu = (uint32_t)widthInCU, heightInLowresCu = (uint32_t)heightInCU;
 
         for (uint32_t row = 0; row < pic->getFrameHeightInCU(); row++)
@@ -215,14 +215,14 @@
     Lowres *frames[X265_LOOKAHEAD_MAX];
     TComPic *list[X265_LOOKAHEAD_MAX];
     TComPic *ipic = inputQueue.first();
-    bool isKeyFrameAnalyse = (cfg->param->rc.cuTree || (cfg->param->rc.vbvBufferSize && cfg->param->lookaheadDepth));
+    bool isKeyFrameAnalyse = (param->rc.cuTree || (param->rc.vbvBufferSize && param->lookaheadDepth));
 
     if (!est.rows && ipic)
-        est.init(cfg, ipic);
+        est.init(param, ipic);
 
-    if ((cfg->param->bFrameAdaptive && cfg->param->bframes) ||
-        cfg->param->rc.cuTree || cfg->param->scenecutThreshold ||
-        (cfg->param->lookaheadDepth && cfg->param->rc.vbvBufferSize))
+    if ((param->bFrameAdaptive && param->bframes) ||
+        param->rc.cuTree || param->scenecutThreshold ||
+        (param->lookaheadDepth && param->rc.vbvBufferSize))
     {
         slicetypeAnalyse(frames, false);
     }
@@ -230,7 +230,7 @@
         frames[0] = lastNonB;
 
     int j;
-    for (j = 0; ipic && j < cfg->param->bframes + 2; ipic = ipic->m_next)
+    for (j = 0; ipic && j < param->bframes + 2; ipic = ipic->m_next)
     {
         list[j++] = ipic;
     }
@@ -242,40 +242,40 @@
     {
         Lowres& frm = list[bframes]->m_lowres;
 
-        if (frm.sliceType == X265_TYPE_BREF && !cfg->param->bBPyramid && brefs == cfg->param->bBPyramid)
+        if (frm.sliceType == X265_TYPE_BREF && !param->bBPyramid && brefs == param->bBPyramid)
         {
             frm.sliceType = X265_TYPE_B;
-            x265_log(cfg->param, X265_LOG_WARNING, "B-ref at frame %d incompatible with B-pyramid\n",
+            x265_log(param, X265_LOG_WARNING, "B-ref at frame %d incompatible with B-pyramid\n",
                      frm.frameNum);
         }
 
         /* pyramid with multiple B-refs needs a big enough dpb that the preceding P-frame stays available.
            smaller dpb could be supported by smart enough use of mmco, but it's easier just to forbid it.*/
-        else if (frm.sliceType == X265_TYPE_BREF && cfg->param->bBPyramid && brefs &&
-                 cfg->param->maxNumReferences <= (brefs + 3))
+        else if (frm.sliceType == X265_TYPE_BREF && param->bBPyramid && brefs &&
+                 param->maxNumReferences <= (brefs + 3))
         {
             frm.sliceType = X265_TYPE_B;
-            x265_log(cfg->param, X265_LOG_WARNING, "B-ref at frame %d incompatible with B-pyramid and %d reference frames\n",
-                     frm.sliceType, cfg->param->maxNumReferences);
+            x265_log(param, X265_LOG_WARNING, "B-ref at frame %d incompatible with B-pyramid and %d reference frames\n",
+                     frm.sliceType, param->maxNumReferences);
         }
 
-        if ( /*(!cfg->param->intraRefresh || frm.frameNum == 0) && */ frm.frameNum - lastKeyframe >= cfg->param->keyframeMax)
+        if ( /*(!param->intraRefresh || frm.frameNum == 0) && */ frm.frameNum - lastKeyframe >= param->keyframeMax)
         {
             if (frm.sliceType == X265_TYPE_AUTO || frm.sliceType == X265_TYPE_I)
-                frm.sliceType = cfg->param->bOpenGOP && lastKeyframe >= 0 ? X265_TYPE_I : X265_TYPE_IDR;
+                frm.sliceType = param->bOpenGOP && lastKeyframe >= 0 ? X265_TYPE_I : X265_TYPE_IDR;
             bool warn = frm.sliceType != X265_TYPE_IDR;
-            if (warn && cfg->param->bOpenGOP)
+            if (warn && param->bOpenGOP)
                 warn &= frm.sliceType != X265_TYPE_I;
             if (warn)
             {
-                x265_log(cfg->param, X265_LOG_WARNING, "specified frame type (%d) at %d is not compatible with keyframe interval\n",
+                x265_log(param, X265_LOG_WARNING, "specified frame type (%d) at %d is not compatible with keyframe interval\n",
                          frm.sliceType, frm.frameNum);
-                frm.sliceType = cfg->param->bOpenGOP && lastKeyframe >= 0 ? X265_TYPE_I : X265_TYPE_IDR;
+                frm.sliceType = param->bOpenGOP && lastKeyframe >= 0 ? X265_TYPE_I : X265_TYPE_IDR;
             }
         }
-        if (frm.sliceType == X265_TYPE_I && frm.frameNum - lastKeyframe >= cfg->param->keyframeMin)
+        if (frm.sliceType == X265_TYPE_I && frm.frameNum - lastKeyframe >= param->keyframeMin)
         {
-            if (cfg->param->bOpenGOP)
+            if (param->bOpenGOP)
             {
                 lastKeyframe = frm.frameNum;
                 frm.bKeyframe = true;
@@ -294,10 +294,10 @@
                 bframes--;
             }
         }
-        if (bframes == cfg->param->bframes || !list[bframes + 1])
+        if (bframes == param->bframes || !list[bframes + 1])
         {
             if (IS_X265_TYPE_B(frm.sliceType))
-                x265_log(cfg->param, X265_LOG_WARNING, "specified frame type is not compatible with max B-frames\n");
+                x265_log(param, X265_LOG_WARNING, "specified frame type is not compatible with max B-frames\n");
             if (frm.sliceType == X265_TYPE_AUTO || IS_X265_TYPE_B(frm.sliceType))
                 frm.sliceType = X265_TYPE_P;
         }
@@ -316,14 +316,14 @@
     histogram[bframes]++;
 
     /* insert a bref into the sequence */
-    if (cfg->param->bBPyramid && bframes > 1 && !brefs)
+    if (param->bBPyramid && bframes > 1 && !brefs)
     {
         list[bframes / 2]->m_lowres.sliceType = X265_TYPE_BREF;
         brefs++;
     }
 
     /* calculate the frame costs ahead of time for x264_rc_analyse_slice while we still have lowres */
-    if (cfg->param->rc.rateControlMode != X265_RC_CQP)
+    if (param->rc.rateControlMode != X265_RC_CQP)
     {
         int p0, p1, b;
         p1 = b = bframes + 1;
@@ -340,7 +340,7 @@
 
         est.estimateFrameCost(frames, p0, p1, b, 0);
 
-        if ((p0 != p1 || bframes) && cfg->param->rc.vbvBufferSize)
+        if ((p0 != p1 || bframes) && param->rc.vbvBufferSize)
         {
             // We need the intra costs for row SATDs
             est.estimateFrameCost(frames, b, b, b, 0);
@@ -381,7 +381,7 @@
     outputQueue.pushBack(*list[bframes]);
 
     /* Add B-ref frame next to P frame in output queue, the B-ref encode before non B-ref frame */
-    if (bframes > 1 && cfg->param->bBPyramid)
+    if (bframes > 1 && param->bBPyramid)
     {
         for (int i = 0; i < bframes; i++)
         {
@@ -453,9 +453,9 @@
 {
     int64_t cost = est.estimateFrameCost(frames, p0, p1, b, 0);
 
-    if (cfg->param->rc.aqMode)
+    if (param->rc.aqMode)
     {
-        if (cfg->param->rc.cuTree)
+        if (param->rc.cuTree)
             return frameCostRecalculate(frames, p0, p1, b);
         else
             return frames[b]->costEstAq[b - p0][p1 - b];
@@ -466,10 +466,10 @@
 void Lookahead::slicetypeAnalyse(Lowres **frames, bool bKeyframe)
 {
     int numFrames, origNumFrames, keyintLimit, framecnt;
-    int maxSearch = X265_MIN(cfg->param->lookaheadDepth, X265_LOOKAHEAD_MAX);
+    int maxSearch = X265_MIN(param->lookaheadDepth, X265_LOOKAHEAD_MAX);
     int cuCount = NUM_CUS;
     int resetStart;
-    bool bIsVbvLookahead = cfg->param->rc.vbvBufferSize && cfg->param->lookaheadDepth;
+    bool bIsVbvLookahead = param->rc.vbvBufferSize && param->lookaheadDepth;
 
     if (!lastNonB)
         return;
@@ -484,19 +484,19 @@
 
     if (!framecnt)
     {
-        if (cfg->param->rc.cuTree)
+        if (param->rc.cuTree)
             cuTree(frames, 0, bKeyframe);
         return;
     }
 
     frames[framecnt + 1] = NULL;
 
-    keyintLimit = cfg->param->keyframeMax - frames[0]->frameNum + lastKeyframe - 1;
+    keyintLimit = param->keyframeMax - frames[0]->frameNum + lastKeyframe - 1;
     origNumFrames = numFrames = X265_MIN(framecnt, keyintLimit);
 
     if (bIsVbvLookahead)
         numFrames = framecnt;
-    else if (cfg->param->bOpenGOP && numFrames < framecnt)
+    else if (param->bOpenGOP && numFrames < framecnt)
         numFrames++;
     else if (numFrames == 0)
     {
@@ -506,15 +506,15 @@
 
     int numBFrames = 0;
     int numAnalyzed = numFrames;
-    if (cfg->param->scenecutThreshold && scenecut(frames, 0, 1, true, origNumFrames, maxSearch))
+    if (param->scenecutThreshold && scenecut(frames, 0, 1, true, origNumFrames, maxSearch))
     {
         frames[1]->sliceType = X265_TYPE_I;
         return;
     }
 
-    if (cfg->param->bframes)
+    if (param->bframes)
     {
-        if (cfg->param->bFrameAdaptive == X265_B_ADAPT_TRELLIS)
+        if (param->bFrameAdaptive == X265_B_ADAPT_TRELLIS)
         {
             if (numFrames > 1)
             {
@@ -537,7 +537,7 @@
             }
             frames[numFrames]->sliceType = X265_TYPE_P;
         }
-        else if (cfg->param->bFrameAdaptive == X265_B_ADAPT_FAST)
+        else if (param->bFrameAdaptive == X265_B_ADAPT_FAST)
         {
             int64_t cost1p0, cost2p0, cost1b1, cost2p1;
 
@@ -565,11 +565,11 @@
 
 // arbitrary and untuned
 #define INTER_THRESH 300
-#define P_SENS_BIAS (50 - cfg->param->bFrameBias)
+#define P_SENS_BIAS (50 - param->bFrameBias)
                 frames[i + 1]->sliceType = X265_TYPE_B;
 
                 int j;
-                for (j = i + 2; j <= X265_MIN(i + cfg->param->bframes, numFrames - 1); j++)
+                for (j = i + 2; j <= X265_MIN(i + param->bframes, numFrames - 1); j++)
                 {
                     int64_t pthresh = X265_MAX(INTER_THRESH - P_SENS_BIAS * (j - i - 1), INTER_THRESH / 10);
                     int64_t pcost = est.estimateFrameCost(frames, i + 0, j + 1, j + 1, 1);
@@ -590,7 +590,7 @@
         }
         else
         {
-            numBFrames = X265_MIN(numFrames - 1, cfg->param->bframes);
+            numBFrames = X265_MIN(numFrames - 1, param->bframes);
             for (int j = 1; j < numFrames; j++)
             {
                 frames[j]->sliceType = (j % (numBFrames + 1)) ? X265_TYPE_B : X265_TYPE_P;
@@ -601,7 +601,7 @@
         /* Check scenecut on the first minigop. */
         for (int j = 1; j < numBFrames + 1; j++)
         {
-            if (cfg->param->scenecutThreshold && scenecut(frames, j, j + 1, false, origNumFrames, maxSearch))
+            if (param->scenecutThreshold && scenecut(frames, j, j + 1, false, origNumFrames, maxSearch))
             {
                 frames[j]->sliceType = X265_TYPE_P;
                 numAnalyzed = j;
@@ -621,11 +621,11 @@
         resetStart = bKeyframe ? 1 : 2;
     }
 
-    if (cfg->param->rc.cuTree)
-        cuTree(frames, X265_MIN(numFrames, cfg->param->keyframeMax), bKeyframe);
+    if (param->rc.cuTree)
+        cuTree(frames, X265_MIN(numFrames, param->keyframeMax), bKeyframe);
 
-    // if (!cfg->param->bIntraRefresh)
-    for (int j = keyintLimit + 1; j <= numFrames; j += cfg->param->keyframeMax)
+    // if (!param->bIntraRefresh)
+    for (int j = keyintLimit + 1; j <= numFrames; j += param->keyframeMax)
     {
         frames[j]->sliceType = X265_TYPE_I;
         resetStart = X265_MIN(resetStart, j + 1);
@@ -644,13 +644,13 @@
 bool Lookahead::scenecut(Lowres **frames, int p0, int p1, bool bRealScenecut, int numFrames, int maxSearch)
 {
     /* Only do analysis during a normal scenecut check. */
-    if (bRealScenecut && cfg->param->bframes)
+    if (bRealScenecut && param->bframes)
     {
         int origmaxp1 = p0 + 1;
         /* Look ahead to avoid coding short flashes as scenecuts. */
-        if (cfg->param->bFrameAdaptive == X265_B_ADAPT_TRELLIS)
+        if (param->bFrameAdaptive == X265_B_ADAPT_TRELLIS)
             /* Don't analyse any more frames than the trellis would have covered. */
-            origmaxp1 += cfg->param->bframes;
+            origmaxp1 += param->bframes;
         else
             origmaxp1++;
         int maxp1 = X265_MIN(origmaxp1, numFrames);
@@ -696,24 +696,24 @@
     int64_t icost = frame->costEst[0][0];
     int64_t pcost = frame->costEst[p1 - p0][0];
     int gopSize = frame->frameNum - lastKeyframe;
-    float threshMax = (float)(cfg->param->scenecutThreshold / 100.0);
+    float threshMax = (float)(param->scenecutThreshold / 100.0);
 
     /* magic numbers pulled out of thin air */
     float threshMin = (float)(threshMax * 0.25);
     float bias;
 
-    if (cfg->param->keyframeMin == cfg->param->keyframeMax)
+    if (param->keyframeMin == param->keyframeMax)
         threshMin = threshMax;
-    if (gopSize <= cfg->param->keyframeMin / 4)
+    if (gopSize <= param->keyframeMin / 4)
         bias = threshMin / 4;
-    else if (gopSize <= cfg->param->keyframeMin)
-        bias = threshMin * gopSize / cfg->param->keyframeMin;
+    else if (gopSize <= param->keyframeMin)
+        bias = threshMin * gopSize / param->keyframeMin;
     else
     {
         bias = threshMin
             + (threshMax - threshMin)
-            * (gopSize - cfg->param->keyframeMin)
-            / (cfg->param->keyframeMax - cfg->param->keyframeMin);
+            * (gopSize - param->keyframeMin)
+            / (param->keyframeMax - param->keyframeMin);
     }
 
     bool res = pcost >= (1.0 - bias) * icost;
@@ -721,7 +721,7 @@
     {
         int imb = frame->intraMbs[p1 - p0];
         int pmb = NUM_CUS - imb;
-        x265_log(cfg->param, X265_LOG_DEBUG, "scene cut at %d Icost:%d Pcost:%d ratio:%.4f bias:%.4f gop:%d (imb:%d pmb:%d)\n",
+        x265_log(param, X265_LOG_DEBUG, "scene cut at %d Icost:%d Pcost:%d ratio:%.4f bias:%.4f gop:%d (imb:%d pmb:%d)\n",
                  frame->frameNum, icost, pcost, 1. - (double)pcost / icost, bias, gopSize, imb, pmb);
     }
     return res;
@@ -730,7 +730,7 @@
 void Lookahead::slicetypePath(Lowres **frames, int length, char(*best_paths)[X265_LOOKAHEAD_MAX + 1])
 {
     char paths[2][X265_LOOKAHEAD_MAX + 1];
-    int num_paths = X265_MIN(cfg->param->bframes + 1, length);
+    int num_paths = X265_MIN(param->bframes + 1, length);
     int64_t best_cost = 1LL << 62;
     int idx = 0;
 
@@ -778,7 +778,7 @@
         if (cost > threshold)
             break;
 
-        if (cfg->param->bBPyramid && next_p - cur_p > 2)
+        if (param->bBPyramid && next_p - cur_p > 2)
         {
             int middle = cur_p + (next_p - cur_p) / 2;
             cost += est.estimateFrameCost(frames, cur_p, next_p, middle, 0);
@@ -817,7 +817,7 @@
     double totalDuration = 0.0;
     for (int j = 0; j <= numframes; j++)
     {
-        totalDuration += (double)cfg->param->fpsDenom / cfg->param->fpsNum;
+        totalDuration += (double)param->fpsDenom / param->fpsNum;
     }
 
     double averageDuration = totalDuration / (numframes + 1);
@@ -838,7 +838,7 @@
     /* Lookaheadless MB-tree is not a theoretically distinct case; the same extrapolation could
      * be applied to the end of a lookahead buffer of any size.  However, it's most needed when
      * lookahead=0, so that's what's currently implemented. */
-    if (!cfg->param->lookaheadDepth)
+    if (!param->lookaheadDepth)
     {
         if (bIntra)
         {
@@ -870,7 +870,7 @@
         est.estimateFrameCost(frames, curnonb, lastnonb, lastnonb, 0);
         memset(frames[curnonb]->propagateCost, 0, cuCount * sizeof(uint16_t));
         bframes = lastnonb - curnonb - 1;
-        if (cfg->param->bBPyramid && bframes > 1)
+        if (param->bBPyramid && bframes > 1)
         {
             int middle = (bframes + 1) / 2 + curnonb;
             est.estimateFrameCost(frames, curnonb, lastnonb, middle, 0);
@@ -902,7 +902,7 @@
         lastnonb = curnonb;
     }
 
-    if (!cfg->param->lookaheadDepth)
+    if (!param->lookaheadDepth)
     {
         est.estimateFrameCost(frames, 0, lastnonb, lastnonb, 0);
         estimateCUPropagate(frames, averageDuration, 0, lastnonb, lastnonb, 1);
@@ -910,7 +910,7 @@
     }
 
     cuTreeFinish(frames[lastnonb], averageDuration, lastnonb);
-    if (cfg->param->bBPyramid && bframes > 1 && !cfg->param->rc.vbvBufferSize)
+    if (param->bBPyramid && bframes > 1 && !param->rc.vbvBufferSize)
         cuTreeFinish(frames[lastnonb + (bframes + 1) / 2], averageDuration, 0);
 }
 
@@ -918,7 +918,7 @@
 {
     uint16_t *refCosts[2] = { frames[p0]->propagateCost, frames[p1]->propagateCost };
     int32_t distScaleFactor = (((b - p0) << 8) + ((p1 - p0) >> 1)) / (p1 - p0);
-    int32_t bipredWeight = cfg->param->bEnableWeightedBiPred ? 64 - (distScaleFactor >> 2) : 32;
+    int32_t bipredWeight = param->bEnableWeightedBiPred ? 64 - (distScaleFactor >> 2) : 32;
     MV *mvs[2] = { frames[b]->lowresMvs[0][b - p0 - 1], frames[b]->lowresMvs[1][p1 - b - 1] };
     int32_t bipredWeights[2] = { bipredWeight, 64 - bipredWeight };
 
@@ -927,7 +927,7 @@
     uint16_t *propagateCost = frames[b]->propagateCost;
 
     x265_emms();
-    double fpsFactor = CLIP_DURATION((double)cfg->param->fpsDenom / cfg->param->fpsNum) / CLIP_DURATION(averageDuration);
+    double fpsFactor = CLIP_DURATION((double)param->fpsDenom / param->fpsNum) / CLIP_DURATION(averageDuration);
 
     /* For non-refferd frames the source costs are always zero, so just memset one row and re-use it. */
     if (!referenced)
@@ -1011,13 +1011,13 @@
         }
     }
 
-    if (cfg->param->rc.vbvBufferSize && cfg->param->logLevel && referenced)
+    if (param->rc.vbvBufferSize && param->logLevel && referenced)
         cuTreeFinish(frames[b], averageDuration, b == p1 ? b - p0 : 0);
 }
 
 void Lookahead::cuTreeFinish(Lowres *frame, double averageDuration, int ref0Distance)
 {
-    int fpsFactor = (int)(CLIP_DURATION(averageDuration) / CLIP_DURATION((double)cfg->param->fpsDenom / cfg->param->fpsNum) * 256);
+    int fpsFactor = (int)(CLIP_DURATION(averageDuration) / CLIP_DURATION((double)param->fpsDenom / param->fpsNum) * 256);
     double weightdelta = 0.0;
 
     if (ref0Distance && frame->weightedCostDelta[ref0Distance - 1] > 0)
@@ -1027,7 +1027,7 @@
      * concepts are very similar. */
 
     int cuCount = widthInCU * heightInCU;
-    double strength = 5.0 * (1.0 - cfg->param->rc.qCompress);
+    double strength = 5.0 * (1.0 - param->rc.qCompress);
 
     for (int cuIndex = 0; cuIndex < cuCount; cuIndex++)
     {
@@ -1092,7 +1092,7 @@
 CostEstimate::CostEstimate(ThreadPool *p)
     : WaveFront(p)
 {
-    cfg = NULL;
+    param = NULL;
     curframes = NULL;
     wbuffer[0] = wbuffer[1] = wbuffer[2] = wbuffer[3] = 0;
     rows = NULL;
@@ -1112,11 +1112,11 @@
     delete[] rows;
 }
 
-void CostEstimate::init(Encoder *_cfg, TComPic *pic)
+void CostEstimate::init(x265_param *_param, TComPic *pic)
 {
-    cfg = _cfg;
-    widthInCU = ((cfg->param->sourceWidth / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
-    heightInCU = ((cfg->param->sourceHeight / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
+    param = _param;
+    widthInCU = ((param->sourceWidth / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
+    heightInCU = ((param->sourceHeight / 2) + X265_LOWRES_CU_SIZE - 1) >> X265_LOWRES_CU_BITS;
 
     rows = new EstimateRow[heightInCU];
     for (int i = 0; i < heightInCU; i++)
@@ -1134,7 +1134,7 @@
         WaveFront::enableAllRows();
     }
 
-    if (cfg->param->bEnableWeightedPred)
+    if (param->bEnableWeightedPred)
     {
         TComPicYuv *orig = pic->getPicYuvOrg();
         paddedLines = pic->m_lowres.lines + 2 * orig->getLumaMarginY();
@@ -1164,7 +1164,7 @@
     else
     {
         weightedRef.isWeighted = false;
-        if (cfg->param->bEnableWeightedPred && b == p1 && b != p0 && fenc->lowresMvs[0][b - p0 - 1][0].x == 0x7FFF)
+        if (param->bEnableWeightedPred && b == p1 && b != p0 && fenc->lowresMvs[0][b - p0 - 1][0].x == 0x7FFF)
         {
             if (!fenc->bIntraCalculated)
                 estimateFrameCost(frames, b, b, b, 0);
@@ -1221,7 +1221,7 @@
         {
             score += rows[row].costEst;
             fenc->costEst[0][0] += rows[row].costIntra;
-            if (cfg->param->rc.aqMode)
+            if (param->rc.aqMode)
             {
                 fenc->costEstAq[0][0] += rows[row].costIntraAq;
                 fenc->costEstAq[b - p0][p1 - b] += rows[row].costEstAq;
@@ -1232,7 +1232,7 @@
         fenc->bIntraCalculated = true;
 
         if (b != p1)
-            score = (uint64_t)score * 100 / (130 + cfg->param->bFrameBias);
+            score = (uint64_t)score * 100 / (130 + param->bFrameBias);
         if (b != p0 || b != p1) //Not Intra cost
             fenc->costEst[b - p0][p1 - b] = score;
     }
diff -r 9f3515756d0f -r 8584ba886cb0 source/encoder/slicetype.h
--- a/source/encoder/slicetype.h	Fri Mar 07 14:49:07 2014 -0800
+++ b/source/encoder/slicetype.h	Fri Mar 07 16:46:58 2014 -0800
@@ -89,9 +89,9 @@
 {
     CostEstimate(ThreadPool *p);
     ~CostEstimate();
-    void init(Encoder *, TComPic *);
+    void init(x265_param *, TComPic *);
 
-    Encoder         *cfg;
+    x265_param      *param;
     EstimateRow     *rows;
     pixel           *wbuffer[4];
     Lowres         **curframes;
@@ -127,7 +127,7 @@
     PicList          inputQueue;      // input pictures in order received
     PicList          outputQueue;     // pictures to be encoded, in encode order
 
-    Encoder         *cfg;
+    x265_param      *param;
     Lowres          *lastNonB;
     int             *scratch;         // temp buffer
 


More information about the x265-devel mailing list