[x265] [PATCH 3 of 4] rc: generate cutree offsets for 2nd pass from stats
aarthi at multicorewareinc.com
aarthi at multicorewareinc.com
Mon Jul 21 09:32:48 CEST 2014
# HG changeset patch
# User Aarthi Thirumalai<aarthi at multicorewareinc.com>
# Date 1405661493 -19800
# Fri Jul 18 11:01:33 2014 +0530
# Node ID cc4d25a063853f2a79fffa2757f3d606011ee0c9
# Parent 382e20845179925356c178c0ff738410f2d0648e
rc: generate cutree offsets for 2nd pass from stats
diff -r 382e20845179 -r cc4d25a06385 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Fri Jul 18 17:22:24 2014 +0530
+++ b/source/encoder/encoder.cpp Fri Jul 18 11:01:33 2014 +0530
@@ -309,7 +309,18 @@
ATOMIC_INC(&pic->m_countRefEncoders);
bool bEnableWP = m_param->bEnableWeightedPred || m_param->bEnableWeightedBiPred;
if (m_param->rc.aqMode || bEnableWP)
- m_rateControl->calcAdaptiveQuantFrame(pic);
+ {
+ if (m_param->rc.cuTree && m_param->rc.bStatRead)
+ {
+ if (!m_rateControl->cuTreeReadFor2Pass(pic))
+ {
+ m_aborted = 1;
+ return -1;
+ }
+ }
+ else
+ m_rateControl->calcAdaptiveQuantFrame(pic);
+ }
m_lookahead->addPicture(pic, pic_in->sliceType);
m_numDelayedPic++;
}
diff -r 382e20845179 -r cc4d25a06385 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Fri Jul 18 17:22:24 2014 +0530
+++ b/source/encoder/ratecontrol.cpp Fri Jul 18 11:01:33 2014 +0530
@@ -1272,6 +1272,47 @@
return adjusted;
}
+bool RateControl::cuTreeReadFor2Pass(Frame* frame)
+{
+ uint8_t sliceTypeActual = m_rce2Pass[frame->m_POC].sliceType;
+
+ if (m_rce2Pass[frame->m_POC].keptAsRef)
+ {
+ uint8_t type;
+ if (m_cuTreeStats.qpBufPos < 0)
+ {
+ do
+ {
+ m_cuTreeStats.qpBufPos++;
+
+ if (!fread(&type, 1, 1, m_cutreeStatFileIn))
+ goto fail;
+ if (fread(m_cuTreeStats.qpBuffer[m_cuTreeStats.qpBufPos], sizeof(uint16_t), m_ncu, m_cutreeStatFileIn) != m_ncu)
+ goto fail;
+
+ if (type != sliceTypeActual && m_cuTreeStats.qpBufPos == 1)
+ {
+ x265_log(m_param, X265_LOG_ERROR, "CU-tree frametype %d doesn't match actual frametype %d.\n", type, sliceTypeActual);
+ return false;
+ }
+ } while(type != sliceTypeActual);
+ }
+ for (int i = 0; i < m_ncu; i++)
+ {
+ int16_t qpFix8 = m_cuTreeStats.qpBuffer[m_cuTreeStats.qpBufPos][i];
+ frame->m_lowres.qpCuTreeOffset[i] = (double)(qpFix8) / 256.0;
+ frame->m_lowres.invQscaleFactor[i] = x265_exp2fix8(frame->m_lowres.qpCuTreeOffset[i]);
+ }
+ m_cuTreeStats.qpBufPos--;
+ }
+ else
+ calcAdaptiveQuantFrame(frame);
+ return true;
+fail:
+ x265_log(m_param, X265_LOG_ERROR, "Incomplete CU-tree stats file.\n");
+ return false;
+}
+
double RateControl::rateEstimateQscale(Frame* pic, RateControlEntry *rce)
{
double q;
diff -r 382e20845179 -r cc4d25a06385 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h Fri Jul 18 17:22:24 2014 +0530
+++ b/source/encoder/ratecontrol.h Fri Jul 18 11:01:33 2014 +0530
@@ -206,6 +206,7 @@
bool init(const SPS* sps);
void initHRD(SPS* sps);
int rateControlSliceType(int frameNum);
+ bool cuTreeReadFor2Pass(Frame* frame);
protected:
static const double s_amortizeFraction;
More information about the x265-devel
mailing list