[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

revision 602, Thu Oct 17 19:10:57 2002 UTC revision 631, Thu Nov 7 10:31:03 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.76.2.13 2002-10-17 19:10:57 Isibaar Exp $   *  $Id: encoder.c,v 1.76.2.16 2002-11-07 10:28:15 suxen_drol Exp $
43   *   *
44   ****************************************************************************/   ****************************************************************************/
45    
# Line 54  Line 54 
54  #include "global.h"  #include "global.h"
55  #include "utils/timer.h"  #include "utils/timer.h"
56  #include "image/image.h"  #include "image/image.h"
 #ifdef BFRAMES  
57  #include "image/font.h"  #include "image/font.h"
58  #include "motion/sad.h"  #include "motion/sad.h"
 #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 109  Line 107 
107  };  };
108    
109    
 static void __inline  
 image_null(IMAGE * image)  
 {  
         image->y = image->u = image->v = NULL;  
 }  
   
   
110  /*****************************************************************************  /*****************************************************************************
111   * Encoder creation   * Encoder creation
112   *   *
# Line 625  Line 616 
616          start_timer();          start_timer();
617          if (image_input          if (image_input
618                  (&pEnc->queue[pEnc->queue_tail], pEnc->mbParam.width, pEnc->mbParam.height,                  (&pEnc->queue[pEnc->queue_tail], pEnc->mbParam.width, pEnc->mbParam.height,
619                   pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))                   pEnc->mbParam.edged_width, pFrame->image, pFrame->stride, pFrame->colorspace, pFrame->general & XVID_INTERLACING))
620                  return;                  return;
621          stop_conv_timer();          stop_conv_timer();
622    
# Line 720  Line 711 
711                          pFrame->length = BitstreamLength(&bs);                          pFrame->length = BitstreamLength(&bs);
712                          pFrame->intra = 0;                          pFrame->intra = 0;
713    
714                            emms();
715    
716                          return XVID_ERR_OK;                          return XVID_ERR_OK;
717                  }                  }
718    
# Line 738  Line 731 
731                  if (input_valid)                  if (input_valid)
732                          queue_image(pEnc, pFrame);                          queue_image(pEnc, pFrame);
733    
734                    emms();
735    
736                  return XVID_ERR_OK;                  return XVID_ERR_OK;
737          }          }
738    
# Line 771  Line 766 
766                          if (input_valid)                          if (input_valid)
767                                  queue_image(pEnc, pFrame);                                  queue_image(pEnc, pFrame);
768    
769                            emms();
770    
771                          return XVID_ERR_OK;                          return XVID_ERR_OK;
772                  }                  }
773          }          }
# Line 801  Line 798 
798                  start_timer();                  start_timer();
799                  if (image_input                  if (image_input
800                          (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,                          (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,
801                          pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace))                          pEnc->mbParam.edged_width, pFrame->image, pFrame->stride, pFrame->colorspace, pFrame->general & XVID_INTERLACING))
802                    {
803                            emms();
804                          return XVID_ERR_FORMAT;                          return XVID_ERR_FORMAT;
805                    }
806                  stop_conv_timer();                  stop_conv_timer();
807    
808                  // queue input frame, and dequue next image                  // queue input frame, and dequue next image
# Line 841  Line 841 
841                  }                  }
842    
843                  pFrame->length = BitstreamLength(&bs);                  pFrame->length = BitstreamLength(&bs);
844                    emms();
845                  return XVID_ERR_OK;                  return XVID_ERR_OK;
846          }          }
847    
# Line 1078  Line 1079 
1079          stop_global_timer();          stop_global_timer();
1080          write_timer();          write_timer();
1081    
1082            emms();
1083          return XVID_ERR_OK;          return XVID_ERR_OK;
1084  }  }
1085    
# Line 1132  Line 1134 
1134          start_timer();          start_timer();
1135          if (image_input          if (image_input
1136                  (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,                  (&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height,
1137                   pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace) < 0)                   pEnc->mbParam.edged_width, pFrame->image, pFrame->stride, pFrame->colorspace, pFrame->general & XVID_INTERLACING) < 0)
1138                  return XVID_ERR_FORMAT;                  return XVID_ERR_FORMAT;
1139          stop_conv_timer();          stop_conv_timer();
1140    
# Line 1509  Line 1511 
1511          pEnc->iFrameNum = 0;          pEnc->iFrameNum = 0;
1512          pEnc->mbParam.m_rounding_type = 1;          pEnc->mbParam.m_rounding_type = 1;
1513          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;
1514            pEnc->current->quarterpel =  pEnc->mbParam.m_quarterpel;
1515          pEnc->current->coding_type = I_VOP;          pEnc->current->coding_type = I_VOP;
1516    
1517          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
# Line 1600  Line 1603 
1603    
1604          pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type;          pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type;
1605          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;
1606            pEnc->current->quarterpel =  pEnc->mbParam.m_quarterpel;
1607          pEnc->current->fcode = pEnc->mbParam.m_fcode;          pEnc->current->fcode = pEnc->mbParam.m_fcode;
1608    
1609          if (!force_inter)          if (!force_inter)
# Line 1619  Line 1623 
1623                  stop_inter_timer();                  stop_inter_timer();
1624          }          }
1625    
1626            if (pEnc->current->global_flags & XVID_GMC) {
1627    //              printf("Global Motion = %d %d quarterpel=%d\n", pEnc->current->GMC_MV.x, pEnc->current->GMC_MV.y,pEnc->current->quarterpel);
1628                    DPRINTF(DPRINTF_HEADER, "Global Motion = %d %d quarterpel=%d\n", pEnc->current->GMC_MV.x, pEnc->current->GMC_MV.y,pEnc->current->quarterpel);
1629                    pEnc->current->coding_type = S_VOP;
1630            } else
1631                    pEnc->current->coding_type = P_VOP;
1632    
1633          start_timer();          start_timer();
1634          if (pEnc->current->global_flags & XVID_HINTEDME_SET) {          if (pEnc->current->global_flags & XVID_HINTEDME_SET) {
1635                  HintedMESet(pEnc, &bIntra);                  HintedMESet(pEnc, &bIntra);
# Line 1634  Line 1645 
1645                  MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,                  MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,
1646                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
1647                           iLimit);                           iLimit);
   
1648          }          }
1649          stop_motion_timer();          stop_motion_timer();
1650    
1651          if (bIntra == 1) return FrameCodeI(pEnc, bs, pBits);          if (bIntra == 1) return FrameCodeI(pEnc, bs, pBits);
1652    
1653          pEnc->current->coding_type = P_VOP;          if ( (pEnc->current->GMC_MV.x == 0) && (pEnc->current->GMC_MV.y == 0) )
1654                            pEnc->current->coding_type = P_VOP;             /* no global motion -> no GMC */
1655    
1656    
1657          if (vol_header)          if (vol_header)
1658                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
# Line 1719  Line 1731 
1731                                                          (pMB->dquant == NO_CHANGE);                                                          (pMB->dquant == NO_CHANGE);
1732    
1733                          if(pEnc->mbParam.m_quarterpel)                          if(pEnc->mbParam.m_quarterpel)
1734                                  skip_possible &= (pMB->qmvs[0].x == 0) & (pMB->qmvs[0].y == 0);                          {       skip_possible &= (pMB->qmvs[0].x == pEnc->current->GMC_MV.x) & (pMB->qmvs[0].y == pEnc->current->GMC_MV.y);
1735                            }
1736                          else                          else
1737                                  skip_possible &= (pMB->mvs[0].x == 0) & (pMB->mvs[0].y == 0);                          {       skip_possible &= (pMB->mvs[0].x == pEnc->current->GMC_MV.x) & (pMB->mvs[0].y == pEnc->current->GMC_MV.y);
1738                            }
1739    
1740                          if ((pMB->mode == MODE_NOT_CODED) || (skip_possible)) {                          if ((pMB->mode == MODE_NOT_CODED) || (skip_possible)) {
 /* This is a candidate for SKIPping, but check intermediate B-frames first */  
1741    
1742    /* This is a candidate for SKIPping, but for P-VOPs check intermediate B-frames first */
1743                                  int bSkip = 1;                                  int bSkip = 1;
                                 pMB->mode = MODE_NOT_CODED;  
1744    
1745                                    if (pEnc->current->coding_type == P_VOP)        /* special rule for P-VOP's SKIP */
1746                                  for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++)                                  for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++)
1747                                  {                                  {
1748                                          int iSAD;                                          int iSAD;
# Line 1740  Line 1754 
1754                                                  break;                                                  break;
1755                                          }                                          }
1756                                  }                                  }
1757    
1758                                  if (!bSkip)                                  if (!bSkip)
1759                                  {                                  {
1760                                          VECTOR predMV;                                          VECTOR predMV;
1761                                          if(pEnc->mbParam.m_quarterpel)                                          if(pEnc->mbParam.m_quarterpel) {
1762                                                  predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);                                                  predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);
1763                                          else                                                  pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x;  /* with GMC, qmvs doesn't have to be (0,0)! */
1764                                                    pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y;
1765                                            }
1766                                            else {
1767                                                  predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);                                                  predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);
1768                                          pMB->pmvs[0].x = -predMV.x; pMB->pmvs[0].y = -predMV.y;                                                  pMB->pmvs[0].x = pMB->mvs[0].x - predMV.x; /* with GMC, mvs doesn't have to be (0,0)! */
1769                                                    pMB->pmvs[0].y = pMB->mvs[0].y - predMV.y;
1770                                            }
1771                                          pMB->mode = MODE_INTER;                                          pMB->mode = MODE_INTER;
1772                                          pMB->cbp = 0;                                          pMB->cbp = 0;
1773                                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);                                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);
1774                                  }                                  }
1775                                  else MBSkip(bs);                                  else
1776                                    {
1777                                            pMB->mode = MODE_NOT_CODED;
1778                                            MBSkip(bs);
1779                                    }
1780    
1781                          } else {                          } else {
1782                                  if (pEnc->current->global_flags & XVID_GREYSCALE)                                  if (pEnc->current->global_flags & XVID_GREYSCALE)
# Line 1814  Line 1838 
1838                  pEnc->current->quant = pEnc->reference->quant;                  pEnc->current->quant = pEnc->reference->quant;
1839                  pEnc->current->motion_flags = pEnc->reference->motion_flags;                  pEnc->current->motion_flags = pEnc->reference->motion_flags;
1840                  pEnc->current->rounding_type = pEnc->reference->rounding_type;                  pEnc->current->rounding_type = pEnc->reference->rounding_type;
1841                    pEnc->current->quarterpel =  pEnc->reference->quarterpel;
1842                  pEnc->current->fcode = pEnc->reference->fcode;                  pEnc->current->fcode = pEnc->reference->fcode;
1843                  pEnc->current->bcode = pEnc->reference->bcode;                  pEnc->current->bcode = pEnc->reference->bcode;
1844                  image_copy(&pEnc->current->image, &pEnc->reference->image, pEnc->mbParam.edged_width, pEnc->mbParam.height);                  image_copy(&pEnc->current->image, &pEnc->reference->image, pEnc->mbParam.edged_width, pEnc->mbParam.height);
# Line 1853  Line 1878 
1878          }          }
1879  #endif  #endif
1880    
1881            frame->quarterpel =  pEnc->mbParam.m_quarterpel;
1882    
1883          // forward          // forward
1884          image_setedges(f_ref, pEnc->mbParam.edged_width,          image_setedges(f_ref, pEnc->mbParam.edged_width,
1885                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,                                     pEnc->mbParam.edged_height, pEnc->mbParam.width,

Legend:
Removed from v.602  
changed lines
  Added in v.631

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