[svn] / branches / dev-api-3 / xvidcore / src / encoder.c Repository:
ViewVC logotype

Diff of /branches/dev-api-3/xvidcore/src/encoder.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/xvidcore/src/encoder.c revision 350, Tue Jul 30 12:14:37 2002 UTC branches/dev-api-3/xvidcore/src/encoder.c revision 543, Thu Sep 26 01:54:54 2002 UTC
# Line 39  Line 39 
39   *             MinChen <chenm001@163.com>   *             MinChen <chenm001@163.com>
40   *  14.04.2002 added FrameCodeB()   *  14.04.2002 added FrameCodeB()
41   *   *
42   *  $Id: encoder.c,v 1.67 2002-07-30 12:14:37 chl Exp $   *  $Id: encoder.c,v 1.76.2.2 2002-09-26 01:54:54 h Exp $
43   *   *
44   ****************************************************************************/   ****************************************************************************/
45    
# Line 70  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 94  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 238  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 276  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 295  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 308  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 341  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 425  Line 415 
415          pEnc->mbParam.m_ticks = 0;          pEnc->mbParam.m_ticks = 0;
416          pEnc->m_framenum = 0;          pEnc->m_framenum = 0;
417          pEnc->last_pframe = 0;          pEnc->last_pframe = 0;
418  #endif          pEnc->last_sync = 0;
419    
420          pParam->handle = (void *) pEnc;          pParam->handle = (void *) pEnc;
421    
# Line 444  Line 434 
434          /*          /*
435           * We handle all XVID_ERR_MEMORY here, this makes the code lighter           * We handle all XVID_ERR_MEMORY here, this makes the code lighter
436           */           */
437  #ifdef BFRAMES  
438    xvid_err_memory5:    xvid_err_memory5:
439    
440    
# Line 478  Line 468 
468                  xvid_free(pEnc->bframes);                  xvid_free(pEnc->bframes);
469          }          }
470    
 #endif  
   
471    xvid_err_memory3:    xvid_err_memory3:
472  #ifdef _DEBUG_PSNR  #ifdef _DEBUG_PSNR
473          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,
474                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
475  #endif  #endif
476    
 #ifdef BFRAMES  
477          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,
478                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
479          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,
480                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
481          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,
482                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
 #endif  
