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

Diff of /xvidcore/src/decoder.c

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

revision 1.37.2.26, Sat Jan 4 06:14:32 2003 UTC revision 1.37.2.29, Sat Jan 11 21:22:24 2003 UTC
# Line 59  Line 59 
59   *   *
60   *************************************************************************/   *************************************************************************/
61    
62    #include <stdio.h>
63  #include <stdlib.h>  #include <stdlib.h>
64  #include <string.h>  #include <string.h>
65    
# Line 104  Line 105 
105          image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);          image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
106          image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);          image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
107    
108            image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);
109    
110          if (dec->last_mbs)          if (dec->last_mbs)
111                  xvid_free(dec->last_mbs);                  xvid_free(dec->last_mbs);
112          if (dec->mbs)          if (dec->mbs)
# Line 153  Line 156 
156                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
157          }          }
158    
159            if (image_create(&dec->gmc, dec->edged_width, dec->edged_height)) {
160                    image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height);
161                    image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
162                    image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
163                    image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
164                    image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
165                    xvid_free(dec);
166                    return XVID_ERR_MEMORY;
167            }
168    
169          dec->mbs =          dec->mbs =
170                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,                  xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height,
171                                          CACHE_LINE);                                          CACHE_LINE);
# Line 211  Line 224 
224          image_null(&dec->tmp);          image_null(&dec->tmp);
225          image_null(&dec->qtmp);          image_null(&dec->qtmp);
226    
227    /* image based GMC */
228            image_null(&dec->gmc);
229    
230    
231          dec->mbs = NULL;          dec->mbs = NULL;
232          dec->last_mbs = NULL;          dec->last_mbs = NULL;
233    
# Line 237  Line 254 
254  {  {
255          xvid_free(dec->last_mbs);          xvid_free(dec->last_mbs);
256          xvid_free(dec->mbs);          xvid_free(dec->mbs);
257    
258            image_destroy(&dec->gmc, dec->edged_width, dec->edged_height);          /* image based GMC */
259    
260          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height);
261          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);          image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height);
262          image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);          image_destroy(&dec->tmp, dec->edged_width, dec->edged_height);
# Line 392  Line 412 
412                                  const MACROBLOCK * pMB,                                  const MACROBLOCK * pMB,
413                                  const uint32_t x_pos,                                  const uint32_t x_pos,
414                                  const uint32_t y_pos,                                  const uint32_t y_pos,
415                                  const uint32_t acpred_flag,                                  const uint32_t fcode,
416                                  const uint32_t cbp,                                  const uint32_t cbp,
417                                  Bitstream * bs,                                  Bitstream * bs,
418                                  const uint32_t quant,                                  const uint32_t quant,
# Line 430  Line 450 
450          }          }
451    
452          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
                 uv_dx = mv[0].x;  
                 uv_dy = mv[0].y;  
453    
454                  if (dec->quarterpel)                  uv_dx = mv[0].x / (1 + dec->quarterpel);
455                  {                  uv_dy = mv[0].y / (1 + dec->quarterpel);
                         uv_dx /= 2;  
                         uv_dy /= 2;  
                 }  
