[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.76.2.25, Sun Dec 8 06:43:34 2002 UTC revision 1.76.2.33, Sun Jan 5 03:30:44 2003 UTC
# Line 73  Line 73 
73   ****************************************************************************/   ****************************************************************************/
74    
75  #define ENC_CHECK(X) if(!(X)) return XVID_ERR_FORMAT  #define ENC_CHECK(X) if(!(X)) return XVID_ERR_FORMAT
76  #define SWAP(A,B)    { void * tmp = A; A = B; B = tmp; }  #define SWAP(_T_,A,B)    { _T_ tmp = A; A = B; B = tmp; }
77    
78  /*****************************************************************************  /*****************************************************************************
79   * Local function prototypes   * Local function prototypes
# Line 231  Line 231 
231          pEnc->bitrate = pParam->rc_bitrate;          pEnc->bitrate = pParam->rc_bitrate;
232    
233          pEnc->iFrameNum = 0;          pEnc->iFrameNum = 0;
234          pEnc->iMaxKeyInterval = pParam->max_key_interval;          pEnc->mbParam.iMaxKeyInterval = pParam->max_key_interval;
235    
236          /* try to allocate frame memory */          /* try to allocate frame memory */
237    
# Line 324  Line 324 
324    
325          /* B Frames specific init */          /* B Frames specific init */
326    
327          pEnc->global = pParam->global;          pEnc->mbParam.global = pParam->global;
328          pEnc->mbParam.max_bframes = pParam->max_bframes;          pEnc->mbParam.max_bframes = pParam->max_bframes;
329          pEnc->bquant_ratio = pParam->bquant_ratio;          pEnc->mbParam.bquant_ratio = pParam->bquant_ratio;
330          pEnc->bquant_offset = pParam->bquant_offset;          pEnc->mbParam.bquant_offset = pParam->bquant_offset;
331          pEnc->frame_drop_ratio = pParam->frame_drop_ratio;          pEnc->mbParam.frame_drop_ratio = pParam->frame_drop_ratio;
332          pEnc->bframes = NULL;          pEnc->bframes = NULL;
333    
334          if (pEnc->mbParam.max_bframes > 0) {          if (pEnc->mbParam.max_bframes > 0) {
# Line 646  Line 646 
646    
647    
648    
649    /* convert pFrame->intra to coding_type */
650    static int intra2coding_type(int intra)
651    {
652            if (intra < 0)          return -1;
653            if (intra == 1)         return I_VOP;
654            if (intra == 2)         return B_VOP;
655    
656            return P_VOP;
657    }
658    
659    
660    
661  /*****************************************************************************  /*****************************************************************************
# Line 703  Line 713 
713                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
714    
715                          pEnc->bframenum_tail--;                          pEnc->bframenum_tail--;
716                          SWAP(pEnc->current, pEnc->reference);                          SWAP(FRAMEINFO *, pEnc->current, pEnc->reference);
717    
718                          SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);                          SWAP(FRAMEINFO *, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);
719    
720                          FrameCodeP(pEnc, &bs, &bits, 1, 0);                          FrameCodeP(pEnc, &bs, &bits, 1, 0);
721                          bframes_count = 0;                          bframes_count = 0;
# Line 749  Line 759 
759                     indentical to the future-referece frame.                     indentical to the future-referece frame.
760                  */                  */
761    
762                  if ((pEnc->global & XVID_GLOBAL_PACKED)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_PACKED)) {
763                          int tmp;                          int tmp;
764    
765                          DPRINTF(DPRINTF_DEBUG,"*** EMPTY bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",                          DPRINTF(DPRINTF_DEBUG,"*** EMPTY bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
# Line 781  Line 791 
791          if (pEnc->bframenum_dx50bvop != -1)          if (pEnc->bframenum_dx50bvop != -1)
792          {          {
793    
794                  SWAP(pEnc->current, pEnc->reference);                  SWAP(FRAMEINFO *, pEnc->current, pEnc->reference);
795                  SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]);                  SWAP(FRAMEINFO *, pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]);
796    
797                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) {
798                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 IVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 IVOP");
799                  }                  }
800    
# Line 796  Line 806 
806    
807          } else if (input_valid) {          } else if (input_valid) {
808    
809                  SWAP(pEnc->current, pEnc->reference);                  SWAP(FRAMEINFO *, pEnc->current, pEnc->reference);
810    
811                  start_timer();                  start_timer();
812                  if (image_input                  if (image_input
# Line 822  Line 832 
832    
833          } else if (pEnc->queue_size > 0) {          } else if (pEnc->queue_size > 0) {
834    
835                  SWAP(pEnc->current, pEnc->reference);                  SWAP(FRAMEINFO *, pEnc->current, pEnc->reference);
836    
837                  image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head]);                  image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head]);
838                  pEnc->queue_head =  (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes;                  pEnc->queue_head =  (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes;
# Line 855  Line 865 
865          // 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
866          if (pEnc->bframenum_dx50bvop < 0 )          if (pEnc->bframenum_dx50bvop < 0 )
867          {          {
868                    mode = intra2coding_type(pFrame->intra);
869                  if (pFrame->quant == 0)                  if (pFrame->quant == 0)
870                          pEnc->current->quant = RateControlGetQ(&pEnc->rate_control, 0);                          pEnc->current->quant = RateControlGetQ(&pEnc->rate_control, 0);
871                  else                  else
# Line 882  Line 893 
893    
894                  emms();                  emms();
895    
896                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) {
897                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5,                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5,
898                                  "%i  if:%i  st:%i", pEnc->m_framenum++, pEnc->iFrameNum, pEnc->current->stamp);                                  "%i  if:%i  st:%i", pEnc->m_framenum++, pEnc->iFrameNum, pEnc->current->stamp);
899                  }                  }
# Line 928  Line 939 
939           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
940          pEnc->iFrameNum++;          pEnc->iFrameNum++;
941    
942          if (pEnc->iFrameNum == 0 || pFrame->intra == 1 || pEnc->bframenum_dx50bvop >= 0 ||          if (pEnc->iFrameNum == 0 || pEnc->bframenum_dx50bvop >= 0 ||
943                  (pFrame->intra < 0 && pEnc->iMaxKeyInterval > 0 &&                  (mode < 0 && pEnc->mbParam.iMaxKeyInterval > 0 &&
944                   pEnc->iFrameNum >= pEnc->iMaxKeyInterval)                          pEnc->iFrameNum >= pEnc->mbParam.iMaxKeyInterval))
945                  || 2 == (mode = MEanalysis(&pEnc->reference->image, pEnc->current,          {
946                                                                          &pEnc->mbParam, pEnc->iMaxKeyInterval,                  mode = I_VOP;
947                                                                          (pFrame->intra < 0) ? pEnc->iFrameNum : 0,          }else{
948                                                                          bframes_count++))) {                  mode = MEanalysis(&pEnc->reference->image, pEnc->current,
949                                            &pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval,
950                                            (mode < 0) ? pEnc->iFrameNum : 0,
951                                            bframes_count++);
952            }
953    
954            if (mode == I_VOP) {
955                  /*                  /*
956                   * This will be coded as an Intra Frame                   * This will be coded as an Intra Frame
957                   */                   */
# Line 958  Line 974 
974                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
975                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
976    
977                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) {
978                          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");
979                  }                  }
980    
981                  // 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
982    
983                  if ((pEnc->global & XVID_GLOBAL_DX50BVOP) && pEnc->bframenum_tail > 0) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_DX50BVOP) && pEnc->bframenum_tail > 0) {
984    
985                          pEnc->bframenum_tail--;                          pEnc->bframenum_tail--;
986                          pEnc->bframenum_dx50bvop = pEnc->bframenum_tail;                          pEnc->bframenum_dx50bvop = pEnc->bframenum_tail;
987    
988                          SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]);                          SWAP(FRAMEINFO *, pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]);
989                          if ((pEnc->global & XVID_GLOBAL_DEBUG)) {                          if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) {
990                                  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, "DX50 BVOP->PVOP");
991                          }                          }
992                          FrameCodeP(pEnc, &bs, &bits, 1, 0);                          FrameCodeP(pEnc, &bs, &bits, 1, 0);
# Line 989  Line 1005 
1005    
1006                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
1007    
1008                  if ((pEnc->global & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) {
1009                          BitstreamPadAlways(&bs);                          BitstreamPadAlways(&bs);
1010                          input_valid = 0;                          input_valid = 0;
1011                          goto ipvop_loop;                          goto ipvop_loop;
# Line 999  Line 1015 
1015                   * NB : sequences like "IIBB" decode fine with msfdam but,                   * NB : sequences like "IIBB" decode fine with msfdam but,
1016                   *      go screwy with divx 5.00                   *      go screwy with divx 5.00
1017                   */                   */
1018          } else if (pEnc->bframenum_tail >= pEnc->mbParam.max_bframes || mode != 0) {          } else if (mode == P_VOP || pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) {
 //      } else if (pFrame->intra == 0 || pEnc->bframenum_tail >= pEnc->mbParam.max_bframes || mode != 0) {  
1019                  /*                  /*
1020                   * This will be coded as a Predicted Frame                   * This will be coded as a Predicted Frame
1021                   */                   */
# Line 1009  Line 1024 
1024                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
1025                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
1026    
1027                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) {
1028                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP");
1029                  }                  }
1030    
# Line 1018  Line 1033 
1033                  pFrame->intra = 0;                  pFrame->intra = 0;
1034                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
1035    
1036                  if ((pEnc->global & XVID_GLOBAL_PACKED) && (pEnc->bframenum_tail > 0)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_PACKED) && (pEnc->bframenum_tail > 0)) {
1037                          BitstreamPadAlways(&bs);                          BitstreamPadAlways(&bs);
1038                          input_valid = 0;                          input_valid = 0;
1039                          goto ipvop_loop;                          goto ipvop_loop;
1040                  }                  }
1041    
1042          } else {          } else {        /* mode == B_VOP */
1043                  /*                  /*
1044                   * This will be coded as a Bidirectional Frame                   * This will be coded as a Bidirectional Frame
1045                   */                   */
1046    
1047                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) {
1048                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP");
1049                  }                  }
1050    
1051                  if (pFrame->bquant < 1) {                  if (pFrame->bquant < 1) {
1052                          pEnc->current->quant = ((((pEnc->reference->quant + pEnc->current->quant) *                          pEnc->current->quant = ((((pEnc->reference->quant + pEnc->current->quant) *
1053                                  pEnc->bquant_ratio) / 2) + pEnc->bquant_offset)/100;                                  pEnc->mbParam.bquant_ratio) / 2) + pEnc->mbParam.bquant_offset)/100;
1054    
1055                  } else {                  } else {
1056                          pEnc->current->quant = pFrame->bquant;                          pEnc->current->quant = pFrame->bquant;
# Line 1051  Line 1066 
1066                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size,pEnc->current->quant);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size,pEnc->current->quant);
1067    
1068                  /* store frame into bframe buffer & swap ref back to current */                  /* store frame into bframe buffer & swap ref back to current */
1069                  SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);                  SWAP(FRAMEINFO *, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);
1070                  SWAP(pEnc->current, pEnc->reference);                  SWAP(FRAMEINFO *, pEnc->current, pEnc->reference);
1071    
1072                  pEnc->bframenum_tail++;                  pEnc->bframenum_tail++;
1073    
# Line 1132  Line 1147 
1147          ENC_CHECK(pFrame->bitstream);          ENC_CHECK(pFrame->bitstream);
1148          ENC_CHECK(pFrame->image);          ENC_CHECK(pFrame->image);
1149    
1150          SWAP(pEnc->current, pEnc->reference);          SWAP(FRAMEINFO *, pEnc->current, pEnc->reference);
1151    
1152          pEnc->current->global_flags = pFrame->general;          pEnc->current->global_flags = pFrame->general;
1153          pEnc->current->motion_flags = pFrame->motion;          pEnc->current->motion_flags = pFrame->motion;
# Line 1235  Line 1250 
1250    
1251          if (pFrame->intra < 0) {          if (pFrame->intra < 0) {
1252                  if ((pEnc->iFrameNum == 0)                  if ((pEnc->iFrameNum == 0)
1253                          || ((pEnc->iMaxKeyInterval > 0)                          || ((pEnc->mbParam.iMaxKeyInterval > 0)
1254                                  && (pEnc->iFrameNum >= pEnc->iMaxKeyInterval))) {                                  && (pEnc->iFrameNum >= pEnc->mbParam.iMaxKeyInterval))) {
1255                          pFrame->intra = FrameCodeI(pEnc, &bs, &bits);                          pFrame->intra = FrameCodeI(pEnc, &bs, &bits);
1256                  } else {                  } else {
1257                          pFrame->intra = FrameCodeP(pEnc, &bs, &bits, 0, write_vol_header);                          pFrame->intra = FrameCodeP(pEnc, &bs, &bits, 0, write_vol_header);
# Line 1518  Line 1533 
1533                     Bitstream * bs,                     Bitstream * bs,
1534                     uint32_t * pBits)                     uint32_t * pBits)
1535  {  {
1536            int mb_width = pEnc->mbParam.mb_width;
1537            int mb_height = pEnc->mbParam.mb_height;
1538    
1539          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);
1540          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
1541    
1542          uint16_t x, y;          uint16_t x, y;
1543    
1544            if ((pEnc->current->global_flags & XVID_REDUCED))
1545            {
1546                    mb_width = (pEnc->mbParam.width + 31) / 32;
1547                    mb_height = (pEnc->mbParam.height + 31) / 32;
1548    
1549                    /* 16x16->8x8 downsample requires 1 additional edge pixel*/
1550                    /* XXX: setedges is overkill */
1551                    start_timer();
1552                    image_setedges(&pEnc->current->image,
1553                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1554                            pEnc->mbParam.width, pEnc->mbParam.height);
1555                    stop_edges_timer();
1556            }
1557    
1558          pEnc->iFrameNum = 0;          pEnc->iFrameNum = 0;
1559          pEnc->mbParam.m_rounding_type = 1;          pEnc->mbParam.m_rounding_type = 1;
1560          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;
# Line 1532  Line 1563 
1563    
1564          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1565    
 #define DIVX501B481P "DivX501b481p"  
         if ((pEnc->global & XVID_GLOBAL_PACKED)) {  
                 BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P));  
         }  
   
 #define XVID_ID "XviD" XVID_BS_VERSION  
         BitstreamWriteUserData(bs, XVID_ID, strlen(XVID_ID));  
   
1566          set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);          set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1567          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1568    
1569          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1570    
1571          pEnc->current->sStat.iTextBits = 0;          pEnc->current->sStat.iTextBits = 0;
1572          pEnc->current->sStat.kblks = pEnc->mbParam.mb_width * pEnc->mbParam.mb_height;          pEnc->current->sStat.kblks = mb_width * mb_height;
1573          pEnc->current->sStat.mblks = pEnc->current->sStat.ublks = 0;          pEnc->current->sStat.mblks = pEnc->current->sStat.ublks = 0;
1574    
1575          for (y = 0; y < pEnc->mbParam.mb_height; y++)          for (y = 0; y < mb_height; y++)
1576                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
1577                          MACROBLOCK *pMB =                          MACROBLOCK *pMB =
1578                                  &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];                                  &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];
1579    
# Line 1573  Line 1596 
1596                          stop_coding_timer();                          stop_coding_timer();
1597                  }                  }
1598    
1599            if ((pEnc->current->global_flags & XVID_REDUCED))
1600            {
1601                    image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width,
1602                            pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width,
1603                            16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV);
1604            }
1605          emms();          emms();
1606    
1607          *pBits = BitstreamPos(bs) - *pBits;          *pBits = BitstreamPos(bs) - *pBits;
# Line 1602  Line 1631 
1631          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);
1632          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
1633    
1634            int mb_width = pEnc->mbParam.mb_width;
1635            int mb_height = pEnc->mbParam.mb_height;
1636    
1637          int iLimit;          int iLimit;
1638          int x, y, k;          int x, y, k;
1639          int iSearchRange;          int iSearchRange;
# Line 1610  Line 1642 
1642          /* IMAGE *pCurrent = &pEnc->current->image; */          /* IMAGE *pCurrent = &pEnc->current->image; */
1643          IMAGE *pRef = &pEnc->reference->image;          IMAGE *pRef = &pEnc->reference->image;
1644    
1645            if ((pEnc->current->global_flags & XVID_REDUCED))
1646            {
1647                    mb_width = (pEnc->mbParam.width + 31) / 32;
1648                    mb_height = (pEnc->mbParam.height + 31) / 32;
1649            }
1650    
1651    
1652          start_timer();          start_timer();
1653          image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,          image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1654                                     pEnc->mbParam.width, pEnc->mbParam.height);                                     pEnc->mbParam.width, pEnc->mbParam.height);
# Line 1621  Line 1660 
1660          pEnc->current->fcode = pEnc->mbParam.m_fcode;          pEnc->current->fcode = pEnc->mbParam.m_fcode;
1661    
1662          if (!force_inter)          if (!force_inter)
1663                  iLimit =                  iLimit = (int)(mb_width * mb_height *  INTRA_THRESHOLD);
                         (int) (pEnc->mbParam.mb_width * pEnc->mbParam.mb_height *  
                                    INTRA_THRESHOLD);  