483    
484          image_destroy(&pEnc->current->image, pEnc->mbParam.edged_width,          image_destroy(&pEnc->current->image, pEnc->mbParam.edged_width,
485                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
# Line 538  Line 524 
524  int  int
525  encoder_destroy(Encoder * pEnc)  encoder_destroy(Encoder * pEnc)
526  {  {
 #ifdef BFRAMES  
527          int i;          int i;
 #endif  
528    
529          ENC_CHECK(pEnc);          ENC_CHECK(pEnc);
530    
531          /* B Frames specific */          /* B Frames specific */
 #ifdef BFRAMES  
532          if (pEnc->mbParam.max_bframes > 0) {          if (pEnc->mbParam.max_bframes > 0) {
533    
534                  for (i = 0; i < pEnc->mbParam.max_bframes; i++) {                  for (i = 0; i < pEnc->mbParam.max_bframes; i++) {
# Line 575  Line 558 
558                  xvid_free(pEnc->bframes);                  xvid_free(pEnc->bframes);
559    
560          }          }
 #endif  
561    
562          /* All images, reference, current etc ... */          /* All images, reference, current etc ... */
563    
# Line 593  Line 575 
575                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
576          image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width,
577                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
578  #ifdef BFRAMES  
579          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,
580                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
581          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,
582                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
583          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,
584                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
585  #endif  
586  #ifdef _DEBUG_PSNR  #ifdef _DEBUG_PSNR
587          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,
588                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
# Line 620  Line 602 
602  }  }
603    
604    
605  #ifdef BFRAMES  static __inline void inc_frame_num(Encoder * pEnc)
 void inc_frame_num(Encoder * pEnc)  
606  {  {
         pEnc->iFrameNum++;  
607          pEnc->mbParam.m_ticks += pEnc->mbParam.fincr;          pEnc->mbParam.m_ticks += pEnc->mbParam.fincr;
608    
         pEnc->mbParam.m_seconds = pEnc->mbParam.m_ticks / pEnc->mbParam.fbase;  
609          pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase;          pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase;
610            if (pEnc->mbParam.m_ticks < pEnc->last_sync)
611                    pEnc->mbParam.m_seconds = 1;
612                                    // more than 1 second since last I or P is not supported.
613            else
614                    pEnc->mbParam.m_seconds = 0;
615    
616  }  }
 #endif  
617    
618    
619  #ifdef BFRAMES  static __inline void
620  void queue_image(Encoder * pEnc, XVID_ENC_FRAME * pFrame)  queue_image(Encoder * pEnc, XVID_ENC_FRAME * pFrame)
621  {  {
622          if (pEnc->queue_size >= pEnc->mbParam.max_bframes)          if (pEnc->queue_size >= pEnc->mbParam.max_bframes)
623          {          {
# Line 656  Line 640 
640          pEnc->queue_size++;          pEnc->queue_size++;
641          pEnc->queue_tail =  (pEnc->queue_tail + 1) % pEnc->mbParam.max_bframes;          pEnc->queue_tail =  (pEnc->queue_tail + 1) % pEnc->mbParam.max_bframes;
642  }  }
 #endif  
643    
644    
645  #ifdef BFRAMES  
646  /*****************************************************************************  /*****************************************************************************
647   * IPB frame encoder entry point   * IPB frame encoder entry point
648   *   *
# Line 826  Line 809 
809    
810                  pFrame->intra = 0;                  pFrame->intra = 0;
811    
812                  BitstreamPutBits(&bs, 0x7f, 8);                  BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); // write N_VOP
813                  BitstreamPad(&bs);                  BitstreamPad(&bs);
814                  pFrame->length = BitstreamLength(&bs);                  pFrame->length = BitstreamLength(&bs);
815    
# Line 840  Line 823 
823    
824          pEnc->flush_bframes = 0;          pEnc->flush_bframes = 0;
825    
         /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
          * Well there was a separation here so i put it in ANSI C  
          * comment style :-)  
          * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */  
   
826          emms();          emms();
827    
828          // 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 1044  Line 1022 
1022                  goto bvop_loop;                  goto bvop_loop;
1023          }          }
1024    
1025            pEnc->iFrameNum++;
1026    
1027          BitstreamPad(&bs);          BitstreamPad(&bs);
1028          pFrame->length = BitstreamLength(&bs);          pFrame->length = BitstreamLength(&bs);
1029    
# Line 1079  Line 1059 
1059          return XVID_ERR_OK;          return XVID_ERR_OK;
1060  }  }
1061    
 #endif  
   
1062    
1063    
1064  /*****************************************************************************  /*****************************************************************************
# Line 1118  Line 1096 
1096    
1097          pEnc->current->global_flags = pFrame->general;          pEnc->current->global_flags = pFrame->general;
1098          pEnc->current->motion_flags = pFrame->motion;          pEnc->current->motion_flags = pFrame->motion;
 #ifdef BFRAMES  
1099          pEnc->current->seconds = pEnc->mbParam.m_seconds;          pEnc->current->seconds = pEnc->mbParam.m_seconds;
1100          pEnc->current->ticks = pEnc->mbParam.m_ticks;          pEnc->current->ticks = pEnc->mbParam.m_ticks;
 #endif  
1101          pEnc->mbParam.hint = &pFrame->hint;          pEnc->mbParam.hint = &pFrame->hint;
1102    
1103            /* disable alternate scan flag if interlacing is not enabled */
1104            if ((pEnc->current->global_flags & XVID_ALTERNATESCAN) &&
1105                    !(pEnc->current->global_flags & XVID_INTERLACING))
1106            {
1107                    pEnc->current->global_flags -= XVID_ALTERNATESCAN;
1108            }
1109    
1110          start_timer();          start_timer();
1111          if (image_input          if (image_input
1112                  (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,                  (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,
# Line 1251  Line 1234 
1234          DEBUG(temp);          DEBUG(temp);
1235  #endif  #endif
1236    
 #ifdef BFRAMES  
1237          inc_frame_num(pEnc);          inc_frame_num(pEnc);
 #else  
1238          pEnc->iFrameNum++;          pEnc->iFrameNum++;
 #endif  
   
1239    
1240          stop_global_timer();          stop_global_timer();
1241          write_timer();          write_timer();
# Line 1507  Line 1486 
1486          pEnc->current->coding_type = I_VOP;          pEnc->current->coding_type = I_VOP;
1487    
1488          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1489  #ifdef BFRAMES  
1490  #define DIVX501B481P "DivX501b481p"  #define DIVX501B481P "DivX501b481p"
1491          if ((pEnc->global & XVID_GLOBAL_PACKED)) {          if ((pEnc->global & XVID_GLOBAL_PACKED)) {
1492                  BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P));                  BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P));
1493          }          }
 #endif  
1494          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1495    
1496          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
# Line 1536  Line 1514 
1514                          stop_prediction_timer();                          stop_prediction_timer();
1515    
1516                          start_timer();                          start_timer();
1517                            if (pEnc->current->global_flags & XVID_GREYSCALE)
1518                            {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */
1519                                    qcoeff[4*64+0]=0;               /* zero, because for INTRA MBs DC value is saved */
1520                                    qcoeff[5*64+0]=0;
1521                            }
1522                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);
1523                          stop_coding_timer();                          stop_coding_timer();
1524                  }                  }
# Line 1548  Line 1531 
1531          pEnc->sStat.iMvCount = 0;          pEnc->sStat.iMvCount = 0;
1532          pEnc->mbParam.m_fcode = 2;          pEnc->mbParam.m_fcode = 2;
1533    
1534            pEnc->last_pframe = pEnc->current->ticks;
1535            pEnc->last_sync = pEnc->current->ticks;
1536    
1537          if (pEnc->current->global_flags & XVID_HINTEDME_GET) {          if (pEnc->current->global_flags & XVID_HINTEDME_GET) {
1538                  HintedMEGet(pEnc, 1);                  HintedMEGet(pEnc, 1);
1539          }          }
# Line 1557  Line 1543 
1543    
1544    
1545  #define INTRA_THRESHOLD 0.5  #define INTRA_THRESHOLD 0.5
1546  #define BFRAME_SKIP_THRESHHOLD 16  #define BFRAME_SKIP_THRESHHOLD 30
1547    
1548  static int  static int
1549  FrameCodeP(Encoder * pEnc,  FrameCodeP(Encoder * pEnc,
# Line 1572  Line 1558 
1558          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
1559    
1560          int iLimit;          int iLimit;
1561          int k;          int x, y, k;
         int x, y;  
1562          int iSearchRange;          int iSearchRange;
1563          int bIntra;          int bIntra;
1564    
# Line 1582  Line 1567 
1567    
1568          start_timer();          start_timer();
1569          image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,          image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1570                                     pEnc->mbParam.width, pEnc->mbParam.height,                                     pEnc->mbParam.width, pEnc->mbParam.height);
                                    pEnc->current->global_flags & XVID_INTERLACING);  
