[cvs] / xvidcore / src / encoder.c Repository:
ViewVC logotype

Diff of /xvidcore/src/encoder.c

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

revision 1.76.2.35, Sat Jan 11 14:59:23 2003 UTC revision 1.76.2.40, Tue Jan 21 22:05:44 2003 UTC
# Line 229  Line 229 
229    
230          pEnc->bitrate = pParam->rc_bitrate;          pEnc->bitrate = pParam->rc_bitrate;
231    
232          pEnc->iFrameNum = 0;          pEnc->iFrameNum = -1;
233          pEnc->mbParam.iMaxKeyInterval = pParam->max_key_interval;          pEnc->mbParam.iMaxKeyInterval = pParam->max_key_interval;
234    
235          /* try to allocate frame memory */          /* try to allocate frame memory */
# Line 730  Line 730 
730                          FrameCodeP(pEnc, &bs, &bits, 1, 0);                          FrameCodeP(pEnc, &bs, &bits, 1, 0);
731                          bframes_count = 0;                          bframes_count = 0;
732    
733                          BitstreamPad(&bs);                          BitstreamPadAlways(&bs);
734                          pFrame->length = BitstreamLength(&bs);                          pFrame->length = BitstreamLength(&bs);
735                          pFrame->intra = 0;                          pFrame->intra = 0;
736    
737    
738                          emms();                          emms();
739    
740                            if (pResult) {
741                                    pResult->quant = pEnc->current->quant;
742                                    pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
743                                    pResult->kblks = pEnc->current->sStat.kblks;
744                                    pResult->mblks = pEnc->current->sStat.mblks;
745                                    pResult->ublks = pEnc->current->sStat.ublks;
746                            }
747    
748                          return XVID_ERR_OK;                          return XVID_ERR_OK;
749                  }                  }
750    
# Line 747  Line 756 
756                  FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs, &bits);                  FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs, &bits);
757                  pEnc->bframenum_head++;                  pEnc->bframenum_head++;
758    
759                  BitstreamPad(&bs);                  BitstreamPadAlways(&bs);
760                  pFrame->length = BitstreamLength(&bs);                  pFrame->length = BitstreamLength(&bs);
761                  pFrame->intra = 2;                  pFrame->intra = 2;
762    
763                    if (pResult) {
764                            pResult->quant = pEnc->current->quant;
765                            pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
766                            pResult->kblks = pEnc->current->sStat.kblks;
767                            pResult->mblks = pEnc->current->sStat.mblks;
768                            pResult->ublks = pEnc->current->sStat.ublks;
769                    }
770    
771                  if (input_valid)                  if (input_valid)
772                          queue_image(pEnc, pFrame);                          queue_image(pEnc, pFrame);
773    
# Line 776  Line 793 
793                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
794                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
795    
                         BitstreamPad(&bs);  
796    
797                          tmp = pEnc->current->seconds;                          tmp = pEnc->current->seconds;
798                          pEnc->current->seconds = 0; /* force time_base = 0 */                          pEnc->current->seconds = 0; /* force time_base = 0 */
799    
800                          BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);                          BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);
801                          pEnc->current->seconds = tmp;                          pEnc->current->seconds = tmp;
802    
803                            BitstreamPadAlways(&bs);
804                          pFrame->length = BitstreamLength(&bs);                          pFrame->length = BitstreamLength(&bs);
805                          pFrame->intra = 4;                          pFrame->intra = 4;
806    
807                            if (pResult) {
808                                    pResult->quant = pEnc->current->quant;
809                                    pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
810                                    pResult->kblks = pEnc->current->sStat.kblks;
811                                    pResult->mblks = pEnc->current->sStat.mblks;
812                                    pResult->ublks = pEnc->current->sStat.ublks;
813                            }
814    
815                          if (input_valid)                          if (input_valid)
816                                  queue_image(pEnc, pFrame);                                  queue_image(pEnc, pFrame);
817    
# Line 859  Line 885 
885                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
886                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
887    
888                          BitstreamPutBits(&bs, 0x7f, 8);                  //      BitstreamPutBits(&bs, 0x7f, 8);
889                          pFrame->intra = 5;                          pFrame->intra = 5;
890    
891                            if (pResult) {
892                                    /*
893                                     * We must decide what to put there because i know some apps
894                                     * are storing statistics about quantizers and just do
895                                     * stats[quant]++ or stats[quant-1]++
896                                     * transcode is one of these app with its 2pass module
897                                     */
898    
899                                    /*
900                                     * For now i prefer 31 than 0 that could lead to a segfault
901                                     * in transcode
902                                     */
903                                    pResult->quant = 31;
904    
905                                    pResult->hlength = 0;
906                                    pResult->kblks = 0;
907                                    pResult->mblks = 0;
908                                    pResult->ublks = 0;
909                            }
910    
911                    } else {
912    
913                            if (pResult) {
914                                    pResult->quant = pEnc->current->quant;
915                                    pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
916                                    pResult->kblks = pEnc->current->sStat.kblks;
917                                    pResult->mblks = pEnc->current->sStat.mblks;
918                                    pResult->ublks = pEnc->current->sStat.ublks;
919                            }
920    
921                  }                  }
922    
923                  pFrame->length = BitstreamLength(&bs);                  pFrame->length = BitstreamLength(&bs);
924    
925                  emms();                  emms();
926    
927                  return XVID_ERR_OK;                  return XVID_ERR_OK;
928          }          }
929    
# Line 1001  Line 1060 
1060                          }                          }
1061                          FrameCodeP(pEnc, &bs, &bits, 1, 0);                          FrameCodeP(pEnc, &bs, &bits, 1, 0);
1062                          bframes_count = 0;                          bframes_count = 0;
   
