[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.64, Wed Jul 24 23:17:19 2002 UTC revision 1.76.2.13, Thu Oct 17 19:10:57 2002 UTC
# Line 56  Line 56 
56  #include "image/image.h"  #include "image/image.h"
57  #ifdef BFRAMES  #ifdef BFRAMES
58  #include "image/font.h"  #include "image/font.h"
59    #include "motion/sad.h"
60  #endif  #endif
61  #include "motion/motion.h"  #include "motion/motion.h"
62  #include "bitstream/cbp.h"  #include "bitstream/cbp.h"
# Line 69  Line 70 
70  #include "quant/quant_matrix.h"  #include "quant/quant_matrix.h"
71  #include "utils/mem_align.h"  #include "utils/mem_align.h"
72    
 #ifdef _SMP  
 #include "motion/smp_motion_est.h"  
 #endif  
73  /*****************************************************************************  /*****************************************************************************
74   * Local macros   * Local macros
75   ****************************************************************************/   ****************************************************************************/
# Line 93  Line 91 
91                                            bool force_inter,                                            bool force_inter,
92                                            bool vol_header);                                            bool vol_header);
93    
 #ifdef BFRAMES  
94  static void FrameCodeB(Encoder * pEnc,  static void FrameCodeB(Encoder * pEnc,
95                                             FRAMEINFO * frame,                                             FRAMEINFO * frame,
96                                             Bitstream * bs,                                             Bitstream * bs,
97                                             uint32_t * pBits);                                             uint32_t * pBits);
 #endif  
