[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.22, Wed Nov 27 11:50:33 2002 UTC revision 1.91, Sat Feb 15 15:22:17 2003 UTC
# Line 43  Line 43 
43   *   *
44   ****************************************************************************/   ****************************************************************************/
45    
   
46  #include <stdlib.h>  #include <stdlib.h>
47  #include <stdio.h>  #include <stdio.h>
48  #include <math.h>  #include <math.h>
# Line 73  Line 72 
72   ****************************************************************************/   ****************************************************************************/
73    
74  #define ENC_CHECK(X) if(!(X)) return XVID_ERR_FORMAT  #define ENC_CHECK(X) if(!(X)) return XVID_ERR_FORMAT
75  #define SWAP(A,B)    { void * tmp = A; A = B; B = tmp; }  #define SWAP(_T_,A,B)    { _T_ tmp = A; A = B; B = tmp; }
76    
77  /*****************************************************************************  /*****************************************************************************
78   * Local function prototypes   * Local function prototypes
# Line 224  Line 223 
223    
224          pEnc->mbParam.m_quant_type = H263_QUANT;          pEnc->mbParam.m_quant_type = H263_QUANT;
225    
226          pEnc->sStat.fMvPrevSigma = -1;          pEnc->fMvPrevSigma = -1;
227    
228          /* Fill rate control parameters */          /* Fill rate control parameters */
229    
230          pEnc->bitrate = pParam->rc_bitrate;          pEnc->bitrate = pParam->rc_bitrate;
231    
232          pEnc->iFrameNum = 0;          pEnc->iFrameNum = -1;
233          pEnc->iMaxKeyInterval = pParam->max_key_interval;          pEnc->mbParam.iMaxKeyInterval = pParam->max_key_interval;
234    
235          /* try to allocate frame memory */          /* try to allocate frame memory */
236    
# Line 255  Line 254 
254    
255          /* try to allocate image memory */          /* try to allocate image memory */
256    
257  #ifdef _DEBUG_PSNR          if (pParam->global & XVID_GLOBAL_EXTRASTATS)
258          image_null(&pEnc->sOriginal);          image_null(&pEnc->sOriginal);
 #endif  
259    
260          image_null(&pEnc->f_refh);          image_null(&pEnc->f_refh);
261          image_null(&pEnc->f_refv);          image_null(&pEnc->f_refv);
# Line 271  Line 269 
269          image_null(&pEnc->vInterHV);          image_null(&pEnc->vInterHV);
270          image_null(&pEnc->vInterHVf);          image_null(&pEnc->vInterHVf);
271    
272  #ifdef _DEBUG_PSNR          if (pParam->global & XVID_GLOBAL_EXTRASTATS)
273          if (image_create          {       if (image_create
274                  (&pEnc->sOriginal, pEnc->mbParam.edged_width,                  (&pEnc->sOriginal, pEnc->mbParam.edged_width,
275                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
276                  goto xvid_err_memory3;                  goto xvid_err_memory3;
277  #endif          }
278    
279          if (image_create          if (image_create
280                  (&pEnc->f_refh, pEnc->mbParam.edged_width,                  (&pEnc->f_refh, pEnc->mbParam.edged_width,
# Line 320  Line 318 
318                   pEnc->mbParam.edged_height) < 0)                   pEnc->mbParam.edged_height) < 0)
319                  goto xvid_err_memory3;                  goto xvid_err_memory3;
320    
321    /* Create full bitplane for GMC, this might be wasteful */
322            if (image_create
323                    (&pEnc->vGMC, pEnc->mbParam.edged_width,
324                     pEnc->mbParam.edged_height) < 0)
325                    goto xvid_err_memory3;
326    
327    
         /* B Frames specific init */  
328    
329          pEnc->global = pParam->global;          pEnc->mbParam.global = pParam->global;
330    
331            /* B Frames specific init */
332          pEnc->mbParam.max_bframes = pParam->max_bframes;          pEnc->mbParam.max_bframes = pParam->max_bframes;
333          pEnc->bquant_ratio = pParam->bquant_ratio;          pEnc->mbParam.bquant_ratio = pParam->bquant_ratio;
334          pEnc->bquant_offset = pParam->bquant_offset;          pEnc->mbParam.bquant_offset = pParam->bquant_offset;
335          pEnc->frame_drop_ratio = pParam->frame_drop_ratio;          pEnc->mbParam.frame_drop_ratio = pParam->frame_drop_ratio;
336          pEnc->bframes = NULL;          pEnc->bframes = NULL;
337    
338          if (pEnc->mbParam.max_bframes > 0) {          if (pEnc->mbParam.max_bframes > 0) {
# Line 460  Line 464 
464          }          }
465    
466    xvid_err_memory3:    xvid_err_memory3:
467  #ifdef _DEBUG_PSNR  
468          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,          if (pEnc->mbParam.global & XVID_GLOBAL_EXTRASTATS)
469            {       image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,
470                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
471  #endif          }
472    
473          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width,
474                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
# Line 487  Line 492 
492          image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width,          image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width,
493                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
494    
495    /* destroy GMC image */
496            image_destroy(&pEnc->vGMC, pEnc->mbParam.edged_width,
497                                      pEnc->mbParam.edged_height);
498    
499    
500    xvid_err_memory2:    xvid_err_memory2:
501          xvid_free(pEnc->current->mbs);          xvid_free(pEnc->current->mbs);
502          xvid_free(pEnc->reference->mbs);          xvid_free(pEnc->reference->mbs);
# Line 574  Line 584 
584          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,          image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width,
585                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
586    
587  #ifdef _DEBUG_PSNR          if (pEnc->mbParam.global & XVID_GLOBAL_EXTRASTATS)
588          image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,          {       image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width,
589                                    pEnc->mbParam.edged_height);                                    pEnc->mbParam.edged_height);
590  #endif          }
591    
592          /* Encoder structure */          /* Encoder structure */
593    
# Line 646  Line 656 
656    
657    
658    
659    /* convert pFrame->intra to coding_type */
660    static int intra2coding_type(int intra)
661    {
662            if (intra < 0)  return -1;
663            if (intra == 1) return I_VOP;
664            if (intra == 2) return B_VOP;
665    
666            return P_VOP;
667    }
668    
669    
670    
671  /*****************************************************************************  /*****************************************************************************
# Line 664  Line 684 
684  {  {
685          uint16_t x, y;          uint16_t x, y;
686          Bitstream bs;          Bitstream bs;
687          uint32_t bits, mode;          uint32_t bits;
688            int mode;
689    
690          int input_valid = 1;          int input_valid = 1;
691          int bframes_count = 0;          int bframes_count = 0;
692    
 #ifdef _DEBUG_PSNR  
         float psnr;  
         char temp[128];  
 #endif  
   
693          ENC_CHECK(pEnc);          ENC_CHECK(pEnc);
694          ENC_CHECK(pFrame);          ENC_CHECK(pFrame);
695          ENC_CHECK(pFrame->image);          ENC_CHECK(pFrame->image);
# Line 703  Line 719 
719                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
720    
721                          pEnc->bframenum_tail--;                          pEnc->bframenum_tail--;
722                          SWAP(pEnc->current, pEnc->reference);                          SWAP(FRAMEINFO *, pEnc->current, pEnc->reference);
723    
724                          SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);                          SWAP(FRAMEINFO *, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);
725    
726                          FrameCodeP(pEnc, &bs, &bits, 1, 0);                          FrameCodeP(pEnc, &bs, &bits, 1, 0);
727                          bframes_count = 0;                          bframes_count = 0;
728    
729                          BitstreamPad(&bs);                          BitstreamPadAlways(&bs);
730                          pFrame->length = BitstreamLength(&bs);                          pFrame->length = BitstreamLength(&bs);
731                          pFrame->intra = 0;                          pFrame->intra = 0;
732    
733    
734                          emms();                          emms();
735    
736                            if (pResult) {
737                                    pResult->quant = pEnc->current->quant;
738                                    pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
739                                    pResult->kblks = pEnc->current->sStat.kblks;
740                                    pResult->mblks = pEnc->current->sStat.mblks;
741                                    pResult->ublks = pEnc->current->sStat.ublks;
742                            }
743    
744                          return XVID_ERR_OK;                          return XVID_ERR_OK;
745                  }                  }
746    
# Line 727  Line 752 
752                  FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs, &bits);                  FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs, &bits);
753                  pEnc->bframenum_head++;                  pEnc->bframenum_head++;
754    
755                  BitstreamPad(&bs);                  BitstreamPadAlways(&bs);
756                  pFrame->length = BitstreamLength(&bs);                  pFrame->length = BitstreamLength(&bs);
757                  pFrame->intra = 2;                  pFrame->intra = 2;
758    
759                    if (pResult) {
760                            pResult->quant = pEnc->current->quant;
761                            pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
762                            pResult->kblks = pEnc->current->sStat.kblks;
763                            pResult->mblks = pEnc->current->sStat.mblks;
764                            pResult->ublks = pEnc->current->sStat.ublks;
765                    }
766    
767                  if (input_valid)                  if (input_valid)
768                          queue_image(pEnc, pFrame);                          queue_image(pEnc, pFrame);
769    
# Line 749  Line 782 
782                     indentical to the future-referece frame.                     indentical to the future-referece frame.
783                  */                  */
784    
785                  if ((pEnc->global & XVID_GLOBAL_PACKED)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_PACKED)) {
786                          int tmp;                          int tmp;
787    
788                          DPRINTF(DPRINTF_DEBUG,"*** EMPTY bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",                          DPRINTF(DPRINTF_DEBUG,"*** EMPTY bf: head=%i tail=%i   queue: head=%i tail=%i size=%i",
789                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
790                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
791    
                         BitstreamPad(&bs);  
792    
793                          tmp = pEnc->current->seconds;                          tmp = pEnc->current->seconds;
794                          pEnc->current->seconds = 0; /* force time_base = 0 */                          pEnc->current->seconds = 0; /* force time_base = 0 */
795    
796                          BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);                          BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0);
797                          pEnc->current->seconds = tmp;                          pEnc->current->seconds = tmp;
798    
799                            BitstreamPadAlways(&bs);
800                          pFrame->length = BitstreamLength(&bs);                          pFrame->length = BitstreamLength(&bs);
801                          pFrame->intra = 4;                          pFrame->intra = 4;
802    
803                            if (pResult) {
804                                    pResult->quant = pEnc->current->quant;
805                                    pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
806                                    pResult->kblks = pEnc->current->sStat.kblks;
807                                    pResult->mblks = pEnc->current->sStat.mblks;
808                                    pResult->ublks = pEnc->current->sStat.ublks;
809                            }
810    
811                          if (input_valid)                          if (input_valid)
812                                  queue_image(pEnc, pFrame);                                  queue_image(pEnc, pFrame);
813    
# Line 781  Line 823 
823          if (pEnc->bframenum_dx50bvop != -1)          if (pEnc->bframenum_dx50bvop != -1)
824          {          {
825    
826                  SWAP(pEnc->current, pEnc->reference);                  SWAP(FRAMEINFO *, pEnc->current, pEnc->reference);
827                  SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]);                  SWAP(FRAMEINFO *, pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]);
828    
829                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) {
830                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 IVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 IVOP");
831                  }                  }
832    
# Line 796  Line 838 
838    
839          } else if (input_valid) {          } else if (input_valid) {
840    
841                  SWAP(pEnc->current, pEnc->reference);                  SWAP(FRAMEINFO *, pEnc->current, pEnc->reference);
842    
843                  start_timer();                  start_timer();
844                  if (image_input                  if (image_input
# Line 822  Line 864 
864    
865          } else if (pEnc->queue_size > 0) {          } else if (pEnc->queue_size > 0) {
866    
867                  SWAP(pEnc->current, pEnc->reference);                  SWAP(FRAMEINFO *, pEnc->current, pEnc->reference);
868    
869                  image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head]);                  image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head]);
870                  pEnc->queue_head =  (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes;                  pEnc->queue_head =  (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes;
# Line 839  Line 881 
881                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
882                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
883    
884                          BitstreamPutBits(&bs, 0x7f, 8);                  //      BitstreamPutBits(&bs, 0x7f, 8);
885                          pFrame->intra = 5;                          pFrame->intra = 5;
886    
887                            if (pResult) {
888                                    /*
889                                     * We must decide what to put there because i know some apps
890                                     * are storing statistics about quantizers and just do
891                                     * stats[quant]++ or stats[quant-1]++
892                                     * transcode is one of these app with its 2pass module
893                                     */
894    
895                                    /*
896                                     * For now i prefer 31 than 0 that could lead to a segfault
897                                     * in transcode
898                                     */
899                                    pResult->quant = 31;
900    
901                                    pResult->hlength = 0;
902                                    pResult->kblks = 0;
903                                    pResult->mblks = 0;
904                                    pResult->ublks = 0;
905                            }
906    
907                    } else {
908    
909                            if (pResult) {
910                                    pResult->quant = pEnc->current->quant;
911                                    pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
912                                    pResult->kblks = pEnc->current->sStat.kblks;
913                                    pResult->mblks = pEnc->current->sStat.mblks;
914                                    pResult->ublks = pEnc->current->sStat.ublks;
915                            }
916    
917                  }                  }
918    
919                  pFrame->length = BitstreamLength(&bs);                  pFrame->length = BitstreamLength(&bs);
920    
921                  emms();                  emms();
922    
923                  return XVID_ERR_OK;                  return XVID_ERR_OK;
924          }          }
925    
# Line 855  Line 930 
930          // only inc frame num, adapt quant, etc. if we havent seen it before          // only inc frame num, adapt quant, etc. if we havent seen it before
931          if (pEnc->bframenum_dx50bvop < 0 )          if (pEnc->bframenum_dx50bvop < 0 )
932          {          {
933                    mode = intra2coding_type(pFrame->intra);
934                  if (pFrame->quant == 0)                  if (pFrame->quant == 0)
935                          pEnc->current->quant = RateControlGetQ(&pEnc->rate_control, 0);                          pEnc->current->quant = RateControlGetQ(&pEnc->rate_control, 0);
936                  else                  else
# Line 875  Line 951 
951    
952                  inc_frame_num(pEnc);                  inc_frame_num(pEnc);
953    
954  #ifdef _DEBUG_PSNR                  if (pFrame->general & XVID_EXTRASTATS)
955                  image_copy(&pEnc->sOriginal, &pEnc->current->image,                  {       image_copy(&pEnc->sOriginal, &pEnc->current->image,
956                             pEnc->mbParam.edged_width, pEnc->mbParam.height);                             pEnc->mbParam.edged_width, pEnc->mbParam.height);
957  #endif                  }
958    
959                  emms();                  emms();
960    
961                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) {
962                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5,                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5,
963                                  "%i  if:%i  st:%i", pEnc->m_framenum++, pEnc->iFrameNum, pEnc->current->stamp);                                  "%i  if:%i  st:%i", pEnc->m_framenum++, pEnc->iFrameNum, pEnc->current->stamp);
964                  }                  }
# Line 926  Line 1002 
1002          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1003           * ivop/pvop/bvop selection           * ivop/pvop/bvop selection
1004           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */           * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
1005            pEnc->iFrameNum++;
1006    
1007          if (pEnc->iFrameNum == 0 || pFrame->intra == 1 || pEnc->bframenum_dx50bvop >= 0 ||          if (pEnc->iFrameNum == 0 || pEnc->bframenum_dx50bvop >= 0 ||
1008                  (pFrame->intra < 0 && pEnc->iMaxKeyInterval > 0 &&                  (mode < 0 && pEnc->mbParam.iMaxKeyInterval > 0 &&
1009                   pEnc->iFrameNum >= pEnc->iMaxKeyInterval)                          pEnc->iFrameNum >= pEnc->mbParam.iMaxKeyInterval))
1010                  || 2 == (mode = MEanalysis(&pEnc->reference->image, pEnc->current,          {
1011                                                                          &pEnc->mbParam, pEnc->iMaxKeyInterval,                  mode = I_VOP;
1012                                                                          (pFrame->intra < 0) ? pEnc->iFrameNum : 0,          }else{
1013                                                                          bframes_count++))) {                  mode = MEanalysis(&pEnc->reference->image, pEnc->current,
1014                                            &pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval,
1015                                            (mode < 0) ? pEnc->iFrameNum : 0,
1016                                            bframes_count++);
1017            }
1018    
1019            if (mode == I_VOP) {
1020                  /*                  /*
1021                   * This will be coded as an Intra Frame                   * This will be coded as an Intra Frame
1022                   */                   */
# Line 957  Line 1039 
1039                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
1040                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
1041    
1042                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) {
1043                          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");
1044                  }                  }
1045    
1046                  // when we reach an iframe in DX50BVOP mode, encode the last bframe as a pframe                  // when we reach an iframe in DX50BVOP mode, encode the last bframe as a pframe
1047    
1048                  if ((pEnc->global & XVID_GLOBAL_DX50BVOP) && pEnc->bframenum_tail > 0) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_DX50BVOP) && pEnc->bframenum_tail > 0) {
1049    
1050                          pEnc->bframenum_tail--;                          pEnc->bframenum_tail--;
1051                          pEnc->bframenum_dx50bvop = pEnc->bframenum_tail;                          pEnc->bframenum_dx50bvop = pEnc->bframenum_tail;
1052    
1053                          SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]);                          SWAP(FRAMEINFO *, pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]);
1054                          if ((pEnc->global & XVID_GLOBAL_DEBUG)) {                          if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) {
1055                                  image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP");                                  image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP");
1056                          }                          }
1057                          FrameCodeP(pEnc, &bs, &bits, 1, 0);                          FrameCodeP(pEnc, &bs, &bits, 1, 0);
1058                          bframes_count = 0;                          bframes_count = 0;
   
