[svn] / branches / dev-api-4 / xvidcore / src / motion / motion_est.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/src/motion/motion_est.c

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

revision 1074, Thu Jun 26 10:37:42 2003 UTC revision 1075, Thu Jun 26 11:50:37 2003 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: motion_est.c,v 1.58.2.18 2003-06-19 09:58:57 syskin Exp $   * $Id: motion_est.c,v 1.58.2.19 2003-06-26 11:50:37 syskin Exp $
25   *   *
26   ****************************************************************************/   ****************************************************************************/
27    
# Line 667  Line 667 
667          for(i = 0; i < 4; i++) {          for(i = 0; i < 4; i++) {
668                  int s = 8*((i&1) + (i>>1)*data->iEdgedWidth);                  int s = 8*((i&1) + (i>>1)*data->iEdgedWidth);
669                  transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth);                  transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth);
670                  bits += data->temp[i] = Block_CalcBits(coeff, in, data->iQuant, data->quant_type, &cbp, i);                  bits += data->temp[i] = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, i);
671          }          }
672    
673          bits += t = BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);          bits += t = BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);
# Line 692  Line 692 
692          /* chroma U */          /* chroma U */
693          ptr = interpolate8x8_switch2(data->RefQ + 64, data->RefP[4], 0, 0, xc, yc,  data->iEdgedWidth/2, data->rounding);          ptr = interpolate8x8_switch2(data->RefQ + 64, data->RefP[4], 0, 0, xc, yc,  data->iEdgedWidth/2, data->rounding);
694          transfer_8to16subro(in, ptr, data->CurU, data->iEdgedWidth/2);          transfer_8to16subro(in, ptr, data->CurU, data->iEdgedWidth/2);
695          bits += Block_CalcBits(coeff, in, data->iQuant, data->quant_type, &cbp, 4);          bits += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 4);
696          if (bits >= data->iMinSAD[0]) return;          if (bits >= data->iMinSAD[0]) return;
697    
698          /* chroma V */          /* chroma V */
699          ptr = interpolate8x8_switch2(data->RefQ + 64, data->RefP[5], 0, 0, xc, yc,  data->iEdgedWidth/2, data->rounding);          ptr = interpolate8x8_switch2(data->RefQ + 64, data->RefP[5], 0, 0, xc, yc,  data->iEdgedWidth/2, data->rounding);
700          transfer_8to16subro(in, ptr, data->CurV, data->iEdgedWidth/2);          transfer_8to16subro(in, ptr, data->CurV, data->iEdgedWidth/2);
701          bits += Block_CalcBits(coeff, in, data->iQuant, data->quant_type, &cbp, 5);          bits += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5);
702    
703          bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len;          bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len;
704    
# Line 731  Line 731 
731          }          }
732    
733          transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth);          transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth);
734          bits = Block_CalcBits(coeff, in, data->iQuant, data->quant_type, &cbp, 5);          bits = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5);
735          bits += BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);          bits += BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);
736    
737          if (bits < data->iMinSAD[0]) {          if (bits < data->iMinSAD[0]) {
# Line 1089  Line 1089 
1089          VECTOR currentMV[5];          VECTOR currentMV[5];
1090          VECTOR currentQMV[5];          VECTOR currentQMV[5];
1091          int32_t iMinSAD[5];          int32_t iMinSAD[5];
1092          DECLARE_ALIGNED_MATRIX(dct_space, 2, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE);
1093          SearchData Data;          SearchData Data;
1094          memset(&Data, 0, sizeof(SearchData));          memset(&Data, 0, sizeof(SearchData));
1095          Data.iEdgedWidth = iEdgedWidth;          Data.iEdgedWidth = iEdgedWidth;
# Line 2161  Line 2161 
2161          }          }
2162  }  }
2163    
2164  #define INTRA_THRESH    1700  #define INTRA_THRESH    2200
2165  #define INTER_THRESH    1200  #define INTER_THRESH    50
2166    #define INTRA_THRESH2   95
2167    
2168  int  int
2169  MEanalysis(     const IMAGE * const pRef,  MEanalysis(     const IMAGE * const pRef,
2170                          const FRAMEINFO * const Current,                          const FRAMEINFO * const Current,
2171                          const MBParam * const pParam,                          const MBParam * const pParam,
2172                          const int maxIntra, /* maximum number if non-I frames */                          const int maxIntra, //maximum number if non-I frames
2173                          const int intraCount, /* number of non-I frames after last I frame; 0 if we force P/B frame */                          const int intraCount, //number of non-I frames after last I frame; 0 if we force P/B frame
2174                          const int bCount,  /* number of B frames in a row */                          const int bCount,  // number of B frames in a row
2175                          const int b_thresh)                          const int b_thresh)
2176  {  {
2177          uint32_t x, y, intra = 0;          uint32_t x, y, intra = 0;
2178          int sSAD = 0;          int sSAD = 0;
2179          MACROBLOCK * const pMBs = Current->mbs;          MACROBLOCK * const pMBs = Current->mbs;
2180          const IMAGE * const pCurrent = &Current->image;          const IMAGE * const pCurrent = &Current->image;
2181          int IntraThresh = INTRA_THRESH, InterThresh = INTER_THRESH + 10*b_thresh;          int IntraThresh = INTRA_THRESH, InterThresh = INTER_THRESH + b_thresh;
2182          int s = 0, blocks = 0;          int s = 0, blocks = 0;
2183            int complexity = 0;
2184    
2185          int32_t iMinSAD[5], temp[5];          int32_t iMinSAD[5], temp[5];
2186          VECTOR currentMV[5];          VECTOR currentMV[5];
# Line 2190  Line 2192 
2192          Data.temp = temp;          Data.temp = temp;
2193          CheckCandidate = CheckCandidate32I;          CheckCandidate = CheckCandidate32I;
2194    
2195    
2196          if (intraCount != 0) {          if (intraCount != 0) {
2197                  if (intraCount < 10) /* we're right after an I frame */                  if (intraCount < 10) // we're right after an I frame
2198                          IntraThresh += 15* (intraCount - 10) * (intraCount - 10);                          IntraThresh += 15* (intraCount - 10) * (intraCount - 10);
2199                  else                  else
2200                          if ( 5*(maxIntra - intraCount) < maxIntra) /* we're close to maximum. 2 sec when max is 10 sec */                          if ( 5*(maxIntra - intraCount) < maxIntra) // we're close to maximum. 2 sec when max is 10 sec
2201                                  IntraThresh -= (IntraThresh * (maxIntra - 8*(maxIntra - intraCount)))/maxIntra;                                  IntraThresh -= (IntraThresh * (maxIntra - 8*(maxIntra - intraCount)))/maxIntra;
2202          }          }
2203    
2204          InterThresh -= (350 - 8*b_thresh) * bCount;          InterThresh -= 12 * bCount;
2205          if (InterThresh < 300 + 5*b_thresh) InterThresh = 300 + 5*b_thresh;          if (InterThresh < 15 + b_thresh) InterThresh = 15 + b_thresh;
2206    
2207          if (sadInit) (*sadInit) ();          if (sadInit) (*sadInit) ();
2208    
2209          for (y = 1; y < pParam->mb_height-1; y += 2) {          for (y = 1; y < pParam->mb_height-1; y += 2) {
2210                  for (x = 1; x < pParam->mb_width-1; x += 2) {                  for (x = 1; x < pParam->mb_width-1; x += 2) {
2211                          int i;                          int i;
2212                          blocks += 4;                          blocks += 10;
2213    
2214                          if (bCount == 0) pMBs[x + y * pParam->mb_width].mvs[0] = zeroMV;                          if (bCount == 0) pMBs[x + y * pParam->mb_width].mvs[0] = zeroMV;
2215                          else { /* extrapolation of the vector found for last frame */                          else { //extrapolation of the vector found for last frame
2216                                  pMBs[x + y * pParam->mb_width].mvs[0].x =                                  pMBs[x + y * pParam->mb_width].mvs[0].x =
2217                                          (pMBs[x + y * pParam->mb_width].mvs[0].x * (bCount+1) ) / bCount;                                          (pMBs[x + y * pParam->mb_width].mvs[0].x * (bCount+1) ) / bCount;
2218                                  pMBs[x + y * pParam->mb_width].mvs[0].y =                                  pMBs[x + y * pParam->mb_width].mvs[0].y =
# Line 2221  Line 2224 
2224                          for (i = 0; i < 4; i++) {                          for (i = 0; i < 4; i++) {
2225                                  int dev;                                  int dev;
2226                                  MACROBLOCK *pMB = &pMBs[x+(i&1) + (y+(i>>1)) * pParam->mb_width];                                  MACROBLOCK *pMB = &pMBs[x+(i&1) + (y+(i>>1)) * pParam->mb_width];
                                 if (pMB->sad16 > IntraThresh) {  
2227                                          dev = dev16(pCurrent->y + (x + (i&1) + (y + (i>>1)) * pParam->edged_width) * 16,                                          dev = dev16(pCurrent->y + (x + (i&1) + (y + (i>>1)) * pParam->edged_width) * 16,
2228                                                                          pParam->edged_width);                                                                          pParam->edged_width);
2229    
2230                                    complexity += dev;
2231                                          if (dev + IntraThresh < pMB->sad16) {                                          if (dev + IntraThresh < pMB->sad16) {
2232                                                  pMB->mode = MODE_INTRA;                                                  pMB->mode = MODE_INTRA;
2233                                                  if (++intra > ((pParam->mb_height-2)*(pParam->mb_width-2))/2) return I_VOP;                                                  if (++intra > ((pParam->mb_height-2)*(pParam->mb_width-2))/2) return I_VOP;
2234                                          }                                          }
2235                                  }  
2236                                  if (pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0) s++;                                  if (pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0)
2237                                            if (dev > 500 && pMB->sad16 < 1000)
2238                                                    sSAD += 1000;
2239    
2240                                  sSAD += pMB->sad16;                                  sSAD += pMB->sad16;
2241                          }                          }
2242                  }                  }
2243          }          }
2244            complexity >>= 7;
2245    
2246          sSAD /= blocks;          sSAD /= complexity + 4*blocks;
   
         if (b_thresh < 20) {  
                 s = (10*s) / blocks;  
                 if (s > 4) sSAD += (s - 2) * (40 - 2*b_thresh); /* static block - looks bad when in bframe... */  
         }  
2247    
2248            if (intraCount > 12 && sSAD > INTRA_THRESH2 ) return I_VOP;
2249          if (sSAD > InterThresh ) return P_VOP;          if (sSAD > InterThresh ) return P_VOP;
2250          emms();          emms();
2251          return B_VOP;          return B_VOP;
2252  }  }
2253    
   
2254  static WARPPOINTS  static WARPPOINTS
2255  GlobalMotionEst(const MACROBLOCK * const pMBs,  GlobalMotionEst(const MACROBLOCK * const pMBs,
2256                                  const MBParam * const pParam,                                  const MBParam * const pParam,
# Line 2621  Line 2623 
2623          /* chroma U */          /* chroma U */
2624          ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[4], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);          ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[4], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);
2625          transfer_8to16subro(in, Data->CurU, ptr, Data->iEdgedWidth/2);          transfer_8to16subro(in, Data->CurU, ptr, Data->iEdgedWidth/2);
2626          bits += Block_CalcBits(coeff, in, Data->iQuant, Data->quant_type, &cbp, 4);          bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4);
2627    
2628          if (bits >= *Data->iMinSAD) return bits;          if (bits >= *Data->iMinSAD) return bits;
2629    
2630          /* chroma V */          /* chroma V */
2631          ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[5], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);          ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[5], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);
2632          transfer_8to16subro(in, Data->CurV, ptr, Data->iEdgedWidth/2);          transfer_8to16subro(in, Data->CurV, ptr, Data->iEdgedWidth/2);
2633          bits += Block_CalcBits(coeff, in, Data->iQuant, Data->quant_type, &cbp, 5);          bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5);
2634    
2635          bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len;          bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len;
2636    
# Line 2645  Line 2647 
2647          for(i = 0; i < 4; i++) {          for(i = 0; i < 4; i++) {
2648                  int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth);                  int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth);
2649                  transfer_8to16copy(in, Data->Cur + s, Data->iEdgedWidth);                  transfer_8to16copy(in, Data->Cur + s, Data->iEdgedWidth);
2650                  bits += Block_CalcBitsIntra(coeff, in, Data->iQuant, Data->quant_type, &cbp, i, &dc);                  bits += Block_CalcBitsIntra(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, i, &dc);
2651    
2652                  if (bits >= Data->iMinSAD[0]) return bits;                  if (bits >= Data->iMinSAD[0]) return bits;
2653          }          }
# Line 2654  Line 2656 
2656    
2657          /*chroma U */          /*chroma U */
2658          transfer_8to16copy(in, Data->CurU, Data->iEdgedWidth/2);          transfer_8to16copy(in, Data->CurU, Data->iEdgedWidth/2);
2659          bits += Block_CalcBitsIntra(coeff, in, Data->iQuant, Data->quant_type, &cbp, 4, &dc);          bits += Block_CalcBitsIntra(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, &dc);
2660    
2661          if (bits >= Data->iMinSAD[0]) return bits;          if (bits >= Data->iMinSAD[0]) return bits;
2662    
2663          /* chroma V */          /* chroma V */
2664          transfer_8to16copy(in, Data->CurV, Data->iEdgedWidth/2);          transfer_8to16copy(in, Data->CurV, Data->iEdgedWidth/2);
2665          bits += Block_CalcBitsIntra(coeff, in, Data->iQuant, Data->quant_type, &cbp, 5, &dc);          bits += Block_CalcBitsIntra(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, &dc);
2666    
2667          bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp & 3) << 3)].len;          bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp & 3) << 3)].len;
2668    

Legend:
Removed from v.1074  
changed lines
  Added in v.1075

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