[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.103, Tue Mar 30 12:31:52 2004 UTC revision 1.117, Sun Mar 27 03:59:42 2005 UTC
# Line 57  Line 57 
57                                            Bitstream * bs);                                            Bitstream * bs);
58    
59  static int FrameCodeP(Encoder * pEnc,  static int FrameCodeP(Encoder * pEnc,
60                                            Bitstream * bs,                                            Bitstream * bs);
                                           bool force_inter,  
                                           bool vol_header);  
61    
62  static void FrameCodeB(Encoder * pEnc,  static void FrameCodeB(Encoder * pEnc,
63                                             FRAMEINFO * frame,                                             FRAMEINFO * frame,
# Line 102  Line 100 
100                  i--;                  i--;
101          }          }
102    
103          /* if neccessary, round to 65535 accuracy */          if (*base > 65535 || *inc > 65535) {
104          if (*base > 65535) {                  int *biggest;
105                  float div = (float) *base / 65535;                  int *other;
106                  *base = (int) (*base / div);                  float div;
107                  *inc = (int) (*inc / div);  
108                    if (*base > *inc) {
109                            biggest = base;
110                            other = inc;
111                    } else {
112                            biggest = inc;
113                            other = base;
114                    }
115    
116                    div = ((float)*biggest)/((float)65535);
117                    *biggest = (int)(((float)*biggest)/div);
118                    *other = (int)(((float)*other)/div);
119          }          }
120  }  }
121    
# Line 137  Line 146 
146    
147          /* global flags */          /* global flags */
148          pEnc->mbParam.global_flags = create->global;          pEnc->mbParam.global_flags = create->global;
149      if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED))
150        pEnc->mbParam.global_flags |= XVID_GLOBAL_DIVX5_USERDATA;
151    
152          /* width, height */          /* width, height */
153          pEnc->mbParam.width = create->width;          pEnc->mbParam.width = create->width;
# Line 1091  Line 1102 
1102                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
1103                                  pEnc->mbParam.frame_drop_ratio = -1; /* it must be a coded vop */                                  pEnc->mbParam.frame_drop_ratio = -1; /* it must be a coded vop */
1104    
1105                                  FrameCodeP(pEnc, &bs, 1, 0);                                  FrameCodeP(pEnc, &bs);
1106    
1107    
1108                                  if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) {                                  if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) {
# Line 1247  Line 1258 
1258                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);
1259    
1260                  if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {                  if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {
1261                          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");
1262                  }                  }
1263    
1264                  /* convert B-VOP quant to P-VOP */                  /* convert B-VOP quant to P-VOP */
# Line 1308  Line 1319 
1319    
1320                  /* prevent vol/vop misuse */                  /* prevent vol/vop misuse */
1321    
                 if (!(pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE))  
                         pEnc->current->vop_flags &= ~XVID_VOP_REDUCED;  
   
1322                  if (!(pEnc->current->vol_flags & XVID_VOL_INTERLACING))                  if (!(pEnc->current->vol_flags & XVID_VOL_INTERLACING))
1323                          pEnc->current->vop_flags &= ~(XVID_VOP_TOPFIELDFIRST|XVID_VOP_ALTERNATESCAN);                          pEnc->current->vop_flags &= ~(XVID_VOP_TOPFIELDFIRST|XVID_VOP_ALTERNATESCAN);
1324    
# Line 1343  Line 1351 
1351                                     pEnc->mbParam.edged_width, pEnc->mbParam.height);                                     pEnc->mbParam.edged_width, pEnc->mbParam.height);
1352                  }                  }
1353    
1354                  if ( FrameCodeP(pEnc, &bs, 1, 0) == 0 ) {                  if ( FrameCodeP(pEnc, &bs) == 0 ) {
1355                          /* N-VOP, we mustn't code b-frames yet */                          /* N-VOP, we mustn't code b-frames yet */
1356                          call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);                          call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats);
1357                          goto done;                          goto done;
# Line 1438  Line 1446 
1446    
1447          uint16_t x, y;          uint16_t x, y;
1448    
         if ((pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE))  
         {  
                 mb_width = (pEnc->mbParam.width + 31) / 32;  
                 mb_height = (pEnc->mbParam.height + 31) / 32;  
   
                 /* 16x16->8x8 downsample requires 1 additional edge pixel*/  
                 /* XXX: setedges is overkill */  
                 start_timer();  
                 image_setedges(&pEnc->current->image,  
                         pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,  
                         pEnc->mbParam.width, pEnc->mbParam.height, 0);  
                 stop_edges_timer();  
         }  
   
