[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.95.2.49, Sun Nov 9 20:49:21 2003 UTC revision 1.95.2.55, Thu Nov 20 12:07:19 2003 UTC
# Line 188  Line 188 
188          pcreate.zones = pEnc->zones;          pcreate.zones = pEnc->zones;
189          pcreate.width = pEnc->mbParam.width;          pcreate.width = pEnc->mbParam.width;
190          pcreate.height = pEnc->mbParam.height;          pcreate.height = pEnc->mbParam.height;
191                    pcreate.mb_width = pEnc->mbParam.mb_width;
192                    pcreate.mb_height = pEnc->mbParam.mb_height;
193          pcreate.fincr = pEnc->mbParam.fincr;          pcreate.fincr = pEnc->mbParam.fincr;
194          pcreate.fbase = pEnc->mbParam.fbase;          pcreate.fbase = pEnc->mbParam.fbase;
195          pcreate.param = create->plugins[n].param;          pcreate.param = create->plugins[n].param;
# Line 263  Line 265 
265          image_null(&pEnc->reference->image);          image_null(&pEnc->reference->image);
266          image_null(&pEnc->vInterH);          image_null(&pEnc->vInterH);
267          image_null(&pEnc->vInterV);          image_null(&pEnc->vInterV);
         image_null(&pEnc->vInterVf);  
268          image_null(&pEnc->vInterHV);          image_null(&pEnc->vInterHV);
         image_null(&pEnc->vInterHVf);  
269    
270          if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) {          if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) {
271          if (image_create          if (image_create
# Line 309  Line 309 
309                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
310                  goto xvid_err_memory3;                  goto xvid_err_memory3;
311          if (image_create          if (image_create
                 (&pEnc->vInterVf, pEnc->mbParam.edged_width,  
                  pEnc->mbParam.edged_height) < 0)  
                 goto xvid_err_memory3;  
         if (image_create  
312                  (&pEnc->vInterHV, pEnc->mbParam.edged_width,                  (&pEnc->vInterHV, pEnc->mbParam.edged_width,
313                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
314                  goto xvid_err_memory3;                  goto xvid_err_memory3;
         if (image_create  
                 (&pEnc->vInterHVf, pEnc->mbParam.edged_width,  
                  pEnc->mbParam.edged_height) < 0)  
                 goto xvid_err_memory3;  
315    
316  /* Create full bitplane for GMC, this might be wasteful */  /* Create full bitplane for GMC, this might be wasteful */
317          if (image_create          if (image_create
# Line 470  Line 462 
462                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
463          image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width,
464                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
         image_destroy(&pEnc->vInterVf, pEnc->mbParam.edged_width,  
                                   pEnc->mbParam.edged_height);  
465          image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width,
466                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
         image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width,  
                                   pEnc->mbParam.edged_height);  
467    
468  /* destroy GMC image */  /* destroy GMC image */
469          image_destroy(&pEnc->vGMC, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vGMC, pEnc->mbParam.edged_width,
# Line 563  Line 551 
551                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
552          image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width,
553                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
         image_destroy(&pEnc->vInterVf, pEnc->mbParam.edged_width,  
                                   pEnc->mbParam.edged_height);  
554          image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width,
555                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
         image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width,  
                                   pEnc->mbParam.edged_height);  
   
556          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,
557                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
558          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width,
# Line 678  Line 661 
661          data.type = *type;          data.type = *type;
662          data.quant = *quant;          data.quant = *quant;
663    
664                    data.vol_flags = frame->vol_flags;
665                    data.vop_flags = frame->vop_flags;
666                    data.motion_flags = frame->motion_flags;
667    
668            } else if (opt == XVID_PLG_FRAME) {
669                    data.type = coding2type(frame->coding_type);
670                    data.quant = frame->quant;
671    
672                  if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) {                  if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) {
673              data.dquant = pEnc->temp_dquants;              data.dquant = pEnc->temp_dquants;
674              data.dquant_stride = pEnc->mbParam.mb_width;              data.dquant_stride = pEnc->mbParam.mb_width;
675                          memset(data.dquant, 0, data.mb_width*data.mb_height);                          memset(data.dquant, 0, data.mb_width*data.mb_height);
676          }          }
677    
         data.vol_flags = frame->vol_flags;  
         data.vop_flags = frame->vop_flags;  
         data.motion_flags = frame->motion_flags;  
   
678      } else { /* XVID_PLG_AFTER */      } else { /* XVID_PLG_AFTER */
679          if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) {          if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) {
680              data.original.csp = XVID_CSP_USER;              data.original.csp = XVID_CSP_USER;
# Line 772  Line 759 
759          *type = data.type;          *type = data.type;
760          *quant = data.quant > 0 ? data.quant : 2;   /* default */          *quant = data.quant > 0 ? data.quant : 2;   /* default */
761    
762                    frame->vol_flags = data.vol_flags;
763                    frame->vop_flags = data.vop_flags;
764                    frame->motion_flags = data.motion_flags;
765    
766            } else if (opt == XVID_PLG_FRAME) {
767    
768          if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) {          if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) {
769              for (j=0; j<pEnc->mbParam.mb_height; j++)              for (j=0; j<pEnc->mbParam.mb_height; j++)
770              for (i=0; i<pEnc->mbParam.mb_width; i++) {              for (i=0; i<pEnc->mbParam.mb_width; i++) {
# Line 783  Line 776 
776                  frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0;                  frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0;
777              }              }
778          }          }
779                    frame->mbs[0].quant = data.quant; /* FRAME will not affect the quant in stats */
         frame->vol_flags = data.vol_flags;  
         frame->vop_flags = data.vop_flags;  
         frame->motion_flags = data.motion_flags;  
     }  
780  }  }
781    
782    
783    }
784    
785    
786  static __inline void inc_frame_num(Encoder * pEnc)  static __inline void inc_frame_num(Encoder * pEnc)
# Line 808  Line 798 
798      pEnc->m_framenum--; /* debug ticker */      pEnc->m_framenum--; /* debug ticker */
799  }  }
800    
801    static __inline void
802    MBSetDquant(MACROBLOCK * pMB, int x, int y, MBParam * mbParam)
803    {
804            if (pMB->cbp == 0) {
805                    /* we want to code dquant but the quantizer value will not be used yet
806                            let's find out if we can postpone dquant to next MB
807                    */
808                    if (x == mbParam->mb_width-1 && y == mbParam->mb_height-1) {
809                            pMB->dquant = 0; /* it's the last MB of all, the easiest case */
810                            return;
811                    } else {
812                            MACROBLOCK * next = pMB + 1;
813                            const MACROBLOCK * prev = pMB - 1;
814                            if (next->mode != MODE_INTER4V && next->mode != MODE_NOT_CODED)
815                                    /* mode allows dquant change in the future */
816                                    if (abs(next->quant - prev->quant) <= 2) {
817                                            /* quant change is not out of range */
818                                            pMB->quant = prev->quant;
819                                            pMB->dquant = 0;
820                                            next->dquant = next->quant - prev->quant;
821                                            return;
822                                    }
823                    }
824            }
825            /* couldn't skip this dquant */
826            pMB->mode = MODE_INTER_Q;
827    }
828    
829    
830    
831  static __inline void  static __inline void
# Line 951  Line 969 
969                          tmp = pEnc->current->seconds;                          tmp = pEnc->current->seconds;
970                          pEnc->current->seconds = 0; /* force time_base = 0 */                          pEnc->current->seconds = 0; /* force time_base = 0 */
971    
972                          BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);                          BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0, pEnc->current->quant);
973                          BitstreamPad(&bs);                          BitstreamPad(&bs);
974                          pEnc->current->seconds = tmp;                          pEnc->current->seconds = tmp;
975    
# Line 1073  Line 1091 
1091                  }else{                  }else{
1092                          type = MEanalysis(&pEnc->reference->image, pEnc->current,                          type = MEanalysis(&pEnc->reference->image, pEnc->current,
1093                                          &pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval,                                          &pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval,
1094                                          pEnc->iFrameNum, pEnc->bframenum_tail, xFrame->bframe_threshold);                                                            pEnc->iFrameNum, pEnc->bframenum_tail, xFrame->bframe_threshold,
1095                                                              (pEnc->bframes) ? pEnc->bframes[pEnc->bframenum_head]->mbs: NULL);
1096                  }                  }
1097          }          }
1098    
# Line 1288  Line 1307 
1307    
1308  static void SetMacroblockQuants(MBParam * const pParam, FRAMEINFO * frame)  static void SetMacroblockQuants(MBParam * const pParam, FRAMEINFO * frame)
1309  {  {
1310      unsigned int i,j;          unsigned int i;
1311      int quant = frame->quant;          MACROBLOCK * pMB = frame->mbs;
1312            int quant = frame->mbs[0].quant; /* set by XVID_PLG_FRAME */
1313      if (quant > 31)      if (quant > 31)
1314                  frame->quant = quant = 31;                  frame->quant = quant = 31;
1315          else if (quant < 1)          else if (quant < 1)
1316                  frame->quant = quant = 1;                  frame->quant = quant = 1;
1317    
1318      for (j=0; j<pParam->mb_height; j++)          for (i = 0; i < pParam->mb_height * pParam->mb_width; i++) {
     for (i=0; i<pParam->mb_width; i++) {  
         MACROBLOCK * pMB = &frame->mbs[j*pParam->mb_width + i];  
1319          quant += pMB->dquant;          quant += pMB->dquant;
1320          if (quant > 31)          if (quant > 31)
1321                          quant = 31;                          quant = 31;
1322                  else if (quant < 1)                  else if (quant < 1)
1323                          quant = 1;                          quant = 1;
1324          pMB->quant = quant;          pMB->quant = quant;
1325                    pMB++;
1326      }      }
1327  }  }
1328    
# Line 1359  Line 1378 
1378          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;
1379          pEnc->current->coding_type = I_VOP;          pEnc->current->coding_type = I_VOP;
1380    
1381            call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL);
1382    
1383      SetMacroblockQuants(&pEnc->mbParam, pEnc->current);      SetMacroblockQuants(&pEnc->mbParam, pEnc->current);
1384    
1385          BitstreamWriteVolHeader(bs, &pEnc->mbParam);          BitstreamWriteVolHeader(bs, &pEnc->mbParam);
# Line 1367  Line 1388 
1388    
1389          BitstreamPad(bs);          BitstreamPad(bs);
1390    
1391          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1, pEnc->current->mbs[0].quant);
1392    
1393          pEnc->current->sStat.iTextBits = 0;          pEnc->current->sStat.iTextBits = 0;
1394          pEnc->current->sStat.kblks = mb_width * mb_height;          pEnc->current->sStat.kblks = mb_width * mb_height;
# Line 1489  Line 1510 
1510    
1511          current->coding_type = P_VOP;          current->coding_type = P_VOP;
1512    
1513            call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL);
1514    
1515      SetMacroblockQuants(&pEnc->mbParam, current);      SetMacroblockQuants(&pEnc->mbParam, current);
1516    
# Line 1507  Line 1529 
1529                                                                  &pEnc->vInterH,                                                                  &pEnc->vInterH,
1530                                                                  &pEnc->vInterV,                                                                  &pEnc->vInterV,
1531                                                                  &pEnc->vInterHV);                                                                  &pEnc->vInterHV);
1532                          gmcval += /*current->quant */ 2 * (int)(pParam->mb_width*pParam->mb_height);                  } else {
                 }  
   