456    
457                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];                  uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
458                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];                  uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
# Line 606  Line 621 
621          stop_transfer_timer();          stop_transfer_timer();
622  }  }
623    
624    static __inline int gmc_sanitize(int value, int quarterpel, int fcode)
625    {
626            int length = 1 << (fcode+4);
627    
628            if (quarterpel) value *= 2;
629    
630            if (value < -length)
631                    return -length;
632            else if (value >= length)
633                    return length-1;
634            else return value;
635    }
636    
637    
638    static void
639    decoder_mbgmc(DECODER * dec,
640                                    MACROBLOCK * const pMB,
641                                    const uint32_t x_pos,
642                                    const uint32_t y_pos,
643                                    const uint32_t fcode,
644                                    const uint32_t cbp,
645                                    Bitstream * bs,
646                                    const uint32_t quant,
647                                    const uint32_t rounding,
648                                    const int reduced_resolution)   /* no reduced res support */
649    {
650    
651            DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
652            DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
653    
654            const uint32_t stride = dec->edged_width;
655            const uint32_t stride2 = stride / 2;
656            const uint32_t next_block = stride * (reduced_resolution ? 16 : 8);
657            uint32_t i;
658            const uint32_t iQuant = pMB->quant;
659            uint8_t *const pY_Cur=dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
660            uint8_t *const pU_Cur=dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
661            uint8_t *const pV_Cur=dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
662    
663            pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
664    
665            start_timer();
666    
667    /* this is where the calculations are done */
668    
669            {
670                    pMB->amv = generate_GMCimageMB(&dec->gmc_data, &dec->refn[0], x_pos, y_pos,
671                                            stride, stride2, dec->quarterpel, rounding, &dec->cur);
672    
673                    pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode);
674                    pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode);
675            }
676            pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
677    
678    
679    /*      transfer16x16_copy(pY_Cur, dec->gmc.y + (y_pos << 4)*stride + (x_pos  << 4), stride);
680            transfer8x8_copy(pU_Cur, dec->gmc.u + (y_pos << 3)*stride2 + (x_pos  << 3), stride2);
681            transfer8x8_copy(pV_Cur, dec->gmc.v + (y_pos << 3)*stride2 + (x_pos << 3), stride2);
682    */
683    
684    
685            stop_transfer_timer();
686    
687            if (!cbp) return;
688    
689            for (i = 0; i < 6; i++) {
690                    int direction = dec->alternate_vertical_scan ? 2 : 0;
691    
692                    if (cbp & (1 << (5 - i)))       // coded
693                    {
694                            memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
695    
696                            start_timer();
697                            get_inter_block(bs, &block[i * 64], direction);
698                            stop_coding_timer();
699    
700                            start_timer();
701                            if (dec->quant_type == 0) {
702                                    dequant_inter(&data[i * 64], &block[i * 64], iQuant);
703                            } else {
704                                    dequant4_inter(&data[i * 64], &block[i * 64], iQuant);
705                            }
706                            stop_iquant_timer();
707    
708                            start_timer();
709                            idct(&data[i * 64]);
710                            stop_idct_timer();
711                    }
712            }
713    
714    /* interlace + GMC is this possible ??? */
715    /*      if (dec->interlacing && pMB->field_dct) {
716                    next_block = stride;
717                    stride *= 2;
718            }
719    */
720            start_timer();
721            if (cbp & 32)
722                    transfer_16to8add(pY_Cur, &data[0 * 64], stride);
723            if (cbp & 16)
724                    transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
725            if (cbp & 8)
726                    transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
727            if (cbp & 4)
728                    transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);
729            if (cbp & 2)
730                    transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
731            if (cbp & 1)
732                    transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
733            stop_transfer_timer();
734    }
735    
736    
737  void  void
738  decoder_iframe(DECODER * dec,  decoder_iframe(DECODER * dec,
# Line 713  Line 840 
840          mv.x = get_mv(bs, fcode);          mv.x = get_mv(bs, fcode);
841          mv.y = get_mv(bs, fcode);          mv.y = get_mv(bs, fcode);
842    
843          DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv.x, mv.y, pmv.x, pmv.y);          DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", mv.x, mv.y, pmv.x, pmv.y, mv.x+pmv.x, mv.y+pmv.y);
844    
845          mv.x += pmv.x;          mv.x += pmv.x;
846          mv.y += pmv.y;          mv.y += pmv.y;
# Line 736  Line 863 
863    
864    
865    
 static __inline int gmc_sanitize(int value, int quarterpel, int fcode)  
 {  
         int length = 1 << (fcode+4);  
   
         if (quarterpel) value *= 2;  
   
         if (value < -length)  
                 return -length;  
         else if (value >= length)  
                 return length-1;  
         else return value;  
 }  
866    
867    
868  /* for P_VOP set gmc_mv to NULL */  /* for P_VOP set gmc_warp to NULL */
869  void  void
870  decoder_pframe(DECODER * dec,  decoder_pframe(DECODER * dec,
871                             Bitstream * bs,                             Bitstream * bs,
# Line 759  Line 874 
874                             int quant,                             int quant,
875                             int fcode,                             int fcode,
876                             int intra_dc_threshold,                             int intra_dc_threshold,
877                             VECTOR * gmc_mv)                             const WARPPOINTS *const gmc_warp)
878  {  {
879    
880          uint32_t x, y;          uint32_t x, y;
# Line 779  Line 894 
894                                     dec->width, dec->height);                                     dec->width, dec->height);
895          stop_edges_timer();          stop_edges_timer();
896    
897            if (gmc_warp)
898            {
899    
900                    // accuracy:  0==1/2, 1=1/4, 2=1/8, 3=1/16
901                    if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) )
902                    {
903                            fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n",
904                                    dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy),
905                                    dec->sprite_warping_points);
906                    }
907    
908                    generate_GMCparameters( dec->sprite_warping_points,
909                                    (2 << dec->sprite_warping_accuracy), gmc_warp,
910                                    dec->width, dec->height, &dec->gmc_data);
911    
912    /* image warping is done block-based  in decoder_mbgmc(), now */
913    /*
914            generate_GMCimage(&dec->gmc_data, &dec->refn[0],
915                                            mb_width, mb_height,
916                                            dec->edged_width, dec->edged_width/2,
917                                            fcode, dec->quarterpel, 0,
918                                            rounding, dec->mbs, &dec->gmc);
919    */
920            }
921    
922          bound = 0;          bound = 0;
923    
924          for (y = 0; y < mb_height; y++) {          for (y = 0; y < mb_height; y++) {
# Line 802  Line 942 
942                          DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32));                          DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32));
943    
944                          //if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs)))         // not_coded                          //if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs)))         // not_coded
945                          if (!(BitstreamGetBit(bs)))     // not_coded                          if (!(BitstreamGetBit(bs)))     // block _is_ coded
946                          {                          {
947                                  uint32_t mcbpc;                                  uint32_t mcbpc;
948                                  uint32_t cbpc;                                  uint32_t cbpc;
# Line 827  Line 967 
967                                          acpred_flag = BitstreamGetBit(bs);                                          acpred_flag = BitstreamGetBit(bs);
968                                  }                                  }
969    
970                                  if (gmc_mv && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))                                  if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))
971                                  {                                  {
972                                          mcsel = BitstreamGetBit(bs);                                          mcsel = BitstreamGetBit(bs);
973                                  }                                  }
974    
975                                  cbpy = get_cbpy(bs, intra);                                  cbpy = get_cbpy(bs, intra);
976                                  DPRINTF(DPRINTF_MB, "cbpy %i", cbpy);                                  DPRINTF(DPRINTF_MB, "cbpy %i  mcsel %i ", cbpy,mcsel);
977    
978                                  cbp = (cbpy << 2) | cbpc;                                  cbp = (cbpy << 2) | cbpc;
979    
# Line 869  Line 1009 
1009                                          }                                          }
1010                                  }                                  }
1011    
1012                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                  if (mcsel) {
1013                                            decoder_mbgmc(dec, mb, x, y, fcode, cbp, bs, quant,
1014                                                                    rounding, reduced_resolution);
1015                                            continue;
1016    
1017                                          if (mcsel)                                  } else if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
                                         {  
                                                 mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = gmc_sanitize(gmc_mv[0].x, dec->quarterpel, fcode);  
                                                 mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = gmc_sanitize(gmc_mv[0].y, dec->quarterpel, fcode);  
1018    
1019                                          } else if (dec->interlacing && mb->field_pred) {                                          if (dec->interlacing && mb->field_pred) {
1020                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],
1021                                                                                    fcode, bound);                                                                                    fcode, bound);
1022                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],
# Line 884  Line 1024 
1024                                          } else {                                          } else {
1025                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],
1026                                                                                    fcode, bound);                                                                                    fcode, bound);
1027                                                  mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x =                                                  mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0];
                                                         mb->mvs[0].x;  
                                                 mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y =  
                                                         mb->mvs[0].y;  
