[svn] / branches / dev-api-3 / xvidcore / src / decoder.c Repository:
ViewVC logotype

Diff of /branches/dev-api-3/xvidcore/src/decoder.c

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

revision 769, Sat Jan 11 14:59:24 2003 UTC revision 773, Sat Jan 11 20:37:46 2003 UTC
# Line 55  Line 55 
55   *  22.12.2001  lock based interpolation   *  22.12.2001  lock based interpolation
56   *  01.12.2001  inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>   *  01.12.2001  inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>
57   *   *
58   *  $Id: decoder.c,v 1.37.2.27 2003-01-11 14:59:23 chl Exp $   *  $Id: decoder.c,v 1.37.2.28 2003-01-11 20:37:46 chl Exp $
59   *   *
60   *************************************************************************/   *************************************************************************/
61    
# Line 417  Line 417 
417                                  Bitstream * bs,                                  Bitstream * bs,
418                                  const uint32_t quant,                                  const uint32_t quant,
419                                  const uint32_t rounding,                                  const uint32_t rounding,
420                                  const int reduced_resolution,                                  const int reduced_resolution)
                                 const int mcsel)  
421  {  {
422    
423          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
# Line 430  Line 429 
429          uint32_t i;          uint32_t i;
430          uint32_t iQuant = pMB->quant;          uint32_t iQuant = pMB->quant;
431          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
         uint8_t *pY_Ref, *pU_Ref, *pV_Ref;              /* ref for GMC is _not_ pRef itself */  
432    
433          int uv_dx, uv_dy;          int uv_dx, uv_dy;
434          VECTOR mv[4];   /* local copy of mvs */          VECTOR mv[4];   /* local copy of mvs */
# Line 451  Line 449 
449                          mv[i] = pMB->mvs[i];                          mv[i] = pMB->mvs[i];
450          }          }
451    
         if (mcsel) {  
                 mv[0].x = mv[0].y = mv[1].x = mv[1].y = mv[2].x = mv[2].y = mv[3].x = mv[3].y = 0;  
                         /* position in ref is same as the block, set vector to (0,0) */  
                 pY_Ref = dec->gmc.y;  
                 pU_Ref = dec->gmc.u;  
                 pV_Ref = dec->gmc.v;  
                         /* but reference itself isn't. It's warped... */  
                         /* Btw., this is too slow! For GMC it should simply be transfer_16to8add() */  
         } else {  
                 pY_Ref = dec->refn[0].y;  
                 pU_Ref = dec->refn[0].u;  
                 pV_Ref = dec->refn[0].v;  
         }  
   
