[svn] / branches / release-1_3-branch / xvidcore / src / decoder.c Repository:
ViewVC logotype

Diff of /branches/release-1_3-branch/xvidcore/src/decoder.c

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

trunk/xvidcore/src/decoder.c revision 1772, Mon Apr 16 19:01:28 2007 UTC branches/release-1_3-branch/xvidcore/src/decoder.c revision 2180, Tue Nov 12 14:48:35 2019 UTC
# Line 4  Line 4 
4   *  - Decoder Module -   *  - Decoder Module -
5   *   *
6   *  Copyright(C) 2002      MinChen <chenm001@163.com>   *  Copyright(C) 2002      MinChen <chenm001@163.com>
7   *               2002-2004 Peter Ross <pross@xvid.org>   *               2002-2010 Peter Ross <pross@xvid.org>
8   *   *
9   *  This program is free software ; you can redistribute it and/or modify   *  This program is free software ; you can redistribute it and/or modify
10   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
# Line 20  Line 20 
20   *  along with this program ; if not, write to the Free Software   *  along with this program ; if not, write to the Free Software
21   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   *   *
23   * $Id: decoder.c,v 1.80 2007-04-16 19:01:28 Skal Exp $   * $Id$
24   *   *
25   ****************************************************************************/   ****************************************************************************/
26    
# Line 149  Line 149 
149  int  int
150  decoder_create(xvid_dec_create_t * create)  decoder_create(xvid_dec_create_t * create)
151  {  {
152      int ret = 0;
153    DECODER *dec;    DECODER *dec;
154    
155    if (XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */    if (XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */
# Line 169  Line 170 
170    
171    create->handle = dec;    create->handle = dec;
172    
173    dec->width = create->width;    dec->width = MAX(0, create->width);
174    dec->height = create->height;    dec->height = MAX(0, create->height);
175    
176      dec->num_threads = MAX(0, create->num_threads);
177    
178    image_null(&dec->cur);    image_null(&dec->cur);
179    image_null(&dec->refn[0]);    image_null(&dec->refn[0]);
# Line 197  Line 200 
200    dec->time_inc_resolution = 1; /* until VOL header says otherwise */    dec->time_inc_resolution = 1; /* until VOL header says otherwise */
201    dec->ver_id = 1;    dec->ver_id = 1;
202    
203      if (create->fourcc == ((int)('X')|((int)('V')<<8)|
204                             ((int)('I')<<16)|((int)('D')<<24))) { /* XVID */
205        dec->bs_version = 0; /* Initially assume oldest xvid version */
206      }
207      else {
208    dec->bs_version = 0xffff; /* Initialize to very high value -> assume bugfree stream */    dec->bs_version = 0xffff; /* Initialize to very high value -> assume bugfree stream */
209      }
210    
211    dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);    dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);
212    
213    if (dec->fixed_dimensions)    ret = decoder_resize(dec);
214      return decoder_resize(dec);    if (ret == XVID_ERR_MEMORY) create->handle = NULL;
215    else  
216      return 0;    return ret;
217  }  }
218    
219    
# Line 255  Line 264 
264    uint32_t stride2 = stride / 2;    uint32_t stride2 = stride / 2;
265    uint32_t next_block = stride * 8;    uint32_t next_block = stride * 8;
266    uint32_t i;    uint32_t i;
267    uint32_t iQuant = pMB->quant;    uint32_t iQuant = MAX(1, pMB->quant);
268    uint8_t *pY_Cur, *pU_Cur, *pV_Cur;    uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
269    
270    pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);    pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
# Line 352  Line 361 
361    
362    int stride = dec->edged_width;    int stride = dec->edged_width;
363    int i;    int i;
364    const uint32_t iQuant = pMB->quant;    const uint32_t iQuant = MAX(1, pMB->quant);
365    const int direction = dec->alternate_vertical_scan ? 2 : 0;    const int direction = dec->alternate_vertical_scan ? 2 : 0;
366    typedef void (*get_inter_block_function_t)(    typedef void (*get_inter_block_function_t)(
367        Bitstream * bs,        Bitstream * bs,
# Line 748  Line 757 
757          bound = read_video_packet_header(bs, dec, 0,          bound = read_video_packet_header(bs, dec, 0,
758                &quant, NULL, NULL, &intra_dc_threshold);                &quant, NULL, NULL, &intra_dc_threshold);
759          x = bound % mb_width;          x = bound % mb_width;
760          y = bound / mb_width;          y = MIN((bound / mb_width), (mb_height-1));
761        }        }
762        mb = &dec->mbs[y * dec->mb_width + x];        mb = &dec->mbs[y * dec->mb_width + x];
763    
# Line 975  Line 984 
984          bound = read_video_packet_header(bs, dec, fcode - 1,          bound = read_video_packet_header(bs, dec, fcode - 1,
985            &quant, &fcode, NULL, &intra_dc_threshold);            &quant, &fcode, NULL, &intra_dc_threshold);
986          x = bound % mb_width;          x = bound % mb_width;
987          y = bound / mb_width;          y = MIN((bound / mb_width), (mb_height-1));
988        }        }
989        mb = &dec->mbs[y * dec->mb_width + x];        mb = &dec->mbs[y * dec->mb_width + x];
990    
# Line 1380  Line 1389 
1389        MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x];        MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x];
1390        int intra_dc_threshold; /* fake variable */        int intra_dc_threshold; /* fake variable */
1391    
       if (check_resync_marker(bs, resync_len)) {  
         int bound = read_video_packet_header(bs, dec, resync_len, &quant,  
                            &fcode_forward, &fcode_backward, &intra_dc_threshold);  
         x = bound % dec->mb_width;  
         y = bound / dec->mb_width;  
         /* reset predicted macroblocks */  
         dec->p_fmv = dec->p_bmv = zeromv;  
         /* update resync len with new fcodes */  
         resync_len = get_resync_len_b(fcode_backward, fcode_forward);  
       }  
   
