Revision 3c275f6d

View differences:

libavcodec/vc1.c
209 209
    CS_HIGH_RATE_INTER
210 210
};
211 211

  
212
/** @name Overlap conditions for Advanced Profile */
213
//@{
214
enum COTypes {
215
    CONDOVER_NONE = 0,
216
    CONDOVER_ALL,
217
    CONDOVER_SELECT
218
};
219
//@}
220

  
221

  
212 222
/** The VC1 Context
213 223
 * @fixme Change size wherever another size is more efficient
214 224
 * Many members are only used for Advanced Profile
......
246 256
    int matrix_coef;      ///< 8bits, Color primaries->YCbCr transform matrix
247 257
    int hrd_param_flag;   ///< Presence of Hypothetical Reference
248 258
                          ///< Decoder parameters
259
    int psf;              ///< Progressive Segmented Frame
249 260
    //@}
250 261

  
251 262
    /** Sequence header data for all Profiles
......
344 355
    int hrd_num_leaky_buckets;
345 356
    uint8_t bit_rate_exponent;
346 357
    uint8_t buffer_size_exponent;
347
//    BitPlane ac_pred_plane;       ///< AC prediction flags bitplane
348
//    BitPlane over_flags_plane;    ///< Overflags bitplane
358
    uint8_t* acpred_plane;       ///< AC prediction flags bitplane
359
    int acpred_is_raw;
360
    uint8_t* over_flags_plane;   ///< Overflags bitplane
361
    int overflg_is_raw;
349 362
    uint8_t condover;
350 363
    uint16_t *hrd_rate, *hrd_buffer;
351 364
    uint8_t *hrd_fullness;
......
354 367
    uint8_t range_mapy;
355 368
    uint8_t range_mapuv;
356 369
    //@}
370

  
371
    int p_frame_skipped;
357 372
} VC1Context;
358 373

  
359 374
/**
......
1095 1110
    }
1096 1111
}
1097 1112

  
1113
static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb);
1114

  
1098 1115
/**
1099 1116
 * Decode Simple/Main Profiles sequence header
1100 1117
 * @see Figure 7-8, p16-17
......
1116 1133

  
1117 1134
    if (v->profile == PROFILE_ADVANCED)
1118 1135
    {
1119
        v->level = get_bits(gb, 3);
1120
        if(v->level >= 5)
1121
        {
1122
            av_log(avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level);
1123
        }
1124
        v->chromaformat = get_bits(gb, 2);
1125
        if (v->chromaformat != 1)
1126
        {
1127
            av_log(avctx, AV_LOG_ERROR,
1128
                   "Only 4:2:0 chroma format supported\n");
1129
            return -1;
1130
        }
1136
        return decode_sequence_header_adv(v, gb);
1131 1137
    }
1132 1138
    else
1133 1139
    {
......
1241 1247
    return -1;
1242 1248
}
1243 1249

  
1250
static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
1251
{
1252
    v->res_rtm_flag = 1;
1253
    v->level = get_bits(gb, 3);
1254
    if(v->level >= 5)
1255
    {
1256
        av_log(v->s.avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level);
1257
    }
1258
    v->chromaformat = get_bits(gb, 2);
1259
    if (v->chromaformat != 1)
1260
    {
1261
        av_log(v->s.avctx, AV_LOG_ERROR,
1262
               "Only 4:2:0 chroma format supported\n");
1263
        return -1;
1264
    }
1265

  
1266
    // (fps-2)/4 (->30)
1267
    v->frmrtq_postproc = get_bits(gb, 3); //common
1268
    // (bitrate-32kbps)/64kbps
1269
    v->bitrtq_postproc = get_bits(gb, 5); //common
1270
    v->postprocflag = get_bits(gb, 1); //common
1271

  
1272
    v->s.avctx->coded_width = (get_bits(gb, 12) + 1) << 1;
1273
    v->s.avctx->coded_height = (get_bits(gb, 12) + 1) << 1;
1274
    v->broadcast = get_bits1(gb);
1275
    v->interlace = get_bits1(gb);
1276
    v->tfcntrflag = get_bits1(gb);
1277
    v->finterpflag = get_bits1(gb);
1278
    get_bits1(gb); // reserved
1279
    v->psf = get_bits1(gb);
1280
    if(v->psf) { //PsF, 6.1.13
1281
        av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n");
1282
        return -1;
1283
    }
1284
    if(get_bits1(gb)) { //Display Info - decoding is not affected by it
1285
        int w, h, ar = 0;
1286
        av_log(v->s.avctx, AV_LOG_INFO, "Display extended info:\n");
1287
        w = get_bits(gb, 14);
1288
        h = get_bits(gb, 14);
1289
        av_log(v->s.avctx, AV_LOG_INFO, "Display dimensions: %ix%i\n", w, h);
1290
        //TODO: store aspect ratio in AVCodecContext
1291
        if(get_bits1(gb))
1292
            ar = get_bits(gb, 4);
1293
        if(ar == 15) {
1294
            w = get_bits(gb, 8);
1295
            h = get_bits(gb, 8);
1296
        }
1297

  
1298
        if(get_bits1(gb)){ //framerate stuff
1299
            if(get_bits1(gb)) {
1300
                get_bits(gb, 16);
1301
            } else {
1302
                get_bits(gb, 8);
1303
                get_bits(gb, 4);
1304
            }
1305
        }
1306

  
1307
        if(get_bits1(gb)){
1308
            v->color_prim = get_bits(gb, 8);
1309
            v->transfer_char = get_bits(gb, 8);
1310
            v->matrix_coef = get_bits(gb, 8);
1311
        }
1312
    }
1313

  
1314
    v->hrd_param_flag = get_bits1(gb);
1315
    if(v->hrd_param_flag) {
1316
        int i;
1317
        v->hrd_num_leaky_buckets = get_bits(gb, 5);
1318
        get_bits(gb, 4); //bitrate exponent
1319
        get_bits(gb, 4); //buffer size exponent
1320
        for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
1321
            get_bits(gb, 16); //hrd_rate[n]
1322
            get_bits(gb, 16); //hrd_buffer[n]
1323
        }
1324
    }
1325
    return 0;
1326
}
1327

  
1328
static int decode_entry_point(AVCodecContext *avctx, GetBitContext *gb)
1329
{
1330
    VC1Context *v = avctx->priv_data;
1331
    int i;
1332

  
1333
    av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32));
1334
    get_bits1(gb); // broken link
1335
    get_bits1(gb); // closed entry
1336
    v->panscanflag = get_bits1(gb);
1337
    get_bits1(gb); // refdist flag
1338
    v->s.loop_filter = get_bits1(gb);
1339
    v->fastuvmc = get_bits1(gb);
1340
    v->extended_mv = get_bits1(gb);
1341
    v->dquant = get_bits(gb, 2);
1342
    v->vstransform = get_bits1(gb);
1343
    v->overlap = get_bits1(gb);
1344
    v->quantizer_mode = get_bits(gb, 2);
1345

  
1346
    if(v->hrd_param_flag){
1347
        for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
1348
            get_bits(gb, 8); //hrd_full[n]
1349
        }
1350
    }
1351

  
1352
    if(get_bits1(gb)){
1353
        avctx->coded_width = (get_bits(gb, 12)+1)<<1;
1354
        avctx->coded_height = (get_bits(gb, 12)+1)<<1;
1355
    }
1356
    if(v->extended_mv)
1357
        v->extended_dmv = get_bits1(gb);
1358
    if(get_bits1(gb)) {
1359
        av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n");
1360
        skip_bits(gb, 3); // Y range, ignored for now
1361
    }
1362
    if(get_bits1(gb)) {
1363
        av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n");
1364
        skip_bits(gb, 3); // UV range, ignored for now
1365
    }
1366

  
1367
    return 0;
1368
}
1244 1369

  
1245 1370
static int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
1246 1371
{
......
1446 1571
    return 0;
1447 1572
}
1448 1573

  
1574
static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
1575
{
1576
    int fcm;
1577
    int pqindex, lowquant;
1578
    int status;
1579

  
1580
    v->p_frame_skipped = 0;
1581

  
1582
    if(v->interlace)
1583
        fcm = decode012(gb);
1584
    switch(get_prefix(gb, 0, 4)) {
1585
    case 0:
1586
        v->s.pict_type = P_TYPE;
1587
        break;
1588
    case 1:
1589
        v->s.pict_type = B_TYPE;
1590
        return -1;
1591
//      break;
1592
    case 2:
1593
        v->s.pict_type = I_TYPE;
1594
        break;
1595
    case 3:
1596
        v->s.pict_type = BI_TYPE;
1597
        return -1;
1598
//      break;
1599
    case 4:
1600
        v->s.pict_type = P_TYPE; // skipped pic
1601
        v->p_frame_skipped = 1;
1602
        return 0;
1603
    }
1604
    if(v->tfcntrflag)
1605
        get_bits(gb, 8);
1606
    if(v->broadcast) {
1607
        if(!v->interlace || v->panscanflag) {
1608
            get_bits(gb, 2);
1609
        } else {
1610
            get_bits1(gb);
1611
            get_bits1(gb);
1612
        }
1613
    }
1614
    if(v->panscanflag) {
1615
        //...
1616
    }
1617
    v->rnd = get_bits1(gb);
1618
    if(v->interlace)
1619
        v->uvsamp = get_bits1(gb);
1620
    if(v->finterpflag) v->interpfrm = get_bits(gb, 1);
1621
    pqindex = get_bits(gb, 5);
1622
    v->pqindex = pqindex;
1623
    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
1624
        v->pq = pquant_table[0][pqindex];
1625
    else
1626
        v->pq = pquant_table[1][pqindex];
1627

  
1628
    v->pquantizer = 1;
1629
    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
1630
        v->pquantizer = pqindex < 9;
1631
    if (v->quantizer_mode == QUANT_NON_UNIFORM)
1632
        v->pquantizer = 0;
1633
    v->pqindex = pqindex;
1634
    if (pqindex < 9) v->halfpq = get_bits(gb, 1);
1635
    else v->halfpq = 0;
1636
    if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
1637
        v->pquantizer = get_bits(gb, 1);
1638

  
1639
    switch(v->s.pict_type) {
1640
    case I_TYPE:
1641
        status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
1642
        if (status < 0) return -1;
1643
        av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: "
1644
                "Imode: %i, Invert: %i\n", status>>1, status&1);
1645
        v->condover = CONDOVER_NONE;
1646
        if(v->overlap && v->pq <= 8) {
1647
            v->condover = decode012(gb);
1648
            if(v->condover == CONDOVER_SELECT) {
1649
                status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v);
1650
                if (status < 0) return -1;
1651
                av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: "
1652
                        "Imode: %i, Invert: %i\n", status>>1, status&1);
1653
            }
1654
        }
1655
        break;
1656
    case P_TYPE:
1657
        if(v->postprocflag)
1658
            v->postproc = get_bits1(gb);
1659
        if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3);
1660
        else v->mvrange = 0;
1661
        v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
1662
        v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
1663
        v->range_x = 1 << (v->k_x - 1);
1664
        v->range_y = 1 << (v->k_y - 1);
1665

  
1666
        if (v->pq < 5) v->tt_index = 0;
1667
        else if(v->pq < 13) v->tt_index = 1;
1668
        else v->tt_index = 2;
1669

  
1670
        lowquant = (v->pq > 12) ? 0 : 1;
1671
        v->mv_mode = mv_pmode_table[lowquant][get_prefix(gb, 1, 4)];
1672
        if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
1673
        {
1674
            int scale, shift, i;
1675
            v->mv_mode2 = mv_pmode_table2[lowquant][get_prefix(gb, 1, 3)];
1676
            v->lumscale = get_bits(gb, 6);
1677
            v->lumshift = get_bits(gb, 6);
1678
            /* fill lookup tables for intensity compensation */
