[x265] [PATCH] simplify math in intra refresh calculation (fixes #208)

santhoshini at multicorewareinc.com santhoshini at multicorewareinc.com
Thu Nov 5 07:46:47 CET 2015


# HG changeset patch
# User Santhoshini Sekar<santhoshini at multicorewareinc.com>
# Date 1446705159 -19800
#      Thu Nov 05 12:02:39 2015 +0530
# Node ID b2bcb012d101d8941911dbf51235ba6d581bbb71
# Parent  3103afbd31fa9b26533f06202516a511ee221439
simplify math in intra refresh calculation (fixes #208)

diff -r 3103afbd31fa -r b2bcb012d101 source/common/framedata.h
--- a/source/common/framedata.h	Thu Nov 05 06:13:51 2015 +0530
+++ b/source/common/framedata.h	Thu Nov 05 12:02:39 2015 +0530
@@ -137,7 +137,6 @@
     /* data needed for periodic intra refresh */
     struct PeriodicIR
     {
-        double     position;
         uint32_t   pirStartCol;
         uint32_t   pirEndCol;
         int        framesSinceLastPir;
diff -r 3103afbd31fa -r b2bcb012d101 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Thu Nov 05 06:13:51 2015 +0530
+++ b/source/encoder/encoder.cpp	Thu Nov 05 12:02:39 2015 +0530
@@ -448,30 +448,29 @@
         m_bQueuedIntraRefresh = 0;
         /* PIR is currently only supported with ref == 1, so any intra frame effectively refreshes
          * the whole frame and counts as an intra refresh. */
-        pir->position = numBlocksInRow;
+        pir->pirEndCol = numBlocksInRow;
     }
     else if (slice->m_sliceType == P_SLICE)
     {
         Frame* ref = frameEnc->m_encData->m_slice->m_refFrameList[0][0];
         int pocdiff = frameEnc->m_poc - ref->m_poc;
-        float increment = X265_MAX(((float)numBlocksInRow - 1) / m_param->keyframeMax, 1);
-        pir->position = ref->m_encData->m_pir.position;
+        int numPFramesInGOP = m_param->keyframeMax / pocdiff;
+        int increment = (numBlocksInRow + numPFramesInGOP - 1) / numPFramesInGOP;
+        pir->pirEndCol = ref->m_encData->m_pir.pirEndCol;
         pir->framesSinceLastPir = ref->m_encData->m_pir.framesSinceLastPir + pocdiff;
         if (pir->framesSinceLastPir >= m_param->keyframeMax ||
-           (m_bQueuedIntraRefresh && pir->position + 0.5 >= numBlocksInRow))
+            (m_bQueuedIntraRefresh && pir->pirEndCol >= numBlocksInRow))
         {
-            pir->position = 0;
+            pir->pirEndCol = 0;
             pir->framesSinceLastPir = 0;
             m_bQueuedIntraRefresh = 0;
             frameEnc->m_lowres.bKeyframe = 1;
         }
-        pir->pirStartCol = (uint32_t)(pir->position + 0.5);
-        pir->position += increment * pocdiff;
-        pir->pirEndCol = (uint32_t)(pir->position + 0.5);
+        pir->pirStartCol = pir->pirEndCol;
+        pir->pirEndCol += increment;
         /* If our intra refresh has reached the right side of the frame, we're done. */
         if (pir->pirEndCol >= numBlocksInRow)
         {
-            pir->position = numBlocksInRow;
             pir->pirEndCol = numBlocksInRow;
         }
     }


More information about the x265-devel mailing list