shithub: openh264

Download patch

ref: a60af6a750ba1492b7b68352b23c1a75ad9ce257
parent: c1817891b520803fca6b998e2baa28bc69405652
author: sijchen <sijchen@cisco.com>
date: Fri Mar 28 05:09:21 EDT 2014

add function pointer

--- a/codec/encoder/core/inc/svc_motion_estimate.h
+++ b/codec/encoder/core/inc/svc_motion_estimate.h
@@ -84,7 +84,9 @@
 
 #define  COST_MVD(table, mx, my)  (table[mx] + table[my])
 
+// Function definitions below
 
+void WelsInitMeFunc( SWelsFuncPtrList* pFuncList, uint32_t uiCpuFlag, bool bScreenContent );
 
 /*!
  * \brief	BL mb motion estimate search
--- a/codec/encoder/core/inc/wels_func_ptr_def.h
+++ b/codec/encoder/core/inc/wels_func_ptr_def.h
@@ -134,11 +134,16 @@
     uint8_t*, uint8_t*);
 
 typedef void (*PMotionSearchFunc) (SWelsFuncPtrList* pFuncList, void* pCurDqLayer, void* pMe,
-                                   void* pSlice);  // here after reset all function pointers, will set as right parameter type
+                                   void* pSlice);
 typedef void (*PCalculateSatdFunc) ( PSampleSadSatdCostFunc pSatd, void * vpMe, const int32_t kiEncStride, const int32_t kiRefStride );
 typedef bool (*PCheckDirectionalMv) (PSampleSadSatdCostFunc pSad, void * vpMe,
                       const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
                       int32_t& iBestSadCost);
+typedef void (*PLineFullSearchFunc) (	void *pFunc, void *vpMe,
+													uint16_t* pMvdTable, const int32_t kiFixedMvd,
+													const int32_t kiEncStride, const int32_t kiRefStride,
+													const int32_t kiMinPos, const int32_t kiMaxPos,
+                          const bool bVerticalSearch );
 
 #define     MAX_BLOCK_TYPE 5 // prev 7
 typedef struct TagSampleDealingFunc {
@@ -192,6 +197,7 @@
   pfMotionSearch; //svc_encode_slice.c svc_mode_decision.c svc_enhance_layer_md.c svc_base_layer_md.c
   PCalculateSatdFunc pfCalculateSatd;
   PCheckDirectionalMv pfCheckDirectionalMv;
+  PLineFullSearchFunc pfLineFullSearch;
 
   PCopyFunc      pfCopy16x16Aligned;		//svc_encode_slice.c svc_mode_decision.c svc_base_layer_md.c
   PCopyFunc      pfCopy16x16NotAligned;	//md.c
--- a/codec/encoder/core/src/encoder.cpp
+++ b/codec/encoder/core/src/encoder.cpp
@@ -185,6 +185,9 @@
   WelsInitFillingPredFuncs (uiCpuFlag);
   WelsInitIntraPredFuncs (pFuncList, uiCpuFlag);
 
+  /* ME func */
+  WelsInitMeFunc(pFuncList, uiCpuFlag, SCREEN_CONTENT_REAL_TIME==pParam->iUsageType);
+
   /* sad, satd, average */
   WelsInitSampleSadFunc (pFuncList, uiCpuFlag);
 
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -2515,7 +2515,6 @@
     pFuncList->pfMotionSearch  = WelsMotionEstimateSearch;
     pFuncList->pfFirstIntraMode = WelsMdFirstIntraMode;
     pFuncList->sSampleDealingFuncs.pfMeCost = pCtx->pFuncList->sSampleDealingFuncs.pfSampleSatd;