1679
            if(!v->lumscale) {
1680
                scale = -64;
1681
                shift = (255 - v->lumshift * 2) << 6;
1682
                if(v->lumshift > 31)
1683
                    shift += 128 << 6;
1684
            } else {
1685
                scale = v->lumscale + 32;
1686
                if(v->lumshift > 31)
1687
                    shift = (v->lumshift - 64) << 6;
1688
                else
1689
                    shift = v->lumshift << 6;
1690
            }
1691
            for(i = 0; i < 256; i++) {
1692
                v->luty[i] = clip_uint8((scale * i + shift + 32) >> 6);
1693
                v->lutuv[i] = clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
1694
            }
1695
        }
1696
        if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
1697
            v->s.quarter_sample = 0;
1698
        else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
1699
            if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
1700
                v->s.quarter_sample = 0;
1701
            else
1702
                v->s.quarter_sample = 1;
1703
        } else
1704
            v->s.quarter_sample = 1;
1705
        v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
1706

  
1707
        if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
1708
                 v->mv_mode2 == MV_PMODE_MIXED_MV)
1709
                || v->mv_mode == MV_PMODE_MIXED_MV)
1710
        {
1711
            status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
1712
            if (status < 0) return -1;
1713
            av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
1714
                   "Imode: %i, Invert: %i\n", status>>1, status&1);
