[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.49.2.3, Wed Mar 26 10:29:51 2003 UTC revision 1.50, Mon Jun 9 17:02:38 2003 UTC
# Line 158  Line 158 
158    
159          memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);          memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height);
160    
161          return 0;          return XVID_ERR_OK;
162  }  }
163    
164    
165  int  int
166  decoder_create(xvid_dec_create_t * create)  decoder_create(XVID_DEC_PARAM * param)
167  {  {
168          DECODER *dec;          DECODER *dec;
169    
         if (XVID_MAJOR(create->version) != 1)   /* v1.x.x */  
                 return XVID_ERR_VERSION;  
   
170          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);
171          if (dec == NULL) {          if (dec == NULL) {
172                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
173          }          }
174          memset(dec, 0, sizeof(DECODER));          memset(dec, 0, sizeof(DECODER));
175    
176          create->handle = dec;          param->handle = dec;
177    
178          dec->width = create->width;          dec->width = param->width;
179          dec->height = create->height;          dec->height = param->height;
180    
181          image_null(&dec->cur);          image_null(&dec->cur);
182          image_null(&dec->refn[0]);          image_null(&dec->refn[0]);
# Line 207  Line 204 
204          if (dec->fixed_dimensions)          if (dec->fixed_dimensions)
205                  return decoder_resize(dec);                  return decoder_resize(dec);
206          else          else
207                  return 0;                  return XVID_ERR_OK;
208  }  }
209    
210    
# Line 228  Line 225 
225          xvid_free(dec);          xvid_free(dec);
226    
227          write_timer();          write_timer();
228          return 0;          return XVID_ERR_OK;
229  }  }
230    
231    
# Line 1705  Line 1702 
1702  #endif  #endif
1703  }  }
1704    
1705    /* swap two MACROBLOCK array */
1706    void
1707    mb_swap(MACROBLOCK ** mb1,
1708                    MACROBLOCK ** mb2)
1709    {
1710            MACROBLOCK *temp = *mb1;
1711    
1712            *mb1 = *mb2;
1713            *mb2 = temp;
1714    }
1715    
1716    
1717  /* perform post processing if necessary, and output the image */  /* perform post processing if necessary, and output the image */
1718  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,
1719                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type)                                          const XVID_DEC_FRAME * frame, int pp_disable)
1720  {  {
1721    
1722            if ((frame->general & (XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV)) && !pp_disable)   /* post process */
         image_output(img, dec->width, dec->height,  
                                  dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride,  
                                  frame->output.csp, dec->interlacing);  
   
         if (stats)  
1723          {          {
1724                  stats->type = coding2type(coding_type);                  /* note: image is stored to tmp */
1725                  stats->data.vop.time_base = (int)dec->time_base;                  image_copy(&dec->tmp, img, dec->edged_width, dec->height);
1726                  stats->data.vop.time_increment = 0;     //XXX: todo                  image_deblock_rrv(&dec->tmp, dec->edged_width,
1727                                                    mbs, dec->mb_width, dec->mb_height, dec->mb_width,
1728                                                    8, frame->general);
1729                    img = &dec->tmp;
1730          }          }
1731    
1732            image_output(img, dec->width, dec->height,
1733                                     dec->edged_width, frame->image, frame->stride,
1734                                     frame->colorspace, dec->interlacing);
1735  }  }
1736    
1737    
1738  int  int
1739  decoder_decode(DECODER * dec,  decoder_decode(DECODER * dec,
1740                             xvid_dec_frame_t * frame, xvid_dec_stats_t * stats)                             XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats)
1741  {  {
1742    
1743          Bitstream bs;          Bitstream bs;
# Line 1739  Line 1748 
1748          uint32_t fcode_backward;          uint32_t fcode_backward;
1749          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1750          WARPPOINTS gmc_warp;          WARPPOINTS gmc_warp;
1751          int coding_type;          int vop_type;
1752          int success, output, seen_something;          int success = 0;
1753            int output = 0;
1754          if (XVID_MAJOR(frame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1))      /* v1.x.x */          int seen_something = 0;
1755                  return XVID_ERR_VERSION;          idctFuncPtr idct_save = idct;
1756    
1757          start_global_timer();          start_global_timer();
1758    
1759          dec->low_delay_default = (frame->general & XVID_LOWDELAY);          dec->low_delay_default = (frame->general & XVID_DEC_LOWDELAY);
1760          if ((frame->general & XVID_DISCONTINUITY))          dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL;
1761    
1762            if ((frame->general & XVID_DEC_DISCONTINUITY))
1763                  dec->frames = 0;                  dec->frames = 0;
         dec->out_frm = (frame->output.csp == XVID_CSP_SLICE) ? &frame->output : NULL;  
1764    
1765          if (frame->length < 0)  /* decoder flush */          if (frame->length < 0)  /* decoder flush */
1766          {          {
         int ret;  
1767                  /* if  not decoding "low_delay/packed", and this isn't low_delay and                  /* if  not decoding "low_delay/packed", and this isn't low_delay and
1768                      we have a reference frame, then outout the reference frame */                      we have a reference frame, then outout the reference frame */
1769                  if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) {                  if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0)
1770                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                  {
1771              dec->frames = 0;                          decoder_output(dec, &dec->refn[0], dec->mbs, frame, dec->last_reduced_resolution);
1772              ret = 0;                          output = 1;
1773          }else{                  }
1774              if (stats) stats->type = XVID_TYPE_NOTHING;  
1775              ret = XVID_ERR_END;                  frame->length = 0;
1776                    if (stats)
1777                    {
1778                            stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING;
1779                            stats->data.vop.time_base = (int)dec->time_base;
1780                            stats->data.vop.time_increment = 0;     /* XXX: todo */
1781          }          }
1782    
1783                  emms();                  emms();
1784    
1785                  stop_global_timer();                  stop_global_timer();
1786                  return ret;                  return XVID_ERR_OK;
1787          }          }
1788    
1789          BitstreamInit(&bs, frame->bitstream, frame->length);          BitstreamInit(&bs, frame->bitstream, frame->length);
# Line 1776  Line 1791 
1791          /* XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's */          /* XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's */
1792          if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)          if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f)
1793          {          {
1794                    if (stats)
1795                            stats->notify = XVID_DEC_VOP;
1796                    frame->length = 1;
1797                  image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width,                  image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width,
1798                                           (uint8_t**)frame->output.plane, frame->output.stride, frame->output.csp, dec->interlacing);                                           frame->image, frame->stride, frame->colorspace, dec->interlacing);
                 if (stats) stats->type = XVID_TYPE_NOTHING;  