1664          else          else
1665                  iLimit = pEnc->mbParam.mb_width * pEnc->mbParam.mb_height + 1;                  iLimit = mb_width * mb_height + 1;
1666    
1667          if ((pEnc->current->global_flags & XVID_HALFPEL)) {          if ((pEnc->current->global_flags & XVID_HALFPEL)) {
1668                  start_timer();                  start_timer();
# Line 1645  Line 1682 
1682                  pEnc->current->coding_type = P_VOP;                  pEnc->current->coding_type = P_VOP;
1683    
1684          start_timer();          start_timer();
1685          if (pEnc->current->global_flags & XVID_HINTEDME_SET) {          if (pEnc->current->global_flags & XVID_HINTEDME_SET)
1686                  HintedMESet(pEnc, &bIntra);                  HintedMESet(pEnc, &bIntra);
1687          if (bIntra == 0) {          else
                         pEnc->current->fcode = FindFcode(&pEnc->mbParam, pEnc->current);  
                         MotionEstimationHinted(&pEnc->mbParam, pEnc->current, pEnc->reference,  
                                                                                         &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV);  
                 }  
   
         } else {  
1688    
1689                  bIntra =                  bIntra =
1690                          MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,                          MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,
1691                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
1692                           iLimit);                           iLimit);
1693          }  
1694          stop_motion_timer();          stop_motion_timer();
1695    
1696          if (bIntra == 1) return FrameCodeI(pEnc, bs, pBits);          if (bIntra == 1) return FrameCodeI(pEnc, bs, pBits);
# Line 1680  Line 1711 
1711          pEnc->current->sStat.iTextBits = pEnc->current->sStat.iMvSum = pEnc->current->sStat.iMvCount =          pEnc->current->sStat.iTextBits = pEnc->current->sStat.iMvSum = pEnc->current->sStat.iMvCount =
1712                  pEnc->current->sStat.kblks = pEnc->current->sStat.mblks = pEnc->current->sStat.ublks = 0;                  pEnc->current->sStat.kblks = pEnc->current->sStat.mblks = pEnc->current->sStat.ublks = 0;
1713    
1714          for (y = 0; y < pEnc->mbParam.mb_height; y++) {          for (y = 0; y < mb_height; y++) {
1715                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
1716                          MACROBLOCK *pMB =                          MACROBLOCK *pMB =
1717                                  &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];                                  &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];
1718    
# Line 1696  Line 1727 
1727                                                                           pEnc->mbParam.height,                                                                           pEnc->mbParam.height,
1728                                                                           pEnc->mbParam.edged_width,                                                                           pEnc->mbParam.edged_width,
1729                                                                           pEnc->mbParam.m_quarterpel,                                                                           pEnc->mbParam.m_quarterpel,
1730                                                                             (pEnc->current->global_flags & XVID_REDUCED),
1731                                                                           pEnc->current->rounding_type);                                                                           pEnc->current->rounding_type);
1732                                  stop_comp_timer();                                  stop_comp_timer();
1733    
# Line 1805  Line 1837 
1837                  }                  }
1838          }          }
1839    
1840            if ((pEnc->current->global_flags & XVID_REDUCED))
1841            {
1842                    image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width,
1843                            pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width,
1844                            16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV);
1845            }
1846    
1847          emms();          emms();
1848    
1849          if (pEnc->current->global_flags & XVID_HINTEDME_GET) {          if (pEnc->current->global_flags & XVID_HINTEDME_GET) {
# Line 1837  Line 1876 
1876          /* frame drop code */          /* frame drop code */
1877          // DPRINTF(DPRINTF_DEBUG, "kmu %i %i %i", pEnc->current->sStat.kblks, pEnc->current->sStat.mblks, pEnc->current->sStat.ublks);          // DPRINTF(DPRINTF_DEBUG, "kmu %i %i %i", pEnc->current->sStat.kblks, pEnc->current->sStat.mblks, pEnc->current->sStat.ublks);
1878          if (pEnc->current->sStat.kblks + pEnc->current->sStat.mblks <          if (pEnc->current->sStat.kblks + pEnc->current->sStat.mblks <
1879                  (pEnc->frame_drop_ratio * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height) / 100)                  (pEnc->mbParam.frame_drop_ratio * mb_width * mb_height) / 100)
1880          {          {
1881                  pEnc->current->sStat.kblks = pEnc->current->sStat.mblks = 0;                  pEnc->current->sStat.kblks = pEnc->current->sStat.mblks = 0;
1882                  pEnc->current->sStat.ublks = pEnc->mbParam.mb_width * pEnc->mbParam.mb_height;                  pEnc->current->sStat.ublks = mb_width * mb_height;
1883    
1884                  BitstreamReset(bs);                  BitstreamReset(bs);
1885    
# Line 1855  Line 1894 
1894                  pEnc->current->fcode = pEnc->reference->fcode;                  pEnc->current->fcode = pEnc->reference->fcode;
1895                  pEnc->current->bcode = pEnc->reference->bcode;                  pEnc->current->bcode = pEnc->reference->bcode;
1896                  image_copy(&pEnc->current->image, &pEnc->reference->image, pEnc->mbParam.edged_width, pEnc->mbParam.height);                  image_copy(&pEnc->current->image, &pEnc->reference->image, pEnc->mbParam.edged_width, pEnc->mbParam.height);
1897                  memcpy(pEnc->current->mbs, pEnc->reference->mbs, sizeof(MACROBLOCK) * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height);                  memcpy(pEnc->current->mbs, pEnc->reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height);
1898            }
1899    
1900            /* XXX: debug
1901            {
1902                    char s[100];
1903                    sprintf(s, "\\%05i_cur.pgm", pEnc->m_framenum);
1904                    image_dump_yuvpgm(&pEnc->current->image,
1905                            pEnc->mbParam.edged_width,
1906                            pEnc->mbParam.width, pEnc->mbParam.height, s);
1907    
1908                    sprintf(s, "\\%05i_ref.pgm", pEnc->m_framenum);
1909                    image_dump_yuvpgm(&pEnc->reference->image,
1910                            pEnc->mbParam.edged_width,
1911                            pEnc->mbParam.width, pEnc->mbParam.height, s);
1912          }          }
1913            */
1914    
1915    
1916          *pBits = BitstreamPos(bs) - *pBits;          *pBits = BitstreamPos(bs) - *pBits;
1917    
# Line 1871  Line 1925 
1925                     Bitstream * bs,                     Bitstream * bs,
1926                     uint32_t * pBits)                     uint32_t * pBits)
1927  {  {
1928          int16_t dct_codes[6 * 64];          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);
1929          int16_t qcoeff[6 * 64];          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
1930          uint32_t x, y;          uint32_t x, y;
1931    
1932          IMAGE *f_ref = &pEnc->reference->image;          IMAGE *f_ref = &pEnc->reference->image;
# Line 1885  Line 1939 
1939                  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); \
1940          }          }
1941    
1942            pEnc->current->global_flags &= ~XVID_REDUCED;   /* reduced resoltion not yet supported */
1943    
1944          if (!first){          if (!first){
1945                  fp=fopen("C:\\XVIDDBGE.TXT","w");                  fp=fopen("C:\\XVIDDBGE.TXT","w");
1946          }          }
# Line 1946  Line 2002 
2002          for (y = 0; y < pEnc->mbParam.mb_height; y++) {          for (y = 0; y < pEnc->mbParam.mb_height; y++) {
2003                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {
2004                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];
2005                          int direction = pEnc->global & XVID_ALTERNATESCAN ? 2 : 0;                          int direction = pEnc->mbParam.global & XVID_ALTERNATESCAN ? 2 : 0;
2006    
2007                          // decoder ignores mb when refence block is INTER(0,0), CBP=0                          // decoder ignores mb when refence block is INTER(0,0), CBP=0
2008                          if (mb->mode == MODE_NOT_CODED) {                          if (mb->mode == MODE_NOT_CODED) {

Legend:
Removed from v.1.76.2.25  
changed lines
  Added in v.1.76.2.33

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