1449          pEnc->mbParam.m_rounding_type = 1;          pEnc->mbParam.m_rounding_type = 1;
1450          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;
1451          pEnc->current->coding_type = I_VOP;          pEnc->current->coding_type = I_VOP;
# Line 1487  Line 1481 
1481                          stop_prediction_timer();                          stop_prediction_timer();
1482    
1483                          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;  
                         }  
1484                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);
1485                          stop_coding_timer();                          stop_coding_timer();
1486                  }                  }
1487    
         if ((pEnc->current->vop_flags & XVID_VOP_REDUCED))  
         {  
                 image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width,  
                         pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width,  
                         16, 0);  
         }  
1488          emms();          emms();
1489    
1490          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */
# Line 1517  Line 1500 
1500          return 1;                                       /* intra */          return 1;                                       /* intra */
1501  }  }
1502    
1503    static __inline void
1504    updateFcode(Statistics * sStat, Encoder * pEnc)
1505    {
1506            float fSigma;
1507            int iSearchRange;
1508    
1509  #define INTRA_THRESHOLD 0.5          if (sStat->iMvCount == 0)
1510  #define BFRAME_SKIP_THRESHHOLD 30                  sStat->iMvCount = 1;
1511    
1512            fSigma = (float) sqrt((float) sStat->iMvSum / sStat->iMvCount);
1513    
1514            iSearchRange = 16 << pEnc->mbParam.m_fcode;
1515    
1516            if ((3.0 * fSigma > iSearchRange) && (pEnc->mbParam.m_fcode <= 5) )
1517                    pEnc->mbParam.m_fcode++;
1518    
1519            else if ((5.0 * fSigma < iSearchRange)
1520                               && (4.0 * pEnc->fMvPrevSigma < iSearchRange)
1521                               && (pEnc->mbParam.m_fcode >= 2) )
1522                    pEnc->mbParam.m_fcode--;
1523    
1524            pEnc->fMvPrevSigma = fSigma;
1525    }
1526    
1527    #define BFRAME_SKIP_THRESHHOLD 30
1528    
1529  /* FrameCodeP also handles S(GMC)-VOPs */  /* FrameCodeP also handles S(GMC)-VOPs */
1530  static int  static int
1531  FrameCodeP(Encoder * pEnc,  FrameCodeP(Encoder * pEnc,
1532                     Bitstream * bs,                     Bitstream * bs)
                    bool force_inter,  
                    bool vol_header)  