1799                  emms();                  emms();
1800                  return 1;   /* one byte consumed */                  return XVID_ERR_OK;
1801          }          }
1802    
         success = 0;  
         output = 0;  
         seen_something = 0;  
   
1803  repeat:  repeat:
1804    
1805          coding_type =   BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,          vop_type =      BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution,
1806                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);                          &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);
1807    
1808          DPRINTF(DPRINTF_HEADER, "coding_type=%i,  packed=%i,  time=%lli,  time_pp=%i,  time_bp=%i",          DPRINTF(DPRINTF_HEADER, "vop_type=%i,  packed=%i,  time=%lli,  time_pp=%i,  time_bp=%i",
1809                                                          coding_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);
1810    
1811          if (coding_type == -1) /* nothing */          if (vop_type == -1)
1812          {          {
1813                  if (success) goto done;                  if (success) goto done;
         if (stats) stats->type = XVID_TYPE_NOTHING;  
1814                  emms();                  emms();
1815          return BitstreamPos(&bs)/8;                  return XVID_ERR_FAIL;
1816          }          }
1817    
1818          if (coding_type == -2 || coding_type == -3)   /* vol and/or resize */          if (vop_type == -2 || vop_type == -3)
1819          {          {
1820                  if (coding_type == -3)                  if (vop_type == -3)
1821                          decoder_resize(dec);                          decoder_resize(dec);
1822    
1823                  if (stats)                  if (stats)
1824                  {                  {
1825                          stats->type = XVID_TYPE_VOL;                          stats->notify = XVID_DEC_VOL;
1826                          stats->data.vol.general = 0;                          stats->data.vol.general = 0;
1827                          /*XXX: if (dec->interlacing)                          if (dec->interlacing)
1828                                  stats->data.vol.general |= ++INTERLACING; */                                  stats->data.vol.general |= XVID_INTERLACING;
1829                          stats->data.vol.width = dec->width;                          stats->data.vol.width = dec->width;
1830                          stats->data.vol.height = dec->height;                          stats->data.vol.height = dec->height;
1831                          stats->data.vol.par = dec->aspect_ratio;                          stats->data.vol.aspect_ratio = dec->aspect_ratio;
1832                          stats->data.vol.par_width = dec->par_width;                          stats->data.vol.par_width = dec->par_width;
1833                          stats->data.vol.par_height = dec->par_height;                          stats->data.vol.par_height = dec->par_height;
1834                            frame->length = BitstreamPos(&bs) / 8;
1835                          emms();                          emms();
1836                          return BitstreamPos(&bs)/8;     /* number of bytes consumed */                          return XVID_ERR_OK;
1837                  }                  }
1838                  goto repeat;                  goto repeat;
1839          }          }
1840    
1841          dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0;  /* init pred vector to 0 */          dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0;  /* init pred vector to 0 */
1842    
1843            if((idct == simple_idct_mmx) && (dec->bs_version < 10)) /* rather ugly but should work */
1844                    idct = idct_mmx;
1845    
1846          /* packed_mode: special-N_VOP treament */          /* packed_mode: special-N_VOP treament */
1847          if (dec->packed_mode && coding_type == N_VOP)          if (dec->packed_mode && vop_type == N_VOP)
1848          {          {
1849                  if (dec->low_delay_default && dec->frames > 0)                  if (dec->low_delay_default && dec->frames > 0)
1850                  {                  {
1851                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution);
1852                          output = 1;                          output = 1;
1853                  }                  }
1854                  /* ignore otherwise */                  /* ignore otherwise */
1855          }          }
1856          else if (coding_type != B_VOP)          else if (vop_type != B_VOP)
1857          {          {
1858                  switch(coding_type)                  switch(vop_type)
1859                  {                  {
1860                  case I_VOP :                  case I_VOP :
1861                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);
# Line 1854  Line 1869 
1869                                                  fcode_forward, intra_dc_threshold, &gmc_warp);                                                  fcode_forward, intra_dc_threshold, &gmc_warp);
1870                          break;                          break;
1871                  case N_VOP :                  case N_VOP :
                         // XXX: not_coded vops are not used for forward prediction  
                         //              we should not swap(last_mbs,mbs)  
1872                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
1873                          break;                          break;
1874                  }                  }
# Line 1864  Line 1877 
1877                  {                  {
1878                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,
1879                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,
1880                                  16, 0);                                  16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV);
1881                  }                  }
1882    
1883                  /* note: for packed_mode, output is performed when the special-N_VOP is decoded */                  /* note: for packed_mode, output is performed when the special-N_VOP is decoded */
# Line 1872  Line 1885 
1885                  {                  {
1886                          if (dec->low_delay)                          if (dec->low_delay)
1887                          {                          {
1888                                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);                                  decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution);
1889                                  output = 1;                                  output = 1;
1890                          }                          }
1891                          else if (dec->frames > 0)       /* is the reference frame valid? */                          else if (dec->frames > 0)       /* is the reference frame valid? */
1892                          {                          {
1893                                  /* output the reference frame */                                  /* output the reference frame */
1894                                  decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                                  decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution);
1895                                  output = 1;                                  output = 1;
1896                          }                          }
1897                  }                  }
1898    
1899                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1900                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1901          SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs);                  mb_swap(&dec->mbs, &dec->last_mbs);
1902                  dec->last_reduced_resolution = reduced_resolution;                  dec->last_reduced_resolution = reduced_resolution;
         dec->last_coding_type = coding_type;  
