[x265] [PATCH] Lookahead Implementation

gopu at multicorewareinc.com gopu at multicorewareinc.com
Fri Aug 2 09:07:29 CEST 2013


# HG changeset patch
# User ggopu
# Date 1375427219 -19800
# Node ID 0db8f9d2ca299fb992e9d27aaf5d0b32c14a089a
# Parent  30c7ae31afd58dbe921fa4a34ce033783e73b6f0
Lookahead Implementation

diff -r 30c7ae31afd5 -r 0db8f9d2ca29 source/Lib/TLibCommon/TComPic.cpp
--- a/source/Lib/TLibCommon/TComPic.cpp	Fri Aug 02 11:40:43 2013 +0530
+++ b/source/Lib/TLibCommon/TComPic.cpp	Fri Aug 02 12:36:59 2013 +0530
@@ -73,6 +73,17 @@
 
     /* store display window parameters with picture */
     m_defaultDisplayWindow = defaultDisplayWindow;
+
+    /* generates the lowres */
+    m_lookahead.width = m_origPicYuv->getWidth() / 2;
+    m_lookahead.lines = m_origPicYuv->getHeight() / 2;
+    m_lookahead.stride = m_lookahead.width + 2 * m_origPicYuv->getLumaMarginX();
+
+    /* allocate the buffer for lowres */
+    for (int i = 0; i < 4; i++)
+    {
+        m_lookahead.buffer[i] = (Pel*)X265_MALLOC(Pel,  m_lookahead.stride * (m_lookahead.lines + 2 * m_origPicYuv->getLumaMarginY()));
+    }
 }
 
 Void TComPic::destroy()
@@ -97,6 +108,12 @@
         delete m_reconPicYuv;
         m_reconPicYuv = NULL;
     }
+
+    for (int i = 0; i < 4; i++)
+    {
+         if(m_lookahead.buffer[i])
+           X265_FREE(m_lookahead.buffer[i]);
+    }
 }
 
 Void TComPic::compressMotion()
diff -r 30c7ae31afd5 -r 0db8f9d2ca29 source/Lib/TLibCommon/TComPic.h
--- a/source/Lib/TLibCommon/TComPic.h	Fri Aug 02 11:40:43 2013 +0530
+++ b/source/Lib/TLibCommon/TComPic.h	Fri Aug 02 12:36:59 2013 +0530
@@ -42,6 +42,7 @@
 #include "CommonDef.h"
 #include "TComPicSym.h"
 #include "TComPicYuv.h"
+#include "lookahead.h"
 
 //! \ingroup TLibCommon
 //! \{
@@ -68,6 +69,7 @@
 
 public:
 
+    x265::LookaheadFrame       m_lookahead;
     TComPic();
     virtual ~TComPic();
 
diff -r 30c7ae31afd5 -r 0db8f9d2ca29 source/Lib/TLibCommon/TComPicYuv.h
--- a/source/Lib/TLibCommon/TComPicYuv.h	Fri Aug 02 11:40:43 2013 +0530
+++ b/source/Lib/TLibCommon/TComPicYuv.h	Fri Aug 02 12:36:59 2013 +0530
@@ -97,15 +97,12 @@
 
     Bool  m_bIsBorderExtended;
 
-protected:
-
-    Void xExtendPicCompBorder(Pel* recon, Int stride, Int width, Int height, Int marginX, Int marginY);
-
 public:
 
     TComPicYuv();
     virtual ~TComPicYuv();
 
+    Void xExtendPicCompBorder(Pel* recon, Int stride, Int width, Int height, Int marginX, Int marginY);
     // ------------------------------------------------------------------------------------------------
     //  Memory management
     // ------------------------------------------------------------------------------------------------
@@ -130,7 +127,9 @@
 
     Int   getCStride()    { return m_strideC; }
 
-    Int   getLumaMargin() { return m_lumaMarginX; }
+    Int   getLumaMarginX() { return m_lumaMarginX; }
+
+    Int   getLumaMarginY() { return m_lumaMarginY; }
 
     Int   getChromaMargin() { return m_chromaMarginX; }
 
diff -r 30c7ae31afd5 -r 0db8f9d2ca29 source/Lib/TLibEncoder/TEncTop.cpp
--- a/source/Lib/TLibEncoder/TEncTop.cpp	Fri Aug 02 11:40:43 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncTop.cpp	Fri Aug 02 12:36:59 2013 +0530
@@ -162,6 +162,32 @@
             pic->getPicYuvOrg()->copyFromPicture(*picture);
             pic->getPicYuvRec()->clearExtendedFlag();
             pic->getSlice()->setReferenced(true);