1063                          pFrame->intra = 0;                          pFrame->intra = 0;
1064    
1065                  } else {                  } else {
# Line 1025  Line 1083 
1083                   * NB : sequences like "IIBB" decode fine with msfdam but,                   * NB : sequences like "IIBB" decode fine with msfdam but,
1084                   *      go screwy with divx 5.00                   *      go screwy with divx 5.00
1085                   */                   */
1086          } else if (mode == P_VOP || pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) {          } else if (mode == P_VOP || mode == S_VOP || pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) {
1087                  /*                  /*
1088                   * This will be coded as a Predicted Frame                   * This will be coded as a Predicted Frame
1089                   */                   */
# Line 1089  Line 1147 
1147                  goto bvop_loop;                  goto bvop_loop;
1148          }          }
1149    
1150          BitstreamPad(&bs);          BitstreamPadAlways(&bs);
1151          pFrame->length = BitstreamLength(&bs);          pFrame->length = BitstreamLength(&bs);
1152    
1153          if (pResult) {          if (pResult) {
# Line 1275  Line 1333 
1333    
1334          }          }
1335    
1336          BitstreamPutBits(&bs, 0xFFFF, 16);  //      BitstreamPutBits(&bs, 0xFFFF, 16);
1337          BitstreamPutBits(&bs, 0xFFFF, 16);  //      BitstreamPutBits(&bs, 0xFFFF, 16);
1338          BitstreamPad(&bs);          BitstreamPadAlways(&bs);
1339          pFrame->length = BitstreamLength(&bs);          pFrame->length = BitstreamLength(&bs);
1340    
1341          if (pResult) {          if (pResult) {
# Line 1468  Line 1526 
1526    
1527          if (intra) {          if (intra) {
1528                  if (!hint->rawhints) {                  if (!hint->rawhints) {
1529                          BitstreamPad(&bs);                          BitstreamPadAlways(&bs);
1530                          hint->hintlength = BitstreamLength(&bs);                          hint->hintlength = BitstreamLength(&bs);
1531                  }                  }
1532                  return;                  return;
# Line 1574  Line 1632 
1632          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1633    
1634          set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);          set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1635    
1636            BitstreamPadAlways(bs);
1637          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1638    
1639          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
# Line 1713  Line 1773 
1773                  generate_GMCimage(&pEnc->current->gmc_data, &pEnc->reference->image,                  generate_GMCimage(&pEnc->current->gmc_data, &pEnc->reference->image,
1774                                  pEnc->mbParam.mb_width, pEnc->mbParam.mb_height,                                  pEnc->mbParam.mb_width, pEnc->mbParam.mb_height,
1775                                  pEnc->mbParam.edged_width, pEnc->mbParam.edged_width/2,                                  pEnc->mbParam.edged_width, pEnc->mbParam.edged_width/2,
1776                                  pEnc->mbParam.m_fcode, 0, 0,                                  pEnc->mbParam.m_fcode, pEnc->mbParam.m_quarterpel, 0,
1777                                  pEnc->current->rounding_type, pEnc->current->mbs, &pEnc->vGMC);                                  pEnc->current->rounding_type, pEnc->current->mbs, &pEnc->vGMC);
1778    
1779          }          }
1780    
1781            set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1782          if (vol_header)          if (vol_header)
1783                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          {       BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1784                    BitstreamPadAlways(bs);
1785            }
1786    
         set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);  
1787          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1788    
1789          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
# Line 1738  Line 1800 
1800  /* Mode decision: Check, if the block should be INTRA / INTER or GMC-coded */  /* Mode decision: Check, if the block should be INTRA / INTER or GMC-coded */
1801  /* For a start, leave INTRA decision as is, only choose only between INTER/GMC  - gruel, 9.1.2002 */  /* For a start, leave INTRA decision as is, only choose only between INTER/GMC  - gruel, 9.1.2002 */
1802    
   
