[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.31, Sat Jun 28 15:49:40 2003 UTC revision 1.95.2.37, Sun Aug 3 10:20:12 2003 UTC
# Line 117  Line 117 
117          Encoder *pEnc;          Encoder *pEnc;
118      int n;      int n;
119    
120          if (XVID_MAJOR(create->version) != 1)   /* v1.x.x */          if (XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */
121                  return XVID_ERR_VERSION;                  return XVID_ERR_VERSION;
122    
123          if (create->width%2 || create->height%2)          if (create->width%2 || create->height%2)
# Line 741  Line 741 
741    
742              for (j=0; j<pEnc->mbParam.mb_height; j++)              for (j=0; j<pEnc->mbParam.mb_height; j++)
743              for (i=0; i<pEnc->mbParam.mb_width; i++) {              for (i=0; i<pEnc->mbParam.mb_width; i++) {
744                  data.dquant[j*data.dquant_stride + i] = frame->mbs[j*pEnc->mbParam.mb_width + i].dquant;;                  data.dquant[j*data.dquant_stride + i] = frame->mbs[j*pEnc->mbParam.mb_width + i].dquant;
745              }              }
746          }          }
747    
# Line 867  Line 867 
867          int type;          int type;
868          Bitstream bs;          Bitstream bs;
869    
870          if (XVID_MAJOR(xFrame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1))     /* v1.x.x */          if (XVID_VERSION_MAJOR(xFrame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1))     /* v1.x.x */
871                  return XVID_ERR_VERSION;                  return XVID_ERR_VERSION;
872    
873          xFrame->out_flags = 0;          xFrame->out_flags = 0;
# Line 904  Line 904 
904    
905                  if (xFrame->quant_intra_matrix)                  if (xFrame->quant_intra_matrix)
906                  {                  {
907                          memcpy(q->quant_intra_matrix, xFrame->quant_intra_matrix, sizeof(xFrame->quant_intra_matrix));                          memcpy(q->quant_intra_matrix, xFrame->quant_intra_matrix, 64*sizeof(unsigned char));
908                          q->frame.quant_intra_matrix = q->quant_intra_matrix;                          q->frame.quant_intra_matrix = q->quant_intra_matrix;
909                  }                  }
910    
911                  if (xFrame->quant_inter_matrix)                  if (xFrame->quant_inter_matrix)
912                  {                  {
913                          memcpy(q->quant_inter_matrix, xFrame->quant_inter_matrix, sizeof(xFrame->quant_inter_matrix));                          memcpy(q->quant_inter_matrix, xFrame->quant_inter_matrix, 64*sizeof(unsigned char));
914                          q->frame.quant_inter_matrix = q->quant_inter_matrix;                          q->frame.quant_inter_matrix = q->quant_inter_matrix;
915                  }                  }
916    
# Line 1196  Line 1196 
1196                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP");
1197                  }                  }
1198    
1199                    pEnc->iFrameNum = 1;
1200    
1201                  /* ---- update vol flags at IVOP ----------- */                  /* ---- update vol flags at IVOP ----------- */
1202                  pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags;                  pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags;
# Line 1284  Line 1285 
1285  {  {
1286      unsigned int i,j;      unsigned int i,j;
1287      int quant = frame->quant;      int quant = frame->quant;
1288        if (quant > 31)
1289                    frame->quant = quant = 31;
1290            else if (quant < 1)
1291                    frame->quant = quant = 1;
1292    
1293      for (j=0; j<pParam->mb_height; j++)      for (j=0; j<pParam->mb_height; j++)
1294      for (i=0; i<pParam->mb_width; i++) {      for (i=0; i<pParam->mb_width; i++) {
# Line 1291  Line 1296 
1296          quant += pMB->dquant;          quant += pMB->dquant;
1297          if (quant > 31)          if (quant > 31)
1298                          quant = 31;                          quant = 31;
1299                  if (quant < 1)                  else if (quant < 1)
1300                          quant = 1;                          quant = 1;
1301          pMB->quant = quant;          pMB->quant = quant;
1302      }      }
# Line 1355  Line 1360 
1360    
1361          set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);          set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1362    
1363          BitstreamPadAlways(bs);          BitstreamPad(bs);
1364    
1365          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1366    
1367          pEnc->current->sStat.iTextBits = 0;          pEnc->current->sStat.iTextBits = 0;
# Line 1394  Line 1400 
1400          }          }
1401          emms();          emms();
1402    
1403  /* XXX: Remove the two #if 0 blocks when we are sure we must always pad the stream */          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */
1404  #if 0  
         /* for divx5 compatibility, we must always pad between the packed p and b frames */  
         if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0)  
 #endif  
                 BitstreamPadAlways(bs);  
 #if 0  
         else  
                 BitstreamPad(bs);  
 #endif  
