[x265] [PATCH 5 of 5] slicetype: Handle Bframes immediately preceding an IDR correctly

deepthidevaki at multicorewareinc.com deepthidevaki at multicorewareinc.com
Fri Sep 6 15:17:37 CEST 2013


# HG changeset patch
# User Deepthi Devaki <deepthidevaki at multicorewareinc.com>
# Date 1378473317 -19800
# Node ID 89aa4b8cb90afae566ee9efa8b2e629b5b77c629
# Parent  ca65bd3590ccd05f4c87adee53b9b866279470b6
slicetype: Handle Bframes immediately preceding an IDR correctly.

diff -r ca65bd3590cc -r 89aa4b8cb90a source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Fri Sep 06 17:11:56 2013 +0530
+++ b/source/encoder/slicetype.cpp	Fri Sep 06 18:45:17 2013 +0530
@@ -118,18 +118,29 @@
     int idx = 1;
 
     for (dframes = 0; (frames[dframes + 1] != NULL) && (frames[dframes + 1]->sliceType != X265_TYPE_AUTO); dframes++)
-    {}
+    {
+        if ((frames[dframes + 1]->sliceType == X265_TYPE_I))
+        {
+            frames[dframes + 1]->keyframe = 1;
+            lastKeyframe = frames[dframes]->frameNum;
+            if (cfg->param.decodingRefreshType == 2 && dframes > 0) //If an IDR frame following a B
+            {
+                frames[dframes]->sliceType = X265_TYPE_P;
+                dframes--;
+            }
+        }
+        if (!IS_X265_TYPE_B(frames[dframes + 1]->sliceType))
+        {
+            dframes++;
+            break;
+        }
+    }
 
     TComPic *pic = NULL;
     for (int i = 1; i <= dframes && !inputQueue.empty(); i++)
     {
         pic = inputQueue.popFront();
         picsAnalysed[idx++] = pic;
-        if ((pic->m_lowres.sliceType == X265_TYPE_I))
-        {
-            pic->m_lowres.keyframe = 1;
-            lastKeyframe = pic->getPOC();
-        }
     }
 
     picsAnalysed[0] = pic;  //Move the P-frame following B-frames to the beginning
@@ -459,10 +470,16 @@
     int vbv_lookahead = 0;
 
     TComList<TComPic*>::iterator iterPic = inputQueue.begin();
-    for (framecnt = 0; (framecnt < maxSearch) && (framecnt < (int)inputQueue.size()); framecnt++)
+    for (framecnt = 0; (framecnt < maxSearch) && (framecnt < (int)inputQueue.size()) && (*iterPic)->m_lowres.sliceType == X265_TYPE_AUTO; framecnt++)
     {
         frames[framecnt + 1] = &((*iterPic++)->m_lowres);
-        frames[framecnt + 1]->sliceType = X265_TYPE_AUTO;
+    }
+
+    if (!framecnt)
+    {
+        frames[1] = &((*iterPic)->m_lowres);
+        frames[2] = NULL;
+        return;
     }
 
     frames[framecnt + 1] = NULL;


More information about the x265-devel mailing list