[cvs] / xvidcore / src / encoder.c Repository:
ViewVC logotype

Diff of /xvidcore/src/encoder.c

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

revision 1.113, Fri Dec 10 01:31:20 2004 UTC revision 1.120.2.1, Mon Jul 10 15:05:30 2006 UTC
# Line 85  Line 85 
85  /*  /*
86   * Simplify the "fincr/fbase" fraction   * Simplify the "fincr/fbase" fraction
87  */  */
88    static int
89    gcd(int a, int b)
90    {
91            int r ;
92    
93            if (b > a) {
94                    r = a;
95                    a = b;
96                    b = r;
97            }
98    
99            while ((r = a % b)) {
100                    a = b;
101                    b = r;
102            }
103            return b;
104    }
105    
106  static void  static void
107  simplify_time(int *inc, int *base)  simplify_time(int *inc, int *base)
108  {  {
109          /* common factor */          /* common factor */
110          int i = *inc;          const int s = gcd(*inc, *base);
111          while (i > 1) {    *inc  /= s;
112                  if (*inc % i == 0 && *base % i == 0) {    *base /= s;
                         *inc /= i;  
                         *base /= i;  
                         i = *inc;  
                         continue;  
                 }  
                 i--;  
         }  
113    
114          if (*base > 65535 || *inc > 65535) {          if (*base > 65535 || *inc > 65535) {
115                  int *biggest;                  int *biggest;
# Line 114  Line 125 
125                  }                  }
126    
127                  div = ((float)*biggest)/((float)65535);                  div = ((float)*biggest)/((float)65535);
128                  *biggest = (int)(((float)*biggest)/div);                  *biggest = (unsigned int)(((float)*biggest)/div);
129                  *other = (int)(((float)*other)/div);                  *other = (unsigned int)(((float)*other)/div);
130          }          }
131  }  }
132    
# Line 146  Line 157 
157    
158          /* global flags */          /* global flags */
159          pEnc->mbParam.global_flags = create->global;          pEnc->mbParam.global_flags = create->global;
160      if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED))
161        pEnc->mbParam.global_flags |= XVID_GLOBAL_DIVX5_USERDATA;
162    
163          /* width, height */          /* width, height */
164          pEnc->mbParam.width = create->width;          pEnc->mbParam.width = create->width;
# Line 159  Line 172 
172          pEnc->mbParam.fincr = MAX(create->fincr, 0);          pEnc->mbParam.fincr = MAX(create->fincr, 0);
173          pEnc->mbParam.fbase = create->fincr <= 0 ? 25 : create->fbase;          pEnc->mbParam.fbase = create->fincr <= 0 ? 25 : create->fbase;
174          if (pEnc->mbParam.fincr>0)          if (pEnc->mbParam.fincr>0)
175                  simplify_time(&pEnc->mbParam.fincr, &pEnc->mbParam.fbase);                  simplify_time((int*)&pEnc->mbParam.fincr, (int*)&pEnc->mbParam.fbase);
176    
177          /* zones */          /* zones */
178          if(create->num_zones > 0) {          if(create->num_zones > 0) {
# Line 190  Line 203 
203    
204                  memset(&pinfo, 0, sizeof(xvid_plg_info_t));                  memset(&pinfo, 0, sizeof(xvid_plg_info_t));
205                  pinfo.version = XVID_VERSION;                  pinfo.version = XVID_VERSION;
206                  if (create->plugins[n].func(0, XVID_PLG_INFO, &pinfo, 0) >= 0) {                  if (create->plugins[n].func(NULL, XVID_PLG_INFO, &pinfo, NULL) >= 0) {
207                          pEnc->mbParam.plugin_flags |= pinfo.flags;                          pEnc->mbParam.plugin_flags |= pinfo.flags;
208                  }                  }
209    
# Line 207  Line 220 
220                  pcreate.param = create->plugins[n].param;                  pcreate.param = create->plugins[n].param;
221    
222                  pEnc->plugins[n].func = NULL;   /* disable plugins that fail */                  pEnc->plugins[n].func = NULL;   /* disable plugins that fail */
223                  if (create->plugins[n].func(0, XVID_PLG_CREATE, &pcreate, &pEnc->plugins[n].param) >= 0) {                  if (create->plugins[n].func(NULL, XVID_PLG_CREATE, &pcreate, &pEnc->plugins[n].param) >= 0) {
224                          pEnc->plugins[n].func = create->plugins[n].func;                          pEnc->plugins[n].func = create->plugins[n].func;
225                  }                  }
226          }          }
# Line 509  Line 522 
522    xvid_err_memory0:    xvid_err_memory0:
523          for (n=0; n<pEnc->num_plugins;n++) {          for (n=0; n<pEnc->num_plugins;n++) {
524                  if (pEnc->plugins[n].func) {                  if (pEnc->plugins[n].func) {
525                          pEnc->plugins[n].func(pEnc->plugins[n].param, XVID_PLG_DESTROY, 0, 0);                          pEnc->plugins[n].func(pEnc->plugins[n].param, XVID_PLG_DESTROY, NULL, NULL);
526                  }                  }
527          }          }
528          xvid_free(pEnc->plugins);          xvid_free(pEnc->plugins);
# Line 614  Line 627 
627    
628                  for (i=0; i<pEnc->num_plugins;i++) {                  for (i=0; i<pEnc->num_plugins;i++) {
629                          if (pEnc->plugins[i].func) {                          if (pEnc->plugins[i].func) {
630                                  pEnc->plugins[i].func(pEnc->plugins[i].param, XVID_PLG_DESTROY, &pdestroy, 0);                                  pEnc->plugins[i].func(pEnc->plugins[i].param, XVID_PLG_DESTROY, &pdestroy, NULL);
631                          }                          }
632                  }                  }
633                  xvid_free(pEnc->plugins);                  xvid_free(pEnc->plugins);
# Line 774  Line 787 
787          for (i=0; i<(unsigned int)pEnc->num_plugins;i++) {          for (i=0; i<(unsigned int)pEnc->num_plugins;i++) {
788                  emms();                  emms();
789                  if (pEnc->plugins[i].func) {                  if (pEnc->plugins[i].func) {
790                          if (pEnc->plugins[i].func(pEnc->plugins[i].param, opt, &data, 0) < 0) {                          if (pEnc->plugins[i].func(pEnc->plugins[i].param, opt, &data, NULL) < 0) {
791                                  continue;                                  continue;
792                          }                          }
793                  }                  }
# Line 872  Line 885 
885  #endif  #endif
886  }  }
887    
 static int  
 gcd(int a, int b)  
 {  
         int r ;  
   
         if (b > a) {  
                 r = a;  
                 a = b;  
                 b = r;  
         }  
   
         while ((r = a % b)) {  
                 a = b;  
                 b = r;  
         }  
         return b;  
 }  
   