1533  {  {
         float fSigma;  
1534          int bits = BitstreamPos(bs);          int bits = BitstreamPos(bs);
1535    
1536          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);
1537          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
1538    
         int iLimit;  
1539          int x, y, k;          int x, y, k;
         int iSearchRange;  
         int bIntra=0, skip_possible;  
1540          FRAMEINFO *const current = pEnc->current;          FRAMEINFO *const current = pEnc->current;
1541          FRAMEINFO *const reference = pEnc->reference;          FRAMEINFO *const reference = pEnc->reference;
1542          MBParam * const pParam = &pEnc->mbParam;          MBParam * const pParam = &pEnc->mbParam;
# Line 1546  Line 1544 
1544          int mb_height = pParam->mb_height;          int mb_height = pParam->mb_height;
1545          int coded = 1;          int coded = 1;
1546    
   
         /* IMAGE *pCurrent = &current->image; */  
1547          IMAGE *pRef = &reference->image;          IMAGE *pRef = &reference->image;
1548    
         if ((current->vop_flags & XVID_VOP_REDUCED))  
         {  
                 mb_width = (pParam->width + 31) / 32;  
                 mb_height = (pParam->height + 31) / 32;  
         }  
   
   
1549          if (!reference->is_edged) {          if (!reference->is_edged) {
1550                  start_timer();                  start_timer();
1551                  image_setedges(pRef, pParam->edged_width, pParam->edged_height,                  image_setedges(pRef, pParam->edged_width, pParam->edged_height,
# Line 1569  Line 1558 
1558          current->rounding_type = pParam->m_rounding_type;          current->rounding_type = pParam->m_rounding_type;
1559          current->fcode = pParam->m_fcode;          current->fcode = pParam->m_fcode;
1560    
         if (!force_inter)  
                 iLimit = (int)(mb_width * mb_height *  INTRA_THRESHOLD);  
         else  
                 iLimit = mb_width * mb_height + 1;  
   
1561          if ((current->vop_flags & XVID_VOP_HALFPEL)) {          if ((current->vop_flags & XVID_VOP_HALFPEL)) {
1562                  if (reference->is_interpolated != current->rounding_type) {                  if (reference->is_interpolated != current->rounding_type) {
1563                          start_timer();                          start_timer();
# Line 1587  Line 1571 
1571                  }                  }
1572          }          }
1573    
1574            current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount =
1575                    current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0;
1576    
1577          current->coding_type = P_VOP;          current->coding_type = P_VOP;
1578    
1579          call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL);          call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL);
# Line 1644  Line 1631 
1631                  }                  }
1632          }          }
1633    
         bIntra =  
1634                  MotionEstimation(&pEnc->mbParam, current, reference,                  MotionEstimation(&pEnc->mbParam, current, reference,
1635                                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,                                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
1636                                           &pEnc->vGMC, iLimit);                                           &pEnc->vGMC, 256*4096);
1637    
1638    
1639          stop_motion_timer();          stop_motion_timer();
1640    
         if (bIntra == 1) return FrameCodeI(pEnc, bs);  
   
1641          set_timecodes(current,reference,pParam->fbase);          set_timecodes(current,reference,pParam->fbase);
         if (vol_header)  
         {       BitstreamWriteVolHeader(bs, &pEnc->mbParam, current);  
                 BitstreamPad(bs);  
         }  
1642    
1643          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant);
1644    
         current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount =  
                 current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0;  
   
   
1645          for (y = 0; y < mb_height; y++) {          for (y = 0; y < mb_height; y++) {
1646                  for (x = 0; x < mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
1647                          MACROBLOCK *pMB =                          MACROBLOCK *pMB = &current->mbs[x + y * pParam->mb_width];
1648                                  &current->mbs[x + y * pParam->mb_width];                          int skip_possible;
1649    
1650                          bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q);                          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) {
   
                         if (bIntra) {  
1651                                  CodeIntraMB(pEnc, pMB);                                  CodeIntraMB(pEnc, pMB);
1652                                  MBTransQuantIntra(&pEnc->mbParam, current, pMB, x, y,                                  MBTransQuantIntra(&pEnc->mbParam, current, pMB, x, y,
1653                                                                    dct_codes, qcoeff);                                                                    dct_codes, qcoeff);
# Line 1684  Line 1658 
1658    
1659                                  current->sStat.kblks++;                                  current->sStat.kblks++;
1660    
                                 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;  
                                 }  
1661                                  MBCoding(current, pMB, qcoeff, bs, &current->sStat);                                  MBCoding(current, pMB, qcoeff, bs, &current->sStat);
1662                                  stop_coding_timer();                                  stop_coding_timer();
1663                                  continue;                                  continue;
# Line 1703  Line 1672 
1672                                                                   pParam->height,                                                                   pParam->height,
1673                                                                   pParam->edged_width,                                                                   pParam->edged_width,
1674                                                                   (current->vol_flags & XVID_VOL_QUARTERPEL),                                                                   (current->vol_flags & XVID_VOL_QUARTERPEL),
                                                                  (current->vop_flags & XVID_VOP_REDUCED),  
1675                                                                   current->rounding_type);                                                                   current->rounding_type);
1676    
1677                          stop_comp_timer();                          stop_comp_timer();
1678    
1679                          pMB->field_pred = 0;                          pMB->field_pred = 0;
1680    
1681                          if (pMB->mode != MODE_NOT_CODED)                          if (pMB->cbp != 0) {
1682                          {       pMB->cbp =                                  pMB->cbp = MBTransQuantInter(&pEnc->mbParam, current, pMB, x, y,
                                         MBTransQuantInter(&pEnc->mbParam, current, pMB, x, y,  
1683                                                                            dct_codes, qcoeff);                                                                            dct_codes, qcoeff);
1684                          }                          }
1685    
# Line 1732  Line 1699 
1699    
1700                          /* Finished processing the MB, now check if to CODE or SKIP */                          /* Finished processing the MB, now check if to CODE or SKIP */
1701    
1702                          skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER) &&                          skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER);
                                                         (pMB->dquant == 0);  