1803                          bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q);                          bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q);
1804    
1805                          if (bIntra) {                          if (bIntra) {
# Line 1753  Line 1814 
1814                                  pEnc->current->sStat.kblks++;                                  pEnc->current->sStat.kblks++;
1815    
1816                                  MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);                                  MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);
1817                                    stop_coding_timer();
1818                                  continue;                                  continue;
1819                          }                          }
1820    
# Line 1762  Line 1824 
1824                                          pEnc->vGMC.y + 16*y*pEnc->mbParam.edged_width + 16*x,                                          pEnc->vGMC.y + 16*y*pEnc->mbParam.edged_width + 16*x,
1825                                          pEnc->mbParam.edged_width,65536);                                          pEnc->mbParam.edged_width,65536);
1826    
1827                                    if (pEnc->current->motion_flags & PMV_CHROMA16) {
1828                                            iSAD += sad8(pEnc->current->image.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x,
1829                                            pEnc->vGMC.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x, pEnc->mbParam.edged_width/2);
1830    
1831                                            iSAD += sad8(pEnc->current->image.v + 8*y*(pEnc->mbParam.edged_width/2) + 8*x,
1832                                            pEnc->vGMC.v + 8*y*(pEnc->mbParam.edged_width/2) + 8*x, pEnc->mbParam.edged_width/2);
1833                                    }
1834    
1835                                  if (iSAD <= pMB->sad16) {               /* mode decision GMC */                                  if (iSAD <= pMB->sad16) {               /* mode decision GMC */
1836    
1837                                          if (pEnc->mbParam.m_quarterpel)                                          if (pEnc->mbParam.m_quarterpel)
1838                                                  pMB->qmvs[0] = pMB->qmvs[1] =pMB->qmvs[2] =pMB->qmvs[3] = pMB->amv;                                                  pMB->qmvs[0] = pMB->qmvs[1] =pMB->qmvs[2] =pMB->qmvs[3] = pMB->amv;
1839                                          else                                          else
# Line 1774  Line 1845 
1845                                  } else {                                  } else {
1846                                          pMB->mcsel = 0;                                          pMB->mcsel = 0;
1847                                  }                                  }
1848                          } else                          } else {
                         {  
1849                                  pMB->mcsel = 0; /* just a precaution */                                  pMB->mcsel = 0; /* just a precaution */
1850                          }                          }
1851    
# Line 1813  Line 1883 
1883                                                                            dct_codes, qcoeff);                                                                            dct_codes, qcoeff);
1884                          }                          }
1885    
   
1886                          if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y ||                          if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y ||
1887                                     pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x ||                                     pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x ||
1888                                     pMB->mvs[2].y || pMB->mvs[3].x || pMB->mvs[3].y) {                                     pMB->mvs[2].y || pMB->mvs[3].x || pMB->mvs[3].y) {
# Line 1826  Line 1895 
1895    
1896                          /* Finished processing the MB, now check if to CODE or SKIP */                          /* Finished processing the MB, now check if to CODE or SKIP */
1897    
1898                          skip_possible = (pMB->cbp == 0) & (pMB->mode == MODE_INTER) &                          skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER) &&
1899                                                          (pMB->dquant == NO_CHANGE);                                                          (pMB->dquant == NO_CHANGE);
1900    
1901                          if (pEnc->current->coding_type == S_VOP)                          if (pEnc->current->coding_type == S_VOP)
1902                                  skip_possible &= (pMB->mcsel == 1);                                  skip_possible &= (pMB->mcsel == 1);
1903                          else if (pEnc->current->coding_type == P_VOP) {                          else if (pEnc->current->coding_type == P_VOP) {
1904                                  if (pEnc->mbParam.m_quarterpel)                                  if (pEnc->mbParam.m_quarterpel)
1905                                          skip_possible &= (pMB->qmvs[0].x == 0) & (pMB->qmvs[0].y == 0);                                          skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) );
1906                                  else                                  else
1907                                          skip_possible &= (pMB->mvs[0].x == 0) & (pMB->mvs[0].y == 0);                                          skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) );
1908                          }                          }
1909    
1910                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {
# Line 1873  Line 1942 
1942                                                  pMB->cbp = 0;                                                  pMB->cbp = 0;
1943                                                  MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);                                                  MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);
1944                                                  stop_coding_timer();                                                  stop_coding_timer();
1945    
1946                                                  continue;       /* next MB */                                                  continue;       /* next MB */
1947                                          }                                          }
1948                                  }                                  }
# Line 1922  Line 1992 
1992    
1993                                  }                                  }
1994                          }                          }
1995    
1996                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);
1997                          stop_coding_timer();                          stop_coding_timer();
1998    
1999                  }                  }
2000          }          }
2001    

Legend:
Removed from v.1.76.2.35  
changed lines
  Added in v.1.76.2.40

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