888  static void  static void
889  simplify_par(int *par_width, int *par_height)  simplify_par(int *par_width, int *par_height)
890  {  {
# Line 1015  Line 1010 
1010                          }                          }
1011    
1012                          FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs);                          FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs);
1013                          call_plugins(pEnc, pEnc->bframes[pEnc->bframenum_head], &pEnc->sOriginal2, XVID_PLG_AFTER, 0, 0, stats);                          call_plugins(pEnc, pEnc->bframes[pEnc->bframenum_head], &pEnc->sOriginal2, XVID_PLG_AFTER, NULL, NULL, stats);
1014                          pEnc->bframenum_head++;                          pEnc->bframenum_head++;
1015    
1016                          goto done;                          goto done;
# Line 1047  Line 1042 
1042    
1043                          /* add the not-coded length to the reference frame size */                          /* add the not-coded length to the reference frame size */
1044                          pEnc->current->length += (BitstreamPos(&bs) - bits) / 8;                          pEnc->current->length += (BitstreamPos(&bs) - bits) / 8;
1045                          call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);                          call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats);
1046    
1047                          /* flush complete: reset counters */                          /* flush complete: reset counters */
1048                          pEnc->flush_bframes = 0;                          pEnc->flush_bframes = 0;
# Line 1075  Line 1070 
1070                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
1071    
1072                          if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->mbParam.max_bframes > 0) {                          if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->mbParam.max_bframes > 0) {
1073                                  call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);                                  call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats);
1074                          }                          }
1075    
1076                          /* if the very last frame is to be b-vop, we must change it to a p-vop */                          /* if the very last frame is to be b-vop, we must change it to a p-vop */
# Line 1104  Line 1099 
1099    
1100    
1101                                  if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) {                                  if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) {
1102                                          call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);                                          call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats);
1103                                  }else{                                  }else{
1104                                          pEnc->flush_bframes = 1;                                          pEnc->flush_bframes = 1;
1105                                          goto done;                                          goto done;
# Line 1153  Line 1148 
1148          type = frame->type;          type = frame->type;
1149          pEnc->current->quant = frame->quant;          pEnc->current->quant = frame->quant;
1150    
1151          call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_BEFORE, &type, &pEnc->current->quant, stats);          call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_BEFORE, &type, (int*)&pEnc->current->quant, stats);
1152    
1153          if (type > 0){  /* XVID_TYPE_?VOP */          if (type > 0){  /* XVID_TYPE_?VOP */
1154                  type = type2coding(type);       /* convert XVID_TYPE_?VOP to bitstream coding type */                  type = type2coding(type);       /* convert XVID_TYPE_?VOP to bitstream coding type */
# Line 1228  Line 1223 
1223          if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->mbParam.max_bframes > 0)          if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->mbParam.max_bframes > 0)
1224          {          {
1225                  if (pEnc->current->stamp > 0) {                  if (pEnc->current->stamp > 0) {
1226                          call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);                          call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats);
1227                  }                  }
1228                  else                  else
1229                          stats->type = XVID_TYPE_NOTHING;                          stats->type = XVID_TYPE_NOTHING;
# Line 1256  Line 1251 
1251                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);
1252    
1253                  if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {                  if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {
1254                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "CLOSED GOP BVOP->PVOP");
1255                  }                  }
1256    
1257                  /* convert B-VOP quant to P-VOP */                  /* convert B-VOP quant to P-VOP */
# Line 1351  Line 1346 
1346    
1347                  if ( FrameCodeP(pEnc, &bs) == 0 ) {                  if ( FrameCodeP(pEnc, &bs) == 0 ) {
1348                          /* N-VOP, we mustn't code b-frames yet */                          /* N-VOP, we mustn't code b-frames yet */
1349                          call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);                          if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) ||
1350                                     pEnc->mbParam.max_bframes == 0)
1351                                    call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats);
1352                          goto done;                          goto done;
1353                  }                  }
1354          }          }
# Line 1372  Line 1369 
1369    
1370          /* packed or no-bframes or no-bframes-queued: output stats */          /* packed or no-bframes or no-bframes-queued: output stats */
1371          if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) || pEnc->mbParam.max_bframes == 0 ) {          if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) || pEnc->mbParam.max_bframes == 0 ) {
1372                  call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);                  call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats);
1373          }          }
1374    
1375          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Line 1479  Line 1476 
1476                          stop_prediction_timer();                          stop_prediction_timer();
1477    
1478                          start_timer();                          start_timer();
                         if (pEnc->current->vop_flags & XVID_VOP_GREYSCALE)  
                         {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */  
                                 qcoeff[4*64+0]=0;               /* zero, because for INTRA MBs DC value is saved */  
                                 qcoeff[5*64+0]=0;  
                         }  
