[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.92, Sat Feb 15 18:48:15 2003 UTC revision 1.95, Wed Feb 19 21:30:52 2003 UTC
# Line 26  Line 26 
26   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
27   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
28   *   *
  ****************************************************************************/  
   
 /*****************************************************************************  
  *  
  *  History  
  *  
  *  10.07.2002  added BFRAMES_DEC_DEBUG support  
  *              MinChen <chenm001@163.com>  
  *  20.06.2002 bframe patch  
  *  08.05.2002 fix some problem in DEBUG mode;  
  *             MinChen <chenm001@163.com>  
  *  14.04.2002 added FrameCodeB()  
  *  
29   *  $Id$   *  $Id$
30   *   *
31   ****************************************************************************/   ****************************************************************************/
# Line 605  Line 592 
592    
593  static __inline void inc_frame_num(Encoder * pEnc)  static __inline void inc_frame_num(Encoder * pEnc)
594  {  {
595          pEnc->current->stamp = pEnc->mbParam.m_stamp;   // first frame is zero          pEnc->current->stamp = pEnc->mbParam.m_stamp;   /* first frame is zero */
596          pEnc->mbParam.m_stamp += pEnc->mbParam.fincr;          pEnc->mbParam.m_stamp += pEnc->mbParam.fincr;
597  }  }
598    
# Line 647  Line 634 
634                  pCur->ticks = (int32_t)pCur->stamp % time_base;                  pCur->ticks = (int32_t)pCur->stamp % time_base;
635                  pCur->seconds =  ((int32_t)pCur->stamp / time_base)     - ((int32_t)pRef->stamp / time_base) ;                  pCur->seconds =  ((int32_t)pCur->stamp / time_base)     - ((int32_t)pRef->stamp / time_base) ;
636    
637                  //HEAVY DEBUG OUTPUT    remove when timecodes prove to be stable                  /* HEAVY DEBUG OUTPUT remove when timecodes prove to be stable */
638    
639  /*              fprintf(stderr,"WriteVop:   %d - %d \n",  /*              fprintf(stderr,"WriteVop:   %d - %d \n",
640                          ((int32_t)pCur->stamp / time_base), ((int32_t)pRef->stamp / time_base));                          ((int32_t)pCur->stamp / time_base), ((int32_t)pRef->stamp / time_base));
# Line 690  Line 677 
677          uint16_t x, y;          uint16_t x, y;
678          Bitstream bs;          Bitstream bs;
679          uint32_t bits;          uint32_t bits;
680          int mode;          int mode = -1; /* Just to shut up compiler warning */
681    
682          int input_valid = 1;          int input_valid = 1;
683          int bframes_count = 0;          int bframes_count = 0;
# Line 860  Line 847 
847                                  pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width);                                  pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width);
848                  }                  }
849    
850                  // queue input frame, and dequue next image                  /* queue input frame, and dequue next image */
851                  if (pEnc->queue_size > 0)                  if (pEnc->queue_size > 0)
852                  {                  {
853                          image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_tail]);                          image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_tail]);
# Line 891  Line 878 
878                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
879                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
880    
881                  //      BitstreamPutBits(&bs, 0x7f, 8);                          /* That disabled line of code was supposed to inform VirtualDub
882                             * that the frame was a dummy delay frame - now disabled (thx god :-)
883                             */
884                            /* BitstreamPutBits(&bs, 0x7f, 8); */
885                          pFrame->intra = 5;                          pFrame->intra = 5;
886    
887                          if (pResult) {                          if (pResult) {
# Line 937  Line 927 
927    
928          emms();          emms();
929    
930          // only inc frame num, adapt quant, etc. if we havent seen it before          /* only inc frame num, adapt quant, etc. if we havent seen it before */
931          if (pEnc->bframenum_dx50bvop < 0 )          if (pEnc->bframenum_dx50bvop < 0 )
932          {          {
933                  mode = intra2coding_type(pFrame->intra);                  mode = intra2coding_type(pFrame->intra);
# Line 1053  Line 1043 
1043                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP");
1044                  }                  }
1045    
1046                  // when we reach an iframe in DX50BVOP mode, encode the last bframe as a pframe                  /* when we reach an iframe in DX50BVOP mode, encode the last bframe as a pframe */
1047    
1048                  if ((pEnc->mbParam.global & XVID_GLOBAL_DX50BVOP) && pEnc->bframenum_tail > 0) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_DX50BVOP) && pEnc->bframenum_tail > 0) {
1049    
# Line 1145  Line 1135 
1135    
1136                  pEnc->bframenum_tail++;                  pEnc->bframenum_tail++;
1137    
1138  // bframe report by koepi                  /* bframe report by koepi */
1139                  pFrame->intra = 2;                  pFrame->intra = 2;
1140                  pFrame->length = 0;                  pFrame->length = 0;
1141    
# Line 1217  Line 1207 
1207          uint16_t write_vol_header = 0;          uint16_t write_vol_header = 0;
1208    
1209          float psnr;          float psnr;
1210          uint8_t temp[128];          char temp[128];
1211    
1212          start_global_timer();          start_global_timer();
1213    
# Line 1349  Line 1339 
1339    
1340          }          }
1341    
1342  //      BitstreamPutBits(&bs, 0xFFFF, 16);          /* Relic from OpenDivX - now disabled
1343  //      BitstreamPutBits(&bs, 0xFFFF, 16);          BitstreamPutBits(&bs, 0xFFFF, 16);
1344            BitstreamPutBits(&bs, 0xFFFF, 16);
1345            */
1346    
1347          BitstreamPadAlways(&bs);          BitstreamPadAlways(&bs);
1348          pFrame->length = BitstreamLength(&bs);          pFrame->length = BitstreamLength(&bs);
1349    
# Line 1441  Line 1434 
1434                  return;                  return;
1435          }          }
1436    
1437          pEnc->current->fcode =          pEnc->current->fcode = (hint->rawhints) ?
1438                  (hint->rawhints) ? hint->mvhint.fcode : BitstreamGetBits(&bs,                  (uint32_t)hint->mvhint.fcode : BitstreamGetBits(&bs, FCODEBITS);
                                                                                                                                  FCODEBITS);  