1703    
1704                          if (current->coding_type == S_VOP)                          if (current->coding_type == S_VOP)
1705                                  skip_possible &= (pMB->mcsel == 1);                                  skip_possible &= (pMB->mcsel == 1);
1706                          else if (current->coding_type == P_VOP) {                          else { /* PVOP */
1707                                  if ((pParam->vol_flags & XVID_VOL_QUARTERPEL))                                  const VECTOR * const mv = (pParam->vol_flags & XVID_VOL_QUARTERPEL) ?
1708                                          skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) );                                                                                  pMB->qmvs : pMB->mvs;
1709                                  else                                  skip_possible &= ((mv->x|mv->y) == 0);
                                         skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) );  
1710                          }                          }
1711    
1712                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {
   
1713  /* 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 */  
                                 {  
1714                                          int bSkip = 1;                                          int bSkip = 1;
1715    
1716                                          for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++)                                  if (current->coding_type == P_VOP) {    /* special rule for P-VOP's SKIP */
1717                                          {  
1718                                            for (k = pEnc->bframenum_head; k < pEnc->bframenum_tail; k++) {
1719                                                  int iSAD;                                                  int iSAD;
1720                                                  iSAD = sad16(reference->image.y + 16*y*pParam->edged_width + 16*x,                                                  iSAD = sad16(reference->image.y + 16*y*pParam->edged_width + 16*x,
1721                                                                          pEnc->bframes[k]->image.y + 16*y*pParam->edged_width + 16*x,                                                                          pEnc->bframes[k]->image.y + 16*y*pParam->edged_width + 16*x,
1722                                                                  pParam->edged_width,BFRAME_SKIP_THRESHHOLD);                                                                                  pParam->edged_width, BFRAME_SKIP_THRESHHOLD * pMB->quant);
1723                                                  if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant)                                                  if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant) {
1724                                                  {       bSkip = 0;                                                          bSkip = 0; /* could not SKIP */
1725                                                          break;                                                          if (pParam->vol_flags & XVID_VOL_QUARTERPEL) {
                                                 }  
                                         }  
   
                                         if (!bSkip) {   /* no SKIP, but trivial block */  
                                                 if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) {  
1726                                                          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);
1727                                                          pMB->pmvs[0].x = - predMV.x;                                                          pMB->pmvs[0].x = - predMV.x;
1728                                                          pMB->pmvs[0].y = - predMV.y;                                                          pMB->pmvs[0].y = - predMV.y;
1729                                                  }                                                          } else {
                                                 else {  
1730                                                          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);
1731                                                          pMB->pmvs[0].x = - predMV.x;                                                          pMB->pmvs[0].x = - predMV.x;
1732                                                          pMB->pmvs[0].y = - predMV.y;                                                          pMB->pmvs[0].y = - predMV.y;
1733                                                  }                                                  }
1734                                                  pMB->mode = MODE_INTER;                                                  pMB->mode = MODE_INTER;
1735                                                  pMB->cbp = 0;                                                  pMB->cbp = 0;
1736                                                  MBCoding(current, pMB, qcoeff, bs, &current->sStat);                                                          break;
1737                                                  stop_coding_timer();                                                  }
   
                                                 continue;       /* next MB */  