1479                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);
1480                          stop_coding_timer();                          stop_coding_timer();
1481                  }                  }
# Line 1503  Line 1495 
1495          return 1;                                       /* intra */          return 1;                                       /* intra */
1496  }  }
1497    
1498    static __inline void
1499    updateFcode(Statistics * sStat, Encoder * pEnc)
1500    {
1501            float fSigma;
1502            int iSearchRange;
1503    
1504            if (sStat->iMvCount == 0)
1505                    sStat->iMvCount = 1;
1506    
1507  #define INTRA_THRESHOLD 0.5          fSigma = (float) sqrt((float) sStat->iMvSum / sStat->iMvCount);
1508  #define BFRAME_SKIP_THRESHHOLD 30  
1509            iSearchRange = 16 << pEnc->mbParam.m_fcode;
1510    
1511            if ((3.0 * fSigma > iSearchRange) && (pEnc->mbParam.m_fcode <= 5) )
1512                    pEnc->mbParam.m_fcode++;
1513    
1514            else if ((5.0 * fSigma < iSearchRange)
1515                               && (4.0 * pEnc->fMvPrevSigma < iSearchRange)
1516                               && (pEnc->mbParam.m_fcode >= 2) )
1517                    pEnc->mbParam.m_fcode--;
1518    
1519            pEnc->fMvPrevSigma = fSigma;
1520    }
1521    
1522    #define BFRAME_SKIP_THRESHHOLD 30
1523    
1524  /* FrameCodeP also handles S(GMC)-VOPs */  /* FrameCodeP also handles S(GMC)-VOPs */
1525  static int  static int
1526  FrameCodeP(Encoder * pEnc,  FrameCodeP(Encoder * pEnc,
1527                     Bitstream * bs)                     Bitstream * bs)
1528  {  {
         float fSigma;  
1529          int bits = BitstreamPos(bs);          int bits = BitstreamPos(bs);
1530    
1531          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);
1532          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
1533    
1534          int x, y, k;          int x, y, k;
         int iSearchRange;  
         int skip_possible;  
1535          FRAMEINFO *const current = pEnc->current;          FRAMEINFO *const current = pEnc->current;
1536          FRAMEINFO *const reference = pEnc->reference;          FRAMEINFO *const reference = pEnc->reference;
1537          MBParam * const pParam = &pEnc->mbParam;          MBParam * const pParam = &pEnc->mbParam;
# Line 1529  Line 1539 
1539          int mb_height = pParam->mb_height;          int mb_height = pParam->mb_height;
1540          int coded = 1;          int coded = 1;
1541    
   
         /* IMAGE *pCurrent = &current->image; */  
1542          IMAGE *pRef = &reference->image;          IMAGE *pRef = &reference->image;
1543    
1544          if (!reference->is_edged) {          if (!reference->is_edged) {
# Line 1631  Line 1639 
1639    
1640          for (y = 0; y < mb_height; y++) {          for (y = 0; y < mb_height; y++) {
1641                  for (x = 0; x < mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
1642                          MACROBLOCK *pMB =                          MACROBLOCK *pMB = &current->mbs[x + y * pParam->mb_width];
1643                                  &current->mbs[x + y * pParam->mb_width];                          int skip_possible;
   
                         int bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q);  
1644    
1645                          if (bIntra) {                          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) {
1646                                  CodeIntraMB(pEnc, pMB);                                  CodeIntraMB(pEnc, pMB);
1647                                  MBTransQuantIntra(&pEnc->mbParam, current, pMB, x, y,                                  MBTransQuantIntra(&pEnc->mbParam, current, pMB, x, y,
1648                                                                    dct_codes, qcoeff);                                                                    dct_codes, qcoeff);
# Line 1647  Line 1653 
1653    
1654                                  current->sStat.kblks++;                                  current->sStat.kblks++;
1655    
                                 if (pEnc->current->vop_flags & XVID_VOP_GREYSCALE) {  
                                         pMB->cbp &= 0x3C;               /* keep only bits 5-2 */  
                                         qcoeff[4*64+0]=0;               /* zero, because for INTRA MBs DC value is saved */  
                                         qcoeff[5*64+0]=0;  
                                 }  
1656                                  MBCoding(current, pMB, qcoeff, bs, &current->sStat);                                  MBCoding(current, pMB, qcoeff, bs, &current->sStat);
1657                                  stop_coding_timer();                                  stop_coding_timer();
1658                                  continue;                                  continue;
# Line 1693  Line 1694 
1694    
1695                          /* Finished processing the MB, now check if to CODE or SKIP */                          /* Finished processing the MB, now check if to CODE or SKIP */
1696    
1697                          skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER) &&                          skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER);
                                                         (pMB->dquant == 0);  
1698    
1699                          if (current->coding_type == S_VOP)                          if (current->coding_type == S_VOP)
1700                                  skip_possible &= (pMB->mcsel == 1);                                  skip_possible &= (pMB->mcsel == 1);
1701                          else if (current->coding_type == P_VOP) {                          else { /* PVOP */
1702                                  if ((pParam->vol_flags & XVID_VOL_QUARTERPEL))                                  const VECTOR * const mv = (pParam->vol_flags & XVID_VOL_QUARTERPEL) ?
1703                                          skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) );                                                                                  pMB->qmvs : pMB->mvs;
1704                                  else                                  skip_possible &= ((mv->x|mv->y) == 0);
                                         skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) );  
1705                          }                          }
1706    
1707                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {
   
1708  /* This is a candidate for SKIPping, but for P-VOPs check intermediate B-frames first */  /* This is a candidate for SKIPping, but for P-VOPs check intermediate B-frames first */
   
                                 if (current->coding_type == P_VOP)      /* special rule for P-VOP's SKIP */  
                                 {  
1709                                          int bSkip = 1;                                          int bSkip = 1;
1710    
1711                                          for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++)                                  if (current->coding_type == P_VOP) {    /* special rule for P-VOP's SKIP */
1712                                          {  
1713                                            for (k = pEnc->bframenum_head; k < pEnc->bframenum_tail; k++) {
1714                                                  int iSAD;                                                  int iSAD;
1715                                                  iSAD = sad16(reference->image.y + 16*y*pParam->edged_width + 16*x,                                                  iSAD = sad16(reference->image.y + 16*y*pParam->edged_width + 16*x,
1716                                                                          pEnc->bframes[k]->image.y + 16*y*pParam->edged_width + 16*x,                                                                          pEnc->bframes[k]->image.y + 16*y*pParam->edged_width + 16*x,
1717                                                                  pParam->edged_width,BFRAME_SKIP_THRESHHOLD);                                                                                  pParam->edged_width, BFRAME_SKIP_THRESHHOLD * pMB->quant);
1718                                                  if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant)                                                  if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant) {
1719                                                  {       bSkip = 0;                                                          bSkip = 0; /* could not SKIP */
1720                                                          break;                                                          if (pParam->vol_flags & XVID_VOL_QUARTERPEL) {
                                                 }  
                                         }  
   
                                         if (!bSkip) {   /* no SKIP, but trivial block */  
                                                 if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) {  
1721                                                          VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, 0);                                                          VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, 0);
1722                                                          pMB->pmvs[0].x = - predMV.x;                                                          pMB->pmvs[0].x = - predMV.x;
1723                                                          pMB->pmvs[0].y = - predMV.y;                                                          pMB->pmvs[0].y = - predMV.y;
1724                                                  }                                                          } else {
                                                 else {  
1725                                                          VECTOR predMV = get_pmv2(current->mbs, pParam->mb_width, 0, x, y, 0);                                                          VECTOR predMV = get_pmv2(current->mbs, pParam->mb_width, 0, x, y, 0);
1726                                                          pMB->pmvs[0].x = - predMV.x;                                                          pMB->pmvs[0].x = - predMV.x;
1727                                                          pMB->pmvs[0].y = - predMV.y;                                                          pMB->pmvs[0].y = - predMV.y;
1728                                                  }                                                  }
1729                                                  pMB->mode = MODE_INTER;                                                  pMB->mode = MODE_INTER;
1730                                                  pMB->cbp = 0;                                                  pMB->cbp = 0;
1731                                                  MBCoding(current, pMB, qcoeff, bs, &current->sStat);                                                          break;
1732                                                  stop_coding_timer();                                                  }
   
                                                 continue;       /* next MB */  