1533                  gmcval = globalSAD(&current->warp, pParam, current->mbs,                  gmcval = globalSAD(&current->warp, pParam, current->mbs,
1534                                                          current,                                                          current,
1535                                                          &reference->image,                                                          &reference->image,
1536                                                          &current->image,                                                          &current->image,
1537                                                          pEnc->vGMC.y);                                                          pEnc->vGMC.y);
1538                    }
1539    
1540                  gmcval += /*current->quant*/ 2 * (int)(pParam->mb_width*pParam->mb_height);                  gmcval += /*current->quant*/ 2 * (int)(pParam->mb_width*pParam->mb_height);
1541    
1542  /* 1st '3': 3 warpoints, 2nd '3': 16th pel res (2<<3) */  /* 1st '3': 3 warpoints, 2nd '3': 16th pel res (2<<3) */
# Line 1559  Line 1581 
1581                  BitstreamPad(bs);                  BitstreamPad(bs);
1582          }          }
1583    
1584          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant);
1585    
1586          current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount =          current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount =
1587                  current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0;                  current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0;
# Line 1607  Line 1629 
1629    
1630                          stop_comp_timer();                          stop_comp_timer();
1631    
                         if (pMB->dquant != 0) {  
                 pMB->mode = MODE_INTER_Q;  
                         }  
   