1738                                          }                                          }
1739                                  }                                  }
                                 /* do SKIP */  
1740    
1741                                    if (bSkip) {
1742                                            /* do SKIP */
1743                                  pMB->mode = MODE_NOT_CODED;                                  pMB->mode = MODE_NOT_CODED;
1744                                  MBSkip(bs);                                  MBSkip(bs);
1745                                  stop_coding_timer();                                  stop_coding_timer();
1746                                  continue;       /* next MB */                                  continue;       /* next MB */
1747                          }                          }
                         /* 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);  
                                         }  
   
                                 }  
1748                          }                          }
1749    
1750                            /* ordinary case: normal coded INTER/INTER4V block */
1751                          MBCoding(current, pMB, qcoeff, bs, &pEnc->current->sStat);                          MBCoding(current, pMB, qcoeff, bs, &pEnc->current->sStat);
1752                          stop_coding_timer();                          stop_coding_timer();
   
                 }  
1753          }          }
   
         if ((current->vop_flags & XVID_VOP_REDUCED))  
         {  
                 image_deblock_rrv(&current->image, pParam->edged_width,  
                         current->mbs, mb_width, mb_height, pParam->mb_width,  
                         16, 0);  
1754          }          }
1755    
1756          emms();          emms();
1757            updateFcode(&current->sStat, pEnc);
         if (current->sStat.iMvCount == 0)  
                 current->sStat.iMvCount = 1;  
   
         fSigma = (float) sqrt((float) current->sStat.iMvSum / current->sStat.iMvCount);  
   
         iSearchRange = 1 << (3 + pParam->m_fcode);  
   
         if ((fSigma > iSearchRange / 3)  
                 && (pParam->m_fcode <= (3 +  (pParam->vol_flags & XVID_VOL_QUARTERPEL?1:0)  ))) /* maximum search range 128 */  
         {  
                 pParam->m_fcode++;  
                 iSearchRange *= 2;  
         } else if ((fSigma < iSearchRange / 6)  
                            && (pEnc->fMvPrevSigma >= 0)  
                            && (pEnc->fMvPrevSigma < iSearchRange / 6)  
                            && (pParam->m_fcode >= (2 + (pParam->vol_flags & XVID_VOL_QUARTERPEL?1:0) )))        /* minimum search range 16 */  
         {  
                 pParam->m_fcode--;  
                 iSearchRange /= 2;  
         }  
   
         pEnc->fMvPrevSigma = fSigma;  
1758    
1759          /* frame drop code */          /* frame drop code */
1760  #if 0  #if 0
1761          DPRINTF(XVID_DEBUG_DEBUG, "kmu %i %i %i\n", current->sStat.kblks, current->sStat.mblks, current->sStat.ublks);          DPRINTF(XVID_DEBUG_DEBUG, "kmu %i %i %i\n", current->sStat.kblks, current->sStat.mblks, current->sStat.ublks);
1762  #endif  #endif
1763          if (current->sStat.kblks + current->sStat.mblks <=          if (current->sStat.kblks + current->sStat.mblks <=
1764                  (pParam->frame_drop_ratio * mb_width * mb_height) / 100)                  (pParam->frame_drop_ratio * mb_width * mb_height) / 100 &&
1765                    ( (pEnc->bframenum_head >= pEnc->bframenum_tail) || !(pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP)) )
1766          {          {
1767                  current->sStat.kblks = current->sStat.mblks = 0;                  current->sStat.kblks = current->sStat.mblks = 0;
1768                  current->sStat.ublks = mb_width * mb_height;                  current->sStat.ublks = mb_width * mb_height;
# Line 1950  Line 1839 
1839                  fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mode,mb->cbp); \                  fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mode,mb->cbp); \
1840          }          }
1841    
         /* XXX: pEnc->current->global_flags &= ~XVID_VOP_REDUCED;  reduced resoltion not yet supported */  
   