1392        mv =        mv =
1393        mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] =        mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] =
1394        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;
# Line 1409  Line 1407 
1407          continue;          continue;
1408        }        }
1409    
1410          if (check_resync_marker(bs, resync_len)) {
1411            int bound = read_video_packet_header(bs, dec, resync_len, &quant,
1412                               &fcode_forward, &fcode_backward, &intra_dc_threshold);
1413    
1414                    bound = MAX(0, bound-1); /* valid bound must always be >0 */
1415            x = bound % dec->mb_width;
1416            y = MIN((bound / dec->mb_width), (dec->mb_height-1));
1417            /* reset predicted macroblocks */
1418            dec->p_fmv = dec->p_bmv = zeromv;
1419            /* update resync len with new fcodes */
1420            resync_len = get_resync_len_b(fcode_backward, fcode_forward);
1421                    continue; /* re-init loop */
1422              }
1423    
1424        if (!BitstreamGetBit(bs)) { /* modb=='0' */        if (!BitstreamGetBit(bs)) { /* modb=='0' */
1425          const uint8_t modb2 = BitstreamGetBit(bs);          const uint8_t modb2 = BitstreamGetBit(bs);
1426    
# Line 1522  Line 1534 
1534      image_copy(&dec->tmp, img, dec->edged_width, dec->height);      image_copy(&dec->tmp, img, dec->edged_width, dec->height);
1535      image_postproc(&dec->postproc, &dec->tmp, dec->edged_width,      image_postproc(&dec->postproc, &dec->tmp, dec->edged_width,
1536               mbs, dec->mb_width, dec->mb_height, dec->mb_width,               mbs, dec->mb_width, dec->mb_height, dec->mb_width,
1537               frame->general, brightness, dec->frames, (coding_type == B_VOP));               frame->general, brightness, dec->frames, (coding_type == B_VOP), dec->num_threads);
1538      img = &dec->tmp;      img = &dec->tmp;
1539    }    }
1540    
1541      if ((frame->output.plane[0] != NULL) && (frame->output.stride[0] >= dec->width)) {
1542    image_output(img, dec->width, dec->height,    image_output(img, dec->width, dec->height,
1543           dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride,           dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride,
1544           frame->output.csp, dec->interlacing);           frame->output.csp, dec->interlacing);
1545      }
1546    
1547    if (stats) {    if (stats) {
1548      stats->type = coding2type(coding_type);      stats->type = coding2type(coding_type);
# Line 1551  Line 1565 
1565  {  {
1566    
1567    Bitstream bs;    Bitstream bs;
1568    uint32_t rounding;    uint32_t rounding = 0;
1569    uint32_t quant = 2;    uint32_t quant = 2;
1570    uint32_t fcode_forward;    uint32_t fcode_forward = 0;
1571    uint32_t fcode_backward;    uint32_t fcode_backward = 0;
1572    uint32_t intra_dc_threshold;    uint32_t intra_dc_threshold = 0;
1573    WARPPOINTS gmc_warp;    WARPPOINTS gmc_warp;
1574    int coding_type;    int coding_type = -1;
1575    int success, output, seen_something;    int success, output, seen_something;
1576    
1577    if (XVID_VERSION_MAJOR(frame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1))  /* v1.x.x */    if (XVID_VERSION_MAJOR(frame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1))  /* v1.x.x */
1578      return XVID_ERR_VERSION;      return XVID_ERR_VERSION;
1579    
1580    start_global_timer();    start_global_timer();
1581      memset((void *)&gmc_warp, 0, sizeof(WARPPOINTS));
1582    
1583    dec->low_delay_default = (frame->general & XVID_LOWDELAY);    dec->low_delay_default = (frame->general & XVID_LOWDELAY);
1584    if ((frame->general & XVID_DISCONTINUITY))    if ((frame->general & XVID_DISCONTINUITY))
# Line 1633  Line 1648 
1648      if(stats) {      if(stats) {
1649        stats->type = XVID_TYPE_VOL;        stats->type = XVID_TYPE_VOL;
1650        stats->data.vol.general = 0;        stats->data.vol.general = 0;
1651        /*XXX: if (dec->interlacing)            stats->data.vop.general = 0;
1652          stats->data.vol.general |= ++INTERLACING; */            if (dec->interlacing) {
1653        stats->data.vol.width = dec->width;                    stats->data.vol.general |= XVID_VOL_INTERLACING;
1654                      if (dec->top_field_first) {
1655                              stats->data.vop.general |= XVID_VOP_TOPFIELDFIRST;
1656                      }
1657              }      stats->data.vol.width = dec->width;
1658        stats->data.vol.height = dec->height;        stats->data.vol.height = dec->height;
1659        stats->data.vol.par = dec->aspect_ratio;        stats->data.vol.par = dec->aspect_ratio;
1660        stats->data.vol.par_width = dec->par_width;        stats->data.vol.par_width = dec->par_width;
# Line 1646  Line 1665 
1665      goto repeat;      goto repeat;
1666    }    }
1667    
1668    if(dec->frames == 0 && coding_type != I_VOP) {    if((dec->frames == 0 && coding_type != I_VOP) || (!dec->width || !dec->height)) {
1669      /* 1st frame is not an i-vop */      /* 1st frame is not an i-vop */
1670      goto repeat;      goto repeat;
1671    }    }
1672    
1673    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.x = dec->p_fmv.y = 0;  /* init pred vector to 0 */
1674    
1675    /* packed_mode: special-N_VOP treament */    /* packed_mode: special-N_VOP treament */
1676    if (dec->packed_mode && coding_type == N_VOP) {    if (dec->packed_mode && coding_type == N_VOP) {

Legend:
Removed from v.1772  
changed lines
  Added in v.2180

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