1405      pEnc->current->length = (BitstreamPos(bs) - bits) / 8;      pEnc->current->length = (BitstreamPos(bs) - bits) / 8;
1406    
1407          pEnc->fMvPrevSigma = -1;          pEnc->fMvPrevSigma = -1;
# Line 1486  Line 1484 
1484                  current->warp = GlobalMotionEst( current->mbs, pParam, current, reference,                  current->warp = GlobalMotionEst( current->mbs, pParam, current, reference,
1485                                                                   &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV);                                                                   &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV);
1486    
1487                  if (current->motion_flags & XVID_GME_REFINE) {                  if (current->motion_flags & XVID_ME_GME_REFINE) {
1488                          gmcval = GlobalMotionEstRefine(&current->warp,                          gmcval = GlobalMotionEstRefine(&current->warp,
1489                                                                  current->mbs, pParam,                                                                  current->mbs, pParam,
1490                                                                  current, reference,                                                                  current, reference,
# Line 1544  Line 1542 
1542          set_timecodes(current,reference,pParam->fbase);          set_timecodes(current,reference,pParam->fbase);
1543          if (vol_header)          if (vol_header)
1544          {       BitstreamWriteVolHeader(bs, &pEnc->mbParam);          {       BitstreamWriteVolHeader(bs, &pEnc->mbParam);
1545                  BitstreamPadAlways(bs);                  BitstreamPad(bs);
1546          }          }
1547    
1548          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1);
# Line 1558  Line 1556 
1556                          MACROBLOCK *pMB =                          MACROBLOCK *pMB =
1557                                  &current->mbs[x + y * pParam->mb_width];                                  &current->mbs[x + y * pParam->mb_width];
1558    
 /* Mode decision: Check, if the block should be INTRA / INTER or GMC-coded */  
 /* For a start, leave INTRA decision as is, only choose only between INTER/GMC  - gruel, 9.1.2002 */  
   
1559                          bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q);                          bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q);
1560    
1561                          if (bIntra) {                          if (bIntra) {
# Line 1579  Line 1574 
1574                                  continue;                                  continue;
1575                          }                          }
1576    
                         if (current->coding_type == S_VOP) {  
   
                                 int32_t iSAD = sad16(current->image.y + 16*y*pParam->edged_width + 16*x,  
                                         pEnc->vGMC.y + 16*y*pParam->edged_width + 16*x,  
                                         pParam->edged_width, 65536);  
   
                                 if (current->motion_flags & XVID_ME_CHROMA16) {  
                                         iSAD += sad8(current->image.u + 8*y*(pParam->edged_width/2) + 8*x,  
                                         pEnc->vGMC.u + 8*y*(pParam->edged_width/2) + 8*x, pParam->edged_width/2);  
   
                                         iSAD += sad8(current->image.v + 8*y*(pParam->edged_width/2) + 8*x,  
                                         pEnc->vGMC.v + 8*y*(pParam->edged_width/2) + 8*x, pParam->edged_width/2);  
                                 }  
   
                                 if (iSAD <= pMB->sad16) {               /* mode decision GMC */  
   
                                         if ((pParam->vol_flags & XVID_VOL_QUARTERPEL))  
                                                 pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv;  
                                         else  
                                                 pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;  
   
                                         pMB->mode = MODE_INTER;  
                                         pMB->mcsel = 1;  
                                         pMB->sad16 = iSAD;  
                                 } else {  
                                         pMB->mcsel = 0;  
                                 }  
                         } else {  
                                 pMB->mcsel = 0; /* just a precaution */  
                         }  
   
1577                          start_timer();                          start_timer();
1578                          MBMotionCompensation(pMB, x, y, &reference->image,                          MBMotionCompensation(pMB, x, y, &reference->image,
1579                                                                   &pEnc->vInterH, &pEnc->vInterV,                                                                   &pEnc->vInterH, &pEnc->vInterV,
# Line 1824  Line 1788 
1788          }          }
1789          */          */
1790    
1791  /* XXX: Remove the two #if 0 blocks when we are sure we must always pad the stream */          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */
 #if 0  
         /* for divx5 compatibility, we must always pad between the packed p and b frames */  
         if ((pParam->global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0)  
 #endif  
                 BitstreamPadAlways(bs);  
 #if 0  
         else  
                 BitstreamPad(bs);  
 #endif  
1792    
1793      current->length = (BitstreamPos(bs) - bits) / 8;      current->length = (BitstreamPos(bs) - bits) / 8;
1794    
# Line 1954  Line 1909 
1909    
1910          /* TODO: dynamic fcode/bcode ??? */          /* TODO: dynamic fcode/bcode ??? */
1911    
1912      BitstreamPadAlways(bs);      BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */
1913          frame->length = (BitstreamPos(bs) - bits) / 8;          frame->length = (BitstreamPos(bs) - bits) / 8;
1914    
1915  #ifdef BFRAMES_DEC_DEBUG  #ifdef BFRAMES_DEC_DEBUG

Legend:
Removed from v.1.95.2.31  
changed lines
  Added in v.1.95.2.37

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