[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.38, Mon Jan 13 23:52:50 2003 UTC
# Line 661  Line 661 
661          if (intra < 0)          return -1;          if (intra < 0)          return -1;
662          if (intra == 1)         return I_VOP;          if (intra == 1)         return I_VOP;
663          if (intra == 2)         return B_VOP;          if (intra == 2)         return B_VOP;
664            if (intra == 3) return S_VOP;
665    
666          return P_VOP;          return P_VOP;
667  }  }
# Line 730  Line 731 
731                          FrameCodeP(pEnc, &bs, &bits, 1, 0);                          FrameCodeP(pEnc, &bs, &bits, 1, 0);
732                          bframes_count = 0;                          bframes_count = 0;
733    
734                          BitstreamPad(&bs);                          BitstreamPadAlways(&bs);
735                          pFrame->length = BitstreamLength(&bs);                          pFrame->length = BitstreamLength(&bs);
736                            if(pEnc->current->coding_type == P_VOP)
737                          pFrame->intra = 0;                          pFrame->intra = 0;
738                            else
739                                    pFrame->intra = 3;
740    
741                          emms();                          emms();
742    
743                            if (pResult) {
744                                    pResult->quant = pEnc->current->quant;
745                                    pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
746                                    pResult->kblks = pEnc->current->sStat.kblks;
747                                    pResult->mblks = pEnc->current->sStat.mblks;
748                                    pResult->ublks = pEnc->current->sStat.ublks;
749                            }
750    
751                          return XVID_ERR_OK;                          return XVID_ERR_OK;
752                  }                  }
753    
# Line 747  Line 759 
759                  FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs, &bits);                  FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs, &bits);
760                  pEnc->bframenum_head++;                  pEnc->bframenum_head++;
761    
762                  BitstreamPad(&bs);                  BitstreamPadAlways(&bs);
763                  pFrame->length = BitstreamLength(&bs);                  pFrame->length = BitstreamLength(&bs);
764                  pFrame->intra = 2;                  pFrame->intra = 2;
765    
766                    if (pResult) {
767                            pResult->quant = pEnc->current->quant;
768                            pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
769                            pResult->kblks = pEnc->current->sStat.kblks;
770                            pResult->mblks = pEnc->current->sStat.mblks;
771                            pResult->ublks = pEnc->current->sStat.ublks;
772                    }
773    
774                  if (input_valid)                  if (input_valid)
775                          queue_image(pEnc, pFrame);                          queue_image(pEnc, pFrame);
776    
# Line 776  Line 796 
796                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
797                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
798    
                         BitstreamPad(&bs);  