-    pFuncList->pfCheckDirectionalMv = CheckDirectionalMvFalse;
     if (kbHighestSpatialLayer) {
       pFuncList->pfCalculateSatd = NotCalculateSatdCost;
       pFuncList->pfInterFineMd = WelsMdInterFinePartitionVaa;
--- a/codec/encoder/core/src/svc_motion_estimate.cpp
+++ b/codec/encoder/core/src/svc_motion_estimate.cpp
@@ -38,7 +38,7 @@
  *************************************************************************************
  */
 
-
+#include "cpu_core.h"
 #include "sample.h"
 #include "svc_motion_estimate.h"
 
@@ -58,7 +58,20 @@
     pMe->uiSatdCost = pMe->uiSadCost;
 }
 
+void WelsInitMeFunc( SWelsFuncPtrList* pFuncList, uint32_t uiCpuFlag, bool bScreenContent ) {
+  if (!bScreenContent) {
+    pFuncList->pfCheckDirectionalMv = CheckDirectionalMvFalse;
+  } else {
+    pFuncList->pfCheckDirectionalMv = CheckDirectionalMv;
 
+    //for cross serarch
+    pFuncList->pfLineFullSearch = LineFullSearch_c;
+    pFuncList->pfLineFullSearch = LineFullSearch_c;
+    if ( uiCpuFlag & WELS_CPU_SSE41 ) {
+    }
+  }
+}
+
 /*!
  * \brief	BL mb motion estimate search
  *
@@ -234,22 +247,21 @@
   pMe->pRefMb = pRefMb;
 }
 
-void CalculateSatdCost( PSampleSadSatdCostFunc pSatd, void * vpMe, const int32_t kiEncStride, const int32_t kiRefStride )
-{
+void CalculateSatdCost( PSampleSadSatdCostFunc pSatd, void * vpMe,
+                       const int32_t kiEncStride, const int32_t kiRefStride ) {
   SWelsME* pMe						 = static_cast<SWelsME *>(vpMe);
   pMe->uSadPredISatd.uiSatd = pSatd(pMe->pEncMb, kiEncStride, pMe->pRefMb, kiRefStride);
   pMe->uiSatdCost = pMe->uSadPredISatd.uiSatd + COST_MVD (pMe->pMvdCost, pMe->sMv.iMvX - pMe->sMvp.iMvX,
                                                             pMe->sMv.iMvY - pMe->sMvp.iMvY);
 }
-void NotCalculateSatdCost( PSampleSadSatdCostFunc pSatd, void * vpMe, const int32_t kiEncStride, const int32_t kiRefStride )
-{
+void NotCalculateSatdCost( PSampleSadSatdCostFunc pSatd, void * vpMe,
+                          const int32_t kiEncStride, const int32_t kiRefStride ) {
 }
 
 
 bool CheckDirectionalMv(PSampleSadSatdCostFunc pSad, void * vpMe,
                       const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
-                      int32_t& iBestSadCost)
-{
+                      int32_t& iBestSadCost) {
   SWelsME* pMe						 = static_cast<SWelsME *>(vpMe);
   const int16_t kiMvX = pMe->sDirectionalMv.iMvX;
   const int16_t kiMvY = pMe->sDirectionalMv.iMvY;
@@ -257,13 +269,11 @@
   //Check MV from scrolling detection
   if ( (BLOCK_16x16!=pMe->uiBlockSize) //scrolled_MV with P16x16 is checked SKIP checking function
     && ( kiMvX | kiMvY ) //(0,0) checked in ordinary initial point checking
-    && CheckMvInRange( pMe->sDirectionalMv, ksMinMv, ksMaxMv ) )
-  {
+    && CheckMvInRange( pMe->sDirectionalMv, ksMinMv, ksMaxMv ) ) {
     uint8_t* pRef = &pMe->pColoRefMb[kiMvY * kiRefStride + kiMvX];
     uint32_t uiCurrentSadCost = pSad( pMe->pEncMb, kiEncStride,  pRef, kiRefStride ) +
       COST_MVD(pMe->pMvdCost, (kiMvX<<2) - pMe->sMvp.iMvX, (kiMvY<<2) - pMe->sMvp.iMvY );
-    if( uiCurrentSadCost < pMe->uiSadCost )
-    {
+    if( uiCurrentSadCost < pMe->uiSadCost ) {
       iBestSadCost = uiCurrentSadCost;
       return true;
     }
@@ -273,8 +283,7 @@
 
 bool CheckDirectionalMvFalse(PSampleSadSatdCostFunc pSad, void * vpMe,
                       const SMVUnitXY ksMinMv, const SMVUnitXY ksMaxMv, const int32_t kiEncStride, const int32_t kiRefStride,
-                      int32_t& iBestSadCost)
-{
+                      int32_t& iBestSadCost) {
   return false;
 }
 
@@ -282,8 +291,7 @@
 														uint16_t* pMvdTable, const int32_t kiFixedMvd,
 														const int32_t kiEncStride, const int32_t kiRefStride,
 													const int32_t kiMinPos, const int32_t kiMaxPos,
-                          const bool bVerticalSearch )
-{
+                          const bool bVerticalSearch ) {
   SWelsFuncPtrList *pFuncList      = static_cast<SWelsFuncPtrList *>(pFunc);
   SWelsME *pMe				                    = static_cast<SWelsME *>(vpMe);
 }
@@ -291,8 +299,7 @@
 													uint16_t* pMvdTable, const int32_t kiFixedMvd,
 													const int32_t kiEncStride, const int32_t kiRefStride,
 													const int32_t kiMinPos, const int32_t kiMaxPos,
-                          const bool bVerticalSearch )
-{
+                          const bool bVerticalSearch ) {
   SWelsFuncPtrList *pFuncList      = static_cast<SWelsFuncPtrList *>(pFunc);
   SWelsME *pMe				                    = static_cast<SWelsME *>(vpMe);
   PSampleSadSatdCostFunc pSad = pFuncList->sSampleDealingFuncs.pfSampleSad[pMe->uiBlockSize];
@@ -323,11 +330,9 @@
 }
 
 void WelsMotionCrossSearch(SWelsFuncPtrList *pFuncList,  SDqLayer* pCurLayer, SWelsME * pMe,
-											const SSlice* pSlice)
-{
-  //TODO:
-  //PMOTION_VERFULL_SEARCH VerticalFullSearchFunc	= pFuncList->VerticalFullSearch_c;
-  //PMOTION_HORFULL_SEARCH HorizontalFullSearchFunc	= pFuncList->HorizontalFullSearch_c;
+											const SSlice* pSlice) {
+  PLineFullSearchFunc pfVerticalFullSearchFunc	= pFuncList->pfLineFullSearch;
+  PLineFullSearchFunc pfHorizontalFullSearchFunc	= pFuncList->pfLineFullSearch;
   const int32_t kiEncStride = pCurLayer->iEncStride[0];
   const int32_t kiRefStride = pCurLayer->pRefPic->iLineSize[0];
 
@@ -339,7 +344,7 @@
   uint16_t* pMvdCostY = pMe->pMvdCost - iCurMeBlockQpelPixY - pMe->sMvp.iMvY;//do the offset here instead of in the search
 
   //vertical search
-  LineFullSearch_c( pFuncList, pMe,
+  pfVerticalFullSearchFunc( pFuncList, pMe,
     pMvdCostY, pMvdCostX[ iCurMeBlockQpelPixX ],
     kiEncStride, kiRefStride,
     iCurMeBlockPixY + pSlice->sMvStartMin.iMvY,
@@ -347,7 +352,7 @@
 
   //horizontal search
   if (pMe->uiSadCost >= pMe->uiSadCostThreshold) {
-    LineFullSearch_c( pFuncList, pMe,
+    pfHorizontalFullSearchFunc( pFuncList, pMe,
       pMvdCostX, pMvdCostY[ iCurMeBlockQpelPixY ],
       kiEncStride, kiRefStride,
       iCurMeBlockPixX + pSlice->sMvStartMin.iMvX,