1733                                          }                                          }
1734                                  }                                  }
                                 /* do SKIP */  
1735    
1736                                    if (bSkip) {
1737                                            /* do SKIP */
1738                                  pMB->mode = MODE_NOT_CODED;                                  pMB->mode = MODE_NOT_CODED;
1739                                  MBSkip(bs);                                  MBSkip(bs);
1740                                  stop_coding_timer();                                  stop_coding_timer();
1741                                  continue;       /* next MB */                                  continue;       /* next MB */
1742                          }                          }
                         /* ordinary case: normal coded INTER/INTER4V block */  
   
                         if ((current->vop_flags & XVID_VOP_GREYSCALE))  
                         {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */  
                                 qcoeff[4*64+0]=0;               /* zero, because DC for INTRA MBs DC value is saved */  
                                 qcoeff[5*64+0]=0;  
                         }  
   
                         if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) {  
                                 VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, 0);  
                                 pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x;  
                                 pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y;  
                                 DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[0].x, pMB->pmvs[0].y, predMV.x, predMV.y, pMB->mvs[0].x, pMB->mvs[0].y);  
                         } else {  
                                 VECTOR predMV = get_pmv2(current->mbs, pParam->mb_width, 0, x, y, 0);  
                                 pMB->pmvs[0].x = pMB->mvs[0].x - predMV.x;  
                                 pMB->pmvs[0].y = pMB->mvs[0].y - predMV.y;  
                                 DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[0].x, pMB->pmvs[0].y, predMV.x, predMV.y, pMB->mvs[0].x, pMB->mvs[0].y);  
                         }  
   
   
                         if (pMB->mode == MODE_INTER4V)  
                         {       int k;  
                                 for (k=1;k<4;k++)  
                                 {  
                                         if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) {  
                                                 VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, k);  
                                                 pMB->pmvs[k].x = pMB->qmvs[k].x - predMV.x;  
                                                 pMB->pmvs[k].y = pMB->qmvs[k].y - predMV.y;  
                                 DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[k].x, pMB->pmvs[k].y, predMV.x, predMV.y, pMB->mvs[k].x, pMB->mvs[k].y);  
                                         } else {  
                                                 VECTOR predMV = get_pmv2(current->mbs, pParam->mb_width, 0, x, y, k);  
                                                 pMB->pmvs[k].x = pMB->mvs[k].x - predMV.x;  
                                                 pMB->pmvs[k].y = pMB->mvs[k].y - predMV.y;  
                                 DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[k].x, pMB->pmvs[k].y, predMV.x, predMV.y, pMB->mvs[k].x, pMB->mvs[k].y);  
                                         }  
   
                                 }  