1571          stop_edges_timer();          stop_edges_timer();
1572    
1573          pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type;          pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type;
# Line 1609  Line 1593 
1593          start_timer();          start_timer();
1594          if (pEnc->current->global_flags & XVID_HINTEDME_SET) {          if (pEnc->current->global_flags & XVID_HINTEDME_SET) {
1595                  HintedMESet(pEnc, &bIntra);                  HintedMESet(pEnc, &bIntra);
1596                    if (bIntra == 0) MotionEstimationHinted(&pEnc->mbParam, pEnc->current, pEnc->reference,
1597                                                                                            &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV);
1598    
1599          } else {          } else {
1600    
 #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  
1601                  bIntra =                  bIntra =
1602                          MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,                          MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,
1603                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
# Line 1627  Line 1606 
1606          }          }
1607          stop_motion_timer();          stop_motion_timer();
1608    
1609          if (bIntra == 1) {          if (bIntra == 1) return FrameCodeI(pEnc, bs, pBits);
                 return FrameCodeI(pEnc, bs, pBits);  
         }  
1610    
1611          pEnc->current->coding_type = P_VOP;          pEnc->current->coding_type = P_VOP;
1612    
# Line 1640  Line 1617 
1617    
1618          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1619    
1620          pEnc->sStat.iTextBits = 0;          pEnc->sStat.iTextBits = pEnc->sStat.iMvSum = pEnc->sStat.iMvCount =
         pEnc->sStat.iMvSum = 0;  
         pEnc->sStat.iMvCount = 0;  
