[svn] / trunk / xvidcore / src / motion / estimation_pvop.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/src/motion/estimation_pvop.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1668, Sun Dec 18 06:52:12 2005 UTC revision 1691, Mon Feb 27 00:24:02 2006 UTC
# Line 21  Line 21 
21   *  along with this program ; if not, write to the Free Software   *  along with this program ; if not, write to the Free Software
22   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23   *   *
24   * $Id: estimation_pvop.c,v 1.18 2005-12-18 06:52:12 syskin Exp $   * $Id: estimation_pvop.c,v 1.21 2006-02-27 00:24:02 syskin Exp $
25   *   *
26   ****************************************************************************/   ****************************************************************************/
27    
# Line 39  Line 39 
39  #include "motion.h"  #include "motion.h"
40  #include "sad.h"  #include "sad.h"
41  #include "motion_inlines.h"  #include "motion_inlines.h"
42    #include "motion_smp.h"
43    
44    
45  static const int xvid_me_lambda_vec8[32] =  static const int xvid_me_lambda_vec8[32] =
46          {     0    ,(int)(1.0 * NEIGH_TEND_8X8 + 0.5),          {     0    ,(int)(1.0 * NEIGH_TEND_8X8 + 0.5),
# Line 981  Line 983 
983          current->sStat.iMvSum = mvSum;          current->sStat.iMvSum = mvSum;
984          current->sStat.iMvCount = mvCount;          current->sStat.iMvCount = mvCount;
985  }  }
986    
987    void
988    MotionEstimateSMP(SMPmotionData * h)
989    {
990            const MBParam * const pParam = h->pParam;
991            const FRAMEINFO * const current = h->current;
992            const FRAMEINFO * const reference = h->reference;
993            const IMAGE * const pRefH = h->pRefH;
994            const IMAGE * const pRefV = h->pRefV;
995            const IMAGE * const pRefHV = h->pRefHV;
996            const IMAGE * const pGMC = h->pGMC;
997            uint32_t MotionFlags = MakeGoodMotionFlags(current->motion_flags,
998                                                                                                    current->vop_flags,
999                                                                                                    current->vol_flags);
1000    
1001            MACROBLOCK *const pMBs = current->mbs;
1002            const IMAGE *const pCurrent = &current->image;
1003            const IMAGE *const pRef = &reference->image;
1004    
1005            const uint32_t mb_width = pParam->mb_width;
1006            const uint32_t mb_height = pParam->mb_height;
1007            const uint32_t iEdgedWidth = pParam->edged_width;
1008            int stat_thresh = 0;
1009            int MVmax = 0, mvSum = 0, mvCount = 0;
1010            int y_step = h->y_step;
1011            int start_y = h->start_y;
1012    
1013            uint32_t x, y;
1014            int sad00;
1015            int skip_thresh = INITIAL_SKIP_THRESH * \
1016                    (current->vop_flags & XVID_VOP_MODEDECISION_RD ? 2:1);
1017            int block = start_y*mb_width;
1018            int * complete_count_self = h->complete_count_self;
1019            const volatile int * complete_count_above = h->complete_count_above;
1020            int max_mbs;
1021            int current_mb = 0;
1022    
1023            /* some pre-initialized thingies for SearchP */
1024            DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE);
1025            SearchData Data;
1026            memset(&Data, 0, sizeof(SearchData));
1027            Data.iEdgedWidth = iEdgedWidth;
1028            Data.iFcode = current->fcode;
1029            Data.rounding = pParam->m_rounding_type;
1030            Data.qpel = (current->vol_flags & XVID_VOL_QUARTERPEL ? 1:0);
1031            Data.chroma = MotionFlags & XVID_ME_CHROMA_PVOP;
1032            Data.dctSpace = dct_space;
1033            Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT);
1034            Data.mpeg_quant_matrices = pParam->mpeg_quant_matrices;
1035    
1036            /* todo: sort out temp memory space */
1037            Data.RefQ = h->RefQ;
1038            if (sadInit) (*sadInit) ();
1039    
1040            max_mbs = 0;
1041    
1042            for (y = start_y; y < mb_height; y += y_step)   {
1043                    if (y == 0) max_mbs = mb_width; /* we can process all blocks of the first row */
1044    
1045                    for (x = 0; x < mb_width; x++)  {
1046    
1047                            MACROBLOCK *pMB, *prevMB;
1048                            int skip;
1049    
1050                            if (current_mb >= max_mbs) {
1051                                    /* we ME-ed all macroblocks we safely could. grab next portion */
1052                                    int above_count = *complete_count_above; /* sync point */
1053                                    if (above_count == mb_width) {
1054                                            /* full line above is ready */
1055                                            above_count = mb_width+1;
1056                                            if (y < mb_height-y_step) {
1057                                                    /* this is not last line, grab a portion of MBs from the next line too */
1058                                                    above_count += MAX(0, complete_count_above[1] - 1);
1059                                            }
1060                                    }
1061    
1062                                    max_mbs = current_mb + above_count - x - 1;
1063    
1064                                    if (current_mb >= max_mbs) {
1065                                            /* current workload is zero */
1066                                            x--;
1067                                            sched_yield();
1068                                            continue;
1069                                    }
1070                            }
1071    
1072    
1073                            pMB = &pMBs[block];
1074                            prevMB = &reference->mbs[block];
1075    
1076                            pMB->sad16 =
1077                                    sad16v(pCurrent->y + (x + y * iEdgedWidth) * 16,
1078                                                            pRef->y + (x + y * iEdgedWidth) * 16,
1079                                                            pParam->edged_width, pMB->sad8);
1080    
1081                            sad00 = 4*MAX(MAX(pMB->sad8[0], pMB->sad8[1]), MAX(pMB->sad8[2], pMB->sad8[3]));
1082    
1083                            if (Data.chroma) {
1084                                    Data.chromaSAD = sad8(pCurrent->u + x*8 + y*(iEdgedWidth/2)*8,
1085                                                                            pRef->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2)
1086                                                                    + sad8(pCurrent->v + (x + y*(iEdgedWidth/2))*8,
1087                                                                            pRef->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2);
1088                                    pMB->sad16 += Data.chromaSAD;
1089                                    sad00 += Data.chromaSAD;
1090                            }
1091    
1092                            skip = InitialSkipDecisionP(sad00, pParam, current, pMB, prevMB, x, y, &Data, pGMC,
1093                                                                                    pCurrent, pRef, MotionFlags);
1094    
1095                            if (skip) {
1096                                    current_mb++;
1097                                    block++;
1098                                    *complete_count_self = x+1;
1099                                    continue;
1100                            }
1101    
1102                            SearchP(pRef, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x,
1103                                            y, MotionFlags, current->vop_flags,
1104                                            &Data, pParam, pMBs, reference->mbs, pMB);
1105    
1106                            if (current->vop_flags & XVID_VOP_MODEDECISION_RD)
1107                                    xvid_me_ModeDecision_RD(&Data, pMB, pMBs, x, y, pParam,
1108                                                                    MotionFlags, current->vop_flags, current->vol_flags,
1109                                                                    pCurrent, pRef, pGMC, current->coding_type);
1110    
1111                            else if (current->vop_flags & XVID_VOP_FAST_MODEDECISION_RD)
1112                                    xvid_me_ModeDecision_Fast(&Data, pMB, pMBs, x, y, pParam,
1113                                                                    MotionFlags, current->vop_flags, current->vol_flags,
1114                                                                    pCurrent, pRef, pGMC, current->coding_type);
1115                            else
1116                                    ModeDecision_SAD(&Data, pMB, pMBs, x, y, pParam,
1117                                                                    MotionFlags, current->vop_flags, current->vol_flags,
1118                                                                    pCurrent, pRef, pGMC, current->coding_type, sad00);
1119    
1120                            *complete_count_self = x+1;
1121    
1122                            current_mb++;
1123                            block++;
1124    
1125                            motionStatsPVOP(&MVmax, &mvCount, &mvSum, pMB, Data.qpel);
1126    
1127                    }
1128                    block += (y_step-1)*pParam->mb_width;
1129                    complete_count_self++;
1130                    complete_count_above++;
1131            }
1132    
1133            h->minfcode = getMinFcode(MVmax);
1134    
1135            h->MVmax = MVmax;
1136            h->mvSum = mvSum;
1137            h->mvCount = mvCount;
1138    }
1139    
1140    

Legend:
Removed from v.1668  
changed lines
  Added in v.1691

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4