1715
        } else {
1716
            v->mv_type_is_raw = 0;
1717
            memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
1718
        }
1719
        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1720
        if (status < 0) return -1;
1721
        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1722
               "Imode: %i, Invert: %i\n", status>>1, status&1);
1723

  
1724
        /* Hopefully this is correct for P frames */
1725
        v->s.mv_table_index = get_bits(gb, 2); //but using vc1_ tables
1726
        v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)];
1727
        if (v->dquant)
1728
        {
1729
            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1730
            vop_dquant_decoding(v);
1731
        }
1732

  
1733
        v->ttfrm = 0; //FIXME Is that so ?
1734
        if (v->vstransform)
1735
        {
1736
            v->ttmbf = get_bits(gb, 1);
1737
            if (v->ttmbf)
1738
            {
1739
                v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)];
1740
            }
1741
        } else {
1742
            v->ttmbf = 1;
1743
            v->ttfrm = TT_8X8;
1744
        }
1745
        break;
1746
    }
1747

  
1748
    /* AC Syntax */
1749
    v->c_ac_table_index = decode012(gb);
1750
    if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)
1751
    {
1752
        v->y_ac_table_index = decode012(gb);
1753
    }
1754
    /* DC Syntax */
1755
    v->s.dc_table_index = get_bits(gb, 1);
1756
    if (v->s.pict_type == I_TYPE && v->dquant) {
1757
        av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1758
        vop_dquant_decoding(v);
1759
    }
1760

  
1761
    return 0;
1762
}
1763

  
1449 1764
/***********************************************************************/
1450 1765
/**
1451 1766
 * @defgroup block VC-1 Block-level functions
......
2229 2544
    return 0;
2230 2545
}
2231 2546

  
2232
/** Decode intra block in inter frames - more generic version than vc1_decode_i_block
2547
/** Decode intra block in intra frames - should be faster than decode_intra_block
2233 2548
 * @param v VC1Context
2234 2549
 * @param block block to decode
2235 2550
 * @param coded are AC coeffs present or not
2236
 * @param mquant block quantizer
2237 2551
 * @param codingset set of VLC to decode data
2238 2552
 */