1621          pEnc->sStat.kblks = pEnc->sStat.mblks = pEnc->sStat.ublks = 0;          pEnc->sStat.kblks = pEnc->sStat.mblks = pEnc->sStat.ublks = 0;
1622    
1623          for (y = 0; y < pEnc->mbParam.mb_height; y++) {          for (y = 0; y < pEnc->mbParam.mb_height; y++) {
# Line 1677  Line 1652 
1652    
1653                                  pMB->field_pred = 0;                                  pMB->field_pred = 0;
1654    
1655                                    if (pMB->mode != MODE_NOT_CODED)
1656                                  pMB->cbp =                                  pMB->cbp =
1657                                          MBTransQuantInter(&pEnc->mbParam, pEnc->current, pMB, x, y,                                          MBTransQuantInter(&pEnc->mbParam, pEnc->current, pMB, x, y,
1658                                                                            dct_codes, qcoeff);                                                                            dct_codes, qcoeff);
# Line 1704  Line 1680 
1680    
1681                          /* Finished processing the MB, now check if to CODE or SKIP */                          /* Finished processing the MB, now check if to CODE or SKIP */
1682    
1683                          if (pMB->cbp == 0 && pMB->mode == MODE_INTER && pMB->mvs[0].x == 0 &&                          if ((pMB->mode == MODE_NOT_CODED) ||
1684                                  pMB->mvs[0].y == 0) {                                  (pMB->cbp == 0 && pMB->mode == MODE_INTER && pMB->mvs[0].x == 0 &&
1685                                    pMB->mvs[0].y == 0 && pMB->dquant == NO_CHANGE)) {
1686    
1687  /* This is a candidate for SKIPping, but check intermediate B-frames first */  /* This is a candidate for SKIPping, but check intermediate B-frames first */
1688    
 #ifdef BFRAMES  
                                 int iSAD=BFRAME_SKIP_THRESHHOLD;  
1689                                  int bSkip=1;                                  int bSkip=1;
1690                                    pMB->mode = MODE_NOT_CODED;
1691    
1692                                  for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++)                                  for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++)
1693                                  {                                  {
1694                                            int iSAD;
1695                                          iSAD = sad16(pEnc->reference->image.y + 16*y*pEnc->mbParam.edged_width + 16*x,                                          iSAD = sad16(pEnc->reference->image.y + 16*y*pEnc->mbParam.edged_width + 16*x,
1696                                                                  pEnc->bframes[k]->image.y + 16*y*pEnc->mbParam.edged_width + 16*x,                                                                  pEnc->bframes[k]->image.y + 16*y*pEnc->mbParam.edged_width + 16*x,
1697                                                                  pEnc->mbParam.edged_width,BFRAME_SKIP_THRESHHOLD);                                                                  pEnc->mbParam.edged_width,BFRAME_SKIP_THRESHHOLD);
1698                                          if (iSAD >= BFRAME_SKIP_THRESHHOLD)                                          if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant)
1699                                          {       bSkip = 0;                                          {       bSkip = 0;
1700                                                  break;                                                  break;
1701                                          }                                          }
1702                                  }                                  }
1703                                  if (!bSkip)                                  if (!bSkip)
1704                                  {                                  {
1705                                            VECTOR predMV;
1706                                            predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);
1707                                            pMB->pmvs[0].x = -predMV.x; pMB->pmvs[0].y = -predMV.y;
1708                                            pMB->mode = MODE_INTER;
1709                                            pMB->cbp = 0;
1710                                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);                                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);
                                         pMB->cbp = 0x80;                /* trick! so cbp!=0, but still nothing is written to bs */  
1711                                  }                                  }
1712                                  else                                  else MBSkip(bs);
                                         MBSkip(bs);  
   
   
 #else  
                                         MBSkip(bs);     /* without B-frames, no precautions are needed */  
   
 #endif  
1713    
1714                          } else {                          } else {
1715                                    if (pEnc->current->global_flags & XVID_GREYSCALE)
1716                                    {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */
1717                                            qcoeff[4*64+0]=0;               /* zero, because DC for INTRA MBs DC value is saved */
1718                                            qcoeff[5*64+0]=0;
1719                                    }
1720                                  MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);                                  MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);
1721                          }                          }
1722    
# Line 1800  Line 1779 
1779    
1780          *pBits = BitstreamPos(bs) - *pBits;          *pBits = BitstreamPos(bs) - *pBits;
1781    
 #ifdef BFRAMES  
1782          pEnc->time_pp = ((int32_t)pEnc->mbParam.fbase - (int32_t)pEnc->last_pframe + (int32_t)pEnc->current->ticks) %          pEnc->time_pp = ((int32_t)pEnc->mbParam.fbase - (int32_t)pEnc->last_pframe + (int32_t)pEnc->current->ticks) %
1783                          (int32_t)pEnc->mbParam.fbase;                          (int32_t)pEnc->mbParam.fbase;
1784          pEnc->last_pframe = pEnc->current->ticks;          pEnc->last_pframe = pEnc->current->ticks;
 #endif  
1785    
1786          return 0;                                       // inter          return 0;                                       // inter
1787  }  }
1788    
1789    
1790  #ifdef BFRAMES  static __inline void
 static void  