1059                          pFrame->intra = 0;                          pFrame->intra = 0;
1060    
1061                  } else {                  } else {
# Line 988  Line 1069 
1069    
1070                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
1071    
1072                  if ((pEnc->global & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) {
1073                          BitstreamPadAlways(&bs);                          BitstreamPadAlways(&bs);
1074                          input_valid = 0;                          input_valid = 0;
1075                          goto ipvop_loop;                          goto ipvop_loop;
# Line 998  Line 1079 
1079                   * NB : sequences like "IIBB" decode fine with msfdam but,                   * NB : sequences like "IIBB" decode fine with msfdam but,
1080                   *      go screwy with divx 5.00                   *      go screwy with divx 5.00
1081                   */                   */
1082          } else if (pEnc->bframenum_tail >= pEnc->mbParam.max_bframes || mode != 0) {          } else if (mode == P_VOP || mode == S_VOP || pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) {
 //      } else if (pFrame->intra == 0 || pEnc->bframenum_tail >= pEnc->mbParam.max_bframes || mode != 0) {  
1083                  /*                  /*
1084                   * This will be coded as a Predicted Frame                   * This will be coded as a Predicted Frame
1085                   */                   */
# Line 1008  Line 1088 
1088                                  pEnc->bframenum_head, pEnc->bframenum_tail,                                  pEnc->bframenum_head, pEnc->bframenum_tail,
1089                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size);
1090    
1091                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) {
1092                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP");
1093                  }                  }
1094    
# Line 1017  Line 1097 
1097                  pFrame->intra = 0;                  pFrame->intra = 0;
1098                  pEnc->flush_bframes = 1;                  pEnc->flush_bframes = 1;
1099    
1100                  if ((pEnc->global & XVID_GLOBAL_PACKED) && (pEnc->bframenum_tail > 0)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_PACKED) && (pEnc->bframenum_tail > 0)) {
1101                          BitstreamPadAlways(&bs);                          BitstreamPadAlways(&bs);
1102                          input_valid = 0;                          input_valid = 0;
1103                          goto ipvop_loop;                          goto ipvop_loop;
1104                  }                  }
1105    
1106          } else {          } else {        /* mode == B_VOP */
1107                  /*                  /*
1108                   * This will be coded as a Bidirectional Frame                   * This will be coded as a Bidirectional Frame
1109                   */                   */
1110    
1111                  if ((pEnc->global & XVID_GLOBAL_DEBUG)) {                  if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) {
1112                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP");
1113                  }                  }
1114    
1115                  if (pFrame->bquant < 1) {                  if (pFrame->bquant < 1) {
1116                          pEnc->current->quant = ((((pEnc->reference->quant + pEnc->current->quant) *                          pEnc->current->quant = ((((pEnc->reference->quant + pEnc->current->quant) *
1117                                  pEnc->bquant_ratio) / 2) + pEnc->bquant_offset)/100;                                  pEnc->mbParam.bquant_ratio) / 2) + pEnc->mbParam.bquant_offset)/100;
1118    
1119                  } else {                  } else {
1120                          pEnc->current->quant = pFrame->bquant;                          pEnc->current->quant = pFrame->bquant;
# Line 1050  Line 1130 
1130                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size,pEnc->current->quant);                                  pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size,pEnc->current->quant);
1131    
1132                  /* store frame into bframe buffer & swap ref back to current */                  /* store frame into bframe buffer & swap ref back to current */
1133                  SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);                  SWAP(FRAMEINFO *, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);
1134                  SWAP(pEnc->current, pEnc->reference);                  SWAP(FRAMEINFO *, pEnc->current, pEnc->reference);
1135    
1136                  pEnc->bframenum_tail++;                  pEnc->bframenum_tail++;
1137    
# Line 1063  Line 1143 
1143                  goto bvop_loop;                  goto bvop_loop;
1144          }          }
1145    
1146          pEnc->iFrameNum++;          BitstreamPadAlways(&bs);
   
         BitstreamPad(&bs);  