+
+            /* Until Lookahead implementation complete */
+            if (!true)
+            {
+                x265::LookaheadFrame &lookahead = pic->m_lookahead;
+                lookahead.mref = new x265::ReferencePlanes();
+                int padoffset = (lookahead.lines + pic->getPicYuvOrg()->getLumaMarginX()) + ( lookahead.width + pic->getPicYuvOrg()->getLumaMarginX());
+                lookahead.m_lumaPlane[0][0] = lookahead.buffer[0] + padoffset;
+                lookahead.m_lumaPlane[2][0] = lookahead.buffer[1] + padoffset;
+                lookahead.m_lumaPlane[0][2] = lookahead.buffer[2] + padoffset;
+                lookahead.m_lumaPlane[2][2] = lookahead.buffer[3] + padoffset;
+                x265::primitives.frame_init_lowres_core(pic->getPicYuvOrg()->getLumaAddr(),
+                                                        lookahead.m_lumaPlane[0][0],
+                                                        lookahead.m_lumaPlane[2][0],
+                                                        lookahead.m_lumaPlane[0][2],
+                                                        lookahead.m_lumaPlane[2][2],
+                                                        pic->getPicYuvOrg()->getStride(),
+                                                        lookahead.stride,
+                                                        lookahead.width,
+                                                        lookahead.lines);
+
+                pic->getPicYuvOrg()->xExtendPicCompBorder(lookahead.m_lumaPlane[0][0], lookahead.stride, lookahead.width, lookahead.lines, pic->getPicYuvOrg()->getLumaMarginX(), pic->getPicYuvOrg()->getLumaMarginY());
+                pic->getPicYuvOrg()->xExtendPicCompBorder(lookahead.m_lumaPlane[2][0], lookahead.stride, lookahead.width, lookahead.lines, pic->getPicYuvOrg()->getLumaMarginX(), pic->getPicYuvOrg()->getLumaMarginY());
+                pic->getPicYuvOrg()->xExtendPicCompBorder(lookahead.m_lumaPlane[0][2], lookahead.stride, lookahead.width, lookahead.lines, pic->getPicYuvOrg()->getLumaMarginX(), pic->getPicYuvOrg()->getLumaMarginY());
+                pic->getPicYuvOrg()->xExtendPicCompBorder(lookahead.m_lumaPlane[2][2], lookahead.stride, lookahead.width, lookahead.lines, pic->getPicYuvOrg()->getLumaMarginX(), pic->getPicYuvOrg()->getLumaMarginY());
+            }
             return;
         }
     }
diff -r 30c7ae31afd5 -r 0db8f9d2ca29 source/common/CMakeLists.txt
--- a/source/common/CMakeLists.txt	Fri Aug 02 11:40:43 2013 +0530
+++ b/source/common/CMakeLists.txt	Fri Aug 02 12:36:59 2013 +0530
@@ -45,7 +45,7 @@
     md5.cpp md5.h
     TShortYUV.cpp TShortYUV.h mv.h
     reference.cpp reference.h
-    common.cpp common.h)
+    common.cpp common.h lookahead.h)
     
 if(ENABLE_PRIMITIVES_VEC)
     add_subdirectory(vec)
diff -r 30c7ae31afd5 -r 0db8f9d2ca29 source/common/common.h
--- a/source/common/common.h	Fri Aug 02 11:40:43 2013 +0530
+++ b/source/common/common.h	Fri Aug 02 12:36:59 2013 +0530
@@ -94,6 +94,7 @@
 #define X265_MAX3(a, b, c) X265_MAX((a), X265_MAX((b), (c)))
 #define X265_MIN4(a, b, c, d) X265_MIN((a), X265_MIN3((b), (c), (d)))
 #define X265_MAX4(a, b, c, d) X265_MAX((a), X265_MAX3((b), (c), (d)))
+#define X265_BFRAME_MAX  16
 
 #define ENABLE_CYCLE_COUNTERS 0
 #if ENABLE_CYCLE_COUNTERS
diff -r 30c7ae31afd5 -r 0db8f9d2ca29 source/common/lookahead.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/common/lookahead.h	Fri Aug 02 12:36:59 2013 +0530
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ * Copyright (C) 2013 x265 project
+ *
+ * Authors: Gopu Govindaswamy <gopu at multicorewareinc.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing at multicorewareinc.com.
+ *****************************************************************************/
+
+#include "x265.h"
+#include "common.h"
+
+namespace x265 {
+class ReferencePlanes;
+
+typedef struct : ReferencePlanes
+{
+    pixel *buffer[4];
+    int     stride;
+    int     width;
+    int     lines;
+    ReferencePlanes *mref;    
+
+}LookaheadFrame;
+
+typedef struct
+{
+    int     costEst[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2];
+    int     costEstaq[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2];
+    int     *rowSatds[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2];
+    int     intraMbs[X265_BFRAME_MAX + 2];
+    uint16_t(*lowresCosts[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2]);
+    int     *lowresmvCosts[2][X265_BFRAME_MAX + 1];
+    MV (*lowresMvs[2][X265_BFRAME_MAX + 1])[2];
+    LookaheadFrame *frames;
+
+}Lookahead;
+
+}


More information about the x265-devel mailing list