799    
800                          tmp = pEnc->current->seconds;                          tmp = pEnc->current->seconds;
801                          pEnc->current->seconds = 0; /* force time_base = 0 */                          pEnc->current->seconds = 0; /* force time_base = 0 */
802    
803                          BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);                          BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);
804                          pEnc->current->seconds = tmp;                          pEnc->current->seconds = tmp;
805    
806                            BitstreamPadAlways(&bs);
807                          pFrame->length = BitstreamLength(&bs);                          pFrame->length = BitstreamLength(&bs);
808                          pFrame->intra = 4;                          pFrame->intra = 4;
809    
810                            if (pResult) {
811                                    pResult->quant = pEnc->current->quant;
812                                    pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
813                                    pResult->kblks = pEnc->current->sStat.kblks;
814                                    pResult->mblks = pEnc->current->sStat.mblks;
815                                    pResult->ublks = pEnc->current->sStat.ublks;
816                            }
817    
818                          if (input_valid)                          if (input_valid)
819                                  queue_image(pEnc, pFrame);                                  queue_image(pEnc, pFrame);
820    
# Line 859  Line 888 
888                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
889                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
890    
891                          BitstreamPutBits(&bs, 0x7f, 8);                  //      BitstreamPutBits(&bs, 0x7f, 8);
892                          pFrame->intra = 5;                          pFrame->intra = 5;
893    
894                            if (pResult) {
895                                    /*
896                                     * We must decide what to put there because i know some apps
897                                     * are storing statistics about quantizers and just do
898                                     * stats[quant]++ or stats[quant-1]++
899                                     * transcode is one of these app with its 2pass module
900                                     */
901    
902                                    /*
903                                     * For now i prefer 31 than 0 that could lead to a segfault
904                                     * in transcode
905                                     */
906                                    pResult->quant = 31;
907    
908                                    pResult->hlength = 0;
909                                    pResult->kblks = 0;
910                                    pResult->mblks = 0;
911                                    pResult->ublks = 0;
912                            }
913    
914                    } else {
915    
916                            if (pResult) {
917                                    pResult->quant = pEnc->current->quant;
918                                    pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
919                                    pResult->kblks = pEnc->current->sStat.kblks;
920                                    pResult->mblks = pEnc->current->sStat.mblks;
921                                    pResult->ublks = pEnc->current->sStat.ublks;
922                            }
923    
924                  }                  }
925    
926                  pFrame->length = BitstreamLength(&bs);                  pFrame->length = BitstreamLength(&bs);
927    
928                  emms();                  emms();
929    
930                  return XVID_ERR_OK;                  return XVID_ERR_OK;
931          }          }
932    
# Line 1002  Line 1064 
1064                          FrameCodeP(pEnc, &bs, &bits, 1, 0);                          FrameCodeP(pEnc, &bs, &bits, 1, 0);
1065                          bframes_count = 0;                          bframes_count = 0;
1066    
1067                            if(pEnc->current->coding_type == P_VOP)
1068                          pFrame->intra = 0;                          pFrame->intra = 0;
1069                            else
1070                                    pFrame->intra = 3;
1071    
1072    
1073                  } else {                  } else {
1074    
# Line 1025  Line 1091 
1091                   * NB : sequences like "IIBB" decode fine with msfdam but,                   * NB : sequences like "IIBB" decode fine with msfdam but,
1092                   *      go screwy with divx 5.00                   *      go screwy with divx 5.00
1093                   */                   */
1094          } 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) {
1095                  /*                  /*
1096                   * This will be coded as a Predicted Frame                   * This will be coded as a Predicted Frame
1097                   */                   */
# Line 1040  Line 1106 
1106    
1107                  FrameCodeP(pEnc, &bs, &bits, 1, 0);                  FrameCodeP(pEnc, &bs, &bits, 1, 0);
1108                  bframes_count = 0;                  bframes_count = 0;
1109                    if(pEnc->current->coding_type == P_VOP)
1110                  pFrame->intra = 0;                  pFrame->intra = 0;
1111                    else
1112                            pFrame->intra = 3;
1113                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
1114    
1115                  if ((pEnc->mbParam.global & XVID_GLOBAL_PACKED) && (pEnc->bframenum_tail > 0)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_PACKED) && (pEnc->bframenum_tail > 0)) {
# Line 1089  Line 1158 
1158                  goto bvop_loop;                  goto bvop_loop;
1159          }          }
1160    
1161          BitstreamPad(&bs);          BitstreamPadAlways(&bs);
1162          pFrame->length = BitstreamLength(&bs);          pFrame->length = BitstreamLength(&bs);
1163    
1164          if (pResult) {          if (pResult) {
# Line 1275  Line 1344 
1344    
1345          }          }
1346    
1347          BitstreamPutBits(&bs, 0xFFFF, 16);  //      BitstreamPutBits(&bs, 0xFFFF, 16);
1348          BitstreamPutBits(&bs, 0xFFFF, 16);  //      BitstreamPutBits(&bs, 0xFFFF, 16);
1349          BitstreamPad(&bs);          BitstreamPadAlways(&bs);
1350          pFrame->length = BitstreamLength(&bs);          pFrame->length = BitstreamLength(&bs);
1351    
1352          if (pResult) {          if (pResult) {
# Line 1468  Line 1537 
1537    
1538          if (intra) {          if (intra) {
1539                  if (!hint->rawhints) {                  if (!hint->rawhints) {
1540                          BitstreamPad(&bs);                          BitstreamPadAlways(&bs);
1541                          hint->hintlength = BitstreamLength(&bs);                          hint->hintlength = BitstreamLength(&bs);
1542                  }                  }
1543                  return;                  return;
# Line 1574  Line 1643 
1643          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1644    
1645          set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);          set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1646    
1647            BitstreamPadAlways(bs);
1648          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1649    
1650          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
# Line 1713  Line 1784 
1784                  generate_GMCimage(&pEnc->current->gmc_data, &pEnc->reference->image,                  generate_GMCimage(&pEnc->current->gmc_data, &pEnc->reference->image,
1785                                  pEnc->mbParam.mb_width, pEnc->mbParam.mb_height,                                  pEnc->mbParam.mb_width, pEnc->mbParam.mb_height,
1786                                  pEnc->mbParam.edged_width, pEnc->mbParam.edged_width/2,                                  pEnc->mbParam.edged_width, pEnc->mbParam.edged_width/2,
1787                                  pEnc->mbParam.m_fcode, 0, 0,                                  pEnc->mbParam.m_fcode, pEnc->mbParam.m_quarterpel, 0,
1788                                  pEnc->current->rounding_type, pEnc->current->mbs, &pEnc->vGMC);                                  pEnc->current->rounding_type, pEnc->current->mbs, &pEnc->vGMC);
1789    
1790          }          }
1791    
1792            set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1793          if (vol_header)          if (vol_header)
1794                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          {       BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1795                    BitstreamPadAlways(bs);
1796            }
1797    
         set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);  