1791  FrameCodeB(Encoder * pEnc,  FrameCodeB(Encoder * pEnc,
1792                     FRAMEINFO * frame,                     FRAMEINFO * frame,
1793                     Bitstream * bs,                     Bitstream * bs,
# Line 1820  Line 1796 
1796          int16_t dct_codes[6 * 64];          int16_t dct_codes[6 * 64];
1797          int16_t qcoeff[6 * 64];          int16_t qcoeff[6 * 64];
1798          uint32_t x, y;          uint32_t x, y;
         VECTOR forward;  
         VECTOR backward;  
1799    
1800          IMAGE *f_ref = &pEnc->reference->image;          IMAGE *f_ref = &pEnc->reference->image;
1801          IMAGE *b_ref = &pEnc->current->image;          IMAGE *b_ref = &pEnc->current->image;
# Line 1841  Line 1815 
1815          // forward          // forward
1816          image_setedges(f_ref, pEnc->mbParam.edged_width,          image_setedges(f_ref, pEnc->mbParam.edged_width,
1817                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,
1818                                     pEnc->mbParam.height,                                     pEnc->mbParam.height);
                                    frame->global_flags & XVID_INTERLACING);  
1819          start_timer();          start_timer();
1820          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,
1821                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
# Line 1852  Line 1825 
1825          // backward          // backward
1826          image_setedges(b_ref, pEnc->mbParam.edged_width,          image_setedges(b_ref, pEnc->mbParam.edged_width,
1827                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,
1828                                     pEnc->mbParam.height,                                     pEnc->mbParam.height);
                                    frame->global_flags & XVID_INTERLACING);  
1829          start_timer();          start_timer();
1830          image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,          image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
1831                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,                                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
# Line 1889  Line 1861 
1861    
1862    
1863          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;  
   
1864                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {
1865                          MACROBLOCK *f_mb =                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];
1866                                  &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];  
1867    
1868                          // decoder ignores mb when refence block is INTER(0,0), CBP=0                          // decoder ignores mb when refence block is INTER(0,0), CBP=0
1869                          if (mb->mode == MODE_NOT_CODED) {                          if (mb->mode == MODE_NOT_CODED) {
1870                                  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  
1871                                  continue;                                  continue;
1872                          }                          }
1873    
1874                            if (mb->mode != MODE_DIRECT_NONE_MV) {
1875                          MBMotionCompensationBVOP(&pEnc->mbParam, mb, x, y, &frame->image,                          MBMotionCompensationBVOP(&pEnc->mbParam, mb, x, y, &frame->image,
1876                                                                           f_ref, &pEnc->f_refh, &pEnc->f_refv,                                                                           f_ref, &pEnc->f_refh, &pEnc->f_refv,
1877                                                                           &pEnc->f_refhv, b_ref, &pEnc->vInterH,                                                                           &pEnc->f_refhv, b_ref, &pEnc->vInterH,
1878                                                                           &pEnc->vInterV, &pEnc->vInterHV,                                                                           &pEnc->vInterV, &pEnc->vInterHV,
1879                                                                           dct_codes);                                                                           dct_codes);
1880    
1881                                    if (mb->mode == MODE_DIRECT_NO4V) mb->mode = MODE_DIRECT;
1882                          mb->quant = frame->quant;                          mb->quant = frame->quant;
1883    
1884                          mb->cbp =                          mb->cbp =
1885                                  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);  
1886    
1887                          if ( (mb->mode == MODE_DIRECT) && (mb->cbp == 0)                          if ( (mb->mode == MODE_DIRECT) && (mb->cbp == 0)
1888                                  && (mb->deltamv.x == 0) && (mb->deltamv.y == 0) ) {                                          && (mb->pmvs[3].x == 0) && (mb->pmvs[3].y == 0) ) {
1889                                  mb->mode = MODE_DIRECT_NONE_MV; // skipped                                  mb->mode = MODE_DIRECT_NONE_MV; // skipped
1890                          }                          }
   
 /* 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;  
1891                          }                          }
1892    
 //                      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);  
   
1893  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG
1894          BFRAME_DEBUG          BFRAME_DEBUG
1895  #endif  #endif
1896                          start_timer();                          start_timer();
1897                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,
1898                                                   &pEnc->sStat);                                                   &pEnc->sStat, direction);
1899                          stop_coding_timer();                          stop_coding_timer();
1900                  }                  }
1901          }          }
# Line 1973  Line 1914 
1914          }          }
1915  #endif  #endif
1916  }  }
 #endif  
1917    
1918    
1919  /*      in case internal output is needed somewhere... */  /*      in case internal output is needed somewhere... */

Legend:
Removed from v.350  
changed lines
  Added in v.543

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