98    
99  /*****************************************************************************  /*****************************************************************************
100   * Local data   * Local data
# Line 237  Line 233 
233    
234          pEnc->mbParam.m_quant_type = H263_QUANT;          pEnc->mbParam.m_quant_type = H263_QUANT;
235    
 #ifdef _SMP  
         pEnc->mbParam.num_threads = MIN(pParam->num_threads, MAXNUMTHREADS);  
 #endif  
   
236          pEnc->sStat.fMvPrevSigma = -1;          pEnc->sStat.fMvPrevSigma = -1;
237    
238          /* Fill rate control parameters */          /* Fill rate control parameters */
# Line 275  Line 267 
267  #ifdef _DEBUG_PSNR  #ifdef _DEBUG_PSNR
268          image_null(&pEnc->sOriginal);          image_null(&pEnc->sOriginal);
269  #endif  #endif
270  #ifdef BFRAMES  
271          image_null(&pEnc->f_refh);          image_null(&pEnc->f_refh);
272          image_null(&pEnc->f_refv);          image_null(&pEnc->f_refv);
273          image_null(&pEnc->f_refhv);          image_null(&pEnc->f_refhv);
274  #endif  
275          image_null(&pEnc->current->image);          image_null(&pEnc->current->image);
276          image_null(&pEnc->reference->image);          image_null(&pEnc->reference->image);
277          image_null(&pEnc->vInterH);          image_null(&pEnc->vInterH);
# Line 294  Line 286 
286                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
287                  goto xvid_err_memory3;                  goto xvid_err_memory3;
288  #endif  #endif
289  #ifdef BFRAMES  
290          if (image_create          if (image_create
291                  (&pEnc->f_refh, pEnc->mbParam.edged_width,                  (&pEnc->f_refh, pEnc->mbParam.edged_width,
292                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
# Line 307  Line 299 
299                  (&pEnc->f_refhv, pEnc->mbParam.edged_width,                  (&pEnc->f_refhv, pEnc->mbParam.edged_width,
300                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
301                  goto xvid_err_memory3;                  goto xvid_err_memory3;
302  #endif  
303          if (image_create          if (image_create
304                  (&pEnc->current->image, pEnc->mbParam.edged_width,                  (&pEnc->current->image, pEnc->mbParam.edged_width,
305                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
# Line 340  Line 332 
332    
333    
334          /* B Frames specific init */          /* B Frames specific init */
 #ifdef BFRAMES  
335    
336          pEnc->global = pParam->global;          pEnc->global = pParam->global;
337          pEnc->mbParam.max_bframes = pParam->max_bframes;          pEnc->mbParam.max_bframes = pParam->max_bframes;
# Line 419  Line 410 
410          pEnc->queue_tail = 0;          pEnc->queue_tail = 0;
411          pEnc->queue_size = 0;          pEnc->queue_size = 0;
412    
413            pEnc->mbParam.m_stamp = 0;
414    
         pEnc->mbParam.m_seconds = 0;  
         pEnc->mbParam.m_ticks = 0;  
415          pEnc->m_framenum = 0;          pEnc->m_framenum = 0;
416          pEnc->last_pframe = 1;          pEnc->current->stamp = 0;
417  #endif          pEnc->reference->stamp = 0;
418    
419          pParam->handle = (void *) pEnc;          pParam->handle = (void *) pEnc;
420    
# Line 443  Line 433 
433          /*          /*
434           * We handle all XVID_ERR_MEMORY here, this makes the code lighter           * We handle all XVID_ERR_MEMORY here, this makes the code lighter
435           */           */
436  #ifdef BFRAMES  
437    xvid_err_memory5:    xvid_err_memory5:
438    
439    
# Line 477  Line 467 
467                  xvid_free(pEnc->bframes);                  xvid_free(pEnc->bframes);
468          }          }
469    
 #endif  
   
470    xvid_err_memory3:    xvid_err_memory3:
471  #ifdef _DEBUG_PSNR  #ifdef _DEBUG_PSNR
472          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,
473                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
474  #endif  #endif
475    
 #ifdef BFRAMES  
476          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,
477                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
478          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,
479                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
480          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,
481                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
 #endif  
482    
483          image_destroy(&pEnc->current->image, pEnc->mbParam.edged_width,          image_destroy(&pEnc->current->image, pEnc->mbParam.edged_width,
484                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
# Line 537  Line 523 
523  int  int
524  encoder_destroy(Encoder * pEnc)  encoder_destroy(Encoder * pEnc)
525  {  {
 #ifdef BFRAMES  
526          int i;          int i;
 #endif  
527    
528          ENC_CHECK(pEnc);          ENC_CHECK(pEnc);
529    
530          /* B Frames specific */          /* B Frames specific */
 #ifdef BFRAMES  
531          if (pEnc->mbParam.max_bframes > 0) {          if (pEnc->mbParam.max_bframes > 0) {
532    
533                  for (i = 0; i < pEnc->mbParam.max_bframes; i++) {                  for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
# Line 574  Line 557 
557                  xvid_free(pEnc->bframes);                  xvid_free(pEnc->bframes);
558    
559          }          }
 #endif  
560    
561          /* All images, reference, current etc ... */          /* All images, reference, current etc ... */
562    
# Line 592  Line 574 
574                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
575          image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width,
576                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
577  #ifdef BFRAMES  
578          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,
579                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
580          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,
581                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
582          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,
583                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
584  #endif  
585  #ifdef _DEBUG_PSNR  #ifdef _DEBUG_PSNR
586          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,
587                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
# Line 619  Line 601 
601  }  }
602    
603    
604  #ifdef BFRAMES  static __inline void inc_frame_num(Encoder * pEnc)
 void inc_frame_num(Encoder * pEnc)  
605  {  {
606          pEnc->iFrameNum++;          pEnc->current->stamp = pEnc->mbParam.m_stamp;   // first frame is zero
607          pEnc->mbParam.m_ticks += pEnc->mbParam.fincr;          pEnc->mbParam.m_stamp += pEnc->mbParam.fincr;
   
         pEnc->mbParam.m_seconds = pEnc->mbParam.m_ticks / pEnc->mbParam.fbase;  
         pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase;  
608  }  }
 #endif  
609    
610    
611  #ifdef BFRAMES  static __inline void
612  void queue_image(Encoder * pEnc, XVID_ENC_FRAME * pFrame)  queue_image(Encoder * pEnc, XVID_ENC_FRAME * pFrame)
613  {  {
614          if (pEnc->queue_size >= pEnc->mbParam.max_bframes)          if (pEnc->queue_size >= pEnc->mbParam.max_bframes)
615          {          {
# Line 655  Line 632 
632          pEnc->queue_size++;          pEnc->queue_size++;
633          pEnc->queue_tail =  (pEnc->queue_tail + 1) % pEnc->mbParam.max_bframes;          pEnc->queue_tail =  (pEnc->queue_tail + 1) % pEnc->mbParam.max_bframes;
634  }  }
635  #endif  
636    static __inline void
637    set_timecodes(FRAMEINFO* pCur,FRAMEINFO *pRef, int32_t time_base)
638    {
639    
640                    pCur->ticks = (int32_t)pCur->stamp % time_base;
641                    pCur->seconds =  ((int32_t)pCur->stamp / time_base)     - ((int32_t)pRef->stamp / time_base) ;
642    
643                    //HEAVY DEBUG OUTPUT    remove when timecodes prove to be stable
644    
645    /*              fprintf(stderr,"WriteVop:   %d - %d \n",
646                            ((int32_t)pCur->stamp / time_base), ((int32_t)pRef->stamp / time_base));
647                    fprintf(stderr,"set_timecodes: VOP %1d   stamp=%lld ref_stamp=%lld  base=%d\n",
648                            pCur->coding_type, pCur->stamp, pRef->stamp, time_base);
649                    fprintf(stderr,"set_timecodes: VOP %1d   seconds=%d   ticks=%d   (ref-sec=%d  ref-tick=%d)\n",
650                            pCur->coding_type, pCur->seconds, pCur->ticks, pRef->seconds, pRef->ticks);
651    
652    */
653    }
654    
655    
656    
657    
658    
 #ifdef BFRAMES  
659  /*****************************************************************************  /*****************************************************************************
660   * IPB frame encoder entry point   * IPB frame encoder entry point
661   *   *
# Line 675  Line 672 
672  {  {
673          uint16_t x, y;          uint16_t x, y;
674          Bitstream bs;          Bitstream bs;
675          uint32_t bits;          uint32_t bits, mode;
676    
677          int input_valid = 1;          int input_valid = 1;
678    
# Line 747  Line 744 
744          if (pEnc->bframenum_head > 0) {          if (pEnc->bframenum_head > 0) {
745                  pEnc->bframenum_head = pEnc->bframenum_tail = 0;                  pEnc->bframenum_head = pEnc->bframenum_tail = 0;
746    
747                    /* write an empty marker to the bitstream.
748    
749                       for divx5 decoder compatibility, this marker must consist
750                       of a not-coded p-vop, with a time_base of zero, and time_increment
751                       indentical to the future-referece frame.
752                    */
753    
754                  if ((pEnc->global & XVID_GLOBAL_PACKED)) {                  if ((pEnc->global & XVID_GLOBAL_PACKED)) {
755                            int tmp;
756    
757                          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",
758                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
759                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
760    
                         BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);  
761                          BitstreamPad(&bs);                          BitstreamPad(&bs);
762                          BitstreamPutBits(&bs, 0x7f, 8);  
763                            tmp = pEnc->current->seconds;
764                            pEnc->current->seconds = 0; /* force time_base = 0 */
765                            BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);
766                            pEnc->current->seconds = tmp;
767    
768                          pFrame->length = BitstreamLength(&bs);                          pFrame->length = BitstreamLength(&bs);
769                          pFrame->intra = 0;                          pFrame->intra = 0;
# Line 817  Line 825 
825                  pEnc->queue_head =  (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes;                  pEnc->queue_head =  (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes;
826                  pEnc->queue_size--;                  pEnc->queue_size--;
827    
828          } else if (BitstreamPos(&bs) == 0) {          } else {
829    
830                    /* if nothing was encoded, write an 'ignore this frame' flag
831                       to the bitstream */
832    
833                    if (BitstreamPos(&bs) == 0) {
834    
835                  DPRINTF(DPRINTF_DEBUG,"*** SKIP bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",                  DPRINTF(DPRINTF_DEBUG,"*** SKIP bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
836                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
837                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
838    
                 pFrame->intra = 0;  
   
839                  BitstreamPutBits(&bs, 0x7f, 8);                  BitstreamPutBits(&bs, 0x7f, 8);
840                  BitstreamPad(&bs);                          pFrame->intra = 0;
841                  pFrame->length = BitstreamLength(&bs);                  }
   
                 return XVID_ERR_OK;  
   
         } else {  
842    
843                  pFrame->length = BitstreamLength(&bs);                  pFrame->length = BitstreamLength(&bs);
844                  return XVID_ERR_OK;                  return XVID_ERR_OK;
# Line 839  Line 846 
846    
847          pEnc->flush_bframes = 0;          pEnc->flush_bframes = 0;
848    
         /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
          * Well there was a separation here so i put it in ANSI C  
          * comment style :-)  
          * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */  
   
849          emms();          emms();
850    
851          // 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
# Line 867  Line 869 
869                  pEnc->current->fcode = pEnc->mbParam.m_fcode;                  pEnc->current->fcode = pEnc->mbParam.m_fcode;
870                  pEnc->current->bcode = pEnc->mbParam.m_fcode;                  pEnc->current->bcode = pEnc->mbParam.m_fcode;
871    
                 pEnc->current->seconds = pEnc->mbParam.m_seconds;  
                 pEnc->current->ticks = pEnc->mbParam.m_ticks;  
   
872                  inc_frame_num(pEnc);                  inc_frame_num(pEnc);
873    
874  #ifdef _DEBUG_PSNR  #ifdef _DEBUG_PSNR
# Line 881  Line 880 
880    
881                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
882                          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,
883                                  "%i  if:%i  st:%i:%i", pEnc->m_framenum++, pEnc->iFrameNum, pEnc->current->seconds, pEnc->current->ticks);                                  "%i  if:%i  st:%i", pEnc->m_framenum++, pEnc->iFrameNum, pEnc->current->stamp);
884                  }                  }
885    
886          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Line 928  Line 927 
927          if (pEnc->iFrameNum == 0 || pFrame->intra == 1 || pEnc->bframenum_dx50bvop >= 0 ||          if (pEnc->iFrameNum == 0 || pFrame->intra == 1 || pEnc->bframenum_dx50bvop >= 0 ||
928                  (pFrame->intra < 0 && pEnc->iMaxKeyInterval > 0 &&                  (pFrame->intra < 0 && pEnc->iMaxKeyInterval > 0 &&
929                   pEnc->iFrameNum >= pEnc->iMaxKeyInterval)                   pEnc->iFrameNum >= pEnc->iMaxKeyInterval)
930                  || image_mad(&pEnc->reference->image, &pEnc->current->image,                  || /*image_mad(&pEnc->reference->image, &pEnc->current->image,
931                                           pEnc->mbParam.edged_width, pEnc->mbParam.width,                                           pEnc->mbParam.edged_width, pEnc->mbParam.width,
932                                           pEnc->mbParam.height) > 30) {                                           pEnc->mbParam.height) > 30) {*/
933                            2 == (mode = MEanalysis(&pEnc->reference->image, &pEnc->current->image,
934                                             &pEnc->mbParam, pEnc->current->mbs, pEnc->current->fcode))) {
935    
936                  /*                  /*
937                   * This will be coded as an Intra Frame                   * This will be coded as an Intra Frame
938                   */                   */
# Line 969  Line 971 
971                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
972    
973                  if ((pEnc->global & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) {                  if ((pEnc->global & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) {
974                          BitstreamPad(&bs);                          BitstreamPadAlways(&bs);
975                          input_valid = 0;                          input_valid = 0;
976                          goto ipvop_loop;                          goto ipvop_loop;
977                  }                  }
# Line 978  Line 980 
980                   * NB : sequences like "IIBB" decode fine with msfdam but,                   * NB : sequences like "IIBB" decode fine with msfdam but,
981                   *      go screwy with divx 5.00                   *      go screwy with divx 5.00
982                   */                   */
983          } else if (pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) {          } else if (pEnc->bframenum_tail >= pEnc->mbParam.max_bframes || mode != 0) {
984                  /*                  /*
985                   * This will be coded as a Predicted Frame                   * This will be coded as a Predicted Frame
986                   */                   */
# Line 996  Line 998 
998                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
999    
1000                  if ((pEnc->global & XVID_GLOBAL_PACKED)) {                  if ((pEnc->global & XVID_GLOBAL_PACKED)) {
1001                          BitstreamPad(&bs);                          BitstreamPadAlways(&bs);
1002                          input_valid = 0;                          input_valid = 0;
1003                          goto ipvop_loop;                          goto ipvop_loop;
1004                  }                  }
# Line 1043  Line 1045 
1045                  goto bvop_loop;                  goto bvop_loop;
1046          }          }
1047    
1048            pEnc->iFrameNum++;
1049    
1050          BitstreamPad(&bs);          BitstreamPad(&bs);
1051          pFrame->length = BitstreamLength(&bs);          pFrame->length = BitstreamLength(&bs);
1052    
# Line 1071  Line 1075 
1075                                                    pFrame->length, pFrame->intra);                                                    pFrame->length, pFrame->intra);
1076          }          }
1077    
   
1078          stop_global_timer();          stop_global_timer();
1079          write_timer();          write_timer();
1080    
1081          return XVID_ERR_OK;          return XVID_ERR_OK;
1082  }  }
1083    
 #endif  
   
1084    
1085    
1086  /*****************************************************************************  /*****************************************************************************
# Line 1117  Line 1118 
1118    
1119          pEnc->current->global_flags = pFrame->general;          pEnc->current->global_flags = pFrame->general;
1120          pEnc->current->motion_flags = pFrame->motion;          pEnc->current->motion_flags = pFrame->motion;
 #ifdef BFRAMES  
         pEnc->current->seconds = pEnc->mbParam.m_seconds;  
         pEnc->current->ticks = pEnc->mbParam.m_ticks;  
 #endif  
1121          pEnc->mbParam.hint = &pFrame->hint;          pEnc->mbParam.hint = &pFrame->hint;
1122    
1123            inc_frame_num(pEnc);
1124    
1125            /* disable alternate scan flag if interlacing is not enabled */
1126            if ((pEnc->current->global_flags & XVID_ALTERNATESCAN) &&
1127                    !(pEnc->current->global_flags & XVID_INTERLACING))
1128            {
1129                    pEnc->current->global_flags -= XVID_ALTERNATESCAN;
1130            }
1131    
1132          start_timer();          start_timer();
1133          if (image_input          if (image_input
1134                  (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,                  (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,
# Line 1145  Line 1151 
1151                  pEnc->current->quant = pFrame->quant;                  pEnc->current->quant = pFrame->quant;
1152          }          }
1153    
1154            if ((pEnc->current->global_flags & XVID_QUARTERPEL))
1155                    pEnc->mbParam.m_quarterpel = 1;
1156            else
1157                    pEnc->mbParam.m_quarterpel = 0;
1158    
1159          if ((pEnc->current->global_flags & XVID_LUMIMASKING)) {          if ((pEnc->current->global_flags & XVID_LUMIMASKING)) {
1160                  int *temp_dquants =                  int *temp_dquants =
1161                          (int *) xvid_malloc(pEnc->mbParam.mb_width *                          (int *) xvid_malloc(pEnc->mbParam.mb_width *
# Line 1250  Line 1261 
1261          DEBUG(temp);          DEBUG(temp);
1262  #endif  #endif
1263    
 #ifdef BFRAMES  
         inc_frame_num(pEnc);  
 #else  
1264          pEnc->iFrameNum++;          pEnc->iFrameNum++;
 #endif  
   
1265    
1266          stop_global_timer();          stop_global_timer();
1267          write_timer();          write_timer();
# Line 1506  Line 1512 
1512          pEnc->current->coding_type = I_VOP;          pEnc->current->coding_type = I_VOP;
1513    
1514          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1515  #ifdef BFRAMES  
1516  #define DIVX501B481P "DivX501b481p"  #define DIVX501B481P "DivX501b481p"
1517          if ((pEnc->global & XVID_GLOBAL_PACKED)) {          if ((pEnc->global & XVID_GLOBAL_PACKED)) {
1518                  BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P));                  BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P));
1519          }          }
1520  #endif  
1521    #define XVID_ID "XviD" XVID_BS_VERSION
1522            BitstreamWriteUserData(bs, XVID_ID, strlen(XVID_ID));
1523    
1524            set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1525          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1526    
1527          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
# Line 1535  Line 1545 
1545                          stop_prediction_timer();                          stop_prediction_timer();
1546    
1547                          start_timer();                          start_timer();
1548                            if (pEnc->current->global_flags & XVID_GREYSCALE)
1549                            {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */
1550                                    qcoeff[4*64+0]=0;               /* zero, because for INTRA MBs DC value is saved */
1551                                    qcoeff[5*64+0]=0;
1552                            }
1553                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);
1554                          stop_coding_timer();                          stop_coding_timer();
1555                  }                  }
# Line 1556  Line 1571 
1571    
1572    
1573  #define INTRA_THRESHOLD 0.5  #define INTRA_THRESHOLD 0.5
1574    #define BFRAME_SKIP_THRESHHOLD 30
1575    
1576  static int  static int
1577  FrameCodeP(Encoder * pEnc,  FrameCodeP(Encoder * pEnc,
# Line 1570  Line 1586 
1586          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
1587    
1588          int iLimit;          int iLimit;
1589          uint32_t x, y;          int x, y, k;
1590          int iSearchRange;          int iSearchRange;
1591          int bIntra;          int bIntra, skip_possible;
1592    
1593          /* IMAGE *pCurrent = &pEnc->current->image; */          /* IMAGE *pCurrent = &pEnc->current->image; */
1594          IMAGE *pRef = &pEnc->reference->image;          IMAGE *pRef = &pEnc->reference->image;
1595    
1596          start_timer();          start_timer();
1597          image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,          image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1598                                     pEnc->mbParam.width, pEnc->mbParam.height,                                     pEnc->mbParam.width, pEnc->mbParam.height);
                                    pEnc->current->global_flags & XVID_INTERLACING);  
1599          stop_edges_timer();          stop_edges_timer();
1600    
1601          pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type;          pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type;
# Line 1599  Line 1614 
1614                  image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV,                  image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV,
1615                                                    &pEnc->vInterHV, pEnc->mbParam.edged_width,                                                    &pEnc->vInterHV, pEnc->mbParam.edged_width,
1616                                                    pEnc->mbParam.edged_height,                                                    pEnc->mbParam.edged_height,
1617                                                      pEnc->mbParam.m_quarterpel,
1618                                                    pEnc->current->rounding_type);                                                    pEnc->current->rounding_type);
1619                  stop_inter_timer();                  stop_inter_timer();
1620          }          }
# Line 1606  Line 1622 
1622          start_timer();          start_timer();
1623          if (pEnc->current->global_flags & XVID_HINTEDME_SET) {          if (pEnc->current->global_flags & XVID_HINTEDME_SET) {
1624                  HintedMESet(pEnc, &bIntra);                  HintedMESet(pEnc, &bIntra);
1625            if (bIntra == 0) {
1626                            pEnc->current->fcode = FindFcode(&pEnc->mbParam, pEnc->current);
1627                            MotionEstimationHinted(&pEnc->mbParam, pEnc->current, pEnc->reference,
1628                                                                                            &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV);
1629                    }
1630    
1631          } else {          } else {
1632    
 #ifdef _SMP  
         if (pEnc->mbParam.num_threads > 1)  
                 bIntra =  
                         SMP_MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,  
                                                  &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,  
                                                  iLimit);  
         else  
 #endif  
1633                  bIntra =                  bIntra =
1634                          MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,                          MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,
1635                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
# Line 1624  Line 1638 
1638          }          }
1639          stop_motion_timer();          stop_motion_timer();
1640    
1641          if (bIntra == 1) {          if (bIntra == 1) return FrameCodeI(pEnc, bs, pBits);
                 return FrameCodeI(pEnc, bs, pBits);  
         }  
1642    
1643          pEnc->current->coding_type = P_VOP;          pEnc->current->coding_type = P_VOP;
1644    
1645          if (vol_header)          if (vol_header)
1646                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1647    
1648    
1649            set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1650          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1651    
1652          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1653    
1654          pEnc->sStat.iTextBits = 0;          pEnc->sStat.iTextBits = pEnc->sStat.iMvSum = pEnc->sStat.iMvCount =
         pEnc->sStat.iMvSum = 0;  
         pEnc->sStat.iMvCount = 0;  
1655          pEnc->sStat.kblks = pEnc->sStat.mblks = pEnc->sStat.ublks = 0;          pEnc->sStat.kblks = pEnc->sStat.mblks = pEnc->sStat.ublks = 0;
1656    
1657          for (y = 0; y < pEnc->mbParam.mb_height; y++) {          for (y = 0; y < pEnc->mbParam.mb_height; y++) {
# Line 1657  Line 1669 
1669                                                                           dct_codes, pEnc->mbParam.width,                                                                           dct_codes, pEnc->mbParam.width,
1670                                                                           pEnc->mbParam.height,                                                                           pEnc->mbParam.height,
1671                                                                           pEnc->mbParam.edged_width,                                                                           pEnc->mbParam.edged_width,
1672                                                                             pEnc->mbParam.m_quarterpel,
1673                                                                           pEnc->current->rounding_type);                                                                           pEnc->current->rounding_type);
1674                                  stop_comp_timer();                                  stop_comp_timer();
1675    
# Line 1674  Line 1687 
1687    
1688                                  pMB->field_pred = 0;                                  pMB->field_pred = 0;
1689    
1690                                    if (pMB->mode != MODE_NOT_CODED)
1691                                  pMB->cbp =                                  pMB->cbp =
1692                                          MBTransQuantInter(&pEnc->mbParam, pEnc->current, pMB, x, y,                                          MBTransQuantInter(&pEnc->mbParam, pEnc->current, pMB, x, y,
1693                                                                            dct_codes, qcoeff);                                                                            dct_codes, qcoeff);
# Line 1698  Line 1712 
1712                          }                          }
1713    
1714                          start_timer();                          start_timer();
1715    
1716                            /* Finished processing the MB, now check if to CODE or SKIP */
1717    
1718                            skip_possible = (pMB->cbp == 0) & (pMB->mode == MODE_INTER) &
1719                                                            (pMB->dquant == NO_CHANGE);
1720    
1721                            if(pEnc->mbParam.m_quarterpel)
1722                                    skip_possible &= (pMB->qmvs[0].x == 0) & (pMB->qmvs[0].y == 0);
1723                            else
1724                                    skip_possible &= (pMB->mvs[0].x == 0) & (pMB->mvs[0].y == 0);
1725    
1726                            if ((pMB->mode == MODE_NOT_CODED) || (skip_possible)) {
1727    /* This is a candidate for SKIPping, but check intermediate B-frames first */
1728    
1729                                    int bSkip = 1;
1730                                    pMB->mode = MODE_NOT_CODED;
1731    
1732                                    for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++)
1733                                    {
1734                                            int iSAD;
1735                                            iSAD = sad16(pEnc->reference->image.y + 16*y*pEnc->mbParam.edged_width + 16*x,
1736                                                                    pEnc->bframes[k]->image.y + 16*y*pEnc->mbParam.edged_width + 16*x,
1737                                                                    pEnc->mbParam.edged_width,BFRAME_SKIP_THRESHHOLD);
1738                                            if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant)
1739                                            {       bSkip = 0;
1740                                                    break;
1741                                            }
1742                                    }
1743                                    if (!bSkip)
1744                                    {
1745                                            VECTOR predMV;
1746                                            if(pEnc->mbParam.m_quarterpel)
1747                                                    predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);
1748                                            else
1749                                                    predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);
1750                                            pMB->pmvs[0].x = -predMV.x; pMB->pmvs[0].y = -predMV.y;
1751                                            pMB->mode = MODE_INTER;
1752                                            pMB->cbp = 0;
1753                                            MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);
1754                                    }
1755                                    else MBSkip(bs);
1756    
1757                            } else {
1758                                    if (pEnc->current->global_flags & XVID_GREYSCALE)
1759                                    {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */
1760                                            qcoeff[4*64+0]=0;               /* zero, because DC for INTRA MBs DC value is saved */
1761                                            qcoeff[5*64+0]=0;
1762                                    }
1763                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);
1764                            }
1765    
1766                          stop_coding_timer();                          stop_coding_timer();
1767                  }                  }
1768          }          }
# Line 1717  Line 1781 
1781          iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode);          iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode);
1782    
1783          if ((fSigma > iSearchRange / 3)          if ((fSigma > iSearchRange / 3)
1784                  && (pEnc->mbParam.m_fcode <= 3))        // maximum search range 128                  && (pEnc->mbParam.m_fcode <= (3 + pEnc->mbParam.m_quarterpel))) // maximum search range 128
1785          {          {
1786                  pEnc->mbParam.m_fcode++;                  pEnc->mbParam.m_fcode++;
1787                  iSearchRange *= 2;                  iSearchRange *= 2;
1788          } else if ((fSigma < iSearchRange / 6)          } else if ((fSigma < iSearchRange / 6)
1789                             && (pEnc->sStat.fMvPrevSigma >= 0)                             && (pEnc->sStat.fMvPrevSigma >= 0)
1790                             && (pEnc->sStat.fMvPrevSigma < iSearchRange / 6)                             && (pEnc->sStat.fMvPrevSigma < iSearchRange / 6)
1791                             && (pEnc->mbParam.m_fcode >= 2))     // minimum search range 16                          && (pEnc->mbParam.m_fcode >= (2 + pEnc->mbParam.m_quarterpel))) // minimum search range 16
1792          {          {
1793                  pEnc->mbParam.m_fcode--;                  pEnc->mbParam.m_fcode--;
1794                  iSearchRange /= 2;                  iSearchRange /= 2;
# Line 1732  Line 1796 
1796    
1797          pEnc->sStat.fMvPrevSigma = fSigma;          pEnc->sStat.fMvPrevSigma = fSigma;
1798    
1799  #ifdef BFRAMES  #ifdef FRAMEDROP
1800          /* frame drop code */          /* frame drop code */
1801          // DPRINTF(DPRINTF_DEBUG, "kmu %i %i %i", pEnc->sStat.kblks, pEnc->sStat.mblks, pEnc->sStat.ublks);          // DPRINTF(DPRINTF_DEBUG, "kmu %i %i %i", pEnc->sStat.kblks, pEnc->sStat.mblks, pEnc->sStat.ublks);
1802          if (pEnc->sStat.kblks + pEnc->sStat.mblks <=          if (pEnc->sStat.kblks + pEnc->sStat.mblks <
1803                  (pEnc->frame_drop_ratio * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height) / 100)                  (pEnc->frame_drop_ratio * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height) / 100)
1804          {          {
1805                  pEnc->sStat.kblks = pEnc->sStat.mblks = 0;                  pEnc->sStat.kblks = pEnc->sStat.mblks = 0;
1806                  pEnc->sStat.ublks = pEnc->mbParam.mb_width * pEnc->mbParam.mb_height;                  pEnc->sStat.ublks = pEnc->mbParam.mb_width * pEnc->mbParam.mb_height;
1807    
1808                  BitstreamReset(bs);                  BitstreamReset(bs);
1809    
1810                    set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1811                  BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 0);                  BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 0);
1812    
1813                  // copy reference frame details into the current frame                  // copy reference frame details into the current frame
# Line 1758  Line 1824 
1824    
1825          *pBits = BitstreamPos(bs) - *pBits;          *pBits = BitstreamPos(bs) - *pBits;
1826    
 #ifdef BFRAMES  
         pEnc->time_pp = ((int32_t)pEnc->mbParam.fbase - (int32_t)pEnc->last_pframe + (int32_t)pEnc->mbParam.m_ticks) % (int32_t)pEnc->mbParam.fbase;  
         pEnc->last_pframe = pEnc->mbParam.m_ticks;  
 #endif  
   
1827          return 0;                                       // inter          return 0;                                       // inter
1828  }  }
1829    
1830    
1831  #ifdef BFRAMES  static __inline void
 static void  
1832  FrameCodeB(Encoder * pEnc,  FrameCodeB(Encoder * pEnc,
1833                     FRAMEINFO * frame,                     FRAMEINFO * frame,
1834                     Bitstream * bs,                     Bitstream * bs,
# Line 1777  Line 1837 
1837          int16_t dct_codes[6 * 64];          int16_t dct_codes[6 * 64];
1838          int16_t qcoeff[6 * 64];          int16_t qcoeff[6 * 64];
1839          uint32_t x, y;          uint32_t x, y;
         VECTOR forward;  
         VECTOR backward;  
1840    
1841          IMAGE *f_ref = &pEnc->reference->image;          IMAGE *f_ref = &pEnc->reference->image;
1842          IMAGE *b_ref = &pEnc->current->image;          IMAGE *b_ref = &pEnc->current->image;
# Line 1798  Line 1856 
1856          // forward          // forward
1857          image_setedges(f_ref, pEnc->mbParam.edged_width,          image_setedges(f_ref, pEnc->mbParam.edged_width,
1858                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,
1859                                     pEnc->mbParam.height,                                     pEnc->mbParam.height);
                                    frame->global_flags & XVID_INTERLACING);  
1860          start_timer();          start_timer();
1861          image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,          image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,
1862                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1863                                            0);                                            pEnc->mbParam.m_quarterpel, 0);
1864          stop_inter_timer();          stop_inter_timer();
1865    
1866          // backward          // backward
1867          image_setedges(b_ref, pEnc->mbParam.edged_width,          image_setedges(b_ref, pEnc->mbParam.edged_width,
1868                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,
1869                                     pEnc->mbParam.height,                                     pEnc->mbParam.height);
                                    frame->global_flags & XVID_INTERLACING);  
1870          start_timer();          start_timer();
1871          image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,          image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
1872                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1873                                            0);                                            pEnc->mbParam.m_quarterpel, 0);
1874          stop_inter_timer();          stop_inter_timer();
1875    
1876          start_timer();          start_timer();
1877    
1878          MotionEstimationBVOP(&pEnc->mbParam, frame,          MotionEstimationBVOP(&pEnc->mbParam, frame,
1879            ((int32_t)pEnc->mbParam.fbase + (int32_t)pEnc->mbParam.m_ticks + 1 - (int32_t)pEnc->last_pframe) % pEnc->mbParam.fbase,                  ((int32_t)(pEnc->current->stamp - frame->stamp)),                               // time_bp
1880                                                  pEnc->time_pp,                  ((int32_t)(pEnc->current->stamp - pEnc->reference->stamp)),     // time_pp
1881                                                  pEnc->reference->mbs, f_ref,                                                  pEnc->reference->mbs, f_ref,
1882                                                   &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,                                                   &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,
1883                                                   pEnc->current->mbs, b_ref, &pEnc->vInterH,                                                   pEnc->current->mbs, b_ref, &pEnc->vInterH,
# Line 1835  Line 1892 
1892             } */             } */
1893    
1894          frame->coding_type = B_VOP;          frame->coding_type = B_VOP;
1895    
1896            set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase);
1897          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1);
1898    
1899          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
# Line 1846  Line 1905 
1905    
1906    
1907          for (y = 0; y < pEnc->mbParam.mb_height; y++) {          for (y = 0; y < pEnc->mbParam.mb_height; y++) {
                 // reset prediction  
   
                 forward.x = 0;  
                 forward.y = 0;  
                 backward.x = 0;  
                 backward.y = 0;  
   
1908                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {
1909                          MACROBLOCK *f_mb =                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];
1910                                  &pEnc->reference->mbs[x + y * pEnc->mbParam.mb_width];                          int direction = pEnc->global & XVID_ALTERNATESCAN ? 2 : 0;
                         MACROBLOCK *b_mb =  
                                 &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];  
                         MACROBLOCK *mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];  