1798          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1799    
1800          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
# Line 1738  Line 1811 
1811  /* 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 */
1812  /* 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 */
1813    
   
1814                          bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q);                          bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q);
1815    
1816                          if (bIntra) {                          if (bIntra) {
# Line 1753  Line 1825 
1825                                  pEnc->current->sStat.kblks++;                                  pEnc->current->sStat.kblks++;
1826    
1827                                  MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);                                  MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);
1828                                    stop_coding_timer();
1829                                  continue;                                  continue;
1830                          }                          }
1831    
# Line 1763  Line 1836 
1836                                          pEnc->mbParam.edged_width,65536);                                          pEnc->mbParam.edged_width,65536);
1837    
1838                                  if (iSAD <= pMB->sad16) {               /* mode decision GMC */                                  if (iSAD <= pMB->sad16) {               /* mode decision GMC */
1839    
1840                                          if (pEnc->mbParam.m_quarterpel)                                          if (pEnc->mbParam.m_quarterpel)
1841                                                  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;
1842                                          else                                          else
# Line 1774  Line 1848 
1848                                  } else {                                  } else {
1849                                          pMB->mcsel = 0;                                          pMB->mcsel = 0;
1850                                  }                                  }
1851                          } else                          } else {
                         {  
1852                                  pMB->mcsel = 0; /* just a precaution */                                  pMB->mcsel = 0; /* just a precaution */
1853                          }                          }
1854    
# Line 1813  Line 1886 
1886                                                                            dct_codes, qcoeff);                                                                            dct_codes, qcoeff);
1887                          }                          }
1888    
   
1889                          if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y ||                          if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y ||
1890                                     pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x ||                                     pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x ||
1891                                     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 1898 
1898    
1899                          /* Finished processing the MB, now check if to CODE or SKIP */                          /* Finished processing the MB, now check if to CODE or SKIP */
1900    
1901                          skip_possible = (pMB->cbp == 0) & (pMB->mode == MODE_INTER) &                          skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER) &&
1902                                                          (pMB->dquant == NO_CHANGE);                                                          (pMB->dquant == NO_CHANGE);
1903    
1904                          if (pEnc->current->coding_type == S_VOP)                          if (pEnc->current->coding_type == S_VOP)
1905                                  skip_possible &= (pMB->mcsel == 1);                                  skip_possible &= (pMB->mcsel == 1);
1906                          else if (pEnc->current->coding_type == P_VOP) {                          else if (pEnc->current->coding_type == P_VOP) {
1907                                  if (pEnc->mbParam.m_quarterpel)                                  if (pEnc->mbParam.m_quarterpel)
1908                                          skip_possible &= (pMB->qmvs[0].x == 0) & (pMB->qmvs[0].y == 0);                                          skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) );
1909                                  else                                  else
1910                                          skip_possible &= (pMB->mvs[0].x == 0) & (pMB->mvs[0].y == 0);                                          skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) );
1911                          }                          }
1912    
1913                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {
# Line 1873  Line 1945 
1945                                                  pMB->cbp = 0;                                                  pMB->cbp = 0;
1946                                                  MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);                                                  MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);
1947                                                  stop_coding_timer();                                                  stop_coding_timer();
1948    
1949                                                  continue;       /* next MB */                                                  continue;       /* next MB */
1950                                          }                                          }
1951                                  }                                  }
# Line 1922  Line 1995 
1995    
1996                                  }                                  }
1997                          }                          }
1998    
1999                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);
2000                          stop_coding_timer();                          stop_coding_timer();
2001    
2002                  }                  }
2003          }          }
2004    

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

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