[x265] [PATCH] rc: Add multi-pass data to x265_rc_stats

Divya Manivannan divya at multicorewareinc.com
Tue Jun 14 13:53:31 CEST 2016


# HG changeset patch
# User Divya Manivannan <divya at multicorewareinc.com>
# Date 1465554208 -19800
#      Fri Jun 10 15:53:28 2016 +0530
# Node ID 1b8f242b521d9ad2bfd5228ea928604bc1809f3d
# Parent  106a5a7dc4b337121c11484bc3bc4900b8a0d9a4
rc: Add multi-pass data to x265_rc_stats
x265_rc_stats is changed into void pointer to avoid the build number change
whenever new fields are added to it in future.

diff -r 106a5a7dc4b3 -r 1b8f242b521d source/CMakeLists.txt
--- a/source/CMakeLists.txt	Thu Jun 09 13:34:55 2016 -0500
+++ b/source/CMakeLists.txt	Fri Jun 10 15:53:28 2016 +0530
@@ -30,7 +30,7 @@
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 85)
+set(X265_BUILD 86)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 106a5a7dc4b3 -r 1b8f242b521d source/common/frame.cpp
--- a/source/common/frame.cpp	Thu Jun 09 13:34:55 2016 -0500
+++ b/source/common/frame.cpp	Fri Jun 10 15:53:28 2016 +0530
@@ -42,12 +42,14 @@
     m_prev = NULL;
     m_param = NULL;
     memset(&m_lowres, 0, sizeof(m_lowres));
+    m_rcData = NULL;
 }
 
 bool Frame::create(x265_param *param, float* quantOffsets)
 {
     m_fencPic = new PicYuv;
     m_param = param;
+    CHECKED_MALLOC_ZERO(m_rcData, RcStats, 1);
 
     if (m_fencPic->create(param->sourceWidth, param->sourceHeight, param->internalCsp) &&
         m_lowres.create(m_fencPic, param->bframes, !!param->rc.aqMode))
@@ -64,6 +66,8 @@
         return true;
     }
     return false;
+fail:
+    return false;
 }
 
 bool Frame::allocEncodeData(x265_param *param, const SPS& sps)
@@ -140,4 +144,5 @@
     }
 
     m_lowres.destroy();
+    X265_FREE(m_rcData);
 }
diff -r 106a5a7dc4b3 -r 1b8f242b521d source/common/frame.h
--- a/source/common/frame.h	Thu Jun 09 13:34:55 2016 -0500
+++ b/source/common/frame.h	Fri Jun 10 15:53:28 2016 +0530
@@ -37,6 +37,27 @@
 
 #define IS_REFERENCED(frame) (frame->m_lowres.sliceType != X265_TYPE_B)
 