452          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {          if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
453    
454                  uv_dx = mv[0].x / (1 + dec->quarterpel);                  uv_dx = mv[0].x / (1 + dec->quarterpel);
# Line 476  Line 460 
460                  start_timer();                  start_timer();
461                  if (reduced_resolution)                  if (reduced_resolution)
462                  {                  {
463                          interpolate32x32_switch(dec->cur.y, pY_Ref , 32*x_pos, 32*y_pos,                          interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
464                                                                    mv[0].x, mv[0].y, stride,  rounding);                                                                    mv[0].x, mv[0].y, stride,  rounding);
465                          interpolate16x16_switch(dec->cur.u, pU_Ref , 16 * x_pos, 16 * y_pos,                          interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos,
466                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
467                          interpolate16x16_switch(dec->cur.v, pV_Ref , 16 * x_pos, 16 * y_pos,                          interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos,
468                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
469    
470                  }                  }
471                  else                  else
472                  {                  {
473                          if(dec->quarterpel) {                          if(dec->quarterpel) {
474                                  interpolate16x16_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64,                                  interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->qtmp.y, dec->qtmp.y + 64,
475                                                                                          dec->qtmp.y + 128, 16*x_pos, 16*y_pos,                                                                                          dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
476                                                                                          mv[0].x, mv[0].y, stride, rounding);                                                                                          mv[0].x, mv[0].y, stride, rounding);
477                          }                          }
478                          else {                          else {
479                                  interpolate16x16_switch(dec->cur.y, pY_Ref , 16*x_pos, 16*y_pos,                                  interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos,
480                                                                            mv[0].x, mv[0].y, stride, rounding);                                                                            mv[0].x, mv[0].y, stride, rounding);
481                          }                          }
482    
483                          interpolate8x8_switch(dec->cur.u, pU_Ref , 8 * x_pos, 8 * y_pos,                          interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos,
484                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
485                          interpolate8x8_switch(dec->cur.v, pV_Ref , 8 * x_pos, 8 * y_pos,                          interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos,
486                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
487                  }                  }
488                  stop_comp_timer();                  stop_comp_timer();
# Line 523  Line 507 
507                  start_timer();                  start_timer();
508                  if (reduced_resolution)                  if (reduced_resolution)
509                  {                  {
510                          interpolate16x16_switch(dec->cur.y, pY_Ref , 32*x_pos, 32*y_pos,                          interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos,
511                                                                    mv[0].x, mv[0].y, stride,  rounding);                                                                    mv[0].x, mv[0].y, stride,  rounding);
512                          interpolate16x16_switch(dec->cur.y, pY_Ref , 32*x_pos + 16, 32*y_pos,                          interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos,
513                                                                    mv[1].x, mv[1].y, stride,  rounding);                                                                    mv[1].x, mv[1].y, stride,  rounding);
514                          interpolate16x16_switch(dec->cur.y, pY_Ref , 32*x_pos, 32*y_pos + 16,                          interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos, 32*y_pos + 16,
515                                                                    mv[2].x, mv[2].y, stride,  rounding);                                                                    mv[2].x, mv[2].y, stride,  rounding);
516                          interpolate16x16_switch(dec->cur.y, pY_Ref , 32*x_pos + 16, 32*y_pos + 16,                          interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos + 16,
517                                                                    mv[3].x, mv[3].y, stride,  rounding);                                                                    mv[3].x, mv[3].y, stride,  rounding);
518                          interpolate16x16_switch(dec->cur.u, pU_Ref , 16 * x_pos, 16 * y_pos,                          interpolate16x16_switch(dec->cur.u, dec->refn[0].u , 16 * x_pos, 16 * y_pos,
519                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
520                          interpolate16x16_switch(dec->cur.v, pV_Ref , 16 * x_pos, 16 * y_pos,                          interpolate16x16_switch(dec->cur.v, dec->refn[0].v , 16 * x_pos, 16 * y_pos,
521                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
522    
523                          // set_block(pY_Cur, stride, 32, 32, 127);                          // set_block(pY_Cur, stride, 32, 32, 127);
# Line 541  Line 525 
525                  else                  else
526                  {                  {
527                          if(dec->quarterpel) {                          if(dec->quarterpel) {
528                                  interpolate8x8_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
529                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos,                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos,
530                                                                                    mv[0].x, mv[0].y, stride,  rounding);                                                                                    mv[0].x, mv[0].y, stride,  rounding);
531                                  interpolate8x8_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
532                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos,                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos,
533                                                                                    mv[1].x, mv[1].y, stride,  rounding);                                                                                    mv[1].x, mv[1].y, stride,  rounding);
534                                  interpolate8x8_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
535                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8,                                                                                    dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8,
536                                                                                    mv[2].x, mv[2].y, stride,  rounding);                                                                                    mv[2].x, mv[2].y, stride,  rounding);
537                                  interpolate8x8_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64,                                  interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64,
538                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,                                                                                    dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8,
539                                                                                    mv[3].x, mv[3].y, stride,  rounding);                                                                                    mv[3].x, mv[3].y, stride,  rounding);
540                          }                          }
541                          else {                          else {
542                                  interpolate8x8_switch(dec->cur.y, pY_Ref , 16*x_pos, 16*y_pos,                                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos, 16*y_pos,
543                                                                            mv[0].x, mv[0].y, stride,  rounding);                                                                            mv[0].x, mv[0].y, stride,  rounding);
544                                  interpolate8x8_switch(dec->cur.y, pY_Ref , 16*x_pos + 8, 16*y_pos,                                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos + 8, 16*y_pos,
545                                                                            mv[1].x, mv[1].y, stride,  rounding);                                                                            mv[1].x, mv[1].y, stride,  rounding);
546                                  interpolate8x8_switch(dec->cur.y, pY_Ref , 16*x_pos, 16*y_pos + 8,                                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos, 16*y_pos + 8,
547                                                                            mv[2].x, mv[2].y, stride,  rounding);                                                                            mv[2].x, mv[2].y, stride,  rounding);
548                                  interpolate8x8_switch(dec->cur.y, pY_Ref , 16*x_pos + 8, 16*y_pos + 8,                                  interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos + 8, 16*y_pos + 8,
549                                                                            mv[3].x, mv[3].y, stride,  rounding);                                                                            mv[3].x, mv[3].y, stride,  rounding);
550                          }                          }
551    
552                          interpolate8x8_switch(dec->cur.u, pU_Ref , 8 * x_pos, 8 * y_pos,                          interpolate8x8_switch(dec->cur.u, dec->refn[0].u , 8 * x_pos, 8 * y_pos,
553                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
554                          interpolate8x8_switch(dec->cur.v, pV_Ref , 8 * x_pos, 8 * y_pos,                          interpolate8x8_switch(dec->cur.v, dec->refn[0].v , 8 * x_pos, 8 * y_pos,
555                                                                    uv_dx, uv_dy, stride2, rounding);                                                                    uv_dx, uv_dy, stride2, rounding);
556                  }                  }
557                  stop_comp_timer();                  stop_comp_timer();
# Line 638  Line 622 
622  }  }
623    
624    
625    static void
626    decoder_mbgmc(DECODER * dec,
627                                    MACROBLOCK * const pMB,
628                                    const uint32_t x_pos,
629                                    const uint32_t y_pos,
630                                    const uint32_t acpred_flag,
631                                    const uint32_t cbp,
632                                    Bitstream * bs,
633                                    const uint32_t quant,
634                                    const uint32_t rounding,
635                                    const int reduced_resolution)   /* no reduced res support */
636    {
637    
638            DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE);
639            DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE);
640    
641            const uint32_t stride = dec->edged_width;
642            const uint32_t stride2 = stride / 2;
643            const uint32_t next_block = stride * (reduced_resolution ? 16 : 8);
644            uint32_t i;
645            const uint32_t iQuant = pMB->quant;
646            uint8_t *const pY_Cur=dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
647            uint8_t *const pU_Cur=dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
648            uint8_t *const pV_Cur=dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
649    
650            pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
651    
652            start_timer();
653            transfer16x16_copy(pY_Cur, dec->gmc.y + (y_pos << 4)*stride + (x_pos  << 4), stride);
654            transfer8x8_copy(pU_Cur, dec->gmc.u + (y_pos << 3)*stride2 + (x_pos  << 3), stride2);
655            transfer8x8_copy(pV_Cur, dec->gmc.v + (y_pos << 3)*stride2 + (x_pos << 3), stride2);
656            stop_transfer_timer();
657    
658            if (!cbp) return;
659    
660            for (i = 0; i < 6; i++) {
661                    int direction = dec->alternate_vertical_scan ? 2 : 0;
662    
663                    if (cbp & (1 << (5 - i)))       // coded
664                    {
665                            memset(&block[i * 64], 0, 64 * sizeof(int16_t));        // clear
666    
667                            start_timer();
668                            get_inter_block(bs, &block[i * 64], direction);
669                            stop_coding_timer();
670    
671                            start_timer();
672                            if (dec->quant_type == 0) {
673                                    dequant_inter(&data[i * 64], &block[i * 64], iQuant);
674                            } else {
675                                    dequant4_inter(&data[i * 64], &block[i * 64], iQuant);
676                            }
677                            stop_iquant_timer();
678    
679                            start_timer();
680                            idct(&data[i * 64]);
681                            stop_idct_timer();
682                    }
683            }
684    
685    /* interlace + GMC is this possible ??? */
686    /*      if (dec->interlacing && pMB->field_dct) {
687                    next_block = stride;
688                    stride *= 2;
689            }
690    */
691            start_timer();
692            if (cbp & 32)
693                    transfer_16to8add(pY_Cur, &data[0 * 64], stride);
694            if (cbp & 16)
695                    transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
696            if (cbp & 8)
697                    transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
698            if (cbp & 4)
699                    transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);
700            if (cbp & 2)
701                    transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
702            if (cbp & 1)
703                    transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
704            stop_transfer_timer();
705    }
706    
707    
708  void  void
709  decoder_iframe(DECODER * dec,  decoder_iframe(DECODER * dec,
710                             Bitstream * bs,                             Bitstream * bs,
# Line 813  Line 880 
880    
881          if (gmc_warp)          if (gmc_warp)
882          {          {
883                  char filename[80];  
                 sprintf(filename,"dGMC%05d.pgm",framecount);  
884                  // accuracy:  0==1/2, 1=1/4, 2=1/8, 3=1/16                  // accuracy:  0==1/2, 1=1/4, 2=1/8, 3=1/16
885                  if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) )                  if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) )
886                  {                  {
# Line 830  Line 896 
896                  generate_GMCimage(&dec->gmc_data, &dec->refn[0],                  generate_GMCimage(&dec->gmc_data, &dec->refn[0],
897                                          mb_width, mb_height,                                          mb_width, mb_height,
898                                          dec->edged_width, dec->edged_width/2,                                          dec->edged_width, dec->edged_width/2,
899                                          fcode, 0, 0,                                          fcode, dec->quarterpel, 0,
900                                          rounding, dec->mbs, &dec->gmc);                                          rounding, dec->mbs, &dec->gmc);
901    
 /*  
                 sprintf(filename,"dGMC%05d.pgm",framecount);  
                 image_dump_yuvpgm(&dec->gmc,  
                                         dec->edged_width, dec->width, dec->height, filename);  
   
                 sprintf(filename,"dREF%05d.pgm",framecount);  
                 image_dump_yuvpgm(&dec->refn[0],  
                                         dec->edged_width, dec->width, dec->height, filename);  
                 sprintf(filename,"dCUR%05d.pgm",framecount);  
                 image_dump_yuvpgm(&dec->cur,  
                                         dec->edged_width, dec->width, dec->height, filename);  
                 framecount++;  
 */  
902          }          }
903    
904          bound = 0;          bound = 0;
# Line 938  Line 991 
991                                          }                                          }
992                                  }                                  }
993    
994                                  if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {                                  if (mcsel) {
995                                            decoder_mbgmc(dec, mb, x, y, 0, cbp, bs, quant,
996                                                                    rounding, reduced_resolution);
997                                            continue;
998    
999                                          if (mcsel)                                  } else if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
                                         {  
                                                 mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->amv;  
                                            /* already clipped to fcode */  
1000    
1001                                          } else if (dec->interlacing && mb->field_pred) {                                          if (dec->interlacing && mb->field_pred) {
1002                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0],
1003                                                                                    fcode, bound);                                                                                    fcode, bound);
1004                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],                                                  get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1],
# Line 972  Line 1025 
1025                                          continue;                                          continue;
1026                                  }                                  }
1027    
1028                                  decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant,                                  decoder_mbinter(dec, mb, x, y, 0, cbp, bs, quant,
1029                                                                  rounding, reduced_resolution, mcsel);                                                                  rounding, reduced_resolution);
1030    
1031                          }                          }
1032                          else if (gmc_warp)      /* a not coded S(GMC)-VOP macroblock */                          else if (gmc_warp)      /* a not coded S(GMC)-VOP macroblock */
1033                          {                          {
1034                                  mb->mode = MODE_NOT_CODED_GMC;                                  mb->mode = MODE_NOT_CODED_GMC;
                                 mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->amv;  
1035    
1036                                  start_timer();                                  start_timer();
1037    
1038                                  transfer16x16_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x),                                  decoder_mbgmc(dec, mb, x, y, 0, 0x00, bs, quant,
1039                                                                   dec->gmc.y + (16*y)*dec->edged_width + (16*x),                                                                  rounding, reduced_resolution);
                                                                  dec->edged_width);  
   
                                 transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x),  
                                                                 dec->gmc.u + (8*y)*dec->edged_width/2 + (8*x),  
                                                                 dec->edged_width/2);  
   
                                 transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x),  
                                                                  dec->gmc.v + (8*y)*dec->edged_width/2 + (8*x),  
                                                                  dec->edged_width/2);  
1040    
1041                                  stop_transfer_timer();                                  stop_transfer_timer();
1042    
# Line 1551  Line 1594 
1594                          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;
1595    
1596                          // skip if the co-located P_VOP macroblock is not coded                          // skip if the co-located P_VOP macroblock is not coded
1597                          // note: gmc+not_coded isn't skipped                          // if not codec in co-located S_VOP macroblock is _not_ automatically skipped
1598    
1599                          if (last_mb->mode == MODE_NOT_CODED) {                          if (last_mb->mode == MODE_NOT_CODED) {
1600                                  //DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y);                                  //DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y);

Legend:
Removed from v.769  
changed lines
  Added in v.773

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