1903    
1904                  dec->frames++;                  dec->frames++;
1905                  seen_something = 1;                  seen_something = 1;
# Line 1914  Line 1926 
1926                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1927                  }                  }
1928    
1929                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);                  decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution);
1930                  output = 1;                  output = 1;
1931                  dec->frames++;                  dec->frames++;
1932          }          }
# Line 1937  Line 1949 
1949                  if (dec->packed_mode && seen_something)                  if (dec->packed_mode && seen_something)
1950                  {                  {
1951                          /* output the recently decoded frame */                          /* output the recently decoded frame */
1952                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type);                          decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution);
1953                            output = 1;
1954                  }                  }
1955                  else                  else
1956                  {                  {
# Line 1947  Line 1960 
1960                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,
1961                                  "bframe decoder lag");                                  "bframe decoder lag");
1962    
1963                          decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP);                          decoder_output(dec, &dec->cur, NULL, frame, 1 /*disable pp*/);
                         if (stats) stats->type = XVID_TYPE_NOTHING;  
   
1964                  }                  }
1965          }          }
1966    
1967            idct = idct_save;
1968    
1969            frame->length = BitstreamPos(&bs) / 8;
1970    
1971            if (stats)
1972            {
1973                    stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING;
1974                    stats->data.vop.time_base = (int)dec->time_base;
1975                    stats->data.vop.time_increment = 0;     /* XXX: todo */
1976            }
1977    
1978          emms();          emms();
1979    
1980          stop_global_timer();          stop_global_timer();
1981    
1982          return BitstreamPos(&bs) / 8;   /* number of bytes consumed */          return XVID_ERR_OK;
1983  }  }

Legend:
Removed from v.1.49.2.3  
changed lines
  Added in v.1.50

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