1632                          pMB->field_pred = 0;                          pMB->field_pred = 0;
1633    
1634                          if (pMB->mode != MODE_NOT_CODED)                          if (pMB->mode != MODE_NOT_CODED)
# Line 1619  Line 1637 
1637                                                                            dct_codes, qcoeff);                                                                            dct_codes, qcoeff);
1638                          }                          }
1639    
1640                            if (pMB->dquant != 0)
1641                                    MBSetDquant(pMB, x, y, &pEnc->mbParam);
1642    
1643    
1644                          if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y ||                          if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y ||
1645                                     pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x ||                                     pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x ||
1646                                     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 1780  Line 1802 
1802                  BitstreamReset(bs);                  BitstreamReset(bs);
1803    
1804                  set_timecodes(current,reference,pParam->fbase);                  set_timecodes(current,reference,pParam->fbase);
1805                  BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 0);                  BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 0, current->mbs[0].quant);
1806    
1807                  /* copy reference frame details into the current frame */                  /* copy reference frame details into the current frame */
1808                  current->quant = reference->quant;                  current->quant = reference->quant;
# Line 1887  Line 1909 
1909                  pEnc->current->is_interpolated = 0;                  pEnc->current->is_interpolated = 0;
1910          }          }
1911    
1912            frame->coding_type = B_VOP;
1913            call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL);
1914    
1915          start_timer();          start_timer();
1916          MotionEstimationBVOP(&pEnc->mbParam, frame,          MotionEstimationBVOP(&pEnc->mbParam, frame,
1917                                                   ((int32_t)(pEnc->current->stamp - frame->stamp)),                              /* time_bp */                                                   ((int32_t)(pEnc->current->stamp - frame->stamp)),                              /* time_bp */
# Line 1897  Line 1922 
1922                                                   &pEnc->vInterV, &pEnc->vInterHV);                                                   &pEnc->vInterV, &pEnc->vInterHV);
1923          stop_motion_timer();          stop_motion_timer();
1924    
         frame->coding_type = B_VOP;  
   
1925          set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase);          set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase);
1926          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1, frame->quant);
1927    
1928          frame->sStat.iTextBits = 0;          frame->sStat.iTextBits = 0;
1929          frame->sStat.iMvSum = 0;          frame->sStat.iMvSum = 0;

Legend:
Removed from v.1.95.2.49  
changed lines
  Added in v.1.95.2.55

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