1147          pFrame->length = BitstreamLength(&bs);          pFrame->length = BitstreamLength(&bs);
1148    
1149          if (pResult) {          if (pResult) {
1150                  pResult->quant = pEnc->current->quant;                  pResult->quant = pEnc->current->quant;
1151                  pResult->hlength = pFrame->length - (pEnc->sStat.iTextBits / 8);                  pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
1152                  pResult->kblks = pEnc->sStat.kblks;                  pResult->kblks = pEnc->current->sStat.kblks;
1153                  pResult->mblks = pEnc->sStat.mblks;                  pResult->mblks = pEnc->current->sStat.mblks;
1154                  pResult->ublks = pEnc->sStat.ublks;                  pResult->ublks = pEnc->current->sStat.ublks;
1155          }  
1156                    if (pFrame->general & XVID_EXTRASTATS)
1157          emms();                  {       pResult->sse_y =
1158                                    plane_sse( pEnc->sOriginal.y, pEnc->current->image.y,
 #ifdef _DEBUG_PSNR  
         psnr =  
                 image_psnr(&pEnc->sOriginal, &pEnc->current->image,  
1159                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,
1160                                     pEnc->mbParam.height);                                     pEnc->mbParam.height);
1161    
1162          snprintf(temp, 127, "PSNR: %f\n", psnr);                          pResult->sse_u =
1163          DEBUG(temp);                                  plane_sse( pEnc->sOriginal.u, pEnc->current->image.u,
1164  #endif                                                     pEnc->mbParam.edged_width/2, pEnc->mbParam.width/2,
1165                                                       pEnc->mbParam.height/2);
1166    
1167                            pResult->sse_v =
1168                                    plane_sse( pEnc->sOriginal.v, pEnc->current->image.v,
1169                                                       pEnc->mbParam.edged_width/2, pEnc->mbParam.width/2,
1170                                                       pEnc->mbParam.height/2);
1171                    }
1172            }
1173    
1174            emms();
1175    
1176          if (pFrame->quant == 0) {          if (pFrame->quant == 0) {
1177                  RateControlUpdate(&pEnc->rate_control, pEnc->current->quant,                  RateControlUpdate(&pEnc->rate_control, pEnc->current->quant,
# Line 1121  Line 1206 
1206          uint32_t bits;          uint32_t bits;
1207          uint16_t write_vol_header = 0;          uint16_t write_vol_header = 0;
1208    
 #ifdef _DEBUG_PSNR  
1209          float psnr;          float psnr;
1210          uint8_t temp[128];          uint8_t temp[128];
 #endif  
1211    
1212          start_global_timer();          start_global_timer();
1213    
# Line 1133  Line 1216 
1216          ENC_CHECK(pFrame->bitstream);          ENC_CHECK(pFrame->bitstream);
1217          ENC_CHECK(pFrame->image);          ENC_CHECK(pFrame->image);
1218    
1219          SWAP(pEnc->current, pEnc->reference);          SWAP(FRAMEINFO *, pEnc->current, pEnc->reference);
1220    
1221          pEnc->current->global_flags = pFrame->general;          pEnc->current->global_flags = pFrame->general;
1222          pEnc->current->motion_flags = pFrame->motion;          pEnc->current->motion_flags = pFrame->motion;
# Line 1155  Line 1238 
1238                  return XVID_ERR_FORMAT;                  return XVID_ERR_FORMAT;
1239          stop_conv_timer();          stop_conv_timer();
1240    
1241  #ifdef _DEBUG_PSNR          if (pFrame->general & XVID_EXTRASTATS)
1242          image_copy(&pEnc->sOriginal, &pEnc->current->image,          {       image_copy(&pEnc->sOriginal, &pEnc->current->image,
1243                             pEnc->mbParam.edged_width, pEnc->mbParam.height);                             pEnc->mbParam.edged_width, pEnc->mbParam.height);
1244  #endif          }
1245    
1246          emms();          emms();
1247    
# Line 1235  Line 1318 
1318          }          }
1319    
1320          if (pFrame->intra < 0) {          if (pFrame->intra < 0) {
1321                  if ((pEnc->iFrameNum == 0)                  if ((pEnc->iFrameNum == -1)
1322                          || ((pEnc->iMaxKeyInterval > 0)                          || ((pEnc->mbParam.iMaxKeyInterval > 0)
1323                                  && (pEnc->iFrameNum >= pEnc->iMaxKeyInterval))) {                                  && (pEnc->iFrameNum >= pEnc->mbParam.iMaxKeyInterval))) {
1324                          pFrame->intra = FrameCodeI(pEnc, &bs, &bits);                          pFrame->intra = FrameCodeI(pEnc, &bs, &bits);
1325                  } else {                  } else {
1326                          pFrame->intra = FrameCodeP(pEnc, &bs, &bits, 0, write_vol_header);                          pFrame->intra = FrameCodeP(pEnc, &bs, &bits, 0, write_vol_header);
# Line 1251  Line 1334 
1334    
1335          }          }
1336    
1337          BitstreamPutBits(&bs, 0xFFFF, 16);  //      BitstreamPutBits(&bs, 0xFFFF, 16);
1338          BitstreamPutBits(&bs, 0xFFFF, 16);  //      BitstreamPutBits(&bs, 0xFFFF, 16);
1339          BitstreamPad(&bs);          BitstreamPadAlways(&bs);
1340          pFrame->length = BitstreamLength(&bs);          pFrame->length = BitstreamLength(&bs);
1341    
1342          if (pResult) {          if (pResult) {
1343                  pResult->quant = pEnc->current->quant;                  pResult->quant = pEnc->current->quant;
1344                  pResult->hlength = pFrame->length - (pEnc->sStat.iTextBits / 8);                  pResult->hlength = pFrame->length - (pEnc->current->sStat.iTextBits / 8);
1345                  pResult->kblks = pEnc->sStat.kblks;                  pResult->kblks = pEnc->current->sStat.kblks;
1346                  pResult->mblks = pEnc->sStat.mblks;                  pResult->mblks = pEnc->current->sStat.mblks;
1347                  pResult->ublks = pEnc->sStat.ublks;                  pResult->ublks = pEnc->current->sStat.ublks;
1348          }          }
1349    
1350          emms();          emms();
# Line 1270  Line 1353 
1353                  RateControlUpdate(&pEnc->rate_control, pEnc->current->quant,                  RateControlUpdate(&pEnc->rate_control, pEnc->current->quant,
1354                                                    pFrame->length, pFrame->intra);                                                    pFrame->length, pFrame->intra);
1355          }          }
1356  #ifdef _DEBUG_PSNR          if (pFrame->general & XVID_EXTRASTATS)
1357            {
1358          psnr =          psnr =
1359                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,                  image_psnr(&pEnc->sOriginal, &pEnc->current->image,
1360                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,                                     pEnc->mbParam.edged_width, pEnc->mbParam.width,
1361                                     pEnc->mbParam.height);                                     pEnc->mbParam.height);
1362    
1363          snprintf(temp, 127, "PSNR: %f\n", psnr);          snprintf(temp, 127, "PSNR: %f\n", psnr);
1364          DEBUG(temp);          }
 #endif  
1365    
1366          pEnc->iFrameNum++;          pEnc->iFrameNum++;
1367    
# Line 1444  Line 1527 
1527    
1528          if (intra) {          if (intra) {
1529                  if (!hint->rawhints) {                  if (!hint->rawhints) {
1530                          BitstreamPad(&bs);                          BitstreamPadAlways(&bs);
1531                          hint->hintlength = BitstreamLength(&bs);                          hint->hintlength = BitstreamLength(&bs);
1532                  }                  }
1533                  return;                  return;
# Line 1519  Line 1602 
1602                     Bitstream * bs,                     Bitstream * bs,
1603                     uint32_t * pBits)                     uint32_t * pBits)
1604  {  {
1605            int mb_width = pEnc->mbParam.mb_width;
1606            int mb_height = pEnc->mbParam.mb_height;
1607    
1608          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);
1609          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
1610    
1611          uint16_t x, y;          uint16_t x, y;
1612    
1613            if ((pEnc->current->global_flags & XVID_REDUCED))
1614            {
1615                    mb_width = (pEnc->mbParam.width + 31) / 32;
1616                    mb_height = (pEnc->mbParam.height + 31) / 32;
1617    
1618                    /* 16x16->8x8 downsample requires 1 additional edge pixel*/
1619                    /* XXX: setedges is overkill */
1620                    start_timer();
1621                    image_setedges(&pEnc->current->image,
1622                            pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1623                            pEnc->mbParam.width, pEnc->mbParam.height);
1624                    stop_edges_timer();
1625            }
1626    
1627          pEnc->iFrameNum = 0;          pEnc->iFrameNum = 0;
1628          pEnc->mbParam.m_rounding_type = 1;          pEnc->mbParam.m_rounding_type = 1;
1629          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;
# Line 1533  Line 1632 
1632    
1633          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);          BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1634    
 #define DIVX501B481P "DivX501b481p"  
         if ((pEnc->global & XVID_GLOBAL_PACKED)) {  
                 BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P));  
         }  
   
 #define XVID_ID "XviD" XVID_BS_VERSION  
         BitstreamWriteUserData(bs, XVID_ID, strlen(XVID_ID));  
   
