[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.115, Fri Dec 10 04:10:12 2004 UTC revision 1.118, Mon May 23 09:29:43 2005 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 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 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 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 1535  Line 1530 
1530          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
1531    
1532          int x, y, k;          int x, y, k;
         int skip_possible;  
1533          FRAMEINFO *const current = pEnc->current;          FRAMEINFO *const current = pEnc->current;
1534          FRAMEINFO *const reference = pEnc->reference;          FRAMEINFO *const reference = pEnc->reference;
1535          MBParam * const pParam = &pEnc->mbParam;          MBParam * const pParam = &pEnc->mbParam;
# Line 1643  Line 1637 
1637    
1638          for (y = 0; y < mb_height; y++) {          for (y = 0; y < mb_height; y++) {
1639                  for (x = 0; x < mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
1640                          MACROBLOCK *pMB =                          MACROBLOCK *pMB = &current->mbs[x + y * pParam->mb_width];
1641                                  &current->mbs[x + y * pParam->mb_width];                          int skip_possible;
1642    
1643                          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) {                          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) {
1644                                  CodeIntraMB(pEnc, pMB);                                  CodeIntraMB(pEnc, pMB);
# Line 1698  Line 1692 
1692    
1693                          /* Finished processing the MB, now check if to CODE or SKIP */                          /* Finished processing the MB, now check if to CODE or SKIP */
1694    
1695                          skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER) &&                          skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER);
                                                         (pMB->dquant == 0);  
1696    
1697                          if (current->coding_type == S_VOP)                          if (current->coding_type == S_VOP)
1698                                  skip_possible &= (pMB->mcsel == 1);                                  skip_possible &= (pMB->mcsel == 1);
1699                          else if (current->coding_type == P_VOP) {                          else { /* PVOP */
1700                                  if ((pParam->vol_flags & XVID_VOL_QUARTERPEL))                                  const VECTOR * const mv = (pParam->vol_flags & XVID_VOL_QUARTERPEL) ?
1701                                          skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) );                                                                                  pMB->qmvs : pMB->mvs;
1702                                  else                                  skip_possible &= ((mv->x|mv->y) == 0);
                                         skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) );  
1703                          }                          }
1704    
1705                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {
   
1706  /* 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 */  
                                 {  
1707                                          int bSkip = 1;                                          int bSkip = 1;
1708    
1709                                          for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++)                                  if (current->coding_type == P_VOP) {    /* special rule for P-VOP's SKIP */
1710                                          {  
1711                                            for (k = pEnc->bframenum_head; k < pEnc->bframenum_tail; k++) {
1712                                                  int iSAD;                                                  int iSAD;
1713                                                  iSAD = sad16(reference->image.y + 16*y*pParam->edged_width + 16*x,                                                  iSAD = sad16(reference->image.y + 16*y*pParam->edged_width + 16*x,
1714                                                                          pEnc->bframes[k]->image.y + 16*y*pParam->edged_width + 16*x,                                                                          pEnc->bframes[k]->image.y + 16*y*pParam->edged_width + 16*x,
1715                                                                  pParam->edged_width,BFRAME_SKIP_THRESHHOLD);                                                                                  pParam->edged_width, BFRAME_SKIP_THRESHHOLD * pMB->quant);
1716                                                  if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant)                                                  if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant) {
1717                                                  {       bSkip = 0;                                                          bSkip = 0; /* could not SKIP */
1718                                                          break;                                                          if (pParam->vol_flags & XVID_VOL_QUARTERPEL) {
                                                 }  
                                         }  
   
                                         if (!bSkip) {   /* no SKIP, but trivial block */  
                                                 if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) {  
1719                                                          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);
1720                                                          pMB->pmvs[0].x = - predMV.x;                                                          pMB->pmvs[0].x = - predMV.x;
1721                                                          pMB->pmvs[0].y = - predMV.y;                                                          pMB->pmvs[0].y = - predMV.y;
1722                                                  }                                                          } else {
                                                 else {  
1723                                                          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);
1724                                                          pMB->pmvs[0].x = - predMV.x;                                                          pMB->pmvs[0].x = - predMV.x;
1725                                                          pMB->pmvs[0].y = - predMV.y;                                                          pMB->pmvs[0].y = - predMV.y;
1726                                                  }                                                  }
1727                                                  pMB->mode = MODE_INTER;                                                  pMB->mode = MODE_INTER;
1728                                                  pMB->cbp = 0;                                                  pMB->cbp = 0;
1729                                                  MBCoding(current, pMB, qcoeff, bs, &current->sStat);                                                          break;
1730                                                  stop_coding_timer();                                                  }
   
                                                 continue;       /* next MB */  
1731                                          }                                          }
1732                                  }                                  }
                                 /* do SKIP */  
1733    
1734                                    if (bSkip) {
1735                                            /* do SKIP */
1736                                  pMB->mode = MODE_NOT_CODED;                                  pMB->mode = MODE_NOT_CODED;
1737                                  MBSkip(bs);                                  MBSkip(bs);
1738                                  stop_coding_timer();                                  stop_coding_timer();
1739                                  continue;       /* next MB */                                  continue;       /* next MB */
1740                          }                          }
                         /* ordinary case: normal coded INTER/INTER4V block */  
   
                         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);  
                                         }  
   
                                 }  
1741                          }                          }
1742    
1743                            /* ordinary case: normal coded INTER/INTER4V block */
1744                          MBCoding(current, pMB, qcoeff, bs, &pEnc->current->sStat);                          MBCoding(current, pMB, qcoeff, bs, &pEnc->current->sStat);
1745                          stop_coding_timer();                          stop_coding_timer();
   
1746                  }                  }
1747          }          }
1748    

Legend:
Removed from v.1.115  
changed lines
  Added in v.1.118

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