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

Diff of /trunk/xvidcore/src/encoder.c

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

revision 1573, Fri Dec 10 04:10:12 2004 UTC revision 1680, Thu Feb 23 07:22:43 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: encoder.c,v 1.115 2004-12-10 04:10:12 syskin Exp $   * $Id: encoder.c,v 1.125 2006-02-23 07:22:43 syskin Exp $
25   *   *
26   ****************************************************************************/   ****************************************************************************/
27    
# 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 225  Line 238 
238                          goto xvid_err_memory1a;                          goto xvid_err_memory1a;
239          }          }
240    
241            /* temp lambdas */
242            if (pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) {
243                    pEnc->temp_lambda = (float *) xvid_malloc(pEnc->mbParam.mb_width *
244                                                    pEnc->mbParam.mb_height * 6 * sizeof(float), CACHE_LINE);
245                    if (pEnc->temp_lambda == NULL)
246                            goto xvid_err_memory1a;
247            }
248    
249          /* bframes */          /* bframes */
250          pEnc->mbParam.max_bframes = MAX(create->max_bframes, 0);          pEnc->mbParam.max_bframes = MAX(create->max_bframes, 0);
251          pEnc->mbParam.bquant_ratio = MAX(create->bquant_ratio, 0);          pEnc->mbParam.bquant_ratio = MAX(create->bquant_ratio, 0);
# Line 506  Line 527 
527                  xvid_free(pEnc->temp_dquants);                  xvid_free(pEnc->temp_dquants);
528          }          }
529    
530            if(pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) {
531                    xvid_free(pEnc->temp_lambda);
532            }
533    
534    xvid_err_memory0:    xvid_err_memory0:
535          for (n=0; n<pEnc->num_plugins;n++) {          for (n=0; n<pEnc->num_plugins;n++) {
536                  if (pEnc->plugins[n].func) {                  if (pEnc->plugins[n].func) {
537                          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);
538                  }                  }
539          }          }
540          xvid_free(pEnc->plugins);          xvid_free(pEnc->plugins);
# Line 614  Line 639 
639    
640                  for (i=0; i<pEnc->num_plugins;i++) {                  for (i=0; i<pEnc->num_plugins;i++) {
641                          if (pEnc->plugins[i].func) {                          if (pEnc->plugins[i].func) {
642                                  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);
643                          }                          }
644                  }                  }
645                  xvid_free(pEnc->plugins);                  xvid_free(pEnc->plugins);
# Line 638  Line 663 
663  static void call_plugins(Encoder * pEnc, FRAMEINFO * frame, IMAGE * original,  static void call_plugins(Encoder * pEnc, FRAMEINFO * frame, IMAGE * original,
664                                                   int opt, int * type, int * quant, xvid_enc_stats_t * stats)                                                   int opt, int * type, int * quant, xvid_enc_stats_t * stats)
665  {  {
666          unsigned int i, j;          unsigned int i, j, k;
667          xvid_plg_data_t data;          xvid_plg_data_t data;
668    
669          /* set data struct */          /* set data struct */
# Line 697  Line 722 
722                  if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) {                  if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) {
723                          data.dquant = pEnc->temp_dquants;                          data.dquant = pEnc->temp_dquants;
724                          data.dquant_stride = pEnc->mbParam.mb_width;                          data.dquant_stride = pEnc->mbParam.mb_width;
725                          memset(data.dquant, 0, data.mb_width*data.mb_height);                          memset(data.dquant, 0, data.mb_width*data.mb_height*sizeof(int));
726                    }
727    
728                    if(pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) {
729                            int block = 0;
730                            data.lambda = pEnc->temp_lambda;
731                            for(i = 0;i < pEnc->mbParam.mb_height; i++)
732                                    for(j = 0;j < pEnc->mbParam.mb_width; j++)
733                                            for (k = 0; k < 6; k++)
734                                                    data.lambda[block++] = 1.0f;
735                  }                  }
736    
737          } else { /* XVID_PLG_AFTER */          } else { /* XVID_PLG_AFTER */
# Line 774  Line 808 
808          for (i=0; i<(unsigned int)pEnc->num_plugins;i++) {          for (i=0; i<(unsigned int)pEnc->num_plugins;i++) {
809                  emms();                  emms();
810                  if (pEnc->plugins[i].func) {                  if (pEnc->plugins[i].func) {
811                          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) {
812                                  continue;                                  continue;
813                          }                          }
814                  }                  }
# Line 803  Line 837 
837                                  frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0;                                  frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0;
838                          }                          }
839                  }                  }
840    
841                    if (pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) {
842                            for (j = 0; j < pEnc->mbParam.mb_height; j++)
843                                    for (i = 0; i < pEnc->mbParam.mb_width; i++)
844                                            for (k = 0; k < 6; k++) {
845                                                    frame->mbs[j*pEnc->mbParam.mb_width + i].lambda[k] =
846                                                            (int) ((float)(1<<LAMBDA_EXP) * data.lambda[6 * (j * data.mb_width + i) + k]);
847                            }
848                    } else {
849                            for (j = 0; j<pEnc->mbParam.mb_height; j++)
850                                    for (i = 0; i<pEnc->mbParam.mb_width; i++)
851                                            for (k = 0; k < 6; k++) {
852                                                    frame->mbs[j*pEnc->mbParam.mb_width + i].lambda[k] = 1<<LAMBDA_EXP;
853                            }
854                    }
855    
856    
857                  frame->mbs[0].quant = data.quant; /* FRAME will not affect the quant in stats */                  frame->mbs[0].quant = data.quant; /* FRAME will not affect the quant in stats */
858          }          }
859    
# Line 872  Line 923 
923  #endif  #endif
924  }  }
925    
 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;  
 }  
   