1635          set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);          set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1636    
1637            BitstreamPadAlways(bs);
1638          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1639    
1640          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1641    
1642          pEnc->sStat.iTextBits = 0;          pEnc->current->sStat.iTextBits = 0;
1643          pEnc->sStat.kblks = pEnc->mbParam.mb_width * pEnc->mbParam.mb_height;          pEnc->current->sStat.kblks = mb_width * mb_height;
1644          pEnc->sStat.mblks = pEnc->sStat.ublks = 0;          pEnc->current->sStat.mblks = pEnc->current->sStat.ublks = 0;
1645    
1646          for (y = 0; y < pEnc->mbParam.mb_height; y++)          for (y = 0; y < mb_height; y++)
1647                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
1648                          MACROBLOCK *pMB =                          MACROBLOCK *pMB =
1649                                  &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];                                  &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];
1650    
# Line 1570  Line 1663 
1663                                  qcoeff[4*64+0]=0;               /* zero, because for INTRA MBs DC value is saved */                                  qcoeff[4*64+0]=0;               /* zero, because for INTRA MBs DC value is saved */
1664                                  qcoeff[5*64+0]=0;                                  qcoeff[5*64+0]=0;
1665                          }                          }
1666                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);
1667                          stop_coding_timer();                          stop_coding_timer();
1668                  }                  }
1669    
1670            if ((pEnc->current->global_flags & XVID_REDUCED))
1671            {
1672                    image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width,
1673                            pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width,
1674                            16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV);
1675            }
1676          emms();          emms();
1677    
1678          *pBits = BitstreamPos(bs) - *pBits;          *pBits = BitstreamPos(bs) - *pBits;
1679          pEnc->sStat.fMvPrevSigma = -1;          pEnc->fMvPrevSigma = -1;
         pEnc->sStat.iMvSum = 0;  
         pEnc->sStat.iMvCount = 0;  