2239
static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int coded, int mquant, int codingset)
2553
static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int coded, int codingset, int mquant)
2240 2554
{
2241 2555
    GetBitContext *gb = &v->s.gb;
2242 2556
    MpegEncContext *s = &v->s;
......
2245 2559
    int16_t *dc_val;
2246 2560
    int16_t *ac_val, *ac_val2;
2247 2561
    int dcdiff;
2248
    int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
2249 2562
    int a_avail = v->a_avail, c_avail = v->c_avail;
2250 2563
    int use_pred = s->ac_pred;
2251 2564
    int scale;
2252 2565
    int q1, q2 = 0;
2253

  
2254
    /* XXX: Guard against dumb values of mquant */
2255
    mquant = (mquant < 1) ? 0 : ( (mquant>31) ? 31 : mquant );
2256

  
2257
    /* Set DC scale - y and c use the same */
2258
    s->y_dc_scale = s->y_dc_scale_table[mquant];
2259
    s->c_dc_scale = s->c_dc_scale_table[mquant];
2566
    int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
2260 2567

  
2261 2568
    /* Get DC differential */
2262 2569
    if (n < 4) {
......
2289 2596
    }
2290 2597

  
2291 2598
    /* Prediction */
2292
    dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
2599
    dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, v->a_avail, v->c_avail, &dc_val, &dc_pred_dir);
2293 2600
    *dc_val = dcdiff;
2294 2601

  
2295 2602
    /* Store the quantized DC coeff, used for prediction */
2296

  
2297 2603
    if (n < 4) {
2298 2604
        block[0] = dcdiff * s->y_dc_scale;
2299 2605
    } else {
......
2330 2636
        const int8_t *zz_table;
2331 2637
        int k;
2332 2638

  
2333
        zz_table = vc1_simple_progressive_8x8_zz;
2639
        if(v->s.ac_pred) {
2640
            if(!dc_pred_dir)
2641
                zz_table = vc1_horizontal_zz;
2642
            else
2643
                zz_table = vc1_vertical_zz;
2644
        } else
2645
            zz_table = vc1_normal_zz;
2334 2646

  
2335 2647
        while (!last) {
2336 2648
            vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
......
2428 2740
    return 0;
2429 2741
}
2430 2742

  
2431
/** Decode P block
2743
/** Decode intra block in inter frames - more generic version than vc1_decode_i_block
2744
 * @param v VC1Context
2745
 * @param block block to decode
2746
 * @param coded are AC coeffs present or not
2747
 * @param mquant block quantizer
2748
 * @param codingset set of VLC to decode data
2432 2749
 */
2433
static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquant, int ttmb, int first_block)
2750
static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int coded, int mquant, int codingset)
2434 2751
{
2752
    GetBitContext *gb = &v->s.gb;
2435 2753
    MpegEncContext *s = &v->s;
2436
    GetBitContext *gb = &s->gb;
2437
    int i, j;
2438
    int subblkpat = 0;
2439
    int scale, off, idx, last, skip, value;
2440
    int ttblk = ttmb & 7;
2754
    int dc_pred_dir = 0; /* Direction of the DC prediction used */
2755
    int run_diff, i;
2756
    int16_t *dc_val;
2757
    int16_t *ac_val, *ac_val2;
2758
    int dcdiff;
2759
    int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
2760
    int a_avail = v->a_avail, c_avail = v->c_avail;
2761
    int use_pred = s->ac_pred;
2762
    int scale;
2763
    int q1, q2 = 0;
2441 2764

  
2442
    if(ttmb == -1) {
2443
        ttblk = ttblk_to_tt[v->tt_index][get_vlc2(gb, vc1_ttblk_vlc[v->tt_index].table, VC1_TTBLK_VLC_BITS, 1)];
2444
    }
2445
    if(ttblk == TT_4X4) {
2446
        subblkpat = ~(get_vlc2(gb, vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1);
2447
    }
2448
    if((ttblk != TT_8X8 && ttblk != TT_4X4) && (v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))) {
2449
        subblkpat = decode012(gb);
2450
        if(subblkpat) subblkpat ^= 3; //swap decoded pattern bits
2451
        if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) ttblk = TT_8X4;
2452
        if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) ttblk = TT_4X8;
2453
    }
2454
    scale = 2 * mquant + v->halfpq;
2765
    /* XXX: Guard against dumb values of mquant */
2766
    mquant = (mquant < 1) ? 0 : ( (mquant>31) ? 31 : mquant );
2455 2767

  
2456
    // convert transforms like 8X4_TOP to generic TT and SUBBLKPAT
2768
    /* Set DC scale - y and c use the same */
2769
    s->y_dc_scale = s->y_dc_scale_table[mquant];
2770
    s->c_dc_scale = s->c_dc_scale_table[mquant];
2771

  
2772
    /* Get DC differential */
2773
    if (n < 4) {
2774
        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
2775
    } else {
2776
        dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
2777
    }
2778
    if (dcdiff < 0){
2779
        av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
2780
        return -1;
2781
    }
2782
    if (dcdiff)
2783
    {
2784
        if (dcdiff == 119 /* ESC index value */)
2785
        {
2786
            /* TODO: Optimize */
2787
            if (mquant == 1) dcdiff = get_bits(gb, 10);
2788
            else if (mquant == 2) dcdiff = get_bits(gb, 9);
2789
            else dcdiff = get_bits(gb, 8);
2790
        }
2791
        else
2792
        {
2793
            if (mquant == 1)
2794
                dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3;
2795
            else if (mquant == 2)
2796
                dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1;
2797
        }
2798
        if (get_bits(gb, 1))
2799
            dcdiff = -dcdiff;
2800
    }
2801

  
2802
    /* Prediction */
2803
    dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
2804
    *dc_val = dcdiff;
2805

  
2806
    /* Store the quantized DC coeff, used for prediction */