1439    
1440          length = pEnc->current->fcode + 5;          length = pEnc->current->fcode + 5;
1441          high = 1 << (length - 1);          high = 1 << (length - 1);
# Line 1458  Line 1450 
1450                          VECTOR tmp;                          VECTOR tmp;
1451                          int vec;                          int vec;
1452    
1453                          pMB->mode =                          pMB->mode =     (hint->rawhints) ?
1454                                  (hint->rawhints) ? bhint->mode : BitstreamGetBits(&bs,                                  (uint32_t)bhint->mode : BitstreamGetBits(&bs, MODEBITS);
                                                                                                                                   MODEBITS);  
1455    
1456                          pMB->mode = (pMB->mode == MODE_INTER_Q) ? MODE_INTER : pMB->mode;                          pMB->mode = (pMB->mode == MODE_INTER_Q) ? MODE_INTER : pMB->mode;
1457                          pMB->mode = (pMB->mode == MODE_INTRA_Q) ? MODE_INTRA : pMB->mode;                          pMB->mode = (pMB->mode == MODE_INTRA_Q) ? MODE_INTRA : pMB->mode;
1458    
1459                          if (pMB->mode == MODE_INTER) {                          if (pMB->mode == MODE_INTER) {
1460                                  tmp.x =                                  tmp.x = (hint->rawhints) ?
1461                                          (hint->rawhints) ? bhint->mvs[0].x : BitstreamGetBits(&bs,                                          bhint->mvs[0].x : (int)BitstreamGetBits(&bs, length);
1462                                                                                                                                                    length);                                  tmp.y = (hint->rawhints) ?
1463                                  tmp.y =                                          bhint->mvs[0].y : (int)BitstreamGetBits(&bs, length);
                                         (hint->rawhints) ? bhint->mvs[0].y : BitstreamGetBits(&bs,  
                                                                                                                                                   length);  
1464                                  tmp.x -= (tmp.x >= high) ? high * 2 : 0;                                  tmp.x -= (tmp.x >= high) ? high * 2 : 0;
1465                                  tmp.y -= (tmp.y >= high) ? high * 2 : 0;                                  tmp.y -= (tmp.y >= high) ? high * 2 : 0;
1466    
# Line 1485  Line 1474 
1474                                  }                                  }
1475                          } else if (pMB->mode == MODE_INTER4V) {                          } else if (pMB->mode == MODE_INTER4V) {
1476                                  for (vec = 0; vec < 4; ++vec) {                                  for (vec = 0; vec < 4; ++vec) {
1477                                          tmp.x =                                          tmp.x = (hint->rawhints) ?
1478                                                  (hint->rawhints) ? bhint->mvs[vec].                                                  bhint->mvs[vec].x : (int)BitstreamGetBits(&bs, length);
1479                                                  x : BitstreamGetBits(&bs, length);                                          tmp.y = (hint->rawhints) ?
1480                                          tmp.y =                                                  bhint->mvs[vec].y : (int)BitstreamGetBits(&bs, length);
                                                 (hint->rawhints) ? bhint->mvs[vec].  
                                                 y : BitstreamGetBits(&bs, length);  
1481                                          tmp.x -= (tmp.x >= high) ? high * 2 : 0;                                          tmp.x -= (tmp.x >= high) ? high * 2 : 0;
1482                                          tmp.y -= (tmp.y >= high) ? high * 2 : 0;                                          tmp.y -= (tmp.y >= high) ? high * 2 : 0;
1483    
# Line 1501  Line 1488 
1488                                          pMB->pmvs[vec].x = pMB->mvs[vec].x - pred.x;                                          pMB->pmvs[vec].x = pMB->mvs[vec].x - pred.x;
1489                                          pMB->pmvs[vec].y = pMB->mvs[vec].y - pred.y;                                          pMB->pmvs[vec].y = pMB->mvs[vec].y - pred.y;
1490                                  }                                  }
1491                          } else                          // intra / stuffing / not_coded                          } else                          /* intra / stuffing / not_coded */
1492                          {                          {
1493                                  for (vec = 0; vec < 4; ++vec) {                                  for (vec = 0; vec < 4; ++vec) {
1494                                          pMB->mvs[vec].x = pMB->mvs[vec].y = 0;                                          pMB->mvs[vec].x = pMB->mvs[vec].y = 0;
# Line 1698  Line 1685 
1685                  HintedMEGet(pEnc, 1);                  HintedMEGet(pEnc, 1);
1686          }          }
1687    
1688          return 1;                                       // intra          return 1;                                       /* intra */
1689  }  }
1690    
1691    
# Line 2036  Line 2023 
2023          iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode);          iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode);
2024    
2025          if ((fSigma > iSearchRange / 3)          if ((fSigma > iSearchRange / 3)
2026                  && (pEnc->mbParam.m_fcode <= (3 + pEnc->mbParam.m_quarterpel))) // maximum search range 128                  && (pEnc->mbParam.m_fcode <= (3 + pEnc->mbParam.m_quarterpel))) /* maximum search range 128 */
2027          {          {
2028                  pEnc->mbParam.m_fcode++;                  pEnc->mbParam.m_fcode++;
2029                  iSearchRange *= 2;                  iSearchRange *= 2;
2030          } else if ((fSigma < iSearchRange / 6)          } else if ((fSigma < iSearchRange / 6)
2031                             && (pEnc->fMvPrevSigma >= 0)                             && (pEnc->fMvPrevSigma >= 0)
2032                             && (pEnc->fMvPrevSigma < iSearchRange / 6)                             && (pEnc->fMvPrevSigma < iSearchRange / 6)
2033                          && (pEnc->mbParam.m_fcode >= (2 + pEnc->mbParam.m_quarterpel))) // minimum search range 16                             && (pEnc->mbParam.m_fcode >= (2 + pEnc->mbParam.m_quarterpel)))      /* minimum search range 16 */
2034          {          {
2035                  pEnc->mbParam.m_fcode--;                  pEnc->mbParam.m_fcode--;
2036                  iSearchRange /= 2;                  iSearchRange /= 2;
# Line 2064  Line 2051 
2051                  set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);                  set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
2052                  BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 0);                  BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 0);
2053    
2054                  // copy reference frame details into the current frame                  /* copy reference frame details into the current frame */
2055                  pEnc->current->quant = pEnc->reference->quant;                  pEnc->current->quant = pEnc->reference->quant;
2056                  pEnc->current->motion_flags = pEnc->reference->motion_flags;                  pEnc->current->motion_flags = pEnc->reference->motion_flags;
2057                  pEnc->current->rounding_type = pEnc->reference->rounding_type;                  pEnc->current->rounding_type = pEnc->reference->rounding_type;
# Line 2093  Line 2080 
2080    
2081          *pBits = BitstreamPos(bs) - *pBits;          *pBits = BitstreamPos(bs) - *pBits;
2082    
2083          return 0;                                       // inter          return 0;                                       /* inter */
2084  }  }
2085    
2086    
# Line 2126  Line 2113 
2113    
2114          frame->quarterpel =  pEnc->mbParam.m_quarterpel;          frame->quarterpel =  pEnc->mbParam.m_quarterpel;
2115    
2116          // forward          /* forward  */
2117          image_setedges(f_ref, pEnc->mbParam.edged_width,          image_setedges(f_ref, pEnc->mbParam.edged_width,
2118                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,
2119                                     pEnc->mbParam.height);                                     pEnc->mbParam.height);
# Line 2136  Line 2123 
2123                                            pEnc->mbParam.m_quarterpel, 0);                                            pEnc->mbParam.m_quarterpel, 0);
2124          stop_inter_timer();          stop_inter_timer();
2125    
2126          // backward          /* backward */
2127          image_setedges(b_ref, pEnc->mbParam.edged_width,          image_setedges(b_ref, pEnc->mbParam.edged_width,
2128                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,
2129                                     pEnc->mbParam.height);                                     pEnc->mbParam.height);
# Line 2149  Line 2136 
2136          start_timer();          start_timer();
2137    
2138          MotionEstimationBVOP(&pEnc->mbParam, frame,          MotionEstimationBVOP(&pEnc->mbParam, frame,
2139                  ((int32_t)(pEnc->current->stamp - frame->stamp)),                               // time_bp                                                   ((int32_t)(pEnc->current->stamp - frame->stamp)),                              /* time_bp */
2140                  ((int32_t)(pEnc->current->stamp - pEnc->reference->stamp)),     // time_pp                                                   ((int32_t)(pEnc->current->stamp - pEnc->reference->stamp)),    /* time_pp */
2141                          pEnc->reference->mbs, f_ref,                          pEnc->reference->mbs, f_ref,
2142                                                   &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,                                                   &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,
2143                                                   pEnc->current, b_ref, &pEnc->vInterH,                                                   pEnc->current, b_ref, &pEnc->vInterH,
# Line 2159  Line 2146 
2146    
2147          stop_motion_timer();          stop_motion_timer();
2148    
2149          /*if (test_quant_type(&pEnc->mbParam, pEnc->current))          /*
2150             {          if (test_quant_type(&pEnc->mbParam, pEnc->current)) {
2151             BitstreamWriteVolHeader(bs, pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.quant_type);             BitstreamWriteVolHeader(bs, pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.quant_type);
2152             } */          }
2153            */
2154    
2155          frame->coding_type = B_VOP;          frame->coding_type = B_VOP;
2156    
# Line 2182  Line 2170 
2170                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];
2171                          int direction = pEnc->mbParam.global & XVID_ALTERNATESCAN ? 2 : 0;                          int direction = pEnc->mbParam.global & XVID_ALTERNATESCAN ? 2 : 0;
2172    
2173                          // decoder ignores mb when refence block is INTER(0,0), CBP=0                          /* decoder ignores mb when refence block is INTER(0,0), CBP=0 */
2174                          if (mb->mode == MODE_NOT_CODED) {                          if (mb->mode == MODE_NOT_CODED) {
2175                                  //mb->mvs[0].x = mb->mvs[0].y = mb->cbp = 0;                                  /* mb->mvs[0].x = mb->mvs[0].y = mb->cbp = 0; */
2176                                  continue;                                  continue;
2177                          }                          }
2178    
# Line 2203  Line 2191 
2191    
2192                                  if ( (mb->mode == MODE_DIRECT) && (mb->cbp == 0)                                  if ( (mb->mode == MODE_DIRECT) && (mb->cbp == 0)
2193                                          && (mb->pmvs[3].x == 0) && (mb->pmvs[3].y == 0) ) {                                          && (mb->pmvs[3].x == 0) && (mb->pmvs[3].y == 0) ) {
2194                                          mb->mode = MODE_DIRECT_NONE_MV; // skipped                                          mb->mode = MODE_DIRECT_NONE_MV; /* skipped */
2195                                  }                                  }
2196                          }                          }
2197    
# Line 2219  Line 2207 
2207    
2208          emms();          emms();
2209    
2210          // TODO: dynamic fcode/bcode ???          /* TODO: dynamic fcode/bcode ??? */
2211    
2212          *pBits = BitstreamPos(bs) - *pBits;          *pBits = BitstreamPos(bs) - *pBits;
2213    

Legend:
Removed from v.1.92  
changed lines
  Added in v.1.95

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