1680          pEnc->mbParam.m_fcode = 2;          pEnc->mbParam.m_fcode = 2;
1681    
1682          if (pEnc->current->global_flags & XVID_HINTEDME_GET) {          if (pEnc->current->global_flags & XVID_HINTEDME_GET) {
# Line 1593  Line 1690 
1690  #define INTRA_THRESHOLD 0.5  #define INTRA_THRESHOLD 0.5
1691  #define BFRAME_SKIP_THRESHHOLD 30  #define BFRAME_SKIP_THRESHHOLD 30
1692    
1693    
1694    /* FrameCodeP also handles S(GMC)-VOPs */
1695  static int  static int
1696  FrameCodeP(Encoder * pEnc,  FrameCodeP(Encoder * pEnc,
1697                     Bitstream * bs,                     Bitstream * bs,
# Line 1605  Line 1704 
1704          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);
1705          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
1706    
1707            int mb_width = pEnc->mbParam.mb_width;
1708            int mb_height = pEnc->mbParam.mb_height;
1709    
1710          int iLimit;          int iLimit;
1711          int x, y, k;          int x, y, k;
1712          int iSearchRange;          int iSearchRange;
# Line 1613  Line 1715 
1715          /* IMAGE *pCurrent = &pEnc->current->image; */          /* IMAGE *pCurrent = &pEnc->current->image; */
1716          IMAGE *pRef = &pEnc->reference->image;          IMAGE *pRef = &pEnc->reference->image;
1717    
1718            if ((pEnc->current->global_flags & XVID_REDUCED))
1719            {
1720                    mb_width = (pEnc->mbParam.width + 31) / 32;
1721                    mb_height = (pEnc->mbParam.height + 31) / 32;
1722            }
1723    
1724    
1725          start_timer();          start_timer();
1726          image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,          image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,
1727                                     pEnc->mbParam.width, pEnc->mbParam.height);                                     pEnc->mbParam.width, pEnc->mbParam.height);
# Line 1624  Line 1733 
1733          pEnc->current->fcode = pEnc->mbParam.m_fcode;          pEnc->current->fcode = pEnc->mbParam.m_fcode;
1734    
1735          if (!force_inter)          if (!force_inter)
1736                  iLimit =                  iLimit = (int)(mb_width * mb_height *  INTRA_THRESHOLD);
                         (int) (pEnc->mbParam.mb_width * pEnc->mbParam.mb_height *  
                                    INTRA_THRESHOLD);  
1737          else          else
1738                  iLimit = pEnc->mbParam.mb_width * pEnc->mbParam.mb_height + 1;                  iLimit = mb_width * mb_height + 1;
1739    
1740          if ((pEnc->current->global_flags & XVID_HALFPEL)) {          if ((pEnc->current->global_flags & XVID_HALFPEL)) {
1741                  start_timer();                  start_timer();
# Line 1640  Line 1747 
1747                  stop_inter_timer();                  stop_inter_timer();
1748          }          }
1749    
         if (pEnc->current->global_flags & XVID_GMC) {  
 //              printf("Global Motion = %d %d quarterpel=%d\n", pEnc->current->GMC_MV.x, pEnc->current->GMC_MV.y,pEnc->current->quarterpel);  
                 DPRINTF(DPRINTF_HEADER, "Global Motion = %d %d quarterpel=%d\n", pEnc->current->GMC_MV.x, pEnc->current->GMC_MV.y,pEnc->current->quarterpel);  
                 pEnc->current->coding_type = S_VOP;  
         } else  
1750                  pEnc->current->coding_type = P_VOP;                  pEnc->current->coding_type = P_VOP;
1751    
1752          start_timer();          start_timer();
1753          if (pEnc->current->global_flags & XVID_HINTEDME_SET) {          if (pEnc->current->global_flags & XVID_HINTEDME_SET)
1754                  HintedMESet(pEnc, &bIntra);                  HintedMESet(pEnc, &bIntra);
1755          if (bIntra == 0) {          else
                         pEnc->current->fcode = FindFcode(&pEnc->mbParam, pEnc->current);  
                         MotionEstimationHinted(&pEnc->mbParam, pEnc->current, pEnc->reference,  
                                                                                         &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV);  
                 }  
   
         } else {  
   
1756                  bIntra =                  bIntra =
1757                          MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,                          MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference,
1758                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,                           &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV,
1759                           iLimit);                           iLimit);
1760          }  
1761          stop_motion_timer();          stop_motion_timer();
1762    
1763          if (bIntra == 1) return FrameCodeI(pEnc, bs, pBits);          if (bIntra == 1) return FrameCodeI(pEnc, bs, pBits);
1764    
1765          if ( (pEnc->current->GMC_MV.x == 0) && (pEnc->current->GMC_MV.y == 0) )          if ( ( pEnc->current->global_flags & XVID_GMC )
1766                          pEnc->current->coding_type = P_VOP;             /* no global motion -> no GMC */                  && ( (pEnc->current->warp.duv[1].x != 0) || (pEnc->current->warp.duv[1].y != 0) ) )
1767            {
1768                    pEnc->current->coding_type = S_VOP;
1769    
1770          if (vol_header)                  generate_GMCparameters( 2, 16, &pEnc->current->warp,
1771                  BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);                                          pEnc->mbParam.width, pEnc->mbParam.height,
1772                                            &pEnc->current->gmc_data);
1773    
1774                    generate_GMCimage(&pEnc->current->gmc_data, &pEnc->reference->image,
1775                                    pEnc->mbParam.mb_width, pEnc->mbParam.mb_height,
1776                                    pEnc->mbParam.edged_width, pEnc->mbParam.edged_width/2,
1777                                    pEnc->mbParam.m_fcode, pEnc->mbParam.m_quarterpel, 0,
1778                                    pEnc->current->rounding_type, pEnc->current->mbs, &pEnc->vGMC);
1779    
1780            }
1781    
1782          set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);          set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase);
1783            if (vol_header)
1784            {       BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current);
1785                    BitstreamPadAlways(bs);
1786            }
1787    
1788          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1);
1789    
1790          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
1791    
1792          pEnc->sStat.iTextBits = pEnc->sStat.iMvSum = pEnc->sStat.iMvCount =          pEnc->current->sStat.iTextBits = pEnc->current->sStat.iMvSum = pEnc->current->sStat.iMvCount =
1793                  pEnc->sStat.kblks = pEnc->sStat.mblks = pEnc->sStat.ublks = 0;                  pEnc->current->sStat.kblks = pEnc->current->sStat.mblks = pEnc->current->sStat.ublks = 0;
1794    
1795          for (y = 0; y < pEnc->mbParam.mb_height; y++) {  
1796                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {          for (y = 0; y < mb_height; y++) {
1797                    for (x = 0; x < mb_width; x++) {
1798                          MACROBLOCK *pMB =                          MACROBLOCK *pMB =
1799                                  &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];                                  &pEnc->current->mbs[x + y * pEnc->mbParam.mb_width];
1800    
1801    /* Mode decision: Check, if the block should be INTRA / INTER or GMC-coded */
1802    /* For a start, leave INTRA decision as is, only choose only between INTER/GMC  - gruel, 9.1.2002 */
1803    
1804                          bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q);                          bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q);
1805    
1806                          if (!bIntra) {                          if (bIntra) {
1807                                    CodeIntraMB(pEnc, pMB);
1808                                    MBTransQuantIntra(&pEnc->mbParam, pEnc->current, pMB, x, y,
1809                                                                      dct_codes, qcoeff);
1810    
1811                                    start_timer();
1812                                    MBPrediction(pEnc->current, x, y, pEnc->mbParam.mb_width, qcoeff);
1813                                    stop_prediction_timer();
1814    
1815                                    pEnc->current->sStat.kblks++;
1816    
1817                                    MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);
1818                                    stop_coding_timer();
1819                                    continue;
1820                            }
1821    
1822                            if (pEnc->current->coding_type == S_VOP) {
1823    
1824                                    int32_t iSAD = sad16(pEnc->current->image.y + 16*y*pEnc->mbParam.edged_width + 16*x,
1825                                            pEnc->vGMC.y + 16*y*pEnc->mbParam.edged_width + 16*x,
1826                                            pEnc->mbParam.edged_width, 65536);
1827    
1828                                    if (pEnc->current->motion_flags & PMV_CHROMA16) {
1829                                            iSAD += sad8(pEnc->current->image.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x,
1830                                            pEnc->vGMC.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x, pEnc->mbParam.edged_width/2);
1831    
1832                                            iSAD += sad8(pEnc->current->image.v + 8*y*(pEnc->mbParam.edged_width/2) + 8*x,
1833                                            pEnc->vGMC.v + 8*y*(pEnc->mbParam.edged_width/2) + 8*x, pEnc->mbParam.edged_width/2);
1834                                    }
1835    
1836                                    if (iSAD <= pMB->sad16) {               /* mode decision GMC */
1837    
1838                                            if (pEnc->mbParam.m_quarterpel)
1839                                                    pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv;
1840                                            else
1841                                                    pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
1842    
1843                                            pMB->mode = MODE_INTER;
1844                                            pMB->mcsel = 1;
1845                                            pMB->sad16 = iSAD;
1846                                    } else {
1847                                            pMB->mcsel = 0;
1848                                    }
1849                            } else {
1850                                    pMB->mcsel = 0; /* just a precaution */
1851                            }
1852    
1853                                  start_timer();                                  start_timer();
1854                                  MBMotionCompensation(pMB, x, y, &pEnc->reference->image,                                  MBMotionCompensation(pMB, x, y, &pEnc->reference->image,
1855                                                                           &pEnc->vInterH, &pEnc->vInterV,                                                                           &pEnc->vInterH, &pEnc->vInterV,
1856                                                                           &pEnc->vInterHV, &pEnc->current->image,                                                                   &pEnc->vInterHV, &pEnc->vGMC,
1857                                                                     &pEnc->current->image,
1858                                                                           dct_codes, pEnc->mbParam.width,                                                                           dct_codes, pEnc->mbParam.width,
1859                                                                           pEnc->mbParam.height,                                                                           pEnc->mbParam.height,
1860                                                                           pEnc->mbParam.edged_width,                                                                           pEnc->mbParam.edged_width,
1861                                                                           pEnc->mbParam.m_quarterpel,                                                                           pEnc->mbParam.m_quarterpel,
1862                                                                     (pEnc->current->global_flags & XVID_REDUCED),
1863                                                                           pEnc->current->rounding_type);                                                                           pEnc->current->rounding_type);
1864    
1865                                  stop_comp_timer();                                  stop_comp_timer();
1866    
1867                                  if ((pEnc->current->global_flags & XVID_LUMIMASKING)) {                                  if ((pEnc->current->global_flags & XVID_LUMIMASKING)) {
# Line 1717  Line 1879 
1879                                  pMB->field_pred = 0;                                  pMB->field_pred = 0;
1880    
1881                                  if (pMB->mode != MODE_NOT_CODED)                                  if (pMB->mode != MODE_NOT_CODED)
1882                                          pMB->cbp =                          {       pMB->cbp =
1883                                                  MBTransQuantInter(&pEnc->mbParam, pEnc->current, pMB, x, y,                                                  MBTransQuantInter(&pEnc->mbParam, pEnc->current, pMB, x, y,
1884                                                                                    dct_codes, qcoeff);                                                                                    dct_codes, qcoeff);
                         } else {  
                                 CodeIntraMB(pEnc, pMB);  
                                 MBTransQuantIntra(&pEnc->mbParam, pEnc->current, pMB, x, y,  
                                                                   dct_codes, qcoeff);  
1885                          }                          }
1886    
1887                          start_timer();                          if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y ||
                         MBPrediction(pEnc->current, x, y, pEnc->mbParam.mb_width, qcoeff);  
                         stop_prediction_timer();  
   
                         if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) {  
                                 pEnc->sStat.kblks++;  
                         } else if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y ||  
1888                                             pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x ||                                             pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x ||
1889                                             pMB->mvs[2].y || pMB->mvs[3].x || pMB->mvs[3].y) {                                             pMB->mvs[2].y || pMB->mvs[3].x || pMB->mvs[3].y) {
1890                                  pEnc->sStat.mblks++;                                  pEnc->current->sStat.mblks++;
1891                          }  else {                          }  else {
1892                                  pEnc->sStat.ublks++;                                  pEnc->current->sStat.ublks++;
1893                          }                          }
1894    
1895                          start_timer();                          start_timer();
1896    
1897                          /* Finished processing the MB, now check if to CODE or SKIP */                          /* Finished processing the MB, now check if to CODE or SKIP */
1898    
1899                          skip_possible = (pMB->cbp == 0) & (pMB->mode == MODE_INTER) &                          skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER) &&
1900                                                          (pMB->dquant == NO_CHANGE);                                                          (pMB->dquant == NO_CHANGE);
1901    
1902                            if (pEnc->current->coding_type == S_VOP)
1903                                    skip_possible &= (pMB->mcsel == 1);
1904                            else if (pEnc->current->coding_type == P_VOP) {
1905                          if(pEnc->mbParam.m_quarterpel)                          if(pEnc->mbParam.m_quarterpel)
1906                          {       skip_possible &= (pMB->qmvs[0].x == pEnc->current->GMC_MV.x) & (pMB->qmvs[0].y == pEnc->current->GMC_MV.y);                                          skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) );
                         }  