+/* Ratecontrol statistics */
+struct RcStats
+{
+    double   qpaRc;
+    double   qpAq;
+    double   qRceq;
+    double   qpNoVbv;
+    double   newQScale;
+    double   iCuCount;
+    double   pCuCount;
+    double   skipCuCount;
+    double   qScale;
+    int      mvBits;
+    int      miscBits;
+    int      coeffBits;
+    int      poc;
+    int      encodeOrder;
+    int      sliceType;
+    int      keptAsRef;
+};
+
 class Frame
 {
 public:
@@ -72,6 +93,7 @@
     Frame*                 m_prev;
     x265_param*            m_param;              // Points to the latest param set for the frame.
     x265_analysis_data     m_analysisData;
+    RcStats*               m_rcData;
     Frame();
 
     bool create(x265_param *param, float* quantOffsets);
diff -r 106a5a7dc4b3 -r 1b8f242b521d source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Thu Jun 09 13:34:55 2016 -0500
+++ b/source/encoder/encoder.cpp	Fri Jun 10 15:53:28 2016 +0530
@@ -779,17 +779,23 @@
 
             if (pic_out && m_param->rc.bStatWrite)
             {
-                pic_out->rcData.qpaRc = outFrame->m_encData->m_avgQpRc;
-                pic_out->rcData.qRceq = curEncoder->m_rce.qRceq;
-                pic_out->rcData.qpNoVbv = curEncoder->m_rce.qpNoVbv;
-                pic_out->rcData.coeffBits = outFrame->m_encData->m_frameStats.coeffBits;
-                pic_out->rcData.miscBits = outFrame->m_encData->m_frameStats.miscBits;
-                pic_out->rcData.mvBits = outFrame->m_encData->m_frameStats.mvBits;
-                pic_out->rcData.newQScale = x265_qp2qScale(outFrame->m_encData->m_avgQpRc);
-                pic_out->rcData.poc = curEncoder->m_rce.poc;
-                pic_out->rcData.encodeOrder = curEncoder->m_rce.encodeOrder;
-                pic_out->rcData.sliceType = curEncoder->m_rce.sliceType;
-                pic_out->rcData.keptAsRef = curEncoder->m_rce.sliceType == B_SLICE && !IS_REFERENCED(outFrame) ? 0 : 1;
+                /* m_rcData is allocated for every frame */
+                pic_out->rcData = outFrame->m_rcData;
+                outFrame->m_rcData->qpaRc = outFrame->m_encData->m_avgQpRc;
+                outFrame->m_rcData->qRceq = curEncoder->m_rce.qRceq;
+                outFrame->m_rcData->qpNoVbv = curEncoder->m_rce.qpNoVbv;
+                outFrame->m_rcData->coeffBits = outFrame->m_encData->m_frameStats.coeffBits;
+                outFrame->m_rcData->miscBits = outFrame->m_encData->m_frameStats.miscBits;
+                outFrame->m_rcData->mvBits = outFrame->m_encData->m_frameStats.mvBits;
+                outFrame->m_rcData->qScale = outFrame->m_rcData->newQScale = x265_qp2qScale(outFrame->m_encData->m_avgQpRc);
+                outFrame->m_rcData->poc = curEncoder->m_rce.poc;
+                outFrame->m_rcData->encodeOrder = curEncoder->m_rce.encodeOrder;
+                outFrame->m_rcData->sliceType = curEncoder->m_rce.sliceType;
+                outFrame->m_rcData->keptAsRef = curEncoder->m_rce.sliceType == B_SLICE && !IS_REFERENCED(outFrame) ? 0 : 1;
+                outFrame->m_rcData->qpAq = outFrame->m_encData->m_avgQpAq;
+                outFrame->m_rcData->iCuCount = outFrame->m_encData->m_frameStats.percent8x8Intra * m_rateControl->m_ncu;
+                outFrame->m_rcData->pCuCount = outFrame->m_encData->m_frameStats.percent8x8Inter * m_rateControl->m_ncu;
+                outFrame->m_rcData->skipCuCount = outFrame->m_encData->m_frameStats.percent8x8Skip  * m_rateControl->m_ncu;
             }
 
             /* Allow this frame to be recycled if no frame encoders are using it for reference */
diff -r 106a5a7dc4b3 -r 1b8f242b521d source/x265.h
--- a/source/x265.h	Thu Jun 09 13:34:55 2016 -0500
+++ b/source/x265.h	Fri Jun 10 15:53:28 2016 +0530
@@ -150,22 +150,6 @@
     x265_cu_stats    cuStats;
 } x265_frame_stats;
 
-/* Ratecontrol statistics */
-typedef struct x265_rc_stats
-{
-    double  qpaRc;
-    double  qRceq;
-    double  qpNoVbv;
-    double  newQScale;
-    int     mvBits;
-    int     miscBits;
-    int     coeffBits;
-    int     poc;
-    int     encodeOrder;
-    int     sliceType;
-    int     keptAsRef;
-} x265_rc_stats;
-
 /* Used to pass pictures into the encoder, and to get picture data back out of
  * the encoder.  The input and output semantics are different */
 typedef struct x265_picture
@@ -240,7 +224,7 @@
     /* Ratecontrol statistics for collecting the ratecontrol information.
      * It is not used for collecting the last pass ratecontrol data in 
      * multi pass ratecontrol mode. */
-    x265_rc_stats rcData;
+    void*  rcData;
 
     uint64_t framesize;
 


More information about the x265-devel mailing list