[x265] [PATCH] Integrated ratecontrol in x265
sumalatha at multicorewareinc.com
sumalatha at multicorewareinc.com
Fri Aug 16 08:49:36 CEST 2013
# HG changeset patch
# User sumalatha
# Date 1376635767 -19800
# Node ID 974bb4274d0cb15e6f18be2af85b9227269d0949
# Parent 96d8704335172db24570cf11d66ad3674ba4790b
Integrated ratecontrol in x265.
Changed API's of ratecontrol methods
diff -r 96d870433517 -r 974bb4274d0c source/Lib/TLibEncoder/TEncTop.cpp
--- a/source/Lib/TLibEncoder/TEncTop.cpp Fri Aug 16 00:00:57 2013 -0500
+++ b/source/Lib/TLibEncoder/TEncTop.cpp Fri Aug 16 12:19:27 2013 +0530
@@ -95,6 +95,7 @@
m_frameEncoder = new x265::FrameEncoder(m_threadPool);
m_lookahead = new x265::Lookahead(this);
+ m_rateControl = new x265::RateControl(¶m);
}
Void TEncTop::destroy()
@@ -197,6 +198,8 @@
calculateHashAndPSNR(fenc, accessUnitOut);
+ m_rateControl->rateControlEnd(m_analyzeAll.getBits());
+
if (pic_out)
{
TComPicYuv *recpic = fenc->getPicYuvRec();
@@ -411,6 +414,9 @@
slice->setNextSlice(false);
slice->setScalingList(getScalingList());
slice->getScalingList()->setUseTransformSkip(frameEncoder->m_pps.getUseTransformSkip());
+
+ //Rate control funciton called
+ m_rateControl->rateControlStart(pic);
}
// This is a function that
diff -r 96d870433517 -r 974bb4274d0c source/Lib/TLibEncoder/TEncTop.h
--- a/source/Lib/TLibEncoder/TEncTop.h Fri Aug 16 00:00:57 2013 -0500
+++ b/source/Lib/TLibEncoder/TEncTop.h Fri Aug 16 12:19:27 2013 +0530
@@ -45,10 +45,12 @@
#include "TEncCfg.h"
#include "TEncAnalyze.h"
#include "threading.h"
+#include "ratecontrol.h"
namespace x265 {
class FrameEncoder;
struct Lookahead;
+struct RateControl;
class ThreadPool;
}
@@ -74,6 +76,7 @@
x265::ThreadPool* m_threadPool;
x265::Lookahead* m_lookahead;
x265::FrameEncoder* m_frameEncoder;
+ x265::RateControl* m_rateControl;
/* Collect statistics globally */
x265::Lock m_statLock;
diff -r 96d870433517 -r 974bb4274d0c source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Fri Aug 16 00:00:57 2013 -0500
+++ b/source/encoder/ratecontrol.cpp Fri Aug 16 12:19:27 2013 +0530
@@ -66,21 +66,17 @@
cbrDecay = 1.0;
}
-void RateControl::rateControlInit(TComSlice* frame)
+void RateControl::rateControlStart(TComPic*& pic)
{
- curFrame = frame;
- frameType = frame->getSliceType();
-}
-
-void RateControl::rateControlStart(LookaheadFrame *lFrame)
-{
+ curFrame = pic->getSlice();
+ frameType = curFrame->getSliceType();
rce = new RateControlEntry();
double q;
//Always enabling ABR
if (rateControlMode == X265_RC_ABR)
{
- q = qScale2qp(rateEstimateQscale(lFrame));
+ q = qScale2qp(rateEstimateQscale(&pic->m_lowres));
}
else
q = 0; // TODO
@@ -94,6 +90,8 @@
if (frameType != B_SLICE)
lastNonBPictType = frameType;
+ /* set the fianl changed QP to slice structure*/
+ curFrame->setSliceQp(qp);
}
void RateControl::accumPQpUpdate()
@@ -107,7 +105,7 @@
accumPQp += qpm;
}
-double RateControl::rateEstimateQscale(LookaheadFrame * /*lframe*/)
+double RateControl::rateEstimateQscale(LookaheadFrame* lframe )
{
double q;
// ratecontrol_entry_t rce = UNINIT(rce);
@@ -160,7 +158,9 @@
* tolerances, the bit distribution approaches that of 2pass. */
double wantedBits, overflow = 1;
- lastSatd = 0; //TODO:need to get this from lookahead //x264_rc_analyse_slice( h );
+ int p0 = curFrame->getRefPic(REF_PIC_LIST_0, 0)->getPOC();
+ int p1 = curFrame->getRefPic(REF_PIC_LIST_1, 0)->getPOC();
+ lastSatd = lframe->costEst[curFrame->getPOC() - p0][p1 - curFrame->getPOC()] ; //TODO:need to get this from lookahead //x264_rc_analyse_slice( h );
rce->pCount = ncu;
shortTermCplxSum *= 0.5;
diff -r 96d870433517 -r 974bb4274d0c source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h Fri Aug 16 00:00:57 2013 -0500
+++ b/source/encoder/ratecontrol.h Fri Aug 16 12:19:27 2013 +0530
@@ -92,8 +92,7 @@
int64_t totalBits; /* totalbits used for already encoded frames */
RateControl(x265_param_t * param); // constructor for initializing values for ratecontrol vars
- void rateControlInit(TComSlice* frame); // to be called for each frame to set the required parameters for rateControl.
- void rateControlStart(LookaheadFrame* lframe); // to be called for each frame to process RateCOntrol and set QP
+ void rateControlStart(TComPic*& pic); // to be called for each frame to process RateCOntrol and set QP
int rateControlEnd(int64_t bits);
double rateEstimateQscale(LookaheadFrame* lframe); // main logic for calculating QP based on ABR
void accumPQpUpdate();
More information about the x265-devel
mailing list