changeset 3903:d934cc573e08

Set all I frames as keyframes, change nalunittype decision accordingly.
author Deepthi Devaki <deepthidevaki@multicorewareinc.com>
date Fri, 06 Sep 2013 17:11:56 +0530
parents 66b3f3b38e84
children aaeeb869133d
files source/common/lowres.cpp source/common/lowres.h source/encoder/dpb.cpp source/encoder/dpb.h source/encoder/slicetype.cpp
diffstat 5 files changed, 15 insertions(+-), 7 deletions(-) [+]
line wrap: on
line diff
--- a/source/common/lowres.cpp	Fri Sep 06 15:45:35 2013 +0530
+++ b/source/common/lowres.cpp	Fri Sep 06 17:11:56 2013 +0530
@@ -113,6 +113,7 @@ void Lowres::init(TComPicYuv *orig)
     bIntraCalculated = false;
     memset(costEst, -1, sizeof(costEst));
     sliceType = X265_TYPE_AUTO;
+    keyframe = 0; //Not a keyframe unless identified by lookahead
     for (int y = 0; y < bframes + 2; y++)
     {
         for (int x = 0; x < bframes + 2; x++)
--- a/source/common/lowres.h	Fri Sep 06 15:45:35 2013 +0530
+++ b/source/common/lowres.h	Fri Sep 06 17:11:56 2013 +0530
@@ -63,6 +63,7 @@ struct Lowres : public ReferencePlanes
     int    scenecut;  // Set to zero if the frame cannot possibly be part of a real scenecut. 
 
     int    sliceType; // Slice type decided by lookahead
+    int    keyframe;
 
     /* lookahead output data */
     int       costEst[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2];
--- a/source/encoder/dpb.cpp	Fri Sep 06 15:45:35 2013 +0530
+++ b/source/encoder/dpb.cpp	Fri Sep 06 17:11:56 2013 +0530
@@ -71,8 +71,8 @@ void DPB::prepareEncode(TComPic *pic, Fr
     m_picList.pushFront(pic);
 
     TComSlice* slice = pic->getSlice();
-    if (getNalUnitType(pocCurr, m_lastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL ||
-        getNalUnitType(pocCurr, m_lastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP)
+    if (getNalUnitType(pocCurr, m_lastIDR, pic) == NAL_UNIT_CODED_SLICE_IDR_W_RADL ||
+        getNalUnitType(pocCurr, m_lastIDR, pic) == NAL_UNIT_CODED_SLICE_IDR_N_LP)
     {
         m_lastIDR = pocCurr;
     }
@@ -80,7 +80,7 @@ void DPB::prepareEncode(TComPic *pic, Fr
     slice->setReferenced(slice->getSliceType() != B_SLICE);
     slice->setTemporalLayerNonReferenceFlag(!slice->isReferenced());
     // Set the nal unit type
-    slice->setNalUnitType(getNalUnitType(pocCurr, m_lastIDR));
+    slice->setNalUnitType(getNalUnitType(pocCurr, m_lastIDR, pic));
 
     // If the slice is un-referenced, change from _R "referenced" to _N "non-referenced" NAL unit type
     if (slice->getTemporalLayerNonReferenceFlag())
@@ -368,13 +368,13 @@ void DPB::applyReferencePictureSet(TComR
  * \returns the nal unit type of the picture
  * This function checks the configuration and returns the appropriate nal_unit_type for the picture.
  */
-NalUnitType DPB::getNalUnitType(int curPOC, int lastIDR)
+NalUnitType DPB::getNalUnitType(int curPOC, int lastIDR, TComPic* pic)
 {
     if (curPOC == 0)
     {
         return NAL_UNIT_CODED_SLICE_IDR_W_RADL;
     }
-    if (curPOC % m_cfg->param.keyframeMax == 0)
+    if (pic->m_lowres.keyframe)
     {
         if (m_cfg->param.decodingRefreshType == 1)
         {
--- a/source/encoder/dpb.h	Fri Sep 06 15:45:35 2013 +0530
+++ b/source/encoder/dpb.h	Fri Sep 06 17:11:56 2013 +0530
@@ -71,7 +71,7 @@ protected:
 
     void arrangeLongtermPicturesInRPS(TComSlice *, FrameEncoder *frameEncoder);
 
-    NalUnitType getNalUnitType(int curPoc, int lastIdr);
+    NalUnitType getNalUnitType(int curPoc, int lastIdr, TComPic* pic);
 };
 }
 
--- a/source/encoder/slicetype.cpp	Fri Sep 06 15:45:35 2013 +0530
+++ b/source/encoder/slicetype.cpp	Fri Sep 06 17:11:56 2013 +0530
@@ -105,6 +105,7 @@ void Lookahead::slicetypeDecide()
         outputQueue.pushBack(pic);
         numDecided++;
         lastKeyframe = 0;
+        pic->m_lowres.keyframe = 1;
         frames[0] = &(pic->m_lowres);
         return;
     }
@@ -124,8 +125,9 @@ void Lookahead::slicetypeDecide()
     {
         pic = inputQueue.popFront();
         picsAnalysed[idx++] = pic;
-        if ((pic->m_lowres.sliceType == X265_TYPE_I) && !(pic->getPOC() % cfg->param.keyframeMax))
+        if ((pic->m_lowres.sliceType == X265_TYPE_I))
         {
+            pic->m_lowres.keyframe = 1;
             lastKeyframe = pic->getPOC();
         }
     }
@@ -148,6 +150,7 @@ void Lookahead::slicetypeDecide()
         TComPic *pic = inputQueue.popFront();
 
         pic->m_lowres.sliceType = X265_TYPE_I;
+        pic->m_lowres.keyframe = 1;
         outputQueue.pushBack(pic);
         numDecided++;
     }
@@ -157,6 +160,7 @@ void Lookahead::slicetypeDecide()
 
         bool forceIntra = (pic->getPOC() % cfg->param.keyframeMax) == 0;
         pic->m_lowres.sliceType = forceIntra ? X265_TYPE_I : X265_TYPE_P;
+        pic->m_lowres.keyframe = forceIntra ? 1 : 0;
         outputQueue.pushBack(pic);
         numDecided++;
     }
@@ -169,10 +173,12 @@ void Lookahead::slicetypeDecide()
         if (forceIntra)
         {
             picB->m_lowres.sliceType = (picB->getPOC() % cfg->param.keyframeMax) ? X265_TYPE_P : X265_TYPE_I;
+            picB->m_lowres.keyframe = (picB->getPOC() % cfg->param.keyframeMax) ? 0 : 1;
             outputQueue.pushBack(picB);
             numDecided++;
 
             picP->m_lowres.sliceType = (picP->getPOC() % cfg->param.keyframeMax) ? X265_TYPE_P : X265_TYPE_I;
+            picP->m_lowres.keyframe = (picP->getPOC() % cfg->param.keyframeMax) ? 0 : 1;
             outputQueue.pushBack(picP);
             numDecided++;
         }