[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.49.4.1, Sat May 3 23:23:38 2003 UTC
# Line 57  Line 57 
57  #include "image/image.h"  #include "image/image.h"
58  #include "image/colorspace.h"  #include "image/colorspace.h"
59  #include "utils/mem_align.h"  #include "utils/mem_align.h"
60    #include "image/postprocessing.h"
61    
62  int  int
63  decoder_resize(DECODER * dec)  decoder_resize(DECODER * dec)
# Line 158  Line 159 
159    
160          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);
161    
162          return 0;          return XVID_ERR_OK;
163  }  }
164    
165    
166  int  int
167  decoder_create(xvid_dec_create_t * create)  decoder_create(XVID_DEC_PARAM * param)
168  {  {
169          DECODER *dec;          DECODER *dec;
170    
         if (XVID_MAJOR(create->version) != 1)   /* v1.x.x */  
                 return XVID_ERR_VERSION;  
   
171          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);          dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);
172          if (dec == NULL) {          if (dec == NULL) {
173                  return XVID_ERR_MEMORY;                  return XVID_ERR_MEMORY;
174          }          }
175          memset(dec, 0, sizeof(DECODER));          memset(dec, 0, sizeof(DECODER));
176    
177          create->handle = dec;          param->handle = dec;
178    
179          dec->width = create->width;          dec->width = param->width;
180          dec->height = create->height;          dec->height = param->height;
181    
182          image_null(&dec->cur);          image_null(&dec->cur);
183          image_null(&dec->refn[0]);          image_null(&dec->refn[0]);
# Line 207  Line 205 
205          if (dec->fixed_dimensions)          if (dec->fixed_dimensions)
206                  return decoder_resize(dec);                  return decoder_resize(dec);
207          else          else
208                  return 0;                  return XVID_ERR_OK;
209  }  }
210    
211    
# Line 228  Line 226 
226          xvid_free(dec);          xvid_free(dec);
227    
228          write_timer();          write_timer();
229          return 0;          return XVID_ERR_OK;
230  }  }
231    
232    
# Line 1705  Line 1703 
1703  #endif  #endif
1704  }  }
1705    
1706    /* swap two MACROBLOCK array */
1707    void
1708    mb_swap(MACROBLOCK ** mb1,
1709                    MACROBLOCK ** mb2)
1710    {
1711            MACROBLOCK *temp = *mb1;
1712    
1713            *mb1 = *mb2;
1714            *mb2 = temp;
1715    }
1716    
1717    
1718  /* perform post processing if necessary, and output the image */  /* perform post processing if necessary, and output the image */
1719  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,  void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs,
1720                                          xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type)                                          const XVID_DEC_FRAME * frame, int pp_disable)
1721  {  {
1722    
1723            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)  
1724          {          {
1725                  stats->type = coding2type(coding_type);                  /* note: image is stored to tmp */
1726                  stats->data.vop.time_base = (int)dec->time_base;                  image_copy(&dec->tmp, img, dec->edged_width, dec->height);
1727                  stats->data.vop.time_increment = 0;     //XXX: todo                  image_deblock(&dec->tmp, dec->edged_width,
1728                                              mbs, dec->mb_width, dec->mb_height, dec->mb_width,
1729                                              frame->general);
1730                    img = &dec->tmp;
1731          }          }
1732    
1733            image_output(img, dec->width, dec->height,
1734                                     dec->edged_width, frame->image, frame->stride,
1735                                     frame->colorspace, dec->interlacing);
1736  }  }
1737    
1738    
1739  int  int
1740  decoder_decode(DECODER * dec,  decoder_decode(DECODER * dec,
1741                             xvid_dec_frame_t * frame, xvid_dec_stats_t * stats)                             XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats)
1742  {  {
1743    
1744          Bitstream bs;          Bitstream bs;
# Line 1739  Line 1749 
1749          uint32_t fcode_backward;          uint32_t fcode_backward;
1750          uint32_t intra_dc_threshold;          uint32_t intra_dc_threshold;
1751          WARPPOINTS gmc_warp;          WARPPOINTS gmc_warp;
1752          int coding_type;          int vop_type;
1753          int success, output, seen_something;          int success = 0;
1754            int output = 0;
1755          if (XVID_MAJOR(frame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1))      /* v1.x.x */          int seen_something = 0;
                 return XVID_ERR_VERSION;  
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          }          }
# Line 1829  Line 1842 
1842    
1843    
1844          /* packed_mode: special-N_VOP treament */          /* packed_mode: special-N_VOP treament */
1845          if (dec->packed_mode && coding_type == N_VOP)          if (dec->packed_mode && vop_type == N_VOP)
1846          {          {
1847                  if (dec->low_delay_default && dec->frames > 0)                  if (dec->low_delay_default && dec->frames > 0)
1848                  {                  {
1849                          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);
1850                          output = 1;                          output = 1;
1851                  }                  }
1852                  /* ignore otherwise */                  /* ignore otherwise */
1853          }          }
1854          else if (coding_type != B_VOP)          else if (vop_type != B_VOP)
1855          {          {
1856                  switch(coding_type)                  switch(vop_type)
1857                  {                  {
1858                  case I_VOP :                  case I_VOP :
1859                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);                          decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold);
# Line 1854  Line 1867 
1867                                                  fcode_forward, intra_dc_threshold, &gmc_warp);                                                  fcode_forward, intra_dc_threshold, &gmc_warp);
1868                          break;                          break;
1869                  case N_VOP :                  case N_VOP :
                         // XXX: not_coded vops are not used for forward prediction  
                         //              we should not swap(last_mbs,mbs)  