1911    
1912                          // decoder ignores mb when refence block is INTER(0,0), CBP=0                          // decoder ignores mb when refence block is INTER(0,0), CBP=0
1913                          if (mb->mode == MODE_NOT_CODED) {                          if (mb->mode == MODE_NOT_CODED) {
1914                                  mb->mvs[0].x = 0;                                  //mb->mvs[0].x = mb->mvs[0].y = mb->cbp = 0;
                                 mb->mvs[0].y = 0;  
   
                                 mb->cbp = 0;  
 #ifdef BFRAMES_DEC_DEBUG  
         BFRAME_DEBUG  
 #endif  
1915                                  continue;                                  continue;
1916                          }                          }
1917    
1918                            if (mb->mode != MODE_DIRECT_NONE_MV) {
1919                          MBMotionCompensationBVOP(&pEnc->mbParam, mb, x, y, &frame->image,                          MBMotionCompensationBVOP(&pEnc->mbParam, mb, x, y, &frame->image,
1920                                                                           f_ref, &pEnc->f_refh, &pEnc->f_refv,                                                                           f_ref, &pEnc->f_refh, &pEnc->f_refv,
1921                                                                           &pEnc->f_refhv, b_ref, &pEnc->vInterH,                                                                           &pEnc->f_refhv, b_ref, &pEnc->vInterH,
1922                                                                           &pEnc->vInterV, &pEnc->vInterHV,                                                                           &pEnc->vInterV, &pEnc->vInterHV,
1923                                                                           dct_codes);                                                                           dct_codes);
1924    
1925                                    if (mb->mode == MODE_DIRECT_NO4V) mb->mode = MODE_DIRECT;
1926                          mb->quant = frame->quant;                          mb->quant = frame->quant;
1927    
1928                          mb->cbp =                          mb->cbp =
1929                                  MBTransQuantInter(&pEnc->mbParam, frame, mb, x, y, dct_codes,                                          MBTransQuantInterBVOP(&pEnc->mbParam, frame, mb, dct_codes, qcoeff);
                                                                   qcoeff);  
                         //mb->cbp = MBTransQuantBVOP(&pEnc->mbParam, x, y, dct_codes, qcoeff, &frame->image, frame->quant);  
1930    
1931                          if ( (mb->mode == MODE_DIRECT) && (mb->cbp == 0)                          if ( (mb->mode == MODE_DIRECT) && (mb->cbp == 0)
1932                                  && (mb->deltamv.x == 0) && (mb->deltamv.y == 0) ) {                                          && (mb->pmvs[3].x == 0) && (mb->pmvs[3].y == 0) ) {
1933                                  mb->mode = MODE_DIRECT_NONE_MV; // skipped                                  mb->mode = MODE_DIRECT_NONE_MV; // skipped
1934                          }                          }
   
 /* update predictors for forward and backward vectors */  
                         if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_FORWARD) {  
                                 mb->pmvs[0].x = mb->mvs[0].x - forward.x;  
                                 mb->pmvs[0].y = mb->mvs[0].y - forward.y;  
                                 forward.x = mb->mvs[0].x;  
                                 forward.y = mb->mvs[0].y;  
                         }  
   
                         if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_BACKWARD) {  
                                 mb->b_pmvs[0].x = mb->b_mvs[0].x - backward.x;  
                                 mb->b_pmvs[0].y = mb->b_mvs[0].y - backward.y;  
                                 backward.x = mb->b_mvs[0].x;  
                                 backward.y = mb->b_mvs[0].y;  
1935                          }                          }
1936    
 //                      DPRINTF("%05i : [%i %i] M=%i CBP=%i MVS=%i,%i forward=%i,%i", pEnc->m_framenum, x, y, mb->mode, mb->cbp, mb->mvs[0].x, mb->mvs[0].y, forward.x, forward.y);  
   
1937  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1938          BFRAME_DEBUG          BFRAME_DEBUG
1939  #endif  #endif
1940                          start_timer();                          start_timer();
1941                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,
1942                                                   &pEnc->sStat);                                                   &pEnc->sStat, direction);
1943                          stop_coding_timer();                          stop_coding_timer();
1944                  }                  }
1945          }          }
# Line 1930  Line 1958 
1958          }          }
1959  #endif  #endif
1960  }  }
 #endif  
1961    
1962    
1963  /*      in case internal output is needed somewhere... */  /*      in case internal output is needed somewhere... */

Legend:
Removed from v.1.64  
changed lines
  Added in v.1.76.2.13

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