1842          if (!first){          if (!first){
1843                  fp=fopen("C:\\XVIDDBGE.TXT","w");                  fp=fopen("C:\\XVIDDBGE.TXT","w");
1844          }          }
# Line 2022  Line 1909 
1909                          if (mb->mode == MODE_NOT_CODED) {                          if (mb->mode == MODE_NOT_CODED) {
1910                                  if (pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) {                                  if (pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) {
1911                                          MBMotionCompensation(mb, x, y, f_ref, NULL, f_ref, NULL, NULL, &frame->image,                                          MBMotionCompensation(mb, x, y, f_ref, NULL, f_ref, NULL, NULL, &frame->image,
1912                                                                                          NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0, 0);                                                                                          NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0);
1913                                  }                                  }
   
1914                                  continue;                                  continue;
1915                          }                          }
1916    
1917                          if (mb->mode != MODE_DIRECT_NONE_MV || pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) {                          mb->quant = frame->quant;
1918    
1919                            if (mb->cbp != 0 || pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) {
1920                                    /* we have to motion-compensate, transfer etc,
1921                                            because there might be blocks to code */
1922    
1923                                  MBMotionCompensationBVOP(&pEnc->mbParam, mb, x, y, &frame->image,                                  MBMotionCompensationBVOP(&pEnc->mbParam, mb, x, y, &frame->image,
1924                                                                           f_ref, &pEnc->f_refh, &pEnc->f_refv,                                                                           f_ref, &pEnc->f_refh, &pEnc->f_refv,
1925                                                                           &pEnc->f_refhv, b_ref, &pEnc->vInterH,                                                                           &pEnc->f_refhv, b_ref, &pEnc->vInterH,
1926                                                                           &pEnc->vInterV, &pEnc->vInterHV,                                                                           &pEnc->vInterV, &pEnc->vInterHV,
1927                                                                           dct_codes);                                                                           dct_codes);
1928    
                                 if (mb->mode == MODE_DIRECT_NO4V) mb->mode = MODE_DIRECT;  
                                 mb->quant = frame->quant;  
   
                                 if (mb->mode != MODE_DIRECT_NONE_MV)  
1929                                          mb->cbp = MBTransQuantInterBVOP(&pEnc->mbParam, frame, mb, x, y,  dct_codes, qcoeff);                                          mb->cbp = MBTransQuantInterBVOP(&pEnc->mbParam, frame, mb, x, y,  dct_codes, qcoeff);
   
                                 if ( (mb->mode == MODE_DIRECT) && (mb->cbp == 0)  
                                         && (mb->pmvs[3].x == 0) && (mb->pmvs[3].y == 0) ) {  
                                         mb->mode = MODE_DIRECT_NONE_MV; /* skipped */  
                                 }  
1930                          }                          }
1931    
1932                          /* keep only bits 5-2 -- Chroma blocks will just be skipped by the                          if (mb->mode == MODE_DIRECT_NO4V)
1933                           * coding function for BFrames, that's why we don't zero teh DC                                  mb->mode = MODE_DIRECT;
1934                           * coeffs */  
1935                          if ((frame->vop_flags & XVID_VOP_GREYSCALE))                          if (mb->mode == MODE_DIRECT && (mb->cbp | mb->pmvs[3].x | mb->pmvs[3].y) == 0)
1936                                    mb->mode = MODE_DIRECT_NONE_MV; /* skipped */
1937                            else
1938                                    if (frame->vop_flags & XVID_VOP_GREYSCALE)
1939                                            /* keep only bits 5-2 -- Chroma blocks will just be skipped by MBCodingBVOP */
1940                                  mb->cbp &= 0x3C;                                  mb->cbp &= 0x3C;
1941    
1942                          start_timer();                          start_timer();
# Line 2062  Line 1948 
1948    
1949          emms();          emms();
1950    
         /* TODO: dynamic fcode/bcode ??? */  
   
1951          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */
1952          frame->length = (BitstreamPos(bs) - bits) / 8;          frame->length = (BitstreamPos(bs) - bits) / 8;
1953    

Legend:
Removed from v.1.103  
changed lines
  Added in v.1.117

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