1028                                          }                                          }
1029                                  } else if (mb->mode == MODE_INTER4V ) {                                  } else if (mb->mode == MODE_INTER4V ) {
1030    
# Line 906  Line 1043 
1043                                          continue;                                          continue;
1044                                  }                                  }
1045    
1046                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                  decoder_mbinter(dec, mb, x, y, fcode, cbp, bs, quant,
1047                                                                  rounding, reduced_resolution);                                                                  rounding, reduced_resolution);
1048    
1049                          }                          }
1050                          else if (gmc_mv)        /* not coded S_VOP macroblock */                          else if (gmc_warp)      /* a not coded S(GMC)-VOP macroblock */
1051                          {                          {
1052                                  mb->mode = MODE_NOT_CODED_GMC;                                  mb->mode = MODE_NOT_CODED_GMC;
1053                                  mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = gmc_sanitize(gmc_mv[0].x, dec->quarterpel, fcode);  
1054                                  mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = gmc_sanitize(gmc_mv[0].y, dec->quarterpel, fcode);                                  start_timer();
1055                                  decoder_mbinter(dec, mb, x, y, 0, 0, bs, quant, rounding, reduced_resolution);  
1056                                    decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, quant,
1057                                                                    rounding, reduced_resolution);
1058    
1059                                    stop_transfer_timer();
1060    
1061                                    if(dec->out_frm && cp_mb > 0) {
1062                                      output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb);
1063                                      cp_mb = 0;
1064                                    }
1065                                    st_mb = x+1;
1066                          }                          }
1067                          else    /* not coded P_VOP macroblock */                          else    /* not coded P_VOP macroblock */
1068                          {                          {
# Line 1465  Line 1612 
1612                          mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv;                          mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv;
1613    
1614                          // skip if the co-located P_VOP macroblock is not coded                          // skip if the co-located P_VOP macroblock is not coded
1615                          // note: gmc+not_coded isn't skipped                          // if not codec in co-located S_VOP macroblock is _not_ automatically skipped
1616    
1617                          if (last_mb->mode == MODE_NOT_CODED) {                          if (last_mb->mode == MODE_NOT_CODED) {
1618                                  //DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y);                                  //DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y);
# Line 1639  Line 1786 
1786          uint32_t fcode_forward;          uint32_t fcode_forward;
1787          uint32_t fcode_backward;          uint32_t fcode_backward;
1788          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1789          VECTOR gmc_mv[5];          WARPPOINTS gmc_warp;
1790          uint32_t vop_type;          uint32_t vop_type;
1791          int success = 0;          int success = 0;
1792          int output = 0;          int output = 0;
# Line 1694  Line 1841 
1841  repeat:  repeat:
1842    
1843          vop_type =      BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,          vop_type =      BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1844                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);
1845    
1846          DPRINTF(DPRINTF_HEADER, "vop_type=%i,  packed=%i,  time=%i,  time_pp=%i,  time_bp=%i",          DPRINTF(DPRINTF_HEADER, "vop_type=%i,  packed=%i,  time=%lli,  time_pp=%i,  time_bp=%i",
1847                                                          vop_type,       dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);                                                          vop_type,       dec->packed_mode, dec->time, dec->time_pp, dec->time_bp);
1848    
1849          if (vop_type == - 1)          if (vop_type == - 1)
# Line 1755  Line 1902 
1902                          break;                          break;
1903                  case S_VOP :                  case S_VOP :
1904                          decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,                          decoder_pframe(dec, &bs, rounding, reduced_resolution, quant,
1905                                                  fcode_forward, intra_dc_threshold, gmc_mv);                                                  fcode_forward, intra_dc_threshold, &gmc_warp);
1906                          break;                          break;
1907                  case N_VOP :                  case N_VOP :
1908                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);

Legend:
Removed from v.1.37.2.26  
changed lines
  Added in v.1.37.2.29

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