2807

  
2808
    if (n < 4) {
2809
        block[0] = dcdiff * s->y_dc_scale;
2810
    } else {
2811
        block[0] = dcdiff * s->c_dc_scale;
2812
    }
2813
    /* Skip ? */
2814
    run_diff = 0;
2815
    i = 0;
2816

  
2817
    //AC Decoding
2818
    i = 1;
2819

  
2820
    /* check if AC is needed at all and adjust direction if needed */
2821
    if(!a_avail) dc_pred_dir = 1;
2822
    if(!c_avail) dc_pred_dir = 0;
2823
    if(!a_avail && !c_avail) use_pred = 0;
2824
    ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
2825
    ac_val2 = ac_val;
2826

  
2827
    scale = mquant * 2 + v->halfpq;
2828

  
2829
    if(dc_pred_dir) //left
2830
        ac_val -= 16;
2831
    else //top
2832
        ac_val -= 16 * s->block_wrap[n];
2833

  
2834
    q1 = s->current_picture.qscale_table[mb_pos];
2835
    if(dc_pred_dir && c_avail) q2 = s->current_picture.qscale_table[mb_pos - 1];
2836
    if(!dc_pred_dir && a_avail) q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];
2837
    if(n && n<4) q2 = q1;
2838

  
2839
    if(coded) {
2840
        int last = 0, skip, value;
2841
        const int8_t *zz_table;
2842
        int k;
2843

  
2844
        zz_table = vc1_simple_progressive_8x8_zz;
2845

  
2846
        while (!last) {
2847
            vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
2848
            i += skip;
2849
            if(i > 63)
2850
                break;
2851
            block[zz_table[i++]] = value;
2852
        }
2853

  
2854
        /* apply AC prediction if needed */
2855
        if(use_pred) {
2856
            /* scale predictors if needed*/
2857
            if(q2 && q1!=q2) {
2858
                q1 = q1 * 2 - 1;
2859
                q2 = q2 * 2 - 1;
2860

  
2861
                if(dc_pred_dir) { //left
2862
                    for(k = 1; k < 8; k++)
2863
                        block[k << 3] += (ac_val[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2864
                } else { //top
2865
                    for(k = 1; k < 8; k++)
2866
                        block[k] += (ac_val[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2867
                }
2868
            } else {
2869
                if(dc_pred_dir) { //left
2870
                    for(k = 1; k < 8; k++)
2871
                        block[k << 3] += ac_val[k];
2872
                } else { //top
2873
                    for(k = 1; k < 8; k++)
2874
                        block[k] += ac_val[k + 8];
2875
                }
2876
            }
2877
        }
2878
        /* save AC coeffs for further prediction */
2879
        for(k = 1; k < 8; k++) {
2880
            ac_val2[k] = block[k << 3];
2881
            ac_val2[k + 8] = block[k];
2882
        }
2883

  
2884
        /* scale AC coeffs */
2885
        for(k = 1; k < 64; k++)
2886
            if(block[k]) {
2887
                block[k] *= scale;
2888
                if(!v->pquantizer)
2889
                    block[k] += (block[k] < 0) ? -mquant : mquant;
2890
            }
2891

  
2892
        if(use_pred) i = 63;
2893
    } else { // no AC coeffs
2894
        int k;
2895

  
2896
        memset(ac_val2, 0, 16 * 2);
2897
        if(dc_pred_dir) {//left
2898
            if(use_pred) {
2899
                memcpy(ac_val2, ac_val, 8 * 2);
2900
                if(q2 && q1!=q2) {
2901
                    q1 = q1 * 2 - 1;
2902
                    q2 = q2 * 2 - 1;
2903
                    for(k = 1; k < 8; k++)
2904
                        ac_val2[k] = (ac_val2[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2905
                }
2906
            }
2907
        } else {//top
2908
            if(use_pred) {
2909
                memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
2910
                if(q2 && q1!=q2) {
2911
                    q1 = q1 * 2 - 1;
2912
                    q2 = q2 * 2 - 1;
2913
                    for(k = 1; k < 8; k++)
2914
                        ac_val2[k + 8] = (ac_val2[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18;
2915
                }
2916
            }
2917
        }
2918

  
2919
        /* apply AC prediction if needed */
2920
        if(use_pred) {
2921
            if(dc_pred_dir) { //left
2922
                for(k = 1; k < 8; k++) {
2923
                    block[k << 3] = ac_val2[k] * scale;
2924
                    if(!v->pquantizer && block[k << 3])
2925
                        block[k << 3] += (block[k << 3] < 0) ? -mquant : mquant;
2926
                }
2927
            } else { //top
2928
                for(k = 1; k < 8; k++) {
2929
                    block[k] = ac_val2[k + 8] * scale;
2930
                    if(!v->pquantizer && block[k])
2931
                        block[k] += (block[k] < 0) ? -mquant : mquant;
2932
                }
2933
            }
2934
            i = 63;
2935
        }
2936
    }
2937
    s->block_last_index[n] = i;
2938

  
2939
    return 0;
2940
}
2941

  
2942
/** Decode P block
2943
 */
2944
static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquant, int ttmb, int first_block)
2945
{
2946
    MpegEncContext *s = &v->s;
2947
    GetBitContext *gb = &s->gb;
2948
    int i, j;
2949
    int subblkpat = 0;
2950
    int scale, off, idx, last, skip, value;
2951
    int ttblk = ttmb & 7;
2952

  
2953
    if(ttmb == -1) {
2954
        ttblk = ttblk_to_tt[v->tt_index][get_vlc2(gb, vc1_ttblk_vlc[v->tt_index].table, VC1_TTBLK_VLC_BITS, 1)];
2955
    }
2956
    if(ttblk == TT_4X4) {
2957
        subblkpat = ~(get_vlc2(gb, vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1);
2958
    }
2959
    if((ttblk != TT_8X8 && ttblk != TT_4X4) && (v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))) {
2960
        subblkpat = decode012(gb);
2961
        if(subblkpat) subblkpat ^= 3; //swap decoded pattern bits
2962
        if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) ttblk = TT_8X4;
2963
        if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) ttblk = TT_4X8;
2964
    }
2965
    scale = 2 * mquant + v->halfpq;
2966

  
2967
    // convert transforms like 8X4_TOP to generic TT and SUBBLKPAT
2457 2968
    if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) {
2458 2969
        subblkpat = 2 - (ttblk == TT_8X4_TOP);
2459 2970
        ttblk = TT_8X4;
......
2507 3018
                i += skip;
2508 3019
                if(i > 31)
2509 3020
                    break;
2510
                idx = vc1_simple_progressive_8x4_zz[i++];
3021
                if(v->profile < PROFILE_ADVANCED)
3022
                    idx = vc1_simple_progressive_8x4_zz[i++];
3023
                else
3024
                    idx = vc1_adv_progressive_8x4_zz[i++];
2511 3025
                block[idx + off] = value * scale;
2512 3026
                if(!v->pquantizer)
2513 3027
                    block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant;
......
2526 3040
                i += skip;
2527 3041
                if(i > 31)
2528 3042
                    break;
2529
                idx = vc1_simple_progressive_4x8_zz[i++];
3043
                if(v->profile < PROFILE_ADVANCED)
3044
                    idx = vc1_simple_progressive_4x8_zz[i++];
3045
                else
3046
                    idx = vc1_adv_progressive_4x8_zz[i++];
2530 3047
                block[idx + off] = value * scale;
2531 3048
                if(!v->pquantizer)
2532 3049
                    block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant;
......
3025 3542
    }
3026 3543
}
3027 3544

  
3545
/** Decode blocks of I-frame for advanced profile
3546
 */
3547
static void vc1_decode_i_blocks_adv(VC1Context *v)
3548
{
3549
    int k, j;
3550
    MpegEncContext *s = &v->s;
3551
    int cbp, val;
3552
    uint8_t *coded_val;
3553
    int mb_pos;
3554
    int mquant = v->pq;
3555
    int mqdiff;
3556
    int overlap;
3557
    GetBitContext *gb = &s->gb;
3558

  
3559
    /* select codingmode used for VLC tables selection */
3560
    switch(v->y_ac_table_index){
3561
    case 0:
3562
        v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
3563
        break;
3564
    case 1:
3565
        v->codingset = CS_HIGH_MOT_INTRA;
3566
        break;
3567
    case 2:
3568
        v->codingset = CS_MID_RATE_INTRA;
3569
        break;
3570
    }
3571

  
3572
    switch(v->c_ac_table_index){
3573
    case 0:
3574
        v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
3575
        break;
3576
    case 1:
3577
        v->codingset2 = CS_HIGH_MOT_INTER;
3578
        break;
3579
    case 2:
3580
        v->codingset2 = CS_MID_RATE_INTER;
3581
        break;
3582
    }
3583

  
3584
    /* Set DC scale - y and c use the same */
3585
    s->y_dc_scale = s->y_dc_scale_table[v->pq];
3586
    s->c_dc_scale = s->c_dc_scale_table[v->pq];
3587

  
3588
    //do frame decode
3589
    s->mb_x = s->mb_y = 0;
3590
    s->mb_intra = 1;
3591
    s->first_slice_line = 1;
3592
    ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
3593
    for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
3594
        for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
3595
            ff_init_block_index(s);
3596
            ff_update_block_index(s);
3597
            s->dsp.clear_blocks(s->block[0]);
3598
            mb_pos = s->mb_x + s->mb_y * s->mb_stride;
3599
            s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
3600

  
3601
            // do actual MB decoding and displaying
3602
            cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
3603
            if(v->acpred_is_raw)
3604
                v->s.ac_pred = get_bits(&v->s.gb, 1);
3605
            else
3606
                v->s.ac_pred = v->acpred_plane[mb_pos];
3607

  
3608
            if(v->condover == CONDOVER_SELECT) {
3609
                if(v->overflg_is_raw)
3610
                    overlap = get_bits(&v->s.gb, 1);
3611
                else
3612
                    overlap = v->over_flags_plane[mb_pos];
3613
            } else
3614
                overlap = (v->condover == CONDOVER_ALL);
3615

  
3616
            GET_MQUANT();
3617

  
3618
            s->current_picture.qscale_table[mb_pos] = mquant;
3619

  
3620
            for(k = 0; k < 6; k++) {
3621
                val = ((cbp >> (5 - k)) & 1);
3622

  
3623
                if (k < 4) {
3624
                    int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
3625
                    val = val ^ pred;
3626
                    *coded_val = val;
3627
                }
3628
                cbp |= val << (5 - k);
3629

  
3630
                v->a_avail = !s->first_slice_line || (k==2 || k==3);
3631
                v->c_avail = !!s->mb_x || (k==1 || k==3);
3632

  
3633
                vc1_decode_i_block_adv(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2, mquant);
3634

  
3635
                s->dsp.vc1_inv_trans_8x8(s->block[k]);
3636
                for(j = 0; j < 64; j++) s->block[k][j] += 128;
3637
            }
3638

  
3639
            vc1_put_block(v, s->block);
3640
            if(overlap) {
3641
                if(!s->first_slice_line) {
3642
                    s->dsp.vc1_v_overlap(s->dest[0], s->linesize, 0);
3643
                    s->dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize, 0);
3644
                    if(!(s->flags & CODEC_FLAG_GRAY)) {
3645
                        s->dsp.vc1_v_overlap(s->dest[1], s->uvlinesize, s->mb_y&1);
3646
                        s->dsp.vc1_v_overlap(s->dest[2], s->uvlinesize, s->mb_y&1);
3647
                    }
3648
                }
3649
                s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize, 1);
3650
                s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize, 1);
3651
                if(s->mb_x) {
3652
                    s->dsp.vc1_h_overlap(s->dest[0], s->linesize, 0);
3653
                    s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize, 0);
3654
                    if(!(s->flags & CODEC_FLAG_GRAY)) {
3655
                        s->dsp.vc1_h_overlap(s->dest[1], s->uvlinesize, s->mb_x&1);
3656
                        s->dsp.vc1_h_overlap(s->dest[2], s->uvlinesize, s->mb_x&1);
3657
                    }
3658
                }
3659
                s->dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize, 1);