926  static void  static void
927  simplify_par(int *par_width, int *par_height)  simplify_par(int *par_width, int *par_height)
928  {  {
# Line 1015  Line 1048 
1048                          }                          }
1049    
1050                          FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs);                          FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs);
1051                          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);
1052                          pEnc->bframenum_head++;                          pEnc->bframenum_head++;
1053    
1054                          goto done;                          goto done;
# Line 1047  Line 1080 
1080    
1081                          /* add the not-coded length to the reference frame size */                          /* add the not-coded length to the reference frame size */
1082                          pEnc->current->length += (BitstreamPos(&bs) - bits) / 8;                          pEnc->current->length += (BitstreamPos(&bs) - bits) / 8;
1083                          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);
1084    
1085                          /* flush complete: reset counters */                          /* flush complete: reset counters */
1086                          pEnc->flush_bframes = 0;                          pEnc->flush_bframes = 0;
# Line 1075  Line 1108 
1108                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
1109    
1110                          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) {
1111                                  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);
1112                          }                          }
1113    
1114                          /* 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 1137 
1137    
1138    
1139                                  if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) {                                  if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) {
1140                                          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);
1141                                  }else{                                  }else{
1142                                          pEnc->flush_bframes = 1;                                          pEnc->flush_bframes = 1;
1143                                          goto done;                                          goto done;
# Line 1153  Line 1186 
1186          type = frame->type;          type = frame->type;
1187          pEnc->current->quant = frame->quant;          pEnc->current->quant = frame->quant;
1188    
1189          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);
1190    
1191          if (type > 0){  /* XVID_TYPE_?VOP */          if (type > 0){  /* XVID_TYPE_?VOP */
1192                  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 1261 
1261          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)
1262          {          {
1263                  if (pEnc->current->stamp > 0) {                  if (pEnc->current->stamp > 0) {
1264                          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);
1265                  }                  }
1266                  else                  else
1267                          stats->type = XVID_TYPE_NOTHING;                          stats->type = XVID_TYPE_NOTHING;
# Line 1256  Line 1289 
1289                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);
1290    
1291                  if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {                  if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {
1292                          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");
1293                  }                  }
1294    
1295                  /* convert B-VOP quant to P-VOP */                  /* convert B-VOP quant to P-VOP */
# Line 1351  Line 1384 
1384    
1385                  if ( FrameCodeP(pEnc, &bs) == 0 ) {                  if ( FrameCodeP(pEnc, &bs) == 0 ) {
1386                          /* N-VOP, we mustn't code b-frames yet */                          /* N-VOP, we mustn't code b-frames yet */
1387                          call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);                          if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) ||
1388                                     pEnc->mbParam.max_bframes == 0)
1389                                    call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats);
1390                          goto done;                          goto done;
1391                  }                  }
1392          }          }
# Line 1372  Line 1407 
1407    
1408          /* packed or no-bframes or no-bframes-queued: output stats */          /* packed or no-bframes or no-bframes-queued: output stats */
1409          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 ) {
1410                  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);
1411          }          }
1412    
1413          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Line 1461  Line 1496 
1496          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1, pEnc->current->mbs[0].quant);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1, pEnc->current->mbs[0].quant);
1497    
1498          pEnc->current->sStat.iTextBits = 0;          pEnc->current->sStat.iTextBits = 0;
1499            pEnc->current->sStat.iMVBits = 0;
1500          pEnc->current->sStat.kblks = mb_width * mb_height;          pEnc->current->sStat.kblks = mb_width * mb_height;
1501          pEnc->current->sStat.mblks = pEnc->current->sStat.ublks = 0;          pEnc->current->sStat.mblks = pEnc->current->sStat.ublks = 0;
1502    
# Line 1535  Line 1571 
1571          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
1572    
1573          int x, y, k;          int x, y, k;
         int skip_possible;  