1870                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);                          image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height);
1871                          break;                          break;
1872                  }                  }
# Line 1864  Line 1875 
1875                  {                  {
1876                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,                          image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs,
1877                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,                                  (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width,
1878                                  16, 0);                                  16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV);
1879                  }                  }
1880    
1881                  /* 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 1883 
1883                  {                  {
1884                          if (dec->low_delay)                          if (dec->low_delay)
1885                          {                          {
1886                                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);                                  decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution);
1887                                  output = 1;                                  output = 1;
1888                          }                          }
1889                          else if (dec->frames > 0)       /* is the reference frame valid? */                          else if (dec->frames > 0)       /* is the reference frame valid? */
1890                          {                          {
1891                                  /* output the reference frame */                                  /* output the reference frame */
1892                                  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);
1893                                  output = 1;                                  output = 1;
1894                          }                          }
1895                  }                  }
1896    
1897                  image_swap(&dec->refn[0], &dec->refn[1]);                  image_swap(&dec->refn[0], &dec->refn[1]);
1898                  image_swap(&dec->cur, &dec->refn[0]);                  image_swap(&dec->cur, &dec->refn[0]);
1899          SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs);                  mb_swap(&dec->mbs, &dec->last_mbs);
1900                  dec->last_reduced_resolution = reduced_resolution;                  dec->last_reduced_resolution = reduced_resolution;
         dec->last_coding_type = coding_type;  
1901    
1902                  dec->frames++;                  dec->frames++;
1903                  seen_something = 1;                  seen_something = 1;
# Line 1914  Line 1924 
1924                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);                          decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward);
1925                  }                  }
1926    
1927                  decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type);                  decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution);
1928                  output = 1;                  output = 1;
1929                  dec->frames++;                  dec->frames++;
1930          }          }
# Line 1937  Line 1947 
1947                  if (dec->packed_mode && seen_something)                  if (dec->packed_mode && seen_something)
1948                  {                  {
1949                          /* output the recently decoded frame */                          /* output the recently decoded frame */
1950                          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);
1951                            output = 1;
1952                  }                  }
1953                  else                  else
1954                  {                  {
# Line 1947  Line 1958 
1958                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,                          image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64,
1959                                  "bframe decoder lag");                                  "bframe decoder lag");
1960    
1961                          decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP);                          decoder_output(dec, &dec->cur, NULL, frame, 1 /*disable pp*/);
1962                          if (stats) stats->type = XVID_TYPE_NOTHING;                  }
   
1963                  }                  }
1964    
1965            frame->length = BitstreamPos(&bs) / 8;
1966    
1967            if (stats)
1968            {
1969                    stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING;
1970                    stats->data.vop.time_base = (int)dec->time_base;
1971                    stats->data.vop.time_increment = 0;     /* XXX: todo */
1972          }          }
1973    
1974          emms();          emms();
1975    
1976          stop_global_timer();          stop_global_timer();
1977    
1978          return BitstreamPos(&bs) / 8;   /* number of bytes consumed */          return XVID_ERR_OK;
1979  }  }

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

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