3660
                s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize, 1);
3661
            }
3662

  
3663
            if(get_bits_count(&s->gb) > v->bits) {
3664
                av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits);
3665
                return;
3666
            }
3667
        }
3668
        ff_draw_horiz_band(s, s->mb_y * 16, 16);
3669
        s->first_slice_line = 0;
3670
    }
3671
}
3672

  
3028 3673
static void vc1_decode_p_blocks(VC1Context *v)
3029 3674
{
3030 3675
    MpegEncContext *s = &v->s;
......
3121 3766
    }
3122 3767
}
3123 3768

  
3769
static void vc1_decode_skip_blocks(VC1Context *v)
3770
{
3771
    MpegEncContext *s = &v->s;
3772

  
3773
    ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
3774
    s->first_slice_line = 1;
3775
    for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
3776
        s->mb_x = 0;
3777
        ff_init_block_index(s);
3778
        ff_update_block_index(s);
3779
        memcpy(s->dest[0], s->last_picture.data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16);
3780
        memcpy(s->dest[1], s->last_picture.data[1] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
3781
        memcpy(s->dest[2], s->last_picture.data[2] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
3782
        ff_draw_horiz_band(s, s->mb_y * 16, 16);
3783
        s->first_slice_line = 0;
3784
    }
3785
    s->pict_type = P_TYPE;
3786
}
3787

  
3124 3788
static void vc1_decode_blocks(VC1Context *v)
3125 3789
{
3126 3790

  
......
3128 3792

  
3129 3793
    switch(v->s.pict_type) {
3130 3794
    case I_TYPE:
3131
        vc1_decode_i_blocks(v);
3795
        if(v->profile == PROFILE_ADVANCED)
3796
            vc1_decode_i_blocks_adv(v);
3797
        else
3798
            vc1_decode_i_blocks(v);
3132 3799
        break;
3133 3800
    case P_TYPE:
3134
        vc1_decode_p_blocks(v);
3801
        if(v->p_frame_skipped)
3802
            vc1_decode_skip_blocks(v);
3803
        else
3804
            vc1_decode_p_blocks(v);
3135 3805
        break;
3136 3806
    case B_TYPE:
3137 3807
        vc1_decode_b_blocks(v);
......
3189 3859
        {
3190 3860
            av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
3191 3861
        }
3862
    } else { // VC1/WVC1
3863
        int edata_size = avctx->extradata_size;
3864
        uint8_t *edata = avctx->extradata;
3865

  
3866
        if(avctx->extradata_size < 16) {
3867
            av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", edata_size);
3868
            return -1;
3869
        }
3870
        while(edata_size > 8) {
3871
            // test if we've found header
3872
            if(BE_32(edata) == 0x0000010F) {
3873
                edata += 4;
3874
                edata_size -= 4;
3875
                break;
3876
            }
3877
            edata_size--;
3878
            edata++;
3879
        }
3880

  
3881
        init_get_bits(&gb, edata, edata_size*8);
3882

  
3883
        if (decode_sequence_header(avctx, &gb) < 0)
3884
          return -1;
3885

  
3886
        while(edata_size > 8) {
3887
            // test if we've found entry point
3888
            if(BE_32(edata) == 0x0000010E) {
3889
                edata += 4;
3890
                edata_size -= 4;
3891
                break;
3892
            }
3893
            edata_size--;
3894
            edata++;
3895
        }
3896

  
3897
        init_get_bits(&gb, edata, edata_size*8);
3898

  
3899
        if (decode_entry_point(avctx, &gb) < 0)
3900
          return -1;
3192 3901
    }
3193 3902
    avctx->has_b_frames= !!(avctx->max_b_frames);
3194 3903

  
......
3198 3907
    /* Allocate mb bitplanes */
3199 3908
    v->mv_type_mb_plane = av_malloc(s->mb_stride * s->mb_height);
3200 3909
    v->direct_mb_plane = av_malloc(s->mb_stride * s->mb_height);
3910
    v->acpred_plane = av_malloc(s->mb_stride * s->mb_height);
3911
    v->over_flags_plane = av_malloc(s->mb_stride * s->mb_height);
3201 3912

  
3202 3913
    /* allocate block type info in that way so it could be used with s->block_index[] */
3203 3914
    v->mb_type_base = av_malloc(s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
......
3229 3940
    VC1Context *v = avctx->priv_data;
3230 3941
    MpegEncContext *s = &v->s;
3231 3942
    AVFrame *pict = data;
3943
    uint8_t *buf2 = NULL;
3232 3944

  
3233 3945
    /* no supplementary picture */
3234 3946
    if (buf_size == 0) {
......
3251 3963

  
3252 3964
    avctx->has_b_frames= !s->low_delay;
3253 3965

  
3254
    init_get_bits(&s->gb, buf, buf_size*8);
3966
    //for advanced profile we need to unescape buffer
3967
    if (avctx->codec_id == CODEC_ID_VC1) {
3968
        int i, buf_size2;
3969
        buf2 = av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
3970
        buf_size2 = 0;
3971
        for(i = 0; i < buf_size; i++) {
3972
            if(buf[i] == 3 && i >= 2 && !buf[i-1] && !buf[i-2] && i < buf_size-1 && buf[i+1] < 4) {
3973
                buf2[buf_size2++] = buf[i+1];
3974
                i++;
3975
            } else
3976
                buf2[buf_size2++] = buf[i];
3977
        }
3978
        init_get_bits(&s->gb, buf2, buf_size2*8);
3979
    } else
3980
        init_get_bits(&s->gb, buf, buf_size*8);
3255 3981
    // do parse frame header
3256
    if(vc1_parse_frame_header(v, &s->gb) == -1)
3257
        return -1;
3982
    if(v->profile < PROFILE_ADVANCED) {
3983
        if(vc1_parse_frame_header(v, &s->gb) == -1) {
3984
            if(buf2)av_free(buf2);
3985
            return -1;
3986
        }
3987
    } else {
3988
        if(vc1_parse_frame_header_adv(v, &s->gb) == -1) {
3989
            if(buf2)av_free(buf2);
3990
            return -1;
3991
        }
3992
    }
3258 3993

  
3259
    if(s->pict_type != I_TYPE && !v->res_rtm_flag)return -1;
3260
    if(s->pict_type == B_TYPE)return -1;
3994
    if(s->pict_type != I_TYPE && !v->res_rtm_flag){
3995
        if(buf2)av_free(buf2);
3996
        return -1;
3997
    }
3261 3998

  
3262 3999
    // for hurry_up==5
3263 4000
    s->current_picture.pict_type= s->pict_type;
3264 4001
    s->current_picture.key_frame= s->pict_type == I_TYPE;
3265 4002

  
3266 4003
    /* skip B-frames if we don't have reference frames */
3267
    if(s->last_picture_ptr==NULL && (s->pict_type==B_TYPE || s->dropable)) return -1;//buf_size;
4004
    if(s->last_picture_ptr==NULL && (s->pict_type==B_TYPE || s->dropable)){
4005
        if(buf2)av_free(buf2);
4006
        return -1;//buf_size;
4007
    }
3268 4008
    /* skip b frames if we are in a hurry */
3269 4009
    if(avctx->hurry_up && s->pict_type==B_TYPE) return -1;//buf_size;
3270 4010
    if(   (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE)
3271 4011
       || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE)
3272
       ||  avctx->skip_frame >= AVDISCARD_ALL)
4012
       ||  avctx->skip_frame >= AVDISCARD_ALL) {
4013
        if(buf2)av_free(buf2);
3273 4014
        return buf_size;
4015
    }
3274 4016
    /* skip everything if we are in a hurry>=5 */
3275
    if(avctx->hurry_up>=5) return -1;//buf_size;
4017
    if(avctx->hurry_up>=5) {
4018
        if(buf2)av_free(buf2);
4019
        return -1;//buf_size;
4020
    }
3276 4021

  
3277 4022
    if(s->next_p_frame_damaged){
3278 4023
        if(s->pict_type==B_TYPE)
......
3281 4026
            s->next_p_frame_damaged=0;
3282 4027
    }
3283 4028

  
3284
    if(MPV_frame_start(s, avctx) < 0)
4029
    if(MPV_frame_start(s, avctx) < 0) {
4030
        if(buf2)av_free(buf2);
3285 4031
        return -1;
4032
    }
3286 4033

  
3287 4034
    ff_er_frame_start(s);
3288 4035

  
......
3312 4059
    /* we substract 1 because it is added on utils.c    */
3313 4060
    avctx->frame_number = s->picture_number - 1;
3314 4061

  
4062
    if(buf2)av_free(buf2);
3315 4063
    return buf_size;
3316 4064
}
3317 4065

  
......
3328 4076
    MPV_common_end(&v->s);
3329 4077
    av_freep(&v->mv_type_mb_plane);
3330 4078
    av_freep(&v->direct_mb_plane);
4079
    av_freep(&v->acpred_plane);
4080
    av_freep(&v->over_flags_plane);
3331 4081
    av_freep(&v->mb_type_base);
3332 4082
    return 0;
3333 4083
}

Also available in: Unified diff