1574          FRAMEINFO *const current = pEnc->current;          FRAMEINFO *const current = pEnc->current;
1575          FRAMEINFO *const reference = pEnc->reference;          FRAMEINFO *const reference = pEnc->reference;
1576          MBParam * const pParam = &pEnc->mbParam;          MBParam * const pParam = &pEnc->mbParam;
# Line 1560  Line 1595 
1595          if ((current->vop_flags & XVID_VOP_HALFPEL)) {          if ((current->vop_flags & XVID_VOP_HALFPEL)) {
1596                  if (reference->is_interpolated != current->rounding_type) {                  if (reference->is_interpolated != current->rounding_type) {
1597                          start_timer();                          start_timer();
1598                          image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV,                          image_interpolate(pRef->y, pEnc->vInterH.y, pEnc->vInterV.y,
1599                                                            &pEnc->vInterHV, pParam->edged_width,                                                            pEnc->vInterHV.y, pParam->edged_width,
1600                                                            pParam->edged_height,                                                            pParam->edged_height,
1601                                                            (pParam->vol_flags & XVID_VOL_QUARTERPEL),                                                            (pParam->vol_flags & XVID_VOL_QUARTERPEL),
1602                                                            current->rounding_type);                                                            current->rounding_type);
# Line 1571  Line 1606 
1606          }          }
1607    
1608          current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount =          current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount =
1609                  current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0;                  current->sStat.kblks = current->sStat.mblks = current->sStat.ublks =
1610                    current->sStat.iMVBits = 0;
1611    
1612          current->coding_type = P_VOP;          current->coding_type = P_VOP;
1613    
# Line 1643  Line 1679 
1679    
1680          for (y = 0; y < mb_height; y++) {          for (y = 0; y < mb_height; y++) {
1681                  for (x = 0; x < mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
1682                          MACROBLOCK *pMB =                          MACROBLOCK *pMB = &current->mbs[x + y * pParam->mb_width];
1683                                  &current->mbs[x + y * pParam->mb_width];                          int skip_possible;
1684    
1685                          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) {                          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) {
1686                                  CodeIntraMB(pEnc, pMB);                                  CodeIntraMB(pEnc, pMB);
# Line 1698  Line 1734 
1734    
1735                          /* Finished processing the MB, now check if to CODE or SKIP */                          /* Finished processing the MB, now check if to CODE or SKIP */
1736    
1737                          skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER) &&                          skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER);
                                                         (pMB->dquant == 0);  
1738    
1739                          if (current->coding_type == S_VOP)                          if (current->coding_type == S_VOP)
1740                                  skip_possible &= (pMB->mcsel == 1);                                  skip_possible &= (pMB->mcsel == 1);
1741                          else if (current->coding_type == P_VOP) {                          else { /* PVOP */
1742                                  if ((pParam->vol_flags & XVID_VOL_QUARTERPEL))                                  const VECTOR * const mv = (pParam->vol_flags & XVID_VOL_QUARTERPEL) ?
1743                                          skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) );                                                                                  pMB->qmvs : pMB->mvs;
1744                                  else                                  skip_possible &= ((mv->x|mv->y) == 0);
                                         skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) );  
1745                          }                          }
1746    
1747                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {
   
1748  /* 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 */  
                                 {  
1749                                          int bSkip = 1;                                          int bSkip = 1;
1750    
1751                                          for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++)                                  if (current->coding_type == P_VOP) {    /* special rule for P-VOP's SKIP */
1752                                          {  
1753                                            for (k = pEnc->bframenum_head; k < pEnc->bframenum_tail; k++) {
1754                                                  int iSAD;                                                  int iSAD;
1755                                                  iSAD = sad16(reference->image.y + 16*y*pParam->edged_width + 16*x,                                                  iSAD = sad16(reference->image.y + 16*y*pParam->edged_width + 16*x,
1756                                                                          pEnc->bframes[k]->image.y + 16*y*pParam->edged_width + 16*x,                                                                          pEnc->bframes[k]->image.y + 16*y*pParam->edged_width + 16*x,
1757                                                                  pParam->edged_width,BFRAME_SKIP_THRESHHOLD);                                                                                  pParam->edged_width, BFRAME_SKIP_THRESHHOLD * pMB->quant);
1758                                                  if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant)                                                  if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant) {
1759                                                  {       bSkip = 0;                                                          bSkip = 0; /* could not SKIP */
1760                                                          break;                                                          if (pParam->vol_flags & XVID_VOL_QUARTERPEL) {
                                                 }  
                                         }  
   
                                         if (!bSkip) {   /* no SKIP, but trivial block */  
                                                 if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) {  
1761                                                          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);
1762                                                          pMB->pmvs[0].x = - predMV.x;                                                          pMB->pmvs[0].x = - predMV.x;
1763                                                          pMB->pmvs[0].y = - predMV.y;                                                          pMB->pmvs[0].y = - predMV.y;
1764                                                  }                                                          } else {
                                                 else {  
1765                                                          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);
1766                                                          pMB->pmvs[0].x = - predMV.x;                                                          pMB->pmvs[0].x = - predMV.x;
1767                                                          pMB->pmvs[0].y = - predMV.y;                                                          pMB->pmvs[0].y = - predMV.y;
1768                                                  }                                                  }
1769                                                  pMB->mode = MODE_INTER;                                                  pMB->mode = MODE_INTER;
1770                                                  pMB->cbp = 0;                                                  pMB->cbp = 0;
1771                                                  MBCoding(current, pMB, qcoeff, bs, &current->sStat);                                                          break;
1772                                                  stop_coding_timer();                                                  }
   
                                                 continue;       /* next MB */  