1743                          }                          }
1744    
1745                            /* ordinary case: normal coded INTER/INTER4V block */
1746                          MBCoding(current, pMB, qcoeff, bs, &pEnc->current->sStat);                          MBCoding(current, pMB, qcoeff, bs, &pEnc->current->sStat);
1747                          stop_coding_timer();                          stop_coding_timer();
   
1748                  }                  }
1749          }          }
1750    
1751          emms();          emms();
1752            updateFcode(&current->sStat, pEnc);
         if (current->sStat.iMvCount == 0)  
                 current->sStat.iMvCount = 1;  
   
         fSigma = (float) sqrt((float) current->sStat.iMvSum / current->sStat.iMvCount);  
   
         iSearchRange = 16 << pParam->m_fcode;  
   
         if ((3.0 * fSigma > iSearchRange) && (pParam->m_fcode <= 5) )  
                 pParam->m_fcode++;  
   
         else if ((5.0 * fSigma < iSearchRange)  
                            && (4.0 * pEnc->fMvPrevSigma < iSearchRange)  
                            && (pParam->m_fcode >= 2) )  /* minimum search range 32 */  
                 pParam->m_fcode--;  
   
         pEnc->fMvPrevSigma = fSigma;  
1753    
1754          /* frame drop code */          /* frame drop code */
1755  #if 0  #if 0
# Line 1824  Line 1759 
1759                  (pParam->frame_drop_ratio * mb_width * mb_height) / 100 &&                  (pParam->frame_drop_ratio * mb_width * mb_height) / 100 &&
1760                  ( (pEnc->bframenum_head >= pEnc->bframenum_tail) || !(pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP)) )                  ( (pEnc->bframenum_head >= pEnc->bframenum_tail) || !(pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP)) )
1761          {          {
1762                  current->sStat.kblks = current->sStat.mblks = 0;                  current->sStat.kblks = current->sStat.mblks = current->sStat.iTextBits = 0;
1763                  current->sStat.ublks = mb_width * mb_height;                  current->sStat.ublks = mb_width * mb_height;
1764    
1765                  BitstreamReset(bs);                  BitstreamReset(bs);
# Line 1994  Line 1929 
1929    
1930                          if (mb->mode == MODE_DIRECT && (mb->cbp | mb->pmvs[3].x | mb->pmvs[3].y) == 0)                          if (mb->mode == MODE_DIRECT && (mb->cbp | mb->pmvs[3].x | mb->pmvs[3].y) == 0)
1931                                  mb->mode = MODE_DIRECT_NONE_MV; /* skipped */                                  mb->mode = MODE_DIRECT_NONE_MV; /* skipped */
1932                            else
                         /* keep only bits 5-2 -- Chroma blocks will just be skipped by the  
                          * coding function for BFrames, that's why we don't zero teh DC  
                          * coeffs */  
1933                          if (frame->vop_flags & XVID_VOP_GREYSCALE)                          if (frame->vop_flags & XVID_VOP_GREYSCALE)
1934                                            /* keep only bits 5-2 -- Chroma blocks will just be skipped by MBCodingBVOP */
1935                                  mb->cbp &= 0x3C;                                  mb->cbp &= 0x3C;
1936    
1937                          start_timer();                          start_timer();
# Line 2010  Line 1943 
1943    
1944          emms();          emms();
1945    
         /* TODO: dynamic fcode/bcode ??? */  
   
1946          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */
1947          frame->length = (BitstreamPos(bs) - bits) / 8;          frame->length = (BitstreamPos(bs) - bits) / 8;
1948    

Legend:
Removed from v.1.113  
changed lines
  Added in v.1.120.2.1

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