1907                          else                          else
1908                          {       skip_possible &= (pMB->mvs[0].x == pEnc->current->GMC_MV.x) & (pMB->mvs[0].y == pEnc->current->GMC_MV.y);                                          skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) );
1909                          }                          }
1910    
1911                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {
1912    
1913  /* This is a candidate for SKIPping, but for P-VOPs check intermediate B-frames first */  /* This is a candidate for SKIPping, but for P-VOPs check intermediate B-frames first */
                                 int bSkip = 1;  
1914    
1915                                  if (pEnc->current->coding_type == P_VOP)        /* special rule for P-VOP's SKIP */                                  if (pEnc->current->coding_type == P_VOP)        /* special rule for P-VOP's SKIP */
1916                                    {
1917                                            int bSkip = 1;
1918    
1919                                          for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++)                                          for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++)
1920                                          {                                          {
1921                                                  int iSAD;                                                  int iSAD;
# Line 1772  Line 1928 
1928                                                  }                                                  }
1929                                          }                                          }
1930    
1931                                  if (!bSkip)                                          if (!bSkip) {   /* no SKIP, but trivial block */
                                 {  
                                         VECTOR predMV;  
1932                                          if(pEnc->mbParam.m_quarterpel) {                                          if(pEnc->mbParam.m_quarterpel) {
1933                                                  predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);                                                          VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);
1934                                                  pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x;  /* with GMC, qmvs doesn't have to be (0,0)! */                                                          pMB->pmvs[0].x = - predMV.x;
1935                                                  pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y;                                                          pMB->pmvs[0].y = - predMV.y;
1936                                          }                                          }
1937                                          else {                                          else {
1938                                                  predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);                                                          VECTOR predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);
1939                                                  pMB->pmvs[0].x = pMB->mvs[0].x - predMV.x; /* with GMC, mvs doesn't have to be (0,0)! */                                                          pMB->pmvs[0].x = - predMV.x;
1940                                                  pMB->pmvs[0].y = pMB->mvs[0].y - predMV.y;                                                          pMB->pmvs[0].y = - predMV.y;
1941                                          }                                          }
1942                                          pMB->mode = MODE_INTER;                                          pMB->mode = MODE_INTER;
1943                                          pMB->cbp = 0;                                          pMB->cbp = 0;
1944                                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);                                                  MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);
1945                                                    stop_coding_timer();
1946    
1947                                                    continue;       /* next MB */
1948                                  }                                  }
1949                                  else                                  }
1950                                  {                                  /* do SKIP */
1951    
1952                                          pMB->mode = MODE_NOT_CODED;                                          pMB->mode = MODE_NOT_CODED;
1953                                          MBSkip(bs);                                          MBSkip(bs);
1954                                    stop_coding_timer();
1955                                    continue;       /* next MB */
1956                                  }                                  }
1957                            /* ordinary case: normal coded INTER/INTER4V block */
1958    
                         } else {  
1959                                  if (pEnc->current->global_flags & XVID_GREYSCALE)                                  if (pEnc->current->global_flags & XVID_GREYSCALE)
1960                                  {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */                                  {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */
1961                                          qcoeff[4*64+0]=0;               /* zero, because DC for INTRA MBs DC value is saved */                                          qcoeff[4*64+0]=0;               /* zero, because DC for INTRA MBs DC value is saved */
1962                                          qcoeff[5*64+0]=0;                                          qcoeff[5*64+0]=0;
1963                                  }                                  }
1964                                  MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat);  
1965                            if(pEnc->mbParam.m_quarterpel) {
1966                                    VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);
1967                                    pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x;
1968                                    pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y;
1969                                    DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", pMB->pmvs[0].x, pMB->pmvs[0].y, predMV.x, predMV.y, pMB->mvs[0].x, pMB->mvs[0].y);
1970                            } else {
1971                                    VECTOR predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0);
1972                                    pMB->pmvs[0].x = pMB->mvs[0].x - predMV.x;
1973                                    pMB->pmvs[0].y = pMB->mvs[0].y - predMV.y;
1974                                    DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", pMB->pmvs[0].x, pMB->pmvs[0].y, predMV.x, predMV.y, pMB->mvs[0].x, pMB->mvs[0].y);
1975                          }                          }
1976    
1977    
1978                            if (pMB->mode == MODE_INTER4V)
1979                            {       int k;
1980                                    for (k=1;k<4;k++)
1981                                    {
1982                                            if(pEnc->mbParam.m_quarterpel) {
1983                                                    VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, k);
1984                                                    pMB->pmvs[k].x = pMB->qmvs[k].x - predMV.x;
1985                                                    pMB->pmvs[k].y = pMB->qmvs[k].y - predMV.y;
1986                                    DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", pMB->pmvs[k].x, pMB->pmvs[k].y, predMV.x, predMV.y, pMB->mvs[k].x, pMB->mvs[k].y);
1987                                            } else {
1988                                                    VECTOR predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, k);
1989                                                    pMB->pmvs[k].x = pMB->mvs[k].x - predMV.x;
1990                                                    pMB->pmvs[k].y = pMB->mvs[k].y - predMV.y;
1991                                    DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", pMB->pmvs[k].x, pMB->pmvs[k].y, predMV.x, predMV.y, pMB->mvs[k].x, pMB->mvs[k].y);
1992                                            }
1993    
1994                                    }
1995                            }
1996    
1997                            MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);
1998                          stop_coding_timer();                          stop_coding_timer();
1999    
2000                    }
2001                  }                  }
2002    
2003            if ((pEnc->current->global_flags & XVID_REDUCED))
2004            {
2005                    image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width,
2006                            pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width,
2007                            16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV);
2008          }          }
2009    
2010          emms();          emms();
# Line 1814  Line 2013 
2013                  HintedMEGet(pEnc, 0);                  HintedMEGet(pEnc, 0);
2014          }          }
2015    
2016          if (pEnc->sStat.iMvCount == 0)          if (pEnc->current->sStat.iMvCount == 0)
2017                  pEnc->sStat.iMvCount = 1;                  pEnc->current->sStat.iMvCount = 1;
2018    
2019          fSigma = (float) sqrt((float) pEnc->sStat.iMvSum / pEnc->sStat.iMvCount);          fSigma = (float) sqrt((float) pEnc->current->sStat.iMvSum / pEnc->current->sStat.iMvCount);
2020    
2021          iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode);          iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode);
2022    
# Line 1827  Line 2026 
2026                  pEnc->mbParam.m_fcode++;                  pEnc->mbParam.m_fcode++;
2027                  iSearchRange *= 2;                  iSearchRange *= 2;
2028          } else if ((fSigma < iSearchRange / 6)          } else if ((fSigma < iSearchRange / 6)
2029                             && (pEnc->sStat.fMvPrevSigma >= 0)                             && (pEnc->fMvPrevSigma >= 0)
2030                             && (pEnc->sStat.fMvPrevSigma < iSearchRange / 6)                             && (pEnc->fMvPrevSigma < iSearchRange / 6)
2031                          && (pEnc->mbParam.m_fcode >= (2 + pEnc->mbParam.m_quarterpel))) // minimum search range 16                          && (pEnc->mbParam.m_fcode >= (2 + pEnc->mbParam.m_quarterpel))) // minimum search range 16
2032          {          {
2033                  pEnc->mbParam.m_fcode--;                  pEnc->mbParam.m_fcode--;
2034                  iSearchRange /= 2;                  iSearchRange /= 2;
2035          }          }
2036    
2037          pEnc->sStat.fMvPrevSigma = fSigma;          pEnc->fMvPrevSigma = fSigma;
2038    
 #ifdef FRAMEDROP  
