[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.44, Thu Jun 20 14:05:57 2002 UTC revision 1.58, Fri Jul 19 15:02:38 2002 UTC
# Line 32  Line 32 
32   *   *
33   *  History   *  History
34   *   *
35     *  10.07.2002  added BFRAMES_DEC_DEBUG support
36     *              MinChen <chenm001@163.com>
37   *      20.06.2002 bframe patch   *      20.06.2002 bframe patch
38   *  08.05.2002 fix some problem in DEBUG mode;   *  08.05.2002 fix some problem in DEBUG mode;
39   *             MinChen <chenm001@163.com>   *             MinChen <chenm001@163.com>
# Line 51  Line 53 
53  #include "global.h"  #include "global.h"
54  #include "utils/timer.h"  #include "utils/timer.h"
55  #include "image/image.h"  #include "image/image.h"
56    #ifdef BFRAMES
57    #include "image/font.h"
58    #endif
59  #include "motion/motion.h"  #include "motion/motion.h"
60  #include "bitstream/cbp.h"  #include "bitstream/cbp.h"
61  #include "utils/mbfunctions.h"  #include "utils/mbfunctions.h"
# Line 63  Line 68 
68  #include "quant/quant_matrix.h"  #include "quant/quant_matrix.h"
69  #include "utils/mem_align.h"  #include "utils/mem_align.h"
70    
71    #ifdef _SMP
72    #include "motion/smp_motion_est.h"
73    #endif
74  /*****************************************************************************  /*****************************************************************************
75   * Local macros   * Local macros
76   ****************************************************************************/   ****************************************************************************/
# Line 204  Line 212 
212          if (pParam->max_key_interval == 0)          if (pParam->max_key_interval == 0)
213                  pParam->max_key_interval = 10 * pParam->fincr / pParam->fbase;                  pParam->max_key_interval = 10 * pParam->fincr / pParam->fbase;
214    
   
215          pEnc = (Encoder *) xvid_malloc(sizeof(Encoder), CACHE_LINE);          pEnc = (Encoder *) xvid_malloc(sizeof(Encoder), CACHE_LINE);
216          if (pEnc == NULL)          if (pEnc == NULL)
217                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
# Line 229  Line 236 
236    
237          pEnc->mbParam.m_quant_type = H263_QUANT;          pEnc->mbParam.m_quant_type = H263_QUANT;
238    
239    #ifdef _SMP
240            pEnc->mbParam.num_threads = MIN(pParam->num_threads, MAXNUMTHREADS);
241    #endif
242    
243          pEnc->sStat.fMvPrevSigma = -1;          pEnc->sStat.fMvPrevSigma = -1;
244    
245          /* Fill rate control parameters */          /* Fill rate control parameters */
# Line 330  Line 341 
341          /* B Frames specific init */          /* B Frames specific init */
342  #ifdef BFRAMES  #ifdef BFRAMES
343    
344          pEnc->packed = pParam->packed;          pEnc->global = pParam->global;
345          pEnc->mbParam.max_bframes = pParam->max_bframes;          pEnc->mbParam.max_bframes = pParam->max_bframes;
346          pEnc->bquant_ratio = pParam->bquant_ratio;          pEnc->bquant_ratio = pParam->bquant_ratio;
347          pEnc->bframes = NULL;          pEnc->bframes = NULL;
# Line 375  Line 386 
386          pEnc->bframenum_head = 0;          pEnc->bframenum_head = 0;
387          pEnc->bframenum_tail = 0;          pEnc->bframenum_tail = 0;
388          pEnc->flush_bframes = 0;          pEnc->flush_bframes = 0;
389            pEnc->bframenum_dx50bvop = -1;
390    
391          pEnc->queue = NULL;          pEnc->queue = NULL;
392    
# Line 408  Line 420 
420    
421          pEnc->mbParam.m_seconds = 0;          pEnc->mbParam.m_seconds = 0;
422          pEnc->mbParam.m_ticks = 0;          pEnc->mbParam.m_ticks = 0;
423            pEnc->m_framenum = 0;
424            pEnc->last_pframe = 1;
425  #endif  #endif
426    
427          pParam->handle = (void *) pEnc;          pParam->handle = (void *) pEnc;
# Line 608  Line 622 
622  {  {
623          pEnc->iFrameNum++;          pEnc->iFrameNum++;
624          pEnc->mbParam.m_ticks += pEnc->mbParam.fincr;          pEnc->mbParam.m_ticks += pEnc->mbParam.fincr;
         if (pEnc->mbParam.m_ticks > pEnc->mbParam.fbase) {  
                 pEnc->mbParam.m_seconds++;  
                 pEnc->mbParam.m_ticks = 0;  
         }  
625    
626            pEnc->mbParam.m_seconds = pEnc->mbParam.m_ticks / pEnc->mbParam.fbase;
627            pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase;
628  }  }
629  #endif  #endif
630    
# Line 622  Line 634 
634  {  {
635          if (pEnc->queue_size >= pEnc->mbParam.max_bframes)          if (pEnc->queue_size >= pEnc->mbParam.max_bframes)
636          {          {
637                  DPRINTF("FATAL: QUEUE FULL");                  DPRINTF(DPRINTF_DEBUG,"FATAL: QUEUE FULL");
638                  return;                  return;
639          }          }
640    
641          DPRINTF("*** QUEUE bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",          DPRINTF(DPRINTF_DEBUG,"*** QUEUE bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
642                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
643                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
644    
# Line 694  Line 706 
706                           * frame as a pframe                           * frame as a pframe
707                           */                           */
708    
709                          DPRINTF("*** BFRAME (final frame) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",                          DPRINTF(DPRINTF_DEBUG,"*** BFRAME (final frame) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
710                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
711                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
712    
# Line 713  Line 725 
725                  }                  }
726    
727    
728                  DPRINTF("*** BFRAME (flush) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",                  DPRINTF(DPRINTF_DEBUG,"*** BFRAME (flush) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
729                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
730                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
731    
# Line 733  Line 745 
745          if (pEnc->bframenum_head > 0) {          if (pEnc->bframenum_head > 0) {
746                  pEnc->bframenum_head = pEnc->bframenum_tail = 0;                  pEnc->bframenum_head = pEnc->bframenum_tail = 0;
747    
748                  if (pEnc->packed) {                  if ((pEnc->global & XVID_GLOBAL_PACKED)) {
749    
750                          DPRINTF("*** 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",
751                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
752                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
753    
   
754                          BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);                          BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);
755                          BitstreamPad(&bs);                          BitstreamPad(&bs);
756                          BitstreamPutBits(&bs, 0x7f, 8);                          BitstreamPutBits(&bs, 0x7f, 8);
# Line 757  Line 768 
768    
769  bvop_loop:  bvop_loop:
770    
771          if (input_valid) {          if (pEnc->bframenum_dx50bvop != -1)
772            {
773    
774                    SWAP(pEnc->current, pEnc->reference);
775                    SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]);
776    
777                    if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
778                            image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 IVOP");
779                    }
780    
781                    if (input_valid)
782                    {
783                            queue_image(pEnc, pFrame);
784                            input_valid = 0;
785                    }
786    
787            } else if (input_valid) {
788    
789                  SWAP(pEnc->current, pEnc->reference);                  SWAP(pEnc->current, pEnc->reference);
790    
# Line 790  Line 817 
817    
818          } else if (BitstreamPos(&bs) == 0) {          } else if (BitstreamPos(&bs) == 0) {
819    
820                  DPRINTF("*** 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",
821                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
822                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
823    
   
824                  pFrame->intra = 0;                  pFrame->intra = 0;
825    
826                  BitstreamPutBits(&bs, 0x7f, 8);                  BitstreamPutBits(&bs, 0x7f, 8);
# Line 816  Line 842 
842           * comment style :-)           * comment style :-)
843           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
844    
 //$$    SWAP(pEnc->current, pEnc->reference);  
   
845          emms();          emms();
846    
847            // only inc frame num, adapt quant, etc. if we havent seen it before
848            if (pEnc->bframenum_dx50bvop < 0 )
849            {
850          if (pFrame->quant == 0)          if (pFrame->quant == 0)
851                  pEnc->current->quant = RateControlGetQ(&pEnc->rate_control, 0);                  pEnc->current->quant = RateControlGetQ(&pEnc->rate_control, 0);
852          else          else
# Line 833  Line 860 
860    
861          pEnc->current->global_flags = pFrame->general;          pEnc->current->global_flags = pFrame->general;
862          pEnc->current->motion_flags = pFrame->motion;          pEnc->current->motion_flags = pFrame->motion;
863          pEnc->current->seconds = pEnc->mbParam.m_seconds;  
         pEnc->current->ticks = pEnc->mbParam.m_ticks;  
864          /* ToDo : dynamic fcode (in both directions) */          /* ToDo : dynamic fcode (in both directions) */
865          pEnc->current->fcode = pEnc->mbParam.m_fcode;          pEnc->current->fcode = pEnc->mbParam.m_fcode;
866          pEnc->current->bcode = pEnc->mbParam.m_fcode;          pEnc->current->bcode = pEnc->mbParam.m_fcode;
867    
868  //$$$   start_timer();                  pEnc->current->seconds = pEnc->mbParam.m_seconds;
869  //$$$   if (image_input                  pEnc->current->ticks = pEnc->mbParam.m_ticks;
870  //$$$           (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,  
871  //$$$            pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))                  inc_frame_num(pEnc);
 //$$$           return XVID_ERR_FORMAT;  
 //$$$   stop_conv_timer();  
872    
873  #ifdef _DEBUG_PSNR  #ifdef _DEBUG_PSNR
874          image_copy(&pEnc->sOriginal, &pEnc->current->image,          image_copy(&pEnc->sOriginal, &pEnc->current->image,
# Line 853  Line 877 
877    
878          emms();          emms();
879    
880                    if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
881                            image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5,
882                                    "%i  if:%i  st:%i:%i", pEnc->m_framenum++, pEnc->iFrameNum, pEnc->current->seconds, pEnc->current->ticks);
883                    }
884    
885          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
886           * Luminance masking           * Luminance masking
887           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
# Line 882  Line 911 
911                          }                          }
912    
913  #undef OFFSET  #undef OFFSET
   
914                  }                  }
915    
916                  xvid_free(temp_dquants);                  xvid_free(temp_dquants);
917          }          }
918    
919            }
920    
921          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
922           * ivop/pvop/bvop selection           * ivop/pvop/bvop selection
923           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
924    
925    
926          if (pEnc->iFrameNum == 0 || pFrame->intra == 1 ||          if (pEnc->iFrameNum == 0 || pFrame->intra == 1 || pEnc->bframenum_dx50bvop >= 0 ||
927                  (pFrame->intra < 0 && pEnc->iMaxKeyInterval > 0 &&                  (pFrame->intra < 0 && pEnc->iMaxKeyInterval > 0 &&
928                   pEnc->iFrameNum >= pEnc->iMaxKeyInterval)                   pEnc->iFrameNum >= pEnc->iMaxKeyInterval)
929                  || image_mad(&pEnc->reference->image, &pEnc->current->image,                  || image_mad(&pEnc->reference->image, &pEnc->current->image,
# Line 903  Line 933 
933                   * This will be coded as an Intra Frame                   * This will be coded as an Intra Frame
934                   */                   */
935    
936                  DPRINTF("*** IFRAME bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",                  DPRINTF(DPRINTF_DEBUG,"*** IFRAME bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
937                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
938                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
939    
940                  FrameCodeI(pEnc, &bs, &bits);                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
941                            image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP");
942                    }
943    
944                    // when we reach an iframe in DX50BVOP mode, encode the last bframe as a pframe
945    
946                    if ((pEnc->global & XVID_GLOBAL_DX50BVOP) && pEnc->bframenum_tail > 0) {
947    
948                            pEnc->bframenum_tail--;
949                            pEnc->bframenum_dx50bvop = pEnc->bframenum_tail;
950    
951                            SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]);
952                            if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
953                                    image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP");
954                            }
955                            FrameCodeP(pEnc, &bs, &bits, 1, 0);
956    
957                            pFrame->intra = 0;
958    
959                    } else {
960    
961                            FrameCodeI(pEnc, &bs, &bits);
962                  pFrame->intra = 1;                  pFrame->intra = 1;
                 pEnc->flush_bframes = 1;  
963    
964                  inc_frame_num(pEnc);                          pEnc->bframenum_dx50bvop = -1;
965                    }
966    
967                    pEnc->flush_bframes = 1;
968    
969                  if (pEnc->packed) {                  if ((pEnc->global & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) {
970                          BitstreamPad(&bs);                          BitstreamPad(&bs);
971                          input_valid = 0;                          input_valid = 0;
972                          goto ipvop_loop;                          goto ipvop_loop;
# Line 929  Line 981 
981                   * This will be coded as a Predicted Frame                   * This will be coded as a Predicted Frame
982                   */                   */
983    
984                  DPRINTF("*** PFRAME bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",                  DPRINTF(DPRINTF_DEBUG,"*** PFRAME bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
985                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
986                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
987    
988                    if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
989                            image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP");
990                    }
991    
992                  FrameCodeP(pEnc, &bs, &bits, 1, 0);                  FrameCodeP(pEnc, &bs, &bits, 1, 0);
993                  pFrame->intra = 0;                  pFrame->intra = 0;
994                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
995    
996                  inc_frame_num(pEnc);                  if ((pEnc->global & XVID_GLOBAL_PACKED)) {
   
                 if (pEnc->packed) {  
997                          BitstreamPad(&bs);                          BitstreamPad(&bs);
998                          input_valid = 0;                          input_valid = 0;
999                          goto ipvop_loop;                          goto ipvop_loop;
# Line 950  Line 1004 
1004                   * This will be coded as a Bidirectional Frame                   * This will be coded as a Bidirectional Frame
1005                   */                   */
1006    
1007                  DPRINTF("*** BFRAME (store) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",                  DPRINTF(DPRINTF_DEBUG,"*** BFRAME (store) bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
1008                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
1009                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
1010    
1011                    if ((pEnc->global & XVID_GLOBAL_DEBUG)) {
1012                            image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP");
1013                    }
1014    
1015                  if (pFrame->bquant < 1) {                  if (pFrame->bquant < 1) {
1016                          pEnc->current->quant =                          pEnc->current->quant =
1017                                  ((pEnc->reference->quant +                                  ((pEnc->reference->quant +
# Line 971  Line 1029 
1029                  pFrame->intra = 0;                  pFrame->intra = 0;
1030                  pFrame->length = 0;                  pFrame->length = 0;
1031    
                 inc_frame_num(pEnc);  
   
1032                  input_valid = 0;                  input_valid = 0;
1033                  goto bvop_loop;                  goto bvop_loop;
1034          }          }
# Line 1265  Line 1321 
1321                                  &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];                                  &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];
1322                          MVBLOCKHINT *bhint =                          MVBLOCKHINT *bhint =
1323                                  &hint->mvhint.block[x + y * pEnc->mbParam.mb_width];                                  &hint->mvhint.block[x + y * pEnc->mbParam.mb_width];
1324                          VECTOR pred[4];                          VECTOR pred;
1325                          VECTOR tmp;                          VECTOR tmp;
                         int32_t dummy[4];  
1326                          int vec;                          int vec;
1327    
1328                          pMB->mode =                          pMB->mode =
# Line 1287  Line 1342 
1342                                  tmp.x -= (tmp.x >= high) ? high * 2 : 0;                                  tmp.x -= (tmp.x >= high) ? high * 2 : 0;
1343                                  tmp.y -= (tmp.y >= high) ? high * 2 : 0;                                  tmp.y -= (tmp.y >= high) ? high * 2 : 0;
1344    
1345                                  get_pmvdata(pEnc->current->mbs, x, y, pEnc->mbParam.mb_width,                                  pred = get_pmv2(pEnc->current->mbs,pEnc->mbParam.mb_width,0,x,y,0);
                                                         0, pred, dummy);  
1346    
1347                                  for (vec = 0; vec < 4; ++vec) {                                  for (vec = 0; vec < 4; ++vec) {
1348                                          pMB->mvs[vec].x = tmp.x;                                          pMB->mvs[vec].x = tmp.x;
1349                                          pMB->mvs[vec].y = tmp.y;                                          pMB->mvs[vec].y = tmp.y;
1350                                          pMB->pmvs[vec].x = pMB->mvs[0].x - pred[0].x;                                          pMB->pmvs[vec].x = pMB->mvs[0].x - pred.x;
1351                                          pMB->pmvs[vec].y = pMB->mvs[0].y - pred[0].y;                                          pMB->pmvs[vec].y = pMB->mvs[0].y - pred.y;
1352                                  }                                  }
1353                          } else if (pMB->mode == MODE_INTER4V) {                          } else if (pMB->mode == MODE_INTER4V) {
1354                                  for (vec = 0; vec < 4; ++vec) {                                  for (vec = 0; vec < 4; ++vec) {
# Line 1307  Line 1361 
1361                                          tmp.x -= (tmp.x >= high) ? high * 2 : 0;                                          tmp.x -= (tmp.x >= high) ? high * 2 : 0;
1362                                          tmp.y -= (tmp.y >= high) ? high * 2 : 0;                                          tmp.y -= (tmp.y >= high) ? high * 2 : 0;
1363    
1364                                          get_pmvdata(pEnc->current->mbs, x, y,                                          pred = get_pmv2(pEnc->current->mbs,pEnc->mbParam.mb_width,0,x,y,vec);
                                                                 pEnc->mbParam.mb_width, vec, pred, dummy);  
1365    
1366                                          pMB->mvs[vec].x = tmp.x;                                          pMB->mvs[vec].x = tmp.x;
1367                                          pMB->mvs[vec].y = tmp.y;                                          pMB->mvs[vec].y = tmp.y;
1368                                          pMB->pmvs[vec].x = pMB->mvs[vec].x - pred[0].x;                                          pMB->pmvs[vec].x = pMB->mvs[vec].x - pred.x;
1369                                          pMB->pmvs[vec].y = pMB->mvs[vec].y - pred[0].y;                                          pMB->pmvs[vec].y = pMB->mvs[vec].y - pred.y;
1370                                  }                                  }
1371                          } else                          // intra / stuffing / not_coded                          } else                          // intra / stuffing / not_coded
1372                          {                          {
# Line 1445  Line 1498 
1498          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1499  #ifdef BFRAMES  #ifdef BFRAMES
1500  #define DIVX501B481P "DivX501b481p"  #define DIVX501B481P "DivX501b481p"
1501          if (pEnc->packed) {          if ((pEnc->global & XVID_GLOBAL_PACKED)) {
1502                  BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P));                  BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P));
1503          }          }
1504  #endif  #endif
# Line 1544  Line 1597 
1597          if (pEnc->current->global_flags & XVID_HINTEDME_SET) {          if (pEnc->current->global_flags & XVID_HINTEDME_SET) {
1598                  HintedMESet(pEnc, &bIntra);                  HintedMESet(pEnc, &bIntra);
1599          } else {          } else {
1600    
1601    #ifdef _SMP
1602            if (pEnc->mbParam.num_threads > 1)
1603                    bIntra =
1604                            SMP_MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,
1605                                                     &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
1606                                                     iLimit);
1607            else
1608    #endif
1609                  bIntra =                  bIntra =
1610                          MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,                          MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,
1611                                                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,                                                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
1612                                                           iLimit);                                                           iLimit);
1613    
1614          }          }
1615          stop_motion_timer();          stop_motion_timer();
1616    
# Line 1661  Line 1724 
1724    
1725          *pBits = BitstreamPos(bs) - *pBits;          *pBits = BitstreamPos(bs) - *pBits;
1726    
1727            pEnc->time_pp = ((int32_t)pEnc->mbParam.fbase - (int32_t)pEnc->last_pframe + (int32_t)pEnc->mbParam.m_ticks) % (int32_t)pEnc->mbParam.fbase;
1728    
1729            pEnc->last_pframe = pEnc->mbParam.m_ticks;
1730          return 0;                                       // inter          return 0;                                       // inter
1731  }  }
1732    
# Line 1681  Line 1747 
1747          IMAGE *f_ref = &pEnc->reference->image;          IMAGE *f_ref = &pEnc->reference->image;
1748          IMAGE *b_ref = &pEnc->current->image;          IMAGE *b_ref = &pEnc->current->image;
1749    
1750    #ifdef BFRAMES_DEC_DEBUG
1751            FILE *fp;
1752            static char first=0;
1753    #define BFRAME_DEBUG    if (!first && fp){ \
1754                    fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mode,mb->cbp); \
1755            }
1756    
1757            if (!first){
1758                    fp=fopen("C:\\XVIDDBGE.TXT","w");
1759            }
1760    #endif
1761    
1762          // forward          // forward
1763          image_setedges(f_ref, pEnc->mbParam.edged_width,          image_setedges(f_ref, pEnc->mbParam.edged_width,
1764                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,
# Line 1704  Line 1782 
1782          stop_inter_timer();          stop_inter_timer();
1783    
1784          start_timer();          start_timer();
1785          MotionEstimationBVOP(&pEnc->mbParam, frame, pEnc->reference->mbs, f_ref,          MotionEstimationBVOP(&pEnc->mbParam, frame,
1786              ((int32_t)pEnc->mbParam.fbase + (int32_t)pEnc->mbParam.m_ticks + 1 - (int32_t)pEnc->last_pframe) % pEnc->mbParam.fbase,
1787                                                    pEnc->time_pp,
1788                                                    pEnc->reference->mbs, f_ref,
1789                                                   &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,                                                   &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv,
1790                                                   pEnc->current->mbs, b_ref, &pEnc->vInterH,                                                   pEnc->current->mbs, b_ref, &pEnc->vInterH,
1791                                                   &pEnc->vInterV, &pEnc->vInterHV);                                                   &pEnc->vInterV, &pEnc->vInterHV);
# Line 1747  Line 1828 
1828                          if (mb->mode == MODE_NOT_CODED) {                          if (mb->mode == MODE_NOT_CODED) {
1829                                  mb->mvs[0].x = 0;                                  mb->mvs[0].x = 0;
1830                                  mb->mvs[0].y = 0;                                  mb->mvs[0].y = 0;
1831    
1832                                    mb->cbp = 0;
1833    #ifdef BFRAMES_DEC_DEBUG
1834            BFRAME_DEBUG
1835    #endif
1836                                  continue;                                  continue;
1837                          }                          }
1838    
# Line 1765  Line 1851 
1851    
1852                          if ((mb->mode == MODE_INTERPOLATE || mb->mode == MODE_DIRECT)                          if ((mb->mode == MODE_INTERPOLATE || mb->mode == MODE_DIRECT)
1853                                  && mb->cbp == 0 && mb->mvs[0].x == 0 && mb->mvs[0].y == 0) {                                  && mb->cbp == 0 && mb->mvs[0].x == 0 && mb->mvs[0].y == 0) {
1854                                  mb->mode = 5;   // skipped                                  mb->mode = MODE_DIRECT_NONE_MV; // skipped
1855                          }                          }
1856    
1857                          if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_FORWARD) {                          if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_FORWARD) {
# Line 1781  Line 1867 
1867                                  backward.x = mb->b_mvs[0].x;                                  backward.x = mb->b_mvs[0].x;
1868                                  backward.y = mb->b_mvs[0].y;                                  backward.y = mb->b_mvs[0].y;
1869                          }                          }
1870  //          printf("[%i %i] M=%i CBP=%i MVX=%i MVY=%i %i,%i  %i,%i\n", x, y, pMB->mode, pMB->cbp, pMB->mvs[0].x, bmb->pmvs[0].x, bmb->pmvs[0].y, forward.x, forward.y);  //                      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);
1871    
1872    #ifdef BFRAMES_DEC_DEBUG
1873            BFRAME_DEBUG
1874    #endif
1875                          start_timer();                          start_timer();
1876                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,
1877                                                   &pEnc->sStat);                                                   &pEnc->sStat);
# Line 1795  Line 1884 
1884          // TODO: dynamic fcode/bcode ???          // TODO: dynamic fcode/bcode ???
1885    
1886          *pBits = BitstreamPos(bs) - *pBits;          *pBits = BitstreamPos(bs) - *pBits;
1887    
1888    #ifdef BFRAMES_DEC_DEBUG
1889            if (!first){
1890                    first=1;
1891                    if (fp)
1892                            fclose(fp);
1893            }
1894    #endif
1895  }  }
1896  #endif  #endif

Legend:
Removed from v.1.44  
changed lines
  Added in v.1.58

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