1773                                          }                                          }
1774                                  }                                  }
                                 /* do SKIP */  
1775    
1776                                    if (bSkip) {
1777                                            /* do SKIP */
1778                                  pMB->mode = MODE_NOT_CODED;                                  pMB->mode = MODE_NOT_CODED;
1779                                  MBSkip(bs);                                  MBSkip(bs);
1780                                  stop_coding_timer();                                  stop_coding_timer();
1781                                  continue;       /* next MB */                                  continue;       /* next MB */
1782                          }                          }
                         /* 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);  
                                         }  
   
                                 }  
1783                          }                          }
1784    
1785                            /* ordinary case: normal coded INTER/INTER4V block */
1786                          MBCoding(current, pMB, qcoeff, bs, &pEnc->current->sStat);                          MBCoding(current, pMB, qcoeff, bs, &pEnc->current->sStat);
1787                          stop_coding_timer();                          stop_coding_timer();
   
1788                  }                  }
1789          }          }
1790    
# Line 1807  Line 1799 
1799                  (pParam->frame_drop_ratio * mb_width * mb_height) / 100 &&                  (pParam->frame_drop_ratio * mb_width * mb_height) / 100 &&
1800                  ( (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)) )
1801          {          {
1802                  current->sStat.kblks = current->sStat.mblks = 0;                  current->sStat.kblks = current->sStat.mblks = current->sStat.iTextBits = 0;
1803                  current->sStat.ublks = mb_width * mb_height;                  current->sStat.ublks = mb_width * mb_height;
1804    
1805                  BitstreamReset(bs);                  BitstreamReset(bs);
# Line 1897  Line 1889 
1889    
1890          if (pEnc->reference->is_interpolated != 0) {          if (pEnc->reference->is_interpolated != 0) {
1891                  start_timer();                  start_timer();
1892                  image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,                  image_interpolate(f_ref->y, pEnc->f_refh.y, pEnc->f_refv.y, pEnc->f_refhv.y,
1893                                                    pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                                    pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1894                                                    (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);                                                    (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);
1895                  stop_inter_timer();                  stop_inter_timer();
# Line 1914  Line 1906 
1906    
1907          if (pEnc->current->is_interpolated != 0) {          if (pEnc->current->is_interpolated != 0) {
1908                  start_timer();                  start_timer();
1909                  image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,                  image_interpolate(b_ref->y, pEnc->vInterH.y, pEnc->vInterV.y, pEnc->vInterHV.y,
1910                                                  pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                                  pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1911                                                  (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);                                                  (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0);
1912                  stop_inter_timer();                  stop_inter_timer();
# Line 1922  Line 1914 
1914          }          }
1915    
1916          frame->coding_type = B_VOP;          frame->coding_type = B_VOP;
1917          call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL);          call_plugins(pEnc, frame, NULL, XVID_PLG_FRAME, NULL, NULL, NULL);
1918    
1919          start_timer();          start_timer();
1920          MotionEstimationBVOP(&pEnc->mbParam, frame,          MotionEstimationBVOP(&pEnc->mbParam, frame,
# Line 1938  Line 1930 
1930          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1, frame->quant);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1, frame->quant);
1931    
1932          frame->sStat.iTextBits = 0;          frame->sStat.iTextBits = 0;
1933            frame->sStat.iMVBits = 0;
1934          frame->sStat.iMvSum = 0;          frame->sStat.iMvSum = 0;
1935          frame->sStat.iMvCount = 0;          frame->sStat.iMvCount = 0;
1936          frame->sStat.kblks = frame->sStat.mblks = frame->sStat.ublks = 0;          frame->sStat.kblks = frame->sStat.mblks = frame->sStat.ublks = 0;

Legend:
Removed from v.1573  
changed lines
  Added in v.1680

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