2039          /* frame drop code */          /* frame drop code */
2040          // DPRINTF(DPRINTF_DEBUG, "kmu %i %i %i", pEnc->sStat.kblks, pEnc->sStat.mblks, pEnc->sStat.ublks);          DPRINTF(DPRINTF_DEBUG, "kmu %i %i %i", pEnc->current->sStat.kblks, pEnc->current->sStat.mblks, pEnc->current->sStat.ublks);
2041          if (pEnc->sStat.kblks + pEnc->sStat.mblks <          if (pEnc->current->sStat.kblks + pEnc->current->sStat.mblks <
2042                  (pEnc->frame_drop_ratio * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height) / 100)                  (pEnc->mbParam.frame_drop_ratio * mb_width * mb_height) / 100)
2043          {          {
2044                  pEnc->sStat.kblks = pEnc->sStat.mblks = 0;                  pEnc->current->sStat.kblks = pEnc->current->sStat.mblks = 0;
2045                  pEnc->sStat.ublks = pEnc->mbParam.mb_width * pEnc->mbParam.mb_height;                  pEnc->current->sStat.ublks = mb_width * mb_height;
2046    
2047                  BitstreamReset(bs);                  BitstreamReset(bs);
2048    
# Line 1859  Line 2057 
2057                  pEnc->current->fcode = pEnc->reference->fcode;                  pEnc->current->fcode = pEnc->reference->fcode;
2058                  pEnc->current->bcode = pEnc->reference->bcode;                  pEnc->current->bcode = pEnc->reference->bcode;
2059                  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);
2060                  memcpy(pEnc->current->mbs, pEnc->reference->mbs, sizeof(MACROBLOCK) * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height);                  memcpy(pEnc->current->mbs, pEnc->reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height);
2061            }
2062    
2063            /* XXX: debug
2064            {
2065                    char s[100];
2066                    sprintf(s, "\\%05i_cur.pgm", pEnc->m_framenum);
2067                    image_dump_yuvpgm(&pEnc->current->image,
2068                            pEnc->mbParam.edged_width,
2069                            pEnc->mbParam.width, pEnc->mbParam.height, s);
2070    
2071                    sprintf(s, "\\%05i_ref.pgm", pEnc->m_framenum);
2072                    image_dump_yuvpgm(&pEnc->reference->image,
2073                            pEnc->mbParam.edged_width,
2074                            pEnc->mbParam.width, pEnc->mbParam.height, s);
2075          }          }
2076  #endif          */
2077    
2078    
2079          *pBits = BitstreamPos(bs) - *pBits;          *pBits = BitstreamPos(bs) - *pBits;
2080    
# Line 1870  Line 2082 
2082  }  }
2083    
2084    
2085  static __inline void  static void
2086  FrameCodeB(Encoder * pEnc,  FrameCodeB(Encoder * pEnc,
2087                     FRAMEINFO * frame,                     FRAMEINFO * frame,
2088                     Bitstream * bs,                     Bitstream * bs,
2089                     uint32_t * pBits)                     uint32_t * pBits)
2090  {  {
2091          int16_t dct_codes[6 * 64];          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);
2092          int16_t qcoeff[6 * 64];          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
2093          uint32_t x, y;          uint32_t x, y;
2094    
2095          IMAGE *f_ref = &pEnc->reference->image;          IMAGE *f_ref = &pEnc->reference->image;
# Line 1890  Line 2102 
2102                  fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mode,mb->cbp); \                  fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mode,mb->cbp); \
2103          }          }
2104    
2105            pEnc->current->global_flags &= ~XVID_REDUCED;   /* reduced resoltion not yet supported */
2106    
2107          if (!first){          if (!first){
2108                  fp=fopen("C:\\XVIDDBGE.TXT","w");                  fp=fopen("C:\\XVIDDBGE.TXT","w");
2109          }          }
# Line 1942  Line 2156 
2156    
2157          *pBits = BitstreamPos(bs);          *pBits = BitstreamPos(bs);
2158    
2159          pEnc->sStat.iTextBits = 0;          frame->sStat.iTextBits = 0;
2160          pEnc->sStat.iMvSum = 0;          frame->sStat.iMvSum = 0;
2161          pEnc->sStat.iMvCount = 0;          frame->sStat.iMvCount = 0;
2162          pEnc->sStat.kblks = pEnc->sStat.mblks = pEnc->sStat.ublks = 0;          frame->sStat.kblks = frame->sStat.mblks = frame->sStat.ublks = 0;
2163    
2164    
2165          for (y = 0; y < pEnc->mbParam.mb_height; y++) {          for (y = 0; y < pEnc->mbParam.mb_height; y++) {
2166                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {                  for (x = 0; x < pEnc->mbParam.mb_width; x++) {
2167                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];                          MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width];
2168                          int direction = pEnc->global & XVID_ALTERNATESCAN ? 2 : 0;                          int direction = pEnc->mbParam.global & XVID_ALTERNATESCAN ? 2 : 0;
2169    
2170                          // decoder ignores mb when refence block is INTER(0,0), CBP=0                          // decoder ignores mb when refence block is INTER(0,0), CBP=0
2171                          if (mb->mode == MODE_NOT_CODED) {                          if (mb->mode == MODE_NOT_CODED) {
# Line 1983  Line 2197 
2197  #endif  #endif
2198                          start_timer();                          start_timer();
2199                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,                          MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs,
2200                                                   &pEnc->sStat, direction);                                                   &frame->sStat, direction);
2201                          stop_coding_timer();                          stop_coding_timer();
2202                  }                  }
2203          }          }
# Line 2002  Line 2216 
2216          }          }
2217  #endif  #endif
2218  }  }
   
   
 /*      in case internal output is needed somewhere... */  
 /*      {  
         FILE *filehandle;  
         filehandle=fopen("last-b.pgm","wb");  
         if (filehandle)  
         {  
                 fprintf(filehandle,"P5\n\n");           //  
                 fprintf(filehandle,"%d %d 255\n",pEnc->mbParam.edged_width,pEnc->mbParam.edged_height);  
                 fwrite(frame->image.y,pEnc->mbParam.edged_width,pEnc->mbParam.edged_height,filehandle);  
                 fclose(filehandle);  
                 }  
         }  
 */  

Legend:
Removed from v.1.76.2.22  
changed lines
  Added in v.1.91

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