[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.76, Sat Dec 24 01:06:20 2005 UTC revision 1.86, Fri Dec 24 13:49:58 2010 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 172  Line 172 
172    dec->width = create->width;    dec->width = create->width;
173    dec->height = create->height;    dec->height = create->height;
174    
175      dec->num_threads = MAX(0, create->num_threads);
176    
177    image_null(&dec->cur);    image_null(&dec->cur);
178    image_null(&dec->refn[0]);    image_null(&dec->refn[0]);
179    image_null(&dec->refn[1]);    image_null(&dec->refn[1]);
# Line 195  Line 197 
197    dec->low_delay = 0;    dec->low_delay = 0;
198    dec->packed_mode = 0;    dec->packed_mode = 0;
199    dec->time_inc_resolution = 1; /* until VOL header says otherwise */    dec->time_inc_resolution = 1; /* until VOL header says otherwise */
200      dec->ver_id = 1;
201    
202      if (create->fourcc == ((int)('X')|((int)('V')<<8)|
203                             ((int)('I')<<16)|((int)('D')<<24))) { /* XVID */
204        dec->bs_version = 0; /* Initially assume oldest xvid version */
205      }
206      else {
207            dec->bs_version = 0xffff; /* Initialize to very high value -> assume bugfree stream */
208      }
209    
210    dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);    dec->fixed_dimensions = (dec->width > 0 && dec->height > 0);
211    
212    if (dec->fixed_dimensions)    if (dec->fixed_dimensions) {
213      return decoder_resize(dec);      int ret = decoder_resize(dec);
214        if (ret == XVID_ERR_MEMORY) create->handle = NULL;
215        return ret;
216      }
217    else    else
218      return 0;      return 0;
219  }  }
# Line 745  Line 759 
759          bound = read_video_packet_header(bs, dec, 0,          bound = read_video_packet_header(bs, dec, 0,
760                &quant, NULL, NULL, &intra_dc_threshold);                &quant, NULL, NULL, &intra_dc_threshold);
761          x = bound % mb_width;          x = bound % mb_width;
762          y = bound / mb_width;          y = MIN((bound / mb_width), (mb_height-1));
763        }        }
764        mb = &dec->mbs[y * dec->mb_width + x];        mb = &dec->mbs[y * dec->mb_width + x];
765    
# Line 972  Line 986 
986          bound = read_video_packet_header(bs, dec, fcode - 1,          bound = read_video_packet_header(bs, dec, fcode - 1,
987            &quant, &fcode, NULL, &intra_dc_threshold);            &quant, &fcode, NULL, &intra_dc_threshold);
988          x = bound % mb_width;          x = bound % mb_width;
989          y = bound / mb_width;          y = MIN((bound / mb_width), (mb_height-1));
990        }        }
991        mb = &dec->mbs[y * dec->mb_width + x];        mb = &dec->mbs[y * dec->mb_width + x];
992    
# Line 1332  Line 1346 
1346    return -1;    return -1;
1347  }  }
1348    
1349    static int __inline get_resync_len_b(const int fcode_backward,
1350                                         const int fcode_forward) {
1351      int resync_len = ((fcode_forward>fcode_backward) ? fcode_forward : fcode_backward) - 1;
1352      if (resync_len < 1) resync_len = 1;
1353      return resync_len;
1354    }
1355    
1356  static void  static void
1357  decoder_bframe(DECODER * dec,  decoder_bframe(DECODER * dec,
1358          Bitstream * bs,          Bitstream * bs,
# Line 1343  Line 1364 
1364    VECTOR mv;    VECTOR mv;
1365    const VECTOR zeromv = {0,0};    const VECTOR zeromv = {0,0};
1366    int i;    int i;
1367      int resync_len;
1368    
1369    if (!dec->is_edged[0]) {    if (!dec->is_edged[0]) {
1370      start_timer();      start_timer();
# Line 1360  Line 1382 
1382      stop_edges_timer();      stop_edges_timer();
1383    }    }
1384    
1385      resync_len = get_resync_len_b(fcode_backward, fcode_forward);
1386    for (y = 0; y < dec->mb_height; y++) {    for (y = 0; y < dec->mb_height; y++) {
1387      /* Initialize Pred Motion Vector */      /* Initialize Pred Motion Vector */
1388      dec->p_fmv = dec->p_bmv = zeromv;      dec->p_fmv = dec->p_bmv = zeromv;
1389      for (x = 0; x < dec->mb_width; x++) {      for (x = 0; x < dec->mb_width; x++) {
1390        MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];        MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x];
1391        MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x];        MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x];
       const int fcode_max = (fcode_forward>fcode_backward) ? fcode_forward : fcode_backward;  
1392        int intra_dc_threshold; /* fake variable */        int intra_dc_threshold; /* fake variable */
1393    
       if (check_resync_marker(bs, fcode_max  - 1)) {  
         int bound = read_video_packet_header(bs, dec, fcode_max - 1, &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;  
       }  
   
1394        mv =        mv =
1395        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] =
1396        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 1396  Line 1409 
1409          continue;          continue;
1410        }        }
1411    
1412          if (check_resync_marker(bs, resync_len)) {
1413            int bound = read_video_packet_header(bs, dec, resync_len, &quant,
1414                               &fcode_forward, &fcode_backward, &intra_dc_threshold);
1415    
1416                    bound = MAX(0, bound--); /* valid bound must always be >0 */
1417            x = bound % dec->mb_width;
1418            y = MIN((bound / dec->mb_width), (dec->mb_height-1));
1419            /* reset predicted macroblocks */
1420            dec->p_fmv = dec->p_bmv = zeromv;
1421            /* update resync len with new fcodes */
1422            resync_len = get_resync_len_b(fcode_backward, fcode_forward);
1423                    continue; /* re-init loop */
1424              }
1425    
1426        if (!BitstreamGetBit(bs)) { /* modb=='0' */        if (!BitstreamGetBit(bs)) { /* modb=='0' */
1427          const uint8_t modb2 = BitstreamGetBit(bs);          const uint8_t modb2 = BitstreamGetBit(bs);
1428    
# Line 1509  Line 1536 
1536      image_copy(&dec->tmp, img, dec->edged_width, dec->height);      image_copy(&dec->tmp, img, dec->edged_width, dec->height);
1537      image_postproc(&dec->postproc, &dec->tmp, dec->edged_width,      image_postproc(&dec->postproc, &dec->tmp, dec->edged_width,
1538               mbs, dec->mb_width, dec->mb_height, dec->mb_width,               mbs, dec->mb_width, dec->mb_height, dec->mb_width,
1539               frame->general, brightness, dec->frames, (coding_type == B_VOP));               frame->general, brightness, dec->frames, (coding_type == B_VOP), dec->num_threads);
1540      img = &dec->tmp;      img = &dec->tmp;
1541    }    }
1542    
# Line 1615  Line 1642 
1642    if (coding_type == -2 || coding_type == -3) { /* vol and/or resize */    if (coding_type == -2 || coding_type == -3) { /* vol and/or resize */
1643    
1644      if (coding_type == -3)      if (coding_type == -3)
1645        decoder_resize(dec);        if (decoder_resize(dec)) return XVID_ERR_MEMORY;
1646    
1647      if(stats) {      if(stats) {
1648        stats->type = XVID_TYPE_VOL;        stats->type = XVID_TYPE_VOL;
# Line 1638  Line 1665 
1665      goto repeat;      goto repeat;
1666    }    }
1667    
1668    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 */
1669    
1670    /* packed_mode: special-N_VOP treament */    /* packed_mode: special-N_VOP treament */
1671    if (dec->packed_mode && coding_type == N_VOP) {    if (dec->packed_mode && coding_type == N_VOP) {

Legend:
Removed from v.1.76  
changed lines
  Added in v.1.86

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